| 1 | /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield |
|---|
| 2 | * |
|---|
| 3 | * This library is open source and may be redistributed and/or modified under |
|---|
| 4 | * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or |
|---|
| 5 | * (at your option) any later version. The full license is in LICENSE file |
|---|
| 6 | * included with this distribution, and on the openscenegraph.org website. |
|---|
| 7 | * |
|---|
| 8 | * This library is distributed in the hope that it will be useful, |
|---|
| 9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 11 | * OpenSceneGraph Public License for more details. |
|---|
| 12 | */ |
|---|
| 13 | |
|---|
| 14 | #ifndef OSGGA_EVENT |
|---|
| 15 | #define OSGGA_EVENT 1 |
|---|
| 16 | |
|---|
| 17 | #include <osg/Object> |
|---|
| 18 | #include <osg/Matrix> |
|---|
| 19 | #include <osg/GraphicsContext> |
|---|
| 20 | #include <osgGA/Export> |
|---|
| 21 | |
|---|
| 22 | namespace osgGA{ |
|---|
| 23 | |
|---|
| 24 | |
|---|
| 25 | /** Event class for storing Keyboard, mouse and window events. |
|---|
| 26 | */ |
|---|
| 27 | class OSGGA_EXPORT GUIEventAdapter : public osg::Object |
|---|
| 28 | { |
|---|
| 29 | public: |
|---|
| 30 | |
|---|
| 31 | enum MouseButtonMask { |
|---|
| 32 | LEFT_MOUSE_BUTTON = 1<<0, |
|---|
| 33 | MIDDLE_MOUSE_BUTTON = 1<<1, |
|---|
| 34 | RIGHT_MOUSE_BUTTON = 1<<2 |
|---|
| 35 | }; |
|---|
| 36 | |
|---|
| 37 | enum EventType { |
|---|
| 38 | NONE = 0, |
|---|
| 39 | PUSH = 1<<0, |
|---|
| 40 | RELEASE = 1<<1, |
|---|
| 41 | DOUBLECLICK = 1<<2, |
|---|
| 42 | DRAG = 1<<3, |
|---|
| 43 | MOVE = 1<<4, |
|---|
| 44 | KEYDOWN = 1<<5, |
|---|
| 45 | KEYUP = 1<<6, |
|---|
| 46 | FRAME = 1<<7, |
|---|
| 47 | RESIZE = 1<<8, |
|---|
| 48 | SCROLL = 1<<9, |
|---|
| 49 | PEN_PRESSURE = 1<<10, |
|---|
| 50 | PEN_ORIENTATION = 1<<11, |
|---|
| 51 | PEN_PROXIMITY_ENTER = 1<<12, |
|---|
| 52 | PEN_PROXIMITY_LEAVE = 1<<13, |
|---|
| 53 | CLOSE_WINDOW = 1<<14, |
|---|
| 54 | QUIT_APPLICATION = 1<<15, |
|---|
| 55 | USER = 1<<16 |
|---|
| 56 | }; |
|---|
| 57 | |
|---|
| 58 | enum KeySymbol |
|---|
| 59 | { |
|---|
| 60 | KEY_Space = 0x20, |
|---|
| 61 | |
|---|
| 62 | KEY_0 = '0', |
|---|
| 63 | KEY_1 = '1', |
|---|
| 64 | KEY_2 = '2', |
|---|
| 65 | KEY_3 = '3', |
|---|
| 66 | KEY_4 = '4', |
|---|
| 67 | KEY_5 = '5', |
|---|
| 68 | KEY_6 = '6', |
|---|
| 69 | KEY_7 = '7', |
|---|
| 70 | KEY_8 = '8', |
|---|
| 71 | KEY_9 = '9', |
|---|
| 72 | KEY_A = 'a', |
|---|
| 73 | KEY_B = 'b', |
|---|
| 74 | KEY_C = 'c', |
|---|
| 75 | KEY_D = 'd', |
|---|
| 76 | KEY_E = 'e', |
|---|
| 77 | KEY_F = 'f', |
|---|
| 78 | KEY_G = 'g', |
|---|
| 79 | KEY_H = 'h', |
|---|
| 80 | KEY_I = 'i', |
|---|
| 81 | KEY_J = 'j', |
|---|
| 82 | KEY_K = 'k', |
|---|
| 83 | KEY_L = 'l', |
|---|
| 84 | KEY_M = 'm', |
|---|
| 85 | KEY_N = 'n', |
|---|
| 86 | KEY_O = 'o', |
|---|
| 87 | KEY_P = 'p', |
|---|
| 88 | KEY_Q = 'q', |
|---|
| 89 | KEY_R = 'r', |
|---|
| 90 | KEY_S = 's', |
|---|
| 91 | KEY_T = 't', |
|---|
| 92 | KEY_U = 'u', |
|---|
| 93 | KEY_V = 'v', |
|---|
| 94 | KEY_W = 'w', |
|---|
| 95 | KEY_X = 'x', |
|---|
| 96 | KEY_Y = 'y', |
|---|
| 97 | KEY_Z = 'z', |
|---|
| 98 | |
|---|
| 99 | KEY_Exclaim = 0x21, |
|---|
| 100 | KEY_Quotedbl = 0x22, |
|---|
| 101 | KEY_Hash = 0x23, |
|---|
| 102 | KEY_Dollar = 0x24, |
|---|
| 103 | KEY_Ampersand = 0x26, |
|---|
| 104 | KEY_Quote = 0x27, |
|---|
| 105 | KEY_Leftparen = 0x28, |
|---|
| 106 | KEY_Rightparen = 0x29, |
|---|
| 107 | KEY_Asterisk = 0x2A, |
|---|
| 108 | KEY_Plus = 0x2B, |
|---|
| 109 | KEY_Comma = 0x2C, |
|---|
| 110 | KEY_Minus = 0x2D, |
|---|
| 111 | KEY_Period = 0x2E, |
|---|
| 112 | KEY_Slash = 0x2F, |
|---|
| 113 | KEY_Colon = 0x3A, |
|---|
| 114 | KEY_Semicolon = 0x3B, |
|---|
| 115 | KEY_Less = 0x3C, |
|---|
| 116 | KEY_Equals = 0x3D, |
|---|
| 117 | KEY_Greater = 0x3E, |
|---|
| 118 | KEY_Question = 0x3F, |
|---|
| 119 | KEY_At = 0x40, |
|---|
| 120 | KEY_Leftbracket = 0x5B, |
|---|
| 121 | KEY_Backslash = 0x5C, |
|---|
| 122 | KEY_Rightbracket = 0x5D, |
|---|
| 123 | KEY_Caret = 0x5E, |
|---|
| 124 | KEY_Underscore = 0x5F, |
|---|
| 125 | KEY_Backquote = 0x60, |
|---|
| 126 | |
|---|
| 127 | KEY_BackSpace = 0xFF08, /* back space, back char */ |
|---|
| 128 | KEY_Tab = 0xFF09, |
|---|
| 129 | KEY_Linefeed = 0xFF0A, /* Linefeed, LF */ |
|---|
| 130 | KEY_Clear = 0xFF0B, |
|---|
| 131 | KEY_Return = 0xFF0D, /* Return, enter */ |
|---|
| 132 | KEY_Pause = 0xFF13, /* Pause, hold */ |
|---|
| 133 | KEY_Scroll_Lock = 0xFF14, |
|---|
| 134 | KEY_Sys_Req = 0xFF15, |
|---|
| 135 | KEY_Escape = 0xFF1B, |
|---|
| 136 | KEY_Delete = 0xFFFF, /* Delete, rubout */ |
|---|
| 137 | |
|---|
| 138 | |
|---|
| 139 | /* Cursor control & motion */ |
|---|
| 140 | |
|---|
| 141 | KEY_Home = 0xFF50, |
|---|
| 142 | KEY_Left = 0xFF51, /* Move left, left arrow */ |
|---|
| 143 | KEY_Up = 0xFF52, /* Move up, up arrow */ |
|---|
| 144 | KEY_Right = 0xFF53, /* Move right, right arrow */ |
|---|
| 145 | KEY_Down = 0xFF54, /* Move down, down arrow */ |
|---|
| 146 | KEY_Prior = 0xFF55, /* Prior, previous */ |
|---|
| 147 | KEY_Page_Up = 0xFF55, |
|---|
| 148 | KEY_Next = 0xFF56, /* Next */ |
|---|
| 149 | KEY_Page_Down = 0xFF56, |
|---|
| 150 | KEY_End = 0xFF57, /* EOL */ |
|---|
| 151 | KEY_Begin = 0xFF58, /* BOL */ |
|---|
| 152 | |
|---|
| 153 | |
|---|
| 154 | /* Misc Functions */ |
|---|
| 155 | |
|---|
| 156 | KEY_Select = 0xFF60, /* Select, mark */ |
|---|
| 157 | KEY_Print = 0xFF61, |
|---|
| 158 | KEY_Execute = 0xFF62, /* Execute, run, do */ |
|---|
| 159 | KEY_Insert = 0xFF63, /* Insert, insert here */ |
|---|
| 160 | KEY_Undo = 0xFF65, /* Undo, oops */ |
|---|
| 161 | KEY_Redo = 0xFF66, /* redo, again */ |
|---|
| 162 | KEY_Menu = 0xFF67, /* On Windows, this is VK_APPS, the context-menu key */ |
|---|
| 163 | KEY_Find = 0xFF68, /* Find, search */ |
|---|
| 164 | KEY_Cancel = 0xFF69, /* Cancel, stop, abort, exit */ |
|---|
| 165 | KEY_Help = 0xFF6A, /* Help */ |
|---|
| 166 | KEY_Break = 0xFF6B, |
|---|
| 167 | KEY_Mode_switch = 0xFF7E, /* Character set switch */ |
|---|
| 168 | KEY_Script_switch = 0xFF7E, /* Alias for mode_switch */ |
|---|
| 169 | KEY_Num_Lock = 0xFF7F, |
|---|
| 170 | |
|---|
| 171 | /* Keypad Functions, keypad numbers cleverly chosen to map to ascii */ |
|---|
| 172 | |
|---|
| 173 | KEY_KP_Space = 0xFF80, /* space */ |
|---|
| 174 | KEY_KP_Tab = 0xFF89, |
|---|
| 175 | KEY_KP_Enter = 0xFF8D, /* enter */ |
|---|
| 176 | KEY_KP_F1 = 0xFF91, /* PF1, KP_A, ... */ |
|---|
| 177 | KEY_KP_F2 = 0xFF92, |
|---|
| 178 | KEY_KP_F3 = 0xFF93, |
|---|
| 179 | KEY_KP_F4 = 0xFF94, |
|---|
| 180 | KEY_KP_Home = 0xFF95, |
|---|
| 181 | KEY_KP_Left = 0xFF96, |
|---|
| 182 | KEY_KP_Up = 0xFF97, |
|---|
| 183 | KEY_KP_Right = 0xFF98, |
|---|
| 184 | KEY_KP_Down = 0xFF99, |
|---|
| 185 | KEY_KP_Prior = 0xFF9A, |
|---|
| 186 | KEY_KP_Page_Up = 0xFF9A, |
|---|
| 187 | KEY_KP_Next = 0xFF9B, |
|---|
| 188 | KEY_KP_Page_Down = 0xFF9B, |
|---|
| 189 | KEY_KP_End = 0xFF9C, |
|---|
| 190 | KEY_KP_Begin = 0xFF9D, |
|---|
| 191 | KEY_KP_Insert = 0xFF9E, |
|---|
| 192 | KEY_KP_Delete = 0xFF9F, |
|---|
| 193 | KEY_KP_Equal = 0xFFBD, /* equals */ |
|---|
| 194 | KEY_KP_Multiply = 0xFFAA, |
|---|
| 195 | KEY_KP_Add = 0xFFAB, |
|---|
| 196 | KEY_KP_Separator = 0xFFAC, /* separator, often comma */ |
|---|
| 197 | KEY_KP_Subtract = 0xFFAD, |
|---|
| 198 | KEY_KP_Decimal = 0xFFAE, |
|---|
| 199 | KEY_KP_Divide = 0xFFAF, |
|---|
| 200 | |
|---|
| 201 | KEY_KP_0 = 0xFFB0, |
|---|
| 202 | KEY_KP_1 = 0xFFB1, |
|---|
| 203 | KEY_KP_2 = 0xFFB2, |
|---|
| 204 | KEY_KP_3 = 0xFFB3, |
|---|
| 205 | KEY_KP_4 = 0xFFB4, |
|---|
| 206 | KEY_KP_5 = 0xFFB5, |
|---|
| 207 | KEY_KP_6 = 0xFFB6, |
|---|
| 208 | KEY_KP_7 = 0xFFB7, |
|---|
| 209 | KEY_KP_8 = 0xFFB8, |
|---|
| 210 | KEY_KP_9 = 0xFFB9, |
|---|
| 211 | |
|---|
| 212 | /* |
|---|
| 213 | * Auxiliary Functions; note the duplicate definitions for left and right |
|---|
| 214 | * function keys; Sun keyboards and a few other manufactures have such |
|---|
| 215 | * function key groups on the left and/or right sides of the keyboard. |
|---|
| 216 | * We've not found a keyboard with more than 35 function keys total. |
|---|
| 217 | */ |
|---|
| 218 | |
|---|
| 219 | KEY_F1 = 0xFFBE, |
|---|
| 220 | KEY_F2 = 0xFFBF, |
|---|
| 221 | KEY_F3 = 0xFFC0, |
|---|
| 222 | KEY_F4 = 0xFFC1, |
|---|
| 223 | KEY_F5 = 0xFFC2, |
|---|
| 224 | KEY_F6 = 0xFFC3, |
|---|
| 225 | KEY_F7 = 0xFFC4, |
|---|
| 226 | KEY_F8 = 0xFFC5, |
|---|
| 227 | KEY_F9 = 0xFFC6, |
|---|
| 228 | KEY_F10 = 0xFFC7, |
|---|
| 229 | KEY_F11 = 0xFFC8, |
|---|
| 230 | KEY_F12 = 0xFFC9, |
|---|
| 231 | KEY_F13 = 0xFFCA, |
|---|
| 232 | KEY_F14 = 0xFFCB, |
|---|
| 233 | KEY_F15 = 0xFFCC, |
|---|
| 234 | KEY_F16 = 0xFFCD, |
|---|
| 235 | KEY_F17 = 0xFFCE, |
|---|
| 236 | KEY_F18 = 0xFFCF, |
|---|
| 237 | KEY_F19 = 0xFFD0, |
|---|
| 238 | KEY_F20 = 0xFFD1, |
|---|
| 239 | KEY_F21 = 0xFFD2, |
|---|
| 240 | KEY_F22 = 0xFFD3, |
|---|
| 241 | KEY_F23 = 0xFFD4, |
|---|
| 242 | KEY_F24 = 0xFFD5, |
|---|
| 243 | KEY_F25 = 0xFFD6, |
|---|
| 244 | KEY_F26 = 0xFFD7, |
|---|
| 245 | KEY_F27 = 0xFFD8, |
|---|
| 246 | KEY_F28 = 0xFFD9, |
|---|
| 247 | KEY_F29 = 0xFFDA, |
|---|
| 248 | KEY_F30 = 0xFFDB, |
|---|
| 249 | KEY_F31 = 0xFFDC, |
|---|
| 250 | KEY_F32 = 0xFFDD, |
|---|
| 251 | KEY_F33 = 0xFFDE, |
|---|
| 252 | KEY_F34 = 0xFFDF, |
|---|
| 253 | KEY_F35 = 0xFFE0, |
|---|
| 254 | |
|---|
| 255 | /* Modifiers */ |
|---|
| 256 | |
|---|
| 257 | KEY_Shift_L = 0xFFE1, /* Left shift */ |
|---|
| 258 | KEY_Shift_R = 0xFFE2, /* Right shift */ |
|---|
| 259 | KEY_Control_L = 0xFFE3, /* Left control */ |
|---|
| 260 | KEY_Control_R = 0xFFE4, /* Right control */ |
|---|
| 261 | KEY_Caps_Lock = 0xFFE5, /* Caps lock */ |
|---|
| 262 | KEY_Shift_Lock = 0xFFE6, /* Shift lock */ |
|---|
| 263 | |
|---|
| 264 | KEY_Meta_L = 0xFFE7, /* Left meta */ |
|---|
| 265 | KEY_Meta_R = 0xFFE8, /* Right meta */ |
|---|
| 266 | KEY_Alt_L = 0xFFE9, /* Left alt */ |
|---|
| 267 | KEY_Alt_R = 0xFFEA, /* Right alt */ |
|---|
| 268 | KEY_Super_L = 0xFFEB, /* Left super */ |
|---|
| 269 | KEY_Super_R = 0xFFEC, /* Right super */ |
|---|
| 270 | KEY_Hyper_L = 0xFFED, /* Left hyper */ |
|---|
| 271 | KEY_Hyper_R = 0xFFEE /* Right hyper */ |
|---|
| 272 | }; |
|---|
| 273 | |
|---|
| 274 | |
|---|
| 275 | enum ModKeyMask |
|---|
| 276 | { |
|---|
| 277 | MODKEY_LEFT_SHIFT = 0x0001, |
|---|
| 278 | MODKEY_RIGHT_SHIFT = 0x0002, |
|---|
| 279 | MODKEY_LEFT_CTRL = 0x0004, |
|---|
| 280 | MODKEY_RIGHT_CTRL = 0x0008, |
|---|
| 281 | MODKEY_LEFT_ALT = 0x0010, |
|---|
| 282 | MODKEY_RIGHT_ALT = 0x0020, |
|---|
| 283 | MODKEY_LEFT_META = 0x0040, |
|---|
| 284 | MODKEY_RIGHT_META = 0x0080, |
|---|
| 285 | MODKEY_LEFT_SUPER = 0x0100, |
|---|
| 286 | MODKEY_RIGHT_SUPER = 0x0200, |
|---|
| 287 | MODKEY_LEFT_HYPER = 0x0400, |
|---|
| 288 | MODKEY_RIGHT_HYPER = 0x0800, |
|---|
| 289 | MODKEY_NUM_LOCK = 0x1000, |
|---|
| 290 | MODKEY_CAPS_LOCK = 0x2000, |
|---|
| 291 | MODKEY_CTRL = (MODKEY_LEFT_CTRL|MODKEY_RIGHT_CTRL), |
|---|
| 292 | MODKEY_SHIFT = (MODKEY_LEFT_SHIFT|MODKEY_RIGHT_SHIFT), |
|---|
| 293 | MODKEY_ALT = (MODKEY_LEFT_ALT|MODKEY_RIGHT_ALT), |
|---|
| 294 | MODKEY_META = (MODKEY_LEFT_META|MODKEY_RIGHT_META), |
|---|
| 295 | MODKEY_SUPER = (MODKEY_LEFT_SUPER|MODKEY_RIGHT_SUPER), |
|---|
| 296 | MODKEY_HYPER = (MODKEY_LEFT_HYPER|MODKEY_RIGHT_HYPER) |
|---|
| 297 | }; |
|---|
| 298 | |
|---|
| 299 | enum MouseYOrientation |
|---|
| 300 | { |
|---|
| 301 | Y_INCREASING_UPWARDS, |
|---|
| 302 | Y_INCREASING_DOWNWARDS |
|---|
| 303 | }; |
|---|
| 304 | |
|---|
| 305 | enum ScrollingMotion |
|---|
| 306 | { |
|---|
| 307 | SCROLL_NONE, |
|---|
| 308 | SCROLL_LEFT, |
|---|
| 309 | SCROLL_RIGHT, |
|---|
| 310 | SCROLL_UP, |
|---|
| 311 | SCROLL_DOWN, |
|---|
| 312 | SCROLL_2D |
|---|
| 313 | }; |
|---|
| 314 | |
|---|
| 315 | enum TabletPointerType |
|---|
| 316 | { |
|---|
| 317 | UNKNOWN = 0, |
|---|
| 318 | PEN, |
|---|
| 319 | PUCK, |
|---|
| 320 | ERASER |
|---|
| 321 | }; |
|---|
| 322 | |
|---|
| 323 | enum TouchPhase |
|---|
| 324 | { |
|---|
| 325 | TOUCH_UNKNOWN, |
|---|
| 326 | TOUCH_BEGAN, |
|---|
| 327 | TOUCH_MOVED, |
|---|
| 328 | TOUCH_STATIONERY, |
|---|
| 329 | TOUCH_ENDED |
|---|
| 330 | }; |
|---|
| 331 | |
|---|
| 332 | class TouchData : public osg::Referenced { |
|---|
| 333 | public: |
|---|
| 334 | struct TouchPoint { |
|---|
| 335 | unsigned int id; |
|---|
| 336 | TouchPhase phase; |
|---|
| 337 | float x, y; |
|---|
| 338 | |
|---|
| 339 | unsigned int tapCount; |
|---|
| 340 | TouchPoint() : id(0), phase(TOUCH_UNKNOWN), x(0.0f), y(0.0f), tapCount(0) {} |
|---|
| 341 | TouchPoint(unsigned int in_id, TouchPhase in_phase, float in_x, float in_y, unsigned int in_tap_count) |
|---|
| 342 | : id(in_id), |
|---|
| 343 | phase(in_phase), |
|---|
| 344 | x(in_x), |
|---|
| 345 | y(in_y), |
|---|
| 346 | tapCount(in_tap_count) |
|---|
| 347 | { |
|---|
| 348 | } |
|---|
| 349 | }; |
|---|
| 350 | |
|---|
| 351 | typedef std::vector<TouchPoint> TouchSet; |
|---|
| 352 | |
|---|
| 353 | typedef TouchSet::iterator iterator; |
|---|
| 354 | typedef TouchSet::const_iterator const_iterator; |
|---|
| 355 | |
|---|
| 356 | TouchData() : osg::Referenced() {} |
|---|
| 357 | |
|---|
| 358 | unsigned int getNumTouchPoints() const { return _touches.size(); } |
|---|
| 359 | |
|---|
| 360 | iterator begin() { return _touches.begin(); } |
|---|
| 361 | const_iterator begin() const { return _touches.begin(); } |
|---|
| 362 | |
|---|
| 363 | iterator end() { return _touches.end(); } |
|---|
| 364 | const_iterator end() const { return _touches.end(); } |
|---|
| 365 | |
|---|
| 366 | const TouchPoint get(unsigned int i) const { return _touches[i]; } |
|---|
| 367 | |
|---|
| 368 | protected: |
|---|
| 369 | |
|---|
| 370 | void addTouchPoint(unsigned int id, TouchPhase phase, float x, float y, unsigned int tap_count) { |
|---|
| 371 | _touches.push_back(TouchPoint(id, phase, x, y, tap_count)); |
|---|
| 372 | } |
|---|
| 373 | |
|---|
| 374 | TouchSet _touches; |
|---|
| 375 | |
|---|
| 376 | friend class GUIEventAdapter; |
|---|
| 377 | }; |
|---|
| 378 | |
|---|
| 379 | public: |
|---|
| 380 | |
|---|
| 381 | GUIEventAdapter(); |
|---|
| 382 | |
|---|
| 383 | GUIEventAdapter(const GUIEventAdapter& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); |
|---|
| 384 | |
|---|
| 385 | META_Object(osgGA, GUIEventAdapter); |
|---|
| 386 | |
|---|
| 387 | |
|---|
| 388 | /** Get the accumulated event state singleton. |
|---|
| 389 | * Typically all EventQueue will share this single GUIEventAdapter object for tracking |
|---|
| 390 | * the mouse position, keyboard and mouse masks. */ |
|---|
| 391 | static osg::ref_ptr<GUIEventAdapter>& getAccumulatedEventState(); |
|---|
| 392 | |
|---|
| 393 | |
|---|
| 394 | /** Set whether this event has been handled by an event handler or not.*/ |
|---|
| 395 | void setHandled(bool handled) const { _handled = handled; } |
|---|
| 396 | |
|---|
| 397 | /** Get whether this event has been handled by an event handler or not.*/ |
|---|
| 398 | bool getHandled() const { return _handled; } |
|---|
| 399 | |
|---|
| 400 | /** set the event type. */ |
|---|
| 401 | void setEventType(EventType Type) { _eventType = Type; } |
|---|
| 402 | |
|---|
| 403 | /** get the event type. */ |
|---|
| 404 | virtual EventType getEventType() const { return _eventType; } |
|---|
| 405 | |
|---|
| 406 | /** set time in seconds of event. */ |
|---|
| 407 | void setTime(double time) { _time = time; } |
|---|
| 408 | |
|---|
| 409 | /** get time in seconds of event. */ |
|---|
| 410 | double getTime() const { return _time; } |
|---|
| 411 | |
|---|
| 412 | /** deprecated function for getting time of event. */ |
|---|
| 413 | double time() const { return _time; } |
|---|
| 414 | |
|---|
| 415 | |
|---|
| 416 | void setGraphicsContext(osg::GraphicsContext* context) { _context = context; } |
|---|
| 417 | const osg::GraphicsContext* getGraphicsContext() const { return _context.get(); } |
|---|
| 418 | |
|---|
| 419 | |
|---|
| 420 | /** set window rectangle. */ |
|---|
| 421 | void setWindowRectangle(int x, int y, int width, int height, bool updateMouseRange = true); |
|---|
| 422 | |
|---|
| 423 | /** get window x origin.*/ |
|---|
| 424 | int getWindowX() const { return _windowX; } |
|---|
| 425 | |
|---|
| 426 | /** get window y origin.*/ |
|---|
| 427 | int getWindowY() const { return _windowY; } |
|---|
| 428 | |
|---|
| 429 | /** get window width.*/ |
|---|
| 430 | int getWindowWidth() const { return _windowWidth; } |
|---|
| 431 | |
|---|
| 432 | /** get window height.*/ |
|---|
| 433 | int getWindowHeight() const { return _windowHeight; } |
|---|
| 434 | |
|---|
| 435 | |
|---|
| 436 | /** set key pressed. */ |
|---|
| 437 | inline void setKey(int key) { _key = key; } |
|---|
| 438 | |
|---|
| 439 | /** get key pressed, return -1 if inappropriate for this GUIEventAdapter. */ |
|---|
| 440 | virtual int getKey() const { return _key; } |
|---|
| 441 | |
|---|
| 442 | /** set virtual key pressed. */ |
|---|
| 443 | void setUnmodifiedKey(int key) { _unmodifiedKey = key; } |
|---|
| 444 | |
|---|
| 445 | /** get virtual key pressed. */ |
|---|
| 446 | int getUnmodifiedKey() const { return _unmodifiedKey; } |
|---|
| 447 | |
|---|
| 448 | /** set button pressed/released.*/ |
|---|
| 449 | void setButton(int button) { _button = button; } |
|---|
| 450 | |
|---|
| 451 | /** button pressed/released, return -1 if inappropriate for this GUIEventAdapter.*/ |
|---|
| 452 | int getButton() const { return _button; } |
|---|
| 453 | |
|---|
| 454 | |
|---|
| 455 | /** set mouse input range. */ |
|---|
| 456 | void setInputRange(float Xmin, float Ymin, float Xmax, float Ymax); |
|---|
| 457 | |
|---|
| 458 | /** get mouse minimum x. */ |
|---|
| 459 | float getXmin() const { return _Xmin; } |
|---|
| 460 | |
|---|
| 461 | /** get mouse maximum x. */ |
|---|
| 462 | float getXmax() const { return _Xmax; } |
|---|
| 463 | |
|---|
| 464 | /** get mouse minimum y. */ |
|---|
| 465 | float getYmin() const { return _Ymin; } |
|---|
| 466 | |
|---|
| 467 | /** get mouse maximum y. */ |
|---|
| 468 | float getYmax() const { return _Ymax; } |
|---|
| 469 | |
|---|
| 470 | /** set current mouse x position.*/ |
|---|
| 471 | void setX(float x) { _mx = x; } |
|---|
| 472 | |
|---|
| 473 | /** get current mouse x position.*/ |
|---|
| 474 | float getX() const { return _mx; } |
|---|
| 475 | |
|---|
| 476 | /** set current mouse y position.*/ |
|---|
| 477 | void setY(float y) { _my = y; } |
|---|
| 478 | |
|---|
| 479 | /** get current mouse y position.*/ |
|---|
| 480 | float getY() const { return _my; } |
|---|
| 481 | |
|---|
| 482 | /** |
|---|
| 483 | * return the current mouse x value normalized to the range of -1 to 1. |
|---|
| 484 | * -1 would be the left hand side of the window. |
|---|
| 485 | * 0.0 would be the middle of the window. |
|---|
| 486 | * +1 would be the right hand side of the window. |
|---|
| 487 | */ |
|---|
| 488 | inline float getXnormalized() const { return 2.0f*(getX()-getXmin())/(getXmax()-getXmin())-1.0f; } |
|---|
| 489 | |
|---|
| 490 | /** |
|---|
| 491 | * return the current mouse y value normalized to the range of -1 to 1. |
|---|
| 492 | * -1 would be the bottom of the window. |
|---|
| 493 | * 0.0 would be the middle of the window. |
|---|
| 494 | * +1 would be the top of the window. |
|---|
| 495 | */ |
|---|
| 496 | inline float getYnormalized() const |
|---|
| 497 | { |
|---|
| 498 | if (_mouseYOrientation==Y_INCREASING_UPWARDS) return 2.0f*(getY()-getYmin())/(getYmax()-getYmin())-1.0f; |
|---|
| 499 | else return -(2.0f*(getY()-getYmin())/(getYmax()-getYmin())-1.0f); |
|---|
| 500 | } |
|---|
| 501 | |
|---|
| 502 | /// set mouse-Y orientation (mouse-Y increases upwards or downwards). |
|---|
| 503 | void setMouseYOrientation(MouseYOrientation myo) { _mouseYOrientation = myo; } |
|---|
| 504 | |
|---|
| 505 | /// get mouse-Y orientation (mouse-Y increases upwards or downwards). |
|---|
| 506 | MouseYOrientation getMouseYOrientation() const { return _mouseYOrientation; } |
|---|
| 507 | |
|---|
| 508 | /// set current mouse button state. |
|---|
| 509 | void setButtonMask(int mask) { _buttonMask = mask; } |
|---|
| 510 | |
|---|
| 511 | /// get current mouse button state. |
|---|
| 512 | int getButtonMask() const { return _buttonMask; } |
|---|
| 513 | |
|---|
| 514 | /// set modifier key mask. |
|---|
| 515 | void setModKeyMask(int mask) { _modKeyMask = mask; } |
|---|
| 516 | |
|---|
| 517 | /// get modifier key mask. |
|---|
| 518 | int getModKeyMask() const { return _modKeyMask; } |
|---|
| 519 | |
|---|
| 520 | /// set scrolling motion (for EventType::SCROLL). |
|---|
| 521 | void setScrollingMotion(ScrollingMotion motion) { _scrolling.motion = motion; } |
|---|
| 522 | |
|---|
| 523 | /// get scrolling motion (for EventType::SCROLL). |
|---|
| 524 | ScrollingMotion getScrollingMotion() const { return _scrolling.motion; } |
|---|
| 525 | |
|---|
| 526 | /// set the scrolling delta to x,y and the scrolling motion to SCROLL_2D. |
|---|
| 527 | void setScrollingMotionDelta(float x, float y) { |
|---|
| 528 | _scrolling.motion = SCROLL_2D; |
|---|
| 529 | _scrolling.deltaX = x; |
|---|
| 530 | _scrolling.deltaY = y; |
|---|
| 531 | } |
|---|
| 532 | |
|---|
| 533 | /// get the scrolling x-delta. |
|---|
| 534 | float getScrollingDeltaX() const { return _scrolling.deltaX; } |
|---|
| 535 | |
|---|
| 536 | /// get the scrolling y-delta. |
|---|
| 537 | float getScrollingDeltaY() const { return _scrolling.deltaY; } |
|---|
| 538 | |
|---|
| 539 | |
|---|
| 540 | /// set the tablet pen pressure (range 0..1). |
|---|
| 541 | void setPenPressure(float pressure) { _tabletPen.pressure = pressure; } |
|---|
| 542 | |
|---|
| 543 | /// get the tablet pen pressure (range 0..1). |
|---|
| 544 | float getPenPressure() const { return _tabletPen.pressure; } |
|---|
| 545 | |
|---|
| 546 | /// set the tablet pen tiltX in degrees. |
|---|
| 547 | void setPenTiltX(float tiltX) { _tabletPen.tiltX = tiltX; } |
|---|
| 548 | |
|---|
| 549 | /// get the tablet pen tiltX in degrees. |
|---|
| 550 | float getPenTiltX() const { return _tabletPen.tiltX; } |
|---|
| 551 | |
|---|
| 552 | /// set the tablet pen tiltY in degrees. |
|---|
| 553 | void setPenTiltY(float tiltY) { _tabletPen.tiltY = tiltY; } |
|---|
| 554 | |
|---|
| 555 | /// get the tablet pen tiltY in degrees. |
|---|
| 556 | float getPenTiltY() const { return _tabletPen.tiltY; } |
|---|
| 557 | |
|---|
| 558 | /// set the tablet pen rotation around the Z-axis in degrees. |
|---|
| 559 | void setPenRotation(float rotation) { _tabletPen.rotation = rotation; } |
|---|
| 560 | |
|---|
| 561 | /// get the tablet pen rotation around the Z-axis in degrees. |
|---|
| 562 | float getPenRotation() const { return _tabletPen.rotation; } |
|---|
| 563 | |
|---|
| 564 | /// set the tablet pointer type. |
|---|
| 565 | void setTabletPointerType(TabletPointerType pt) { _tabletPen.tabletPointerType = pt; } |
|---|
| 566 | |
|---|
| 567 | /// get the tablet pointer type. |
|---|
| 568 | TabletPointerType getTabletPointerType() const { return _tabletPen.tabletPointerType; } |
|---|
| 569 | |
|---|
| 570 | /// set the orientation from a tablet input device as a matrix. |
|---|
| 571 | const osg::Matrix getPenOrientation() const; |
|---|
| 572 | |
|---|
| 573 | void addTouchPoint(unsigned int id, TouchPhase phase, float x, float y, unsigned int tapCount = 0); |
|---|
| 574 | |
|---|
| 575 | TouchData* getTouchData() const { return _touchData.get(); } |
|---|
| 576 | bool isMultiTouchEvent() const { return (_touchData.valid()); } |
|---|
| 577 | |
|---|
| 578 | protected: |
|---|
| 579 | |
|---|
| 580 | /** Force users to create on heap, so that multiple referencing is safe.*/ |
|---|
| 581 | virtual ~GUIEventAdapter(); |
|---|
| 582 | |
|---|
| 583 | mutable bool _handled; |
|---|
| 584 | EventType _eventType; |
|---|
| 585 | double _time; |
|---|
| 586 | |
|---|
| 587 | osg::observer_ptr<osg::GraphicsContext> _context; |
|---|
| 588 | int _windowX; |
|---|
| 589 | int _windowY; |
|---|
| 590 | int _windowWidth; |
|---|
| 591 | int _windowHeight; |
|---|
| 592 | int _key; |
|---|
| 593 | int _unmodifiedKey; |
|---|
| 594 | int _button; |
|---|
| 595 | float _Xmin,_Xmax; |
|---|
| 596 | float _Ymin,_Ymax; |
|---|
| 597 | float _mx; |
|---|
| 598 | float _my; |
|---|
| 599 | int _buttonMask; |
|---|
| 600 | int _modKeyMask; |
|---|
| 601 | MouseYOrientation _mouseYOrientation; |
|---|
| 602 | |
|---|
| 603 | struct Scrolling { |
|---|
| 604 | ScrollingMotion motion; |
|---|
| 605 | float deltaX; |
|---|
| 606 | float deltaY; |
|---|
| 607 | |
|---|
| 608 | Scrolling() : motion(SCROLL_NONE), deltaX(0), deltaY(0) {} |
|---|
| 609 | Scrolling(const Scrolling& rhs) : motion(rhs.motion), deltaX(rhs.deltaX), deltaY(rhs.deltaY) {} |
|---|
| 610 | }; |
|---|
| 611 | Scrolling _scrolling; |
|---|
| 612 | |
|---|
| 613 | struct TabletPen { |
|---|
| 614 | float pressure; |
|---|
| 615 | float tiltX; |
|---|
| 616 | float tiltY; |
|---|
| 617 | float rotation; |
|---|
| 618 | TabletPointerType tabletPointerType; |
|---|
| 619 | |
|---|
| 620 | TabletPen() : pressure(0), tiltX(0), tiltY(0), rotation(0), tabletPointerType(UNKNOWN) {} |
|---|
| 621 | TabletPen(const TabletPen& rhs) : pressure(rhs.pressure), tiltX(rhs.tiltX), tiltY(rhs.tiltY), rotation(rhs.rotation), tabletPointerType(rhs.tabletPointerType) {} |
|---|
| 622 | }; |
|---|
| 623 | TabletPen _tabletPen; |
|---|
| 624 | |
|---|
| 625 | osg::ref_ptr<TouchData> _touchData; |
|---|
| 626 | }; |
|---|
| 627 | |
|---|
| 628 | } |
|---|
| 629 | |
|---|
| 630 | #endif |
|---|