From: James Turner Date: Sun, 15 Apr 2012 12:21:12 +0000 (+0100) Subject: Make 2D panel mouse action repeat independent of the frame-rate. X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=91f2d0798a772eda1663adb73262ea0991ca6682;p=flightgear.git Make 2D panel mouse action repeat independent of the frame-rate. --- diff --git a/src/Cockpit/panel.cxx b/src/Cockpit/panel.cxx index ff13176e2..0eb1f96f2 100644 --- a/src/Cockpit/panel.cxx +++ b/src/Cockpit/panel.cxx @@ -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; diff --git a/src/Cockpit/panel.hxx b/src/Cockpit/panel.hxx index 361c43984..6be50754b 100644 --- a/src/Cockpit/panel.hxx +++ b/src/Cockpit/panel.hxx @@ -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 instrument_list_type; int _width; diff --git a/src/Model/panelnode.cxx b/src/Model/panelnode.cxx index 6657d2f75..150b2ef40 100644 --- a/src/Model/panelnode.cxx +++ b/src/Model/panelnode.cxx @@ -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)