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

Revision 13890, 12.2 kB (checked in by robert, 11 hours ago)

Implemented callbacks for validate(), textChanged() and returnPressed()

  • 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<Event> > Events;
37
38        bool empty() const
39        {
40            OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_eventQueueMutex);
41            return _eventQueue.empty();
42        }
43
44        /** Set events.*/
45        void setEvents(Events& events);
46
47        /** Take the entire event queue leaving the EventQueue' event queue empty.*/
48        bool takeEvents(Events& events);
49
50        /** Take the events that were recorded before with specified time queue.*/
51        bool takeEvents(Events& events, double cutOffTime);
52
53        /** Take a copy the entire event queue leaving the EventQueue' event queue intact.*/
54        bool copyEvents(Events& events) const;
55
56        /** Add events to end of event queue.*/
57        void appendEvents(Events& events);
58
59        /** Add an event to the end of the event queue.*/
60        void addEvent(Event* event);
61
62
63        /** Specify if mouse coordinates should be transformed into a pre defined input range, or whether they
64          * should be simply based on as local coordinates to the window that generated the mouse events.*/
65        void setUseFixedMouseInputRange(bool useFixedMouseInputRange) { _useFixedMouseInputRange = useFixedMouseInputRange; }
66
67        /** Get whether the mouse coordinates should be transformed into a pre defined input range.*/
68        bool getUseFixedMouseInputRange() { return _useFixedMouseInputRange; }
69
70
71        /** Set the graphics context associated with this event queue.*/
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
78        /** Read the window record dimensions from the graphics context. */
79        void syncWindowRectangleWithGraphcisContext();
80
81
82        /** Set the mouse input range.*/
83        void setMouseInputRange(float xMin, float yMin, float xMax, float yMax) { getCurrentEventState()->setInputRange(xMin, yMin, xMax, yMax); }
84
85
86        /** Method for adapting window resize event, placing this event on the back of the event queue. */
87        void windowResize(int x, int y, int width, int height) { windowResize(x,y,width,height,getTime()); }
88
89        /** Method for adapting window resize event, placing this event on the back of the event queue, with specified time. */
90        void windowResize(int x, int y, int width, int height, double time);
91
92
93        /** Method for adapting mouse scroll wheel events, placing this event on the back of the event queue. */
94        void mouseScroll(GUIEventAdapter::ScrollingMotion sm) { mouseScroll(sm,getTime()); }
95
96        /** Method for adapting mouse scroll wheel events, placing this event on the back of the event queue, with specified time. */
97        void mouseScroll(GUIEventAdapter::ScrollingMotion sm, double time);
98
99
100        /** Method for adapting mouse scroll wheel events, placing this event on the back of the event queue. */
101        void mouseScroll2D(float x, float y) { mouseScroll2D(x, y, getTime()); }
102
103        /** Method for adapting mouse scroll wheel events, placing this event on the back of the event queue. */
104        void mouseScroll2D(float x, float y, double time);
105
106
107        /** Method for adapting pen pressure events, placing this event on the back of the event queue.*/
108        void penPressure(float pressure) { penPressure(pressure, getTime()); }
109
110        /** Method for adapting pen pressure events, placing this event on the back of the event queue, with specified time.*/
111        void penPressure(float pressure, double time);
112
113        /** Method for adapting pen orientation events, placing this event on the back of the event queue.*/
114        void penOrientation(float tiltX, float tiltY, float rotation) { penOrientation(tiltX, tiltY, rotation, getTime()); }
115
116        /** Method for adapting pen orientation events, placing this event on the back of the event queue, with specified time.*/
117        void penOrientation(float tiltX, float tiltY, float rotation, double time);
118
119         /** Method for adapting pen proximity events, placing this event on the back of the event queue.*/
120        void penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering) { penProximity(pt, isEntering, getTime()); }
121
122         /** Method for adapting pen proximity events, placing this event on the back of the event queue, with specified time.*/
123        void penProximity(GUIEventAdapter::TabletPointerType pt, bool isEntering, double time);
124
125
126        /** Method for updating in response to a mouse warp. Note, just moves the mouse position without creating a new event for it.*/
127        void mouseWarped(float x, float y);
128
129
130        /** Method for adapting mouse motion events, placing this event on the back of the event queue.*/
131        void mouseMotion(float x, float y) { mouseMotion(x,y, getTime()); }
132
133        /** Method for adapting mouse motion events, placing this event on the back of the event queue, with specified time.*/
134        void mouseMotion(float x, float y, double time);
135
136
137        /** Method for adapting mouse button pressed events, placing this event on the back of the event queue.
138          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
139        void mouseButtonPress(float x, float y, unsigned int button) { mouseButtonPress(x, y, button, getTime()); }
140
141        /** Method for adapting mouse button pressed events, placing this event on the back of the event queue, with specified time.
142          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
143        void mouseButtonPress(float x, float y, unsigned int button, double time);
144
145
146        /** Method for adapting mouse button pressed events, placing this event on the back of the event queue.
147          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
148        void mouseDoubleButtonPress(float x, float y, unsigned int button) { mouseDoubleButtonPress(x, y, button, getTime()); }
149
150        /** Method for adapting mouse button pressed events, placing this event on the back of the event queue, with specified time.
151          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
152        void mouseDoubleButtonPress(float x, float y, unsigned int button, double time);
153
154
155        /** Method for adapting mouse button release events, placing this event on the back of the event queue.
156          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
157        void mouseButtonRelease(float x, float y, unsigned int button) { mouseButtonRelease(x, y, button, getTime()); }
158
159        /** Method for adapting mouse button release events, placing this event on the back of the event queue, with specified time.
160          * Button numbering is 1 for left mouse button, 2 for middle, 3 for right. */
161        void mouseButtonRelease(float x, float y, unsigned int button, double time);
162
163
164        /** Method for adapting keyboard press events. Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings.*/
165        void keyPress(int key, int unmodifiedKey = 0) { keyPress(key, getTime(), unmodifiedKey); }
166
167        /** Method for adapting keyboard press events. Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings, with specified time.*/
168        void keyPress(int key, double time, int unmodifiedKey = 0);
169
170
171        /** Method for adapting keyboard press events. Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings.*/
172        void keyRelease(int key, int unmodifiedKey = 0) { keyRelease(key, getTime(), unmodifiedKey); }
173
174        /** Method for adapting keyboard press events. Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings, with specified time.*/
175        void 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
194        /** Method for adapting close window events.*/
195        void closeWindow() { closeWindow(getTime()); }
196
197        /** Method for adapting close window event with specified event time.*/
198        void closeWindow(double time);
199
200
201        /** Method for adapting application quit events.*/
202        void quitApplication() { quitApplication(getTime()); }
203
204        /** Method for adapting application quit events with specified event time.*/
205        void quitApplication(double time);
206
207
208        /** Method for adapting frame events.*/
209        void 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
217        /** clear all events from queue. */
218        void clear();
219
220        /** convenience method for create an event ready to fill in.  Clones the getCurrentEventState() to produce a up to date event state. */
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
228        /** Method for adapting user defined events */
229        void userEvent(osg::Referenced* userEventData) { userEvent(userEventData, getTime()); }
230
231        /** Method for adapting user defined events with specified event time */
232        void 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
241        /** Prevent unwanted copy operator.*/
242        EventQueue& operator = (const EventQueue&) { return *this; }
243
244        osg::ref_ptr<GUIEventAdapter>   _accumulateEventState;
245
246        bool                        _useFixedMouseInputRange;
247
248        osg::Timer_t                _startTick;
249        mutable OpenThreads::Mutex  _eventQueueMutex;
250        Events                      _eventQueue;
251        bool                        _firstTouchEmulatesMouse;
252
253};
254
255}
256
257#endif
Note: See TracBrowser for help on using the browser.