diff options
| author | 2021-12-18 13:57:14 +0800 | |
|---|---|---|
| committer | 2021-12-18 13:57:14 +0800 | |
| commit | e49184e6069a9d791d2df3c1958f5c4b1187e124 (patch) | |
| tree | b776caf722e0be0e680f67b0ad0842628162ef1c /src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | |
| parent | Implement convert legacy to generic (diff) | |
| parent | Merge pull request #7570 from ameerj/favorites-expanded (diff) | |
| download | yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.gz yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.tar.xz yuzu-e49184e6069a9d791d2df3c1958f5c4b1187e124.zip | |
Merge branch 'yuzu-emu:master' into convert_legacy
Diffstat (limited to 'src/yuzu_cmd/emu_window/emu_window_sdl2.cpp')
| -rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | 72 |
1 files changed, 35 insertions, 37 deletions
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp index 87fce0c23..57f807826 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | |||
| @@ -9,10 +9,10 @@ | |||
| 9 | #include "common/settings.h" | 9 | #include "common/settings.h" |
| 10 | #include "core/core.h" | 10 | #include "core/core.h" |
| 11 | #include "core/perf_stats.h" | 11 | #include "core/perf_stats.h" |
| 12 | #include "input_common/keyboard.h" | 12 | #include "input_common/drivers/keyboard.h" |
| 13 | #include "input_common/drivers/mouse.h" | ||
| 14 | #include "input_common/drivers/touch_screen.h" | ||
| 13 | #include "input_common/main.h" | 15 | #include "input_common/main.h" |
| 14 | #include "input_common/mouse/mouse_input.h" | ||
| 15 | #include "input_common/sdl/sdl.h" | ||
| 16 | #include "yuzu_cmd/emu_window/emu_window_sdl2.h" | 16 | #include "yuzu_cmd/emu_window/emu_window_sdl2.h" |
| 17 | #include "yuzu_cmd/yuzu_icon.h" | 17 | #include "yuzu_cmd/yuzu_icon.h" |
| 18 | 18 | ||
| @@ -32,42 +32,32 @@ EmuWindow_SDL2::~EmuWindow_SDL2() { | |||
| 32 | } | 32 | } |
| 33 | 33 | ||
| 34 | void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { | 34 | void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { |
| 35 | TouchMoved((unsigned)std::max(x, 0), (unsigned)std::max(y, 0), 0); | 35 | input_subsystem->GetMouse()->MouseMove(x, y, 0, 0, 0, 0); |
| 36 | |||
| 37 | input_subsystem->GetMouse()->MouseMove(x, y, 0, 0); | ||
| 38 | } | 36 | } |
| 39 | 37 | ||
| 40 | MouseInput::MouseButton EmuWindow_SDL2::SDLButtonToMouseButton(u32 button) const { | 38 | InputCommon::MouseButton EmuWindow_SDL2::SDLButtonToMouseButton(u32 button) const { |
| 41 | switch (button) { | 39 | switch (button) { |
| 42 | case SDL_BUTTON_LEFT: | 40 | case SDL_BUTTON_LEFT: |
| 43 | return MouseInput::MouseButton::Left; | 41 | return InputCommon::MouseButton::Left; |
| 44 | case SDL_BUTTON_RIGHT: | 42 | case SDL_BUTTON_RIGHT: |
| 45 | return MouseInput::MouseButton::Right; | 43 | return InputCommon::MouseButton::Right; |
| 46 | case SDL_BUTTON_MIDDLE: | 44 | case SDL_BUTTON_MIDDLE: |
| 47 | return MouseInput::MouseButton::Wheel; | 45 | return InputCommon::MouseButton::Wheel; |
| 48 | case SDL_BUTTON_X1: | 46 | case SDL_BUTTON_X1: |
| 49 | return MouseInput::MouseButton::Backward; | 47 | return InputCommon::MouseButton::Backward; |
| 50 | case SDL_BUTTON_X2: | 48 | case SDL_BUTTON_X2: |
| 51 | return MouseInput::MouseButton::Forward; | 49 | return InputCommon::MouseButton::Forward; |
| 52 | default: | 50 | default: |
| 53 | return MouseInput::MouseButton::Undefined; | 51 | return InputCommon::MouseButton::Undefined; |
| 54 | } | 52 | } |
| 55 | } | 53 | } |
| 56 | 54 | ||
| 57 | void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { | 55 | void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { |
| 58 | const auto mouse_button = SDLButtonToMouseButton(button); | 56 | const auto mouse_button = SDLButtonToMouseButton(button); |
| 59 | if (button == SDL_BUTTON_LEFT) { | 57 | if (state == SDL_PRESSED) { |
| 60 | if (state == SDL_PRESSED) { | 58 | input_subsystem->GetMouse()->PressButton(x, y, 0, 0, mouse_button); |
| 61 | TouchPressed((unsigned)std::max(x, 0), (unsigned)std::max(y, 0), 0); | ||
| 62 | } else { | ||
| 63 | TouchReleased(0); | ||
| 64 | } | ||
| 65 | } else { | 59 | } else { |
| 66 | if (state == SDL_PRESSED) { | 60 | input_subsystem->GetMouse()->ReleaseButton(mouse_button); |
| 67 | input_subsystem->GetMouse()->PressButton(x, y, mouse_button); | ||
| 68 | } else { | ||
| 69 | input_subsystem->GetMouse()->ReleaseButton(mouse_button); | ||
| 70 | } | ||
| 71 | } | 61 | } |
| 72 | } | 62 | } |
| 73 | 63 | ||
| @@ -82,29 +72,35 @@ std::pair<unsigned, unsigned> EmuWindow_SDL2::TouchToPixelPos(float touch_x, flo | |||
| 82 | static_cast<unsigned>(std::max(std::round(touch_y), 0.0f))}; | 72 | static_cast<unsigned>(std::max(std::round(touch_y), 0.0f))}; |
| 83 | } | 73 | } |
| 84 | 74 | ||
| 85 | void EmuWindow_SDL2::OnFingerDown(float x, float y) { | 75 | void EmuWindow_SDL2::OnFingerDown(float x, float y, std::size_t id) { |
| 86 | // TODO(NeatNit): keep track of multitouch using the fingerID and a dictionary of some kind | 76 | int width, height; |
| 87 | // This isn't critical because the best we can do when we have that is to average them, like the | 77 | SDL_GetWindowSize(render_window, &width, &height); |
| 88 | // 3DS does | ||
| 89 | |||
| 90 | const auto [px, py] = TouchToPixelPos(x, y); | 78 | const auto [px, py] = TouchToPixelPos(x, y); |
| 91 | TouchPressed(px, py, 0); | 79 | const float fx = px * 1.0f / width; |
| 80 | const float fy = py * 1.0f / height; | ||
| 81 | |||
| 82 | input_subsystem->GetTouchScreen()->TouchPressed(fx, fy, id); | ||
| 92 | } | 83 | } |
| 93 | 84 | ||
| 94 | void EmuWindow_SDL2::OnFingerMotion(float x, float y) { | 85 | void EmuWindow_SDL2::OnFingerMotion(float x, float y, std::size_t id) { |
| 86 | int width, height; | ||
| 87 | SDL_GetWindowSize(render_window, &width, &height); | ||
| 95 | const auto [px, py] = TouchToPixelPos(x, y); | 88 | const auto [px, py] = TouchToPixelPos(x, y); |
| 96 | TouchMoved(px, py, 0); | 89 | const float fx = px * 1.0f / width; |
| 90 | const float fy = py * 1.0f / height; | ||
| 91 | |||
| 92 | input_subsystem->GetTouchScreen()->TouchMoved(fx, fy, id); | ||
| 97 | } | 93 | } |
| 98 | 94 | ||
| 99 | void EmuWindow_SDL2::OnFingerUp() { | 95 | void EmuWindow_SDL2::OnFingerUp() { |
| 100 | TouchReleased(0); | 96 | input_subsystem->GetTouchScreen()->TouchReleased(0); |
| 101 | } | 97 | } |
| 102 | 98 | ||
| 103 | void EmuWindow_SDL2::OnKeyEvent(int key, u8 state) { | 99 | void EmuWindow_SDL2::OnKeyEvent(int key, u8 state) { |
| 104 | if (state == SDL_PRESSED) { | 100 | if (state == SDL_PRESSED) { |
| 105 | input_subsystem->GetKeyboard()->PressKey(key); | 101 | input_subsystem->GetKeyboard()->PressKey(static_cast<std::size_t>(key)); |
| 106 | } else if (state == SDL_RELEASED) { | 102 | } else if (state == SDL_RELEASED) { |
| 107 | input_subsystem->GetKeyboard()->ReleaseKey(key); | 103 | input_subsystem->GetKeyboard()->ReleaseKey(static_cast<std::size_t>(key)); |
| 108 | } | 104 | } |
| 109 | } | 105 | } |
| 110 | 106 | ||
| @@ -205,10 +201,12 @@ void EmuWindow_SDL2::WaitEvent() { | |||
| 205 | } | 201 | } |
| 206 | break; | 202 | break; |
| 207 | case SDL_FINGERDOWN: | 203 | case SDL_FINGERDOWN: |
| 208 | OnFingerDown(event.tfinger.x, event.tfinger.y); | 204 | OnFingerDown(event.tfinger.x, event.tfinger.y, |
| 205 | static_cast<std::size_t>(event.tfinger.touchId)); | ||
| 209 | break; | 206 | break; |
| 210 | case SDL_FINGERMOTION: | 207 | case SDL_FINGERMOTION: |
| 211 | OnFingerMotion(event.tfinger.x, event.tfinger.y); | 208 | OnFingerMotion(event.tfinger.x, event.tfinger.y, |
| 209 | static_cast<std::size_t>(event.tfinger.touchId)); | ||
| 212 | break; | 210 | break; |
| 213 | case SDL_FINGERUP: | 211 | case SDL_FINGERUP: |
| 214 | OnFingerUp(); | 212 | OnFingerUp(); |