Moved Handled propety from GUIEventAdapter to Event base class.

Added CameraManipulator::finishAnimation() method to allow application code to stop any animation/throw of manipulators.
This commit is contained in:
Robert Osfield 2013-11-15 16:15:09 +00:00
parent 835d9455a9
commit c194e92df8
8 changed files with 33 additions and 12 deletions

View File

@ -143,6 +143,9 @@ class OSGGA_EXPORT CameraManipulator : public GUIEventHandler
/** Compute the home position.*/
virtual void computeHomePosition(const osg::Camera *camera = NULL, bool useBoundingBox = false);
/** finish any active manipulator animations.*/
virtual void finishAnimation() {}
/**
Move the camera to the default position.
May be ignored by manipulators if home functionality is not appropriate.

View File

@ -35,6 +35,14 @@ public:
virtual GUIEventAdapter* asGUIEventAdapter() { return 0; }
virtual const GUIEventAdapter* asGUIEventAdapter() const { return 0; }
/** Set whether this event has been handled by an event handler or not.*/
void setHandled(bool handled) const { _handled = handled; }
/** Get whether this event has been handled by an event handler or not.*/
bool getHandled() const { return _handled; }
/** set time in seconds of event. */
void setTime(double time) { _time = time; }
@ -44,7 +52,8 @@ public:
protected:
virtual ~Event() {}
double _time;
mutable bool _handled;
double _time;
};
}

View File

@ -459,12 +459,6 @@ public:
static osg::ref_ptr<GUIEventAdapter>& getAccumulatedEventState();
/** Set whether this event has been handled by an event handler or not.*/
void setHandled(bool handled) const { _handled = handled; }
/** Get whether this event has been handled by an event handler or not.*/
bool getHandled() const { return _handled; }
/** set the event type. */
void setEventType(EventType Type) { _eventType = Type; }
@ -705,7 +699,6 @@ public:
/** Force users to create on heap, so that multiple referencing is safe.*/
virtual ~GUIEventAdapter();
mutable bool _handled;
EventType _eventType;
osg::observer_ptr<osg::GraphicsContext> _context;

View File

@ -115,6 +115,8 @@ class OSGGA_EXPORT KeySwitchMatrixManipulator : public CameraManipulator
virtual void computeHomePosition();
virtual void finishAnimation();
virtual void home(const GUIEventAdapter& ee,GUIActionAdapter& aa);
virtual void init(const GUIEventAdapter& ee,GUIActionAdapter& aa) { if (_current.valid()) _current->init(ee,aa); }

View File

@ -16,10 +16,12 @@
using namespace osgGA;
Event::Event():
_handled(false),
_time(0.0)
{}
Event::Event(const Event& rhs, const osg::CopyOp& copyop):
osg::Object(rhs, copyop),
_handled(rhs._handled),
_time(rhs._time)
{}

View File

@ -23,7 +23,6 @@ osg::ref_ptr<GUIEventAdapter>& GUIEventAdapter::getAccumulatedEventState()
}
GUIEventAdapter::GUIEventAdapter():
_handled(false),
_eventType(NONE),
_windowX(0),
_windowY(0),
@ -48,7 +47,6 @@ GUIEventAdapter::GUIEventAdapter():
GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& copyop):
osgGA::Event(rhs,copyop),
_handled(rhs._handled),
_eventType(rhs._eventType),
_context(rhs._context),
_windowX(rhs._windowX),

View File

@ -98,6 +98,18 @@ void KeySwitchMatrixManipulator::computeHomePosition()
}
}
void KeySwitchMatrixManipulator::finishAnimation()
{
OSG_NOTICE<<"KeySwitchMatrixManipulator::finishAnimation()"<<std::endl;
for(KeyManipMap::iterator itr=_manips.begin();
itr!=_manips.end();
++itr)
{
itr->second.second->finishAnimation();
}
}
void KeySwitchMatrixManipulator::home(const GUIEventAdapter& ee,GUIActionAdapter& aa)
{
// call home for all child manipulators
@ -178,7 +190,7 @@ bool KeySwitchMatrixManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapt
{
CameraManipulator* selectedManipulator = it->second.second.get();
if (selectedManipulator!=_current)
{
{
OSG_INFO<<"Switching to manipulator: "<<it->second.first<<std::endl;
if ( !selectedManipulator->getNode() )
{
@ -186,7 +198,7 @@ bool KeySwitchMatrixManipulator::handle(const GUIEventAdapter& ea,GUIActionAdapt
}
selectedManipulator->setByMatrix(_current->getMatrix());
selectedManipulator->init(ea,aa);
_current = selectedManipulator;
}
handled = true;

View File

@ -154,6 +154,8 @@ bool StandardManipulator::isAnimating() const
/// Finishes the animation by performing a step that moves it to its final position.
void StandardManipulator::finishAnimation()
{
_thrown = false;
if( !isAnimating() )
return;