complete dual-brush implementation and ui integration
This commit is contained in:
@@ -58,10 +58,13 @@ void NodePanelStroke::update_controls()
|
||||
m_tip_randflipx->checked = b->m_tip_randflipx;
|
||||
m_tip_randflipy->checked = b->m_tip_randflipy;
|
||||
|
||||
m_dual_size->m_value.x = b->m_dual_size;
|
||||
m_dual_spacing->m_value.x = b->m_dual_spacing;
|
||||
m_dual_size->m_value.x = glm::pow(b->m_dual_size, 1.f / 3.f);
|
||||
m_dual_spacing->m_value.x = glm::pow(b->m_dual_spacing, 1.f / 2.f);
|
||||
m_dual_flow->m_value.x = glm::pow(b->m_dual_flow, 1.f / 2.f);
|
||||
m_dual_scatter->m_value.x = b->m_dual_scatter;
|
||||
m_tip_aspect->m_value.x = b->m_tip_aspect;
|
||||
m_dual_opacity->m_value.x = b->m_dual_opacity;
|
||||
m_dual_rotate->m_value.x = b->m_dual_rotate;
|
||||
|
||||
m_blend_mode->set_index(b->m_blend_mode);
|
||||
m_dual_blend_mode->set_index(b->m_dual_blend_mode);
|
||||
@@ -98,19 +101,14 @@ void NodePanelStroke::init_controls()
|
||||
// init main brush
|
||||
auto b = std::make_shared<Brush>();
|
||||
b->load_texture(m_brush_popup->get_texture_path(br_idx), m_brush_popup->get_thumb_path(br_idx));
|
||||
b->load_dual(m_brush_popup->get_texture_path(br_idx), m_brush_popup->get_thumb_path(br_idx));
|
||||
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;
|
||||
// init dual brush
|
||||
auto db = std::make_shared<Brush>();
|
||||
db->load_texture(m_brush_popup->get_texture_path(br_idx), m_brush_popup->get_thumb_path(br_idx));
|
||||
db->m_tip_size = .3f;
|
||||
db->m_tip_flow = .5f;
|
||||
db->m_tip_spacing = .1f;
|
||||
db->m_tip_opacity = 1.f;
|
||||
Canvas::I->m_dual_brush = db;
|
||||
|
||||
// BRUSH PRESETS
|
||||
|
||||
m_preset_thumb = find<NodeImage>("preset-thumb");
|
||||
m_preset_thumb->m_use_mipmaps = true;
|
||||
@@ -156,55 +154,10 @@ void NodePanelStroke::init_controls()
|
||||
};
|
||||
};
|
||||
|
||||
m_dual_preset_thumb = find<NodeImage>("dual-preset-thumb");
|
||||
m_dual_preset_thumb->m_use_mipmaps = true;
|
||||
m_dual_preset_preview = find<NodeStrokePreview>("dual-preset-preview");
|
||||
m_dual_preset_preview->m_brush = b;
|
||||
m_dual_preset_preview->draw_stroke();
|
||||
m_dual_preset_button = find<NodeButtonCustom>("dual-preset-button");
|
||||
m_dual_preset_button->on_click = [this](Node*) {
|
||||
auto screen = root()->m_size;
|
||||
glm::vec2 pos = m_dual_preset_button->m_pos + glm::vec2(m_dual_preset_button->m_size.x, 0);
|
||||
root()->add_child(m_presets_popup);
|
||||
auto tick = root()->add_child<NodeImage>();
|
||||
tick->SetPositioning(YGPositionTypeAbsolute);
|
||||
tick->SetSize(16, 32);
|
||||
tick->SetPosition(pos.x, pos.y + (m_dual_preset_button->m_size.y - 32) * 0.5f);
|
||||
tick->set_image("data/ui/popup-tick.png");
|
||||
root()->update();
|
||||
if ((pos.y + m_presets_popup->m_size.y) > screen.y)
|
||||
pos.y = screen.y - m_presets_popup->m_size.y;
|
||||
if (pos.y < 0)
|
||||
pos.y = 0;
|
||||
m_presets_popup->SetPosition(pos.x + 16, pos.y);
|
||||
m_presets_popup->mouse_capture();
|
||||
root()->update();
|
||||
|
||||
m_presets_popup->on_popup_close = [this, tick](Node*) {
|
||||
tick->destroy();
|
||||
};
|
||||
|
||||
m_presets_popup->on_brush_changed = [this](Node* target, std::shared_ptr<Brush>& b) {
|
||||
// don't change some params
|
||||
b->m_tip_size = Canvas::I->m_current_brush->m_tip_size;
|
||||
b->m_tip_color = { 0, 0, 0, 1 };
|
||||
*Canvas::I->m_dual_brush = *b;
|
||||
m_preview->draw_stroke();
|
||||
m_dual_preset_preview->draw_stroke();
|
||||
m_dual_brush_thumb->set_image(b->m_brush_thumb_path);
|
||||
m_dual_preset_thumb->set_image(b->m_brush_thumb_path);
|
||||
update_controls();
|
||||
|
||||
//m_presets_popup->mouse_release();
|
||||
//m_presets_popup->parent->remove_child(m_presets_popup.get());
|
||||
};
|
||||
};
|
||||
// BRUSH TIP SHAPE
|
||||
|
||||
m_brush_thumb = find<NodeImage>("tip-change-thumb");
|
||||
m_brush_thumb->set_image(m_brush_popup->get_thumb_path(br_idx));
|
||||
m_dual_brush_thumb = find<NodeImage>("dual-change-thumb");
|
||||
m_dual_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*) {
|
||||
auto screen = root()->m_size;
|
||||
@@ -237,6 +190,42 @@ void NodePanelStroke::init_controls()
|
||||
};
|
||||
};
|
||||
|
||||
// DUAL BRUSH TIP SHAPE
|
||||
|
||||
m_dual_brush_thumb = find<NodeImage>("dual-change-thumb");
|
||||
m_dual_brush_thumb->set_image(m_brush_popup->get_thumb_path(br_idx));
|
||||
m_dual_brush_button = find<NodeButtonCustom>("dual-change");
|
||||
m_dual_brush_button->on_click = [this](Node*) {
|
||||
auto screen = root()->m_size;
|
||||
glm::vec2 pos = m_dual_brush_button->m_pos + glm::vec2(m_dual_brush_button->m_size.x, 0);
|
||||
root()->add_child(m_brush_popup);
|
||||
auto tick = root()->add_child<NodeImage>();
|
||||
tick->SetPositioning(YGPositionTypeAbsolute);
|
||||
tick->SetSize(16, 32);
|
||||
tick->SetPosition(pos.x, pos.y + (m_dual_brush_button->m_size.y - 32) * 0.5f);
|
||||
tick->set_image("data/ui/popup-tick.png");
|
||||
root()->update();
|
||||
if ((pos.y + m_brush_popup->m_size.y) > screen.y)
|
||||
pos.y = screen.y - m_brush_popup->m_size.y;
|
||||
if (pos.y < 0)
|
||||
pos.y = 0;
|
||||
m_brush_popup->SetPosition(pos.x + 16, pos.y);
|
||||
m_brush_popup->mouse_capture();
|
||||
root()->update();
|
||||
|
||||
m_brush_popup->on_popup_close = [this, tick](Node*) {
|
||||
tick->destroy();
|
||||
};
|
||||
|
||||
m_brush_popup->on_brush_changed = [this](Node*, int index) {
|
||||
if (on_dual_changed)
|
||||
on_dual_changed(this, m_brush_popup->get_texture_path(index), m_brush_popup->get_thumb_path(index));
|
||||
m_dual_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 = [this](Node*, int index) {
|
||||
@@ -266,9 +255,6 @@ void NodePanelStroke::init_controls()
|
||||
init_slider(m_jitter_hue, "jitter-hue", &Brush::m_jitter_hue);
|
||||
init_slider(m_jitter_sat, "jitter-sat", &Brush::m_jitter_sat);
|
||||
init_slider(m_jitter_val, "jitter-val", &Brush::m_jitter_val);
|
||||
m_curves[m_tip_size] = [](float v){ return glm::pow(v, 3.f); };
|
||||
m_curves[m_tip_spacing] = [](float v){ return glm::pow(v, 2.f); };
|
||||
m_curves[m_tip_flow] = [](float v){ return glm::pow(v, 2.f); };
|
||||
|
||||
init_checkbox(m_tip_angle_follow, "tip-angle-follow", &Brush::m_tip_angle_follow);
|
||||
init_checkbox(m_tip_flow_pressure, "tip-flow-pressure", &Brush::m_tip_flow_pressure);
|
||||
@@ -291,6 +277,18 @@ void NodePanelStroke::init_controls()
|
||||
init_slider(m_dual_spacing, "dual-spacing", &Brush::m_dual_spacing);
|
||||
init_slider(m_dual_scatter, "dual-scatter", &Brush::m_dual_scatter);
|
||||
init_slider(m_tip_aspect, "tip-aspect", &Brush::m_tip_aspect);
|
||||
init_slider(m_dual_opacity, "dual-opacity", &Brush::m_dual_opacity);
|
||||
init_slider(m_dual_flow, "dual-flow", &Brush::m_dual_flow);
|
||||
init_slider(m_dual_rotate, "dual-rotate", &Brush::m_dual_rotate);
|
||||
|
||||
auto curve_cubic = [](float v) { return glm::pow(v, 3.f); };
|
||||
auto curve_quad = [](float v) { return glm::pow(v, 2.f); };
|
||||
m_curves[m_tip_size] = curve_cubic;
|
||||
m_curves[m_tip_spacing] = curve_quad;
|
||||
m_curves[m_tip_flow] = curve_quad;
|
||||
m_curves[m_dual_size] = curve_cubic;
|
||||
m_curves[m_dual_spacing] = curve_quad;
|
||||
m_curves[m_dual_flow] = curve_quad;
|
||||
|
||||
m_tip_aspect_reset = find<NodeButtonCustom>("tip-aspect-reset");
|
||||
m_tip_aspect_reset->on_click = [this](Node*) {
|
||||
@@ -319,7 +317,7 @@ void NodePanelStroke::init_controls()
|
||||
if (TextureManager::load(path.c_str()))
|
||||
{
|
||||
if (on_stencil_changed)
|
||||
on_stencil_changed(this, path);
|
||||
on_stencil_changed(this, path, "");
|
||||
}
|
||||
App::I.async_redraw();
|
||||
App::I.async_end();
|
||||
|
||||
Reference in New Issue
Block a user