diff options
author | german77 <juangerman-13@hotmail.com> | 2023-02-04 17:31:12 +0100 |
---|---|---|
committer | german77 <juangerman-13@hotmail.com> | 2023-02-04 17:31:12 +0100 |
commit | 424643f9af91ff704f1bebfd9150f8ff153bdda5 (patch) | |
tree | a2a17960bf5b94165070e4f266d6a8c5442d060f /src/yuzu_cmd/emu_window | |
parent | Merge pull request #9708 from ameerj/gl-context-flush (diff) | |
download | yuzu-424643f9af91ff704f1bebfd9150f8ff153bdda5.tar yuzu-424643f9af91ff704f1bebfd9150f8ff153bdda5.tar.gz yuzu-424643f9af91ff704f1bebfd9150f8ff153bdda5.tar.bz2 yuzu-424643f9af91ff704f1bebfd9150f8ff153bdda5.tar.lz yuzu-424643f9af91ff704f1bebfd9150f8ff153bdda5.tar.xz yuzu-424643f9af91ff704f1bebfd9150f8ff153bdda5.tar.zst yuzu-424643f9af91ff704f1bebfd9150f8ff153bdda5.zip |
Diffstat (limited to 'src/yuzu_cmd/emu_window')
-rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2.cpp | 44 | ||||
-rw-r--r-- | src/yuzu_cmd/emu_window/emu_window_sdl2.h | 10 |
2 files changed, 21 insertions, 33 deletions
diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp index 31f28a507..e2dfe3a9b 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.cpp @@ -32,10 +32,6 @@ EmuWindow_SDL2::~EmuWindow_SDL2() { SDL_Quit(); } -void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { - input_subsystem->GetMouse()->MouseMove(x, y, 0, 0, 0, 0); -} - InputCommon::MouseButton EmuWindow_SDL2::SDLButtonToMouseButton(u32 button) const { switch (button) { case SDL_BUTTON_LEFT: @@ -53,44 +49,36 @@ InputCommon::MouseButton EmuWindow_SDL2::SDLButtonToMouseButton(u32 button) cons } } +std::pair<float, float> EmuWindow_SDL2::MouseToTouchPos(s32 touch_x, s32 touch_y) const { + int w, h; + SDL_GetWindowSize(render_window, &w, &h); + const float fx = static_cast<float>(touch_x) / w; + const float fy = static_cast<float>(touch_y) / h; + + return {std::clamp<float>(fx, 0.0f, 1.0f), std::clamp<float>(fy, 0.0f, 1.0f)}; +} + void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { const auto mouse_button = SDLButtonToMouseButton(button); if (state == SDL_PRESSED) { - input_subsystem->GetMouse()->PressButton(x, y, 0, 0, mouse_button); + const auto [touch_x, touch_y] = MouseToTouchPos(x, y); + input_subsystem->GetMouse()->PressButton(x, y, touch_x, touch_y, mouse_button); } else { input_subsystem->GetMouse()->ReleaseButton(mouse_button); } } -std::pair<unsigned, unsigned> EmuWindow_SDL2::TouchToPixelPos(float touch_x, float touch_y) const { - int w, h; - SDL_GetWindowSize(render_window, &w, &h); - - touch_x *= w; - touch_y *= h; - - return {static_cast<unsigned>(std::max(std::round(touch_x), 0.0f)), - static_cast<unsigned>(std::max(std::round(touch_y), 0.0f))}; +void EmuWindow_SDL2::OnMouseMotion(s32 x, s32 y) { + const auto [touch_x, touch_y] = MouseToTouchPos(x, y); + input_subsystem->GetMouse()->MouseMove(x, y, touch_x, touch_y, 0, 0); } void EmuWindow_SDL2::OnFingerDown(float x, float y, std::size_t id) { - int width, height; - SDL_GetWindowSize(render_window, &width, &height); - const auto [px, py] = TouchToPixelPos(x, y); - const float fx = px * 1.0f / width; - const float fy = py * 1.0f / height; - - input_subsystem->GetTouchScreen()->TouchPressed(fx, fy, id); + input_subsystem->GetTouchScreen()->TouchPressed(x, y, id); } void EmuWindow_SDL2::OnFingerMotion(float x, float y, std::size_t id) { - int width, height; - SDL_GetWindowSize(render_window, &width, &height); - const auto [px, py] = TouchToPixelPos(x, y); - const float fx = px * 1.0f / width; - const float fy = py * 1.0f / height; - - input_subsystem->GetTouchScreen()->TouchMoved(fx, fy, id); + input_subsystem->GetTouchScreen()->TouchMoved(x, y, id); } void EmuWindow_SDL2::OnFingerUp() { diff --git a/src/yuzu_cmd/emu_window/emu_window_sdl2.h b/src/yuzu_cmd/emu_window/emu_window_sdl2.h index 25c23e2a5..d9b453dee 100644 --- a/src/yuzu_cmd/emu_window/emu_window_sdl2.h +++ b/src/yuzu_cmd/emu_window/emu_window_sdl2.h @@ -38,17 +38,17 @@ protected: /// Called by WaitEvent when a key is pressed or released. void OnKeyEvent(int key, u8 state); - /// Called by WaitEvent when the mouse moves. - void OnMouseMotion(s32 x, s32 y); - /// Converts a SDL mouse button into MouseInput mouse button InputCommon::MouseButton SDLButtonToMouseButton(u32 button) const; + /// Translates pixel position to float position + std::pair<float, float> MouseToTouchPos(s32 touch_x, s32 touch_y) const; + /// Called by WaitEvent when a mouse button is pressed or released void OnMouseButton(u32 button, u8 state, s32 x, s32 y); - /// Translates pixel position (0..1) to pixel positions - std::pair<unsigned, unsigned> TouchToPixelPos(float touch_x, float touch_y) const; + /// Called by WaitEvent when the mouse moves. + void OnMouseMotion(s32 x, s32 y); /// Called by WaitEvent when a finger starts touching the touchscreen void OnFingerDown(float x, float y, std::size_t id); |