فهرست منبع

Do not distinguish between upper/lower case

Daniele Bartolini 11 سال پیش
والد
کامیت
ad8ffa7758
4فایلهای تغییر یافته به همراه52 افزوده شده و 78 حذف شده
  1. 14 27
      engine/input/key_code.h
  2. 0 12
      engine/input/keyboard.h
  3. 0 28
      engine/lua/lua_keyboard.cpp
  4. 38 11
      engine/main/main_linux.cpp

+ 14 - 27
engine/input/key_code.h

@@ -29,7 +29,20 @@ OTHER DEALINGS IN THE SOFTWARE.
 namespace crown
 {
 
-/// Uniquely identifies a button on the keyboard.
+/// Enumerates keyboard modifier buttons.
+///
+/// @ingroup Input
+struct ModifierButton
+{
+	enum Enum
+	{
+		SHIFT	= 1,
+		CTRL	= 2,
+		ALT		= 4
+	};
+};
+
+/// Enumerates keyboard buttons.
 ///
 /// @ingroup Input
 struct KeyboardButton
@@ -131,32 +144,6 @@ struct KeyboardButton
 		Z			= 0x5A,
 
 		/* [0x61, 0x7A] reserved for ASCII alphabet */
-		a			= 0x61,
-		b			= 0x62,
-		c			= 0x63,
-		d			= 0x64,
-		e			= 0x65,
-		f			= 0x66,
-		g			= 0x67,
-		h			= 0x68,
-		i			= 0x69,
-		j			= 0x6A,
-		k			= 0x6B,
-		l			= 0x6C,
-		m			= 0x6D,
-		n			= 0x6E,
-		o			= 0x6F,
-		p			= 0x70,
-		q			= 0x71,
-		r			= 0x72,
-		s			= 0x73,
-		t			= 0x74,
-		u			= 0x75,
-		v			= 0x76,
-		w			= 0x77,
-		x			= 0x78,
-		y			= 0x79,
-		z			= 0x7A,
 
 		// The last key _must_ be <= 0xFF
 		COUNT		= 0xFF

+ 0 - 12
engine/input/keyboard.h

@@ -32,18 +32,6 @@ OTHER DEALINGS IN THE SOFTWARE.
 
 namespace crown
 {
-/// Enumerates modifier keys.
-///
-/// @ingroup Input
-struct ModifierButton
-{
-	enum Enum
-	{
-		SHIFT	= 1,
-		CTRL	= 2,
-		ALT		= 4
-	};
-};
 
 /// Interface for accessing keyboard input device.
 ///

+ 0 - 28
engine/lua/lua_keyboard.cpp

@@ -174,34 +174,6 @@ void load_keyboard(LuaEnvironment& env)
 	env.load_module_enum("Keyboard", "X",			KeyboardButton::X);
 	env.load_module_enum("Keyboard", "Y",			KeyboardButton::Y);
 	env.load_module_enum("Keyboard", "Z",			KeyboardButton::Z);
-
-	/* [0x61, 0x7A] reserved for ASCII alphabet */
-	env.load_module_enum("Keyboard", "a",			KeyboardButton::a);
-	env.load_module_enum("Keyboard", "b",			KeyboardButton::b);
-	env.load_module_enum("Keyboard", "c",			KeyboardButton::c);
-	env.load_module_enum("Keyboard", "d",			KeyboardButton::d);
-	env.load_module_enum("Keyboard", "e",			KeyboardButton::e);
-	env.load_module_enum("Keyboard", "f",			KeyboardButton::f);
-	env.load_module_enum("Keyboard", "g",			KeyboardButton::g);
-	env.load_module_enum("Keyboard", "h",			KeyboardButton::h);
-	env.load_module_enum("Keyboard", "i",			KeyboardButton::i);
-	env.load_module_enum("Keyboard", "j",			KeyboardButton::j);
-	env.load_module_enum("Keyboard", "k",			KeyboardButton::k);
-	env.load_module_enum("Keyboard", "l",			KeyboardButton::l);
-	env.load_module_enum("Keyboard", "m",			KeyboardButton::m);
-	env.load_module_enum("Keyboard", "n",			KeyboardButton::n);
-	env.load_module_enum("Keyboard", "o",			KeyboardButton::o);
-	env.load_module_enum("Keyboard", "p",			KeyboardButton::p);
-	env.load_module_enum("Keyboard", "q",			KeyboardButton::q);
-	env.load_module_enum("Keyboard", "r",			KeyboardButton::r);
-	env.load_module_enum("Keyboard", "s",			KeyboardButton::s);
-	env.load_module_enum("Keyboard", "t",			KeyboardButton::t);
-	env.load_module_enum("Keyboard", "u",			KeyboardButton::u);
-	env.load_module_enum("Keyboard", "v",			KeyboardButton::v);
-	env.load_module_enum("Keyboard", "w",			KeyboardButton::w);
-	env.load_module_enum("Keyboard", "x",			KeyboardButton::x);
-	env.load_module_enum("Keyboard", "y",			KeyboardButton::y);
-	env.load_module_enum("Keyboard", "z",			KeyboardButton::z);
 }
 
 } // namespace crown

