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