| 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_BackSpace = 0xFF08, /* back space, back char */ |
|---|
| 63 | KEY_Tab = 0xFF09, |
|---|
| 64 | KEY_Linefeed = 0xFF0A, /* Linefeed, LF */ |
|---|
| 65 | KEY_Clear = 0xFF0B, |
|---|
| 66 | KEY_Return = 0xFF0D, /* Return, enter */ |
|---|
| 67 | KEY_Pause = 0xFF13, /* Pause, hold */ |
|---|
| 68 | KEY_Scroll_Lock = 0xFF14, |
|---|
| 69 | KEY_Sys_Req = 0xFF15, |
|---|
| 70 | KEY_Escape = 0xFF1B, |
|---|
| 71 | KEY_Delete = 0xFFFF, /* Delete, rubout */ |
|---|
| 72 | |
|---|
| 73 | |
|---|
| 74 | /* Cursor control & motion */ |
|---|
| 75 | |
|---|
| 76 | KEY_Home = 0xFF50, |
|---|
| 77 | KEY_Left = 0xFF51, /* Move left, left arrow */ |
|---|
| 78 | KEY_Up = 0xFF52, /* Move up, up arrow */ |
|---|
| 79 | KEY_Right = 0xFF53, /* Move right, right arrow */ |
|---|
| 80 | KEY_Down = 0xFF54, /* Move down, down arrow */ |
|---|
| 81 | KEY_Prior = 0xFF55, /* Prior, previous */ |
|---|
| 82 | KEY_Page_Up = 0xFF55, |
|---|
| 83 | KEY_Next = 0xFF56, /* Next */ |
|---|
| 84 | KEY_Page_Down = 0xFF56, |
|---|
| 85 | KEY_End = 0xFF57, /* EOL */ |
|---|
| 86 | KEY_Begin = 0xFF58, /* BOL */ |
|---|
| 87 | |
|---|
| 88 | |
|---|
| 89 | /* Misc Functions */ |
|---|
| 90 | |
|---|
| 91 | KEY_Select = 0xFF60, /* Select, mark */ |
|---|
| 92 | KEY_Print = 0xFF61, |
|---|
| 93 | KEY_Execute = 0xFF62, /* Execute, run, do */ |
|---|
| 94 | KEY_Insert = 0xFF63, /* Insert, insert here */ |
|---|
| 95 | KEY_Undo = 0xFF65, /* Undo, oops */ |
|---|
| 96 | KEY_Redo = 0xFF66, /* redo, again */ |
|---|
| 97 | KEY_Menu = 0xFF67, /* On Windows, this is VK_APPS, the context-menu key */ |
|---|
| 98 | KEY_Find = 0xFF68, /* Find, search */ |
|---|
| 99 | KEY_Cancel = 0xFF69, /* Cancel, stop, abort, exit */ |
|---|
| 100 | KEY_Help = 0xFF6A, /* Help */ |
|---|
| 101 | KEY_Break = 0xFF6B, |
|---|
| 102 | KEY_Mode_switch = 0xFF7E, /* Character set switch */ |
|---|
| 103 | KEY_Script_switch = 0xFF7E, /* Alias for mode_switch */ |
|---|
| 104 | KEY_Num_Lock = 0xFF7F, |
|---|
| 105 | |
|---|
| 106 | /* Keypad Functions, keypad numbers cleverly chosen to map to ascii */ |
|---|
| 107 | |
|---|
| 108 | KEY_KP_Space = 0xFF80, /* space */ |
|---|
| 109 | KEY_KP_Tab = 0xFF89, |
|---|
| 110 | KEY_KP_Enter = 0xFF8D, /* enter */ |
|---|
| 111 | KEY_KP_F1 = 0xFF91, /* PF1, KP_A, ... */ |
|---|
| 112 | KEY_KP_F2 = 0xFF92, |
|---|
| 113 | KEY_KP_F3 = 0xFF93, |
|---|
| 114 | KEY_KP_F4 = 0xFF94, |
|---|
| 115 | KEY_KP_Home = 0xFF95, |
|---|
| 116 | KEY_KP_Left = 0xFF96, |
|---|
| 117 | KEY_KP_Up = 0xFF97, |
|---|
| 118 | KEY_KP_Right = 0xFF98, |
|---|
| 119 | KEY_KP_Down = 0xFF99, |
|---|
| 120 | KEY_KP_Prior = 0xFF9A, |
|---|
| 121 | KEY_KP_Page_Up = 0xFF9A, |
|---|
| 122 | KEY_KP_Next = 0xFF9B, |
|---|
| 123 | KEY_KP_Page_Down = 0xFF9B, |
|---|
| 124 | KEY_KP_End = 0xFF9C, |
|---|
| 125 | KEY_KP_Begin = 0xFF9D, |
|---|
| 126 | KEY_KP_Insert = 0xFF9E, |
|---|
| 127 | KEY_KP_Delete = 0xFF9F, |
|---|
| 128 | KEY_KP_Equal = 0xFFBD, /* equals */ |
|---|
| 129 | KEY_KP_Multiply = 0xFFAA, |
|---|
| 130 | KEY_KP_Add = 0xFFAB, |
|---|
| 131 | KEY_KP_Separator = 0xFFAC, /* separator, often comma */ |
|---|
| 132 | KEY_KP_Subtract = 0xFFAD, |
|---|
| 133 | KEY_KP_Decimal = 0xFFAE, |
|---|
| 134 | KEY_KP_Divide = 0xFFAF, |
|---|
| 135 | |
|---|
| 136 | KEY_KP_0 = 0xFFB0, |
|---|
| 137 | KEY_KP_1 = 0xFFB1, |
|---|
| 138 | KEY_KP_2 = 0xFFB2, |
|---|
| 139 | KEY_KP_3 = 0xFFB3, |
|---|
| 140 | KEY_KP_4 = 0xFFB4, |
|---|
| 141 | KEY_KP_5 = 0xFFB5, |
|---|
| 142 | KEY_KP_6 = 0xFFB6, |
|---|
| 143 | KEY_KP_7 = 0xFFB7, |
|---|
| 144 | KEY_KP_8 = 0xFFB8, |
|---|
| 145 | KEY_KP_9 = 0xFFB9, |
|---|
| 146 | |
|---|
| 147 | /* |
|---|
| 148 | * Auxiliary Functions; note the duplicate definitions for left and right |
|---|
| 149 | * function keys; Sun keyboards and a few other manufactures have such |
|---|
| 150 | * function key groups on the left and/or right sides of the keyboard. |
|---|
| 151 | * We've not found a keyboard with more than 35 function keys total. |
|---|
| 152 | */ |
|---|
| 153 | |
|---|
| 154 | KEY_F1 = 0xFFBE, |
|---|
| 155 | KEY_F2 = 0xFFBF, |
|---|
| 156 | KEY_F3 = 0xFFC0, |
|---|
| 157 | KEY_F4 = 0xFFC1, |
|---|
| 158 | KEY_F5 = 0xFFC2, |
|---|
| 159 | KEY_F6 = 0xFFC3, |
|---|
| 160 | KEY_F7 = 0xFFC4, |
|---|
| 161 | KEY_F8 = 0xFFC5, |
|---|
| 162 | KEY_F9 = 0xFFC6, |
|---|
| 163 | KEY_F10 = 0xFFC7, |
|---|
| 164 | KEY_F11 = 0xFFC8, |
|---|
| 165 | KEY_F12 = 0xFFC9, |
|---|
| 166 | KEY_F13 = 0xFFCA, |
|---|
| 167 | KEY_F14 = 0xFFCB, |
|---|
| 168 | KEY_F15 = 0xFFCC, |
|---|
| 169 | KEY_F16 = 0xFFCD, |
|---|
| 170 | KEY_F17 = 0xFFCE, |
|---|
| 171 | KEY_F18 = 0xFFCF, |
|---|
| 172 | KEY_F19 = 0xFFD0, |
|---|
| 173 | KEY_F20 = 0xFFD1, |
|---|
| 174 | KEY_F21 = 0xFFD2, |
|---|
| 175 | KEY_F22 = 0xFFD3, |
|---|
| 176 | KEY_F23 = 0xFFD4, |
|---|
| 177 | KEY_F24 = 0xFFD5, |
|---|
| 178 | KEY_F25 = 0xFFD6, |
|---|
| 179 | KEY_F26 = 0xFFD7, |
|---|
| 180 | KEY_F27 = 0xFFD8, |
|---|
| 181 | KEY_F28 = 0xFFD9, |
|---|
| 182 | KEY_F29 = 0xFFDA, |
|---|
| 183 | KEY_F30 = 0xFFDB, |
|---|
| 184 | KEY_F31 = 0xFFDC, |
|---|
| 185 | KEY_F32 = 0xFFDD, |
|---|
| 186 | KEY_F33 = 0xFFDE, |
|---|
| 187 | KEY_F34 = 0xFFDF, |
|---|
| 188 | KEY_F35 = 0xFFE0, |
|---|
| 189 | |
|---|
| 190 | /* Modifiers */ |
|---|
| 191 | |
|---|
| 192 | KEY_Shift_L = 0xFFE1, /* Left shift */ |
|---|
| 193 | KEY_Shift_R = 0xFFE2, /* Right shift */ |
|---|
| 194 | KEY_Control_L = 0xFFE3, /* Left control */ |
|---|
| 195 | KEY_Control_R = 0xFFE4, /* Right control */ |
|---|
| 196 | KEY_Caps_Lock = 0xFFE5, /* Caps lock */ |
|---|
| 197 | KEY_Shift_Lock = 0xFFE6, /* Shift lock */ |
|---|
| 198 | |
|---|
| 199 | KEY_Meta_L = 0xFFE7, /* Left meta */ |
|---|
| 200 | KEY_Meta_R = 0xFFE8, /* Right meta */ |
|---|
| 201 | KEY_Alt_L = 0xFFE9, /* Left alt */ |
|---|
| 202 | KEY_Alt_R = 0xFFEA, /* Right alt */ |
|---|
| 203 | KEY_Super_L = 0xFFEB, /* Left super */ |
|---|
| 204 | KEY_Super_R = 0xFFEC, /* Right super */ |
|---|
| 205 | KEY_Hyper_L = 0xFFED, /* Left hyper */ |
|---|
| 206 | KEY_Hyper_R = 0xFFEE /* Right hyper */ |
|---|
| 207 | }; |
|---|
| 208 | |
|---|
| 209 | |
|---|
| 210 | enum ModKeyMask |
|---|
| 211 | { |
|---|
| 212 | MODKEY_LEFT_SHIFT = 0x0001, |
|---|
| 213 | MODKEY_RIGHT_SHIFT = 0x0002, |
|---|
| 214 | MODKEY_LEFT_CTRL = 0x0004, |
|---|
| 215 | MODKEY_RIGHT_CTRL = 0x0008, |
|---|
| 216 | MODKEY_LEFT_ALT = 0x0010, |
|---|
| 217 | MODKEY_RIGHT_ALT = 0x0020, |
|---|
| 218 | MODKEY_LEFT_META = 0x0040, |
|---|
| 219 | MODKEY_RIGHT_META = 0x0080, |
|---|
| 220 | MODKEY_LEFT_SUPER = 0x0100, |
|---|
| 221 | MODKEY_RIGHT_SUPER = 0x0200, |
|---|
| 222 | MODKEY_LEFT_HYPER = 0x0400, |
|---|
| 223 | MODKEY_RIGHT_HYPER = 0x0800, |
|---|
| 224 | MODKEY_NUM_LOCK = 0x1000, |
|---|
| 225 | MODKEY_CAPS_LOCK = 0x2000, |
|---|
| 226 | MODKEY_CTRL = (MODKEY_LEFT_CTRL|MODKEY_RIGHT_CTRL), |
|---|
| 227 | MODKEY_SHIFT = (MODKEY_LEFT_SHIFT|MODKEY_RIGHT_SHIFT), |
|---|
| 228 | MODKEY_ALT = (MODKEY_LEFT_ALT|MODKEY_RIGHT_ALT), |
|---|
| 229 | MODKEY_META = (MODKEY_LEFT_META|MODKEY_RIGHT_META), |
|---|
| 230 | MODKEY_SUPER = (MODKEY_LEFT_SUPER|MODKEY_RIGHT_SUPER), |
|---|
| 231 | MODKEY_HYPER = (MODKEY_LEFT_HYPER|MODKEY_RIGHT_HYPER) |
|---|
| 232 | }; |
|---|
| 233 | |
|---|
| 234 | enum MouseYOrientation |
|---|
| 235 | { |
|---|
| 236 | Y_INCREASING_UPWARDS, |
|---|
| 237 | Y_INCREASING_DOWNWARDS |
|---|
| 238 | }; |
|---|
| 239 | |
|---|
| 240 | enum ScrollingMotion |
|---|
| 241 | { |
|---|
| 242 | SCROLL_NONE, |
|---|
| 243 | SCROLL_LEFT, |
|---|
| 244 | SCROLL_RIGHT, |
|---|
| 245 | SCROLL_UP, |
|---|
| 246 | SCROLL_DOWN, |
|---|
| 247 | SCROLL_2D |
|---|
| 248 | }; |
|---|
| 249 | |
|---|
| 250 | enum TabletPointerType |
|---|
| 251 | { |
|---|
| 252 | UNKNOWN = 0, |
|---|
| 253 | PEN, |
|---|
| 254 | PUCK, |
|---|
| 255 | ERASER |
|---|
| 256 | }; |
|---|
| 257 | |
|---|
| 258 | public: |
|---|
| 259 | |
|---|
| 260 | GUIEventAdapter(); |
|---|
| 261 | |
|---|
| 262 | GUIEventAdapter(const GUIEventAdapter& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY); |
|---|
| 263 | |
|---|
| 264 | META_Object(osgGA, GUIEventAdapter); |
|---|
| 265 | |
|---|
| 266 | |
|---|
| 267 | /** Get the accumulated event state singleton. |
|---|
| 268 | * Typically all EventQueue will share this single GUIEventAdapter object for tracking |
|---|
| 269 | * the mouse position, keyboard and mouse masks. */ |
|---|
| 270 | static osg::ref_ptr<GUIEventAdapter>& getAccumulatedEventState(); |
|---|
| 271 | |
|---|
| 272 | |
|---|
| 273 | /** Set whether this event has been handled by an event handler or not.*/ |
|---|
| 274 | void setHandled(bool handled) const { _handled = handled; } |
|---|
| 275 | |
|---|
| 276 | /** Get whether this event has been handled by an event handler or not.*/ |
|---|
| 277 | bool getHandled() const { return _handled; } |
|---|
| 278 | |
|---|
| 279 | /** set the event type. */ |
|---|
| 280 | void setEventType(EventType Type) { _eventType = Type; } |
|---|
| 281 | |
|---|
| 282 | /** get the event type. */ |
|---|
| 283 | virtual EventType getEventType() const { return _eventType; } |
|---|
| 284 | |
|---|
| 285 | /** set time in seconds of event. */ |
|---|
| 286 | void setTime(double time) { _time = time; } |
|---|
| 287 | |
|---|
| 288 | /** get time in seconds of event. */ |
|---|
| 289 | double getTime() const { return _time; } |
|---|
| 290 | |
|---|
| 291 | /** deprecated function for getting time of event. */ |
|---|
| 292 | double time() const { return _time; } |
|---|
| 293 | |
|---|
| 294 | |
|---|
| 295 | void setGraphicsContext(osg::GraphicsContext* context) { _context = context; } |
|---|
| 296 | const osg::GraphicsContext* getGraphicsContext() const { return _context.get(); } |
|---|
| 297 | |
|---|
| 298 | |
|---|
| 299 | /** set window rectangle. */ |
|---|
| 300 | void setWindowRectangle(int x, int y, int width, int height, bool updateMouseRange = true); |
|---|
| 301 | |
|---|
| 302 | /** get window x origin.*/ |
|---|
| 303 | int getWindowX() const { return _windowX; } |
|---|
| 304 | |
|---|
| 305 | /** get window y origin.*/ |
|---|
| 306 | int getWindowY() const { return _windowY; } |
|---|
| 307 | |
|---|
| 308 | /** get window width.*/ |
|---|
| 309 | int getWindowWidth() const { return _windowWidth; } |
|---|
| 310 | |
|---|
| 311 | /** get window height.*/ |
|---|
| 312 | int getWindowHeight() const { return _windowHeight; } |
|---|
| 313 | |
|---|
| 314 | |
|---|
| 315 | /** set key pressed. */ |
|---|
| 316 | inline void setKey(int key) { _key = key; } |
|---|
| 317 | |
|---|
| 318 | /** get key pressed, return -1 if inappropriate for this GUIEventAdapter. */ |
|---|
| 319 | virtual int getKey() const { return _key; } |
|---|
| 320 | |
|---|
| 321 | /** set button pressed/released.*/ |
|---|
| 322 | void setButton(int button) { _button = button; } |
|---|
| 323 | |
|---|
| 324 | /** button pressed/released, return -1 if inappropriate for this GUIEventAdapter.*/ |
|---|
| 325 | int getButton() const { return _button; } |
|---|
| 326 | |
|---|
| 327 | |
|---|
| 328 | /** set mouse input range. */ |
|---|
| 329 | void setInputRange(float Xmin, float Ymin, float Xmax, float Ymax); |
|---|
| 330 | |
|---|
| 331 | /** get mouse minimum x. */ |
|---|
| 332 | float getXmin() const { return _Xmin; } |
|---|
| 333 | |
|---|
| 334 | /** get mouse maximum x. */ |
|---|
| 335 | float getXmax() const { return _Xmax; } |
|---|
| 336 | |
|---|
| 337 | /** get mouse minimum y. */ |
|---|
| 338 | float getYmin() const { return _Ymin; } |
|---|
| 339 | |
|---|
| 340 | /** get mouse maximum y. */ |
|---|
| 341 | float getYmax() const { return _Ymax; } |
|---|
| 342 | |
|---|
| 343 | /** set current mouse x position.*/ |
|---|
| 344 | void setX(float x) { _mx = x; } |
|---|
| 345 | |
|---|
| 346 | /** get current mouse x position.*/ |
|---|
| 347 | float getX() const { return _mx; } |
|---|
| 348 | |
|---|
| 349 | /** set current mouse y position.*/ |
|---|
| 350 | void setY(float y) { _my = y; } |
|---|
| 351 | |
|---|
| 352 | /** get current mouse y position.*/ |
|---|
| 353 | float getY() const { return _my; } |
|---|
| 354 | |
|---|
| 355 | /** |
|---|
| 356 | * return the current mouse x value normalized to the range of -1 to 1. |
|---|
| 357 | * -1 would be the left hand side of the window. |
|---|
| 358 | * 0.0 would be the middle of the window. |
|---|
| 359 | * +1 would be the right hand side of the window. |
|---|
| 360 | */ |
|---|
| 361 | inline float getXnormalized() const { return 2.0f*(getX()-getXmin())/(getXmax()-getXmin())-1.0f; } |
|---|
| 362 | |
|---|
| 363 | /** |
|---|
| 364 | * return the current mouse y value normalized to the range of -1 to 1. |
|---|
| 365 | * -1 would be the bottom of the window. |
|---|
| 366 | * 0.0 would be the middle of the window. |
|---|
| 367 | * +1 would be the top of the window. |
|---|
| 368 | */ |
|---|
| 369 | inline float getYnormalized() const |
|---|
| 370 | { |
|---|
| 371 | if (_mouseYOrientation==Y_INCREASING_UPWARDS) return 2.0f*(getY()-getYmin())/(getYmax()-getYmin())-1.0f; |
|---|
| 372 | else return -(2.0f*(getY()-getYmin())/(getYmax()-getYmin())-1.0f); |
|---|
| 373 | } |
|---|
| 374 | |
|---|
| 375 | /// set mouse-Y orientation (mouse-Y increases upwards or downwards). |
|---|
| 376 | void setMouseYOrientation(MouseYOrientation myo) { _mouseYOrientation = myo; } |
|---|
| 377 | |
|---|
| 378 | /// get mouse-Y orientation (mouse-Y increases upwards or downwards). |
|---|
| 379 | MouseYOrientation getMouseYOrientation() const { return _mouseYOrientation; } |
|---|
| 380 | |
|---|
| 381 | /// set current mouse button state. |
|---|
| 382 | void setButtonMask(int mask) { _buttonMask = mask; } |
|---|
| 383 | |
|---|
| 384 | /// get current mouse button state. |
|---|
| 385 | int getButtonMask() const { return _buttonMask; } |
|---|
| 386 | |
|---|
| 387 | /// set modifier key mask. |
|---|
| 388 | void setModKeyMask(int mask) { _modKeyMask = mask; } |
|---|
| 389 | |
|---|
| 390 | /// get modifier key mask. |
|---|
| 391 | int getModKeyMask() const { return _modKeyMask; } |
|---|
| 392 | |
|---|
| 393 | /// set scrolling motion (for EventType::SCROLL). |
|---|
| 394 | void setScrollingMotion(ScrollingMotion motion) { _scrolling.motion = motion; } |
|---|
| 395 | |
|---|
| 396 | /// get scrolling motion (for EventType::SCROLL). |
|---|
| 397 | ScrollingMotion getScrollingMotion() const { return _scrolling.motion; } |
|---|
| 398 | |
|---|
| 399 | /// set the scrolling delta to x,y and the scrolling motion to SCROLL_2D. |
|---|
| 400 | void setScrollingMotionDelta(float x, float y) { |
|---|
| 401 | _scrolling.motion = SCROLL_2D; |
|---|
| 402 | _scrolling.deltaX = x; |
|---|
| 403 | _scrolling.deltaY = y; |
|---|
| 404 | } |
|---|
| 405 | |
|---|
| 406 | /// get the scrolling x-delta. |
|---|
| 407 | float getScrollingDeltaX() const { return _scrolling.deltaX; } |
|---|
| 408 | |
|---|
| 409 | /// get the scrolling y-delta. |
|---|
| 410 | float getScrollingDeltaY() const { return _scrolling.deltaY; } |
|---|
| 411 | |
|---|
| 412 | |
|---|
| 413 | /// set the tablet pen pressure (range 0..1). |
|---|
| 414 | void setPenPressure(float pressure) { _tabletPen.pressure = pressure; } |
|---|
| 415 | |
|---|
| 416 | /// get the tablet pen pressure (range 0..1). |
|---|
| 417 | float getPenPressure() const { return _tabletPen.pressure; } |
|---|
| 418 | |
|---|
| 419 | /// set the tablet pen tiltX in degrees. |
|---|
| 420 | void setPenTiltX(float tiltX) { _tabletPen.tiltX = tiltX; } |
|---|
| 421 | |
|---|
| 422 | /// get the tablet pen tiltX in degrees. |
|---|
| 423 | float getPenTiltX() const { return _tabletPen.tiltX; } |
|---|
| 424 | |
|---|
| 425 | /// set the tablet pen tiltY in degrees. |
|---|
| 426 | void setPenTiltY(float tiltY) { _tabletPen.tiltY = tiltY; } |
|---|
| 427 | |
|---|
| 428 | /// get the tablet pen tiltY in degrees. |
|---|
| 429 | float getPenTiltY() const { return _tabletPen.tiltY; } |
|---|
| 430 | |
|---|
| 431 | /// set the tablet pen rotation around the Z-axis in degrees. |
|---|
| 432 | void setPenRotation(float rotation) { _tabletPen.rotation = rotation; } |
|---|
| 433 | |
|---|
| 434 | /// get the tablet pen rotation around the Z-axis in degrees. |
|---|
| 435 | float getPenRotation() const { return _tabletPen.rotation; } |
|---|
| 436 | |
|---|
| 437 | /// set the tablet pointer type. |
|---|
| 438 | void setTabletPointerType(TabletPointerType pt) { _tabletPen.tabletPointerType = pt; } |
|---|
| 439 | |
|---|
| 440 | /// get the tablet pointer type. |
|---|
| 441 | TabletPointerType getTabletPointerType() const { return _tabletPen.tabletPointerType; } |
|---|
| 442 | |
|---|
| 443 | /// set the orientation from a tablet input device as a matrix. |
|---|
| 444 | const osg::Matrix getPenOrientation() const; |
|---|
| 445 | |
|---|
| 446 | |
|---|
| 447 | protected: |
|---|
| 448 | |
|---|
| 449 | /** Force users to create on heap, so that multiple referencing is safe.*/ |
|---|
| 450 | virtual ~GUIEventAdapter(); |
|---|
| 451 | |
|---|
| 452 | mutable bool _handled; |
|---|
| 453 | EventType _eventType; |
|---|
| 454 | double _time; |
|---|
| 455 | |
|---|
| 456 | osg::observer_ptr<osg::GraphicsContext> _context; |
|---|
| 457 | int _windowX; |
|---|
| 458 | int _windowY; |
|---|
| 459 | int _windowWidth; |
|---|
| 460 | int _windowHeight; |
|---|
| 461 | int _key; |
|---|
| 462 | int _button; |
|---|
| 463 | float _Xmin,_Xmax; |
|---|
| 464 | float _Ymin,_Ymax; |
|---|
| 465 | float _mx; |
|---|
| 466 | float _my; |
|---|
| 467 | int _buttonMask; |
|---|
| 468 | int _modKeyMask; |
|---|
| 469 | MouseYOrientation _mouseYOrientation; |
|---|
| 470 | |
|---|
| 471 | struct Scrolling { |
|---|
| 472 | ScrollingMotion motion; |
|---|
| 473 | float deltaX; |
|---|
| 474 | float deltaY; |
|---|
| 475 | |
|---|
| 476 | Scrolling() : motion(SCROLL_NONE), deltaX(0), deltaY(0) {} |
|---|
| 477 | Scrolling(const Scrolling& rhs) : motion(rhs.motion), deltaX(rhs.deltaX), deltaY(rhs.deltaY) {} |
|---|
| 478 | }; |
|---|
| 479 | Scrolling _scrolling; |
|---|
| 480 | |
|---|
| 481 | struct TabletPen { |
|---|
| 482 | float pressure; |
|---|
| 483 | float tiltX; |
|---|
| 484 | float tiltY; |
|---|
| 485 | float rotation; |
|---|
| 486 | TabletPointerType tabletPointerType; |
|---|
| 487 | |
|---|
| 488 | TabletPen() : pressure(0), tiltX(0), tiltY(0), rotation(0), tabletPointerType(UNKNOWN) {} |
|---|
| 489 | TabletPen(const TabletPen& rhs) : pressure(rhs.pressure), tiltX(rhs.tiltX), tiltY(rhs.tiltY), rotation(rhs.rotation), tabletPointerType(rhs.tabletPointerType) {} |
|---|
| 490 | }; |
|---|
| 491 | TabletPen _tabletPen; |
|---|
| 492 | |
|---|
| 493 | }; |
|---|
| 494 | |
|---|
| 495 | } |
|---|
| 496 | |
|---|
| 497 | #endif |
|---|