OpenSceneGraph 3.6.5
EventQueue
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSGGA_EVENTQUEUE
15#define OSGGA_EVENTQUEUE 1
16
17#include <osgGA/GUIEventAdapter>
18
19#include <osg/ref_ptr>
20#include <osg/Timer>
21
22#include <OpenThreads/Mutex>
23#include <list>
24
25namespace osgGA {
26
31{
32 public:
33
35
36 typedef std::list< osg::ref_ptr<Event> > Events;
37
38 bool empty() const
39 {
40 OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
41 return _eventQueue.empty();
42 }
43
45 void setEvents(Events& events);
46
48 bool takeEvents(Events& events);
49
51 bool takeEvents(Events& events, double cutOffTime);
52
54 bool copyEvents(Events& events) const;
55
57 void appendEvents(Events& events);
58
60 void addEvent(Event* event);
61
62
65 void setUseFixedMouseInputRange(bool useFixedMouseInputRange) { _useFixedMouseInputRange = useFixedMouseInputRange; }
66
69
70
72 void setGraphicsContext(osg::GraphicsContext* context) { getCurrentEventState()->setGraphicsContext(context); }
73
74 osg::GraphicsContext* getGraphicsContext() { return getCurrentEventState()->getGraphicsContext(); }
75
76 const osg::GraphicsContext* getGraphicsContext() const { return getCurrentEventState()->getGraphicsContext(); }
77
80
81
83 void setMouseInputRange(float xMin, float yMin, float xMax, float yMax) { getCurrentEventState()->setInputRange(xMin, yMin, xMax, yMax); }
84
85
87 osgGA::GUIEventAdapter* windowResize(int x, int y, int width, int height) { return windowResize(x,y,width,height,getTime()); }
88
90 osgGA::GUIEventAdapter* windowResize(int x, int y, int width, int height, double time);
91
92
95
98
99
101 osgGA::GUIEventAdapter* mouseScroll2D(float x, float y) { return mouseScroll2D(x, y, getTime()); }
102
104 osgGA::GUIEventAdapter* mouseScroll2D(float x, float y, double time);
105
106
108 osgGA::GUIEventAdapter* penPressure(float pressure) { return penPressure(pressure, getTime()); }
109
111 osgGA::GUIEventAdapter* penPressure(float pressure, double time);
112
114 osgGA::GUIEventAdapter* penOrientation(float tiltX, float tiltY, float rotation) { return penOrientation(tiltX, tiltY, rotation, getTime()); }
115
117 osgGA::GUIEventAdapter* penOrientation(float tiltX, float tiltY, float rotation, double time);
118
121
124
125
127 void mouseWarped(float x, float y);
128
129
131 osgGA::GUIEventAdapter* mouseMotion(float x, float y) { return mouseMotion(x,y, getTime()); }
132
134 osgGA::GUIEventAdapter* mouseMotion(float x, float y, double time);
135
136
139 osgGA::GUIEventAdapter* mouseButtonPress(float x, float y, unsigned int button) { return mouseButtonPress(x, y, button, getTime()); }
140
143 osgGA::GUIEventAdapter* mouseButtonPress(float x, float y, unsigned int button, double time);
144
145
148 osgGA::GUIEventAdapter* mouseDoubleButtonPress(float x, float y, unsigned int button) { return mouseDoubleButtonPress(x, y, button, getTime()); }
149
152 osgGA::GUIEventAdapter* mouseDoubleButtonPress(float x, float y, unsigned int button, double time);
153
154
157 osgGA::GUIEventAdapter* mouseButtonRelease(float x, float y, unsigned int button) { return mouseButtonRelease(x, y, button, getTime()); }
158
161 osgGA::GUIEventAdapter* mouseButtonRelease(float x, float y, unsigned int button, double time);
162
163
165 osgGA::GUIEventAdapter* keyPress(int key, int unmodifiedKey = 0) { return keyPress(key, getTime(), unmodifiedKey); }
166
168 osgGA::GUIEventAdapter* keyPress(int key, double time, int unmodifiedKey = 0);
169
170
172 osgGA::GUIEventAdapter* keyRelease(int key, int unmodifiedKey = 0) { return keyRelease(key, getTime(), unmodifiedKey); }
173
175 osgGA::GUIEventAdapter* keyRelease(int key, double time, int unmodifiedKey = 0);
176
177 GUIEventAdapter* touchBegan(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, double time);
178 GUIEventAdapter* touchBegan(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y) {
179 return touchBegan(id, phase, x, y, getTime());
180 }
181
182 GUIEventAdapter* touchMoved(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, double time);
183 GUIEventAdapter* touchMoved(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y) {
184 return touchMoved(id, phase, x, y, getTime());
185 }
186
187 GUIEventAdapter* touchEnded(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, unsigned int tap_count, double time);
188 GUIEventAdapter* touchEnded(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, unsigned int tap_count) {
189 return touchEnded(id, phase, x, y, tap_count, getTime());
190 }
191
192
193
196
199
200
203
206
207
210
211
212 void setStartTick(osg::Timer_t tick) { _startTick = tick; clear(); }
214
215 double getTime() const { return osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()); }
216
218 void clear();
219
222
223
227
229 GUIEventAdapter* userEvent(osg::Referenced* userEventData) { return userEvent(userEventData, getTime()); }
230
232 GUIEventAdapter* userEvent(osg::Referenced* userEventData, double time);
233
236
237 protected:
238
239 virtual ~EventQueue();
240
242 EventQueue& operator = (const EventQueue&) { return *this; }
243
245
247
249 mutable OpenThreads::Mutex _eventQueueMutex;
252
253};
254
255}
256
257#endif
unsigned long long Timer_t
Definition Timer:24
The 'GA' in osgGA stands for 'GUI Abstraction'; the osgGA namespace provides facilities to help devel...
Definition Callback:21
Base class for providing Windowing API agnostic access to creating and managing graphics context.
Definition GraphicsContext:30
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
Base class for providing reference counted objects.
Definition Referenced:44
static Timer * instance()
double delta_s(Timer_t t1, Timer_t t2) const
Get the time in seconds between timer ticks t1 and t2.
Definition Timer:59
Base Event class.
Definition Event:27
osgGA::GUIEventAdapter * mouseScroll2D(float x, float y)
Method for adapting mouse scroll wheel events, placing this event on the back of the event queue.
Definition EventQueue:101
osgGA::GUIEventAdapter * penPressure(float pressure, double time)
Method for adapting pen pressure events, placing this event on the back of the event queue,...
GUIEventAdapter * userEvent(osg::Referenced *userEventData, double time)
Method for adapting user defined events with specified event time.
void setCurrentEventState(GUIEventAdapter *ea)
Definition EventQueue:224
bool takeEvents(Events &events, double cutOffTime)
Take the events that were recorded before with specified time queue.
osgGA::GUIEventAdapter * penOrientation(float tiltX, float tiltY, float rotation, double time)
Method for adapting pen orientation events, placing this event on the back of the event queue,...
void setUseFixedMouseInputRange(bool useFixedMouseInputRange)
Specify if mouse coordinates should be transformed into a pre defined input range,...
Definition EventQueue:65
GUIEventAdapter * touchBegan(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, double time)
void clear()
clear all events from queue.
osgGA::GUIEventAdapter * mouseScroll(GUIEventAdapter::ScrollingMotion sm)
Method for adapting mouse scroll wheel events, placing this event on the back of the event queue.
Definition EventQueue:94
osgGA::GUIEventAdapter * keyRelease(int key, double time, int unmodifiedKey=0)
Method for adapting keyboard press events.
bool _useFixedMouseInputRange
Definition EventQueue:246
GUIEventAdapter * touchMoved(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, double time)
void setFirstTouchEmulatesMouse(bool b)
Definition EventQueue:234
osgGA::GUIEventAdapter * penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering)
Method for adapting pen proximity events, placing this event on the back of the event queue.
Definition EventQueue:120
bool _firstTouchEmulatesMouse
Definition EventQueue:251
GUIEventAdapter * userEvent(osg::Referenced *userEventData)
Method for adapting user defined events.
Definition EventQueue:229
GUIEventAdapter * touchEnded(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, unsigned int tap_count)
Definition EventQueue:188
osg::Timer_t getStartTick() const
Definition EventQueue:213
std::list< osg::ref_ptr< Event > > Events
Definition EventQueue:36
osgGA::GUIEventAdapter * keyPress(int key, double time, int unmodifiedKey=0)
Method for adapting keyboard press events.
osgGA::GUIEventAdapter * keyPress(int key, int unmodifiedKey=0)
Method for adapting keyboard press events.
Definition EventQueue:165
bool getUseFixedMouseInputRange()
Get whether the mouse coordinates should be transformed into a pre defined input range.
Definition EventQueue:68
GUIEventAdapter * getCurrentEventState()
Definition EventQueue:225
osgGA::GUIEventAdapter * keyRelease(int key, int unmodifiedKey=0)
Method for adapting keyboard press events.
Definition EventQueue:172
osgGA::GUIEventAdapter * closeWindow()
Method for adapting close window events.
Definition EventQueue:195
GUIEventAdapter * touchEnded(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, unsigned int tap_count, double time)
bool empty() const
Definition EventQueue:38
void addEvent(Event *event)
Add an event to the end of the event queue.
osgGA::GUIEventAdapter * mouseButtonRelease(float x, float y, unsigned int button, double time)
Method for adapting mouse button release events, placing this event on the back of the event queue,...
osgGA::GUIEventAdapter * mouseMotion(float x, float y, double time)
Method for adapting mouse motion events, placing this event on the back of the event queue,...
osgGA::GUIEventAdapter * penOrientation(float tiltX, float tiltY, float rotation)
Method for adapting pen orientation events, placing this event on the back of the event queue.
Definition EventQueue:114
osgGA::GUIEventAdapter * mouseDoubleButtonPress(float x, float y, unsigned int button)
Method for adapting mouse button pressed events, placing this event on the back of the event queue.
Definition EventQueue:148
osgGA::GUIEventAdapter * windowResize(int x, int y, int width, int height, double time)
Method for adapting window resize event, placing this event on the back of the event queue,...
virtual ~EventQueue()
osgGA::GUIEventAdapter * mouseButtonPress(float x, float y, unsigned int button)
Method for adapting mouse button pressed events, placing this event on the back of the event queue.
Definition EventQueue:139
GUIEventAdapter * touchMoved(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y)
Definition EventQueue:183
osgGA::GUIEventAdapter * closeWindow(double time)
Method for adapting close window event with specified event time.
void appendEvents(Events &events)
Add events to end of event queue.
osgGA::GUIEventAdapter * mouseButtonRelease(float x, float y, unsigned int button)
Method for adapting mouse button release events, placing this event on the back of the event queue.
Definition EventQueue:157
osgGA::GUIEventAdapter * mouseButtonPress(float x, float y, unsigned int button, double time)
Method for adapting mouse button pressed events, placing this event on the back of the event queue,...
void setStartTick(osg::Timer_t tick)
Definition EventQueue:212
const GUIEventAdapter * getCurrentEventState() const
Definition EventQueue:226
void setEvents(Events &events)
Set events.
osgGA::GUIEventAdapter * penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering, double time)
Method for adapting pen proximity events, placing this event on the back of the event queue,...
const osg::GraphicsContext * getGraphicsContext() const
Definition EventQueue:76
osgGA::GUIEventAdapter * quitApplication()
Method for adapting application quit events.
Definition EventQueue:202
GUIEventAdapter * createEvent()
convenience method for create an event ready to fill in.
double getTime() const
Definition EventQueue:215
osgGA::GUIEventAdapter * windowResize(int x, int y, int width, int height)
Method for adapting window resize event, placing this event on the back of the event queue.
Definition EventQueue:87
OpenThreads::Mutex _eventQueueMutex
Definition EventQueue:249
bool takeEvents(Events &events)
Take the entire event queue leaving the EventQueue' event queue empty.
bool getFirstTouchEmulatesMouse() const
Definition EventQueue:235
osgGA::GUIEventAdapter * penPressure(float pressure)
Method for adapting pen pressure events, placing this event on the back of the event queue.
Definition EventQueue:108
osgGA::GUIEventAdapter * frame(double time)
Method for adapting frame events.
void mouseWarped(float x, float y)
Method for updating in response to a mouse warp.
osg::Timer_t _startTick
Definition EventQueue:248
osg::ref_ptr< GUIEventAdapter > _accumulateEventState
Definition EventQueue:244
bool copyEvents(Events &events) const
Take a copy the entire event queue leaving the EventQueue' event queue intact.
void setGraphicsContext(osg::GraphicsContext *context)
Set the graphics context associated with this event queue.
Definition EventQueue:72
void setMouseInputRange(float xMin, float yMin, float xMax, float yMax)
Set the mouse input range.
Definition EventQueue:83
Events _eventQueue
Definition EventQueue:250
osgGA::GUIEventAdapter * mouseMotion(float x, float y)
Method for adapting mouse motion events, placing this event on the back of the event queue.
Definition EventQueue:131
GUIEventAdapter * touchBegan(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y)
Definition EventQueue:178
osgGA::GUIEventAdapter * mouseScroll(GUIEventAdapter::ScrollingMotion sm, double time)
Method for adapting mouse scroll wheel events, placing this event on the back of the event queue,...
osgGA::GUIEventAdapter * mouseDoubleButtonPress(float x, float y, unsigned int button, double time)
Method for adapting mouse button pressed events, placing this event on the back of the event queue,...
osgGA::GUIEventAdapter * mouseScroll2D(float x, float y, double time)
Method for adapting mouse scroll wheel events, placing this event on the back of the event queue.
osgGA::GUIEventAdapter * quitApplication(double time)
Method for adapting application quit events with specified event time.
EventQueue(GUIEventAdapter::MouseYOrientation mouseYOrientation=GUIEventAdapter::Y_INCREASING_DOWNWARDS)
osg::GraphicsContext * getGraphicsContext()
Definition EventQueue:74
void syncWindowRectangleWithGraphicsContext()
Read the window record dimensions from the graphics context.
Event class for storing Keyboard, mouse and window events.
Definition GUIEventAdapter:82
ScrollingMotion
Definition GUIEventAdapter:360
MouseYOrientation
Definition GUIEventAdapter:354
@ Y_INCREASING_DOWNWARDS
Definition GUIEventAdapter:356
TouchPhase
Definition GUIEventAdapter:378
TabletPointerType
Definition GUIEventAdapter:370
#define OSGGA_EXPORT
Definition Export:40

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.