217 lines
8.0 KiB
C++
217 lines
8.0 KiB
C++
#include "pch.h"
|
|
#include "node_panel_quick.h"
|
|
#include "node_stroke_preview.h"
|
|
#include "node_image.h"
|
|
#include "app.h"
|
|
|
|
Node* NodePanelQuick::clone_instantiate() const
|
|
{
|
|
return new this_class;
|
|
}
|
|
|
|
void NodePanelQuick::clone_finalize(Node* dest) const
|
|
{
|
|
parent::clone_finalize(dest);
|
|
auto n = static_cast<this_class*>(dest);
|
|
n->init_controls();
|
|
}
|
|
|
|
void NodePanelQuick::init()
|
|
{
|
|
parent::init();
|
|
init_template("tpl-panel-quick");
|
|
init_controls();
|
|
}
|
|
|
|
void NodePanelQuick::set_color(glm::vec3 color)
|
|
{
|
|
static_cast<NodeBorder*>(m_button_color_current->m_children[0].get())->m_color = glm::vec4(color, 1.f);
|
|
}
|
|
|
|
void NodePanelQuick::init_controls()
|
|
{
|
|
m_picker = std::make_shared<NodeColorPicker>();
|
|
m_picker->m_manager = m_manager;
|
|
m_picker->init();
|
|
m_picker->create();
|
|
m_picker->loaded();
|
|
m_picker->m_mouse_ignore = false;
|
|
m_picker->m_flood_events = true;
|
|
m_picker->m_capture_children = false;
|
|
|
|
m_slider_size = find<NodeSliderV>("quick-size");
|
|
m_slider_size->on_value_changed = [this](Node* target, float value) {
|
|
auto newpos = (m_slider_flow->m_pos + glm::vec2(100.f, m_slider_flow->m_size.y / 2.f)) * App::I.zoom;
|
|
if (auto m = dynamic_cast<CanvasModePen*>(Canvas::I->modes[(int)Canvas::I->m_current_mode][0]))
|
|
{
|
|
m->m_cur_pos = newpos;
|
|
m->m_draw_tip = true;
|
|
m->m_draw_outline = false;
|
|
}
|
|
if (auto m = dynamic_cast<CanvasModeLine*>(Canvas::I->modes[(int)Canvas::I->m_current_mode][0]))
|
|
{
|
|
m->m_cur_pos = newpos;
|
|
m->m_draw_tip = true;
|
|
}
|
|
m_button_brush_current_preview->draw_stroke();
|
|
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) {
|
|
auto newpos = (m_slider_flow->m_pos + glm::vec2(100.f, m_slider_flow->m_size.y / 2.f)) * App::I.zoom;
|
|
if (auto m = dynamic_cast<CanvasModePen*>(Canvas::I->modes[(int)Canvas::I->m_current_mode][0]))
|
|
{
|
|
m->m_cur_pos = newpos;
|
|
m->m_draw_tip = true;
|
|
m->m_draw_outline = false;
|
|
}
|
|
if (auto m = dynamic_cast<CanvasModeLine*>(Canvas::I->modes[(int)Canvas::I->m_current_mode][0]))
|
|
{
|
|
m->m_cur_pos = newpos;
|
|
m->m_draw_tip = true;
|
|
}
|
|
m_button_brush_current_preview->draw_stroke();
|
|
if (on_flow_change)
|
|
on_flow_change(target, value);
|
|
};
|
|
|
|
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 });
|
|
|
|
m_button_brush1 = init_button_brush("quick-brush1");
|
|
m_button_brush2 = init_button_brush("quick-brush2");
|
|
m_button_brush3 = init_button_brush("quick-brush3");
|
|
m_button_brush_current = m_button_brush1;
|
|
m_button_brush_current->set_active(true);
|
|
m_button_brush_current_preview = static_cast<NodeStrokePreview*>(m_button_brush_current->m_children[0].get());
|
|
}
|
|
|
|
NodeButtonCustom* NodePanelQuick::init_button_brush(const std::string& name)
|
|
{
|
|
auto button = find<NodeButtonCustom>(name.c_str());
|
|
button->on_click = std::bind(&this_class::handle_button_brush_click, this, std::placeholders::_1);
|
|
auto pr = static_cast<NodeStrokePreview*>(button->m_children[0].get());
|
|
pr->m_brush = std::make_shared<Brush>();
|
|
pr->m_max_size = 20;
|
|
pr->m_pad_override = 0;
|
|
pr->m_draw_first = true;
|
|
pr->m_brush->load_tip("data/brushes/Round-Hard.png", "data/brushes/thumbs/Round-Hard.png");
|
|
pr->draw_stroke();
|
|
return button;
|
|
}
|
|
|
|
void NodePanelQuick::handle_button_brush_click(Node* button)
|
|
{
|
|
// the first time select the box
|
|
if (m_button_brush_current != button)
|
|
{
|
|
auto b = static_cast<NodeButtonCustom*>(button);
|
|
b->set_active(true);
|
|
m_button_brush_current->set_active(false);
|
|
m_button_brush_current = b;
|
|
m_button_brush_current_preview = static_cast<NodeStrokePreview*>(button->m_children[0].get());
|
|
if (on_brush_change)
|
|
on_brush_change(this, m_button_brush_current_preview->m_brush);
|
|
return;
|
|
}
|
|
|
|
// if the box is already selected show the popup
|
|
|
|
auto screen = root()->m_size;
|
|
glm::vec2 pos = button->m_pos + glm::vec2(button->m_size.x, 0);
|
|
root()->add_child(App::I.presets);
|
|
auto tick = root()->add_child<NodeImage>();
|
|
tick->SetPositioning(YGPositionTypeAbsolute);
|
|
tick->SetSize(16, 32);
|
|
tick->SetPosition(pos.x, pos.y + (button->m_size.y - 32) * 0.5f);
|
|
tick->set_image("data/ui/popup-tick.png");
|
|
float hh = App::I.presets->m_container->m_children.size() > 10 ? App::I.height / App::I.zoom * .75f : 400.f;
|
|
App::I.presets->SetHeight(glm::max(hh, 400.f));
|
|
root()->update();
|
|
if ((pos.y + App::I.presets->m_size.y) > screen.y)
|
|
pos.y = screen.y - App::I.presets->m_size.y;
|
|
if (pos.y < 0)
|
|
pos.y = 0;
|
|
App::I.presets->SetPosition(pos.x + 16, pos.y);
|
|
App::I.presets->SetPositioning(YGPositionTypeAbsolute);
|
|
App::I.presets->m_mouse_ignore = false;
|
|
App::I.presets->m_flood_events = true;
|
|
App::I.presets->m_capture_children = false;
|
|
App::I.presets->mouse_capture();
|
|
root()->update();
|
|
|
|
App::I.presets->on_popup_close = [this, tick](Node*) {
|
|
tick->destroy();
|
|
};
|
|
|
|
App::I.presets->on_brush_changed = [this, button](Node* target, std::shared_ptr<Brush>& b) {
|
|
auto pr = static_cast<NodeStrokePreview*>(button->m_children[0].get());
|
|
*pr->m_brush = *b;
|
|
pr->m_brush->load();
|
|
pr->draw_stroke();
|
|
if (on_brush_change)
|
|
on_brush_change(button, pr->m_brush);
|
|
};
|
|
}
|
|
|
|
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);
|
|
};
|
|
}
|