瀏覽代碼

Move keyboard tests to keyboard handler

Ivan Savenko 2 年之前
父節點
當前提交
dc16781877
共有 3 個文件被更改,包括 26 次插入7 次删除
  1. 3 7
      client/eventsSDL/InputHandler.cpp
  2. 19 0
      client/eventsSDL/InputSourceKeyboard.cpp
  3. 4 0
      client/eventsSDL/InputSourceKeyboard.h

+ 3 - 7
client/eventsSDL/InputHandler.cpp

@@ -186,21 +186,17 @@ void InputHandler::fetchEvents()
 
 bool InputHandler::isKeyboardCtrlDown() const
 {
-#ifdef VCMI_MAC
-	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LGUI] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RGUI];
-#else
-	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LCTRL] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RCTRL];
-#endif
+	return keyboardHandler->isKeyboardCtrlDown();
 }
 
 bool InputHandler::isKeyboardAltDown() const
 {
-	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LALT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RALT];
+	return keyboardHandler->isKeyboardAltDown();
 }
 
 bool InputHandler::isKeyboardShiftDown() const
 {
-	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LSHIFT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RSHIFT];
+	return keyboardHandler->isKeyboardShiftDown();
 }
 
 void InputHandler::moveCursorPosition(const Point & distance)

+ 19 - 0
client/eventsSDL/InputSourceKeyboard.cpp

@@ -83,3 +83,22 @@ void InputSourceKeyboard::handleEventKeyUp(const SDL_KeyboardEvent & key)
 
 	GH.events().dispatchShortcutReleased(shortcutsVector);
 }
+
+bool InputSourceKeyboard::isKeyboardCtrlDown() const
+{
+#ifdef VCMI_MAC
+	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LGUI] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RGUI];
+#else
+	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LCTRL] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RCTRL];
+#endif
+}
+
+bool InputSourceKeyboard::isKeyboardAltDown() const
+{
+	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LALT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RALT];
+}
+
+bool InputSourceKeyboard::isKeyboardShiftDown() const
+{
+	return SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_LSHIFT] || SDL_GetKeyboardState(nullptr)[SDL_SCANCODE_RSHIFT];
+}

+ 4 - 0
client/eventsSDL/InputSourceKeyboard.h

@@ -20,4 +20,8 @@ public:
 
 	void handleEventKeyDown(const SDL_KeyboardEvent & current);
 	void handleEventKeyUp(const SDL_KeyboardEvent & current);
+
+	bool isKeyboardAltDown() const;
+	bool isKeyboardCtrlDown() const;
+	bool isKeyboardShiftDown() const;
 };