Centralize legacy brush UI bridge
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
#include "log.h"
|
||||
#include "node_panel_brush.h"
|
||||
#include "app_core/brush_ui.h"
|
||||
#include "legacy_brush_ui_services.h"
|
||||
#include "asset.h"
|
||||
#include "texture.h"
|
||||
|
||||
@@ -78,109 +79,7 @@ Node* NodePanelBrush::clone_instantiate() const
|
||||
|
||||
void NodePanelBrush::execute_texture_list_plan(const pp::app::BrushTextureListPlan& plan)
|
||||
{
|
||||
class LegacyBrushTextureListServices final : public pp::app::BrushTextureListServices {
|
||||
public:
|
||||
explicit LegacyBrushTextureListServices(NodePanelBrush& panel) noexcept
|
||||
: panel_(panel)
|
||||
{
|
||||
}
|
||||
|
||||
pp::foundation::Status add_texture_from_source(
|
||||
std::string_view source_path,
|
||||
std::string_view high_path,
|
||||
std::string_view thumbnail_path,
|
||||
std::string_view brush_name,
|
||||
bool converts_brush_alpha) override
|
||||
{
|
||||
Image img;
|
||||
if (!img.load_file(std::string(source_path))) {
|
||||
return pp::foundation::Status::invalid_argument("brush texture source could not be loaded");
|
||||
}
|
||||
|
||||
if (converts_brush_alpha) {
|
||||
img.gayscale_alpha();
|
||||
}
|
||||
|
||||
auto thumbnail_image = img.resize(64, 64).resize_squared(glm::u8vec4(255));
|
||||
thumbnail_image.save_png(std::string(thumbnail_path));
|
||||
img.save_png(std::string(high_path));
|
||||
|
||||
NodeButtonBrush* brush = new NodeButtonBrush;
|
||||
panel_.m_container->add_child(brush);
|
||||
brush->init();
|
||||
brush->create();
|
||||
brush->loaded();
|
||||
const auto thumbnail_path_string = std::string(thumbnail_path);
|
||||
brush->set_icon(thumbnail_path_string.c_str());
|
||||
brush->thumb_path = std::string(thumbnail_path);
|
||||
brush->high_path = std::string(high_path);
|
||||
brush->brush_name = std::string(brush_name);
|
||||
brush->m_user_brush = true;
|
||||
brush->on_click = std::bind(&NodePanelBrush::handle_click, &panel_, std::placeholders::_1);
|
||||
return pp::foundation::Status::success();
|
||||
}
|
||||
|
||||
void remove_texture(int index, bool delete_texture_files) override
|
||||
{
|
||||
auto* brush = brush_at(index);
|
||||
if (!brush) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (delete_texture_files) {
|
||||
Asset::delete_file(brush->thumb_path);
|
||||
Asset::delete_file(brush->high_path);
|
||||
}
|
||||
|
||||
if (panel_.m_current == brush) {
|
||||
panel_.m_current = nullptr;
|
||||
}
|
||||
panel_.m_container->remove_child(brush);
|
||||
}
|
||||
|
||||
void move_texture(int from_index, int to_index) override
|
||||
{
|
||||
if (auto* brush = brush_at(from_index)) {
|
||||
panel_.m_container->move_child(brush, to_index);
|
||||
}
|
||||
}
|
||||
|
||||
void select_texture(int index) override
|
||||
{
|
||||
if (panel_.m_current) {
|
||||
panel_.m_current->m_selected = false;
|
||||
}
|
||||
|
||||
panel_.m_current = brush_at(index);
|
||||
if (!panel_.m_current) {
|
||||
return;
|
||||
}
|
||||
|
||||
panel_.m_current->m_selected = true;
|
||||
if (panel_.on_brush_changed) {
|
||||
panel_.on_brush_changed(&panel_, index);
|
||||
}
|
||||
}
|
||||
|
||||
void save_texture_list() override
|
||||
{
|
||||
panel_.save();
|
||||
}
|
||||
|
||||
private:
|
||||
NodeButtonBrush* brush_at(int index) const
|
||||
{
|
||||
if (index < 0 || index >= static_cast<int>(panel_.m_container->m_children.size())) {
|
||||
return nullptr;
|
||||
}
|
||||
return static_cast<NodeButtonBrush*>(panel_.m_container->m_children[index].get());
|
||||
}
|
||||
|
||||
NodePanelBrush& panel_;
|
||||
};
|
||||
|
||||
LegacyBrushTextureListServices services(*this);
|
||||
const auto status = pp::app::execute_brush_texture_list_plan(plan, services);
|
||||
const auto status = pp::panopainter::execute_legacy_brush_texture_list_plan(*this, plan);
|
||||
if (!status.ok()) {
|
||||
LOG("Brush texture list action failed: %s", status.message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user