NDEVR
API Documentation
Event.h
1/*--------------------------------------------------------------------------------------------
2Copyright (c) 2019, NDEVR LLC
3tyler.parke@ndevr.org
4 __ __ ____ _____ __ __ _______
5 | \ | | | __ \ | ___|\ \ / / | __ \
6 | \ | | | | \ \ | |___ \ \ / / | |__) |
7 | . \| | | |__/ / | |___ \ V / | _ /
8 | |\ |_|_____/__|_____|___\_/____| | \ \
9 |__| \__________________________________| \__\
10
11Subject to the terms of the Enterprise+ Agreement, NDEVR hereby grants
12Licensee a limited, non-exclusive, non-transferable, royalty-free license
13(without the right to sublicense) to use the API solely for the purpose of
14Licensee's internal development efforts to develop applications for which
15the API was provided.
16
17The above copyright notice and this permission notice shall be included in all
18copies or substantial portions of the Software.
19
20THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
21INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
22PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE
23FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
24OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25DEALINGS IN THE SOFTWARE.
26
27Library: Base
28File: Event
29Included in API: True
30Author(s): Tyler Parke
31 *-----------------------------------------------------------------------------------------**/
32#pragma once
33#include <NDEVR/Vector.h>
34#include <NDEVR/StringStream.h>
35namespace NDEVR
36{
41 struct Event
42 {};
43
48 class KeyEvent : public Event
49 {
50 public:
54 enum KEY
55 {
56 VK_UNSPECIFIED = 0x00
57 , VK_ABNT_C1 = 0xC1
58 , VK_ABNT_C2 = 0xC2
59 , LIB_VK_ADD = 0x6B
60 , LIB_VK_ATTN = 0xF6
61 , LIB_VK_BACK = 0x08
62 , LIB_VK_CANCEL = 0x03
63 , LIB_VK_CLEAR = 0x0C
64 , LIB_VK_CRSEL = 0xF7
65 , LIB_VK_DECIMAL = 0x6E
66 , LIB_VK_DIVIDE = 0x6F
67 , LIB_VK_EREOF = 0xF9
68 , LIB_VK_EQUAL = 61
69 , LIB_VK_SHIFT = 0x10
70
71 , LIB_VK_LEFT = 0x25
72 , LIB_VK_UP = 0x26
73 , LIB_VK_RIGHT = 0x27
74 , LIB_VK_DOWN = 0x28
75 , LIB_VK_DELETE = 0x2E
76
77 , LIB_VK_LCONTROL = 0xA2
78 , LIB_VK_RCONTROL = 0xA3
79 , LIB_VK_META = 0xA4
80 , LIB_VK_MENU = 0x12
81 //, LIB_VK_ESCAPE = 0x1B
82 , LIB_VK_ESCAPE = 256
83 , LIB_VK_EXECUTE = 0x2B
84 , LIB_VK_EXSEL = 0xF8
85 , LIB_VK_ICO_CLEAR = 0xE6
86 , LIB_VK_ICO_HELP = 0xE3
87
88 //Number keys
89 , VK_KEY_0 = 0x30
90 , VK_KEY_1 = 0x31
91 , VK_KEY_2 = 0x32
92 , VK_KEY_3 = 0x33
93 , VK_KEY_4 = 0x34
94 , VK_KEY_5 = 0x35
95 , VK_KEY_6 = 0x36
96 , VK_KEY_7 = 0x37
97 , VK_KEY_8 = 0x38
98 , VK_KEY_9 = 0x39
99 //Letter Keys
100 , VK_KEY_A = 0x41
101 , VK_KEY_B = 0x42
102 , VK_KEY_C = 0x43
103 , VK_KEY_D = 0x44
104 , VK_KEY_E = 0x45
105 , VK_KEY_F = 0x46
106 , VK_KEY_G = 0x47
107 , VK_KEY_H = 0x48
108 , VK_KEY_I = 0x49
109 , VK_KEY_J = 0x4A
110 , VK_KEY_K = 0x4B
111 , VK_KEY_L = 0x4C
112 , VK_KEY_M = 0x4D
113 , VK_KEY_N = 0x4E
114 , VK_KEY_O = 0x4F
115 , VK_KEY_P = 0x50
116 , VK_KEY_Q = 0x51
117 , VK_KEY_R = 0x52
118 , VK_KEY_S = 0x53
119 , VK_KEY_T = 0x54
120 , VK_KEY_U = 0x55
121 , VK_KEY_V = 0x56
122 , VK_KEY_W = 0x57
123 , VK_KEY_X = 0x58
124 , VK_KEY_Y = 0x59
125 , VK_KEY_Z = 0x5A
126 //
127 , LIB_VK_MULTIPLY = 0x6A
128 , LIB_VK_NONAME = 0xFC
129 //NumPad
130 , LIB_VK_NUMPAD0 = 0x60
131 , LIB_VK_NUMPAD1 = 0x61
132 , LIB_VK_NUMPAD2 = 0x62
133 , LIB_VK_NUMPAD3 = 0x63
134 , LIB_VK_NUMPAD4 = 0x64
135 , LIB_VK_NUMPAD5 = 0x65
136 , LIB_VK_NUMPAD6 = 0x66
137 , LIB_VK_NUMPAD7 = 0x67
138 , LIB_VK_NUMPAD8 = 0x68
139 , LIB_VK_NUMPAD9 = 0x69
140 //Function keys
141 , VK_KEY_F1 = 0x70
142 , VK_KEY_F2 = 0x71
143 , VK_KEY_F3 = 0x72
144 , VK_KEY_F4 = 0x73
145 , VK_KEY_F5 = 0x74
146 , VK_KEY_F6 = 0x75
147 , VK_KEY_F7 = 0x76
148 , VK_KEY_F8 = 0x77
149 , VK_KEY_F9 = 0x78
150 , VK_KEY_F10 = 0x79
151 , VK_KEY_F11 = 0x7A
152 , VK_KEY_F12 = 0x7B
153 , VK_KEY_F13 = 0x7C
154 , VK_KEY_F14 = 0x7D
155 , VK_KEY_F15 = 0x7E
156 , VK_KEY_F16 = 0x7F
157 , VK_KEY_F17 = 0x80
158 , VK_KEY_F18 = 0x81
159 , VK_KEY_F19 = 0x82
160 , VK_KEY_F20 = 0x83
161 , VK_KEY_F21 = 0x84
162 , VK_KEY_F22 = 0x85
163 , VK_KEY_F23 = 0x86
164 , VK_KEY_F24 = 0x87
165 //OEM
166 , LIB_VK_OEM_1 = 0xBA
167 , LIB_VK_OEM_102 = 0xE2
168 , LIB_VK_OEM_2 = 0xBF
169 , LIB_VK_OEM_3 = 0xC0
170 , LIB_VK_OEM_4 = 0xDB
171 , LIB_VK_OEM_5 = 0xDC
172 , LIB_VK_OEM_6 = 0xDD
173 , LIB_VK_OEM_7 = 0xDE
174 , LIB_VK_OEM_8 = 0xDF
175 , LIB_VK_OEM_ATTN = 0xF0
176 , LIB_VK_OEM_AUTO = 0xF3
177 , LIB_VK_OEM_AX = 0xE1
178 , LIB_VK_OEM_BACKTAB = 0xF5
179 , LIB_LIB_VK_OEM_CLEAR = 0xFE
180 , LIB_VK_OEM_COMMA = 44
181 , LIB_VK_OEM_COPY = 0xF2
182 , LIB_VK_OEM_CUSEL = 0xEF
183 , LIB_VK_OEM_ENLW = 0xF4
184 , LIB_VK_OEM_FINISH = 0xF1
185 , LIB_VK_OEM_FJ_LOYA = 0x95
186 , LIB_VK_OEM_FJ_MASSHOU = 0x93
187 , LIB_VK_OEM_FJ_ROYA = 0x96
188 , LIB_VK_OEM_FJ_TOUROKU = 0x94
189 , LIB_VK_OEM_JUMP = 0xEA
190 , LIB_VK_OEM_MINUS = 0xBD
191 , LIB_VK_OEM_PA1 = 0xEB
192 , LIB_VK_OEM_PA2 = 0xEC
193 , LIB_VK_OEM_PA3 = 0xED
194 , LIB_VK_OEM_PERIOD = 0xBE
195 , LIB_VK_OEM_PLUS = 0xBB
196 , LIB_VK_OEM_RESET = 0xE9
197 , LIB_VK_OEM_WSCTRL = 0xEE
198 //
199 , LIB_VK_PA1 = 0xFD
200 , LIB_VK_PACKET = 0xE7
201 , LIB_VK_PLAY = 0xFA
202 , LIB_VK_PROCESSKEY = 0xE5
203 , LIB_VK_RETURN = 257
204 , LIB_VK_SELECT = 0x29
205 , LIB_VK_SEPARATOR = 0x6C
206 , LIB_VK_SPACE = 0x20
207 , LIB_VK_SUBTRACT = 0x6D
208 , LIB_VK_TAB = 258
209 , LIB_VK_ZOOM = 0xFB
210 , LIB_VK_NONE = 0xFF
211 , LIB_VK_BACKSLASH = 0x5C
212
213 , LIB_VK_BUTTON_A = 0x0130
214 , LIB_VK_BUTTON_B = 0x0131
215 , LIB_VK_BUTTON_X = 0x0133
216 , LIB_VK_BUTTON_Y = 0x0134
217 , LIB_VK_BUTTON_L1 = 0x0136
218 , LIB_VK_BUTTON_R1 = 0x0137
219 , LIB_VK_BUTTON_SELECT = 0x013A
220 , LIB_VK_BUTTON_START = 0x013B
221 , LIB_VK_BUTTON_MODE = 0x013C
222 , LIB_VK_BUTTON_THUMBL = 0x013D
223 , LIB_VK_BUTTON_THUMBR = 0x013E
224
225 , LIB_VK_VOLUME_UP = 0x0200
226 , LIB_VK_VOLUME_DOWN = 0x0201
227 , LIB_VK_VOLUME_MUTE = 0x0202
228 , LIB_VK_BASS_BOOST = 0x0203
229 , LIB_VK_BASS_UP = 0x0204
230 , LIB_VK_BASS_DOWN = 0x0205
231 , LIB_VK_TREBLE_UP = 0x0206
232 , LIB_VK_TREBLE_DOWN = 0x0207
233
234 , LIB_VK_FORWARD = 0x0301
235 , LIB_VK_STOP = 0x0302
236 , LIB_VK_REFRESH = 0x0303
237
238 , LIB_VK_MEDIA_PLAY = 0x0200
239 , LIB_VK_MEDIA_STOP = 0x0201
240 , LIB_VK_MEDIA_PREVIOUS = 0x0202
241 , LIB_VK_MEDIA_NEXT = 0x0203
242 , LIB_VK_MEDIA_RECORD = 0x0204
243 , LIB_VK_MEDIA_PAUSE = 0x0205
244
245
246 };
247
257
263 {
264 e_shift = 0x01
265 , e_ctrl = 0x02
266 , e_function = 0x04
267 , e_alt = 0x08
268 , e_meta = 0x10
269 };
270 public:
275 : key_type(VK_UNSPECIFIED)
276 , key_modifier(0)
278 {}
279
298 bool operator==(const KeyEvent& other) const
299 {
300 return other.key_type == key_type &&
301 other.event_type == event_type &&
302 other.key_modifier == key_modifier;
303 }
304
308 NDEVR_BASE_API char toChar() const;
309 };
310 class WindowInstance;
315 class MouseEvent : public Event
316 {
317 public:
333
344 public:
349 : window_instance(nullptr)
350 {}
351
356 : window_instance(instance)
357 {}
358
364 {
365 return cast<uint04>(modifier) & key_modifier;
366 }
375 public:
381 bool operator==(const MouseEvent& other) const
382 {
383 return other.event_location == event_location
384 && other.prev_location == prev_location
385 && other.click_type == click_type
386 && other.event_type == event_type
389 && other.key_modifier == key_modifier
390 && other.window_instance;
391 }
392 };
393
394 template class NDEVR_BASE_API StringStream<KeyEvent>;
395}
396
uint01 key_modifier
Bitmask of active KeyModifier flags during this event.
Definition Event.h:291
KeyEvent()
Constructs a default KeyEvent with no key, modifier, or type set.
Definition Event.h:274
KeyModifier
Modifiers describe a second key which affects the behavior of the key being pressed.
Definition Event.h:263
@ e_shift
The Shift key modifier.
Definition Event.h:264
@ e_meta
The Meta (Windows/Command) key modifier.
Definition Event.h:268
@ e_ctrl
The Control key modifier.
Definition Event.h:265
@ e_alt
The Alt key modifier.
Definition Event.h:267
@ e_function
The Function key modifier.
Definition Event.h:266
char toChar() const
Converts this key event to its corresponding ASCII character.
KeyEentType
The action taken with the key The type of the KeyEvent determines how the program will react.
Definition Event.h:252
@ e_key_released
After key pressed, key returns to default 'up' position.
Definition Event.h:255
@ e_key_unspecified
Unspecified key action.
Definition Event.h:253
@ e_key_pressed
Key is pushed to the 'down' position.
Definition Event.h:254
KeyEentType event_type
The type of key action (pressed, released, or unspecified).
Definition Event.h:292
bool operator==(const KeyEvent &other) const
Checks equality between two KeyEvent objects.
Definition Event.h:298
KeyEvent(KEY key_type, uint01 key_modifier=0, KeyEentType event_type=KeyEentType::e_key_unspecified)
Constructs a KeyEvent with the specified key, modifier, and event type.
Definition Event.h:285
KEY key_type
The virtual key code associated with this event.
Definition Event.h:290
WindowInstance * window_instance
The window instance where this event originated.
Definition Event.h:374
MouseEvent()
Constructs a default MouseEvent with no associated window instance.
Definition Event.h:348
Vector< 2, fltp04 > prev_location
The previous mouse position in window coordinates.
Definition Event.h:368
MouseClickType
Identifies which mouse button was involved in the event.
Definition Event.h:338
@ e_left_button
The left mouse button.
Definition Event.h:341
@ none
No mouse button involved.
Definition Event.h:342
@ e_center_button
The center (middle) mouse button.
Definition Event.h:340
@ e_right_button
The right mouse button.
Definition Event.h:339
MouseEvent(WindowInstance *instance)
Constructs a MouseEvent associated with the given window instance.
Definition Event.h:355
uint01 number_of_clicks
The number of consecutive clicks (e.g., 2 for double-click).
Definition Event.h:373
MouseEventType event_type
The type of mouse action that occurred.
Definition Event.h:371
MouseClickType click_type
Which mouse button was involved.
Definition Event.h:372
bool hasModifier(KeyEvent::KeyModifier modifier) const
Checks whether a specific key modifier was active during this mouse event.
Definition Event.h:363
bool operator==(const MouseEvent &other) const
Checks equality between two MouseEvent objects.
Definition Event.h:381
MouseEventType
The type of mouse or touch action that occurred.
Definition Event.h:322
@ e_touch_zoomed
A pinch-to-zoom touch gesture was performed.
Definition Event.h:331
@ e_mouse_scrolled
The mouse scroll wheel was used.
Definition Event.h:330
@ e_mouse_pressed
A mouse button was pressed down.
Definition Event.h:328
@ e_mouse_exited
The mouse cursor exited the window or widget area.
Definition Event.h:326
@ e_mouse_entered
The mouse cursor entered the window or widget area.
Definition Event.h:325
@ e_mouse_clicked
A complete click (press and release) occurred.
Definition Event.h:323
@ e_mouse_moved
The mouse moved without any button pressed.
Definition Event.h:327
@ e_mouse_dragged
The mouse moved while a button was held down.
Definition Event.h:324
@ e_mouse_released
A mouse button was released.
Definition Event.h:329
uint01 key_modifier
Bitmask of active KeyModifier flags during this event.
Definition Event.h:370
Vector< 2, fltp04 > event_location
The current mouse position in window coordinates.
Definition Event.h:367
Vector< 2, fltp04 > distance_scrolled
The scroll distance in X and Y directions.
Definition Event.h:369
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
Definition Vector.hpp:62
Contains core information about a Viewport.
The primary namespace for the NDEVR SDK.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Definition Angle.h:408
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...
Base class for user-driven events which are typically KeyEvent or MouseEvent.
Definition Event.h:42