diff --git a/src/DrawingProgram/DrawingProgram.cpp b/src/DrawingProgram/DrawingProgram.cpp index 0c418c2..0677acc 100644 --- a/src/DrawingProgram/DrawingProgram.cpp +++ b/src/DrawingProgram/DrawingProgram.cpp @@ -91,30 +91,33 @@ void DrawingProgram::input_mouse_button_callback(const InputManager::MouseButton if(button.down) { if(button.button == InputManager::MouseButton::RIGHT) { if(!controls.middleClickHeld && !controls.leftClickHeld) { - if(world.main.toolbar.rightClickPopupLocation) - world.main.toolbar.rightClickPopupLocation = std::nullopt; + if(rightClickPopupLocation.has_value()) + clear_right_click_popup(); else - world.main.toolbar.rightClickPopupLocation = world.main.input.mouse.pos / world.main.g.final_gui_scale(); + set_right_click_popup_location(world.main.input.mouse.pos / world.main.g.final_gui_scale()); } } else { - world.main.toolbar.rightClickPopupLocation = std::nullopt; - if(button.button == InputManager::MouseButton::LEFT && !controls.middleClickHeld) { - controls.leftClickHeld = true; - buttonCallbacks(button); - } - else if(button.button == InputManager::MouseButton::MIDDLE) { - if(controls.leftClickHeld) { - controls.leftClickHeld = false; - InputManager::MouseButtonCallbackArgs leftReleaseCallback; - leftReleaseCallback.clicks = 0; - leftReleaseCallback.down = false; - leftReleaseCallback.pos = button.pos; - leftReleaseCallback.button = InputManager::MouseButton::LEFT; - buttonCallbacks(leftReleaseCallback); + if(!rightClickPopupHoverOnClick) + clear_right_click_popup(); + if(!world.main.g.gui.cursor_obstructed()) { + if(button.button == InputManager::MouseButton::LEFT && !controls.middleClickHeld) { + controls.leftClickHeld = true; + buttonCallbacks(button); + } + else if(button.button == InputManager::MouseButton::MIDDLE) { + if(controls.leftClickHeld) { + controls.leftClickHeld = false; + InputManager::MouseButtonCallbackArgs leftReleaseCallback; + leftReleaseCallback.clicks = 0; + leftReleaseCallback.down = false; + leftReleaseCallback.pos = button.pos; + leftReleaseCallback.button = InputManager::MouseButton::LEFT; + buttonCallbacks(leftReleaseCallback); + } + controls.middleClickHeld = true; + buttonCallbacks(button); } - controls.middleClickHeld = true; - buttonCallbacks(button); } } } @@ -378,12 +381,34 @@ void DrawingProgram::toolbar_gui() { }); } +void DrawingProgram::right_click_popup_gui() { + if(rightClickPopupLocation.has_value()) + drawTool->right_click_popup_gui(rightClickPopupLocation.value()); +} + +void DrawingProgram::set_right_click_popup_location(const Vector2f& newLoc) { + if(!rightClickPopupLocation.has_value() || rightClickPopupLocation.value() != newLoc) { + rightClickPopupLocation = newLoc; + rightClickPopupHoverOnClick = false; + world.main.g.gui.set_to_layout(); + } +} + +void DrawingProgram::clear_right_click_popup() { + if(rightClickPopupLocation.has_value()) { + rightClickPopupLocation = std::nullopt; + world.main.g.gui.set_to_layout(); + rightClickPopupHoverOnClick = false; + } +} + void DrawingProgram::popup_menu_action_button(const char* id, const char* text, const std::function& onClick) { GUIStuff::GUIManager& gui = world.main.g.gui; GUIStuff::ElementHelpers::text_button(gui, id, text, { .drawType = GUIStuff::SelectableButton::DrawType::TRANSPARENT_ALL, .wide = true, + .centered = false, .onClick = onClick }); } @@ -393,45 +418,43 @@ void DrawingProgram::selection_action_menu(Vector2f popupPos) { using namespace GUIStuff; using namespace ElementHelpers; - Toolbar& t = world.main.toolbar; GUIStuff::GUIManager& gui = world.main.g.gui; - auto& io = gui.io; - gui.element("Selection popup menu", popupPos, [&, popupPos] { - text_label_light(gui, "Selection menu"); - popup_menu_action_button("Paste", "Paste", [&] { - selection.deselect_all(); - selection.paste_clipboard(popupPos * world.main.g.final_gui_scale()); + gui.set_z_index(-1, [&] { + gui.element("Selection popup menu", popupPos, [&] { + text_label_light(gui, "Selection menu"); + popup_menu_action_button("Paste", "Paste", [&, popupPos] { + selection.deselect_all(); + selection.paste_clipboard(popupPos * world.main.g.final_gui_scale()); + }); + popup_menu_action_button("Paste Image", "Paste Image", [&, popupPos] { + selection.deselect_all(); + selection.paste_image(popupPos * world.main.g.final_gui_scale()); + }); + if(selection.is_something_selected()) { + popup_menu_action_button("Copy", "Copy", [&] { + selection.selection_to_clipboard(); + }); + popup_menu_action_button("Cut", "Cut", [&] { + selection.selection_to_clipboard(); + selection.delete_all(); + }); + popup_menu_action_button("Delete", "Delete", [&] { + selection.delete_all(); + }); + popup_menu_action_button("Bring to front of layer", "Bring to front of layer", [&] { + selection.push_selection_to_front(); + }); + popup_menu_action_button("Send to back of layer", "Send to back of layer", [&] { + selection.push_selection_to_back(); + }); + } }); - popup_menu_action_button("Paste Image", "Paste Image", [&] { - selection.deselect_all(); - selection.paste_image(popupPos * world.main.g.final_gui_scale()); - }); - if(selection.is_something_selected()) { - popup_menu_action_button("Copy", "Copy", [&] { - selection.selection_to_clipboard(); - }); - popup_menu_action_button("Cut", "Cut", [&] { - selection.selection_to_clipboard(); - selection.delete_all(); - }); - popup_menu_action_button("Delete", "Delete", [&] { - selection.delete_all(); - }); - popup_menu_action_button("Bring to front of layer", "Bring to front of layer", [&] { - selection.push_selection_to_front(); - }); - popup_menu_action_button("Send to back of layer", "Send to back of layer", [&] { - selection.push_selection_to_back(); - }); - } }); } void DrawingProgram::right_click_popup_gui(Vector2f popupPos) { - Toolbar& t = world.main.toolbar; GUIStuff::GUIManager& gui = world.main.g.gui; - auto& io = gui.io; gui.new_id("Drawing Program right click GUI", [&] { drawTool->right_click_popup_gui(popupPos); @@ -441,7 +464,6 @@ void DrawingProgram::right_click_popup_gui(Vector2f popupPos) { void DrawingProgram::tool_options_gui() { using namespace GUIStuff; - Toolbar& t = world.main.toolbar; GUIStuff::GUIManager& gui = world.main.g.gui; auto& io = gui.io; @@ -524,7 +546,7 @@ bool DrawingProgram::is_selection_allowing_tool(DrawingProgramToolType typeToChe void DrawingProgram::switch_to_tool_ptr(std::unique_ptr newTool) { drawTool->switch_tool(newTool->get_type()); drawTool = std::move(newTool); - world.main.toolbar.rightClickPopupLocation = std::nullopt; + clear_right_click_popup(); world.main.g.gui.set_to_layout(); } @@ -532,7 +554,7 @@ void DrawingProgram::switch_to_tool(DrawingProgramToolType newToolType, bool for if(newToolType != drawTool->get_type() || force) { drawTool->switch_tool(newToolType); drawTool = DrawingProgramToolBase::allocate_tool_type(*this, newToolType); - world.main.toolbar.rightClickPopupLocation = std::nullopt; + clear_right_click_popup(); world.main.g.gui.set_to_layout(); } } diff --git a/src/DrawingProgram/DrawingProgram.hpp b/src/DrawingProgram/DrawingProgram.hpp index bd55753..8cfd7b3 100644 --- a/src/DrawingProgram/DrawingProgram.hpp +++ b/src/DrawingProgram/DrawingProgram.hpp @@ -26,6 +26,7 @@ class DrawingProgram { DrawingProgram(World& initWorld); void server_init_no_file(); void toolbar_gui(); + void right_click_popup_gui(); void tool_options_gui(); void right_click_popup_gui(Vector2f popupPos); void update(); @@ -69,6 +70,7 @@ class DrawingProgram { void input_pen_touch_callback(const InputManager::PenTouchCallbackArgs& touch); void input_pen_motion_callback(const InputManager::PenMotionCallbackArgs& motion); void input_pen_axis_callback(const InputManager::PenAxisCallbackArgs& axis); + bool rightClickPopupHoverOnClick = false; private: void process_transform_message(const std::vector>& transforms); @@ -125,6 +127,11 @@ class DrawingProgram { std::unique_ptr drawTool; + std::optional rightClickPopupLocation; + + void set_right_click_popup_location(const Vector2f& newLoc); + void clear_right_click_popup(); + uint32_t nextID = 0; friend class EyeDropperTool; diff --git a/src/GUIStuff/Elements/CheckBox.cpp b/src/GUIStuff/Elements/CheckBox.cpp index 5c4a16e..e67865f 100644 --- a/src/GUIStuff/Elements/CheckBox.cpp +++ b/src/GUIStuff/Elements/CheckBox.cpp @@ -20,14 +20,14 @@ void CheckBox::layout(const Clay_ElementId& id, const std::function& isT }) {} } -bool CheckBox::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { +void CheckBox::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { isHovering = mouseHovering; if(isHovering && button.button == InputManager::MouseButton::LEFT && button.down) gui.set_post_callback_func([&](){if(onClick) onClick();}); return Element::input_mouse_button_callback(button, mouseHovering); } -bool CheckBox::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { +void CheckBox::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { isHovering = mouseHovering; return Element::input_mouse_motion_callback(motion, mouseHovering); } diff --git a/src/GUIStuff/Elements/CheckBox.hpp b/src/GUIStuff/Elements/CheckBox.hpp index 282598c..0601ad0 100644 --- a/src/GUIStuff/Elements/CheckBox.hpp +++ b/src/GUIStuff/Elements/CheckBox.hpp @@ -8,8 +8,8 @@ class CheckBox : public Element { CheckBox(GUIManager& gui); virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override; - virtual bool input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; - virtual bool input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; + virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; + virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; void layout(const Clay_ElementId& id, const std::function& isTicked, const std::function& onClick); private: diff --git a/src/GUIStuff/Elements/ColorPicker.decl.hpp b/src/GUIStuff/Elements/ColorPicker.decl.hpp index 626a4fe..5a35210 100644 --- a/src/GUIStuff/Elements/ColorPicker.decl.hpp +++ b/src/GUIStuff/Elements/ColorPicker.decl.hpp @@ -63,8 +63,8 @@ template class ColorPicker : public Element { ColorPicker(GUIManager& gui); void layout(const Clay_ElementId& id, T* data, bool selectAlpha, const std::function& onChange); virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA); - bool input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; - bool input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; + void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; + void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; private: void update_color_picker_pos(const Vector2f& p); float get_sv_selection_area_size(); diff --git a/src/GUIStuff/Elements/ColorPicker.impl.hpp b/src/GUIStuff/Elements/ColorPicker.impl.hpp index 9cdd747..214c3ef 100644 --- a/src/GUIStuff/Elements/ColorPicker.impl.hpp +++ b/src/GUIStuff/Elements/ColorPicker.impl.hpp @@ -82,7 +82,7 @@ template void ColorPicker::clay_draw(SkCanvas* canvas, UpdateInp canvas->restore(); } -template bool ColorPicker::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { +template void ColorPicker::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { held = HeldBar::NONE; if(mouseHovering && button.button == InputManager::MouseButton::LEFT && button.down && boundingBox.has_value()) { auto& bb = boundingBox.value(); @@ -103,12 +103,12 @@ template bool ColorPicker::input_mouse_button_callback(const Inp } } update_color_picker_pos(button.pos); - return Element::input_mouse_button_callback(button, mouseHovering); + Element::input_mouse_button_callback(button, mouseHovering); } -template bool ColorPicker::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { +template void ColorPicker::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { update_color_picker_pos(motion.pos); - return Element::input_mouse_motion_callback(motion, mouseHovering); + Element::input_mouse_motion_callback(motion, mouseHovering); } template void ColorPicker::update_color_picker_pos(const Vector2f& p) { diff --git a/src/GUIStuff/Elements/Element.cpp b/src/GUIStuff/Elements/Element.cpp index e9651a1..d99350f 100644 --- a/src/GUIStuff/Elements/Element.cpp +++ b/src/GUIStuff/Elements/Element.cpp @@ -6,9 +6,9 @@ namespace GUIStuff { void Element::tick_update() {} - bool Element::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { return mouseHovering; } - bool Element::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { return mouseHovering; } - bool Element::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering) { return mouseHovering; } + void Element::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { } + void Element::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { } + void Element::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering) { } 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 15217a0..875af85 100644 --- a/src/GUIStuff/Elements/Element.hpp +++ b/src/GUIStuff/Elements/Element.hpp @@ -21,9 +21,9 @@ namespace GUIStuff { virtual void tick_update(); // Return true when mouse obstructs what's behind it - virtual bool input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering); - virtual bool input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering); - virtual bool input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering); + virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering); + virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering); + virtual void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering); 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/LayoutElement.cpp b/src/GUIStuff/Elements/LayoutElement.cpp index c9b554c..74250cf 100644 --- a/src/GUIStuff/Elements/LayoutElement.cpp +++ b/src/GUIStuff/Elements/LayoutElement.cpp @@ -10,21 +10,18 @@ void LayoutElement::layout(const Clay_ElementId& id, const std::function mouseButton; - std::function mouseMotion; - std::function mouseWheel; + std::function mouseButton; + std::function mouseMotion; + std::function mouseWheel; std::function key; }; void layout(const Clay_ElementId& id, const std::function& layout, const Callbacks& c = {}); - virtual bool input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; - virtual bool input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; - virtual bool input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering) override; + virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; + virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; + virtual void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering) override; virtual void input_key_callback(const InputManager::KeyCallbackArgs& key) override; private: Callbacks c; diff --git a/src/GUIStuff/Elements/NumberSlider.hpp b/src/GUIStuff/Elements/NumberSlider.hpp index 433aa75..71cc256 100644 --- a/src/GUIStuff/Elements/NumberSlider.hpp +++ b/src/GUIStuff/Elements/NumberSlider.hpp @@ -73,19 +73,19 @@ template class NumberSlider : public Element { canvas->restore(); } - virtual bool input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override { + virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override { isHovering = mouseHovering; isHeld = isHovering && button.button == InputManager::MouseButton::LEFT && button.down; if(isHeld && boundingBox.has_value()) update_slider_pos(button.pos); - return Element::input_mouse_button_callback(button, mouseHovering); + Element::input_mouse_button_callback(button, mouseHovering); } - virtual bool input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override { + virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override { isHovering = mouseHovering; if(isHeld && boundingBox.has_value()) update_slider_pos(motion.pos); - return Element::input_mouse_motion_callback(motion, mouseHovering); + Element::input_mouse_motion_callback(motion, mouseHovering); } private: diff --git a/src/GUIStuff/Elements/PaintCircleMenu.cpp b/src/GUIStuff/Elements/PaintCircleMenu.cpp index 3981396..8a1446b 100644 --- a/src/GUIStuff/Elements/PaintCircleMenu.cpp +++ b/src/GUIStuff/Elements/PaintCircleMenu.cpp @@ -30,26 +30,33 @@ bool PaintCircleMenu::collides_with_point(const Vector2f& p) const { return boundingBox.has_value() && SCollision::collide(SCollision::Circle(boundingBox.value().center(), CIRCLE_END), p); } -bool PaintCircleMenu::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { +void PaintCircleMenu::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { + if(d.mouseButton) d.mouseButton(button, mouseHovering); isHovering = mouseHovering; isHeld = isHovering && button.button == InputManager::MouseButton::LEFT && button.down; + update_paint_circle_menu_mouse_hover(button.pos); + isRotateBarHeld = isRotateBarHovered && isHeld; update_paint_circle_menu_mouse(button.pos, button.button == InputManager::MouseButton::LEFT && button.down); - return mouseHovering && collides_with_point(button.pos); + Element::input_mouse_button_callback(button, mouseHovering); } -bool PaintCircleMenu::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { +void PaintCircleMenu::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { + isHovering = mouseHovering; + update_paint_circle_menu_mouse_hover(motion.pos); update_paint_circle_menu_mouse(motion.pos, false); - return mouseHovering && collides_with_point(motion.pos); + Element::input_mouse_motion_callback(motion, mouseHovering); +} + +void PaintCircleMenu::update_paint_circle_menu_mouse_hover(const Vector2f& p) { + float distFromCenter = vec_distance(p, boundingBox.value().center()); + isRotateBarHovered = isHovering && distFromCenter > ROTATE_START && distFromCenter < CIRCLE_END; + isColorBarHovered = isHovering && distFromCenter > PALETTE_START && distFromCenter < ROTATE_START; } void PaintCircleMenu::update_paint_circle_menu_mouse(const Vector2f& p, bool leftClicked) { if(boundingBox.has_value()) { - Vector2f vecFromCenter = (p - boundingBox.value().center()).normalized(); - float distFromCenter = vec_distance(p, boundingBox.value().center()); - isRotateBarHovered = isHovering && distFromCenter > ROTATE_START && distFromCenter < CIRCLE_END; - isRotateBarHeld = isRotateBarHovered && isHeld; - isColorBarHovered = isHovering && distFromCenter > PALETTE_START && distFromCenter < ROTATE_START; + Vector2f vecFromCenter = (p - boundingBox.value().center()).normalized(); if(isColorBarHovered) { double selectionAngle = std::atan2(-vecFromCenter.y(), -vecFromCenter.x()) + std::numbers::pi; colorSelectionIndex = (selectionAngle / (std::numbers::pi * 2.0)) * d.palette.size(); @@ -69,8 +76,8 @@ void PaintCircleMenu::update_paint_circle_menu_mouse(const Vector2f& p, bool lef break; } } - d.onRotate(); } + d.onRotate(); }); } else if(isColorBarHovered && leftClicked) { diff --git a/src/GUIStuff/Elements/PaintCircleMenu.hpp b/src/GUIStuff/Elements/PaintCircleMenu.hpp index 502f0c6..48bfb25 100644 --- a/src/GUIStuff/Elements/PaintCircleMenu.hpp +++ b/src/GUIStuff/Elements/PaintCircleMenu.hpp @@ -12,12 +12,13 @@ class PaintCircleMenu : public Element { std::vector palette; std::function onRotate; std::function onPaletteClick; + std::function mouseButton; }; void layout(const Clay_ElementId& id, const Data& data); virtual bool collides_with_point(const Vector2f& p) const override; virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override; - virtual bool input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; - virtual bool input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; + virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; + virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; private: void draw_rotate_bar(SkCanvas* canvas, UpdateInputData& io, bool skiaAA); void draw_palette_bar(SkCanvas* canvas, UpdateInputData& io, bool skiaAA); @@ -29,6 +30,7 @@ class PaintCircleMenu : public Element { bool isColorBarHovered = false; bool isHeld = false; + void update_paint_circle_menu_mouse_hover(const Vector2f& p); void update_paint_circle_menu_mouse(const Vector2f& p, bool leftClicked); }; diff --git a/src/GUIStuff/Elements/PositionAdjustingPopupMenu.cpp b/src/GUIStuff/Elements/PositionAdjustingPopupMenu.cpp index 4ade17a..b1429a9 100644 --- a/src/GUIStuff/Elements/PositionAdjustingPopupMenu.cpp +++ b/src/GUIStuff/Elements/PositionAdjustingPopupMenu.cpp @@ -6,7 +6,7 @@ namespace GUIStuff { PositionAdjustingPopupMenu::PositionAdjustingPopupMenu(GUIManager& gui): Element(gui) {} -void PositionAdjustingPopupMenu::layout(const Clay_ElementId& id, Vector2f popupPos, const std::function& innerContent) { +void PositionAdjustingPopupMenu::layout(const Clay_ElementId& id, Vector2f popupPos, const std::function& innerContent, const LayoutElement::Callbacks& callbacks) { if(layoutElement && layoutElement->get_bb().has_value()) { auto& bb = layoutElement->get_bb().value(); if((popupPos.y() + bb.height()) > gui.io.windowSize.y()) @@ -34,7 +34,7 @@ void PositionAdjustingPopupMenu::layout(const Clay_ElementId& id, Vector2f popup }) { innerContent(); } - }); + }, callbacks); } } diff --git a/src/GUIStuff/Elements/PositionAdjustingPopupMenu.hpp b/src/GUIStuff/Elements/PositionAdjustingPopupMenu.hpp index 4663711..8f7d9e2 100644 --- a/src/GUIStuff/Elements/PositionAdjustingPopupMenu.hpp +++ b/src/GUIStuff/Elements/PositionAdjustingPopupMenu.hpp @@ -7,7 +7,7 @@ namespace GUIStuff { class PositionAdjustingPopupMenu : public Element { public: PositionAdjustingPopupMenu(GUIManager& gui); - void layout(const Clay_ElementId& id, Vector2f popupPos, const std::function& innerContent); + void layout(const Clay_ElementId& id, Vector2f popupPos, const std::function& innerContent, const LayoutElement::Callbacks& callbacks = {}); private: LayoutElement* layoutElement = nullptr; }; diff --git a/src/GUIStuff/Elements/RadioButton.cpp b/src/GUIStuff/Elements/RadioButton.cpp index 3eefacf..2cdfc7b 100644 --- a/src/GUIStuff/Elements/RadioButton.cpp +++ b/src/GUIStuff/Elements/RadioButton.cpp @@ -18,16 +18,16 @@ void RadioButton::layout(const Clay_ElementId& id, const std::function& }) {} } -bool RadioButton::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { +void RadioButton::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { isHovering = mouseHovering; if(isHovering && button.button == InputManager::MouseButton::LEFT && button.down) gui.set_post_callback_func([&] { if(onClick) onClick(); }); - return Element::input_mouse_button_callback(button, mouseHovering); + Element::input_mouse_button_callback(button, mouseHovering); } -bool RadioButton::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { +void RadioButton::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { isHovering = mouseHovering; - return Element::input_mouse_motion_callback(motion, mouseHovering); + Element::input_mouse_motion_callback(motion, mouseHovering); } void RadioButton::clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) { diff --git a/src/GUIStuff/Elements/RadioButton.hpp b/src/GUIStuff/Elements/RadioButton.hpp index ea6ad9d..2a79a10 100644 --- a/src/GUIStuff/Elements/RadioButton.hpp +++ b/src/GUIStuff/Elements/RadioButton.hpp @@ -7,8 +7,8 @@ class RadioButton : public Element { public: RadioButton(GUIManager& gui); virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override; - virtual bool input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; - virtual bool input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; + virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; + virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; void layout(const Clay_ElementId& id, const std::function& isTicked, const std::function& onClick); private: diff --git a/src/GUIStuff/Elements/RotateWheel.cpp b/src/GUIStuff/Elements/RotateWheel.cpp index e6366f5..fb799df 100644 --- a/src/GUIStuff/Elements/RotateWheel.cpp +++ b/src/GUIStuff/Elements/RotateWheel.cpp @@ -34,26 +34,30 @@ float RotateWheel::wheel_end() { return boundingBox.value().width() * 0.5f; } -bool RotateWheel::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { +void RotateWheel::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { isHovering = mouseHovering; isHeld = isHovering && button.button == InputManager::MouseButton::LEFT && button.down; + update_rotate_wheel_mouse_hover(button.pos); isRotateBarHeld = isRotateBarHovered && isHeld; - update_paint_circle_menu_mouse(button.pos); - return Element::input_mouse_button_callback(button, mouseHovering); + update_rotate_wheel_mouse(button.pos); + Element::input_mouse_button_callback(button, mouseHovering); } -bool RotateWheel::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { +void RotateWheel::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { isHovering = mouseHovering; - update_paint_circle_menu_mouse(motion.pos); - return Element::input_mouse_motion_callback(motion, mouseHovering); + update_rotate_wheel_mouse_hover(motion.pos); + update_rotate_wheel_mouse(motion.pos); + Element::input_mouse_motion_callback(motion, mouseHovering); } -void RotateWheel::update_paint_circle_menu_mouse(const Vector2f& p) { +void RotateWheel::update_rotate_wheel_mouse_hover(const Vector2f& p) { + float distFromCenter = vec_distance(p, boundingBox.value().center()); + isRotateBarHovered = isHovering && distFromCenter > wheel_start() && distFromCenter < wheel_end(); +} + +void RotateWheel::update_rotate_wheel_mouse(const Vector2f& p) { if(boundingBox.has_value()) { Vector2f vecFromCenter = (p - boundingBox.value().center()).normalized(); - float distFromCenter = vec_distance(p, boundingBox.value().center()); - isRotateBarHovered = isHovering && distFromCenter > wheel_start() && distFromCenter < wheel_end(); - if(isRotateBarHeld) { gui.set_post_callback_func([&, vecFromCenter] { auto& rotationAngle = *rotateAngle; diff --git a/src/GUIStuff/Elements/RotateWheel.hpp b/src/GUIStuff/Elements/RotateWheel.hpp index 7bb706c..26aed43 100644 --- a/src/GUIStuff/Elements/RotateWheel.hpp +++ b/src/GUIStuff/Elements/RotateWheel.hpp @@ -8,8 +8,8 @@ class RotateWheel : public Element { RotateWheel(GUIManager& gui); void layout(const Clay_ElementId& id, double* rotateAngle, const std::function& onChange); virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override; - virtual bool input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; - virtual bool input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; + virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; + virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; private: float wheel_start(); @@ -23,7 +23,8 @@ class RotateWheel : public Element { bool isRotateBarHovered = false; std::function onChange; - void update_paint_circle_menu_mouse(const Vector2f& p); + void update_rotate_wheel_mouse_hover(const Vector2f& p); + void update_rotate_wheel_mouse(const Vector2f& p); }; } diff --git a/src/GUIStuff/Elements/ScrollArea.cpp b/src/GUIStuff/Elements/ScrollArea.cpp index a401146..47831f7 100644 --- a/src/GUIStuff/Elements/ScrollArea.cpp +++ b/src/GUIStuff/Elements/ScrollArea.cpp @@ -142,20 +142,12 @@ void ScrollArea::reset_scroll() { scrollOffset = {0.0f, 0.0f}; } -bool ScrollArea::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { - return Element::input_mouse_button_callback(button, mouseHovering); -} - -bool ScrollArea::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { - return Element::input_mouse_motion_callback(motion, mouseHovering); -} - void ScrollArea::clamp_scroll() { scrollOffset.x() = std::clamp(scrollOffset.x(), -std::max(0.0f, contentDimensions.x() - containerDimensions.x()), 0.0f); scrollOffset.y() = std::clamp(scrollOffset.y(), -std::max(0.0f, contentDimensions.y() - containerDimensions.y()), 0.0f); } -bool ScrollArea::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering) { +void ScrollArea::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering) { if(mouseHovering) { Vector2f oldScrollOffset = scrollOffset; @@ -168,7 +160,7 @@ bool ScrollArea::input_mouse_wheel_callback(const InputManager::MouseWheelCallba if(oldScrollOffset != scrollOffset) gui.set_to_layout(); } - return Element::input_mouse_wheel_callback(wheel, mouseHovering); + Element::input_mouse_wheel_callback(wheel, mouseHovering); } } diff --git a/src/GUIStuff/Elements/ScrollArea.hpp b/src/GUIStuff/Elements/ScrollArea.hpp index f423810..3d74f56 100644 --- a/src/GUIStuff/Elements/ScrollArea.hpp +++ b/src/GUIStuff/Elements/ScrollArea.hpp @@ -28,9 +28,7 @@ class ScrollArea : public Element { void layout(const Clay_ElementId& id, const Options& options); void reset_scroll(); - virtual bool input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; - virtual bool input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; - virtual bool input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering) override; + virtual void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel, bool mouseHovering) override; private: Options opts; bool isScrollbarHeldY = false; diff --git a/src/GUIStuff/Elements/SelectableButton.cpp b/src/GUIStuff/Elements/SelectableButton.cpp index 7c794da..c016065 100644 --- a/src/GUIStuff/Elements/SelectableButton.cpp +++ b/src/GUIStuff/Elements/SelectableButton.cpp @@ -63,7 +63,7 @@ void SelectableButton::layout(const Clay_ElementId& id, const Data& d) { } } -bool SelectableButton::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { +void SelectableButton::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { bool oldIsHovering = isHovering; bool oldIsHeld = isHeld; isHovering = mouseHovering; @@ -74,15 +74,15 @@ bool SelectableButton::input_mouse_button_callback(const InputManager::MouseButt } else if(isHovering != oldIsHovering || isHeld != oldIsHeld) gui.set_to_layout(); - return Element::input_mouse_button_callback(button, mouseHovering); + Element::input_mouse_button_callback(button, mouseHovering); } -bool SelectableButton::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { +void SelectableButton::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { bool oldIsHovering = isHovering; isHovering = mouseHovering; if(isHovering != oldIsHovering) gui.set_to_layout(); - return Element::input_mouse_motion_callback(motion, mouseHovering); + Element::input_mouse_motion_callback(motion, mouseHovering); } } diff --git a/src/GUIStuff/Elements/SelectableButton.hpp b/src/GUIStuff/Elements/SelectableButton.hpp index 6c554ff..339b28d 100644 --- a/src/GUIStuff/Elements/SelectableButton.hpp +++ b/src/GUIStuff/Elements/SelectableButton.hpp @@ -27,8 +27,8 @@ class SelectableButton : public Element { SelectableButton(GUIManager& gui); void layout(const Clay_ElementId& id, const Data& d); - virtual bool input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; - virtual bool input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; + virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; + virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; private: bool isHovering = false; diff --git a/src/GUIStuff/Elements/TextBox.decl.hpp b/src/GUIStuff/Elements/TextBox.decl.hpp index 94a6514..62915f9 100644 --- a/src/GUIStuff/Elements/TextBox.decl.hpp +++ b/src/GUIStuff/Elements/TextBox.decl.hpp @@ -26,8 +26,8 @@ template class TextBox : public Element { void layout(const Clay_ElementId& id, const TextBoxData& userInfo); virtual void clay_draw(SkCanvas* canvas, UpdateInputData& io, Clay_RenderCommand* command, bool skiaAA) override; - virtual bool input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; - virtual bool input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; + virtual void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) override; + virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) override; virtual void input_key_callback(const InputManager::KeyCallbackArgs& key) override; ~TextBox(); private: diff --git a/src/GUIStuff/Elements/TextBox.impl.hpp b/src/GUIStuff/Elements/TextBox.impl.hpp index cd81486..50c91b0 100644 --- a/src/GUIStuff/Elements/TextBox.impl.hpp +++ b/src/GUIStuff/Elements/TextBox.impl.hpp @@ -61,7 +61,7 @@ template void TextBox::clay_draw(SkCanvas* canvas, UpdateInputDa canvas->restore(); } -template bool TextBox::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { +template void TextBox::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { auto& io = gui.io; if(button.button == InputManager::MouseButton::LEFT && boundingBox.has_value()) { @@ -84,13 +84,13 @@ template bool TextBox::input_mouse_button_callback(const InputMa textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, 0, false, gui.io.input->key(InputManager::KEY_TEXT_SHIFT).held); } } - return Element::input_mouse_button_callback(button, mouseHovering); + Element::input_mouse_button_callback(button, mouseHovering); } -template bool TextBox::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { +template void TextBox::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { if(boundingBox.has_value()) textbox->process_mouse_left_button(*cur, motion.pos - boundingBox.value().min, 0, gui.io.input->mouse.leftDown, gui.io.input->key(InputManager::KEY_TEXT_SHIFT).held); - return Element::input_mouse_motion_callback(motion, mouseHovering); + Element::input_mouse_motion_callback(motion, mouseHovering); } template void TextBox::input_key_callback(const InputManager::KeyCallbackArgs& key) { diff --git a/src/GUIStuff/Elements/TreeListing.cpp b/src/GUIStuff/Elements/TreeListing.cpp index f0ab85f..f9a079d 100644 --- a/src/GUIStuff/Elements/TreeListing.cpp +++ b/src/GUIStuff/Elements/TreeListing.cpp @@ -281,15 +281,4 @@ void TreeListing::select_and_unselect_parents(const std::vectordrawData.cam.c.rotation, - .selectedColor = main.world->drawProg.get_foreground_color_ptr(), - .palette = paletteData.palettes[paletteData.selectedPalette].colors, - .onRotate = [&] { - main.world->drawData.cam.c.rotate_about(main.world->drawData.cam.c.from_space(main.window.size.cast() * 0.5f), newRotationAngle - main.world->drawData.cam.c.rotation); - }, - .onPaletteClick = [&] { - gui.set_to_layout(); - } + std::shared_ptr newRotationAngle = std::make_shared(main.world->drawData.cam.c.rotation); + + gui.set_z_index(-1, [&] { + paint_circle_popup_menu(gui, "paint circle popup", popupPos, { + .rotationAngle = newRotationAngle.get(), + .selectedColor = main.world->drawProg.get_foreground_color_ptr(), + .palette = paletteData.palettes[paletteData.selectedPalette].colors, + .onRotate = [&, newRotationAngle] { + main.world->drawData.cam.c.rotate_about(main.world->drawData.cam.c.from_space(main.window.size.cast() * 0.5f), *newRotationAngle - main.world->drawData.cam.c.rotation); + *newRotationAngle = main.world->drawData.cam.c.rotation; + gui.set_to_layout(); + }, + .onPaletteClick = [&] { + gui.set_to_layout(); + }, + .mouseButton = [&](const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { + main.world->drawProg.rightClickPopupHoverOnClick = mouseHovering; + } + }); }); } @@ -636,7 +644,6 @@ void Toolbar::top_toolbar() { menuPopupOpenFlipped = true; gui.set_to_layout(); } - return mouseHovering; } }); } @@ -1225,6 +1232,7 @@ void Toolbar::drawing_program_gui() { // } //} main.world->drawProg.tool_options_gui(); + main.world->drawProg.right_click_popup_gui(); } } @@ -2150,7 +2158,6 @@ void Toolbar::file_picker_gui() { }); gui.set_to_layout(); } - return mouseHovering; } }); } diff --git a/src/Toolbar.hpp b/src/Toolbar.hpp index efd8130..c44480e 100644 --- a/src/Toolbar.hpp +++ b/src/Toolbar.hpp @@ -61,8 +61,6 @@ class Toolbar { bool isUpdatingColorLeft = false; bool isUpdatingColorRight = false; - std::optional rightClickPopupLocation; - bool app_close_requested(); private: static void sdl_open_file_dialog_callback(void* userData, const char * const * fileList, int filter);