From 95e5d2782c132fec64630d9685da0b4c13d9cc9d Mon Sep 17 00:00:00 2001 From: SoftCoder Date: Tue, 29 Sep 2015 06:22:54 -0700 Subject: [PATCH] - bugfix to get proper typed character in sdl2 --- source/glest_game/global/config.cpp | 12 ++++-------- source/glest_game/menu/menu_state_root.cpp | 1 + source/shared_lib/sources/platform/sdl/window.cpp | 11 ++++++++--- 3 files changed, 13 insertions(+), 11 deletions(-) diff --git a/source/glest_game/global/config.cpp b/source/glest_game/global/config.cpp index d1cd91e7..93b3185d 100644 --- a/source/glest_game/global/config.cpp +++ b/source/glest_game/global/config.cpp @@ -541,14 +541,10 @@ SDL_Keycode Config::translateStringToSDLKey(const string &value) const { else { bool foundKey = false; if(value.length() > 1) { - for(int i = SDLK_UNKNOWN; i < SDL_NUM_SCANCODES; ++i) { - SDL_Keycode key = static_cast(i); - string keyName = SDL_GetKeyName(key); - if(value == keyName) { - result = key; - foundKey = true; - break; - } + SDL_Keycode lookup = SDL_GetKeyFromName(value.c_str()); + if(lookup != SDLK_UNKNOWN) { + result = lookup; + foundKey = true; } } diff --git a/source/glest_game/menu/menu_state_root.cpp b/source/glest_game/menu/menu_state_root.cpp index b5f685b3..9abf4985 100644 --- a/source/glest_game/menu/menu_state_root.cpp +++ b/source/glest_game/menu/menu_state_root.cpp @@ -706,6 +706,7 @@ void MenuStateRoot::keyDown(SDL_KeyboardEvent key) { Config &configKeys = Config::getInstance(std::pair(cfgMainKeys,cfgUserKeys)); //exit //if(key == configKeys.getCharKey("ExitKey")) { + //printf("Check Root menu exit key!\n"); if(isKeyPressed(configKeys.getSDLKey("ExitKey"),key) == true) { Lang &lang= Lang::getInstance(); showMessageBox(lang.getString("ExitGameQuestion"), "", true); diff --git a/source/shared_lib/sources/platform/sdl/window.cpp b/source/shared_lib/sources/platform/sdl/window.cpp index 25f97f7a..027d9dbe 100644 --- a/source/shared_lib/sources/platform/sdl/window.cpp +++ b/source/shared_lib/sources/platform/sdl/window.cpp @@ -166,6 +166,7 @@ bool Window::handleEvent() { //codeLocation = "b"; + SDL_StartTextInput(); while(SDL_PollEvent(&event)) { try { codeLocation = "c"; @@ -235,6 +236,7 @@ bool Window::handleEvent() { } break; } + case SDL_KEYDOWN: //printf("In [%s::%s] Line :%d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__); @@ -681,7 +683,8 @@ bool isKeyPressed(SDL_Keycode compareKey, SDL_KeyboardEvent input,bool modifiers return result; } bool isKeyPressed(SDL_Keycode compareKey, SDL_KeyboardEvent input,vector modifiersToCheck) { - Uint16 c = SDLK_UNKNOWN; + //Uint16 c = SDLK_UNKNOWN; + SDL_Keycode c = SDLK_UNKNOWN; //if(input.keysym.unicode > 0 && input.keysym.unicode < 0x80) { if(input.keysym.sym > 0) { c = input.keysym.sym; @@ -780,6 +783,8 @@ bool isKeyPressed(SDL_Keycode compareKey, SDL_KeyboardEvent input,vector mo } bool result = (c == compareKey); + //printf("result = %d input = %d compare = %d\n",result,c,compareKey); + if(result == false) { if(compareKey == SDLK_RETURN) { result = (c == SDLK_KP_ENTER); @@ -963,7 +968,7 @@ SDL_Keycode extractKeyPressed(SDL_KeyboardEvent input) { if(input.keysym.sym > 0) { if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] input.keysym.sym = %d input.keysym.mod = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,input.keysym.sym,input.keysym.mod); - c = (SDL_Keycode)input.keysym.sym; + c = input.keysym.sym; // if(c <= SDLK_UNKNOWN || c >= SDLK_LAST) { // c = SDLKey(c & 0xFF); // } @@ -983,7 +988,7 @@ SDL_Keycode extractKeyPressed(SDL_KeyboardEvent input) { if(SystemFlags::VERBOSE_MODE_ENABLED) printf ("In [%s::%s Line: %d] returning key [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,c); if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] returning key [%d]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,c); - string pressKeyName = SDL_GetKeyName((SDL_Keycode)c); + string pressKeyName = SDL_GetKeyName(c); //string inputKeyName = SDL_GetKeyName(input.keysym.sym); //printf ("PRESS pressed key [%d - %s] input.keysym.sym [%d] input.keysym.unicode [%d] mod = %d\n",