]> git.mxchange.org Git - flightgear.git/commitdiff
- Track a saved mouse pointer location from the previous frame so we can detect
authorcurt <curt>
Mon, 14 Jun 2004 18:46:58 +0000 (18:46 +0000)
committercurt <curt>
Mon, 14 Jun 2004 18:46:58 +0000 (18:46 +0000)
  motion.

- Track a timeout value so we can optionally hide the mouse pointer after
  some user specified timeout period.

- in doMouseMotion() always update m.x and m.y even if we return early because
  pui wanted the event.  Without this, we can't reliably detect motion vs.
  inactivity.

- in _update_mouse() add a dt parameter so we can decriment the timeout value
  in "real" time.

- in _update_mouse() optionally hide the mouse pointer if m.timeout goes to
  zero.  Restore the pointer (and the timeout counter) if the mouse is moved.

src/Input/input.cxx
src/Input/input.hxx

index 0c5ce80fb07bdd8271690fef966f44369be4e841..dea8995c52eb7a5c818b1469c126bdc7aa96edb9 100644 (file)
@@ -184,7 +184,7 @@ FGInput::update (double dt)
 {
   _update_keyboard();
   _update_joystick(dt);
-  _update_mouse();
+  _update_mouse(dt);
 }
 
 void
@@ -303,15 +303,23 @@ FGInput::doMouseMotion (int x, int y)
 
   int xsize = fgGetInt("/sim/startup/xsize", 800);
   int ysize = fgGetInt("/sim/startup/ysize", 600);
+
   mouse &m = _mouse_bindings[0];
-  if (m.current_mode < 0 || m.current_mode >= m.nModes)
-    return;
+
+  if (m.current_mode < 0 || m.current_mode >= m.nModes) {
+      m.x = x;
+      m.y = y;
+      return;
+  }
   mouse_mode &mode = m.modes[m.current_mode];
 
                                 // Pass on to PUI if requested, and return
                                 // if PUI consumed the event.
-  if (mode.pass_through && puMouse(x, y))
-    return;
+  if (mode.pass_through && puMouse(x, y)) {
+      m.x = x;
+      m.y = y;
+      return;
+  }
 
                                 // OK, PUI didn't want the event,
                                 // so we can play with it.
@@ -709,12 +717,13 @@ FGInput::_update_joystick (double dt)
 }
 
 void
-FGInput::_update_mouse ()
+FGInput::_update_mouse ( double dt )
 {
   mouse &m = _mouse_bindings[0];
   int mode =  m.mode_node->getIntValue();
   if (mode != m.current_mode) {
     m.current_mode = mode;
+    m.timeout = fgGetDouble( "/sim/mouse/cursor-timeout-sec", 10.0 );
     if (mode >= 0 && mode < m.nModes) {
       fgSetMouseCursor(m.modes[mode].cursor);
       m.x = fgGetInt("/sim/startup/xsize", 800) / 2;
@@ -725,6 +734,21 @@ FGInput::_update_mouse ()
       fgSetMouseCursor(MOUSE_CURSOR_POINTER);
     }
   }
+
+  if ( fgGetBool( "/sim/mouse/hide-cursor", true ) ) {
+      if ( m.x != m.save_x || m.y != m.save_y ) {
+          m.timeout = fgGetDouble( "/sim/mouse/cursor-timeout-sec", 10.0 );
+          fgSetMouseCursor(m.modes[mode].cursor);
+      } else {
+          m.timeout -= dt;
+          if ( m.timeout <= 0.0 ) {
+              fgSetMouseCursor(MOUSE_CURSOR_NONE);
+              m.timeout = 0.0;
+          }
+      }
+      m.save_x = m.x;
+      m.save_y = m.y;
+  }
 }
 
 void
index ac59a66278f6148edf651dcb2255fac7a5b145aa..755b6d66fd74c8a74f32edaaf190eb39982733a3 100644 (file)
@@ -339,6 +339,9 @@ private:
     SGPropertyNode * mouse_button_nodes[MAX_MOUSE_BUTTONS];
     int nModes;
     int current_mode;
+    double timeout;
+    int save_x;
+    int save_y;
     mouse_mode * modes;
   };
 
@@ -384,7 +387,7 @@ private:
   /**
    * Update the mouse.
    */
-  void _update_mouse ();
+  void _update_mouse (double dt);
 
 
   /**