From e7d9e91525a92eb55e2939e8a5e6838ad2e77987 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Tue, 4 Jul 2006 14:18:44 +0000 Subject: [PATCH] From Stephan Huber, "attached you'll find some modifications to Producer, osgGA and osgProducer to enable Mac OS X support for + scrollwheels, + mightymouse-srollballs + new tracking-pads with scroll feature + tablet-support (pressure, proximity and pointertype) (Wacom only tested) I think there was a bug in the windows-implementation of scroll-wheel support (wrong order of ScrollingMotion-enum, casting problem) which is fixed now. The scrollwheel-code is a bit klunky across platforms, some devices on OS X can report an absolute delta in pixel-coordinates not only the direction, so for now there is scrollingMotion (which describes the direction) and scrolldeltax and scrolldeltay. I decided to leave the scrollingmotion-stuff to not break old code relying on this." --- include/osgGA/EventQueue | 9 +++++ include/osgGA/GUIEventAdapter | 45 +++++++++++++++++++++-- include/osgProducer/KeyboardMouseCallback | 3 ++ src/osgGA/EventQueue.cpp | 28 ++++++++++++++ src/osgGA/GUIEventAdapter.cpp | 14 +++++-- src/osgProducer/KeyboardMouseCallback.cpp | 21 +++++++++++ 6 files changed, 113 insertions(+), 7 deletions(-) diff --git a/include/osgGA/EventQueue b/include/osgGA/EventQueue index 7a525ada4..03a8d54e1 100644 --- a/include/osgGA/EventQueue +++ b/include/osgGA/EventQueue @@ -56,6 +56,15 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced /** method for adapting mouse scroll wheel events, placing this event on the back of the event queue. */ void mouseScroll(GUIEventAdapter::ScrollingMotion sm); + + /** method for adapting mouse scroll wheel events, placing this event on the back of the event queue. */ + void mouseScroll2D(float x, float y); + + /** method for adapting pen pressure events, placing this event on the back og the event queue.*/ + void penPressure(float pressure); + + /** method for adapting pen proximity events, placing this event on the back og the event queue.*/ + void penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering); /** method for updating in response to a mouse warp. Note, just moves the mouse position without creating a new event for it.*/ void mouseWarp(float x, float y); diff --git a/include/osgGA/GUIEventAdapter b/include/osgGA/GUIEventAdapter index 8b3b03cb1..fe6a337f6 100644 --- a/include/osgGA/GUIEventAdapter +++ b/include/osgGA/GUIEventAdapter @@ -50,7 +50,10 @@ public: KEYUP, FRAME, RESIZE, - SCROLL + SCROLL, + PEN_PRESSURE, + PEN_PROXIMITY_ENTER, + PEN_PROXIMITY_LEAVE }; enum KeySymbol @@ -231,12 +234,22 @@ public: enum ScrollingMotion { + SCROLL_NONE, SCROLL_LEFT, SCROLL_RIGHT, SCROLL_UP, - SCROLL_DOWN + SCROLL_DOWN, + SCROLL_2D }; + enum TabletPointerType + { + UNKNOWN = 0, + PEN, + PUCK, + ERASER + }; + public: GUIEventAdapter(); @@ -319,9 +332,30 @@ public: unsigned int getModKeyMask() const { return _modKeyMask; } - + /// get the pressure, from a tablet input device (range 0 - 1) + float getPenPressure() const { return _pressure; } + /// sets the pressure from a tablet + void setPenPressure(float pressure) { _pressure = pressure; } + /// get the current used tablet pointer type + TabletPointerType getTabletPointerType() const { return _tabletPointerType; } + /// set the current used tablet pointer type + void setTabletPointerType(TabletPointerType pt) { _tabletPointerType = pt; } + void setScrollingMotion(ScrollingMotion motion) { _scrollingMotion = motion; } - + + /** get the scrolling x-delta */ + float getScrollingDeltaX() const { return _scrollingDeltaX; } + + /** get the scrolling y-delta */ + float getScrollingDeltaY() const { return _scrollingDeltaY; } + + /** sets the scrolling delta to x,y and the type of scrolling to SCROLL_2D */ + void setScrollingMotionDelta(float x, float y) { + _scrollingMotion = SCROLL_2D; + _scrollingDeltaX = x; + _scrollingDeltaY = y; + } + ScrollingMotion getScrollingMotion() const { return _scrollingMotion; } @@ -360,10 +394,13 @@ public: float _Ymin,_Ymax; float _mx; float _my; + float _pressure; unsigned int _buttonMask; unsigned int _modKeyMask; ScrollingMotion _scrollingMotion; + float _scrollingDeltaX, _scrollingDeltaY; MouseYOrientation _mouseYOrientation; + TabletPointerType _tabletPointerType; }; } diff --git a/include/osgProducer/KeyboardMouseCallback b/include/osgProducer/KeyboardMouseCallback index c3fd8e9d4..5c2401e04 100644 --- a/include/osgProducer/KeyboardMouseCallback +++ b/include/osgProducer/KeyboardMouseCallback @@ -37,6 +37,9 @@ class OSGPRODUCER_EXPORT KeyboardMouseCallback : public Producer::KeyboardMouseC // override KeyboardMouseCallback methods. virtual void mouseScroll( Producer::KeyboardMouseCallback::ScrollingMotion sm ); + virtual void mouseScroll2D( float, float); + virtual void penPressure(float pressure); + virtual void penProximity(TabletPointerType, bool); virtual void mouseMotion( float mx, float my); virtual void passiveMouseMotion( float mx, float my); virtual void mouseWarp( float mx, float my); diff --git a/src/osgGA/EventQueue.cpp b/src/osgGA/EventQueue.cpp index 3d5e40797..0d22836d2 100644 --- a/src/osgGA/EventQueue.cpp +++ b/src/osgGA/EventQueue.cpp @@ -87,6 +87,24 @@ void EventQueue::windowResize(float Xmin, float Ymin, float Xmax, float Ymax) addEvent(event); } +void EventQueue::penPressure(float pressure) +{ + GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); + event->setEventType(GUIEventAdapter::PEN_PRESSURE); + event->setPenPressure(pressure); + + addEvent(event); +} + +void EventQueue::penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering) +{ + GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); + event->setEventType( (isEntering) ? GUIEventAdapter::PEN_PROXIMITY_ENTER : GUIEventAdapter::PEN_PROXIMITY_LEAVE); + event->setTabletPointerType(pt); + + addEvent(event); +} + void EventQueue::mouseScroll(GUIEventAdapter::ScrollingMotion sm) { GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); @@ -96,6 +114,16 @@ void EventQueue::mouseScroll(GUIEventAdapter::ScrollingMotion sm) addEvent(event); } +void EventQueue::mouseScroll2D(float x, float y) +{ + GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState); + event->setEventType(GUIEventAdapter::SCROLL); + event->setScrollingMotionDelta(x,y); + + addEvent(event); +} + + void EventQueue::mouseWarp(float x, float y) { _accumulateEventState->setX(x); diff --git a/src/osgGA/GUIEventAdapter.cpp b/src/osgGA/GUIEventAdapter.cpp index 43378bcab..4ad7a884a 100644 --- a/src/osgGA/GUIEventAdapter.cpp +++ b/src/osgGA/GUIEventAdapter.cpp @@ -26,10 +26,14 @@ GUIEventAdapter::GUIEventAdapter(): _Ymax(1.0), _mx(0.5), _my(0.5), + _pressure(0.0), _buttonMask(0), _modKeyMask(0), - _scrollingMotion(SCROLL_DOWN), - _mouseYOrientation(Y_INCREASING_DOWNWARDS) + _scrollingMotion(SCROLL_NONE), + _scrollingDeltaX(0), + _scrollingDeltaY(0), + _mouseYOrientation(Y_INCREASING_DOWNWARDS), + _tabletPointerType(UNKNOWN) {} GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs): @@ -44,10 +48,14 @@ GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs): _Ymax(rhs._Ymax), _mx(rhs._mx), _my(rhs._my), + _pressure(rhs._pressure), _buttonMask(rhs._buttonMask), _modKeyMask(rhs._modKeyMask), _scrollingMotion(rhs._scrollingMotion), - _mouseYOrientation(rhs._mouseYOrientation) + _scrollingDeltaX(rhs._scrollingDeltaX), + _scrollingDeltaY(rhs._scrollingDeltaY), + _mouseYOrientation(rhs._mouseYOrientation), + _tabletPointerType(rhs._tabletPointerType) {} GUIEventAdapter::~GUIEventAdapter() diff --git a/src/osgProducer/KeyboardMouseCallback.cpp b/src/osgProducer/KeyboardMouseCallback.cpp index 115bb3d73..178b8aaaa 100644 --- a/src/osgProducer/KeyboardMouseCallback.cpp +++ b/src/osgProducer/KeyboardMouseCallback.cpp @@ -25,12 +25,33 @@ void KeyboardMouseCallback::mouseScroll( Producer::KeyboardMouseCallback::Scroll switch(sm) { case(Producer::KeyboardMouseCallback::ScrollNone): break; + case(Producer::KeyboardMouseCallback::ScrollLeft): _eventQueue->mouseScroll(osgGA::GUIEventAdapter::SCROLL_LEFT); break; + case(Producer::KeyboardMouseCallback::ScrollRight): _eventQueue->mouseScroll(osgGA::GUIEventAdapter::SCROLL_RIGHT); break; case(Producer::KeyboardMouseCallback::ScrollUp): _eventQueue->mouseScroll(osgGA::GUIEventAdapter::SCROLL_UP); break; case(Producer::KeyboardMouseCallback::ScrollDown): _eventQueue->mouseScroll(osgGA::GUIEventAdapter::SCROLL_DOWN); break; + case(Producer::KeyboardMouseCallback::Scroll2D): _eventQueue->mouseScroll(osgGA::GUIEventAdapter::SCROLL_2D); break; } } } +void KeyboardMouseCallback::mouseScroll2D( float x, float y ) +{ + updateWindowSize(); + if (_eventQueue.valid()) _eventQueue->mouseScroll2D(x,y); +} + +void KeyboardMouseCallback::penPressure( float pressure ) +{ + updateWindowSize(); + if (_eventQueue.valid()) _eventQueue->penPressure(pressure); +} + +void KeyboardMouseCallback::penProximity(TabletPointerType pt, bool isEntering) +{ + updateWindowSize(); + if (_eventQueue.valid()) _eventQueue->penProximity((osgGA::GUIEventAdapter::TabletPointerType)pt, isEntering); +} + void KeyboardMouseCallback::buttonPress( float mx, float my, unsigned int mbutton ) { updateWindowSize();