#include "pch.h" #include "log.h" #include "node_panel_color.h" #include "canvas.h" Node* NodePanelColor::clone_instantiate() const { return new NodePanelColor(); } void NodePanelColor::clone_finalize(Node* dest) const { NodePanelColor* n = static_cast(dest); n->init_controls(); } void NodePanelColor::init() { init_template("tpl-panel-color"); init_controls(); } void NodePanelColor::init_controls() { m_quad = find("quad"); m_hue = find("hue"); m_hue->on_hue_changed = [this](Node*, glm::vec4 hue_color) { m_base_color = m_quad->m_color = hue_color; float hue = convert_rgb2hsv(m_base_color).x; m_color = glm::vec4(convert_hsv2rgb(glm::vec3(hue, m_cursor.x, 1.f-m_cursor.y)), 1.f); m_quad->m_color = hue_color; if (on_color_changed) on_color_changed(this, m_color); m_interacted = true; }; m_quad->on_value_changed = [this](Node*, glm::vec2 pos) { m_cursor = pos; float hue = convert_rgb2hsv(m_base_color).x; m_color = glm::vec4(convert_hsv2rgb(glm::vec3(hue, m_cursor.x, 1.f-m_cursor.y)), 1.f); if (on_color_changed) on_color_changed(this, m_color); m_interacted = true; }; m_hue->set_value(0); } void NodePanelColor::set_color(glm::vec3 rgb) { auto hsv = convert_rgb2hsv(rgb); m_hue->m_value = hsv.x; m_quad->m_value = glm::vec2(hsv.y, 1.f - hsv.z); m_quad->m_color = glm::vec4(rgb, 1); m_cursor = m_quad->m_value; m_base_color = glm::vec4(rgb, 1); } kEventResult NodePanelColor::handle_event(Event* e) { switch (e->m_type) { case kEventType::MouseLeave: if (!m_interacted) break; // else fall through case kEventType::MouseUpL: if (!m_mouse_inside) { mouse_release(); m_parent->remove_child(this); if (on_popup_close) on_popup_close(this); } break; default: return kEventResult::Available; break; } return kEventResult::Available; } void NodePanelColor::added(Node* parent) { set_color(Canvas::I->m_current_brush->m_tip_color); m_interacted = false; }