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:
@@ -27,8 +27,7 @@
|
||||
|
||||
#include <osgGA/GUIEventAdapter>
|
||||
#include <osgGA/GUIActionAdapter>
|
||||
|
||||
#include <list>
|
||||
#include <osgGA/EventQueue>
|
||||
|
||||
namespace osgGA {
|
||||
|
||||
@@ -54,45 +53,19 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
|
||||
|
||||
typedef std::list< osg::ref_ptr<GUIEventAdapter> > 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<GUIEventAdapter> _accumulateEventState;
|
||||
|
||||
EventList _events;
|
||||
bool _handled;
|
||||
EventQueue::Events _events;
|
||||
|
||||
};
|
||||
|
||||
|
||||
@@ -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 <osg/Referenced>
|
||||
#include <osgGA/Export>
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
namespace osgGA{
|
||||
|
||||
class GUIEventAdapter;
|
||||
class GUIActionAdapter;
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user