improve update_brush performance

This commit is contained in:
2019-08-14 08:49:20 +02:00
parent f7db4a924e
commit a08e8c5796
4 changed files with 46 additions and 39 deletions

View File

@@ -245,7 +245,7 @@ public:
std::shared_ptr<NodeProgressBar> show_progress(const std::string& title);
void brush_update();
void brush_update(bool update_color, bool update_brush);
void title_update();
void update_memory_usage(size_t bytes);
void update_rec_frames();

View File

@@ -128,27 +128,28 @@ void App::init_sidebar()
quick->set_state(quick_mode_state[mode], true);
else
quick->reset_state(true);
brush_update();
brush_update(true, true);
};
color->on_color_changed = [this](Node* target, glm::vec4 color) {
Canvas::I->m_current_brush->m_tip_color = color;
quick->set_color(color);
brush_update(true, false);
};
stroke->on_brush_changed = [this](Node* target, const std::string& path, const std::string& thumb) {
Canvas::I->m_current_brush->load_tip(path, thumb);
brush_update();
brush_update(true, true);
};
stroke->on_pattern_changed = [this](Node*target, const std::string& path, const std::string& thumb) {
Canvas::I->m_current_brush->load_pattern(path, thumb);
brush_update();
brush_update(true, true);
};
stroke->on_dual_changed = [this](Node*target, const std::string& path, const std::string& thumb) {
Canvas::I->m_current_brush->load_dual(path, thumb);
brush_update();
brush_update(true, true);
};
stroke->on_stroke_change = [this](Node*) {
brush_update();
brush_update(true, true);
};
quick->on_color_change = [this](Node*, glm::vec3 c) {
@@ -165,7 +166,7 @@ void App::init_sidebar()
auto c = Canvas::I->m_current_brush->m_tip_color;
*Canvas::I->m_current_brush = *b;
Canvas::I->m_current_brush->m_tip_color = c;
brush_update();
brush_update(true, true);
};
layers->on_layer_add = [this](Node*, std::shared_ptr<class Layer> layer, int index) {
@@ -816,7 +817,7 @@ void App::init_menu_tools()
*Canvas::I->m_current_brush = *b;
Canvas::I->m_current_brush->m_tip_color = c;
Canvas::I->m_current_brush->load();
brush_update();
brush_update(true, true);
};
}
else
@@ -842,7 +843,7 @@ void App::init_menu_tools()
floating_color->find("title")->destroy();
floating_color->on_color_changed = [this](Node* target, glm::vec4 color) {
Canvas::I->m_current_brush->m_tip_color = color;
brush_update();
brush_update(true, false);
};
}
else
@@ -867,7 +868,7 @@ void App::init_menu_tools()
floating_picker->m_autohide = false;
floating_picker->on_color_change = [this](Node* target, glm::vec3 color) {
Canvas::I->m_current_brush->m_tip_color = glm::vec4(color, 1.f);
brush_update();
brush_update(true, false);
};
}
else
@@ -1127,22 +1128,28 @@ void App::init_menu_about()
}
}
void App::brush_update()
void App::brush_update(bool update_color, bool update_brush)
{
// brushes->select_brush(canvas->m_brush->id);
// stroke->set_params(canvas->m_brush);
render_task_async([this]
render_task_async([this, update_color, update_brush]
{
if (update_brush)
{
stroke->update_controls();
quick->m_slider_flow->set_value(stroke->m_tip_flow->get_value());
quick->m_slider_size->set_value(stroke->m_tip_size->get_value());
*quick->m_button_brush_current_preview->m_brush = *Canvas::I->m_current_brush;
quick->m_button_brush_current_preview->draw_stroke();
}
if (update_color)
{
quick->m_button_color_current_inner->m_color = Canvas::I->m_current_brush->m_tip_color;
if (floating_picker)
floating_picker->set_color(Canvas::I->m_current_brush->m_tip_color);
if (floating_color)
floating_color->set_color(Canvas::I->m_current_brush->m_tip_color);
}
}, true);
}
@@ -1299,7 +1306,7 @@ void App::initLayout()
}
}
brush_update();
brush_update(true, true);
// hacky thing to make the toolbar buttons not steal events when moving cursor fast
if (auto* toolbar = layout[main_id]->find<Node>("toolbar"))
@@ -1526,7 +1533,7 @@ void App::ui_restore()
*Canvas::I->m_current_brush = *b;
Canvas::I->m_current_brush->m_tip_color = c;
Canvas::I->m_current_brush->load();
brush_update();
brush_update(true, true);
};
break;
}
@@ -1537,7 +1544,7 @@ void App::ui_restore()
floating_color->find("title")->destroy();
floating_color->on_color_changed = [this](Node* target, glm::vec4 color) {
Canvas::I->m_current_brush->m_tip_color = color;
brush_update();
brush_update(true, false);
};
break;
}
@@ -1547,7 +1554,7 @@ void App::ui_restore()
floating_picker->m_autohide = false;
floating_picker->on_color_change = [this](Node* target, glm::vec3 color) {
Canvas::I->m_current_brush->m_tip_color = glm::vec4(color, 1.f);
brush_update();
brush_update(true, false);
};
break;
}
@@ -1604,7 +1611,7 @@ void App::ui_restore()
*Canvas::I->m_current_brush = *b;
Canvas::I->m_current_brush->m_tip_color = c;
Canvas::I->m_current_brush->load();
brush_update();
brush_update(true, true);
};
break;
}
@@ -1615,7 +1622,7 @@ void App::ui_restore()
floating_color->find("title")->destroy();
floating_color->on_color_changed = [this](Node* target, glm::vec4 color) {
Canvas::I->m_current_brush->m_tip_color = color;
brush_update();
brush_update(true, false);
};
break;
}
@@ -1625,7 +1632,7 @@ void App::ui_restore()
floating_picker->m_autohide = false;
floating_picker->on_color_change = [this](Node* target, glm::vec3 color) {
Canvas::I->m_current_brush->m_tip_color = glm::vec4(color, 1.f);
brush_update();
brush_update(true, false);
};
break;
}
@@ -1681,7 +1688,7 @@ void App::ui_restore()
*Canvas::I->m_current_brush = *b;
Canvas::I->m_current_brush->m_tip_color = c;
Canvas::I->m_current_brush->load();
brush_update();
brush_update(true, true);
};
break;
}
@@ -1692,7 +1699,7 @@ void App::ui_restore()
floating_color->find("title")->destroy();
floating_color->on_color_changed = [this](Node* target, glm::vec4 color) {
Canvas::I->m_current_brush->m_tip_color = color;
brush_update();
brush_update(true, false);
};
break;
}
@@ -1702,7 +1709,7 @@ void App::ui_restore()
floating_picker->m_autohide = false;
floating_picker->on_color_change = [this](Node* target, glm::vec3 color) {
Canvas::I->m_current_brush->m_tip_color = glm::vec4(color, 1.f);
brush_update();
brush_update(true, false);
};
break;
}

