KeyboardTogglesComponentBehavior.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_BLOCKS_KEYBOARDTOGGLESCOMPONENTBEHAVIOR_H
17 #define SURGSIM_BLOCKS_KEYBOARDTOGGLESCOMPONENTBEHAVIOR_H
18 
19 #include <unordered_map>
20 #include <unordered_set>
21 
25 
26 namespace SurgSim
27 {
28 
29 namespace Framework
30 {
31 class Component;
32 }
33 
34 namespace Input
35 {
36 class InputComponent;
37 }
38 
39 namespace Blocks
40 {
41 SURGSIM_STATIC_REGISTRATION(KeyboardTogglesComponentBehavior);
42 
45 {
46 public:
47  typedef std::unordered_map<int, std::unordered_set<std::shared_ptr<SurgSim::Framework::Component>>>
49 
52  explicit KeyboardTogglesComponentBehavior(const std::string& name);
53 
55 
58  void setInputComponent(std::shared_ptr<SurgSim::Framework::Component> inputComponent);
59 
62  std::shared_ptr<SurgSim::Input::InputComponent> getInputComponent() const;
63 
68  void registerKey(SurgSim::Devices::KeyCode key, std::shared_ptr<SurgSim::Framework::Component> component);
69 
72  void setKeyboardRegistry(const KeyboardRegistryType& map);
73 
76  const KeyboardRegistryType& getKeyboardRegistry() const;
77 
80  void update(double dt) override;
81 
82 protected:
86  bool doInitialize() override;
87 
91  bool doWakeUp() override;
92 
93 private:
96 
98  std::shared_ptr<SurgSim::Input::InputComponent> m_inputComponent;
99 
102 };
103 
104 }; // namespace Blocks
105 }; // namespace SurgSim
106 
107 #endif //SURGSIM_BLOCKS_KEYBOARDTOGGLESCOMPONENTBEHAVIOR_H
Definition: CompoundShapeToGraphics.cpp:29
std::shared_ptr< SurgSim::Input::InputComponent > m_inputComponent
Input component from which pressed keys come.
Definition: KeyboardTogglesComponentBehavior.h:98
std::unordered_map< int, std::unordered_set< std::shared_ptr< SurgSim::Framework::Component > > > KeyboardRegistryType
Definition: KeyboardTogglesComponentBehavior.h:48
KeyboardRegistryType m_registry
A mapping between key and the graphical representation(s) it controls.
Definition: KeyboardTogglesComponentBehavior.h:101
#define SURGSIM_CLASSNAME(ClassName)
Declare the class name of a class with the appropriate function header, do not use quotes...
Definition: Macros.h:21
bool m_keyPressedLastUpdate
Record if any key is pressed in last update() call.
Definition: KeyboardTogglesComponentBehavior.h:95
This behavior is used to control the activity of registered components.
Definition: KeyboardTogglesComponentBehavior.h:44
Behaviors perform actions.
Definition: Behavior.h:40
KeyCode
Definition: KeyCode.h:24