Migrate stroke panel popup overlays to checked handles

This commit is contained in:
2026-06-15 19:15:02 +02:00
parent e5f2255b08
commit 62d4c16e72

View File

@@ -116,6 +116,43 @@ pp::app::BrushStrokePanelInput make_stroke_panel_input(const Brush& brush)
return input;
}
template <pp::panopainter::LegacyPopupOverlay PopupT>
bool open_stroke_popup_with_handles(
NodePanelStroke& panel,
const std::shared_ptr<PopupT>& popup,
const glm::vec2& tick_pos,
float button_height) noexcept
{
if (!popup) {
return false;
}
panel.close_popup_overlay_handles();
auto tick = pp::panopainter::make_legacy_overlay_node_for_anchor<NodeImage>(panel);
tick->SetPositioning(YGPositionTypeAbsolute);
tick->SetSize(16, 32);
tick->SetPosition(tick_pos.x, tick_pos.y + (button_height - 32) * 0.5f);
tick->set_image("data/ui/popup-tick.png");
tick->m_scale = { 1, 1 };
const auto popup_overlay = pp::panopainter::open_legacy_overlay_node_with_handle(panel, popup);
const auto tick_overlay = pp::panopainter::open_legacy_overlay_node_with_handle(panel, tick);
if (!popup_overlay || !tick_overlay) {
pp::panopainter::close_legacy_overlay_handles_if_open(panel, popup_overlay, tick_overlay);
panel.m_popup_overlay_handle = {};
panel.m_tick_overlay_handle = {};
return false;
}
panel.m_popup_overlay_handle = popup_overlay.value();
panel.m_tick_overlay_handle = tick_overlay.value();
popup->on_popup_close = [&panel](Node*) {
panel.close_popup_overlay_handles();
};
return true;
}
} // namespace
Node* NodePanelStroke::clone_instantiate() const
@@ -313,28 +350,21 @@ void NodePanelStroke::init_controls()
m_preset_button->on_click = [this](Node*) {
auto screen = root()->m_size;
glm::vec2 pos = m_preset_button->m_pos + glm::vec2(m_preset_button->m_size.x, 0);
(void)pp::panopainter::attach_legacy_overlay_node_to_root(*this, App::I->presets);
auto tick = pp::panopainter::make_legacy_overlay_node_for_anchor<NodeImage>(*this);
tick->SetPositioning(YGPositionTypeAbsolute);
tick->SetSize(16, 32);
tick->SetPosition(pos.x, pos.y + (m_preset_button->m_size.y - 32) * 0.5f);
tick->set_image("data/ui/popup-tick.png");
(void)pp::panopainter::attach_legacy_overlay_node_to_root(*this, tick);
if (!open_stroke_popup_with_handles(*this, App::I->presets, pos, m_preset_button->m_size.y)) {
return;
}
float hh = App::I->presets->m_container->m_children.size() > 10 ? App::I->height / App::I->zoom * .75f : 400.f;
App::I->presets->SetHeight(glm::max(hh, 400.f));
App::I->presets->SetWidth(300);
root()->update();
if ((pos.y + App::I->presets->m_size.y) > screen.y)
pos.y = screen.y - App::I->presets->m_size.y;
if (pos.y < 0)
if (pos.y < 0)
pos.y = 0;
App::I->presets->SetPosition(pos.x + 16, pos.y);
App::I->presets->SetPositioning(YGPositionTypeAbsolute);
pp::panopainter::activate_legacy_popup_overlay(*App::I->presets);
root()->update();
pp::panopainter::bind_legacy_popup_close_destroys_overlay(*App::I->presets, tick);
App::I->presets->on_brush_changed = [this](Node* target, std::shared_ptr<Brush>& b) {
// don't change some params
//b->m_tip_size = Canvas::I->m_current_brush->m_tip_size;
@@ -360,13 +390,9 @@ void NodePanelStroke::init_controls()
m_brush_button->on_click = [this](Node*) {
auto screen = root()->m_size;
glm::vec2 pos = m_brush_button->m_pos + glm::vec2(m_brush_button->m_size.x, 0);
(void)pp::panopainter::attach_legacy_overlay_node_to_root(*this, m_brush_popup);
auto tick = pp::panopainter::make_legacy_overlay_node_for_anchor<NodeImage>(*this);
tick->SetPositioning(YGPositionTypeAbsolute);
tick->SetSize(16, 32);
tick->SetPosition(pos.x, pos.y + (m_brush_button->m_size.y - 32) * 0.5f);
tick->set_image("data/ui/popup-tick.png");
(void)pp::panopainter::attach_legacy_overlay_node_to_root(*this, tick);
if (!open_stroke_popup_with_handles(*this, m_brush_popup, pos, m_brush_button->m_size.y)) {
return;
}
root()->update();
if ((pos.y + m_brush_popup->m_size.y) > screen.y)
pos.y = screen.y - m_brush_popup->m_size.y;
@@ -376,8 +402,6 @@ void NodePanelStroke::init_controls()
pp::panopainter::activate_legacy_popup_overlay(*m_brush_popup);
root()->update();
pp::panopainter::bind_legacy_popup_close_destroys_overlay(*m_brush_popup, tick);
m_brush_popup->on_brush_changed = [this](Node*, int index) {
if (on_brush_changed)
on_brush_changed(this, m_brush_popup->get_texture_path(index), m_brush_popup->get_thumb_path(index));
@@ -395,13 +419,9 @@ void NodePanelStroke::init_controls()
m_dual_brush_button->on_click = [this](Node*) {
auto screen = root()->m_size;
glm::vec2 pos = m_dual_brush_button->m_pos + glm::vec2(m_dual_brush_button->m_size.x, 0);
(void)pp::panopainter::attach_legacy_overlay_node_to_root(*this, m_brush_popup);
auto tick = pp::panopainter::make_legacy_overlay_node_for_anchor<NodeImage>(*this);
tick->SetPositioning(YGPositionTypeAbsolute);
tick->SetSize(16, 32);
tick->SetPosition(pos.x, pos.y + (m_dual_brush_button->m_size.y - 32) * 0.5f);
tick->set_image("data/ui/popup-tick.png");
(void)pp::panopainter::attach_legacy_overlay_node_to_root(*this, tick);
if (!open_stroke_popup_with_handles(*this, m_brush_popup, pos, m_dual_brush_button->m_size.y)) {
return;
}
root()->update();
if ((pos.y + m_brush_popup->m_size.y) > screen.y)
pos.y = screen.y - m_brush_popup->m_size.y;
@@ -411,8 +431,6 @@ void NodePanelStroke::init_controls()
pp::panopainter::activate_legacy_popup_overlay(*m_brush_popup);
root()->update();
pp::panopainter::bind_legacy_popup_close_destroys_overlay(*m_brush_popup, tick);
m_brush_popup->on_brush_changed = [this](Node*, int index) {
m_dual_enabled->set_value(true, true);
if (on_dual_changed)
@@ -430,13 +448,9 @@ void NodePanelStroke::init_controls()
m_pattern_button->on_click = [this](Node*) {
auto screen = root()->m_size;
glm::vec2 pos = m_pattern_button->m_pos + glm::vec2(m_pattern_button->m_size.x, 0);
(void)pp::panopainter::attach_legacy_overlay_node_to_root(*this, m_pattern_popup);
auto tick = pp::panopainter::make_legacy_overlay_node_for_anchor<NodeImage>(*this);
tick->SetPositioning(YGPositionTypeAbsolute);
tick->SetSize(16, 32);
tick->SetPosition(pos.x, pos.y + (m_pattern_button->m_size.y - 32) * 0.5f);
tick->set_image("data/ui/popup-tick.png");
(void)pp::panopainter::attach_legacy_overlay_node_to_root(*this, tick);
if (!open_stroke_popup_with_handles(*this, m_pattern_popup, pos, m_pattern_button->m_size.y)) {
return;
}
root()->update();
if ((pos.y + m_pattern_popup->m_size.y) > screen.y)
pos.y = screen.y - m_pattern_popup->m_size.y;
@@ -446,8 +460,6 @@ void NodePanelStroke::init_controls()
pp::panopainter::activate_legacy_popup_overlay(*m_pattern_popup);
root()->update();
pp::panopainter::bind_legacy_popup_close_destroys_overlay(*m_pattern_popup, tick);
m_pattern_popup->on_brush_changed = [this](Node*, int index) {
m_pattern_enabled->set_value(true, true);
if (on_pattern_changed)
@@ -708,6 +720,18 @@ void NodePanelStroke::execute_stroke_control_plan(const pp::app::BrushStrokeCont
}
}
void NodePanelStroke::close_popup_overlay_handles() noexcept
{
if (m_popup_overlay_handle.valid()) {
pp::panopainter::close_legacy_overlay_handle_ignoring_status(*this, m_popup_overlay_handle);
m_popup_overlay_handle = {};
}
if (m_tick_overlay_handle.valid()) {
pp::panopainter::close_legacy_overlay_handle_ignoring_status(*this, m_tick_overlay_handle);
m_tick_overlay_handle = {};
}
}
kEventResult NodePanelStroke::handle_event(Event* e)
{
switch (e->m_type)
@@ -715,7 +739,7 @@ kEventResult NodePanelStroke::handle_event(Event* e)
case kEventType::MouseUpL:
if (!m_mouse_inside)
{
pp::panopainter::close_legacy_popup_panel(*this, on_popup_close);
close_popup_overlay_handles();
}
break;
default: