summaryrefslogtreecommitdiff
path: root/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
diff options
context:
space:
mode:
authorGravatar James Rowe2018-01-11 19:21:20 -0700
committerGravatar James Rowe2018-01-12 19:11:03 -0700
commitebf9a784a9f7f4148a669dbb39e7cd50df779a14 (patch)
treed585685a1c0a34b903af1d086d62560bf56bb29f /src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
parentconfig: Default CPU core to Unicorn. (diff)
downloadyuzu-ebf9a784a9f7f4148a669dbb39e7cd50df779a14.tar.gz
yuzu-ebf9a784a9f7f4148a669dbb39e7cd50df779a14.tar.xz
yuzu-ebf9a784a9f7f4148a669dbb39e7cd50df779a14.zip
Massive removal of unused modules
Diffstat (limited to 'src/yuzu_cmd/emu_window/emu_window_sdl2.cpp')
-rw-r--r--src/yuzu_cmd/emu_window/emu_window_sdl2.cpp177
1 files changed, 177 insertions, 0 deletions
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
new file mode 100644
index 000000000..e65b04e4b
--- /dev/null
+++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp
@@ -0,0 +1,177 @@
1// Copyright 2016 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#define SDL_MAIN_HANDLED
9#include <SDL.h>
10#include <glad/glad.h>
11#include "citra/emu_window/emu_window_sdl2.h"
12#include "common/logging/log.h"
13#include "common/scm_rev.h"
14#include "common/string_util.h"
15#include "core/settings.h"
16#include "input_common/keyboard.h"
17#include "input_common/main.h"
18#include "input_common/motion_emu.h"
19#include "network/network.h"
20
21void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) {
22 TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0));
23 InputCommon::GetMotionEmu()->Tilt(x, y);
24}
25
26void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) {
27 if (button == SDL_BUTTON_LEFT) {
28 if (state == SDL_PRESSED) {
29 TouchPressed((unsigned)std::max(x, 0), (unsigned)std::max(y, 0));
30 } else {
31 TouchReleased();
32 }
33 } else if (button == SDL_BUTTON_RIGHT) {
34 if (state == SDL_PRESSED) {
35 InputCommon::GetMotionEmu()->BeginTilt(x, y);
36 } else {
37 InputCommon::GetMotionEmu()->EndTilt();
38 }
39 }
40}
41
42void EmuWindow_SDL2::OnKeyEvent(int key, u8 state) {
43 if (state == SDL_PRESSED) {
44 InputCommon::GetKeyboard()->PressKey(key);
45 } else if (state == SDL_RELEASED) {
46 InputCommon::GetKeyboard()->ReleaseKey(key);
47 }
48}
49
50bool EmuWindow_SDL2::IsOpen() const {
51 return is_open;
52}
53
54void EmuWindow_SDL2::OnResize() {
55 int width, height;
56 SDL_GetWindowSize(render_window, &width, &height);
57 UpdateCurrentFramebufferLayout(width, height);
58}
59
60EmuWindow_SDL2::EmuWindow_SDL2() {
61 InputCommon::Init();
62 Network::Init();
63
64 SDL_SetMainReady();
65
66 // Initialize the window
67 if (SDL_Init(SDL_INIT_VIDEO) < 0) {
68 LOG_CRITICAL(Frontend, "Failed to initialize SDL2! Exiting...");
69 exit(1);
70 }
71
72 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
73 SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
74 SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
75 SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
76 SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 8);
77 SDL_GL_SetAttribute(SDL_GL_GREEN_SIZE, 8);
78 SDL_GL_SetAttribute(SDL_GL_BLUE_SIZE, 8);
79 SDL_GL_SetAttribute(SDL_GL_ALPHA_SIZE, 0);
80
81 std::string window_title = Common::StringFromFormat("yuzu %s| %s-%s ", Common::g_build_name,
82 Common::g_scm_branch, Common::g_scm_desc);
83 render_window =
84 SDL_CreateWindow(window_title.c_str(),
85 SDL_WINDOWPOS_UNDEFINED, // x position
86 SDL_WINDOWPOS_UNDEFINED, // y position
87 Layout::ScreenUndocked::Width, Layout::ScreenUndocked::Height,
88 SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI);
89
90 if (render_window == nullptr) {
91 LOG_CRITICAL(Frontend, "Failed to create SDL2 window! Exiting...");
92 exit(1);
93 }
94
95 gl_context = SDL_GL_CreateContext(render_window);
96
97 if (gl_context == nullptr) {
98 LOG_CRITICAL(Frontend, "Failed to create SDL2 GL context! Exiting...");
99 exit(1);
100 }
101
102 if (!gladLoadGLLoader(static_cast<GLADloadproc>(SDL_GL_GetProcAddress))) {
103 LOG_CRITICAL(Frontend, "Failed to initialize GL functions! Exiting...");
104 exit(1);
105 }
106
107 OnResize();
108 OnMinimalClientAreaChangeRequest(GetActiveConfig().min_client_area_size);
109 SDL_PumpEvents();
110 SDL_GL_SetSwapInterval(Settings::values.use_vsync);
111
112 DoneCurrent();
113}
114
115EmuWindow_SDL2::~EmuWindow_SDL2() {
116 SDL_GL_DeleteContext(gl_context);
117 SDL_Quit();
118
119 Network::Shutdown();
120 InputCommon::Shutdown();
121}
122
123void EmuWindow_SDL2::SwapBuffers() {
124 SDL_GL_SwapWindow(render_window);
125}
126
127void EmuWindow_SDL2::PollEvents() {
128 SDL_Event event;
129
130 // SDL_PollEvent returns 0 when there are no more events in the event queue
131 while (SDL_PollEvent(&event)) {
132 switch (event.type) {
133 case SDL_WINDOWEVENT:
134 switch (event.window.event) {
135 case SDL_WINDOWEVENT_SIZE_CHANGED:
136 case SDL_WINDOWEVENT_RESIZED:
137 case SDL_WINDOWEVENT_MAXIMIZED:
138 case SDL_WINDOWEVENT_RESTORED:
139 case SDL_WINDOWEVENT_MINIMIZED:
140 OnResize();
141 break;
142 case SDL_WINDOWEVENT_CLOSE:
143 is_open = false;
144 break;
145 }
146 break;
147 case SDL_KEYDOWN:
148 case SDL_KEYUP:
149 OnKeyEvent(static_cast<int>(event.key.keysym.scancode), event.key.state);
150 break;
151 case SDL_MOUSEMOTION:
152 OnMouseMotion(event.motion.x, event.motion.y);
153 break;
154 case SDL_MOUSEBUTTONDOWN:
155 case SDL_MOUSEBUTTONUP:
156 OnMouseButton(event.button.button, event.button.state, event.button.x, event.button.y);
157 break;
158 case SDL_QUIT:
159 is_open = false;
160 break;
161 }
162 }
163}
164
165void EmuWindow_SDL2::MakeCurrent() {
166 SDL_GL_MakeCurrent(render_window, gl_context);
167}
168
169void EmuWindow_SDL2::DoneCurrent() {
170 SDL_GL_MakeCurrent(render_window, nullptr);
171}
172
173void EmuWindow_SDL2::OnMinimalClientAreaChangeRequest(
174 const std::pair<unsigned, unsigned>& minimal_size) {
175
176 SDL_SetWindowMinimumSize(render_window, minimal_size.first, minimal_size.second);
177}