+ 38 - 11
engine/main/main_linux.cpp

@@ -101,11 +101,6 @@ namespace crown
 //-----------------------------------------------------------------------------
 static KeyboardButton::Enum x11_translate_key(KeySym x11_key)
 {
-	if ((x11_key > 0x40 && x11_key < 0x5B) || (x11_key > 0x60 && x11_key < 0x7B) || (x11_key > 0x2F && x11_key < 0x3A))
-	{
-		return (KeyboardButton::Enum) x11_key;
-	}
-
 	switch (x11_key)
 	{
 		case XK_BackSpace:	return KeyboardButton::BACKSPACE;
@@ -151,6 +146,42 @@ static KeyboardButton::Enum x11_translate_key(KeySym x11_key)
 		case XK_KP_7:		return KeyboardButton::KP_7;
 		case XK_KP_8:		return KeyboardButton::KP_8;
 		case XK_KP_9:		return KeyboardButton::KP_9;
+		case '0':			return KeyboardButton::NUM_0;
+		case '1':			return KeyboardButton::NUM_1;
+		case '2':			return KeyboardButton::NUM_2;
+		case '3':			return KeyboardButton::NUM_3;
+		case '4':			return KeyboardButton::NUM_4;
+		case '5':			return KeyboardButton::NUM_5;
+		case '6':			return KeyboardButton::NUM_6;
+		case '7':			return KeyboardButton::NUM_7;
+		case '8':			return KeyboardButton::NUM_8;
+		case '9':			return KeyboardButton::NUM_9;
+		case 'a':			return KeyboardButton::A;
+		case 'b':			return KeyboardButton::B;
+		case 'c':			return KeyboardButton::C;
+		case 'd':			return KeyboardButton::D;
+		case 'e':			return KeyboardButton::E;
+		case 'f':			return KeyboardButton::F;
+		case 'g':			return KeyboardButton::G;
+		case 'h':			return KeyboardButton::H;
+		case 'i':			return KeyboardButton::I;
+		case 'j':			return KeyboardButton::J;
+		case 'k':			return KeyboardButton::K;
+		case 'l':			return KeyboardButton::L;
+		case 'm':			return KeyboardButton::M;
+		case 'n':			return KeyboardButton::N;
+		case 'o':			return KeyboardButton::O;
+		case 'p':			return KeyboardButton::P;
+		case 'q':			return KeyboardButton::Q;
+		case 'r':			return KeyboardButton::R;
+		case 's':			return KeyboardButton::S;
+		case 't':			return KeyboardButton::T;
+		case 'u':			return KeyboardButton::U;
+		case 'v':			return KeyboardButton::V;
+		case 'w':			return KeyboardButton::W;
+		case 'x':			return KeyboardButton::X;
+		case 'y':			return KeyboardButton::Y;
+		case 'z':			return KeyboardButton::Z;
 		default:			return KeyboardButton::NONE;
 	}
 }
@@ -345,12 +376,8 @@ struct LinuxDevice
 				case KeyPress:
 				case KeyRelease:
 				{
-					char string[4] = {0, 0, 0, 0};
-					KeySym key;
-
-					XLookupString(&event.xkey, string, 4, &key, NULL);
-
-					KeyboardButton::Enum kb = x11_translate_key(key);
+					KeySym keysym = XLookupKeysym(&event.xkey, 0);
+					KeyboardButton::Enum kb = x11_translate_key(keysym);
 
 					// Check if any modifier key is pressed or released
 					int32_t modifier_mask = 0;