infinipaint/src/DrawingProgram/Tools/EditTools/EllipseDrawEditTool.cpp

127 lines
5 KiB
C++
Raw Normal View History

/*
* InfiniPaint
* Copyright (C) 2025-2026 Yousef Khadadeh
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
2025-08-02 20:10:33 +03:00
#include "EllipseDrawEditTool.hpp"
#include "../../DrawingProgram.hpp"
#include "../../../World.hpp"
#include "../../../MainProgram.hpp"
#include "../../../DrawData.hpp"
2025-08-02 20:10:33 +03:00
#include <cereal/types/vector.hpp>
#include "../EditTool.hpp"
2025-08-02 20:10:33 +03:00
#include "../../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
#include "../../../GUIStuff/ElementHelpers/RadioButtonHelpers.hpp"
#include "../../../GUIStuff/ElementHelpers/LayoutHelpers.hpp"
#include "../../../GUIStuff/ElementHelpers/NumberSliderHelpers.hpp"
EllipseDrawEditTool::EllipseDrawEditTool(DrawingProgram& initDrawP, CanvasComponentContainer::ObjInfo* initComp):
DrawingProgramEditToolBase(initDrawP, initComp)
2025-08-02 20:10:33 +03:00
{}
2026-04-12 12:36:00 +03:00
void EllipseDrawEditTool::edit_gui(Toolbar& t) {
using namespace GUIStuff;
using namespace ElementHelpers;
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_and_layout_func = [&] {
2026-04-02 10:15:22 +03:00
comp->obj->commit_update(drawP);
drawP.world.main.g.gui.set_to_layout();
};
2025-08-02 20:10:33 +03:00
gui.new_id("edit tool ellipse", [&] {
text_label_centered(gui, "Edit Ellipse");
radio_button_selector(gui, "Fill selector", &a.d.fillStrokeMode, {
2026-03-30 18:51:14 +03:00
{"Fill only", 0},
{"Outline only", 1},
{"Fill and outline", 2}
2026-04-02 10:15:22 +03:00
}, commit_update_and_layout_func);
2026-03-30 18:51:14 +03:00
if(a.d.fillStrokeMode == 0 || a.d.fillStrokeMode == 2) {
left_to_right_line_layout(gui, [&] {
t.color_button_right("Fill color button", &a.d.fillColor, { .onChange = commit_update_func });
text_label(gui, "Fill Color");
2026-03-30 18:51:14 +03:00
});
}
if(a.d.fillStrokeMode == 1 || a.d.fillStrokeMode == 2) {
2026-04-02 10:15:22 +03:00
slider_scalar_field(gui, "relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f, {.onEdit = commit_update_func});
left_to_right_line_layout(gui, [&] {
t.color_button_right("Outline color button", &a.d.strokeColor, { .onChange = commit_update_func });
text_label(gui, "Outline Color");
2026-03-30 18:51:14 +03:00
});
}
});
2025-08-02 20:10:33 +03:00
}
Vector4f* EllipseDrawEditTool::color_picker_color(Vector4f* oldColor) {
auto& a = static_cast<EllipseCanvasComponent&>(comp->obj->get_comp());
if(oldColor == &a.d.fillColor)
return oldColor;
if(oldColor == &a.d.strokeColor)
return oldColor;
return nullptr;
}
void EllipseDrawEditTool::gui_phone_toolbox(PhoneDrawingProgramScreen& t) {
using namespace GUIStuff;
using namespace ElementHelpers;
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_and_layout_func = [&] {
comp->obj->commit_update(drawP);
drawP.world.main.g.gui.set_to_layout();
};
gui.new_id("edit tool ellipse", [&] {
radio_button_selector(gui, "Fill selector", &a.d.fillStrokeMode, {
{"Fill only", 0},
{"Outline only", 1},
{"Fill and outline", 2}
}, commit_update_and_layout_func);
if(a.d.fillStrokeMode == 0 || a.d.fillStrokeMode == 2) {
left_to_right_line_layout(gui, [&] {
t.color_selector_button("Fill color button", &a.d.fillColor, { .onChange = commit_update_func });
text_label(gui, "Fill Color");
});
}
if(a.d.fillStrokeMode == 1 || a.d.fillStrokeMode == 2) {
slider_scalar_field(gui, "relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f, {.onEdit = commit_update_func});
left_to_right_line_layout(gui, [&] {
t.color_selector_button("Outline color button", &a.d.strokeColor, { .onChange = commit_update_func });
text_label(gui, "Outline Color");
});
}
});
}
void EllipseDrawEditTool::edit_start(EditTool& editTool, std::any& prevData) {
auto& a = static_cast<EllipseCanvasComponent&>(comp->obj->get_comp());
2025-08-02 20:10:33 +03:00
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});
2025-08-02 20:10:33 +03:00
}
void EllipseDrawEditTool::commit_edit_updates(std::any& prevData) {
2025-08-02 20:10:33 +03:00
}
2026-05-18 17:57:02 +03:00
void EllipseDrawEditTool::edit_update() {
2025-08-02 20:10:33 +03:00
}