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.
This commit is contained in:
Robert Osfield
2006-03-08 14:09:47 +00:00
parent 582967286a
commit dbbabf87c6
37 changed files with 450 additions and 835 deletions

View File

@@ -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 <osgProducer/Export>
#include <osgGA/GUIEventAdapter>
#include <Producer/KeyboardMouse>
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

View File

@@ -20,8 +20,7 @@
#include <Producer/RenderSurface> // For definition of KeySymbol
#include <Producer/KeyboardMouse>
#include <osgProducer/EventAdapter>
#include <osgGA/EventQueue>
#include <osg/ref_ptr>
#include <osg/Timer>
@@ -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<EventAdapter> > 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<osgGA::EventQueue> _eventQueue;
};