Converted osgGA::GUIEventAdapter into a concrete class capable of respresenting

keyboard and mouse events.

Added osgGA::EventQueue class to support a thread safe event queue and adaption
of keyboard and mouse events.

Removed osgProducer::EventAdapter as GUIEventAdapter replaces it.

Adapted osgProducer and examples to work with the new changes to osgGA.
This commit is contained in:
Robert Osfield
2006-03-08 14:09:47 +00:00
parent 582967286a
commit dbbabf87c6
37 changed files with 450 additions and 835 deletions

View File

@@ -57,7 +57,7 @@ void AnimationPathManipulator::home(double currentTime)
void AnimationPathManipulator::home(const GUIEventAdapter& ea,GUIActionAdapter&)
{
home(ea.time());
home(ea.getTime());
}
void AnimationPathManipulator::init(const GUIEventAdapter& ea,GUIActionAdapter& aa)
@@ -78,7 +78,7 @@ bool AnimationPathManipulator::handle(const osgGA::GUIEventAdapter& ea,osgGA::GU
}
else
{
handleFrame( ea.time() );
handleFrame( ea.getTime() );
}
return false;
case GUIEventAdapter::KEYDOWN:
@@ -96,12 +96,12 @@ bool AnimationPathManipulator::handle(const osgGA::GUIEventAdapter& ea,osgGA::GU
if( _isPaused )
{
_isPaused = false;
_timeOffset -= ea.time() - _pauseTime;
_timeOffset -= ea.getTime() - _pauseTime;
}
else
{
_isPaused = true;
_pauseTime = ea.time();
_pauseTime = ea.getTime();
}
us.requestRedraw();
us.requestContinuousUpdate(false);

View File

@@ -486,7 +486,7 @@ bool DriveManipulator::calcMovement()
// return if less then two events have been added.
if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;
double dt = _ga_t0->time()-_ga_t1->time();
double dt = _ga_t0->getTime()-_ga_t1->getTime();
if (dt<0.0f)
{

View File

@@ -234,7 +234,7 @@ bool FlightManipulator::calcMovement()
if (_ga_t0.get()==NULL || _ga_t1.get()==NULL) return false;
double dt = _ga_t0->time()-_ga_t1->time();
double dt = _ga_t0->getTime()-_ga_t1->getTime();
if (dt<0.0f)
{

View File

@@ -9,6 +9,7 @@ CXXFILES = \
EventVisitor.cpp\
FlightManipulator.cpp\
UFOManipulator.cpp\
EventQueue.cpp\
GUIEventAdapter.cpp\
GUIEventHandler.cpp\
GUIEventHandlerVisitor.cpp\

View File

@@ -11,10 +11,53 @@
* OpenSceneGraph Public License for more details.
*/
#include <osgGA/GUIEventHandler>
#include <osgGA/GUIEventAdapter>
using namespace osgGA;
GUIEventAdapter::GUIEventAdapter():
_eventType(NONE),
_time(0.0),
_key(0),
_button(0),
_Xmin(0.0),
_Xmax(1.0),
_Ymin(0.0),
_Ymax(1.0),
_mx(0.5),
_my(0.5),
_buttonMask(0),
_modKeyMask(0),
_scrollingMotion(SCROLL_DOWN),
_mouseYOrientation(Y_INCREASING_DOWNWARDS)
{}
GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs):
Referenced(),
_eventType(rhs._eventType),
_time(rhs._time),
_key(rhs._key),
_button(rhs._button),
_Xmin(rhs._Xmin),
_Xmax(rhs._Xmax),
_Ymin(rhs._Ymin),
_Ymax(rhs._Ymax),
_mx(rhs._mx),
_my(rhs._my),
_buttonMask(rhs._buttonMask),
_modKeyMask(rhs._modKeyMask),
_scrollingMotion(rhs._scrollingMotion),
_mouseYOrientation(rhs._mouseYOrientation)
{}
GUIEventAdapter::~GUIEventAdapter()
{
}
void GUIEventAdapter::setWindowSize(float Xmin, float Ymin, float Xmax, float Ymax)
{
_Xmin = Xmin;
_Ymin = Ymin;
_Xmax = Xmax;
_Ymax = Ymax;
}

View File

@@ -20,15 +20,14 @@ using namespace osgGA;
void GUIEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv)
{
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv);
if (ev && ev->getActionAdapter() && !ev->getEventList().empty())
if (ev && ev->getActionAdapter() && !ev->getEvents().empty())
{
for(osgGA::EventVisitor::EventList::iterator itr = ev->getEventList().begin();
itr != ev->getEventList().end();
for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin();
itr != ev->getEvents().end();
++itr)
{
if (handle(*(*itr), *(ev->getActionAdapter()), node, nv))
{
ev->setEventHandled(true);
return;
}
}
@@ -39,10 +38,10 @@ void GUIEventHandler::operator()(osg::Node* node, osg::NodeVisitor* nv)
void GUIEventHandler::event(osg::NodeVisitor* nv, osg::Drawable* drawable)
{
osgGA::EventVisitor* ev = dynamic_cast<osgGA::EventVisitor*>(nv);
if (ev && ev->getActionAdapter() && !ev->getEventList().empty())
if (ev && ev->getActionAdapter() && !ev->getEvents().empty())
{
for(osgGA::EventVisitor::EventList::iterator itr = ev->getEventList().begin();
itr != ev->getEventList().end();
for(osgGA::EventQueue::Events::iterator itr = ev->getEvents().begin();
itr != ev->getEvents().end();
++itr)
{
handle(*(*itr), *(ev->getActionAdapter()), drawable, nv);

View File

@@ -288,7 +288,7 @@ bool NodeTrackerManipulator::isMouseMoving()
float dx = _ga_t0->getXnormalized()-_ga_t1->getXnormalized();
float dy = _ga_t0->getYnormalized()-_ga_t1->getYnormalized();
float len = sqrtf(dx*dx+dy*dy);
float dt = _ga_t0->time()-_ga_t1->time();
float dt = _ga_t0->getTime()-_ga_t1->getTime();
return (len>dt*velocity);
}

View File

@@ -189,7 +189,7 @@ bool TerrainManipulator::isMouseMoving()
float dx = _ga_t0->getXnormalized()-_ga_t1->getXnormalized();
float dy = _ga_t0->getYnormalized()-_ga_t1->getYnormalized();
float len = sqrtf(dx*dx+dy*dy);
float dt = _ga_t0->time()-_ga_t1->time();
float dt = _ga_t0->getTime()-_ga_t1->getTime();
return (len>dt*velocity);
}

View File

@@ -54,7 +54,7 @@ void TrackballManipulator::home(double /*currentTime*/)
void TrackballManipulator::home(const GUIEventAdapter& ea ,GUIActionAdapter& us)
{
home(ea.time());
home(ea.getTime());
us.requestRedraw();
}
@@ -167,7 +167,7 @@ bool TrackballManipulator::isMouseMoving()
float dx = _ga_t0->getXnormalized()-_ga_t1->getXnormalized();
float dy = _ga_t0->getYnormalized()-_ga_t1->getYnormalized();
float len = sqrtf(dx*dx+dy*dy);
float dt = _ga_t0->time()-_ga_t1->time();
float dt = _ga_t0->getTime()-_ga_t1->getTime();
return (len>dt*velocity);
}

View File

@@ -161,14 +161,14 @@ void UFOManipulator::computeHomePosition()
void UFOManipulator::init(const GUIEventAdapter&, GUIActionAdapter&)
{
//home(ea.time());
//home(ea.getTime());
_stop();
}
void UFOManipulator::home(const osgGA::GUIEventAdapter& ea, osgGA::GUIActionAdapter&)
{
home(ea.time());
home(ea.getTime());
}
void UFOManipulator::home(double)
@@ -398,17 +398,17 @@ void UFOManipulator::_keyDown( const osgGA::GUIEventAdapter &ea, osgGA::GUIActio
break;
case 'H':
home(ea.time());
home(ea.getTime());
break;
}
}
void UFOManipulator::_frame( const osgGA::GUIEventAdapter &ea, osgGA::GUIActionAdapter & )
{
double t1 = ea.time();
double t1 = ea.getTime();
if( _t0 == 0.0 )
{
_t0 = ea.time();
_t0 = ea.getTime();
_dt = 0.0;
}
else