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.cpp168
1 files changed, 0 insertions, 168 deletions
diff --git a/src/citra/emu_window/emu_window_glfw.cpp b/src/citra/emu_window/emu_window_glfw.cpp
deleted file mode 100644
index 9453b1f48..000000000
--- a/src/citra/emu_window/emu_window_glfw.cpp
+++ /dev/null
@@ -1,168 +0,0 @@
1// Copyright 2014 Citra Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#include <algorithm>
6#include <cstdlib>
7#include <string>
8
9// Let’s use our own GL header, instead of one from GLFW.
10#include <glad/glad.h>
11#define GLFW_INCLUDE_NONE
12#include <GLFW/glfw3.h>
13
14#include "common/assert.h"
15#include "common/key_map.h"
16#include "common/logging/log.h"
17#include "common/scm_rev.h"
18#include "common/string_util.h"
19
20#include "video_core/video_core.h"
21
22#include "core/settings.h"
23#include "core/hle/service/hid/hid.h"
24
25#include "citra/emu_window/emu_window_glfw.h"
26
27EmuWindow_GLFW* EmuWindow_GLFW::GetEmuWindow(GLFWwindow* win) {
28 return static_cast<EmuWindow_GLFW*>(glfwGetWindowUserPointer(win));
29}
30
31void EmuWindow_GLFW::OnMouseButtonEvent(GLFWwindow* win, int button, int action, int mods) {
32 if (button == GLFW_MOUSE_BUTTON_LEFT) {
33 auto emu_window = GetEmuWindow(win);
34 auto layout = emu_window->GetFramebufferLayout();
35 double x, y;
36 glfwGetCursorPos(win, &x, &y);
37
38 if (action == GLFW_PRESS)
39 emu_window->TouchPressed(static_cast<unsigned>(x), static_cast<unsigned>(y));
40 else if (action == GLFW_RELEASE)
41 emu_window->TouchReleased();
42 }
43}
44
45void EmuWindow_GLFW::OnCursorPosEvent(GLFWwindow* win, double x, double y) {
46 GetEmuWindow(win)->TouchMoved(static_cast<unsigned>(std::max(x, 0.0)), static_cast<unsigned>(std::max(y, 0.0)));
47}
48
49/// Called by GLFW when a key event occurs
50void EmuWindow_GLFW::OnKeyEvent(GLFWwindow* win, int key, int scancode, int action, int mods) {
51 auto emu_window = GetEmuWindow(win);
52 int keyboard_id = emu_window->keyboard_id;
53
54 if (action == GLFW_PRESS) {
55 emu_window->KeyPressed({key, keyboard_id});
56 } else if (action == GLFW_RELEASE) {
57 emu_window->KeyReleased({key, keyboard_id});
58 }
59}
60
61/// Whether the window is still open, and a close request hasn't yet been sent
62const bool EmuWindow_GLFW::IsOpen() {
63 return glfwWindowShouldClose(m_render_window) == 0;
64}
65
66void EmuWindow_GLFW::OnFramebufferResizeEvent(GLFWwindow* win, int width, int height) {
67 GetEmuWindow(win)->NotifyFramebufferLayoutChanged(EmuWindow::FramebufferLayout::DefaultScreenLayout(width, height));
68}
69
70void EmuWindow_GLFW::OnClientAreaResizeEvent(GLFWwindow* win, int width, int height) {
71 // NOTE: GLFW provides no proper way to set a minimal window size.
72 // Hence, we just ignore the corresponding EmuWindow hint.
73 OnFramebufferResizeEvent(win, width, height);
74}
75
76/// EmuWindow_GLFW constructor
77EmuWindow_GLFW::EmuWindow_GLFW() {
78 keyboard_id = KeyMap::NewDeviceId();
79
80 ReloadSetKeymaps();
81
82 glfwSetErrorCallback([](int error, const char *desc){
83 LOG_ERROR(Frontend, "GLFW 0x%08x: %s", error, desc);
84 });
85
86 // Initialize the window
87 if(glfwInit() != GL_TRUE) {
88 LOG_CRITICAL(Frontend, "Failed to initialize GLFW! Exiting...");
89 exit(1);
90 }
91 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
92 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 3);
93 // GLFW on OSX requires these window hints to be set to create a 3.2+ GL context.
94 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GL_TRUE);
95 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
96
97 std::string window_title = Common::StringFromFormat("Citra | %s-%s", Common::g_scm_branch, Common::g_scm_desc);
98 m_render_window = glfwCreateWindow(VideoCore::kScreenTopWidth,
99 (VideoCore::kScreenTopHeight + VideoCore::kScreenBottomHeight),
100 window_title.c_str(), nullptr, nullptr);
101
102 if (m_render_window == nullptr) {
103 LOG_CRITICAL(Frontend, "Failed to create GLFW window! Exiting...");
104 exit(1);
105 }
106
107 glfwSetWindowUserPointer(m_render_window, this);
108
109 // Notify base interface about window state
110 int width, height;
111 glfwGetFramebufferSize(m_render_window, &width, &height);
112 OnFramebufferResizeEvent(m_render_window, width, height);
113
114 glfwGetWindowSize(m_render_window, &width, &height);
115 OnClientAreaResizeEvent(m_render_window, width, height);
116
117 // Setup callbacks
118 glfwSetKeyCallback(m_render_window, OnKeyEvent);
119 glfwSetMouseButtonCallback(m_render_window, OnMouseButtonEvent);
120 glfwSetCursorPosCallback(m_render_window, OnCursorPosEvent);
121 glfwSetFramebufferSizeCallback(m_render_window, OnFramebufferResizeEvent);
122 glfwSetWindowSizeCallback(m_render_window, OnClientAreaResizeEvent);
123
124 DoneCurrent();
125}
126
127/// EmuWindow_GLFW destructor
128EmuWindow_GLFW::~EmuWindow_GLFW() {
129 glfwTerminate();
130}
131
132/// Swap buffers to display the next frame
133void EmuWindow_GLFW::SwapBuffers() {
134 glfwSwapBuffers(m_render_window);
135}
136
137/// Polls window events
138void EmuWindow_GLFW::PollEvents() {
139 glfwPollEvents();
140}
141
142/// Makes the GLFW OpenGL context current for the caller thread
143void EmuWindow_GLFW::MakeCurrent() {
144 glfwMakeContextCurrent(m_render_window);
145}
146
147/// Releases (dunno if this is the "right" word) the GLFW context from the caller thread
148void EmuWindow_GLFW::DoneCurrent() {
149 glfwMakeContextCurrent(nullptr);
150}
151
152void EmuWindow_GLFW::ReloadSetKeymaps() {
153 for (int i = 0; i < Settings::NativeInput::NUM_INPUTS; ++i) {
154 KeyMap::SetKeyMapping({Settings::values.input_mappings[Settings::NativeInput::All[i]], keyboard_id}, Service::HID::pad_mapping[i]);
155 }
156}
157
158void EmuWindow_GLFW::OnMinimalClientAreaChangeRequest(const std::pair<unsigned,unsigned>& minimal_size) {
159 std::pair<int,int> current_size;
160 glfwGetWindowSize(m_render_window, &current_size.first, &current_size.second);
161
162 DEBUG_ASSERT((int)minimal_size.first > 0 && (int)minimal_size.second > 0);
163 int new_width = std::max(current_size.first, (int)minimal_size.first);
164 int new_height = std::max(current_size.second, (int)minimal_size.second);
165
166 if (current_size != std::make_pair(new_width, new_height))
167 glfwSetWindowSize(m_render_window, new_width, new_height);
168}