KeyboardTogglesComponentBehavior.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_BLOCKS_KEYBOARDTOGGLESCOMPONENTBEHAVIOR_H
#define SURGSIM_BLOCKS_KEYBOARDTOGGLESCOMPONENTBEHAVIOR_H
#include <unordered_map>
#include <unordered_set>
#include "SurgSim/Devices/Keyboard/KeyCode.h"
#include "SurgSim/Framework/Behavior.h"
#include "SurgSim/Framework/Macros.h"
namespace SurgSim
{
namespace Framework
{
class Component;
}
namespace Input
{
class InputComponent;
}
namespace Blocks
{
SURGSIM_STATIC_REGISTRATION(KeyboardTogglesComponentBehavior);
class KeyboardTogglesComponentBehavior : public SurgSim::Framework::Behavior
{
public:
typedef std::unordered_map<int, std::unordered_set<std::shared_ptr<SurgSim::Framework::Component>>>
KeyboardRegistryType;
explicit KeyboardTogglesComponentBehavior(const std::string& name);
SURGSIM_CLASSNAME(SurgSim::Blocks::KeyboardTogglesComponentBehavior);
void setInputComponent(std::shared_ptr<SurgSim::Framework::Component> inputComponent);
std::shared_ptr<SurgSim::Input::InputComponent> getInputComponent() const;
void registerKey(SurgSim::Devices::KeyCode key, std::shared_ptr<SurgSim::Framework::Component> component);
void setKeyboardRegistry(const KeyboardRegistryType& map);
const KeyboardRegistryType& getKeyboardRegistry() const;
void update(double dt) override;
protected:
bool doInitialize() override;
bool doWakeUp() override;
private:
bool m_keyPressedLastUpdate;
std::shared_ptr<SurgSim::Input::InputComponent> m_inputComponent;
KeyboardRegistryType m_registry;
};
}; // namespace Blocks
}; // namespace SurgSim
#endif //SURGSIM_BLOCKS_KEYBOARDTOGGLESCOMPONENTBEHAVIOR_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Blocks::KeyboardTogglesComponentBehavior::m_inputComponent
std::shared_ptr< SurgSim::Input::InputComponent > m_inputComponent
Input component from which pressed keys come.
Definition: KeyboardTogglesComponentBehavior.h:98
KeyCode.h
SurgSim::Blocks::KeyboardTogglesComponentBehavior::KeyboardRegistryType
std::unordered_map< int, std::unordered_set< std::shared_ptr< SurgSim::Framework::Component > > > KeyboardRegistryType
Definition: KeyboardTogglesComponentBehavior.h:48
SurgSim::Blocks::KeyboardTogglesComponentBehavior::m_registry
KeyboardRegistryType m_registry
A mapping between key and the graphical representation(s) it controls.
Definition: KeyboardTogglesComponentBehavior.h:101
Behavior.h
SURGSIM_CLASSNAME
#define SURGSIM_CLASSNAME(ClassName)
Declare the class name of a class with the appropriate function header, do not use quotes...
Definition: Macros.h:21
SurgSim::Blocks::KeyboardTogglesComponentBehavior::m_keyPressedLastUpdate
bool m_keyPressedLastUpdate
Record if any key is pressed in last update() call.
Definition: KeyboardTogglesComponentBehavior.h:95
Macros.h
SurgSim::Blocks::KeyboardTogglesComponentBehavior
This behavior is used to control the activity of registered components.
Definition: KeyboardTogglesComponentBehavior.h:44
SurgSim::Framework::Behavior
Behaviors perform actions.
Definition: Behavior.h:40
SurgSim::Devices::KeyCode
KeyCode
Definition: KeyCode.h:24