From dbbabf87c61bd68d22e899a70b8bf7b552bc112f Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Wed, 8 Mar 2006 14:09:47 +0000 Subject: [PATCH] Converted osgGA::GUIEventAdapter into a concrete class capable of respresenting keyboard and mouse events. Added osgGA::EventQueue class to support a thread safe event queue and adaption of keyboard and mouse events. Removed osgProducer::EventAdapter as GUIEventAdapter replaces it. Adapted osgProducer and examples to work with the new changes to osgGA. --- VisualStudio/osgGA/osgGA.dsp | 8 + VisualStudio/osgProducer/osgProducer.dsp | 8 - .../osgWrappers/osgGA/wrapper_osgGA.dsp | 8 + .../osgProducer/wrapper_osgProducer.dsp | 2 +- examples/osgcatch/osgcatch.cpp | 16 +- examples/osgcluster/osgcluster.cpp | 62 ++--- examples/osghangglide/GliderManipulator.cpp | 2 +- examples/osgimpostor/TestManipulator.cpp | 2 +- examples/osgphotoalbum/osgphotoalbum.cpp | 14 +- examples/osgstereoimage/osgstereoimage.cpp | 2 +- examples/osgvolume/osgvolume.cpp | 4 +- include/osgGA/EventVisitor | 44 +--- include/osgGA/GUIEventAdapter | 136 ++++++----- include/osgGA/KeySwitchMatrixManipulator | 1 - include/osgProducer/EventAdapter | 89 ------- include/osgProducer/KeyboardMouseCallback | 40 ++- src/osgGA/AnimationPathManipulator.cpp | 8 +- src/osgGA/DriveManipulator.cpp | 2 +- src/osgGA/FlightManipulator.cpp | 2 +- src/osgGA/GNUmakefile | 1 + src/osgGA/GUIEventAdapter.cpp | 45 +++- src/osgGA/GUIEventHandler.cpp | 13 +- src/osgGA/NodeTrackerManipulator.cpp | 2 +- src/osgGA/TerrainManipulator.cpp | 2 +- src/osgGA/TrackballManipulator.cpp | 4 +- src/osgGA/UFOManipulator.cpp | 10 +- src/osgProducer/EventAdapter.cpp | 229 ------------------ src/osgProducer/GNUmakefile | 1 - src/osgProducer/KeyboardMouseCallback.cpp | 222 +++++------------ src/osgProducer/Viewer.cpp | 27 ++- src/osgWrappers/osgGA/EventQueue.cpp | 66 +++++ src/osgWrappers/osgGA/EventVisitor.cpp | 25 +- src/osgWrappers/osgGA/GNUmakefile | 2 + src/osgWrappers/osgGA/GUIEventAdapter.cpp | 80 +++--- src/osgWrappers/osgProducer/EventAdapter.cpp | 64 ----- src/osgWrappers/osgProducer/GNUmakefile | 2 +- .../osgProducer/KeyboardMouseCallback.cpp | 40 +-- 37 files changed, 450 insertions(+), 835 deletions(-) delete mode 100644 include/osgProducer/EventAdapter delete mode 100644 src/osgProducer/EventAdapter.cpp create mode 100644 src/osgWrappers/osgGA/EventQueue.cpp delete mode 100644 src/osgWrappers/osgProducer/EventAdapter.cpp diff --git a/VisualStudio/osgGA/osgGA.dsp b/VisualStudio/osgGA/osgGA.dsp index 6f9ae8edb..15604fe81 100755 --- a/VisualStudio/osgGA/osgGA.dsp +++ b/VisualStudio/osgGA/osgGA.dsp @@ -99,6 +99,10 @@ SOURCE=..\..\src\osgGA\AnimationPathManipulator.cpp # End Source File # Begin Source File +SOURCE=..\..\src\osgGA\EventQueue.cpp +# End Source File +# Begin Source File + SOURCE=..\..\src\osgGA\EventVisitor.cpp # End Source File # Begin Source File @@ -175,6 +179,10 @@ SOURCE=..\..\Include\osgGA\Export # End Source File # Begin Source File +SOURCE=..\..\Include\osgGA\EventQueue +# End Source File +# Begin Source File + SOURCE=..\..\Include\osgGA\EventVisitor # End Source File # Begin Source File diff --git a/VisualStudio/osgProducer/osgProducer.dsp b/VisualStudio/osgProducer/osgProducer.dsp index 43a95fcd6..bb59951b2 100755 --- a/VisualStudio/osgProducer/osgProducer.dsp +++ b/VisualStudio/osgProducer/osgProducer.dsp @@ -95,10 +95,6 @@ LINK32=link.exe # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File -SOURCE=..\..\src\osgProducer\EventAdapter.cpp -# End Source File -# Begin Source File - SOURCE=..\..\src\osgProducer\KeyboardMouseCallback.cpp # End Source File # Begin Source File @@ -131,10 +127,6 @@ SOURCE=..\..\src\osgProducer\ViewerEventHandler.cpp # PROP Default_Filter ";h;hpp;hxx;hm;inl" # Begin Source File -SOURCE=..\..\Include\osgProducer\EventAdapter -# End Source File -# Begin Source File - SOURCE=..\..\Include\osgProducer\Export # End Source File # Begin Source File diff --git a/VisualStudio/osgWrappers/osgGA/wrapper_osgGA.dsp b/VisualStudio/osgWrappers/osgGA/wrapper_osgGA.dsp index 805c692ad..ef0452198 100644 --- a/VisualStudio/osgWrappers/osgGA/wrapper_osgGA.dsp +++ b/VisualStudio/osgWrappers/osgGA/wrapper_osgGA.dsp @@ -103,6 +103,14 @@ SOURCE=..\..\..\src\osgWrappers\osgGA\AnimationPathManipulator.cpp SOURCE=..\..\..\src\osgWrappers\osgGA\DriveManipulator.cpp # End Source File +# Begin Source File +SOURCE=..\..\..\src\osgWrappers\osgGA\Event.cpp +# End Source File + +# Begin Source File +SOURCE=..\..\..\src\osgWrappers\osgGA\EventQueue.cpp +# End Source File + # Begin Source File SOURCE=..\..\..\src\osgWrappers\osgGA\EventVisitor.cpp # End Source File diff --git a/VisualStudio/osgWrappers/osgProducer/wrapper_osgProducer.dsp b/VisualStudio/osgWrappers/osgProducer/wrapper_osgProducer.dsp index 7a5bce0cd..ca2a6bb2f 100644 --- a/VisualStudio/osgWrappers/osgProducer/wrapper_osgProducer.dsp +++ b/VisualStudio/osgWrappers/osgProducer/wrapper_osgProducer.dsp @@ -96,7 +96,7 @@ LINK32=link.exe # PROP Default_Filter "cpp;c;cxx;rc;def;r;odl;idl;hpj;bat" # Begin Source File -SOURCE=..\..\..\src\osgWrappers\osgProducer\EventAdapter.cpp +SOURCE=..\..\..\src\osgWrappers\osgProducer\Export.cpp # End Source File # Begin Source File diff --git a/examples/osgcatch/osgcatch.cpp b/examples/osgcatch/osgcatch.cpp index ad4f0f7d6..ecd6b1163 100644 --- a/examples/osgcatch/osgcatch.cpp +++ b/examples/osgcatch/osgcatch.cpp @@ -862,9 +862,9 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA if (_numberOfPlayers>=2) _players[1].moveRight(); } - static double previous_time = ea.time(); - double dt = ea.time()-previous_time; - previous_time = ea.time(); + static double previous_time = ea.getTime(); + double dt = ea.getTime()-previous_time; + previous_time = ea.getTime(); // move objects for(CatchableObjectList::iterator itr=_catchableObjects.begin(); @@ -921,7 +921,7 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA } if (!(*itr)->anyInside(_origin, _origin+_width+_height) || - (*itr)->needToRemove(ea.time()) || + (*itr)->needToRemove(ea.getTime()) || removeEntry) { // need to remove @@ -944,16 +944,16 @@ bool GameEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionA // hit base line (*itr)->explode(); (*itr)->stop(); - (*itr)->setTimeToRemove(ea.time()+3.0); + (*itr)->setTimeToRemove(ea.getTime()+3.0); } } // create new catchable objects - static double previousTime = ea.time(); - double deltaTime = ea.time()-previousTime; - previousTime = ea.time(); + static double previousTime = ea.getTime(); + double deltaTime = ea.getTime()-previousTime; + previousTime = ea.getTime(); float numDropsPerSecond = _initialNumDropsPerSecond * (_level+1); float r = (float)rand()/(float)RAND_MAX; diff --git a/examples/osgcluster/osgcluster.cpp b/examples/osgcluster/osgcluster.cpp index 4e63636be..3e47a9b98 100644 --- a/examples/osgcluster/osgcluster.cpp +++ b/examples/osgcluster/osgcluster.cpp @@ -64,7 +64,7 @@ class CameraPacket { // us to do this, even though its a reference counted object. osg::FrameStamp _frameStamp; - osgProducer::KeyboardMouseCallback::EventQueue _events; + osgGA::EventQueue::Events _events; }; @@ -295,36 +295,36 @@ class DataConverter } - void write(const osgProducer::EventAdapter& event) + void write(const osgGA::GUIEventAdapter& event) { - writeUInt(event._eventType); - writeUInt(event._key); - writeUInt(event._button); - writeFloat(event._Xmin); - writeFloat(event._Xmax); - writeFloat(event._Ymin); - writeFloat(event._Ymax); - writeFloat(event._mx); - writeFloat(event._my); - writeUInt(event._buttonMask); - writeUInt(event._modKeyMask); - writeDouble(event._time); + writeUInt(event.getEventType()); + writeUInt(event.getKey()); + writeUInt(event.getButton()); + writeFloat(event.getXmin()); + writeFloat(event.getXmax()); + writeFloat(event.getYmin()); + writeFloat(event.getYmax()); + writeFloat(event.getX()); + writeFloat(event.getY()); + writeUInt(event.getButtonMask()); + writeUInt(event.getModKeyMask()); + writeDouble(event.getTime()); } - void read(osgProducer::EventAdapter& event) + void read(osgGA::GUIEventAdapter& event) { - event._eventType = (osgGA::GUIEventAdapter::EventType)readUInt(); - event._key = readUInt(); - event._button = readUInt(); - event._Xmin = readFloat(); - event._Xmax = readFloat(); - event._Ymin = readFloat(); - event._Ymax = readFloat(); - event._mx = readFloat(); - event._my = readFloat(); - event._buttonMask = readUInt(); - event._modKeyMask = readUInt(); - event._time = readDouble(); + event.setEventType((osgGA::GUIEventAdapter::EventType)readUInt()); + event.setKey(readUInt()); + event.setButton(readUInt()); + event.setXmin(readFloat()); + event.setXmax(readFloat()); + event.setYmin(readFloat()); + event.setYmax(readFloat()); + event.setX(readFloat()); + event.setY(readFloat()); + event.setButtonMask(readUInt()); + event.setModKeyMask(readUInt()); + event.setTime(readDouble()); } void write(CameraPacket& cameraPacket) @@ -337,9 +337,11 @@ class DataConverter write(cameraPacket._frameStamp); writeUInt(cameraPacket._events.size()); - for(unsigned int i=0;itime()-_ga_t1->time(); + double dt = _ga_t0->getTime()-_ga_t1->getTime(); if (dt<0.0f) { diff --git a/examples/osgimpostor/TestManipulator.cpp b/examples/osgimpostor/TestManipulator.cpp index af98c3745..5395a3127 100644 --- a/examples/osgimpostor/TestManipulator.cpp +++ b/examples/osgimpostor/TestManipulator.cpp @@ -160,7 +160,7 @@ bool TestManipulator::isMouseMoving() float dx = _ga_t0->getXnormalized()-_ga_t1->getXnormalized(); float dy = _ga_t0->getYnormalized()-_ga_t1->getYnormalized(); float len = sqrtf(dx*dx+dy*dy); - float dt = _ga_t0->time()-_ga_t1->time(); + float dt = _ga_t0->getTime()-_ga_t1->getTime(); return (len>dt*velocity); } diff --git a/examples/osgphotoalbum/osgphotoalbum.cpp b/examples/osgphotoalbum/osgphotoalbum.cpp index 96ece6e26..b526805d1 100644 --- a/examples/osgphotoalbum/osgphotoalbum.cpp +++ b/examples/osgphotoalbum/osgphotoalbum.cpp @@ -612,17 +612,17 @@ bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction if (ea.getKey()=='a') { _autoSteppingActive = !_autoSteppingActive; - _previousTime = ea.time(); + _previousTime = ea.getTime(); return true; } else if (ea.getKey()=='n') { - _album->nextPage(ea.time()+1.0f); + _album->nextPage(ea.getTime()+1.0f); return true; } else if (ea.getKey()=='p') { - _album->previousPage(ea.time()+1.0f); + _album->previousPage(ea.getTime()+1.0f); return true; } return false; @@ -634,13 +634,13 @@ bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction if (_firstTraversal) { _firstTraversal = false; - _previousTime = ea.time(); + _previousTime = ea.getTime(); } - else if (ea.time()-_previousTime>_timePerSlide) + else if (ea.getTime()-_previousTime>_timePerSlide) { - _previousTime = ea.time(); + _previousTime = ea.getTime(); - _album->nextPage(ea.time()+1.0f); + _album->nextPage(ea.getTime()+1.0f); } } diff --git a/examples/osgstereoimage/osgstereoimage.cpp b/examples/osgstereoimage/osgstereoimage.cpp index f4683ad1c..89e1afea7 100644 --- a/examples/osgstereoimage/osgstereoimage.cpp +++ b/examples/osgstereoimage/osgstereoimage.cpp @@ -118,7 +118,7 @@ bool SlideEventHandler::handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIAction if (ea.getKey()=='a') { _autoSteppingActive = !_autoSteppingActive; - _previousTime = ea.time(); + _previousTime = ea.getTime(); return true; } else if (ea.getKey()=='n') diff --git a/examples/osgvolume/osgvolume.cpp b/examples/osgvolume/osgvolume.cpp index 56babf301..396bbd2a7 100644 --- a/examples/osgvolume/osgvolume.cpp +++ b/examples/osgvolume/osgvolume.cpp @@ -667,8 +667,8 @@ class FollowMouseCallback : public osgGA::GUIEventHandler, public osg::StateSet: if (ev) { osgGA::GUIActionAdapter* aa = ev->getActionAdapter(); - osgGA::EventVisitor::EventList& events = ev->getEventList(); - for(osgGA::EventVisitor::EventList::iterator itr=events.begin(); + osgGA::EventQueue::Events& events = ev->getEvents(); + for(osgGA::EventQueue::Events::iterator itr=events.begin(); itr!=events.end(); ++itr) { diff --git a/include/osgGA/EventVisitor b/include/osgGA/EventVisitor index 7253a94e2..41ea919a8 100644 --- a/include/osgGA/EventVisitor +++ b/include/osgGA/EventVisitor @@ -27,8 +27,7 @@ #include #include - -#include +#include namespace osgGA { @@ -54,45 +53,19 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor typedef std::list< osg::ref_ptr > EventList; - void setEventList(const EventList& events) { _events = events; } - EventList& getEventList() { return _events; } - const EventList& getEventList() const { return _events; } - void addEvent(GUIEventAdapter* event); void removeEvent(GUIEventAdapter* event); void setEventHandled(bool handled) { _handled = handled; } bool getEventHandled() const { return _handled; } + + void setEvents(const EventQueue::Events& events) { _events = events; } + EventQueue::Events& getEvents() { return _events; } + const EventQueue::Events& getEvents() const { return _events; } + public: - - /** method for adapting resize events. */ - void eventResize(float Xmin, float Ymin, float Xmax, float Ymax); - - /** method for adapting mouse scroll wheel events. */ - void eventMouseScroll(GUIEventAdapter::ScrollingMotion sm); - - /** method for adapting mouse motion events whilst mouse buttons are pressed.*/ - void adaptMouseMotion(float x, float y); - - void adaptButtonPress(float x, float y, unsigned int button); - - void adaptButtonRelease(float x, float y, unsigned int button); - - /** method for adapting keyboard events.*/ - void adaptKeyPress( GUIEventAdapter::KeySymbol key); - - void adaptKeyRelease( GUIEventAdapter::KeySymbol key); - - /** method for adapting frame events, i.e. idle/display callback.*/ - void adaptFrame(double t); - - - - - public: - virtual void reset(); /** During traversal each type of node calls its callbacks and its children traversed. */ @@ -113,9 +86,6 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor protected: -// /** Prevent unwanted copy construction.*/ -// EventVisitor(const EventVisitor&):osg::NodeVisitor() {} - /** Prevent unwanted copy operator.*/ EventVisitor& operator = (const EventVisitor&) { return *this; } @@ -164,8 +134,8 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor osg::ref_ptr _accumulateEventState; - EventList _events; bool _handled; + EventQueue::Events _events; }; diff --git a/include/osgGA/GUIEventAdapter b/include/osgGA/GUIEventAdapter index 16427e316..1e76d774f 100644 --- a/include/osgGA/GUIEventAdapter +++ b/include/osgGA/GUIEventAdapter @@ -11,21 +11,22 @@ * OpenSceneGraph Public License for more details. */ -#ifndef OSGGA_GUIEVENTADAPTER -#define OSGGA_GUIEVENTADAPTER 1 +#ifndef OSGGA_EVENT +#define OSGGA_EVENT 1 #include #include namespace osgGA{ + /** -Pure virtual base class for adapting platform specific events into -generic keyboard and mouse events. +Pure virtual base class for adapting platform specific GUIEventAdapters into +generic keyboard and mouse GUIEventAdapters. Used as GUI toolkit-independent input into GUIEventAdapters. Viewer writers should subclass this base class to implement the functionality -to translate one of their GUI events, e.g. a Qt Event or an MFC Event, +to translate one of their GUI GUIEventAdapters, e.g. a Qt GUIEventAdapter or an MFC GUIEventAdapter, as appropriate. */ class OSGGA_EXPORT GUIEventAdapter : public osg::Referenced @@ -49,10 +50,7 @@ public: KEYUP, FRAME, RESIZE, - SCROLLUP, - SCROLLDOWN, - SCROLLLEFT, - SCROLLRIGHT + SCROLL }; enum KeySymbol @@ -233,63 +231,99 @@ public: enum ScrollingMotion { + SCROLL_LEFT, + SCROLL_RIGHT, SCROLL_UP, SCROLL_DOWN }; - /** Get the EventType of the GUI event.*/ - void setEventType(EventType eventType) { _eventType = eventType; } + public: - /** Get the EventType of the GUI event.*/ + GUIEventAdapter(); + + GUIEventAdapter(const GUIEventAdapter& rhs); + + /** Get the Type of the GUI GUIEventAdapter.*/ + void setEventType(EventType Type) { _eventType = Type; } + + /** Get the Type of the GUI GUIEventAdapter.*/ virtual EventType getEventType() const { return _eventType; } - /** time in seconds of event. */ + /** set time in seconds of event. */ void setTime(double time) { _time = time; } - /** time in seconds of event. */ + /** get time in seconds of event. */ double getTime() const { return _time; } + /** deprecated function for getting time of event. */ + double time() const { return _time; } - /** time in seconds of event. */ - virtual double time() const { return getTime(); } - - + /** set key pressed. */ inline void setKey(int key) { _key = key; } - /** key pressed, return -1 if inappropriate for this event. */ + /** get key pressed, return -1 if inappropriate for this GUIEventAdapter. */ virtual int getKey() const { return _key; } - /** button pressed/released, return -1 if inappropriate for this event.*/ - virtual int getButton() const { return _button; } + /** set button pressed/released.*/ + void setButton(int button) { _button = button; } - /** window minimum x. */ - virtual float getXmin() const { return _Xmin; } + /** button pressed/released, return -1 if inappropriate for this GUIEventAdapter.*/ + int getButton() const { return _button; } - /** window maximum x. */ - virtual float getXmax() const { return _Xmax; } + /** set window minimum x. */ + void setWindowSize(float Xmin, float Ymin, float Xmax, float Ymax); - /** window minimum y. */ - virtual float getYmin() const { return _Ymin; } + /** set window minimum x. */ + void setXmin(float x) { _Xmin = x; } - /** window maximum y. */ - virtual float getYmax() const { return _Ymax; } + /** get window minimum x. */ + float getXmin() const { return _Xmin; } - inline void setX(float x) { _mx = x; } + /** set window maximum x. */ + void setXmax(float x) { _Xmax = x; } - /** current mouse x position.*/ - virtual float getX() const { return _mx; } + /** get window maximum x. */ + float getXmax() const { return _Xmax; } - inline void setY(float y) { _my = y; } + /** set window minimum y. */ + void setYmin(float y) { _Ymin = y; } - /** current mouse y position.*/ - virtual float getY() const { return _my; } + /** get window minimum y. */ + float getYmin() const { return _Ymin; } - inline void setButtonMask(unsigned int mask) { _buttonMask = mask; } + /** set window maYimum y. */ + void setYmax(float y) { _Ymax = y; } - /** current mouse button state */ - virtual unsigned int getButtonMask() const { return _buttonMask; } + /** get window maYimum y. */ + float getYmax() const { return _Ymax; } + + /** set current mouse x position.*/ + void setX(float x) { _mx = x; } + + /** get current mouse x position.*/ + float getX() const { return _mx; } + + /** set current mouse y position.*/ + void setY(float y) { _my = y; } + + /** get current mouse y position.*/ + float getY() const { return _my; } + + /** set current mouse button state */ + void setButtonMask(unsigned int mask) { _buttonMask = mask; } + + /** get current mouse button state */ + unsigned int getButtonMask() const { return _buttonMask; } + + void setModKeyMask(unsigned int mask) { _modKeyMask = mask; } + + unsigned int getModKeyMask() const { return _modKeyMask; } + + + void setScrollingMotion(ScrollingMotion motion) { _scrollingMotion = motion; } + + ScrollingMotion getScrollingMotion() const { return _scrollingMotion; } - virtual unsigned int getModKeyMask() const { return _modKeyMask; } /** return the getX() value normalised to the range of -1 to 1. * -1 would be the left hand side of the window. @@ -310,32 +344,13 @@ public: void setMouseYOrientation(MouseYOrientation myo) { _mouseYOrientation = myo; } MouseYOrientation getMouseYOrientation() const { return _mouseYOrientation; } -protected: - - GUIEventAdapter(MouseYOrientation myo=Y_INCREASING_DOWNWARDS):_mouseYOrientation(myo) {} - - GUIEventAdapter(const GUIEventAdapter& rhs): - Referenced(), - _eventType(rhs._eventType), - _time(rhs._time), - _key(rhs._key), - _button(rhs._button), - _Xmin(rhs._Xmin), - _Xmax(rhs._Xmax), - _Ymin(rhs._Ymin), - _Ymax(rhs._Ymax), - _mx(rhs._mx), - _my(rhs._my), - _buttonMask(rhs._buttonMask), - _modKeyMask(rhs._modKeyMask), - _mouseYOrientation(rhs._mouseYOrientation) {} + protected: + /** Force users to create on heap, so that multiple referencing is safe.*/ virtual ~GUIEventAdapter(); - public: - EventType _eventType; double _time; @@ -347,6 +362,7 @@ protected: float _my; unsigned int _buttonMask; unsigned int _modKeyMask; + ScrollingMotion _scrollingMotion; MouseYOrientation _mouseYOrientation; }; diff --git a/include/osgGA/KeySwitchMatrixManipulator b/include/osgGA/KeySwitchMatrixManipulator index 1c550840d..8544c153c 100644 --- a/include/osgGA/KeySwitchMatrixManipulator +++ b/include/osgGA/KeySwitchMatrixManipulator @@ -21,7 +21,6 @@ namespace osgGA{ -class GUIEventAdapter; class GUIActionAdapter; /** diff --git a/include/osgProducer/EventAdapter b/include/osgProducer/EventAdapter deleted file mode 100644 index 2e99f7743..000000000 --- a/include/osgProducer/EventAdapter +++ /dev/null @@ -1,89 +0,0 @@ -/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2005 Robert Osfield - * - * This library is open source and may be redistributed and/or modified under - * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or - * (at your option) any later version. The full license is in LICENSE file - * included with this distribution, and on the openscenegraph.org website. - * - * This library is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * OpenSceneGraph Public License for more details. -*/ - -#ifndef OSGGLUT_ProducerEventAdapter -#define OSGGLUT_ProducerEventAdapter 1 - -#include - -#include -#include - - -namespace osgProducer { - -/** Class for adapting Producer events so that they can be used as input to osgGA::CameraManipulators.*/ -class OSGPRODUCER_EXPORT EventAdapter : public osgGA::GUIEventAdapter -{ - - public: - EventAdapter(); - virtual ~EventAdapter() {} - - - /** static method for setting window dimensions.*/ - static void setWindowSize(float Xmin, float Ymin, float Xmax, float Ymax); - - /** static method for setting button state.*/ - static void setButtonMask(unsigned int buttonMask); - - - /** 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); - - void adaptButtonPress(double t,float x, float y, unsigned int button); - - void adaptButtonRelease(double t,float x, float y, unsigned int button); - - /** method for adapting keyboard events.*/ - void adaptKeyPress( double t, Producer::KeySymbol key); - - void adaptKeyRelease( double t, Producer::KeySymbol key); - - /** method for adapting frame events, i.e. idle/display callback.*/ - void adaptFrame(double t); - - - void copyStaticVariables(); - - public: - - // used to accumulate the button mask state, it represents - // the current button mask state, which is modified by the - // adaptMouse() method which then copies it to value _buttonMask - // which required the mouse buttons state at the time of the event. - static unsigned int _s_accumulatedButtonMask; - - // used to store current button value - static int _s_button; - - // used to store window min and max values. - static float _s_Xmin; - static float _s_Xmax; - static float _s_Ymin; - static float _s_Ymax; - static float _s_mx; - static float _s_my; - static int _s_modKeyMask; - -}; - -} - -#endif diff --git a/include/osgProducer/KeyboardMouseCallback b/include/osgProducer/KeyboardMouseCallback index 39527fd92..576817e46 100644 --- a/include/osgProducer/KeyboardMouseCallback +++ b/include/osgProducer/KeyboardMouseCallback @@ -20,8 +20,7 @@ #include // For definition of KeySymbol #include - -#include +#include #include #include @@ -32,13 +31,7 @@ namespace osgProducer { class OSGPRODUCER_EXPORT KeyboardMouseCallback : public Producer::KeyboardMouseCallback { public: - KeyboardMouseCallback(Producer::KeyboardMouse* keyboardMouse, bool &done, bool escapeKeySetsDone=true) : - Producer::KeyboardMouseCallback(), - _keyboardMouse(keyboardMouse), - _mx(0.0f),_my(0.0f),_mbutton(0), - _done(done), - _escapeKeySetsDone(escapeKeySetsDone) - {} + KeyboardMouseCallback(Producer::KeyboardMouse* keyboardMouse, bool &done, bool escapeKeySetsDone=true); virtual ~KeyboardMouseCallback() {} @@ -68,28 +61,26 @@ class OSGPRODUCER_EXPORT KeyboardMouseCallback : public Producer::KeyboardMouseC // local methods and members - typedef std::vector< osg::ref_ptr > EventQueue; + typedef osgGA::EventQueue::Events EventQueue; - double getEventQueue(EventQueue& queue); - double copyEventQueue(EventQueue& queue) const; - double setEventQueue(EventQueue& queue); - double appendEventQueue(EventQueue& queue); + osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); } + + bool takeEventQueue(EventQueue& queue); + bool copyEventQueue(EventQueue& queue) const; + void setEventQueue(EventQueue& queue); + void appendEventQueue(EventQueue& queue); bool done() const { return _done; } - float mx() const { return _mx; } - float my() const { return _my; } - unsigned int mbutton() const { return _mbutton; } - void setStartTick(osg::Timer_t tick) { _startTick = tick; } - osg::Timer_t getStartTick() const { return _startTick; } - - double getTime() const { return _timer.delta_s(_startTick,_timer.tick()); } + double getTime() const { return _eventQueue->getTime(); } Producer::KeyboardMouse* getKeyboardMouse() { return _keyboardMouse; } const Producer::KeyboardMouse* getKeyboardMouse() const { return _keyboardMouse; } - EventAdapter* createEventAdapter(); + osgGA::GUIEventAdapter* createEventAdapter(); + void updateWindowSize(); + protected: @@ -99,10 +90,7 @@ class OSGPRODUCER_EXPORT KeyboardMouseCallback : public Producer::KeyboardMouseC bool &_done; bool _escapeKeySetsDone; - osg::Timer_t _startTick; - osg::Timer _timer; - mutable OpenThreads::Mutex _eventQueueMutex; - EventQueue _eventQueue; + osg::ref_ptr _eventQueue; }; diff --git a/src/osgGA/AnimationPathManipulator.cpp b/src/osgGA/AnimationPathManipulator.cpp index be62fd5b3..8715c69b7 100644 --- a/src/osgGA/AnimationPathManipulator.cpp +++ b/src/osgGA/AnimationPathManipulator.cpp @@ -57,7 +57,7 @@ void AnimationPathManipulator::home(double currentTime) void AnimationPathManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter&) { - home(ea.time()); + home(ea.getTime()); } void AnimationPathManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& aa) @@ -78,7 +78,7 @@ bool AnimationPathManipulator::handle(const osgGA::GUIEventAdapter& ea,osgGA::GU } else { - handleFrame( ea.time() ); + handleFrame( ea.getTime() ); } return false; case GUIEventAdapter::KEYDOWN: @@ -96,12 +96,12 @@ bool AnimationPathManipulator::handle(const osgGA::GUIEventAdapter& ea,osgGA::GU if( _isPaused ) { _isPaused = false; - _timeOffset -= ea.time() - _pauseTime; + _timeOffset -= ea.getTime() - _pauseTime; } else { _isPaused = true; - _pauseTime = ea.time(); + _pauseTime = ea.getTime(); } us.requestRedraw(); us.requestContinuousUpdate(false); diff --git a/src/osgGA/DriveManipulator.cpp b/src/osgGA/DriveManipulator.cpp index fb1b5cfd1..f2cc08fc2 100644 --- a/src/osgGA/DriveManipulator.cpp +++ b/src/osgGA/DriveManipulator.cpp @@ -486,7 +486,7 @@ bool DriveManipulator::calcMovement() // return if less then two events have been added. if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false; - double dt = _ga_t0->time()-_ga_t1->time(); + double dt = _ga_t0->getTime()-_ga_t1->getTime(); if (dt<0.0f) { diff --git a/src/osgGA/FlightManipulator.cpp b/src/osgGA/FlightManipulator.cpp index 5c1407ef1..379f31f36 100644 --- a/src/osgGA/FlightManipulator.cpp +++ b/src/osgGA/FlightManipulator.cpp @@ -234,7 +234,7 @@ bool FlightManipulator::calcMovement() if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false; - double dt = _ga_t0->time()-_ga_t1->time(); + double dt = _ga_t0->getTime()-_ga_t1->getTime(); if (dt<0.0f) { diff --git a/src/osgGA/GNUmakefile b/src/osgGA/GNUmakefile index 3ce88368e..92890fa6c 100644 --- a/src/osgGA/GNUmakefile +++ b/src/osgGA/GNUmakefile @@ -9,6 +9,7 @@ CXXFILES = \ EventVisitor.cpp\ FlightManipulator.cpp\ UFOManipulator.cpp\ + EventQueue.cpp\ GUIEventAdapter.cpp\ GUIEventHandler.cpp\ GUIEventHandlerVisitor.cpp\ diff --git a/src/osgGA/GUIEventAdapter.cpp b/src/osgGA/GUIEventAdapter.cpp index 11cd0629e..43378bcab 100644 --- a/src/osgGA/GUIEventAdapter.cpp +++ b/src/osgGA/GUIEventAdapter.cpp @@ -11,10 +11,53 @@ * OpenSceneGraph Public License for more details. */ -#include +#include using namespace osgGA; +GUIEventAdapter::GUIEventAdapter(): + _eventType(NONE), + _time(0.0), + _key(0), + _button(0), + _Xmin(0.0), + _Xmax(1.0), + _Ymin(0.0), + _Ymax(1.0), + _mx(0.5), + _my(0.5), + _buttonMask(0), + _modKeyMask(0), + _scrollingMotion(SCROLL_DOWN), + _mouseYOrientation(Y_INCREASING_DOWNWARDS) +{} + +GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs): + Referenced(), + _eventType(rhs._eventType), + _time(rhs._time), + _key(rhs._key), + _button(rhs._button), + _Xmin(rhs._Xmin), + _Xmax(rhs._Xmax), + _Ymin(rhs._Ymin), + _Ymax(rhs._Ymax), + _mx(rhs._mx), + _my(rhs._my), + _buttonMask(rhs._buttonMask), + _modKeyMask(rhs._modKeyMask), + _scrollingMotion(rhs._scrollingMotion), + _mouseYOrientation(rhs._mouseYOrientation) +{} + GUIEventAdapter::~GUIEventAdapter() { } + +void GUIEventAdapter::setWindowSize(float Xmin, float Ymin, float Xmax, float Ymax) +{ + _Xmin = Xmin; + _Ymin = Ymin; + _Xmax = Xmax; + _Ymax = Ymax; +} diff --git a/src/osgGA/GUIEventHandler.cpp b/src/osgGA/GUIEventHandler.cpp index 89ebbd9ee..7e3b9a091 100644 --- a/src/osgGA/GUIEventHandler.cpp +++ b/src/osgGA/GUIEventHandler.cpp @@ -20,15 +20,14 @@ using namespace osgGA; void GUIEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv) { osgGA::EventVisitor* ev = dynamic_cast(nv); - if (ev && ev->getActionAdapter() && !ev->getEventList().empty()) + if (ev && ev->getActionAdapter() && !ev->getEvents().empty()) { - for(osgGA::EventVisitor::EventList::iterator itr = ev->getEventList().begin(); - itr != ev->getEventList().end(); + for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin(); + itr != ev->getEvents().end(); ++itr) { if (handle(*(*itr), *(ev->getActionAdapter()), node, nv)) { - ev->setEventHandled(true); return; } } @@ -39,10 +38,10 @@ void GUIEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv) void GUIEventHandler::event(osg::NodeVisitor* nv, osg::Drawable* drawable) { osgGA::EventVisitor* ev = dynamic_cast(nv); - if (ev && ev->getActionAdapter() && !ev->getEventList().empty()) + if (ev && ev->getActionAdapter() && !ev->getEvents().empty()) { - for(osgGA::EventVisitor::EventList::iterator itr = ev->getEventList().begin(); - itr != ev->getEventList().end(); + for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin(); + itr != ev->getEvents().end(); ++itr) { handle(*(*itr), *(ev->getActionAdapter()), drawable, nv); diff --git a/src/osgGA/NodeTrackerManipulator.cpp b/src/osgGA/NodeTrackerManipulator.cpp index 6145db183..6f392f22d 100644 --- a/src/osgGA/NodeTrackerManipulator.cpp +++ b/src/osgGA/NodeTrackerManipulator.cpp @@ -288,7 +288,7 @@ bool NodeTrackerManipulator::isMouseMoving() float dx = _ga_t0->getXnormalized()-_ga_t1->getXnormalized(); float dy = _ga_t0->getYnormalized()-_ga_t1->getYnormalized(); float len = sqrtf(dx*dx+dy*dy); - float dt = _ga_t0->time()-_ga_t1->time(); + float dt = _ga_t0->getTime()-_ga_t1->getTime(); return (len>dt*velocity); } diff --git a/src/osgGA/TerrainManipulator.cpp b/src/osgGA/TerrainManipulator.cpp index 227d3e6d8..e70675504 100644 --- a/src/osgGA/TerrainManipulator.cpp +++ b/src/osgGA/TerrainManipulator.cpp @@ -189,7 +189,7 @@ bool TerrainManipulator::isMouseMoving() float dx = _ga_t0->getXnormalized()-_ga_t1->getXnormalized(); float dy = _ga_t0->getYnormalized()-_ga_t1->getYnormalized(); float len = sqrtf(dx*dx+dy*dy); - float dt = _ga_t0->time()-_ga_t1->time(); + float dt = _ga_t0->getTime()-_ga_t1->getTime(); return (len>dt*velocity); } diff --git a/src/osgGA/TrackballManipulator.cpp b/src/osgGA/TrackballManipulator.cpp index 7910797bb..33b8f56f5 100644 --- a/src/osgGA/TrackballManipulator.cpp +++ b/src/osgGA/TrackballManipulator.cpp @@ -54,7 +54,7 @@ void TrackballManipulator::home(double /*currentTime*/) void TrackballManipulator::home(const GUIEventAdapter& ea ,GUIActionAdapter& us) { - home(ea.time()); + home(ea.getTime()); us.requestRedraw(); } @@ -167,7 +167,7 @@ bool TrackballManipulator::isMouseMoving() float dx = _ga_t0->getXnormalized()-_ga_t1->getXnormalized(); float dy = _ga_t0->getYnormalized()-_ga_t1->getYnormalized(); float len = sqrtf(dx*dx+dy*dy); - float dt = _ga_t0->time()-_ga_t1->time(); + float dt = _ga_t0->getTime()-_ga_t1->getTime(); return (len>dt*velocity); } diff --git a/src/osgGA/UFOManipulator.cpp b/src/osgGA/UFOManipulator.cpp index ae71c199b..f4c12db07 100644 --- a/src/osgGA/UFOManipulator.cpp +++ b/src/osgGA/UFOManipulator.cpp @@ -161,14 +161,14 @@ void UFOManipulator::computeHomePosition() void UFOManipulator::init(const GUIEventAdapter&, GUIActionAdapter&) { - //home(ea.time()); + //home(ea.getTime()); _stop(); } void UFOManipulator::home(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&) { - home(ea.time()); + home(ea.getTime()); } void UFOManipulator::home(double) @@ -398,17 +398,17 @@ void UFOManipulator::_keyDown( const osgGA::GUIEventAdapter &ea, osgGA::GUIActio break; case 'H': - home(ea.time()); + home(ea.getTime()); break; } } void UFOManipulator::_frame( const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter & ) { - double t1 = ea.time(); + double t1 = ea.getTime(); if( _t0 == 0.0 ) { - _t0 = ea.time(); + _t0 = ea.getTime(); _dt = 0.0; } else diff --git a/src/osgProducer/EventAdapter.cpp b/src/osgProducer/EventAdapter.cpp deleted file mode 100644 index 87deadf30..000000000 --- a/src/osgProducer/EventAdapter.cpp +++ /dev/null @@ -1,229 +0,0 @@ -#include - -using namespace osgProducer; - -// default to no mouse buttons being pressed. -unsigned int EventAdapter::_s_accumulatedButtonMask = 0; - -int EventAdapter::_s_button = 0; -int EventAdapter::_s_modKeyMask = 0; -float EventAdapter::_s_Xmin = 0; -float EventAdapter::_s_Xmax = 1280; -float EventAdapter::_s_Ymin = 0; -float EventAdapter::_s_Ymax = 1024; -float EventAdapter::_s_mx = 0; -float EventAdapter::_s_my = 0; - -EventAdapter::EventAdapter(): - osgGA::GUIEventAdapter(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS) -{ - _eventType = NONE; // adaptor does not encapsulate any events. - _key = -1; // set to 'invalid' key value. - _button = -1; // set to 'invalid' button value. - _mx = -1; // set to 'invalid' position value. - _my = -1; // set to 'invalid' position value. - _buttonMask = 0; // default to no mouse buttons being pressed. - _modKeyMask = 0; // default to no mouse buttons being pressed. - _time = 0.0f; // default to no time has been set. - - copyStaticVariables(); - -} - - -void EventAdapter::copyStaticVariables() -{ - _buttonMask = _s_accumulatedButtonMask; - _modKeyMask = _s_modKeyMask; - _button = _s_button; - _Xmin = _s_Xmin; - _Xmax = _s_Xmax; - _Ymin = _s_Ymin; - _Ymax = _s_Ymax; - _mx = _s_mx; - _my = _s_my; -} - - -void EventAdapter::setWindowSize(float Xmin, float Ymin, float Xmax, float Ymax) -{ - _s_Xmin = Xmin; - _s_Xmax = Xmax; - _s_Ymin = Ymin; - _s_Ymax = Ymax; -} - - -void EventAdapter::setButtonMask(unsigned int buttonMask) -{ - _s_accumulatedButtonMask = buttonMask; -} - - -void EventAdapter::adaptResize(double time, float Xmin, float Ymin, float Xmax, float Ymax) -{ - setWindowSize(Xmin,Ymin,Xmax,Ymax); - _eventType = RESIZE; - _time = time; - 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; - - _eventType = PUSH; - _button = button-1; - - switch(_button) - { - case(0): - _s_accumulatedButtonMask = _s_accumulatedButtonMask | LEFT_MOUSE_BUTTON; - _s_button = LEFT_MOUSE_BUTTON; - break; - case(1): - _s_accumulatedButtonMask = _s_accumulatedButtonMask | MIDDLE_MOUSE_BUTTON; - _s_button = MIDDLE_MOUSE_BUTTON; - break; - case(2): - _s_accumulatedButtonMask = _s_accumulatedButtonMask | RIGHT_MOUSE_BUTTON; - _s_button = RIGHT_MOUSE_BUTTON; - break; - } - - _s_mx = x; - _s_my = y; - - copyStaticVariables(); -} - -void EventAdapter::adaptButtonRelease(double time,float x, float y, unsigned int button) -{ - _time = time; - - _eventType = RELEASE; - _button = button-1; - - switch(_button) - { - case(0): - _s_accumulatedButtonMask = _s_accumulatedButtonMask & ~LEFT_MOUSE_BUTTON; - _s_button = LEFT_MOUSE_BUTTON; - break; - case(1): - _s_accumulatedButtonMask = _s_accumulatedButtonMask & ~MIDDLE_MOUSE_BUTTON; - _s_button = MIDDLE_MOUSE_BUTTON; - break; - case(2): - _s_accumulatedButtonMask = _s_accumulatedButtonMask & ~RIGHT_MOUSE_BUTTON; - _s_button = RIGHT_MOUSE_BUTTON; - break; - } - - _s_mx = x; - _s_my = y; - - copyStaticVariables(); -} - -/** method for adapting mouse motion events whilst mouse buttons are pressed.*/ -void EventAdapter::adaptMouseMotion(double time, float x, float y) -{ - - _eventType = (_s_accumulatedButtonMask) ? - DRAG : - MOVE; - - _time = time; - _s_mx = x; - _s_my = y; - copyStaticVariables(); - -} - - -/** method for adapting keyboard events.*/ -void EventAdapter::adaptKeyPress( double time, Producer::KeySymbol key) -{ - _eventType = KEYDOWN; - _time = time; - _key = key; - - switch(key) - { - case(KEY_Shift_L): _s_modKeyMask = MODKEY_LEFT_SHIFT | _s_modKeyMask; break; - case(KEY_Shift_R): _s_modKeyMask = MODKEY_RIGHT_SHIFT | _s_modKeyMask; break; - case(KEY_Control_L): _s_modKeyMask = MODKEY_LEFT_CTRL | _s_modKeyMask; break; - case(KEY_Control_R): _s_modKeyMask = MODKEY_RIGHT_CTRL | _s_modKeyMask; break; - case(KEY_Meta_L): _s_modKeyMask = MODKEY_LEFT_META | _s_modKeyMask; break; - case(KEY_Meta_R): _s_modKeyMask = MODKEY_RIGHT_META | _s_modKeyMask; break; - case(KEY_Alt_L): _s_modKeyMask = MODKEY_LEFT_ALT | _s_modKeyMask; break; - case(KEY_Alt_R): _s_modKeyMask = MODKEY_LEFT_ALT | _s_modKeyMask; break; - - case(KEY_Caps_Lock): - { - if ((_s_modKeyMask & MODKEY_CAPS_LOCK)!=0) - _s_modKeyMask = ~MODKEY_CAPS_LOCK & _s_modKeyMask; - else - _s_modKeyMask = MODKEY_CAPS_LOCK | _s_modKeyMask; - break; - } - case(KEY_Num_Lock): - { - if ((_s_modKeyMask & MODKEY_NUM_LOCK)!=0) - _s_modKeyMask = ~MODKEY_NUM_LOCK & _s_modKeyMask; - else - _s_modKeyMask = MODKEY_NUM_LOCK | _s_modKeyMask; - break; - } - } - - copyStaticVariables(); -} - -void EventAdapter::adaptKeyRelease( double time, Producer::KeySymbol key) -{ - // we won't handle this correctly right now.. GUIEventAdapter isn't up to it - _eventType = KEYUP; - _time = time; - _key = key; - - switch(key) - { - case(KEY_Shift_L): _s_modKeyMask = ~MODKEY_LEFT_SHIFT & _s_modKeyMask; break; - case(KEY_Shift_R): _s_modKeyMask = ~MODKEY_RIGHT_SHIFT & _s_modKeyMask; break; - case(KEY_Control_L): _s_modKeyMask = ~MODKEY_LEFT_CTRL & _s_modKeyMask; break; - case(KEY_Control_R): _s_modKeyMask = ~MODKEY_RIGHT_CTRL & _s_modKeyMask; break; - case(KEY_Meta_L): _s_modKeyMask = ~MODKEY_LEFT_META & _s_modKeyMask; break; - case(KEY_Meta_R): _s_modKeyMask = ~MODKEY_RIGHT_META & _s_modKeyMask; break; - case(KEY_Alt_L): _s_modKeyMask = ~MODKEY_LEFT_ALT & _s_modKeyMask; break; - case(KEY_Alt_R): _s_modKeyMask = ~MODKEY_LEFT_ALT & _s_modKeyMask; break; - } - - copyStaticVariables(); -} - - - -/** method for adapting frame events, i.e. iddle/display callback.*/ -void EventAdapter::adaptFrame(double time) -{ - _eventType = FRAME; - _time = time; - - copyStaticVariables(); -} diff --git a/src/osgProducer/GNUmakefile b/src/osgProducer/GNUmakefile index 77e307dd4..e6cc0a242 100644 --- a/src/osgProducer/GNUmakefile +++ b/src/osgProducer/GNUmakefile @@ -2,7 +2,6 @@ TOPDIR = ../.. include $(TOPDIR)/Make/makedefs CXXFILES =\ - EventAdapter.cpp\ KeyboardMouseCallback.cpp\ GraphicsContextImplementation.cpp\ OsgCameraGroup.cpp\ diff --git a/src/osgProducer/KeyboardMouseCallback.cpp b/src/osgProducer/KeyboardMouseCallback.cpp index 0c6a3482f..b774db81c 100644 --- a/src/osgProducer/KeyboardMouseCallback.cpp +++ b/src/osgProducer/KeyboardMouseCallback.cpp @@ -7,212 +7,98 @@ using namespace osgProducer; +KeyboardMouseCallback::KeyboardMouseCallback(Producer::KeyboardMouse* keyboardMouse, bool &done, bool escapeKeySetsDone): + Producer::KeyboardMouseCallback(), + _keyboardMouse(keyboardMouse), + _mx(0.0f),_my(0.0f),_mbutton(0), + _done(done), + _escapeKeySetsDone(escapeKeySetsDone) +{ + _eventQueue = new osgGA::EventQueue; + _eventQueue->getCurrentEventState()->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS); + updateWindowSize(); +} + void KeyboardMouseCallback::mouseScroll( Producer::KeyboardMouseCallback::ScrollingMotion sm ) { - osg::ref_ptr event = createEventAdapter(); - - _eventQueueMutex.lock(); - event->adaptMouseScroll(getTime(), sm); - _eventQueue.push_back(event); - _eventQueueMutex.unlock(); + updateWindowSize(); + _eventQueue->mouseScroll((osgGA::GUIEventAdapter::ScrollingMotion)sm); } void KeyboardMouseCallback::buttonPress( float mx, float my, unsigned int mbutton ) { - _mx = mx; - _my = my; - _mbutton |= (1<<(mbutton-1)); - - osg::ref_ptr event = createEventAdapter(); - - _eventQueueMutex.lock(); - event->adaptButtonPress(getTime(),mx,my,mbutton); - _eventQueue.push_back(event); - _eventQueueMutex.unlock(); + updateWindowSize(); + _eventQueue->mouseButtonPress(mx,my,mbutton); } void KeyboardMouseCallback::buttonRelease( float mx, float my, unsigned int mbutton ) { - _mx = mx; - _my = my; - _mbutton &= ~(1<<(mbutton-1)); - - osg::ref_ptr event = createEventAdapter(); - - _eventQueueMutex.lock(); - event->adaptButtonRelease(getTime(),mx,my,mbutton); - _eventQueue.push_back(event); - _eventQueueMutex.unlock(); + updateWindowSize(); + _eventQueue->mouseButtonRelease(mx,my,mbutton); } void KeyboardMouseCallback::doubleButtonPress( float mx, float my, unsigned int mbutton ) { - _mx = mx; - _my = my; - _mbutton |= (1<<(mbutton-1)); - - osg::ref_ptr event = createEventAdapter(); - - _eventQueueMutex.lock(); - event->adaptButtonPress(getTime(),mx,my,mbutton); - _eventQueue.push_back(event); - _eventQueueMutex.unlock(); + updateWindowSize(); + _eventQueue->mouseButtonPress(mx,my,mbutton); } void KeyboardMouseCallback::keyPress( Producer::KeyCharacter key ) { - osg::ref_ptr event = createEventAdapter(); - - _eventQueueMutex.lock(); - event->adaptKeyPress(getTime(),key); - _eventQueue.push_back(event); - _eventQueueMutex.unlock(); + updateWindowSize(); + _eventQueue->keyPress((osgGA::GUIEventAdapter::KeySymbol)key); // check against adapted key symbol. if (_escapeKeySetsDone && - event->getKey()==osgGA::GUIEventAdapter::KEY_Escape) _done = true; + (osgGA::GUIEventAdapter::KeySymbol)key==osgGA::GUIEventAdapter::KEY_Escape) _done = true; } void KeyboardMouseCallback::keyRelease( Producer::KeyCharacter key ) { - osg::ref_ptr event = createEventAdapter(); - - _eventQueueMutex.lock(); - event->adaptKeyRelease(getTime(),key); - _eventQueue.push_back(event); - _eventQueueMutex.unlock(); + updateWindowSize(); + _eventQueue->keyRelease((osgGA::GUIEventAdapter::KeySymbol)key); } void KeyboardMouseCallback::specialKeyPress( Producer::KeyCharacter key ) { - osg::ref_ptr event = createEventAdapter(); - - _eventQueueMutex.lock(); - event->adaptKeyPress(getTime(),key); - _eventQueue.push_back(event); - _eventQueueMutex.unlock(); - - // check against adapted key symbol. - if (_escapeKeySetsDone && - event->getKey()==osgGA::GUIEventAdapter::KEY_Escape) _done = true; + updateWindowSize(); + keyPress(key); } void KeyboardMouseCallback::specialKeyRelease( Producer::KeyCharacter key ) { - osg::ref_ptr event = createEventAdapter(); - - _eventQueueMutex.lock(); - event->adaptKeyRelease(getTime(),key); - _eventQueue.push_back(event); - _eventQueueMutex.unlock(); + updateWindowSize(); + keyRelease(key); } void KeyboardMouseCallback::windowConfig( int x, int y, unsigned int width, unsigned int height ) { - osg::ref_ptr event = createEventAdapter(); - - _eventQueueMutex.lock(); - event->adaptResize(getTime(), x, y, x+width, y+height ); - _eventQueue.push_back(event); - _eventQueueMutex.unlock(); + updateWindowSize(); + _eventQueue->windowResize(x,y,x+width,y+height); } void KeyboardMouseCallback::mouseMotion( float mx, float my) { - _mx = mx; - _my = my; - - osg::ref_ptr event = createEventAdapter(); - - _eventQueueMutex.lock(); - event->adaptMouseMotion(getTime(),mx,my); - _eventQueue.push_back(event); - _eventQueueMutex.unlock(); - + updateWindowSize(); + _eventQueue->mouseMotion(mx,my); } void KeyboardMouseCallback::passiveMouseMotion( float mx, float my) { - _mx = mx; - _my = my; - - //std::cout << "mx="<