add ABR brushes and presets with properties and patterns
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#endif
|
||||
#include "canvas.h"
|
||||
#include "app.h"
|
||||
#include "abr.h"
|
||||
|
||||
Node* NodeButtonBrush::clone_instantiate() const
|
||||
{
|
||||
@@ -50,29 +51,28 @@ void NodePanelBrush::init()
|
||||
|
||||
m_btn_add = find<NodeButtonCustom>("btn-add");
|
||||
m_btn_add->on_click = [this](Node*) {
|
||||
App::I.pick_image([this](std::string path) {
|
||||
App::I.pick_file({ "JPG", "PNG", "ABR" }, [this](std::string path) {
|
||||
std::string name, base, ext;
|
||||
std::regex r(R"((.*)[\\/]([^\\/]+)\.(\w+)$)");
|
||||
std::smatch m;
|
||||
if (!std::regex_search(path, m, r))
|
||||
return;
|
||||
base = m[1].str();
|
||||
name = m[2].str();
|
||||
ext = m[3].str();
|
||||
Image img;
|
||||
if (img.load_file(path))
|
||||
|
||||
if (str_iequals(ext, "abr"))
|
||||
{
|
||||
std::string name, base, ext;
|
||||
std::regex r(R"((.*)[\\/]([^\\/]+)\.(\w+)$)");
|
||||
std::smatch m;
|
||||
if (std::regex_search(path, m, r))
|
||||
ABR abr;
|
||||
abr.open(path);
|
||||
for (const auto& samp : abr.m_samples)
|
||||
{
|
||||
base = m[1].str();
|
||||
name = m[2].str();
|
||||
ext = m[3].str();
|
||||
|
||||
std::string path_high = App::I.data_path + "/brushes/" + name + ".png";
|
||||
std::string path_thumb = App::I.data_path + "/brushes/thumbs/" + name + ".png";
|
||||
|
||||
img = img.resize_squared();
|
||||
img.gayscale_alpha();
|
||||
|
||||
auto thumb = img.resize(64, 64);
|
||||
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";
|
||||
samp.second->save(path_high);
|
||||
auto thumb = samp.second->resize(64, 64);
|
||||
thumb.save(path_thumb);
|
||||
auto po2 = img.resize_power2();
|
||||
po2.save(path_high);
|
||||
|
||||
async_start();
|
||||
NodeButtonBrush* brush = new NodeButtonBrush;
|
||||
@@ -86,11 +86,54 @@ void NodePanelBrush::init()
|
||||
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();
|
||||
save();
|
||||
}
|
||||
for (const auto& patt : abr.m_patterns)
|
||||
{
|
||||
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(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;
|
||||
if (pr->load())
|
||||
presets->add_brush(pr);
|
||||
}
|
||||
//save();
|
||||
}
|
||||
else if (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";
|
||||
|
||||
img = img.resize_squared();
|
||||
img.gayscale_alpha();
|
||||
|
||||
auto thumb = img.resize(64, 64);
|
||||
thumb.save(path_thumb);
|
||||
auto po2 = img.resize_power2();
|
||||
po2.save(path_high);
|
||||
|
||||
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();
|
||||
save();
|
||||
}
|
||||
});
|
||||
};
|
||||
@@ -317,7 +360,7 @@ bool NodePanelBrush::restore()
|
||||
brush->thumb_path = path_thumb;
|
||||
brush->high_path = path_high;
|
||||
brush->brush_name = name;
|
||||
brush->m_user_brush = true;
|
||||
brush->m_user_brush = i.m_user_brush;
|
||||
brush->on_click = std::bind(&NodePanelBrush::handle_click, this, std::placeholders::_1);
|
||||
}
|
||||
}
|
||||
@@ -602,3 +645,21 @@ bool NodePanelBrushPreset::restore()
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void NodePanelBrushPreset::add_brush(std::shared_ptr<Brush> brush)
|
||||
{
|
||||
NodeBrushPresetItem* b = new NodeBrushPresetItem;
|
||||
m_container->add_child(b);
|
||||
b->init();
|
||||
b->create();
|
||||
b->loaded();
|
||||
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;
|
||||
b->m_thumb->set_image(brush->m_brush_thumb_path);
|
||||
b->on_click = std::bind(&NodePanelBrushPreset::handle_click, this, std::placeholders::_1);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user