From 8f7e3119bfc02d31f4129d16ae1032fbc11bd8de Mon Sep 17 00:00:00 2001 From: Max Horn Date: Mon, 30 Sep 2002 12:56:59 +0000 Subject: fixed key repeat in NewGui; made the launcher game list non-editable svn-id: r5052 --- gui/ListWidget.cpp | 3 ++- gui/ListWidget.h | 2 ++ gui/launcher.cpp | 1 + gui/newgui.cpp | 25 +++++++++++++------------ gui/newgui.h | 8 +------- 5 files changed, 19 insertions(+), 20 deletions(-) (limited to 'gui') diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp index 1f607bfbfc..25c11b2065 100644 --- a/gui/ListWidget.cpp +++ b/gui/ListWidget.cpp @@ -125,7 +125,8 @@ bool ListWidget::handleKeyDown(char key, int modifiers) case '\n': // enter case '\r': if (_selectedItem >= 0) { - if ((_currentKeyDown != '\n' && _currentKeyDown != '\r')) { // override continuous enter keydown + // override continuous enter keydown + if (_editable && (_currentKeyDown != '\n' && _currentKeyDown != '\r')) { _editMode = true; dirty = true; _backupString = _list[_selectedItem]; diff --git a/gui/ListWidget.h b/gui/ListWidget.h index 106e61ceb6..abdd99b66e 100644 --- a/gui/ListWidget.h +++ b/gui/ListWidget.h @@ -62,6 +62,8 @@ public: int getSelected() const { return _selectedItem; } const String& getSelectedString() const { return _list[_selectedItem]; } void setNumberingMode(int numberingMode) { _numberingMode = numberingMode; } + bool isEditable() const { return _editable; } + void setEditable(bool editable) { _editable = editable; } virtual void handleMouseDown(int x, int y, int button, int clickCount); virtual void handleMouseUp(int x, int y, int button, int clickCount); diff --git a/gui/launcher.cpp b/gui/launcher.cpp index 95dee83fa9..e953982035 100644 --- a/gui/launcher.cpp +++ b/gui/launcher.cpp @@ -54,6 +54,7 @@ LauncherDialog::LauncherDialog(NewGui *gui, GameDetector &detector) // Add list with game titles _list = new ListWidget(this, 10, 10, 300, 112); + _list->setEditable(false); _list->setNumberingMode(kListNumberingOff); const VersionSettings *v = version_settings; diff --git a/gui/newgui.cpp b/gui/newgui.cpp index 8b82e5b8a5..aed586fe04 100644 --- a/gui/newgui.cpp +++ b/gui/newgui.cpp @@ -25,9 +25,7 @@ #ifdef _MSC_VER - # pragma warning( disable : 4068 ) // unknown pragma - #endif @@ -44,6 +42,14 @@ * - ... */ +enum { + kDoubleClickDelay = 500, // milliseconds + kCursorAnimateDelay = 500, + + kKeyRepeatInitialDelay = 400, + kKeyRepeatSustainDelay = 100, +}; + // Built-in font static byte guifont[] = { 0,0,99,1,226,8,4,8,6,8,6,0,0,0,0,0,0,0,0,0,0,0,8,2,1,8,0,0,0,0,0,0,0,0,0,0,0,0,4,3,7,8,7,7,8,4,5,5,8,7,4,7,3,8,7,7,7,7,8,7,7,7,7,7,3,4,7,5,7,7,8,7,7,7,7,7,7,7,7,5,7,7, @@ -126,6 +132,8 @@ void NewGui::runLoop() _system->update_screen(); + uint32 time = _system->get_msecs(); + while (_system->poll_event(&event)) { switch(event.event_code) { case OSystem::EVENT_KEYDOWN: @@ -134,8 +142,7 @@ void NewGui::runLoop() // init continuous event stream _currentKeyDown = event.kbd.ascii; _currentKeyDownFlags = event.kbd.flags; - _keyRepeatEvenCount = 1; - _keyRepeatLoopCount = 0; + _keyRepeatTime = time + kKeyRepeatInitialDelay; break; case OSystem::EVENT_KEYUP: activeDialog->handleKeyUp((byte)event.kbd.ascii, event.kbd.flags); @@ -150,7 +157,6 @@ void NewGui::runLoop() // We don'event distinguish between mousebuttons (for now at least) case OSystem::EVENT_LBUTTONDOWN: case OSystem::EVENT_RBUTTONDOWN: { - uint32 time = _system->get_msecs(); if (_lastClick.count && (time < _lastClick.time + kDoubleClickDelay) && ABS(_lastClick.x - event.mouse.x) < 3 && ABS(_lastClick.y - event.mouse.y) < 3) { @@ -174,17 +180,12 @@ void NewGui::runLoop() // check if event should be sent again (keydown) if (_currentKeyDown != 0) { - // if only fired once, wait longer - if ( _keyRepeatLoopCount >= ((_keyRepeatEvenCount > 1) ? 2 : 4) ) - // ^ loops to wait first event - // ^ loops to wait after first event + if (_keyRepeatTime < time) { // fire event activeDialog->handleKeyDown(_currentKeyDown, _currentKeyDownFlags); - _keyRepeatEvenCount++; - _keyRepeatLoopCount = 0; + _keyRepeatTime = time + kKeyRepeatSustainDelay; } - _keyRepeatLoopCount++; } // Delay for a moment diff --git a/gui/newgui.h b/gui/newgui.h index 1667a0d5b8..bd97bcaaf0 100644 --- a/gui/newgui.h +++ b/gui/newgui.h @@ -43,11 +43,6 @@ enum { kTextAlignRight, }; -enum { - kDoubleClickDelay = 500, // milliseconds - kCursorAnimateDelay = 500 -}; - // Extremly simple stack class, doesn't even do any error checking (for now) class DialogStack { protected: @@ -88,8 +83,7 @@ protected: // for continuous events (keyDown) int _currentKeyDown, _currentKeyDownFlags; - int _keyRepeatLoopCount; - int _keyRepeatEvenCount; + uint32 _keyRepeatTime; // position and time of last mouse click (used to detect double clicks) struct { -- cgit v1.2.3