diff options
author | Muhammad Rifqi Priyo Susanto <muhammadrifqipriyosusanto@gmail.com> | 2022-11-26 21:16:14 +0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-26 09:16:14 -0500 |
commit | 40a45b8c995e12778c4478011583c08447da88eb (patch) | |
tree | 07cc3603f8f9aa3a8a53f2f2da1a677761317273 /src | |
parent | f04d4d029182d27e2557b9ea0a6a6fc39a3e17f5 (diff) | |
download | minetest-40a45b8c995e12778c4478011583c08447da88eb.tar.xz |
Virtual joystick: Use s32 when using m_screensize as a subtrahend (#12814)
If still uses u32, m_screensize will yield a big value (underflow) when used as a subtrahend.
ETIE_MOVED is allowed to be run if joystick's ID is available and virtual joystick is fixed.
Add .0f for some float values.
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/touchscreengui.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/gui/touchscreengui.cpp b/src/gui/touchscreengui.cpp index 70f1c5163..c52bc59bb 100644 --- a/src/gui/touchscreengui.cpp +++ b/src/gui/touchscreengui.cpp @@ -773,7 +773,7 @@ void TouchScreenGUI::translateEvent(const SEvent &event) m_rarecontrolsbar.deactivate(); s32 dxj = event.TouchInput.X - button_size * 5.0f / 2.0f; - s32 dyj = event.TouchInput.Y - m_screensize.Y + button_size * 5.0f / 2.0f; + s32 dyj = event.TouchInput.Y - (s32)m_screensize.Y + button_size * 5.0f / 2.0f; /* Select joystick when left 1/3 of screen dragged or * when joystick tapped (fixed joystick position) @@ -824,8 +824,9 @@ void TouchScreenGUI::translateEvent(const SEvent &event) } else { assert(event.TouchInput.Event == ETIE_MOVED); - if (m_pointerpos[event.TouchInput.ID] == - v2s32(event.TouchInput.X, event.TouchInput.Y)) + if (!(m_has_joystick_id && m_fixed_joystick) && + m_pointerpos[event.TouchInput.ID] == + v2s32(event.TouchInput.X, event.TouchInput.Y)) return; if (m_has_move_id) { @@ -878,14 +879,14 @@ void TouchScreenGUI::translateEvent(const SEvent &event) s32 dx = X - m_pointerpos[event.TouchInput.ID].X; s32 dy = Y - m_pointerpos[event.TouchInput.ID].Y; if (m_fixed_joystick) { - dx = X - button_size * 5 / 2; - dy = Y - m_screensize.Y + button_size * 5 / 2; + dx = X - button_size * 5.0f / 2.0f; + dy = Y - (s32)m_screensize.Y + button_size * 5.0f / 2.0f; } double distance_sq = dx * dx + dy * dy; s32 dxj = event.TouchInput.X - button_size * 5.0f / 2.0f; - s32 dyj = event.TouchInput.Y - m_screensize.Y + button_size * 5.0f / 2.0f; + s32 dyj = event.TouchInput.Y - (s32)m_screensize.Y + button_size * 5.0f / 2.0f; bool inside_joystick = (dxj * dxj + dyj * dyj <= button_size * button_size * 1.5 * 1.5); if (m_joystick_has_really_moved || inside_joystick || @@ -936,8 +937,8 @@ void TouchScreenGUI::translateEvent(const SEvent &event) s32 ndy = button_size * dy / distance - button_size / 2.0f; if (m_fixed_joystick) { m_joystick_btn_center->guibutton->setRelativePosition(v2s32( - button_size * 5 / 2 + ndx, - m_screensize.Y - button_size * 5 / 2 + ndy)); + button_size * 5.0f / 2.0f + ndx, + m_screensize.Y - button_size * 5.0f / 2.0f + ndy)); } else { m_joystick_btn_center->guibutton->setRelativePosition(v2s32( m_pointerpos[event.TouchInput.ID].X + ndx, |