EventQueue
Go to the documentation of this file.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 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 OSGGA_EVENTQUEUE
#define OSGGA_EVENTQUEUE 1
#include <osgGA/GUIEventAdapter>
#include <osg/ref_ptr>
#include <osg/Timer>
#include <OpenThreads/Mutex>
#include <list>
namespace osgGA {
class OSGGA_EXPORT EventQueue : public osg::Referenced
{
public:
EventQueue(GUIEventAdapter::MouseYOrientation mouseYOrientation=GUIEventAdapter::Y_INCREASING_DOWNWARDS);
typedef std::list< osg::ref_ptr<Event> > Events;
bool empty() const
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
return _eventQueue.empty();
}
void setEvents(Events& events);
bool takeEvents(Events& events);
bool takeEvents(Events& events, double cutOffTime);
bool copyEvents(Events& events) const;
void appendEvents(Events& events);
void addEvent(Event* event);
void setUseFixedMouseInputRange(bool useFixedMouseInputRange) { _useFixedMouseInputRange = useFixedMouseInputRange; }
bool getUseFixedMouseInputRange() { return _useFixedMouseInputRange; }
void setGraphicsContext(osg::GraphicsContext* context) { getCurrentEventState()->setGraphicsContext(context); }
osg::GraphicsContext* getGraphicsContext() { return getCurrentEventState()->getGraphicsContext(); }
const osg::GraphicsContext* getGraphicsContext() const { return getCurrentEventState()->getGraphicsContext(); }
void syncWindowRectangleWithGraphicsContext();
void setMouseInputRange(float xMin, float yMin, float xMax, float yMax) { getCurrentEventState()->setInputRange(xMin, yMin, xMax, yMax); }
osgGA::GUIEventAdapter* windowResize(int x, int y, int width, int height) { return windowResize(x,y,width,height,getTime()); }
osgGA::GUIEventAdapter* windowResize(int x, int y, int width, int height, double time);
osgGA::GUIEventAdapter* mouseScroll(GUIEventAdapter::ScrollingMotion sm) { return mouseScroll(sm,getTime()); }
osgGA::GUIEventAdapter* mouseScroll(GUIEventAdapter::ScrollingMotion sm, double time);
osgGA::GUIEventAdapter* mouseScroll2D(float x, float y) { return mouseScroll2D(x, y, getTime()); }
osgGA::GUIEventAdapter* mouseScroll2D(float x, float y, double time);
osgGA::GUIEventAdapter* penPressure(float pressure) { return penPressure(pressure, getTime()); }
osgGA::GUIEventAdapter* penPressure(float pressure, double time);
osgGA::GUIEventAdapter* penOrientation(float tiltX, float tiltY, float rotation) { return penOrientation(tiltX, tiltY, rotation, getTime()); }
osgGA::GUIEventAdapter* penOrientation(float tiltX, float tiltY, float rotation, double time);
osgGA::GUIEventAdapter* penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering) { return penProximity(pt, isEntering, getTime()); }
osgGA::GUIEventAdapter* penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering, double time);
void mouseWarped(float x, float y);
osgGA::GUIEventAdapter* mouseMotion(float x, float y) { return mouseMotion(x,y, getTime()); }
osgGA::GUIEventAdapter* mouseMotion(float x, float y, double time);
osgGA::GUIEventAdapter* mouseButtonPress(float x, float y, unsigned int button) { return mouseButtonPress(x, y, button, getTime()); }
osgGA::GUIEventAdapter* mouseButtonPress(float x, float y, unsigned int button, double time);
osgGA::GUIEventAdapter* mouseDoubleButtonPress(float x, float y, unsigned int button) { return mouseDoubleButtonPress(x, y, button, getTime()); }
osgGA::GUIEventAdapter* mouseDoubleButtonPress(float x, float y, unsigned int button, double time);
osgGA::GUIEventAdapter* mouseButtonRelease(float x, float y, unsigned int button) { return mouseButtonRelease(x, y, button, getTime()); }
osgGA::GUIEventAdapter* mouseButtonRelease(float x, float y, unsigned int button, double time);
osgGA::GUIEventAdapter* keyPress(int key, int unmodifiedKey = 0) { return keyPress(key, getTime(), unmodifiedKey); }
osgGA::GUIEventAdapter* keyPress(int key, double time, int unmodifiedKey = 0);
osgGA::GUIEventAdapter* keyRelease(int key, int unmodifiedKey = 0) { return keyRelease(key, getTime(), unmodifiedKey); }
osgGA::GUIEventAdapter* keyRelease(int key, double time, int unmodifiedKey = 0);
GUIEventAdapter* touchBegan(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, double time);
GUIEventAdapter* touchBegan(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y) {
return touchBegan(id, phase, x, y, getTime());
}
GUIEventAdapter* touchMoved(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, double time);
GUIEventAdapter* touchMoved(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y) {
return touchMoved(id, phase, x, y, getTime());
}
GUIEventAdapter* touchEnded(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, unsigned int tap_count, double time);
GUIEventAdapter* touchEnded(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, unsigned int tap_count) {
return touchEnded(id, phase, x, y, tap_count, getTime());
}
osgGA::GUIEventAdapter* closeWindow() { return closeWindow(getTime()); }
osgGA::GUIEventAdapter* closeWindow(double time);
osgGA::GUIEventAdapter* quitApplication() { return quitApplication(getTime()); }
osgGA::GUIEventAdapter* quitApplication(double time);
osgGA::GUIEventAdapter* frame(double time);
void setStartTick(osg::Timer_t tick) { _startTick = tick; clear(); }
osg::Timer_t getStartTick() const { return _startTick; }
double getTime() const { return osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()); }
void clear();
GUIEventAdapter* createEvent();
void setCurrentEventState(GUIEventAdapter* ea) { _accumulateEventState = ea; }
GUIEventAdapter* getCurrentEventState() { return _accumulateEventState.get(); }
const GUIEventAdapter* getCurrentEventState() const { return _accumulateEventState.get(); }
GUIEventAdapter* userEvent(osg::Referenced* userEventData) { return userEvent(userEventData, getTime()); }
GUIEventAdapter* userEvent(osg::Referenced* userEventData, double time);
void setFirstTouchEmulatesMouse(bool b) { _firstTouchEmulatesMouse = b; }
bool getFirstTouchEmulatesMouse() const { return _firstTouchEmulatesMouse; }
protected:
virtual ~EventQueue();
EventQueue& operator = (const EventQueue&) { return *this; }
osg::ref_ptr<GUIEventAdapter> _accumulateEventState;
bool _useFixedMouseInputRange;
osg::Timer_t _startTick;
mutable OpenThreads::Mutex _eventQueueMutex;
Events _eventQueue;
bool _firstTouchEmulatesMouse;
};
}
#endif
GUIEventAdapter
Mutex
Timer
OpenThreads::Mutex
This class provides an object-oriented thread mutex interface.
Definition Mutex:31
OpenThreads::ScopedLock
Definition ScopedLock:25
osgGA::EventQueue::mouseScroll2D
osgGA::GUIEventAdapter * mouseScroll2D(float x, float y)
Definition EventQueue:101
osgGA::EventQueue::penPressure
osgGA::GUIEventAdapter * penPressure(float pressure, double time)
osgGA::EventQueue::userEvent
GUIEventAdapter * userEvent(osg::Referenced *userEventData, double time)
osgGA::EventQueue::setCurrentEventState
void setCurrentEventState(GUIEventAdapter *ea)
Definition EventQueue:224
osgGA::EventQueue::takeEvents
bool takeEvents(Events &events, double cutOffTime)
osgGA::EventQueue::penOrientation
osgGA::GUIEventAdapter * penOrientation(float tiltX, float tiltY, float rotation, double time)
osgGA::EventQueue::setUseFixedMouseInputRange
void setUseFixedMouseInputRange(bool useFixedMouseInputRange)
Definition EventQueue:65
osgGA::EventQueue::touchBegan
GUIEventAdapter * touchBegan(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, double time)
osgGA::EventQueue::clear
void clear()
osgGA::EventQueue::mouseScroll
osgGA::GUIEventAdapter * mouseScroll(GUIEventAdapter::ScrollingMotion sm)
Definition EventQueue:94
osgGA::EventQueue::keyRelease
osgGA::GUIEventAdapter * keyRelease(int key, double time, int unmodifiedKey=0)
osgGA::EventQueue::_useFixedMouseInputRange
bool _useFixedMouseInputRange
Definition EventQueue:246
osgGA::EventQueue::touchMoved
GUIEventAdapter * touchMoved(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, double time)
osgGA::EventQueue::setFirstTouchEmulatesMouse
void setFirstTouchEmulatesMouse(bool b)
Definition EventQueue:234
osgGA::EventQueue::penProximity
osgGA::GUIEventAdapter * penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering)
Definition EventQueue:120
osgGA::EventQueue::_firstTouchEmulatesMouse
bool _firstTouchEmulatesMouse
Definition EventQueue:251
osgGA::EventQueue::userEvent
GUIEventAdapter * userEvent(osg::Referenced *userEventData)
Definition EventQueue:229
osgGA::EventQueue::touchEnded
GUIEventAdapter * touchEnded(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, unsigned int tap_count)
Definition EventQueue:188
osgGA::EventQueue::getStartTick
osg::Timer_t getStartTick() const
Definition EventQueue:213
osgGA::EventQueue::Events
std::list< osg::ref_ptr< Event > > Events
Definition EventQueue:36
osgGA::EventQueue::keyPress
osgGA::GUIEventAdapter * keyPress(int key, double time, int unmodifiedKey=0)
osgGA::EventQueue::keyPress
osgGA::GUIEventAdapter * keyPress(int key, int unmodifiedKey=0)
Definition EventQueue:165
osgGA::EventQueue::getUseFixedMouseInputRange
bool getUseFixedMouseInputRange()
Definition EventQueue:68
osgGA::EventQueue::getCurrentEventState
GUIEventAdapter * getCurrentEventState()
Definition EventQueue:225
osgGA::EventQueue::keyRelease
osgGA::GUIEventAdapter * keyRelease(int key, int unmodifiedKey=0)
Definition EventQueue:172
osgGA::EventQueue::closeWindow
osgGA::GUIEventAdapter * closeWindow()
Definition EventQueue:195
osgGA::EventQueue::touchEnded
GUIEventAdapter * touchEnded(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, unsigned int tap_count, double time)
osgGA::EventQueue::empty
bool empty() const
Definition EventQueue:38
osgGA::EventQueue::addEvent
void addEvent(Event *event)
osgGA::EventQueue::mouseButtonRelease
osgGA::GUIEventAdapter * mouseButtonRelease(float x, float y, unsigned int button, double time)
osgGA::EventQueue::mouseMotion
osgGA::GUIEventAdapter * mouseMotion(float x, float y, double time)
osgGA::EventQueue::penOrientation
osgGA::GUIEventAdapter * penOrientation(float tiltX, float tiltY, float rotation)
Definition EventQueue:114
osgGA::EventQueue::mouseDoubleButtonPress
osgGA::GUIEventAdapter * mouseDoubleButtonPress(float x, float y, unsigned int button)
Definition EventQueue:148
osgGA::EventQueue::windowResize
osgGA::GUIEventAdapter * windowResize(int x, int y, int width, int height, double time)
osgGA::EventQueue::~EventQueue
virtual ~EventQueue()
osgGA::EventQueue::mouseButtonPress
osgGA::GUIEventAdapter * mouseButtonPress(float x, float y, unsigned int button)
Definition EventQueue:139
osgGA::EventQueue::touchMoved
GUIEventAdapter * touchMoved(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y)
Definition EventQueue:183
osgGA::EventQueue::closeWindow
osgGA::GUIEventAdapter * closeWindow(double time)
osgGA::EventQueue::appendEvents
void appendEvents(Events &events)
osgGA::EventQueue::mouseButtonRelease
osgGA::GUIEventAdapter * mouseButtonRelease(float x, float y, unsigned int button)
Definition EventQueue:157
osgGA::EventQueue::mouseButtonPress
osgGA::GUIEventAdapter * mouseButtonPress(float x, float y, unsigned int button, double time)
osgGA::EventQueue::setStartTick
void setStartTick(osg::Timer_t tick)
Definition EventQueue:212
osgGA::EventQueue::getCurrentEventState
const GUIEventAdapter * getCurrentEventState() const
Definition EventQueue:226
osgGA::EventQueue::setEvents
void setEvents(Events &events)
osgGA::EventQueue::penProximity
osgGA::GUIEventAdapter * penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering, double time)
osgGA::EventQueue::getGraphicsContext
const osg::GraphicsContext * getGraphicsContext() const
Definition EventQueue:76
osgGA::EventQueue::quitApplication
osgGA::GUIEventAdapter * quitApplication()
Definition EventQueue:202
osgGA::EventQueue::createEvent
GUIEventAdapter * createEvent()
osgGA::EventQueue::getTime
double getTime() const
Definition EventQueue:215
osgGA::EventQueue::windowResize
osgGA::GUIEventAdapter * windowResize(int x, int y, int width, int height)
Definition EventQueue:87
osgGA::EventQueue::_eventQueueMutex
OpenThreads::Mutex _eventQueueMutex
Definition EventQueue:249
osgGA::EventQueue::takeEvents
bool takeEvents(Events &events)
osgGA::EventQueue::getFirstTouchEmulatesMouse
bool getFirstTouchEmulatesMouse() const
Definition EventQueue:235
osgGA::EventQueue::penPressure
osgGA::GUIEventAdapter * penPressure(float pressure)
Definition EventQueue:108
osgGA::EventQueue::frame
osgGA::GUIEventAdapter * frame(double time)
osgGA::EventQueue::mouseWarped
void mouseWarped(float x, float y)
osgGA::EventQueue::_startTick
osg::Timer_t _startTick
Definition EventQueue:248
osgGA::EventQueue::_accumulateEventState
osg::ref_ptr< GUIEventAdapter > _accumulateEventState
Definition EventQueue:244
osgGA::EventQueue::copyEvents
bool copyEvents(Events &events) const
osgGA::EventQueue::setGraphicsContext
void setGraphicsContext(osg::GraphicsContext *context)
Definition EventQueue:72
osgGA::EventQueue::setMouseInputRange
void setMouseInputRange(float xMin, float yMin, float xMax, float yMax)
Definition EventQueue:83
osgGA::EventQueue::_eventQueue
Events _eventQueue
Definition EventQueue:250
osgGA::EventQueue::mouseMotion
osgGA::GUIEventAdapter * mouseMotion(float x, float y)
Definition EventQueue:131
osgGA::EventQueue::touchBegan
GUIEventAdapter * touchBegan(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y)
Definition EventQueue:178
osgGA::EventQueue::mouseScroll
osgGA::GUIEventAdapter * mouseScroll(GUIEventAdapter::ScrollingMotion sm, double time)
osgGA::EventQueue::mouseDoubleButtonPress
osgGA::GUIEventAdapter * mouseDoubleButtonPress(float x, float y, unsigned int button, double time)
osgGA::EventQueue::mouseScroll2D
osgGA::GUIEventAdapter * mouseScroll2D(float x, float y, double time)
osgGA::EventQueue::quitApplication
osgGA::GUIEventAdapter * quitApplication(double time)
osgGA::EventQueue::EventQueue
EventQueue(GUIEventAdapter::MouseYOrientation mouseYOrientation=GUIEventAdapter::Y_INCREASING_DOWNWARDS)
osgGA::EventQueue::getGraphicsContext
osg::GraphicsContext * getGraphicsContext()
Definition EventQueue:74
osgGA::EventQueue::syncWindowRectangleWithGraphicsContext
void syncWindowRectangleWithGraphicsContext()
osgGA::Event
Definition Event:27
osgGA::GUIEventAdapter
Definition GUIEventAdapter:82
osgGA::GUIEventAdapter::ScrollingMotion
ScrollingMotion
Definition GUIEventAdapter:360
osgGA::GUIEventAdapter::MouseYOrientation
MouseYOrientation
Definition GUIEventAdapter:354
osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS
@ Y_INCREASING_DOWNWARDS
Definition GUIEventAdapter:356
osgGA::GUIEventAdapter::TouchPhase
TouchPhase
Definition GUIEventAdapter:378
osgGA::GUIEventAdapter::TabletPointerType
TabletPointerType
Definition GUIEventAdapter:370
osg::GraphicsContext
Definition GraphicsContext:30
osg::Referenced
Definition Referenced:44
osg::Timer::instance
static Timer * instance()
osg::Timer::delta_s
double delta_s(Timer_t t1, Timer_t t2) const
Definition Timer:59
osg::ref_ptr
Definition ref_ptr:32
osgGA
Definition Callback:21
osg::Timer_t
unsigned long long Timer_t
Definition Timer:24
OSGGA_EXPORT
#define OSGGA_EXPORT
Definition osgGA/Export:40
ref_ptr