Nebula
Loading...
Searching...
No Matches
keyboardbase.h
Go to the documentation of this file.
1#pragma once
2//------------------------------------------------------------------------------
12#include "input/inputhandler.h"
13#include "input/key.h"
14
15//------------------------------------------------------------------------------
16namespace Base
17{
19{
21public:
25 virtual ~KeyboardBase();
26
28 virtual void BeginCapture();
30 virtual void EndCapture();
31
33 void SetKeyDown(Input::Key::Code keyCode);
35 void SetKeyUp(Input::Key::Code keyCode);
36
38 bool KeyPressed(Input::Key::Code keyCode) const;
40 bool KeyDown(Input::Key::Code keyCode) const;
42 bool KeyUp(Input::Key::Code keyCode) const;
44 const Util::String& GetCharInput() const;
45
46protected:
48 virtual void OnAttach();
50 virtual void OnBeginFrame();
52 virtual bool OnEvent(const Input::InputEvent& inputEvent);
54 virtual void OnObtainCapture();
56 virtual void OnReleaseCapture();
58 virtual void OnReset();
59
60
61private:
63 {
64 public:
66 KeyState() : pressed(false), down(false), up(false) {};
67
68 bool pressed; // currently pressed
69 bool down; // was down this frame
70 bool up; // was up this frame
71 };
75};
76
77//------------------------------------------------------------------------------
80inline void
82{
83 KeyState& keyState = this->keyStates[keyCode];
84 if (!keyState.pressed)
85 {
86 keyState.down = true;
87 keyState.pressed = true;
88 }
89}
90
91//------------------------------------------------------------------------------
94inline void
96{
97 this->keyStates[keyCode].up = true;
98}
99
100//------------------------------------------------------------------------------
103inline bool
105{
106 return this->keyStates[keyCode].pressed;
107}
108
109//------------------------------------------------------------------------------
112inline bool
114{
115 return this->keyStates[keyCode].down;
116}
117
118//------------------------------------------------------------------------------
121inline bool
123{
124 return this->keyStates[keyCode].up;
125}
126
127//------------------------------------------------------------------------------
130inline const Util::String&
132{
133 return this->charInput;
134}
135
136} // namespace Input
137//------------------------------------------------------------------------------
138
Definition keyboardbase.h:63
bool pressed
Definition keyboardbase.h:68
KeyState()
constructor
Definition keyboardbase.h:66
bool down
Definition keyboardbase.h:69
bool up
Definition keyboardbase.h:70
An input handler which represents a keyboard for polling.
Definition keyboardbase.h:19
void SetKeyDown(Input::Key::Code keyCode)
sets a key to be down
Definition keyboardbase.h:81
virtual void OnAttach()
called when the handler is attached to the input server
Definition keyboardbase.cc:58
virtual void OnReset()
reset the input handler
Definition keyboardbase.cc:189
virtual void OnObtainCapture()
called when input handler obtains capture
Definition keyboardbase.cc:161
__DeclareClass(KeyboardBase)
Util::FixedArray< KeyState > nextKeyStates
Definition keyboardbase.h:73
bool KeyUp(Input::Key::Code keyCode) const
return true if key was released at least once in current frame
Definition keyboardbase.h:122
virtual void EndCapture()
end input capturing to this event handler
Definition keyboardbase.cc:48
bool KeyDown(Input::Key::Code keyCode) const
return true if key was pushed down at least once in current frame
Definition keyboardbase.h:113
virtual void BeginCapture()
capture input to this event handler
Definition keyboardbase.cc:38
void SetKeyUp(Input::Key::Code keyCode)
sets a key to be up
Definition keyboardbase.h:95
KeyboardBase()
constructor
Definition keyboardbase.cc:19
Util::FixedArray< KeyState > keyStates
Definition keyboardbase.h:72
virtual ~KeyboardBase()
destructor
Definition keyboardbase.cc:29
Util::String charInput
Definition keyboardbase.h:74
const Util::String & GetCharInput() const
get character input in current frame
Definition keyboardbase.h:131
bool KeyPressed(Input::Key::Code keyCode) const
return true if a key is currently pressed
Definition keyboardbase.h:104
virtual void OnReleaseCapture()
called when input handler looses capture
Definition keyboardbase.cc:175
virtual bool OnEvent(const Input::InputEvent &inputEvent)
called when an input event should be processed
Definition keyboardbase.cc:104
virtual void OnBeginFrame()
called on InputServer::BeginFrame()
Definition keyboardbase.cc:71
The input events of the Input subsystems.
Definition inputevent.h:24
Input handlers receive and process input events.
Definition inputhandler.h:29
Code
key codes
Definition key.h:25
Implements a fixed size one-dimensional array.
Definition fixedarray.h:20
Definition gamecontentserverbase.cc:10
Nebula's universal string class.
Definition String.cs:8