OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
EventQueue.h
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 
25 namespace 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 
68  bool getUseFixedMouseInputRange() { return _useFixedMouseInputRange; }
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 
79  void syncWindowRectangleWithGraphicsContext();
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 
97  osgGA::GUIEventAdapter* mouseScroll(GUIEventAdapter::ScrollingMotion sm, double time);
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 
120  osgGA::GUIEventAdapter* penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering) { return penProximity(pt, isEntering, getTime()); }
121 
123  osgGA::GUIEventAdapter* penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering, double time);
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 
198  osgGA::GUIEventAdapter* closeWindow(double time);
199 
200 
203 
205  osgGA::GUIEventAdapter* quitApplication(double time);
206 
207 
209  osgGA::GUIEventAdapter* frame(double time);
210 
211 
212  void setStartTick(osg::Timer_t tick) { _startTick = tick; clear(); }
213  osg::Timer_t getStartTick() const { return _startTick; }
214 
215  double getTime() const { return osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()); }
216 
218  void clear();
219 
221  GUIEventAdapter* createEvent();
222 
223 
224  void setCurrentEventState(GUIEventAdapter* ea) { _accumulateEventState = ea; }
225  GUIEventAdapter* getCurrentEventState() { return _accumulateEventState.get(); }
226  const GUIEventAdapter* getCurrentEventState() const { return _accumulateEventState.get(); }
227 
229  GUIEventAdapter* userEvent(osg::Referenced* userEventData) { return userEvent(userEventData, getTime()); }
230 
232  GUIEventAdapter* userEvent(osg::Referenced* userEventData, double time);
233 
234  void setFirstTouchEmulatesMouse(bool b) { _firstTouchEmulatesMouse = b; }
235  bool getFirstTouchEmulatesMouse() const { return _firstTouchEmulatesMouse; }
236 
237  protected:
238 
239  virtual ~EventQueue();
240 
242  EventQueue& operator = (const EventQueue&) { return *this; }
243 
245 
247 
250  Events _eventQueue;
252 
253 };
254 
255 }
256 
257 #endif
GUIEventAdapter * getCurrentEventState()
Definition: EventQueue.h:225
osgGA::GUIEventAdapter * mouseScroll(GUIEventAdapter::ScrollingMotion sm)
Definition: EventQueue.h:94
This class provides an object-oriented thread mutex interface.
Definition: Mutex.h:31
osg::GraphicsContext * getGraphicsContext()
Definition: EventQueue.h:74
bool _useFixedMouseInputRange
Definition: EventQueue.h:246
osgGA::GUIEventAdapter * penOrientation(float tiltX, float tiltY, float rotation)
Definition: EventQueue.h:114
GUIEventAdapter * userEvent(osg::Referenced *userEventData)
Definition: EventQueue.h:229
double getTime() const
Definition: EventQueue.h:215
void setGraphicsContext(osg::GraphicsContext *context)
Definition: EventQueue.h:72
void setStartTick(osg::Timer_t tick)
Definition: EventQueue.h:212
double delta_s(Timer_t t1, Timer_t t2) const
Definition: Timer.h:59
osgGA::GUIEventAdapter * mouseMotion(float x, float y)
Definition: EventQueue.h:131
OpenThreads::Mutex _eventQueueMutex
Definition: EventQueue.h:249
unsigned long long Timer_t
Definition: Timer.h:24
osgGA::GUIEventAdapter * mouseScroll2D(float x, float y)
Definition: EventQueue.h:101
std::list< osg::ref_ptr< Event > > Events
Definition: EventQueue.h:36
static Timer * instance()
osgGA::GUIEventAdapter * quitApplication()
Definition: EventQueue.h:202
#define OSGGA_EXPORT
Definition: Export.h:40
GLint GLenum GLsizei width
Definition: GLU.h:71
osgGA::GUIEventAdapter * mouseDoubleButtonPress(float x, float y, unsigned int button)
Definition: EventQueue.h:148
bool getFirstTouchEmulatesMouse() const
Definition: EventQueue.h:235
void setUseFixedMouseInputRange(bool useFixedMouseInputRange)
Definition: EventQueue.h:65
osgGA::GUIEventAdapter * penPressure(float pressure)
Definition: EventQueue.h:108
osgGA::GUIEventAdapter * keyPress(int key, int unmodifiedKey=0)
Definition: EventQueue.h:165
void setCurrentEventState(GUIEventAdapter *ea)
Definition: EventQueue.h:224
osg::Timer_t _startTick
Definition: EventQueue.h:248
osgGA::GUIEventAdapter * closeWindow()
Definition: EventQueue.h:195
osgGA::GUIEventAdapter * mouseButtonPress(float x, float y, unsigned int button)
Definition: EventQueue.h:139
osgGA::GUIEventAdapter * mouseButtonRelease(float x, float y, unsigned int button)
Definition: EventQueue.h:157
GLint GLenum GLsizei GLsizei height
Definition: GLU.h:71
osg::ref_ptr< GUIEventAdapter > _accumulateEventState
Definition: EventQueue.h:244
void setMouseInputRange(float xMin, float yMin, float xMax, float yMax)
Definition: EventQueue.h:83
GUIEventAdapter * touchMoved(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y)
Definition: EventQueue.h:183
const osg::GraphicsContext * getGraphicsContext() const
Definition: EventQueue.h:76
osg::Timer_t getStartTick() const
Definition: EventQueue.h:213
GUIEventAdapter * touchBegan(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y)
Definition: EventQueue.h:178
GUIEventAdapter * touchEnded(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, unsigned int tap_count)
Definition: EventQueue.h:188
const GUIEventAdapter * getCurrentEventState() const
Definition: EventQueue.h:226
void setFirstTouchEmulatesMouse(bool b)
Definition: EventQueue.h:234
bool _firstTouchEmulatesMouse
Definition: EventQueue.h:251
osgGA::GUIEventAdapter * windowResize(int x, int y, int width, int height)
Definition: EventQueue.h:87
bool empty() const
Definition: EventQueue.h:38
bool getUseFixedMouseInputRange()
Definition: EventQueue.h:68
osgGA::GUIEventAdapter * keyRelease(int key, int unmodifiedKey=0)
Definition: EventQueue.h:172
osgGA::GUIEventAdapter * penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering)
Definition: EventQueue.h:120