move abr import to main menu, add progress bar
This commit is contained in:
@@ -51,7 +51,7 @@ void NodePanelBrush::init()
|
||||
|
||||
m_btn_add = find<NodeButtonCustom>("btn-add");
|
||||
m_btn_add->on_click = [this](Node*) {
|
||||
App::I.pick_file({ "JPG", "PNG", "ABR" }, [this](std::string path) {
|
||||
App::I.pick_file({ "JPG", "PNG" }, [this](std::string path) {
|
||||
std::string name, base, ext;
|
||||
std::regex r(R"((.*)[\\/]([^\\/]+)\.(\w+)$)");
|
||||
std::smatch m;
|
||||
@@ -61,72 +61,7 @@ void NodePanelBrush::init()
|
||||
name = m[2].str();
|
||||
ext = m[3].str();
|
||||
Image img;
|
||||
|
||||
if (str_iequals(ext, "abr"))
|
||||
{
|
||||
ABR abr;
|
||||
LOG("ABR detected");
|
||||
|
||||
if (!abr.open(path))
|
||||
{
|
||||
LOG("ABR read failed");
|
||||
return;
|
||||
}
|
||||
|
||||
parallel_for(abr.m_samples.size(), [&](size_t i)
|
||||
{
|
||||
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);
|
||||
auto thumb = padded.resize(64, 64);
|
||||
thumb.save(path_thumb);
|
||||
|
||||
//async_start();
|
||||
//NodeButtonBrush* brush = new NodeButtonBrush;
|
||||
//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, this, std::placeholders::_1);
|
||||
//app_redraw();
|
||||
//async_end();
|
||||
});
|
||||
parallel_for(abr.m_patterns.size(), [&](size_t i)
|
||||
{
|
||||
auto ii = abr.m_patterns.begin();
|
||||
std::advance(ii, i);
|
||||
const auto& patt = *ii;
|
||||
std::string path_high = App::I.data_path + "/textures/" + patt.first + ".png";
|
||||
std::string path_thumb = App::I.data_path + "/textures/thumbs/" + patt.first + ".png";
|
||||
patt.second->save(path_high);
|
||||
auto thumb = patt.second->resize(64, 64);
|
||||
thumb.save(path_thumb);
|
||||
});
|
||||
auto brushes = abr.compute_brushes(App::I.data_path);
|
||||
for (const auto& pr : brushes)
|
||||
{
|
||||
auto presets = App::I.stroke->m_presets_popup;
|
||||
async_start();
|
||||
if (pr->load())
|
||||
{
|
||||
LOG("add preset %s", pr->m_name.c_str());
|
||||
presets->add_brush(pr);
|
||||
}
|
||||
async_end();
|
||||
}
|
||||
//save();
|
||||
}
|
||||
else if (!m_dir_name.empty() && img.load_file(path))
|
||||
if (!m_dir_name.empty() && img.load_file(path))
|
||||
{
|
||||
std::string path_high = App::I.data_path + "/" + m_dir_name + "/" + name + ".png";
|
||||
std::string path_thumb = App::I.data_path + "/" + m_dir_name + "/thumbs/" + name + ".png";
|
||||
@@ -547,7 +482,7 @@ bool NodePanelBrushPreset::save()
|
||||
i.m_dual_path_len = b->m_brush_path.size();
|
||||
i.m_dual_thumb_path_len = b->m_brush_thumb_path.size();
|
||||
i.m_stencil_path_len = b->m_pattern_path.size();
|
||||
i.m_stencil_thumb_path_len = b->m_texture_thumb_path.size();
|
||||
i.m_stencil_thumb_path_len = b->m_pattern_thumb_path.size();
|
||||
i.m_tip_color = b->m_tip_color;
|
||||
i.m_tip_size = b->m_tip_size;
|
||||
i.m_tip_spacing = b->m_tip_spacing;
|
||||
@@ -611,7 +546,7 @@ bool NodePanelBrushPreset::save()
|
||||
fwrite(b->m_dual_path.c_str(), 1, b->m_brush_path.size(), fp);
|
||||
fwrite(b->m_dual_thumb_path.c_str(), 1, b->m_brush_thumb_path.size(), fp);
|
||||
fwrite(b->m_pattern_path.c_str(), 1, b->m_pattern_path.size(), fp);
|
||||
fwrite(b->m_texture_thumb_path.c_str(), 1, b->m_texture_thumb_path.size(), fp);
|
||||
fwrite(b->m_pattern_thumb_path.c_str(), 1, b->m_pattern_thumb_path.size(), fp);
|
||||
}
|
||||
fclose(fp);
|
||||
return true;
|
||||
@@ -704,19 +639,19 @@ bool NodePanelBrushPreset::restore()
|
||||
b->m_dual_path.resize(i.m_brush_path_len);
|
||||
b->m_dual_thumb_path.resize(i.m_brush_thumb_path_len);
|
||||
b->m_pattern_path.resize(i.m_stencil_path_len);
|
||||
b->m_texture_thumb_path.resize(i.m_stencil_thumb_path_len);
|
||||
b->m_pattern_thumb_path.resize(i.m_stencil_thumb_path_len);
|
||||
fread((char*)b->m_name.c_str(), 1, b->m_name.size(), fp);
|
||||
fread((char*)b->m_brush_path.c_str(), 1, b->m_brush_path.size(), fp);
|
||||
fread((char*)b->m_brush_thumb_path.c_str(), 1, b->m_brush_thumb_path.size(), fp);
|
||||
fread((char*)b->m_dual_path.c_str(), 1, b->m_brush_path.size(), fp);
|
||||
fread((char*)b->m_dual_thumb_path.c_str(), 1, b->m_brush_thumb_path.size(), fp);
|
||||
fread((char*)b->m_pattern_path.c_str(), 1, b->m_pattern_path.size(), fp);
|
||||
fread((char*)b->m_texture_thumb_path.c_str(), 1, b->m_texture_thumb_path.size(), fp);
|
||||
fread((char*)b->m_pattern_thumb_path.c_str(), 1, b->m_pattern_thumb_path.size(), fp);
|
||||
|
||||
if (b->load_tip(b->m_brush_path, b->m_brush_thumb_path))
|
||||
{
|
||||
if (!b->m_pattern_path.empty())
|
||||
b->load_pattern(b->m_pattern_path, b->m_texture_thumb_path);
|
||||
b->load_pattern(b->m_pattern_path, b->m_pattern_thumb_path);
|
||||
|
||||
NodeBrushPresetItem* brush = new NodeBrushPresetItem;
|
||||
m_container->add_child(brush);
|
||||
|
||||
Reference in New Issue
Block a user