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:
Robert Osfield
2008-06-02 17:34:47 +00:00
parent 213a2d8d13
commit e09e07d45b
10 changed files with 45 additions and 31 deletions

View File

@@ -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),

View File

@@ -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();

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;