Further work osgViewer::Viewer and related classes.
This commit is contained in:
@@ -18,6 +18,7 @@ using namespace osgGA;
|
||||
|
||||
EventQueue::EventQueue(GUIEventAdapter::MouseYOrientation mouseYOrientation)
|
||||
{
|
||||
_useFixedMouseInputRange = false;
|
||||
_startTick = osg::Timer::instance()->tick();
|
||||
_accumulateEventState = new GUIEventAdapter();
|
||||
_accumulateEventState->setMouseYOrientation(mouseYOrientation);
|
||||
@@ -77,9 +78,9 @@ bool EventQueue::copyEvents(Events& events) const
|
||||
}
|
||||
|
||||
|
||||
void EventQueue::windowResize(int x, int y, unsigned int width, unsigned int height, bool updateMouseRange)
|
||||
void EventQueue::windowResize(int x, int y, unsigned int width, unsigned int height)
|
||||
{
|
||||
_accumulateEventState->setWindowRectangle(x, y, width, height, updateMouseRange);
|
||||
_accumulateEventState->setWindowRectangle(x, y, width, height, !_useFixedMouseInputRange);
|
||||
|
||||
GUIEventAdapter* event = new GUIEventAdapter(*_accumulateEventState);
|
||||
event->setEventType(GUIEventAdapter::RESIZE);
|
||||
@@ -252,7 +253,7 @@ void EventQueue::mouseButtonRelease(float x, float y, unsigned int button)
|
||||
addEvent(event);
|
||||
}
|
||||
|
||||
void EventQueue::keyPress(GUIEventAdapter::KeySymbol key)
|
||||
void EventQueue::keyPress(int key)
|
||||
{
|
||||
switch(key)
|
||||
{
|
||||
@@ -290,7 +291,7 @@ void EventQueue::keyPress(GUIEventAdapter::KeySymbol key)
|
||||
addEvent(event);
|
||||
}
|
||||
|
||||
void EventQueue::keyRelease(GUIEventAdapter::KeySymbol key)
|
||||
void EventQueue::keyRelease(int key)
|
||||
{
|
||||
switch(key)
|
||||
{
|
||||
|
||||
@@ -18,10 +18,21 @@
|
||||
|
||||
using namespace osgViewer;
|
||||
|
||||
class ActionAdapter : public osgGA::GUIActionAdapter
|
||||
{
|
||||
public:
|
||||
virtual ~ActionAdapter() {}
|
||||
|
||||
virtual void requestRedraw() { /*osg::notify(osg::NOTICE)<<"requestRedraw()"<<std::endl;*/ }
|
||||
virtual void requestContinuousUpdate(bool needed=true) { /*osg::notify(osg::NOTICE)<<"requestContinuousUpdate("<<needed<<")"<<std::endl;*/ }
|
||||
virtual void requestWarpPointer(float x,float y) { osg::notify(osg::NOTICE)<<"requestWarpPointer("<<x<<","<<y<<")"<<std::endl; }
|
||||
|
||||
};
|
||||
|
||||
View::View()
|
||||
{
|
||||
// osg::notify(osg::NOTICE)<<"Constructing osgViewer::View"<<std::endl;
|
||||
|
||||
setEventQueue(new osgGA::EventQueue);
|
||||
}
|
||||
|
||||
View::~View()
|
||||
@@ -37,6 +48,20 @@ void View::setSceneData(osg::Node* node)
|
||||
assignSceneDataToCameras();
|
||||
}
|
||||
|
||||
void View::setCameraManipulator(osgGA::MatrixManipulator* manipulator)
|
||||
{
|
||||
_cameraManipulator = manipulator;
|
||||
if (_cameraManipulator.valid() && getSceneData())
|
||||
{
|
||||
_cameraManipulator->setNode(getSceneData());
|
||||
|
||||
osg::ref_ptr<osgGA::GUIEventAdapter> dummyEvent = _eventQueue->createEvent();
|
||||
|
||||
ActionAdapter aa;
|
||||
_cameraManipulator->home(*dummyEvent, aa);
|
||||
}
|
||||
}
|
||||
|
||||
void View::setUpViewAcrossAllScreens()
|
||||
{
|
||||
osg::GraphicsContext::GraphicsContext::WindowingSystemInterface* wsi = osg::GraphicsContext::getWindowingSystemInterface();
|
||||
@@ -86,6 +111,11 @@ void View::setUpViewAcrossAllScreens()
|
||||
else
|
||||
{
|
||||
double rotate_x = - double(numScreens-1) * 0.5 * fovx;
|
||||
|
||||
float inputRangeMinX = 0.0f;
|
||||
float inputRangeMinY = 0.0f;
|
||||
|
||||
float maxHeight = 0.0f;
|
||||
|
||||
for(unsigned int i=0; i<numScreens; ++i, rotate_x += fovx)
|
||||
{
|
||||
@@ -111,6 +141,12 @@ void View::setUpViewAcrossAllScreens()
|
||||
if (gw)
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<" GraphicsWindow has been created successfully."<<gw<<std::endl;
|
||||
|
||||
gw->getEventQueue()->setUseFixedMouseInputRange(true);
|
||||
gw->getEventQueue()->getCurrentEventState()->setInputRange(inputRangeMinX, inputRangeMinY, inputRangeMinX+float(width),inputRangeMinY+float(height) );
|
||||
inputRangeMinX += float(width);
|
||||
|
||||
if (maxHeight < float(height)) maxHeight = float(height);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -122,6 +158,9 @@ void View::setUpViewAcrossAllScreens()
|
||||
addSlave(camera.get(), osg::Matrixd(), osg::Matrixd::rotate( rotate_x, 0.0, 1.0, 0.0));
|
||||
|
||||
}
|
||||
|
||||
getEventQueue()->setUseFixedMouseInputRange(true);
|
||||
getEventQueue()->getCurrentEventState()->setInputRange(0.0f, 0.0, inputRangeMinX, maxHeight);
|
||||
}
|
||||
|
||||
setUpRenderingSupport();
|
||||
@@ -156,6 +195,16 @@ void View::assignSceneDataToCameras()
|
||||
{
|
||||
osg::Node* sceneData = _scene.valid() ? _scene->getSceneData() : 0;
|
||||
|
||||
if (_cameraManipulator.valid())
|
||||
{
|
||||
_cameraManipulator->setNode(sceneData);
|
||||
|
||||
osg::ref_ptr<osgGA::GUIEventAdapter> dummyEvent = _eventQueue->createEvent();
|
||||
|
||||
ActionAdapter aa;
|
||||
_cameraManipulator->home(*dummyEvent, aa);
|
||||
}
|
||||
|
||||
if (_camera.valid())
|
||||
{
|
||||
_camera->removeChildren(0,_camera->getNumChildren());
|
||||
|
||||
@@ -18,7 +18,19 @@
|
||||
|
||||
using namespace osgViewer;
|
||||
|
||||
Viewer::Viewer()
|
||||
class ActionAdapter : public osgGA::GUIActionAdapter
|
||||
{
|
||||
public:
|
||||
virtual ~ActionAdapter() {}
|
||||
|
||||
virtual void requestRedraw() { /*osg::notify(osg::NOTICE)<<"requestRedraw()"<<std::endl;*/ }
|
||||
virtual void requestContinuousUpdate(bool needed=true) { /*osg::notify(osg::NOTICE)<<"requestContinuousUpdate("<<needed<<")"<<std::endl;*/ }
|
||||
virtual void requestWarpPointer(float x,float y) { osg::notify(osg::NOTICE)<<"requestWarpPointer("<<x<<","<<y<<")"<<std::endl; }
|
||||
|
||||
};
|
||||
|
||||
Viewer::Viewer():
|
||||
_firstFrame(true)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -26,6 +38,20 @@ Viewer::~Viewer()
|
||||
{
|
||||
}
|
||||
|
||||
void Viewer::init()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Viewer::init()"<<std::endl;
|
||||
|
||||
osg::ref_ptr<osgGA::GUIEventAdapter> initEvent = _eventQueue->createEvent();
|
||||
initEvent->setEventType(osgGA::GUIEventAdapter::FRAME);
|
||||
|
||||
if (_cameraManipulator.valid())
|
||||
{
|
||||
ActionAdapter aa;
|
||||
_cameraManipulator->init(*initEvent, aa);
|
||||
}
|
||||
}
|
||||
|
||||
void Viewer::realize()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Viewer::realize()"<<std::endl;
|
||||
@@ -49,22 +75,141 @@ void Viewer::realize()
|
||||
|
||||
void Viewer::frame()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Viewer::frame() not implemented yet."<<std::endl;
|
||||
if (_firstFrame)
|
||||
{
|
||||
init();
|
||||
_firstFrame = false;
|
||||
}
|
||||
|
||||
frameEventTraversal();
|
||||
frameUpdateTraversal();
|
||||
frameCullTraversal();
|
||||
frameDrawTraversal();
|
||||
}
|
||||
|
||||
void Viewer::frameAdvance()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Viewer::frameAdvance() not implemented yet."<<std::endl;
|
||||
// osg::notify(osg::NOTICE)<<"Viewer::frameAdvance()."<<std::endl;
|
||||
|
||||
_scene->frameAdvance();
|
||||
}
|
||||
|
||||
void Viewer::frameEventTraversal()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Viewer::frameEventTraversal() not implemented yet."<<std::endl;
|
||||
// osg::notify(osg::NOTICE)<<"Viewer::frameEventTraversal()."<<std::endl;
|
||||
|
||||
// need to copy events from the GraphicsWindow's into local EventQueue;
|
||||
osgGA::EventQueue::Events events;
|
||||
|
||||
if (_camera.valid() && _camera->getGraphicsContext())
|
||||
{
|
||||
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(_camera->getGraphicsContext());
|
||||
if (gw)
|
||||
{
|
||||
gw->checkEvents();
|
||||
gw->getEventQueue()->takeEvents(events);
|
||||
}
|
||||
}
|
||||
|
||||
for(unsigned int i=0; i<getNumSlaves(); ++i)
|
||||
{
|
||||
Slave& slave = getSlave(i);
|
||||
if (slave._camera.valid() && slave._camera->getGraphicsContext())
|
||||
{
|
||||
osgViewer::GraphicsWindow* gw = dynamic_cast<osgViewer::GraphicsWindow*>(slave._camera->getGraphicsContext());
|
||||
if (gw)
|
||||
{
|
||||
gw->checkEvents();
|
||||
gw->getEventQueue()->takeEvents(events);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
_eventQueue->frame( _scene->getFrameStamp()->getReferenceTime() );
|
||||
|
||||
_eventQueue->takeEvents(events);
|
||||
|
||||
osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState();
|
||||
for(osgGA::EventQueue::Events::iterator itr = events.begin();
|
||||
itr != events.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
event->setInputRange(eventState->getXmin(), eventState->getYmin(), eventState->getXmax(), eventState->getYmax());
|
||||
}
|
||||
|
||||
#if 0
|
||||
// osg::notify(osg::NOTICE)<<"Events "<<events.size()<<std::endl;
|
||||
for(osgGA::EventQueue::Events::iterator itr = events.begin();
|
||||
itr != events.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
switch(event->getEventType())
|
||||
{
|
||||
case(osgGA::GUIEventAdapter::PUSH):
|
||||
osg::notify(osg::NOTICE)<<" PUSH "<<event->getButton()<<" x="<<event->getX()<<" y="<<event->getY()<<std::endl;
|
||||
break;
|
||||
case(osgGA::GUIEventAdapter::RELEASE):
|
||||
osg::notify(osg::NOTICE)<<" RELEASE "<<event->getButton()<<" x="<<event->getX()<<" y="<<event->getY()<<std::endl;
|
||||
break;
|
||||
case(osgGA::GUIEventAdapter::DRAG):
|
||||
osg::notify(osg::NOTICE)<<" DRAG "<<event->getButtonMask()<<" x="<<event->getX()<<" y="<<event->getY()<<std::endl;
|
||||
break;
|
||||
case(osgGA::GUIEventAdapter::MOVE):
|
||||
osg::notify(osg::NOTICE)<<" MOVE "<<event->getButtonMask()<<" x="<<event->getX()<<" y="<<event->getY()<<std::endl;
|
||||
break;
|
||||
case(osgGA::GUIEventAdapter::SCROLL):
|
||||
osg::notify(osg::NOTICE)<<" SCROLL "<<event->getScrollingMotion()<<std::endl;
|
||||
break;
|
||||
case(osgGA::GUIEventAdapter::KEYDOWN):
|
||||
osg::notify(osg::NOTICE)<<" KEYDOWN '"<<(char)event->getKey()<<"'"<<std::endl;
|
||||
break;
|
||||
case(osgGA::GUIEventAdapter::KEYUP):
|
||||
osg::notify(osg::NOTICE)<<" KEYUP '"<<(char)event->getKey()<<"'"<<std::endl;
|
||||
break;
|
||||
case(osgGA::GUIEventAdapter::FRAME):
|
||||
// osg::notify(osg::NOTICE)<<" FRAME "<<std::endl;
|
||||
break;
|
||||
default:
|
||||
// osg::notify(osg::NOTICE)<<" Event not handled"<<std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
ActionAdapter aa;
|
||||
|
||||
for(osgGA::EventQueue::Events::iterator itr = events.begin();
|
||||
itr != events.end();
|
||||
++itr)
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
|
||||
bool handled = false;
|
||||
|
||||
if (_cameraManipulator.valid())
|
||||
{
|
||||
_cameraManipulator->handle( *event, aa);
|
||||
}
|
||||
|
||||
for(EventHandlers::iterator hitr = _eventHandlers.begin();
|
||||
hitr != _eventHandlers.end() && !handled;
|
||||
++hitr)
|
||||
{
|
||||
handled = (*hitr)->handle( *event, aa, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Viewer::frameUpdateTraversal()
|
||||
{
|
||||
osg::notify(osg::NOTICE)<<"Viewer::frameUpdateTraversal() not implemented yet."<<std::endl;
|
||||
if (_cameraManipulator.valid())
|
||||
{
|
||||
_camera->setViewMatrix(_cameraManipulator->getInverseMatrix());
|
||||
}
|
||||
|
||||
updateSlaves();
|
||||
}
|
||||
|
||||
void Viewer::frameCullTraversal()
|
||||
|
||||
@@ -50,10 +50,22 @@ BEGIN_OBJECT_REFLECTOR(osgGA::EventQueue)
|
||||
__void__addEvent__GUIEventAdapter_P1,
|
||||
"Add an event to the end of the event queue. ",
|
||||
"");
|
||||
I_MethodWithDefaults5(void, windowResize, IN, int, x, , IN, int, y, , IN, unsigned int, width, , IN, unsigned int, height, , IN, bool, updateMouseRange, true,
|
||||
__void__windowResize__int__int__unsigned_int__unsigned_int__bool,
|
||||
"Method for adapting window resize event, placing this event on the back of the event queue. ",
|
||||
"");
|
||||
I_Method1(void, setUseFixedMouseInputRange, IN, bool, useFixedMouseInputRange,
|
||||
__void__setUseFixedMouseInputRange__bool,
|
||||
"Specify if mouse coordinates should be transformed into a pre defined input range, or whether they should be simply based on as local coordinates to the window that generated the mouse events. ",
|
||||
"");
|
||||
I_Method0(bool, getUseFixedMouseInputRange,
|
||||
__bool__getUseFixedMouseInputRange,
|
||||
"Get whether the mouse coordinates should be transformed into a pre defined input range. ",
|
||||
"");
|
||||
I_Method4(void, setMouseInputRange, IN, float, xMin, IN, float, yMin, IN, float, xMax, IN, float, yMax,
|
||||
__void__setMouseInputRange__float__float__float__float,
|
||||
"Set the mouse input range. ",
|
||||
"");
|
||||
I_Method4(void, windowResize, IN, int, x, IN, int, y, IN, unsigned int, width, IN, unsigned int, height,
|
||||
__void__windowResize__int__int__unsigned_int__unsigned_int,
|
||||
"Method for adapting window resize event, placing this event on the back of the event queue. ",
|
||||
"");
|
||||
I_Method1(void, mouseScroll, IN, osgGA::GUIEventAdapter::ScrollingMotion, sm,
|
||||
__void__mouseScroll__GUIEventAdapter_ScrollingMotion,
|
||||
"Method for adapting mouse scroll wheel events, placing this event on the back of the event queue. ",
|
||||
@@ -90,14 +102,14 @@ BEGIN_OBJECT_REFLECTOR(osgGA::EventQueue)
|
||||
__void__mouseButtonRelease__float__float__unsigned_int,
|
||||
"Method for adapting mouse button release events, placing this event on the back of the event queue. ",
|
||||
"Button numbering is 1 for left mouse button, 2 for middle, 3 for right. ");
|
||||
I_Method1(void, keyPress, IN, osgGA::GUIEventAdapter::KeySymbol, key,
|
||||
__void__keyPress__GUIEventAdapter_KeySymbol,
|
||||
I_Method1(void, keyPress, IN, int, key,
|
||||
__void__keyPress__int,
|
||||
"Method for adapting keyboard press events. ",
|
||||
"");
|
||||
I_Method1(void, keyRelease, IN, osgGA::GUIEventAdapter::KeySymbol, key,
|
||||
__void__keyRelease__GUIEventAdapter_KeySymbol,
|
||||
"Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings. ");
|
||||
I_Method1(void, keyRelease, IN, int, key,
|
||||
__void__keyRelease__int,
|
||||
"Method for adapting keyboard press events. ",
|
||||
"");
|
||||
"Note, special keys such as Ctrl/Function keys should be adapted to GUIEventAdapter::KeySymbol mappings. ");
|
||||
I_Method1(void, frame, IN, double, t,
|
||||
__void__frame__double,
|
||||
"Method for adapting frame events. ",
|
||||
@@ -138,6 +150,9 @@ BEGIN_OBJECT_REFLECTOR(osgGA::EventQueue)
|
||||
I_SimpleProperty(double, Time,
|
||||
__double__getTime,
|
||||
0);
|
||||
I_SimpleProperty(bool, UseFixedMouseInputRange,
|
||||
__bool__getUseFixedMouseInputRange,
|
||||
__void__setUseFixedMouseInputRange__bool);
|
||||
END_REFLECTOR
|
||||
|
||||
BEGIN_VALUE_REFLECTOR(osg::ref_ptr< osgGA::GUIEventAdapter >)
|
||||
|
||||
@@ -40,6 +40,10 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::GraphicsWindow)
|
||||
__C5_osgGA_EventQueue_P1__getEventQueue,
|
||||
"",
|
||||
"");
|
||||
I_Method0(void, checkEvents,
|
||||
__void__checkEvents,
|
||||
"",
|
||||
"");
|
||||
I_Method0(bool, realizeImplementation,
|
||||
__bool__realizeImplementation,
|
||||
"Realise the GraphicsContext implementation, Pure virtual - must be implemented by concrate implementations of GraphicsContext. ",
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include <osgIntrospection/StaticMethodInfo>
|
||||
#include <osgIntrospection/Attributes>
|
||||
|
||||
#include <osg/FrameStamp>
|
||||
#include <osg/Node>
|
||||
#include <osgDB/DatabasePager>
|
||||
#include <osgGA/EventQueue>
|
||||
@@ -43,6 +44,10 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::Scene)
|
||||
__C5_osg_Node_P1__getSceneData,
|
||||
"",
|
||||
"");
|
||||
I_Method0(osg::FrameStamp *, getFrameStamp,
|
||||
__osg_FrameStamp_P1__getFrameStamp,
|
||||
"",
|
||||
"");
|
||||
I_Method1(void, setEventQueue, IN, osgGA::EventQueue *, eventQueue,
|
||||
__void__setEventQueue__osgGA_EventQueue_P1,
|
||||
"",
|
||||
@@ -104,6 +109,9 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::Scene)
|
||||
I_SimpleProperty(osgGA::EventQueue *, EventQueue,
|
||||
__osgGA_EventQueue_P1__getEventQueue,
|
||||
__void__setEventQueue__osgGA_EventQueue_P1);
|
||||
I_SimpleProperty(osg::FrameStamp *, FrameStamp,
|
||||
__osg_FrameStamp_P1__getFrameStamp,
|
||||
0);
|
||||
I_SimpleProperty(osg::Node *, SceneData,
|
||||
__osg_Node_P1__getSceneData,
|
||||
__void__setSceneData__osg_Node_P1);
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#include <osgIntrospection/Attributes>
|
||||
|
||||
#include <osg/Node>
|
||||
#include <osgGA/EventQueue>
|
||||
#include <osgGA/GUIEventHandler>
|
||||
#include <osgGA/MatrixManipulator>
|
||||
#include <osgViewer/View>
|
||||
@@ -42,6 +43,18 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::View)
|
||||
__C5_osg_Node_P1__getSceneData,
|
||||
"",
|
||||
"");
|
||||
I_Method1(void, setEventQueue, IN, osgGA::EventQueue *, eventQueue,
|
||||
__void__setEventQueue__osgGA_EventQueue_P1,
|
||||
"",
|
||||
"");
|
||||
I_Method0(osgGA::EventQueue *, getEventQueue,
|
||||
__osgGA_EventQueue_P1__getEventQueue,
|
||||
"",
|
||||
"");
|
||||
I_Method0(const osgGA::EventQueue *, getEventQueue,
|
||||
__C5_osgGA_EventQueue_P1__getEventQueue,
|
||||
"",
|
||||
"");
|
||||
I_Method1(void, setCameraManipulator, IN, osgGA::MatrixManipulator *, manipulator,
|
||||
__void__setCameraManipulator__osgGA_MatrixManipulator_P1,
|
||||
"",
|
||||
@@ -84,6 +97,9 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::View)
|
||||
I_SimpleProperty(osgViewer::View::EventHandlers &, EventHandlers,
|
||||
__EventHandlers_R1__getEventHandlers,
|
||||
0);
|
||||
I_SimpleProperty(osgGA::EventQueue *, EventQueue,
|
||||
__osgGA_EventQueue_P1__getEventQueue,
|
||||
__void__setEventQueue__osgGA_EventQueue_P1);
|
||||
I_SimpleProperty(osg::Node *, SceneData,
|
||||
__osg_Node_P1__getSceneData,
|
||||
__void__setSceneData__osg_Node_P1);
|
||||
|
||||
@@ -65,5 +65,6 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::Viewer)
|
||||
__void__init,
|
||||
"",
|
||||
"");
|
||||
I_PublicMemberProperty(bool, _firstFrame);
|
||||
END_REFLECTOR
|
||||
|
||||
|
||||
Reference in New Issue
Block a user