Ocular Engine
InputHandler.hpp
1 
17 #ifndef __H__OCULAR_INPUT_INPUT_HANDLER__H__
18 #define __H__OCULAR_INPUT_INPUT_HANDLER__H__
19 
20 #include "Keys.hpp"
21 #include "Math/Vector2.hpp"
22 
23 #include <array>
24 
25 //------------------------------------------------------------------------------------------
26 
31 namespace Ocular
32 {
37  namespace Core
38  {
48  {
49  public:
50 
51  InputHandler();
52  ~InputHandler();
53 
58  void update();
59 
60  //------------------------------------------------------------
61  // Trigger Methods
62 
71  void triggerKeyboardKeyDown(KeyboardKeys key);
72 
81  void triggerMouseButtonDown(MouseButtons button);
82 
91  void triggerKeyboardKeyUp(KeyboardKeys key);
92 
101  void triggerMouseButtonUp(MouseButtons button);
102 
108  void triggerMouseMoveDelta(Math::Vector2i const& delta);
109 
118  void setMousePosition(Math::Vector2i const& position);
119 
124  void triggerMouseScrollDelta(int8_t delta);
125 
126  //------------------------------------------------------------
127  // Query Methods
128 
132  Math::Vector2i const& getMousePosition() const;
133 
141  bool isKeyboardKeyDown(KeyboardKeys key) const;
142 
150  bool isMouseButtonDown(MouseButtons button) const;
151 
160  bool isLeftShiftDown() const;
161 
170  bool isRightShiftDown() const;
171 
180  bool isLeftCtrlDown() const;
181 
190  bool isRightCtrlDown() const;
191 
200  bool isLeftAltDown() const;
201 
210  bool isRightAltDown() const;
211 
220  bool isLeftMouseDown() const;
221 
230  bool isRightMouseDown() const;
231 
232  //------------------------------------------------------------
233  // Misc.
234 
235  static std::string ToString(KeyState state);
236  static std::string ToString(MouseButtons button);
237  static std::string ToString(KeyboardKeys key);
238 
239  protected:
240 
241  private:
242 
243  void toggleKeyState(KeyboardKeys key);
244  void toggleButtonState(MouseButtons button);
245 
250  void shiftConvertKey(KeyboardKeys& key);
251 
261  void swapShiftSpecialKeys();
262 
263  //------------------------------------------------------------
264 
265  std::array<bool, 255> m_KeyboardState;
266  std::array<bool, 5> m_MouseState;
267 
268  Math::Vector2i m_MousePosition;
269  };
270  }
274 }
279 //------------------------------------------------------------------------------------------
280 
281 #endif
bool isLeftCtrlDown() const
Definition: InputHandler.cpp:156
bool isLeftAltDown() const
Definition: InputHandler.cpp:166
bool isMouseButtonDown(MouseButtons button) const
Definition: InputHandler.cpp:141
void triggerMouseButtonUp(MouseButtons button)
Definition: InputHandler.cpp:95
bool isRightShiftDown() const
Definition: InputHandler.cpp:151
void triggerKeyboardKeyUp(KeyboardKeys key)
Definition: InputHandler.cpp:70
void update()
Definition: InputHandler.cpp:190
Note: Once this library is made dynamic, this will no longer be needed.
Definition: Common.hpp:70
bool isKeyboardKeyDown(KeyboardKeys key) const
Definition: InputHandler.cpp:136
bool isLeftShiftDown() const
Definition: InputHandler.cpp:146
void triggerMouseButtonDown(MouseButtons button)
Definition: InputHandler.cpp:62
bool isRightMouseDown() const
Definition: InputHandler.cpp:181
Math::Vector2i const & getMousePosition() const
Definition: InputHandler.cpp:131
Definition: Vector2.hpp:44
void triggerMouseScrollDelta(int8_t delta)
Definition: InputHandler.cpp:103
void triggerMouseMoveDelta(Math::Vector2i const &delta)
Definition: InputHandler.cpp:111
bool isRightCtrlDown() const
Definition: InputHandler.cpp:161
Definition: InputHandler.hpp:47
bool isRightAltDown() const
Definition: InputHandler.cpp:171
bool isLeftMouseDown() const
Definition: InputHandler.cpp:176
void setMousePosition(Math::Vector2i const &position)
Definition: InputHandler.cpp:122
void triggerKeyboardKeyDown(KeyboardKeys key)
Definition: InputHandler.cpp:52