From dd73217ae388a74f0c4d000ef52edd0f2b7fa64c Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 8 Mar 2015 03:19:33 -0400 Subject: GLFW: Implemented EmuWindow touchpad support. --- src/citra/emu_window/emu_window_glfw.cpp | 22 ++++++++++++++++++++++ src/citra/emu_window/emu_window_glfw.h | 4 ++++ 2 files changed, 26 insertions(+) (limited to 'src/citra') diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp index 81231e1e5..8a0cd9b5a 100644 --- a/src/citra/emu_window/emu_window_glfw.cpp +++ b/src/citra/emu_window/emu_window_glfw.cpp @@ -16,6 +16,26 @@ EmuWindow_GLFW* EmuWindow_GLFW::GetEmuWindow(GLFWwindow* win) { return static_cast(glfwGetWindowUserPointer(win)); } +void EmuWindow_GLFW::OnMouseButtonEvent(GLFWwindow* window, int button, int action, int mods) { + if (button == GLFW_MOUSE_BUTTON_LEFT) { + auto layout = GetEmuWindow(window)->GetFramebufferLayout(); + double x, y; + glfwGetCursorPos(window, &x, &y); + + if (action == GLFW_PRESS) { + EmuWindow::TouchPressed(layout, static_cast(x), static_cast(y)); + } else if (action == GLFW_RELEASE) { + EmuWindow::TouchReleased(layout, static_cast(x), static_cast(y)); + } + } +} + +void EmuWindow_GLFW::OnCursorPosEvent(GLFWwindow* window, double x, double y) { + + auto layout = GetEmuWindow(window)->GetFramebufferLayout(); + EmuWindow::TouchMoved(layout, static_cast(x), static_cast(y)); +} + /// Called by GLFW when a key event occurs void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods) { @@ -88,6 +108,8 @@ EmuWindow_GLFW::EmuWindow_GLFW() { // Setup callbacks glfwSetKeyCallback(m_render_window, OnKeyEvent); + glfwSetMouseButtonCallback(m_render_window, OnMouseButtonEvent); + glfwSetCursorPosCallback(m_render_window, OnCursorPosEvent); glfwSetFramebufferSizeCallback(m_render_window, OnFramebufferResizeEvent); glfwSetWindowSizeCallback(m_render_window, OnClientAreaResizeEvent); diff --git a/src/citra/emu_window/emu_window_glfw.h b/src/citra/emu_window/emu_window_glfw.h index 5252fccc8..16c109b79 100644 --- a/src/citra/emu_window/emu_window_glfw.h +++ b/src/citra/emu_window/emu_window_glfw.h @@ -27,6 +27,10 @@ public: static void OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods); + static void OnMouseButtonEvent(GLFWwindow* window, int button, int action, int mods); + + static void OnCursorPosEvent(GLFWwindow* window, double x, double y); + /// Whether the window is still open, and a close request hasn't yet been sent const bool IsOpen(); -- cgit v1.2.3 From 953e09ddb5cab8f4d8606966020e8eefa20e04ce Mon Sep 17 00:00:00 2001 From: bunnei Date: Sun, 8 Mar 2015 21:45:45 -0400 Subject: EmuWindow: Made pad/touch functions non-static. --- src/citra/emu_window/emu_window_glfw.cpp | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) (limited to 'src/citra') diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp index 8a0cd9b5a..3e58d6663 100644 --- a/src/citra/emu_window/emu_window_glfw.cpp +++ b/src/citra/emu_window/emu_window_glfw.cpp @@ -16,35 +16,36 @@ EmuWindow_GLFW* EmuWindow_GLFW::GetEmuWindow(GLFWwindow* win) { return static_cast(glfwGetWindowUserPointer(win)); } -void EmuWindow_GLFW::OnMouseButtonEvent(GLFWwindow* window, int button, int action, int mods) { +void EmuWindow_GLFW::OnMouseButtonEvent(GLFWwindow* win, int button, int action, int mods) { if (button == GLFW_MOUSE_BUTTON_LEFT) { - auto layout = GetEmuWindow(window)->GetFramebufferLayout(); + auto emu_window = GetEmuWindow(win); + auto layout = emu_window->GetFramebufferLayout(); double x, y; - glfwGetCursorPos(window, &x, &y); + glfwGetCursorPos(win, &x, &y); if (action == GLFW_PRESS) { - EmuWindow::TouchPressed(layout, static_cast(x), static_cast(y)); + emu_window->TouchPressed(layout, static_cast(x), static_cast(y)); } else if (action == GLFW_RELEASE) { - EmuWindow::TouchReleased(layout, static_cast(x), static_cast(y)); + emu_window->TouchReleased(layout, static_cast(x), static_cast(y)); } } } -void EmuWindow_GLFW::OnCursorPosEvent(GLFWwindow* window, double x, double y) { - - auto layout = GetEmuWindow(window)->GetFramebufferLayout(); - EmuWindow::TouchMoved(layout, static_cast(x), static_cast(y)); +void EmuWindow_GLFW::OnCursorPosEvent(GLFWwindow* win, double x, double y) { + auto emu_window = GetEmuWindow(win); + auto layout = emu_window->GetFramebufferLayout(); + emu_window->TouchMoved(layout, static_cast(x), static_cast(y)); } /// Called by GLFW when a key event occurs void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods) { - - int keyboard_id = GetEmuWindow(win)->keyboard_id; + auto emu_window = GetEmuWindow(win); + int keyboard_id = emu_window->keyboard_id; if (action == GLFW_PRESS) { - EmuWindow::KeyPressed({key, keyboard_id}); + emu_window->KeyPressed({key, keyboard_id}); } else if (action == GLFW_RELEASE) { - EmuWindow::KeyReleased({key, keyboard_id}); + emu_window->KeyReleased({ key, keyboard_id }); } Service::HID::PadUpdateComplete(); -- cgit v1.2.3 From d61b26b79f889603a084e148626bba3c267cf75f Mon Sep 17 00:00:00 2001 From: bunnei Date: Mon, 9 Mar 2015 00:14:59 -0400 Subject: HID: Complete refactor of pad/touch input to fix threading issues. --- src/citra/emu_window/emu_window_glfw.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) (limited to 'src/citra') diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp index 3e58d6663..997e3bc7d 100644 --- a/src/citra/emu_window/emu_window_glfw.cpp +++ b/src/citra/emu_window/emu_window_glfw.cpp @@ -23,18 +23,15 @@ void EmuWindow_GLFW::OnMouseButtonEvent(GLFWwindow* win, int button, int action, double x, y; glfwGetCursorPos(win, &x, &y); - if (action == GLFW_PRESS) { - emu_window->TouchPressed(layout, static_cast(x), static_cast(y)); - } else if (action == GLFW_RELEASE) { - emu_window->TouchReleased(layout, static_cast(x), static_cast(y)); - } + if (action == GLFW_PRESS) + emu_window->TouchPressed(static_cast(x), static_cast(y)); + else if (action == GLFW_RELEASE) + emu_window->TouchReleased(); } } void EmuWindow_GLFW::OnCursorPosEvent(GLFWwindow* win, double x, double y) { - auto emu_window = GetEmuWindow(win); - auto layout = emu_window->GetFramebufferLayout(); - emu_window->TouchMoved(layout, static_cast(x), static_cast(y)); + GetEmuWindow(win)->TouchMoved(static_cast(x), static_cast(y)); } /// Called by GLFW when a key event occurs @@ -45,10 +42,8 @@ void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int acti if (action == GLFW_PRESS) { emu_window->KeyPressed({key, keyboard_id}); } else if (action == GLFW_RELEASE) { - emu_window->KeyReleased({ key, keyboard_id }); + emu_window->KeyReleased({key, keyboard_id}); } - - Service::HID::PadUpdateComplete(); } /// Whether the window is still open, and a close request hasn't yet been sent -- cgit v1.2.3