]> git.mxchange.org Git - flightgear.git/blob - src/Input/FGMouseInput.cxx
Change tooltips to enable explicit.
[flightgear.git] / src / Input / FGMouseInput.cxx
1 // FGMouseInput.cxx -- handle user input from mouse devices
2 //
3 // Written by Torsten Dreyer, started August 2009
4 // Based on work from David Megginson, started May 2001.
5 //
6 // Copyright (C) 2009 Torsten Dreyer, Torsten (at) t3r _dot_ de
7 // Copyright (C) 2001 David Megginson, david@megginson.com
8 //
9 // This program is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU General Public License as
11 // published by the Free Software Foundation; either version 2 of the
12 // License, or (at your option) any later version.
13 //
14 // This program is distributed in the hope that it will be useful, but
15 // WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 // General Public License for more details.
18 //
19 // You should have received a copy of the GNU General Public License
20 // along with this program; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
22 //
23 // $Id$
24
25 #ifdef HAVE_CONFIG_H
26 #  include "config.h"
27 #endif
28
29 #include "FGMouseInput.hxx"
30
31 #include <boost/foreach.hpp>
32 #include <osgGA/GUIEventAdapter>
33
34 #include <simgear/scene/util/SGPickCallback.hxx>
35 #include <simgear/timing/timestamp.hxx>
36 #include <simgear/scene/model/SGPickAnimation.hxx>
37
38 #include "FGButton.hxx"
39 #include "Main/globals.hxx"
40 #include <Viewer/renderer.hxx>
41 #include <plib/pu.h>
42 #include <Model/panelnode.hxx>
43 #include <Cockpit/panel.hxx>
44 #include <Viewer/FGEventHandler.hxx>
45 #include <GUI/MouseCursor.hxx>
46
47 using std::ios_base;
48
49 const int MAX_MICE = 1;
50 const int MAX_MOUSE_BUTTONS = 8;
51
52 typedef std::vector<SGSceneryPick> SGSceneryPicks;
53 typedef SGSharedPtr<SGPickCallback> SGPickCallbackPtr;
54 typedef std::list<SGPickCallbackPtr> SGPickCallbackList;
55
56 ////////////////////////////////////////////////////////////////////////
57
58 /**
59  * List of currently pressed mouse button events
60  */
61 class ActivePickCallbacks:
62   public std::map<int, SGPickCallbackList>
63 {
64   public:
65     void update( double dt, unsigned int keyModState );
66     void init( int button, const osgGA::GUIEventAdapter* ea );
67 };
68
69
70 void ActivePickCallbacks::init( int button, const osgGA::GUIEventAdapter* ea )
71 {
72   osg::Vec2d windowPos;
73   flightgear::eventToWindowCoords(ea, windowPos.x(), windowPos.y());
74     
75   // Get the list of hit callbacks. Take the first callback that
76   // accepts the mouse button press and ignore the rest of them
77   // That is they get sorted by distance and by scenegraph depth.
78   // The nearest one is the first one and the deepest
79   // (the most specialized one in the scenegraph) is the first.
80   SGSceneryPicks pickList;
81   if (!globals->get_renderer()->pick(pickList, windowPos)) {
82     return;
83   }
84
85   SGSceneryPicks::const_iterator i;
86   for (i = pickList.begin(); i != pickList.end(); ++i) {
87     if (i->callback->buttonPressed(button, *ea, i->info)) {
88         (*this)[button].push_back(i->callback);
89         return;
90     }
91   }
92 }
93
94 void ActivePickCallbacks::update( double dt, unsigned int keyModState )
95 {
96   // handle repeatable mouse press events
97   for( iterator mi = begin(); mi != end(); ++mi ) {
98     SGPickCallbackList::iterator li;
99     for (li = mi->second.begin(); li != mi->second.end(); ++li) {
100       (*li)->update(dt, keyModState);
101     }
102   }
103 }
104
105 ////////////////////////////////////////////////////////////////////////
106
107
108 /**
109  * Settings for a mouse mode.
110  */
111 struct mouse_mode {
112     mouse_mode ();
113     virtual ~mouse_mode ();
114     FGMouseCursor::Cursor cursor;
115     bool constrained;
116     bool pass_through;
117     FGButton * buttons;
118     SGBindingList x_bindings[KEYMOD_MAX];
119     SGBindingList y_bindings[KEYMOD_MAX];
120 };
121
122
123 /**
124  * Settings for a mouse.
125  */
126 struct mouse {
127     mouse ();
128     virtual ~mouse ();
129     int x, y;
130     SGPropertyNode_ptr mode_node;
131     SGPropertyNode_ptr mouse_button_nodes[MAX_MOUSE_BUTTONS];
132     int nModes;
133     int current_mode;
134     
135     SGTimeStamp timeSinceLastMove;
136     mouse_mode * modes;
137 };
138
139 static
140 const SGSceneryPick*
141 getPick( const SGSceneryPicks& pick_list,
142          const SGPickCallback* cb )
143 {
144   for(size_t i = 0; i < pick_list.size(); ++i)
145     if( pick_list[i].callback == cb )
146       return &pick_list[i];
147
148   return 0;
149 }
150
151 ////////////////////////////////////////////////////////////////////////
152
153 class FGMouseInput::FGMouseInputPrivate : public SGPropertyChangeListener
154 {
155 public:
156     FGMouseInputPrivate() :
157         haveWarped(false),
158         xSizeNode(fgGetNode("/sim/startup/xsize", false ) ),
159         ySizeNode(fgGetNode("/sim/startup/ysize", false ) ),
160         xAccelNode(fgGetNode("/devices/status/mice/mouse/accel-x", true ) ),
161         yAccelNode(fgGetNode("/devices/status/mice/mouse/accel-y", true ) ),
162         mouseXNode(fgGetNode("/devices/status/mice/mouse/x", true)),
163         mouseYNode(fgGetNode("/devices/status/mice/mouse/y", true))
164     {
165         tooltipTimeoutDone = false;
166         hoverPickScheduled = false;
167         tooltipsEnabled = false;
168         
169         fgGetNode("/sim/mouse/hide-cursor", true )->addChangeListener(this, true);
170         fgGetNode("/sim/mouse/cursor-timeout-sec", true )->addChangeListener(this, true);
171         fgGetNode("/sim/mouse/right-button-mode-cycle-enabled", true)->addChangeListener(this, true);
172         fgGetNode("/sim/mouse/tooltip-delay-msec", true)->addChangeListener(this, true);
173         fgGetNode("/sim/mouse/click-shows-tooltip", true)->addChangeListener(this, true);
174         fgGetNode("/sim/mouse/tooltips-enabled", true)->addChangeListener(this, true);
175         fgGetNode("/sim/mouse/drag-sensitivity", true)->addChangeListener(this, true);
176         fgGetNode("/sim/mouse/invert-mouse-wheel", true)->addChangeListener(this, true);
177     }
178   
179     void centerMouseCursor(mouse& m)
180     {    
181       // center the cursor
182       m.x = (xSizeNode ? xSizeNode->getIntValue() : 800) / 2;
183       m.y = (ySizeNode ? ySizeNode->getIntValue() : 600) / 2;
184       fgWarpMouse(m.x, m.y);
185       haveWarped = true;
186     }
187   
188     void constrainMouse(int x, int y)
189     {
190         int new_x=x,new_y=y;
191         int xsize = xSizeNode ? xSizeNode->getIntValue() : 800;
192         int ysize = ySizeNode ? ySizeNode->getIntValue() : 600;
193         
194         bool need_warp = false;
195         if (x <= (xsize * .25) || x >= (xsize * .75)) {
196           new_x = int(xsize * .5);
197           need_warp = true;
198         }
199
200         if (y <= (ysize * .25) || y >= (ysize * .75)) {
201           new_y = int(ysize * .5);
202           need_warp = true;
203         }
204
205         if (need_warp)
206         {
207           fgWarpMouse(new_x, new_y);
208           haveWarped = true;
209         }
210     }
211
212     void scheduleHoverPick(const osg::Vec2d& windowPos)
213     {
214       hoverPickScheduled = true;
215       hoverPos = windowPos;
216     }
217   
218     void doHoverPick(const osg::Vec2d& windowPos)
219     {
220         FGMouseCursor::Cursor cur = FGMouseCursor::CURSOR_ARROW;
221         bool explicitCursor = false;
222         bool didPick = false;
223
224         SGPickCallback::Priority priority = SGPickCallback::PriorityScenery;
225         SGSceneryPicks pickList;
226         globals->get_renderer()->pick(pickList, windowPos);
227
228         SGSceneryPicks::const_iterator i;
229         for( i = pickList.begin(); i != pickList.end(); ++i )
230         {
231             bool done = i->callback->hover(windowPos, i->info);
232             std::string curName(i->callback->getCursor());
233             if (!curName.empty()) {
234                 explicitCursor = true;
235                 cur = FGMouseCursor::cursorFromString(curName.c_str());
236             }
237             
238             // if the callback is of higher prioirty (lower enum index),
239             // record that.
240             if (i->callback->getPriority() < priority) {
241                 priority = i->callback->getPriority();
242             }
243
244             if (done) {
245                 didPick = true;
246                 break;
247             }
248         } // of picks iteration
249
250         // Check if any pick from the previous iteration has disappeared. If so
251         // notify the callback that the mouse has left its element.
252         for( i = _previous_picks.begin(); i != _previous_picks.end(); ++i )
253         {
254           if( !getPick(pickList, i->callback) )
255             i->callback->mouseLeave(windowPos);
256         }
257         _previous_picks = pickList;
258       
259         if (!explicitCursor && (priority == SGPickCallback::PriorityPanel)) {
260             cur = FGMouseCursor::CURSOR_HAND;
261         }
262         
263         FGMouseCursor::instance()->setCursor(cur);
264         if (!didPick) {
265           SGPropertyNode_ptr args(new SGPropertyNode);
266           globals->get_commands()->execute("update-hover", args);
267
268         }
269     }
270     
271     void doMouseMoveWithCallbacks(const osgGA::GUIEventAdapter* ea)
272     {
273         FGMouseCursor::Cursor cur = FGMouseCursor::CURSOR_CLOSED_HAND;
274         
275         osg::Vec2d windowPos;
276         flightgear::eventToWindowCoords(ea, windowPos.x(), windowPos.y());
277
278         SGSceneryPicks pickList;
279         if( !globals->get_renderer()->pick(pickList, windowPos) )
280           return;
281
282         for( ActivePickCallbacks::iterator mi = activePickCallbacks.begin();
283                                            mi != activePickCallbacks.end();
284                                          ++mi )
285         {
286           SGPickCallbackList::iterator li;
287           for( li = mi->second.begin(); li != mi->second.end(); ++li )
288           {
289             const SGSceneryPick* pick = getPick(pickList, *li);
290             (*li)->mouseMoved(*ea, pick ? &pick->info : 0);
291
292             std::string curName((*li)->getCursor());
293             if( !curName.empty() )
294               cur = FGMouseCursor::cursorFromString(curName.c_str());
295           }
296         }
297
298         FGMouseCursor::instance()->setCursor(cur);
299     }
300
301     // implement the property-change-listener interfacee
302     virtual void valueChanged( SGPropertyNode * node )
303     {
304         if (node->getNameString() == "drag-sensitivity") {
305             SGKnobAnimation::setDragSensitivity(node->getDoubleValue());
306         } else if (node->getNameString() == "invert-mouse-wheel") {
307             SGKnobAnimation::setAlternateMouseWheelDirection(node->getBoolValue());
308         } else if (node->getNameString() == "hide-cursor") {
309             hideCursor = node->getBoolValue();
310         } else if (node->getNameString() == "cursor-timeout-sec") {
311             cursorTimeoutMsec = node->getDoubleValue() * 1000;
312         } else if (node->getNameString() == "tooltip-delay-msec") {
313             tooltipDelayMsec = node->getIntValue();
314         } else if (node->getNameString() == "right-button-mode-cycle-enabled") {
315             rightClickModeCycle = node->getBoolValue();
316         } else if (node->getNameString() == "click-shows-tooltip") {
317             clickTriggersTooltip = node->getBoolValue();
318         } else if (node->getNameString() == "tooltips-enabled") {
319             tooltipsEnabled = node->getBoolValue();
320         }
321     }
322     
323     ActivePickCallbacks activePickCallbacks;
324     SGSceneryPicks _previous_picks;
325
326     mouse mice[MAX_MICE];
327     
328     bool hideCursor, haveWarped;
329     bool tooltipTimeoutDone;
330     bool clickTriggersTooltip;
331     int tooltipDelayMsec, cursorTimeoutMsec;
332     bool rightClickModeCycle;
333     bool tooltipsEnabled;
334     
335     SGPropertyNode_ptr xSizeNode;
336     SGPropertyNode_ptr ySizeNode;
337     SGPropertyNode_ptr xAccelNode;
338     SGPropertyNode_ptr yAccelNode;
339     SGPropertyNode_ptr mouseXNode, mouseYNode;
340   
341     bool hoverPickScheduled;
342     osg::Vec2d hoverPos;
343 };
344
345
346 ////////////////////////////////////////////////////////////////////////
347 // The Mouse Input Implementation
348 ////////////////////////////////////////////////////////////////////////
349
350 static FGMouseInput* global_mouseInput = NULL;
351
352 static void mouseClickHandler(int button, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea)
353 {
354     if(global_mouseInput)
355         global_mouseInput->doMouseClick(button, updown, x, y, mainWindow, ea);
356 }
357
358 static void mouseMotionHandler(int x, int y, const osgGA::GUIEventAdapter* ea)
359 {
360     if (global_mouseInput != 0)
361         global_mouseInput->doMouseMotion(x, y, ea);
362 }
363
364
365
366 FGMouseInput::FGMouseInput() :
367   d(new FGMouseInputPrivate)
368 {
369     global_mouseInput = this;
370 }
371
372 FGMouseInput::~FGMouseInput()
373 {
374     global_mouseInput = NULL;
375 }
376
377 void FGMouseInput::init()
378 {
379   SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse bindings");
380   std::string module = "";
381
382   SGPropertyNode * mouse_nodes = fgGetNode("/input/mice");
383   if (mouse_nodes == 0) {
384     SG_LOG(SG_INPUT, SG_WARN, "No mouse bindings (/input/mice)!!");
385     mouse_nodes = fgGetNode("/input/mice", true);
386   }
387
388   int j;
389   for (int i = 0; i < MAX_MICE; i++) {
390     SGPropertyNode * mouse_node = mouse_nodes->getChild("mouse", i, true);
391     mouse &m = d->mice[i];
392
393                                 // Grab node pointers
394     std::ostringstream buf;
395     buf <<  "/devices/status/mice/mouse[" << i << "]/mode";
396     m.mode_node = fgGetNode(buf.str().c_str());
397     if (m.mode_node == NULL) {
398       m.mode_node = fgGetNode(buf.str().c_str(), true);
399       m.mode_node->setIntValue(0);
400     }
401     for (j = 0; j < MAX_MOUSE_BUTTONS; j++) {
402       buf.seekp(ios_base::beg);
403       buf << "/devices/status/mice/mouse["<< i << "]/button[" << j << "]";
404       m.mouse_button_nodes[j] = fgGetNode(buf.str().c_str(), true);
405       m.mouse_button_nodes[j]->setBoolValue(false);
406     }
407
408    // Read all the modes
409     m.nModes = mouse_node->getIntValue("mode-count", 1);
410     m.modes = new mouse_mode[m.nModes];
411
412     for (int j = 0; j < m.nModes; j++) {
413       int k;
414       SGPropertyNode * mode_node = mouse_node->getChild("mode", j, true);
415
416     // Read the mouse cursor for this mode
417       m.modes[j].cursor = FGMouseCursor::cursorFromString(mode_node->getStringValue("cursor", "inherit"));
418         
419       // Read other properties for this mode
420       m.modes[j].constrained = mode_node->getBoolValue("constrained", false);
421       m.modes[j].pass_through = mode_node->getBoolValue("pass-through", false);
422
423       // Read the button bindings for this mode
424       m.modes[j].buttons = new FGButton[MAX_MOUSE_BUTTONS];
425       std::ostringstream buf;
426       for (k = 0; k < MAX_MOUSE_BUTTONS; k++) {
427         buf.seekp(ios_base::beg);
428         buf << "mouse button " << k;
429         m.modes[j].buttons[k].init( mode_node->getChild("button", k), buf.str(), module );
430       }
431
432       // Read the axis bindings for this mode
433       read_bindings(mode_node->getChild("x-axis", 0, true), m.modes[j].x_bindings, KEYMOD_NONE, module );
434       read_bindings(mode_node->getChild("y-axis", 0, true), m.modes[j].y_bindings, KEYMOD_NONE, module );
435       
436       if (mode_node->hasChild("x-axis-ctrl")) {
437         read_bindings(mode_node->getChild("x-axis-ctrl"), m.modes[j].x_bindings, KEYMOD_CTRL, module );
438       }
439       if (mode_node->hasChild("x-axis-shift")) {
440         read_bindings(mode_node->getChild("x-axis-shift"), m.modes[j].x_bindings, KEYMOD_SHIFT, module );
441       }
442       if (mode_node->hasChild("x-axis-ctrl-shift")) {
443         read_bindings(mode_node->getChild("x-axis-ctrl-shift"), m.modes[j].x_bindings, KEYMOD_CTRL|KEYMOD_SHIFT, module );
444       }
445       
446       if (mode_node->hasChild("y-axis-ctrl")) {
447         read_bindings(mode_node->getChild("y-axis-ctrl"), m.modes[j].y_bindings, KEYMOD_CTRL, module );
448       }
449       if (mode_node->hasChild("y-axis-shift")) {
450         read_bindings(mode_node->getChild("y-axis-shift"), m.modes[j].y_bindings, KEYMOD_SHIFT, module );
451       }
452       if (mode_node->hasChild("y-axis-ctrl-shift")) {
453         read_bindings(mode_node->getChild("y-axis-ctrl-shift"), m.modes[j].y_bindings, KEYMOD_CTRL|KEYMOD_SHIFT, module );
454       }
455     } // of modes iteration
456   }
457
458   fgRegisterMouseClickHandler(mouseClickHandler);
459   fgRegisterMouseMotionHandler(mouseMotionHandler);
460 }
461
462 void FGMouseInput::update ( double dt )
463 {
464   mouse &m = d->mice[0];
465   int mode =  m.mode_node->getIntValue();
466   if (mode != m.current_mode) {
467     // current mode has changed
468     m.current_mode = mode;
469     m.timeSinceLastMove.stamp();
470       
471     if (mode >= 0 && mode < m.nModes) {
472       FGMouseCursor::instance()->setCursor(m.modes[mode].cursor);
473       d->centerMouseCursor(m);
474     } else {
475       SG_LOG(SG_INPUT, SG_WARN, "Mouse mode " << mode << " out of range");
476       FGMouseCursor::instance()->setCursor(FGMouseCursor::CURSOR_ARROW);
477     }
478   }
479
480   if ((mode == 0) && d->hoverPickScheduled) {
481     d->doHoverPick(d->hoverPos);
482     d->hoverPickScheduled = false;
483   }
484   
485   if ( !d->tooltipTimeoutDone &&
486       d->tooltipsEnabled &&
487       (m.timeSinceLastMove.elapsedMSec() > d->tooltipDelayMsec))
488   {
489       d->tooltipTimeoutDone = true;
490       SGPropertyNode_ptr arg(new SGPropertyNode);
491       globals->get_commands()->execute("tooltip-timeout", arg);
492   }
493   
494   if ( d->hideCursor ) {
495       if ( m.timeSinceLastMove.elapsedMSec() > d->cursorTimeoutMsec) {
496           FGMouseCursor::instance()->hideCursorUntilMouseMove();
497           m.timeSinceLastMove.stamp();
498       }
499   }
500     
501   d->activePickCallbacks.update( dt, fgGetKeyModifiers() );
502 }
503
504 mouse::mouse ()
505   : x(-1),
506     y(-1),
507     nModes(1),
508     current_mode(0),
509     modes(NULL)
510 {
511 }
512
513 mouse::~mouse ()
514 {
515   delete [] modes;
516 }
517
518 mouse_mode::mouse_mode ()
519   : cursor(FGMouseCursor::CURSOR_ARROW),
520     constrained(false),
521     pass_through(false),
522     buttons(NULL)
523 {
524 }
525
526 mouse_mode::~mouse_mode ()
527 {
528                                 // FIXME: memory leak
529 //   for (int i = 0; i < KEYMOD_MAX; i++) {
530 //     int j;
531 //     for (j = 0; i < x_bindings[i].size(); j++)
532 //       delete bindings[i][j];
533 //     for (j = 0; j < y_bindings[i].size(); j++)
534 //       delete bindings[i][j];
535 //   }
536   if (buttons) {
537     delete [] buttons;
538   }
539 }
540
541 void FGMouseInput::doMouseClick (int b, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea)
542 {
543   int modifiers = fgGetKeyModifiers();
544
545   mouse &m = d->mice[0];
546   mouse_mode &mode = m.modes[m.current_mode];
547                                 // Let the property manager know.
548   if (b >= 0 && b < MAX_MOUSE_BUTTONS)
549     m.mouse_button_nodes[b]->setBoolValue(updown == MOUSE_BUTTON_DOWN);
550
551   if (!d->rightClickModeCycle && (b == 2)) {
552     // in spring-loaded look mode, ignore right clicks entirely here
553     return;
554   }
555   
556   // Pass on to PUI and the panel if
557   // requested, and return if one of
558   // them consumes the event.
559
560   osg::Vec2d windowPos;
561   flightgear::eventToWindowCoords(ea, windowPos.x(), windowPos.y());
562
563   SGSceneryPicks pickList;
564   globals->get_renderer()->pick(pickList, windowPos);
565
566   if( updown != MOUSE_BUTTON_DOWN )
567   {
568     // Execute the mouse up event in any case, may be we should
569     // stop processing here?
570
571     SGPickCallbackList& callbacks = d->activePickCallbacks[b];
572
573     while( !callbacks.empty() )
574     {
575       SGPickCallbackPtr& cb = callbacks.front();
576       const SGSceneryPick* pick = getPick(pickList, cb);
577       cb->buttonReleased(ea->getModKeyMask(), *ea, pick ? &pick->info : 0);
578
579       callbacks.pop_front();
580     }
581   }
582
583   if (mode.pass_through) {
584     // remove once PUI uses standard picking mechanism
585     if (0 <= x && 0 <= y && puMouse(b, updown, x, y))
586       return; // pui handled it
587
588     // pui didn't want the click event so compute a
589     // scenegraph intersection point corresponding to the mouse click
590     if (updown == MOUSE_BUTTON_DOWN) {
591       d->activePickCallbacks.init( b, ea );
592         
593       if (d->clickTriggersTooltip) {
594             SGPropertyNode_ptr args(new SGPropertyNode);
595             args->setStringValue("reason", "click");
596             globals->get_commands()->execute("tooltip-timeout", args);
597             d->tooltipTimeoutDone = true;
598       }
599     } else {
600       // do a hover pick now, to fix up cursor
601       d->doHoverPick(windowPos);
602     } // mouse button was released
603   } // of pass-through mode
604
605   // OK, PUI and the panel didn't want the click
606   if (b >= MAX_MOUSE_BUTTONS) {
607     SG_LOG(SG_INPUT, SG_ALERT, "Mouse button " << b
608            << " where only " << MAX_MOUSE_BUTTONS << " expected");
609     return;
610   }
611
612   m.modes[m.current_mode].buttons[b].update( modifiers, 0 != updown, x, y);  
613 }
614
615 void FGMouseInput::processMotion(int x, int y, const osgGA::GUIEventAdapter* ea)
616 {
617   if (!d->activePickCallbacks[0].empty()) {
618     d->doMouseMoveWithCallbacks(ea);
619     return;
620   }
621   
622   mouse &m = d->mice[0];
623   int modeIndex = m.current_mode;
624   // are we in spring-loaded look mode?
625   if (!d->rightClickModeCycle) {
626     if (m.mouse_button_nodes[2]->getBoolValue()) {
627       // right mouse is down, force look mode
628       modeIndex = 3;
629     }
630   }
631
632   if (modeIndex == 0) {
633     osg::Vec2d windowPos;
634     flightgear::eventToWindowCoords(ea, windowPos.x(), windowPos.y());
635     d->scheduleHoverPick(windowPos);
636     // mouse has moved, so we may need to issue tooltip-timeout command again
637     d->tooltipTimeoutDone = false;
638   }
639   
640   mouse_mode &mode = m.modes[modeIndex];
641   
642   // Pass on to PUI if requested, and return
643   // if PUI consumed the event.
644   if (mode.pass_through && puMouse(x, y)) {
645     return;
646   }
647
648   if (d->haveWarped)
649   {
650     // don't fire mouse-movement events at the first update after warping the mouse,
651     // just remember the new mouse position
652     d->haveWarped = false;
653   }
654   else
655   {
656     int modifiers = fgGetKeyModifiers();
657     int xsize = d->xSizeNode ? d->xSizeNode->getIntValue() : 800;
658     int ysize = d->ySizeNode ? d->ySizeNode->getIntValue() : 600;
659       
660     // OK, PUI didn't want the event,
661     // so we can play with it.
662     if (x != m.x) {
663       int delta = x - m.x;
664       d->xAccelNode->setIntValue( delta );
665       for (unsigned int i = 0; i < mode.x_bindings[modifiers].size(); i++)
666         mode.x_bindings[modifiers][i]->fire(double(delta), double(xsize));
667     }
668     if (y != m.y) {
669       int delta = y - m.y;
670       d->yAccelNode->setIntValue( -delta );
671       for (unsigned int i = 0; i < mode.y_bindings[modifiers].size(); i++)
672         mode.y_bindings[modifiers][i]->fire(double(delta), double(ysize));
673     }
674   }
675   
676   // Constrain the mouse if requested
677   if (mode.constrained) {
678     d->constrainMouse(x, y);
679   }
680 }
681
682 void FGMouseInput::doMouseMotion (int x, int y, const osgGA::GUIEventAdapter* ea)
683 {
684   mouse &m = d->mice[0];
685
686   if (m.current_mode < 0 || m.current_mode >= m.nModes) {
687       m.x = x;
688       m.y = y;
689       return;
690   }
691
692   m.timeSinceLastMove.stamp();
693   FGMouseCursor::instance()->mouseMoved();
694
695   // TODO Get rid of this as soon as soon as cursor hide timeout works globally
696   if( ea->getHandled() )
697     return;
698
699   processMotion(x, y, ea);
700     
701   m.x = x;
702   m.y = y;
703   d->mouseXNode->setIntValue(x);
704   d->mouseYNode->setIntValue(y);
705 }
706
707
708