Added support for assigning GraphicsContext to individual GUIEventAdapter events,
and use of this within osgViewer::View to better track the sources of events.
This commit is contained in:
parent
213a2d8d13
commit
e09e07d45b
@ -59,6 +59,10 @@ class OSGGA_EXPORT EventQueue : public osg::Referenced
|
||||
bool getUseFixedMouseInputRange() { return _useFixedMouseInputRange; }
|
||||
|
||||
|
||||
/** Set the graphics context associated with this event queue.*/
|
||||
void setGraphicsContext(osg::GraphicsContext* context) { getCurrentEventState()->setGraphicsContext(context); }
|
||||
|
||||
|
||||
/** Set the mouse input range.*/
|
||||
void setMouseInputRange(float xMin, float yMin, float xMax, float yMax) { getCurrentEventState()->setInputRange(xMin, yMin, xMax, yMax); }
|
||||
|
||||
|
@ -16,6 +16,7 @@
|
||||
|
||||
#include <osg/Object>
|
||||
#include <osg/Matrix>
|
||||
#include <osg/GraphicsContext>
|
||||
#include <osgGA/Export>
|
||||
|
||||
namespace osgGA{
|
||||
@ -290,6 +291,9 @@ public:
|
||||
/** deprecated function for getting time of event. */
|
||||
double time() const { return _time; }
|
||||
|
||||
|
||||
void setGraphicsContext(osg::GraphicsContext* context) { _context = context; }
|
||||
const osg::GraphicsContext* getGraphicsContext() const { return _context.get(); }
|
||||
|
||||
|
||||
/** set window rectangle. */
|
||||
@ -429,6 +433,7 @@ public:
|
||||
EventType _eventType;
|
||||
double _time;
|
||||
|
||||
osg::observer_ptr<osg::GraphicsContext> _context;
|
||||
int _windowX;
|
||||
int _windowY;
|
||||
int _windowWidth;
|
||||
|
@ -40,7 +40,7 @@ class OSGVIEWER_EXPORT GraphicsWindow : public osg::GraphicsContext, public osgG
|
||||
{
|
||||
public:
|
||||
|
||||
GraphicsWindow() { _eventQueue = new osgGA::EventQueue; }
|
||||
GraphicsWindow() { _eventQueue = new osgGA::EventQueue; _eventQueue->setGraphicsContext(this); }
|
||||
|
||||
virtual bool isSameKindAs(const Object* object) const { return dynamic_cast<const GraphicsWindow*>(object)!=0; }
|
||||
virtual const char* libraryName() const { return "osgViewer"; }
|
||||
|
@ -176,7 +176,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
|
||||
/** Get the camera which contains the pointer position x,y specified master cameras window/eye coords.
|
||||
* Also passes back the local window coords for the graphics context associated with the camera passed back. */
|
||||
const osg::Camera* getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const;
|
||||
|
||||
|
||||
/** Compute intersections between a ray through the specified master cameras window/eye coords and a specified node.
|
||||
* Note, when a master cameras has slaves and no viewport itself its coordinate frame will be in clip space i.e. -1,-1 to 1,1,
|
||||
* while if its has a viewport the coordintates will be relative to its viewport dimensions.
|
||||
@ -186,7 +186,7 @@ class OSGVIEWER_EXPORT View : public osg::View, public osgGA::GUIActionAdapter
|
||||
|
||||
/** Compute intersections between a ray through the specified master cameras window/eye coords and a specified nodePath's subgraph. */
|
||||
bool computeIntersections(float x,float y, osg::NodePath& nodePath, osgUtil::LineSegmentIntersector::Intersections& intersections,osg::Node::NodeMask traversalMask = 0xffffffff);
|
||||
|
||||
|
||||
|
||||
virtual void requestRedraw();
|
||||
virtual void requestContinuousUpdate(bool needed=true);
|
||||
|
@ -32,12 +32,12 @@ GUIEventAdapter::GUIEventAdapter():
|
||||
_windowHeight(1024),
|
||||
_key(0),
|
||||
_button(0),
|
||||
_Xmin(0.0),
|
||||
_Xmin(-1.0),
|
||||
_Xmax(1.0),
|
||||
_Ymin(0.0),
|
||||
_Ymin(-1.0),
|
||||
_Ymax(1.0),
|
||||
_mx(0.5),
|
||||
_my(0.5),
|
||||
_mx(0.0),
|
||||
_my(0.0),
|
||||
_pressure(0.0),
|
||||
_tiltX(0.0),
|
||||
_tiltY(0.0),
|
||||
@ -56,6 +56,7 @@ GUIEventAdapter::GUIEventAdapter(const GUIEventAdapter& rhs,const osg::CopyOp& c
|
||||
_handled(rhs._handled),
|
||||
_eventType(rhs._eventType),
|
||||
_time(rhs._time),
|
||||
_context(rhs._context),
|
||||
_windowX(rhs._windowX),
|
||||
_windowY(rhs._windowY),
|
||||
_windowWidth(rhs._windowWidth),
|
||||
|
@ -626,6 +626,8 @@ void CompositeViewer::eventTraversal()
|
||||
{
|
||||
osgGA::GUIEventAdapter* event = itr->get();
|
||||
|
||||
//osg::notify(osg::NOTICE)<<"event->getGraphicsContext()="<<event->getGraphicsContext()<<std::endl;
|
||||
|
||||
bool pointerEvent = false;
|
||||
|
||||
float x = event->getX();
|
||||
@ -668,15 +670,11 @@ void CompositeViewer::eventTraversal()
|
||||
// If this camera is not a slave camera
|
||||
if (camera->getView()->getCamera() == camera)
|
||||
{
|
||||
const osg::GraphicsContext::Traits* traits = gw ? gw->getTraits() : 0;
|
||||
if (traits)
|
||||
{
|
||||
eventState->setInputRange( 0, 0, traits->width, traits->height);
|
||||
}
|
||||
else
|
||||
{
|
||||
eventState->setInputRange(-1.0, -1.0, 1.0, 1.0);
|
||||
}
|
||||
eventState->setGraphicsContext(gw);
|
||||
eventState->setInputRange( viewport->x(), viewport->y(),
|
||||
viewport->x()+viewport->width(),
|
||||
viewport->y()+viewport->height());
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -744,8 +742,6 @@ void CompositeViewer::eventTraversal()
|
||||
event->setButtonMask(eventState->getButtonMask());
|
||||
event->setMouseYOrientation(eventState->getMouseYOrientation());
|
||||
}
|
||||
//osg::notify(osg::NOTICE)<<" mouse x = "<<event->getX()<<" y="<<event->getY()<<std::endl;
|
||||
// osg::notify(osg::NOTICE)<<" mouse Xmin = "<<event->getXmin()<<" Ymin="<<event->getYmin()<<" xMax="<<event->getXmax()<<" Ymax="<<event->getYmax()<<std::endl;
|
||||
}
|
||||
|
||||
for(itr = gw_events.begin();
|
||||
|
@ -500,7 +500,7 @@ void GraphicsWindowCarbon::init()
|
||||
{
|
||||
if (_initialized) return;
|
||||
|
||||
getEventQueue()->setCurrentEventState(osgGA::GUIEventAdapter::getAccumulatedEventState().get());
|
||||
// getEventQueue()->setCurrentEventState(osgGA::GUIEventAdapter::getAccumulatedEventState().get());
|
||||
|
||||
_lastModifierKeys = 0;
|
||||
_windowTitleHeight = 0;
|
||||
|
@ -1011,7 +1011,7 @@ void GraphicsWindowWin32::init()
|
||||
{
|
||||
if (_initialized) return;
|
||||
|
||||
getEventQueue()->setCurrentEventState(osgGA::GUIEventAdapter::getAccumulatedEventState().get());
|
||||
// getEventQueue()->setCurrentEventState(osgGA::GUIEventAdapter::getAccumulatedEventState().get());
|
||||
|
||||
WindowData *windowData = _traits.get() ? dynamic_cast<WindowData*>(_traits->inheritedWindowData.get()) : 0;
|
||||
HWND windowHandle = windowData ? windowData->_hwnd : 0;
|
||||
|
@ -545,7 +545,7 @@ void GraphicsWindowX11::init()
|
||||
return;
|
||||
}
|
||||
|
||||
getEventQueue()->setCurrentEventState(osgGA::GUIEventAdapter::getAccumulatedEventState().get());
|
||||
// getEventQueue()->setCurrentEventState(osgGA::GUIEventAdapter::getAccumulatedEventState().get());
|
||||
|
||||
WindowData* inheritedWindowData = dynamic_cast<WindowData*>(_traits->inheritedWindowData.get());
|
||||
Window windowHandle = inheritedWindowData ? inheritedWindowData->_window : 0;
|
||||
@ -903,6 +903,8 @@ void GraphicsWindowX11::checkEvents()
|
||||
double eventTime = baseTime;
|
||||
double resizeTime = eventTime;
|
||||
_timeOfLastCheckEvents = getEventQueue()->getTime();
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"GraphicsWindowX11::checkEvents() : getEventQueue()->getCurrentEventState()->getGraphicsContext()="<<getEventQueue()->getCurrentEventState()->getGraphicsContext()<<std::endl;
|
||||
|
||||
int windowX = _traits->x;
|
||||
int windowY = _traits->y;
|
||||
|
@ -1703,24 +1703,29 @@ bool View::containsCamera(const osg::Camera* camera) const
|
||||
const osg::Camera* View::getCameraContainingPosition(float x, float y, float& local_x, float& local_y) const
|
||||
{
|
||||
const osgGA::GUIEventAdapter* eventState = getEventQueue()->getCurrentEventState();
|
||||
const osgViewer::GraphicsWindow* gw = dynamic_cast<const osgViewer::GraphicsWindow*>(eventState->getGraphicsContext());
|
||||
|
||||
bool view_invert_y = eventState->getMouseYOrientation()==osgGA::GUIEventAdapter::Y_INCREASING_DOWNWARDS;
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"View::getCameraContainingPosition("<<x<<","<<y<<",..,..) view_invert_y="<<view_invert_y<<std::endl;
|
||||
|
||||
double epsilon = 0.5;
|
||||
|
||||
if (_camera->getGraphicsContext() && _camera->getViewport())
|
||||
if (_camera->getGraphicsContext() &&
|
||||
(!gw || _camera->getGraphicsContext()==gw) &&
|
||||
_camera->getViewport())
|
||||
{
|
||||
const osg::Viewport* viewport = _camera->getViewport();
|
||||
|
||||
double new_x = static_cast<double>(_camera->getGraphicsContext()->getTraits()->width) * (x - eventState->getXmin())/(eventState->getXmax()-eventState->getXmin());
|
||||
double new_y = view_invert_y ?
|
||||
double new_x = x;
|
||||
double new_y = y;
|
||||
|
||||
if (!gw)
|
||||
{
|
||||
new_x = static_cast<double>(_camera->getGraphicsContext()->getTraits()->width) * (x - eventState->getXmin())/(eventState->getXmax()-eventState->getXmin());
|
||||
new_y = view_invert_y ?
|
||||
static_cast<double>(_camera->getGraphicsContext()->getTraits()->height) * (1.0 - (y- eventState->getYmin())/(eventState->getYmax()-eventState->getYmin())) :
|
||||
static_cast<double>(_camera->getGraphicsContext()->getTraits()->height) * (y - eventState->getYmin())/(eventState->getYmax()-eventState->getXmin());
|
||||
}
|
||||
|
||||
// osg::notify(osg::NOTICE)<<" new_x="<<new_x<<","<<new_y<<std::endl;
|
||||
|
||||
|
||||
if (viewport &&
|
||||
new_x >= (viewport->x()-epsilon) && new_y >= (viewport->y()-epsilon) &&
|
||||
new_x < (viewport->x()+viewport->width()-1.0+epsilon) && new_y <= (viewport->y()+viewport->height()-1.0+epsilon) )
|
||||
@ -1728,7 +1733,7 @@ const osg::Camera* View::getCameraContainingPosition(float x, float y, float& lo
|
||||
local_x = new_x;
|
||||
local_y = new_y;
|
||||
|
||||
// osg::notify(osg::NOTICE)<<"Returning master camera"<<std::endl;
|
||||
osg::notify(osg::INFO)<<"Returning master camera"<<std::endl;
|
||||
|
||||
return _camera.get();
|
||||
}
|
||||
@ -1736,6 +1741,7 @@ const osg::Camera* View::getCameraContainingPosition(float x, float y, float& lo
|
||||
|
||||
osg::Matrix masterCameraVPW = getCamera()->getViewMatrix() * getCamera()->getProjectionMatrix();
|
||||
|
||||
// convert to non dimensional
|
||||
x = (x - eventState->getXmin()) * 2.0 / (eventState->getXmax()-eventState->getXmin()) - 1.0;
|
||||
y = (y - eventState->getYmin())* 2.0 / (eventState->getYmax()-eventState->getYmin()) - 1.0;
|
||||
|
||||
@ -1748,7 +1754,7 @@ const osg::Camera* View::getCameraContainingPosition(float x, float y, float& lo
|
||||
slave._camera->getAllowEventFocus() &&
|
||||
slave._camera->getRenderTargetImplementation()==osg::Camera::FRAME_BUFFER)
|
||||
{
|
||||
// osg::notify(osg::NOTICE)<<"Testing slave camera "<<slave._camera->getName()<<std::endl;
|
||||
osg::notify(osg::INFO)<<"Testing slave camera "<<slave._camera->getName()<<std::endl;
|
||||
|
||||
const osg::Camera* camera = slave._camera.get();
|
||||
const osg::Viewport* viewport = camera ? camera->getViewport() : 0;
|
||||
|
Loading…
Reference in New Issue
Block a user