View File

@@ -83,7 +83,7 @@ void CanvasModeBasicCamera::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
m_zoom_canvas += me->m_scroll_delta * 0.1f;
Canvas::I->m_cam_fov = glm::clamp(Canvas::I->m_cam_fov - me->m_scroll_delta * 2.0f,
Canvas::I->m_cam_fov_min, Canvas::I->m_cam_fov_max);
App::I->brush_update();
App::I->brush_update(true, true);
break;
case kEventType::MouseCancel:
m_draggingR = false;
@@ -110,7 +110,7 @@ void CanvasModeBasicCamera::on_GestureEvent(GestureEvent* ge)
Canvas::I->m_cam_fov_min, Canvas::I->m_cam_fov_max);
auto angle = Canvas::I->m_pan * 0.003f;
Canvas::I->m_cam_rot = glm::eulerAngleXY(angle.y, angle.x);
App::I->brush_update();
App::I->brush_update(true, true);
break;
}
default:
@@ -154,7 +154,7 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
Canvas::I->pick_start();
glm::vec4 pix = Canvas::I->pick_get(loc);
Canvas::I->m_current_brush->m_tip_color = pix;
App::I->brush_update();
App::I->brush_update(true, false);
}
else
{
@@ -181,7 +181,7 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
node->mouse_release();
glm::vec4 pix = Canvas::I->pick_get(loc);
Canvas::I->m_current_brush->m_tip_color = pix;
App::I->brush_update();
App::I->brush_update(true, false);
Canvas::I->pick_end();
}
m_dragging = false;
@@ -218,14 +218,14 @@ void CanvasModePen::on_MouseEvent(MouseEvent* me, glm::vec2& loc)
{
glm::vec4 pix = Canvas::I->pick_get(loc);
Canvas::I->m_current_brush->m_tip_color = pix;
App::I->brush_update();
App::I->brush_update(true, false);
}
if (m_dragging && m_resizing)
{
auto diff = m_cur_pos - m_size_pos_start;
auto curve = App::I->stroke->m_curves[App::I->stroke->m_tip_size];
Canvas::I->m_current_brush->m_tip_size = glm::max(curve.to_value(m_size_value_start + diff.x * 0.001f), 0.001f);
App::I->brush_update();
App::I->brush_update(true, true);
}
m_cur_pos = loc;
break;

View File

@@ -629,7 +629,7 @@ void NodePanelStroke::init_controls()
b->m_tip_opacity = 1.f;
Canvas::I->m_current_brush = b;
update_controls();
App::I->brush_update();
App::I->brush_update(true, true);
};
update_controls();