diff options
| author | 2014-09-12 17:44:25 -0400 | |
|---|---|---|
| committer | 2014-09-12 17:44:25 -0400 | |
| commit | cbdf4d4c8e11f8d1503b440eee1ed2d5f144a73f (patch) | |
| tree | c9c95671835d73b5ca7e52029de5bb27832e11a3 /src/citra/emu_window/emu_window_glfw.cpp | |
| parent | Merge pull request #99 from archshift/ext-check (diff) | |
| parent | Added support for multiple input device types for KeyMap and connected Qt. (diff) | |
| download | yuzu-cbdf4d4c8e11f8d1503b440eee1ed2d5f144a73f.tar.gz yuzu-cbdf4d4c8e11f8d1503b440eee1ed2d5f144a73f.tar.xz yuzu-cbdf4d4c8e11f8d1503b440eee1ed2d5f144a73f.zip | |
Merge pull request #105 from kevinhartman/hid
Digital user input and HID module implementation for PAD
Diffstat (limited to 'src/citra/emu_window/emu_window_glfw.cpp')
| -rw-r--r-- | src/citra/emu_window/emu_window_glfw.cpp | 54 |
1 files changed, 45 insertions, 9 deletions
diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp index 02f524e03..b911e60c5 100644 --- a/src/citra/emu_window/emu_window_glfw.cpp +++ b/src/citra/emu_window/emu_window_glfw.cpp | |||
| @@ -8,18 +8,55 @@ | |||
| 8 | 8 | ||
| 9 | #include "citra/emu_window/emu_window_glfw.h" | 9 | #include "citra/emu_window/emu_window_glfw.h" |
| 10 | 10 | ||
| 11 | static void OnKeyEvent(GLFWwindow* win, int key, int action) { | 11 | static const std::pair<int, HID_User::PadState> default_key_map[] = { |
| 12 | // TODO(bunnei): ImplementMe | 12 | { GLFW_KEY_A, HID_User::PAD_A }, |
| 13 | } | 13 | { GLFW_KEY_B, HID_User::PAD_B }, |
| 14 | { GLFW_KEY_BACKSLASH, HID_User::PAD_SELECT }, | ||
| 15 | { GLFW_KEY_ENTER, HID_User::PAD_START }, | ||
| 16 | { GLFW_KEY_RIGHT, HID_User::PAD_RIGHT }, | ||
| 17 | { GLFW_KEY_LEFT, HID_User::PAD_LEFT }, | ||
| 18 | { GLFW_KEY_UP, HID_User::PAD_UP }, | ||
| 19 | { GLFW_KEY_DOWN, HID_User::PAD_DOWN }, | ||
| 20 | { GLFW_KEY_R, HID_User::PAD_R }, | ||
| 21 | { GLFW_KEY_L, HID_User::PAD_L }, | ||
| 22 | { GLFW_KEY_X, HID_User::PAD_X }, | ||
| 23 | { GLFW_KEY_Y, HID_User::PAD_Y }, | ||
| 24 | { GLFW_KEY_H, HID_User::PAD_CIRCLE_RIGHT }, | ||
| 25 | { GLFW_KEY_F, HID_User::PAD_CIRCLE_LEFT }, | ||
| 26 | { GLFW_KEY_T, HID_User::PAD_CIRCLE_UP }, | ||
| 27 | { GLFW_KEY_G, HID_User::PAD_CIRCLE_DOWN }, | ||
| 28 | }; | ||
| 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; | ||
| 38 | |||
| 39 | if (action == GLFW_PRESS) { | ||
| 40 | EmuWindow::KeyPressed({key, keyboard_id}); | ||
| 41 | } | ||
| 14 | 42 | ||
| 15 | static void OnWindowSizeEvent(GLFWwindow* win, int width, int height) { | 43 | if (action == GLFW_RELEASE) { |
| 16 | EmuWindow_GLFW* emu_window = (EmuWindow_GLFW*)glfwGetWindowUserPointer(win); | 44 | EmuWindow::KeyReleased({key, keyboard_id}); |
| 17 | emu_window->SetClientAreaWidth(width); | 45 | } |
| 18 | emu_window->SetClientAreaHeight(height); | 46 | HID_User::PadUpdateComplete(); |
| 19 | } | 47 | } |
| 20 | 48 | ||
| 21 | /// EmuWindow_GLFW constructor | 49 | /// EmuWindow_GLFW constructor |
| 22 | EmuWindow_GLFW::EmuWindow_GLFW() { | 50 | EmuWindow_GLFW::EmuWindow_GLFW() { |
| 51 | |||
| 52 | // Register a new ID for the default keyboard | ||
| 53 | keyboard_id = KeyMap::NewDeviceId(); | ||
| 54 | |||
| 55 | // Set default key mappings for keyboard | ||
| 56 | for (auto mapping : default_key_map) { | ||
| 57 | KeyMap::SetKeyMapping({mapping.first, keyboard_id}, mapping.second); | ||
| 58 | } | ||
| 59 | |||
| 23 | // Initialize the window | 60 | // Initialize the window |
| 24 | if(glfwInit() != GL_TRUE) { | 61 | if(glfwInit() != GL_TRUE) { |
| 25 | printf("Failed to initialize GLFW! Exiting..."); | 62 | printf("Failed to initialize GLFW! Exiting..."); |
| @@ -45,8 +82,7 @@ EmuWindow_GLFW::EmuWindow_GLFW() { | |||
| 45 | 82 | ||
| 46 | // Setup callbacks | 83 | // Setup callbacks |
| 47 | glfwSetWindowUserPointer(m_render_window, this); | 84 | glfwSetWindowUserPointer(m_render_window, this); |
| 48 | //glfwSetKeyCallback(m_render_window, OnKeyEvent); | 85 | glfwSetKeyCallback(m_render_window, OnKeyEvent); |
| 49 | //glfwSetWindowSizeCallback(m_render_window, OnWindowSizeEvent); | ||
| 50 | 86 | ||
| 51 | DoneCurrent(); | 87 | DoneCurrent(); |
| 52 | } | 88 | } |