nux-0.9.46
|
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 #define NUX_LEFT_MOUSE 1 00118 #define NUX_MIDDLE_MOUSE 2 00119 #define NUX_RIGHT_MOUSE 3 00120 00121 // Key States. Set in e_key_modifiers. 00122 #define NUX_STATE_SHIFT 0x00010000 00123 #define NUX_STATE_CAPS_LOCK 0x00020000 00124 #define NUX_STATE_CTRL 0x00040000 00125 #define NUX_STATE_ALT 0x00080000 00126 #define NUX_STATE_NUMLOCK 0x00100000 // most X servers do this? 00127 #define NUX_STATE_META 0x00400000 // correct for XFree86 00128 #define NUX_STATE_SCROLLLOCK 0x00800000 // correct for XFree86 00129 00130 // These flags describe the mouse button responsible for the mouse event. 00131 // They are valid only for the current frame. 00132 // Go in e_mouse_state. 00133 #define NUX_EVENT_BUTTON1_UP 0x00001000 00134 #define NUX_EVENT_BUTTON2_UP 0x00002000 00135 #define NUX_EVENT_BUTTON3_UP 0x00004000 00136 #define NUX_EVENT_BUTTON4_UP 0x00008000 00137 00138 #define NUX_EVENT_BUTTON1_DOWN 0x00010000 00139 #define NUX_EVENT_BUTTON2_DOWN 0x00020000 00140 #define NUX_EVENT_BUTTON3_DOWN 0x00040000 00141 #define NUX_EVENT_BUTTON4_DOWN 0x00080000 00142 00143 #define NUX_EVENT_BUTTON1 0x00010000 00144 #define NUX_EVENT_BUTTON2 0x00020000 00145 #define NUX_EVENT_BUTTON3 0x00040000 00146 #define NUX_EVENT_BUTTON4 0x00080000 00147 00148 #define NUX_EVENT_MOUSEWHEEL 0x00100000 00149 // These flags describe the state of the mouse buttons. 00150 // They persist over several frame until the mouse buttons change state. 00151 // Go in e_mouse_state. 00152 #define NUX_STATE_BUTTON1_DOWN 0x01000000 00153 #define NUX_STATE_BUTTON2_DOWN 0x02000000 00154 #define NUX_STATE_BUTTON3_DOWN 0x04000000 00155 #define NUX_STATE_BUTTON4_DOWN 0x08000000 00156 00157 // These flags are set if the event is a double click. 00158 // They are valid only for the current frame. 00159 // Go in e_mouse_state. 00160 #define NUX_EVENT_BUTTON1_DBLCLICK 0x10000000 00161 #define NUX_EVENT_BUTTON2_DBLCLICK 0x20000000 00162 #define NUX_EVENT_BUTTON3_DBLCLICK 0x40000000 00163 00164 #define NUX_MOUSEWHEEL_DELTA 120 // 120 correspond to one notch of the mouse wheel 00165 00166 typedef unsigned char uchar; 00167 typedef unsigned long ulong; 00168 00169 struct EventToNameStruct 00170 { 00171 int event; 00172 const TCHAR *EventName; 00173 }; 00174 00175 enum 00176 { 00177 // events 00178 NUX_NO_EVENT = 0, 00179 NUX_MOUSE_PRESSED, 00180 NUX_MOUSE_RELEASED, 00181 NUX_MOUSE_DOUBLECLICK, 00182 NUX_KEYDOWN, 00183 NUX_KEYUP, 00184 NUX_MOUSE_MOVE, 00185 NUX_SIZE_CONFIGURATION, 00186 NUX_WINDOW_MAP, 00187 NUX_WINDOW_UNMAP, 00188 NUX_WINDOW_CONFIGURATION, 00189 NUX_WINDOW_ENTER_FOCUS, 00190 NUX_WINDOW_EXIT_FOCUS, 00191 NUX_WINDOW_DIRTY, 00192 NUX_WINDOW_MOUSELEAVE, 00193 NUX_MOUSE_WHEEL, 00194 NUX_MOUSEWHEEL = NUX_MOUSE_WHEEL, 00195 NUX_DESTROY_WINDOW, 00196 NUX_TERMINATE_APP, 00197 NUX_TAKE_FOCUS, // ClientMessage for window with WM_TAKE_FOCUS protocol-atom set 00198 NUX_DND_MOVE, 00199 NUX_DND_DROP, 00200 NUX_DND_ENTER, 00201 NUX_DND_LEAVE, 00202 NUX_DND_ENTER_WINDOW, 00203 NUX_DND_LEAVE_WINDOW, 00204 }; 00205 00206 unsigned long GetEventButton(unsigned long button_state); 00207 bool GetButtonState(unsigned long button_state, int button); 00208 00209 #define NUX_EVENT_TEXT_BUFFER_SIZE 16 00210 00212 class Event 00213 { 00214 public: 00215 Event (); 00216 00217 // Because an event is save in e_event instead of calling immediately the handling function, 00218 // we must clear the previous event each time before we test for new event in Gfx_OpenGLImpl::get_event. 00219 void Reset(); 00220 00221 int GetX() const; 00222 int GetY() const; 00223 int GetRootX() const; 00224 int GetRootY() const; 00225 int GetDeltaX() const; 00226 int GetDeltaY() const; 00227 unsigned long GetKeyState() const; 00228 unsigned long GetMouseState() const; 00229 00234 unsigned long GetEventButton() const; 00235 00241 bool GetButtonState(int button) const; 00242 00243 00244 00246 00250 unsigned long GetKeySym() const; 00251 unsigned short GetKeyRepeatCount() const; 00252 const TCHAR* GetText() const; 00253 00255 00260 unsigned long GetVirtualKeyState (unsigned long VirtualKey) const; 00261 00262 unsigned long VirtualKeycodeState[NUX_MAX_VK]; 00263 int width, height; 00264 unsigned int ascii_code; 00265 int virtual_code; 00266 00267 int e_x; 00268 int e_y; 00269 int e_x_root; 00270 int e_y_root; 00271 int e_dx; 00272 int e_dy; 00273 int e_clicks; 00274 int e_is_click; 00275 00276 #if defined(NUX_OS_LINUX) 00277 Time e_x11_timestamp; 00278 Window e_x11_window; 00279 #endif 00280 00281 00282 int e_x11_keycode; 00283 int e_keysym; 00284 int e_wheeldelta; 00285 00286 TCHAR e_text [NUX_EVENT_TEXT_BUFFER_SIZE]; 00287 unsigned long e_key_modifiers; // key modifiers 00288 unsigned long e_mouse_state; 00289 unsigned short e_key_repeat_count; // number of time a key is repeated; 00290 int e_length; 00291 unsigned long e_event; 00292 }; 00293 00294 typedef Event IEvent; 00295 } 00296 00297 #endif // EVENTS_H