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

Revision 13721, 11.0 kB (checked in by robert, 5 days ago)

Added shaders to support experimental shader based displacement mapping technique osgTerrain::ShaderTerrain?.

  • 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 void accept(osgGA::GUIEventHandlerVisitor& v) { v.visit(*this); }
258
259    /** Event traversal node callback method.*/
260    virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
261
262    virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
263
264    virtual void getUsage(osg::ApplicationUsage& usage) const;
265
266    osgViewer::Viewer* getViewer() { return _viewer.get(); }
267
268    osg::Switch* getPresentationSwitch() { return _presentationSwitch.get(); }
269
270    enum WhichPosition
271    {
272        FIRST_POSITION = 0,
273        LAST_POSITION = -1
274    };
275
276    void compileSlide(unsigned int slideNum);
277    void releaseSlide(unsigned int slideNum);
278
279    unsigned int getNumSlides();
280
281    int getActiveSlide() const { return _activeSlide; }
282    int getActiveLayer() const { return _activeLayer; }
283
284    osg::Switch* getSlide(int slideNum);
285    osg::Node* getLayer(int slideNum, int layerNum);
286
287    bool selectSlide(int slideNum,int layerNum=FIRST_POSITION);
288    bool selectLayer(int layerNum);
289
290    bool nextLayerOrSlide();
291    bool previousLayerOrSlide();
292
293    bool nextSlide();
294    bool previousSlide();
295
296    bool nextLayer();
297    bool previousLayer();
298
299    bool home();
300
301    void setAutoSteppingActive(bool flag = true) { _autoSteppingActive = flag; }
302    bool getAutoSteppingActive() const { return _autoSteppingActive; }
303
304    void setTimeDelayBetweenSlides(double dt) { _timePerSlide = dt; }
305    double getTimeDelayBetweenSlides() const { return _timePerSlide; }
306
307    double getDuration(const osg::Node* node) const;
308
309    double getCurrentTimeDelayBetweenSlides() const;
310
311    void setReleaseAndCompileOnEachNewSlide(bool flag) { _releaseAndCompileOnEachNewSlide = flag; }
312    bool getReleaseAndCompileOnEachNewSlide() const { return _releaseAndCompileOnEachNewSlide; }
313
314    void setTimeDelayOnNewSlideWithMovies(float t) { _timeDelayOnNewSlideWithMovies = t; }
315    float getTimeDelayOnNewSlideWithMovies() const { return _timeDelayOnNewSlideWithMovies; }
316
317    void setLoopPresentation(bool loop) { _loopPresentation = loop; }
318    bool getLoopPresentation() const { return _loopPresentation; }
319
320    void dispatchEvent(const KeyPosition& keyPosition);
321
322    void setRequestReload(bool flag);
323    bool getRequestReload() const { return _requestReload; }
324
325    double getReferenceTime() const { return _referenceTime; }
326
327protected:
328
329    ~SlideEventHandler() {}
330    SlideEventHandler(const SlideEventHandler&,const osg::CopyOp&) {}
331
332    bool home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa);
333
334    void updateAlpha(bool, bool, float x, float y);
335    void updateLight(float x, float y);
336
337    void updateOperators();
338
339
340    osg::observer_ptr<osgViewer::Viewer>    _viewer;
341
342    osg::observer_ptr<osg::Switch>          _showSwitch;
343    int                                     _activePresentation;
344
345    osg::observer_ptr<osg::Switch>          _presentationSwitch;
346    int                                     _activeSlide;
347
348    osg::observer_ptr<osg::Switch>          _slideSwitch;
349    int                                     _activeLayer;
350
351    bool                                    _firstTraversal;
352    double                                  _referenceTime;
353    double                                  _previousTime;
354    double                                  _timePerSlide;
355    bool                                    _autoSteppingActive;
356    bool                                    _loopPresentation;
357    bool                                    _pause;
358    bool                                    _hold;
359
360    bool                                    _updateLightActive;
361    bool                                    _updateOpacityActive;
362    float                                   _previousX, _previousY;
363
364    bool                                    _cursorOn;
365
366    bool                                    _releaseAndCompileOnEachNewSlide;
367
368    bool                                    _firstSlideOrLayerChange;
369    osg::Timer_t                            _tickAtFirstSlideOrLayerChange;
370    osg::Timer_t                            _tickAtLastSlideOrLayerChange;
371
372    float                                   _timeDelayOnNewSlideWithMovies;
373
374    double                                  _minimumTimeBetweenKeyPresses;
375    double                                  _timeLastKeyPresses;
376
377    ActiveOperators                         _activeOperators;
378
379    osg::ref_ptr<CompileSlideCallback>      _compileSlideCallback;
380
381    bool                                    _requestReload;
382};
383
384}
385
386#endif
Note: See TracBrowser for help on using the browser.