Ticket #8532: keyboard-repeat.diff

File keyboard-repeat.diff, 14.3 KB (added by eriktorbjorn, 18 years ago)

Patch against current SVN

  • gui/newgui.cpp

     
    4646
    4747enum {
    4848        kDoubleClickDelay = 500, // milliseconds
    49         kCursorAnimateDelay = 250,
    50         kKeyRepeatInitialDelay = 400,
    51         kKeyRepeatSustainDelay = 100
     49        kCursorAnimateDelay = 250
    5250};
    5351
    5452#if defined(__SYMBIAN32__) // Testing: could be removed? Just making sure that an CVS update doesn't break my code :P
     
    9694        // Clear the cursor
    9795        memset(_cursor, 0xFF, sizeof(_cursor));
    9896
    99         // Reset key repeat
    100         _currentKeyDown.keycode = 0;
    101 
    10297#ifndef DISABLE_FANCY_THEMES
    10398        ConfMan.registerDefault("gui_theme", "default");
    10499        Common::String style = ConfMan.get("gui_theme");
     
    186181                       
    187182                        switch (event.type) {
    188183                        case OSystem::EVENT_KEYDOWN:
    189 #if !defined(PALMOS_MODE)
    190                                 // init continuous event stream
    191                                 // not done on PalmOS because keyboard is emulated and keyup is not generated
    192                                 _currentKeyDown.ascii = event.kbd.ascii;
    193                                 _currentKeyDown.keycode = event.kbd.keycode;
    194                                 _currentKeyDown.flags = event.kbd.flags;
    195                                 _keyRepeatTime = time + kKeyRepeatInitialDelay;
    196 #endif
    197184                                activeDialog->handleKeyDown(event.kbd.ascii, event.kbd.keycode, event.kbd.flags);
    198185                                break;
    199186                        case OSystem::EVENT_KEYUP:
    200187                                activeDialog->handleKeyUp(event.kbd.ascii, event.kbd.keycode, event.kbd.flags);
    201                                 if (event.kbd.keycode == _currentKeyDown.keycode)
    202                                         // only stop firing events if it's the current key
    203                                         _currentKeyDown.keycode = 0;
    204188                                break;
    205189                        case OSystem::EVENT_MOUSEMOVE:
    206190                                activeDialog->handleMouseMoved(mouse.x, mouse.y, 0);
     
    247231                        }
    248232                }
    249233
    250                 // check if event should be sent again (keydown)
    251                 if (_currentKeyDown.keycode != 0) {
    252                         if (_keyRepeatTime < time) {
    253                                 // fire event
    254                                 activeDialog->handleKeyDown(_currentKeyDown.ascii, _currentKeyDown.keycode, _currentKeyDown.flags);
    255                                 _keyRepeatTime = time + kKeyRepeatSustainDelay;
    256                         }
    257                 }
    258 
    259234                // Delay for a moment
    260235                _system->delayMillis(10);
    261236        }
     
    274249        // Backup old cursor
    275250        _oldCursorMode = _system->showMouse(true);
    276251
    277         _currentKeyDown.keycode = 0;
    278252        _lastClick.x = _lastClick.y = 0;
    279253        _lastClick.time = 0;
    280254        _lastClick.count = 0;
  • gui/newgui.h

     
    9191
    9292        bool            _stateIsSaved;
    9393
    94         // for continuous events (keyDown)
    95         struct {
    96                 uint16 ascii;
    97                 byte flags;
    98                 int keycode;
    99         } _currentKeyDown;
    100         uint32          _keyRepeatTime;
    101 
    10294        // position and time of last mouse click (used to detect double clicks)
    10395        struct {
    10496                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) {
     
    10541047                                        _keyPressed = 8;
    10551048                                else
    10561049                                        _keyPressed = (byte)event.kbd.ascii;
    1057                                 _keyRepeatTime = now + kKeyRepeatInitialDelay;
    1058                                 _keyRepeat = _keyPressed;
    10591050                                // we skip the rest of the delay and return immediately
    10601051                                // to handle keyboard input
    10611052                                return;
    1062                         case OSystem::EVENT_KEYUP:
    1063                                 _keyRepeatTime = 0;
    1064                                 _keyRepeat = 0;
    1065                                 break;
    10661053                        case OSystem::EVENT_MOUSEMOVE:
    10671054                                _mouseX = event.mouse.x;
    10681055                                _mouseY = event.mouse.y;
     
    10941081                                break;
    10951082                        }
    10961083                }
    1097                 if (_keyRepeatTime && now > _keyRepeatTime) {
    1098                         _keyRepeatTime += kKeyRepeatSustainDelay;
    1099                         _keyPressed = _keyRepeat;
    1100                 }
    11011084
    11021085                _system->updateScreen();
    11031086                _system->delayMillis(10);
  • engines/sword2/sword2.cpp

     
    148148        _debugger = NULL;
    149149
    150150        _keyboardEvent.pending = false;
    151         _keyboardEvent.repeat = 0;
    152151        _mouseEvent.pending = false;
    153152
    154153        _wantSfxDebug = false;
     
    506505
    507506void Sword2Engine::clearInputEvents() {
    508507        _keyboardEvent.pending = false;
    509         _keyboardEvent.repeat = 0;
    510508        _mouseEvent.pending = false;
    511509}
    512510
     
    517515void Sword2Engine::parseInputEvents() {
    518516        OSystem::Event event;
    519517
    520         uint32 now = _system->getMillis();
    521 
    522518        while (_system->pollEvent(event)) {
    523519                switch (event.type) {
    524520                case OSystem::EVENT_KEYDOWN:
    525521                        if (!(_inputEventFilter & RD_KEYDOWN)) {
    526522                                _keyboardEvent.pending = true;
    527                                 _keyboardEvent.repeat = now + 400;
    528523                                _keyboardEvent.ascii = event.kbd.ascii;
    529524                                _keyboardEvent.keycode = event.kbd.keycode;
    530525                                _keyboardEvent.modifiers = event.kbd.flags;
    531526                        }
    532527                        break;
    533                 case OSystem::EVENT_KEYUP:
    534                         _keyboardEvent.repeat = 0;
    535                         break;
    536528                case OSystem::EVENT_MOUSEMOVE:
    537529                        if (!(_inputEventFilter & RD_KEYDOWN)) {
    538530                                _mouse->setPos(event.mouse.x, event.mouse.y - MENUDEEP);
     
    581573                        break;
    582574                }
    583575        }
    584 
    585         // Handle keyboard auto-repeat
    586         if (!_keyboardEvent.pending && _keyboardEvent.repeat && now >= _keyboardEvent.repeat) {
    587                 _keyboardEvent.pending = true;
    588                 _keyboardEvent.repeat = now + 100;
    589         }
    590576}
    591577
    592578void 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

     
    8989        _scriptMain = 0;
    9090        _scriptClickData = 0;
    9191        _scriptClick = 0;
     92        _keyPressed = 0;
    9293        _characterList = 0;
    9394        _movFacingTable = 0;
    9495        memset(_shapes, 0, sizeof(_shapes));
  • engines/kyra/gui.cpp

     
    514514                calcCoords(_menu[i]);
    515515
    516516        _menuRestoreScreen = true;
    517         _keyboardEvent.pending = 0;
    518         _keyboardEvent.repeat = 0;
    519517        _mousePressFlag = false;
    520518       
    521519        _toplevelMenu = 0;
     
    704702
    705703void KyraEngine::gui_getInput() {
    706704        OSystem::Event event;
    707         uint32 now = _system->getMillis();
    708705
    709706        _mouseWheel = 0;
    710707        while (_system->pollEvent(event)) {
     
    730727                        _mouseWheel = 1;
    731728                        break;
    732729                case OSystem::EVENT_KEYDOWN:
    733                         _keyboardEvent.pending = true;
    734                         _keyboardEvent.repeat = now + 400;
    735                         _keyboardEvent.ascii = event.kbd.ascii;
     730                        _keyPressed = event.kbd.ascii;
    736731                        break;
    737                 case OSystem::EVENT_KEYUP:
    738                         _keyboardEvent.repeat = 0;
    739                         break;
    740732                default:
    741733                        break;
    742734                }
    743735        }
    744736
    745         if (!_keyboardEvent.pending && _keyboardEvent.repeat && now >= _keyboardEvent.repeat) {
    746                 _keyboardEvent.pending = true;
    747                 _keyboardEvent.repeat = now + 100;
    748         }
    749737        _system->delayMillis(3);
    750738}
    751739
     
    910898void KyraEngine::gui_updateSavegameString() {
    911899        int length;
    912900
    913         if (_keyboardEvent.pending && _keyboardEvent.ascii) {
     901        if (_keyPressed) {
    914902                length = strlen(_savegameName);
    915903
    916                 if (_keyboardEvent.ascii > 31 && _keyboardEvent.ascii < 127) {
     904                if (_keyPressed > 31 && _keyPressed < 127) {
    917905                        if (length < 31) {
    918                                 _savegameName[length] = _keyboardEvent.ascii;
     906                                _savegameName[length] = _keyPressed;
    919907                                _savegameName[length+1] = 0;
    920908                                gui_redrawTextfield();
    921909                        }
    922                 } else if (_keyboardEvent.ascii == 8 ||_keyboardEvent.ascii == 127) {
     910                } else if (_keyPressed == 8 ||_keyPressed == 127) {
    923911                        if (length > 0) {
    924912                                _savegameName[length-1] = 0;
    925913                                gui_redrawTextfield();
    926914                        }
    927                 } else if (_keyboardEvent.ascii == 13) {
     915                } else if (_keyPressed == 13) {
    928916                        _displaySubMenu = false;
    929917                }
    930918        }
    931919
    932         _keyboardEvent.pending = false;
     920        _keyPressed = 0;
    933921}
    934922
    935923int KyraEngine::gui_saveGame(Button *button) {
  • engines/kyra/kyra.h

     
    230230        MenuItem item[6];
    231231};
    232232
    233 struct KeyboardEvent {
    234         bool pending;
    235         uint32 repeat;
    236         uint8 ascii;
    237 };
    238 
    239233class KyraEngine : public Engine {
    240234        friend class MusicPlayer;
    241235        friend class Debugger;
     
    823817        int _gameToLoad;
    824818        char _savegameName[31];
    825819        const char *_specialSavegameString;
    826         KeyboardEvent _keyboardEvent;
     820        uint8 _keyPressed;
    827821
    828822        struct KyragemState {
    829823                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/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/sdl/sdl-common.h

     
    5353        GFX_DOTMATRIX = 11
    5454};
    5555
     56enum {
     57        kKeyRepeatInitialDelay = 400,
     58        kKeyRepeatSustainDelay = 100
     59};
    5660
     61
    5762class OSystem_SDL : public OSystem {
    5863public:
    5964        OSystem_SDL();