1
0
Fork 0
mirror of https://github.com/luanti-org/luanti.git synced 2025-07-22 17:18:39 +00:00

Support both mouse and touch input in GUIs in a single binary (#14146)

This commit is contained in:
grorp 2023-12-27 22:37:36 +01:00 committed by GitHub
parent 4f1dbb127a
commit 32e492837c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 95 additions and 83 deletions

View file

@ -23,6 +23,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#include "irr_ptr.h"
#include "util/string.h"
enum class PointerType {
Mouse,
Touch,
};
class GUIModalMenu;
class IMenuManager
@ -58,6 +63,8 @@ public:
bool hasAndroidUIInput();
#endif
PointerType getPointerType() { return m_pointer_type; };
protected:
virtual std::wstring getLabelByID(s32 id) = 0;
virtual std::string getNameByID(s32 id) = 0;
@ -69,18 +76,25 @@ protected:
*/
bool DoubleClickDetection(const SEvent &event);
// Stores the last known pointer type.
PointerType m_pointer_type = PointerType::Mouse;
// Stores the last known pointer position.
// If the last input event was a mouse event, it's the cursor position.
// If the last input event was a touch event, it's the finger position.
v2s32 m_pointer;
v2s32 m_old_pointer; // Mouse position after previous mouse event
v2u32 m_screensize_old;
float m_gui_scale;
#ifdef __ANDROID__
std::string m_jni_field_name;
#endif
#ifdef HAVE_TOUCHSCREENGUI
// This is set to true if the menu is currently processing a second-touch event.
bool m_second_touch = false;
bool m_touchscreen_visible = true;
#endif
// This is set to true if the menu is currently processing a mouse event
// that was synthesized by the menu itself from a touch event.
bool m_simulated_mouse = false;
private:
struct clickpos
@ -102,11 +116,11 @@ private:
// wants to launch other menus
bool m_allow_focus_removal = false;
#ifdef HAVE_TOUCHSCREENGUI
irr_ptr<gui::IGUIElement> m_hovered;
// Stuff related to touchscreen input
irr_ptr<gui::IGUIElement> m_touch_hovered;
bool simulateMouseEvent(gui::IGUIElement *target, ETOUCH_INPUT_EVENT touch_event);
void enter(gui::IGUIElement *element);
void leave();
#endif
};