~canonical-dx-team/nux/nux.arch-cleanup

« back to all changes in this revision

Viewing changes to NuxGraphics/GfxEventsX11.h

  • Committer: Jay Taoko
  • Date: 2010-12-05 01:15:51 UTC
  • mfrom: (137.2.1 nux)
  • Revision ID: jay.taoko@canonical.com-20101205011551-706e6farovbwe23b
* Cleanup Nux Graphics
* Added GpuInfo
* Fixed end of line

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/*
2
 
 * Copyright 2010 Inalogic Inc.
3
 
 *
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.
7
 
 *
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.
13
 
 *
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/>
17
 
 *
18
 
 * Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
19
 
 *
20
 
 */
21
 
 
22
 
 
23
 
#ifndef GFXEVENTSX11_H
24
 
#define GFXEVENTSX11_H
25
 
 
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.
39
 
//enum eKeyCode
40
 
//{
41
 
//    // ASCII set. Should be supported everywhere
42
 
//    key_backspace      = 8,
43
 
//    key_tab            = 9,
44
 
//    key_clear          = 12,
45
 
//    key_return         = 13,
46
 
//    key_shift          = 16,
47
 
//    key_control        = 17,
48
 
//    key_pause          = 19,
49
 
//    key_escape         = 27,
50
 
//
51
 
//    key_space          = 32,
52
 
//
53
 
//    // Keypad
54
 
//    key_delete         = 127,
55
 
//    key_kp0            = 256,
56
 
//    key_kp1            = 257,
57
 
//    key_kp2            = 258,
58
 
//    key_kp3            = 259,
59
 
//    key_kp4            = 260,
60
 
//    key_kp5            = 261,
61
 
//    key_kp6            = 262,
62
 
//    key_kp7            = 263,
63
 
//    key_kp8            = 264,
64
 
//    key_kp9            = 265,
65
 
//    key_kp_period      = 266,
66
 
//    key_kp_divide      = 267,
67
 
//    key_kp_multiply    = 268,
68
 
//    key_kp_minus       = 269,
69
 
//    key_kp_plus        = 270,
70
 
//    key_kp_enter       = 271,
71
 
//    key_kp_equals      = 272,
72
 
//
73
 
//    // Arrow-keys and stuff
74
 
//    key_up             = 273,
75
 
//    key_down           = 274,
76
 
//    key_right          = 275,
77
 
//    key_left           = 276,
78
 
//    key_insert         = 277,
79
 
//    key_home           = 278,
80
 
//    key_end            = 279,
81
 
//    key_page_up        = 280,
82
 
//    key_page_down      = 281,
83
 
//
84
 
//    // Functional keys. You'd better avoid using
85
 
//    // f11...f15 in your applications if you want
86
 
//    // the applications to be portable
87
 
//    key_f1             = 282,
88
 
//    key_f2             = 283,
89
 
//    key_f3             = 284,
90
 
//    key_f4             = 285,
91
 
//    key_f5             = 286,
92
 
//    key_f6             = 287,
93
 
//    key_f7             = 288,
94
 
//    key_f8             = 289,
95
 
//    key_f9             = 290,
96
 
//    key_f10            = 291,
97
 
//    key_f11            = 292,
98
 
//    key_f12            = 293,
99
 
//    key_f13            = 294,
100
 
//    key_f14            = 295,
101
 
//    key_f15            = 296,
102
 
//
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,
109
 
//
110
 
//    // Phew!
111
 
//    end_of_key_codes
112
 
//};
113
 
 
114
 
namespace nux
115
 
{
116
 
 
117
 
  const long I_ExposureMask               = (1L << 15);
118
 
  const long I_StructureNotifyMask        = (1L << 17);
119
 
  const long I_SubstructureNotifyMask     = (1L << 19);
120
 
 
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
153
 
 
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)
158
 
 
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)
167
 
 
168
 
#define NUX_KP_INSERT      (0xff00 | NUX_VK_INSERT)
169
 
#define NUX_KP_DELETE      (0xff00 | NUX_VK_DELETE)
170
 
 
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
195
 
 
196
 
#define NUX_LEFT_MOUSE  1
197
 
#define NUX_MIDDLE_MOUSE        2
198
 
#define NUX_RIGHT_MOUSE 3
199
 
 
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
208
 
 
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
215
 
 
216
 
