fix mixer rect, textures popup, parallel abr import

This commit is contained in:
2019-02-15 16:02:52 +01:00
parent 945c51aa25
commit 49d9b17719
13 changed files with 135 additions and 71 deletions

View File

@@ -73,8 +73,11 @@ void NodePanelBrush::init()
return;
}
for (const auto& samp : abr.m_samples)
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));
@@ -83,29 +86,32 @@ void NodePanelBrush::init()
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();
}
for (const auto& patt : abr.m_patterns)
//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)
{
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";
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)
{
@@ -120,10 +126,10 @@ void NodePanelBrush::init()
}
//save();
}
else if (img.load_file(path))
else if (!m_dir_name.empty() && img.load_file(path))
{
std::string path_high = App::I.data_path + "/brushes/" + name + ".png";
std::string path_thumb = App::I.data_path + "/brushes/thumbs/" + name + ".png";
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";
img = img.resize_squared(glm::u8vec4(255));
//img.gayscale_alpha();
@@ -204,13 +210,13 @@ void NodePanelBrush::init()
m_container = find<NodeScroll>("brushes");
restore();
if (m_container->m_children.empty())
if (m_container->m_children.empty() && !m_dir_name.empty())
{
auto icons = Asset::list_files("data/brushes", true, ".*\\.png$");
auto icons = Asset::list_files("data/" + m_dir_name, true, ".*\\.png$");
for (auto& i : icons)
{
std::string path = "data/thumbs/" + i;
std::string path_hi = "data/brushes/" + i;
std::string path = "data/" + m_dir_name + "/thumbs/" + i;
std::string path_hi = "data/" + m_dir_name + "/" + i;
NodeButtonBrush* brush = new NodeButtonBrush;
m_container->add_child(brush);
brush->init();
@@ -224,11 +230,11 @@ void NodePanelBrush::init()
brush->on_click = std::bind(&NodePanelBrush::handle_click, this, std::placeholders::_1);
}
auto custom_icons = Asset::list_files(App::I.data_path + "/brushes", true, ".*\\.png$");
auto custom_icons = Asset::list_files(App::I.data_path + "/" + m_dir_name, true, ".*\\.png$");
for (auto& i : custom_icons)
{
std::string path_thumb = App::I.data_path + "/brushes/thumbs/" + i;
std::string path_high = App::I.data_path + "/brushes/" + i;
std::string path_thumb = App::I.data_path + "/" + m_dir_name + "/thumbs/" + i;
std::string path_high = App::I.data_path + "/" + m_dir_name + "/" + i;
NodeButtonBrush* brush = new NodeButtonBrush;
m_container->add_child(brush);
brush->init();
@@ -290,17 +296,21 @@ int NodePanelBrush::find_brush(const std::string & name) const
std::string NodePanelBrush::get_texture_path(int index) const
{
if (index < 0 || index >= m_container->m_children.size())
return "";
return ((NodeButtonBrush*)m_container->m_children[index].get())->high_path;
}
std::string NodePanelBrush::get_thumb_path(int index) const
{
if (index < 0 || index >= m_container->m_children.size())
return "";
return ((NodeButtonBrush*)m_container->m_children[index].get())->thumb_path;
}
bool NodePanelBrush::save()
{
auto path = App::I.data_path + "/settings/brushes.bin";
auto path = App::I.data_path + "/settings/" + m_dir_name + ".bin";
if (FILE* fp = fopen(path.c_str(), "wb"))
{
header_t h;
@@ -334,7 +344,7 @@ bool NodePanelBrush::save()
bool NodePanelBrush::restore()
{
auto path = App::I.data_path + "/settings/brushes.bin";
auto path = App::I.data_path + "/settings/" + m_dir_name + ".bin";
if (FILE* fp = fopen(path.c_str(), "rb"))
{
header_t h;