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.
#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()
void FGPanel::updateMouseDelay(double dt)
{
if (_mouseDown) {
_mouseDelay--;
if (_mouseDelay < 0) {
_mouseInstrument->doMouseAction(_mouseButton, 0, _mouseX, _mouseY);
_mouseDelay = 2;
}
}
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;

View 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;

View 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)