~thumper/nux/next-changes

« back to all changes in this revision

Viewing changes to NuxGraphics/Gfx_Events.h

  • Committer: Neil Jagdish Patel
  • Date: 2010-09-01 21:15:42 UTC
  • Revision ID: neil.patel@canonical.com-20100901211542-cw2ce3ak28unouwb
Add NuxGraphics with licensing

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 EVENTS_H
 
24
#define EVENTS_H
 
25
 
 
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.
 
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_BEGIN_OGL
 
115
 
 
116
const long I_ExposureMask               = (1L<<15); 
 
117
const long I_StructureNotifyMask        = (1L<<17); 
 
118
const long I_SubstructureNotifyMask     = (1L<<19); 
 
119
/*
 
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
 
152
*/
 
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)
 
157
 
 
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)
 
166
 
 
167
#define INL_KP_INSERT      (0xff00 | INL_VK_INSERT)
 
168
#define INL_KP_DELETE      (0xff00 | INL_VK_DELETE)
 
169
 
 
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    
 
194
 
 
195
#define INL_LEFT_MOUSE  1
 
196
#define INL_MIDDLE_MOUSE        2
 
197
#define INL_RIGHT_MOUSE 3
 
198
 
 
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
 
207
 
 
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
 
214
 
 
215
#define INL_EVENT_BUTTON1_DOWN      0x00010000
 
216
#define INL_EVENT_BUTTON2_DOWN      0x00020000
 
217
#define INL_EVENT_BUTTON3_DOWN      0x00040000
 
218
 
 
219
#define INL_EVENT_BUTTON1           0x00010000
 
220
#define INL_EVENT_BUTTON2           0x00020000
 
221
#define INL_EVENT_BUTTON3           0x00040000
 
222
 
 
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
 
230
 
 
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
 
237
 
 
238
#define eLEFT_BUTTON            INL_EVENT_BUTTON1
 
239
#define eMIDDLE_BUTTON          INL_EVENT_BUTTON2
 
240
#define eRIGHT_BUTTON           INL_EVENT_BUTTON3
 
241
 
 
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
 
245
 
 
246
#define INL_WIN32_MOUSEWHEEL_DELTA  120 // 120 correspond to one notch of the mouse wheel
 
247
 
 
248
typedef unsigned char uchar;
 
249
typedef unsigned long ulong;
 
250
 
 
251
struct EventToNameStruct {
 
252
    int event;
 
253
    const TCHAR* EventName;
 
254
};
 
255
 
 
256
enum 
 
257
{       // events
 
258
    INL_NO_EVENT         = 0,
 
259
    INL_MOUSE_PRESSED,
 
260
    INL_MOUSE_RELEASED,
 
261
    INL_KEYDOWN,
 
262
    INL_KEYUP,
 
263
    INL_MOUSE_MOVE,
 
264
    INL_SIZE_CONFIGURATION,
 
265
    INL_WINDOW_CONFIGURATION,
 
266
    INL_WINDOW_ENTER_FOCUS,
 
267
    INL_WINDOW_EXIT_FOCUS,
 
268
    INL_WINDOW_DIRTY,
 
269
    INL_WINDOW_MOUSELEAVE,
 
270
    INL_MOUSEWHEEL,
 
271
    INL_DESTROY_WINDOW,
 
272
    INL_TERMINATE_APP
 
273
};
 
274
 
 
275
typedef struct IEvent
 
276
{                              
 
277
    int width, height;
 
278
    unsigned int ascii_code;
 
279
    int virtual_code;
 
280
    bool IsLeftMouseDown;     
 
281
    bool IsRightMouseDown;
 
282
    bool IsMiddleMouseDown;
 
283
    int e_x,
 
284
        e_y,
 
285
        e_x_root,
 
286
        e_y_root,
 
287
        e_dx,
 
288
        e_dy,
 
289
        e_clicks,
 
290
        e_is_click,
 
291
        e_keysym;
 
292
    int e_wheeldelta;
 
293
 
 
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;
 
297
    char    *e_text;
 
298
    int     e_length;
 
299
    unsigned long e_event;
 
300
    
 
301
    IEvent()
 
302
    {
 
303
        IsLeftMouseDown = false;
 
304
        IsRightMouseDown = false;
 
305
        IsMiddleMouseDown = false;
 
306
        e_text = (char *)"";
 
307
 
 
308
        for(int i = 0; i < INL_MAX_VK; i++) 
 
309
        {
 
310
            VirtualKeycodeState[i] = 0;
 
311
        }
 
312
 
 
313
        ascii_code = 0;
 
314
        virtual_code = 0;
 
315
        e_key_modifiers = 0;
 
316
        e_key_repeat_count = 0;
 
317
        e_mouse_state = 0;
 
318
        e_x = 0;
 
319
        e_y = 0;
 
320
        e_x_root = 0;
 
321
        e_y_root = 0;
 
322
        e_dx = 0;
 
323
        e_dy = 0;
 
324
        e_clicks = 0;
 
325
        e_is_click = 0;
 
326
        e_keysym = 0;
 
327
        e_wheeldelta = 0;
 
328
 
 
329
        //Application = 0;
 
330
    }
 
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;}
 
340
 
 
341
    //! Return virtual key code of the key that has triggered the last event.
 
342
    /*! 
 
343
        Return virtual key code of the key that has triggered the last event.
 
344
        @return the virtual key code.
 
345
    */
 
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 
 
349
    {
 
350
        if(e_key_repeat_count > 1)
 
351
            return true;
 
352
        return false;
 
353
    }
 
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.
 
357
    void Reset()
 
358
    {
 
359
        e_event = INL_NO_EVENT;
 
360
        e_text = (char *)"";
 
361
        e_keysym = 0;
 
362
        e_key_repeat_count = 0;
 
363
        e_wheeldelta = 0;
 
364
    }
 
365
 
 
366
    unsigned long VirtualKeycodeState[INL_MAX_VK];
 
367
 
 
368
    //! Return the state of the Virtual key
 
369
    /*! 
 
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.
 
373
    */
 
374
    unsigned long GetVirtualKeyState(unsigned long VirtualKey) const
 
375
    {
 
376
        if(VirtualKey >= INL_MAX_VK)
 
377
            return 0;
 
378
 
 
379
        if(VirtualKey <= 0)
 
380
            return 0;
 
381
 
 
382
        return VirtualKeycodeState[VirtualKey];
 
383
    }
 
384
 
 
385
    //void* Application;
 
386
} IEvent;
 
387
 
 
388
NAMESPACE_END_OGL
 
389
 
 
390
#endif // EVENTS_H