GUI: Change scrollbar repeat handling from a timer proc to handleTickle.
This should be less heavy on timer usage and makes sure no race conditions
will occur.
(cherry picked from commit 7f2b2e99f8
)
This commit is contained in:
parent
29dd6df611
commit
58c4b4870e
4 changed files with 26 additions and 41 deletions
|
@ -245,6 +245,8 @@ void ConsoleDialog::handleTickle() {
|
||||||
} else
|
} else
|
||||||
draw();
|
draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
_scrollBar->handleTickle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConsoleDialog::handleMouseWheel(int x, int y, int direction) {
|
void ConsoleDialog::handleMouseWheel(int x, int y, int direction) {
|
||||||
|
|
|
@ -220,6 +220,7 @@ void ListWidget::scrollBarRecalc() {
|
||||||
void ListWidget::handleTickle() {
|
void ListWidget::handleTickle() {
|
||||||
if (_editMode)
|
if (_editMode)
|
||||||
EditableWidget::handleTickle();
|
EditableWidget::handleTickle();
|
||||||
|
_scrollBar->handleTickle();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ListWidget::handleMouseDown(int x, int y, int button, int clickCount) {
|
void ListWidget::handleMouseDown(int x, int y, int button, int clickCount) {
|
||||||
|
|
|
@ -45,28 +45,8 @@ ScrollBarWidget::ScrollBarWidget(GuiObject *boss, int x, int y, int w, int h)
|
||||||
_numEntries = 0;
|
_numEntries = 0;
|
||||||
_entriesPerPage = 0;
|
_entriesPerPage = 0;
|
||||||
_currentPos = 0;
|
_currentPos = 0;
|
||||||
}
|
|
||||||
|
|
||||||
static void upArrowRepeater(void *ref) {
|
_repeatTimer = 0;
|
||||||
ScrollBarWidget *sb = (ScrollBarWidget *)ref;
|
|
||||||
int old_pos = sb->_currentPos;
|
|
||||||
|
|
||||||
sb->_currentPos -= 3;
|
|
||||||
sb->checkBounds(old_pos);
|
|
||||||
|
|
||||||
g_system->getTimerManager()->removeTimerProc(&upArrowRepeater);
|
|
||||||
g_system->getTimerManager()->installTimerProc(&upArrowRepeater, 1000000/10, ref, "guiScrollBarUp");
|
|
||||||
}
|
|
||||||
|
|
||||||
static void downArrowRepeater(void *ref) {
|
|
||||||
ScrollBarWidget *sb = (ScrollBarWidget *)ref;
|
|
||||||
int old_pos = sb->_currentPos;
|
|
||||||
|
|
||||||
sb->_currentPos += 3;
|
|
||||||
sb->checkBounds(old_pos);
|
|
||||||
|
|
||||||
g_system->getTimerManager()->removeTimerProc(&downArrowRepeater);
|
|
||||||
g_system->getTimerManager()->installTimerProc(&downArrowRepeater, 1000000/10, ref, "guiScrollBarDown");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollBarWidget::handleMouseDown(int x, int y, int button, int clickCount) {
|
void ScrollBarWidget::handleMouseDown(int x, int y, int button, int clickCount) {
|
||||||
|
@ -79,13 +59,13 @@ void ScrollBarWidget::handleMouseDown(int x, int y, int button, int clickCount)
|
||||||
if (y <= UP_DOWN_BOX_HEIGHT) {
|
if (y <= UP_DOWN_BOX_HEIGHT) {
|
||||||
// Up arrow
|
// Up arrow
|
||||||
_currentPos--;
|
_currentPos--;
|
||||||
|
_repeatTimer = g_system->getMillis() + kRepeatInitialDelay;
|
||||||
_draggingPart = kUpArrowPart;
|
_draggingPart = kUpArrowPart;
|
||||||
g_system->getTimerManager()->installTimerProc(&upArrowRepeater, 1000000/2, this, "guiScrollBarUp");
|
|
||||||
} else if (y >= _h - UP_DOWN_BOX_HEIGHT) {
|
} else if (y >= _h - UP_DOWN_BOX_HEIGHT) {
|
||||||
// Down arrow
|
// Down arrow
|
||||||
_currentPos++;
|
_currentPos++;
|
||||||
|
_repeatTimer = g_system->getMillis() + kRepeatInitialDelay;
|
||||||
_draggingPart = kDownArrowPart;
|
_draggingPart = kDownArrowPart;
|
||||||
g_system->getTimerManager()->installTimerProc(&downArrowRepeater, 1000000/2, this, "guiScrollBarDown");
|
|
||||||
} else if (y < _sliderPos) {
|
} else if (y < _sliderPos) {
|
||||||
_currentPos -= _entriesPerPage - 1;
|
_currentPos -= _entriesPerPage - 1;
|
||||||
} else if (y >= _sliderPos + _sliderHeight) {
|
} else if (y >= _sliderPos + _sliderHeight) {
|
||||||
|
@ -101,9 +81,7 @@ void ScrollBarWidget::handleMouseDown(int x, int y, int button, int clickCount)
|
||||||
|
|
||||||
void ScrollBarWidget::handleMouseUp(int x, int y, int button, int clickCount) {
|
void ScrollBarWidget::handleMouseUp(int x, int y, int button, int clickCount) {
|
||||||
_draggingPart = kNoPart;
|
_draggingPart = kNoPart;
|
||||||
|
_repeatTimer = 0;
|
||||||
g_system->getTimerManager()->removeTimerProc(&upArrowRepeater);
|
|
||||||
g_system->getTimerManager()->removeTimerProc(&downArrowRepeater);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollBarWidget::handleMouseWheel(int x, int y, int direction) {
|
void ScrollBarWidget::handleMouseWheel(int x, int y, int direction) {
|
||||||
|
@ -160,23 +138,21 @@ void ScrollBarWidget::handleMouseMoved(int x, int y, int button) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollBarWidget::handleTickle() {
|
void ScrollBarWidget::handleTickle() {
|
||||||
/*
|
if (_repeatTimer) {
|
||||||
// FIXME/TODO - this code is supposed to allow for "click-repeat" (like key repeat),
|
const uint32 curTime = g_system->getMillis();
|
||||||
// i.e. if you click on one of the arrows and keep clicked, it will scroll
|
if (curTime >= _repeatTimer) {
|
||||||
// continuously. However, just like key repeat, this requires two delays:
|
const int old_pos = _currentPos;
|
||||||
// First an "initial" delay that has to pass before repeating starts (otherwise
|
|
||||||
// it is near to impossible to achieve single clicks). Secondly, a repeat delay
|
|
||||||
// that determines how often per second a click is simulated.
|
|
||||||
int old_pos = _currentPos;
|
|
||||||
|
|
||||||
if (_draggingPart == kUpArrowPart)
|
if (_part == kUpArrowPart)
|
||||||
_currentPos--;
|
_currentPos -= 3;
|
||||||
else if (_draggingPart == kDownArrowPart)
|
else if (_part == kDownArrowPart)
|
||||||
_currentPos++;
|
_currentPos += 3;
|
||||||
|
|
||||||
// Make sure that _currentPos is still inside the bounds
|
checkBounds(old_pos);
|
||||||
checkBounds(old_pos);
|
|
||||||
*/
|
_repeatTimer = curTime + kRepeatDelay;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ScrollBarWidget::checkBounds(int old_pos) {
|
void ScrollBarWidget::checkBounds(int old_pos) {
|
||||||
|
|
|
@ -49,6 +49,12 @@ protected:
|
||||||
Part _draggingPart;
|
Part _draggingPart;
|
||||||
int _sliderDeltaMouseDownPos;
|
int _sliderDeltaMouseDownPos;
|
||||||
|
|
||||||
|
enum {
|
||||||
|
kRepeatInitialDelay = 500,
|
||||||
|
kRepeatDelay = 100
|
||||||
|
};
|
||||||
|
uint32 _repeatTimer;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
int _numEntries;
|
int _numEntries;
|
||||||
int _entriesPerPage;
|
int _entriesPerPage;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue