implement export/import ppbr
This commit is contained in:
@@ -23,110 +23,6 @@ void NodePanelStroke::init()
|
||||
init_controls();
|
||||
}
|
||||
|
||||
bool NodePanelStroke::import_abr(const std::string& path)
|
||||
{
|
||||
BT_SetTerminate();
|
||||
|
||||
ABR abr;
|
||||
LOG("ABR detected");
|
||||
|
||||
std::string name, base, ext;
|
||||
std::regex r(R"((.*)[\\/]([^\\/]+)\.(\w+)$)");
|
||||
std::smatch m;
|
||||
if (!std::regex_search(path, m, r))
|
||||
return false;
|
||||
base = m[1].str();
|
||||
name = m[2].str();
|
||||
ext = m[3].str();
|
||||
|
||||
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);
|
||||
|
||||
parallel_for(abr.m_samples.size(), [&](size_t i)
|
||||
//for (const auto& samp : abr.m_samples)
|
||||
{
|
||||
auto ii = abr.m_samples.begin();
|
||||
std::advance(ii, i);
|
||||
const auto& samp = *ii;
|
||||
std::string path_high = App::I->data_path + "/brushes/" + samp.first + ".png";
|
||||
std::string path_thumb = App::I->data_path + "/brushes/thumbs/" + samp.first + ".png";
|
||||
auto padded = samp.second->resize_squared(glm::u8vec4(255));
|
||||
//auto high = padded.resize_power2();
|
||||
//high.save(path_high);
|
||||
samp.second->save_png(path_high);
|
||||
auto thumb = padded.resize(64, 64);
|
||||
thumb.save_png(path_thumb);
|
||||
|
||||
NodeButtonBrush* brush = new NodeButtonBrush;
|
||||
m_brush_popup->m_container->add_child(brush);
|
||||
brush->init();
|
||||
brush->create();
|
||||
brush->loaded();
|
||||
brush->set_icon(path_thumb.c_str());
|
||||
brush->thumb_path = path_thumb;
|
||||
brush->high_path = path_high;
|
||||
brush->brush_name = name;
|
||||
brush->m_user_brush = true;
|
||||
brush->on_click = std::bind(&NodePanelBrush::handle_click, m_brush_popup, std::placeholders::_1);
|
||||
count++;
|
||||
pb->set_progress((float)count / (float)tot);
|
||||
});
|
||||
m_brush_popup->save();
|
||||
|
||||
parallel_for(abr.m_patterns.size(), [&](size_t i)
|
||||
//for (const auto& patt : abr.m_patterns)
|
||||
{
|
||||
auto ii = abr.m_patterns.begin();
|
||||
std::advance(ii, i);
|
||||
const auto& patt = *ii;
|
||||
std::string path_high = App::I->data_path + "/patterns/" + patt.first + ".png";
|
||||
std::string path_thumb = App::I->data_path + "/patterns/thumbs/" + patt.first + ".png";
|
||||
patt.second->save_png(path_high);
|
||||
auto thumb = patt.second->resize(64, 64);
|
||||
thumb.save_png(path_thumb);
|
||||
|
||||
NodeButtonBrush* brush = new NodeButtonBrush;
|
||||
m_pattern_popup->m_container->add_child(brush);
|
||||
brush->init();
|
||||
brush->create();
|
||||
brush->loaded();
|
||||
brush->set_icon(path_thumb.c_str());
|
||||
brush->thumb_path = path_thumb;
|
||||
brush->high_path = path_high;
|
||||
brush->brush_name = name;
|
||||
brush->m_user_brush = true;
|
||||
brush->on_click = std::bind(&NodePanelBrush::handle_click, m_pattern_popup, std::placeholders::_1);
|
||||
count++;
|
||||
pb->set_progress((float)count / (float)tot);
|
||||
});
|
||||
m_pattern_popup->save();
|
||||
|
||||
auto brushes = abr.compute_brushes(App::I->data_path);
|
||||
for (const auto& pr : brushes)
|
||||
{
|
||||
if (pr->valid())
|
||||
{
|
||||
LOG("add preset %s", pr->m_name.c_str());
|
||||
App::I->presets->add_brush(pr);
|
||||
}
|
||||
count++;
|
||||
pb->set_progress((float)count / (float)tot);
|
||||
}
|
||||
|
||||
App::I->presets->save();
|
||||
pb->destroy();
|
||||
//save();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
void NodePanelStroke::update_controls()
|
||||
{
|
||||
const auto& b = Canvas::I->m_current_brush;
|
||||
|
||||
Reference in New Issue
Block a user