diff options
| author | 2014-10-12 18:14:57 +0200 | |
|---|---|---|
| committer | 2014-11-18 13:09:01 +0100 | |
| commit | bd8f491e4c08e9b9a7b852de0b50c144da8ac8c8 (patch) | |
| tree | b1f350a3506289263c3652f46946baf267cb27f8 /src/citra | |
| parent | Viewport scaling and display density independence (diff) | |
| download | yuzu-bd8f491e4c08e9b9a7b852de0b50c144da8ac8c8.tar.gz yuzu-bd8f491e4c08e9b9a7b852de0b50c144da8ac8c8.tar.xz yuzu-bd8f491e4c08e9b9a7b852de0b50c144da8ac8c8.zip | |
Fixup EmuWindow interface and implementations thereof.
Diffstat (limited to 'src/citra')
| -rw-r--r-- | src/citra/emu_window/emu_window_glfw.cpp | 51 | ||||
| -rw-r--r-- | src/citra/emu_window/emu_window_glfw.h | 13 |
2 files changed, 44 insertions, 20 deletions
diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp index d0f6e9a9e..28aa3450c 100644 --- a/src/citra/emu_window/emu_window_glfw.cpp +++ b/src/citra/emu_window/emu_window_glfw.cpp | |||
| @@ -2,6 +2,8 @@ | |||
| 2 | // Licensed under GPLv2 | 2 | // Licensed under GPLv2 |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include <GLFW/glfw3.h> | ||
| 6 | |||
| 5 | #include "common/common.h" | 7 | #include "common/common.h" |
| 6 | 8 | ||
| 7 | #include "video_core/video_core.h" | 9 | #include "video_core/video_core.h" |
| @@ -10,22 +12,21 @@ | |||
| 10 | 12 | ||
| 11 | #include "citra/emu_window/emu_window_glfw.h" | 13 | #include "citra/emu_window/emu_window_glfw.h" |
| 12 | 14 | ||
| 15 | EmuWindow_GLFW* EmuWindow_GLFW::GetEmuWindow(GLFWwindow* win) { | ||
| 16 | return static_cast<EmuWindow_GLFW*>(glfwGetWindowUserPointer(win)); | ||
| 17 | } | ||
| 18 | |||
| 13 | /// Called by GLFW when a key event occurs | 19 | /// Called by GLFW when a key event occurs |
| 14 | void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods) { | 20 | void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods) { |
| 15 | 21 | ||
| 16 | if (!VideoCore::g_emu_window) { | 22 | int keyboard_id = GetEmuWindow(win)->keyboard_id; |
| 17 | return; | ||
| 18 | } | ||
| 19 | |||
| 20 | int keyboard_id = ((EmuWindow_GLFW*)VideoCore::g_emu_window)->keyboard_id; | ||
| 21 | 23 | ||
| 22 | if (action == GLFW_PRESS) { | 24 | if (action == GLFW_PRESS) { |
| 23 | EmuWindow::KeyPressed({key, keyboard_id}); | 25 | EmuWindow::KeyPressed({key, keyboard_id}); |
| 24 | } | 26 | } else if (action == GLFW_RELEASE) { |
| 25 | |||
| 26 | if (action == GLFW_RELEASE) { | ||
| 27 | EmuWindow::KeyReleased({key, keyboard_id}); | 27 | EmuWindow::KeyReleased({key, keyboard_id}); |
| 28 | } | 28 | } |
| 29 | |||
| 29 | HID_User::PadUpdateComplete(); | 30 | HID_User::PadUpdateComplete(); |
| 30 | } | 31 | } |
| 31 | 32 | ||
| @@ -34,8 +35,18 @@ const bool EmuWindow_GLFW::IsOpen() { | |||
| 34 | return glfwWindowShouldClose(m_render_window) == 0; | 35 | return glfwWindowShouldClose(m_render_window) == 0; |
| 35 | } | 36 | } |
| 36 | 37 | ||
| 37 | void EmuWindow_GLFW::GetFramebufferSize(int* fbWidth, int* fbHeight) { | 38 | void EmuWindow_GLFW::OnFramebufferResizeEvent(GLFWwindow* win, int width, int height) { |
| 38 | glfwGetFramebufferSize(m_render_window, fbWidth, fbHeight); | 39 | _dbg_assert_(GUI, width > 0); |
| 40 | _dbg_assert_(GUI, height > 0); | ||
| 41 | |||
| 42 | GetEmuWindow(win)->NotifyFramebufferSizeChanged(std::pair<unsigned,unsigned>(width, height)); | ||
| 43 | } | ||
| 44 | |||
| 45 | void EmuWindow_GLFW::OnClientAreaResizeEvent(GLFWwindow* win, int width, int height) { | ||
| 46 | _dbg_assert_(GUI, width > 0); | ||
| 47 | _dbg_assert_(GUI, height > 0); | ||
| 48 | |||
| 49 | GetEmuWindow(win)->NotifyClientAreaSizeChanged(std::pair<unsigned,unsigned>(width, height)); | ||
| 39 | } | 50 | } |
| 40 | 51 | ||
| 41 | /// EmuWindow_GLFW constructor | 52 | /// EmuWindow_GLFW constructor |
| @@ -54,20 +65,30 @@ EmuWindow_GLFW::EmuWindow_GLFW() { | |||
| 54 | // GLFW on OSX requires these window hints to be set to create a 3.2+ GL context. | 65 | // GLFW on OSX requires these window hints to be set to create a 3.2+ GL context. |
| 55 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); | 66 | glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE); |
| 56 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); | 67 | glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE); |
| 57 | 68 | ||
| 58 | m_render_window = glfwCreateWindow(VideoCore::kScreenTopWidth, | 69 | m_render_window = glfwCreateWindow(VideoCore::kScreenTopWidth, |
| 59 | (VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight), | 70 | (VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight), |
| 60 | m_window_title.c_str(), NULL, NULL); | 71 | GetWindowTitle().c_str(), NULL, NULL); |
| 61 | 72 | ||
| 62 | if (m_render_window == NULL) { | 73 | if (m_render_window == NULL) { |
| 63 | printf("Failed to create GLFW window! Exiting..."); | 74 | printf("Failed to create GLFW window! Exiting..."); |
| 64 | exit(1); | 75 | exit(1); |
| 65 | } | 76 | } |
| 66 | 77 | ||
| 67 | // Setup callbacks | ||
| 68 | glfwSetWindowUserPointer(m_render_window, this); | 78 | glfwSetWindowUserPointer(m_render_window, this); |
| 69 | glfwSetKeyCallback(m_render_window, OnKeyEvent); | ||
| 70 | 79 | ||
| 80 | // Notify base interface about window state | ||
| 81 | int width, height; | ||
| 82 | glfwGetFramebufferSize(m_render_window, &width, &height); | ||
| 83 | OnFramebufferResizeEvent(m_render_window, width, height); | ||
| 84 | |||
| 85 | glfwGetWindowSize(m_render_window, &width, &height); | ||
| 86 | OnClientAreaResizeEvent(m_render_window, width, height); | ||
| 87 | |||
| 88 | // Setup callbacks | ||
| 89 | glfwSetKeyCallback(m_render_window, OnKeyEvent); | ||
| 90 | glfwSetFramebufferSizeCallback(m_render_window, OnFramebufferResizeEvent); | ||
| 91 | glfwSetWindowSizeCallback(m_render_window, OnClientAreaResizeEvent); | ||
| 71 | 92 | ||
| 72 | DoneCurrent(); | 93 | DoneCurrent(); |
| 73 | } | 94 | } |
diff --git a/src/citra/emu_window/emu_window_glfw.h b/src/citra/emu_window/emu_window_glfw.h index e96228765..0da688a54 100644 --- a/src/citra/emu_window/emu_window_glfw.h +++ b/src/citra/emu_window/emu_window_glfw.h | |||
| @@ -4,10 +4,10 @@ | |||
| 4 | 4 | ||
| 5 | #pragma once | 5 | #pragma once |
| 6 | 6 | ||
| 7 | #include <GLFW/glfw3.h> | ||
| 8 | |||
| 9 | #include "common/emu_window.h" | 7 | #include "common/emu_window.h" |
| 10 | 8 | ||
| 9 | struct GLFWwindow; | ||
| 10 | |||
| 11 | class EmuWindow_GLFW : public EmuWindow { | 11 | class EmuWindow_GLFW : public EmuWindow { |
| 12 | public: | 12 | public: |
| 13 | EmuWindow_GLFW(); | 13 | EmuWindow_GLFW(); |
| @@ -30,12 +30,15 @@ public: | |||
| 30 | /// Whether the window is still open, and a close request hasn't yet been sent | 30 | /// Whether the window is still open, and a close request hasn't yet been sent |
| 31 | const bool IsOpen(); | 31 | const bool IsOpen(); |
| 32 | 32 | ||
| 33 | void ReloadSetKeymaps() override; | 33 | static void OnClientAreaResizeEvent(GLFWwindow* win, int width, int height); |
| 34 | 34 | ||
| 35 | /// Gets the size of the window in pixels | 35 | static void OnFramebufferResizeEvent(GLFWwindow* win, int width, int height); |
| 36 | void GetFramebufferSize(int* fbWidth, int* fbHeight); | 36 | |
| 37 | void ReloadSetKeymaps() override; | ||
| 37 | 38 | ||
| 38 | private: | 39 | private: |
| 40 | static EmuWindow_GLFW* GetEmuWindow(GLFWwindow* win); | ||
| 41 | |||
| 39 | GLFWwindow* m_render_window; ///< Internal GLFW render window | 42 | GLFWwindow* m_render_window; ///< Internal GLFW render window |
| 40 | 43 | ||
| 41 | /// Device id of keyboard for use with KeyMap | 44 | /// Device id of keyboard for use with KeyMap |