refactor Brush to be used in shared_ptr

This commit is contained in:
2019-01-22 22:49:43 +01:00
parent 9e76cf3194
commit e26fcf1163
22 changed files with 254 additions and 197 deletions

View File

@@ -25,34 +25,75 @@ void NodePanelStroke::init()
void NodePanelStroke::update_controls()
{
const auto& b = 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_jitter_hue->m_value.x = b.m_jitter_hue;
m_jitter_sat->m_value.x = b.m_jitter_sat;
m_jitter_val->m_value.x = b.m_jitter_val;
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_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_jitter_hue->m_value.x = b->m_jitter_hue;
m_jitter_sat->m_value.x = b->m_jitter_sat;
m_jitter_val->m_value.x = b->m_jitter_val;
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_brush_popup = std::make_shared<NodePanelBrush>();
m_brush_popup->m_manager = m_manager;
m_brush_popup->init();
m_brush_popup->create();
m_brush_popup->loaded();
m_brush_popup->SetPositioning(YGPositionTypeAbsolute);
m_brush_popup->SetSize(400, 400);
m_brush_popup->m_mouse_ignore = false;
m_brush_popup->m_flood_events = true;
m_brush_popup->m_capture_children = false;
auto b = std::make_shared<Brush>();
int br_idx = m_brush_popup->find_brush("Round-Hard");
b->load_texture(m_brush_popup->get_texture_path(br_idx));
b->load_stencil("data/paper.jpg");
b->m_tip_size = .1f;
b->m_tip_flow = .5f;
b->m_tip_spacing = .1f;
b->m_tip_opacity = 1.f;
Canvas::I->m_current_brush = b;
m_brush_thumb = find<NodeImage>("tip-change-thumb");
m_brush_thumb->set_image(m_brush_popup->get_thumb_path(br_idx));
m_brush_button = find<NodeButtonCustom>("tip-change");
m_brush_button->on_click = [this](Node*) {
glm::vec2 pos = m_brush_button->m_pos + glm::vec2(m_brush_button->m_size.x, 0);
root()->add_child(m_brush_popup);
m_brush_popup->SetPosition(pos.x, pos.y);
m_brush_popup->mouse_capture();
root()->update();
m_brush_popup->on_brush_changed = [this](Node*, int index) {
if (on_brush_changed)
on_brush_changed(this, m_brush_popup->get_texture_path(index));
m_brush_thumb->set_image(m_brush_popup->get_thumb_path(index));
m_brush_popup->mouse_release();
m_brush_popup->parent->remove_child(m_brush_popup.get());
};
};
m_preview = find<NodeStrokePreview>("canvas");
m_blend_mode = find<NodeComboBox>("blend-mode");
m_blend_mode->on_select = [](Node*, int index) {
Canvas::I->m_current_brush.m_blend_mode = index;
Canvas::I->m_current_brush->m_blend_mode = index;
};
init_slider(m_tip_size, "tip-size", &Brush::m_tip_size);
@@ -91,42 +132,17 @@ void NodePanelStroke::init_controls()
auto load_stencil = find<NodeButton>("tip-stencil-load");
load_stencil->on_click = [this](Node*) {
App::I.pick_image([this](std::string path) {
App::I.async_start();
if (TextureManager::load(path.c_str()))
{
if (on_stencil_changed)
on_stencil_changed(this, const_hash(path.c_str()));
on_stencil_changed(this, path);
}
App::I.async_redraw();
App::I.async_end();
});
};
m_brush_popup = std::make_shared<NodePanelBrush>();
m_brush_popup->m_manager = m_manager;
m_brush_popup->init();
m_brush_popup->create();
m_brush_popup->loaded();
m_brush_popup->SetPositioning(YGPositionTypeAbsolute);
m_brush_popup->SetSize(400, 400);
m_brush_popup->m_mouse_ignore = false;
m_brush_popup->m_flood_events = true;
m_brush_popup->m_capture_children = false;
m_brush_thumb = find<NodeImage>("tip-change-thumb");
m_brush_button = find<NodeButtonCustom>("tip-change");
m_brush_button->on_click = [this](Node*) {
glm::vec2 pos = m_brush_button->m_pos + glm::vec2(m_brush_button->m_size.x, 0);
root()->add_child(m_brush_popup);
m_brush_popup->SetPosition(pos.x, pos.y);
m_brush_popup->mouse_capture();
root()->update();
m_brush_popup->on_brush_changed = [this](Node*, int index) {
if (on_brush_changed)
on_brush_changed(this, m_brush_popup->get_brush_id(index), m_brush_popup->get_texture_id(index));
m_brush_thumb->set_image(m_brush_popup->get_thumb_path(index));
m_brush_popup->mouse_release();
m_brush_popup->parent->remove_child(m_brush_popup.get());
};
};
}
void NodePanelStroke::init_slider(NodeSliderH*& target, const char* id, float Brush::* prop)
@@ -134,13 +150,13 @@ void NodePanelStroke::init_slider(NodeSliderH*& target, const char* id, float Br
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;
//m_canvas->m_brush->*prop = target->m_value.x;
}
void NodePanelStroke::handle_slide(float Brush::* prop, Node* target, float value)
{
auto curve = m_curves.find((NodeSliderH*)target);
Canvas::I->m_current_brush.*prop = curve != m_curves.end() ? curve->second(value) : value;
Canvas::I->m_current_brush.get()->*prop = curve != m_curves.end() ? curve->second(value) : value;
m_preview->m_brush = Canvas::I->m_current_brush;
m_preview->draw_stroke();
if (on_stroke_change)
@@ -152,12 +168,12 @@ 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);
Canvas::I->m_current_brush.*prop = target->checked;
Canvas::I->m_current_brush.get()->*prop = target->checked;
}
void NodePanelStroke::handle_checkbox(bool Brush::* prop, Node *target, bool value)
{
Canvas::I->m_current_brush.*prop = value;
Canvas::I->m_current_brush.get()->*prop = value;
m_preview->m_brush = Canvas::I->m_current_brush;
m_preview->draw_stroke();
if (on_stroke_change)