Back to index

nux  3.0.0
Events.h
Go to the documentation of this file.
00001 /*
00002  * Copyright 2010 Inalogic® Inc.
00003  *
00004  * This program is free software: you can redistribute it and/or modify it
00005  * under the terms of the GNU Lesser General Public License, as
00006  * published by the  Free Software Foundation; either version 2.1 or 3.0
00007  * of the License.
00008  *
00009  * This program is distributed in the hope that it will be useful, but
00010  * WITHOUT ANY WARRANTY; without even the implied warranties of
00011  * MERCHANTABILITY, SATISFACTORY QUALITY or FITNESS FOR A PARTICULAR
00012  * PURPOSE.  See the applicable version of the GNU Lesser General Public
00013  * License for more details.
00014  *
00015  * You should have received a copy of both the GNU Lesser General Public
00016  * License along with this program. If not, see <http://www.gnu.org/licenses/>
00017  *
00018  * Authored by: Jay Taoko <jaytaoko@inalogic.com>
00019  *
00020  */
00021 
00022 
00023 #ifndef EVENTS_H
00024 #define EVENTS_H
00025 
00026 #include "GLResource.h"
00027 
00028 #if defined(NUX_OS_WINDOWS)
00029   #include "VirtualKeyCodes.h"
00030 #elif defined(NUX_OS_LINUX)
00031   #include "VirtualKeyCodesX11.h"
00032 #else
00033   #error VirtualKeyCode file not Implemented.
00034 #endif
00035 
00036 
00037 namespace nux
00038 {
00039   const long I_ExposureMask               = (1L << 15);
00040   const long I_StructureNotifyMask        = (1L << 17);
00041   const long I_SubstructureNotifyMask     = (1L << 19);
00042 
00043   #define NUX_BackSpace       NUX_VK_BACK
00044   #define NUX_Tab             NUX_VK_TAB
00045   #define NUX_Clear           NUX_VK_CLEAR
00046   #define NUX_Enter           NUX_VK_ENTER
00047   #define NUX_Shift_L         NUX_VK_SHIFT
00048   #define NUX_Control_L       NUX_VK_CONTROL
00049   #define NUX_Alt_L           NUX_VK_MENU
00050   #define NUX_Pause           NUX_VK_PAUSE
00051   #define NUX_Caps_Lock       NUX_VK_CAPITAL
00052   #define NUX_Escape          NUX_VK_ESCAPE
00053   #define NUX_SpaceBar        NUX_VK_SPACE
00054   #define NUX_Page_Up         NUX_VK_PAGE_UP
00055   #define NUX_Page_Down       NUX_VK_PAGE_DOWN
00056   #define NUX_End             NUX_VK_END
00057   #define NUX_Home            NUX_VK_HOME
00058   #define NUX_Left            NUX_VK_LEFT
00059   #define NUX_Up              NUX_VK_UP
00060   #define NUX_Right           NUX_VK_RIGHT
00061   #define NUX_Down            NUX_VK_DOWN
00062   #define NUX_Print           NUX_VK_SNAPSHOT
00063   #define NUX_Insert          NUX_VK_INSERT
00064   #define NUX_Delete          NUX_VK_DELETE
00065   #define NUX_LWin            NUX_VK_LWIN
00066   #define NUX_RWin            NUX_VK_RWIN
00067   #define NUX_APPS            NUX_VK_APPS
00068   #define NUX_Multiply        NUX_VK_MULTIPLY
00069   #define NUX_Add             NUX_VK_ADD
00070   #define NUX_Subtract        NUX_VK_SUBTRACT
00071   #define NUX_Decimal         NUX_VK_DECIMAL
00072   #define NUX_Divide          NUX_VK_DIVIDE
00073   #define NUX_Numlock         NUX_VK_NUMLOCK
00074   #define NUX_Scroll          NUX_VK_SCROLL
00075 
00076 #define NUX_EXT_Shift_R     (0xff00 | NUX_VK_SHIFT)
00077 #define NUX_EXT_Control_R   (0xff00 | NUX_VK_CONTROL)
00078 #define NUX_EXT_Alt_R       (0xff00 | NUX_VK_MENU)
00079 
00080 #define NUX_KP_DOWN         0xFF99
00081 #define NUX_KP_UP           0xFF97
00082 #define NUX_KP_LEFT         0xFF96
00083 #define NUX_KP_RIGHT        0xFF98
00084 
00085 // #define NUX_KP_PAGE_UP     (0xff00 | NUX_VK_PAGE_UP)
00086 // #define NUX_KP_PAGE_DOWN   (0xff00 | NUX_VK_PAGE_DOWN)
00087 // #define NUX_KP_END         (0xff00 | NUX_VK_END)
00088 // #define NUX_KP_HOME        (0xff00 | NUX_VK_HOME)
00089 // #define NUX_KP_INSERT      (0xff00 | NUX_VK_INSERT)
00090 // #define NUX_KP_DELETE      (0xff00 | NUX_VK_DELETE)
00091 
00092 #define NUX_F1     NUX_VK_F1
00093 #define NUX_F2     NUX_VK_F2
00094 #define NUX_F3     NUX_VK_F3
00095 #define NUX_F4     NUX_VK_F4
00096 #define NUX_F5     NUX_VK_F5
00097 #define NUX_F6     NUX_VK_F6
00098 #define NUX_F7     NUX_VK_F7
00099 #define NUX_F8     NUX_VK_F8
00100 #define NUX_F9     NUX_VK_F9
00101 #define NUX_F10    NUX_VK_F10
00102 #define NUX_F11    NUX_VK_F11
00103 #define NUX_F12    NUX_VK_F12
00104 #define NUX_F13    NUX_VK_F13
00105 #define NUX_F14    NUX_VK_F14
00106 #define NUX_F15    NUX_VK_F15
00107 #define NUX_F16    NUX_VK_F16
00108 #define NUX_F17    NUX_VK_F17
00109 #define NUX_F18    NUX_VK_F18
00110 #define NUX_F19    NUX_VK_F19
00111 #define NUX_F20    NUX_VK_F20
00112 #define NUX_F21    NUX_VK_F21
00113 #define NUX_F22    NUX_VK_F22
00114 #define NUX_F23    NUX_VK_F23
00115 #define NUX_F24    NUX_VK_F24
00116 
00117 // These flags describe the mouse button responsible for the mouse event.
00118 // They are valid only for the current frame.
00119 // Go in mouse_state.
00120 #define NUX_EVENT_BUTTON1_UP        0x00001000
00121 #define NUX_EVENT_BUTTON2_UP        0x00002000
00122 #define NUX_EVENT_BUTTON3_UP        0x00004000
00123 #define NUX_EVENT_BUTTON4_UP        0x00008000
00124 
00125 #define NUX_EVENT_BUTTON1_DOWN      0x00010000
00126 #define NUX_EVENT_BUTTON2_DOWN      0x00020000
00127 #define NUX_EVENT_BUTTON3_DOWN      0x00040000
00128 #define NUX_EVENT_BUTTON4_DOWN      0x00080000
00129 
00130 #define NUX_EVENT_BUTTON1           0x00010000
00131 #define NUX_EVENT_BUTTON2           0x00020000
00132 #define NUX_EVENT_BUTTON3           0x00040000
00133 #define NUX_EVENT_BUTTON4           0x00080000
00134 
00135 #define NUX_EVENT_MOUSEWHEEL        0x00100000
00136 // These flags describe the state of the mouse buttons.
00137 // They persist over several frame until the mouse buttons change state.
00138 // Go in mouse_state.
00139 #define NUX_STATE_BUTTON1_DOWN      0x01000000
00140 #define NUX_STATE_BUTTON2_DOWN      0x02000000
00141 #define NUX_STATE_BUTTON3_DOWN      0x04000000
00142 #define NUX_STATE_BUTTON4_DOWN      0x08000000
00143 
00144 // These flags are set if the event is a double click.
00145 // They are valid only for the current frame.
00146 // Go in mouse_state.
00147 #define NUX_EVENT_BUTTON1_DBLCLICK  0x10000000
00148 #define NUX_EVENT_BUTTON2_DBLCLICK  0x20000000
00149 #define NUX_EVENT_BUTTON3_DBLCLICK  0x40000000
00150 
00151 #define NUX_MOUSEWHEEL_DELTA  120 // 120 correspond to one notch of the mouse wheel
00152 
00153   typedef unsigned char uchar;
00154   typedef unsigned long ulong;
00155 
00156   struct EventToNameStruct
00157   {
00158     int event;
00159     const char *EventName;
00160   };
00161 
00162   enum MouseButton
00163   {
00164     MOUSE_BUTTON_INVALID = 0,
00165     MOUSE_BUTTON1 = 1,
00166     MOUSE_BUTTON2 = 2,
00167     MOUSE_BUTTON3 = 3,
00168     MOUSE_BUTTON4 = 4,
00169     MOUSE_BUTTON5 = 5,
00170     MOUSE_BUTTON6 = 6,
00171     MOUSE_BUTTON7 = 7,
00172 
00173     // The following values are deprecated. Use the ones above.
00174     NUX_INVALID_MOUSE_BUTTON = MOUSE_BUTTON_INVALID,
00175     NUX_MOUSE_BUTTON1 = MOUSE_BUTTON1,
00176     NUX_MOUSE_BUTTON2 = MOUSE_BUTTON2,
00177     NUX_MOUSE_BUTTON3 = MOUSE_BUTTON3,
00178     NUX_MOUSE_BUTTON4 = MOUSE_BUTTON4,
00179     NUX_MOUSE_BUTTON5 = MOUSE_BUTTON5,
00180     NUX_MOUSE_BUTTON6 = MOUSE_BUTTON6,
00181     NUX_LEFT_MOUSE    = NUX_MOUSE_BUTTON1,   // Deprecated
00182     NUX_MIDDLE_MOUSE  = NUX_MOUSE_BUTTON2, // Deprecated
00183     NUX_RIGHT_MOUSE   = NUX_MOUSE_BUTTON3,  // Deprecated
00184   };
00185 
00186   enum KeyModifier
00187   {
00188     KEY_MODIFIER_SHIFT       = 0x00010000,
00189     KEY_MODIFIER_CAPS_LOCK   = 0x00020000,
00190     KEY_MODIFIER_CTRL        = 0x00040000,
00191     KEY_MODIFIER_ALT         = 0x00080000,
00192     KEY_MODIFIER_NUMLOCK     = 0x00100000,
00193     KEY_MODIFIER_SUPER       = 0x00200000,
00194     KEY_MODIFIER_SCROLLLOCK  = 0x00400000,
00195 
00196     // The following values are deprecated. Use the ones above.
00197     NUX_STATE_SHIFT       = KEY_MODIFIER_SHIFT,
00198     NUX_STATE_CAPS_LOCK   = KEY_MODIFIER_CAPS_LOCK,
00199     NUX_STATE_CTRL        = KEY_MODIFIER_CTRL,
00200     NUX_STATE_ALT         = KEY_MODIFIER_ALT,
00201     NUX_STATE_NUMLOCK     = KEY_MODIFIER_NUMLOCK,
00202     NUX_STATE_SUPER       = KEY_MODIFIER_SUPER,
00203     NUX_STATE_SCROLLLOCK  = KEY_MODIFIER_SCROLLLOCK,
00204   };
00205 
00206   enum EventType
00207   {
00208     EVENT_NONE         = 0,
00209     EVENT_MOUSE_DOWN,
00210     EVENT_MOUSE_UP,
00211     EVENT_MOUSE_MOVE,
00212     EVENT_MOUSE_DOUBLECLICK,
00213     EVENT_MOUSE_WHEEL,
00214     EVENT_KEY_DOWN,
00215     EVENT_KEY_UP,
00216     EVENT_WINDOW_SIZE_CONFIGURATION,
00217     EVENT_WINDOW_MAP,
00218     EVENT_WINDOW_UNMAP,
00219     EVENT_NC_WINDOW_CONFIGURATION,  
00220     EVENT_WINDOW_ENTER_FOCUS,
00221     EVENT_WINDOW_EXIT_FOCUS,
00222     EVENT_WINDOW_DIRTY,
00223     EVENT_WINDOW_MOUSELEAVE,
00224     EVENT_DESTROY_WINDOW,
00225     EVENT_TERMINATE_APP,
00226     EVENT_TAKE_FOCUS, // ClientMessage for window with WM_TAKE_FOCUS protocol-atom set
00227     EVENT_DND_MOVE,
00228     EVENT_DND_DROP,
00229     EVENT_DND_ENTER,  
00230     EVENT_DND_LEAVE,  
00231     EVENT_DND_ENTER_WINDOW,  
00232     EVENT_DND_LEAVE_WINDOW,   
00233 
00234 
00235     // The following values are deprecated. Use the ones above.
00236     NUX_NO_EVENT                  = EVENT_NONE,
00237     NUX_MOUSE_PRESSED             = EVENT_MOUSE_DOWN,
00238     NUX_MOUSE_RELEASED            = EVENT_MOUSE_UP,
00239     NUX_MOUSE_MOVE                = EVENT_MOUSE_MOVE,
00240     NUX_MOUSE_DOUBLECLICK         = EVENT_MOUSE_DOUBLECLICK,
00241     NUX_MOUSE_WHEEL               = EVENT_MOUSE_WHEEL,
00242     NUX_MOUSEWHEEL                = EVENT_MOUSE_WHEEL, 
00243     NUX_KEYDOWN                   = EVENT_KEY_DOWN,
00244     NUX_KEYUP                     = EVENT_KEY_UP,
00245     NUX_SIZE_CONFIGURATION        = EVENT_WINDOW_SIZE_CONFIGURATION,
00246     NUX_WINDOW_MAP                = EVENT_WINDOW_MAP,
00247     NUX_WINDOW_UNMAP              = EVENT_WINDOW_UNMAP,
00248     NUX_NC_WINDOW_CONFIGURATION   = EVENT_NC_WINDOW_CONFIGURATION,
00249     NUX_WINDOW_ENTER_FOCUS        = EVENT_WINDOW_ENTER_FOCUS,
00250     NUX_WINDOW_EXIT_FOCUS         = EVENT_WINDOW_EXIT_FOCUS,
00251     NUX_WINDOW_DIRTY              = EVENT_WINDOW_DIRTY,
00252     NUX_WINDOW_MOUSELEAVE         = EVENT_WINDOW_MOUSELEAVE,
00253     NUX_DESTROY_WINDOW            = EVENT_DESTROY_WINDOW,
00254     NUX_TERMINATE_APP             = EVENT_TERMINATE_APP,
00255     NUX_TAKE_FOCUS                = EVENT_TAKE_FOCUS,         // ClientMessage for window with WM_TAKE_FOCUS protocol-atom set
00256     NUX_DND_MOVE                  = EVENT_DND_MOVE,
00257     NUX_DND_DROP                  = EVENT_DND_DROP,
00258     NUX_DND_ENTER                 = EVENT_DND_ENTER,          
00259     NUX_DND_LEAVE                 = EVENT_DND_LEAVE,          
00260     NUX_DND_ENTER_WINDOW          = EVENT_DND_ENTER_WINDOW,   
00261     NUX_DND_LEAVE_WINDOW          = EVENT_DND_LEAVE_WINDOW,   
00262   };
00263 
00264   typedef EventType NuxEventType; // NuxEventType is deprecated.
00265 
00267 
00275   MouseButton GetEventButton(unsigned long button_state);
00276 
00278 
00286   bool GetButtonState(unsigned long button_state, MouseButton button);
00287 
00289 
00297   bool GetKeyModifierState(unsigned long key_modifiers_states, KeyModifier key_modifier);
00298 
00299   #define NUX_EVENT_TEXT_BUFFER_SIZE 16
00300 
00302   class Event
00303   {
00304   public:
00305     Event();
00306 
00307     // Because an event is save in event_type instead of calling immediately the handling function,
00308     // we must clear the previous event each time before we test for new event in Gfx_OpenGLImpl::get_event.
00309     void Reset();
00310 
00311     int GetX() const;
00312     int GetY() const;
00313     int GetRootX() const;
00314     int GetRootY() const;
00315     int GetDeltaX() const;
00316     int GetDeltaY() const;
00317     unsigned long GetKeyState()  const;
00318     unsigned long GetMouseState() const;
00319 
00320     bool IsShiftDown() const;
00321     bool IsControlDown() const;
00322     bool IsCapsLockDown() const;
00323     bool IsAltDown() const;
00324     bool IsNumLockDown() const;
00325     bool IsScrollLockDown() const;
00326     bool IsSuperKeyDown() const;
00327 
00329 
00336     MouseButton GetEventButton() const;
00337 
00339 
00346     bool GetButtonState(MouseButton button) const;
00347 
00349 
00356     bool GetKeyModifierState(KeyModifier key_modifier) const;
00357 
00359 
00363     unsigned long GetKeySym() const;
00364     unsigned short GetKeyRepeatCount() const;
00365     const char* GetText() const;
00366 
00368 
00373     unsigned long GetVirtualKeyState(unsigned long VirtualKey) const;
00374 
00375     unsigned long VirtualKeycodeState[NUX_MAX_VK];
00376     int width, height;
00377     unsigned int ascii_code;
00378     int virtual_code;
00379 
00380     int x;
00381     int y;
00382     int x_root;
00383     int y_root;
00384     int dx;
00385     int dy;
00386     int clicks;
00387     int is_click;
00388 
00389 #if defined(NUX_OS_WINDOWS)
00390     int win32_keycode; // Not used. Just a place holder.
00391     int win32_keysym;
00392 #endif
00393 
00394 #if defined(NUX_OS_LINUX)
00395     Time          x11_timestamp;  
00396     Window        x11_window;     
00397     unsigned int  x11_key_state;  
00398     unsigned int  x11_keycode;    
00399     KeySym        x11_keysym;     
00400 #endif
00401 
00402     int wheel_delta;              
00403 
00404     char            text[NUX_EVENT_TEXT_BUFFER_SIZE];
00405     unsigned long   key_modifiers;    
00406     unsigned long   mouse_state;
00407     unsigned short  key_repeat_count; 
00408     EventType    type;
00409   };
00410 };
00411 
00412 #endif // EVENTS_H