integrate quick panel and new color picker

This commit is contained in:
2019-03-04 18:38:38 +01:00
parent fb006a6859
commit 6e73a9eee5
13 changed files with 234 additions and 81 deletions

View File

@@ -18,7 +18,7 @@ void NodePanelQuick::clone_finalize(Node* dest) const
void NodePanelQuick::init()
{
parent::init();
auto t = static_cast<const NodeBorder*>(init_template("panel-quick"));
auto t = static_cast<const NodeBorder*>(init_template("tpl-panel-quick"));
init_controls();
}
@@ -39,32 +39,77 @@ void NodePanelQuick::init_controls()
m_picker->m_flood_events = true;
m_picker->m_capture_children = false;
if (auto b = find<NodeButtonCustom>("quick-color1"))
{
b->on_click = [this,b](Node*) {
auto screen = root()->m_size;
glm::vec2 pos = b->m_pos + glm::vec2(b->m_size.x, 0);
root()->add_child(m_picker);
auto tick = root()->add_child<NodeImage>();
tick->SetPositioning(YGPositionTypeAbsolute);
tick->SetSize(16, 32);
tick->SetPosition(pos.x, pos.y + (b->m_size.y - 32) * 0.5f);
tick->set_image("data/ui/popup-tick.png");
//float hh = m_picker->m_container->m_children.size() > 10 ? App::I.height / App::I.zoom * .75f : 400.f;
//m_picker->SetHeight(4);
root()->update();
pos.y -= 130;
if ((pos.y + m_picker->m_size.y) > screen.y)
pos.y = screen.y - m_picker->m_size.y;
if (pos.y < 0)
pos.y = 0;
m_picker->SetPosition(pos.x + 16, pos.y);
m_picker->mouse_capture();
root()->update();
m_slider_size = find<NodeSliderV>("quick-size");
m_slider_size->on_value_changed = [this](Node* target, float value) {
if (on_size_change)
on_size_change(target, value);
};
m_slider_flow = find<NodeSliderV>("quick-flow");
m_slider_flow->on_value_changed = [this](Node* target, float value) {
if (on_flow_change)
on_flow_change(target, value);
};
m_picker->on_popup_close = [this, tick](Node*) {
tick->destroy();
};
};
}
m_button_color1 = find<NodeButtonCustom>("quick-color1");
m_button_color2 = find<NodeButtonCustom>("quick-color2");
m_button_color3 = find<NodeButtonCustom>("quick-color3");
m_button_color_current = m_button_color1;
m_button_color_current->set_active(true);
m_button_color1->on_click = std::bind(&this_class::handle_button_color_click, this, std::placeholders::_1);
m_button_color2->on_click = std::bind(&this_class::handle_button_color_click, this, std::placeholders::_1);
m_button_color3->on_click = std::bind(&this_class::handle_button_color_click, this, std::placeholders::_1);
m_button_color1->color_active = { 0, 0, 0, 0.5f };
m_button_color2->color_active = { 0, 0, 0, 0.5f };
m_button_color3->color_active = { 0, 0, 0, 0.5f };
m_button_color1->set_color({ 0, 0, 0, 0 });
m_button_color2->set_color({ 0, 0, 0, 0 });
m_button_color3->set_color({ 0, 0, 0, 0 });
}
void NodePanelQuick::handle_button_color_click(Node* target)
{
// the first time select the box
if (m_button_color_current != target)
{
auto button = static_cast<NodeButtonCustom*>(target);
button->set_active(true);
m_button_color_current->set_active(false);
m_button_color_current = button;
if (on_color_change)
on_color_change(this, static_cast<NodeBorder*>(button->m_children[0].get())->m_color);
return;
}
// if the box is already selected show the popup
auto screen = root()->m_size;
glm::vec2 pos = target->m_pos + glm::vec2(target->m_size.x, 0);
root()->add_child(m_picker);
auto tick = root()->add_child<NodeImage>();
tick->SetPositioning(YGPositionTypeAbsolute);
tick->SetSize(16, 32);
tick->SetPosition(pos.x, pos.y + (target->m_size.y - 32) * 0.5f);
tick->set_image("data/ui/popup-tick.png");
//float hh = m_picker->m_container->m_children.size() > 10 ? App::I.height / App::I.zoom * .75f : 400.f;
//m_picker->SetHeight(4);
root()->update();
pos.y -= 130;
if ((pos.y + m_picker->m_size.y) > screen.y)
pos.y = screen.y - m_picker->m_size.y;
if (pos.y < 0)
pos.y = 0;
m_picker->SetPosition(pos.x + 16, pos.y);
m_picker->mouse_capture();
root()->update();
auto c = static_cast<NodeBorder*>(target->m_children[0].get());
m_picker->set_color(c->m_color);
m_picker->on_popup_close = [this, tick](Node*) {
tick->destroy();
};
m_picker->on_color_change = [this, c](Node*, glm::vec3 rgb) {
c->m_color = glm::vec4(rgb, 1.f);
if (on_color_change)
on_color_change(this, rgb);
};
}