]> git.mxchange.org Git - flightgear.git/commitdiff
Make 2D panel mouse action repeat independent of the frame-rate.
authorJames Turner <zakalawe@mac.com>
Sun, 15 Apr 2012 12:21:12 +0000 (13:21 +0100)
committerJames Turner <zakalawe@mac.com>
Sun, 15 Apr 2012 12:21:12 +0000 (13:21 +0100)
src/Cockpit/panel.cxx
src/Cockpit/panel.hxx
src/Model/panelnode.cxx

index ff13176e2fa88db2e3035541a5c385e2352cc24b..0eb1f96f2013cd4d295221b193aaae063dd6c866 100644 (file)
@@ -73,6 +73,9 @@
 // my hardware/driver requires many more.
 #define POFF_UNITS 8
 
+const double MOUSE_ACTION_REPEAT_DELAY = 0.5; // 500msec initial delay
+const double MOUSE_ACTION_REPEAT_INTERVAL = 0.1; // 10Hz repeat rate
+
 using std::map;
 
 ////////////////////////////////////////////////////////////////////////
@@ -268,9 +271,9 @@ FGPanel::unbind ()
 
 
 void
-FGPanel::update (double /* dt */)
+FGPanel::update (double dt)
 {
-  updateMouseDelay();
+  updateMouseDelay(dt);
 }
 
 double
@@ -293,15 +296,18 @@ FGPanel::getAspectScale() const
  * fgUpdate3DPanels().  This functionality needs to move into the
  * input subsystem.  Counting a tick every two frames is clumsy...
  */
-void FGPanel::updateMouseDelay()
-{
-    if (_mouseDown) {
-        _mouseDelay--;
-        if (_mouseDelay < 0) {
-            _mouseInstrument->doMouseAction(_mouseButton, 0, _mouseX, _mouseY);
-            _mouseDelay = 2;
-        }
-    }
+void FGPanel::updateMouseDelay(double dt)
+{
+  if (!_mouseDown) {
+    return;
+  }
+
+  _mouseActionRepeat -= dt;
+  while (_mouseActionRepeat < 0.0) {
+    _mouseActionRepeat += MOUSE_ACTION_REPEAT_INTERVAL;
+    _mouseInstrument->doMouseAction(_mouseButton, 0, _mouseX, _mouseY);
+    
+  }
 }
 
 void
@@ -595,7 +601,7 @@ FGPanel::doLocalMouseAction(int button, int updown, int x, int y)
     int ih = inst->getHeight() / 2;
     if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) {
       _mouseDown = true;
-      _mouseDelay = 20;
+      _mouseActionRepeat = MOUSE_ACTION_REPEAT_DELAY;
       _mouseInstrument = inst;
       _mouseButton = button;
       _mouseX = x - ix;
index 361c43984f3e6fa485872097893adffe1ea8b8f7..6be50754b77935ac34bbeaf2244a7e29c7a44336 100644 (file)
@@ -135,7 +135,7 @@ public:
   //void update (osg::State& state);
   //virtual void update (osg::State& state, GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh);
 
-  virtual void updateMouseDelay();
+  virtual void updateMouseDelay(double dt);
 
                                // transfer pointer ownership!!!
   virtual void addInstrument (FGPanelInstrument * instrument);
@@ -193,7 +193,8 @@ private:
 
   mutable bool _mouseDown;
   mutable int _mouseButton, _mouseX, _mouseY;
-  mutable int _mouseDelay;
+  double _mouseActionRepeat;
+    
   mutable FGPanelInstrument * _mouseInstrument;
   typedef std::vector<FGPanelInstrument *> instrument_list_type;
   int _width;
index 6657d2f7513f4dfaaf412dbb5bd9644aac9c8047..150b2ef40654f505bbfe1a12a9d36aabf547fc1f 100644 (file)
@@ -44,9 +44,9 @@ public:
                                           picked.x(), picked.y());
   }
   
-  virtual void update(double /* dt */)
+  virtual void update(double dt)
   {
-    panel->getPanel()->updateMouseDelay();
+    panel->getPanel()->updateMouseDelay(dt);
   }
   
   virtual void buttonReleased(void)