preset remove
This commit is contained in:
@@ -96,7 +96,7 @@
|
||||
<icon width="30" icon="add"/>
|
||||
</button-custom>
|
||||
<button-custom id="btn-up" thickness="1" color="0 0" border-color=".0" shrink="1" margin="0 2 0 0">
|
||||
<icon width="30" icon="disk"/>
|
||||
<icon width="30" icon="bullet_arrow_up"/>
|
||||
</button-custom>
|
||||
<button-custom id="btn-down" thickness="1" color="0 0" border-color=".0" shrink="1" margin="0 2 0 0">
|
||||
<icon width="30" icon="bullet_arrow_down"/>
|
||||
|
||||
@@ -130,7 +130,7 @@ public:
|
||||
Node&& operator=(Node&& o);
|
||||
Node(Node&& o);
|
||||
Node();
|
||||
~Node();
|
||||
virtual ~Node();
|
||||
|
||||
void SetWidth(float value);
|
||||
void SetWidthP(float value);
|
||||
|
||||
@@ -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<NodeButtonCustom>("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<int>(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<NodeBorder>("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>();
|
||||
//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<NodeBrushPresetItem>(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);
|
||||
|
||||
@@ -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<NodeBrushPresetItem*> m_brushes;
|
||||
//std::vector<NodeBrushPresetItem*> 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;
|
||||
|
||||
@@ -63,7 +63,7 @@ void NodePanelStroke::init_controls()
|
||||
auto b = std::make_shared<Brush>();
|
||||
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;
|
||||
|
||||
Reference in New Issue
Block a user