Improve performance for all tools

This commit is contained in:
Yousef Khadadeh 2026-05-18 18:35:40 +03:00
parent 0a474c16a0
commit 22e04b0ca5
17 changed files with 76 additions and 38 deletions

View file

@ -225,8 +225,8 @@ void BrushTool::tool_update() {
if(commitUpdate && objInfoBeingEdited) {
NetworkingObjects::NetObjOwnerPtr<CanvasComponentContainer>& containerPtr = objInfoBeingEdited->obj;
containerPtr->send_comp_update(drawP, false);
containerPtr->commit_update(drawP);
containerPtr->send_comp_update(drawP, false);
commitUpdate = false;
}
}
@ -237,6 +237,7 @@ void BrushTool::commit_stroke() {
fix_tip();
containerPtr->commit_update(drawP);
containerPtr->send_comp_update(drawP, true);
commitUpdate = false;
if(containerPtr->get_world_bounds().has_value())
drawP.layerMan.add_undo_place_component(objInfoBeingEdited);
else {
@ -244,7 +245,6 @@ void BrushTool::commit_stroke() {
components->erase(components, containerPtr->objInfo);
}
objInfoBeingEdited = nullptr;
commitUpdate = false;
}
}

View file

@ -196,7 +196,7 @@ void EditTool::input_mouse_motion_callback(const InputManager::MouseMotionCallba
if(pointDragging->max)
newPos = cwise_vec_min((*pointDragging->max - Vector2f{pointDragging->minimumDistanceBetweenMaxAndPoint, pointDragging->minimumDistanceBetweenMaxAndPoint}).eval(), newPos);
*pointDragging->p = newPos;
objInfoBeingEdited->obj->commit_update(drawP);
compEditTool->commitUpdate = true;
}
}
compEditTool->input_mouse_motion_callback(motion, pointDragging);
@ -319,7 +319,11 @@ bool EditTool::is_editable(CanvasComponentContainer::ObjInfo* comp) {
void EditTool::tool_update() {
if(objInfoBeingEdited) {
compEditTool->edit_update();
objInfoBeingEdited->obj->send_comp_update(drawP, false);
if(compEditTool->commitUpdate) {
objInfoBeingEdited->obj->commit_update(drawP);
objInfoBeingEdited->obj->send_comp_update(drawP, false);
compEditTool->commitUpdate = false;
}
}
}

View file

@ -79,8 +79,4 @@ void BrushEditTool::commit_edit_updates(std::any& prevData) {
}
void BrushEditTool::edit_update() {
if(commitUpdate) {
comp->obj->commit_update(drawP);
commitUpdate = false;
}
}

View file

@ -33,6 +33,5 @@ class BrushEditTool : public DrawingProgramEditToolBase {
virtual void gui_phone_toolbox(PhoneDrawingProgramScreen& t) override;
virtual Vector4f* color_picker_color(Vector4f* oldColor) override;
private:
bool commitUpdate = false;
Vector4f oldColor;
};

View file

@ -46,6 +46,8 @@ class DrawingProgramEditToolBase {
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool isDraggingPoint);
virtual std::optional<InputManager::TextBoxStartInfo> get_text_box_start_info();
virtual ~DrawingProgramEditToolBase();
bool commitUpdate = false;
protected:
DrawingProgram& drawP;
CanvasComponentContainer::ObjInfo* comp;

View file

@ -39,9 +39,9 @@ void EllipseDrawEditTool::edit_gui(Toolbar& t) {
auto& a = static_cast<EllipseCanvasComponent&>(comp->obj->get_comp());
auto& gui = drawP.world.main.g.gui;
auto commit_update_func = [&] { comp->obj->commit_update(drawP); };
auto commit_update_func = [&] { commitUpdate = true; };
auto commit_update_and_layout_func = [&] {
comp->obj->commit_update(drawP);
commitUpdate = true;
drawP.world.main.g.gui.set_to_layout();
};
@ -83,9 +83,9 @@ void EllipseDrawEditTool::gui_phone_toolbox(PhoneDrawingProgramScreen& t) {
auto& a = static_cast<EllipseCanvasComponent&>(comp->obj->get_comp());
auto& gui = drawP.world.main.g.gui;
auto commit_update_func = [&] { comp->obj->commit_update(drawP); };
auto commit_update_func = [&] { commitUpdate = true; };
auto commit_update_and_layout_func = [&] {
comp->obj->commit_update(drawP);
commitUpdate = true;
drawP.world.main.g.gui.set_to_layout();
};

View file

@ -50,13 +50,12 @@ void ImageEditTool::edit_start(EditTool& editTool, std::any& prevData) {
editTool.add_point_handle({&a.d.cropP1, &staticZero, &a.d.cropP2, 0.0f, MINIMUM_DISTANCE_BETWEEN_IMAGE_CROP_POINTS, transformMat});
editTool.add_point_handle({&a.d.cropP2, &a.d.cropP1, &staticOne, MINIMUM_DISTANCE_BETWEEN_IMAGE_CROP_POINTS, 0.0f, transformMat});
a.d.editing = true;
comp->obj->commit_update(drawP);
commitUpdate = true;
}
void ImageEditTool::commit_edit_updates(std::any& prevData) {
auto& a = static_cast<ImageCanvasComponent&>(comp->obj->get_comp());
a.d.editing = false;
comp->obj->commit_update(drawP);
}
void ImageEditTool::edit_update() {

View file

@ -36,10 +36,10 @@ void RectDrawEditTool::edit_gui(Toolbar& t) {
auto& a = static_cast<RectangleCanvasComponent&>(comp->obj->get_comp());
auto commit_update_and_layout_func = [&] {
comp->obj->commit_update(drawP);
commitUpdate = true;
drawP.world.main.g.gui.set_to_layout();
};
auto commit_update_func = [&] { comp->obj->commit_update(drawP); };
auto commit_update_func = [&] { commitUpdate = true; };
auto& gui = drawP.world.main.g.gui;
gui.new_id("edit tool rectangle", [&] {
@ -81,10 +81,10 @@ void RectDrawEditTool::gui_phone_toolbox(PhoneDrawingProgramScreen& t) {
auto& a = static_cast<RectangleCanvasComponent&>(comp->obj->get_comp());
auto commit_update_and_layout_func = [&] {
comp->obj->commit_update(drawP);
commitUpdate = true;
drawP.world.main.g.gui.set_to_layout();
};
auto commit_update_func = [&] { comp->obj->commit_update(drawP); };
auto commit_update_func = [&] { commitUpdate = true; };
auto& gui = drawP.world.main.g.gui;
gui.new_id("edit tool rectangle", [&] {

View file

@ -47,13 +47,13 @@ TextBoxEditTool::TextBoxEditTool(DrawingProgram& initDrawP, CanvasComponentConta
{}
void TextBoxEditTool::commit_update_func_no_android_update() {
comp->obj->commit_update(drawP);
commitUpdate = true;
if(userInput)
userInput->android_force_update_modmap();
}
void TextBoxEditTool::commit_update_and_layout_func_no_android_update() {
comp->obj->commit_update(drawP);
commitUpdate = true;
drawP.world.main.g.gui.set_to_layout();
// modmap update is required at the very least in response to input from the C++ side
if(userInput)
@ -61,13 +61,13 @@ void TextBoxEditTool::commit_update_and_layout_func_no_android_update() {
}
void TextBoxEditTool::commit_update_func_and_android_update() {
comp->obj->commit_update(drawP);
commitUpdate = true;
if(userInput)
userInput->android_force_update_textbox_and_cursor();
}
void TextBoxEditTool::commit_update_and_layout_func_and_android_update() {
comp->obj->commit_update(drawP);
commitUpdate = true;
drawP.world.main.g.gui.set_to_layout();
if(userInput)
userInput->android_force_update_textbox_and_cursor();
@ -760,7 +760,6 @@ void TextBoxEditTool::set_styles_at_selection(TextBoxCanvasComponent& a) {
void TextBoxEditTool::commit_edit_updates(std::any& prevData) {
auto& a = static_cast<TextBoxCanvasComponent&>(comp->obj->get_comp());
a.d.editing = false;
comp->obj->commit_update(drawP);
userInput = nullptr;
CustomEvents::emit_event(CustomEvents::RefreshTextBoxInputEvent{});
}
@ -790,7 +789,7 @@ void TextBoxEditTool::edit_start(EditTool& editTool, std::any& prevData) {
editTool.add_point_handle({&a.d.p1, nullptr, &a.d.p2});
editTool.add_point_handle({&a.d.p2, &a.d.p1, nullptr});
comp->obj->commit_update(drawP);
commitUpdate = true;
userInput = std::make_unique<RichTextUserInput>(CustomEvents::text_box_get_new_id(), textbox, cur, currentModsPtr);
CustomEvents::emit_event(CustomEvents::RefreshTextBoxInputEvent{});

View file

@ -119,14 +119,15 @@ void EllipseDrawTool::input_mouse_motion_callback(const InputManager::MouseMotio
ellipse.d.p1 = cwise_vec_min(startAt, newPos);
ellipse.d.p2 = cwise_vec_max(startAt, newPos);
ellipse.d.p2 = ensure_points_have_distance(ellipse.d.p1, ellipse.d.p2, MINIMUM_DISTANCE_BETWEEN_BOUNDS);
containerPtr->send_comp_update(drawP, false);
containerPtr->commit_update(drawP);
commitUpdate = true;
}
}
void EllipseDrawTool::erase_component(CanvasComponentContainer::ObjInfo* erasedComp) {
if(objInfoBeingEdited == erasedComp)
if(objInfoBeingEdited == erasedComp) {
objInfoBeingEdited = nullptr;
commitUpdate = false;
}
}
void EllipseDrawTool::right_click_popup_gui(Toolbar& t, Vector2f popupPos) {
@ -138,6 +139,12 @@ void EllipseDrawTool::switch_tool(DrawingProgramToolType newTool) {
}
void EllipseDrawTool::tool_update() {
if(commitUpdate && objInfoBeingEdited) {
NetworkingObjects::NetObjOwnerPtr<CanvasComponentContainer>& containerPtr = objInfoBeingEdited->obj;
containerPtr->commit_update(drawP);
containerPtr->send_comp_update(drawP, false);
commitUpdate = false;
}
}
bool EllipseDrawTool::prevent_undo_or_redo() {
@ -149,6 +156,7 @@ void EllipseDrawTool::commit() {
NetworkingObjects::NetObjOwnerPtr<CanvasComponentContainer>& containerPtr = objInfoBeingEdited->obj;
containerPtr->commit_update(drawP);
containerPtr->send_comp_update(drawP, true);
commitUpdate = false;
if(containerPtr->get_world_bounds().has_value())
drawP.layerMan.add_undo_place_component(objInfoBeingEdited);
else {

View file

@ -41,6 +41,8 @@ class EllipseDrawTool : public DrawingProgramToolBase {
private:
void commit();
bool commitUpdate = false;
Vector2f startAt;
CanvasComponentContainer::ObjInfo* objInfoBeingEdited = nullptr;
};

View file

@ -106,14 +106,15 @@ void LineDrawTool::input_mouse_motion_callback(const InputManager::MouseMotionCa
newPos = oldPos + diffLength * Vector2f{cos(angle), sin(angle)};
}
brushStroke.d.points->back().pos = ensure_points_have_distance(oldPos, newPos, 1.0f);
containerPtr->send_comp_update(drawP, false);
containerPtr->commit_update(drawP);
commitUpdate = true;
}
}
void LineDrawTool::erase_component(CanvasComponentContainer::ObjInfo* erasedComp) {
if(objInfoBeingEdited == erasedComp)
if(objInfoBeingEdited == erasedComp) {
objInfoBeingEdited = nullptr;
commitUpdate = false;
}
}
void LineDrawTool::right_click_popup_gui(Toolbar& t, Vector2f popupPos) {
@ -125,6 +126,12 @@ void LineDrawTool::switch_tool(DrawingProgramToolType newTool) {
}
void LineDrawTool::tool_update() {
if(commitUpdate && objInfoBeingEdited) {
NetworkingObjects::NetObjOwnerPtr<CanvasComponentContainer>& containerPtr = objInfoBeingEdited->obj;
containerPtr->commit_update(drawP);
containerPtr->send_comp_update(drawP, false);
commitUpdate = false;
}
}
bool LineDrawTool::prevent_undo_or_redo() {
@ -136,6 +143,7 @@ void LineDrawTool::commit() {
NetworkingObjects::NetObjOwnerPtr<CanvasComponentContainer>& containerPtr = objInfoBeingEdited->obj;
containerPtr->commit_update(drawP);
containerPtr->send_comp_update(drawP, true);
commitUpdate = false;
if(containerPtr->get_world_bounds().has_value())
drawP.layerMan.add_undo_place_component(objInfoBeingEdited);
else {

View file

@ -39,6 +39,7 @@ class LineDrawTool : public DrawingProgramToolBase {
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override;
private:
void commit();
bool commitUpdate = false;
CanvasComponentContainer::ObjInfo* objInfoBeingEdited = nullptr;
};

View file

@ -125,14 +125,15 @@ void RectDrawTool::input_mouse_motion_callback(const InputManager::MouseMotionCa
rectangle.d.p1 = cwise_vec_min(startAt, newPos);
rectangle.d.p2 = cwise_vec_max(startAt, newPos);
rectangle.d.p2 = ensure_points_have_distance(rectangle.d.p1, rectangle.d.p2, MINIMUM_DISTANCE_BETWEEN_BOUNDS);
containerPtr->send_comp_update(drawP, false);
containerPtr->commit_update(drawP);
commitUpdate = true;
}
}
void RectDrawTool::erase_component(CanvasComponentContainer::ObjInfo* erasedComp) {
if(objInfoBeingEdited == erasedComp)
if(objInfoBeingEdited == erasedComp) {
objInfoBeingEdited = nullptr;
commitUpdate = false;
}
}
void RectDrawTool::right_click_popup_gui(Toolbar& t, Vector2f popupPos) {
@ -144,6 +145,12 @@ void RectDrawTool::switch_tool(DrawingProgramToolType newTool) {
}
void RectDrawTool::tool_update() {
if(commitUpdate && objInfoBeingEdited) {
NetworkingObjects::NetObjOwnerPtr<CanvasComponentContainer>& containerPtr = objInfoBeingEdited->obj;
containerPtr->commit_update(drawP);
containerPtr->send_comp_update(drawP, false);
commitUpdate = false;
}
}
bool RectDrawTool::prevent_undo_or_redo() {
@ -155,6 +162,7 @@ void RectDrawTool::commit() {
NetworkingObjects::NetObjOwnerPtr<CanvasComponentContainer>& containerPtr = objInfoBeingEdited->obj;
containerPtr->commit_update(drawP);
containerPtr->send_comp_update(drawP, true);
commitUpdate = false;
if(containerPtr->get_world_bounds().has_value())
drawP.layerMan.add_undo_place_component(objInfoBeingEdited);
else {

View file

@ -38,6 +38,8 @@ class RectDrawTool : public DrawingProgramToolBase {
virtual void input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) override;
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override;
private:
bool commitUpdate = false;
void commit();
Vector2f startAt;

View file

@ -70,6 +70,7 @@ void TextBoxTool::input_mouse_button_on_canvas_callback(const InputManager::Mous
}
else if(!button.down && objInfoBeingEdited) {
make_sure_textbox_is_big();
tool_update();
auto editTool = std::make_unique<EditTool>(drawP);
editTool->edit_start(objInfoBeingEdited, false);
drawP.toolToSwitchToAfterUpdate = std::move(editTool);
@ -91,9 +92,7 @@ void TextBoxTool::input_mouse_motion_callback(const InputManager::MouseMotionCal
textBox.d.p1 = cwise_vec_min(endAt, startAt);
textBox.d.p2 = cwise_vec_max(endAt, startAt);
textBox.d.p2 = ensure_points_have_distance(textBox.d.p1, textBox.d.p2, MINIMUM_DISTANCE_BETWEEN_BOUNDS);
containerPtr->send_comp_update(drawP, false);
containerPtr->commit_update(drawP);
commitUpdate = true;
}
}
@ -108,8 +107,10 @@ void TextBoxTool::make_sure_textbox_is_big() {
}
void TextBoxTool::erase_component(CanvasComponentContainer::ObjInfo* erasedComp) {
if(objInfoBeingEdited == erasedComp)
if(objInfoBeingEdited == erasedComp) {
objInfoBeingEdited = nullptr;
commitUpdate = false;
}
}
void TextBoxTool::right_click_popup_gui(Toolbar& t, Vector2f popupPos) {
@ -121,6 +122,12 @@ void TextBoxTool::switch_tool(DrawingProgramToolType newTool) {
}
void TextBoxTool::tool_update() {
if(commitUpdate && objInfoBeingEdited) {
NetworkingObjects::NetObjOwnerPtr<CanvasComponentContainer>& containerPtr = objInfoBeingEdited->obj;
containerPtr->commit_update(drawP);
containerPtr->send_comp_update(drawP, false);
commitUpdate = false;
}
}
bool TextBoxTool::prevent_undo_or_redo() {
@ -133,6 +140,7 @@ void TextBoxTool::commit() {
make_sure_textbox_is_big();
containerPtr->commit_update(drawP);
containerPtr->send_comp_update(drawP, true);
commitUpdate = false;
drawP.layerMan.add_undo_place_component(objInfoBeingEdited);
objInfoBeingEdited = nullptr;
}

View file

@ -38,6 +38,8 @@ class TextBoxTool : public DrawingProgramToolBase {
virtual void input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) override;
virtual void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) override;
private:
bool commitUpdate = false;
void commit();
void make_sure_textbox_is_big();