diff --git a/data/layout.xml b/data/layout.xml
index 17c49a3..551141e 100644
--- a/data/layout.xml
+++ b/data/layout.xml
@@ -96,7 +96,7 @@
-
+
diff --git a/src/node.h b/src/node.h
index 8fd33cf..be9aa1a 100644
--- a/src/node.h
+++ b/src/node.h
@@ -130,7 +130,7 @@ public:
Node&& operator=(Node&& o);
Node(Node&& o);
Node();
- ~Node();
+ virtual ~Node();
void SetWidth(float value);
void SetWidthP(float value);
diff --git a/src/node_panel_brush.cpp b/src/node_panel_brush.cpp
index 3379700..e057324 100644
--- a/src/node_panel_brush.cpp
+++ b/src/node_panel_brush.cpp
@@ -178,6 +178,11 @@ void NodeBrushPresetItem::draw()
NodeButtonCustom::draw();
}
+NodeBrushPresetItem::~NodeBrushPresetItem()
+{
+ bool u = m_brush.unique();
+}
+
//---
Node* NodePanelBrushPreset::clone_instantiate() const
@@ -203,50 +208,29 @@ void NodePanelBrushPreset::init()
brush->m_preview->m_brush = brush->m_brush;
brush->m_preview->draw_stroke();
brush->m_thumb->set_image(brush->m_brush->m_brush_thumb_path);
- m_brushes.push_back(brush);
brush->on_click = std::bind(&NodePanelBrushPreset::handle_click, this, std::placeholders::_1);
save();
};
+ m_btn_delete = find("btn-remove");
+ m_btn_delete->on_click = [this](Node*) {
+ if (!m_current)
+ return;
+ int index = m_container->get_child_index(m_current);
+ m_current->destroy();
+ if (m_container->m_children.empty())
+ {
+ m_current = nullptr;
+ }
+ else
+ {
+ int next = std::min(m_container->m_children.size() - 1, index);
+ m_current = (NodeBrushPresetItem*)m_container->m_children[next].get();
+ m_current->m_selected = true;
+ }
+ save();
+ };
restore();
-
-/*
- static auto icons = Asset::list_files("data/thumbs", true, ".*\\.png$");
-
- if ((m_container = find("brushes")))
- {
- int count = 0;
- for (auto& i : icons)
- {
- std::string path = "data/thumbs/" + i;
- std::string path_hi = "data/brushes/" + i;
- NodeBrushPresetItem* brush = new NodeBrushPresetItem;
- m_container->add_child(brush);
- brush->init();
- brush->create();
- brush->loaded();
-// brush->set_icon(path.c_str());
- brush->m_brushID = count++;
- brush->thumb_path = path;
- brush->high_path = path_hi;
- brush->high_id = const_hash(path_hi.c_str());
- brush->m_brush = std::make_shared();
- //brush->m_brush->m_tex_id = const_hash(path.c_str());
- brush->m_brush->m_tip_size = .05;
- brush->m_brush->m_tip_flow = .2;
- brush->m_brush->m_tip_opacity = 1;
- brush->m_brush->m_tip_spacing = 0.03;
- //brush->m_brush->m_jitter_spread = (rand() % 1000) * 0.0001;
- brush->m_preview->m_brush = brush->m_brush;
- //brush->m_preview->draw_stroke();
- brush->m_thumb->m_path = path;
- brush->m_thumb->m_tex_id = const_hash(path.c_str());
- brush->m_thumb->create();
- m_brushes.push_back(brush);
- brush->on_click = std::bind(&NodePanelBrushPreset::handle_click, this, std::placeholders::_1);
- }
- }
-*/
}
void NodePanelBrushPreset::handle_click(Node* target)
@@ -267,10 +251,11 @@ bool NodePanelBrushPreset::save()
if (FILE* fp = fopen(path.c_str(), "wb"))
{
header_t h;
- h.count = m_brushes.size();
+ h.count = m_container->m_children.size();
fwrite(&h, sizeof(h), 1, fp);
- for (const auto& b : m_brushes)
+ for (const auto& child : m_container->m_children)
{
+ auto b = std::static_pointer_cast(child);
item_t i;
i.m_name_len = b->m_brush->m_name.size();
i.m_brush_path_len = b->m_brush->m_brush_path.size();
@@ -364,6 +349,8 @@ bool NodePanelBrushPreset::restore()
fread((char*)b->m_stencil_path.c_str(), 1, b->m_stencil_path.size(), fp);
b->load_texture(b->m_brush_path, b->m_brush_thumb_path);
+ if (!b->m_stencil_path.empty())
+ b->load_stencil(b->m_stencil_path);
NodeBrushPresetItem* brush = new NodeBrushPresetItem;
m_container->add_child(brush);
@@ -377,7 +364,6 @@ bool NodePanelBrushPreset::restore()
brush->m_preview->m_brush = b;
brush->m_preview->draw_stroke();
brush->m_thumb->set_image(brush->m_brush->m_brush_thumb_path);
- m_brushes.push_back(brush);
brush->on_click = std::bind(&NodePanelBrushPreset::handle_click, this, std::placeholders::_1);
}
fclose(fp);
diff --git a/src/node_panel_brush.h b/src/node_panel_brush.h
index 49e3e0d..534b4e1 100644
--- a/src/node_panel_brush.h
+++ b/src/node_panel_brush.h
@@ -55,15 +55,18 @@ public:
virtual Node* clone_instantiate() const override;
virtual void init() override;
virtual void draw() override;
+ virtual ~NodeBrushPresetItem();
};
class NodePanelBrushPreset : public Node
{
- std::vector m_brushes;
+ //std::vector m_brushes;
NodeBrushPresetItem* m_current = nullptr;
Node* m_container;
NodeButtonCustom* m_btn_add;
- NodeButtonCustom* m_btn_save;
+ NodeButtonCustom* m_btn_up;
+ NodeButtonCustom* m_btn_down;
+ NodeButtonCustom* m_btn_delete;
struct header_t {
char magic[4]{ 'P', 'P', 'P', 'R' };
uint16_t version = 0;
diff --git a/src/node_panel_stroke.cpp b/src/node_panel_stroke.cpp
index a1ed67c..d3b92ce 100644
--- a/src/node_panel_stroke.cpp
+++ b/src/node_panel_stroke.cpp
@@ -63,7 +63,7 @@ void NodePanelStroke::init_controls()
auto b = std::make_shared();
int br_idx = m_brush_popup->find_brush("Round-Hard");
b->load_texture(m_brush_popup->get_texture_path(br_idx), m_brush_popup->get_thumb_path(br_idx));
- b->load_stencil("data/paper.jpg");
+ //b->load_stencil("data/paper.jpg");
b->m_tip_size = .1f;
b->m_tip_flow = .5f;
b->m_tip_spacing = .1f;