All tools now converted to use new net objects

This commit is contained in:
Yousef Khadadeh 2025-12-15 15:36:42 +03:00
parent 45ba26446a
commit 7d1671229b
62 changed files with 492 additions and 481 deletions

View file

@ -11,66 +11,48 @@ EllipseDrawEditTool::EllipseDrawEditTool(DrawingProgram& initDrawP):
DrawingProgramEditToolBase(initDrawP)
{}
bool EllipseDrawEditTool::edit_gui(const std::shared_ptr<DrawComponent>& comp) {
auto a = std::static_pointer_cast<DrawEllipse>(comp);
bool EllipseDrawEditTool::edit_gui(const CanvasComponentContainer::ObjInfoSharedPtr& comp) {
auto& a = static_cast<EllipseCanvasComponent&>(comp->obj->get_comp());
Toolbar& t = drawP.world.main.toolbar;
t.gui.push_id("edit tool ellipse");
t.gui.text_label_centered("Edit Ellipse");
if(t.gui.radio_button_field("fillonly", "Fill only", a->d.fillStrokeMode == 0)) a->d.fillStrokeMode = 0;
if(t.gui.radio_button_field("outlineonly", "Outline only", a->d.fillStrokeMode == 1)) a->d.fillStrokeMode = 1;
if(t.gui.radio_button_field("filloutline", "Fill and Outline", a->d.fillStrokeMode == 2)) a->d.fillStrokeMode = 2;
if(a->d.fillStrokeMode == 0 || a->d.fillStrokeMode == 2) {
if(t.gui.radio_button_field("fillonly", "Fill only", a.d.fillStrokeMode == 0)) a.d.fillStrokeMode = 0;
if(t.gui.radio_button_field("outlineonly", "Outline only", a.d.fillStrokeMode == 1)) a.d.fillStrokeMode = 1;
if(t.gui.radio_button_field("filloutline", "Fill and Outline", a.d.fillStrokeMode == 2)) a.d.fillStrokeMode = 2;
if(a.d.fillStrokeMode == 0 || a.d.fillStrokeMode == 2) {
t.gui.left_to_right_line_layout([&]() {
if(t.gui.color_button_big("Fill Color", &a->d.fillColor, &a->d.fillColor == t.colorRight))
t.color_selector_right(&a->d.fillColor == t.colorRight ? nullptr : &a->d.fillColor);
if(t.gui.color_button_big("Fill Color", &a.d.fillColor, &a.d.fillColor == t.colorRight))
t.color_selector_right(&a.d.fillColor == t.colorRight ? nullptr : &a.d.fillColor);
t.gui.text_label("Fill Color");
});
}
if(a->d.fillStrokeMode == 1 || a->d.fillStrokeMode == 2) {
t.gui.slider_scalar_field("relstrokewidth", "Outline Size", &a->d.strokeWidth, 3.0f, 40.0f);
if(a.d.fillStrokeMode == 1 || a.d.fillStrokeMode == 2) {
t.gui.slider_scalar_field("relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f);
t.gui.left_to_right_line_layout([&]() {
if(t.gui.color_button_big("Outline Color", &a->d.strokeColor, &a->d.strokeColor == t.colorRight))
t.color_selector_right(&a->d.strokeColor == t.colorRight ? nullptr : &a->d.strokeColor);
if(t.gui.color_button_big("Outline Color", &a.d.strokeColor, &a.d.strokeColor == t.colorRight))
t.color_selector_right(&a.d.strokeColor == t.colorRight ? nullptr : &a.d.strokeColor);
t.gui.text_label("Outline Color");
});
}
t.gui.pop_id();
bool editHappened = (!oldData.has_value()) || (a->d != oldData);
oldData = a->d;
bool editHappened = (!oldData.has_value()) || (a.d != oldData);
oldData = a.d;
return editHappened;
}
void EllipseDrawEditTool::edit_start(EditTool& editTool, const std::shared_ptr<DrawComponent>& comp, std::any& prevData) {
auto a = std::static_pointer_cast<DrawEllipse>(comp);
void EllipseDrawEditTool::edit_start(EditTool& editTool, const CanvasComponentContainer::ObjInfoSharedPtr& comp, std::any& prevData) {
auto& a = static_cast<EllipseCanvasComponent&>(comp->obj->get_comp());
prevData = a->d;
editTool.add_point_handle({&a->d.p1, nullptr, &a->d.p2});
editTool.add_point_handle({&a->d.p2, &a->d.p1, nullptr});
prevData = a.d;
editTool.add_point_handle({&a.d.p1, nullptr, &a.d.p2});
editTool.add_point_handle({&a.d.p2, &a.d.p1, nullptr});
}
void EllipseDrawEditTool::commit_edit_updates(const std::shared_ptr<DrawComponent>& comp, std::any& prevData) {
auto a = std::static_pointer_cast<DrawEllipse>(comp);
DrawEllipse::Data pData = std::any_cast<DrawEllipse::Data>(prevData);
DrawEllipse::Data cData = a->d;
drawP.world.undo.push(UndoManager::UndoRedoPair{
[&drawP = drawP, a, pData]() {
a->d = pData;
a->client_send_update(drawP, true);
a->commit_update(drawP);
return true;
},
[&drawP = drawP, a, cData]() {
a->d = cData;
a->client_send_update(drawP, true);
a->commit_update(drawP);
return true;
}
});
void EllipseDrawEditTool::commit_edit_updates(const CanvasComponentContainer::ObjInfoSharedPtr& comp, std::any& prevData) {
}
bool EllipseDrawEditTool::edit_update(const std::shared_ptr<DrawComponent>& comp) {
bool EllipseDrawEditTool::edit_update(const CanvasComponentContainer::ObjInfoSharedPtr& comp) {
return true;
}