2009-08-07 18:56:48 +00:00
|
|
|
// FGMouseInput.cxx -- handle user input from mouse devices
|
|
|
|
//
|
|
|
|
// Written by Torsten Dreyer, started August 2009
|
|
|
|
// Based on work from David Megginson, started May 2001.
|
|
|
|
//
|
|
|
|
// Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de
|
|
|
|
// Copyright (C) 2001 David Megginson, david@megginson.com
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// published by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful, but
|
|
|
|
// WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
2011-11-14 08:38:58 +01:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2009-08-07 18:56:48 +00:00
|
|
|
#include "FGMouseInput.hxx"
|
2013-02-03 16:34:36 +00:00
|
|
|
|
2013-02-09 16:05:54 +00:00
|
|
|
#include <boost/foreach.hpp>
|
2013-02-03 16:34:36 +00:00
|
|
|
#include <osgGA/GUIEventAdapter>
|
2013-02-09 16:05:54 +00:00
|
|
|
|
|
|
|
#include <simgear/scene/util/SGPickCallback.hxx>
|
|
|
|
#include <simgear/timing/timestamp.hxx>
|
2013-03-08 16:34:21 +00:00
|
|
|
#include <simgear/scene/model/SGPickAnimation.hxx>
|
2013-02-09 16:05:54 +00:00
|
|
|
|
|
|
|
#include "FGButton.hxx"
|
2011-05-21 13:22:47 +02:00
|
|
|
#include "Main/globals.hxx"
|
2013-02-09 16:05:54 +00:00
|
|
|
#include <Viewer/renderer.hxx>
|
|
|
|
#include <plib/pu.h>
|
|
|
|
#include <Model/panelnode.hxx>
|
|
|
|
#include <Cockpit/panel.hxx>
|
|
|
|
#include <Viewer/FGEventHandler.hxx>
|
|
|
|
#include <GUI/MouseCursor.hxx>
|
2009-08-07 18:56:48 +00:00
|
|
|
|
2011-10-17 17:41:59 +01:00
|
|
|
using std::ios_base;
|
|
|
|
|
2013-02-09 16:05:54 +00:00
|
|
|
const int MAX_MICE = 1;
|
|
|
|
const int MAX_MOUSE_BUTTONS = 8;
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of currently pressed mouse button events
|
|
|
|
*/
|
|
|
|
class ActivePickCallbacks : public std::map<int, std::list<SGSharedPtr<SGPickCallback> > > {
|
|
|
|
public:
|
2013-03-07 18:41:38 +00:00
|
|
|
void update( double dt, unsigned int keyModState );
|
2013-02-09 16:05:54 +00:00
|
|
|
void init( int button, const osgGA::GUIEventAdapter* ea );
|
|
|
|
};
|
|
|
|
|
|
|
|
|
2013-02-03 16:34:36 +00:00
|
|
|
void ActivePickCallbacks::init( int button, const osgGA::GUIEventAdapter* ea )
|
2009-08-07 18:56:48 +00:00
|
|
|
{
|
2013-02-09 16:05:54 +00:00
|
|
|
osg::Vec2d windowPos;
|
|
|
|
flightgear::eventToWindowCoords(ea, windowPos.x(), windowPos.y());
|
|
|
|
|
2009-08-07 18:56:48 +00:00
|
|
|
// Get the list of hit callbacks. Take the first callback that
|
|
|
|
// accepts the mouse button press and ignore the rest of them
|
|
|
|
// That is they get sorted by distance and by scenegraph depth.
|
|
|
|
// The nearest one is the first one and the deepest
|
|
|
|
// (the most specialized one in the scenegraph) is the first.
|
|
|
|
std::vector<SGSceneryPick> pickList;
|
2013-02-09 16:05:54 +00:00
|
|
|
if (!globals->get_renderer()->pick(pickList, windowPos)) {
|
2013-02-03 16:34:36 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<SGSceneryPick>::const_iterator i;
|
|
|
|
for (i = pickList.begin(); i != pickList.end(); ++i) {
|
|
|
|
if (i->callback->buttonPressed(button, ea, i->info)) {
|
|
|
|
(*this)[button].push_back(i->callback);
|
|
|
|
return;
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-07 18:41:38 +00:00
|
|
|
void ActivePickCallbacks::update( double dt, unsigned int keyModState )
|
2009-08-07 18:56:48 +00:00
|
|
|
{
|
|
|
|
// handle repeatable mouse press events
|
|
|
|
for( iterator mi = begin(); mi != end(); ++mi ) {
|
|
|
|
std::list<SGSharedPtr<SGPickCallback> >::iterator li;
|
|
|
|
for (li = mi->second.begin(); li != mi->second.end(); ++li) {
|
2013-03-07 18:41:38 +00:00
|
|
|
(*li)->update(dt, keyModState);
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-09 16:05:54 +00:00
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Settings for a mouse mode.
|
|
|
|
*/
|
|
|
|
struct mouse_mode {
|
|
|
|
mouse_mode ();
|
|
|
|
virtual ~mouse_mode ();
|
|
|
|
FGMouseCursor::Cursor cursor;
|
|
|
|
bool constrained;
|
|
|
|
bool pass_through;
|
|
|
|
FGButton * buttons;
|
|
|
|
SGBindingList x_bindings[KEYMOD_MAX];
|
|
|
|
SGBindingList y_bindings[KEYMOD_MAX];
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Settings for a mouse.
|
|
|
|
*/
|
|
|
|
struct mouse {
|
|
|
|
mouse ();
|
|
|
|
virtual ~mouse ();
|
|
|
|
int x, y;
|
|
|
|
SGPropertyNode_ptr mode_node;
|
|
|
|
SGPropertyNode_ptr mouse_button_nodes[MAX_MOUSE_BUTTONS];
|
|
|
|
int nModes;
|
|
|
|
int current_mode;
|
|
|
|
|
|
|
|
SGTimeStamp timeSinceLastMove;
|
|
|
|
mouse_mode * modes;
|
|
|
|
};
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-03-08 16:34:21 +00:00
|
|
|
class FGMouseInput::FGMouseInputPrivate : public SGPropertyChangeListener
|
2013-02-09 16:05:54 +00:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
FGMouseInputPrivate() :
|
|
|
|
haveWarped(false),
|
|
|
|
xSizeNode(fgGetNode("/sim/startup/xsize", false ) ),
|
|
|
|
ySizeNode(fgGetNode("/sim/startup/ysize", false ) ),
|
|
|
|
xAccelNode(fgGetNode("/devices/status/mice/mouse/accel-x", true ) ),
|
|
|
|
yAccelNode(fgGetNode("/devices/status/mice/mouse/accel-y", true ) ),
|
2013-03-05 14:31:58 +00:00
|
|
|
mouseXNode(fgGetNode("/devices/status/mice/mouse/x", true)),
|
|
|
|
mouseYNode(fgGetNode("/devices/status/mice/mouse/y", true))
|
2013-02-09 16:05:54 +00:00
|
|
|
{
|
|
|
|
tooltipTimeoutDone = false;
|
2013-03-08 16:34:21 +00:00
|
|
|
|
|
|
|
fgGetNode("/sim/mouse/hide-cursor", true )->addChangeListener(this, true);
|
|
|
|
fgGetNode("/sim/mouse/cursor-timeout-sec", true )->addChangeListener(this, true);
|
|
|
|
fgGetNode("/sim/mouse/right-button-mode-cycle-enabled", true)->addChangeListener(this, true);
|
|
|
|
fgGetNode("/sim/mouse/tooltip-delay-msec", true)->addChangeListener(this, true);
|
|
|
|
fgGetNode("/sim/mouse/click-shows-tooltip", true)->addChangeListener(this, true);
|
|
|
|
fgGetNode("/sim/mouse/drag-sensitivity", true)->addChangeListener(this, true);
|
|
|
|
fgGetNode("/sim/mouse/invert-mouse-wheel", true)->addChangeListener(this, true);
|
2013-02-09 16:05:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void centerMouseCursor(mouse& m)
|
|
|
|
{
|
|
|
|
// center the cursor
|
|
|
|
m.x = (xSizeNode ? xSizeNode->getIntValue() : 800) / 2;
|
|
|
|
m.y = (ySizeNode ? ySizeNode->getIntValue() : 600) / 2;
|
|
|
|
fgWarpMouse(m.x, m.y);
|
|
|
|
haveWarped = true;
|
|
|
|
}
|
2013-03-05 14:31:58 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-09 16:05:54 +00:00
|
|
|
void doHoverPick(const osg::Vec2d& windowPos)
|
|
|
|
{
|
|
|
|
std::vector<SGSceneryPick> pickList;
|
|
|
|
SGPickCallback::Priority priority = SGPickCallback::PriorityScenery;
|
|
|
|
|
|
|
|
if (globals->get_renderer()->pick(pickList, windowPos)) {
|
|
|
|
|
|
|
|
std::vector<SGSceneryPick>::const_iterator i;
|
|
|
|
for (i = pickList.begin(); i != pickList.end(); ++i) {
|
|
|
|
if (i->callback->hover(windowPos, i->info)) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// if the callback is of higher prioirty (lower enum index),
|
|
|
|
// record that.
|
|
|
|
if (i->callback->getPriority() < priority) {
|
|
|
|
priority = i->callback->getPriority();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} // of have valid pick
|
|
|
|
|
2013-03-05 08:40:17 +00:00
|
|
|
if (priority == SGPickCallback::PriorityPanel) {
|
2013-02-09 16:05:54 +00:00
|
|
|
FGMouseCursor::instance()->setCursor(FGMouseCursor::CURSOR_HAND);
|
|
|
|
} else {
|
|
|
|
// restore normal cursor
|
|
|
|
FGMouseCursor::instance()->setCursor(FGMouseCursor::CURSOR_ARROW);
|
|
|
|
}
|
|
|
|
|
|
|
|
updateHover();
|
|
|
|
}
|
|
|
|
|
|
|
|
void updateHover()
|
|
|
|
{
|
|
|
|
SGPropertyNode_ptr args(new SGPropertyNode);
|
|
|
|
globals->get_commands()->execute("update-hover", args);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-08 16:34:21 +00:00
|
|
|
// implement the property-change-listener interfacee
|
|
|
|
virtual void valueChanged( SGPropertyNode * node )
|
|
|
|
{
|
|
|
|
if (node->getNameString() == "drag-sensitivity") {
|
|
|
|
SGKnobAnimation::setDragSensitivity(node->getDoubleValue());
|
|
|
|
} else if (node->getNameString() == "invert-mouse-wheel") {
|
|
|
|
SGKnobAnimation::setAlternateMouseWheelDirection(node->getBoolValue());
|
|
|
|
} else if (node->getNameString() == "hide-cursor") {
|
|
|
|
hideCursor = node->getBoolValue();
|
|
|
|
} else if (node->getNameString() == "cursor-timeout-sec") {
|
|
|
|
cursorTimeoutMsec = node->getDoubleValue() * 1000;
|
|
|
|
} else if (node->getNameString() == "tooltip-delay-msec") {
|
|
|
|
tooltipDelayMsec = node->getIntValue();
|
|
|
|
} else if (node->getNameString() == "right-button-mode-cycle-enabled") {
|
|
|
|
rightClickModeCycle = node->getBoolValue();
|
|
|
|
} else if (node->getNameString() == "click-shows-tooltip") {
|
|
|
|
clickTriggersTooltip = node->getBoolValue();
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-02-09 16:05:54 +00:00
|
|
|
ActivePickCallbacks activePickCallbacks;
|
|
|
|
|
|
|
|
mouse mice[MAX_MICE];
|
|
|
|
|
2013-03-08 16:34:21 +00:00
|
|
|
bool hideCursor, haveWarped;
|
2013-02-09 16:05:54 +00:00
|
|
|
bool tooltipTimeoutDone;
|
2013-03-08 16:34:21 +00:00
|
|
|
bool clickTriggersTooltip;
|
|
|
|
int tooltipDelayMsec, cursorTimeoutMsec;
|
|
|
|
bool rightClickModeCycle;
|
|
|
|
|
2013-02-09 16:05:54 +00:00
|
|
|
SGPropertyNode_ptr xSizeNode;
|
|
|
|
SGPropertyNode_ptr ySizeNode;
|
|
|
|
SGPropertyNode_ptr xAccelNode;
|
|
|
|
SGPropertyNode_ptr yAccelNode;
|
2013-03-05 14:31:58 +00:00
|
|
|
SGPropertyNode_ptr mouseXNode, mouseYNode;
|
2013-02-09 16:05:54 +00:00
|
|
|
};
|
|
|
|
|
2009-08-07 18:56:48 +00:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
// The Mouse Input Implementation
|
|
|
|
////////////////////////////////////////////////////////////////////////
|
|
|
|
|
2013-02-09 16:05:54 +00:00
|
|
|
static FGMouseInput* global_mouseInput = NULL;
|
|
|
|
|
|
|
|
static void mouseClickHandler(int button, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea)
|
|
|
|
{
|
|
|
|
if(global_mouseInput)
|
|
|
|
global_mouseInput->doMouseClick(button, updown, x, y, mainWindow, ea);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void mouseMotionHandler(int x, int y, const osgGA::GUIEventAdapter* ea)
|
|
|
|
{
|
|
|
|
if (global_mouseInput != 0)
|
|
|
|
global_mouseInput->doMouseMotion(x, y, ea);
|
|
|
|
}
|
|
|
|
|
2009-08-07 18:56:48 +00:00
|
|
|
|
|
|
|
|
2011-01-07 21:05:17 +01:00
|
|
|
FGMouseInput::FGMouseInput() :
|
2013-02-09 16:05:54 +00:00
|
|
|
d(new FGMouseInputPrivate)
|
2009-08-07 18:56:48 +00:00
|
|
|
{
|
2013-02-09 16:05:54 +00:00
|
|
|
global_mouseInput = this;
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FGMouseInput::~FGMouseInput()
|
|
|
|
{
|
2013-02-09 16:05:54 +00:00
|
|
|
global_mouseInput = NULL;
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FGMouseInput::init()
|
|
|
|
{
|
|
|
|
SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse bindings");
|
|
|
|
string module = "";
|
|
|
|
|
|
|
|
SGPropertyNode * mouse_nodes = fgGetNode("/input/mice");
|
|
|
|
if (mouse_nodes == 0) {
|
|
|
|
SG_LOG(SG_INPUT, SG_WARN, "No mouse bindings (/input/mice)!!");
|
|
|
|
mouse_nodes = fgGetNode("/input/mice", true);
|
|
|
|
}
|
|
|
|
|
|
|
|
int j;
|
|
|
|
for (int i = 0; i < MAX_MICE; i++) {
|
|
|
|
SGPropertyNode * mouse_node = mouse_nodes->getChild("mouse", i, true);
|
2013-02-09 16:05:54 +00:00
|
|
|
mouse &m = d->mice[i];
|
2009-08-07 18:56:48 +00:00
|
|
|
|
|
|
|
// Grab node pointers
|
2011-01-07 21:05:17 +01:00
|
|
|
std::ostringstream buf;
|
|
|
|
buf << "/devices/status/mice/mouse[" << i << "]/mode";
|
|
|
|
m.mode_node = fgGetNode(buf.str().c_str());
|
2009-08-07 18:56:48 +00:00
|
|
|
if (m.mode_node == NULL) {
|
2011-01-07 21:05:17 +01:00
|
|
|
m.mode_node = fgGetNode(buf.str().c_str(), true);
|
2009-08-07 18:56:48 +00:00
|
|
|
m.mode_node->setIntValue(0);
|
|
|
|
}
|
|
|
|
for (j = 0; j < MAX_MOUSE_BUTTONS; j++) {
|
2011-01-08 12:50:55 +01:00
|
|
|
buf.seekp(ios_base::beg);
|
2011-01-07 21:05:17 +01:00
|
|
|
buf << "/devices/status/mice/mouse["<< i << "]/button[" << j << "]";
|
|
|
|
m.mouse_button_nodes[j] = fgGetNode(buf.str().c_str(), true);
|
2009-08-07 18:56:48 +00:00
|
|
|
m.mouse_button_nodes[j]->setBoolValue(false);
|
|
|
|
}
|
|
|
|
|
2013-03-06 14:24:29 +00:00
|
|
|
// Read all the modes
|
2009-08-07 18:56:48 +00:00
|
|
|
m.nModes = mouse_node->getIntValue("mode-count", 1);
|
|
|
|
m.modes = new mouse_mode[m.nModes];
|
|
|
|
|
|
|
|
for (int j = 0; j < m.nModes; j++) {
|
|
|
|
int k;
|
|
|
|
SGPropertyNode * mode_node = mouse_node->getChild("mode", j, true);
|
|
|
|
|
2013-02-09 16:05:54 +00:00
|
|
|
// Read the mouse cursor for this mode
|
|
|
|
m.modes[j].cursor = FGMouseCursor::cursorFromString(mode_node->getStringValue("cursor", "inherit"));
|
|
|
|
|
2013-03-06 14:24:29 +00:00
|
|
|
// Read other properties for this mode
|
2009-08-07 18:56:48 +00:00
|
|
|
m.modes[j].constrained = mode_node->getBoolValue("constrained", false);
|
|
|
|
m.modes[j].pass_through = mode_node->getBoolValue("pass-through", false);
|
|
|
|
|
2013-03-06 14:24:29 +00:00
|
|
|
// Read the button bindings for this mode
|
2009-08-07 18:56:48 +00:00
|
|
|
m.modes[j].buttons = new FGButton[MAX_MOUSE_BUTTONS];
|
2011-01-07 21:05:17 +01:00
|
|
|
std::ostringstream buf;
|
2009-08-07 18:56:48 +00:00
|
|
|
for (k = 0; k < MAX_MOUSE_BUTTONS; k++) {
|
2011-01-08 12:50:55 +01:00
|
|
|
buf.seekp(ios_base::beg);
|
2011-01-07 21:05:17 +01:00
|
|
|
buf << "mouse button " << k;
|
|
|
|
m.modes[j].buttons[k].init( mode_node->getChild("button", k), buf.str(), module );
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
2013-03-06 14:24:29 +00:00
|
|
|
// Read the axis bindings for this mode
|
2009-08-07 18:56:48 +00:00
|
|
|
read_bindings(mode_node->getChild("x-axis", 0, true), m.modes[j].x_bindings, KEYMOD_NONE, module );
|
|
|
|
read_bindings(mode_node->getChild("y-axis", 0, true), m.modes[j].y_bindings, KEYMOD_NONE, module );
|
2013-03-06 14:24:29 +00:00
|
|
|
|
|
|
|
if (mode_node->hasChild("x-axis-ctrl")) {
|
|
|
|
read_bindings(mode_node->getChild("x-axis-ctrl"), m.modes[j].x_bindings, KEYMOD_CTRL, module );
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode_node->hasChild("y-axis-ctrl")) {
|
|
|
|
read_bindings(mode_node->getChild("y-axis-ctrl"), m.modes[j].y_bindings, KEYMOD_CTRL, module );
|
|
|
|
}
|
|
|
|
} // of modes iteration
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
fgRegisterMouseClickHandler(mouseClickHandler);
|
|
|
|
fgRegisterMouseMotionHandler(mouseMotionHandler);
|
|
|
|
}
|
|
|
|
|
|
|
|
void FGMouseInput::update ( double dt )
|
|
|
|
{
|
2013-02-09 16:05:54 +00:00
|
|
|
mouse &m = d->mice[0];
|
2009-08-07 18:56:48 +00:00
|
|
|
int mode = m.mode_node->getIntValue();
|
|
|
|
if (mode != m.current_mode) {
|
2013-02-09 16:05:54 +00:00
|
|
|
// current mode has changed
|
2009-08-07 18:56:48 +00:00
|
|
|
m.current_mode = mode;
|
2013-02-09 16:05:54 +00:00
|
|
|
m.timeSinceLastMove.stamp();
|
|
|
|
|
2009-08-07 18:56:48 +00:00
|
|
|
if (mode >= 0 && mode < m.nModes) {
|
2013-02-09 16:05:54 +00:00
|
|
|
FGMouseCursor::instance()->setCursor(m.modes[mode].cursor);
|
|
|
|
d->centerMouseCursor(m);
|
2009-08-07 18:56:48 +00:00
|
|
|
} else {
|
2013-02-09 16:05:54 +00:00
|
|
|
SG_LOG(SG_INPUT, SG_WARN, "Mouse mode " << mode << " out of range");
|
|
|
|
FGMouseCursor::instance()->setCursor(FGMouseCursor::CURSOR_ARROW);
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-08 16:34:21 +00:00
|
|
|
if ( d->hideCursor ) {
|
2013-02-09 16:05:54 +00:00
|
|
|
// if delay is <= 0, disable tooltips
|
|
|
|
if ( !d->tooltipTimeoutDone &&
|
2013-03-08 16:34:21 +00:00
|
|
|
(d->tooltipDelayMsec > 0) &&
|
|
|
|
(m.timeSinceLastMove.elapsedMSec() > d->tooltipDelayMsec))
|
2013-02-09 16:05:54 +00:00
|
|
|
{
|
|
|
|
d->tooltipTimeoutDone = true;
|
|
|
|
SGPropertyNode_ptr arg(new SGPropertyNode);
|
|
|
|
globals->get_commands()->execute("tooltip-timeout", arg);
|
|
|
|
}
|
|
|
|
|
2013-03-08 16:34:21 +00:00
|
|
|
if ( m.timeSinceLastMove.elapsedMSec() > d->cursorTimeoutMsec) {
|
2013-02-09 16:05:54 +00:00
|
|
|
FGMouseCursor::instance()->hideCursorUntilMouseMove();
|
|
|
|
m.timeSinceLastMove.stamp();
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
|
|
|
}
|
2013-02-09 16:05:54 +00:00
|
|
|
|
2013-03-07 18:41:38 +00:00
|
|
|
d->activePickCallbacks.update( dt, fgGetKeyModifiers() );
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
2013-02-09 16:05:54 +00:00
|
|
|
mouse::mouse ()
|
2009-08-07 18:56:48 +00:00
|
|
|
: x(-1),
|
|
|
|
y(-1),
|
|
|
|
nModes(1),
|
|
|
|
current_mode(0),
|
|
|
|
modes(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-09 16:05:54 +00:00
|
|
|
mouse::~mouse ()
|
2009-08-07 18:56:48 +00:00
|
|
|
{
|
|
|
|
delete [] modes;
|
|
|
|
}
|
|
|
|
|
2013-02-09 16:05:54 +00:00
|
|
|
mouse_mode::mouse_mode ()
|
|
|
|
: cursor(FGMouseCursor::CURSOR_ARROW),
|
2009-08-07 18:56:48 +00:00
|
|
|
constrained(false),
|
|
|
|
pass_through(false),
|
|
|
|
buttons(NULL)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-02-09 16:05:54 +00:00
|
|
|
mouse_mode::~mouse_mode ()
|
2009-08-07 18:56:48 +00:00
|
|
|
{
|
|
|
|
// FIXME: memory leak
|
|
|
|
// for (int i = 0; i < KEYMOD_MAX; i++) {
|
|
|
|
// int j;
|
|
|
|
// for (j = 0; i < x_bindings[i].size(); j++)
|
|
|
|
// delete bindings[i][j];
|
|
|
|
// for (j = 0; j < y_bindings[i].size(); j++)
|
|
|
|
// delete bindings[i][j];
|
|
|
|
// }
|
2013-02-09 16:05:54 +00:00
|
|
|
if (buttons) {
|
|
|
|
delete [] buttons;
|
|
|
|
}
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void FGMouseInput::doMouseClick (int b, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea)
|
|
|
|
{
|
|
|
|
int modifiers = fgGetKeyModifiers();
|
|
|
|
|
2013-02-09 16:05:54 +00:00
|
|
|
mouse &m = d->mice[0];
|
2009-08-07 18:56:48 +00:00
|
|
|
mouse_mode &mode = m.modes[m.current_mode];
|
|
|
|
// Let the property manager know.
|
|
|
|
if (b >= 0 && b < MAX_MOUSE_BUTTONS)
|
|
|
|
m.mouse_button_nodes[b]->setBoolValue(updown == MOUSE_BUTTON_DOWN);
|
|
|
|
|
2013-03-08 16:34:21 +00:00
|
|
|
if (!d->rightClickModeCycle && (b == 2)) {
|
2013-02-09 16:05:54 +00:00
|
|
|
// in spring-loaded look mode, ignore right clicks entirely here
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Pass on to PUI and the panel if
|
|
|
|
// requested, and return if one of
|
|
|
|
// them consumes the event.
|
2009-08-07 18:56:48 +00:00
|
|
|
|
|
|
|
if (updown != MOUSE_BUTTON_DOWN) {
|
|
|
|
// Execute the mouse up event in any case, may be we should
|
|
|
|
// stop processing here?
|
2013-02-09 16:05:54 +00:00
|
|
|
while (!d->activePickCallbacks[b].empty()) {
|
2013-03-07 18:41:38 +00:00
|
|
|
d->activePickCallbacks[b].front()->buttonReleased(ea->getModKeyMask());
|
2013-02-09 16:05:54 +00:00
|
|
|
d->activePickCallbacks[b].pop_front();
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (mode.pass_through) {
|
2012-01-02 23:16:18 +00:00
|
|
|
// remove once PUI uses standard picking mechanism
|
2009-08-07 18:56:48 +00:00
|
|
|
if (0 <= x && 0 <= y && puMouse(b, updown, x, y))
|
|
|
|
return;
|
|
|
|
else {
|
|
|
|
// pui didn't want the click event so compute a
|
|
|
|
// scenegraph intersection point corresponding to the mouse click
|
|
|
|
if (updown == MOUSE_BUTTON_DOWN) {
|
2013-02-09 16:05:54 +00:00
|
|
|
d->activePickCallbacks.init( b, ea );
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// OK, PUI and the panel didn't want the click
|
|
|
|
if (b >= MAX_MOUSE_BUTTONS) {
|
|
|
|
SG_LOG(SG_INPUT, SG_ALERT, "Mouse button " << b
|
|
|
|
<< " where only " << MAX_MOUSE_BUTTONS << " expected");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
m.modes[m.current_mode].buttons[b].update( modifiers, 0 != updown, x, y);
|
2013-02-09 16:05:54 +00:00
|
|
|
|
2013-03-08 16:34:21 +00:00
|
|
|
if (d->clickTriggersTooltip) {
|
2013-02-09 16:05:54 +00:00
|
|
|
SGPropertyNode_ptr args(new SGPropertyNode);
|
|
|
|
args->setStringValue("reason", "click");
|
|
|
|
globals->get_commands()->execute("tooltip-timeout", args);
|
|
|
|
d->tooltipTimeoutDone = true;
|
|
|
|
}
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
2013-03-05 14:31:58 +00:00
|
|
|
void FGMouseInput::processMotion(int x, int y, const osgGA::GUIEventAdapter* ea)
|
2009-08-07 18:56:48 +00:00
|
|
|
{
|
2013-02-09 16:05:54 +00:00
|
|
|
if (!d->activePickCallbacks[0].empty()) {
|
2013-03-05 14:31:58 +00:00
|
|
|
//SG_LOG(SG_GENERAL, SG_INFO, "mouse-motion, have active pick callback");
|
2013-02-09 16:05:54 +00:00
|
|
|
BOOST_FOREACH(SGPickCallback* cb, d->activePickCallbacks[0]) {
|
|
|
|
cb->mouseMoved(ea);
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-03-05 14:31:58 +00:00
|
|
|
mouse &m = d->mice[0];
|
2013-02-09 16:05:54 +00:00
|
|
|
int modeIndex = m.current_mode;
|
|
|
|
// are we in spring-loaded look mode?
|
2013-03-08 16:34:21 +00:00
|
|
|
if (!d->rightClickModeCycle) {
|
2013-02-09 16:05:54 +00:00
|
|
|
if (m.mouse_button_nodes[2]->getBoolValue()) {
|
|
|
|
// right mouse is down, force look mode
|
|
|
|
modeIndex = 3;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (modeIndex == 0) {
|
|
|
|
osg::Vec2d windowPos;
|
|
|
|
flightgear::eventToWindowCoords(ea, windowPos.x(), windowPos.y());
|
|
|
|
d->doHoverPick(windowPos);
|
2013-03-05 14:31:58 +00:00
|
|
|
// mouse has moved, so we may need to issue tooltip-timeout command again
|
2013-02-09 16:05:54 +00:00
|
|
|
d->tooltipTimeoutDone = false;
|
|
|
|
}
|
2013-03-05 14:31:58 +00:00
|
|
|
|
2013-02-09 16:05:54 +00:00
|
|
|
mouse_mode &mode = m.modes[modeIndex];
|
2013-03-05 14:31:58 +00:00
|
|
|
|
|
|
|
// Pass on to PUI if requested, and return
|
|
|
|
// if PUI consumed the event.
|
2009-08-07 18:56:48 +00:00
|
|
|
if (mode.pass_through && puMouse(x, y)) {
|
2013-03-05 14:31:58 +00:00
|
|
|
return;
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
2013-03-05 14:31:58 +00:00
|
|
|
|
2013-02-09 16:05:54 +00:00
|
|
|
if (d->haveWarped)
|
2011-08-11 21:36:29 +02:00
|
|
|
{
|
2013-03-05 14:31:58 +00:00
|
|
|
// don't fire mouse-movement events at the first update after warping the mouse,
|
|
|
|
// just remember the new mouse position
|
|
|
|
d->haveWarped = false;
|
2011-08-11 21:36:29 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2013-03-05 14:31:58 +00:00
|
|
|
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));
|
|
|
|
}
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
2013-03-05 14:31:58 +00:00
|
|
|
|
|
|
|
// Constrain the mouse if requested
|
2009-08-07 18:56:48 +00:00
|
|
|
if (mode.constrained) {
|
2013-03-05 14:31:58 +00:00
|
|
|
d->constrainMouse(x, y);
|
|
|
|
}
|
|
|
|
}
|
2009-08-07 18:56:48 +00:00
|
|
|
|
2013-03-05 14:31:58 +00:00
|
|
|
void FGMouseInput::doMouseMotion (int x, int y, const osgGA::GUIEventAdapter* ea)
|
|
|
|
{
|
|
|
|
mouse &m = d->mice[0];
|
2009-08-07 18:56:48 +00:00
|
|
|
|
2013-03-05 14:31:58 +00:00
|
|
|
if (m.current_mode < 0 || m.current_mode >= m.nModes) {
|
|
|
|
m.x = x;
|
|
|
|
m.y = y;
|
|
|
|
return;
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
2013-03-05 14:31:58 +00:00
|
|
|
m.timeSinceLastMove.stamp();
|
|
|
|
FGMouseCursor::instance()->mouseMoved();
|
2009-08-07 18:56:48 +00:00
|
|
|
|
2013-03-05 14:31:58 +00:00
|
|
|
processMotion(x, y, ea);
|
|
|
|
|
|
|
|
m.x = x;
|
|
|
|
m.y = y;
|
|
|
|
d->mouseXNode->setIntValue(x);
|
|
|
|
d->mouseYNode->setIntValue(y);
|
2009-08-07 18:56:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|