opensurgsim
KeyboardCallbackBehavior.h
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2015, 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_KEYBOARDCALLBACKBEHAVIOR_H
17 #define SURGSIM_BLOCKS_KEYBOARDCALLBACKBEHAVIOR_H
18 
19 #include <functional>
20 
21 #include "SurgSim/Devices/Keyboard/KeyCode.h"
22 #include "SurgSim/Framework/Behavior.h"
23 
24 namespace SurgSim
25 {
26 namespace Input
27 {
28 class InputComponent;
29 }
30 
31 namespace Blocks
32 {
33 SURGSIM_STATIC_REGISTRATION(KeyboardCallbackBehavior);
34 
37 {
38 public:
39  typedef std::function<void()> CallbackType;
40 
43  explicit KeyboardCallbackBehavior(const std::string& name);
44 
46 
49  void setInputComponent(std::shared_ptr<Framework::Component> inputComponent);
50 
53  std::shared_ptr<Input::InputComponent> getInputComponent() const;
54 
57  void registerKey(int key);
58 
62  void registerCallback(CallbackType func);
63 
64  void update(double dt) override;
65 
66 protected:
69  int getKey() const;
70 
71  bool doInitialize() override;
72 
73  bool doWakeUp() override;
74 
75 private:
77  bool m_keyPressedLastUpdate;
78 
80  int m_actionKey;
81 
83  CallbackType m_callback;
84 
86  std::shared_ptr<Input::InputComponent> m_inputComponent;
87 };
88 
89 }; // namespace Blocks
90 }; // namespace SurgSim
91 
92 #endif //SURGSIM_BLOCKS_KEYBOARDCALLBACKBEHAVIOR_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Behaviors perform actions.
Definition: Behavior.h:40
This behavior will call the registered callback function when the registered key is pressed...
Definition: KeyboardCallbackBehavior.h:36