|
|
|
|
@@ -370,6 +370,8 @@ void NodePanelBrush::added(Node* parent)
|
|
|
|
|
|
|
|
|
|
// -----------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
std::vector<NodePanelBrushPreset*> NodePanelBrushPreset::s_panels;
|
|
|
|
|
|
|
|
|
|
Node* NodeBrushPresetItem::clone_instantiate() const
|
|
|
|
|
{
|
|
|
|
|
return new NodeBrushPresetItem();
|
|
|
|
|
@@ -394,6 +396,16 @@ void NodeBrushPresetItem::draw()
|
|
|
|
|
NodeButtonCustom::draw();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NodePanelBrushPreset::NodePanelBrushPreset()
|
|
|
|
|
{
|
|
|
|
|
s_panels.push_back(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
NodePanelBrushPreset::~NodePanelBrushPreset()
|
|
|
|
|
{
|
|
|
|
|
s_panels.erase(std::remove(s_panels.begin(), s_panels.end(), this));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//---
|
|
|
|
|
|
|
|
|
|
Node* NodePanelBrushPreset::clone_instantiate() const
|
|
|
|
|
@@ -407,14 +419,18 @@ void NodePanelBrushPreset::init()
|
|
|
|
|
m_container = find<Node>("brushes");
|
|
|
|
|
m_btn_add = find<NodeButtonCustom>("btn-add");
|
|
|
|
|
m_btn_add->on_click = [this] (Node*) {
|
|
|
|
|
add_brush(std::make_shared<Brush>(*Canvas::I->m_current_brush));
|
|
|
|
|
for (auto p : s_panels)
|
|
|
|
|
p->add_brush(std::make_shared<Brush>(*Canvas::I->m_current_brush));
|
|
|
|
|
save();
|
|
|
|
|
};
|
|
|
|
|
m_btn_up = find<NodeButtonCustom>("btn-up");
|
|
|
|
|
m_btn_up->on_click = [this](Node*) {
|
|
|
|
|
if (m_current)
|
|
|
|
|
{
|
|
|
|
|
m_container->move_child(m_current, std::max(m_container->get_child_index(m_current) - 1, 0));
|
|
|
|
|
int idx = m_container->get_child_index(m_current);
|
|
|
|
|
int to = std::max(idx - 1, 0);
|
|
|
|
|
for (auto p : s_panels)
|
|
|
|
|
p->m_container->move_child(p->m_container->m_children[idx].get(), to);
|
|
|
|
|
save();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@@ -422,8 +438,10 @@ void NodePanelBrushPreset::init()
|
|
|
|
|
m_btn_down->on_click = [this](Node*) {
|
|
|
|
|
if (m_current)
|
|
|
|
|
{
|
|
|
|
|
m_container->move_child(m_current,
|
|
|
|
|
std::min(m_container->get_child_index(m_current) + 1, (int)m_container->m_children.size() - 1));
|
|
|
|
|
int idx = m_container->get_child_index(m_current);
|
|
|
|
|
int to = std::min(idx + 1, (int)m_container->m_children.size() - 1);
|
|
|
|
|
for (auto p : s_panels)
|
|
|
|
|
p->m_container->move_child(p->m_container->m_children[idx].get(), to);
|
|
|
|
|
save();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
@@ -441,24 +459,26 @@ void NodePanelBrushPreset::init()
|
|
|
|
|
*/
|
|
|
|
|
m_btn_delete = find<NodeButtonCustom>("btn-remove");
|
|
|
|
|
m_btn_delete->on_click = [this](Node*) {
|
|
|
|
|
auto pb = App::I->show_progress("Exporting ABR");
|
|
|
|
|
return;
|
|
|
|
|
if (!m_current)
|
|
|
|
|
return;
|
|
|
|
|
int index = m_container->get_child_index(m_current);
|
|
|
|
|
m_current->destroy();
|
|
|
|
|
if (m_container->m_children.empty())
|
|
|
|
|
for (auto p : s_panels)
|
|
|
|
|
{
|
|
|
|
|
m_current = nullptr;
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
int next = std::min<int>((int)m_container->m_children.size() - 1, index);
|
|
|
|
|
m_current = (NodeBrushPresetItem*)m_container->m_children[next].get();
|
|
|
|
|
m_current->m_selected = true;
|
|
|
|
|
bool new_current = !p->m_current || p->m_container->get_child_index(p->m_current) == index;
|
|
|
|
|
p->m_container->m_children[index]->destroy();
|
|
|
|
|
if (p->m_container->m_children.empty())
|
|
|
|
|
{
|
|
|
|
|
p->m_current = nullptr;
|
|
|
|
|
}
|
|
|
|
|
else if (new_current)
|
|
|
|
|
{
|
|
|
|
|
int next = std::min<int>((int)p->m_container->m_children.size() - 1, index);
|
|
|
|
|
p->m_current = (NodeBrushPresetItem*)p->m_container->m_children[next].get();
|
|
|
|
|
p->m_current->m_selected = true;
|
|
|
|
|
}
|
|
|
|
|
p->m_notification->SetVisibility(p->m_container->m_children.size() == 0);
|
|
|
|
|
}
|
|
|
|
|
save();
|
|
|
|
|
m_notification->SetVisibility(m_container->m_children.size() == 0);
|
|
|
|
|
};
|
|
|
|
|
m_btn_menu = find<NodeButtonCustom>("btn-menu");
|
|
|
|
|
m_btn_menu->on_click = [this](Node* b) {
|
|
|
|
|
@@ -476,7 +496,8 @@ void NodePanelBrushPreset::init()
|
|
|
|
|
std::thread([this, path] {
|
|
|
|
|
BT_SetTerminate();
|
|
|
|
|
import_brush(path);
|
|
|
|
|
m_notification->SetVisibility(m_container->m_children.size() == 0);
|
|
|
|
|
for (auto p : s_panels)
|
|
|
|
|
p->m_notification->SetVisibility(p->m_container->m_children.size() == 0);
|
|
|
|
|
}).detach();
|
|
|
|
|
});
|
|
|
|
|
break;
|
|
|
|
|
@@ -503,7 +524,8 @@ void NodePanelBrushPreset::init()
|
|
|
|
|
std::thread([this, path] {
|
|
|
|
|
BT_SetTerminate();
|
|
|
|
|
import_brush(path);
|
|
|
|
|
m_notification->SetVisibility(m_container->m_children.size() == 0);
|
|
|
|
|
for (auto p : s_panels)
|
|
|
|
|
p->m_notification->SetVisibility(p->m_container->m_children.size() == 0);
|
|
|
|
|
}).detach();
|
|
|
|
|
});
|
|
|
|
|
};
|
|
|
|
|
@@ -553,15 +575,17 @@ kEventResult NodePanelBrushPreset::handle_event(Event* e)
|
|
|
|
|
|
|
|
|
|
void NodePanelBrushPreset::handle_click(Node* target)
|
|
|
|
|
{
|
|
|
|
|
//if (target == m_current)
|
|
|
|
|
// return;
|
|
|
|
|
if (m_current)
|
|
|
|
|
m_current->m_selected = false;
|
|
|
|
|
m_current = (NodeBrushPresetItem*)target;
|
|
|
|
|
m_current->m_selected = true;
|
|
|
|
|
int idx = m_container->get_child_index(target);
|
|
|
|
|
for (auto p : s_panels)
|
|
|
|
|
{
|
|
|
|
|
if (p->m_current)
|
|
|
|
|
p->m_current->m_selected = false;
|
|
|
|
|
p->m_current = (NodeBrushPresetItem*)p->m_container->get_child_at(idx);
|
|
|
|
|
p->m_current->m_selected = true;
|
|
|
|
|
p->m_interacted = true;
|
|
|
|
|
}
|
|
|
|
|
if (on_brush_changed)
|
|
|
|
|
on_brush_changed(this, m_current->m_brush);
|
|
|
|
|
m_interacted = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool NodePanelBrushPreset::save()
|
|
|
|
|
@@ -645,7 +669,6 @@ void NodePanelBrushPreset::add_brush(std::shared_ptr<Brush> brush)
|
|
|
|
|
b->thumb_path = brush->m_brush_thumb_path;
|
|
|
|
|
b->high_path = brush->m_brush_path;
|
|
|
|
|
b->m_brush = brush;
|
|
|
|
|
//brush->m_brush->m_tip_size = .05f;
|
|
|
|
|
b->m_preview->m_brush = brush;
|
|
|
|
|
b->m_preview->draw_stroke();
|
|
|
|
|
b->m_thumb->m_use_mipmaps = true;
|
|
|
|
|
@@ -868,7 +891,8 @@ bool NodePanelBrushPreset::import_ppbr(const std::string& path)
|
|
|
|
|
LOG("import_ppbr brush name %s", b->m_name.c_str());
|
|
|
|
|
if (b->valid())
|
|
|
|
|
{
|
|
|
|
|
add_brush(b);
|
|
|
|
|
for (auto p : s_panels)
|
|
|
|
|
p->add_brush(b);
|
|
|
|
|
}
|
|
|
|
|
pb->increment();
|
|
|
|
|
}
|
|
|
|
|
@@ -899,12 +923,10 @@ bool NodePanelBrushPreset::import_abr(const std::string& path)
|
|
|
|
|
if (!str_iequals(ext, "abr") || !Asset::exist(path))
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
auto pb = App::I->show_progress("Importing ABR");
|
|
|
|
|
|
|
|
|
|
abr.open(path);
|
|
|
|
|
|
|
|
|
|
int tot = (int)(abr.m_samples.size() + abr.m_patterns.size() + abr.m_presets.size());
|
|
|
|
|
std::atomic_int count(0);
|
|
|
|
|
auto pb = App::I->show_progress("Importing ABR",
|
|
|
|
|
abr.m_samples.size() + abr.m_patterns.size() + abr.m_presets.size());
|
|
|
|
|
|
|
|
|
|
parallel_for(abr.m_samples.size(), [&](size_t i)
|
|
|
|
|
//for (const auto& samp : abr.m_samples)
|
|
|
|
|
@@ -920,9 +942,7 @@ bool NodePanelBrushPreset::import_abr(const std::string& path)
|
|
|
|
|
samp.second->save_png(path_high);
|
|
|
|
|
auto thumb = padded.resize(64, 64);
|
|
|
|
|
thumb.save_png(path_thumb);
|
|
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
pb->set_progress((float)count / (float)tot);
|
|
|
|
|
pb->increment();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
parallel_for(abr.m_patterns.size(), [&](size_t i)
|
|
|
|
|
@@ -936,24 +956,22 @@ bool NodePanelBrushPreset::import_abr(const std::string& path)
|
|
|
|
|
patt.second->save_png(path_high);
|
|
|
|
|
auto thumb = patt.second->resize(64, 64);
|
|
|
|
|
thumb.save_png(path_thumb);
|
|
|
|
|
|
|
|
|
|
count++;
|
|
|
|
|
pb->set_progress((float)count / (float)tot);
|
|
|
|
|
pb->increment();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
auto brushes = abr.compute_brushes(App::I->data_path);
|
|
|
|
|
for (const auto& pr : brushes)
|
|
|
|
|
for (const auto& b : brushes)
|
|
|
|
|
{
|
|
|
|
|
if (pr->valid())
|
|
|
|
|
if (b->valid())
|
|
|
|
|
{
|
|
|
|
|
LOG("add preset %s", pr->m_name.c_str());
|
|
|
|
|
App::I->presets->add_brush(pr);
|
|
|
|
|
LOG("add preset %s", b->m_name.c_str());
|
|
|
|
|
for (auto p : s_panels)
|
|
|
|
|
p->add_brush(b);
|
|
|
|
|
}
|
|
|
|
|
count++;
|
|
|
|
|
pb->set_progress((float)count / (float)tot);
|
|
|
|
|
pb->increment();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
App::I->presets->save();
|
|
|
|
|
save();
|
|
|
|
|
pb->destroy();
|
|
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
@@ -974,8 +992,11 @@ bool NodePanelBrushPreset::import_brush(const std::string& path)
|
|
|
|
|
|
|
|
|
|
void NodePanelBrushPreset::clear_brushes()
|
|
|
|
|
{
|
|
|
|
|
m_container->remove_all_children();
|
|
|
|
|
m_notification->SetVisibility(m_container->m_children.size() == 0);
|
|
|
|
|
for (auto p : s_panels)
|
|
|
|
|
{
|
|
|
|
|
p->m_container->remove_all_children();
|
|
|
|
|
p->m_notification->SetVisibility(p->m_container->m_children.size() == 0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void NodePanelBrushPreset::added(Node* parent)
|
|
|
|
|
|