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 ) ),
|
cursorTimeoutNode(fgGetNode("/sim/mouse/cursor-timeout-sec", true ) ),
|
||||||
rightButtonModeCycleNode(fgGetNode("/sim/mouse/right-button-mode-cycle-enabled", true)),
|
rightButtonModeCycleNode(fgGetNode("/sim/mouse/right-button-mode-cycle-enabled", true)),
|
||||||
tooltipShowDelayNode( fgGetNode("/sim/mouse/tooltip-delay-msec", 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;
|
tooltipTimeoutDone = false;
|
||||||
}
|
}
|
||||||
|
@ -158,6 +160,30 @@ public:
|
||||||
haveWarped = true;
|
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)
|
void doHoverPick(const osg::Vec2d& windowPos)
|
||||||
{
|
{
|
||||||
std::vector<SGSceneryPick> pickList;
|
std::vector<SGSceneryPick> pickList;
|
||||||
|
@ -212,6 +238,7 @@ public:
|
||||||
SGPropertyNode_ptr rightButtonModeCycleNode;
|
SGPropertyNode_ptr rightButtonModeCycleNode;
|
||||||
SGPropertyNode_ptr tooltipShowDelayNode;
|
SGPropertyNode_ptr tooltipShowDelayNode;
|
||||||
SGPropertyNode_ptr clickTriggersTooltipNode;
|
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()) {
|
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]) {
|
BOOST_FOREACH(SGPickCallback* cb, d->activePickCallbacks[0]) {
|
||||||
cb->mouseMoved(ea);
|
cb->mouseMoved(ea);
|
||||||
}
|
}
|
||||||
|
|
||||||
m.x = x;
|
|
||||||
m.y = y;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
m.timeSinceLastMove.stamp();
|
mouse &m = d->mice[0];
|
||||||
FGMouseCursor::instance()->mouseMoved();
|
|
||||||
|
|
||||||
int modeIndex = m.current_mode;
|
int modeIndex = m.current_mode;
|
||||||
// are we in spring-loaded look mode?
|
// are we in spring-loaded look mode?
|
||||||
if (!d->rightButtonModeCycleNode->getBoolValue()) {
|
if (!d->rightButtonModeCycleNode->getBoolValue()) {
|
||||||
|
@ -489,8 +498,7 @@ void FGMouseInput::doMouseMotion (int x, int y, const osgGA::GUIEventAdapter* ea
|
||||||
osg::Vec2d windowPos;
|
osg::Vec2d windowPos;
|
||||||
flightgear::eventToWindowCoords(ea, windowPos.x(), windowPos.y());
|
flightgear::eventToWindowCoords(ea, windowPos.x(), windowPos.y());
|
||||||
d->doHoverPick(windowPos);
|
d->doHoverPick(windowPos);
|
||||||
// mouse has moved, so we may need to issue tooltip-timeout command
|
// mouse has moved, so we may need to issue tooltip-timeout command again
|
||||||
// again
|
|
||||||
d->tooltipTimeoutDone = false;
|
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
|
// Pass on to PUI if requested, and return
|
||||||
// if PUI consumed the event.
|
// if PUI consumed the event.
|
||||||
if (mode.pass_through && puMouse(x, y)) {
|
if (mode.pass_through && puMouse(x, y)) {
|
||||||
m.x = x;
|
|
||||||
m.y = y;
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -512,6 +518,10 @@ void FGMouseInput::doMouseMotion (int x, int y, const osgGA::GUIEventAdapter* ea
|
||||||
}
|
}
|
||||||
else
|
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,
|
// OK, PUI didn't want the event,
|
||||||
// so we can play with it.
|
// so we can play with it.
|
||||||
if (x != m.x) {
|
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));
|
mode.y_bindings[modifiers][i]->fire(double(delta), double(ysize));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Constrain the mouse if requested
|
// Constrain the mouse if requested
|
||||||
if (mode.constrained) {
|
if (mode.constrained) {
|
||||||
int new_x=x,new_y=y;
|
d->constrainMouse(x, y);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool need_warp = false;
|
void FGMouseInput::doMouseMotion (int x, int y, const osgGA::GUIEventAdapter* ea)
|
||||||
if (x <= (xsize * .25) || x >= (xsize * .75)) {
|
{
|
||||||
new_x = int(xsize * .5);
|
mouse &m = d->mice[0];
|
||||||
need_warp = true;
|
|
||||||
|
if (m.current_mode < 0 || m.current_mode >= m.nModes) {
|
||||||
|
m.x = x;
|
||||||
|
m.y = y;
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (y <= (ysize * .25) || y >= (ysize * .75)) {
|
m.timeSinceLastMove.stamp();
|
||||||
new_y = int(ysize * .5);
|
FGMouseCursor::instance()->mouseMoved();
|
||||||
need_warp = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (need_warp)
|
processMotion(x, y, ea);
|
||||||
{
|
|
||||||
fgWarpMouse(new_x, new_y);
|
|
||||||
d->haveWarped = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m.x != x)
|
m.x = x;
|
||||||
fgSetInt("/devices/status/mice/mouse/x", m.x = x);
|
m.y = y;
|
||||||
|
d->mouseXNode->setIntValue(x);
|
||||||
if (m.y != y)
|
d->mouseYNode->setIntValue(y);
|
||||||
fgSetInt("/devices/status/mice/mouse/y", m.y = y);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -49,6 +49,8 @@ public:
|
||||||
void doMouseClick (int b, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea);
|
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*);
|
void doMouseMotion (int x, int y, const osgGA::GUIEventAdapter*);
|
||||||
private:
|
private:
|
||||||
|
void processMotion(int x, int y, const osgGA::GUIEventAdapter* ea);
|
||||||
|
|
||||||
class FGMouseInputPrivate;
|
class FGMouseInputPrivate;
|
||||||
std::auto_ptr<FGMouseInputPrivate> d;
|
std::auto_ptr<FGMouseInputPrivate> d;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue