nux-1.14.0
|
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_PAGE_UP (0xff00 | NUX_VK_PAGE_UP) 00081 // #define NUX_KP_PAGE_DOWN (0xff00 | NUX_VK_PAGE_DOWN) 00082 // #define NUX_KP_END (0xff00 | NUX_VK_END) 00083 // #define NUX_KP_HOME (0xff00 | NUX_VK_HOME) 00084 // #define NUX_KP_LEFT (0xff00 | NUX_VK_LEFT) 00085 // #define NUX_KP_UP (0xff00 | NUX_VK_UP) 00086 // #define NUX_KP_RIGHT (0xff00 | NUX_VK_RIGHT) 00087 // #define NUX_KP_DOWN (0xff00 | NUX_VK_DOWN) 00088 // 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 enum MouseButton 00118 { 00119 NUX_INVALID_MOUSE_BUTTON = 0, 00120 NUX_MOUSE_BUTTON1 = 1, 00121 NUX_MOUSE_BUTTON2 = 2, 00122 NUX_MOUSE_BUTTON3 = 3, 00123 NUX_MOUSE_BUTTON4 = 4, 00124 NUX_MOUSE_BUTTON5 = 5, 00125 NUX_MOUSE_BUTTON6 = 6, 00126 NUX_LEFT_MOUSE = NUX_MOUSE_BUTTON1, // Deprecated 00127 NUX_MIDDLE_MOUSE = NUX_MOUSE_BUTTON2, // Deprecated 00128 NUX_RIGHT_MOUSE = NUX_MOUSE_BUTTON3, // Deprecated 00129 }; 00130 00131 enum KeyModifier 00132 { 00133 NUX_STATE_SHIFT = 0x00010000, 00134 NUX_STATE_CAPS_LOCK = 0x00020000, 00135 NUX_STATE_CTRL = 0x00040000, 00136 NUX_STATE_ALT = 0x00080000, 00137 NUX_STATE_NUMLOCK = 0x00100000, 00138 NUX_STATE_META = 0x00400000, 00139 NUX_STATE_SCROLLLOCK = 0x00800000, 00140 }; 00141 00142 // These flags describe the mouse button responsible for the mouse event. 00143 // They are valid only for the current frame. 00144 // Go in e_mouse_state. 00145 #define NUX_EVENT_BUTTON1_UP 0x00001000 00146 #define NUX_EVENT_BUTTON2_UP 0x00002000 00147 #define NUX_EVENT_BUTTON3_UP 0x00004000 00148 #define NUX_EVENT_BUTTON4_UP 0x00008000 00149 00150 #define NUX_EVENT_BUTTON1_DOWN 0x00010000 00151 #define NUX_EVENT_BUTTON2_DOWN 0x00020000 00152 #define NUX_EVENT_BUTTON3_DOWN 0x00040000 00153 #define NUX_EVENT_BUTTON4_DOWN 0x00080000 00154 00155 #define NUX_EVENT_BUTTON1 0x00010000 00156 #define NUX_EVENT_BUTTON2 0x00020000 00157 #define NUX_EVENT_BUTTON3 0x00040000 00158 #define NUX_EVENT_BUTTON4 0x00080000 00159 00160 #define NUX_EVENT_MOUSEWHEEL 0x00100000 00161 // These flags describe the state of the mouse buttons. 00162 // They persist over several frame until the mouse buttons change state. 00163 // Go in e_mouse_state. 00164 #define NUX_STATE_BUTTON1_DOWN 0x01000000 00165 #define NUX_STATE_BUTTON2_DOWN 0x02000000 00166 #define NUX_STATE_BUTTON3_DOWN 0x04000000 00167 #define NUX_STATE_BUTTON4_DOWN 0x08000000 00168 00169 // These flags are set if the event is a double click. 00170 // They are valid only for the current frame. 00171 // Go in e_mouse_state. 00172 #define NUX_EVENT_BUTTON1_DBLCLICK 0x10000000 00173 #define NUX_EVENT_BUTTON2_DBLCLICK 0x20000000 00174 #define NUX_EVENT_BUTTON3_DBLCLICK 0x40000000 00175 00176 #define NUX_MOUSEWHEEL_DELTA 120 // 120 correspond to one notch of the mouse wheel 00177 00178 typedef unsigned char uchar; 00179 typedef unsigned long ulong; 00180 00181 struct EventToNameStruct 00182 { 00183 int event; 00184 const TCHAR *EventName; 00185 }; 00186 00187 enum NuxEventType 00188 { 00189 // events 00190 NUX_NO_EVENT = 0, 00191 NUX_MOUSE_PRESSED, 00192 NUX_MOUSE_RELEASED, 00193 NUX_MOUSE_MOVE, 00194 NUX_MOUSE_DOUBLECLICK, 00195 NUX_MOUSE_WHEEL, 00196 NUX_MOUSEWHEEL = NUX_MOUSE_WHEEL, 00197 NUX_KEYDOWN, 00198 NUX_KEYUP, 00199 NUX_SIZE_CONFIGURATION, 00200 NUX_WINDOW_MAP, 00201 NUX_WINDOW_UNMAP, 00202 NUX_WINDOW_CONFIGURATION, 00203 NUX_WINDOW_ENTER_FOCUS, 00204 NUX_WINDOW_EXIT_FOCUS, 00205 NUX_WINDOW_DIRTY, 00206 NUX_WINDOW_MOUSELEAVE, 00207 NUX_DESTROY_WINDOW, 00208 NUX_TERMINATE_APP, 00209 NUX_TAKE_FOCUS, // ClientMessage for window with WM_TAKE_FOCUS protocol-atom set 00210 NUX_DND_MOVE, 00211 NUX_DND_DROP, 00212 NUX_DND_ENTER, 00213 NUX_DND_LEAVE, 00214 NUX_DND_ENTER_WINDOW, 00215 NUX_DND_LEAVE_WINDOW, 00216 }; 00217 00219 00227 MouseButton GetEventButton(unsigned long button_state); 00228 00230 00238 bool GetButtonState(unsigned long button_state, MouseButton button); 00239 00241 00249 bool GetKeyModifierState(unsigned long key_modifiers_states, KeyModifier key_modifier); 00250 00251 #define NUX_EVENT_TEXT_BUFFER_SIZE 16 00252 00254 class Event 00255 { 00256 public: 00257 Event (); 00258 00259 // Because an event is save in e_event instead of calling immediately the handling function, 00260 // we must clear the previous event each time before we test for new event in Gfx_OpenGLImpl::get_event. 00261 void Reset(); 00262 00263 int GetX() const; 00264 int GetY() const; 00265 int GetRootX() const; 00266 int GetRootY() const; 00267 int GetDeltaX() const; 00268 int GetDeltaY() const; 00269 unsigned long GetKeyState() const; 00270 unsigned long GetMouseState() const; 00271 00273 00280 MouseButton GetEventButton() const; 00281 00283 00290 bool GetButtonState(MouseButton button) const; 00291 00293 00300 bool GetKeyModifierState(KeyModifier key_modifier) const; 00301 00303 00307 unsigned long GetKeySym() const; 00308 unsigned short GetKeyRepeatCount() const; 00309 const TCHAR* GetText() const; 00310 00312 00317 unsigned long GetVirtualKeyState (unsigned long VirtualKey) const; 00318 00319 unsigned long VirtualKeycodeState[NUX_MAX_VK]; 00320 int width, height; 00321 unsigned int ascii_code; 00322 int virtual_code; 00323 00324 int e_x; 00325 int e_y; 00326 int e_x_root; 00327 int e_y_root; 00328 int e_dx; 00329 int e_dy; 00330 int e_clicks; 00331 int e_is_click; 00332 00333 #if defined(NUX_OS_LINUX) 00334 Time e_x11_timestamp; 00335 Window e_x11_window; 00336 unsigned int e_x11_state; 00337 #endif 00338 00339 00340 int e_x11_keycode; 00341 int e_keysym; 00342 int e_wheeldelta; 00343 00344 TCHAR e_text [NUX_EVENT_TEXT_BUFFER_SIZE]; 00345 unsigned long e_key_modifiers; // key modifiers 00346 unsigned long e_mouse_state; 00347 unsigned short e_key_repeat_count; // number of time a key is repeated; 00348 int e_length; 00349 NuxEventType e_event; 00350 }; 00351 00352 typedef Event IEvent; 00353 }; 00354 00355 #endif // EVENTS_H