111 lines
4.3 KiB
C++
111 lines
4.3 KiB
C++
#include "pch.h"
|
|
#include "log.h"
|
|
#include "node_panel_stroke.h"
|
|
#include "canvas.h"
|
|
|
|
Node* NodePanelStroke::clone_instantiate() const
|
|
{
|
|
return new NodePanelStroke();
|
|
}
|
|
|
|
void NodePanelStroke::clone_finalize(Node* dest) const
|
|
{
|
|
NodePanelStroke* n = static_cast<NodePanelStroke*>(dest);
|
|
n->init_controls();
|
|
}
|
|
|
|
void NodePanelStroke::init()
|
|
{
|
|
init_template("tpl-panel-stroke");
|
|
init_controls();
|
|
}
|
|
|
|
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);
|
|
m_tip_opacity->m_value.x = b.m_tip_opacity;
|
|
m_tip_angle->m_value.x = b.m_tip_angle;
|
|
m_tip_stencil->m_value.x = b.m_tip_stencil;
|
|
m_tip_wet->m_value.x = b.m_tip_wet;
|
|
m_tip_noise->m_value.x = b.m_tip_noise;
|
|
m_jitter_scale->m_value.x = b.m_jitter_scale;
|
|
m_jitter_angle->m_value.x = b.m_jitter_angle;
|
|
m_jitter_spread->m_value.x = b.m_jitter_spread;
|
|
m_jitter_flow->m_value.x = b.m_jitter_flow;
|
|
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_preview->m_brush = b;
|
|
m_preview->draw_stroke();
|
|
}
|
|
|
|
void NodePanelStroke::init_controls()
|
|
{
|
|
m_preview = find<NodeStrokePreview>("canvas");
|
|
m_blend_mode = find<NodeComboBox>("blend-mode");
|
|
m_blend_mode->on_select = [](Node*, int index) {
|
|
ui::Canvas::I->m_current_brush.m_blend_mode = index;
|
|
};
|
|
|
|
init_slider(m_tip_size, "tip-size", &ui::Brush::m_tip_size);
|
|
init_slider(m_tip_spacing, "tip-spacing", &ui::Brush::m_tip_spacing);
|
|
init_slider(m_tip_flow, "tip-flow", &ui::Brush::m_tip_flow);
|
|
init_slider(m_tip_opacity, "tip-opacity", &ui::Brush::m_tip_opacity);
|
|
init_slider(m_tip_angle, "tip-angle", &ui::Brush::m_tip_angle);
|
|
init_slider(m_tip_stencil, "tip-stencil", &ui::Brush::m_tip_stencil);
|
|
init_slider(m_tip_wet, "tip-wet", &ui::Brush::m_tip_wet);
|
|
init_slider(m_tip_noise, "tip-noise", &ui::Brush::m_tip_noise);
|
|
init_slider(m_jitter_scale, "jitter-scale", &ui::Brush::m_jitter_scale);
|
|
init_slider(m_jitter_angle, "jitter-angle", &ui::Brush::m_jitter_angle);
|
|
init_slider(m_jitter_spread, "jitter-spread", &ui::Brush::m_jitter_spread);
|
|
init_slider(m_jitter_flow, "jitter-flow", &ui::Brush::m_jitter_flow);
|
|
m_curves[m_tip_size] = [](float v){ return glm::pow(v, 3.f); };
|
|
m_curves[m_tip_spacing] = [](float v){ return glm::pow(v * 4.f, 2.f); };
|
|
m_curves[m_tip_flow] = [](float v){ return glm::pow(v, 2.f); };
|
|
|
|
init_checkbox(m_tip_angle_follow, "tip-angle-follow", &ui::Brush::m_tip_angle_follow);
|
|
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_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)
|
|
{
|
|
target = find<NodeSliderH>(id);
|
|
target->on_value_changed = std::bind(&NodePanelStroke::handle_slide,
|
|
this, prop, std::placeholders::_1, std::placeholders::_2);
|
|
//m_canvas->m_brush.*prop = target->m_value.x;
|
|
}
|
|
|
|
void NodePanelStroke::handle_slide(float ui::Brush::* prop, Node* target, float value)
|
|
{
|
|
auto curve = m_curves.find((NodeSliderH*)target);
|
|
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);
|
|
}
|
|
|
|
void NodePanelStroke::init_checkbox(NodeCheckBox*& target, const char* id, bool ui::Brush::* prop)
|
|
{
|
|
target = find<NodeCheckBox>(id);
|
|
target->on_value_changed = std::bind(&NodePanelStroke::handle_checkbox,
|
|
this, prop, std::placeholders::_1, std::placeholders::_2);
|
|
ui::Canvas::I->m_current_brush.*prop = target->checked;
|
|
}
|
|
|
|
void NodePanelStroke::handle_checkbox(bool ui::Brush::* prop, Node *target, bool value)
|
|
{
|
|
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);
|
|
}
|