Input.h
Go to the documentation of this file.
1 #ifndef B_INPUT_H
2 #define B_INPUT_H
3 
4 #include "OSdetect.h"
5 #include <memory>
6 #include "Renderer_GL.h"
7 #include "Logger.h"
8 #include "View.h"
9 #include "Touch.h"
10 
11 #ifdef __OBJC__
12 #import <CoreMotion/CoreMotion.h>
13 #endif
14 
15 #ifndef __OBJC__
16 typedef int CMMotionManager;
17 #endif
18 
19 namespace bRenderer
20 {
21  const GLint INPUT_RELEASE = 0; // The key or mouse button was pressed
22  const GLint INPUT_PRESS = 1; // The key or mouse button was released
23  const GLint INPUT_REPEAT = 2; // The key was held down until it repeated
24  const GLint INPUT_UNDEFINED = -1; // Will be returned if the OS doesn't support the input method
25 
26  const GLint LEFT_MOUSE_BUTTON = 1;
27  const GLint RIGHT_MOUSE_BUTTON = 2;
28  const GLint MIDDLE_MOUSE_BUTTON = 3;
29 
30  const GLint KEY_SPACE = 32;
31  const GLint KEY_APOSTROPHE = 39; // '
32  const GLint KEY_COMMA = 44; // ,
33  const GLint KEY_MINUS = 45; // -
34  const GLint KEY_PERIOD = 46; // .
35  const GLint KEY_SLASH = 47; // /
36  const GLint KEY_0 = 48;
37  const GLint KEY_1 = 49;
38  const GLint KEY_2 = 50;
39  const GLint KEY_3 = 51;
40  const GLint KEY_4 = 52;
41  const GLint KEY_5 = 53;
42  const GLint KEY_6 = 54;
43  const GLint KEY_7 = 55;
44  const GLint KEY_8 = 56;
45  const GLint KEY_9 = 57;
46  const GLint KEY_SEMICOLON = 59;
47  const GLint KEY_EQUAL = 61;
48  const GLint KEY_A = 65;
49  const GLint KEY_B = 66;
50  const GLint KEY_C = 67;
51  const GLint KEY_D = 68;
52  const GLint KEY_E = 69;
53  const GLint KEY_F = 70;
54  const GLint KEY_G = 71;
55  const GLint KEY_H = 72;
56  const GLint KEY_I = 73;
57  const GLint KEY_J = 74;
58  const GLint KEY_K = 75;
59  const GLint KEY_L = 76;
60  const GLint KEY_M = 77;
61  const GLint KEY_N = 78;
62  const GLint KEY_O = 79;
63  const GLint KEY_P = 80;
64  const GLint KEY_Q = 81;
65  const GLint KEY_R = 82;
66  const GLint KEY_S = 83;
67  const GLint KEY_T = 84;
68  const GLint KEY_U = 85;
69  const GLint KEY_V = 86;
70  const GLint KEY_W = 87;
71  const GLint KEY_X = 88;
72  const GLint KEY_Y = 89;
73  const GLint KEY_Z = 90;
74  const GLint KEY_LEFT_BRACKET = 91; // [
75  const GLint KEY_BACKSLASH = 92; // \
76  const GLint KEY_RIGHT_BRACKET = 93; // ]
77  const GLint KEY_GRAVE_ACCENT = 96; // `
78  const GLint KEY_WORLD_1 = 161; // non-US #1
79  const GLint KEY_WORLD_2 = 162; // non-US #2
80  const GLint KEY_ESCAPE = 256;
81  const GLint KEY_ENTER = 257;
82  const GLint KEY_TAB = 258;
83  const GLint KEY_BACKSPACE = 259;
84  const GLint KEY_INSERT = 260;
85  const GLint KEY_DELETE = 261;
86  const GLint KEY_RIGHT = 262;
87  const GLint KEY_LEFT = 263;
88  const GLint KEY_DOWN = 264;
89  const GLint KEY_UP = 265;
90  const GLint KEY_PAGE_UP = 266;
91  const GLint KEY_PAGE_DOWN = 267;
92  const GLint KEY_HOME = 268;
93  const GLint KEY_END = 269;
94  const GLint KEY_CAPS_LOCK = 280;
95  const GLint KEY_SCROLL_LOCK = 281;
96  const GLint KEY_NUM_LOCK = 282;
97  const GLint KEY_PRINT_SCREEN = 283;
98  const GLint KEY_PAUSE = 284;
99  const GLint KEY_F1 = 290;
100  const GLint KEY_F2 = 291;
101  const GLint KEY_F3 = 292;
102  const GLint KEY_F4 = 293;
103  const GLint KEY_F5 = 294;
104  const GLint KEY_F6 = 295;
105  const GLint KEY_F7 = 296;
106  const GLint KEY_F8 = 297;
107  const GLint KEY_F9 = 298;
108  const GLint KEY_F10 = 299;
109  const GLint KEY_F11 = 300;
110  const GLint KEY_F12 = 301;
111  const GLint KEY_F13 = 302;
112  const GLint KEY_F14 = 303;
113  const GLint KEY_F15 = 304;
114  const GLint KEY_F16 = 305;
115  const GLint KEY_F17 = 306;
116  const GLint KEY_F18 = 307;
117  const GLint KEY_F19 = 308;
118  const GLint KEY_F20 = 309;
119  const GLint KEY_F21 = 310;
120  const GLint KEY_F22 = 311;
121  const GLint KEY_F23 = 312;
122  const GLint KEY_F24 = 313;
123  const GLint KEY_F25 = 314;
124  const GLint KEY_KP_0 = 320;
125  const GLint KEY_KP_1 = 321;
126  const GLint KEY_KP_2 = 322;
127  const GLint KEY_KP_3 = 323;
128  const GLint KEY_KP_4 = 324;
129  const GLint KEY_KP_5 = 325;
130  const GLint KEY_KP_6 = 326;
131  const GLint KEY_KP_7 = 327;
132  const GLint KEY_KP_8 = 328;
133  const GLint KEY_KP_9 = 329;
134  const GLint KEY_KP_DECIMAL = 330;
135  const GLint KEY_KP_DIVIDE = 331;
136  const GLint KEY_KP_MULTIPLY = 332;
137  const GLint KEY_KP_SUBTRACT = 333;
138  const GLint KEY_KP_ADD = 334;
139  const GLint KEY_KP_ENTER = 335;
140  const GLint KEY_KP_EQUAL = 336;
141  const GLint KEY_LEFT_SHIFT = 340;
142  const GLint KEY_LEFT_CONTROL = 341;
143  const GLint KEY_LEFT_ALT = 342;
144  const GLint KEY_LEFT_SUPER = 343;
145  const GLint KEY_RIGHT_SHIFT = 344;
146  const GLint KEY_RIGHT_CONTROL = 345;
147  const GLint KEY_RIGHT_ALT = 346;
148  const GLint KEY_RIGHT_SUPER = 347;
149 
150 } // namespace bRenderer
151 
155 class Input
156 {
157 public:
158 
159  /* Functions */
160 
163  Input();
164 
168  Input(ViewPtr view);
169 
172  virtual ~Input();
173 
177  void setView(ViewPtr view) { _view = view; }
178 
182  GLint getKeyState(GLint key);
183 
187  GLint getMouseButtonState(GLint button);
188 
191  double getCursorPositionX();
192 
195  double getCursorPositionY();
196 
202  void getCursorPosition(double* x, double* y, bool* deviceHasCursor = nullptr);
203 
207  double getGyroscopePitch(bool* deviceHasGyroscope = nullptr);
208 
212  double getGyroscopeYaw(bool* deviceHasGyroscope = nullptr);
213 
217  double getGyroscopeRoll(bool* deviceHasGyroscope = nullptr);
218 
222 
225  bool singleTapRecognized();
226 
229  bool doubleTapRecognized();
230 
234 
238 
241  void setCursorEnabled();
242 
246  void setCursorEnabled(bool enabled);
247 
250  void setCursorDisabled();
251 
256  void setCursorPosition(double x, double y);
257 
260  static bool isTouchDevice();
261 
262 private:
263 
264  /* Variables */
265 
266  ViewPtr _view = nullptr;
267  CMMotionManager *_motionManager = nullptr;
268 };
269 
270 typedef std::shared_ptr< Input > InputPtr;
271 
272 #endif /* defined(B_INPUT_H) */
Input()
Constructor.
const GLint KEY_3
Definition: Input.h:39
const GLint KEY_INSERT
Definition: Input.h:84
const GLint KEY_R
Definition: Input.h:65
const GLint KEY_KP_ENTER
Definition: Input.h:139
const GLint KEY_F10
Definition: Input.h:108
GLint getMouseButtonState(GLint button)
Gets the current state of a specified mouse button.
const GLint KEY_F11
Definition: Input.h:109
const GLint KEY_O
Definition: Input.h:62
TouchMap getTouches()
Returns a map containing all current touches.
const GLint KEY_F20
Definition: Input.h:118
const GLint KEY_PRINT_SCREEN
Definition: Input.h:97
Touch getLastSingleTapLocation()
Returns the last single tap location as a touch object.
void getCursorPosition(double *x, double *y, bool *deviceHasCursor=nullptr)
Returns the current position of the cursor.
const GLint KEY_KP_6
Definition: Input.h:130
const GLint KEY_X
Definition: Input.h:71
const GLint KEY_L
Definition: Input.h:59
const GLint KEY_S
Definition: Input.h:66
Definition: Configuration.h:8
const GLint KEY_F18
Definition: Input.h:116
virtual ~Input()
Virtual destructor.
void setCursorDisabled()
Sets the cursor disabled.
const GLint KEY_DELETE
Definition: Input.h:85
const GLint KEY_LEFT_BRACKET
Definition: Input.h:74
std::shared_ptr< Input > InputPtr
Definition: Input.h:270
const GLint KEY_T
Definition: Input.h:67
void setCursorEnabled()
Sets the cursor enabled.
const GLint KEY_W
Definition: Input.h:70
void setView(ViewPtr view)
Set the view to get inputs from.
Definition: Input.h:177
Touch getLastDoubleTapLocation()
Returns the last double tap location as a touch object.
const GLint KEY_KP_2
Definition: Input.h:126
const GLint KEY_WORLD_1
Definition: Input.h:78
static bool isTouchDevice()
Returns true on mobile devices like the iPad.
double getGyroscopePitch(bool *deviceHasGyroscope=nullptr)
Returns the pitch measured by the gyroscope of the mobile device.
const GLint KEY_F14
Definition: Input.h:112
const GLint KEY_B
Definition: Input.h:49
const GLint KEY_LEFT
Definition: Input.h:87
double getCursorPositionY()
Returns the current y-position of the cursor.
const GLint KEY_5
Definition: Input.h:41
const GLint KEY_RIGHT_BRACKET
Definition: Input.h:76
int CMMotionManager
Definition: Input.h:16
const GLint LEFT_MOUSE_BUTTON
Definition: Input.h:26
const GLint KEY_F25
Definition: Input.h:123
const GLint KEY_KP_ADD
Definition: Input.h:138
const GLint KEY_DOWN
Definition: Input.h:88
const GLint KEY_KP_7
Definition: Input.h:131
void setCursorPosition(double x, double y)
Sets the position of the cursor.
const GLint KEY_U
Definition: Input.h:68
const GLint KEY_RIGHT_CONTROL
Definition: Input.h:146
const GLint KEY_LEFT_SHIFT
Definition: Input.h:141
const GLint RIGHT_MOUSE_BUTTON
Definition: Input.h:27
const GLint KEY_CAPS_LOCK
Definition: Input.h:94
const GLint KEY_6
Definition: Input.h:42
double getGyroscopeRoll(bool *deviceHasGyroscope=nullptr)
Returns the roll measured by the gyroscope of the mobile device.
const GLint KEY_LEFT_SUPER
Definition: Input.h:144
const GLint KEY_F16
Definition: Input.h:114
const GLint KEY_NUM_LOCK
Definition: Input.h:96
const GLint KEY_UP
Definition: Input.h:89
const GLint KEY_F7
Definition: Input.h:105
const GLint KEY_LEFT_ALT
Definition: Input.h:143
const GLint KEY_8
Definition: Input.h:44
const GLint KEY_KP_4
Definition: Input.h:128
std::shared_ptr< View > ViewPtr
Definition: View.h:225
const GLint KEY_WORLD_2
Definition: Input.h:79
const GLint KEY_P
Definition: Input.h:63
const GLint KEY_0
Definition: Input.h:36
const GLint KEY_RIGHT_ALT
Definition: Input.h:147
An object that holds the characteristics of a touch on a touch screen.
Definition: Touch.h:9
const GLint KEY_F23
Definition: Input.h:121
The input class is closely coupled to a view to retrieve actions taken by the user directly from the ...
Definition: Input.h:155
const GLint KEY_F13
Definition: Input.h:111
const GLint KEY_D
Definition: Input.h:51
const GLint KEY_F
Definition: Input.h:53
const GLint KEY_2
Definition: Input.h:38
const GLint KEY_KP_9
Definition: Input.h:133
const GLint KEY_SLASH
Definition: Input.h:35
GLint getKeyState(GLint key)
Gets the current state of a specified key.
const GLint KEY_COMMA
Definition: Input.h:32
const GLint KEY_BACKSLASH
Definition: Input.h:75
const GLint KEY_F24
Definition: Input.h:122
const GLint KEY_N
Definition: Input.h:61
const GLint KEY_9
Definition: Input.h:45
const GLint KEY_GRAVE_ACCENT
Definition: Input.h:77
const GLint KEY_C
Definition: Input.h:50
const GLint KEY_END
Definition: Input.h:93
std::map< int, Touch > TouchMap
Definition: Touch.h:20
const GLint KEY_SEMICOLON
Definition: Input.h:46
const GLint KEY_BACKSPACE
Definition: Input.h:83
const GLint KEY_4
Definition: Input.h:40
const GLint KEY_KP_SUBTRACT
Definition: Input.h:137
const GLint KEY_F19
Definition: Input.h:117
const GLint KEY_F15
Definition: Input.h:113
const GLint KEY_J
Definition: Input.h:57
const GLint KEY_KP_1
Definition: Input.h:125
const GLint KEY_F4
Definition: Input.h:102
const GLint KEY_SCROLL_LOCK
Definition: Input.h:95
const GLint KEY_F21
Definition: Input.h:119
const GLint KEY_F8
Definition: Input.h:106
const GLint KEY_HOME
Definition: Input.h:92
const GLint KEY_K
Definition: Input.h:58
const GLint KEY_G
Definition: Input.h:54
const GLint KEY_E
Definition: Input.h:52
const GLint KEY_I
Definition: Input.h:56
const GLint KEY_H
Definition: Input.h:55
const GLint KEY_KP_DECIMAL
Definition: Input.h:134
const GLint MIDDLE_MOUSE_BUTTON
Definition: Input.h:28
bool singleTapRecognized()
Returns true if a single tap was recognized since last calling the function.
const GLint KEY_KP_EQUAL
Definition: Input.h:140
const GLint KEY_KP_8
Definition: Input.h:132
const GLint KEY_ESCAPE
Definition: Input.h:80
double getGyroscopeYaw(bool *deviceHasGyroscope=nullptr)
Returns the yaw measured by the gyroscope of the mobile device.
const GLint KEY_KP_5
Definition: Input.h:129
const GLint KEY_Q
Definition: Input.h:64
const GLint KEY_F3
Definition: Input.h:101
const GLint KEY_M
Definition: Input.h:60
const GLint KEY_PERIOD
Definition: Input.h:34
const GLint KEY_F22
Definition: Input.h:120
const GLint KEY_RIGHT_SHIFT
Definition: Input.h:145
const GLint KEY_SPACE
Definition: Input.h:30
const GLint KEY_F5
Definition: Input.h:103
const GLint KEY_7
Definition: Input.h:43
const GLint KEY_TAB
Definition: Input.h:82
const GLint KEY_ENTER
Definition: Input.h:81
const GLint KEY_F1
Definition: Input.h:99
const GLint KEY_MINUS
Definition: Input.h:33
const GLint KEY_Z
Definition: Input.h:73
const GLint KEY_PAGE_DOWN
Definition: Input.h:91
const GLint KEY_F9
Definition: Input.h:107
const GLint KEY_F6
Definition: Input.h:104
const GLint KEY_KP_0
Definition: Input.h:124
const GLint KEY_KP_3
Definition: Input.h:127
const GLint KEY_1
Definition: Input.h:37
bool doubleTapRecognized()
Returns true if a single tap was recognized since last calling the function.
const GLint KEY_Y
Definition: Input.h:72
const GLint KEY_F17
Definition: Input.h:115
const GLint KEY_PAGE_UP
Definition: Input.h:90
const GLint KEY_KP_MULTIPLY
Definition: Input.h:136
const GLint KEY_F2
Definition: Input.h:100
const GLint KEY_F12
Definition: Input.h:110
const GLint KEY_PAUSE
Definition: Input.h:98
const GLint INPUT_UNDEFINED
Definition: Input.h:24
const GLint KEY_A
Definition: Input.h:48
const GLint KEY_APOSTROPHE
Definition: Input.h:31
const GLint KEY_KP_DIVIDE
Definition: Input.h:135
const GLint INPUT_PRESS
Definition: Input.h:22
const GLint KEY_V
Definition: Input.h:69
const GLint KEY_LEFT_CONTROL
Definition: Input.h:142
const GLint KEY_RIGHT_SUPER
Definition: Input.h:148
const GLint KEY_RIGHT
Definition: Input.h:86
double getCursorPositionX()
Returns the current x-position of the cursor.
const GLint INPUT_RELEASE
Definition: Input.h:21
const GLint INPUT_REPEAT
Definition: Input.h:23
const GLint KEY_EQUAL
Definition: Input.h:47