]> git.mxchange.org Git - flightgear.git/blobdiff - src/Input/FGMouseInput.cxx
Merge branch 'next' of gitorious.org:fg/flightgear into next
[flightgear.git] / src / Input / FGMouseInput.cxx
index b171e021bdac308185d4b1b4c7f8e0e8a4549b23..927106f47c490543a4fa6425af1ca8318b931c0a 100644 (file)
 //
 // $Id$
 
+#ifdef HAVE_CONFIG_H
+#  include "config.h"
+#endif
+
 #include "FGMouseInput.hxx"
+#include "Main/globals.hxx"
+
+using std::ios_base;
 
-\f
 void ActivePickCallbacks::init( int b, const osgGA::GUIEventAdapter* ea )
 {
   // Get the list of hit callbacks. Take the first callback that
@@ -33,7 +39,7 @@ void ActivePickCallbacks::init( int b, const osgGA::GUIEventAdapter* ea )
   // The nearest one is the first one and the deepest
   // (the most specialized one in the scenegraph) is the first.
   std::vector<SGSceneryPick> pickList;
-  if (FGRenderer::pick(pickList, ea)) {
+  if (globals->get_renderer()->pick(pickList, ea)) {
     std::vector<SGSceneryPick>::const_iterator i;
     for (i = pickList.begin(); i != pickList.end(); ++i) {
       if (i->callback->buttonPressed(b, i->info)) {
@@ -75,6 +81,7 @@ const FGMouseInput::MouseCursorMap FGMouseInput::mouse_cursor_map[] = {
 FGMouseInput * FGMouseInput::mouseInput = NULL;
 
 FGMouseInput::FGMouseInput() :
+  haveWarped(false),
   xSizeNode(fgGetNode("/sim/startup/xsize", false ) ),
   ySizeNode(fgGetNode("/sim/startup/ysize", false ) ),
   xAccelNode(fgGetNode("/devices/status/mice/mouse/accel-x", true ) ),
@@ -117,7 +124,7 @@ void FGMouseInput::init()
       m.mode_node->setIntValue(0);
     }
     for (j = 0; j < MAX_MOUSE_BUTTONS; j++) {
-      buf.clear();
+      buf.seekp(ios_base::beg);
       buf << "/devices/status/mice/mouse["<< i << "]/button[" << j << "]";
       m.mouse_button_nodes[j] = fgGetNode(buf.str().c_str(), true);
       m.mouse_button_nodes[j]->setBoolValue(false);
@@ -150,7 +157,7 @@ void FGMouseInput::init()
       m.modes[j].buttons = new FGButton[MAX_MOUSE_BUTTONS];
       std::ostringstream buf;
       for (k = 0; k < MAX_MOUSE_BUTTONS; k++) {
-        buf.clear();
+        buf.seekp(ios_base::beg);
         buf << "mouse button " << k;
         SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse button " << k);
         m.modes[j].buttons[k].init( mode_node->getChild("button", k), buf.str(), module );
@@ -180,6 +187,7 @@ void FGMouseInput::update ( double dt )
       m.x = (xSizeNode ? xSizeNode->getIntValue() : 800) / 2;
       m.y = (ySizeNode ? ySizeNode->getIntValue() : 600) / 2;
       fgWarpMouse(m.x, m.y);
+      haveWarped = true;
     } else {
       SG_LOG(SG_INPUT, SG_DEBUG, "Mouse mode " << mode << " out of range");
       fgSetMouseCursor(MOUSE_CURSOR_POINTER);
@@ -321,37 +329,51 @@ void FGMouseInput::doMouseMotion (int x, int y)
       m.y = y;
       return;
   }
-
+  
+  if (haveWarped)
+  {
+      // don't fire mouse-movement events at the first update after warping the mouse,
+      // just remember the new mouse position
+      haveWarped = false;
+  }
+  else
+  {
                                 // OK, PUI didn't want the event,
                                 // so we can play with it.
-  if (x != m.x) {
-    int delta = x - m.x;
-    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;
-    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));
+      if (x != m.x) {
+        int delta = x - m.x;
+        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;
+        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));
+      }
   }
-
                                 // 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)) {
-      x = int(xsize * .5);
+      new_x = int(xsize * .5);
       need_warp = true;
     }
 
     if (y <= (ysize * .25) || y >= (ysize * .75)) {
-      y = int(ysize * .5);
+      new_y = int(ysize * .5);
       need_warp = true;
     }
 
     if (need_warp)
-      fgWarpMouse(x, y);
+    {
+      fgWarpMouse(new_x, new_y);
+      haveWarped = true;
+      SG_LOG(SG_INPUT, SG_DEBUG, "Mouse warp: " << x << ", " << y << " => " << new_x << ", " << new_y);
+    }
   }
 
   if (m.x != x)