Added scripting support for JumpData, KeyPosition, HomePosition and parts of SlideEventHandler that enable dispatching of user created events.
This commit is contained in:
parent
9b299dc4b9
commit
ee266255eb
@ -41,7 +41,7 @@ enum Operation
|
|||||||
FORWARD_TOUCH_EVENT
|
FORWARD_TOUCH_EVENT
|
||||||
};
|
};
|
||||||
|
|
||||||
struct JumpData
|
struct JumpData : public osg::Object
|
||||||
{
|
{
|
||||||
JumpData():
|
JumpData():
|
||||||
relativeJump(true),
|
relativeJump(true),
|
||||||
@ -60,7 +60,8 @@ struct JumpData
|
|||||||
slideName(in_slideName),
|
slideName(in_slideName),
|
||||||
layerName(in_layerName) {}
|
layerName(in_layerName) {}
|
||||||
|
|
||||||
JumpData(const JumpData& rhs):
|
JumpData(const JumpData& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||||
|
osg::Object(rhs, copyop),
|
||||||
relativeJump(rhs.relativeJump),
|
relativeJump(rhs.relativeJump),
|
||||||
slideNum(rhs.slideNum),
|
slideNum(rhs.slideNum),
|
||||||
layerNum(rhs.layerNum),
|
layerNum(rhs.layerNum),
|
||||||
@ -78,6 +79,8 @@ struct JumpData
|
|||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
META_Object(osgPresentation, JumpData);
|
||||||
|
|
||||||
bool requiresJump() const
|
bool requiresJump() const
|
||||||
{
|
{
|
||||||
if (!slideName.empty() || !layerName.empty()) return true;
|
if (!slideName.empty() || !layerName.empty()) return true;
|
||||||
@ -86,6 +89,21 @@ struct JumpData
|
|||||||
|
|
||||||
bool jump(SlideEventHandler* seh) const;
|
bool jump(SlideEventHandler* seh) const;
|
||||||
|
|
||||||
|
void setRelativeJump(bool flag) { relativeJump = flag; }
|
||||||
|
bool getRelativeJump() const { return relativeJump; }
|
||||||
|
|
||||||
|
void setSlideNum(int num) { slideNum = num; }
|
||||||
|
int getSlideNum() const { return slideNum; }
|
||||||
|
|
||||||
|
void setLayerNum(int num) { layerNum = num; }
|
||||||
|
int getLayerNum() const { return layerNum; }
|
||||||
|
|
||||||
|
void setSlideName(const std::string& name) { slideName = name; }
|
||||||
|
const std::string& getSlideName() const { return slideName; }
|
||||||
|
|
||||||
|
void setLayerName(const std::string& name) { layerName = name; }
|
||||||
|
const std::string& getLayerName() const { return layerName; }
|
||||||
|
|
||||||
bool relativeJump;
|
bool relativeJump;
|
||||||
int slideNum;
|
int slideNum;
|
||||||
int layerNum;
|
int layerNum;
|
||||||
@ -95,21 +113,50 @@ struct JumpData
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
struct HomePosition : public virtual osg::Referenced
|
struct HomePosition : public osg::Object
|
||||||
{
|
{
|
||||||
HomePosition() {}
|
HomePosition():
|
||||||
|
eye(0.0, -1.0, 0.0),
|
||||||
|
center(0.0, 0.0, 0.0),
|
||||||
|
up(0.0, 0.0, 1.0) {}
|
||||||
|
|
||||||
HomePosition(const osg::Vec3& in_eye, const osg::Vec3& in_center, const osg::Vec3& in_up):
|
HomePosition(const osg::Vec3& in_eye, const osg::Vec3& in_center, const osg::Vec3& in_up):
|
||||||
eye(in_eye),
|
eye(in_eye),
|
||||||
center(in_center),
|
center(in_center),
|
||||||
up(in_up) {}
|
up(in_up) {}
|
||||||
|
|
||||||
osg::Vec3 eye;
|
HomePosition(const HomePosition& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||||
osg::Vec3 center;
|
osg::Object(rhs, copyop),
|
||||||
osg::Vec3 up;
|
eye(rhs.eye),
|
||||||
|
center(rhs.center),
|
||||||
|
up(rhs.up) {}
|
||||||
|
|
||||||
|
HomePosition& operator = (const HomePosition& rhs)
|
||||||
|
{
|
||||||
|
if (&rhs==this) return *this;
|
||||||
|
eye = rhs.eye;
|
||||||
|
center = rhs.center;
|
||||||
|
up = rhs.up;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
|
META_Object(osgPresentation, HomePosition);
|
||||||
|
|
||||||
|
void setEye(const osg::Vec3d& e) { eye = e; }
|
||||||
|
const osg::Vec3d& getEye() const { return eye; }
|
||||||
|
|
||||||
|
void setCenter(const osg::Vec3d& c) { center = c; }
|
||||||
|
const osg::Vec3d& getCenter() const { return center; }
|
||||||
|
|
||||||
|
void setUp(const osg::Vec3d& u) { up = u; }
|
||||||
|
const osg::Vec3d& getUp() const { return up; }
|
||||||
|
|
||||||
|
osg::Vec3d eye;
|
||||||
|
osg::Vec3d center;
|
||||||
|
osg::Vec3d up;
|
||||||
};
|
};
|
||||||
|
|
||||||
struct KeyPosition
|
struct KeyPosition : public osg::Object
|
||||||
{
|
{
|
||||||
KeyPosition(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX, bool forward_to_devices = false):
|
KeyPosition(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX, bool forward_to_devices = false):
|
||||||
_key((osgGA::GUIEventAdapter::KeySymbol)key),
|
_key((osgGA::GUIEventAdapter::KeySymbol)key),
|
||||||
@ -117,6 +164,24 @@ struct KeyPosition
|
|||||||
_y(y),
|
_y(y),
|
||||||
_forwardToDevices(forward_to_devices) {}
|
_forwardToDevices(forward_to_devices) {}
|
||||||
|
|
||||||
|
KeyPosition(const KeyPosition& rhs, const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY):
|
||||||
|
osg::Object(rhs, copyop),
|
||||||
|
_key(rhs._key),
|
||||||
|
_x(rhs._x),
|
||||||
|
_y(rhs._y),
|
||||||
|
_forwardToDevices(rhs._forwardToDevices) {}
|
||||||
|
|
||||||
|
META_Object(osgPresentation, KeyPosition);
|
||||||
|
|
||||||
|
KeyPosition& operator = (const KeyPosition& rhs)
|
||||||
|
{
|
||||||
|
if (&rhs==this) return *this;
|
||||||
|
_key = rhs._key;
|
||||||
|
_x = rhs._x;
|
||||||
|
_y = rhs._y;
|
||||||
|
_forwardToDevices = rhs._forwardToDevices;
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
|
||||||
void set(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX, bool forward_to_devices = false)
|
void set(unsigned int key=0, float x=FLT_MAX, float y=FLT_MAX, bool forward_to_devices = false)
|
||||||
{
|
{
|
||||||
@ -126,6 +191,19 @@ struct KeyPosition
|
|||||||
_forwardToDevices = forward_to_devices;
|
_forwardToDevices = forward_to_devices;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void setKey(int key) { _key = static_cast<osgGA::GUIEventAdapter::KeySymbol>(key); }
|
||||||
|
int getKey() const { return _key; }
|
||||||
|
|
||||||
|
void setX(float x) { _x = x; }
|
||||||
|
float getX() const { return _x; }
|
||||||
|
|
||||||
|
void setY(float y) { _y = y; }
|
||||||
|
float getY() const { return _y; }
|
||||||
|
|
||||||
|
void setForwardToDevices(bool flag) { _forwardToDevices = flag; }
|
||||||
|
bool getForwardToDevices() const { return _forwardToDevices; }
|
||||||
|
|
||||||
|
|
||||||
osgGA::GUIEventAdapter::KeySymbol _key;
|
osgGA::GUIEventAdapter::KeySymbol _key;
|
||||||
float _x;
|
float _x;
|
||||||
float _y;
|
float _y;
|
||||||
@ -254,7 +332,7 @@ public:
|
|||||||
|
|
||||||
static SlideEventHandler* instance();
|
static SlideEventHandler* instance();
|
||||||
|
|
||||||
META_Object(osgslideshowApp,SlideEventHandler);
|
META_Object(osgPresentation,SlideEventHandler);
|
||||||
|
|
||||||
void set(osg::Node* model);
|
void set(osg::Node* model);
|
||||||
|
|
||||||
@ -316,7 +394,10 @@ public:
|
|||||||
void setLoopPresentation(bool loop) { _loopPresentation = loop; }
|
void setLoopPresentation(bool loop) { _loopPresentation = loop; }
|
||||||
bool getLoopPresentation() const { return _loopPresentation; }
|
bool getLoopPresentation() const { return _loopPresentation; }
|
||||||
|
|
||||||
|
|
||||||
void dispatchEvent(const KeyPosition& keyPosition);
|
void dispatchEvent(const KeyPosition& keyPosition);
|
||||||
|
void dispatchEvent(osgGA::Event* event);
|
||||||
|
|
||||||
void forwardEventToDevices(osgGA::Event* event);
|
void forwardEventToDevices(osgGA::Event* event);
|
||||||
|
|
||||||
void setRequestReload(bool flag);
|
void setRequestReload(bool flag);
|
||||||
|
@ -39,7 +39,7 @@ SlideEventHandler* SlideEventHandler::instance() { return s_seh.get(); }
|
|||||||
|
|
||||||
bool JumpData::jump(SlideEventHandler* seh) const
|
bool JumpData::jump(SlideEventHandler* seh) const
|
||||||
{
|
{
|
||||||
OSG_INFO<<"Requires jump "<<relativeJump<<", "<<slideNum<<", "<<layerNum<<", "<<slideName<<", "<<layerName<<std::endl;
|
OSG_NOTICE<<"Requires jump"<<seh<<", "<<relativeJump<<", "<<slideNum<<", "<<layerNum<<", "<<slideName<<", "<<layerName<<std::endl;
|
||||||
|
|
||||||
int slideNumToUse = slideNum;
|
int slideNumToUse = slideNum;
|
||||||
int layerNumToUse = layerNum;
|
int layerNumToUse = layerNum;
|
||||||
@ -47,7 +47,8 @@ bool JumpData::jump(SlideEventHandler* seh) const
|
|||||||
if (!slideName.empty())
|
if (!slideName.empty())
|
||||||
{
|
{
|
||||||
osg::Switch* presentation = seh->getPresentationSwitch();
|
osg::Switch* presentation = seh->getPresentationSwitch();
|
||||||
|
if (presentation)
|
||||||
|
{
|
||||||
for(unsigned int i=0; i<presentation->getNumChildren(); ++i)
|
for(unsigned int i=0; i<presentation->getNumChildren(); ++i)
|
||||||
{
|
{
|
||||||
osg::Node* node = seh->getSlide(i);
|
osg::Node* node = seh->getSlide(i);
|
||||||
@ -59,6 +60,7 @@ bool JumpData::jump(SlideEventHandler* seh) const
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
else if (relativeJump)
|
else if (relativeJump)
|
||||||
{
|
{
|
||||||
slideNumToUse = seh->getActiveSlide() + slideNum;
|
slideNumToUse = seh->getActiveSlide() + slideNum;
|
||||||
@ -1552,7 +1554,15 @@ void SlideEventHandler::releaseSlide(unsigned int slideNum)
|
|||||||
|
|
||||||
void SlideEventHandler::forwardEventToDevices(osgGA::Event* event)
|
void SlideEventHandler::forwardEventToDevices(osgGA::Event* event)
|
||||||
{
|
{
|
||||||
|
if (!event) return;
|
||||||
|
|
||||||
// dispatch cloned event to devices
|
// dispatch cloned event to devices
|
||||||
|
if (!_viewer)
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<"Warning: SlideEventHandler::forwardEventToDevices(Event*) error, no Viewer to dispatch to."<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
osgViewer::View::Devices& devices = _viewer->getDevices();
|
osgViewer::View::Devices& devices = _viewer->getDevices();
|
||||||
for(osgViewer::View::Devices::iterator i = devices.begin(); i != devices.end(); ++i)
|
for(osgViewer::View::Devices::iterator i = devices.begin(); i != devices.end(); ++i)
|
||||||
{
|
{
|
||||||
@ -1563,8 +1573,36 @@ void SlideEventHandler::forwardEventToDevices(osgGA::Event* event)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void SlideEventHandler::dispatchEvent(osgGA::Event* event)
|
||||||
|
{
|
||||||
|
if (!event) return;
|
||||||
|
|
||||||
|
// dispatch cloned event to devices
|
||||||
|
if (!_viewer)
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<"Warning: SlideEventHandler::forwardEventToDevices(Event*) error, no Viewer to dispatch to."<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
osgGA::EventQueue* eq = _viewer!=0 ? _viewer->getEventQueue() : 0;
|
||||||
|
if (!eq)
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<"Warning: SlideEventHandler::dispatchEvent(KeyPosition&) error, no EventQueue to dispatch to."<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
eq->addEvent(event);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void SlideEventHandler::dispatchEvent(const KeyPosition& keyPosition)
|
void SlideEventHandler::dispatchEvent(const KeyPosition& keyPosition)
|
||||||
{
|
{
|
||||||
|
if (!_viewer)
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<"Warning: SlideEventHandler::dispatchEvent(KeyPosition*) error, no Viewer to dispatch to."<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (keyPosition._forwardToDevices)
|
if (keyPosition._forwardToDevices)
|
||||||
{
|
{
|
||||||
osg::ref_ptr<osgGA::GUIEventAdapter> event = new osgGA::GUIEventAdapter();
|
osg::ref_ptr<osgGA::GUIEventAdapter> event = new osgGA::GUIEventAdapter();
|
||||||
@ -1583,7 +1621,12 @@ void SlideEventHandler::dispatchEvent(const KeyPosition& keyPosition)
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
osgGA::EventQueue* eq = _viewer->getEventQueue();
|
osgGA::EventQueue* eq = _viewer!=0 ? _viewer->getEventQueue() : 0;
|
||||||
|
if (!eq)
|
||||||
|
{
|
||||||
|
OSG_NOTICE<<"Warning: SlideEventHandler::dispatchEvent(KeyPosition&) error, no EventQueue to dispatch to."<<std::endl;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// reset the time of the last key press to ensure that the event is disgarded as a key repeat.
|
// reset the time of the last key press to ensure that the event is disgarded as a key repeat.
|
||||||
_timeLastKeyPresses = -1.0;
|
_timeLastKeyPresses = -1.0;
|
||||||
|
Loading…
Reference in New Issue
Block a user