Mercurial > hg > openttd
changeset 20696:d6112ef021b2 draft
-Codechange: Pass character and key code separately to the keyboard handler.
author | Michael Lutz <michi@icosahedron.de> |
---|---|
date | Sun, 24 Mar 2013 00:06:33 +0100 |
parents | 0d650ab65a85 |
children | c3ef81a9b92e |
files | src/gfx_func.h src/video/allegro_v.cpp src/video/cocoa/event.mm src/video/sdl_v.cpp src/video/win32_v.cpp src/window.cpp |
diffstat | 6 files changed, 25 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/src/gfx_func.h +++ b/src/gfx_func.h @@ -44,6 +44,7 @@ #include "gfx_type.h" #include "strings_type.h" +#include "string_type.h" void GameLoop(); @@ -69,7 +70,7 @@ extern Dimension _cur_resolution; extern Palette _cur_palette; ///< Current palette -void HandleKeypress(uint32 key); +void HandleKeypress(uint keycode, WChar key); void HandleCtrlChanged(); void HandleMouseEvents(); void CSleep(int milliseconds);
--- a/src/video/allegro_v.cpp +++ b/src/video/allegro_v.cpp @@ -304,7 +304,7 @@ AS(KEY_TILDE, WKC_BACKQUOTE), }; -static uint32 ConvertAllegroKeyIntoMy() +static uint32 ConvertAllegroKeyIntoMy(WChar *character) { int scancode; int unicode = ureadkey(&scancode); @@ -326,7 +326,9 @@ DEBUG(driver, 0, "Scancode character pressed %u", scancode); DEBUG(driver, 0, "Unicode character pressed %u", unicode); #endif - return (key << 16) + unicode; + + *character = unicode; + return key; } static const uint LEFT_BUTTON = 0; @@ -414,7 +416,9 @@ if ((key_shifts & KB_ALT_FLAG) && (key[KEY_ENTER] || key[KEY_F])) { ToggleFullScreen(!_fullscreen); } else if (keypressed()) { - HandleKeypress(ConvertAllegroKeyIntoMy()); + WChar character; + uint keycode = ConvertAllegroKeyIntoMy(&character); + HandleKeypress(keycode, character); } }
--- a/src/video/cocoa/event.mm +++ b/src/video/cocoa/event.mm @@ -267,7 +267,7 @@ if (_current_mods & NSAlternateKeyMask) key |= WKC_ALT; if (_current_mods & NSCommandKeyMask) key |= (_settings_client.gui.right_mouse_btn_emulation != RMBE_CONTROL ? WKC_META : WKC_CTRL); - return key << 16; + return key; } static void QZ_KeyEvent(unsigned short keycode, unsigned short unicode, BOOL down) @@ -289,8 +289,8 @@ } if (down) { - uint32 pressed_key = QZ_MapKey(keycode) | unicode; - HandleKeypress(pressed_key); + uint32 pressed_key = QZ_MapKey(keycode); + HandleKeypress(pressed_key, unicode); DEBUG(driver, 2, "cocoa_v: QZ_KeyEvent: %x (%x), down, mapping: %x", keycode, unicode, pressed_key); } else { DEBUG(driver, 2, "cocoa_v: QZ_KeyEvent: %x (%x), up", keycode, unicode);
--- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -495,7 +495,7 @@ AS(SDLK_PERIOD, WKC_PERIOD) }; -static uint32 ConvertSdlKeyIntoMy(SDL_keysym *sym) +static uint ConvertSdlKeyIntoMy(SDL_keysym *sym, WChar *character) { const VkMapping *map; uint key = 0; @@ -531,7 +531,8 @@ if (sym->mod & KMOD_CTRL) key |= WKC_CTRL; if (sym->mod & KMOD_ALT) key |= WKC_ALT; - return (key << 16) + sym->unicode; + *character = sym->unicode; + return key; } int VideoDriver_SDL::PollEvent() @@ -617,7 +618,9 @@ (ev.key.keysym.sym == SDLK_RETURN || ev.key.keysym.sym == SDLK_f)) { ToggleFullScreen(!_fullscreen); } else { - HandleKeypress(ConvertSdlKeyIntoMy(&ev.key.keysym)); + WChar character; + uint keycode = ConvertSdlKeyIntoMy(&ev.key.keysym, &character); + HandleKeypress(keycode, character); } break;
--- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -442,7 +442,7 @@ charcode = len == 1 ? w : 0; #endif /* UNICODE */ - HandleKeypress(GB(charcode, 0, 16) | (keycode << 16)); + HandleKeypress(keycode, charcode); return 0; } @@ -632,7 +632,7 @@ /* No character translation? */ if (charcode == 0) { - HandleKeypress(0 | (keycode << 16)); + HandleKeypress(keycode, 0); return 0; } @@ -664,11 +664,11 @@ return 0; // do nothing case VK_F10: // F10, ignore activation of menu - HandleKeypress(MapWindowsKey(wParam) << 16); + HandleKeypress(MapWindowsKey(wParam), 0); return 0; default: // ALT in combination with something else - HandleKeypress(MapWindowsKey(wParam) << 16); + HandleKeypress(MapWindowsKey(wParam), 0); break; } break;
--- a/src/window.cpp +++ b/src/window.cpp @@ -2443,18 +2443,15 @@ /** * Handle keyboard input. - * @param raw_key Lower 8 bits contain the ASCII character, the higher 16 bits the keycode + * @param keycode Virtual keycode of the key. + * @param key Unicode character of the key. */ -void HandleKeypress(uint32 raw_key) +void HandleKeypress(uint keycode, WChar key) { /* World generation is multithreaded and messes with companies. * But there is no company related window open anyway, so _current_company is not used. */ assert(HasModalProgress() || IsLocalCompany()); - /* Setup event */ - uint16 key = GB(raw_key, 0, 16); - uint16 keycode = GB(raw_key, 16, 16); - /* * The Unicode standard defines an area called the private use area. Code points in this * area are reserved for private use and thus not portable between systems. For instance,