#define NUX_EVENT_BUTTON1_DOWN      0x00010000
217
 
#define NUX_EVENT_BUTTON2_DOWN      0x00020000
218
 
#define NUX_EVENT_BUTTON3_DOWN      0x00040000
219
 
 
220
 
#define NUX_EVENT_BUTTON1           0x00010000
221
 
#define NUX_EVENT_BUTTON2           0x00020000
222
 
#define NUX_EVENT_BUTTON3           0x00040000
223
 
 
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
231
 
 
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
238
 
 
239
 
#define eLEFT_BUTTON            NUX_EVENT_BUTTON1
240
 
#define eMIDDLE_BUTTON          NUX_EVENT_BUTTON2
241
 
#define eRIGHT_BUTTON           NUX_EVENT_BUTTON3
242
 
 
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
246
 
 
247
 
#define NUX_WIN32_MOUSEWHEEL_DELTA  120 // 120 correspond to one notch of the mouse wheel
248
 
 
249
 
  typedef unsigned char uchar;
250
 
  typedef unsigned long ulong;
251
 
 
252
 
  struct EventToNameStruct
253
 
  {
254
 
    int event;
255
 
    const TCHAR *EventName;
256
 
  };
257
 
 
258
 
  enum
259
 
  {
260
 
    // events
261
 
    NUX_NO_EVENT         = 0,
262
 
    NUX_MOUSE_PRESSED,
263
 
    NUX_MOUSE_RELEASED,
264
 
    NUX_KEYDOWN,
265
 
    NUX_KEYUP,
266
 
    NUX_MOUSE_MOVE,
267
 
    NUX_SIZE_CONFIGURATION,
268
 
    NUX_WINDOW_CONFIGURATION,
269
 
    NUX_WINDOW_ENTER_FOCUS,
270
 
    NUX_WINDOW_EXIT_FOCUS,
271
 
    NUX_WINDOW_DIRTY,
272
 
    NUX_WINDOW_MOUSELEAVE,
273
 
    NUX_MOUSEWHEEL,
274
 
    NUX_DESTROY_WINDOW,
275
 
    NUX_TERMINATE_APP
276
 
  };
277
 
 
278
 
  typedef struct IEvent
