]> git.mxchange.org Git - flightgear.git/blobdiff - src/Input/input.cxx
Don't restore initial screen geometry because there is nothing in fg_os* to resize...
[flightgear.git] / src / Input / input.cxx
index 76c9a2d1958c1e8a9e6795a4ff2adbf23efa39b4..be5d83071db9176adb0394c18a2eed6e33098be2 100644 (file)
@@ -16,7 +16,7 @@
 //
 // 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., 675 Mass Ave, Cambridge, MA 02139, USA.
+// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 //
 // $Id$
 
 
 #include "input.hxx"
 
+#include <Scenery/scenery.hxx>
+#include <Main/renderer.hxx>
+#include <plib/ssg.h>
+#include <simgear/math/sg_geodesy.hxx>
+
 SG_USING_STD(ifstream);
 SG_USING_STD(string);
 SG_USING_STD(vector);
@@ -95,7 +100,7 @@ FGBinding::FGBinding (const SGPropertyNode * node)
 
 FGBinding::~FGBinding ()
 {
-  _arg->getParent()->removeChild(_arg->getName(), _arg->getIndex());
+  _arg->getParent()->removeChild(_arg->getName(), _arg->getIndex(), false);
 }
 
 void
@@ -263,6 +268,23 @@ FGInput::doKey (int k, int modifiers, int x, int y)
       for (unsigned int i = 0; i < bindings.size(); i++)
         bindings[i]->fire();
       b.last_state = 0;
+    } else {
+      if (k >= 1 && k <= 26) {
+        if (_key_bindings[k + '@'].last_state)
+          doKey(k + '@', KEYMOD_RELEASED, x, y);
+        if (_key_bindings[k + '`'].last_state)
+          doKey(k + '`', KEYMOD_RELEASED, x, y);
+      } else if (k >= 'A' && k <= 'Z') {
+        if (_key_bindings[k - '@'].last_state)
+          doKey(k - '@', KEYMOD_RELEASED, x, y);
+        if (_key_bindings[tolower(k)].last_state)
+          doKey(tolower(k), KEYMOD_RELEASED, x, y);
+      } else if (k >= 'a' && k <= 'z') {
+        if (_key_bindings[k - '`'].last_state)
+          doKey(k - '`', KEYMOD_RELEASED, x, y);
+        if (_key_bindings[toupper(k)].last_state)
+          doKey(toupper(k), KEYMOD_RELEASED, x, y);
+      }
     }
   }
 }
@@ -291,6 +313,26 @@ FGInput::doMouseClick (int b, int updown, int x, int y)
       return;
     else if (fgHandle3DPanelMouseEvent(b, updown, x, y))
       return;
+    else {
+      // pui and the panel didn't want the click event so compute a
+      // terrain intersection point corresponding to the mouse click
+      // and be happy.
+      FGScenery* scenery = globals->get_scenery();
+      sgdVec3 start, dir, hit;
+      if (!b && updown == MOUSE_BUTTON_DOWN && FGRenderer::getPickInfo(start, dir, x, y)
+          && scenery->get_cart_ground_intersection(start, dir, hit)) {
+
+        Point3D geod = sgCartToGeod(Point3D(hit[0], hit[1], hit[2]));
+
+        SGPropertyNode *c = fgGetNode("/sim/input/click", true);
+        c->setDoubleValue("longitude-deg", geod.lon() * SGD_RADIANS_TO_DEGREES);
+        c->setDoubleValue("latitude-deg", geod.lat() * SGD_RADIANS_TO_DEGREES);
+        c->setDoubleValue("elevation-m", geod.elev());
+        c->setDoubleValue("elevation-ft", geod.elev() * SG_METER_TO_FEET);
+
+        fgSetBool("/sim/signals/click", 1);
+      }
+    }
   }
 
                                 // OK, PUI and the panel didn't want the click
@@ -347,19 +389,13 @@ FGInput::doMouseMotion (int x, int y)
                                 // Constrain the mouse if requested
   if (mode.constrained) {
     bool need_warp = false;
-    if (x <= 0) {
-      x = xsize - 2;
-      need_warp = true;
-    } else if (x >= (xsize-1)) {
-      x = 1;
+    if (x <= (xsize * .25) || x >= (xsize * .75)) {
+      x = int(xsize * .5);
       need_warp = true;
     }
 
-    if (y <= 0) {
-      y = ysize - 2;
-      need_warp = true;
-    } else if (y >= (ysize-1)) {
-      y = 1;
+    if (y <= (ysize * .25) || y >= (ysize * .75)) {
+      y = int(ysize * .5);
       need_warp = true;
     }
 
@@ -484,6 +520,9 @@ FGInput::_init_joystick ()
       js_node->setStringValue("id", name);
     }
   }
+
+  // get rid of unused config nodes
+  js_nodes->removeChildren("js-named", false);
 }
 
 
@@ -492,7 +531,6 @@ FGInput::_postinit_joystick()
 {
   FGNasalSys *nasalsys = (FGNasalSys *)globals->get_subsystem("nasal");
   SGPropertyNode *js_nodes = fgGetNode("/input/joysticks");
-  js_nodes->removeChildren("js-named");
 
   for (int i = 0; i < MAX_JOYSTICKS; i++) {
     SGPropertyNode_ptr js_node = js_nodes->getChild("js", i);
@@ -954,7 +992,9 @@ FGInput::_find_key_bindings (unsigned int k, int modifiers)
 
 FGInput::button::button ()
   : is_repeatable(false),
-    last_state(-1)
+    interval_sec(0),
+    last_dt(0),
+    last_state(0)
 {
 }
 
@@ -976,7 +1016,9 @@ FGInput::axis::axis ()
   : last_value(9999999),
     tolerance(0.002),
     low_threshold(-0.9),
-    high_threshold(0.9)
+    high_threshold(0.9),
+    interval_sec(0),
+    last_dt(0)
 {
 }
 
@@ -994,6 +1036,12 @@ FGInput::axis::~axis ()
 ////////////////////////////////////////////////////////////////////////
 
 FGInput::joystick::joystick ()
+  : jsnum(0),
+    js(0),
+    naxes(0),
+    nbuttons(0),
+    axes(0),
+    buttons(0)
 {
 }