fix color picker panel, introduce an added() method when a node is added to che scene

This commit is contained in:
2017-12-23 10:56:38 +00:00
parent b389d895ab
commit 0a3363fb13
6 changed files with 30 additions and 4 deletions

View File

@@ -257,10 +257,6 @@ void App::update(float dt)
canvas->m_canvas->m_touch_lock ? color_button_hlight : color_button_normal);
stroke->update_controls();
auto pix = ui::Canvas::I->m_current_brush.m_tip_color;
auto hsv = convert_rgb2hsv(glm::vec3(pix[0], pix[1], pix[2]));
color->m_hue->m_value.y = hsv.x;
color->m_quad->m_value = glm::vec2(hsv.y, 1.f - hsv.z);
auto observer = [this](Node* n)
{

View File

@@ -98,6 +98,7 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
node->mouse_release();
glm::vec4 pix = canvas->pick_get(loc);
canvas->m_current_brush.m_tip_color = pix;
App::I.color->set_color(pix);
}
m_dragging = false;
m_picking = false;
@@ -109,6 +110,7 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
{
glm::vec4 pix = canvas->pick_get(loc);
canvas->m_current_brush.m_tip_color = pix;
App::I.color->set_color(pix);
}
m_cur_pos = loc;
break;

View File

@@ -186,6 +186,11 @@ void Node::loaded()
}
void Node::added(Node* parent)
{
}
const Node* Node::init_template(const char* id)
{
const auto& m_template = static_cast<Node*>((*m_manager)[const_hash(id)]->m_children[0].get());
@@ -207,6 +212,7 @@ void Node::add_child(Node* n)
n->parent = this;
n->m_manager = m_manager;
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
n->added(this);
}
void Node::add_child(Node* n, int index)
@@ -215,6 +221,7 @@ void Node::add_child(Node* n, int index)
n->parent = this;
n->m_manager = m_manager;
YGNodeInsertChild(y_node, n->y_node, index);
n->added(this);
}
void Node::add_child(std::shared_ptr<Node> n)
@@ -223,6 +230,7 @@ void Node::add_child(std::shared_ptr<Node> n)
n->parent = this;
n->m_manager = m_manager;
YGNodeInsertChild(y_node, n->y_node, YGNodeGetChildCount(y_node));
n->added(this);
}
void Node::add_child(std::shared_ptr<Node> n, int index)
@@ -231,6 +239,7 @@ void Node::add_child(std::shared_ptr<Node> n, int index)
n->parent = this;
n->m_manager = m_manager;
YGNodeInsertChild(y_node, n->y_node, index);
n->added(this);
}
void Node::remove_child(Node* n)

View File

@@ -191,6 +191,7 @@ public:
virtual void create();
virtual void init();
virtual void loaded();
virtual void added(Node* parent);
const Node* init_template(const char* id);
void async_start();
void async_update();

View File

@@ -1,6 +1,7 @@
#include "pch.h"
#include "log.h"
#include "node_panel_color.h"
#include "canvas.h"
Node* NodePanelColor::clone_instantiate() const
{
@@ -27,6 +28,7 @@ void NodePanelColor::init_controls()
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);
};
@@ -40,3 +42,17 @@ void NodePanelColor::init_controls()
};
m_hue->set_value(0);
}
void NodePanelColor::set_color(glm::vec3 rgb)
{
auto hsv = convert_rgb2hsv(rgb);
m_hue->m_value.y = 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;
}
void NodePanelColor::added(Node* parent)
{
set_color(ui::Canvas::I->m_current_brush.m_tip_color);
}

View File

@@ -15,5 +15,7 @@ public:
virtual Node* clone_instantiate() const override;
virtual void clone_finalize(Node* dest) const override;
virtual void init() override;
virtual void added(Node* parent) override;
void init_controls();
void set_color(glm::vec3 rgb);
};