279
 
  {
280
 
    int width, height;
281
 
    unsigned int ascii_code;
282
 
    int virtual_code;
283
 
    bool IsLeftMouseDown;
284
 
    bool IsRightMouseDown;
285
 
    bool IsMiddleMouseDown;
286
 
    int e_x,
287
 
        e_y,
288
 
        e_x_root,
289
 
        e_y_root,
290
 
        e_dx,
291
 
        e_dy,
292
 
        e_clicks,
293
 
        e_is_click,
294
 
        e_keysym;
295
 
    int e_wheeldelta;
296
 
 
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;
300
 
    char    *e_text;
301
 
    int     e_length;
302
 
    unsigned long e_event;
303
 
 
304
 
    IEvent()
305
 
    {
306
 
      IsLeftMouseDown = false;
307
 
      IsRightMouseDown = false;
308
 
      IsMiddleMouseDown = false;
309
 
      e_text = (char *) "";
310
 
 
311
 
      for (int i = 0; i < NUX_MAX_VK; i++)
312
 
      {
313
 
        VirtualKeycodeState[i] = 0;
314
 
      }
315
 
 
316
 
      ascii_code = 0;
317
 
      virtual_code = 0;
318
 
      e_key_modifiers = 0;
319
 
      e_key_repeat_count = 0;
320
 
      e_mouse_state = 0;
321
 
      e_x = 0;
322
 
      e_y = 0;
323
 
      e_x_root = 0;
324
 
      e_y_root = 0;
325
 
      e_dx = 0;
326
 
      e_dy = 0;
327
 
      e_clicks = 0;
328
 
      e_is_click = 0;
329
 
      e_keysym = 0;
330
 
      e_wheeldelta = 0;
331
 
 
332
 
      //Application = 0;
333
 
    }
334
 
    int event_x() const
335
 
    {
336
 
      return e_x;
337
 
    }
338
 
    int event_y() const
339
 
    {
340
 
      return e_y;
341
 
    }
342
 
    int event_x_root() const
343
 
    {
344
 
      return e_x_root;
345
 
    }
346
 
    int event_y_root() const
347
 
    {
348
 
      return e_y_root;
349
 
    }
350
 
    int event_dx() const
351
 
    {
352
 
      return e_dx;
353
 
    }
354
 
    int event_dy() const
355
 
    {
356
 
      return e_dy;
357
 
    }
358
 
    void get_mouse (int &, int &);
359
 
    unsigned long event_key_state()     const
360
 
    {
361
 
      return e_key_modifiers;
362
 
    }
363
 
    unsigned long event_mouse_state() const
364
 
    {
365
 
      return e_mouse_state;
366
 
    }
367
 
 
368
 
    //! Return virtual key code of the key that has triggered the last event.
369
 
    /*!
370
 
        Return virtual key code of the key that has triggered the last event.
371
 
        @return the virtual key code.
372
 
    */
373
 
    unsigned long event_keysym() const
374
 
    {
375
 
      return e_keysym;
376
 
    }
377
 
    unsigned short event_key_auto_repeat_count() const
378
 
    {
379
 
      return e_key_repeat_count;
380
 
    }
381
 
    bool event_is_key_auto_repeat() const
382
 
    {
383
 
      if (e_key_repeat_count > 1)
384
 
        return true;
385
 
 
386
 
      return false;
387
 
    }
388
 
    const char *event_text() const
389
 
    {
390
 
      return e_text;
391
 
    }
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.
394
 
    void Reset()
395
 
    {
396
 
      e_event = NUX_NO_EVENT;
397
 
      e_text = (char *) "";
398
 
      e_keysym = 0;
399
 
      e_key_repeat_count = 0;
400
 
      e_wheeldelta = 0;
401
 
    }
402
 
 
403
 
    unsigned long VirtualKeycodeState[NUX_MAX_VK];
404
 
 
405
 
    //! Return the state of the Virtual key
406
 
    /*!
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.
410
 
    */
411
 
    unsigned long GetVirtualKeyState (unsigned long VirtualKey) const
412
 
    {
413
 
      if (VirtualKey >= NUX_MAX_VK)
414
 
        return 0;
415
 
 
416
 
      if (VirtualKey <= 0)
417
 
        return 0;
418
 
 
419
 
      return VirtualKeycodeState[VirtualKey];
420
 
    }
421
 
 
422
 
    //void* Application;
423
 
  } IEvent;
424
 
 
425
 
}
426
 
 
427
 
#endif // GFXEVENTSX11_H
428
 
 
 
1
/*
 
2
 * Copyright 2010 Inalogic Inc.
 
3
 *
 
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.
 
7
 *
 
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.
 
13
 *
 
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/>
 
17
 *
 
18
 * Authored by: Jay Taoko <jay.taoko_AT_gmail_DOT_com>
 
19
 *
 
20
 */
 
21
 
 
22
 
 
23
#ifndef GFXEVENTSX11_H
 
24
#define GFXEVENTSX11_H
 
25
 
 
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.
 
39
//enum eKeyCode
 
40
//{
 
41
//    // ASCII set. Should be supported everywhere
 
42
//    key_backspace      = 8,
 
43
//    key_tab            = 9,
 
44
//    key_clear          = 12,
 
45
//    key_return         = 13,
 
46
//    key_shift          = 16,
 
47
//    key_control        = 17,
 
48
//    key_pause          = 19,
 
49
//    key_escape         = 27,
 
50
//
 
51
//    key_space          = 32,
 
52
//
 
53
//    // Keypad
 
54
//    key_delete         = 127,
 
55
//    key_kp0            = 256,
 
56
//    key_kp1            = 257,
 
57
//    key_kp2            = 258,
 
58
//    key_kp3            = 259,
 
59
//    key_kp4            = 260,
 
60
//    key_kp5            = 261,
 
61
//    key_kp6            = 262,
 
62
//    key_kp7            = 263,
 
63
//    key_kp8            = 264,
 
64
//    key_kp9            = 265,
 
65
//    key_kp_period      = 266,
 
66
//    key_kp_divide      = 267,
 
67
//    key_kp_multiply    = 268,
 
68
//    key_kp_minus       = 269,
 
69
//    key_kp_plus        = 270,
 
70
//    key_kp_enter       = 271,
 
71
//    key_kp_equals      = 272,
 
72
//
 
73
//    // Arrow-keys and stuff
 
74
//    key_up             = 273,
 
75
//    key_down           = 274,
 
76
//    key_right          = 275,
 
77
//    key_left           = 276,
 
