refactor to have a single global current brush on Canvas::m_current_brush and make panels read from it for drawing instead of relying on their own copy
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "pch.h"
|
||||
#include "log.h"
|
||||
#include "node_panel_stroke.h"
|
||||
#include "canvas.h"
|
||||
|
||||
Node* NodePanelStroke::clone_instantiate() const
|
||||
{
|
||||
@@ -19,8 +20,9 @@ void NodePanelStroke::init()
|
||||
init_controls();
|
||||
}
|
||||
|
||||
void NodePanelStroke::set_params(const ui::Brush &b)
|
||||
void NodePanelStroke::update_controls()
|
||||
{
|
||||
const auto& b = ui::Canvas::I->m_current_brush;
|
||||
m_tip_size->m_value.x = glm::pow(b.m_tip_size, 1.f/3.f);
|
||||
m_tip_spacing->m_value.x = glm::pow(b.m_tip_spacing, 1.f/2.f) / 4.f;
|
||||
m_tip_flow->m_value.x = glm::pow(b.m_tip_flow, 1.f/2.f);
|
||||
@@ -34,13 +36,13 @@ void NodePanelStroke::set_params(const ui::Brush &b)
|
||||
m_tip_angle_follow->checked = b.m_tip_angle_follow;
|
||||
m_tip_flow_pressure->checked = b.m_tip_flow_pressure;
|
||||
m_tip_size_pressure->checked = b.m_tip_size_pressure;
|
||||
m_canvas->m_brush = b;
|
||||
m_canvas->draw_stroke();
|
||||
m_preview->m_brush = b;
|
||||
m_preview->draw_stroke();
|
||||
}
|
||||
|
||||
void NodePanelStroke::init_controls()
|
||||
{
|
||||
m_canvas = find<NodeStrokePreview>("canvas");
|
||||
m_preview = find<NodeStrokePreview>("canvas");
|
||||
|
||||
init_slider(m_tip_size, "tip-size", &ui::Brush::m_tip_size);
|
||||
init_slider(m_tip_spacing, "tip-spacing", &ui::Brush::m_tip_spacing);
|
||||
@@ -61,7 +63,8 @@ void NodePanelStroke::init_controls()
|
||||
init_checkbox(m_tip_flow_pressure, "tip-flow-pressure", &ui::Brush::m_tip_flow_pressure);
|
||||
init_checkbox(m_tip_size_pressure, "tip-size-pressure", &ui::Brush::m_tip_size_pressure);
|
||||
|
||||
//m_canvas->draw_stroke();
|
||||
m_preview->m_brush = ui::Canvas::I->m_current_brush;
|
||||
m_preview->draw_stroke();
|
||||
}
|
||||
|
||||
void NodePanelStroke::init_slider(NodeSliderH*& target, const char* id, float ui::Brush::* prop)
|
||||
@@ -75,8 +78,9 @@ void NodePanelStroke::init_slider(NodeSliderH*& target, const char* id, float ui
|
||||
void NodePanelStroke::handle_slide(float ui::Brush::* prop, Node* target, float value)
|
||||
{
|
||||
auto curve = m_curves.find((NodeSliderH*)target);
|
||||
m_canvas->m_brush.*prop = curve != m_curves.end() ? curve->second(value) : value;
|
||||
m_canvas->draw_stroke();
|
||||
ui::Canvas::I->m_current_brush.*prop = curve != m_curves.end() ? curve->second(value) : value;
|
||||
m_preview->m_brush = ui::Canvas::I->m_current_brush;
|
||||
m_preview->draw_stroke();
|
||||
if (on_stroke_change)
|
||||
on_stroke_change(this);
|
||||
}
|
||||
@@ -86,13 +90,14 @@ void NodePanelStroke::init_checkbox(NodeCheckBox*& target, const char* id, bool
|
||||
target = find<NodeCheckBox>(id);
|
||||
target->on_value_changed = std::bind(&NodePanelStroke::handle_checkbox,
|
||||
this, prop, std::placeholders::_1, std::placeholders::_2);
|
||||
m_canvas->m_brush.*prop = target->checked;
|
||||
ui::Canvas::I->m_current_brush.*prop = target->checked;
|
||||
}
|
||||
|
||||
void NodePanelStroke::handle_checkbox(bool ui::Brush::* prop, Node *target, bool value)
|
||||
{
|
||||
m_canvas->m_brush.*prop = value;
|
||||
m_canvas->draw_stroke();
|
||||
ui::Canvas::I->m_current_brush.*prop = value;
|
||||
m_preview->m_brush = ui::Canvas::I->m_current_brush;
|
||||
m_preview->draw_stroke();
|
||||
if (on_stroke_change)
|
||||
on_stroke_change(this);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user