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.
This commit is contained in:
parent
4c32b832ec
commit
d5c382a780
2 changed files with 90 additions and 79 deletions
|
@ -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;
|
||||
}
|
||||
|
@ -158,6 +160,30 @@ public:
|
|||
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<SGSceneryPick> 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,8 +498,7 @@ 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;
|
||||
}
|
||||
|
||||
|
@ -499,8 +507,6 @@ void FGMouseInput::doMouseMotion (int x, int y, const osgGA::GUIEventAdapter* ea
|
|||
// 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;
|
||||
}
|
||||
|
||||
|
@ -512,6 +518,10 @@ void FGMouseInput::doMouseMotion (int x, int y, const osgGA::GUIEventAdapter* ea
|
|||
}
|
||||
else
|
||||
{
|
||||
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) {
|
||||
|
@ -527,33 +537,32 @@ void FGMouseInput::doMouseMotion (int x, int y, const osgGA::GUIEventAdapter* ea
|
|||
mode.y_bindings[modifiers][i]->fire(double(delta), double(ysize));
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
|
||||
if (need_warp)
|
||||
void FGMouseInput::doMouseMotion (int x, int y, const osgGA::GUIEventAdapter* ea)
|
||||
{
|
||||
fgWarpMouse(new_x, new_y);
|
||||
d->haveWarped = true;
|
||||
}
|
||||
mouse &m = d->mice[0];
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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<FGMouseInputPrivate> d;
|
||||
|
||||
|
|
Loading…
Reference in a new issue