Added an EventQueue directly into osgProducer::Viewer.

This commit is contained in:
Robert Osfield
2006-03-13 13:19:37 +00:00
parent 8229875432
commit 1a16d6d6b0
9 changed files with 49 additions and 24 deletions

View File

@@ -31,7 +31,7 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
{
public:
EventQueue();
EventQueue(GUIEventAdapter::MouseYOrientation mouseYOrientation=GUIEventAdapter::Y_INCREASING_DOWNWARDS);
typedef std::list< osg::ref_ptr<GUIEventAdapter> > Events;

View File

@@ -63,6 +63,7 @@ class OSGPRODUCER_EXPORT KeyboardMouseCallback : public Producer::KeyboardMouseC
// local methods and members
typedef osgGA::EventQueue::Events EventQueue;
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
bool takeEventQueue(EventQueue& queue);

View File

@@ -255,6 +255,12 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction
/** Compute, from normalized mouse coords, for all Cameras, intersections with the scene.*/
bool computeIntersections(float x,float y,osgUtil::IntersectVisitor::HitList& hits,osg::Node::NodeMask traversalMask = 0xffffffff);
/** Set the EventQueue - a thread safe queue for registering events.*/
void setEventQueue(osgGA::EventQueue* eventQueue) { _eventQueue = eventQueue; }
/** Get the EventQueue.*/
osgGA::EventQueue* getEventQueue() { return _eventQueue.get(); }
void setKeyboardMouse(Producer::KeyboardMouse* kbm);
Producer::KeyboardMouse* getKeyboardMouse() { return _kbm.get(); }
const Producer::KeyboardMouse* getKeyboardMouse() const { return _kbm.get(); }
@@ -310,6 +316,8 @@ class OSGPRODUCER_EXPORT Viewer : public OsgCameraGroup, public osgGA::GUIAction
bool _writeImageWhenDone;
std::string _writeImageFileName;
osg::ref_ptr<osgGA::EventQueue> _eventQueue;
osg::ref_ptr<Producer::KeyboardMouse> _kbm;
osg::ref_ptr<osgProducer::KeyboardMouseCallback> _kbmcb;

View File

@@ -16,10 +16,11 @@
using namespace osgGA;
EventQueue::EventQueue()
EventQueue::EventQueue(GUIEventAdapter::MouseYOrientation mouseYOrientation)
{
_startTick = osg::Timer::instance()->tick();
_accumulateEventState = new GUIEventAdapter();
_accumulateEventState->setMouseYOrientation(mouseYOrientation);
}
EventQueue::~EventQueue()

View File

@@ -14,39 +14,37 @@ KeyboardMouseCallback::KeyboardMouseCallback(Producer::KeyboardMouse* keyboardMo
_done(done),
_escapeKeySetsDone(escapeKeySetsDone)
{
_eventQueue = new osgGA::EventQueue;
_eventQueue->getCurrentEventState()->setMouseYOrientation(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS);
updateWindowSize();
}
void KeyboardMouseCallback::mouseScroll( Producer::KeyboardMouseCallback::ScrollingMotion sm )
{
updateWindowSize();
_eventQueue->mouseScroll((osgGA::GUIEventAdapter::ScrollingMotion)sm);
if (_eventQueue.valid()) _eventQueue->mouseScroll((osgGA::GUIEventAdapter::ScrollingMotion)sm);
}
void KeyboardMouseCallback::buttonPress( float mx, float my, unsigned int mbutton )
{
updateWindowSize();
_eventQueue->mouseButtonPress(mx,my,mbutton);
if (_eventQueue.valid()) _eventQueue->mouseButtonPress(mx,my,mbutton);
}
void KeyboardMouseCallback::buttonRelease( float mx, float my, unsigned int mbutton )
{
updateWindowSize();
_eventQueue->mouseButtonRelease(mx,my,mbutton);
if (_eventQueue.valid()) _eventQueue->mouseButtonRelease(mx,my,mbutton);
}
void KeyboardMouseCallback::doubleButtonPress( float mx, float my, unsigned int mbutton )
{
updateWindowSize();
_eventQueue->mouseButtonPress(mx,my,mbutton);
if (_eventQueue.valid()) _eventQueue->mouseButtonPress(mx,my,mbutton);
}
void KeyboardMouseCallback::keyPress( Producer::KeyCharacter key )
{
updateWindowSize();
_eventQueue->keyPress((osgGA::GUIEventAdapter::KeySymbol)key);
if (_eventQueue.valid()) _eventQueue->keyPress((osgGA::GUIEventAdapter::KeySymbol)key);
// check against adapted key symbol.
if (_escapeKeySetsDone &&
@@ -56,7 +54,7 @@ void KeyboardMouseCallback::keyPress( Producer::KeyCharacter key )
void KeyboardMouseCallback::keyRelease( Producer::KeyCharacter key )
{
updateWindowSize();
_eventQueue->keyRelease((osgGA::GUIEventAdapter::KeySymbol)key);
if (_eventQueue.valid()) _eventQueue->keyRelease((osgGA::GUIEventAdapter::KeySymbol)key);
}
void KeyboardMouseCallback::specialKeyPress( Producer::KeyCharacter key )
@@ -74,30 +72,32 @@ void KeyboardMouseCallback::specialKeyRelease( Producer::KeyCharacter key )
void KeyboardMouseCallback::windowConfig( int x, int y, unsigned int width, unsigned int height )
{
updateWindowSize();
_eventQueue->windowResize(x,y,x+width,y+height);
if (_eventQueue.valid()) _eventQueue->windowResize(x,y,x+width,y+height);
}
void KeyboardMouseCallback::mouseMotion( float mx, float my)
{
updateWindowSize();
_eventQueue->mouseMotion(mx,my);
if (_eventQueue.valid()) _eventQueue->mouseMotion(mx,my);
}
void KeyboardMouseCallback::passiveMouseMotion( float mx, float my)
{
updateWindowSize();
_eventQueue->mouseMotion(mx,my);
if (_eventQueue.valid()) _eventQueue->mouseMotion(mx,my);
}
void KeyboardMouseCallback::mouseWarp( float mx, float my)
{
updateWindowSize();
_eventQueue->mouseMotion(mx,my); // need mouse warp??
if (_eventQueue.valid()) _eventQueue->mouseMotion(mx,my); // need mouse warp??
}
void KeyboardMouseCallback::updateWindowSize()
{
if (!_eventQueue) return;
osgGA::GUIEventAdapter* ea = _eventQueue->getCurrentEventState();
Producer::InputArea* ia = _keyboardMouse->getInputArea();

View File

@@ -144,6 +144,7 @@ Viewer::Viewer():
_recordingAnimationPath(false),
_recordingStartTime(0.0)
{
_eventQueue = new osgGA::EventQueue(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS);
_position[0] = 0.0;
_position[1] = 0.0;
_position[2] = 0.0;
@@ -162,6 +163,7 @@ Viewer::Viewer(Producer::CameraConfig *cfg):
_recordingAnimationPath(false),
_recordingStartTime(0.0)
{
_eventQueue = new osgGA::EventQueue(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS);
_position[0] = 0.0;
_position[1] = 0.0;
_position[2] = 0.0;
@@ -181,6 +183,7 @@ Viewer::Viewer(const std::string& configFile):
_recordingAnimationPath(false),
_recordingStartTime(0.0)
{
_eventQueue = new osgGA::EventQueue(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS);
_position[0] = 0.0;
_position[1] = 0.0;
_position[2] = 0.0;
@@ -199,6 +202,7 @@ Viewer::Viewer(osg::ArgumentParser& arguments):
_recordingAnimationPath(false),
_recordingStartTime(0.0)
{
_eventQueue = new osgGA::EventQueue(osgGA::GUIEventAdapter::Y_INCREASING_UPWARDS);
_position[0] = 0.0;
_position[1] = 0.0;
_position[2] = 0.0;
@@ -342,7 +346,11 @@ void Viewer::setKeyboardMouse(Producer::KeyboardMouse* kbm)
void Viewer::setKeyboardMouseCallback(osgProducer::KeyboardMouseCallback* kbmcb)
{
_kbmcb = kbmcb;
if (_kbm.valid() && _kbmcb.valid()) _kbm->setCallback(_kbmcb.get());
if (_kbm.valid() && _kbmcb.valid())
{
_kbm->setCallback(_kbmcb.get());
_kbmcb->setEventQueue(_eventQueue.get());
}
}
void Viewer::setUpViewer(unsigned int options)
@@ -353,17 +361,19 @@ void Viewer::setUpViewer(unsigned int options)
if (!_kbm)
{
_kbm = ia ?
setKeyboardMouse(ia ?
(new Producer::KeyboardMouse(ia)) :
(new Producer::KeyboardMouse(getCamera(0)->getRenderSurface()));
(new Producer::KeyboardMouse(getCamera(0)->getRenderSurface())) );
}
// set the keyboard mouse callback to catch the events from the windows.
if (!_kbmcb)
_kbmcb = new osgProducer::KeyboardMouseCallback( _kbm.get(), _done, (options & ESCAPE_SETS_DONE)!=0 );
{
setKeyboardMouseCallback(new osgProducer::KeyboardMouseCallback( _kbm.get(), _done, (options & ESCAPE_SETS_DONE)!=0 ));
}
_kbmcb->getEventQueue()->setStartTick(_start_tick);
getEventQueue()->setStartTick(_start_tick);
// register the callback with the keyboard mouse manger.
_kbm->setCallback( _kbmcb.get() );
@@ -567,7 +577,7 @@ void Viewer::update()
#endif
// create an event to signal the new frame.
_kbmcb->getEventQueue()->frame(_frameStamp->getReferenceTime());
getEventQueue()->frame(_frameStamp->getReferenceTime());
// get the event since the last frame.
osgProducer::KeyboardMouseCallback::EventQueue queue;
@@ -915,8 +925,8 @@ void Viewer::requestWarpPointer(float x,float y)
{
osg::notify(osg::INFO) << "requestWarpPointer x= "<<x<<" y="<<y<<std::endl;
_kbmcb->getEventQueue()->getCurrentEventState()->setX(x);
_kbmcb->getEventQueue()->getCurrentEventState()->setY(y);
getEventQueue()->getCurrentEventState()->setX(x);
getEventQueue()->getCurrentEventState()->setY(y);
_kbmcb->getKeyboardMouse()->positionPointer(x,y);
return;
}

View File

@@ -25,7 +25,7 @@ TYPE_NAME_ALIAS(std::list< osg::ref_ptr< osgGA::GUIEventAdapter > >, osgGA::Even
BEGIN_OBJECT_REFLECTOR(osgGA::EventQueue)
I_BaseType(osg::Referenced);
I_Constructor0();
I_ConstructorWithDefaults1(IN, osgGA::GUIEventAdapter::MouseYOrientation, mouseYOrientation, osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS);
I_Method1(void, setEvents, IN, osgGA::EventQueue::Events &, events);
I_Method1(bool, takeEvents, IN, osgGA::EventQueue::Events &, events);
I_Method1(bool, copyEvents, IN, osgGA::EventQueue::Events &, events);

View File

@@ -40,6 +40,7 @@ BEGIN_OBJECT_REFLECTOR(osgProducer::KeyboardMouseCallback)
I_Method0(void, shutdown);
I_Method1(void, setEscapeSetDone, IN, bool, esc);
I_Method0(bool, getEscapeSetDone);
I_Method1(void, setEventQueue, IN, osgGA::EventQueue *, eventQueue);
I_Method0(osgGA::EventQueue *, getEventQueue);
I_Method1(bool, takeEventQueue, IN, osgProducer::KeyboardMouseCallback::EventQueue &, queue);
I_Method1(bool, copyEventQueue, IN, osgProducer::KeyboardMouseCallback::EventQueue &, queue);
@@ -52,7 +53,7 @@ BEGIN_OBJECT_REFLECTOR(osgProducer::KeyboardMouseCallback)
I_Method0(osgGA::GUIEventAdapter *, createEventAdapter);
I_Method0(void, updateWindowSize);
I_Property(bool, EscapeSetDone);
I_ReadOnlyProperty(osgGA::EventQueue *, EventQueue);
I_Property(osgGA::EventQueue *, EventQueue);
I_ReadOnlyProperty(Producer::KeyboardMouse *, KeyboardMouse);
I_ReadOnlyProperty(double, Time);
END_REFLECTOR

View File

@@ -16,6 +16,7 @@
#include <osg/NodeVisitor>
#include <osg/Quat>
#include <osg/Vec3>
#include <osgGA/EventQueue>
#include <osgGA/EventVisitor>
#include <osgGA/KeySwitchMatrixManipulator>
#include <osgGA/MatrixManipulator>
@@ -96,6 +97,8 @@ BEGIN_OBJECT_REFLECTOR(osgProducer::Viewer)
I_MethodWithDefaults5(bool, computeIntersections, IN, float, x, , IN, float, y, , IN, unsigned int, cameraNum, , IN, osgUtil::IntersectVisitor::HitList &, hits, , IN, osg::Node::NodeMask, traversalMask, 0xffffffff);
I_MethodWithDefaults5(bool, computeIntersections, IN, float, x, , IN, float, y, , IN, osg::Node *, node, , IN, osgUtil::IntersectVisitor::HitList &, hits, , IN, osg::Node::NodeMask, traversalMask, 0xffffffff);
I_MethodWithDefaults4(bool, computeIntersections, IN, float, x, , IN, float, y, , IN, osgUtil::IntersectVisitor::HitList &, hits, , IN, osg::Node::NodeMask, traversalMask, 0xffffffff);
I_Method1(void, setEventQueue, IN, osgGA::EventQueue *, eventQueue);
I_Method0(osgGA::EventQueue *, getEventQueue);
I_Method1(void, setKeyboardMouse, IN, Producer::KeyboardMouse *, kbm);
I_Method0(Producer::KeyboardMouse *, getKeyboardMouse);
I_Method0(const Producer::KeyboardMouse *, getKeyboardMouse);
@@ -129,6 +132,7 @@ BEGIN_OBJECT_REFLECTOR(osgProducer::Viewer)
I_Property(unsigned int, DoneAtFrameNumber);
I_Property(bool, DoneAtFrameNumberEnabled);
I_ReadOnlyProperty(osgProducer::Viewer::EventHandlerList &, EventHandlerList);
I_Property(osgGA::EventQueue *, EventQueue);
I_Property(osgGA::EventVisitor *, EventVisitor);
I_ReadOnlyProperty(osgGA::KeySwitchMatrixManipulator *, KeySwitchMatrixManipulator);
I_Property(Producer::KeyboardMouse *, KeyboardMouse);