From: James Turner Date: Tue, 5 Mar 2013 14:31:58 +0000 (+0000) Subject: Fix updating of mouse position props. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=d5c382a780c90fcb70bfb7d2652dd0adc7411a4f;p=flightgear.git Fix updating of mouse position props. Some cockpits rely on mouse position props being updated even when using a dragged pick-callback. Thanks to Clement for noticing. Re-structured so however we process the mouse (PUI, pick-callback, normal motion), we always update the props. --- diff --git a/src/Input/FGMouseInput.cxx b/src/Input/FGMouseInput.cxx index 6fa697ab6..eee13d6f6 100644 --- a/src/Input/FGMouseInput.cxx +++ b/src/Input/FGMouseInput.cxx @@ -144,7 +144,9 @@ public: cursorTimeoutNode(fgGetNode("/sim/mouse/cursor-timeout-sec", true ) ), rightButtonModeCycleNode(fgGetNode("/sim/mouse/right-button-mode-cycle-enabled", true)), tooltipShowDelayNode( fgGetNode("/sim/mouse/tooltip-delay-msec", true) ), - clickTriggersTooltipNode( fgGetNode("/sim/mouse/click-shows-tooltip", true) ) + clickTriggersTooltipNode( fgGetNode("/sim/mouse/click-shows-tooltip", true) ), + mouseXNode(fgGetNode("/devices/status/mice/mouse/x", true)), + mouseYNode(fgGetNode("/devices/status/mice/mouse/y", true)) { tooltipTimeoutDone = false; } @@ -157,7 +159,31 @@ public: fgWarpMouse(m.x, m.y); haveWarped = true; } - + + void constrainMouse(int x, int y) + { + int new_x=x,new_y=y; + int xsize = xSizeNode ? xSizeNode->getIntValue() : 800; + int ysize = ySizeNode ? ySizeNode->getIntValue() : 600; + + bool need_warp = false; + if (x <= (xsize * .25) || x >= (xsize * .75)) { + new_x = int(xsize * .5); + need_warp = true; + } + + if (y <= (ysize * .25) || y >= (ysize * .75)) { + new_y = int(ysize * .5); + need_warp = true; + } + + if (need_warp) + { + fgWarpMouse(new_x, new_y); + haveWarped = true; + } + } + void doHoverPick(const osg::Vec2d& windowPos) { std::vector pickList; @@ -212,6 +238,7 @@ public: SGPropertyNode_ptr rightButtonModeCycleNode; SGPropertyNode_ptr tooltipShowDelayNode; SGPropertyNode_ptr clickTriggersTooltipNode; + SGPropertyNode_ptr mouseXNode, mouseYNode; }; @@ -447,35 +474,17 @@ void FGMouseInput::doMouseClick (int b, int updown, int x, int y, bool mainWindo } } -void FGMouseInput::doMouseMotion (int x, int y, const osgGA::GUIEventAdapter* ea) +void FGMouseInput::processMotion(int x, int y, const osgGA::GUIEventAdapter* ea) { - int modifiers = fgGetKeyModifiers(); - - int xsize = d->xSizeNode ? d->xSizeNode->getIntValue() : 800; - int ysize = d->ySizeNode ? d->ySizeNode->getIntValue() : 600; - - mouse &m = d->mice[0]; - - if (m.current_mode < 0 || m.current_mode >= m.nModes) { - m.x = x; - m.y = y; - return; - } - if (!d->activePickCallbacks[0].empty()) { - SG_LOG(SG_GENERAL, SG_INFO, "mouse-motion, have active pick callback"); + //SG_LOG(SG_GENERAL, SG_INFO, "mouse-motion, have active pick callback"); BOOST_FOREACH(SGPickCallback* cb, d->activePickCallbacks[0]) { cb->mouseMoved(ea); } - - m.x = x; - m.y = y; return; } - m.timeSinceLastMove.stamp(); - FGMouseCursor::instance()->mouseMoved(); - + mouse &m = d->mice[0]; int modeIndex = m.current_mode; // are we in spring-loaded look mode? if (!d->rightButtonModeCycleNode->getBoolValue()) { @@ -489,71 +498,71 @@ void FGMouseInput::doMouseMotion (int x, int y, const osgGA::GUIEventAdapter* ea osg::Vec2d windowPos; flightgear::eventToWindowCoords(ea, windowPos.x(), windowPos.y()); d->doHoverPick(windowPos); - // mouse has moved, so we may need to issue tooltip-timeout command - // again + // mouse has moved, so we may need to issue tooltip-timeout command again d->tooltipTimeoutDone = false; } - + mouse_mode &mode = m.modes[modeIndex]; - - // Pass on to PUI if requested, and return - // if PUI consumed the event. + + // Pass on to PUI if requested, and return + // if PUI consumed the event. if (mode.pass_through && puMouse(x, y)) { - m.x = x; - m.y = y; - return; + return; } - + if (d->haveWarped) { - // don't fire mouse-movement events at the first update after warping the mouse, - // just remember the new mouse position - d->haveWarped = false; + // don't fire mouse-movement events at the first update after warping the mouse, + // just remember the new mouse position + d->haveWarped = false; } else { - // OK, PUI didn't want the event, - // so we can play with it. - if (x != m.x) { - int delta = x - m.x; - d->xAccelNode->setIntValue( delta ); - for (unsigned int i = 0; i < mode.x_bindings[modifiers].size(); i++) - mode.x_bindings[modifiers][i]->fire(double(delta), double(xsize)); - } - if (y != m.y) { - int delta = y - m.y; - d->yAccelNode->setIntValue( -delta ); - for (unsigned int i = 0; i < mode.y_bindings[modifiers].size(); i++) - mode.y_bindings[modifiers][i]->fire(double(delta), double(ysize)); - } + int modifiers = fgGetKeyModifiers(); + int xsize = d->xSizeNode ? d->xSizeNode->getIntValue() : 800; + int ysize = d->ySizeNode ? d->ySizeNode->getIntValue() : 600; + + // OK, PUI didn't want the event, + // so we can play with it. + if (x != m.x) { + int delta = x - m.x; + d->xAccelNode->setIntValue( delta ); + for (unsigned int i = 0; i < mode.x_bindings[modifiers].size(); i++) + mode.x_bindings[modifiers][i]->fire(double(delta), double(xsize)); + } + if (y != m.y) { + int delta = y - m.y; + d->yAccelNode->setIntValue( -delta ); + for (unsigned int i = 0; i < mode.y_bindings[modifiers].size(); i++) + mode.y_bindings[modifiers][i]->fire(double(delta), double(ysize)); + } } - // Constrain the mouse if requested + + // Constrain the mouse if requested if (mode.constrained) { - int new_x=x,new_y=y; - - bool need_warp = false; - if (x <= (xsize * .25) || x >= (xsize * .75)) { - new_x = int(xsize * .5); - need_warp = true; - } + d->constrainMouse(x, y); + } +} - if (y <= (ysize * .25) || y >= (ysize * .75)) { - new_y = int(ysize * .5); - need_warp = true; - } +void FGMouseInput::doMouseMotion (int x, int y, const osgGA::GUIEventAdapter* ea) +{ + mouse &m = d->mice[0]; - if (need_warp) - { - fgWarpMouse(new_x, new_y); - d->haveWarped = true; - } + if (m.current_mode < 0 || m.current_mode >= m.nModes) { + m.x = x; + m.y = y; + return; } - if (m.x != x) - fgSetInt("/devices/status/mice/mouse/x", m.x = x); + m.timeSinceLastMove.stamp(); + FGMouseCursor::instance()->mouseMoved(); - if (m.y != y) - fgSetInt("/devices/status/mice/mouse/y", m.y = y); + processMotion(x, y, ea); + + m.x = x; + m.y = y; + d->mouseXNode->setIntValue(x); + d->mouseYNode->setIntValue(y); } diff --git a/src/Input/FGMouseInput.hxx b/src/Input/FGMouseInput.hxx index 7e1634413..fa684b455 100644 --- a/src/Input/FGMouseInput.hxx +++ b/src/Input/FGMouseInput.hxx @@ -49,6 +49,8 @@ public: void doMouseClick (int b, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea); void doMouseMotion (int x, int y, const osgGA::GUIEventAdapter*); private: + void processMotion(int x, int y, const osgGA::GUIEventAdapter* ea); + class FGMouseInputPrivate; std::auto_ptr d;