root/OpenSceneGraph/trunk/include/osgGA/EventQueue @ 13376

Revision 13376, 12.1 kB (checked in by robert, 96 minutes ago)

Improved handling of VolumeSettings?

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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
27/**
28 * EventQueue implementation for collecting and adapting windowing events
29 */
30class OSGGA_EXPORT EventQueue : public osg::Referenced
31{
32    public:
33
34        EventQueue(GUIEventAdapter::MouseYOrientation mouseYOrientation=GUIEventAdapter::Y_INCREASING_DOWNWARDS);
35
36        typedef std::list< osg::ref_ptr<GUIEventAdapter> > Events;
37
38        /** Set events.*/
39        void setEvents(Events& events);
40
41        /** Take the entire event queue leaving the EventQueue' event queue empty.*/
42        bool takeEvents(Events& events);
43
44        /** Take the events that were recorded before with specified time queue.*/
45        bool takeEvents(Events& events, double cutOffTime);
46
47        /** Take a copy the entire event queue leaving the EventQueue' event queue intact.*/
48        bool copyEvents(Events& events) const;
49
50        /** Add events to end of event queue.*/
51        void appendEvents(Events& events);
52
53        /** Add an event to the end of the event queue.*/
54        void addEvent(GUIEventAdapter* event);
55
56
57        /** Specify if mouse coordinates should be transformed into a pre defined input range, or whether they
58          * should be simply based on as local coordinates to the window that generated the mouse events.*/
59        void setUseFixedMouseInputRange(bool useFixedMouseInputRange) { _useFixedMouseInputRange = useFixedMouseInputRange; }
60
61        /** Get whether the mouse coordinates should be transformed into a pre defined input range.*/
62        bool getUseFixedMouseInputRange() { return _useFixedMouseInputRange; }
63
64
65        /** Set the graphics context associated with this event queue.*/
66        void setGraphicsContext(osg::GraphicsContext* context) { getCurrentEventState()->setGraphicsContext(context); }
67       
68        osg::GraphicsContext* getGraphicsContext() { return getCurrentEventState()->getGraphicsContext(); }
69
70        const osg::GraphicsContext* getGraphicsContext() const { return getCurrentEventState()->getGraphicsContext(); }
71
72        /** Read the window record dimensions from the graphics context. */
73        void syncWindowRectangleWithGraphcisContext();
74
75
76        /** Set the mouse input range.*/
77        void setMouseInputRange(float xMin, float yMin, float xMax, float yMax) { getCurrentEventState()->setInputRange(xMin, yMin, xMax, yMax); }
78
79
80        /** Method for adapting window resize event, placing this event on the back of the event queue. */
81        void windowResize(int x, int y, int width, int height) { windowResize(x,y,width,height,getTime()); }
82
83        /** Method for adapting window resize event, placing this event on the back of the event queue, with specified time. */
84        void windowResize(int x, int y, int width, int height, double time);
85
86
87        /** Method for adapting mouse scroll wheel events, placing this event on the back of the event queue. */
88        void mouseScroll(GUIEventAdapter::ScrollingMotion sm) { mouseScroll(sm,getTime()); }
89
90        /** Method for adapting mouse scroll wheel events, placing this event on the back of the event queue, with specified time. */
91        void mouseScroll(GUIEventAdapter::ScrollingMotion sm, double time);
92
93
94        /** Method for adapting mouse scroll wheel events, placing this event on the back of the event queue. */
95        void mouseScroll2D(float x, float y) { mouseScroll2D(x, y, getTime()); }
96
97        /** Method for adapting mouse scroll wheel events, placing this event on the back of the event queue. */
98        void mouseScroll2D(float x, float y, double time);
99
100
101        /** Method for adapting pen pressure events, placing this event on the back of the event queue.*/
102        void penPressure(float pressure) { penPressure(pressure, getTime()); }
103
104        /** Method for adapting pen pressure events, placing this event on the back of the event queue, with specified time.*/
105        void penPressure(float pressure, double time);
106
107        /** Method for adapting pen orientation events, placing this event on the back of the event queue.*/
108        void penOrientation(float tiltX, float tiltY, float rotation) { penOrientation(tiltX, tiltY, rotation, getTime()); }
109
110        /** Method for adapting pen orientation events, placing this event on the back of the event queue, with specified time.*/
111        void penOrientation(float tiltX, float tiltY, float rotation, double time);
112
113         /** Method for adapting pen proximity events, placing this event on the back of the event queue.*/
114        void penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering) { penProximity(pt, isEntering, getTime()); }
115
116         /** Method for adapting pen proximity events, placing this event on the back of the event queue, with specified time.*/
117        void penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering, double time);
118
119
120        /** Method for updating in response to a mouse warp. Note, just moves the mouse position without creating a new event for it.*/
121        void mouseWarped(float x, float y);
122
123
124        /** Method for adapting mouse motion events, placing this event on the back of the event queue.*/
125        void mouseMotion(float x, float y) { mouseMotion(x,y, getTime()); }
126
127        /** Method for adapting mouse motion events, placing this event on the back of the event queue, with specified time.*/
128        void mouseMotion(float x, float y, double time);
129
130
131        /** Method for adapting mouse button pressed events, placing this event on the back of the event queue.
132          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
133        void mouseButtonPress(float x, float y, unsigned int button) { mouseButtonPress(x, y, button, getTime()); }
134
135        /** Method for adapting mouse button pressed events, placing this event on the back of the event queue, with specified time.
136          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
137        void mouseButtonPress(float x, float y, unsigned int button, double time);
138
139
140        /** Method for adapting mouse button pressed events, placing this event on the back of the event queue.
141          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
142        void mouseDoubleButtonPress(float x, float y, unsigned int button) { mouseDoubleButtonPress(x, y, button, getTime()); }
143
144        /** Method for adapting mouse button pressed events, placing this event on the back of the event queue, with specified time.
145          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
146        void mouseDoubleButtonPress(float x, float y, unsigned int button, double time);
147
148
149        /** Method for adapting mouse button release events, placing this event on the back of the event queue.
150          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
151        void mouseButtonRelease(float x, float y, unsigned int button) { mouseButtonRelease(x, y, button, getTime()); }
152
153        /** Method for adapting mouse button release events, placing this event on the back of the event queue, with specified time.
154          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
155        void mouseButtonRelease(float x, float y, unsigned int button, double time);
156
157
158        /** Method for adapting keyboard press events. Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings.*/
159        void keyPress(int key, int unmodifiedKey = 0) { keyPress(key, getTime(), unmodifiedKey); }
160
161        /** Method for adapting keyboard press events. Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings, with specified time.*/
162        void keyPress(int key, double time, int unmodifiedKey = 0);
163
164
165        /** Method for adapting keyboard press events. Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings.*/
166        void keyRelease(int key, int unmodifiedKey = 0) { keyRelease(key, getTime(), unmodifiedKey); }
167
168        /** Method for adapting keyboard press events. Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings, with specified time.*/
169        void keyRelease(int key, double time, int unmodifiedKey = 0);
170
171        GUIEventAdapter* touchBegan(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, double time);
172        GUIEventAdapter*  touchBegan(unsigned int id, GUIEventAdapter::TouchPhase phase,  float x, float y) {
173            return touchBegan(id, phase, x, y, getTime());
174        }
175
176        GUIEventAdapter*  touchMoved(unsigned int id, GUIEventAdapter::TouchPhase phase,  float x, float y, double time);
177        GUIEventAdapter*  touchMoved(unsigned int id, GUIEventAdapter::TouchPhase phase,  float x, float y) {
178            return touchMoved(id, phase, x, y, getTime());
179        }
180
181        GUIEventAdapter*  touchEnded(unsigned int id, GUIEventAdapter::TouchPhase phase,  float x, float y, unsigned int tap_count, double time);
182        GUIEventAdapter*  touchEnded(unsigned int id, GUIEventAdapter::TouchPhase phase,  float x, float y, unsigned int tap_count) {
183            return touchEnded(id, phase, x, y, tap_count, getTime());
184        }
185
186
187
188        /** Method for adapting close window events.*/
189        void closeWindow() { closeWindow(getTime()); }
190
191        /** Method for adapting close window event with specified event time.*/
192        void closeWindow(double time);
193
194
195        /** Method for adapting application quit events.*/
196        void quitApplication() { quitApplication(getTime()); }
197
198        /** Method for adapting application quit events with specified event time.*/
199        void quitApplication(double time);
200
201
202        /** Method for adapting frame events.*/
203        void frame(double time);
204
205
206        void setStartTick(osg::Timer_t tick) { _startTick = tick; clear(); }
207        osg::Timer_t getStartTick() const { return _startTick; }
208
209        double getTime() const { return osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()); }
210
211        /** clear all events from queue. */
212        void clear();
213
214        /** convenience method for create an event ready to fill in.  Clones the getCurrentEventState() to produce a up to date event state. */
215        GUIEventAdapter* createEvent();
216
217
218        void setCurrentEventState(GUIEventAdapter* ea) { _accumulateEventState = ea; }
219        GUIEventAdapter* getCurrentEventState() { return _accumulateEventState.get(); }
220        const GUIEventAdapter* getCurrentEventState() const { return _accumulateEventState.get(); }
221
222        /** Method for adapting user defined events */
223        void userEvent(osg::Referenced* userEventData) { userEvent(userEventData, getTime()); }
224
225        /** Method for adapting user defined events with specified event time */
226        void userEvent(osg::Referenced* userEventData, double time);
227
228        void setFirstTouchEmulatesMouse(bool b) { _firstTouchEmulatesMouse = b; }
229        bool getFirstTouchEmulatesMouse() const { return _firstTouchEmulatesMouse; }
230
231    protected:
232
233        virtual ~EventQueue();
234
235        /** Prevent unwanted copy operator.*/
236        EventQueue& operator = (const EventQueue&) { return *this; }
237
238        osg::ref_ptr<GUIEventAdapter>   _accumulateEventState;
239
240        bool                        _useFixedMouseInputRange;
241
242        osg::Timer_t                _startTick;
243        mutable OpenThreads::Mutex  _eventQueueMutex;
244        Events                      _eventQueue;
245        bool                        _firstTouchEmulatesMouse;
246
247};
248
249}
250
251#endif
Note: See TracBrowser for help on using the browser.