preset remove
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user