CeresEngine 0.2.0
A game development framework
Loading...
Searching...
No Matches
Input.hpp
Go to the documentation of this file.
1//
2// CeresEngine - A game development framework
3//
4// Created by Rogiel Sulzbach.
5// Copyright (c) 2018-2022 Rogiel Sulzbach. All rights reserved.
6//
7
8#pragma once
9
12
16
17#include <algorithm>
18#include <cstdint>
19#include <limits>
20
21namespace CeresEngine {
22
26 None = 0,
27
28 Space,
29 Apostrophe, /* ' */
30 Comma, /* , */
31 Minus, /* - */
32 Period, /* . */
33 Slash, /* / */
34 Semicolon, /* ; */
35 Equal, /* = */
36
37 Number0,
38 Number1,
39 Number2,
40 Number3,
41 Number4,
42 Number5,
43 Number6,
44 Number7,
45 Number8,
46 Number9,
47
48 A,
49 B,
50 C,
51 D,
52 E,
53 F,
54 G,
55 H,
56 I,
57 J,
58 K,
59 L,
60 M,
61 N,
62 O,
63 P,
64 Q,
65 R,
66 S,
67 T,
68 U,
69 V,
70 W,
71 X,
72 Y,
73 Z,
74
75 LeftBracket, /* [ */
76 RightBracket, /* ] */
77 Backslash, /* \ */
78 GraveAccent, /* ` */
79
80 World1, /* non-us #1 */
81 World2, /* non-us #2 */
82
83 Escape,
84 Enter,
85 Tab,
87 Insert,
88 Delete,
89 Right,
90 Left,
91 Down,
92 Up,
93
94 PageUp,
96 Home,
97 End,
100 NumLock,
102 Pause,
103
104 F1,
105 F2,
106 F3,
107 F4,
108 F5,
109 F6,
110 F7,
111 F8,
112 F9,
113 F10,
114 F11,
115 F12,
116 F13,
117 F14,
118 F15,
119 F16,
120 F17,
121 F18,
122 F19,
123 F20,
124 F21,
125 F22,
126 F23,
127 F24,
128 F25,
129
130 Keypad0,
131 Keypad1,
132 Keypad2,
133 Keypad3,
134 Keypad4,
135 Keypad5,
136 Keypad6,
137 Keypad7,
138 Keypad8,
139 Keypad9,
140
145 KeypadAdd,
148
149 LeftShift,
151 LeftAlt,
152 LeftSuper,
155 RightAlt,
157 Menu,
158
159 MouseLeft,
162
163 Mouse0,
164 Mouse1,
165 Mouse2,
166 Mouse3,
167 Mouse4,
168 Mouse5,
169 Mouse6,
170 Mouse7,
171
172 Unknown = std::numeric_limits<UInt32>::max()
173 };
174
177
182 [[nodiscard]] inline bool operator&(const ButtonSet& set, const Button button) noexcept { return std::find(set.begin(), set.end(), button) != set.end(); }
183
188 [[nodiscard]] inline bool operator&(const ButtonSet& a, const ButtonSet& b) noexcept {
189 for(const Button button : b) {
190 if(!(a & button)) {
191 return false;
192 }
193 }
194 return true;
195 }
196
201 [[nodiscard]] inline ButtonSet operator+(const Button a, const Button b) { return ButtonSet{a, b}; }
202
208 const auto found = std::find(set.begin(), set.end(), button);
209 if(found != set.end()) {
210 return set;
211 }
212 set.push_back(button);
213 return set;
214 }
215
220 [[nodiscard]] inline ButtonSet operator+(const ButtonSet& set, const Button button) {
221 ButtonSet buttonSet = set;
222 buttonSet += button;
223 return buttonSet;
224 }
225
230 inline ButtonSet& operator+=(ButtonSet& set, const ButtonSet& buttons) {
231 for(const Button button : buttons) {
232 set += button;
233 }
234 return set;
235 }
236
241 [[nodiscard]] inline ButtonSet operator+(const ButtonSet& set, const ButtonSet& buttons) {
242 ButtonSet buttonSet = set;
243 buttonSet += buttons;
244 return buttonSet;
245 }
246
251 [[nodiscard]] inline ButtonSet operator|(const ButtonSet& set, const Button button) { return set + button; }
252
258 const auto found = std::find(set.begin(), set.end(), button);
259 if(found == set.end()) {
260 return set;
261 }
262 set.erase(found);
263 return set;
264 }
265
270 [[nodiscard]] inline ButtonSet operator-(const ButtonSet& set, const Button button) {
271 ButtonSet buttonSet = set;
272 buttonSet -= button;
273 return buttonSet;
274 }
275
280 inline ButtonSet& operator-=(ButtonSet& set, const ButtonSet& buttons) {
281 for(const Button button : buttons) {
282 set -= button;
283 }
284 return set;
285 }
286
291 [[nodiscard]] inline ButtonSet operator-(const ButtonSet& set, const ButtonSet& buttons) {
292 ButtonSet buttonSet = set;
293 buttonSet -= buttons;
294 return buttonSet;
295 }
296
300 Shift = 1u << 0u,
301
303 Control = 1u << 1u,
304
306 Alt = 1u << 2u,
307
311 Super = 1u << 3u,
312
314 CapsLock = 1u << 4u,
315
317 NumLock = 1u << 5u,
318
320 ScrollLock = 1u << 6u,
321
324 None = 0,
325
328 Any = std::numeric_limits<std::underlying_type_t<ModifierButton>>::max()
329 };
330
335 [[nodiscard]] inline constexpr bool operator&(ModifierButton a, ModifierButton b) noexcept {
336 if(b == ModifierButton::None) {
337 return a == b;
338 }
339 if(b == ModifierButton::Any) {
340 return true;
341 }
342 return (static_cast<std::underlying_type_t<ModifierButton>>(a) & static_cast<std::underlying_type_t<ModifierButton>>(b)) ==
343 static_cast<std::underlying_type_t<ModifierButton>>(b);
344 }
345
350 [[nodiscard]] inline constexpr ModifierButton operator|(ModifierButton a, ModifierButton b) noexcept {
351 return static_cast<ModifierButton>(static_cast<std::underlying_type_t<ModifierButton>>(a) | static_cast<std::underlying_type_t<ModifierButton>>(b));
352 }
353
358 [[nodiscard]] inline constexpr ModifierButton operator+(ModifierButton a, ModifierButton b) noexcept {
359 return static_cast<ModifierButton>(static_cast<std::underlying_type_t<ModifierButton>>(a) | static_cast<std::underlying_type_t<ModifierButton>>(b));
360 }
361
366 inline constexpr ModifierButton operator+=(ModifierButton& a, const ModifierButton b) noexcept { return a = (a + b); }
367
372 [[nodiscard]] inline constexpr ModifierButton operator-(ModifierButton a, ModifierButton b) noexcept {
373 return static_cast<ModifierButton>(static_cast<std::underlying_type_t<ModifierButton>>(a) & // NOLINT
374 ~static_cast<std::underlying_type_t<ModifierButton>>(b));
375 }
376
381 inline constexpr ModifierButton operator-=(ModifierButton& a, const ModifierButton b) noexcept { return a = (a - b); }
382
387
391 [[nodiscard]] Button button(const StringView& str) noexcept;
392
397
400 enum class CE_SCRIPT_EXPORT() Axis : UInt8 {
403
406
409
412
414 Unknown = std::numeric_limits<UInt8>::max()
415 };
416
421
425 [[nodiscard]] Axis axis(const StringView& str) noexcept;
426
428 enum class CursorMode {
431 Normal,
432
434 Hidden,
435
438 };
439
440} // namespace CeresEngine
#define CE_SCRIPT_EXPORT(...)
The CE_SCRIPT_EXPORT macro marks a class or method as exportable and available in scripting environme...
Definition Macros.hpp:247
Definition Any.hpp:13
Definition Application.hpp:19
ButtonSet & operator-=(ButtonSet &set, const Button button)
Removes a button from a set.
Definition Input.hpp:257
ModifierButton
A enumeration of possible modifier buttons.
Definition Input.hpp:298
@ Super
A constant for the super modifier key, called the "windows key" on Windows PCs and "command" on Macin...
@ None
A special modifier button constant that only returns true if no modifier key is pressed.
@ Shift
A constant for the shift modifier key.
@ Control
A constant for the control modifier key.
@ Alt
A constant for the alt modifier key.
Button
A enumeration of known buttons.
Definition Input.hpp:25
StringView toString(Button button) noexcept
Returns a string representation for the given button
Axis
A enumeration of known axes.
Definition Input.hpp:400
@ MouseVertical
A axis that represents the mouse cursor vertical position.
@ MouseScrollVertical
A axis that represents the mouse scroll wheel vertical position.
@ MouseHorizontal
A axis that represents the mouse cursor horizontal position.
@ MouseScrollHorizontal
A axis that represents the mouse scroll wheel horizontal position.
std::vector< T, ScopedAllocatorAdaptor< StdAllocator< T, RawAllocator > > > Vector
Vector is a sequence container that encapsulates dynamic size arrays.
Definition Vector.hpp:17
Vector< Button > ButtonSet
A type that represents a set of buttons.
Definition Input.hpp:176
std::uint16_t UInt16
Definition DataTypes.hpp:20
ButtonSet & operator+=(ButtonSet &set, const Button button)
Adds a button to a set.
Definition Input.hpp:207
ButtonSet operator-(const ButtonSet &set, const Button button)
Removes a button from a set.
Definition Input.hpp:270
std::uint8_t UInt8
Definition DataTypes.hpp:17
constexpr Byte operator|(const Byte left, const Byte right) noexcept
Definition DataTypes.hpp:57
Axis axis(const StringView &str) noexcept
Returns the Axis constant that is represented by str.
Button button(const StringView &str) noexcept
Returns the Button constant that is represented by str.
CursorMode
A enumeration of supported cursor modes.
Definition Input.hpp:428
@ Hidden
Hides the cursor, but does not capture it.
@ Normal
Displays the cursor normally as per the user operating system preferences.
@ Captured
Captures the cursor.
std::uint32_t UInt32
Definition DataTypes.hpp:23
constexpr Byte operator&(const Byte left, const Byte right) noexcept
Definition DataTypes.hpp:63
BasicString< T, CharTraits, RawAllocator > operator+(const BasicString< T, CharTraits, RawAllocator > &lhs, const T *rhs)
Definition String.hpp:119
constexpr size_t hash(const T &v)
Generates a hash for the provided type.
Definition Hash.hpp:25
decltype(&*std::declval< I >() found)(const I &it, C &container)
Returns a pointer to the value if found, otherwise nullptr.
Definition Iterator.hpp:572