]> git.mxchange.org Git - flightgear.git/commitdiff
Fix for issue #999
authorPhilosopher <NasalMusician@gmail.com>
Fri, 16 Aug 2013 02:05:16 +0000 (21:05 -0500)
committerClément de l'Hamaide <clemaez@hotmail.fr>
Tue, 4 Mar 2014 23:33:45 +0000 (00:33 +0100)
Introduces delay-sec and release-delay-sec properties. The former is how
long to wait to run the binding(s) after pressing the button, the latter
is how long to wait after releasing the button. interval-sec now
specifies the delay before a repeat event occurs.

src/Input/FGButton.cxx
src/Input/FGButton.hxx
src/Input/FGJoystickInput.cxx
src/Input/FGJoystickInput.hxx

index 315b4d3e9aaba9927780813d0ec29a8fa4804945..400de289e8f805bfd6d2942e1d67a8c425aed5a9 100644 (file)
@@ -32,6 +32,8 @@
 FGButton::FGButton ()
   : is_repeatable(false),
     interval_sec(0),
+    delay_sec(0),
+    release_delay_sec(0),
     last_dt(0),
     last_state(0)
 {
index 80c9eed6d2b7ae5faed45b881ac32a0d8ea5968d..497be1c460dedbd3f9a5d544bab62b96ed99022f 100644 (file)
@@ -35,7 +35,7 @@ public:
   void init( const SGPropertyNode * node, const std::string & name, std::string & module );
   void update( int modifiers, bool pressed, int x = -1, int y = -1);
   bool is_repeatable;
-  float interval_sec;
+  float interval_sec, delay_sec, release_delay_sec;
   float last_dt;
   int last_state;
   binding_list_t bindings[KEYMOD_MAX];
index b15649cda3b334589e90c4b84495d68ea80e9fbd..4cbeb1ae16817490c5347633adc03dd5669f6b70 100644 (file)
@@ -42,6 +42,8 @@ FGJoystickInput::axis::axis ()
     low_threshold(-0.9),
     high_threshold(0.9),
     interval_sec(0),
+    delay_sec(0),
+    release_delay_sec(0),
     last_dt(0)
 {
 }
@@ -264,6 +266,8 @@ void FGJoystickInput::postinit()
       a.high.init(axis_node->getChild("high"), "high", module );
       a.high_threshold = axis_node->getDoubleValue("high-threshold", 0.9);
       a.interval_sec = axis_node->getDoubleValue("interval-sec",0.0);
+      a.delay_sec = axis_node->getDoubleValue("delay-sec",0.0);
+      a.release_delay_sec = axis_node->getDoubleValue("release-delay-sec",0.0);
       a.last_dt = 0.0;
     }
 
@@ -291,6 +295,8 @@ void FGJoystickInput::postinit()
       b.init(button_node, buf.str(), module );
       // get interval-sec property
       b.interval_sec = button_node->getDoubleValue("interval-sec",0.0);
+      b.delay_sec = button_node->getDoubleValue("delay-sec",0.0);
+      b.release_delay_sec = button_node->getDoubleValue("release-delay-sec",0.0);
       b.last_dt = 0.0;
     }
 
@@ -305,6 +311,8 @@ void FGJoystickInput::updateJoystick(int index, FGJoystickInput::joystick* joy,
   float axis_values[MAX_JOYSTICK_AXES];
   int modifiers = fgGetKeyModifiers();
   int buttons;
+  bool pressed, last_state;
+  float delay;
   
   jsJoystick * js = joy->plibJS.get();
   if (js == 0 || js->notWorking())
@@ -340,25 +348,33 @@ void FGJoystickInput::updateJoystick(int index, FGJoystickInput::joystick* joy,
     }
     
     // do we have to emulate axis buttons?
-    a.last_dt += dt;
-    if(a.last_dt >= a.interval_sec) {
+    last_state = joy->axes[j].low.last_state || joy->axes[j].high.last_state;
+    pressed = axis_values[j] < a.low_threshold || axis_values[j] > a.high_threshold;
+    delay = (pressed ? last_state ? a.interval_sec : a.delay_sec : a.release_delay_sec );
+    if(pressed || last_state) a.last_dt += dt;
+    else a.last_dt = 0;
+    if(a.last_dt >= delay) {
       if (a.low.bindings[modifiers].size())
         joy->axes[j].low.update( modifiers, axis_values[j] < a.low_threshold );
       
       if (a.high.bindings[modifiers].size())
         joy->axes[j].high.update( modifiers, axis_values[j] > a.high_threshold );
       
-      a.last_dt -= a.interval_sec;
+      a.last_dt -= delay;
     }
   } // of axes iteration
   
   // Fire bindings for the buttons.
   for (int j = 0; j < joy->nbuttons; j++) {
     FGButton &b = joy->buttons[j];
-    b.last_dt += dt;
-    if(b.last_dt >= b.interval_sec) {
-      joy->buttons[j].update( modifiers, (buttons & (1u << j)) > 0 );
-      b.last_dt -= b.interval_sec;
+    pressed = (buttons & (1u << j)) > 0;
+    last_state = joy->buttons[j].last_state;
+    delay = (pressed ? last_state ? b.interval_sec : b.delay_sec : b.release_delay_sec );
+    if(pressed || last_state) b.last_dt += dt;
+    else b.last_dt = 0;
+    if(b.last_dt >= delay) {
+      joy->buttons[j].update( modifiers, pressed );
+      b.last_dt -= delay;
     }
   } // of butotns iterations
 
index 89a9c9f20f77bcf3bbf90e0e55f18ef8eb0c0072..b161da9a3dc9d1c3521d9dbb7ff65cb00a6e9a3f 100644 (file)
@@ -68,7 +68,7 @@ private:
     float high_threshold;
     FGButton low;
     FGButton high;
-    float interval_sec;
+    float interval_sec, delay_sec, release_delay_sec;
     double last_dt;
   };