summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormichi_cc <michi_cc@openttd.org>2013-08-05 20:36:36 +0000
committermichi_cc <michi_cc@openttd.org>2013-08-05 20:36:36 +0000
commit019984a14f01e4463ae479765d2340ff26055367 (patch)
tree291b47c56523ebef7368f3588e921a1cdb78f331
parent270d8aa639341f8be7fde9aa6e6f5bb6fa894d4f (diff)
downloadopenttd-019984a14f01e4463ae479765d2340ff26055367.tar.xz
(svn r25671) -Codechange: Pass character and key code separately to the keyboard handler.
-rw-r--r--src/gfx_func.h3
-rw-r--r--src/video/allegro_v.cpp10
-rw-r--r--src/video/cocoa/event.mm6
-rw-r--r--src/video/sdl_v.cpp9
-rw-r--r--src/video/win32_v.cpp8
-rw-r--r--src/window.cpp9
6 files changed, 25 insertions, 20 deletions
diff --git a/src/gfx_func.h b/src/gfx_func.h
index 1226816b4..1e121b4c3 100644
--- 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 _resolutions[32];
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);
diff --git a/src/video/allegro_v.cpp b/src/video/allegro_v.cpp
index 029cc062a..963353f0d 100644
--- a/src/video/allegro_v.cpp
+++ b/src/video/allegro_v.cpp
@@ -304,7 +304,7 @@ static const VkMapping _vk_mapping[] = {
AS(KEY_TILDE, WKC_BACKQUOTE),
};
-static uint32 ConvertAllegroKeyIntoMy()
+static uint32 ConvertAllegroKeyIntoMy(WChar *character)
{
int scancode;
int unicode = ureadkey(&scancode);
@@ -326,7 +326,9 @@ static uint32 ConvertAllegroKeyIntoMy()
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 @@ static void PollEvent()
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);
}
}
diff --git a/src/video/cocoa/event.mm b/src/video/cocoa/event.mm
index 0e7831c34..40bf57eb6 100644
--- a/src/video/cocoa/event.mm
+++ b/src/video/cocoa/event.mm
@@ -267,7 +267,7 @@ static uint32 QZ_MapKey(unsigned short sym)
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 @@ static void QZ_KeyEvent(unsigned short keycode, unsigned short unicode, BOOL dow
}
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);
diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp
index d66ad59a8..a95e86332 100644
--- a/src/video/sdl_v.cpp
+++ b/src/video/sdl_v.cpp
@@ -495,7 +495,7 @@ static const VkMapping _vk_mapping[] = {
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 @@ static uint32 ConvertSdlKeyIntoMy(SDL_keysym *sym)
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 @@ int VideoDriver_SDL::PollEvent()
(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;
diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp
index 814fdc4b9..7a6e8a866 100644
--- a/src/video/win32_v.cpp
+++ b/src/video/win32_v.cpp
@@ -447,7 +447,7 @@ static LRESULT HandleCharMsg(uint keycode, uint charcode)
charcode = len == 1 ? w : 0;
#endif /* UNICODE */
- HandleKeypress(GB(charcode, 0, 16) | (keycode << 16));
+ HandleKeypress(keycode, charcode);
return 0;
}
@@ -637,7 +637,7 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
/* No character translation? */
if (charcode == 0) {
- HandleKeypress(0 | (keycode << 16));
+ HandleKeypress(keycode, 0);
return 0;
}
@@ -669,11 +669,11 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP
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;
diff --git a/src/window.cpp b/src/window.cpp
index bf51fd7ad..93a84812c 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -2448,18 +2448,15 @@ EventState Window::HandleEditBoxKey(int wid, WChar key, uint16 keycode)
/**
* 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,