diff options
| author | 2014-09-08 21:46:02 -0700 | |
|---|---|---|
| committer | 2014-09-12 01:15:14 -0700 | |
| commit | 02fd19b2f60f4db8a683734e4300d7498c861309 (patch) | |
| tree | c9c95671835d73b5ca7e52029de5bb27832e11a3 /src/citra | |
| parent | Initial HID PAD work, with GLFW only. (diff) | |
| download | yuzu-02fd19b2f60f4db8a683734e4300d7498c861309.tar.gz yuzu-02fd19b2f60f4db8a683734e4300d7498c861309.tar.xz yuzu-02fd19b2f60f4db8a683734e4300d7498c861309.zip | |
Added support for multiple input device types for KeyMap and connected Qt.
Diffstat (limited to 'src/citra')
| -rw-r--r-- | src/citra/emu_window/emu_window_glfw.cpp | 65 | ||||
| -rw-r--r-- | src/citra/emu_window/emu_window_glfw.h | 5 |
2 files changed, 37 insertions, 33 deletions
diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp index 0a861cff0..b911e60c5 100644 --- a/src/citra/emu_window/emu_window_glfw.cpp +++ b/src/citra/emu_window/emu_window_glfw.cpp | |||
| @@ -8,49 +8,53 @@ | |||
| 8 | 8 | ||
| 9 | #include "citra/emu_window/emu_window_glfw.h" | 9 | #include "citra/emu_window/emu_window_glfw.h" |
| 10 | 10 | ||
| 11 | static const KeyMap::DefaultKeyMapping default_key_map[] = { | 11 | static const std::pair<int, HID_User::PadState> default_key_map[] = { |
| 12 | { KeyMap::CitraKey(GLFW_KEY_A), HID_User::PAD_A }, | 12 | { GLFW_KEY_A, HID_User::PAD_A }, |
| 13 | { KeyMap::CitraKey(GLFW_KEY_B), HID_User::PAD_B }, | 13 | { GLFW_KEY_B, HID_User::PAD_B }, |
| 14 | { KeyMap::CitraKey(GLFW_KEY_BACKSLASH), HID_User::PAD_SELECT }, | 14 | { GLFW_KEY_BACKSLASH, HID_User::PAD_SELECT }, |
| 15 | { KeyMap::CitraKey(GLFW_KEY_ENTER), HID_User::PAD_START }, | 15 | { GLFW_KEY_ENTER, HID_User::PAD_START }, |
| 16 | { KeyMap::CitraKey(GLFW_KEY_RIGHT), HID_User::PAD_RIGHT }, | 16 | { GLFW_KEY_RIGHT, HID_User::PAD_RIGHT }, |
| 17 | { KeyMap::CitraKey(GLFW_KEY_LEFT), HID_User::PAD_LEFT }, | 17 | { GLFW_KEY_LEFT, HID_User::PAD_LEFT }, |
| 18 | { KeyMap::CitraKey(GLFW_KEY_UP), HID_User::PAD_UP }, | 18 | { GLFW_KEY_UP, HID_User::PAD_UP }, |
| 19 | { KeyMap::CitraKey(GLFW_KEY_DOWN), HID_User::PAD_DOWN }, | 19 | { GLFW_KEY_DOWN, HID_User::PAD_DOWN }, |
| 20 | { KeyMap::CitraKey(GLFW_KEY_R), HID_User::PAD_R }, | 20 | { GLFW_KEY_R, HID_User::PAD_R }, |
| 21 | { KeyMap::CitraKey(GLFW_KEY_L), HID_User::PAD_L }, | 21 | { GLFW_KEY_L, HID_User::PAD_L }, |
| 22 | { KeyMap::CitraKey(GLFW_KEY_X), HID_User::PAD_X }, | 22 | { GLFW_KEY_X, HID_User::PAD_X }, |
| 23 | { KeyMap::CitraKey(GLFW_KEY_Y), HID_User::PAD_Y }, | 23 | { GLFW_KEY_Y, HID_User::PAD_Y }, |
| 24 | { KeyMap::CitraKey(GLFW_KEY_H), HID_User::PAD_CIRCLE_RIGHT }, | 24 | { GLFW_KEY_H, HID_User::PAD_CIRCLE_RIGHT }, |
| 25 | { KeyMap::CitraKey(GLFW_KEY_F), HID_User::PAD_CIRCLE_LEFT }, | 25 | { GLFW_KEY_F, HID_User::PAD_CIRCLE_LEFT }, |
| 26 | { KeyMap::CitraKey(GLFW_KEY_T), HID_User::PAD_CIRCLE_UP }, | 26 | { GLFW_KEY_T, HID_User::PAD_CIRCLE_UP }, |
| 27 | { KeyMap::CitraKey(GLFW_KEY_G), HID_User::PAD_CIRCLE_DOWN }, | 27 | { GLFW_KEY_G, HID_User::PAD_CIRCLE_DOWN }, |
| 28 | }; | 28 | }; |
| 29 | 29 | ||
| 30 | /// Called by GLFW when a key event occurs | ||
| 31 | void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods) { | ||
| 32 | |||
| 33 | if (!VideoCore::g_emu_window) { | ||
| 34 | return; | ||
| 35 | } | ||
| 36 | |||
| 37 | int keyboard_id = ((EmuWindow_GLFW*)VideoCore::g_emu_window)->keyboard_id; | ||
| 30 | 38 | ||
| 31 | static void OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods) { | ||
| 32 | if (action == GLFW_PRESS) { | 39 | if (action == GLFW_PRESS) { |
| 33 | EmuWindow::KeyPressed(KeyMap::CitraKey(key)); | 40 | EmuWindow::KeyPressed({key, keyboard_id}); |
| 34 | } | 41 | } |
| 35 | 42 | ||
| 36 | if (action == GLFW_RELEASE) { | 43 | if (action == GLFW_RELEASE) { |
| 37 | EmuWindow::KeyReleased(KeyMap::CitraKey(key)); | 44 | EmuWindow::KeyReleased({key, keyboard_id}); |
| 38 | } | 45 | } |
| 39 | HID_User::PADUpdateComplete(); | 46 | HID_User::PadUpdateComplete(); |
| 40 | } | ||
| 41 | |||
| 42 | static void OnWindowSizeEvent(GLFWwindow* win, int width, int height) { | ||
| 43 | EmuWindow_GLFW* emu_window = (EmuWindow_GLFW*)glfwGetWindowUserPointer(win); | ||
| 44 | emu_window->SetClientAreaWidth(width); | ||
| 45 | emu_window->SetClientAreaHeight(height); | ||
| 46 | } | 47 | } |
| 47 | 48 | ||
| 48 | /// EmuWindow_GLFW constructor | 49 | /// EmuWindow_GLFW constructor |
| 49 | EmuWindow_GLFW::EmuWindow_GLFW() { | 50 | EmuWindow_GLFW::EmuWindow_GLFW() { |
| 50 | 51 | ||
| 51 | // Set default key mappings | 52 | // Register a new ID for the default keyboard |
| 52 | for (int i = 0; i < ARRAY_SIZE(default_key_map); i++) { | 53 | keyboard_id = KeyMap::NewDeviceId(); |
| 53 | KeyMap::SetKeyMapping(default_key_map[i].key, default_key_map[i].state); | 54 | |
| 55 | // Set default key mappings for keyboard | ||
| 56 | for (auto mapping : default_key_map) { | ||
| 57 | KeyMap::SetKeyMapping({mapping.first, keyboard_id}, mapping.second); | ||
| 54 | } | 58 | } |
| 55 | 59 | ||
| 56 | // Initialize the window | 60 | // Initialize the window |
| @@ -79,7 +83,6 @@ EmuWindow_GLFW::EmuWindow_GLFW() { | |||
| 79 | // Setup callbacks | 83 | // Setup callbacks |
| 80 | glfwSetWindowUserPointer(m_render_window, this); | 84 | glfwSetWindowUserPointer(m_render_window, this); |
| 81 | glfwSetKeyCallback(m_render_window, OnKeyEvent); | 85 | glfwSetKeyCallback(m_render_window, OnKeyEvent); |
| 82 | //glfwSetWindowSizeCallback(m_render_window, OnWindowSizeEvent); | ||
| 83 | 86 | ||
| 84 | DoneCurrent(); | 87 | DoneCurrent(); |
| 85 | } | 88 | } |
diff --git a/src/citra/emu_window/emu_window_glfw.h b/src/citra/emu_window/emu_window_glfw.h index c1b41203b..29325bb75 100644 --- a/src/citra/emu_window/emu_window_glfw.h +++ b/src/citra/emu_window/emu_window_glfw.h | |||
| @@ -25,8 +25,9 @@ public: | |||
| 25 | /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread | 25 | /// Releases (dunno if this is the "right" word) the GLFW context from the caller thread |
| 26 | void DoneCurrent(); | 26 | void DoneCurrent(); |
| 27 | 27 | ||
| 28 | GLFWwindow* m_render_window; ///< Internal GLFW render window | 28 | static void OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods); |
| 29 | 29 | ||
| 30 | private: | 30 | private: |
| 31 | 31 | GLFWwindow* m_render_window; ///< Internal GLFW render window | |
| 32 | int keyboard_id; ///< Device id of keyboard for use with KeyMap | ||
| 32 | }; | 33 | }; |