Route quick slider preview through app core
This commit is contained in:
@@ -121,39 +121,13 @@ void NodePanelQuick::init_controls()
|
||||
|
||||
m_slider_size = find<NodeSliderV>("quick-size");
|
||||
m_slider_size->on_value_changed = [this](Node* target, float value) {
|
||||
float off = App::I->ui_rtl ? -100.f : 100.f;
|
||||
auto newpos = (m_slider_flow->m_pos + glm::vec2(off, m_slider_flow->m_size.y / 2.f)) * App::I->zoom;
|
||||
if (auto m = dynamic_cast<CanvasModePen*>(Canvas::I->modes[(int)Canvas::I->m_current_mode][0]))
|
||||
{
|
||||
m->m_cur_pos = newpos;
|
||||
m->m_draw_tip = true;
|
||||
m->m_draw_outline = false;
|
||||
}
|
||||
if (auto m = dynamic_cast<CanvasModeLine*>(Canvas::I->modes[(int)Canvas::I->m_current_mode][0]))
|
||||
{
|
||||
m->m_cur_pos = newpos;
|
||||
m->m_draw_tip = true;
|
||||
}
|
||||
m_button_brush_current_preview->draw_stroke();
|
||||
update_slider_preview();
|
||||
if (on_size_change)
|
||||
on_size_change(target, value);
|
||||
};
|
||||
m_slider_flow = find<NodeSliderV>("quick-flow");
|
||||
m_slider_flow->on_value_changed = [this](Node* target, float value) {
|
||||
float off = App::I->ui_rtl ? -100.f : 100.f;
|
||||
auto newpos = (m_slider_flow->m_pos + glm::vec2(off, m_slider_flow->m_size.y / 2.f)) * App::I->zoom;
|
||||
if (auto m = dynamic_cast<CanvasModePen*>(Canvas::I->modes[(int)Canvas::I->m_current_mode][0]))
|
||||
{
|
||||
m->m_cur_pos = newpos;
|
||||
m->m_draw_tip = true;
|
||||
m->m_draw_outline = false;
|
||||
}
|
||||
if (auto m = dynamic_cast<CanvasModeLine*>(Canvas::I->modes[(int)Canvas::I->m_current_mode][0]))
|
||||
{
|
||||
m->m_cur_pos = newpos;
|
||||
m->m_draw_tip = true;
|
||||
}
|
||||
m_button_brush_current_preview->draw_stroke();
|
||||
update_slider_preview();
|
||||
if (on_flow_change)
|
||||
on_flow_change(target, value);
|
||||
};
|
||||
@@ -199,6 +173,45 @@ NodeButtonCustom* NodePanelQuick::init_button_brush(const std::string& name, boo
|
||||
return button;
|
||||
}
|
||||
|
||||
void NodePanelQuick::update_slider_preview()
|
||||
{
|
||||
if (!App::I || !Canvas::I || !Canvas::I->m_mode || Canvas::I->m_mode->empty() || !m_slider_flow || !m_button_brush_current_preview)
|
||||
return;
|
||||
|
||||
auto* mode = (*Canvas::I->m_mode)[0];
|
||||
auto* pen_mode = dynamic_cast<CanvasModePen*>(mode);
|
||||
auto* line_mode = dynamic_cast<CanvasModeLine*>(mode);
|
||||
|
||||
const auto plan = pp::app::plan_quick_slider_preview(pp::app::QuickSliderPreviewInput {
|
||||
.ui_rtl = App::I->ui_rtl,
|
||||
.slider_x = m_slider_flow->m_pos.x,
|
||||
.slider_y = m_slider_flow->m_pos.y,
|
||||
.slider_height = m_slider_flow->m_size.y,
|
||||
.zoom = App::I->zoom,
|
||||
.has_pen_mode = pen_mode != nullptr,
|
||||
.has_line_mode = line_mode != nullptr,
|
||||
});
|
||||
if (!plan) {
|
||||
LOG("Quick slider preview failed: %s", plan.status().message);
|
||||
return;
|
||||
}
|
||||
|
||||
const glm::vec2 cursor(plan.value().cursor_x, plan.value().cursor_y);
|
||||
if (plan.value().updates_pen_mode && pen_mode)
|
||||
{
|
||||
pen_mode->m_cur_pos = cursor;
|
||||
pen_mode->m_draw_tip = plan.value().draws_tip;
|
||||
pen_mode->m_draw_outline = !plan.value().disables_pen_outline;
|
||||
}
|
||||
if (plan.value().updates_line_mode && line_mode)
|
||||
{
|
||||
line_mode->m_cur_pos = cursor;
|
||||
line_mode->m_draw_tip = plan.value().draws_tip;
|
||||
}
|
||||
if (plan.value().redraws_brush_preview)
|
||||
m_button_brush_current_preview->draw_stroke();
|
||||
}
|
||||
|
||||
void NodePanelQuick::handle_button_brush_click(Node* button)
|
||||
{
|
||||
const auto clicked = std::find(m_button_brushes.begin(), m_button_brushes.end(), button);
|
||||
|
||||
Reference in New Issue
Block a user