Divide Framework 0.1
A free and open-source 3D Framework under heavy development
Loading...
Searching...
No Matches
Input.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018 DIVIDE-Studio
3 Copyright (c) 2009 Ionut Cava
4
5 This file is part of DIVIDE Framework.
6
7 Permission is hereby granted, free of charge, to any person obtaining a copy
8 of this software
9 and associated documentation files (the "Software"), to deal in the Software
10 without restriction,
11 including without limitation the rights to use, copy, modify, merge, publish,
12 distribute, sublicense,
13 and/or sell copies of the Software, and to permit persons to whom the
14 Software is furnished to do so,
15 subject to the following conditions:
16
17 The above copyright notice and this permission notice shall be included in
18 all copies or substantial portions of the Software.
19
20 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
21 IMPLIED,
22 INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
23 PARTICULAR PURPOSE AND NONINFRINGEMENT.
24 IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
25 DAMAGES OR OTHER LIABILITY,
26 WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
27 IN CONNECTION WITH THE SOFTWARE
28 OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29
30 */
31
32#pragma once
33#ifndef DVD_INPUT_H_
34#define DVD_INPUT_H_
35
36namespace Divide {
37namespace Input {
39 enum class Joystick : U8 {
40 JOYSTICK_1 = 0,
41 JOYSTICK_2 = 1,
42 JOYSTICK_3 = 2,
43 JOYSTICK_4 = 3,
44 JOYSTICK_5 = 4,
45 JOYSTICK_6 = 5,
46 JOYSTICK_7 = 6,
47 JOYSTICK_8 = 7,
48 JOYSTICK_9 = 8,
49 JOYSTICK_10 = 9,
50 COUNT
51 };
52
53 enum class JoystickElementType : U8 {
54 POV_MOVE = 0,
60 COUNT
61 };
62
63 enum class JoystickPovDirection : U8 {
64 UP = toBit(1),
65 DOWN = toBit(2),
66 LEFT = toBit(3),
67 RIGHT = toBit(4),
68 CENTERED = toBit(5)
69 };
70
71 struct JoystickData {
72 bool _gamePad = false;
73 I32 _deadZone = 8000;
74 I32 _max = 0;
75 union
76 {
81 };
82 };
83
87 U8 _elementIndex = 0u; //item index on device
88 };
89
90 struct MouseAxis {
91 I32 abs = 0;
92 I32 rel = 0;
93 };
94
95 struct MouseState {
97 I32 VWheel = -1;
98 I32 HWheel = -1;
99 };
100
101 enum class MouseButton : U8 {
102 MB_Left = 0,
103 MB_Right,
104 MB_Middle,
110 COUNT
111 };
112
113 enum class KeyModifier : U16 {
114 LSHIFT = toBit(1),
115 RSHIFT = toBit(2),
116 LCTRL = toBit(3),
117 RCTRL = toBit(4),
118 LALT = toBit(5),
119 RALT = toBit(6),
120 LGUI = toBit(7),
121 RGUI = toBit(8),
122 NUM = toBit(9),
123 CAPS = toBit(10),
124 MODE = toBit(11)
125 };
126
127 enum class KeyCode : U8
128 {
129 KC_UNASSIGNED = 0x00,
130 KC_ESCAPE = 0x01,
131 KC_1 = 0x02,
132 KC_2 = 0x03,
133 KC_3 = 0x04,
134 KC_4 = 0x05,
135 KC_5 = 0x06,
136 KC_6 = 0x07,
137 KC_7 = 0x08,
138 KC_8 = 0x09,
139 KC_9 = 0x0A,
140 KC_0 = 0x0B,
141 KC_MINUS = 0x0C, // - on main keyboard
142 KC_EQUALS = 0x0D,
143 KC_BACK = 0x0E, // backspace
144 KC_TAB = 0x0F,
145 KC_Q = 0x10,
146 KC_W = 0x11,
147 KC_E = 0x12,
148 KC_R = 0x13,
149 KC_T = 0x14,
150 KC_Y = 0x15,
151 KC_U = 0x16,
152 KC_I = 0x17,
153 KC_O = 0x18,
154 KC_P = 0x19,
155 KC_LBRACKET = 0x1A,
156 KC_RBRACKET = 0x1B,
157 KC_RETURN = 0x1C, // Enter on main keyboard
158 KC_LCONTROL = 0x1D,
159 KC_A = 0x1E,
160 KC_S = 0x1F,
161 KC_D = 0x20,
162 KC_F = 0x21,
163 KC_G = 0x22,
164 KC_H = 0x23,
165 KC_J = 0x24,
166 KC_K = 0x25,
167 KC_L = 0x26,
168 KC_SEMICOLON = 0x27,
169 KC_APOSTROPHE = 0x28,
170 KC_GRAVE = 0x29, // accent
171 KC_LSHIFT = 0x2A,
172 KC_BACKSLASH = 0x2B,
173 KC_Z = 0x2C,
174 KC_X = 0x2D,
175 KC_C = 0x2E,
176 KC_V = 0x2F,
177 KC_B = 0x30,
178 KC_N = 0x31,
179 KC_M = 0x32,
180 KC_COMMA = 0x33,
181 KC_PERIOD = 0x34, // . on main keyboard
182 KC_SLASH = 0x35, // / on main keyboard
183 KC_RSHIFT = 0x36,
184 KC_MULTIPLY = 0x37, // * on numeric keypad
185 KC_LMENU = 0x38, // left Alt
186 KC_SPACE = 0x39,
187 KC_CAPITAL = 0x3A,
188 KC_F1 = 0x3B,
189 KC_F2 = 0x3C,
190 KC_F3 = 0x3D,
191 KC_F4 = 0x3E,
192 KC_F5 = 0x3F,
193 KC_F6 = 0x40,
194 KC_F7 = 0x41,
195 KC_F8 = 0x42,
196 KC_F9 = 0x43,
197 KC_F10 = 0x44,
198 KC_NUMLOCK = 0x45,
199 KC_SCROLL = 0x46, // Scroll Lock
200 KC_NUMPAD7 = 0x47,
201 KC_NUMPAD8 = 0x48,
202 KC_NUMPAD9 = 0x49,
203 KC_SUBTRACT = 0x4A, // - on numeric keypad
204 KC_NUMPAD4 = 0x4B,
205 KC_NUMPAD5 = 0x4C,
206 KC_NUMPAD6 = 0x4D,
207 KC_ADD = 0x4E, // + on numeric keypad
208 KC_NUMPAD1 = 0x4F,
209 KC_NUMPAD2 = 0x50,
210 KC_NUMPAD3 = 0x51,
211 KC_NUMPAD0 = 0x52,
212 KC_DECIMAL = 0x53, // . on numeric keypad
213 KC_OEM_102 = 0x56, // < > | on UK/Germany keyboards
214 KC_F11 = 0x57,
215 KC_F12 = 0x58,
216 KC_F13 = 0x64, // (NEC PC98)
217 KC_F14 = 0x65, // (NEC PC98)
218 KC_F15 = 0x66, // (NEC PC98)
219 KC_KANA = 0x70, // (Japanese keyboard)
220 KC_ABNT_C1 = 0x73, // / ? on Portugese (Brazilian) keyboards
221 KC_CONVERT = 0x79, // (Japanese keyboard)
222 KC_NOCONVERT = 0x7B, // (Japanese keyboard)
223 KC_YEN = 0x7D, // (Japanese keyboard)
224 KC_ABNT_C2 = 0x7E, // Numpad . on Portugese (Brazilian) keyboards
225 KC_NUMPADEQUALS = 0x8D, // = on numeric keypad (NEC PC98)
226 KC_PREVTRACK = 0x90, // Previous Track (KC_CIRCUMFLEX on Japanese keyboard)
227 KC_AT = 0x91, // (NEC PC98)
228 KC_COLON = 0x92, // (NEC PC98)
229 KC_UNDERLINE = 0x93, // (NEC PC98)
230 KC_KANJI = 0x94, // (Japanese keyboard)
231 KC_STOP = 0x95, // (NEC PC98)
232 KC_AX = 0x96, // (Japan AX)
233 KC_UNLABELED = 0x97, // (J3100)
234 KC_NEXTTRACK = 0x99, // Next Track
235 KC_NUMPADENTER = 0x9C, // Enter on numeric keypad
236 KC_RCONTROL = 0x9D,
237 KC_MUTE = 0xA0, // Mute
238 KC_CALCULATOR = 0xA1, // Calculator
239 KC_PLAYPAUSE = 0xA2, // Play / Pause
240 KC_MEDIASTOP = 0xA4, // Media Stop
241 KC_TWOSUPERIOR = 0xAA, // ² on French AZERTY keyboard (same place as ~ ` on QWERTY)
242 KC_VOLUMEDOWN = 0xAE, // Volume -
243 KC_VOLUMEUP = 0xB0, // Volume +
244 KC_WEBHOME = 0xB2, // Web home
245 KC_NUMPADCOMMA = 0xB3, // , on numeric keypad (NEC PC98)
246 KC_DIVIDE = 0xB5, // / on numeric keypad
247 KC_SYSRQ = 0xB7,
248 KC_RMENU = 0xB8, // right Alt
249 KC_PAUSE = 0xC5, // Pause
250 KC_HOME = 0xC7, // Home on arrow keypad
251 KC_UP = 0xC8, // UpArrow on arrow keypad
252 KC_PGUP = 0xC9, // PgUp on arrow keypad
253 KC_LEFT = 0xCB, // LeftArrow on arrow keypad
254 KC_RIGHT = 0xCD, // RightArrow on arrow keypad
255 KC_END = 0xCF, // End on arrow keypad
256 KC_DOWN = 0xD0, // DownArrow on arrow keypad
257 KC_PGDOWN = 0xD1, // PgDn on arrow keypad
258 KC_INSERT = 0xD2, // Insert on arrow keypad
259 KC_DELETE = 0xD3, // Delete on arrow keypad
260 KC_LWIN = 0xDB, // Left Windows key
261 KC_RWIN = 0xDC, // Right Windows key
262 KC_APPS = 0xDD, // AppMenu key
263 KC_POWER = 0xDE, // System Power
264 KC_SLEEP = 0xDF, // System Sleep
265 KC_WAKE = 0xE3, // System Wake
266 KC_WEBSEARCH = 0xE5, // Web Search
267 KC_WEBFAVORITES = 0xE6, // Web Favorites
268 KC_WEBREFRESH = 0xE7, // Web Refresh
269 KC_WEBSTOP = 0xE8, // Web Stop
270 KC_WEBFORWARD = 0xE9, // Web Forward
271 KC_WEBBACK = 0xEA, // Web Back
272 KC_MYCOMPUTER = 0xEB, // My Computer
273 KC_MAIL = 0xEC, // Mail
274 KC_MEDIASELECT = 0xED, // Media Select
275 KC_PRINTSCREEN = 0xEE, // Print Screen
276 };
277
278 enum class InputState : U8 {
279 PRESSED = 0,
280 RELEASED,
281 COUNT
282 };
283
284 SDL_Keycode SDLKeyCodeFromKey(KeyCode code) noexcept;
285 KeyCode KeyCodeFromSDLKey(SDL_Keycode code) noexcept;
286
287 KeyCode KeyCodeByName(const char* keyName) noexcept;
288 MouseButton mouseButtonByName(const string& buttonName);
289 JoystickElement joystickElementByName(const string& elementName);
290
291 InputState GetKeyState(U8 deviceIndex, KeyCode key) noexcept;
292 InputState GetMouseButtonState(U8 deviceIndex, MouseButton button) noexcept;
293 InputState GetJoystickElementState(Joystick deviceIndex, JoystickElement element) noexcept;
294
295 }; //namespace Input
296}; //namespace Divide
297#endif //DVD_INPUT_H_
SDL_Keycode SDLKeyCodeFromKey(KeyCode code) noexcept
Definition: Input.cpp:126
JoystickElementType
Definition: Input.h:53
InputState GetJoystickElementState(Joystick deviceIndex, JoystickElement element) noexcept
Definition: Input.cpp:188
Joystick
Points to the position of said joystick in the vector.
Definition: Input.h:39
MouseButton mouseButtonByName(const string &buttonName)
JoystickElement joystickElementByName(const string &elementName)
InputState GetKeyState(U8 deviceIndex, KeyCode key) noexcept
Definition: Input.cpp:150
KeyCode KeyCodeFromSDLKey(SDL_Keycode code) noexcept
Definition: Input.cpp:136
InputState GetMouseButtonState(U8 deviceIndex, MouseButton button) noexcept
Definition: Input.cpp:157
JoystickPovDirection
Definition: Input.h:63
KeyCode KeyCodeByName(const char *keyName) noexcept
Definition: Input.cpp:146
Handle console commands that start with a forward slash.
Definition: AIProcessor.cpp:7
int32_t I32
uint8_t U8
int16_t I16
uint16_t U16
uint32_t U32
constexpr T toBit(const T X)
Converts an arbitrary positive integer value to a bitwise value used for masks.
JoystickElementType _type
Definition: Input.h:85