diff --git a/src/GUIHolder.cpp b/src/GUIHolder.cpp index aa7823c..85af9d0 100644 --- a/src/GUIHolder.cpp +++ b/src/GUIHolder.cpp @@ -163,7 +163,9 @@ void GUIHolder::input_mouse_wheel_callback(const InputManager::MouseWheelCallbac } void GUIHolder::input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) { + gui.input_finger_touch_callback(touch); } void GUIHolder::input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) { + gui.input_finger_motion_callback(motion); } diff --git a/src/GUIStuff/Elements/Element.cpp b/src/GUIStuff/Elements/Element.cpp index 85b490e..8eb144a 100644 --- a/src/GUIStuff/Elements/Element.cpp +++ b/src/GUIStuff/Elements/Element.cpp @@ -14,6 +14,8 @@ namespace GUIStuff { void Element::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) { } void Element::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) { } void Element::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel) { } + void Element::input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) { } + void Element::input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) { } void Element::input_key_callback(const InputManager::KeyCallbackArgs& key) {} void Element::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) {} diff --git a/src/GUIStuff/Elements/Element.hpp b/src/GUIStuff/Elements/Element.hpp index ce93c08..a296297 100644 --- a/src/GUIStuff/Elements/Element.hpp +++ b/src/GUIStuff/Elements/Element.hpp @@ -32,6 +32,8 @@ namespace GUIStuff { virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button); virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion); virtual void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel); + virtual void input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch); + virtual void input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion); virtual void input_key_callback(const InputManager::KeyCallbackArgs& key); protected: static SCollision::AABB get_bb_from_command(Clay_RenderCommand* command); diff --git a/src/GUIStuff/Elements/SelectableButton.cpp b/src/GUIStuff/Elements/SelectableButton.cpp index ffe19a3..68950ed 100644 --- a/src/GUIStuff/Elements/SelectableButton.cpp +++ b/src/GUIStuff/Elements/SelectableButton.cpp @@ -21,7 +21,7 @@ void SelectableButton::layout(const Clay_ElementId& id, const Data& d) { else if(d.onClick) d.onClick(); }; - if(isHeld || ((d.isSelected || mouseHovering) && d.drawType == DrawType::TRANSPARENT_BORDER)) + if(isHeld || ((d.isSelected || isHovering) && d.drawType == DrawType::TRANSPARENT_BORDER)) borderColor = io.theme->fillColor1; else if(d.drawType == DrawType::TRANSPARENT_BORDER) borderColor = io.theme->backColor2; @@ -30,7 +30,7 @@ void SelectableButton::layout(const Clay_ElementId& id, const Data& d) { if(d.isSelected) backgroundColorHighlight = color_mul_alpha(io.theme->fillColor1, 0.4f); - else if(mouseHovering || isHeld) + else if(isHovering || isHeld) backgroundColorHighlight = color_mul_alpha(io.theme->fillColor1, 0.2f); else backgroundColorHighlight = {0.0f, 0.0f, 0.0f, 0.0f}; @@ -63,7 +63,7 @@ void SelectableButton::layout(const Clay_ElementId& id, const Data& d) { .cornerRadius = CLAY_CORNER_RADIUS(4) }) { if(d.innerContent) - d.innerContent({.isSelected = d.isSelected, .isHovering = mouseHovering, .isHeld = isHeld}); + d.innerContent({.isSelected = d.isSelected, .isHovering = isHovering, .isHeld = isHeld}); } } } @@ -81,15 +81,42 @@ void SelectableButton::input_mouse_button_callback(const InputManager::MouseButt gui.set_post_callback_func(onClick); gui.set_to_layout(); } - else if(mouseHovering != oldIsHovering || isHeld != oldIsHeld) + else if(mouseHovering != isHovering || isHeld != oldIsHeld) gui.set_to_layout(); - oldIsHovering = mouseHovering; + isHovering = mouseHovering; } void SelectableButton::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) { - if(mouseHovering != oldIsHovering) + if(mouseHovering != isHovering) gui.set_to_layout(); - oldIsHovering = mouseHovering; + isHovering = mouseHovering; +} + +void SelectableButton::input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) { + bool oldIsHeld = isHeld; + bool oldIsHovering = isHovering; + isHeld = mouseHovering && touch.down; + isHovering = mouseHovering && touch.down; + if(isHeld) { + if(instantResponse) + gui.set_post_callback_func(onClick); + gui.set_to_layout(); + } + else if(mouseHovering && oldIsHeld && !touch.down) { + if(!instantResponse) + gui.set_post_callback_func(onClick); + gui.set_to_layout(); + } + else if(oldIsHovering != isHovering || isHeld != oldIsHeld) + gui.set_to_layout(); +} + +void SelectableButton::input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) { + if(isHovering || isHeld) { + isHovering = false; + isHeld = false; + gui.set_to_layout(); + } } } diff --git a/src/GUIStuff/Elements/SelectableButton.hpp b/src/GUIStuff/Elements/SelectableButton.hpp index 6ae4d73..d1ca940 100644 --- a/src/GUIStuff/Elements/SelectableButton.hpp +++ b/src/GUIStuff/Elements/SelectableButton.hpp @@ -31,11 +31,14 @@ class SelectableButton : public Element { void layout(const Clay_ElementId& id, const Data& d); virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) override; virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override; + virtual void input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) override; + virtual void input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) override; private: bool instantResponse = false; bool isHeld = false; - bool oldIsHovering = false; + bool isHovering = false; + bool moved = false; std::function onClick; }; diff --git a/src/GUIStuff/GUIManager.cpp b/src/GUIStuff/GUIManager.cpp index 9e63e32..93e4f75 100644 --- a/src/GUIStuff/GUIManager.cpp +++ b/src/GUIStuff/GUIManager.cpp @@ -690,13 +690,17 @@ void GUIManager::input_key_callback(const InputManager::KeyCallbackArgs& key) { } void GUIManager::input_mouse_button_callback(InputManager::MouseButtonCallbackArgs button) { - button.pos /= io.guiScaleMultiplier; - mouse_callback(button.pos, [&button] (ElementContainer* e) { e->elem->input_mouse_button_callback(button); }); + if(button.deviceType != InputManager::MouseDeviceType::TOUCH) { + button.pos /= io.guiScaleMultiplier; + mouse_callback(button.pos, [&button] (ElementContainer* e) { e->elem->input_mouse_button_callback(button); }); + } } void GUIManager::input_mouse_motion_callback(InputManager::MouseMotionCallbackArgs motion) { - motion.pos /= io.guiScaleMultiplier; - mouse_callback(motion.pos, [&motion] (ElementContainer* e) { e->elem->input_mouse_motion_callback(motion); }); + if(motion.deviceType != InputManager::MouseDeviceType::TOUCH) { + motion.pos /= io.guiScaleMultiplier; + mouse_callback(motion.pos, [&motion] (ElementContainer* e) { e->elem->input_mouse_motion_callback(motion); }); + } } void GUIManager::input_mouse_wheel_callback(InputManager::MouseWheelCallbackArgs wheel) { @@ -704,6 +708,16 @@ void GUIManager::input_mouse_wheel_callback(InputManager::MouseWheelCallbackArgs mouse_callback(wheel.mousePos, [&wheel] (ElementContainer* e) { e->elem->input_mouse_wheel_callback(wheel); }); } +void GUIManager::input_finger_touch_callback(InputManager::FingerTouchCallbackArgs touch) { + touch.pos /= io.guiScaleMultiplier; + mouse_callback(touch.pos, [&touch] (ElementContainer* e) { e->elem->input_finger_touch_callback(touch); }); +} + +void GUIManager::input_finger_motion_callback(InputManager::FingerMotionCallbackArgs motion) { + motion.pos /= io.guiScaleMultiplier; + mouse_callback(motion.pos, [&motion] (ElementContainer* e) { e->elem->input_finger_motion_callback(motion); }); +} + void GUIManager::mouse_callback(const Vector2f& mousePos, const std::function& f) { cursorObstructed = false; int16_t zIndexObstructed = 0; diff --git a/src/GUIStuff/GUIManager.hpp b/src/GUIStuff/GUIManager.hpp index f3d1e5c..a9ba4b7 100644 --- a/src/GUIStuff/GUIManager.hpp +++ b/src/GUIStuff/GUIManager.hpp @@ -101,6 +101,8 @@ class GUIManager { void input_mouse_button_callback(InputManager::MouseButtonCallbackArgs button); void input_mouse_motion_callback(InputManager::MouseMotionCallbackArgs motion); void input_mouse_wheel_callback(InputManager::MouseWheelCallbackArgs wheel); + void input_finger_touch_callback(InputManager::FingerTouchCallbackArgs touch); + void input_finger_motion_callback(InputManager::FingerMotionCallbackArgs motion); bool cursor_obstructed() const; private: diff --git a/src/MainProgram.cpp b/src/MainProgram.cpp index 1f126de..041e9d7 100755 --- a/src/MainProgram.cpp +++ b/src/MainProgram.cpp @@ -397,11 +397,13 @@ void MainProgram::input_multi_finger_motion_callback(const InputManager::MultiFi } void MainProgram::input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) { + g.input_finger_touch_callback(touch); screen->input_finger_touch_callback(touch); post_callback(); } void MainProgram::input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) { + g.input_finger_motion_callback(motion); screen->input_finger_motion_callback(motion); post_callback(); }