(svn r25671) -Codechange: Pass character and key code separately to the keyboard handler.

pull/155/head
michi_cc 11 years ago
parent d5590fa8f2
commit be50bc410f

@ -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);

@ -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);
}
}

@ -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);

@ -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;

@ -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;

@ -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,

Loading…
Cancel
Save