root/OpenSceneGraph/trunk/include/osgPresentation/deprecated/SlideEventHandler @ 13890

Revision 13890, 10.8 kB (checked in by robert, 6 hours ago)

Added src/osg/OpenGL.in configuration file and include/osg/OpenGL header files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
1/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
2 *
3 * This software is open source and may be redistributed and/or modified under
4 * the terms of the GNU General Public License (GPL) version 2.0.
5 * The full license is in LICENSE.txt file included with this distribution,.
6 *
7 * This software is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
10 * include LICENSE.txt for more details.
11*/
12
13#ifndef SLIDEEVENTHANDLER
14#define SLIDEEVENTHANDLER 1
15
16#include <osg/Switch>
17#include <osg/Timer>
18#include <osg/ValueObject>
19#include <osg/ImageSequence>
20
21#include <osgGA/GUIEventHandler>
22#include <osgViewer/Viewer>
23
24#include <osgPresentation/deprecated/CompileSlideCallback>
25#include <osgPresentation/deprecated/PropertyManager>
26
27namespace osgPresentation
28{
29
30// forward declare
31class SlideEventHandler;
32
33/// Operations related to click to run/load/key events.
34enum Operation
35{
36    RUN,
37    LOAD,
38    EVENT,
39    JUMP,
40    FORWARD_EVENT
41};
42
43struct JumpData
44{
45    JumpData():
46        relativeJump(true),
47        slideNum(0),
48        layerNum(0) {}
49
50    JumpData(bool in_relativeJump, int in_slideNum, int in_layerNum):
51        relativeJump(in_relativeJump),
52        slideNum(in_slideNum),
53        layerNum(in_layerNum) {}
54
55    JumpData(const std::string& in_slideName, const std::string& in_layerName):
56        relativeJump(true),
57        slideNum(0),
58        layerNum(0),
59        slideName(in_slideName),
60        layerName(in_layerName) {}
61
62    JumpData(const JumpData& rhs):
63        relativeJump(rhs.relativeJump),
64        slideNum(rhs.slideNum),
65        layerNum(rhs.layerNum),
66        slideName(rhs.slideName),
67        layerName(rhs.layerName) {}
68
69    JumpData& operator = (const JumpData& rhs)
70    {
71        if (&rhs==this) return *this;
72        relativeJump = rhs.relativeJump;
73        slideNum = rhs.slideNum;
74        layerNum = rhs.layerNum;
75        slideName = rhs.slideName;
76        layerName = rhs.layerName;
77        return *this;
78    }
79
80    bool requiresJump() const
81    {
82        if (!slideName.empty() || !layerName.empty()) return true;
83        return relativeJump ? (slideNum!=0 || layerNum!=0) : true;
84    }
85
86    bool jump(SlideEventHandler* seh) const;
87
88    bool relativeJump;
89    int slideNum;
90    int layerNum;
91
92    std::string slideName;
93    std::string layerName;
94};
95
96
97struct HomePosition : public virtual osg::Referenced
98{
99    HomePosition() {}
100
101    HomePosition(const osg::Vec3& in_eye, const osg::Vec3& in_center, const osg::Vec3& in_up):
102        eye(in_eye),
103        center(in_center),
104        up(in_up) {}
105
106    osg::Vec3   eye;
107    osg::Vec3   center;
108    osg::Vec3   up;
109};
110
111struct KeyPosition
112{
113    KeyPosition(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX):
114        _key((osgGA::GUIEventAdapter::KeySymbol)key),
115        _x(x),
116        _y(y) {}
117
118
119    void set(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX)
120    {
121        _key = (osgGA::GUIEventAdapter::KeySymbol)key;
122        _x = x;
123        _y = y;
124    }
125
126    osgGA::GUIEventAdapter::KeySymbol _key;
127    float        _x;
128    float        _y;
129};
130
131struct LayerCallback : public virtual osg::Referenced
132{
133    virtual void operator() (osg::Node* node) const = 0;
134};
135
136struct OSGPRESENTATION_EXPORT LayerAttributes : public virtual osg::Referenced
137{
138    LayerAttributes():_duration(0) {}
139    LayerAttributes(double in_duration):_duration(in_duration) {}
140
141    void setDuration(double duration) { _duration = duration; }
142    double getDuration() const { return _duration; }
143
144    typedef std::vector<KeyPosition> Keys;
145    typedef std::vector<std::string> RunStrings;
146
147    void setKeys(const Keys& keys) { _keys = keys; }
148    const Keys& getKeys() const { return _keys; }
149
150    void addKey(const KeyPosition& kp) { _keys.push_back(kp); }
151
152    void setRunStrings(const RunStrings& runStrings) { _runStrings = runStrings; }
153    const RunStrings& getRunStrings() const { return _runStrings; }
154
155    void addRunString(const std::string& runString) { _runStrings.push_back(runString); }
156
157    void setJump(const JumpData& jumpData) { _jumpData = jumpData; }
158    const JumpData& getJumpData() const { return _jumpData; }
159
160    double      _duration;
161    Keys        _keys;
162    RunStrings  _runStrings;
163    JumpData    _jumpData;
164
165    void addEnterCallback(LayerCallback* lc) { _enterLayerCallbacks.push_back(lc); }
166    void addLeaveCallback(LayerCallback* lc) { _leaveLayerCallbacks.push_back(lc); }
167
168    void callEnterCallbacks(osg::Node* node);
169    void callLeaveCallbacks(osg::Node* node);
170
171    typedef std::list< osg::ref_ptr<LayerCallback> > LayerCallbacks;
172    LayerCallbacks _enterLayerCallbacks;
173    LayerCallbacks _leaveLayerCallbacks;
174};
175
176struct FilePathData : public virtual osg::Referenced
177{
178    FilePathData(const osgDB::FilePathList& fpl):filePathList(fpl) {}
179
180    osgDB::FilePathList filePathList;
181};
182
183
184struct dereference_less
185{
186    template<class T, class U>
187    inline bool operator() (const T& lhs,const U& rhs) const
188    {
189        return *lhs < *rhs;
190    }
191};
192
193struct ObjectOperator : public osg::Referenced
194{
195    inline bool operator < (const ObjectOperator& rhs) const { return ptr() < rhs.ptr(); }
196
197    virtual void* ptr() const = 0;
198
199    virtual void enter(SlideEventHandler*) = 0;
200    virtual void frame(SlideEventHandler*) {} ;
201    virtual void maintain(SlideEventHandler*) = 0;
202    virtual void leave(SlideEventHandler*) = 0;
203    virtual void setPause(SlideEventHandler*, bool pause) = 0;
204    virtual void reset(SlideEventHandler*) = 0;
205
206    virtual ~ObjectOperator() {}
207};
208
209class OSGPRESENTATION_EXPORT ActiveOperators
210{
211public:
212    ActiveOperators();
213    ~ActiveOperators();
214
215    void collect(osg::Node* incommingNode, osg::NodeVisitor::TraversalMode tm = osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN);
216
217    void process(SlideEventHandler* seh);
218
219    void frame(SlideEventHandler*);
220
221    void setPause(SlideEventHandler* seh, bool pause);
222    bool getPause() const { return _pause; }
223
224    void reset(SlideEventHandler* seh);
225
226    typedef std::set< osg::ref_ptr<ObjectOperator>, dereference_less >  OperatorList;
227
228protected:
229
230    void processOutgoing(SlideEventHandler* seh);
231    void processIncomming(SlideEventHandler* seh);
232    void processMaintained(SlideEventHandler* seh);
233
234    bool            _pause;
235
236    OperatorList    _previous;
237    OperatorList    _current;
238
239    OperatorList    _outgoing;
240    OperatorList    _incomming;
241    OperatorList    _maintained;
242
243};
244
245class OSGPRESENTATION_EXPORT SlideEventHandler : public osgGA::GUIEventHandler
246{
247public:
248
249    SlideEventHandler(osgViewer::Viewer* viewer=0);
250
251    static SlideEventHandler* instance();
252
253    META_Object(osgslideshowApp,SlideEventHandler);
254
255    void set(osg::Node* model);
256
257    virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
258
259    virtual void getUsage(osg::ApplicationUsage& usage) const;
260
261    osgViewer::Viewer* getViewer() { return _viewer.get(); }
262
263    osg::Switch* getPresentationSwitch() { return _presentationSwitch.get(); }
264
265    enum WhichPosition
266    {
267        FIRST_POSITION = 0,
268        LAST_POSITION = -1
269    };
270
271    void compileSlide(unsigned int slideNum);
272    void releaseSlide(unsigned int slideNum);
273
274    unsigned int getNumSlides();
275
276    int getActiveSlide() const { return _activeSlide; }
277    int getActiveLayer() const { return _activeLayer; }
278
279    osg::Switch* getSlide(int slideNum);
280    osg::Node* getLayer(int slideNum, int layerNum);
281
282    bool selectSlide(int slideNum,int layerNum=FIRST_POSITION);
283    bool selectLayer(int layerNum);
284
285    bool nextLayerOrSlide();
286    bool previousLayerOrSlide();
287
288    bool nextSlide();
289    bool previousSlide();
290
291    bool nextLayer();
292    bool previousLayer();
293
294    bool home();
295
296    void setAutoSteppingActive(bool flag = true) { _autoSteppingActive = flag; }
297    bool getAutoSteppingActive() const { return _autoSteppingActive; }
298
299    void setTimeDelayBetweenSlides(double dt) { _timePerSlide = dt; }
300    double getTimeDelayBetweenSlides() const { return _timePerSlide; }
301
302    double getDuration(const osg::Node* node) const;
303
304    double getCurrentTimeDelayBetweenSlides() const;
305
306    void setReleaseAndCompileOnEachNewSlide(bool flag) { _releaseAndCompileOnEachNewSlide = flag; }
307    bool getReleaseAndCompileOnEachNewSlide() const { return _releaseAndCompileOnEachNewSlide; }
308
309    void setTimeDelayOnNewSlideWithMovies(float t) { _timeDelayOnNewSlideWithMovies = t; }
310    float getTimeDelayOnNewSlideWithMovies() const { return _timeDelayOnNewSlideWithMovies; }
311
312    void setLoopPresentation(bool loop) { _loopPresentation = loop; }
313    bool getLoopPresentation() const { return _loopPresentation; }
314
315    void dispatchEvent(const KeyPosition& keyPosition);
316
317    void setRequestReload(bool flag);
318    bool getRequestReload() const { return _requestReload; }
319
320    double getReferenceTime() const { return _referenceTime; }
321
322protected:
323
324    ~SlideEventHandler() {}
325    SlideEventHandler(const SlideEventHandler&,const osg::CopyOp&) {}
326
327    bool home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa);
328
329    void updateAlpha(bool, bool, float x, float y);
330    void updateLight(float x, float y);
331
332    void updateOperators();
333
334
335    osg::observer_ptr<osgViewer::Viewer>    _viewer;
336
337    osg::observer_ptr<osg::Switch>          _showSwitch;
338    int                                     _activePresentation;
339
340    osg::observer_ptr<osg::Switch>          _presentationSwitch;
341    int                                     _activeSlide;
342
343    osg::observer_ptr<osg::Switch>          _slideSwitch;
344    int                                     _activeLayer;
345
346    bool                                    _firstTraversal;
347    double                                  _referenceTime;
348    double                                  _previousTime;
349    double                                  _timePerSlide;
350    bool                                    _autoSteppingActive;
351    bool                                    _loopPresentation;
352    bool                                    _pause;
353    bool                                    _hold;
354
355    bool                                    _updateLightActive;
356    bool                                    _updateOpacityActive;
357    float                                   _previousX, _previousY;
358
359    bool                                    _cursorOn;
360
361    bool                                    _releaseAndCompileOnEachNewSlide;
362
363    bool                                    _firstSlideOrLayerChange;
364    osg::Timer_t                            _tickAtFirstSlideOrLayerChange;
365    osg::Timer_t                            _tickAtLastSlideOrLayerChange;
366
367    float                                   _timeDelayOnNewSlideWithMovies;
368
369    double                                  _minimumTimeBetweenKeyPresses;
370    double                                  _timeLastKeyPresses;
371
372    ActiveOperators                         _activeOperators;
373
374    osg::ref_ptr<CompileSlideCallback>      _compileSlideCallback;
375
376    bool                                    _requestReload;
377};
378
379}
380
381#endif
Note: See TracBrowser for help on using the browser.