diff options
author | Max Horn | 2002-11-22 18:46:18 +0000 |
---|---|---|
committer | Max Horn | 2002-11-22 18:46:18 +0000 |
commit | 0b82e20b00dc7056494ce2bd6a5554d6813d4974 (patch) | |
tree | 045fce394992d51ccf81004aa1b046d62efa644b | |
parent | 17cf386e8820fe312eb216c9be93d6d309f512e1 (diff) | |
download | scummvm-rg350-0b82e20b00dc7056494ce2bd6a5554d6813d4974.tar.gz scummvm-rg350-0b82e20b00dc7056494ce2bd6a5554d6813d4974.tar.bz2 scummvm-rg350-0b82e20b00dc7056494ce2bd6a5554d6813d4974.zip |
improved keyboard input behaviour in SDL backend: make use of the unicode feature in SDL. This way, Shift-1 on my german keyboard generates ! not 1 (on an US keyboard it'll be a different symbol). Should fix bug #600258 and #551447
svn-id: r5692
-rw-r--r-- | backends/sdl/sdl-common.cpp | 38 | ||||
-rw-r--r-- | gui/EditTextWidget.cpp | 8 | ||||
-rw-r--r-- | gui/ListWidget.cpp | 14 |
3 files changed, 35 insertions, 25 deletions
diff --git a/backends/sdl/sdl-common.cpp b/backends/sdl/sdl-common.cpp index 0efa7b4132..d415ddee94 100644 --- a/backends/sdl/sdl-common.cpp +++ b/backends/sdl/sdl-common.cpp @@ -47,6 +47,9 @@ OSystem *OSystem_SDL_Common::create(int gfx_mode, bool full_screen) { } SDL_ShowCursor(SDL_DISABLE); + + // Enable unicode support if possible + SDL_EnableUNICODE(1); #ifndef MACOSX // Don't set icon on OS X, as we use a nicer external icon there // Setup the icon @@ -423,14 +426,19 @@ void *OSystem_SDL_Common::create_thread(ThreadProc *proc, void *param) { return SDL_CreateThread(proc, param); } -int mapKey(int key, byte mod) +static int mapKey(SDLKey key, SDLMod mod, Uint16 unicode) { if (key >= SDLK_F1 && key <= SDLK_F9) { return key - SDLK_F1 + 315; + } else if (key >= SDLK_UP && key <= SDLK_PAGEDOWN) { + return key; + } else if (unicode) { + return unicode; } else if (key >= 'a' && key <= 'z' && mod & KMOD_SHIFT) { - key &= ~0x20; - } else if (key >= SDLK_NUMLOCK && key <= SDLK_EURO) + return key & ~0x20; + } else if (key >= SDLK_NUMLOCK && key <= SDLK_EURO) { return 0; + } return key; } @@ -486,24 +494,24 @@ bool OSystem_SDL_Common::poll_event(Event *event) { break; } // map menu key (f11) to f5 (scumm menu) - if (ev.key.keysym.sym == 292) { + if (ev.key.keysym.sym == SDLK_F11) { event->event_code = EVENT_KEYDOWN; - event->kbd.keycode = 286; - event->kbd.ascii = mapKey(286, ev.key.keysym.mod); + event->kbd.keycode = SDLK_F5; + event->kbd.ascii = mapKey(SDLK_F5, ev.key.keysym.mod, 0); } // map center (space) to tab (default action ) // I wanted to map the calendar button but the calendar comes up // - else if (ev.key.keysym.sym==32) { + else if (ev.key.keysym.sym == SDLK_SPACE) { event->event_code = EVENT_KEYDOWN; - event->kbd.keycode = 9; - event->kbd.ascii = mapKey(9, ev.key.keysym.mod); + event->kbd.keycode = SDLK_TAB; + event->kbd.ascii = mapKey(SDLK_TAB, ev.key.keysym.mod, 0); } // since we stole space (pause) above we'll rebind it to the tab key on the keyboard - else if (ev.key.keysym.sym==9) { + else if (ev.key.keysym.sym == SDLK_TAB) { event->event_code = EVENT_KEYDOWN; - event->kbd.keycode = 32; - event->kbd.ascii = mapKey(32, ev.key.keysym.mod); + event->kbd.keycode = SDLK_SPACE; + event->kbd.ascii = mapKey(SDLK_SPACE, ev.key.keysym.mod, 0); } else { // let the events fall through if we didn't change them, this may not be the best way to @@ -511,12 +519,12 @@ bool OSystem_SDL_Common::poll_event(Event *event) { // and yes i have an huge terminal size so i dont wrap soon enough. event->event_code = EVENT_KEYDOWN; event->kbd.keycode = ev.key.keysym.sym; - event->kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod); + event->kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode); } #else event->event_code = EVENT_KEYDOWN; event->kbd.keycode = ev.key.keysym.sym; - event->kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod); + event->kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode); #endif switch(ev.key.keysym.sym) { @@ -546,7 +554,7 @@ bool OSystem_SDL_Common::poll_event(Event *event) { case SDL_KEYUP: { event->event_code = EVENT_KEYUP; event->kbd.keycode = ev.key.keysym.sym; - event->kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod); + event->kbd.ascii = mapKey(ev.key.keysym.sym, ev.key.keysym.mod, ev.key.keysym.unicode); switch(ev.key.keysym.sym){ case SDLK_LEFT: diff --git a/gui/EditTextWidget.cpp b/gui/EditTextWidget.cpp index e91aff4986..10caf64cd7 100644 --- a/gui/EditTextWidget.cpp +++ b/gui/EditTextWidget.cpp @@ -76,13 +76,13 @@ bool EditTextWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) _label.deleteLastChar(); dirty = true; break; - case 20: // left arrow + case 256+20: // left arrow break; - case 19: // right arrow + case 256+19: // right arrow break; - case 22: // home + case 256+22: // home break; - case 23: // end + case 256+23: // end break; default: if (isprint((char)ascii)) { diff --git a/gui/ListWidget.cpp b/gui/ListWidget.cpp index 3a1937d0fe..19024f952d 100644 --- a/gui/ListWidget.cpp +++ b/gui/ListWidget.cpp @@ -142,6 +142,8 @@ bool ListWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) bool dirty = false; int oldSelectedItem = _selectedItem; +printf("ListWidget::handleKeyDown(%d, %d, %d)\n", (int)ascii, (int)keycode, (int)modifiers); + if (_editMode) { if (_caretVisible) @@ -189,28 +191,28 @@ bool ListWidget::handleKeyDown(uint16 ascii, int keycode, int modifiers) } } break; - case 17: // up arrow + case 256+17: // up arrow if (_selectedItem > 0) _selectedItem--; break; - case 18: // down arrow + case 256+18: // down arrow if (_selectedItem < _list.size() - 1) _selectedItem++; break; - case 24: // pageup + case 256+24: // pageup _selectedItem -= _entriesPerPage - 1; if (_selectedItem < 0) _selectedItem = 0; break; - case 25: // pagedown + case 256+25: // pagedown _selectedItem += _entriesPerPage - 1; if (_selectedItem >= _list.size() ) _selectedItem = _list.size() - 1; break; - case 22: // home + case 256+22: // home _selectedItem = 0; break; - case 23: // end + case 256+23: // end _selectedItem = _list.size() - 1; break; default: |