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

Revision 11934, 11.3 kB (checked in by robert, 3 years ago)

From Stephan Huber, "attached you'll find a proposal for handling multi-touch-events with
osgGA. My approach is to bundle all touchpoints into one custom data
structure which is attached to an GUIEventAdapter.

The current approach simulates a moving mouse for the first touch-point,
so basic manipulators do work, sort of.

I created a MultiTouchTrackballManipulator?-class, one touch-point does
rotate the view, two touch-points pan and zoom the view as known from
the iphone or other similar multi-touch-devices. A double-tap (similar
to a double-click) resets the manipulator to its home-position.

The multi-touch-trackball-implementation is not the best, see it as a
first starting point. (there's a demo-video at http://vimeo.com/15017377 )"

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