2
* Copyright 2010 Inalogic Inc.
4
* This program is free software: you can redistribute it and/or modify it
5
* under the terms of the GNU Lesser General Public License version 3, as
6
* published by the Free Software Foundation.
8
* This program is distributed in the hope that it will be useful, but
9
* WITHOUT ANY WARRANTY; without even the implied warranties of
10
* MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
11
* PURPOSE. See the applicable version of the GNU Lesser General Public
12
* License for more details.
14
* You should have received a copy of both the GNU Lesser General Public
15
* License version 3 along with this program. If not, see
16
* <http://www.gnu.org/licenses/>
18
* Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
26
#include "GLResource.h"
27
#include "VirtualKeyCodes.h"
28
//--------------------------------------------------------------key_code_e
29
// Keyboard codes. There's also a restricted set of codes that are most
30
// probably supported on different platforms. Any platform dependent codes
31
// should be converted into these ones. There're only those codes are
32
// defined that cannot be represented as printable ASCII-characters.
33
// All printable ASCII-set can be used in a regilar C/C++ manner:
34
// ' ', 'A', '0' '+' and so on.
35
// Since the class is used for creating very simple demo-applications
36
// we don't need very rich possibilities here, just basic ones.
37
// Actually the numeric key codes are taken from the SDL library, so,
38
// the implementation of the SDL support does not require any mapping.
41
// // ASCII set. Should be supported everywhere
65
// key_kp_period = 266,
66
// key_kp_divide = 267,
67
// key_kp_multiply = 268,
68
// key_kp_minus = 269,
70
// key_kp_enter = 271,
71
// key_kp_equals = 272,
73
// // Arrow-keys and stuff
82
// key_page_down = 281,
84
// // Functional keys. You'd better avoid using
85
// // f11...f15 in your applications if you want
86
// // the applications to be portable
103
// // The possibility of using these keys is
104
// // very restricted. Actually it's guaranteed
105
// // only in win32_api and win32_sdl implementations
106
// key_numlock = 300,
107
// key_capslock = 301,
108
// key_scrollock = 302,
116
const long I_ExposureMask = (1L<<15);
117
const long I_StructureNotifyMask = (1L<<17);
118
const long I_SubstructureNotifyMask = (1L<<19);
120
#define INL_BackSpace INL_VK_BACK
121
#define INL_Tab INL_VK_TAB
122
#define INL_Clear INL_VK_CLEAR
123
#define INL_Enter INL_VK_ENTER
124
#define INL_Shift_L INL_VK_SHIFT
125
#define INL_Control_L INL_VK_CONTROL
126
#define INL_Alt_L INL_VK_MENU
127
#define INL_Pause INL_VK_PAUSE
128
#define INL_Caps_Lock INL_VK_CAPITAL
129
#define INL_Escape INL_VK_ESCAPE
130
#define INL_SpaceBar INL_VK_SPACE
131
#define INL_Page_Up INL_VK_PAGE_UP
132
#define INL_Page_Down INL_VK_PAGE_DOWN
133
#define INL_End INL_VK_END
134
#define INL_Home INL_VK_HOME
135
#define INL_Left INL_VK_LEFT
136
#define INL_Up INL_VK_UP
137
#define INL_Right INL_VK_RIGHT
138
#define INL_Down INL_VK_DOWN
139
#define INL_Print INL_VK_SNAPSHOT
140
#define INL_Insert INL_VK_INSERT
141
#define INL_Delete INL_VK_DELETE
142
#define INL_LWin INL_VK_LWIN
143
#define INL_RWin INL_VK_RWIN
144
#define INL_APPS INL_VK_APPS
145
#define INL_Multiply INL_VK_MULTIPLY
146
#define INL_Add INL_VK_ADD
147
#define INL_Subtract INL_VK_SUBTRACT
148
#define INL_Decimal INL_VK_DECIMAL
149
#define INL_Divide INL_VK_DIVIDE
150
#define INL_Numlock INL_VK_NUMLOCK
151
#define INL_Scroll INL_VK_SCROLL
153
#define INL_KP_ENTER (0xff00 | INL_VK_ENTER)
154
#define INL_EXT_Shift_R (0xff00 | INL_VK_SHIFT)
155
#define INL_EXT_Control_R (0xff00 | INL_VK_CONTROL)
156
#define INL_EXT_Alt_R (0xff00 | INL_VK_MENU)
158
#define INL_KP_PAGE_UP (0xff00 | INL_VK_PAGE_UP)
159
#define INL_KP_PAGE_DOWN (0xff00 | INL_VK_PAGE_DOWN)
160
#define INL_KP_END (0xff00 | INL_VK_END)
161
#define INL_KP_HOME (0xff00 | INL_VK_HOME)
162
#define INL_KP_LEFT (0xff00 | INL_VK_LEFT)
163
#define INL_KP_UP (0xff00 | INL_VK_UP)
164
#define INL_KP_RIGHT (0xff00 | INL_VK_RIGHT)
165
#define INL_KP_DOWN (0xff00 | INL_VK_DOWN)
167
#define INL_KP_INSERT (0xff00 | INL_VK_INSERT)
168
#define INL_KP_DELETE (0xff00 | INL_VK_DELETE)
170
#define INL_F1 INL_VK_F1
171
#define INL_F2 INL_VK_F2
172
#define INL_F3 INL_VK_F3
173
#define INL_F4 INL_VK_F4
174
#define INL_F5 INL_VK_F5
175
#define INL_F6 INL_VK_F6
176
#define INL_F7 INL_VK_F7
177
#define INL_F8 INL_VK_F8
178
#define INL_F9 INL_VK_F9
179
#define INL_F10 INL_VK_F10
180
#define INL_F11 INL_VK_F11
181
#define INL_F12 INL_VK_F12
182
#define INL_F13 INL_VK_F13
183
#define INL_F14 INL_VK_F14
184
#define INL_F15 INL_VK_F15
185
#define INL_F16 INL_VK_F16
186
#define INL_F17 INL_VK_F17
187
#define INL_F18 INL_VK_F18
188
#define INL_F19 INL_VK_F19
189
#define INL_F20 INL_VK_F20
190
#define INL_F21 INL_VK_F21
191
#define INL_F22 INL_VK_F22
192
#define INL_F23 INL_VK_F23
193
#define INL_F24 INL_VK_F24
195
#define INL_LEFT_MOUSE 1
196
#define INL_MIDDLE_MOUSE 2
197
#define INL_RIGHT_MOUSE 3
199
// Key States. Set in e_key_modifiers.
200
#define INL_STATE_SHIFT 0x00010000
201
#define INL_STATE_CAPS_LOCK 0x00020000
202
#define INL_STATE_CTRL 0x00040000
203
#define INL_STATE_ALT 0x00080000
204
#define INL_STATE_NUMLOCK 0x00100000 // most X servers do this?
205
#define INL_STATE_META 0x00400000 // correct for XFree86
206
#define INL_STATE_SCROLLLOCK 0x00800000 // correct for XFree86
208
// These flags describe the mouse button responsible for the mouse event.
209
// They are valid only for the current frame.
210
// Go in e_mouse_state.
211
#define INL_EVENT_BUTTON1_UP 0x00001000
212
#define INL_EVENT_BUTTON2_UP 0x00002000
213
#define INL_EVENT_BUTTON3_UP 0x00004000
215
#define INL_EVENT_BUTTON1_DOWN 0x00010000
216
#define INL_EVENT_BUTTON2_DOWN 0x00020000
217
#define INL_EVENT_BUTTON3_DOWN 0x00040000
219
#define INL_EVENT_BUTTON1 0x00010000
220
#define INL_EVENT_BUTTON2 0x00020000
221
#define INL_EVENT_BUTTON3 0x00040000
223
#define INL_EVENT_MOUSEWHEEL 0x00080000
224
// These flags describe the state of the mouse buttons.
225
// They persist over several frame until the mouse buttons change state.
226
// Go in e_mouse_state.
227
#define INL_STATE_BUTTON1_DOWN 0x01000000
228
#define INL_STATE_BUTTON2_DOWN 0x02000000
229
#define INL_STATE_BUTTON3_DOWN 0x04000000
231
// These flags are set if the event is a double click.
232
// They are valid only for the current frame.
233
// Go in e_mouse_state.
234
#define INL_EVENT_BUTTON1_DBLCLICK 0x10000000
235
#define INL_EVENT_BUTTON2_DBLCLICK 0x20000000
236
#define INL_EVENT_BUTTON3_DBLCLICK 0x40000000
238
#define eLEFT_BUTTON INL_EVENT_BUTTON1
239
#define eMIDDLE_BUTTON INL_EVENT_BUTTON2
240
#define eRIGHT_BUTTON INL_EVENT_BUTTON3
242
#define eLEFT_BUTTON_DOWN INL_STATE_BUTTON1_DOWN
243
#define eMIDDLE_BUTTON_DOWN INL_STATE_BUTTON2_DOWN
244
#define eRIGHT_BUTTON_DOWN INL_STATE_BUTTON3_DOWN
246
#define INL_WIN32_MOUSEWHEEL_DELTA 120 // 120 correspond to one notch of the mouse wheel
248
typedef unsigned char uchar;
249
typedef unsigned long ulong;
251
struct EventToNameStruct {
253
const TCHAR* EventName;
264
INL_SIZE_CONFIGURATION,
265
INL_WINDOW_CONFIGURATION,
266
INL_WINDOW_ENTER_FOCUS,
267
INL_WINDOW_EXIT_FOCUS,
269
INL_WINDOW_MOUSELEAVE,
275
typedef struct IEvent
278
unsigned int ascii_code;
280
bool IsLeftMouseDown;
281
bool IsRightMouseDown;
282
bool IsMiddleMouseDown;
294
unsigned long e_key_modifiers; // key modifiers
295
unsigned short e_key_repeat_count; // number of time a key is repeated;
296
unsigned long e_mouse_state;
299
unsigned long e_event;
303
IsLeftMouseDown = false;
304
IsRightMouseDown = false;
305
IsMiddleMouseDown = false;
308
for(int i = 0; i < INL_MAX_VK; i++)
310
VirtualKeycodeState[i] = 0;
316
e_key_repeat_count = 0;
331
int event_x() const {return e_x;}
332
int event_y() const {return e_y;}
333
int event_x_root() const {return e_x_root;}
334
int event_y_root() const {return e_y_root;}
335
int event_dx() const {return e_dx;}
336
int event_dy() const {return e_dy;}
337
void get_mouse(int &,int &);
338
unsigned long event_key_state() const {return e_key_modifiers;}
339
unsigned long event_mouse_state() const {return e_mouse_state;}
341
//! Return virtual key code of the key that has triggered the last event.
343
Return virtual key code of the key that has triggered the last event.
344
@return the virtual key code.
346
unsigned long event_keysym() const {return e_keysym;}
347
unsigned short event_key_auto_repeat_count() const {return e_key_repeat_count;}
348
bool event_is_key_auto_repeat() const
350
if(e_key_repeat_count > 1)
354
const char* event_text() const { return e_text; }
355
// Because an event is save in e_event instead of calling immediately the handling function,
356
// we must clear the previous event each time before we test for new event in Gfx_OpenGLImpl::get_event.
359
e_event = INL_NO_EVENT;
362
e_key_repeat_count = 0;
366
unsigned long VirtualKeycodeState[INL_MAX_VK];
368
//! Return the state of the Virtual key
370
Return the state of the Virtual key.
371
@param VirtualKey virtual key code.
372
@return 1 if the key is pressed, 0 if the key is released.
374
unsigned long GetVirtualKeyState(unsigned long VirtualKey) const
376
if(VirtualKey >= INL_MAX_VK)
382
return VirtualKeycodeState[VirtualKey];