opensurgsim
KeyboardTogglesComponentBehavior.h
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 
22 #include "SurgSim/Devices/Keyboard/KeyCode.h"
23 #include "SurgSim/Framework/Behavior.h"
24 #include "SurgSim/Framework/Macros.h"
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>>>
48  KeyboardRegistryType;
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:
95  bool m_keyPressedLastUpdate;
96 
98  std::shared_ptr<SurgSim::Input::InputComponent> m_inputComponent;
99 
101  KeyboardRegistryType m_registry;
102 };
103 
104 }; // namespace Blocks
105 }; // namespace SurgSim
106 
107 #endif //SURGSIM_BLOCKS_KEYBOARDTOGGLESCOMPONENTBEHAVIOR_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
This behavior is used to control the activity of registered components.
Definition: KeyboardTogglesComponentBehavior.h:44
Behaviors perform actions.
Definition: Behavior.h:40