X-Git-Url: https://git.librecmc.org/?a=blobdiff_plain;f=src%2Fkeycode.cpp;h=890c97cc27a875e123a60b6c6bb9b9e1c0722406;hb=8852333eb3042580592ade478e5def20f8ed5d4c;hp=30d1dd5a283997aff0601afd5a413955a1899784;hpb=037b2591971d752e67fa7d47095b996b3f56da5a;p=oweals%2Fminetest.git diff --git a/src/keycode.cpp b/src/keycode.cpp index 30d1dd5a2..890c97cc2 100644 --- a/src/keycode.cpp +++ b/src/keycode.cpp @@ -1,6 +1,6 @@ /* -Minetest-c55 -Copyright (C) 2010-2011 celeron55, Perttu Ahola +Minetest +Copyright (C) 2010-2013 celeron55, Perttu Ahola This program is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by @@ -21,6 +21,8 @@ with this program; if not, write to the Free Software Foundation, Inc., #include "main.h" // For g_settings #include "exceptions.h" #include "settings.h" +#include "log.h" +#include "hex.h" class UnknownKeycode : public BaseException { @@ -258,9 +260,10 @@ KeyPress::KeyPress(const char *name) try { Key = keyname_to_keycode(name); m_name = name; - if (strlen(name) > 8) - mbtowc(&Char, name + 8, 1); - else + if (strlen(name) > 8 && strncmp(name, "KEY_KEY_", 8) == 0) { + int chars_read = mbtowc(&Char, name + 8, 1); + assert (chars_read == 1 && "unexpected multibyte character"); + } else Char = L'\0'; return; } catch (UnknownKeycode &e) {}; @@ -270,7 +273,8 @@ KeyPress::KeyPress(const char *name) m_name += name; try { Key = keyname_to_keycode(m_name.c_str()); - mbtowc(&Char, name, 1); + int chars_read = mbtowc(&Char, name, 1); + assert (chars_read == 1 && "unexpected multibyte character"); return; } catch (UnknownKeycode &e) {}; } @@ -279,20 +283,35 @@ KeyPress::KeyPress(const char *name) Key = irr::KEY_KEY_CODES_COUNT; - mbtowc(&Char, name, 1); + int mbtowc_ret = mbtowc(&Char, name, 1); + assert (mbtowc_ret == 1 && "unexpected multibyte character"); m_name = name[0]; } -KeyPress::KeyPress(const irr::SEvent::SKeyInput &in) +KeyPress::KeyPress(const irr::SEvent::SKeyInput &in, bool prefer_character) { Key = in.Key; Char = in.Char; + + if(prefer_character){ + m_name.resize(MB_CUR_MAX+1, '\0'); + int written = wctomb(&m_name[0], Char); + if(written > 0){ + infostream<<"KeyPress: Preferring character for "< g_key_setting_cache; +std::map g_key_setting_cache; KeyPress getKeySetting(const char *settingname) { - core::map::Node *n; + std::map::iterator n; n = g_key_setting_cache.find(settingname); - if(n) - return n->getValue(); - g_key_setting_cache.insert(settingname, - g_settings->get(settingname).c_str()); - return g_key_setting_cache.find(settingname)->getValue(); + if(n != g_key_setting_cache.end()) + return n->second; + g_key_setting_cache[settingname] = g_settings->get(settingname).c_str(); + return g_key_setting_cache.find(settingname)->second; } void clearKeyCache()