KeyboardCallbackBehavior.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2015, 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_KEYBOARDCALLBACKBEHAVIOR_H
#define SURGSIM_BLOCKS_KEYBOARDCALLBACKBEHAVIOR_H
#include <functional>
#include "SurgSim/Devices/Keyboard/KeyCode.h"
#include "SurgSim/Framework/Behavior.h"
namespace SurgSim
{
namespace Input
{
class InputComponent;
}
namespace Blocks
{
SURGSIM_STATIC_REGISTRATION(KeyboardCallbackBehavior);
class KeyboardCallbackBehavior : public Framework::Behavior
{
public:
typedef std::function<void()> CallbackType;
explicit KeyboardCallbackBehavior(const std::string& name);
SURGSIM_CLASSNAME(SurgSim::Blocks::KeyboardCallbackBehavior);
void setInputComponent(std::shared_ptr<Framework::Component> inputComponent);
std::shared_ptr<Input::InputComponent> getInputComponent() const;
void registerKey(int key);
void registerCallback(CallbackType func);
void update(double dt) override;
protected:
int getKey() const;
bool doInitialize() override;
bool doWakeUp() override;
private:
bool m_keyPressedLastUpdate;
int m_actionKey;
CallbackType m_callback;
std::shared_ptr<Input::InputComponent> m_inputComponent;
};
}; // namespace Blocks
}; // namespace SurgSim
#endif //SURGSIM_BLOCKS_KEYBOARDCALLBACKBEHAVIOR_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Blocks::KeyboardCallbackBehavior::m_actionKey
int m_actionKey
The registered key, when pressed, the registered callback will be called.
Definition: KeyboardCallbackBehavior.h:80
KeyCode.h
SurgSim::Blocks::KeyboardCallbackBehavior::m_callback
CallbackType m_callback
Callback function.
Definition: KeyboardCallbackBehavior.h:83
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::KeyboardCallbackBehavior::m_inputComponent
std::shared_ptr< Input::InputComponent > m_inputComponent
Input component from which pressed key comes.
Definition: KeyboardCallbackBehavior.h:86
SurgSim::Framework::Behavior
Behaviors perform actions.
Definition: Behavior.h:40
SurgSim::Blocks::KeyboardCallbackBehavior
This behavior will call the registered callback function when the registered key is pressed...
Definition: KeyboardCallbackBehavior.h:36
SurgSim::Blocks::KeyboardCallbackBehavior::CallbackType
std::function< void()> CallbackType
Definition: KeyboardCallbackBehavior.h:39
SurgSim::Blocks::KeyboardCallbackBehavior::m_keyPressedLastUpdate
bool m_keyPressedLastUpdate
Record if any key is pressed in last update() call.
Definition: KeyboardCallbackBehavior.h:77