#include "pch.h" #include "log.h" #include "node_panel_brush.h" #include "asset.h" #ifdef __APPLE__ #include #endif Node* NodeButtonBrush::clone_instantiate() const { return new NodeButtonBrush(); } void NodeButtonBrush::init() { init_template("tpl-brush-icon"); color_hover = glm::vec4(.7, .7, .7, 1); color_normal = glm::vec4(.3, .3, .3, 1); m_color = color_normal; img = (NodeImage*)m_children[0].get(); } void NodeButtonBrush::set_icon(const char* path) { img->m_path = path; img->m_tex_id = const_hash(img->m_path.c_str()); img->create(); } void NodeButtonBrush::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* NodePanelBrush::clone_instantiate() const { return new NodePanelBrush(); } void NodePanelBrush::init() { init_template("tpl-panel-brushes"); //m_layers_container = find("layers-container"); static auto icons = Asset::list_files("data/Icons/", true, ".*\\.png$"); if ((m_container = find("brushes"))) { int count = 0; for (auto& i : icons) { std::string path = "data/Icons/" + i; NodeButtonBrush* brush = new NodeButtonBrush; m_container->add_child(brush); brush->init(); brush->create(); brush->loaded(); brush->set_icon(path.c_str()); brush->m_brushID = count++; m_brushes.push_back(brush); brush->on_click = std::bind(&NodePanelBrush::handle_click, this, std::placeholders::_1); } } } void NodePanelBrush::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); } uint16_t NodePanelBrush::get_texture_id(int index) const { return m_brushes[index]->img->m_tex_id; }