Added support for naming slides and layers with slide_name and layer_name properties respectively.

Added support for creating events based on key presses using a <key_to_run> and <key_to_jump> tags.
This commit is contained in:
Robert Osfield
2012-11-09 21:32:54 +00:00
parent fd4126dc59
commit ff476e9c15
8 changed files with 424 additions and 183 deletions

View File

@@ -26,6 +26,9 @@
namespace osgPresentation
{
// forward declare
class SlideEventHandler;
/// Operations related to click to run/load/key events.
enum Operation
{
@@ -35,6 +38,60 @@ enum Operation
JUMP
};
struct JumpData
{
JumpData():
relativeJump(false),
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):
relativeJump(false),
slideNum(-1),
layerNum(-1),
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;
};
struct HomePosition : public virtual osg::Referenced
{
HomePosition() {}
@@ -76,8 +133,8 @@ struct LayerCallback : public virtual osg::Referenced
struct OSGPRESENTATION_EXPORT LayerAttributes : public virtual osg::Referenced
{
LayerAttributes():_duration(0),_relativeJump(true),_slideNum(0),_layerNum(0) {}
LayerAttributes(double in_duration):_duration(in_duration),_relativeJump(true),_slideNum(0),_layerNum(0) {}
LayerAttributes():_duration(0) {}
LayerAttributes(double in_duration):_duration(in_duration) {}
void setDuration(double duration) { _duration = duration; }
double getDuration() const { return _duration; }
@@ -95,26 +152,13 @@ struct OSGPRESENTATION_EXPORT LayerAttributes : public virtual osg::Referenced
void addRunString(const std::string& runString) { _runStrings.push_back(runString); }
void setJump(bool relativeJump, int slideNum, int layerNum)
{
_relativeJump = relativeJump;
_slideNum = slideNum;
_layerNum = layerNum;
}
void setJump(const JumpData& jumpData) { _jumpData = jumpData; }
const JumpData& getJumpData() const { return _jumpData; }
bool getRelativeJump() const { return _relativeJump; }
int getSlideNum() const { return _slideNum; }
int getLayerNum() const { return _layerNum; }
bool requiresJump() const { return _relativeJump ? (_slideNum!=0 || _layerNum!=0) : true; }
double _duration;
Keys _keys;
RunStrings _runStrings;
bool _relativeJump;
int _slideNum;
int _layerNum;
double _duration;
Keys _keys;
RunStrings _runStrings;
JumpData _jumpData;
void addEnterCallback(LayerCallback* lc) { _enterLayerCallbacks.push_back(lc); }
void addLeaveCallback(LayerCallback* lc) { _leaveLayerCallbacks.push_back(lc); }
@@ -144,9 +188,6 @@ struct dereference_less
}
};
// forward declare
class SlideEventHandler;
struct ObjectOperator : public osg::Referenced
{
inline bool operator < (const ObjectOperator& rhs) const { return ptr() < rhs.ptr(); }
@@ -282,6 +323,8 @@ public:
osgViewer::Viewer* getViewer() { return _viewer.get(); }
osg::Switch* getPresentationSwitch() { return _presentationSwitch.get(); }
enum WhichPosition
{
FIRST_POSITION = 0,
@@ -296,6 +339,9 @@ public:
int getActiveSlide() const { return _activeSlide; }
int getActiveLayer() const { return _activeLayer; }
osg::Switch* getSlide(int slideNum);
osg::Node* getLayer(int slideNum, int layerNum);
bool selectSlide(int slideNum,int layerNum=FIRST_POSITION);
bool selectLayer(int layerNum);