quick panel brushes slots
This commit is contained in:
@@ -119,6 +119,12 @@ void App::init_sidebar()
|
|||||||
//presets = find_or_create_panel<NodePanelBrushPreset>(panels);
|
//presets = find_or_create_panel<NodePanelBrushPreset>(panels);
|
||||||
|
|
||||||
canvas->m_canvas->on_mode_changed = [this](kCanvasMode prev, kCanvasMode mode) {
|
canvas->m_canvas->on_mode_changed = [this](kCanvasMode prev, kCanvasMode mode) {
|
||||||
|
static std::map<kCanvasMode, NodePanelQuick::MiniState> mode_state;
|
||||||
|
mode_state[prev] = quick->get_state();
|
||||||
|
if (mode_state.find(mode) != mode_state.end())
|
||||||
|
quick->set_state(mode_state[mode]);
|
||||||
|
else
|
||||||
|
quick->reset_state();
|
||||||
brush_update();
|
brush_update();
|
||||||
};
|
};
|
||||||
color->on_color_changed = [this](Node* target, glm::vec4 color) {
|
color->on_color_changed = [this](Node* target, glm::vec4 color) {
|
||||||
|
|||||||
@@ -28,6 +28,78 @@ void NodePanelQuick::set_color(glm::vec3 color)
|
|||||||
m_button_color_current_inner->m_color = glm::vec4(color, 1.f);
|
m_button_color_current_inner->m_color = glm::vec4(color, 1.f);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int NodePanelQuick::get_selected_brush_index() const
|
||||||
|
{
|
||||||
|
auto it = std::find(m_button_brushes.begin(), m_button_brushes.end(), m_button_brush_current);
|
||||||
|
return std::distance(m_button_brushes.begin(), it);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodePanelQuick::set_selected_brush_index(int idx)
|
||||||
|
{
|
||||||
|
if (m_button_brush_current)
|
||||||
|
m_button_brush_current->set_active(false);
|
||||||
|
m_button_brush_current = m_button_brushes[idx];
|
||||||
|
m_button_brush_current->set_active(true);
|
||||||
|
m_button_brush_current_preview = static_cast<NodeStrokePreview*>(m_button_brush_current->m_children[0].get());
|
||||||
|
}
|
||||||
|
|
||||||
|
int NodePanelQuick::get_selected_color_index() const
|
||||||
|
{
|
||||||
|
auto it = std::find(m_button_colors.begin(), m_button_colors.end(), m_button_color_current);
|
||||||
|
return std::distance(m_button_colors.begin(), it);
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodePanelQuick::set_selected_color_index(int idx)
|
||||||
|
{
|
||||||
|
if (m_button_color_current)
|
||||||
|
m_button_color_current->set_active(false);
|
||||||
|
m_button_color_current = m_button_colors[idx];
|
||||||
|
m_button_color_current->set_active(true);
|
||||||
|
m_button_color_current_inner = static_cast<NodeBorder*>(m_button_color_current->m_children[0].get());
|
||||||
|
}
|
||||||
|
|
||||||
|
NodePanelQuick::MiniState NodePanelQuick::get_state() const
|
||||||
|
{
|
||||||
|
MiniState s;
|
||||||
|
s.brush_index = get_selected_brush_index();
|
||||||
|
s.color_index = get_selected_color_index();
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
s.brushes[i] = static_cast<NodeStrokePreview*>(m_button_brushes[i]->m_children[0].get())->m_brush;
|
||||||
|
s.colors[i] = static_cast<NodeBorder*>(m_button_color_current->m_children[0].get())->m_color;
|
||||||
|
}
|
||||||
|
return s;
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodePanelQuick::set_state(const MiniState& state)
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
auto b = static_cast<NodeStrokePreview*>(m_button_brushes[i]->m_children[0].get());
|
||||||
|
b->m_brush = state.brushes[i];
|
||||||
|
auto c = static_cast<NodeBorder*>(m_button_color_current->m_children[0].get());
|
||||||
|
c->m_color = state.colors[i];
|
||||||
|
}
|
||||||
|
set_selected_color_index(state.color_index);
|
||||||
|
set_selected_brush_index(state.brush_index);
|
||||||
|
m_button_brush_current_preview->draw_stroke();
|
||||||
|
}
|
||||||
|
|
||||||
|
void NodePanelQuick::reset_state()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
auto b = static_cast<NodeStrokePreview*>(m_button_brushes[i]->m_children[0].get());
|
||||||
|
b->m_brush = std::make_shared<Brush>();
|
||||||
|
b->m_brush->load_tip("data/brushes/Round-Hard.png", "data/brushes/thumbs/Round-Hard.png");
|
||||||
|
auto c = static_cast<NodeBorder*>(m_button_color_current->m_children[0].get());
|
||||||
|
c->m_color = glm::vec4(0, 0, 0, 1);
|
||||||
|
}
|
||||||
|
set_selected_brush_index(0);
|
||||||
|
set_selected_color_index(0);
|
||||||
|
m_button_brush_current_preview->draw_stroke();
|
||||||
|
}
|
||||||
|
|
||||||
void NodePanelQuick::init_controls()
|
void NodePanelQuick::init_controls()
|
||||||
{
|
{
|
||||||
m_picker = std::make_shared<NodeColorPicker>();
|
m_picker = std::make_shared<NodeColorPicker>();
|
||||||
@@ -79,26 +151,20 @@ void NodePanelQuick::init_controls()
|
|||||||
on_flow_change(target, value);
|
on_flow_change(target, value);
|
||||||
};
|
};
|
||||||
|
|
||||||
m_button_color1 = find<NodeButtonCustom>("quick-color1");
|
for (int i = 0; i < m_button_colors.size(); i++)
|
||||||
m_button_color2 = find<NodeButtonCustom>("quick-color2");
|
{
|
||||||
m_button_color3 = find<NodeButtonCustom>("quick-color3");
|
m_button_colors[i] = find<NodeButtonCustom>(fmt::format("quick-color{}", i + 1).c_str());
|
||||||
m_button_color_current = m_button_color1;
|
m_button_colors[i]->on_click = std::bind(&this_class::handle_button_color_click, this, std::placeholders::_1);
|
||||||
|
m_button_colors[i]->color_active = { 0, 0, 0, 0.5f };
|
||||||
|
m_button_colors[i]->set_color({ 0, 0, 0, 0 });
|
||||||
|
}
|
||||||
|
m_button_color_current = m_button_colors[0];
|
||||||
m_button_color_current->set_active(true);
|
m_button_color_current->set_active(true);
|
||||||
m_button_color_current_inner = static_cast<NodeBorder*>(m_button_color_current->m_children[0].get());
|
m_button_color_current_inner = static_cast<NodeBorder*>(m_button_color_current->m_children[0].get());
|
||||||
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");
|
for (int i = 0; i < m_button_brushes.size(); i++)
|
||||||
m_button_brush2 = init_button_brush("quick-brush2");
|
m_button_brushes[i] = init_button_brush(fmt::format("quick-brush{}", i + 1));
|
||||||
m_button_brush3 = init_button_brush("quick-brush3");
|
m_button_brush_current = m_button_brushes[0];
|
||||||
m_button_brush_current = m_button_brush1;
|
|
||||||
m_button_brush_current->set_active(true);
|
m_button_brush_current->set_active(true);
|
||||||
m_button_brush_current_preview = static_cast<NodeStrokePreview*>(m_button_brush_current->m_children[0].get());
|
m_button_brush_current_preview = static_cast<NodeStrokePreview*>(m_button_brush_current->m_children[0].get());
|
||||||
}
|
}
|
||||||
@@ -108,11 +174,11 @@ NodeButtonCustom* NodePanelQuick::init_button_brush(const std::string& name)
|
|||||||
auto button = find<NodeButtonCustom>(name.c_str());
|
auto button = find<NodeButtonCustom>(name.c_str());
|
||||||
button->on_click = std::bind(&this_class::handle_button_brush_click, this, std::placeholders::_1);
|
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());
|
auto pr = static_cast<NodeStrokePreview*>(button->m_children[0].get());
|
||||||
pr->m_brush = std::make_shared<Brush>();
|
pr->m_brush = std::make_shared<Brush>();;
|
||||||
|
pr->m_brush->load_tip("data/brushes/Round-Hard.png", "data/brushes/thumbs/Round-Hard.png");
|
||||||
pr->m_max_size = 20;
|
pr->m_max_size = 20;
|
||||||
pr->m_pad_override = 0;
|
pr->m_pad_override = 0;
|
||||||
pr->m_draw_first = true;
|
pr->m_draw_first = true;
|
||||||
pr->m_brush->load_tip("data/brushes/Round-Hard.png", "data/brushes/thumbs/Round-Hard.png");
|
|
||||||
pr->draw_stroke();
|
pr->draw_stroke();
|
||||||
return button;
|
return button;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,6 +9,14 @@
|
|||||||
class NodePanelQuick : public NodeBorder
|
class NodePanelQuick : public NodeBorder
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
struct MiniState
|
||||||
|
{
|
||||||
|
int brush_index;
|
||||||
|
int color_index;
|
||||||
|
std::array<glm::vec4, 3> colors;
|
||||||
|
std::array<std::shared_ptr<Brush>, 3> brushes;
|
||||||
|
};
|
||||||
|
|
||||||
std::function<void(Node* target, glm::vec3 rgb)> on_color_change;
|
std::function<void(Node* target, glm::vec3 rgb)> on_color_change;
|
||||||
std::function<void(Node* target, float value)> on_flow_change;
|
std::function<void(Node* target, float value)> on_flow_change;
|
||||||
std::function<void(Node* target, float value)> on_size_change;
|
std::function<void(Node* target, float value)> on_size_change;
|
||||||
@@ -16,23 +24,30 @@ public:
|
|||||||
|
|
||||||
using this_class = NodePanelQuick;
|
using this_class = NodePanelQuick;
|
||||||
using parent = NodeBorder;
|
using parent = NodeBorder;
|
||||||
|
|
||||||
NodeSliderV* m_slider_size;
|
NodeSliderV* m_slider_size;
|
||||||
NodeSliderV* m_slider_flow;
|
NodeSliderV* m_slider_flow;
|
||||||
NodeButtonCustom* m_button_color1;
|
std::array<NodeButtonCustom*, 3> m_button_colors;
|
||||||
NodeButtonCustom* m_button_color2;
|
|
||||||
NodeButtonCustom* m_button_color3;
|
|
||||||
NodeButtonCustom* m_button_color_current;
|
NodeButtonCustom* m_button_color_current;
|
||||||
NodeBorder* m_button_color_current_inner;
|
NodeBorder* m_button_color_current_inner;
|
||||||
NodeButtonCustom* m_button_brush1;
|
std::array<NodeButtonCustom*, 3> m_button_brushes;
|
||||||
NodeButtonCustom* m_button_brush2;
|
|
||||||
NodeButtonCustom* m_button_brush3;
|
|
||||||
NodeButtonCustom* m_button_brush_current;
|
NodeButtonCustom* m_button_brush_current;
|
||||||
NodeStrokePreview* m_button_brush_current_preview;
|
NodeStrokePreview* m_button_brush_current_preview;
|
||||||
std::shared_ptr<NodeColorPicker> m_picker;
|
std::shared_ptr<NodeColorPicker> m_picker;
|
||||||
|
|
||||||
virtual Node* clone_instantiate() const override;
|
virtual Node* clone_instantiate() const override;
|
||||||
virtual void clone_finalize(Node* dest) const override;
|
virtual void clone_finalize(Node* dest) const override;
|
||||||
virtual void init() override;
|
virtual void init() override;
|
||||||
|
|
||||||
void set_color(glm::vec3 color);
|
void set_color(glm::vec3 color);
|
||||||
|
int get_selected_brush_index() const;
|
||||||
|
void set_selected_brush_index(int idx);
|
||||||
|
int get_selected_color_index() const;
|
||||||
|
void set_selected_color_index(int idx);
|
||||||
|
MiniState get_state() const;
|
||||||
|
void set_state(const MiniState& state);
|
||||||
|
void reset_state();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void init_controls();
|
void init_controls();
|
||||||
NodeButtonCustom* init_button_brush(const std::string& name);
|
NodeButtonCustom* init_button_brush(const std::string& name);
|
||||||
|
|||||||
Reference in New Issue
Block a user