78
//    key_insert         = 277,
 
79
//    key_home           = 278,
 
80
//    key_end            = 279,
 
81
//    key_page_up        = 280,
 
82
//    key_page_down      = 281,
 
83
//
 
84
//    // Functional keys. You'd better avoid using
 
85
//    // f11...f15 in your applications if you want
 
86
//    // the applications to be portable
 
87
//    key_f1             = 282,
 
88
//    key_f2             = 283,
 
89
//    key_f3             = 284,
 
90
//    key_f4             = 285,
 
91
//    key_f5             = 286,
 
92
//    key_f6             = 287,
 
93
//    key_f7             = 288,
 
94
//    key_f8             = 289,
 
95
//    key_f9             = 290,
 
96
//    key_f10            = 291,
 
97
//    key_f11            = 292,
 
98
//    key_f12            = 293,
 
99
//    key_f13            = 294,
 
100
//    key_f14            = 295,
 
101
//    key_f15            = 296,
 
102
//
 
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,
 
109
//
 
110
//    // Phew!
 
111
//    end_of_key_codes
 
112
//};
 
113
 
 
114
namespace nux
 
115
{
 
116
 
 
117
  const long I_ExposureMask               = (1L << 15);
 
118
  const long I_StructureNotifyMask        = (1L << 17);
 
119
  const long I_SubstructureNotifyMask     = (1L << 19);
 
120
 
 
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
 
153
 
 
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)
 
158
 
 
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)
 
167
 
 
168
#define NUX_KP_INSERT      (0xff00 | NUX_VK_INSERT)
 
169
#define NUX_KP_DELETE      (0xff00 | NUX_VK_DELETE)
 
170
 
 
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
 
195
 
 
196
#define NUX_LEFT_MOUSE  1
 
197
#define NUX_MIDDLE_MOUSE        2
 
198
#define NUX_RIGHT_MOUSE 3
 
199
 
 
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
 
208
 
 
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
 
215
 
 
216
#define NUX_EVENT_BUTTON1_DOWN      0x00010000
 
217
#define NUX_EVENT_BUTTON2_DOWN      0x00020000
 
218
#define NUX_EVENT_BUTTON3_DOWN      0x00040000
 
219
 
 
220
#define NUX_EVENT_BUTTON1           0x00010000
 
221
#define NUX_EVENT_BUTTON2           0x00020000
 
222
#define NUX_EVENT_BUTTON3           0x00040000
 
223
 
 
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
 
231
 
 
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
 
238
 
 
239
#define eLEFT_BUTTON            NUX_EVENT_BUTTON1
 
240
#define eMIDDLE_BUTTON          NUX_EVENT_BUTTON2
 
241
#define eRIGHT_BUTTON           NUX_EVENT_BUTTON3
 
242
 
 
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
 
246
 
 
247
#define NUX_WIN32_MOUSEWHEEL_DELTA  120 // 120 correspond to one notch of the mouse wheel
 
248
 
 
249
  typedef unsigned char uchar;
 
250
  typedef unsigned long ulong;
 
251
 
 
252
  struct EventToNameStruct
 
253
  {
 
254
    int event;
 
255
    const TCHAR *EventName;
 
256
  };
 
257
 
 
258
  enum
 
259
  {
 
260
    // events
 
261
    NUX_NO_EVENT         = 0,
 
262
    NUX_MOUSE_PRESSED,
 
263
    NUX_MOUSE_RELEASED,
 
264
    NUX_KEYDOWN,
 
265
    NUX_KEYUP,
 
266
    NUX_MOUSE_MOVE,
 
267
    NUX_SIZE_CONFIGURATION,
 
268
    NUX_WINDOW_CONFIGURATION,
 
269
    NUX_WINDOW_ENTER_FOCUS,
 
270
    NUX_WINDOW_EXIT_FOCUS,
 
271
    NUX_WINDOW_DIRTY,
 
272
    NUX_WINDOW_MOUSELEAVE,
 
273
    NUX_MOUSEWHEEL,
 
274
    NUX_DESTROY_WINDOW,
 
275
    NUX_TERMINATE_APP
 
276
  };
 
277
 
 
278
  typedef struct IEvent
 
