add brush preset panel

This commit is contained in:
2017-10-03 14:35:30 +01:00
parent db55a055fd
commit 41e52b7757
7 changed files with 191 additions and 7 deletions

View File

@@ -106,3 +106,105 @@ void NodePanelBrush::select_brush(int brush_id)
}
}
}
// -----------------------------------------------------------------------
Node* NodeBrushPresetItem::clone_instantiate() const
{
return new NodeBrushPresetItem();
}
void NodeBrushPresetItem::init()
{
init_template("tpl-brush-preset");
color_hover = glm::vec4(.7, .7, .7, 1);
color_normal = glm::vec4(.3, .3, .3, 1);
m_color = color_normal;
m_thumb = (NodeImage*)m_children[0].get();
m_preview = (NodeStrokePreview*)m_children[1].get();
}
void NodeBrushPresetItem::draw()
{
m_color = m_mouse_inside ? color_hover : color_normal;
m_color = m_selected ? glm::vec4(.9, 0, 0, 1) : m_color;
NodeButtonCustom::draw();
}
//---
Node* NodePanelBrushPreset::clone_instantiate() const
{
return new NodePanelBrushPreset();
}
void NodePanelBrushPreset::init()
{
init_template("tpl-panel-brush-preset");
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->high_path = path_hi;
brush->high_id = const_hash(path_hi.c_str());
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)
{
if (target == m_current)
return;
if (m_current)
m_current->m_selected = false;
m_current = (NodeButtonBrush*)target;
m_current->m_selected = true;
if (on_brush_changed)
on_brush_changed(this, m_current->m_brushID);
}
ui::Brush NodePanelBrushPreset::get_brush(int index) const
{
auto b = m_brushes[index]->m_brush;
TextureManager::load(m_brushes[index]->high_path.c_str(), true);
b.m_tex_id = m_brushes[index]->high_id;
return b;
}
uint16_t NodePanelBrushPreset::get_texture_id(int index) const
{
TextureManager::load(m_brushes[index]->high_path.c_str(), true);
return m_brushes[index]->high_id;
}
int NodePanelBrushPreset::get_brush_id(int index) const
{
return m_brushes[index]->m_brushID;
}