2012-03-22 01:36:20 +08:00
|
|
|
/* -*-c++-*- Present3D - Copyright (C) 1999-2006 Robert Osfield
|
2009-04-27 19:02:18 +08:00
|
|
|
*
|
2012-03-22 01:36:20 +08:00
|
|
|
* This software is open source and may be redistributed and/or modified under
|
2009-04-27 19:02:18 +08:00
|
|
|
* the terms of the GNU General Public License (GPL) version 2.0.
|
|
|
|
* The full license is in LICENSE.txt file included with this distribution,.
|
2012-03-22 01:36:20 +08:00
|
|
|
*
|
2009-04-27 19:02:18 +08:00
|
|
|
* This software is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2012-03-22 01:36:20 +08:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
2009-04-27 19:02:18 +08:00
|
|
|
* include LICENSE.txt for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef SLIDEEVENTHANDLER
|
|
|
|
#define SLIDEEVENTHANDLER 1
|
|
|
|
|
|
|
|
#include <osg/Switch>
|
|
|
|
#include <osg/Timer>
|
2012-11-01 00:07:23 +08:00
|
|
|
#include <osg/ValueObject>
|
|
|
|
#include <osg/ImageSequence>
|
2009-04-27 19:02:18 +08:00
|
|
|
|
|
|
|
#include <osgGA/GUIEventHandler>
|
|
|
|
#include <osgViewer/Viewer>
|
|
|
|
|
2009-06-25 00:03:49 +08:00
|
|
|
#include <osgPresentation/CompileSlideCallback>
|
2012-11-27 23:09:44 +08:00
|
|
|
#include <osgPresentation/PropertyManager>
|
2009-04-30 04:30:21 +08:00
|
|
|
|
|
|
|
namespace osgPresentation
|
|
|
|
{
|
|
|
|
|
2012-11-10 05:32:54 +08:00
|
|
|
// forward declare
|
|
|
|
class SlideEventHandler;
|
|
|
|
|
2009-04-30 04:30:21 +08:00
|
|
|
/// Operations related to click to run/load/key events.
|
|
|
|
enum Operation
|
|
|
|
{
|
|
|
|
RUN,
|
|
|
|
LOAD,
|
|
|
|
EVENT,
|
2013-01-07 20:17:26 +08:00
|
|
|
JUMP,
|
|
|
|
FORWARD_EVENT
|
2009-04-30 04:30:21 +08:00
|
|
|
};
|
|
|
|
|
2012-11-10 05:32:54 +08:00
|
|
|
struct JumpData
|
|
|
|
{
|
|
|
|
JumpData():
|
2012-11-12 18:36:21 +08:00
|
|
|
relativeJump(true),
|
2012-11-10 05:32:54 +08:00
|
|
|
slideNum(0),
|
|
|
|
layerNum(0) {}
|
|
|
|
|
|
|
|
JumpData(bool in_relativeJump, int in_slideNum, int in_layerNum):
|
|
|
|
relativeJump(in_relativeJump),
|
|
|
|
slideNum(in_slideNum),
|
|
|
|
layerNum(in_layerNum) {}
|
|
|
|
|
|
|
|
JumpData(const std::string& in_slideName, const std::string& in_layerName):
|
2012-11-12 18:36:21 +08:00
|
|
|
relativeJump(true),
|
|
|
|
slideNum(0),
|
|
|
|
layerNum(0),
|
2012-11-10 05:32:54 +08:00
|
|
|
slideName(in_slideName),
|
|
|
|
layerName(in_layerName) {}
|
|
|
|
|
|
|
|
JumpData(const JumpData& rhs):
|
|
|
|
relativeJump(rhs.relativeJump),
|
|
|
|
slideNum(rhs.slideNum),
|
|
|
|
layerNum(rhs.layerNum),
|
|
|
|
slideName(rhs.slideName),
|
|
|
|
layerName(rhs.layerName) {}
|
|
|
|
|
|
|
|
JumpData& operator = (const JumpData& rhs)
|
|
|
|
{
|
|
|
|
if (&rhs==this) return *this;
|
|
|
|
relativeJump = rhs.relativeJump;
|
|
|
|
slideNum = rhs.slideNum;
|
|
|
|
layerNum = rhs.layerNum;
|
|
|
|
slideName = rhs.slideName;
|
|
|
|
layerName = rhs.layerName;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool requiresJump() const
|
|
|
|
{
|
|
|
|
if (!slideName.empty() || !layerName.empty()) return true;
|
|
|
|
return relativeJump ? (slideNum!=0 || layerNum!=0) : true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool jump(SlideEventHandler* seh) const;
|
|
|
|
|
|
|
|
bool relativeJump;
|
|
|
|
int slideNum;
|
|
|
|
int layerNum;
|
|
|
|
|
|
|
|
std::string slideName;
|
|
|
|
std::string layerName;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2009-04-30 04:30:21 +08:00
|
|
|
struct HomePosition : public virtual osg::Referenced
|
|
|
|
{
|
|
|
|
HomePosition() {}
|
|
|
|
|
|
|
|
HomePosition(const osg::Vec3& in_eye, const osg::Vec3& in_center, const osg::Vec3& in_up):
|
|
|
|
eye(in_eye),
|
|
|
|
center(in_center),
|
|
|
|
up(in_up) {}
|
|
|
|
|
|
|
|
osg::Vec3 eye;
|
|
|
|
osg::Vec3 center;
|
|
|
|
osg::Vec3 up;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct KeyPosition
|
|
|
|
{
|
|
|
|
KeyPosition(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX):
|
|
|
|
_key((osgGA::GUIEventAdapter::KeySymbol)key),
|
|
|
|
_x(x),
|
|
|
|
_y(y) {}
|
|
|
|
|
|
|
|
|
|
|
|
void set(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX)
|
|
|
|
{
|
|
|
|
_key = (osgGA::GUIEventAdapter::KeySymbol)key;
|
|
|
|
_x = x;
|
|
|
|
_y = y;
|
|
|
|
}
|
|
|
|
|
|
|
|
osgGA::GUIEventAdapter::KeySymbol _key;
|
|
|
|
float _x;
|
|
|
|
float _y;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct LayerCallback : public virtual osg::Referenced
|
|
|
|
{
|
|
|
|
virtual void operator() (osg::Node* node) const = 0;
|
|
|
|
};
|
|
|
|
|
2009-06-25 00:03:49 +08:00
|
|
|
struct OSGPRESENTATION_EXPORT LayerAttributes : public virtual osg::Referenced
|
2009-04-30 04:30:21 +08:00
|
|
|
{
|
2012-11-10 05:32:54 +08:00
|
|
|
LayerAttributes():_duration(0) {}
|
|
|
|
LayerAttributes(double in_duration):_duration(in_duration) {}
|
2009-04-30 04:30:21 +08:00
|
|
|
|
|
|
|
void setDuration(double duration) { _duration = duration; }
|
|
|
|
double getDuration() const { return _duration; }
|
|
|
|
|
|
|
|
typedef std::vector<KeyPosition> Keys;
|
|
|
|
typedef std::vector<std::string> RunStrings;
|
|
|
|
|
|
|
|
void setKeys(const Keys& keys) { _keys = keys; }
|
|
|
|
const Keys& getKeys() const { return _keys; }
|
|
|
|
|
|
|
|
void addKey(const KeyPosition& kp) { _keys.push_back(kp); }
|
|
|
|
|
|
|
|
void setRunStrings(const RunStrings& runStrings) { _runStrings = runStrings; }
|
|
|
|
const RunStrings& getRunStrings() const { return _runStrings; }
|
|
|
|
|
|
|
|
void addRunString(const std::string& runString) { _runStrings.push_back(runString); }
|
|
|
|
|
2012-11-10 05:32:54 +08:00
|
|
|
void setJump(const JumpData& jumpData) { _jumpData = jumpData; }
|
|
|
|
const JumpData& getJumpData() const { return _jumpData; }
|
2009-04-30 04:30:21 +08:00
|
|
|
|
2012-11-10 05:32:54 +08:00
|
|
|
double _duration;
|
|
|
|
Keys _keys;
|
|
|
|
RunStrings _runStrings;
|
|
|
|
JumpData _jumpData;
|
2009-04-30 04:30:21 +08:00
|
|
|
|
|
|
|
void addEnterCallback(LayerCallback* lc) { _enterLayerCallbacks.push_back(lc); }
|
|
|
|
void addLeaveCallback(LayerCallback* lc) { _leaveLayerCallbacks.push_back(lc); }
|
|
|
|
|
|
|
|
void callEnterCallbacks(osg::Node* node);
|
|
|
|
void callLeaveCallbacks(osg::Node* node);
|
|
|
|
|
|
|
|
typedef std::list< osg::ref_ptr<LayerCallback> > LayerCallbacks;
|
|
|
|
LayerCallbacks _enterLayerCallbacks;
|
|
|
|
LayerCallbacks _leaveLayerCallbacks;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct FilePathData : public virtual osg::Referenced
|
|
|
|
{
|
|
|
|
FilePathData(const osgDB::FilePathList& fpl):filePathList(fpl) {}
|
|
|
|
|
|
|
|
osgDB::FilePathList filePathList;
|
|
|
|
};
|
2009-04-27 19:02:18 +08:00
|
|
|
|
|
|
|
|
|
|
|
struct dereference_less
|
|
|
|
{
|
|
|
|
template<class T, class U>
|
|
|
|
inline bool operator() (const T& lhs,const U& rhs) const
|
|
|
|
{
|
|
|
|
return *lhs < *rhs;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct ObjectOperator : public osg::Referenced
|
|
|
|
{
|
|
|
|
inline bool operator < (const ObjectOperator& rhs) const { return ptr() < rhs.ptr(); }
|
|
|
|
|
|
|
|
virtual void* ptr() const = 0;
|
|
|
|
|
2012-10-29 23:58:02 +08:00
|
|
|
virtual void enter(SlideEventHandler*) = 0;
|
2013-01-11 03:55:50 +08:00
|
|
|
virtual void frame(SlideEventHandler*) {} ;
|
2012-10-29 23:58:02 +08:00
|
|
|
virtual void maintain(SlideEventHandler*) = 0;
|
|
|
|
virtual void leave(SlideEventHandler*) = 0;
|
|
|
|
virtual void setPause(SlideEventHandler*, bool pause) = 0;
|
|
|
|
virtual void reset(SlideEventHandler*) = 0;
|
2009-04-27 19:02:18 +08:00
|
|
|
|
|
|
|
virtual ~ObjectOperator() {}
|
|
|
|
};
|
|
|
|
|
2009-06-25 00:03:49 +08:00
|
|
|
class OSGPRESENTATION_EXPORT ActiveOperators
|
2009-04-27 19:02:18 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
ActiveOperators();
|
|
|
|
~ActiveOperators();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
void collect(osg::Node* incommingNode, osg::NodeVisitor::TraversalMode tm = osg::NodeVisitor::TRAVERSE_ACTIVE_CHILDREN);
|
|
|
|
|
2012-10-29 23:58:02 +08:00
|
|
|
void process(SlideEventHandler* seh);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2013-01-11 03:55:50 +08:00
|
|
|
void frame(SlideEventHandler*);
|
|
|
|
|
2012-10-29 23:58:02 +08:00
|
|
|
void setPause(SlideEventHandler* seh, bool pause);
|
2009-04-27 19:02:18 +08:00
|
|
|
bool getPause() const { return _pause; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2012-10-29 23:58:02 +08:00
|
|
|
void reset(SlideEventHandler* seh);
|
2009-04-27 19:02:18 +08:00
|
|
|
|
|
|
|
typedef std::set< osg::ref_ptr<ObjectOperator>, dereference_less > OperatorList;
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2012-10-29 23:58:02 +08:00
|
|
|
void processOutgoing(SlideEventHandler* seh);
|
|
|
|
void processIncomming(SlideEventHandler* seh);
|
|
|
|
void processMaintained(SlideEventHandler* seh);
|
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
bool _pause;
|
|
|
|
|
|
|
|
OperatorList _previous;
|
|
|
|
OperatorList _current;
|
|
|
|
|
|
|
|
OperatorList _outgoing;
|
|
|
|
OperatorList _incomming;
|
|
|
|
OperatorList _maintained;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
2009-06-25 00:03:49 +08:00
|
|
|
class OSGPRESENTATION_EXPORT SlideEventHandler : public osgGA::GUIEventHandler
|
2009-04-27 19:02:18 +08:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
SlideEventHandler(osgViewer::Viewer* viewer=0);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
static SlideEventHandler* instance();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
META_Object(osgslideshowApp,SlideEventHandler);
|
|
|
|
|
|
|
|
void set(osg::Node* model);
|
|
|
|
|
|
|
|
virtual void accept(osgGA::GUIEventHandlerVisitor& v) { v.visit(*this); }
|
|
|
|
|
2009-04-30 04:55:48 +08:00
|
|
|
/** Event traversal node callback method.*/
|
|
|
|
virtual void operator()(osg::Node* node, osg::NodeVisitor* nv);
|
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
virtual bool handle(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter&);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
virtual void getUsage(osg::ApplicationUsage& usage) const;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
osgViewer::Viewer* getViewer() { return _viewer.get(); }
|
|
|
|
|
2012-11-10 05:32:54 +08:00
|
|
|
osg::Switch* getPresentationSwitch() { return _presentationSwitch.get(); }
|
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
enum WhichPosition
|
|
|
|
{
|
|
|
|
FIRST_POSITION = 0,
|
2009-05-04 02:51:13 +08:00
|
|
|
LAST_POSITION = -1
|
2009-04-27 19:02:18 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
void compileSlide(unsigned int slideNum);
|
|
|
|
void releaseSlide(unsigned int slideNum);
|
|
|
|
|
|
|
|
unsigned int getNumSlides();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-05-04 02:51:13 +08:00
|
|
|
int getActiveSlide() const { return _activeSlide; }
|
|
|
|
int getActiveLayer() const { return _activeLayer; }
|
2009-04-27 19:02:18 +08:00
|
|
|
|
2012-11-10 05:32:54 +08:00
|
|
|
osg::Switch* getSlide(int slideNum);
|
|
|
|
osg::Node* getLayer(int slideNum, int layerNum);
|
|
|
|
|
2009-05-04 02:51:13 +08:00
|
|
|
bool selectSlide(int slideNum,int layerNum=FIRST_POSITION);
|
|
|
|
bool selectLayer(int layerNum);
|
2009-04-27 19:02:18 +08:00
|
|
|
|
|
|
|
bool nextLayerOrSlide();
|
|
|
|
bool previousLayerOrSlide();
|
|
|
|
|
|
|
|
bool nextSlide();
|
|
|
|
bool previousSlide();
|
|
|
|
|
|
|
|
bool nextLayer();
|
|
|
|
bool previousLayer();
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
bool home();
|
|
|
|
|
|
|
|
void setAutoSteppingActive(bool flag = true) { _autoSteppingActive = flag; }
|
|
|
|
bool getAutoSteppingActive() const { return _autoSteppingActive; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
void setTimeDelayBetweenSlides(double dt) { _timePerSlide = dt; }
|
|
|
|
double getTimeDelayBetweenSlides() const { return _timePerSlide; }
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
double getDuration(const osg::Node* node) const;
|
|
|
|
|
|
|
|
double getCurrentTimeDelayBetweenSlides() const;
|
|
|
|
|
|
|
|
void setReleaseAndCompileOnEachNewSlide(bool flag) { _releaseAndCompileOnEachNewSlide = flag; }
|
|
|
|
bool getReleaseAndCompileOnEachNewSlide() const { return _releaseAndCompileOnEachNewSlide; }
|
|
|
|
|
|
|
|
void setTimeDelayOnNewSlideWithMovies(float t) { _timeDelayOnNewSlideWithMovies = t; }
|
|
|
|
float getTimeDelayOnNewSlideWithMovies() const { return _timeDelayOnNewSlideWithMovies; }
|
|
|
|
|
|
|
|
void setLoopPresentation(bool loop) { _loopPresentation = loop; }
|
|
|
|
bool getLoopPresentation() const { return _loopPresentation; }
|
|
|
|
|
2010-03-05 20:55:08 +08:00
|
|
|
void dispatchEvent(const KeyPosition& keyPosition);
|
2009-04-27 19:02:18 +08:00
|
|
|
|
2011-11-04 20:50:05 +08:00
|
|
|
void setRequestReload(bool flag);
|
|
|
|
bool getRequestReload() const { return _requestReload; }
|
|
|
|
|
2013-01-11 03:55:50 +08:00
|
|
|
double getReferenceTime() const { return _referenceTime; }
|
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
protected:
|
|
|
|
|
|
|
|
~SlideEventHandler() {}
|
|
|
|
SlideEventHandler(const SlideEventHandler&,const osg::CopyOp&) {}
|
|
|
|
|
|
|
|
bool home(const osgGA::GUIEventAdapter& ea,osgGA::GUIActionAdapter& aa);
|
|
|
|
|
|
|
|
void updateAlpha(bool, bool, float x, float y);
|
|
|
|
void updateLight(float x, float y);
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2012-10-29 23:58:02 +08:00
|
|
|
void updateOperators();
|
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
|
|
|
|
osg::observer_ptr<osgViewer::Viewer> _viewer;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-04-30 04:55:48 +08:00
|
|
|
osg::observer_ptr<osg::Switch> _showSwitch;
|
2009-05-04 02:51:13 +08:00
|
|
|
int _activePresentation;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-04-30 04:55:48 +08:00
|
|
|
osg::observer_ptr<osg::Switch> _presentationSwitch;
|
2009-05-04 02:51:13 +08:00
|
|
|
int _activeSlide;
|
2009-04-27 19:02:18 +08:00
|
|
|
|
2009-04-30 04:55:48 +08:00
|
|
|
osg::observer_ptr<osg::Switch> _slideSwitch;
|
2009-05-04 02:51:13 +08:00
|
|
|
int _activeLayer;
|
2009-04-27 19:02:18 +08:00
|
|
|
|
|
|
|
bool _firstTraversal;
|
2013-01-11 03:55:50 +08:00
|
|
|
double _referenceTime;
|
2009-04-27 19:02:18 +08:00
|
|
|
double _previousTime;
|
|
|
|
double _timePerSlide;
|
|
|
|
bool _autoSteppingActive;
|
|
|
|
bool _loopPresentation;
|
|
|
|
bool _pause;
|
|
|
|
bool _hold;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
bool _updateLightActive;
|
|
|
|
bool _updateOpacityActive;
|
|
|
|
float _previousX, _previousY;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
bool _cursorOn;
|
|
|
|
|
|
|
|
bool _releaseAndCompileOnEachNewSlide;
|
|
|
|
|
|
|
|
bool _firstSlideOrLayerChange;
|
|
|
|
osg::Timer_t _tickAtFirstSlideOrLayerChange;
|
|
|
|
osg::Timer_t _tickAtLastSlideOrLayerChange;
|
|
|
|
|
|
|
|
float _timeDelayOnNewSlideWithMovies;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
double _minimumTimeBetweenKeyPresses;
|
|
|
|
double _timeLastKeyPresses;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
ActiveOperators _activeOperators;
|
2012-03-22 01:36:20 +08:00
|
|
|
|
2009-06-25 00:03:49 +08:00
|
|
|
osg::ref_ptr<CompileSlideCallback> _compileSlideCallback;
|
2009-04-27 19:02:18 +08:00
|
|
|
|
2011-11-04 20:50:05 +08:00
|
|
|
bool _requestReload;
|
2009-04-27 19:02:18 +08:00
|
|
|
};
|
|
|
|
|
2009-04-30 04:30:21 +08:00
|
|
|
}
|
|
|
|
|
2009-04-27 19:02:18 +08:00
|
|
|
#endif
|