279
  {
 
280
    int width, height;
 
281
    unsigned int ascii_code;
 
282
    int virtual_code;
 
283
    bool IsLeftMouseDown;
 
284
    bool IsRightMouseDown;
 
285
    bool IsMiddleMouseDown;
 
286
    int e_x,
 
287
        e_y,
 
288
        e_x_root,
 
289
        e_y_root,
 
290
        e_dx,
 
291
        e_dy,
 
292
        e_clicks,
 
293
        e_is_click,
 
294
        e_keysym;
 
295
    int e_wheeldelta;
 
296
 
 
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;
 
300
    char    *e_text;
 
301
    int     e_length;
 
302
    unsigned long e_event;
 
303
 
 
304
    IEvent()
 
305
    {
 
306
      IsLeftMouseDown = false;
 
307
      IsRightMouseDown = false;
 
308
      IsMiddleMouseDown = false;
 
309
      e_text = (char *) "";
 
310
 
 
311
      for (int i = 0; i < NUX_MAX_VK; i++)
 
312
      {
 
313
        VirtualKeycodeState[i] = 0;
 
314
      }
 
315
 
 
316
      ascii_code = 0;
 
317
      virtual_code = 0;
 
318
      e_key_modifiers = 0;
 
319
      e_key_repeat_count = 0;
 
320
      e_mouse_state = 0;
 
321
      e_x = 0;
 
322
      e_y = 0;
 
323
      e_x_root = 0;
 
324
      e_y_root = 0;
 
325
      e_dx = 0;
 
326
      e_dy = 0;
 
327
      e_clicks = 0;
 
328
      e_is_click = 0;
 
329
      e_keysym = 0;
 
330
      e_wheeldelta = 0;
 
331
 
 
332
      //Application = 0;
 
333
    }
 
334
    int event_x() const
 
335
    {
 
336
      return e_x;
 
337
    }
 
338
    int event_y() const
 
339
    {
 
340
      return e_y;
 
341
    }
 
342
    int event_x_root() const
 
343
    {
 
344
      return e_x_root;
 
345
    }
 
346
    int event_y_root() const
 
347
    {
 
348
      return e_y_root;
 
349
    }
 
350
    int event_dx() const
 
351
    {
 
352
      return e_dx;
 
353
    }
 
354
    int event_dy() const
 
355
    {
 
356
      return e_dy;
 
357
    }
 
358
    void get_mouse (int &, int &);
 
359
    unsigned long event_key_state()     const
 
360
    {
 
361
      return e_key_modifiers;
 
362
    }
 
363
    unsigned long event_mouse_state() const
 
364
    {
 
365
      return e_mouse_state;
 
366
    }
 
367
 
 
368
    //! Return virtual key code of the key that has triggered the last event.
 
369
    /*!
 
370
        Return virtual key code of the key that has triggered the last event.
 
371
        @return the virtual key code.
 
372
    */
 
373
    unsigned long event_keysym() const
 
374
    {
 
375
      return e_keysym;
 
376
    }
 
377
    unsigned short event_key_auto_repeat_count() const
 
378
    {
 
379
      return e_key_repeat_count;
 
380
    }
 
381
    bool event_is_key_auto_repeat() const
 
382
    {
 
383
      if (e_key_repeat_count > 1)
 
384
        return true;
 
385
 
 
386
      return false;
 
387
    }
 
388
    const char *event_text() const
 
389
    {
 
390
      return e_text;
 
391
    }
 
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.
 
394
    void Reset()
 
395
    {
 
396
      e_event = NUX_NO_EVENT;
 
397
      e_text = (char *) "";
 
398
      e_keysym = 0;
 
399
      e_key_repeat_count = 0;
 
400
      e_wheeldelta = 0;
 
401
    }
 
402
 
 
403
    unsigned long VirtualKeycodeState[NUX_MAX_VK];
 
404
 
 
405
    //! Return the state of the Virtual key
 
406
    /*!
 
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.
 
410
    */
 
411
    unsigned long GetVirtualKeyState (unsigned long VirtualKey) const
 
412
    {
 
413
      if (VirtualKey >= NUX_MAX_VK)
 
414
        return 0;
 
415
 
 
416
      if (VirtualKey <= 0)
 
417
        return 0;
 
418
 
 
419
      return VirtualKeycodeState[VirtualKey];
 
420
    }
 
421
 
 
422
    //void* Application;
 
423
  } IEvent;
 
424
 
 
425
}
 
426
 
 
427
#endif // GFXEVENTSX11_H
 
428