diff --git a/src/citra/emu_window/emu_window_sdl2.cpp b/src/citra/emu_window/emu_window_sdl2.cpp index e6e0c0cad..89dc79244 100644 --- a/src/citra/emu_window/emu_window_sdl2.cpp +++ b/src/citra/emu_window/emu_window_sdl2.cpp @@ -41,15 +41,15 @@ void EmuWindow_SDL2::OnMouseButton(u32 button, u8 state, s32 x, s32 y) { } } -std::pair EmuWindow_SDL2::TouchToPixelPos(float touch_x, float touch_y) const { +std::pair 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; - // add 0.5 to have .99992 round up instead of down. These will always be near-integers. - return {static_cast(touch_x + 0.5), static_cast(touch_y + 0.5)}; + return {static_cast(std::max(std::round(touch_x), 0.0f)), + static_cast(std::max(std::round(touch_y), 0.0f))}; } void EmuWindow_SDL2::OnFingerDown(float x, float y) { @@ -58,12 +58,12 @@ void EmuWindow_SDL2::OnFingerDown(float x, float y) { // 3DS does const auto [px, py] = TouchToPixelPos(x, y); - TouchPressed(static_cast(std::max(px, 0)), static_cast(std::max(py, 0))); + TouchPressed(px, py); } void EmuWindow_SDL2::OnFingerMotion(float x, float y) { const auto [px, py] = TouchToPixelPos(x, y); - TouchMoved(static_cast(std::max(px, 0)), static_cast(std::max(py, 0))); + TouchMoved(px, py); } void EmuWindow_SDL2::OnFingerUp() { diff --git a/src/citra/emu_window/emu_window_sdl2.h b/src/citra/emu_window/emu_window_sdl2.h index f15032477..8ae4ee83c 100644 --- a/src/citra/emu_window/emu_window_sdl2.h +++ b/src/citra/emu_window/emu_window_sdl2.h @@ -42,7 +42,7 @@ private: void OnMouseButton(u32 button, u8 state, s32 x, s32 y); /// Translates pixel position (0..1) to pixel positions - std::pair TouchToPixelPos(float touch_x, float touch_y) const; + std::pair TouchToPixelPos(float touch_x, float touch_y) const; /// Called by PollEvents when a finger starts touching the touchscreen void OnFingerDown(float x, float y);