From ba8bf1e94c77bac70e16b77cad7807c539632d24 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 7 May 2003 11:13:49 +0000 Subject: [PATCH] From Eric Sokolowsky, support for mouse scroll wheel in osgGA/osgProducer. --- include/osgGA/GUIEventAdapter | 6 +++++- include/osgProducer/EventAdapter | 3 +++ include/osgProducer/KeyboardMouseCallback | 1 + src/osgProducer/EventAdapter.cpp | 14 ++++++++++++++ src/osgProducer/KeyboardMouseCallback.cpp | 10 ++++++++++ 5 files changed, 33 insertions(+), 1 deletion(-) diff --git a/include/osgGA/GUIEventAdapter b/include/osgGA/GUIEventAdapter index dd9f2e53e..ee27a0043 100644 --- a/include/osgGA/GUIEventAdapter +++ b/include/osgGA/GUIEventAdapter @@ -39,6 +39,7 @@ public: }; enum EventType { + NONE=0, PUSH, RELEASE, DOUBLECLICK, @@ -48,7 +49,10 @@ public: KEYUP, FRAME, RESIZE, - NONE + SCROLLUP, + SCROLLDOWN, + SCROLLLEFT, + SCROLLRIGHT }; enum KeySymbol diff --git a/include/osgProducer/EventAdapter b/include/osgProducer/EventAdapter index cb2c3d5c5..99c56643a 100644 --- a/include/osgProducer/EventAdapter +++ b/include/osgProducer/EventAdapter @@ -75,6 +75,9 @@ class OSGPRODUCER_EXPORT EventAdapter : public osgGA::GUIEventAdapter /** method for adapting resize events. */ void adaptResize(double t, float Xmin, float Ymin, float Xmax, float Ymax); + /** method for adapting mouse scroll wheel events. */ + void adaptMouseScroll(double t, Producer::KeyboardMouseCallback::ScrollingMotion sm); + /** method for adapting mouse motion events whilst mouse buttons are pressed.*/ void adaptMouseMotion(double t, float x, float y); diff --git a/include/osgProducer/KeyboardMouseCallback b/include/osgProducer/KeyboardMouseCallback index 310315548..009283942 100644 --- a/include/osgProducer/KeyboardMouseCallback +++ b/include/osgProducer/KeyboardMouseCallback @@ -41,6 +41,7 @@ class OSGPRODUCER_EXPORT KeyboardMouseCallback : public Producer::KeyboardMouseC virtual ~KeyboardMouseCallback() {} // override KeyboardMouseCallback methods. + virtual void mouseScroll( Producer::KeyboardMouseCallback::ScrollingMotion sm ); virtual void mouseMotion( float mx, float my); virtual void passiveMouseMotion( float mx, float my); diff --git a/src/osgProducer/EventAdapter.cpp b/src/osgProducer/EventAdapter.cpp index 5b44480f9..1b8f3f1f0 100644 --- a/src/osgProducer/EventAdapter.cpp +++ b/src/osgProducer/EventAdapter.cpp @@ -68,6 +68,20 @@ void EventAdapter::adaptResize(double time, float Xmin, float Ymin, float Xmax, copyStaticVariables(); } +void EventAdapter::adaptMouseScroll(double time, Producer::KeyboardMouseCallback::ScrollingMotion sm) +{ + _time = time; + + if (sm == Producer::KeyboardMouseCallback::ScrollUp) + _eventType = SCROLLUP; + else if (sm == Producer::KeyboardMouseCallback::ScrollDown) + _eventType = SCROLLDOWN; + else + _eventType = NONE; + + copyStaticVariables(); +} + void EventAdapter::adaptButtonPress(double time,float x, float y, unsigned int button) { _time = time; diff --git a/src/osgProducer/KeyboardMouseCallback.cpp b/src/osgProducer/KeyboardMouseCallback.cpp index 2b34de7c9..acb3b185c 100644 --- a/src/osgProducer/KeyboardMouseCallback.cpp +++ b/src/osgProducer/KeyboardMouseCallback.cpp @@ -5,6 +5,16 @@ using namespace osgProducer; +void KeyboardMouseCallback::mouseScroll( Producer::KeyboardMouseCallback::ScrollingMotion sm ) +{ + osg::ref_ptr event = createEventAdapter(); + event->adaptMouseScroll(getTime(), sm); + + _eventQueueMutex.lock(); + _eventQueue.push_back(event); + _eventQueueMutex.unlock(); +} + void KeyboardMouseCallback::buttonPress( float mx, float my, unsigned int mbutton ) { _mx = mx;