1
0
Fork 0

Make 2D panel mouse action repeat independent of the frame-rate.

This commit is contained in:
James Turner 2012-04-15 13:21:12 +01:00
parent 96ee2b1577
commit 91f2d0798a
3 changed files with 22 additions and 15 deletions

View file

@ -73,6 +73,9 @@
// my hardware/driver requires many more. // my hardware/driver requires many more.
#define POFF_UNITS 8 #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; using std::map;
//////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////
@ -268,9 +271,9 @@ FGPanel::unbind ()
void void
FGPanel::update (double /* dt */) FGPanel::update (double dt)
{ {
updateMouseDelay(); updateMouseDelay(dt);
} }
double double
@ -293,14 +296,17 @@ FGPanel::getAspectScale() const
* fgUpdate3DPanels(). This functionality needs to move into the * fgUpdate3DPanels(). This functionality needs to move into the
* input subsystem. Counting a tick every two frames is clumsy... * input subsystem. Counting a tick every two frames is clumsy...
*/ */
void FGPanel::updateMouseDelay() void FGPanel::updateMouseDelay(double dt)
{ {
if (_mouseDown) { if (!_mouseDown) {
_mouseDelay--; return;
if (_mouseDelay < 0) {
_mouseInstrument->doMouseAction(_mouseButton, 0, _mouseX, _mouseY);
_mouseDelay = 2;
} }
_mouseActionRepeat -= dt;
while (_mouseActionRepeat < 0.0) {
_mouseActionRepeat += MOUSE_ACTION_REPEAT_INTERVAL;
_mouseInstrument->doMouseAction(_mouseButton, 0, _mouseX, _mouseY);
} }
} }
@ -595,7 +601,7 @@ FGPanel::doLocalMouseAction(int button, int updown, int x, int y)
int ih = inst->getHeight() / 2; int ih = inst->getHeight() / 2;
if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) { if (x >= ix - iw && x < ix + iw && y >= iy - ih && y < iy + ih) {
_mouseDown = true; _mouseDown = true;
_mouseDelay = 20; _mouseActionRepeat = MOUSE_ACTION_REPEAT_DELAY;
_mouseInstrument = inst; _mouseInstrument = inst;
_mouseButton = button; _mouseButton = button;
_mouseX = x - ix; _mouseX = x - ix;

View file

@ -135,7 +135,7 @@ public:
//void update (osg::State& state); //void update (osg::State& state);
//virtual void update (osg::State& state, GLfloat winx, GLfloat winw, GLfloat winy, GLfloat winh); //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!!! // transfer pointer ownership!!!
virtual void addInstrument (FGPanelInstrument * instrument); virtual void addInstrument (FGPanelInstrument * instrument);
@ -193,7 +193,8 @@ private:
mutable bool _mouseDown; mutable bool _mouseDown;
mutable int _mouseButton, _mouseX, _mouseY; mutable int _mouseButton, _mouseX, _mouseY;
mutable int _mouseDelay; double _mouseActionRepeat;
mutable FGPanelInstrument * _mouseInstrument; mutable FGPanelInstrument * _mouseInstrument;
typedef std::vector<FGPanelInstrument *> instrument_list_type; typedef std::vector<FGPanelInstrument *> instrument_list_type;
int _width; int _width;

View file

@ -44,9 +44,9 @@ public:
picked.x(), picked.y()); 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) virtual void buttonReleased(void)