More GUI code changes (broken build)

This commit is contained in:
Yousef Khadadeh 2026-03-30 12:32:41 +03:00
parent 644bb85d99
commit 3566b7e563
28 changed files with 178 additions and 120 deletions

View file

@ -182,7 +182,6 @@ void BrushTool::gui_toolbox() {
void BrushTool::right_click_popup_gui(Vector2f popupPos) {
Toolbar& t = drawP.world.main.toolbar;
t.paint_popup(popupPos);
return true;
}
bool BrushTool::prevent_undo_or_redo() {

View file

@ -154,7 +154,7 @@ void EditTool::input_mouse_motion_callback(const InputManager::MouseMotionCallba
drawP.selection.input_mouse_motion_callback_modify_selection(motion);
}
bool EditTool::right_click_popup_gui(Vector2f popupPos) {
void EditTool::right_click_popup_gui(Vector2f popupPos) {
if(objInfoBeingEdited)
return compEditTool->right_click_popup_gui(objInfoBeingEdited, popupPos);
else

View file

@ -19,7 +19,7 @@ class EditTool : public DrawingProgramToolBase {
EditTool(DrawingProgram& initDrawP);
virtual DrawingProgramToolType get_type() override;
virtual void gui_toolbox() override;
virtual bool right_click_popup_gui(Vector2f popupPos) override;
virtual void right_click_popup_gui(Vector2f popupPos) override;
virtual void tool_update() override;
virtual void erase_component(CanvasComponentContainer::ObjInfo* erasedComp) override;
virtual void switch_tool(DrawingProgramToolType newTool) override;

View file

@ -9,6 +9,9 @@
#include "../../CanvasComponents/EllipseCanvasComponent.hpp"
#include "../../CanvasComponents/CanvasComponentContainer.hpp"
#include "../../GUIStuff/ElementHelpers/RadioButtonHelpers.hpp"
#include "../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
EllipseDrawTool::EllipseDrawTool(DrawingProgram& initDrawP):
DrawingProgramToolBase(initDrawP)
{}
@ -18,14 +21,19 @@ DrawingProgramToolType EllipseDrawTool::get_type() {
}
void EllipseDrawTool::gui_toolbox() {
using namespace GUIStuff;
using namespace ElementHelpers;
Toolbar& t = drawP.world.main.toolbar;
auto& toolConfig = drawP.world.main.toolConfig;
auto& fillStrokeMode = toolConfig.ellipseDraw.fillStrokeMode;
t.gui.push_id("ellipse draw tool");
t.gui.text_label_centered("Draw Ellipse");
if(t.gui.radio_button_field("fillonly", "Fill only", fillStrokeMode == 0)) fillStrokeMode = 0;
if(t.gui.radio_button_field("outlineonly", "Outline only", fillStrokeMode == 1)) fillStrokeMode = 1;
if(t.gui.radio_button_field("filloutline", "Fill and Outline", fillStrokeMode == 2)) fillStrokeMode = 2;
text_label_centered(t.gui, "Draw Ellipse");
radio_button_selector(t.gui, "fill type", &fillStrokeMode, {
{"Fill only", 0},
{"Outline only", 1},
{"Fill and Outline", 2}
});
if(fillStrokeMode == 1 || fillStrokeMode == 2)
toolConfig.relative_width_gui(drawP, "Outline Size");
t.gui.pop_id();
@ -85,10 +93,9 @@ void EllipseDrawTool::erase_component(CanvasComponentContainer::ObjInfo* erasedC
objInfoBeingEdited = nullptr;
}
bool EllipseDrawTool::right_click_popup_gui(Vector2f popupPos) {
void EllipseDrawTool::right_click_popup_gui(Vector2f popupPos) {
Toolbar& t = drawP.world.main.toolbar;
t.paint_popup(popupPos);
return true;
}
void EllipseDrawTool::switch_tool(DrawingProgramToolType newTool) {

View file

@ -11,7 +11,7 @@ class EllipseDrawTool : public DrawingProgramToolBase {
EllipseDrawTool(DrawingProgram& initDrawP);
virtual DrawingProgramToolType get_type() override;
virtual void gui_toolbox() override;
virtual bool right_click_popup_gui(Vector2f popupPos) override;
virtual void right_click_popup_gui(Vector2f popupPos) override;
virtual void erase_component(CanvasComponentContainer::ObjInfo* erasedComp) override;
virtual void tool_update() override;
virtual void switch_tool(DrawingProgramToolType newTool) override;

View file

@ -5,6 +5,9 @@
#include <include/core/SkBlendMode.h>
#include <include/core/SkPathBuilder.h>
#include "../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
#include "../../GUIStuff/ElementHelpers/RadioButtonHelpers.hpp"
EraserTool::EraserTool(DrawingProgram& initDrawP):
DrawingProgramToolBase(initDrawP)
{}
@ -14,22 +17,24 @@ DrawingProgramToolType EraserTool::get_type() {
}
void EraserTool::gui_toolbox() {
using namespace GUIStuff;
using namespace ElementHelpers;
Toolbar& t = drawP.world.main.toolbar;
t.gui.push_id("eraser tool");
t.gui.text_label_centered("Eraser");
text_label_centered(t.gui, "Eraser");
drawP.world.main.toolConfig.relative_width_gui(drawP, "Size");
t.gui.text_label("Erase from:");
if(t.gui.radio_button_field("layer edited", "Layer being edited", drawP.controls.layerSelector == DrawingProgramLayerManager::LayerSelector::LAYER_BEING_EDITED))
drawP.controls.layerSelector = DrawingProgramLayerManager::LayerSelector::LAYER_BEING_EDITED;
if(t.gui.radio_button_field("all visible", "All visible layers", drawP.controls.layerSelector == DrawingProgramLayerManager::LayerSelector::ALL_VISIBLE_LAYERS))
drawP.controls.layerSelector = DrawingProgramLayerManager::LayerSelector::ALL_VISIBLE_LAYERS;
text_label(t.gui, "Erase from:");
radio_button_selector(t.gui, "layer selector", &drawP.controls.layerSelector, {
{"Layer being edited", DrawingProgramLayerManager::LayerSelector::LAYER_BEING_EDITED},
{"All visible layers", DrawingProgramLayerManager::LayerSelector::ALL_VISIBLE_LAYERS}
});
t.gui.pop_id();
}
bool EraserTool::right_click_popup_gui(Vector2f popupPos) {
void EraserTool::right_click_popup_gui(Vector2f popupPos) {
Toolbar& t = drawP.world.main.toolbar;
t.paint_popup(popupPos);
return true;
}
void EraserTool::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) {

View file

@ -11,7 +11,7 @@ class EraserTool : public DrawingProgramToolBase {
EraserTool(DrawingProgram& initDrawP);
virtual DrawingProgramToolType get_type() override;
virtual void gui_toolbox() override;
virtual bool right_click_popup_gui(Vector2f popupPos) override;
virtual void right_click_popup_gui(Vector2f popupPos) override;
virtual void erase_component(CanvasComponentContainer::ObjInfo* erasedComp) override;
virtual void tool_update() override;
virtual void switch_tool(DrawingProgramToolType newTool) override;

View file

@ -14,6 +14,9 @@
#include <include/core/SkSurface.h>
#include <Helpers/Logger.hpp>
#include "../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
#include "../../GUIStuff/ElementHelpers/RadioButtonHelpers.hpp"
EyeDropperTool::EyeDropperTool(DrawingProgram& initDrawP):
DrawingProgramToolBase(initDrawP)
{
@ -24,19 +27,24 @@ DrawingProgramToolType EyeDropperTool::get_type() {
}
void EyeDropperTool::gui_toolbox() {
using namespace GUIStuff;
using namespace ElementHelpers;
Toolbar& t = drawP.world.main.toolbar;
auto& selectingStrokeColor = drawP.world.main.toolConfig.eyeDropper.selectingStrokeColor;
t.gui.push_id("Color select tool");
t.gui.text_label_centered("Color Select");
if(t.gui.radio_button_field("Stroke Color", "Stroke Color", selectingStrokeColor)) selectingStrokeColor = true;
if(t.gui.radio_button_field("Fill Color", "Fill Color", !selectingStrokeColor)) selectingStrokeColor = false;
text_label_centered(t.gui, "Color Select");
radio_button_selector<bool>(t.gui, "Stroke type", &selectingStrokeColor, {
{"Stroke Color", true},
{"Fill Color", false}
});
t.gui.pop_id();
}
bool EyeDropperTool::right_click_popup_gui(Vector2f popupPos) {
void EyeDropperTool::right_click_popup_gui(Vector2f popupPos) {
Toolbar& t = drawP.world.main.toolbar;
t.paint_popup(popupPos);
return true;
}
void EyeDropperTool::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) {

View file

@ -8,7 +8,7 @@ class EyeDropperTool : public DrawingProgramToolBase {
EyeDropperTool(DrawingProgram& initDrawP);
virtual DrawingProgramToolType get_type() override;
virtual void gui_toolbox() override;
virtual bool right_click_popup_gui(Vector2f popupPos) override;
virtual void right_click_popup_gui(Vector2f popupPos) override;
virtual void tool_update() override;
virtual void erase_component(CanvasComponentContainer::ObjInfo* erasedComp) override;
virtual void draw(SkCanvas* canvas, const DrawData& drawData) override;

View file

@ -8,6 +8,12 @@
#include <Helpers/NetworkingObjects/NetObjGenericSerializedClass.hpp>
#include <cstddef>
#include "../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
#include "../../GUIStuff/ElementHelpers/LayoutHelpers.hpp"
#include "../../GUIStuff/ElementHelpers/TextBoxHelpers.hpp"
#include "../../GUIStuff/ElementHelpers/CheckBoxHelpers.hpp"
#include "../../GUIStuff/Elements/DropDown.hpp"
using namespace NetworkingObjects;
GridModifyTool::GridModifyTool(DrawingProgram& initDrawP):
@ -108,15 +114,18 @@ void GridModifyTool::input_mouse_motion_callback(const InputManager::MouseMotion
}
void GridModifyTool::gui_toolbox() {
using namespace GUIStuff;
using namespace ElementHelpers;
Toolbar& t = drawP.world.main.toolbar;
t.gui.push_id("Grid modify tool");
t.gui.text_label_centered("Edit Grid");
text_label_centered(t.gui, "Edit Grid");
NetworkingObjects::NetObjTemporaryPtr<WorldGrid> gLock = grid.lock();
if(gLock) {
WorldGrid& g = *gLock;
t.gui.input_text_field("grid name", "Name", &g.name);
t.gui.checkbox_field("Visible", "Visible", &g.visible);
t.gui.checkbox_field("Display in Front", "Display in front of canvas", &g.displayInFront);
input_text_field(t.gui, "grid name", "Name", &g.name);
checkbox_boolean_field(t.gui, "Visible", "Visible", &g.visible);
checkbox_boolean_field(t.gui, "Display in Front", "Display in front of canvas", &g.displayInFront);
size_t typeSelected = static_cast<size_t>(g.gridType);
std::vector<std::string> listOfGridTypes = {
"Circle Points",
@ -124,25 +133,25 @@ void GridModifyTool::gui_toolbox() {
"Square Lines",
"Horizontal Lines"
};
t.gui.left_to_right_line_layout([&]() {
t.gui.text_label("Type");
t.gui.dropdown_select("filepicker select type", &typeSelected, listOfGridTypes, 200.0f);
left_to_right_line_layout(t.gui, [&]() {
text_label(t.gui, "Type");
t.gui.element<DropDown<size_t>>("filepicker select type", &typeSelected, listOfGridTypes, 200.0f);
});
g.gridType = static_cast<WorldGrid::GridType>(typeSelected);
uint32_t sDiv = g.subdivisions;
t.gui.input_scalar_field<uint32_t>("Subdivisions", "Subdivisions", &sDiv, 1, 10);
input_scalar_field<uint32_t>(t.gui, "Subdivisions", "Subdivisions", &sDiv, 1, 10);
g.set_subdivisions(sDiv);
bool divOut = g.removeDivisionsOutwards;
t.gui.checkbox_field("Subdivide outwards", "Subdivide when zooming out", &divOut);
checkbox_boolean_field(t.gui, "Subdivide outwards", "Subdivide when zooming out", &divOut);
g.set_remove_divisions_outwards(divOut);
t.gui.left_to_right_line_layout([&]() {
if(t.gui.color_button_big("Grid Color", &g.color, &g.color == t.colorRight))
t.color_selector_right(&g.color == t.colorRight ? nullptr : &g.color);
t.gui.text_label("Grid Color");
left_to_right_line_layout(t.gui, [&]() {
//if(t.gui.color_button_big("Grid Color", &g.color, &g.color == t.colorRight))
// t.color_selector_right(&g.color == t.colorRight ? nullptr : &g.color);
text_label(t.gui, "Grid Color");
});
bool bounded = g.bounds.has_value();
bool prevBoundedValue = bounded;
t.gui.checkbox_field("Bounded", "Bounded", &bounded);
checkbox_boolean_field(t.gui, "Bounded", "Bounded", &bounded);
if(bounded && !prevBoundedValue) {
SCollision::AABB<WorldScalar> newBounds;
newBounds.min = g.offset - drawP.world.drawData.cam.c.dir_from_space(drawP.world.main.window.size.cast<float>() * 0.3f);
@ -151,15 +160,14 @@ void GridModifyTool::gui_toolbox() {
}
else if(!bounded && prevBoundedValue)
g.bounds = std::nullopt;
t.gui.checkbox_field("Show Coordinates", "Show Coordinates (visible\nwhen canvas isn't rotated)", &g.showCoordinates);
checkbox_boolean_field(t.gui, "Show Coordinates", "Show Coordinates (visible\nwhen canvas isn't rotated)", &g.showCoordinates);
}
t.gui.pop_id();
}
bool GridModifyTool::right_click_popup_gui(Vector2f popupPos) {
void GridModifyTool::right_click_popup_gui(Vector2f popupPos) {
Toolbar& t = drawP.world.main.toolbar;
t.paint_popup(popupPos);
return true;
}
void GridModifyTool::tool_update() {

View file

@ -11,7 +11,7 @@ class GridModifyTool : public DrawingProgramToolBase {
void set_grid(const NetworkingObjects::NetObjWeakPtr<WorldGrid>& newGrid);
virtual DrawingProgramToolType get_type() override;
virtual void gui_toolbox() override;
virtual bool right_click_popup_gui(Vector2f popupPos) override;
virtual void right_click_popup_gui(Vector2f popupPos) override;
virtual void tool_update() override;
virtual void erase_component(CanvasComponentContainer::ObjInfo* erasedComp) override;
virtual void draw(SkCanvas* canvas, const DrawData& drawData) override;

View file

@ -11,6 +11,8 @@
#include <earcut.hpp>
#include <include/core/SkPathBuilder.h>
#include "../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
namespace mapbox {
namespace util {
@ -41,13 +43,13 @@ DrawingProgramToolType LassoSelectTool::get_type() {
void LassoSelectTool::gui_toolbox() {
auto& t = drawP.world.main.toolbar;
t.gui.push_id("lasso select tool");
t.gui.text_label_centered("Lasso Select");
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Lasso Select");
drawP.selection.selection_gui();
t.gui.pop_id();
}
bool LassoSelectTool::right_click_popup_gui(Vector2f popupPos) {
return drawP.selection_action_menu(popupPos);
void LassoSelectTool::right_click_popup_gui(Vector2f popupPos) {
drawP.selection_action_menu(popupPos);
}
void LassoSelectTool::input_key_callback(const InputManager::KeyCallbackArgs& key) {

View file

@ -12,7 +12,7 @@ class LassoSelectTool : public DrawingProgramToolBase {
LassoSelectTool(DrawingProgram& initDrawP);
virtual DrawingProgramToolType get_type() override;
virtual void gui_toolbox() override;
virtual bool right_click_popup_gui(Vector2f popupPos) override;
virtual void right_click_popup_gui(Vector2f popupPos) override;
virtual void erase_component(CanvasComponentContainer::ObjInfo* erasedComp) override;
virtual void tool_update() override;
virtual void draw(SkCanvas* canvas, const DrawData& drawData) override;

View file

@ -8,6 +8,9 @@
#include "Helpers/MathExtras.hpp"
#include <limits>
#include "../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
#include "../../GUIStuff/ElementHelpers/CheckBoxHelpers.cpp"
LineDrawTool::LineDrawTool(DrawingProgram& initDrawP):
DrawingProgramToolBase(initDrawP)
{}
@ -17,12 +20,14 @@ DrawingProgramToolType LineDrawTool::get_type() {
}
void LineDrawTool::gui_toolbox() {
using namespace GUIStuff;
using namespace ElementHelpers;
Toolbar& t = drawP.world.main.toolbar;
auto& toolConfig = drawP.world.main.toolConfig;
t.gui.push_id("rect draw tool");
t.gui.text_label_centered("Draw Line");
text_label_centered(t.gui, "Draw Line");
toolConfig.relative_width_gui(drawP, "Size");
t.gui.checkbox_field("hasroundcaps", "Round Caps", &toolConfig.lineDraw.hasRoundCaps);
checkbox_boolean_field(t.gui, "hasroundcaps", "Round Caps", &toolConfig.lineDraw.hasRoundCaps);
t.gui.pop_id();
}
@ -83,10 +88,9 @@ void LineDrawTool::erase_component(CanvasComponentContainer::ObjInfo* erasedComp
objInfoBeingEdited = nullptr;
}
bool LineDrawTool::right_click_popup_gui(Vector2f popupPos) {
void LineDrawTool::right_click_popup_gui(Vector2f popupPos) {
Toolbar& t = drawP.world.main.toolbar;
t.paint_popup(popupPos);
return true;
}
void LineDrawTool::switch_tool(DrawingProgramToolType newTool) {

View file

@ -10,7 +10,7 @@ class LineDrawTool : public DrawingProgramToolBase {
LineDrawTool(DrawingProgram& initDrawP);
virtual DrawingProgramToolType get_type() override;
virtual void gui_toolbox() override;
virtual bool right_click_popup_gui(Vector2f popupPos) override;
virtual void right_click_popup_gui(Vector2f popupPos) override;
virtual void erase_component(CanvasComponentContainer::ObjInfo* erasedComp) override;
virtual void tool_update() override;
virtual void switch_tool(DrawingProgramToolType newTool) override;

View file

@ -5,6 +5,8 @@
#include "DrawingProgramToolBase.hpp"
#include <Helpers/Logger.hpp>
#include "../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
PanCanvasTool::PanCanvasTool(DrawingProgram& initDrawP):
DrawingProgramToolBase(initDrawP)
{
@ -17,12 +19,12 @@ DrawingProgramToolType PanCanvasTool::get_type() {
void PanCanvasTool::gui_toolbox() {
Toolbar& t = drawP.world.main.toolbar;
t.gui.push_id("Pan canvas tool");
t.gui.text_label_centered("Pan tool");
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Pan tool");
t.gui.pop_id();
}
bool PanCanvasTool::right_click_popup_gui(Vector2f popupPos) {
return drawP.selection_action_menu(popupPos);
void PanCanvasTool::right_click_popup_gui(Vector2f popupPos) {
drawP.selection_action_menu(popupPos);
}
void PanCanvasTool::erase_component(CanvasComponentContainer::ObjInfo* erasedComp) {

View file

@ -8,7 +8,7 @@ class PanCanvasTool : public DrawingProgramToolBase {
PanCanvasTool(DrawingProgram& initDrawP);
virtual DrawingProgramToolType get_type() override;
virtual void gui_toolbox() override;
virtual bool right_click_popup_gui(Vector2f popupPos) override;
virtual void right_click_popup_gui(Vector2f popupPos) override;
virtual void erase_component(CanvasComponentContainer::ObjInfo* erasedComp) override;
virtual void tool_update() override;
virtual void draw(SkCanvas* canvas, const DrawData& drawData) override;

View file

@ -6,6 +6,10 @@
#include "../../CanvasComponents/RectangleCanvasComponent.hpp"
#include "../../CanvasComponents/CanvasComponentContainer.hpp"
#include "../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
#include "../../GUIStuff/ElementHelpers/NumberSliderHelpers.hpp"
#include "../../GUIStuff/ElementHelpers/RadioButtonHelpers.hpp"
RectDrawTool::RectDrawTool(DrawingProgram& initDrawP):
DrawingProgramToolBase(initDrawP)
{}
@ -15,16 +19,21 @@ DrawingProgramToolType RectDrawTool::get_type() {
}
void RectDrawTool::gui_toolbox() {
using namespace GUIStuff;
using namespace ElementHelpers;
Toolbar& t = drawP.world.main.toolbar;
auto& toolConfig = drawP.world.main.toolConfig;
auto& fillStrokeMode = toolConfig.rectDraw.fillStrokeMode;
auto& relativeRadiusWidth = toolConfig.rectDraw.relativeRadiusWidth;
t.gui.push_id("rect draw tool");
t.gui.text_label_centered("Draw Rectangle");
t.gui.slider_scalar_field("relradiuswidth", "Corner Radius", &relativeRadiusWidth, 0.0f, 40.0f);
if(t.gui.radio_button_field("fillonly", "Fill only", fillStrokeMode == 0)) fillStrokeMode = 0;
if(t.gui.radio_button_field("outlineonly", "Outline only", fillStrokeMode == 1)) fillStrokeMode = 1;
if(t.gui.radio_button_field("filloutline", "Fill and Outline", fillStrokeMode == 2)) fillStrokeMode = 2;
text_label_centered(t.gui, "Draw Rectangle");
slider_scalar_field(t.gui, "relradiuswidth", "Corner Radius", &relativeRadiusWidth, 0.0f, 40.0f);
radio_button_selector(t.gui, "fill type", &fillStrokeMode, {
{"Fill only", 0},
{"Outline only", 1},
{"Fill and Outline", 2}
});
if(fillStrokeMode == 1 || fillStrokeMode == 2)
toolConfig.relative_width_gui(drawP, "Outline Size");
t.gui.pop_id();
@ -88,10 +97,9 @@ void RectDrawTool::erase_component(CanvasComponentContainer::ObjInfo* erasedComp
objInfoBeingEdited = nullptr;
}
bool RectDrawTool::right_click_popup_gui(Vector2f popupPos) {
void RectDrawTool::right_click_popup_gui(Vector2f popupPos) {
Toolbar& t = drawP.world.main.toolbar;
t.paint_popup(popupPos);
return true;
}
void RectDrawTool::switch_tool(DrawingProgramToolType newTool) {

View file

@ -10,7 +10,7 @@ class RectDrawTool : public DrawingProgramToolBase {
RectDrawTool(DrawingProgram& initDrawP);
virtual DrawingProgramToolType get_type() override;
virtual void gui_toolbox() override;
virtual bool right_click_popup_gui(Vector2f popupPos) override;
virtual void right_click_popup_gui(Vector2f popupPos) override;
virtual void erase_component(CanvasComponentContainer::ObjInfo* erasedComp) override;
virtual void tool_update() override;
virtual void switch_tool(DrawingProgramToolType newTool) override;

View file

@ -7,6 +7,8 @@
#include "Helpers/SCollision.hpp"
#include "../../CoordSpaceHelper.hpp"
#include "../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
RectSelectTool::RectSelectTool(DrawingProgram& initDrawP):
DrawingProgramToolBase(initDrawP)
{
@ -19,7 +21,7 @@ DrawingProgramToolType RectSelectTool::get_type() {
void RectSelectTool::gui_toolbox() {
auto& t = drawP.world.main.toolbar;
t.gui.push_id("rectangle select tool");
t.gui.text_label_centered("Rectangle Select");
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Rectangle Select");
drawP.selection.selection_gui();
t.gui.pop_id();
}
@ -70,8 +72,8 @@ void RectSelectTool::input_mouse_motion_callback(const InputManager::MouseMotion
void RectSelectTool::erase_component(CanvasComponentContainer::ObjInfo* erasedComp) {
}
bool RectSelectTool::right_click_popup_gui(Vector2f popupPos) {
return drawP.selection_action_menu(popupPos);
void RectSelectTool::right_click_popup_gui(Vector2f popupPos) {
drawP.selection_action_menu(popupPos);
}
void RectSelectTool::switch_tool(DrawingProgramToolType newTool) {

View file

@ -11,7 +11,7 @@ class RectSelectTool : public DrawingProgramToolBase {
virtual DrawingProgramToolType get_type() override;
virtual void gui_toolbox() override;
virtual void erase_component(CanvasComponentContainer::ObjInfo* erasedComp) override;
virtual bool right_click_popup_gui(Vector2f popupPos) override;
virtual void right_click_popup_gui(Vector2f popupPos) override;
virtual void tool_update() override;
virtual void draw(SkCanvas* canvas, const DrawData& drawData) override;
virtual void switch_tool(DrawingProgramToolType newTool) override;

View file

@ -36,6 +36,11 @@
#include <EmscriptenHelpers/emscripten_browser_file.h>
#endif
#include "../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
#include "../../GUIStuff/ElementHelpers/CheckBoxHelpers.hpp"
#include "../../GUIStuff/ElementHelpers/TextBoxHelpers.hpp"
#include "../../GUIStuff/Elements/DropDown.hpp"
#define SECTION_SIZE 4000
#define AA_LEVEL 4
@ -48,26 +53,29 @@ DrawingProgramToolType ScreenshotTool::get_type() {
}
void ScreenshotTool::gui_toolbox() {
using namespace GUIStuff;
using namespace ElementHelpers;
Toolbar& t = drawP.world.main.toolbar;
auto& screenshotConfig = drawP.world.main.toolConfig.screenshot;
t.gui.push_id("screenshot tool");
t.gui.text_label_centered("Screenshot");
text_label_centered(t.gui, "Screenshot");
auto oldImgSize = controls.imageSize;
if(controls.selectionMode == ScreenshotControls::SelectionMode::NO_SELECTION)
t.gui.text_label("Select an area on the canvas...");
text_label(t.gui, "Select an area on the canvas...");
if(controls.selectionMode != ScreenshotControls::SelectionMode::NO_SELECTION && screenshotConfig.selectedType != SCREENSHOT_SVG)
t.gui.input_scalar_fields("Image Size", "Image Size", &controls.imageSize, 2, 0, 999999999);
input_scalars_field(t.gui, "Image Size", "Image Size", &controls.imageSize, 2, 0, 999999999);
if(controls.selectionMode == ScreenshotControls::SelectionMode::SELECTION_EXISTS) {
t.gui.left_to_right_line_layout([&]() {
t.gui.text_label("Image Type");
t.gui.dropdown_select("image type select", (size_t*)(&screenshotConfig.selectedType), controls.typeSelections);
left_to_right_line_layout(t.gui, [&]() {
text_label(t.gui, "Image Type");
t.gui.element<DropDown<size_t>>("image type select", (size_t*)(&screenshotConfig.selectedType), controls.typeSelections);
});
if(screenshotConfig.selectedType != SCREENSHOT_SVG)
t.gui.checkbox_field("Display Grid", "Display Grid", &controls.displayGrid);
checkbox_boolean_field(t.gui, "Display Grid", "Display Grid", &controls.displayGrid);
else
t.gui.text_label("Note: Screenshot will ignore blend\nmodes and layer alpha");
text_label(t.gui, "Note: Screenshot will ignore blend\nmodes and layer alpha");
if(screenshotConfig.selectedType != 0)
t.gui.checkbox_field("Transparent Background", "Transparent Background", &controls.transparentBackground);
checkbox_boolean_field(t.gui, "Transparent Background", "Transparent Background", &controls.transparentBackground);
if(controls.imageSize.x() != oldImgSize.x()) {
screenshotConfig.setDimensionSize = controls.imageSize.x();
screenshotConfig.setDimensionIsX = true;
@ -78,46 +86,48 @@ void ScreenshotTool::gui_toolbox() {
screenshotConfig.setDimensionIsX = false;
controls.imageSize.x() = controls.imageSize.y() * (controls.rectX2 - controls.rectX1) / (controls.rectY2 - controls.rectY1);
}
if(t.gui.text_button_wide("Take Screenshot", "Take Screenshot")) {
controls.selectionMode = ScreenshotControls::SelectionMode::NO_SELECTION;
#ifdef __EMSCRIPTEN__
take_screenshot("a" + controls.typeSelections[screenshotConfig.selectedType], screenshotConfig.selectedType);
#else
// We can't actually use the extension from the callback, so we have to set the extension of choice beforehand
Toolbar::ExtensionFilter setExtensionFilter;
switch(screenshotConfig.selectedType) {
case SCREENSHOT_JPG:
setExtensionFilter = {"JPEG", "jpg;jpeg"};
break;
case SCREENSHOT_PNG:
setExtensionFilter = {"PNG", "png"};
break;
case SCREENSHOT_WEBP:
setExtensionFilter = {"WEBP", "webp"};
break;
case SCREENSHOT_SVG:
setExtensionFilter = {"SVG", "svg"};
break;
}
t.open_file_selector("Export", {setExtensionFilter}, [setExtensionFilter, w = make_weak_ptr(drawP.world.main.world)](const std::filesystem::path& p, const auto& e) {
auto world = w.lock();
if(world && world->drawProg.drawTool->get_type() == DrawingProgramToolType::SCREENSHOT) {
ScreenshotTool* screenshotTool = static_cast<ScreenshotTool*>(world->drawProg.drawTool.get());
screenshotTool->controls.screenshotSavePath = p;
screenshotTool->controls.screenshotSaveType = world->main.toolConfig.screenshot.selectedType;
screenshotTool->controls.setToTakeScreenshot = true;
text_button(t.gui, "Take Screenshot", "Take Screenshot", {
.wide = true,
.onClick = [&] {
controls.selectionMode = ScreenshotControls::SelectionMode::NO_SELECTION;
#ifdef __EMSCRIPTEN__
take_screenshot("a" + controls.typeSelections[screenshotConfig.selectedType], screenshotConfig.selectedType);
#else
// We can't actually use the extension from the callback, so we have to set the extension of choice beforehand
Toolbar::ExtensionFilter setExtensionFilter;
switch(screenshotConfig.selectedType) {
case SCREENSHOT_JPG:
setExtensionFilter = {"JPEG", "jpg;jpeg"};
break;
case SCREENSHOT_PNG:
setExtensionFilter = {"PNG", "png"};
break;
case SCREENSHOT_WEBP:
setExtensionFilter = {"WEBP", "webp"};
break;
case SCREENSHOT_SVG:
setExtensionFilter = {"SVG", "svg"};
break;
}
}, "screenshot", true);
#endif
}
t.open_file_selector("Export", {setExtensionFilter}, [setExtensionFilter, w = make_weak_ptr(drawP.world.main.world)](const std::filesystem::path& p, const auto& e) {
auto world = w.lock();
if(world && world->drawProg.drawTool->get_type() == DrawingProgramToolType::SCREENSHOT) {
ScreenshotTool* screenshotTool = static_cast<ScreenshotTool*>(world->drawProg.drawTool.get());
screenshotTool->controls.screenshotSavePath = p;
screenshotTool->controls.screenshotSaveType = world->main.toolConfig.screenshot.selectedType;
screenshotTool->controls.setToTakeScreenshot = true;
}
}, "screenshot", true);
#endif
}
});
}
t.gui.pop_id();
}
bool ScreenshotTool::right_click_popup_gui(Vector2f popupPos) {
void ScreenshotTool::right_click_popup_gui(Vector2f popupPos) {
Toolbar& t = drawP.world.main.toolbar;
t.paint_popup(popupPos);
return true;
}
void ScreenshotTool::input_mouse_button_on_canvas_callback(const InputManager::MouseButtonCallbackArgs& button) {

View file

@ -12,7 +12,7 @@ class ScreenshotTool : public DrawingProgramToolBase {
ScreenshotTool(DrawingProgram& initDrawP);
virtual DrawingProgramToolType get_type() override;
virtual void gui_toolbox() override;
virtual bool right_click_popup_gui(Vector2f popupPos) override;
virtual void right_click_popup_gui(Vector2f popupPos) override;
virtual void erase_component(CanvasComponentContainer::ObjInfo* erasedComp) override;
virtual void tool_update() override;
virtual void draw(SkCanvas* canvas, const DrawData& drawData) override;

View file

@ -11,6 +11,8 @@
#include "../../CanvasComponents/CanvasComponentContainer.hpp"
#include "EditTool.hpp"
#include "../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
TextBoxTool::TextBoxTool(DrawingProgram& initDrawP):
DrawingProgramToolBase(initDrawP)
{}
@ -22,7 +24,7 @@ DrawingProgramToolType TextBoxTool::get_type() {
void TextBoxTool::gui_toolbox() {
Toolbar& t = drawP.world.main.toolbar;
t.gui.push_id("textbox tool");
t.gui.text_label_centered("Textbox");
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Zoom tool");
t.gui.pop_id();
}
@ -74,10 +76,9 @@ void TextBoxTool::erase_component(CanvasComponentContainer::ObjInfo* erasedComp)
objInfoBeingEdited = nullptr;
}
bool TextBoxTool::right_click_popup_gui(Vector2f popupPos) {
void TextBoxTool::right_click_popup_gui(Vector2f popupPos) {
Toolbar& t = drawP.world.main.toolbar;
t.paint_popup(popupPos);
return true;
}
void TextBoxTool::switch_tool(DrawingProgramToolType newTool) {

View file

@ -10,7 +10,7 @@ class TextBoxTool : public DrawingProgramToolBase {
TextBoxTool(DrawingProgram& initDrawP);
virtual DrawingProgramToolType get_type() override;
virtual void gui_toolbox() override;
virtual bool right_click_popup_gui(Vector2f popupPos) override;
virtual void right_click_popup_gui(Vector2f popupPos) override;
virtual void erase_component(CanvasComponentContainer::ObjInfo* erasedComp) override;
virtual void tool_update() override;
virtual void draw(SkCanvas* canvas, const DrawData& drawData) override;

View file

@ -5,6 +5,8 @@
#include "DrawingProgramToolBase.hpp"
#include <Helpers/Logger.hpp>
#include "../../GUIStuff/ElementHelpers/TextLabelHelpers.hpp"
ZoomCanvasTool::ZoomCanvasTool(DrawingProgram& initDrawP):
DrawingProgramToolBase(initDrawP)
{
@ -17,12 +19,12 @@ DrawingProgramToolType ZoomCanvasTool::get_type() {
void ZoomCanvasTool::gui_toolbox() {
Toolbar& t = drawP.world.main.toolbar;
t.gui.push_id("Zoom canvas tool");
t.gui.text_label_centered("Zoom tool");
GUIStuff::ElementHelpers::text_label_centered(t.gui, "Zoom tool");
t.gui.pop_id();
}
bool ZoomCanvasTool::right_click_popup_gui(Vector2f popupPos) {
return drawP.selection_action_menu(popupPos);
void ZoomCanvasTool::right_click_popup_gui(Vector2f popupPos) {
drawP.selection_action_menu(popupPos);
}
void ZoomCanvasTool::erase_component(CanvasComponentContainer::ObjInfo* erasedComp) {

View file

@ -8,7 +8,7 @@ class ZoomCanvasTool : public DrawingProgramToolBase {
ZoomCanvasTool(DrawingProgram& initDrawP);
virtual DrawingProgramToolType get_type() override;
virtual void gui_toolbox() override;
virtual bool right_click_popup_gui(Vector2f popupPos) override;
virtual void right_click_popup_gui(Vector2f popupPos) override;
virtual void erase_component(CanvasComponentContainer::ObjInfo* erasedComp) override;
virtual void tool_update() override;
virtual void draw(SkCanvas* canvas, const DrawData& drawData) override;