Extract canvas live stroke, node canvas state, and preset panel UI

This commit is contained in:
2026-06-16 19:53:50 +02:00
parent f78f72b607
commit 9b2a0d9c30
13 changed files with 1107 additions and 807 deletions

View File

@@ -1,6 +1,7 @@
#include "pch.h"
#include "log.h"
#include "node_panel_brush.h"
#include "legacy_brush_preset_panel_ui.h"
#include "legacy_brush_panel_services.h"
#include "app_core/brush_ui.h"
#include "legacy_brush_ui_services.h"
@@ -405,142 +406,7 @@ void NodePanelBrushPreset::execute_preset_list_plan(const pp::app::BrushPresetLi
void NodePanelBrushPreset::init()
{
init_template_file("data/dialogs/panel-brushes.xml", "tpl-panel-brush-preset");
m_container = find<Node>("brushes");
m_btn_add = find<NodeButtonCustom>("btn-add");
m_btn_add->on_click = [this] (Node*) {
const auto plan = pp::app::plan_brush_preset_list_add(
static_cast<int>(m_container->m_children.size()),
Canvas::I && Canvas::I->m_current_brush);
if (plan) {
execute_preset_list_plan(plan.value());
}
};
m_btn_up = find<NodeButtonCustom>("btn-up");
m_btn_up->on_click = [this](Node*) {
if (m_current)
{
int idx = m_container->get_child_index(m_current);
const auto plan = pp::app::plan_brush_preset_list_move(
static_cast<int>(m_container->m_children.size()),
idx,
-1);
if (plan) {
execute_preset_list_plan(plan.value());
}
}
};
m_btn_down = find<NodeButtonCustom>("btn-down");
m_btn_down->on_click = [this](Node*) {
if (m_current)
{
int idx = m_container->get_child_index(m_current);
const auto plan = pp::app::plan_brush_preset_list_move(
static_cast<int>(m_container->m_children.size()),
idx,
1);
if (plan) {
execute_preset_list_plan(plan.value());
}
}
};
/*
m_btn_save = find<NodeButtonCustom>("btn-save");
m_btn_save->on_click = [this](Node*) {
if (m_current)
{
*m_current->m_brush = *Canvas::I->m_current_brush;
m_current->m_preview->draw_stroke();
m_current->m_thumb->set_image(m_current->m_brush->m_brush_thumb_path);
save();
}
};
*/
m_btn_delete = find<NodeButtonCustom>("btn-remove");
m_btn_delete->on_click = [this](Node*) {
if (!m_current)
return;
int index = m_container->get_child_index(m_current);
const auto plan = pp::app::plan_brush_preset_list_remove(
static_cast<int>(m_container->m_children.size()),
index);
if (plan) {
execute_preset_list_plan(plan.value());
}
};
m_btn_menu = find<NodeButtonCustom>("btn-menu");
m_btn_menu->on_click = [this](Node* b) {
auto popup = std::dynamic_pointer_cast<NodePopupMenu>(
load_template("data/dialogs/panel-brushes.xml", "tpl-brush-popup"));
if (!popup)
return;
popup->SetPosition(b->m_pos.x + b->m_size.x, b->m_pos.y);
const auto popup_overlay = pp::panopainter::open_legacy_overlay_node_with_handle(*this, popup);
if (!popup_overlay) {
return;
}
const auto popup_handle = popup_overlay.value();
root()->update();
auto bounds = root()->GetSize() - zw(popup->get_children_rect());
popup->SetPosition(glm::clamp(popup->m_pos, { 0, 0 }, bounds));
popup->on_select = [this, popup_handle](Node* target, int index) {
switch (index)
{
case 0: // import file
App::I->pick_file({"abr", "ppbr"}, [presets = std::static_pointer_cast<NodePanelBrushPreset>(shared_from_this())] (std::string path) {
presets->import_brush(path);
});
break;
case 1: // export file
App::I->dialog_ppbr_export();
break;
case 2: // download
break;
case 3: // upload
break;
case 4: // clear presets
{
auto mb = App::I->message_box("Clear Presets", "Do you want to remove all the Brush Presets?", true);
mb->btn_ok->m_text->set_text("Yes");
mb->btn_cancel->m_text->set_text("No");
mb->btn_ok->on_click = mb->on_submit = [this, mb](Node*) {
const auto plan = pp::app::plan_brush_preset_list_clear(
static_cast<int>(m_container->m_children.size()));
if (plan) {
execute_preset_list_plan(plan.value());
}
pp::panopainter::close_legacy_dialog_node(*mb);
};
break;
}
}
(void)pp::panopainter::close_legacy_overlay_node(*this, popup_handle);
};
};
m_btn_import = find<NodeButton>("import");
m_btn_import->on_click = [this] (Node*) {
App::I->pick_file({ "abr", "ppbr" }, [presets = std::static_pointer_cast<NodePanelBrushPreset>(shared_from_this())](std::string path) {
presets->import_brush(path);
});
};
m_btn_download = find<NodeButton>("download");
m_btn_download->on_click = [this] (Node*) {
App::I->dialog_preset_download();
};
m_notification = find("notification");
if (Asset::exist(App::I->data_path + "/settings/presets.bin") && !restore())
{
auto mb = App::I->message_box("Presets", "Could not read brush presets file, it will be deleted.", true);
mb->btn_ok->on_click = [mb](Node*) {
Asset::delete_file(App::I->data_path + "/settings/presets.bin");
pp::panopainter::close_legacy_dialog_node(*mb);
};
mb->btn_cancel->on_click = [mb](Node*) {
pp::panopainter::close_legacy_dialog_node(*mb);
};
}
m_notification->SetVisibility(m_container->m_children.size() == 0);
pp::panopainter::LegacyBrushPresetPanelUi::init(*this);
}
kEventResult NodePanelBrushPreset::handle_event(Event* e)
@@ -574,13 +440,7 @@ kEventResult NodePanelBrushPreset::handle_event(Event* e)
void NodePanelBrushPreset::handle_click(Node* target)
{
int idx = m_container->get_child_index(target);
const auto plan = pp::app::plan_brush_preset_list_select(
static_cast<int>(m_container->m_children.size()),
idx);
if (plan) {
execute_preset_list_plan(plan.value());
}
pp::panopainter::LegacyBrushPresetPanelUi::handle_click(*this, target);
}
bool NodePanelBrushPreset::save()
@@ -599,21 +459,7 @@ bool NodePanelBrushPreset::restore()
void NodePanelBrushPreset::add_brush(std::shared_ptr<Brush> brush)
{
NodeBrushPresetItem* b = new NodeBrushPresetItem;
m_container->add_child(b);
b->init();
b->create();
b->loaded();
b->thumb_path = brush->m_brush_thumb_path;
b->high_path = brush->m_brush_path;
b->m_brush = brush;
b->m_preview->m_brush = brush;
b->m_preview->draw_stroke();
b->m_thumb->m_use_mipmaps = true;
b->m_thumb->set_image(brush->m_brush_thumb_path);
b->m_caption_size->set_text_format("%d", (int)brush->m_tip_size);
b->on_click = std::bind(&NodePanelBrushPreset::handle_click, this, std::placeholders::_1);
m_notification->SetVisibility(m_container->m_children.size() == 0);
pp::panopainter::LegacyBrushPresetPanelUi::add_brush(*this, std::move(brush));
}
bool NodePanelBrushPreset::export_ppbr(const std::string& path_in, const PPBRInfo& info_data)
@@ -647,6 +493,6 @@ void NodePanelBrushPreset::clear_brushes()
void NodePanelBrushPreset::added(Node* parent)
{
m_interacted = false;
m_notification->SetVisibility(m_container->m_children.size() == 0);
(void)parent;
pp::panopainter::LegacyBrushPresetPanelUi::added(*this);
}