summaryrefslogtreecommitdiff
path: root/src/citra/emu_window/emu_window_glfw.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/citra/emu_window/emu_window_glfw.cpp')
-rw-r--r--src/citra/emu_window/emu_window_glfw.cpp51
1 files changed, 36 insertions, 15 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
15EmuWindow_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
14void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods) { 20void 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
37void EmuWindow_GLFW::GetFramebufferSize(int* fbWidth, int* fbHeight) { 38void 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
45void 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}