Began work on making EventVisitor capable of adapting events directly.

This commit is contained in:
Robert Osfield 2006-03-05 20:46:59 +00:00
parent cdc8b13f14
commit c448e4d791
3 changed files with 124 additions and 100 deletions

View File

@ -55,19 +55,43 @@ 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 setEventHandled(bool handled) { _handled = handled; }
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();
@ -136,9 +160,12 @@ class OSGGA_EXPORT EventVisitor : public osg::NodeVisitor
}
}
osgGA::GUIActionAdapter* _actionAdapter;
EventList _events;
bool _handled;
osgGA::GUIActionAdapter* _actionAdapter;
osg::ref_ptr<GUIEventAdapter> _accumulateEventState;
EventList _events;
bool _handled;
};

View File

@ -225,52 +225,72 @@ public:
MODKEY_META = (MODKEY_LEFT_META|MODKEY_RIGHT_META)
};
/** Get the EventType of the GUI event.*/
virtual EventType getEventType() const = 0;
/** key pressed, return -1 if inappr opriate for this event. */
virtual int getKey() const = 0;
/** button pressed/released, return -1 if inappropriate for this event.*/
virtual int getButton() const = 0;
enum MouseYOrientation
{
Y_INCREASING_UPWARDS,
Y_INCREASING_DOWNWARDS
};
void setMouseYOrientation(MouseYOrientation myo) { _mouseYOrientation = myo; }
MouseYOrientation getMouseYOrientation() const { return _mouseYOrientation; }
enum ScrollingMotion
{
SCROLL_UP,
SCROLL_DOWN
};
/** manimum x mouse position. */
virtual float getXmin() const = 0;
/** Get the EventType of the GUI event.*/
void setEventType(EventType eventType) { _eventType = eventType; }
/** maximum x mouse position. */
virtual float getXmax() const = 0;
/** minimum y mouse position. */
virtual float getYmin() const = 0;
/** maximum y mouse position. */
virtual float getYmax() const = 0;
/** current mouse x position.*/
virtual float getX() const = 0;
/** current mouse y position.*/
virtual float getY() const = 0;
/** current mouse button state */
virtual unsigned int getButtonMask() const = 0;
/** current modkey state */
virtual unsigned int getModKeyMask() const = 0;
/** Get the EventType of the GUI event.*/
virtual EventType getEventType() const { return _eventType; }
/** time in seconds of event. */
virtual double time() const = 0;
void setTime(double time) { _time = time; }
/** time in seconds of event. */
double getTime() const { return _time; }
/** time in seconds of event. */
virtual double time() const { return getTime(); }
inline void setKey(int key) { _key = key; }
/** key pressed, return -1 if inappropriate for this event. */
virtual int getKey() const { return _key; }
/** button pressed/released, return -1 if inappropriate for this event.*/
virtual int getButton() const { return _button; }
/** window minimum x. */
virtual float getXmin() const { return _Xmin; }
/** window maximum x. */
virtual float getXmax() const { return _Xmax; }
/** window minimum y. */
virtual float getYmin() const { return _Ymin; }
/** window maximum y. */
virtual float getYmax() const { return _Ymax; }
inline void setX(float x) { _mx = x; }
/** current mouse x position.*/
virtual float getX() const { return _mx; }
inline void setY(float y) { _my = y; }
/** current mouse y position.*/
virtual float getY() const { return _my; }
inline void setButtonMask(unsigned int mask) { _buttonMask = mask; }
/** current mouse button state */
virtual unsigned int getButtonMask() const { return _buttonMask; }
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.
* 0.0 would be the middle of the window.
@ -287,15 +307,47 @@ public:
else return -(2.0f*(getY()-getYmin())/(getYmax()-getYmin())-1.0f);
}
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) {}
/** Force users to create on heap, so that multiple referencing is safe.*/
virtual ~GUIEventAdapter(); // {}
virtual ~GUIEventAdapter();
public:
EventType _eventType;
double _time;
int _key;
int _button;
float _Xmin,_Xmax;
float _Ymin,_Ymax;
float _mx;
float _my;
unsigned int _buttonMask;
unsigned int _modKeyMask;
MouseYOrientation _mouseYOrientation;
};
}

View File

@ -30,48 +30,6 @@ class OSGPRODUCER_EXPORT EventAdapter : public osgGA::GUIEventAdapter
EventAdapter();
virtual ~EventAdapter() {}
/** Get the EventType of the GUI event.*/
virtual EventType getEventType() const { return _eventType; }
inline void setKey(int key) { _key = key; }
/** key pressed, return -1 if inappropriate for this event. */
virtual int getKey() const { return _key; }
/** button pressed/released, return -1 if inappropriate for this event.*/
virtual int getButton() const { return _button; }
/** window minimum x. */
virtual float getXmin() const { return _Xmin; }
/** window maximum x. */
virtual float getXmax() const { return _Xmax; }
/** window minimum y. */
virtual float getYmin() const { return _Ymin; }
/** window maximum y. */
virtual float getYmax() const { return _Ymax; }
inline void setX(float x) { _mx = x; }
/** current mouse x position.*/
virtual float getX() const { return _mx; }
inline void setY(float y) { _my = y; }
/** current mouse y position.*/
virtual float getY() const { return _my; }
inline void setButtonMak(unsigned int mask) { _buttonMask = mask; }
/** current mouse button state */
virtual unsigned int getButtonMask() const { return _buttonMask; }
/** time in seconds of event. */
virtual double time() const { return _time; }
virtual unsigned int getModKeyMask() const { return _modKeyMask; }
/** static method for setting window dimensions.*/
static void setWindowSize(float Xmin, float Ymin, float Xmax, float Ymax);
@ -104,19 +62,6 @@ class OSGPRODUCER_EXPORT EventAdapter : public osgGA::GUIEventAdapter
void copyStaticVariables();
public:
EventType _eventType;
int _key;
int _button;
float _Xmin,_Xmax;
float _Ymin,_Ymax;
float _mx;
float _my;
unsigned int _buttonMask;
unsigned int _modKeyMask;
double _time;
public:
// used to accumulate the button mask state, it represents