move presets panel out of stroke panel, implement brush buttons in quick panel

This commit is contained in:
2019-03-05 17:49:14 +01:00
parent 1f794a6811
commit 1cbe9a4a76
10 changed files with 141 additions and 38 deletions

View File

@@ -2,6 +2,7 @@
#include "node_panel_quick.h"
#include "node_stroke_preview.h"
#include "node_image.h"
#include "app.h"
Node* NodePanelQuick::clone_instantiate() const
{
@@ -29,11 +30,11 @@ void NodePanelQuick::set_color(glm::vec3 color)
void NodePanelQuick::init_controls()
{
auto s = find<NodeStrokePreview>("quick-brush1");
s->m_brush = std::make_shared<Brush>();
s->m_max_size = 10;
s->m_brush->load_tip("data/brushes/Round-Hard.png", "data/brushes/thumbs/Round-Hard.png");
s->draw_stroke();
//auto s = find<NodeStrokePreview>("quick-brush1");
//s->m_brush = std::make_shared<Brush>();
//s->m_max_size = 10;
//s->m_brush->load_tip("data/brushes/Round-Hard.png", "data/brushes/thumbs/Round-Hard.png");
//s->draw_stroke();
m_picker = std::make_shared<NodeColorPicker>();
m_picker->m_manager = m_manager;
@@ -46,11 +47,13 @@ void NodePanelQuick::init_controls()
m_slider_size = find<NodeSliderV>("quick-size");
m_slider_size->on_value_changed = [this](Node* target, float value) {
static_cast<NodeStrokePreview*>(m_button_brush_current->m_children[0].get())->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) {
static_cast<NodeStrokePreview*>(m_button_brush_current->m_children[0].get())->draw_stroke();
if (on_flow_change)
on_flow_change(target, value);
};
@@ -69,6 +72,79 @@ void NodePanelQuick::init_controls()
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);
}
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;
if (on_brush_change)
on_brush_change(this, static_cast<NodeStrokePreview*>(button->m_children[0].get())->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)