Ticket #8532: keyboard-repeat2.diff

File keyboard-repeat2.diff, 14.2 KB (added by eriktorbjorn, 18 years ago)

Updated patch

  • gui/newgui.cpp

     
    4848
    4949enum {
    5050        kDoubleClickDelay = 500, // milliseconds
    51         kCursorAnimateDelay = 250,
    52         kKeyRepeatInitialDelay = 400,
    53         kKeyRepeatSustainDelay = 100
     51        kCursorAnimateDelay = 250
    5452};
    5553
    5654// HACK. FIXME. This doesn't belong here. But otherwise it creates compilation problems
     
    9290        // Clear the cursor
    9391        memset(_cursor, 0xFF, sizeof(_cursor));
    9492
    95         // Reset key repeat
    96         _currentKeyDown.keycode = 0;
    97 
    9893#ifndef DISABLE_FANCY_THEMES
    9994        ConfMan.registerDefault("gui_theme", "default");
    10095        Common::String style(ConfMan.get("gui_theme"));
     
    208203                       
    209204                        switch (event.type) {
    210205                        case OSystem::EVENT_KEYDOWN:
    211 #if !defined(PALMOS_MODE)
    212                                 // init continuous event stream
    213                                 // not done on PalmOS because keyboard is emulated and keyup is not generated
    214                                 _currentKeyDown.ascii = event.kbd.ascii;
    215                                 _currentKeyDown.keycode = event.kbd.keycode;
    216                                 _currentKeyDown.flags = event.kbd.flags;
    217                                 _keyRepeatTime = time + kKeyRepeatInitialDelay;
    218 #endif
    219206                                activeDialog->handleKeyDown(event.kbd.ascii, event.kbd.keycode, event.kbd.flags);
    220207                                break;
    221208                        case OSystem::EVENT_KEYUP:
    222209                                activeDialog->handleKeyUp(event.kbd.ascii, event.kbd.keycode, event.kbd.flags);
    223                                 if (event.kbd.keycode == _currentKeyDown.keycode)
    224                                         // only stop firing events if it's the current key
    225                                         _currentKeyDown.keycode = 0;
    226210                                break;
    227211                        case OSystem::EVENT_MOUSEMOVE:
    228212                                activeDialog->handleMouseMoved(mouse.x, mouse.y, 0);
     
    272256                        }
    273257                }
    274258
    275                 // check if event should be sent again (keydown)
    276                 if (_currentKeyDown.keycode != 0 && activeDialog == _dialogStack.top()) {
    277                         if (_keyRepeatTime < time) {
    278                                 // fire event
    279                                 activeDialog->handleKeyDown(_currentKeyDown.ascii, _currentKeyDown.keycode, _currentKeyDown.flags);
    280                                 _keyRepeatTime = time + kKeyRepeatSustainDelay;
    281                         }
    282                 }
    283 
    284259                // Delay for a moment
    285260                _system->delayMillis(10);
    286261        }
     
    298273#pragma mark -
    299274
    300275void NewGui::saveState() {
    301         // Backup old cursor
    302         _currentKeyDown.keycode = 0;
    303276        _lastClick.x = _lastClick.y = 0;
    304277        _lastClick.time = 0;
    305278        _lastClick.count = 0;
  • gui/newgui.h

     
    9494
    9595        bool            _stateIsSaved;
    9696
    97         // for continuous events (keyDown)
    98         struct {
    99                 uint16 ascii;
    100                 byte flags;
    101                 int keycode;
    102         } _currentKeyDown;
    103         uint32          _keyRepeatTime;
    104 
    10597        // position and time of last mouse click (used to detect double clicks)
    10698        struct {
    10799                int16 x, y;     // Position of mouse when the click occured
  • engines/sword1/control.h

     
    139139        uint8 *_font, *_redFont;
    140140        uint8 *_screenBuf;
    141141        uint8 _keyPressed;
    142         uint8 _keyRepeat;
    143         uint32 _keyRepeatTime;
    144142        void delay(uint32 msecs);
    145143        uint16 _mouseX, _mouseY, _mouseState;
    146144        bool _mouseDown;
  • engines/sword1/control.cpp

     
    4242
    4343namespace Sword1 {
    4444
    45 enum {
    46         kKeyRepeatInitialDelay = 400,
    47         kKeyRepeatSustainDelay = 100
    48 };
    49 
    5045enum LangStrings {
    5146        STR_PAUSED = 0,
    5247        STR_INSERT_CD_A,
     
    171166        _music = pMusic;
    172167        _sound = pSound;
    173168        _lStrings = _languageStrings + SwordEngine::_systemVars.language * 20;
    174         _keyRepeat = 0;
    175         _keyRepeatTime = 0;
    176169}
    177170
    178171void Control::askForCd(void) {
     
    10511044                                        _keyPressed = 8;
    10521045                                else
    10531046                                        _keyPressed = (byte)event.kbd.ascii;
    1054                                 _keyRepeatTime = now + kKeyRepeatInitialDelay;
    1055                                 _keyRepeat = _keyPressed;
    10561047                                // we skip the rest of the delay and return immediately
    10571048                                // to handle keyboard input
    10581049                                return;
    1059                         case OSystem::EVENT_KEYUP:
    1060                                 _keyRepeatTime = 0;
    1061                                 _keyRepeat = 0;
    1062                                 break;
    10631050                        case OSystem::EVENT_MOUSEMOVE:
    10641051                                _mouseX = event.mouse.x;
    10651052                                _mouseY = event.mouse.y;
     
    10911078                                break;
    10921079                        }
    10931080                }
    1094                 if (_keyRepeatTime && now > _keyRepeatTime) {
    1095                         _keyRepeatTime += kKeyRepeatSustainDelay;
    1096                         _keyPressed = _keyRepeat;
    1097                 }
    10981081
    10991082                _system->updateScreen();
    11001083                _system->delayMillis(10);
  • engines/sword2/sword2.cpp

     
    147147        _debugger = NULL;
    148148
    149149        _keyboardEvent.pending = false;
    150         _keyboardEvent.repeat = 0;
    151150        _mouseEvent.pending = false;
    152151
    153152        _wantSfxDebug = false;
     
    504503
    505504void Sword2Engine::clearInputEvents() {
    506505        _keyboardEvent.pending = false;
    507         _keyboardEvent.repeat = 0;
    508506        _mouseEvent.pending = false;
    509507}
    510508
     
    515513void Sword2Engine::parseInputEvents() {
    516514        OSystem::Event event;
    517515
    518         uint32 now = _system->getMillis();
    519 
    520516        while (_system->pollEvent(event)) {
    521517                switch (event.type) {
    522518                case OSystem::EVENT_KEYDOWN:
    523519                        if (!(_inputEventFilter & RD_KEYDOWN)) {
    524520                                _keyboardEvent.pending = true;
    525                                 _keyboardEvent.repeat = now + 400;
    526521                                _keyboardEvent.ascii = event.kbd.ascii;
    527522                                _keyboardEvent.keycode = event.kbd.keycode;
    528523                                _keyboardEvent.modifiers = event.kbd.flags;
    529524                        }
    530525                        break;
    531                 case OSystem::EVENT_KEYUP:
    532                         _keyboardEvent.repeat = 0;
    533                         break;
    534526                case OSystem::EVENT_MOUSEMOVE:
    535527                        if (!(_inputEventFilter & RD_KEYDOWN)) {
    536528                                _mouse->setPos(event.mouse.x, event.mouse.y - MENUDEEP);
     
    579571                        break;
    580572                }
    581573        }
    582 
    583         // Handle keyboard auto-repeat
    584         if (!_keyboardEvent.pending && _keyboardEvent.repeat && now >= _keyboardEvent.repeat) {
    585                 _keyboardEvent.pending = true;
    586                 _keyboardEvent.repeat = now + 100;
    587         }
    588574}
    589575
    590576void Sword2Engine::gameCycle() {
  • engines/sword2/sword2.h

     
    7272
    7373struct KeyboardEvent {
    7474        bool pending;
    75         uint32 repeat;
    7675        uint16 ascii;
    7776        int keycode;
    7877        int modifiers;
  • engines/kyra/kyra.cpp

     
    9292        _scriptMain = 0;
    9393        _scriptClickData = 0;
    9494        _scriptClick = 0;
     95        _keyPressed = 0;
    9596        _characterList = 0;
    9697        _movFacingTable = 0;
    9798        memset(_shapes, 0, sizeof(_shapes));
  • engines/kyra/gui.cpp

     
    616616                calcCoords(_menu[i]);
    617617
    618618        _menuRestoreScreen = true;
    619         _keyboardEvent.pending = 0;
    620         _keyboardEvent.repeat = 0;
    621619        _mousePressFlag = false;
    622620       
    623621        _toplevelMenu = 0;
     
    834832                        _mouseWheel = 1;
    835833                        break;
    836834                case OSystem::EVENT_KEYDOWN:
    837                         _keyboardEvent.pending = true;
    838                         _keyboardEvent.repeat = now + 400;
    839                         _keyboardEvent.ascii = event.kbd.ascii;
     835                        _keyPressed = event.kbd.ascii;
    840836                        break;
    841                 case OSystem::EVENT_KEYUP:
    842                         _keyboardEvent.repeat = 0;
    843                         break;
    844837                default:
    845838                        break;
    846839                }
     
    851844                lastScreenUpdate = now;
    852845        }
    853846
    854         if (!_keyboardEvent.pending && _keyboardEvent.repeat && now >= _keyboardEvent.repeat) {
    855                 _keyboardEvent.pending = true;
    856                 _keyboardEvent.repeat = now + 100;
    857         }
    858847        _system->delayMillis(3);
    859848}
    860849
     
    10191008void KyraEngine::gui_updateSavegameString() {
    10201009        int length;
    10211010
    1022         if (_keyboardEvent.pending && _keyboardEvent.ascii) {
     1011        if (_keyPressed) {
    10231012                length = strlen(_savegameName);
    10241013
    1025                 if (_keyboardEvent.ascii > 31 && _keyboardEvent.ascii < 127) {
     1014                if (_keyPressed > 31 && _keyPressed < 127) {
    10261015                        if (length < 31) {
    1027                                 _savegameName[length] = _keyboardEvent.ascii;
     1016                                _savegameName[length] = _keyPressed;
    10281017                                _savegameName[length+1] = 0;
    10291018                                gui_redrawTextfield();
    10301019                        }
    1031                 } else if (_keyboardEvent.ascii == 8 ||_keyboardEvent.ascii == 127) {
     1020                } else if (_keyPressed == 8 || _keyPressed == 127) {
    10321021                        if (length > 0) {
    10331022                                _savegameName[length-1] = 0;
    10341023                                gui_redrawTextfield();
    10351024                        }
    1036                 } else if (_keyboardEvent.ascii == 13) {
     1025                } else if (_keyPressed == 13) {
    10371026                        _displaySubMenu = false;
    10381027                }
    10391028        }
    10401029
    1041         _keyboardEvent.pending = false;
     1030        _keyPressed = 0;
    10421031}
    10431032
    10441033int KyraEngine::gui_saveGame(Button *button) {
  • engines/kyra/kyra.h

     
    232232        MenuItem item[6];
    233233};
    234234
    235 struct KeyboardEvent {
    236         bool pending;
    237         uint32 repeat;
    238         uint8 ascii;
    239 };
    240 
    241235class KyraEngine : public Engine {
    242236        friend class MusicPlayer;
    243237        friend class Debugger;
     
    836830        int _gameToLoad;
    837831        char _savegameName[31];
    838832        const char *_specialSavegameString;
    839         KeyboardEvent _keyboardEvent;
     833        uint8 _keyPressed;
    840834
    841835        struct KyragemState {
    842836                uint16 nextOperation;
  • engines/saga/input.cpp

     
    119119                                break;
    120120                        }
    121121                        break;
    122                 case OSystem::EVENT_KEYUP:
    123                         _interface->processKeyUp(event.kbd.ascii);
    124                         break;
    125122                case OSystem::EVENT_LBUTTONUP:
    126123                        _leftMouseButtonPressed = false;
    127124                        break;
  • engines/saga/interface.h

     
    222222        void drawStatusBar();
    223223        void setVerbState(int verb, int state);
    224224
    225         bool processAscii(uint16 ascii, bool synthetic = false);
    226         void processKeyUp(uint16 ascii);
     225        bool processAscii(uint16 ascii);
    227226
    228227        void keyBoss();
    229228        void keyBossExit();
     
    243242        }
    244243
    245244private:
    246         static void textInputRepeatCallback(void *refCon);
    247 
    248245        void drawInventory(Surface *backBuffer);
    249246        void updateInventory(int pos);
    250247        void inventoryChangePos(int chg);
     
    343340        void calcOptionSaveSlider();
    344341        bool processTextInput(uint16 ascii);
    345342        void processStatusTextInput(uint16 ascii);
    346         void textInputStartRepeat(uint16 ascii);
    347         void textInputRepeat(void);
    348343
    349344public:
    350345        void converseInit(void);
     
    452447
    453448        uint _statusTextInputPos;
    454449
    455         int _textInputRepeatPhase;
    456         uint16 _textInputRepeatChar;
    457 
    458450        PalEntry _mapSavedPal[PAL_ENTRIES];
    459451        bool _mapPanelCrossHairState;
    460452
  • engines/saga/interface.cpp

     
    4747
    4848#include "common/config-manager.h"
    4949#include "common/system.h"
    50 #include "common/timer.h"
    5150
    5251namespace Saga {
    5352
     
    212211                error("Interface::Interface(): not enough memory");
    213212        }
    214213
    215         _textInputRepeatPhase = 0;
    216214        _textInput = false;
    217215        _statusTextInput = false;
    218216        _statusTextInputState = kStatusTextInputFirstRun;
     
    316314                _textInput = true;
    317315                _textInputStringLength = strlen(_textInputString);
    318316                _textInputPos = _textInputStringLength + 1;
    319                 _textInputRepeatPhase = 0;
    320317                break;
    321318        case kPanelMap:
    322319                mapPanelShow();
     
    337334                _textInputString[0] = 0;
    338335                _textInputStringLength = 0;
    339336                _textInputPos = _textInputStringLength + 1;
    340                 _textInputRepeatPhase = 0;
    341337                break;
    342338        }
    343339
    344340        draw();
    345341}
    346342
    347 bool Interface::processAscii(uint16 ascii, bool synthetic) {
     343bool Interface::processAscii(uint16 ascii) {
    348344        // TODO: Checking for Esc and Enter below is a bit hackish, and
    349345        // and probably only works with the English version. Maybe we should
    350346        // add a flag to the button so it can indicate if it's the default or
     
    352348
    353349        int i;
    354350        PanelButton *panelButton;
    355         if (!synthetic)
    356                 _textInputRepeatPhase = 0;
    357351        if (_statusTextInput) {
    358352                processStatusTextInput(ascii);
    359353                return true;
     
    536530        return false;
    537531}
    538532
    539 #define KEYBOARD_REPEAT_DELAY1 300000L
    540 #define KEYBOARD_REPEAT_DELAY2 50000L
    541 
    542 void Interface::textInputRepeatCallback(void *refCon) {
    543         ((Interface *)refCon)->textInputRepeat();
    544 }
    545 
    546 void Interface::textInputStartRepeat(uint16 ascii) {
    547         if (!_textInputRepeatPhase) {
    548                 _textInputRepeatPhase = 1;
    549                 Common::g_timer->removeTimerProc(&textInputRepeatCallback);
    550                 Common::g_timer->installTimerProc(&textInputRepeatCallback, KEYBOARD_REPEAT_DELAY1, this);
    551         }
    552 
    553         _textInputRepeatChar = ascii;
    554 }
    555 
    556 void Interface::textInputRepeat() {
    557         if (_textInputRepeatPhase == 1) {
    558                 _textInputRepeatPhase = 2;
    559                 Common::g_timer->removeTimerProc(&textInputRepeatCallback);
    560                 Common::g_timer->installTimerProc(&textInputRepeatCallback, KEYBOARD_REPEAT_DELAY2, this);
    561         } else if (_textInputRepeatPhase == 2) {
    562                 processAscii(_textInputRepeatChar, true);
    563         }
    564 }
    565 
    566 void Interface::processKeyUp(uint16 ascii) {
    567         if (_textInputRepeatPhase) {
    568                 Common::g_timer->removeTimerProc(&textInputRepeatCallback);
    569                 _textInputRepeatPhase = 0;
    570         }
    571 }
    572 
    573533void Interface::setStatusText(const char *text, int statusColor) {
    574534        assert(text != NULL);
    575535        assert(strlen(text) < STATUS_TEXT_LEN);
     
    928888
    929889void Interface::processStatusTextInput(uint16 ascii) {
    930890
    931         textInputStartRepeat(ascii);
    932891        switch (ascii) {
    933892        case 27: // esc
    934893                _statusTextInputState = kStatusTextInputAborted;
     
    968927        memset(tempString, 0, SAVE_TITLE_SIZE);
    969928        ch[1] = 0;
    970929
    971         textInputStartRepeat(ascii);
    972 
    973930        switch (ascii) {
    974931        case 13:
    975932                return false;
  • backends/platform/sdl/sdl.cpp

     
    132132        // Enable unicode support if possible
    133133        SDL_EnableUNICODE(1);
    134134
     135        SDL_EnableKeyRepeat(kKeyRepeatInitialDelay, kKeyRepeatSustainDelay);
     136
    135137        _cksumValid = false;
    136138#if !defined(_WIN32_WCE) && !defined(__SYMBIAN32__) && !defined(DISABLE_SCALERS)
    137139        _mode = GFX_DOUBLESIZE;
  • backends/platform/sdl/sdl-common.h

     
    5454        GFX_DOTMATRIX = 11
    5555};
    5656
     57enum {
     58        kKeyRepeatInitialDelay = 400,
     59        kKeyRepeatSustainDelay = 100
     60};
    5761
    5862class OSystem_SDL : public OSystem {
    5963public: