vkmEngine 1.0.0
A C++ game engine · vkmengine.com
Loading...
Searching...
No Matches
input_handle.h
1#pragma once
2
3#include <string>
4
5namespace Vkm::Engine {
6
12constexpr int MAX_MOUSE_BUTTON = 7; // GLFW_MOUSE_BUTTON_LAST
13constexpr int MAX_KEY = 348; // GLFW_KEY_LAST
14
22class InputHandle {
23 public:
24 InputHandle() = default;
25 ~InputHandle() = default;
26
27 InputHandle(const InputHandle& other) = delete;
28 InputHandle& operator=(const InputHandle& other) = delete;
29
30 InputHandle(InputHandle && other) = delete;
31 InputHandle& operator=(InputHandle && other) = delete;
32
33 public:
40 bool isKeyPressed(int key) const;
41
50 bool wasKeyStruck(int key) const;
51
58 bool wasKeyTyped(int key) const;
59
69 void onKeyEvent(int key, bool pressed);
70
76 void onText(char32_t codepoint);
77
85 const std::u32string& text() const { return m_text; }
86
95 void moveTo(double x, double y);
96
105 void setButton(int button, bool pressed);
106
113 bool isButtonPressed(int button) const;
114
122 bool wasButtonStruck(int button) const;
123
128
135
143 void addScroll(double yOffset);
144
150 double getX() const { return m_x; }
151
157 double getY() const { return m_y; }
158
164 double getDeltaX() const { return m_deltaX; }
165
171 double getDeltaY() const { return m_deltaY; }
172
178 double getScrollY() const { return m_scrollY; }
179
180 private:
181 bool m_keyState[MAX_KEY + 1] = {};
182 bool m_keyStruck[MAX_KEY + 1] = {};
183 bool m_keyTyped[MAX_KEY + 1] = {};
184
185 std::u32string m_text;
186
187 bool m_buttonState[MAX_MOUSE_BUTTON + 1] = {};
188 bool m_buttonStruck[MAX_MOUSE_BUTTON + 1] = {};
189
190 double m_x = 0.0;
191 double m_y = 0.0;
192 double m_deltaX = 0.0;
193 double m_deltaY = 0.0;
194
195 double m_scrollY = 0.0;
196};
197
198} // namespace Vkm::Engine
bool wasKeyTyped(int key) const
Whether the key went down or auto-repeated since the last clearStrikes().
double getScrollY() const
The scroll accumulated since resetScrollDelta().
Definition input_handle.h:178
bool wasButtonStruck(int button) const
Whether the button went down since the last clearStrikes(), even if it is up again.
void addScroll(double yOffset)
Add to this frame's scroll, which resetScrollDelta() clears.
void setButton(int button, bool pressed)
Record a mouse button's held state.
void clearStrikes()
Forget every key and button press, repeat and character recorded so far.
double getX() const
The absolute cursor X position.
Definition input_handle.h:150
void resetScrollDelta()
Zero the scroll delta before the window polls for this frame's.
bool isKeyPressed(int key) const
Check whether the specified key is currently held down.
void onText(char32_t codepoint)
Record a character the keyboard produced.
const std::u32string & text() const
The characters typed since the last clearStrikes(), in order, as UTF-32.
Definition input_handle.h:85
double getDeltaX() const
The X movement the last moveTo recorded.
Definition input_handle.h:164
bool isButtonPressed(int button) const
Check if the specified mouse button is pressed.
double getY() const
The absolute cursor Y position.
Definition input_handle.h:157
double getDeltaY() const
The Y movement the last moveTo recorded.
Definition input_handle.h:171
void moveTo(double x, double y)
Move the cursor to x, y, recording the step it took.
void onKeyEvent(int key, bool pressed)
Record a key's held state.
bool wasKeyStruck(int key) const
Whether the key went down since the last clearStrikes().