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

Revision 13041, 11.8 kB (checked in by robert, 2 years ago)

Ran script to remove trailing spaces and tabs

  • 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
69        /** Set the mouse input range.*/
70        void setMouseInputRange(float xMin, float yMin, float xMax, float yMax) { getCurrentEventState()->setInputRange(xMin, yMin, xMax, yMax); }
71
72
73        /** Method for adapting window resize event, placing this event on the back of the event queue. */
74        void windowResize(int x, int y, int width, int height) { windowResize(x,y,width,height,getTime()); }
75
76        /** Method for adapting window resize event, placing this event on the back of the event queue, with specified time. */
77        void windowResize(int x, int y, int width, int height, double time);
78
79
80        /** Method for adapting mouse scroll wheel events, placing this event on the back of the event queue. */
81        void mouseScroll(GUIEventAdapter::ScrollingMotion sm) { mouseScroll(sm,getTime()); }
82
83        /** Method for adapting mouse scroll wheel events, placing this event on the back of the event queue, with specified time. */
84        void mouseScroll(GUIEventAdapter::ScrollingMotion sm, double time);
85
86
87        /** Method for adapting mouse scroll wheel events, placing this event on the back of the event queue. */
88        void mouseScroll2D(float x, float y) { mouseScroll2D(x, y, getTime()); }
89
90        /** Method for adapting mouse scroll wheel events, placing this event on the back of the event queue. */
91        void mouseScroll2D(float x, float y, double time);
92
93
94        /** Method for adapting pen pressure events, placing this event on the back of the event queue.*/
95        void penPressure(float pressure) { penPressure(pressure, getTime()); }
96
97        /** Method for adapting pen pressure events, placing this event on the back of the event queue, with specified time.*/
98        void penPressure(float pressure, double time);
99
100        /** Method for adapting pen orientation events, placing this event on the back of the event queue.*/
101        void penOrientation(float tiltX, float tiltY, float rotation) { penOrientation(tiltX, tiltY, rotation, getTime()); }
102
103        /** Method for adapting pen orientation events, placing this event on the back of the event queue, with specified time.*/
104        void penOrientation(float tiltX, float tiltY, float rotation, double time);
105
106         /** Method for adapting pen proximity events, placing this event on the back of the event queue.*/
107        void penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering) { penProximity(pt, isEntering, getTime()); }
108
109         /** Method for adapting pen proximity events, placing this event on the back of the event queue, with specified time.*/
110        void penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering, double time);
111
112
113        /** Method for updating in response to a mouse warp. Note, just moves the mouse position without creating a new event for it.*/
114        void mouseWarped(float x, float y);
115
116
117        /** Method for adapting mouse motion events, placing this event on the back of the event queue.*/
118        void mouseMotion(float x, float y) { mouseMotion(x,y, getTime()); }
119
120        /** Method for adapting mouse motion events, placing this event on the back of the event queue, with specified time.*/
121        void mouseMotion(float x, float y, double time);
122
123
124        /** Method for adapting mouse button pressed events, placing this event on the back of the event queue.
125          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
126        void mouseButtonPress(float x, float y, unsigned int button) { mouseButtonPress(x, y, button, getTime()); }
127
128        /** Method for adapting mouse button pressed events, placing this event on the back of the event queue, with specified time.
129          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
130        void mouseButtonPress(float x, float y, unsigned int button, double time);
131
132
133        /** Method for adapting mouse button pressed events, placing this event on the back of the event queue.
134          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
135        void mouseDoubleButtonPress(float x, float y, unsigned int button) { mouseDoubleButtonPress(x, y, button, getTime()); }
136
137        /** Method for adapting mouse button pressed events, placing this event on the back of the event queue, with specified time.
138          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
139        void mouseDoubleButtonPress(float x, float y, unsigned int button, double time);
140
141
142        /** Method for adapting mouse button release events, placing this event on the back of the event queue.
143          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
144        void mouseButtonRelease(float x, float y, unsigned int button) { mouseButtonRelease(x, y, button, getTime()); }
145
146        /** Method for adapting mouse button release events, placing this event on the back of the event queue, with specified time.
147          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
148        void mouseButtonRelease(float x, float y, unsigned int button, double time);
149
150
151        /** Method for adapting keyboard press events. Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings.*/
152        void keyPress(int key, int unmodifiedKey = 0) { keyPress(key, getTime(), unmodifiedKey); }
153
154        /** Method for adapting keyboard press events. Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings, with specified time.*/
155        void keyPress(int key, double time, int unmodifiedKey = 0);
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 keyRelease(int key, int unmodifiedKey = 0) { keyRelease(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 keyRelease(int key, double time, int unmodifiedKey = 0);
163
164        GUIEventAdapter* touchBegan(unsigned int id, GUIEventAdapter::TouchPhase phase, float x, float y, double time);
165        GUIEventAdapter*  touchBegan(unsigned int id, GUIEventAdapter::TouchPhase phase,  float x, float y) {
166            return touchBegan(id, phase, x, y, getTime());
167        }
168
169        GUIEventAdapter*  touchMoved(unsigned int id, GUIEventAdapter::TouchPhase phase,  float x, float y, double time);
170        GUIEventAdapter*  touchMoved(unsigned int id, GUIEventAdapter::TouchPhase phase,  float x, float y) {
171            return touchMoved(id, phase, x, y, getTime());
172        }
173
174        GUIEventAdapter*  touchEnded(unsigned int id, GUIEventAdapter::TouchPhase phase,  float x, float y, unsigned int tap_count, double time);
175        GUIEventAdapter*  touchEnded(unsigned int id, GUIEventAdapter::TouchPhase phase,  float x, float y, unsigned int tap_count) {
176            return touchEnded(id, phase, x, y, tap_count, getTime());
177        }
178
179
180
181        /** Method for adapting close window events.*/
182        void closeWindow() { closeWindow(getTime()); }
183
184        /** Method for adapting close window event with specified event time.*/
185        void closeWindow(double time);
186
187
188        /** Method for adapting application quit events.*/
189        void quitApplication() { quitApplication(getTime()); }
190
191        /** Method for adapting application quit events with specified event time.*/
192        void quitApplication(double time);
193
194
195        /** Method for adapting frame events.*/
196        void frame(double time);
197
198
199        void setStartTick(osg::Timer_t tick) { _startTick = tick; clear(); }
200        osg::Timer_t getStartTick() const { return _startTick; }
201
202        double getTime() const { return osg::Timer::instance()->delta_s(_startTick, osg::Timer::instance()->tick()); }
203
204        /** clear all events from queue. */
205        void clear();
206
207        /** convenience method for create an event ready to fill in.  Clones the getCurrentEventState() to produce a up to date event state. */
208        GUIEventAdapter* createEvent();
209
210
211        void setCurrentEventState(GUIEventAdapter* ea) { _accumulateEventState = ea; }
212        GUIEventAdapter* getCurrentEventState() { return _accumulateEventState.get(); }
213        const GUIEventAdapter* getCurrentEventState() const { return _accumulateEventState.get(); }
214
215        /** Method for adapting user defined events */
216        void userEvent(osg::Referenced* userEventData) { userEvent(userEventData, getTime()); }
217
218        /** Method for adapting user defined events with specified event time */
219        void userEvent(osg::Referenced* userEventData, double time);
220
221        void setFirstTouchEmulatesMouse(bool b) { _firstTouchEmulatesMouse = b; }
222        bool getFirstTouchEmulatesMouse() const { return _firstTouchEmulatesMouse; }
223
224    protected:
225
226        virtual ~EventQueue();
227
228        /** Prevent unwanted copy operator.*/
229        EventQueue& operator = (const EventQueue&) { return *this; }
230
231        osg::ref_ptr<GUIEventAdapter>   _accumulateEventState;
232
233        bool                        _useFixedMouseInputRange;
234
235        osg::Timer_t                _startTick;
236        mutable OpenThreads::Mutex  _eventQueueMutex;
237        Events                      _eventQueue;
238        bool                        _firstTouchEmulatesMouse;
239
240};
241
242}
243
244#endif
Note: See TracBrowser for help on using the browser.