Own brush workers and thin preview/platform seams
This commit is contained in:
@@ -4,6 +4,7 @@
|
||||
#include "assets/brush_package.h"
|
||||
#include "app_core/brush_ui.h"
|
||||
#include "legacy_brush_ui_services.h"
|
||||
#include "legacy_brush_package_import_services.h"
|
||||
#include "legacy_ui_overlay_services.h"
|
||||
#include "asset.h"
|
||||
#include "texture.h"
|
||||
@@ -600,13 +601,8 @@ void NodePanelBrushPreset::init()
|
||||
switch (index)
|
||||
{
|
||||
case 0: // import file
|
||||
App::I->pick_file({"abr", "ppbr"}, [this] (std::string path) {
|
||||
std::thread([this, path] {
|
||||
BT_SetTerminate();
|
||||
import_brush(path);
|
||||
for (auto p : s_panels)
|
||||
p->m_notification->SetVisibility(p->m_container->m_children.size() == 0);
|
||||
}).detach();
|
||||
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
|
||||
@@ -637,13 +633,8 @@ void NodePanelBrushPreset::init()
|
||||
};
|
||||
m_btn_import = find<NodeButton>("import");
|
||||
m_btn_import->on_click = [this] (Node*) {
|
||||
App::I->pick_file({ "abr", "ppbr" }, [this](std::string path) {
|
||||
std::thread([this, path] {
|
||||
BT_SetTerminate();
|
||||
import_brush(path);
|
||||
for (auto p : s_panels)
|
||||
p->m_notification->SetVisibility(p->m_container->m_children.size() == 0);
|
||||
}).detach();
|
||||
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");
|
||||
@@ -1050,6 +1041,10 @@ bool NodePanelBrushPreset::import_ppbr(const std::string& path)
|
||||
|
||||
// brush settings
|
||||
auto brushes_count = sr.ru32();
|
||||
std::vector<std::shared_ptr<Brush>> brushes_to_add;
|
||||
if (brushes_count > 0) {
|
||||
brushes_to_add.reserve(static_cast<std::size_t>(brushes_count));
|
||||
}
|
||||
for (int i = 0; i < brushes_count; i++)
|
||||
{
|
||||
auto b = std::make_shared<Brush>();
|
||||
@@ -1058,16 +1053,23 @@ bool NodePanelBrushPreset::import_ppbr(const std::string& path)
|
||||
LOG("import_ppbr brush name %s", b->m_name.c_str());
|
||||
if (b->valid())
|
||||
{
|
||||
for (auto p : s_panels)
|
||||
p->add_brush(b);
|
||||
brushes_to_add.push_back(b);
|
||||
}
|
||||
pb->increment();
|
||||
}
|
||||
|
||||
save();
|
||||
App::I->stroke->m_brush_popup->reload();
|
||||
auto owner = std::static_pointer_cast<NodePanelBrushPreset>(shared_from_this());
|
||||
App::I->ui_task([owner, brushes_to_add = std::move(brushes_to_add), pb]() mutable {
|
||||
for (const auto& b : brushes_to_add)
|
||||
{
|
||||
for (auto p : s_panels)
|
||||
p->add_brush(b);
|
||||
}
|
||||
|
||||
pp::panopainter::close_legacy_dialog_node(*pb);
|
||||
owner->save();
|
||||
App::I->stroke->m_brush_popup->reload();
|
||||
pp::panopainter::close_legacy_dialog_node(*pb);
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
@@ -1148,7 +1150,8 @@ bool NodePanelBrushPreset::import_abr(const std::string& path)
|
||||
});
|
||||
|
||||
auto brushes = abr.compute_brushes(App::I->data_path);
|
||||
App::I->ui_task([&]{
|
||||
auto owner = std::static_pointer_cast<NodePanelBrushPreset>(shared_from_this());
|
||||
App::I->ui_task([owner, brushes = std::move(brushes), pb]() mutable {
|
||||
for (const auto& b : brushes)
|
||||
{
|
||||
if (b->valid())
|
||||
@@ -1159,12 +1162,11 @@ bool NodePanelBrushPreset::import_abr(const std::string& path)
|
||||
}
|
||||
pb->increment();
|
||||
}
|
||||
owner->save();
|
||||
App::I->stroke->m_brush_popup->reload();
|
||||
pp::panopainter::close_legacy_dialog_node(*pb);
|
||||
});
|
||||
|
||||
save();
|
||||
App::I->stroke->m_brush_popup->reload();
|
||||
pp::panopainter::close_legacy_dialog_node(*pb);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1178,7 +1180,15 @@ bool NodePanelBrushPreset::import_brush(const std::string& path)
|
||||
std::string name = m[2].str();
|
||||
std::string ext = m[3].str();
|
||||
|
||||
return ext == "ppbr" ? import_ppbr(path) : import_abr(path);
|
||||
const auto kind = ext == "ppbr"
|
||||
? pp::app::BrushPackageImportKind::ppbr
|
||||
: pp::app::BrushPackageImportKind::abr;
|
||||
const auto status = pp::panopainter::execute_legacy_brush_package_import(*App::I, kind, path);
|
||||
if (!status.ok()) {
|
||||
LOG("Brush package import request failed: %s", status.message);
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void NodePanelBrushPreset::clear_brushes()
|
||||
|
||||
Reference in New Issue
Block a user