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>
23
#ifndef GFXEVENTSX11_H
24
#define GFXEVENTSX11_H
26
#include "GLResource.h"
27
#include "VirtualKeyCodesX11.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,
117
const long I_ExposureMask = (1L << 15);
118
const long I_StructureNotifyMask = (1L << 17);
119
const long I_SubstructureNotifyMask = (1L << 19);
121
#define NUX_BackSpace NUX_VK_BACK
122
#define NUX_Tab NUX_VK_TAB
123
#define NUX_Clear NUX_VK_CLEAR
124
#define NUX_Enter NUX_VK_ENTER
125
#define NUX_Shift_L NUX_VK_SHIFT
126
#define NUX_Control_L NUX_VK_CONTROL
127
#define NUX_Alt_L NUX_VK_MENU
128
#define NUX_Pause NUX_VK_PAUSE
129
#define NUX_Caps_Lock NUX_VK_CAPITAL
130
#define NUX_Escape NUX_VK_ESCAPE
131
#define NUX_SpaceBar NUX_VK_SPACE
132
#define NUX_Page_Up NUX_VK_PAGE_UP
133
#define NUX_Page_Down NUX_VK_PAGE_DOWN
134
#define NUX_End NUX_VK_END
135
#define NUX_Home NUX_VK_HOME
136
#define NUX_Left NUX_VK_LEFT
137
#define NUX_Up NUX_VK_UP
138
#define NUX_Right NUX_VK_RIGHT
139
#define NUX_Down NUX_VK_DOWN
140
#define NUX_Print NUX_VK_SNAPSHOT
141
#define NUX_Insert NUX_VK_INSERT
142
#define NUX_Delete NUX_VK_DELETE
143
#define NUX_LWin NUX_VK_LWIN
144
#define NUX_RWin NUX_VK_RWIN
145
#define NUX_APPS NUX_VK_APPS
146
#define NUX_Multiply NUX_VK_MULTIPLY
147
#define NUX_Add NUX_VK_ADD
148
#define NUX_Subtract NUX_VK_SUBTRACT
149
#define NUX_Decimal NUX_VK_DECIMAL
150
#define NUX_Divide NUX_VK_DIVIDE
151
#define NUX_Numlock NUX_VK_NUMLOCK
152
#define NUX_Scroll NUX_VK_SCROLL
154
#define NUX_KP_ENTER (0xff00 | NUX_VK_ENTER)
155
#define NUX_EXT_Shift_R (0xff00 | NUX_VK_SHIFT)
156
#define NUX_EXT_Control_R (0xff00 | NUX_VK_CONTROL)
157
#define NUX_EXT_Alt_R (0xff00 | NUX_VK_MENU)
159
#define NUX_KP_PAGE_UP (0xff00 | NUX_VK_PAGE_UP)
160
#define NUX_KP_PAGE_DOWN (0xff00 | NUX_VK_PAGE_DOWN)
161
#define NUX_KP_END (0xff00 | NUX_VK_END)
162
#define NUX_KP_HOME (0xff00 | NUX_VK_HOME)
163
#define NUX_KP_LEFT (0xff00 | NUX_VK_LEFT)
164
#define NUX_KP_UP (0xff00 | NUX_VK_UP)
165
#define NUX_KP_RIGHT (0xff00 | NUX_VK_RIGHT)
166
#define NUX_KP_DOWN (0xff00 | NUX_VK_DOWN)
168
#define NUX_KP_INSERT (0xff00 | NUX_VK_INSERT)
169
#define NUX_KP_DELETE (0xff00 | NUX_VK_DELETE)
171
#define NUX_F1 NUX_VK_F1
172
#define NUX_F2 NUX_VK_F2
173
#define NUX_F3 NUX_VK_F3
174
#define NUX_F4 NUX_VK_F4
175
#define NUX_F5 NUX_VK_F5
176
#define NUX_F6 NUX_VK_F6
177
#define NUX_F7 NUX_VK_F7
178
#define NUX_F8 NUX_VK_F8
179
#define NUX_F9 NUX_VK_F9
180
#define NUX_F10 NUX_VK_F10
181
#define NUX_F11 NUX_VK_F11
182
#define NUX_F12 NUX_VK_F12
183
#define NUX_F13 NUX_VK_F13
184
#define NUX_F14 NUX_VK_F14
185
#define NUX_F15 NUX_VK_F15
186
#define NUX_F16 NUX_VK_F16
187
#define NUX_F17 NUX_VK_F17
188
#define NUX_F18 NUX_VK_F18
189
#define NUX_F19 NUX_VK_F19
190
#define NUX_F20 NUX_VK_F20
191
#define NUX_F21 NUX_VK_F21
192
#define NUX_F22 NUX_VK_F22
193
#define NUX_F23 NUX_VK_F23
194
#define NUX_F24 NUX_VK_F24
196
#define NUX_LEFT_MOUSE 1
197
#define NUX_MIDDLE_MOUSE 2
198
#define NUX_RIGHT_MOUSE 3
200
// Key States. Set in e_key_modifiers.
201
#define NUX_STATE_SHIFT 0x00010000
202
#define NUX_STATE_CAPS_LOCK 0x00020000
203
#define NUX_STATE_CTRL 0x00040000
204
#define NUX_STATE_ALT 0x00080000
205
#define NUX_STATE_NUMLOCK 0x00100000 // most X servers do this?
206
#define NUX_STATE_META 0x00400000 // correct for XFree86
207
#define NUX_STATE_SCROLLLOCK 0x00800000 // correct for XFree86
209
// These flags describe the mouse button responsible for the mouse event.
210
// They are valid only for the current frame.
211
// Go in e_mouse_state.
212
#define NUX_EVENT_BUTTON1_UP 0x00001000
213
#define NUX_EVENT_BUTTON2_UP 0x00002000
214
#define NUX_EVENT_BUTTON3_UP 0x00004000
216
#define NUX_EVENT_BUTTON1_DOWN 0x00010000
217
#define NUX_EVENT_BUTTON2_DOWN 0x00020000
218
#define NUX_EVENT_BUTTON3_DOWN 0x00040000
220
#define NUX_EVENT_BUTTON1 0x00010000
221
#define NUX_EVENT_BUTTON2 0x00020000
222
#define NUX_EVENT_BUTTON3 0x00040000
224
#define NUX_EVENT_MOUSEWHEEL 0x00080000
225
// These flags describe the state of the mouse buttons.
226
// They persist over several frame until the mouse buttons change state.
227
// Go in e_mouse_state.
228
#define NUX_STATE_BUTTON1_DOWN 0x01000000
229
#define NUX_STATE_BUTTON2_DOWN 0x02000000
230
#define NUX_STATE_BUTTON3_DOWN 0x04000000
232
// These flags are set if the event is a double click.
233
// They are valid only for the current frame.
234
// Go in e_mouse_state.
235
#define NUX_EVENT_BUTTON1_DBLCLICK 0x10000000
236
#define NUX_EVENT_BUTTON2_DBLCLICK 0x20000000
237
#define NUX_EVENT_BUTTON3_DBLCLICK 0x40000000
239
#define eLEFT_BUTTON NUX_EVENT_BUTTON1
240
#define eMIDDLE_BUTTON NUX_EVENT_BUTTON2
241
#define eRIGHT_BUTTON NUX_EVENT_BUTTON3
243
#define eLEFT_BUTTON_DOWN NUX_STATE_BUTTON1_DOWN
244
#define eMIDDLE_BUTTON_DOWN NUX_STATE_BUTTON2_DOWN
245
#define eRIGHT_BUTTON_DOWN NUX_STATE_BUTTON3_DOWN
247
#define NUX_WIN32_MOUSEWHEEL_DELTA 120 // 120 correspond to one notch of the mouse wheel
249
typedef unsigned char uchar;
250
typedef unsigned long ulong;
252
struct EventToNameStruct
255
const TCHAR *EventName;
267
NUX_SIZE_CONFIGURATION,
268
NUX_WINDOW_CONFIGURATION,
269
NUX_WINDOW_ENTER_FOCUS,
270
NUX_WINDOW_EXIT_FOCUS,
272
NUX_WINDOW_MOUSELEAVE,
278
typedef struct IEvent
281
unsigned int ascii_code;
283
bool IsLeftMouseDown;
284
bool IsRightMouseDown;
285
bool IsMiddleMouseDown;
297
unsigned long e_key_modifiers; // key modifiers
298
unsigned short e_key_repeat_count; // number of time a key is repeated;
299
unsigned long e_mouse_state;
302
unsigned long e_event;
306
IsLeftMouseDown = false;
307
IsRightMouseDown = false;
308
IsMiddleMouseDown = false;
309
e_text = (char *) "";
311
for (int i = 0; i < NUX_MAX_VK; i++)
313
VirtualKeycodeState[i] = 0;
319
e_key_repeat_count = 0;
342
int event_x_root() const
346
int event_y_root() const
358
void get_mouse (int &, int &);
359
unsigned long event_key_state() const
361
return e_key_modifiers;
363
unsigned long event_mouse_state() const
365
return e_mouse_state;
368
//! Return virtual key code of the key that has triggered the last event.
370
Return virtual key code of the key that has triggered the last event.
371
@return the virtual key code.
373
unsigned long event_keysym() const
377
unsigned short event_key_auto_repeat_count() const
379
return e_key_repeat_count;
381
bool event_is_key_auto_repeat() const
383
if (e_key_repeat_count > 1)
388
const char *event_text() const
392
// Because an event is save in e_event instead of calling immediately the handling function,
393
// we must clear the previous event each time before we test for new event in Gfx_OpenGLImpl::get_event.
396
e_event = NUX_NO_EVENT;
397
e_text = (char *) "";
399
e_key_repeat_count = 0;
403
unsigned long VirtualKeycodeState[NUX_MAX_VK];
405
//! Return the state of the Virtual key
407
Return the state of the Virtual key.
408
@param VirtualKey virtual key code.
409
@return 1 if the key is pressed, 0 if the key is released.
411
unsigned long GetVirtualKeyState (unsigned long VirtualKey) const
413
if (VirtualKey >= NUX_MAX_VK)
419
return VirtualKeycodeState[VirtualKey];
427
#endif // GFXEVENTSX11_H
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>
23
#ifndef GFXEVENTSX11_H
24
#define GFXEVENTSX11_H
26
#include "GLResource.h"
27
#include "VirtualKeyCodesX11.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,
117
const long I_ExposureMask = (1L << 15);
118
const long I_StructureNotifyMask = (1L << 17);
119
const long I_SubstructureNotifyMask = (1L << 19);
121
#define NUX_BackSpace NUX_VK_BACK
122
#define NUX_Tab NUX_VK_TAB
123
#define NUX_Clear NUX_VK_CLEAR
124
#define NUX_Enter NUX_VK_ENTER
125
#define NUX_Shift_L NUX_VK_SHIFT
126
#define NUX_Control_L NUX_VK_CONTROL
127
#define NUX_Alt_L NUX_VK_MENU
128
#define NUX_Pause NUX_VK_PAUSE
129
#define NUX_Caps_Lock NUX_VK_CAPITAL
130
#define NUX_Escape NUX_VK_ESCAPE
131
#define NUX_SpaceBar NUX_VK_SPACE
132
#define NUX_Page_Up NUX_VK_PAGE_UP
133
#define NUX_Page_Down NUX_VK_PAGE_DOWN
134
#define NUX_End NUX_VK_END
135
#define NUX_Home NUX_VK_HOME
136
#define NUX_Left NUX_VK_LEFT
137
#define NUX_Up NUX_VK_UP
138
#define NUX_Right NUX_VK_RIGHT
139
#define NUX_Down NUX_VK_DOWN
140
#define NUX_Print NUX_VK_SNAPSHOT
141
#define NUX_Insert NUX_VK_INSERT
142
#define NUX_Delete NUX_VK_DELETE
143
#define NUX_LWin NUX_VK_LWIN
144
#define NUX_RWin NUX_VK_RWIN
145
#define NUX_APPS NUX_VK_APPS
146
#define NUX_Multiply NUX_VK_MULTIPLY
147
#define NUX_Add NUX_VK_ADD
148
#define NUX_Subtract NUX_VK_SUBTRACT
149
#define NUX_Decimal NUX_VK_DECIMAL
150
#define NUX_Divide NUX_VK_DIVIDE
151
#define NUX_Numlock NUX_VK_NUMLOCK
152
#define NUX_Scroll NUX_VK_SCROLL
154
#define NUX_KP_ENTER (0xff00 | NUX_VK_ENTER)
155
#define NUX_EXT_Shift_R (0xff00 | NUX_VK_SHIFT)
156
#define NUX_EXT_Control_R (0xff00 | NUX_VK_CONTROL)
157
#define NUX_EXT_Alt_R (0xff00 | NUX_VK_MENU)
159
#define NUX_KP_PAGE_UP (0xff00 | NUX_VK_PAGE_UP)
160
#define NUX_KP_PAGE_DOWN (0xff00 | NUX_VK_PAGE_DOWN)
161
#define NUX_KP_END (0xff00 | NUX_VK_END)
162
#define NUX_KP_HOME (0xff00 | NUX_VK_HOME)
163
#define NUX_KP_LEFT (0xff00 | NUX_VK_LEFT)
164
#define NUX_KP_UP (0xff00 | NUX_VK_UP)
165
#define NUX_KP_RIGHT (0xff00 | NUX_VK_RIGHT)
166
#define NUX_KP_DOWN (0xff00 | NUX_VK_DOWN)
168
#define NUX_KP_INSERT (0xff00 | NUX_VK_INSERT)
169
#define NUX_KP_DELETE (0xff00 | NUX_VK_DELETE)
171
#define NUX_F1 NUX_VK_F1
172
#define NUX_F2 NUX_VK_F2
173
#define NUX_F3 NUX_VK_F3
174
#define NUX_F4 NUX_VK_F4
175
#define NUX_F5 NUX_VK_F5
176
#define NUX_F6 NUX_VK_F6
177
#define NUX_F7 NUX_VK_F7
178
#define NUX_F8 NUX_VK_F8
179
#define NUX_F9 NUX_VK_F9
180
#define NUX_F10 NUX_VK_F10
181
#define NUX_F11 NUX_VK_F11
182
#define NUX_F12 NUX_VK_F12
183
#define NUX_F13 NUX_VK_F13
184
#define NUX_F14 NUX_VK_F14
185
#define NUX_F15 NUX_VK_F15
186
#define NUX_F16 NUX_VK_F16
187
#define NUX_F17 NUX_VK_F17
188
#define NUX_F18 NUX_VK_F18
189
#define NUX_F19 NUX_VK_F19
190
#define NUX_F20 NUX_VK_F20
191
#define NUX_F21 NUX_VK_F21
192
#define NUX_F22 NUX_VK_F22
193
#define NUX_F23 NUX_VK_F23
194
#define NUX_F24 NUX_VK_F24
196
#define NUX_LEFT_MOUSE 1
197
#define NUX_MIDDLE_MOUSE 2
198
#define NUX_RIGHT_MOUSE 3
200
// Key States. Set in e_key_modifiers.
201
#define NUX_STATE_SHIFT 0x00010000
202
#define NUX_STATE_CAPS_LOCK 0x00020000
203
#define NUX_STATE_CTRL 0x00040000
204
#define NUX_STATE_ALT 0x00080000
205
#define NUX_STATE_NUMLOCK 0x00100000 // most X servers do this?
206
#define NUX_STATE_META 0x00400000 // correct for XFree86
207
#define NUX_STATE_SCROLLLOCK 0x00800000 // correct for XFree86
209
// These flags describe the mouse button responsible for the mouse event.
210
// They are valid only for the current frame.
211
// Go in e_mouse_state.
212
#define NUX_EVENT_BUTTON1_UP 0x00001000
213
#define NUX_EVENT_BUTTON2_UP 0x00002000
214
#define NUX_EVENT_BUTTON3_UP 0x00004000
216
#define NUX_EVENT_BUTTON1_DOWN 0x00010000
217
#define NUX_EVENT_BUTTON2_DOWN 0x00020000
218
#define NUX_EVENT_BUTTON3_DOWN 0x00040000
220
#define NUX_EVENT_BUTTON1 0x00010000
221
#define NUX_EVENT_BUTTON2 0x00020000
222
#define NUX_EVENT_BUTTON3 0x00040000
224
#define NUX_EVENT_MOUSEWHEEL 0x00080000
225
// These flags describe the state of the mouse buttons.
226
// They persist over several frame until the mouse buttons change state.
227
// Go in e_mouse_state.
228
#define NUX_STATE_BUTTON1_DOWN 0x01000000
229
#define NUX_STATE_BUTTON2_DOWN 0x02000000
230
#define NUX_STATE_BUTTON3_DOWN 0x04000000
232
// These flags are set if the event is a double click.
233
// They are valid only for the current frame.
234
// Go in e_mouse_state.
235
#define NUX_EVENT_BUTTON1_DBLCLICK 0x10000000
236
#define NUX_EVENT_BUTTON2_DBLCLICK 0x20000000
237
#define NUX_EVENT_BUTTON3_DBLCLICK 0x40000000
239
#define eLEFT_BUTTON NUX_EVENT_BUTTON1
240
#define eMIDDLE_BUTTON NUX_EVENT_BUTTON2
241
#define eRIGHT_BUTTON NUX_EVENT_BUTTON3
243
#define eLEFT_BUTTON_DOWN NUX_STATE_BUTTON1_DOWN
244
#define eMIDDLE_BUTTON_DOWN NUX_STATE_BUTTON2_DOWN
245
#define eRIGHT_BUTTON_DOWN NUX_STATE_BUTTON3_DOWN
247
#define NUX_WIN32_MOUSEWHEEL_DELTA 120 // 120 correspond to one notch of the mouse wheel
249
typedef unsigned char uchar;
250
typedef unsigned long ulong;
252
struct EventToNameStruct
255
const TCHAR *EventName;
267
NUX_SIZE_CONFIGURATION,
268
NUX_WINDOW_CONFIGURATION,
269
NUX_WINDOW_ENTER_FOCUS,
270
NUX_WINDOW_EXIT_FOCUS,
272
NUX_WINDOW_MOUSELEAVE,
278
typedef struct IEvent
281
unsigned int ascii_code;
283
bool IsLeftMouseDown;
284
bool IsRightMouseDown;
285
bool IsMiddleMouseDown;
297
unsigned long e_key_modifiers; // key modifiers
298
unsigned short e_key_repeat_count; // number of time a key is repeated;
299
unsigned long e_mouse_state;
302
unsigned long e_event;
306
IsLeftMouseDown = false;
307
IsRightMouseDown = false;
308
IsMiddleMouseDown = false;
309
e_text = (char *) "";
311
for (int i = 0; i < NUX_MAX_VK; i++)
313
VirtualKeycodeState[i] = 0;
319
e_key_repeat_count = 0;
342
int event_x_root() const
346
int event_y_root() const
358
void get_mouse (int &, int &);
359
unsigned long event_key_state() const
361
return e_key_modifiers;
363
unsigned long event_mouse_state() const
365
return e_mouse_state;
368
//! Return virtual key code of the key that has triggered the last event.
370
Return virtual key code of the key that has triggered the last event.
371
@return the virtual key code.
373
unsigned long event_keysym() const
377
unsigned short event_key_auto_repeat_count() const
379
return e_key_repeat_count;
381
bool event_is_key_auto_repeat() const
383
if (e_key_repeat_count > 1)
388
const char *event_text() const
392
// Because an event is save in e_event instead of calling immediately the handling function,
393
// we must clear the previous event each time before we test for new event in Gfx_OpenGLImpl::get_event.
396
e_event = NUX_NO_EVENT;
397
e_text = (char *) "";
399
e_key_repeat_count = 0;
403
unsigned long VirtualKeycodeState[NUX_MAX_VK];
405
//! Return the state of the Virtual key
407
Return the state of the Virtual key.
408
@param VirtualKey virtual key code.
409
@return 1 if the key is pressed, 0 if the key is released.
411
unsigned long GetVirtualKeyState (unsigned long VirtualKey) const
413
if (VirtualKey >= NUX_MAX_VK)
419
return VirtualKeycodeState[VirtualKey];
427
#endif // GFXEVENTSX11_H