From ea353973265c941cff21b818d6e2d8af755bf37b Mon Sep 17 00:00:00 2001 From: Yousef Khadadeh Date: Tue, 31 Mar 2026 13:17:58 +0300 Subject: [PATCH] Separate general GUI managing code and global configuration from toolbar UI code --- CMakeLists.txt | 2 + src/CanvasComponents/ImageCanvasComponent.cpp | 2 +- src/CanvasTheme.cpp | 6 +- src/ClientData.cpp | 4 +- src/DrawCamera.cpp | 12 +- src/DrawingProgram/DrawingProgram.cpp | 51 +- .../DrawingProgramSelection.cpp | 15 +- src/DrawingProgram/ToolConfiguration.cpp | 2 +- src/DrawingProgram/Tools/BrushTool.cpp | 12 +- src/DrawingProgram/Tools/EditTool.cpp | 6 +- .../Tools/EditTools/BrushEditTool.cpp | 11 +- .../Tools/EditTools/EllipseDrawEditTool.cpp | 21 +- .../Tools/EditTools/ImageEditTool.cpp | 11 +- .../Tools/EditTools/RectDrawEditTool.cpp | 23 +- .../Tools/EditTools/TextBoxEditTool.cpp | 56 +- src/DrawingProgram/Tools/EllipseDrawTool.cpp | 7 +- src/DrawingProgram/Tools/EraserTool.cpp | 9 +- src/DrawingProgram/Tools/EyeDropperTool.cpp | 7 +- src/DrawingProgram/Tools/GridModifyTool.cpp | 32 +- src/DrawingProgram/Tools/LassoSelectTool.cpp | 5 +- src/DrawingProgram/Tools/LineDrawTool.cpp | 7 +- src/DrawingProgram/Tools/PanCanvasTool.cpp | 5 +- src/DrawingProgram/Tools/RectDrawTool.cpp | 9 +- src/DrawingProgram/Tools/RectSelectTool.cpp | 5 +- src/DrawingProgram/Tools/ScreenshotTool.cpp | 23 +- src/DrawingProgram/Tools/TextBoxTool.cpp | 5 +- src/DrawingProgram/Tools/ZoomCanvasTool.cpp | 5 +- src/GUIHolder.cpp | 106 +++ src/GUIHolder.hpp | 24 + src/GUIStuff/ElementHelpers/LayoutHelpers.cpp | 12 +- .../ElementHelpers/TextLabelHelpers.cpp | 12 +- src/GUIStuff/Elements/DropDown.hpp | 14 +- src/GUIStuff/Elements/GUIStuffHelpers.hpp | 3 +- .../Elements/PositionAdjustingPopupMenu.cpp | 10 +- src/GUIStuff/Elements/SVGIcon.cpp | 2 +- src/GUIStuff/Elements/ScrollArea.cpp | 18 +- src/GUIStuff/Elements/SelectableButton.cpp | 2 +- src/GUIStuff/Elements/TextBox.impl.hpp | 18 +- src/GUIStuff/GUIManager.cpp | 25 +- src/GUIStuff/GUIManager.hpp | 2 +- src/GlobalConfig.cpp | 130 ++++ src/GlobalConfig.hpp | 63 ++ src/InputManager.cpp | 12 +- src/InputManager.hpp | 4 +- src/MainProgram.cpp | 30 +- src/MainProgram.hpp | 26 +- src/ResourceDisplay/FileResourceDisplay.cpp | 6 +- src/Toolbar.cpp | 720 ++++++------------ src/Toolbar.hpp | 37 - src/World.cpp | 4 +- src/World.hpp | 2 - src/WorldGrid.cpp | 10 +- src/main.cpp | 2 +- 53 files changed, 859 insertions(+), 788 deletions(-) create mode 100644 src/GUIHolder.cpp create mode 100644 src/GUIHolder.hpp create mode 100644 src/GlobalConfig.cpp create mode 100644 src/GlobalConfig.hpp diff --git a/CMakeLists.txt b/CMakeLists.txt index 88f1764..5f9ecf1 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -50,6 +50,8 @@ set(sources "src/main.cpp" "src/VersionConstants.cpp" "src/ScaleUpCanvas.cpp" "src/WorldUndoManager.cpp" + "src/GUIHolder.cpp" + "src/GlobalConfig.cpp" "src/Bookmarks/BookmarkListItem.cpp" "src/Bookmarks/BookmarkManager.cpp" "src/ResourceDisplay/ResourceDisplay.cpp" diff --git a/src/CanvasComponents/ImageCanvasComponent.cpp b/src/CanvasComponents/ImageCanvasComponent.cpp index aafd620..cfb5564 100644 --- a/src/CanvasComponents/ImageCanvasComponent.cpp +++ b/src/CanvasComponents/ImageCanvasComponent.cpp @@ -64,7 +64,7 @@ void ImageCanvasComponent::draw_download_progress_bar(SkCanvas* canvas, const Dr p.setStroke(true); p.setStrokeWidth(10.0f); p.setStrokeCap(SkPaint::kRound_Cap); - p.setColor4f(drawData.main->toolbar.io->theme->fillColor1); + p.setColor4f(drawData.main->g.gui.io.theme->fillColor1); p.setAntiAlias(drawData.skiaAA); Vector2f center = (d.p1 + d.p2) * 0.5f; diff --git a/src/CanvasTheme.cpp b/src/CanvasTheme.cpp index 6fd0443..52874cf 100644 --- a/src/CanvasTheme.cpp +++ b/src/CanvasTheme.cpp @@ -38,13 +38,13 @@ CanvasTheme::CanvasTheme(World& w): {} void CanvasTheme::server_init_no_file() { - backColor = world.netObjMan.make_obj_direct(world.main.defaultCanvasBackgroundColor); + backColor = world.netObjMan.make_obj_direct(world.main.conf.defaultCanvasBackgroundColor); set_tool_front_color(world.drawProg); } SkColor4f CanvasTheme::get_back_color() const { if(!backColor) - return SkColor4f{world.main.defaultCanvasBackgroundColor.x(), world.main.defaultCanvasBackgroundColor.y(), world.main.defaultCanvasBackgroundColor.z(), 1.0f}; + return SkColor4f{world.main.conf.defaultCanvasBackgroundColor.x(), world.main.conf.defaultCanvasBackgroundColor.y(), world.main.conf.defaultCanvasBackgroundColor.z(), 1.0f}; else return SkColor4f{backColor->c.x(), backColor->c.y(), backColor->c.z(), 1.0f}; } @@ -91,7 +91,7 @@ void CanvasTheme::save_file(cereal::PortableBinaryOutputArchive& a) const { } void CanvasTheme::load_file(cereal::PortableBinaryInputArchive& a, VersionNumber version) { - backColor = world.netObjMan.make_obj_direct(world.main.defaultCanvasBackgroundColor); + backColor = world.netObjMan.make_obj_direct(world.main.conf.defaultCanvasBackgroundColor); set_tool_front_color(world.drawProg); if(version < VersionNumber(0, 1, 0)) diff --git a/src/ClientData.cpp b/src/ClientData.cpp index 6de8e48..ba02aa2 100644 --- a/src/ClientData.cpp +++ b/src/ClientData.cpp @@ -199,7 +199,7 @@ void ClientData::draw_cursor(SkCanvas* canvas, const DrawData& drawData) const { p.setColor4f({cursorColor.x(), cursorColor.y(), cursorColor.z(), 0.7f}); canvas->drawCircle(0.0f, 0.0f, 5.0f, p); - SkFont f = drawData.main->toolbar.io->get_font(18.0f); + SkFont f = drawData.main->g.gui.io.get_font(18.0f); SkFontMetrics metrics; f.getMetrics(&metrics); @@ -209,7 +209,7 @@ void ClientData::draw_cursor(SkCanvas* canvas, const DrawData& drawData) const { SkPaint p2(SkColor4f{cursorColor.x(), cursorColor.y(), cursorColor.z(), 0.5f}); canvas->drawSimpleText(displayName.c_str(), displayName.length(), SkTextEncoding::kUTF8, 6.0f, -metrics.fDescent, f, p2); - SkPaint p3(color_mul_alpha(drawData.main->toolbar.io->theme->backColor1, 0.5f)); + SkPaint p3(color_mul_alpha(drawData.main->g.gui.io.theme->backColor1, 0.5f)); canvas->drawRoundRect(SkRect::MakeXYWH(6.0f, -bounds.y(), bounds.x(), bounds.y()), 3.0f, 3.0f, p3); canvas->restore(); diff --git a/src/DrawCamera.cpp b/src/DrawCamera.cpp index b10c2aa..bb50dbf 100755 --- a/src/DrawCamera.cpp +++ b/src/DrawCamera.cpp @@ -49,7 +49,7 @@ void DrawCamera::smooth_move_to(World& w, const CoordSpaceHelper& newCoords, Vec smoothMove.endUniformZoom = std::max(smoothMove.end.inverseScale.multiply_double((a1 < a2) ? a1 : a2), WorldScalar(1)); smoothMove.occurring = true; - smoothMove.moveTime = (instantJump || w.main.toolbar.jumpTransitionTime <= 0.01f) ? w.main.toolbar.jumpTransitionTime : 0.0f; + smoothMove.moveTime = (instantJump || w.main.conf.jumpTransitionTime <= 0.01f) ? w.main.conf.jumpTransitionTime : 0.0f; } void DrawCamera::scale_up(World& w, const WorldScalar& scaleUpAmount) { @@ -64,8 +64,8 @@ void DrawCamera::scale_up(World& w, const WorldScalar& scaleUpAmount) { void DrawCamera::update_main(World& w) { if(smoothMove.occurring) { - BezierEasing zoomAnim{w.main.toolbar.jumpTransitionEasing}; - float smoothTime = smooth_two_way_time(smoothMove.moveTime, w.main.deltaTime, true, w.main.toolbar.jumpTransitionTime); + BezierEasing zoomAnim{w.main.conf.jumpTransitionEasing}; + float smoothTime = smooth_two_way_time(smoothMove.moveTime, w.main.deltaTime, true, w.main.conf.jumpTransitionTime); float lerpTime; float rotationLerpTime = zoomAnim(smoothTime); lerpTime = zoomAnim(smoothTime); @@ -142,7 +142,7 @@ void DrawCamera::input_key_callback(const InputManager::KeyCallbackArgs& key) { void DrawCamera::input_mouse_button_on_canvas_callback(World& w, const InputManager::MouseButtonCallbackArgs& button) { if(!smoothMove.occurring && !isTouchTransforming) { - bool newIsAccurateZooming = (w.drawProg.controls.middleClickHeld && w.main.input.pen.isDown && w.main.toolbar.tabletOptions.zoomWhilePenDownAndButtonHeld) || // Hold middle click (pen button assigned to middle click) while pen is down + bool newIsAccurateZooming = (w.drawProg.controls.middleClickHeld && w.main.input.pen.isDown && w.main.conf.tabletOptions.zoomWhilePenDownAndButtonHeld) || // Hold middle click (pen button assigned to middle click) while pen is down (w.drawProg.controls.middleClickHeld && w.main.input.key(InputManager::KEY_GENERIC_LCTRL).held) || // Hold middle click/pen button while holding control (w.drawProg.controls.leftClickHeld && w.drawProg.drawTool->get_type() == DrawingProgramToolType::ZOOM); // Hold left click while on zoom tool if(newIsAccurateZooming && !isAccurateZooming) { @@ -159,7 +159,7 @@ void DrawCamera::input_mouse_button_on_canvas_callback(World& w, const InputMana void DrawCamera::input_mouse_motion_callback(World& w, const InputManager::MouseMotionCallbackArgs& motion) { if(!smoothMove.occurring && !isTouchTransforming) { if(isAccurateZooming && startZoomVal != WorldScalar(0)) { - WorldScalar zoomFactor(std::pow(1.0 + w.main.toolbar.dragZoomSpeed, w.main.toolbar.flipZoomToolDirection ? motion.move.y() : -motion.move.y())); + WorldScalar zoomFactor(std::pow(1.0 + w.main.conf.dragZoomSpeed, w.main.conf.flipZoomToolDirection ? motion.move.y() : -motion.move.y())); if(zoomFactor < WorldScalar(0.000001)) zoomFactor = WorldScalar(0.000001); @@ -180,7 +180,7 @@ void DrawCamera::input_mouse_motion_callback(World& w, const InputManager::Mouse void DrawCamera::input_mouse_wheel_callback(World& w, const InputManager::MouseWheelCallbackArgs& wheel) { if(!smoothMove.occurring && !isTouchTransforming && wheel.tickAmount.y()) { WorldVec mouseWorldPos = c.from_space(wheel.mousePos); - WorldScalar zoomFactor(1.0 + w.main.toolbar.scrollZoomSpeed); + WorldScalar zoomFactor(1.0 + w.main.conf.scrollZoomSpeed); if(zoomFactor < WorldScalar(0.000001)) zoomFactor = WorldScalar(0.000001); diff --git a/src/DrawingProgram/DrawingProgram.cpp b/src/DrawingProgram/DrawingProgram.cpp index 6e70be4..e41b264 100644 --- a/src/DrawingProgram/DrawingProgram.cpp +++ b/src/DrawingProgram/DrawingProgram.cpp @@ -328,23 +328,25 @@ void DrawingProgram::toolbar_gui() { using namespace GUIStuff; using namespace ElementHelpers; - Toolbar& t = world.main.toolbar; - t.gui.new_id("Drawing Program Toolbar GUI", [&] { - t.gui.element("Drawing Program Toolbar GUI", [&] { + GUIManager& gui = world.main.g.gui; + auto& io = gui.io; + + gui.new_id("Drawing Program Toolbar GUI", [&] { + gui.element("Drawing Program Toolbar GUI", [&] { CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0)}, - .padding = CLAY_PADDING_ALL(static_cast(t.io->theme->padding1 / 2)), - .childGap = static_cast(t.io->theme->childGap1 / 2), + .padding = CLAY_PADDING_ALL(static_cast(io.theme->padding1 / 2)), + .childGap = static_cast(io.theme->childGap1 / 2), .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, - .backgroundColor = convert_vec4(t.io->theme->backColor1), - .cornerRadius = CLAY_CORNER_RADIUS(t.io->theme->windowCorners1) + .backgroundColor = convert_vec4(io.theme->backColor1), + .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1) }) { auto tool_button = [&](const char* id, const std::string& svgPath, DrawingProgramToolType toolType) { - svg_icon_button(t.gui, id, svgPath, { + svg_icon_button(gui, id, svgPath, { .drawType = SelectableButton::DrawType::TRANSPARENT_ALL, .isSelected = drawTool->get_type() == toolType, .onClick = [&, toolType] { @@ -367,7 +369,7 @@ void DrawingProgram::toolbar_gui() { tool_button("Pan Canvas Toolbar Button", "data/icons/hand.svg", DrawingProgramToolType::PAN); std::shared_ptr oldRotationAngle = std::make_shared(world.drawData.cam.c.rotation); - t.gui.element("Canvas Rotate Wheel", &world.drawData.cam.c.rotation, [&, oldRotationAngle] { + gui.element("Canvas Rotate Wheel", &world.drawData.cam.c.rotation, [&, oldRotationAngle] { world.drawData.cam.c.rotate_about(world.drawData.cam.c.from_space(world.main.window.size.cast() * 0.5f), world.drawData.cam.c.rotation - *oldRotationAngle); *oldRotationAngle = world.drawData.cam.c.rotation; }); @@ -377,7 +379,9 @@ void DrawingProgram::toolbar_gui() { } void DrawingProgram::popup_menu_action_button(const char* id, const char* text, const std::function& onClick) { - GUIStuff::ElementHelpers::text_button(world.main.toolbar.gui, id, text, { + GUIStuff::GUIManager& gui = world.main.g.gui; + + GUIStuff::ElementHelpers::text_button(gui, id, text, { .drawType = GUIStuff::SelectableButton::DrawType::TRANSPARENT_ALL, .wide = true, .onClick = onClick @@ -390,8 +394,11 @@ void DrawingProgram::selection_action_menu(Vector2f popupPos) { using namespace ElementHelpers; Toolbar& t = world.main.toolbar; - t.gui.element("Selection popup menu", popupPos, [&, popupPos] { - text_label_light(t.gui, "Selection menu"); + GUIStuff::GUIManager& gui = world.main.g.gui; + auto& io = gui.io; + + gui.element("Selection popup menu", popupPos, [&, popupPos] { + text_label_light(gui, "Selection menu"); popup_menu_action_button("Paste", "Paste", [&] { selection.deselect_all(); selection.paste_clipboard(popupPos * t.final_gui_scale()); @@ -423,7 +430,10 @@ void DrawingProgram::selection_action_menu(Vector2f popupPos) { void DrawingProgram::right_click_popup_gui(Vector2f popupPos) { Toolbar& t = world.main.toolbar; - t.gui.new_id("Drawing Program right click GUI", [&] { + GUIStuff::GUIManager& gui = world.main.g.gui; + auto& io = gui.io; + + gui.new_id("Drawing Program right click GUI", [&] { drawTool->right_click_popup_gui(popupPos); }); } @@ -432,18 +442,21 @@ void DrawingProgram::tool_options_gui() { using namespace GUIStuff; Toolbar& t = world.main.toolbar; + GUIStuff::GUIManager& gui = world.main.g.gui; + auto& io = gui.io; + float minGUIWidth = drawTool->get_type() == DrawingProgramToolType::SCREENSHOT ? 300 : 200; - t.gui.element("Drawing program tool options gui", [&] { + gui.element("Drawing program tool options gui", [&] { CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(minGUIWidth), .height = CLAY_SIZING_FIT(0)}, - .padding = CLAY_PADDING_ALL(t.io->theme->padding1), - .childGap = t.io->theme->childGap1, + .padding = CLAY_PADDING_ALL(io.theme->padding1), + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, - .backgroundColor = convert_vec4(t.io->theme->backColor1), - .cornerRadius = CLAY_CORNER_RADIUS(t.io->theme->windowCorners1) + .backgroundColor = convert_vec4(io.theme->backColor1), + .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1) }) { drawTool->gui_toolbox(); } @@ -514,7 +527,7 @@ void DrawingProgram::switch_to_tool_ptr(std::unique_ptr drawTool->switch_tool(newTool->get_type()); drawTool = std::move(newTool); world.main.toolbar.rightClickPopupLocation = std::nullopt; - world.main.toolbar.gui.set_to_layout(); + world.main.g.gui.set_to_layout(); } void DrawingProgram::switch_to_tool(DrawingProgramToolType newToolType, bool force) { diff --git a/src/DrawingProgram/DrawingProgramSelection.cpp b/src/DrawingProgram/DrawingProgramSelection.cpp index 5d07891..03b8dd1 100644 --- a/src/DrawingProgram/DrawingProgramSelection.cpp +++ b/src/DrawingProgram/DrawingProgramSelection.cpp @@ -35,21 +35,22 @@ void DrawingProgramSelection::selection_gui() { using namespace GUIStuff; using namespace ElementHelpers; - auto& t = drawP.world.main.toolbar; - t.gui.new_id("general selection gui", [&] { - text_label(t.gui, "Select from:"); - radio_button_selector(t.gui, "layer selector", &drawP.controls.layerSelector, { + auto& gui = drawP.world.main.g.gui; + + gui.new_id("general selection gui", [&] { + text_label(gui, "Select from:"); + radio_button_selector(gui, "layer selector", &drawP.controls.layerSelector, { {"Layer being edited", DrawingProgramLayerManager::LayerSelector::LAYER_BEING_EDITED}, {"All visible layers", DrawingProgramLayerManager::LayerSelector::ALL_VISIBLE_LAYERS} }); if(is_something_selected()) { - left_to_right_line_layout(t.gui, [&]() { - //if(t.gui.color_button_big("Stroke Color Button", &strokeColorChangeData.newColor, &strokeColorChangeData.newColor == t.colorRight)) { + left_to_right_line_layout(gui, [&]() { + //if(gui.color_button_big("Stroke Color Button", &strokeColorChangeData.newColor, &strokeColorChangeData.newColor == t.colorRight)) { // if(strokeColorChangeData.newColor.w() == 0.0f) // strokeColorChangeData.newColor.w() = 1.0f; // t.color_selector_right(&strokeColorChangeData.newColor == t.colorRight ? nullptr : &strokeColorChangeData.newColor); //} - text_label(t.gui, "Stroke Color"); + text_label(gui, "Stroke Color"); }); update_selection_stroke_color(); } diff --git a/src/DrawingProgram/ToolConfiguration.cpp b/src/DrawingProgram/ToolConfiguration.cpp index a104365..0571c46 100644 --- a/src/DrawingProgram/ToolConfiguration.cpp +++ b/src/DrawingProgram/ToolConfiguration.cpp @@ -81,7 +81,7 @@ void ToolConfiguration::print_relative_width_fail_message(RelativeWidthFailCode } void ToolConfiguration::relative_width_gui(DrawingProgram& drawP, const char* label) { - auto& gui = drawP.world.main.toolbar.gui; + auto& gui = drawP.world.main.g.gui; auto& lockedCameraScale = drawP.controls.lockedCameraScale; GUIStuff::ElementHelpers::slider_scalar_field(gui, "relstrokewidth", label, &get_stroke_size_relative_width_ref(drawP.drawTool->get_type()), 3.0f, 40.0f); GUIStuff::ElementHelpers::text_button(gui, "lock brush size", lockedCameraScale.has_value() ? "Unlock Size" : "Lock Size to Zoom", { diff --git a/src/DrawingProgram/Tools/BrushTool.cpp b/src/DrawingProgram/Tools/BrushTool.cpp index 782e0a3..ce61ab4 100644 --- a/src/DrawingProgram/Tools/BrushTool.cpp +++ b/src/DrawingProgram/Tools/BrushTool.cpp @@ -41,7 +41,7 @@ void BrushTool::input_mouse_button_on_canvas_callback(const InputManager::MouseB if(drawP.world.main.input.pen.isDown) { penWidth = drawP.world.main.input.pen.pressure; if(penWidth != 0.0f) { - float brushMinSize = drawP.world.main.toolbar.tabletOptions.brushMinimumSize; + float brushMinSize = drawP.world.main.conf.tabletOptions.brushMinimumSize; penWidth = brushMinSize + penWidth * (1.0f - brushMinSize); } } @@ -124,7 +124,7 @@ void BrushTool::input_pen_axis_callback(const InputManager::PenAxisCallbackArgs& if(axis.axis == SDL_PEN_AXIS_PRESSURE) { penWidth = axis.value; if(penWidth != 0.0f) { - float brushMinSize = drawP.world.main.toolbar.tabletOptions.brushMinimumSize; + float brushMinSize = drawP.world.main.conf.tabletOptions.brushMinimumSize; penWidth = brushMinSize + penWidth * (1.0f - brushMinSize); } } @@ -172,9 +172,11 @@ void BrushTool::gui_toolbox() { using namespace ElementHelpers; Toolbar& t = drawP.world.main.toolbar; - t.gui.new_id("brush tool", [&] { - text_label_centered(t.gui, "Brush"); - checkbox_boolean_field(t.gui, "hasroundcaps", "Round Caps", &drawP.world.main.toolConfig.brush.hasRoundCaps); + auto& gui = drawP.world.main.g.gui; + + gui.new_id("brush tool", [&] { + text_label_centered(gui, "Brush"); + checkbox_boolean_field(gui, "hasroundcaps", "Round Caps", &drawP.world.main.toolConfig.brush.hasRoundCaps); drawP.world.main.toolConfig.relative_width_gui(drawP, "Size"); }); } diff --git a/src/DrawingProgram/Tools/EditTool.cpp b/src/DrawingProgram/Tools/EditTool.cpp index 79ecf20..5a437c1 100644 --- a/src/DrawingProgram/Tools/EditTool.cpp +++ b/src/DrawingProgram/Tools/EditTool.cpp @@ -30,11 +30,13 @@ void EditTool::gui_toolbox() { using namespace ElementHelpers; Toolbar& t = drawP.world.main.toolbar; + auto& gui = drawP.world.main.g.gui; + if(objInfoBeingEdited) compEditTool->edit_gui(objInfoBeingEdited); else { - t.gui.new_id("edit tool", [&] { - text_label_centered(t.gui, "Edit"); + gui.new_id("edit tool", [&] { + text_label_centered(gui, "Edit"); }); } } diff --git a/src/DrawingProgram/Tools/EditTools/BrushEditTool.cpp b/src/DrawingProgram/Tools/EditTools/BrushEditTool.cpp index 1c50ce6..b2b17b4 100644 --- a/src/DrawingProgram/Tools/EditTools/BrushEditTool.cpp +++ b/src/DrawingProgram/Tools/EditTools/BrushEditTool.cpp @@ -16,12 +16,13 @@ void BrushEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) { using namespace ElementHelpers; Toolbar& t = drawP.world.main.toolbar; - t.gui.new_id("edit tool brush", [&] { - text_label_centered(t.gui, "Edit Brush Stroke"); - left_to_right_line_layout(t.gui, [&]() { - //if(t.gui.color_button_big("Outline Color", &a.d.color, &a.d.color == t.colorRight)) + auto& gui = drawP.world.main.g.gui; + gui.new_id("edit tool brush", [&] { + text_label_centered(gui, "Edit Brush Stroke"); + left_to_right_line_layout(gui, [&]() { + //if(gui.color_button_big("Outline Color", &a.d.color, &a.d.color == t.colorRight)) // t.color_selector_right(&a.d.color == t.colorRight ? nullptr : &a.d.color); - text_label(t.gui, "Outline Color"); + text_label(gui, "Outline Color"); }); }); } diff --git a/src/DrawingProgram/Tools/EditTools/EllipseDrawEditTool.cpp b/src/DrawingProgram/Tools/EditTools/EllipseDrawEditTool.cpp index e426fb6..8c312f7 100644 --- a/src/DrawingProgram/Tools/EditTools/EllipseDrawEditTool.cpp +++ b/src/DrawingProgram/Tools/EditTools/EllipseDrawEditTool.cpp @@ -21,28 +21,29 @@ void EllipseDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) { using namespace ElementHelpers; auto& a = static_cast(comp->obj->get_comp()); + auto& gui = drawP.world.main.g.gui; Toolbar& t = drawP.world.main.toolbar; - t.gui.new_id("edit tool ellipse", [&] { - text_label_centered(t.gui, "Edit Ellipse"); - radio_button_selector(t.gui, "Fill selector", &a.d.fillStrokeMode, { + gui.new_id("edit tool ellipse", [&] { + text_label_centered(gui, "Edit Ellipse"); + radio_button_selector(gui, "Fill selector", &a.d.fillStrokeMode, { {"Fill only", 0}, {"Outline only", 1}, {"Fill and outline", 2} }); if(a.d.fillStrokeMode == 0 || a.d.fillStrokeMode == 2) { - left_to_right_line_layout(t.gui, [&] { - //if(t.gui.color_button_big("Fill Color", &a.d.fillColor, &a.d.fillColor == t.colorRight)) + left_to_right_line_layout(gui, [&] { + //if(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); - text_label(t.gui, "Fill Color"); + text_label(gui, "Fill Color"); }); } if(a.d.fillStrokeMode == 1 || a.d.fillStrokeMode == 2) { - slider_scalar_field(t.gui, "relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f); - left_to_right_line_layout(t.gui, [&] { - //if(t.gui.color_button_big("Outline Color", &a.d.strokeColor, &a.d.strokeColor == t.colorRight)) + slider_scalar_field(gui, "relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f); + left_to_right_line_layout(gui, [&] { + //if(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); - text_label(t.gui, "Outline Color"); + text_label(gui, "Outline Color"); }); } }); diff --git a/src/DrawingProgram/Tools/EditTools/ImageEditTool.cpp b/src/DrawingProgram/Tools/EditTools/ImageEditTool.cpp index 42567a8..ac567b0 100644 --- a/src/DrawingProgram/Tools/EditTools/ImageEditTool.cpp +++ b/src/DrawingProgram/Tools/EditTools/ImageEditTool.cpp @@ -51,13 +51,14 @@ void ImageEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) { ImageCanvasComponent& a = static_cast(comp->obj->get_comp()); Toolbar& t = drawP.world.main.toolbar; - t.gui.new_id("edit tool image", [&] { - text_label_centered(t.gui, "File Properties"); + auto& gui = drawP.world.main.g.gui; + gui.new_id("edit tool image", [&] { + text_label_centered(gui, "File Properties"); auto resourceData = drawP.world.netObjMan.get_obj_temporary_ref_from_id(a.d.imageID); if(resourceData) { - text_label(t.gui, "Name: " + resourceData->name); - text_button(t.gui, "file download", "Download file", { + text_label(gui, "Name: " + resourceData->name); + text_button(gui, "file download", "Download file", { .wide = true, .onClick = [&] { #ifdef __EMSCRIPTEN__ @@ -74,6 +75,6 @@ void ImageEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) { }); } else - text_label_centered(t.gui, "Loading resource..."); + text_label_centered(gui, "Loading resource..."); }); } diff --git a/src/DrawingProgram/Tools/EditTools/RectDrawEditTool.cpp b/src/DrawingProgram/Tools/EditTools/RectDrawEditTool.cpp index 80db139..12d33ef 100644 --- a/src/DrawingProgram/Tools/EditTools/RectDrawEditTool.cpp +++ b/src/DrawingProgram/Tools/EditTools/RectDrawEditTool.cpp @@ -19,27 +19,28 @@ void RectDrawEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) { auto& a = static_cast(comp->obj->get_comp()); Toolbar& t = drawP.world.main.toolbar; - t.gui.new_id("edit tool rectangle", [&] { - text_label_centered(t.gui, "Edit Rectangle"); - slider_scalar_field(t.gui, "relradiuswidth", "Corner Radius", &a.d.cornerRadius, 0.0f, 40.0f); - radio_button_selector(t.gui, "Fill selector", &a.d.fillStrokeMode, { + auto& gui = drawP.world.main.g.gui; + gui.new_id("edit tool rectangle", [&] { + text_label_centered(gui, "Edit Rectangle"); + slider_scalar_field(gui, "relradiuswidth", "Corner Radius", &a.d.cornerRadius, 0.0f, 40.0f); + radio_button_selector(gui, "Fill selector", &a.d.fillStrokeMode, { {"Fill only", 0}, {"Outline only", 1}, {"Fill and outline", 2} }); if(a.d.fillStrokeMode == 0 || a.d.fillStrokeMode == 2) { - left_to_right_line_layout(t.gui, [&] { - //if(t.gui.color_button_big("Fill Color", &a.d.fillColor, &a.d.fillColor == t.colorRight)) + left_to_right_line_layout(gui, [&] { + //if(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); - text_label(t.gui, "Fill Color"); + text_label(gui, "Fill Color"); }); } if(a.d.fillStrokeMode == 1 || a.d.fillStrokeMode == 2) { - slider_scalar_field(t.gui, "relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f); - left_to_right_line_layout(t.gui, [&] { - //if(t.gui.color_button_big("Outline Color", &a.d.strokeColor, &a.d.strokeColor == t.colorRight)) + slider_scalar_field(gui, "relstrokewidth", "Outline Size", &a.d.strokeWidth, 3.0f, 40.0f); + left_to_right_line_layout(gui, [&] { + //if(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); - text_label(t.gui, "Outline Color"); + text_label(gui, "Outline Color"); }); } }); diff --git a/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.cpp b/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.cpp index 12eea55..6903c90 100644 --- a/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.cpp +++ b/src/DrawingProgram/Tools/EditTools/TextBoxEditTool.cpp @@ -30,43 +30,44 @@ void TextBoxEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) { auto& a = static_cast(comp->obj->get_comp()); Toolbar& t = drawP.world.main.toolbar; + auto& gui = drawP.world.main.g.gui; auto& currentMods = *currentModsPtr; - t.gui.new_id("edit tool text", [&] { - text_label_centered(t.gui, "Edit Text"); + gui.new_id("edit tool text", [&] { + text_label_centered(gui, "Edit Text"); - left_to_right_line_layout(t.gui, [&] { - text_label(t.gui, "Font"); - //if(t.gui.font_picker("font picker", &newFontName)) { + left_to_right_line_layout(gui, [&] { + text_label(gui, "Font"); + //if(gui.font_picker("font picker", &newFontName)) { // currentMods[TextStyleModifier::ModifierType::FONT_FAMILIES] = std::make_shared(std::vector{SkString{newFontName.c_str(), newFontName.size()}}); // add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::FONT_FAMILIES]);}); //} }); - //left_to_right_line_centered_layout(t.gui, [&] { + //left_to_right_line_centered_layout(gui, [&] { // if(svg_icon_button("Bold button", "data/icons/RemixIcon/bold.svg", newIsBold)) { // newIsBold = !newIsBold; // currentMods[TextStyleModifier::ModifierType::WEIGHT] = std::make_shared(newIsBold ? SkFontStyle::Weight::kBold_Weight : SkFontStyle::Weight::kNormal_Weight); // add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::WEIGHT]);}); // } - // if(t.gui.svg_icon_button("Italic button", "data/icons/RemixIcon/italic.svg", newIsItalic)) { + // if(gui.svg_icon_button("Italic button", "data/icons/RemixIcon/italic.svg", newIsItalic)) { // newIsItalic = !newIsItalic; // currentMods[TextStyleModifier::ModifierType::SLANT] = std::make_shared(newIsItalic ? SkFontStyle::Slant::kItalic_Slant : SkFontStyle::Slant::kUpright_Slant); // add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::SLANT]);}); // } // bool decorationEdited = false; - // if(t.gui.svg_icon_button("Underline button", "data/icons/RemixIcon/underline.svg", newIsUnderlined)) { + // if(gui.svg_icon_button("Underline button", "data/icons/RemixIcon/underline.svg", newIsUnderlined)) { // newIsUnderlined = !newIsUnderlined; // decorationEdited = true; // } - // if(t.gui.svg_icon_button("Strikethrough button", "data/icons/RemixIcon/strikethrough.svg", newIsLinethrough)) { + // if(gui.svg_icon_button("Strikethrough button", "data/icons/RemixIcon/strikethrough.svg", newIsLinethrough)) { // newIsLinethrough = !newIsLinethrough; // decorationEdited = true; // } - // if(t.gui.svg_icon_button("Overline button", "data/icons/RemixIcon/overline.svg", newIsOverline)) { + // if(gui.svg_icon_button("Overline button", "data/icons/RemixIcon/overline.svg", newIsOverline)) { // newIsOverline = !newIsOverline; // decorationEdited = true; // } @@ -76,22 +77,22 @@ void TextBoxEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) { // } //}); - //t.gui.left_to_right_line_centered_layout([&]() { - // if(t.gui.svg_icon_button("Align left button", "data/icons/RemixIcon/align-left.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kLeft)) + //gui.left_to_right_line_centered_layout([&]() { + // if(gui.svg_icon_button("Align left button", "data/icons/RemixIcon/align-left.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kLeft)) // add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kLeft);}); - // if(t.gui.svg_icon_button("Align center button", "data/icons/RemixIcon/align-center.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kCenter)) + // if(gui.svg_icon_button("Align center button", "data/icons/RemixIcon/align-center.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kCenter)) // add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kCenter);}); - // if(t.gui.svg_icon_button("Align right button", "data/icons/RemixIcon/align-right.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kRight)) + // if(gui.svg_icon_button("Align right button", "data/icons/RemixIcon/align-right.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kRight)) // add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kRight);}); - // if(t.gui.svg_icon_button("Align justify button", "data/icons/RemixIcon/align-justify.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kJustify)) + // if(gui.svg_icon_button("Align justify button", "data/icons/RemixIcon/align-justify.svg", currentPStyle.textAlignment == skia::textlayout::TextAlign::kJustify)) // add_undo([&](){a.textBox->set_text_alignment_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextAlign::kJustify);}); - // if(t.gui.svg_icon_button("Text direction left", "data/icons/RemixIcon/text-direction-l.svg", currentPStyle.textDirection == skia::textlayout::TextDirection::kLtr)) + // if(gui.svg_icon_button("Text direction left", "data/icons/RemixIcon/text-direction-l.svg", currentPStyle.textDirection == skia::textlayout::TextDirection::kLtr)) // add_undo([&](){a.textBox->set_text_direction_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextDirection::kLtr);}); - // if(t.gui.svg_icon_button("Text direction right", "data/icons/RemixIcon/text-direction-r.svg", currentPStyle.textDirection == skia::textlayout::TextDirection::kRtl)) + // if(gui.svg_icon_button("Text direction right", "data/icons/RemixIcon/text-direction-r.svg", currentPStyle.textDirection == skia::textlayout::TextDirection::kRtl)) // add_undo([&](){a.textBox->set_text_direction_between(a.cursor->selectionBeginPos.fParagraphIndex, a.cursor->selectionEndPos.fParagraphIndex, skia::textlayout::TextDirection::kRtl);}); //}); - //if(t.gui.slider_scalar_field("Font Size Slider", "Font Size", &newFontSize, 3, 100)) { + //if(gui.slider_scalar_field("Font Size Slider", "Font Size", &newFontSize, 3, 100)) { // hold_undo_data("Font Size", a); // currentMods[TextStyleModifier::ModifierType::SIZE] = std::make_shared(newFontSize); // a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::SIZE]); @@ -100,10 +101,10 @@ void TextBoxEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) { // release_undo_data("Font Size"); //// Text color - //t.gui.left_to_right_line_layout([&]() { - // if(t.gui.color_button_big("Text Color", &newTextColor, &newTextColor == t.colorRight)) + //gui.left_to_right_line_layout([&]() { + // if(gui.color_button_big("Text Color", &newTextColor, &newTextColor == t.colorRight)) // t.color_selector_right(&newTextColor == t.colorRight ? nullptr : &newTextColor); - // t.gui.text_label("Text Color"); + // gui.text_label("Text Color"); //}); //if(&newTextColor == t.colorRight) @@ -119,8 +120,8 @@ void TextBoxEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) { //// Highlight color - //t.gui.left_to_right_line_layout([&]() { - // if(t.gui.color_button_big("Highlight Color", &newHighlightColor, &newHighlightColor == t.colorRight)) { + //gui.left_to_right_line_layout([&]() { + // if(gui.color_button_big("Highlight Color", &newHighlightColor, &newHighlightColor == t.colorRight)) { // if(newHighlightColor.w() == 0.0f) { // Make highlight appear when the button is pressed // newHighlightColor.w() = 1.0f; // currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR] = std::make_shared(newHighlightColor); @@ -129,13 +130,13 @@ void TextBoxEditTool::edit_gui(CanvasComponentContainer::ObjInfo* comp) { // t.color_selector_right(&newHighlightColor == t.colorRight ? nullptr : &newHighlightColor); // } // if(newHighlightColor.w() != 0.0f) { - // if(t.gui.svg_icon_button("Remove Highlight Color", "data/icons/close.svg")) { + // if(gui.svg_icon_button("Remove Highlight Color", "data/icons/close.svg")) { // newHighlightColor = {0.0f, 0.0f, 0.0f, 0.0f}; // currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR] = std::make_shared(newHighlightColor); // add_undo_if_selecting_area(a, [&]() {a.textBox->set_text_style_modifier_between(a.cursor->selectionBeginPos, a.cursor->selectionEndPos, currentMods[TextStyleModifier::ModifierType::HIGHLIGHT_COLOR]);}); // } // } - // t.gui.text_label("Highlight Color"); + // gui.text_label("Highlight Color"); //}); //if(&newHighlightColor == t.colorRight) @@ -200,10 +201,11 @@ void TextBoxEditTool::right_click_popup_gui(CanvasComponentContainer::ObjInfo* c using namespace ElementHelpers; Toolbar& t = drawP.world.main.toolbar; + auto& gui = drawP.world.main.g.gui; auto& a = static_cast(comp->obj->get_comp()); - t.gui.element("Text popup menu", popupPos, [&, popupPos] { - text_label_light(t.gui, "Text menu"); + gui.element("Text popup menu", popupPos, [&, popupPos] { + text_label_light(gui, "Text menu"); InputManager& input = drawP.world.main.input; drawP.popup_menu_action_button("Paste", "Paste", [&] { input.call_text_paste(true); diff --git a/src/DrawingProgram/Tools/EllipseDrawTool.cpp b/src/DrawingProgram/Tools/EllipseDrawTool.cpp index 70740fd..ffb3918 100644 --- a/src/DrawingProgram/Tools/EllipseDrawTool.cpp +++ b/src/DrawingProgram/Tools/EllipseDrawTool.cpp @@ -25,11 +25,12 @@ void EllipseDrawTool::gui_toolbox() { using namespace ElementHelpers; Toolbar& t = drawP.world.main.toolbar; + auto& gui = drawP.world.main.g.gui; auto& toolConfig = drawP.world.main.toolConfig; auto& fillStrokeMode = toolConfig.ellipseDraw.fillStrokeMode; - t.gui.new_id("ellipse draw tool", [&] { - text_label_centered(t.gui, "Draw Ellipse"); - radio_button_selector(t.gui, "fill type", &fillStrokeMode, { + gui.new_id("ellipse draw tool", [&] { + text_label_centered(gui, "Draw Ellipse"); + radio_button_selector(gui, "fill type", &fillStrokeMode, { {"Fill only", 0}, {"Outline only", 1}, {"Fill and Outline", 2} diff --git a/src/DrawingProgram/Tools/EraserTool.cpp b/src/DrawingProgram/Tools/EraserTool.cpp index 74659dc..221daa0 100644 --- a/src/DrawingProgram/Tools/EraserTool.cpp +++ b/src/DrawingProgram/Tools/EraserTool.cpp @@ -21,11 +21,12 @@ void EraserTool::gui_toolbox() { using namespace ElementHelpers; Toolbar& t = drawP.world.main.toolbar; - t.gui.new_id("eraser tool", [&] { - text_label_centered(t.gui, "Eraser"); + auto& gui = drawP.world.main.g.gui; + gui.new_id("eraser tool", [&] { + text_label_centered(gui, "Eraser"); drawP.world.main.toolConfig.relative_width_gui(drawP, "Size"); - text_label(t.gui, "Erase from:"); - radio_button_selector(t.gui, "layer selector", &drawP.controls.layerSelector, { + text_label(gui, "Erase from:"); + radio_button_selector(gui, "layer selector", &drawP.controls.layerSelector, { {"Layer being edited", DrawingProgramLayerManager::LayerSelector::LAYER_BEING_EDITED}, {"All visible layers", DrawingProgramLayerManager::LayerSelector::ALL_VISIBLE_LAYERS} }); diff --git a/src/DrawingProgram/Tools/EyeDropperTool.cpp b/src/DrawingProgram/Tools/EyeDropperTool.cpp index 50f1516..8668df8 100644 --- a/src/DrawingProgram/Tools/EyeDropperTool.cpp +++ b/src/DrawingProgram/Tools/EyeDropperTool.cpp @@ -31,11 +31,12 @@ void EyeDropperTool::gui_toolbox() { using namespace ElementHelpers; Toolbar& t = drawP.world.main.toolbar; + auto& gui = drawP.world.main.g.gui; auto& selectingStrokeColor = drawP.world.main.toolConfig.eyeDropper.selectingStrokeColor; - t.gui.new_id("Color select tool", [&] { - text_label_centered(t.gui, "Color Select"); + gui.new_id("Color select tool", [&] { + text_label_centered(gui, "Color Select"); - radio_button_selector(t.gui, "Stroke type", &selectingStrokeColor, { + radio_button_selector(gui, "Stroke type", &selectingStrokeColor, { {"Stroke Color", true}, {"Fill Color", false} }); diff --git a/src/DrawingProgram/Tools/GridModifyTool.cpp b/src/DrawingProgram/Tools/GridModifyTool.cpp index d4d0828..b5e222f 100644 --- a/src/DrawingProgram/Tools/GridModifyTool.cpp +++ b/src/DrawingProgram/Tools/GridModifyTool.cpp @@ -118,14 +118,16 @@ void GridModifyTool::gui_toolbox() { using namespace ElementHelpers; Toolbar& t = drawP.world.main.toolbar; - t.gui.new_id("Grid modify tool", [&] { - text_label_centered(t.gui, "Edit Grid"); + auto& gui = drawP.world.main.g.gui; + + gui.new_id("Grid modify tool", [&] { + text_label_centered(gui, "Edit Grid"); NetworkingObjects::NetObjTemporaryPtr gLock = grid.lock(); if(gLock) { WorldGrid& g = *gLock; - 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); + input_text_field(gui, "grid name", "Name", &g.name); + checkbox_boolean_field(gui, "Visible", "Visible", &g.visible); + checkbox_boolean_field(gui, "Display in Front", "Display in front of canvas", &g.displayInFront); size_t typeSelected = static_cast(g.gridType); std::vector listOfGridTypes = { "Circle Points", @@ -133,25 +135,25 @@ void GridModifyTool::gui_toolbox() { "Square Lines", "Horizontal Lines" }; - left_to_right_line_layout(t.gui, [&]() { - text_label(t.gui, "Type"); - t.gui.element>("filepicker select type", &typeSelected, listOfGridTypes); + left_to_right_line_layout(gui, [&]() { + text_label(gui, "Type"); + gui.element>("filepicker select type", &typeSelected, listOfGridTypes); }); g.gridType = static_cast(typeSelected); uint32_t sDiv = g.subdivisions; - input_scalar_field(t.gui, "Subdivisions", "Subdivisions", &sDiv, 1, 10); + input_scalar_field(gui, "Subdivisions", "Subdivisions", &sDiv, 1, 10); g.set_subdivisions(sDiv); bool divOut = g.removeDivisionsOutwards; - checkbox_boolean_field(t.gui, "Subdivide outwards", "Subdivide when zooming out", &divOut); + checkbox_boolean_field(gui, "Subdivide outwards", "Subdivide when zooming out", &divOut); g.set_remove_divisions_outwards(divOut); - left_to_right_line_layout(t.gui, [&]() { - //if(t.gui.color_button_big("Grid Color", &g.color, &g.color == t.colorRight)) + left_to_right_line_layout(gui, [&]() { + //if(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"); + text_label(gui, "Grid Color"); }); bool bounded = g.bounds.has_value(); bool prevBoundedValue = bounded; - checkbox_boolean_field(t.gui, "Bounded", "Bounded", &bounded); + checkbox_boolean_field(gui, "Bounded", "Bounded", &bounded); if(bounded && !prevBoundedValue) { SCollision::AABB newBounds; newBounds.min = g.offset - drawP.world.drawData.cam.c.dir_from_space(drawP.world.main.window.size.cast() * 0.3f); @@ -160,7 +162,7 @@ void GridModifyTool::gui_toolbox() { } else if(!bounded && prevBoundedValue) g.bounds = std::nullopt; - checkbox_boolean_field(t.gui, "Show Coordinates", "Show Coordinates (visible\nwhen canvas isn't rotated)", &g.showCoordinates); + checkbox_boolean_field(gui, "Show Coordinates", "Show Coordinates (visible\nwhen canvas isn't rotated)", &g.showCoordinates); } }); } diff --git a/src/DrawingProgram/Tools/LassoSelectTool.cpp b/src/DrawingProgram/Tools/LassoSelectTool.cpp index 1b524b9..52c869f 100644 --- a/src/DrawingProgram/Tools/LassoSelectTool.cpp +++ b/src/DrawingProgram/Tools/LassoSelectTool.cpp @@ -42,8 +42,9 @@ DrawingProgramToolType LassoSelectTool::get_type() { void LassoSelectTool::gui_toolbox() { auto& t = drawP.world.main.toolbar; - t.gui.new_id("lasso select tool", [&] { - GUIStuff::ElementHelpers::text_label_centered(t.gui, "Lasso Select"); + auto& gui = drawP.world.main.g.gui; + gui.new_id("lasso select tool", [&] { + GUIStuff::ElementHelpers::text_label_centered(gui, "Lasso Select"); drawP.selection.selection_gui(); }); } diff --git a/src/DrawingProgram/Tools/LineDrawTool.cpp b/src/DrawingProgram/Tools/LineDrawTool.cpp index 65f8dd3..6a40253 100644 --- a/src/DrawingProgram/Tools/LineDrawTool.cpp +++ b/src/DrawingProgram/Tools/LineDrawTool.cpp @@ -23,11 +23,12 @@ void LineDrawTool::gui_toolbox() { using namespace GUIStuff; using namespace ElementHelpers; Toolbar& t = drawP.world.main.toolbar; + auto& gui = drawP.world.main.g.gui; auto& toolConfig = drawP.world.main.toolConfig; - t.gui.new_id("rect draw tool", [&] { - text_label_centered(t.gui, "Draw Line"); + gui.new_id("rect draw tool", [&] { + text_label_centered(gui, "Draw Line"); toolConfig.relative_width_gui(drawP, "Size"); - checkbox_boolean_field(t.gui, "hasroundcaps", "Round Caps", &toolConfig.lineDraw.hasRoundCaps); + checkbox_boolean_field(gui, "hasroundcaps", "Round Caps", &toolConfig.lineDraw.hasRoundCaps); }); } diff --git a/src/DrawingProgram/Tools/PanCanvasTool.cpp b/src/DrawingProgram/Tools/PanCanvasTool.cpp index b1b7a28..54563fd 100644 --- a/src/DrawingProgram/Tools/PanCanvasTool.cpp +++ b/src/DrawingProgram/Tools/PanCanvasTool.cpp @@ -18,8 +18,9 @@ DrawingProgramToolType PanCanvasTool::get_type() { void PanCanvasTool::gui_toolbox() { Toolbar& t = drawP.world.main.toolbar; - t.gui.new_id("Pan canvas tool", [&] { - GUIStuff::ElementHelpers::text_label_centered(t.gui, "Pan tool"); + auto& gui = drawP.world.main.g.gui; + gui.new_id("Pan canvas tool", [&] { + GUIStuff::ElementHelpers::text_label_centered(gui, "Pan tool"); }); } diff --git a/src/DrawingProgram/Tools/RectDrawTool.cpp b/src/DrawingProgram/Tools/RectDrawTool.cpp index 9b7c98e..0b363e3 100644 --- a/src/DrawingProgram/Tools/RectDrawTool.cpp +++ b/src/DrawingProgram/Tools/RectDrawTool.cpp @@ -23,13 +23,14 @@ void RectDrawTool::gui_toolbox() { using namespace ElementHelpers; Toolbar& t = drawP.world.main.toolbar; + auto& gui = drawP.world.main.g.gui; auto& toolConfig = drawP.world.main.toolConfig; auto& fillStrokeMode = toolConfig.rectDraw.fillStrokeMode; auto& relativeRadiusWidth = toolConfig.rectDraw.relativeRadiusWidth; - t.gui.new_id("rect draw tool", [&] { - 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, { + gui.new_id("rect draw tool", [&] { + text_label_centered(gui, "Draw Rectangle"); + slider_scalar_field(gui, "relradiuswidth", "Corner Radius", &relativeRadiusWidth, 0.0f, 40.0f); + radio_button_selector(gui, "fill type", &fillStrokeMode, { {"Fill only", 0}, {"Outline only", 1}, {"Fill and Outline", 2} diff --git a/src/DrawingProgram/Tools/RectSelectTool.cpp b/src/DrawingProgram/Tools/RectSelectTool.cpp index 35b843c..e1cc927 100644 --- a/src/DrawingProgram/Tools/RectSelectTool.cpp +++ b/src/DrawingProgram/Tools/RectSelectTool.cpp @@ -20,8 +20,9 @@ DrawingProgramToolType RectSelectTool::get_type() { void RectSelectTool::gui_toolbox() { auto& t = drawP.world.main.toolbar; - t.gui.new_id("rectangle select tool", [&] { - GUIStuff::ElementHelpers::text_label_centered(t.gui, "Rectangle Select"); + auto& gui = drawP.world.main.g.gui; + gui.new_id("rectangle select tool", [&] { + GUIStuff::ElementHelpers::text_label_centered(gui, "Rectangle Select"); drawP.selection.selection_gui(); }); } diff --git a/src/DrawingProgram/Tools/ScreenshotTool.cpp b/src/DrawingProgram/Tools/ScreenshotTool.cpp index c998915..12e3bec 100644 --- a/src/DrawingProgram/Tools/ScreenshotTool.cpp +++ b/src/DrawingProgram/Tools/ScreenshotTool.cpp @@ -57,25 +57,26 @@ void ScreenshotTool::gui_toolbox() { using namespace ElementHelpers; Toolbar& t = drawP.world.main.toolbar; + auto& gui = drawP.world.main.g.gui; auto& screenshotConfig = drawP.world.main.toolConfig.screenshot; - t.gui.new_id("screenshot tool", [&] { - text_label_centered(t.gui, "Screenshot"); + gui.new_id("screenshot tool", [&] { + text_label_centered(gui, "Screenshot"); auto oldImgSize = controls.imageSize; if(controls.selectionMode == ScreenshotControls::SelectionMode::NO_SELECTION) - text_label(t.gui, "Select an area on the canvas..."); + text_label(gui, "Select an area on the canvas..."); if(controls.selectionMode != ScreenshotControls::SelectionMode::NO_SELECTION && screenshotConfig.selectedType != SCREENSHOT_SVG) - input_scalars_field(t.gui, "Image Size", "Image Size", &controls.imageSize, 2, 0, 999999999); + input_scalars_field(gui, "Image Size", "Image Size", &controls.imageSize, 2, 0, 999999999); if(controls.selectionMode == ScreenshotControls::SelectionMode::SELECTION_EXISTS) { - left_to_right_line_layout(t.gui, [&]() { - text_label(t.gui, "Image Type"); - t.gui.element>("image type select", (size_t*)(&screenshotConfig.selectedType), controls.typeSelections); + left_to_right_line_layout(gui, [&]() { + text_label(gui, "Image Type"); + gui.element>("image type select", (size_t*)(&screenshotConfig.selectedType), controls.typeSelections); }); if(screenshotConfig.selectedType != SCREENSHOT_SVG) - checkbox_boolean_field(t.gui, "Display Grid", "Display Grid", &controls.displayGrid); + checkbox_boolean_field(gui, "Display Grid", "Display Grid", &controls.displayGrid); else - text_label(t.gui, "Note: Screenshot will ignore blend\nmodes and layer alpha"); + text_label(gui, "Note: Screenshot will ignore blend\nmodes and layer alpha"); if(screenshotConfig.selectedType != 0) - checkbox_boolean_field(t.gui, "Transparent Background", "Transparent Background", &controls.transparentBackground); + checkbox_boolean_field(gui, "Transparent Background", "Transparent Background", &controls.transparentBackground); if(controls.imageSize.x() != oldImgSize.x()) { screenshotConfig.setDimensionSize = controls.imageSize.x(); screenshotConfig.setDimensionIsX = true; @@ -86,7 +87,7 @@ void ScreenshotTool::gui_toolbox() { screenshotConfig.setDimensionIsX = false; controls.imageSize.x() = controls.imageSize.y() * (controls.rectX2 - controls.rectX1) / (controls.rectY2 - controls.rectY1); } - text_button(t.gui, "Take Screenshot", "Take Screenshot", { + text_button(gui, "Take Screenshot", "Take Screenshot", { .wide = true, .onClick = [&] { controls.selectionMode = ScreenshotControls::SelectionMode::NO_SELECTION; diff --git a/src/DrawingProgram/Tools/TextBoxTool.cpp b/src/DrawingProgram/Tools/TextBoxTool.cpp index d215e62..aad34e9 100644 --- a/src/DrawingProgram/Tools/TextBoxTool.cpp +++ b/src/DrawingProgram/Tools/TextBoxTool.cpp @@ -23,8 +23,9 @@ DrawingProgramToolType TextBoxTool::get_type() { void TextBoxTool::gui_toolbox() { Toolbar& t = drawP.world.main.toolbar; - t.gui.new_id("textbox tool", [&] { - GUIStuff::ElementHelpers::text_label_centered(t.gui, "Zoom tool"); + auto& gui = drawP.world.main.g.gui; + gui.new_id("textbox tool", [&] { + GUIStuff::ElementHelpers::text_label_centered(gui, "Zoom tool"); }); } diff --git a/src/DrawingProgram/Tools/ZoomCanvasTool.cpp b/src/DrawingProgram/Tools/ZoomCanvasTool.cpp index cc8d3a6..05c2d51 100644 --- a/src/DrawingProgram/Tools/ZoomCanvasTool.cpp +++ b/src/DrawingProgram/Tools/ZoomCanvasTool.cpp @@ -18,8 +18,9 @@ DrawingProgramToolType ZoomCanvasTool::get_type() { void ZoomCanvasTool::gui_toolbox() { Toolbar& t = drawP.world.main.toolbar; - t.gui.new_id("Zoom canvas tool", [&] { - GUIStuff::ElementHelpers::text_label_centered(t.gui, "Zoom tool"); + auto& gui = drawP.world.main.g.gui; + gui.new_id("Zoom canvas tool", [&] { + GUIStuff::ElementHelpers::text_label_centered(gui, "Zoom tool"); }); } diff --git a/src/GUIHolder.cpp b/src/GUIHolder.cpp new file mode 100644 index 0000000..78b23df --- /dev/null +++ b/src/GUIHolder.cpp @@ -0,0 +1,106 @@ +#include "GUIHolder.hpp" +#include +#include + +#include + +GUIHolder::GUIHolder() { + // NOTE: On windows, when the native file picker is open, any call to MakeFromFile fails + // So, it's better to load the icons at the beginning of the program so that the icon loading doesn't fail later + load_icons_at("data/icons"); + +#ifdef __ANDROID__ + load_icons_at("data/icons/RemixIcon"); // SDL_GlobDirectory doesn't work recursively on Android +#endif + + load_default_theme(); +} + +void GUIHolder::load_icons_at(const std::filesystem::path& pathToLoad) { + int globCount; + char** filesInPath = SDL_GlobDirectory(pathToLoad.c_str(), nullptr, 0, &globCount); + if(filesInPath) { + for(int i = 0; i < globCount; i++) { + std::filesystem::path filePath = pathToLoad / std::filesystem::path(filesInPath[i]); + SDL_PathInfo fileInfo; + if(SDL_GetPathInfo(filePath.c_str(), &fileInfo) && fileInfo.type == SDL_PATHTYPE_FILE) { + std::string iconRelativePath = filePath.relative_path().string(); + std::replace(iconRelativePath.begin(), iconRelativePath.end(), '\\', '/'); + std::string iconData = read_file_to_string(iconRelativePath); + auto stream = SkMemoryStream(iconData.c_str(), iconData.size(), false); + auto svgDom = SkSVGDOM::Builder().make(stream); + if(!svgDom) + throw std::runtime_error("[Toolbar::Toolbar] Could not parse SVG " + iconRelativePath); + else { + if(svgDom->containerSize().width() == 0 || svgDom->containerSize().height() == 0) + svgDom->setContainerSize({1000, 1000}); + gui.io.svgData[iconRelativePath] = svgDom; + } + } + } + SDL_free(filesInPath); + } +} + +void GUIHolder::load_default_theme() { + gui.io.theme = GUIStuff::get_default_dark_mode(); +} + +void GUIHolder::save_theme(const std::filesystem::path& configPath, const std::string& themeName) { + std::filesystem::create_directory(configPath / "themes"); + std::ofstream f(configPath / "themes" / (themeName + ".json")); + if(f.is_open()) { + using json = nlohmann::json; + json j; + j = *gui.io.theme; + f << j; + f.close(); + } +} + +bool GUIHolder::load_theme(const std::filesystem::path& configPath, const std::string& themeName) { + std::filesystem::path themeDir = configPath / "themes"; + bool successfullyLoaded = false; + if(std::filesystem::exists(themeDir) && std::filesystem::is_directory(themeDir)) { + std::ifstream f(themeDir / (themeName + ".json")); + if(f.is_open()) { + using json = nlohmann::json; + try { + json j; + f >> j; + auto theme(std::make_shared()); + j.get_to(*theme); + gui.io.theme = theme; + successfullyLoaded = true; + } catch(...) {} + f.close(); + } + } + if(!successfullyLoaded) + load_default_theme(); + return successfullyLoaded; +} + +void GUIHolder::update() { +} + +void GUIHolder::draw(SkCanvas* canvas) { +} + +void GUIHolder::input_key_callback(const InputManager::KeyCallbackArgs& key) { +} + +void GUIHolder::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) { +} + +void GUIHolder::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) { +} + +void GUIHolder::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel) { +} + +void GUIHolder::input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) { +} + +void GUIHolder::input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) { +} diff --git a/src/GUIHolder.hpp b/src/GUIHolder.hpp new file mode 100644 index 0000000..38ac64f --- /dev/null +++ b/src/GUIHolder.hpp @@ -0,0 +1,24 @@ +#pragma once + +#include "GUIStuff/GUIManager.hpp" + +class GUIHolder { + public: + GUIHolder(); + + GUIStuff::GUIManager gui; + + void load_icons_at(const std::filesystem::path& pathToLoad); + void load_default_theme(); + void save_theme(const std::filesystem::path& configPath, const std::string& themeName); + bool load_theme(const std::filesystem::path& configPath, const std::string& themeName); + + void update(); + void draw(SkCanvas* canvas); + void input_key_callback(const InputManager::KeyCallbackArgs& key); + void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button); + void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion); + void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel); + void input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch); + void input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion); +}; diff --git a/src/GUIStuff/ElementHelpers/LayoutHelpers.cpp b/src/GUIStuff/ElementHelpers/LayoutHelpers.cpp index ae53dd8..1823370 100644 --- a/src/GUIStuff/ElementHelpers/LayoutHelpers.cpp +++ b/src/GUIStuff/ElementHelpers/LayoutHelpers.cpp @@ -8,14 +8,14 @@ void top_to_bottom_window_popup_layout(GUIManager& gui, const char* id, Clay_Siz CLAY_AUTO_ID({ .layout = { .sizing = {.width = x, .height = y }, - .padding = CLAY_PADDING_ALL(gui.io->theme->padding1), - .childGap = gui.io->theme->childGap1, + .padding = CLAY_PADDING_ALL(gui.io.theme->padding1), + .childGap = gui.io.theme->childGap1, .layoutDirection = CLAY_TOP_TO_BOTTOM }, - .backgroundColor = convert_vec4(gui.io->theme->backColor1), + .backgroundColor = convert_vec4(gui.io.theme->backColor1), .cornerRadius = CLAY_CORNER_RADIUS(10), .floating = { .attachTo = CLAY_ATTACH_TO_PARENT }, - .border = {.color = convert_vec4(gui.io->theme->fillColor2), .width = CLAY_BORDER_OUTSIDE(1)} + .border = {.color = convert_vec4(gui.io.theme->fillColor2), .width = CLAY_BORDER_OUTSIDE(1)} }) { innerContent(); } @@ -25,7 +25,7 @@ void top_to_bottom_window_popup_layout(GUIManager& gui, const char* id, Clay_Siz void left_to_right_layout(GUIManager& gui, Clay_SizingAxis x, Clay_SizingAxis y, const std::function& innerContent) { CLAY_AUTO_ID({.layout = { .sizing = {.width = x, .height = y }, - .childGap = gui.io->theme->childGap1, + .childGap = gui.io.theme->childGap1, .childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER}, .layoutDirection = CLAY_LEFT_TO_RIGHT, } @@ -41,7 +41,7 @@ void left_to_right_line_layout(GUIManager& gui, const std::function& inn void left_to_right_line_centered_layout(GUIManager& gui, const std::function& innerContent) { CLAY_AUTO_ID({.layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) }, - .childGap = gui.io->theme->childGap1, + .childGap = gui.io.theme->childGap1, .childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER}, .layoutDirection = CLAY_LEFT_TO_RIGHT, } diff --git a/src/GUIStuff/ElementHelpers/TextLabelHelpers.cpp b/src/GUIStuff/ElementHelpers/TextLabelHelpers.cpp index 23029d4..cf0892e 100644 --- a/src/GUIStuff/ElementHelpers/TextLabelHelpers.cpp +++ b/src/GUIStuff/ElementHelpers/TextLabelHelpers.cpp @@ -3,19 +3,19 @@ namespace GUIStuff { namespace ElementHelpers { void text_label_size(GUIManager& gui, std::string_view val, float modifier) { - CLAY_TEXT(gui.strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4(gui.io->theme->frontColor1), .fontSize = static_cast(gui.io->fontSize * modifier)})); + CLAY_TEXT(gui.strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4(gui.io.theme->frontColor1), .fontSize = static_cast(gui.io.fontSize * modifier)})); } void text_label_color(GUIManager& gui, std::string_view val, const SkColor4f& color) { - CLAY_TEXT(gui.strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4(color), .fontSize = gui.io->fontSize })); + CLAY_TEXT(gui.strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4(color), .fontSize = gui.io.fontSize })); } void text_label_light(GUIManager& gui, std::string_view val) { - CLAY_TEXT(gui.strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4(gui.io->theme->frontColor2), .fontSize = gui.io->fontSize })); + CLAY_TEXT(gui.strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4(gui.io.theme->frontColor2), .fontSize = gui.io.fontSize })); } void text_label(GUIManager& gui, std::string_view val) { - CLAY_TEXT(gui.strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4(gui.io->theme->frontColor1), .fontSize = gui.io->fontSize })); + CLAY_TEXT(gui.strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4(gui.io.theme->frontColor1), .fontSize = gui.io.fontSize })); } void text_label_centered(GUIManager& gui, std::string_view val) { @@ -25,7 +25,7 @@ void text_label_centered(GUIManager& gui, std::string_view val) { .childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER}, } }) { - CLAY_TEXT(gui.strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4(gui.io->theme->frontColor1), .fontSize = gui.io->fontSize, .textAlignment = CLAY_TEXT_ALIGN_CENTER})); + CLAY_TEXT(gui.strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4(gui.io.theme->frontColor1), .fontSize = gui.io.fontSize, .textAlignment = CLAY_TEXT_ALIGN_CENTER})); } } @@ -36,7 +36,7 @@ void text_label_light_centered(GUIManager& gui, std::string_view val) { .childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER}, } }) { - CLAY_TEXT(gui.strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4(gui.io->theme->frontColor2), .fontSize = gui.io->fontSize, .textAlignment = CLAY_TEXT_ALIGN_CENTER})); + CLAY_TEXT(gui.strArena.std_str_to_clay_str(val), CLAY_TEXT_CONFIG({.textColor = convert_vec4(gui.io.theme->frontColor2), .fontSize = gui.io.fontSize, .textAlignment = CLAY_TEXT_ALIGN_CENTER})); } } diff --git a/src/GUIStuff/Elements/DropDown.hpp b/src/GUIStuff/Elements/DropDown.hpp index 6ee9541..9aca317 100644 --- a/src/GUIStuff/Elements/DropDown.hpp +++ b/src/GUIStuff/Elements/DropDown.hpp @@ -32,7 +32,7 @@ template class DropDown : public Element { .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) }, .padding = {.left = 4, .right = 4}, - .childGap = gui.io->theme->childGap1, + .childGap = gui.io.theme->childGap1, .childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER}, .layoutDirection = CLAY_LEFT_TO_RIGHT, } @@ -55,13 +55,13 @@ template class DropDown : public Element { Clay_ElementData dropdownElemData = Clay_GetElementData(localID); float calculatedDropdownMaxHeight = 0.0f; if(dropdownElemData.found) - calculatedDropdownMaxHeight = std::max(gui.io->windowSize.y() - dropdownElemData.boundingBox.y - 2.0f, 0.0f); + calculatedDropdownMaxHeight = std::max(gui.io.windowSize.y() - dropdownElemData.boundingBox.y - 2.0f, 0.0f); CLAY(localID, { .layout = { .sizing = {.width = CLAY_SIZING_FIXED(opts.width), .height = CLAY_SIZING_FIT(0, calculatedDropdownMaxHeight)}, .childGap = 0 }, - .backgroundColor = convert_vec4(gui.io->theme->backColor1), + .backgroundColor = convert_vec4(gui.io.theme->backColor1), .cornerRadius = CLAY_CORNER_RADIUS(4), .floating = { .offset = { @@ -74,7 +74,7 @@ template class DropDown : public Element { .attachTo = CLAY_ATTACH_TO_PARENT }, .border = { - .color = convert_vec4(gui.io->theme->fillColor2), + .color = convert_vec4(gui.io.theme->fillColor2), .width = CLAY_BORDER_OUTSIDE(1) } }) { @@ -96,11 +96,11 @@ template class DropDown : public Element { }) { SkColor4f entryColor; if(selectedEntry) - entryColor = gui.io->theme->backColor2; + entryColor = gui.io.theme->backColor2; else if(hoveringOver.has_value() && hoveringOver.value() == i) - entryColor = gui.io->theme->backColor2; + entryColor = gui.io.theme->backColor2; else - entryColor = gui.io->theme->backColor1; + entryColor = gui.io.theme->backColor1; CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, diff --git a/src/GUIStuff/Elements/GUIStuffHelpers.hpp b/src/GUIStuff/Elements/GUIStuffHelpers.hpp index 3b115e4..1c27e73 100644 --- a/src/GUIStuff/Elements/GUIStuffHelpers.hpp +++ b/src/GUIStuff/Elements/GUIStuffHelpers.hpp @@ -68,7 +68,7 @@ struct Theme { std::shared_ptr get_default_dark_mode(); struct UpdateInputData { - InputManager* input; + InputManager* input = nullptr; std::function layoutRun; SkFont get_font(float fSize) const; @@ -84,7 +84,6 @@ struct UpdateInputData { std::shared_ptr fonts; sk_sp textTypeface; - DefaultStringArena* strArena; std::shared_ptr theme; std::unordered_map> svgData; }; diff --git a/src/GUIStuff/Elements/PositionAdjustingPopupMenu.cpp b/src/GUIStuff/Elements/PositionAdjustingPopupMenu.cpp index 1217658..81d59a6 100644 --- a/src/GUIStuff/Elements/PositionAdjustingPopupMenu.cpp +++ b/src/GUIStuff/Elements/PositionAdjustingPopupMenu.cpp @@ -8,9 +8,9 @@ PositionAdjustingPopupMenu::PositionAdjustingPopupMenu(GUIManager& gui): Element void PositionAdjustingPopupMenu::layout(Vector2f popupPos, const std::function& innerContent) { if(layoutElement && layoutElement->get_bb().has_value()) { auto& bb = layoutElement->get_bb().value(); - if((popupPos.y() + bb.height()) > gui.io->windowSize.y()) + if((popupPos.y() + bb.height()) > gui.io.windowSize.y()) popupPos.y() -= bb.height(); - if((popupPos.x() + bb.width()) > gui.io->windowSize.x()) + if((popupPos.x() + bb.width()) > gui.io.windowSize.x()) popupPos.x() -= bb.width(); } @@ -18,13 +18,13 @@ void PositionAdjustingPopupMenu::layout(Vector2f popupPos, const std::functiontheme->padding1), + .padding = CLAY_PADDING_ALL(gui.io.theme->padding1), .childGap = 1, .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, - .backgroundColor = convert_vec4(gui.io->theme->backColor1), - .cornerRadius = CLAY_CORNER_RADIUS(gui.io->theme->windowCorners1), + .backgroundColor = convert_vec4(gui.io.theme->backColor1), + .cornerRadius = CLAY_CORNER_RADIUS(gui.io.theme->windowCorners1), .floating = { .offset = {popupPos.x(), popupPos.y()}, .zIndex = gui.zIndex, diff --git a/src/GUIStuff/Elements/SVGIcon.cpp b/src/GUIStuff/Elements/SVGIcon.cpp index 8b4d24d..9f6b143 100644 --- a/src/GUIStuff/Elements/SVGIcon.cpp +++ b/src/GUIStuff/Elements/SVGIcon.cpp @@ -11,7 +11,7 @@ SVGIcon::SVGIcon(GUIManager& gui): Element(gui) {} void SVGIcon::layout(const std::string& newSvgPath, bool newIsHighlighted) { - auto& io = *gui.io; + auto& io = gui.io; auto findSVGData = io.svgData.find(newSvgPath); if(findSVGData == io.svgData.end()) throw std::runtime_error("[SVGIcon::update] Could not load icon " + newSvgPath); diff --git a/src/GUIStuff/Elements/ScrollArea.cpp b/src/GUIStuff/Elements/ScrollArea.cpp index 0942ed9..9a5cf37 100644 --- a/src/GUIStuff/Elements/ScrollArea.cpp +++ b/src/GUIStuff/Elements/ScrollArea.cpp @@ -46,15 +46,15 @@ void ScrollArea::layout(const Options& options) { // .childAlignment = {.x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP}, // .layoutDirection = CLAY_TOP_TO_BOTTOM // }, - // .backgroundColor = convert_vec4(io->theme->backColor2) + // .backgroundColor = convert_vec4(io.theme->backColor2) // }) { // SkColor4f scrollerColor; // if(sD.isMoving) - // scrollerColor = io->theme->fillColor1; + // scrollerColor = io.theme->fillColor1; // else if(Clay_Hovered()) - // scrollerColor = io->theme->fillColor1; + // scrollerColor = io.theme->fillColor1; // else - // scrollerColor = io->theme->fillColor2; + // scrollerColor = io.theme->fillColor2; // bool isHoveringOverScroller = false; // CLAY_AUTO_ID({ @@ -71,19 +71,19 @@ void ScrollArea::layout(const Options& options) { // isHoveringOverScroller = true; // } // CLAY_AUTO_ID({ .layout = {.sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}}}) {} - // if(Clay_Hovered() && io->mouse.leftClick) { + // if(Clay_Hovered() && io.mouse.leftClick) { // isMoving = true; // if(isHoveringOverScroller) // scrollerStartPos = scrollAreaBB.y + areaAboveScrollerSize + scrollerSize * 0.5f; // else - // scrollerStartPos = std::clamp(io->mouse.pos.y(), scrollAreaBB.y + scrollerSize * 0.5f, scrollAreaBB.y + scrollAreaBB.height - scrollerSize * 0.5f); - // mouseStartPos = io->mouse.pos.y(); + // scrollerStartPos = std::clamp(io.mouse.pos.y(), scrollAreaBB.y + scrollerSize * 0.5f, scrollAreaBB.y + scrollAreaBB.height - scrollerSize * 0.5f); + // mouseStartPos = io.mouse.pos.y(); // } - // if(!io->mouse.leftHeld) + // if(!io.mouse.leftHeld) // isMoving = false; // if(isMoving) { // float newScrollPosFrac; - // newScrollPosFrac = std::clamp((scrollerStartPos - (mouseStartPos - io->mouse.pos.y()) - scrollAreaBB.y - scrollerSize * 0.5f) / (scrollAreaBB.height - scrollerSize), 0.0f, 1.0f); + // newScrollPosFrac = std::clamp((scrollerStartPos - (mouseStartPos - io.mouse.pos.y()) - scrollAreaBB.y - scrollerSize * 0.5f) / (scrollAreaBB.height - scrollerSize), 0.0f, 1.0f); // currentScrollPos = newScrollPosFrac * (-scrollPosMax); // } // currentScrollPos = std::clamp(currentScrollPos, -scrollPosMax, 0.0f); diff --git a/src/GUIStuff/Elements/SelectableButton.cpp b/src/GUIStuff/Elements/SelectableButton.cpp index 9ee43ef..4435ed7 100644 --- a/src/GUIStuff/Elements/SelectableButton.cpp +++ b/src/GUIStuff/Elements/SelectableButton.cpp @@ -8,7 +8,7 @@ SelectableButton::SelectableButton(GUIManager& gui): Element(gui) {} void SelectableButton::layout(const Data& d) { - auto& io = *gui.io; + auto& io = gui.io; SkColor4f borderColor; SkColor4f backgroundColorHighlight; diff --git a/src/GUIStuff/Elements/TextBox.impl.hpp b/src/GUIStuff/Elements/TextBox.impl.hpp index d01c506..1034d00 100644 --- a/src/GUIStuff/Elements/TextBox.impl.hpp +++ b/src/GUIStuff/Elements/TextBox.impl.hpp @@ -6,7 +6,7 @@ namespace GUIStuff { template TextBox::TextBox(GUIManager& gui): Element(gui) {} template void TextBox::layout(const TextBoxData& userInfo) { - auto& io = *gui.io; + auto& io = gui.io; this->userInfo = userInfo; init_textbox(io); CLAY_AUTO_ID({ @@ -59,26 +59,26 @@ template void TextBox::clay_draw(SkCanvas* canvas, UpdateInputDa } template bool TextBox::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button, bool mouseHovering) { - auto& io = *gui.io; + auto& io = gui.io; if(button.button == InputManager::MouseButton::LEFT && boundingBox.has_value()) { if(button.down) { if(mouseHovering) { *rect = {(boundingBox.value().min + io.windowPos) * io.guiScaleMultiplier, (boundingBox.value().max + io.windowPos) * io.guiScaleMultiplier}; - gui.io->input->set_rich_text_box_input_front(textbox, cur, false, rect, userInfo.textInputProps, nullptr); - textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, button.clicks, true, gui.io->input->key(InputManager::KEY_TEXT_SHIFT).held); + gui.io.input->set_rich_text_box_input_front(textbox, cur, false, rect, userInfo.textInputProps, nullptr); + textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, button.clicks, true, gui.io.input->key(InputManager::KEY_TEXT_SHIFT).held); isSelected = true; } else { - gui.io->input->remove_rich_text_box_input(textbox); + gui.io.input->remove_rich_text_box_input(textbox); if(update_data()) gui.set_post_callback_func(userInfo.onEdit); - init_textbox(*gui.io); + init_textbox(gui.io); isSelected = false; } } else { - textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, 0, false, gui.io->input->key(InputManager::KEY_TEXT_SHIFT).held); + textbox->process_mouse_left_button(*cur, button.pos - boundingBox.value().min, 0, false, gui.io.input->key(InputManager::KEY_TEXT_SHIFT).held); } } return Element::input_mouse_button_callback(button, mouseHovering); @@ -86,7 +86,7 @@ template bool TextBox::input_mouse_button_callback(const InputMa template bool TextBox::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion, bool mouseHovering) { if(boundingBox.has_value()) - textbox->process_mouse_left_button(*cur, motion.pos - boundingBox.value().min, 0, gui.io->input->mouse.leftDown, gui.io->input->key(InputManager::KEY_TEXT_SHIFT).held); + textbox->process_mouse_left_button(*cur, motion.pos - boundingBox.value().min, 0, gui.io.input->mouse.leftDown, gui.io.input->key(InputManager::KEY_TEXT_SHIFT).held); return Element::input_mouse_motion_callback(motion, mouseHovering); } @@ -130,7 +130,7 @@ template bool TextBox::update_data() { } template TextBox::~TextBox() { - gui.io->input->remove_rich_text_box_input(textbox); + gui.io.input->remove_rich_text_box_input(textbox); } } diff --git a/src/GUIStuff/GUIManager.cpp b/src/GUIStuff/GUIManager.cpp index 86a3412..4621053 100644 --- a/src/GUIStuff/GUIManager.cpp +++ b/src/GUIStuff/GUIManager.cpp @@ -45,10 +45,10 @@ Clay_Dimensions GUIManager::clay_skia_measure_text(Clay_StringSlice str, Clay_Te pStyle.setTextAlign(skia::textlayout::TextAlign::kLeft); skia::textlayout::TextStyle tStyle; tStyle.setFontSize(config->fontSize); - tStyle.setFontFamilies(window->io->fonts->get_default_font_families()); + tStyle.setFontFamilies(window->io.fonts->get_default_font_families()); pStyle.setTextStyle(tStyle); - skia::textlayout::ParagraphBuilderImpl a(pStyle, window->io->fonts->collection, SkUnicodes::ICU::Make()); + skia::textlayout::ParagraphBuilderImpl a(pStyle, window->io.fonts->collection, SkUnicodes::ICU::Make()); a.addText(str.chars, str.length); std::unique_ptr p = a.Build(); p->layout(std::numeric_limits::max()); @@ -58,7 +58,7 @@ Clay_Dimensions GUIManager::clay_skia_measure_text(Clay_StringSlice str, Clay_Te void GUIManager::draw(SkCanvas* canvas, bool skiaAA) { canvas->save(); - canvas->translate(io->windowPos.x(), io->windowPos.y()); + canvas->translate(io.windowPos.x(), io.windowPos.y()); for(size_t i = 0; i < static_cast(renderCommands.length); i++) { Clay_RenderCommand* command = Clay_RenderCommandArray_Get(&renderCommands, i); @@ -94,11 +94,11 @@ void GUIManager::draw(SkCanvas* canvas, bool skiaAA) { pStyle.setTextAlign(skia::textlayout::TextAlign::kLeft); skia::textlayout::TextStyle tStyle; tStyle.setFontSize(config->fontSize); - tStyle.setFontFamilies(io->fonts->get_default_font_families()); + tStyle.setFontFamilies(io.fonts->get_default_font_families()); tStyle.setColor(convert_vec4(config->textColor).toSkColor()); pStyle.setTextStyle(tStyle); - skia::textlayout::ParagraphBuilderImpl a(pStyle, io->fonts->collection, SkUnicodes::ICU::Make()); + skia::textlayout::ParagraphBuilderImpl a(pStyle, io.fonts->collection, SkUnicodes::ICU::Make()); a.addText(config->stringContents.chars, config->stringContents.length); std::unique_ptr p = a.Build(); p->layout(std::numeric_limits::max()); @@ -211,7 +211,7 @@ void GUIManager::draw(SkCanvas* canvas, bool skiaAA) { } case CLAY_RENDER_COMMAND_TYPE_CUSTOM: { Element* customElement = static_cast(command->renderData.custom.customData); - customElement->clay_draw(canvas, *io, command, skiaAA); + customElement->clay_draw(canvas, io, command, skiaAA); break; } default: @@ -223,11 +223,11 @@ void GUIManager::draw(SkCanvas* canvas, bool skiaAA) { } void GUIManager::update_window(const Vector2f& windowPos, const Vector2f& windowSize, float guiScaleMultiplier) { - if(io->windowPos != windowPos || io->windowSize != windowSize || io->guiScaleMultiplier != guiScaleMultiplier) + if(io.windowPos != windowPos || io.windowSize != windowSize || io.guiScaleMultiplier != guiScaleMultiplier) set_to_layout(); - io->windowPos = windowPos; - io->windowSize = windowSize; - io->guiScaleMultiplier = guiScaleMultiplier; + io.windowPos = windowPos; + io.windowSize = windowSize; + io.guiScaleMultiplier = guiScaleMultiplier; } void GUIManager::set_to_layout() { @@ -251,8 +251,7 @@ void GUIManager::layout_begin() { for(auto& [id, e] : elements) e.isUsedThisFrame = false; - io->strArena = &strArena; - Clay_SetLayoutDimensions(Clay_Dimensions(io->windowSize.x(), io->windowSize.y())); + Clay_SetLayoutDimensions(Clay_Dimensions(io.windowSize.x(), io.windowSize.y())); Clay_SetCurrentContext(clayInstance); strArena.reset(); @@ -284,7 +283,7 @@ void GUIManager::update_element_bounding_boxes() { void GUIManager::single_layout_run() { layout_begin(); - io->layoutRun(); + io.layoutRun(); layout_end(); } diff --git a/src/GUIStuff/GUIManager.hpp b/src/GUIStuff/GUIManager.hpp index 7def7e9..fe5bee6 100644 --- a/src/GUIStuff/GUIManager.hpp +++ b/src/GUIStuff/GUIManager.hpp @@ -23,7 +23,7 @@ class GUIManager { void update_window(const Vector2f& windowPos, const Vector2f& windowSize, float guiScaleMultiplier); - std::shared_ptr io; + UpdateInputData io; GUIManagerIDStack idStack; std::unordered_map elements; diff --git a/src/GlobalConfig.cpp b/src/GlobalConfig.cpp new file mode 100644 index 0000000..8b97c24 --- /dev/null +++ b/src/GlobalConfig.cpp @@ -0,0 +1,130 @@ +#include "GlobalConfig.hpp" +#include +#include "ResourceDisplay/ImageResourceDisplay.hpp" +#include "DrawingProgram/DrawingProgramCache.hpp" + +GlobalConfig::GlobalConfig() { + displayName = Random::get().alphanumeric_str(10); +} + +nlohmann::json GlobalConfig::get_config_json(const InputManager& input) const { + using json = nlohmann::json; + json toRet; + + json jKeybinds; + for(unsigned i = 0; i < InputManager::KEY_ASSIGNABLE_COUNT; i++) { + auto f = std::find_if(input.keyAssignments.begin(), input.keyAssignments.end(), [&](auto& p) { + return p.second == i; + }); + if(f != input.keyAssignments.end()) + jKeybinds[json(static_cast(i))] = input.key_assignment_to_str(f->first); + } + toRet["keybinds"] = jKeybinds; + toRet["guiScale"] = guiScale; + toRet["jumpTransitionTime"] = jumpTransitionTime; + toRet["disableGraphicsDriverWorkarounds"] = disableGraphicsDriverWorkarounds; + toRet["dragZoomSpeed"] = dragZoomSpeed; + toRet["scrollZoomSpeed"] = scrollZoomSpeed; + toRet["vsync"] = vsyncValue; +#ifndef __EMSCRIPTEN__ + toRet["applyDisplayScale"] = applyDisplayScale; +#endif + toRet["displayName"] = displayName; + toRet["antialiasing"] = antialiasing; + toRet["useNativeFilePicker"] = useNativeFilePicker; + toRet["themeInUse"] = themeCurrentlyLoaded; + toRet["defaultCanvasBackgroundColor"] = defaultCanvasBackgroundColor; + toRet["flipZoomToolDirection"] = flipZoomToolDirection; +#ifndef __EMSCRIPTEN__ + toRet["checkForUpdates"] = checkForUpdates; +#endif + + json tablet; + tablet["pressureAffectsBrushWidth"] = tabletOptions.pressureAffectsBrushWidth; + tablet["smoothingSamplingTime"] = tabletOptions.smoothingSamplingTime; + tablet["middleClickButton"] = tabletOptions.middleClickButton; + tablet["rightClickButton"] = tabletOptions.rightClickButton; + tablet["ignoreMouseMovementWhenPenInProximity"] = tabletOptions.ignoreMouseMovementWhenPenInProximity; + tablet["brushMinimumSize"] = tabletOptions.brushMinimumSize; + tablet["zoomWhilePenDownAndButtonHeld"] = tabletOptions.zoomWhilePenDownAndButtonHeld; + toRet["tablet"] = tablet; + + json debugJson; + debugJson["showPerformance"] = showPerformance; + debugJson["fpsLimit"] = fpsLimit; + debugJson["jumpTransitionEasing"] = jumpTransitionEasing; + debugJson["imageLoadMaxThreads"] = ImageResourceDisplay::IMAGE_LOAD_THREAD_COUNT_MAX; + debugJson["cacheNodeResolution"] = DrawingProgramCache::CACHE_NODE_RESOLUTION; + debugJson["maxCacheNodes"] = DrawingProgramCache::MAXIMUM_DRAW_CACHE_SURFACES; + debugJson["maxComponentsInNode"] = DrawingProgramCache::MAXIMUM_COMPONENTS_IN_SINGLE_NODE; + debugJson["componentCountToForceCacheRebuild"] = DrawingProgramCache::MINIMUM_COMPONENTS_TO_START_REBUILD; + debugJson["maximumFrameTimeToForceCacheRebuild"] = DrawingProgramCache::MILLISECOND_FRAME_TIME_TO_FORCE_CACHE_REFRESH; + debugJson["millisecondMinimumTimeToCheckForCacheRebuild"] = DrawingProgramCache::MILLISECOND_MINIMUM_TIME_TO_CHECK_FORCE_REFRESH; + toRet["debug"] = debugJson; + + return toRet; +} + +void GlobalConfig::set_config_json(InputManager& input, const nlohmann::json& j, VersionNumber version) { + using json = nlohmann::json; + input.keyAssignments.clear(); + try { + const json& jKeybinds = j.at("keybinds"); + for(unsigned i = 0; i < InputManager::KEY_ASSIGNABLE_COUNT; i++) { + try { + Vector2ui32 a = input.key_assignment_from_str(jKeybinds.at(json(static_cast(i)))); + if(a != Vector2ui32{0, 0}) + input.keyAssignments.emplace(a, i); + else + throw; + } + catch(...) { + auto f = std::find_if(input.defaultKeyAssignments.begin(), input.defaultKeyAssignments.end(), [&](auto& p) { + return p.second == i; + }); + input.keyAssignments.emplace(f->first, i); + } + } + } + catch(...) { + input.keyAssignments = input.defaultKeyAssignments; + } + try{j.at("displayName").get_to(displayName);} catch(...) {} + try{j.at("dragZoomSpeed").get_to(dragZoomSpeed);} catch(...) {} + try{j.at("scrollZoomSpeed").get_to(scrollZoomSpeed);} catch(...) {} + try{j.at("vsync").get_to(vsyncValue);} catch(...) {} +#ifndef __EMSCRIPTEN__ + try{j.at("applyDisplayScale").get_to(applyDisplayScale);} catch(...) {} +#endif + try{j.at("guiScale").get_to(guiScale);} catch(...) {} + try{j.at("jumpTransitionTime").get_to(jumpTransitionTime);} catch(...) {} + try{j.at("disableGraphicsDriverWorkarounds").get_to(disableGraphicsDriverWorkarounds);} catch(...) {} + try{j.at("useNativeFilePicker").get_to(useNativeFilePicker);} catch(...) {} + try{j.at("themeInUse").get_to(themeCurrentlyLoaded);} catch(...) {} + if(version >= VersionNumber(0, 3, 0)) + try{j.at("defaultCanvasBackgroundColor").get_to(defaultCanvasBackgroundColor);} catch(...) {} + try{j.at("flipZoomToolDirection").get_to(flipZoomToolDirection);} catch(...) {} +#ifndef __EMSCRIPTEN__ + try{j.at("checkForUpdates").get_to(checkForUpdates);} catch(...) {} +#endif + try{j.at("antialiasing").get_to(antialiasing);} catch(...) {} + + try{j.at("tablet").at("pressureAffectsBrushWidth").get_to(tabletOptions.pressureAffectsBrushWidth);} catch(...) {} + try{j.at("tablet").at("smoothingSamplingTime").get_to(tabletOptions.smoothingSamplingTime);} catch(...) {} + try{j.at("tablet").at("middleClickButton").get_to(tabletOptions.middleClickButton);} catch(...) {} + try{j.at("tablet").at("rightClickButton").get_to(tabletOptions.rightClickButton);} catch(...) {} + try{j.at("tablet").at("ignoreMouseMovementWhenPenInProximity").get_to(tabletOptions.ignoreMouseMovementWhenPenInProximity);} catch(...) {} + try{j.at("tablet").at("brushMinimumSize").get_to(tabletOptions.brushMinimumSize);} catch(...) {} + try{j.at("tablet").at("zoomWhilePenDownAndButtonHeld").get_to(tabletOptions.zoomWhilePenDownAndButtonHeld);} catch(...) {} + + try{j.at("debug").at("showPerformance").get_to(showPerformance);} catch(...) {} + try{j.at("debug").at("fpsLimit").get_to(fpsLimit);} catch(...) {} + try{j.at("debug").at("jumpTransitionEasing").get_to(jumpTransitionEasing);} catch(...) {} + try{j.at("debug").at("imageLoadMaxThreads").get_to(ImageResourceDisplay::IMAGE_LOAD_THREAD_COUNT_MAX);} catch(...) {} + try{j.at("debug").at("cacheNodeResolution").get_to(DrawingProgramCache::CACHE_NODE_RESOLUTION);} catch(...) {} + try{j.at("debug").at("maxCacheNodes").get_to(DrawingProgramCache::MAXIMUM_DRAW_CACHE_SURFACES);} catch(...) {} + try{j.at("debug").at("maxComponentsInNode").get_to(DrawingProgramCache::MAXIMUM_COMPONENTS_IN_SINGLE_NODE);} catch(...) {} + try{j.at("debug").at("componentCountToForceCacheRebuild").get_to(DrawingProgramCache::MINIMUM_COMPONENTS_TO_START_REBUILD);} catch(...) {} + try{j.at("debug").at("maximumFrameTimeToForceCacheRebuild").get_to(DrawingProgramCache::MILLISECOND_FRAME_TIME_TO_FORCE_CACHE_REFRESH);} catch(...) {} + try{j.at("debug").at("millisecondMinimumTimeToCheckForCacheRebuild").get_to(DrawingProgramCache::MILLISECOND_MINIMUM_TIME_TO_CHECK_FORCE_REFRESH);} catch(...) {} +} diff --git a/src/GlobalConfig.hpp b/src/GlobalConfig.hpp new file mode 100644 index 0000000..33ac607 --- /dev/null +++ b/src/GlobalConfig.hpp @@ -0,0 +1,63 @@ +#pragma once +#include +#include +#include "InputManager.hpp" + +#define DEFAULT_CANVAS_BACKGROUND_COLOR Vector3f{0.07f, 0.07f, 0.07f} + +class GlobalConfig { + public: + GlobalConfig(); + + float guiScale = 1.0f; + + double dragZoomSpeed = 0.02; + double scrollZoomSpeed = 0.4; + float jumpTransitionTime = 0.5f; + Vector4f jumpTransitionEasing{0.75, 0.25, 0.25, 0.75}; + bool viewWebVersionWelcome = false; + + struct TabletOptions { + bool pressureAffectsBrushWidth = true; + float smoothingSamplingTime = 0.04f; + uint8_t middleClickButton = 1; + uint8_t rightClickButton = 2; + bool ignoreMouseMovementWhenPenInProximity = false; + float brushMinimumSize = 0.0f; + bool zoomWhilePenDownAndButtonHeld = true; + } tabletOptions; + + Vector3f defaultCanvasBackgroundColor = DEFAULT_CANVAS_BACKGROUND_COLOR; + float fpsLimit = 10000.0f; + + nlohmann::json get_config_json(const InputManager& input) const; + void set_config_json(InputManager& input, const nlohmann::json& j, VersionNumber version); + + bool showPerformance = false; + bool checkForUpdates = false; + bool useNativeFilePicker = true; + + std::string themeCurrentlyLoaded = "Default"; + + enum class AntiAliasing { + NONE, + SKIA, + DYNAMIC_MSAA + } antialiasing = AntiAliasing::DYNAMIC_MSAA; + + std::string displayName; + bool flipZoomToolDirection = false; + + bool disableGraphicsDriverWorkarounds = false; + int vsyncValue = 1; + + #ifndef __EMSCRIPTEN__ + bool applyDisplayScale = true; + #endif +}; + +NLOHMANN_JSON_SERIALIZE_ENUM(GlobalConfig::AntiAliasing, { + {GlobalConfig::AntiAliasing::NONE, "None"}, + {GlobalConfig::AntiAliasing::SKIA, "Skia"}, + {GlobalConfig::AntiAliasing::DYNAMIC_MSAA, "Dynamic MSAA"}, +}) diff --git a/src/InputManager.cpp b/src/InputManager.cpp index b6e16e3..ff150b4 100644 --- a/src/InputManager.cpp +++ b/src/InputManager.cpp @@ -326,7 +326,7 @@ void InputManager::set_clipboard_plain_and_richtext_pair(const std::pair lastCopiedRichText; - std::string key_assignment_to_str(const Vector2ui32& k); - Vector2ui32 key_assignment_from_str(const std::string& s); + std::string key_assignment_to_str(const Vector2ui32& k) const; + Vector2ui32 key_assignment_from_str(const std::string& s) const; const KeyData& key(KeyCode kCode); diff --git a/src/MainProgram.cpp b/src/MainProgram.cpp index 6eb672c..201149b 100755 --- a/src/MainProgram.cpp +++ b/src/MainProgram.cpp @@ -40,8 +40,6 @@ MainProgram::MainProgram(): fonts(std::make_shared()), toolbar(*this) { - displayName = Random::get().alphanumeric_str(10); - Logger::get().add_log("WORLDFATAL", [&](const std::string& text) { *logFile << "[WORLDFATAL] " << text << std::endl; std::cout << "[WORLDFATAL] " << text << std::endl; @@ -65,7 +63,7 @@ MainProgram::MainProgram(): } void MainProgram::update() { - while(std::chrono::duration_cast>(std::chrono::steady_clock::now() - lastFrameTime).count() < 1.0 / fpsLimit); + while(std::chrono::duration_cast>(std::chrono::steady_clock::now() - lastFrameTime).count() < 1.0 / conf.fpsLimit); lastFrameTime = std::chrono::steady_clock::now(); input.update(); @@ -120,7 +118,7 @@ bool MainProgram::app_close_requested() { void MainProgram::update_display_names() { for(auto& w : worlds) { if(!w->netObjMan.is_connected()) - w->ownClientData->set_display_name(displayName); + w->ownClientData->set_display_name(conf.displayName); } } @@ -160,7 +158,7 @@ void MainProgram::save_config() { json j; j["version"] = VersionConstants::CURRENT_VERSION_STRING; - j["settings"] = toolbar.get_config_json(); + j["settings"] = conf.get_config_json(input); j["window"]["pos"] = window.writtenPos; j["window"]["size"] = window.writtenSize; j["window"]["maximized"] = window.maximized; @@ -206,7 +204,7 @@ void MainProgram::load_config() { catch(...) {} try { - toolbar.set_config_json(j["settings"], version); + conf.set_config_json(input, j["settings"], version); } catch(...) {} #ifndef __EMSCRIPTEN__ @@ -238,11 +236,13 @@ void MainProgram::load_config() { toolbar.viewWebVersionWelcome = true; #endif toolbar.load_palettes(); - toolbar.load_theme(); + g.load_theme(configPath, conf.themeCurrentlyLoaded); toolbar.load_licenses(); NetLibrary::copy_default_p2p_config_to_path(configPath / "p2p.json"); + update_display_names(); + set_vsync_value(conf.vsyncValue); refresh_draw_surfaces(); } @@ -255,14 +255,14 @@ void MainProgram::set_vsync_value(int vsyncValue) { } SDL_GL_SetSwapInterval(1); } - window.vsyncValue = vsyncValue; + conf.vsyncValue = vsyncValue; } void MainProgram::update_scale_and_density() { #ifdef __EMSCRIPTEN__ window.scale = 1.0f; #else - window.scale = window.applyDisplayScale ? SDL_GetWindowDisplayScale(window.sdlWindow) : 1.0f; + window.scale = conf.applyDisplayScale ? SDL_GetWindowDisplayScale(window.sdlWindow) : 1.0f; #endif window.density = SDL_GetWindowPixelDensity(window.sdlWindow); } @@ -274,7 +274,7 @@ float MainProgram::get_scale_and_density_factor_gui() { void MainProgram::refresh_draw_surfaces() { if(window.canCreateSurfaces) { window.defaultMSAASampleCount = 0; - window.defaultMSAASurfaceProps = SkSurfaceProps(antialiasing == AntiAliasing::DYNAMIC_MSAA ? SkSurfaceProps::kDynamicMSAA_Flag : SkSurfaceProps::kDefault_Flag, kUnknown_SkPixelGeometry); + window.defaultMSAASurfaceProps = SkSurfaceProps(conf.antialiasing == GlobalConfig::AntiAliasing::DYNAMIC_MSAA ? SkSurfaceProps::kDynamicMSAA_Flag : SkSurfaceProps::kDefault_Flag, kUnknown_SkPixelGeometry); window.intermediateSurface = create_native_surface(window.size, true); window.intermediateCanvas = window.intermediateSurface->getCanvas(); @@ -288,10 +288,8 @@ void MainProgram::refresh_draw_surfaces() { void MainProgram::draw(SkCanvas* canvas, std::shared_ptr worldToDraw, const DrawData& drawData) { canvas->clear(drawData.transparentBackground ? SkColor4f{0.0f, 0.0f, 0.0f, 0.0f} : worldToDraw->canvasTheme.get_back_color()); DrawData drawDataCopy = drawData; - drawDataCopy.skiaAA = antialiasing == AntiAliasing::SKIA; + drawDataCopy.skiaAA = conf.antialiasing == GlobalConfig::AntiAliasing::SKIA; worldToDraw->draw(canvas, drawDataCopy); - if(!drawData.takingScreenshot) - toolbar.draw(canvas, drawDataCopy.skiaAA); } sk_sp MainProgram::create_native_surface(Vector2i resolution, bool isMSAA) { @@ -348,25 +346,21 @@ void MainProgram::input_key_callback(const InputManager::KeyCallbackArgs& key) { drawGui = !drawGui; } } - toolbar.input_key_callback(key); if(world) world->input_key_callback(key); } void MainProgram::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) { - toolbar.input_mouse_button_callback(button); if(world) world->input_mouse_button_callback(button); } void MainProgram::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) { - toolbar.input_mouse_motion_callback(motion); if(world) world->input_mouse_motion_callback(motion); } void MainProgram::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel) { - toolbar.input_mouse_wheel_callback(wheel); if(world) world->input_mouse_wheel_callback(wheel); } @@ -402,11 +396,9 @@ void MainProgram::input_multi_finger_motion_callback(const InputManager::MultiFi } void MainProgram::input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) { - toolbar.input_finger_touch_callback(touch); } void MainProgram::input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) { - toolbar.input_finger_motion_callback(motion); } bool MainProgram::network_being_used() { diff --git a/src/MainProgram.hpp b/src/MainProgram.hpp index 8fa6431..d8f9897 100644 --- a/src/MainProgram.hpp +++ b/src/MainProgram.hpp @@ -12,6 +12,8 @@ #include "Toolbar.hpp" #include "World.hpp" #include "DrawingProgram/ToolConfiguration.hpp" +#include "GUIHolder.hpp" +#include "GlobalConfig.hpp" #ifdef USE_SKIA_BACKEND_GRAPHITE #include "include/gpu/graphite/Recorder.h" @@ -28,7 +30,6 @@ class MainProgram { InputManager input; std::chrono::steady_clock::time_point lastFrameTime = std::chrono::steady_clock::now(); - float fpsLimit = 10000.0f; Vector3f userColor; @@ -42,15 +43,9 @@ class MainProgram { bool fullscreen = false; SkColorType defaultColorType; SkAlphaType defaultAlphaType; - int vsyncValue = 1; float density = 1.0f; float scale = 1.0f; - #ifndef __EMSCRIPTEN__ - bool applyDisplayScale = true; - #endif - - bool disableGraphicsDriverWorkarounds = false; int defaultMSAASampleCount = 0; SkSurfaceProps defaultMSAASurfaceProps; @@ -92,12 +87,6 @@ class MainProgram { sk_sp create_native_surface(Vector2i resolution, bool isMSAA); bool setToQuit = false; - - enum class AntiAliasing { - NONE, - SKIA, - DYNAMIC_MSAA - } antialiasing = AntiAliasing::DYNAMIC_MSAA; void early_destroy(); @@ -124,12 +113,11 @@ class MainProgram { bool drawGui = true; - Vector3f defaultCanvasBackgroundColor = DEFAULT_CANVAS_BACKGROUND_COLOR; - size_t worldIndex = 0; std::vector> worlds; - std::string displayName; + GUIHolder g; + GlobalConfig conf; void input_drop_file_callback(const InputManager::DropCallbackArgs& drop); void input_drop_text_callback(const InputManager::DropCallbackArgs& drop); @@ -159,9 +147,3 @@ class MainProgram { void gui(); void draw_grid(SkCanvas* canvas); }; - -NLOHMANN_JSON_SERIALIZE_ENUM(MainProgram::AntiAliasing, { - {MainProgram::AntiAliasing::NONE, "None"}, - {MainProgram::AntiAliasing::SKIA, "Skia"}, - {MainProgram::AntiAliasing::DYNAMIC_MSAA, "Dynamic MSAA"}, -}) diff --git a/src/ResourceDisplay/FileResourceDisplay.cpp b/src/ResourceDisplay/FileResourceDisplay.cpp index 8368051..1e138ba 100644 --- a/src/ResourceDisplay/FileResourceDisplay.cpp +++ b/src/ResourceDisplay/FileResourceDisplay.cpp @@ -23,10 +23,10 @@ bool FileResourceDisplay::load(ResourceManager& rMan, const std::string& fileNam } void FileResourceDisplay::draw(SkCanvas* canvas, const DrawData& drawData, const SkRect& imRect) { - std::shared_ptr& io = drawData.main->toolbar.io; - auto findSVGData = io->svgData.find(FILE_ICON_PATH); + GUIStuff::UpdateInputData& io = drawData.main->g.gui.io; + auto findSVGData = io.svgData.find(FILE_ICON_PATH); sk_sp svgDom; - if(findSVGData == io->svgData.end()) + if(findSVGData == io.svgData.end()) throw std::runtime_error("[FileResourceDisplay::draw] Could not load icon " + FILE_ICON_PATH); else svgDom = findSVGData->second; diff --git a/src/Toolbar.cpp b/src/Toolbar.cpp index 2302748..c7468a0 100644 --- a/src/Toolbar.cpp +++ b/src/Toolbar.cpp @@ -64,94 +64,11 @@ using namespace GUIStuff; using namespace ElementHelpers; Toolbar::Toolbar(MainProgram& initMain): - io(std::make_shared()), main(initMain) { - io->textTypeface = main.fonts->map["Roboto"]; - io->fonts = main.fonts; - io->layoutRun = [&] { - layout_run(); - }; - io->input = &main.input; - gui.io = io; - - // NOTE: On windows, when the native file picker is open, any call to MakeFromFile fails - // So, it's better to load the icons at the beginning of the program so that the icon loading doesn't fail later - load_icons_at("data/icons"); - -#ifdef __ANDROID__ - load_icons_at("data/icons/RemixIcon"); // SDL_GlobDirectory doesn't work recursively on Android -#endif - load_default_palette(); - load_default_theme(); } -void Toolbar::load_icons_at(const std::filesystem::path& pathToLoad) { - int globCount; - char** filesInPath = SDL_GlobDirectory(pathToLoad.c_str(), nullptr, 0, &globCount); - if(filesInPath) { - for(int i = 0; i < globCount; i++) { - std::filesystem::path filePath = pathToLoad / std::filesystem::path(filesInPath[i]); - SDL_PathInfo fileInfo; - if(SDL_GetPathInfo(filePath.c_str(), &fileInfo) && fileInfo.type == SDL_PATHTYPE_FILE) { - std::string iconRelativePath = filePath.relative_path().string(); - std::replace(iconRelativePath.begin(), iconRelativePath.end(), '\\', '/'); - std::string iconData = read_file_to_string(iconRelativePath); - auto stream = SkMemoryStream(iconData.c_str(), iconData.size(), false); - auto svgDom = SkSVGDOM::Builder().make(stream); - if(!svgDom) - throw std::runtime_error("[Toolbar::Toolbar] Could not parse SVG " + iconRelativePath); - else { - if(svgDom->containerSize().width() == 0 || svgDom->containerSize().height() == 0) - svgDom->setContainerSize({1000, 1000}); - io->svgData[iconRelativePath] = svgDom; - } - } - } - SDL_free(filesInPath); - } -} - -void Toolbar::load_default_theme() { - io->theme = GUIStuff::get_default_dark_mode(); - themeData.themeCurrentlyLoaded = "Default"; -} - -void Toolbar::save_theme() { - std::filesystem::create_directory(main.configPath / "themes"); - std::ofstream f(main.configPath / "themes" / (themeData.themeCurrentlyLoaded + ".json")); - if(f.is_open()) { - using json = nlohmann::json; - json j; - j = *io->theme; - f << j; - f.close(); - } -} - -bool Toolbar::load_theme() { - std::filesystem::path themeDir = main.configPath / "themes"; - bool successfullyLoaded = false; - if(std::filesystem::exists(themeDir) && std::filesystem::is_directory(themeDir)) { - std::ifstream f(themeDir / (themeData.themeCurrentlyLoaded + ".json")); - if(f.is_open()) { - using json = nlohmann::json; - try { - json j; - f >> j; - auto theme(std::make_shared()); - j.get_to(*theme); - io->theme = theme; - successfullyLoaded = true; - } catch(...) {} - f.close(); - } - } - if(!successfullyLoaded) - load_default_theme(); - return successfullyLoaded; -} void Toolbar::load_default_palette() { paletteData.palettes.clear(); @@ -210,7 +127,7 @@ void Toolbar::sdl_open_file_dialog_callback(void* userData, const char * const * } void Toolbar::open_file_selector(const std::string& filePickerName, const std::vector& extensionFilters, OpenFileSelectorCallback postSelectionFunc, const std::string& fileName, bool isSaving) { - if(useNativeFilePicker) { + if(main.conf.useNativeFilePicker) { if(!nativeFilePicker.isOpen) { nativeFilePicker.postSelectionFunc = postSelectionFunc; nativeFilePicker.extensionFiltersComplete = extensionFilters; @@ -285,144 +202,20 @@ THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR I )"; } -nlohmann::json Toolbar::get_config_json() { - using json = nlohmann::json; - json toRet; - - json jKeybinds; - for(unsigned i = 0; i < InputManager::KEY_ASSIGNABLE_COUNT; i++) { - auto f = std::find_if(main.input.keyAssignments.begin(), main.input.keyAssignments.end(), [&](auto& p) { - return p.second == i; - }); - if(f != main.input.keyAssignments.end()) - jKeybinds[json(static_cast(i))] = main.input.key_assignment_to_str(f->first); - } - toRet["keybinds"] = jKeybinds; - toRet["guiScale"] = guiScale; - toRet["jumpTransitionTime"] = jumpTransitionTime; - toRet["disableGraphicsDriverWorkarounds"] = main.window.disableGraphicsDriverWorkarounds; - toRet["dragZoomSpeed"] = dragZoomSpeed; - toRet["scrollZoomSpeed"] = scrollZoomSpeed; - toRet["vsync"] = main.window.vsyncValue; -#ifndef __EMSCRIPTEN__ - toRet["applyDisplayScale"] = main.window.applyDisplayScale; -#endif - toRet["displayName"] = main.displayName; - toRet["antialiasing"] = main.antialiasing; - toRet["useNativeFilePicker"] = useNativeFilePicker; - toRet["themeInUse"] = themeData.themeCurrentlyLoaded; - toRet["defaultCanvasBackgroundColor"] = main.defaultCanvasBackgroundColor; - toRet["flipZoomToolDirection"] = flipZoomToolDirection; -#ifndef __EMSCRIPTEN__ - toRet["checkForUpdates"] = updateCheckerData.checkForUpdates; -#endif - - json tablet; - tablet["pressureAffectsBrushWidth"] = tabletOptions.pressureAffectsBrushWidth; - tablet["smoothingSamplingTime"] = tabletOptions.smoothingSamplingTime; - tablet["middleClickButton"] = tabletOptions.middleClickButton; - tablet["rightClickButton"] = tabletOptions.rightClickButton; - tablet["ignoreMouseMovementWhenPenInProximity"] = tabletOptions.ignoreMouseMovementWhenPenInProximity; - tablet["brushMinimumSize"] = tabletOptions.brushMinimumSize; - tablet["zoomWhilePenDownAndButtonHeld"] = tabletOptions.zoomWhilePenDownAndButtonHeld; - toRet["tablet"] = tablet; - - json debugJson; - debugJson["showPerformance"] = showPerformance; - debugJson["fpsLimit"] = main.fpsLimit; - debugJson["jumpTransitionEasing"] = jumpTransitionEasing; - debugJson["imageLoadMaxThreads"] = ImageResourceDisplay::IMAGE_LOAD_THREAD_COUNT_MAX; - debugJson["cacheNodeResolution"] = DrawingProgramCache::CACHE_NODE_RESOLUTION; - debugJson["maxCacheNodes"] = DrawingProgramCache::MAXIMUM_DRAW_CACHE_SURFACES; - debugJson["maxComponentsInNode"] = DrawingProgramCache::MAXIMUM_COMPONENTS_IN_SINGLE_NODE; - debugJson["componentCountToForceCacheRebuild"] = DrawingProgramCache::MINIMUM_COMPONENTS_TO_START_REBUILD; - debugJson["maximumFrameTimeToForceCacheRebuild"] = DrawingProgramCache::MILLISECOND_FRAME_TIME_TO_FORCE_CACHE_REFRESH; - debugJson["millisecondMinimumTimeToCheckForCacheRebuild"] = DrawingProgramCache::MILLISECOND_MINIMUM_TIME_TO_CHECK_FORCE_REFRESH; - toRet["debug"] = debugJson; - - return toRet; -} - -void Toolbar::set_config_json(const nlohmann::json& j, VersionNumber version) { - using json = nlohmann::json; - main.input.keyAssignments.clear(); - try { - const json& jKeybinds = j.at("keybinds"); - for(unsigned i = 0; i < InputManager::KEY_ASSIGNABLE_COUNT; i++) { - try { - Vector2ui32 a = main.input.key_assignment_from_str(jKeybinds.at(json(static_cast(i)))); - if(a != Vector2ui32{0, 0}) - main.input.keyAssignments.emplace(a, i); - else - throw; - } - catch(...) { - auto f = std::find_if(main.input.defaultKeyAssignments.begin(), main.input.defaultKeyAssignments.end(), [&](auto& p) { - return p.second == i; - }); - main.input.keyAssignments.emplace(f->first, i); - } - } - } - catch(...) { - main.input.keyAssignments = main.input.defaultKeyAssignments; - } - try{j.at("displayName").get_to(main.displayName);} catch(...) {} - try{j.at("dragZoomSpeed").get_to(dragZoomSpeed);} catch(...) {} - try{j.at("scrollZoomSpeed").get_to(scrollZoomSpeed);} catch(...) {} - try { - j.at("vsync").get_to(main.window.vsyncValue); - main.set_vsync_value(main.window.vsyncValue); - } - catch(...) { - main.set_vsync_value(1); - } -#ifndef __EMSCRIPTEN__ - try{j.at("applyDisplayScale").get_to(main.window.applyDisplayScale);} catch(...) {} -#endif - try{j.at("guiScale").get_to(guiScale);} catch(...) {} - try{j.at("jumpTransitionTime").get_to(jumpTransitionTime);} catch(...) {} - try{j.at("disableGraphicsDriverWorkarounds").get_to(main.window.disableGraphicsDriverWorkarounds);} catch(...) {} - try{j.at("useNativeFilePicker").get_to(useNativeFilePicker);} catch(...) {} - try{j.at("themeInUse").get_to(themeData.themeCurrentlyLoaded);} catch(...) {} - if(version >= VersionNumber(0, 3, 0)) - try{j.at("defaultCanvasBackgroundColor").get_to(main.defaultCanvasBackgroundColor);} catch(...) {} - try{j.at("flipZoomToolDirection").get_to(flipZoomToolDirection);} catch(...) {} -#ifndef __EMSCRIPTEN__ - try{j.at("checkForUpdates").get_to(updateCheckerData.checkForUpdates);} catch(...) {} -#endif - try{j.at("antialiasing").get_to(main.antialiasing);} catch(...) {} - - try{j.at("tablet").at("pressureAffectsBrushWidth").get_to(tabletOptions.pressureAffectsBrushWidth);} catch(...) {} - try{j.at("tablet").at("smoothingSamplingTime").get_to(tabletOptions.smoothingSamplingTime);} catch(...) {} - try{j.at("tablet").at("middleClickButton").get_to(tabletOptions.middleClickButton);} catch(...) {} - try{j.at("tablet").at("rightClickButton").get_to(tabletOptions.rightClickButton);} catch(...) {} - try{j.at("tablet").at("ignoreMouseMovementWhenPenInProximity").get_to(tabletOptions.ignoreMouseMovementWhenPenInProximity);} catch(...) {} - try{j.at("tablet").at("brushMinimumSize").get_to(tabletOptions.brushMinimumSize);} catch(...) {} - try{j.at("tablet").at("zoomWhilePenDownAndButtonHeld").get_to(tabletOptions.zoomWhilePenDownAndButtonHeld);} catch(...) {} - - try{j.at("debug").at("showPerformance").get_to(showPerformance);} catch(...) {} - try{j.at("debug").at("fpsLimit").get_to(main.fpsLimit);} catch(...) {} - try{j.at("debug").at("jumpTransitionEasing").get_to(jumpTransitionEasing);} catch(...) {} - try{j.at("debug").at("imageLoadMaxThreads").get_to(ImageResourceDisplay::IMAGE_LOAD_THREAD_COUNT_MAX);} catch(...) {} - try{j.at("debug").at("cacheNodeResolution").get_to(DrawingProgramCache::CACHE_NODE_RESOLUTION);} catch(...) {} - try{j.at("debug").at("maxCacheNodes").get_to(DrawingProgramCache::MAXIMUM_DRAW_CACHE_SURFACES);} catch(...) {} - try{j.at("debug").at("maxComponentsInNode").get_to(DrawingProgramCache::MAXIMUM_COMPONENTS_IN_SINGLE_NODE);} catch(...) {} - try{j.at("debug").at("componentCountToForceCacheRebuild").get_to(DrawingProgramCache::MINIMUM_COMPONENTS_TO_START_REBUILD);} catch(...) {} - try{j.at("debug").at("maximumFrameTimeToForceCacheRebuild").get_to(DrawingProgramCache::MILLISECOND_FRAME_TIME_TO_FORCE_CACHE_REFRESH);} catch(...) {} - try{j.at("debug").at("millisecondMinimumTimeToCheckForCacheRebuild").get_to(DrawingProgramCache::MILLISECOND_MINIMUM_TIME_TO_CHECK_FORCE_REFRESH);} catch(...) {} - - main.update_display_names(); -} - void Toolbar::update() { + auto& gui = main.g.gui; + auto& io = gui.io; + calculate_final_gui_scale(); - io->windowSize = main.window.size.cast(); - io->windowPos = {0, 0}; + io.windowSize = main.window.size.cast(); + io.windowPos = {0, 0}; gui.layout_if_necessary(); } void Toolbar::layout_run() { + auto& gui = main.g.gui; + auto& io = gui.io; + #ifndef __EMSCRIPTEN__ update_notification_check(); #endif @@ -430,9 +223,9 @@ void Toolbar::layout_run() { if(main.drawGui) { CLAY_AUTO_ID({ .layout = { - .sizing = {.width = CLAY_SIZING_FIT(gui.io->windowSize.x()), .height = CLAY_SIZING_FIT(gui.io->windowSize.y())}, - .padding = CLAY_PADDING_ALL(io->theme->padding1), - .childGap = io->theme->childGap1, + .sizing = {.width = CLAY_SIZING_FIT(gui.io.windowSize.x()), .height = CLAY_SIZING_FIT(gui.io.windowSize.y())}, + .padding = CLAY_PADDING_ALL(io.theme->padding1), + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM } @@ -442,7 +235,7 @@ void Toolbar::layout_run() { drawing_program_gui(); if(!closePopupData.worldsToClose.empty()) close_popup_gui(); - if(viewWebVersionWelcome) + if(main.conf.viewWebVersionWelcome) web_version_welcome(); #ifndef __EMSCRIPTEN__ else if(updateCheckerData.showGui) @@ -471,7 +264,7 @@ void Toolbar::layout_run() { } if(!main.world->clientStillConnecting) { - //if(io->hoverObstructed && (io->mouse.leftClick || io->mouse.rightClick)) + //if(io.hoverObstructed && (io.mouse.leftClick || io.mouse.rightClick)) // rightClickPopupLocation = std::nullopt; //if(rightClickPopupLocation.has_value()) { @@ -479,7 +272,7 @@ void Toolbar::layout_run() { // rightClickPopupLocation = std::nullopt; //} - //if(io->hoverObstructed && io->mouse.rightClick) // This runs specifically if the paint popup has the cursor + //if(io.hoverObstructed && io.mouse.rightClick) // This runs specifically if the paint popup has the cursor // rightClickPopupLocation = std::nullopt; } @@ -510,19 +303,22 @@ void Toolbar::add_world_to_close_popup_data(const std::shared_ptr& w) { } void Toolbar::close_popup_gui() { + auto& gui = main.g.gui; + auto& io = gui.io; + std::erase_if(closePopupData.worldsToClose, [](auto& wPair) { return wPair.w.expired(); }); CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0, 600) }, - .padding = CLAY_PADDING_ALL(io->theme->padding1), - .childGap = io->theme->childGap1, + .padding = CLAY_PADDING_ALL(io.theme->padding1), + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, - .backgroundColor = convert_vec4(io->theme->backColor1), - .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), + .backgroundColor = convert_vec4(io.theme->backColor1), + .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1), .floating = {.zIndex = 1, .attachPoints = {.element = CLAY_ATTACH_POINT_CENTER_CENTER, .parent = CLAY_ATTACH_POINT_CENTER_CENTER}, .attachTo = CLAY_ATTACH_TO_PARENT} }) { gui.new_id("Close single file popup gui", [&] { @@ -534,7 +330,7 @@ void Toolbar::close_popup_gui() { .innerContent = [&](const ScrollArea::InnerContentParameters&) { CLAY_AUTO_ID({ .layout = { - .childGap = io->theme->childGap1, + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM } @@ -545,13 +341,13 @@ void Toolbar::close_popup_gui() { CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) }, - .padding = CLAY_PADDING_ALL(io->theme->padding1), - .childGap = io->theme->childGap1, + .padding = CLAY_PADDING_ALL(io.theme->padding1), + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER}, .layoutDirection = CLAY_LEFT_TO_RIGHT }, - .backgroundColor = convert_vec4(io->theme->backColor2), - .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), + .backgroundColor = convert_vec4(io.theme->backColor2), + .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1), }) { gui.new_id(i, [&] { checkbox_boolean(gui, "set to save checkbox", &setToSave); @@ -633,6 +429,9 @@ void Toolbar::save_as_func() { } void Toolbar::paint_popup(Vector2f popupPos) { + auto& gui = main.g.gui; + auto& io = main.g.gui.io; + double newRotationAngle = 0.0; paint_circle_popup_menu(gui, "paint circle popup", popupPos, { .rotationAngle = &main.world->drawData.cam.c.rotation, @@ -648,16 +447,19 @@ void Toolbar::paint_popup(Vector2f popupPos) { } void Toolbar::top_toolbar() { + auto& gui = main.g.gui; + auto& io = gui.io; + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) }, - .padding = CLAY_PADDING_ALL(static_cast(io->theme->padding1 / 2)), - .childGap = static_cast(io->theme->childGap1 / 2), + .padding = CLAY_PADDING_ALL(static_cast(io.theme->padding1 / 2)), + .childGap = static_cast(io.theme->childGap1 / 2), .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER}, .layoutDirection = CLAY_LEFT_TO_RIGHT }, - .backgroundColor = convert_vec4(io->theme->backColor1), - .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1) + .backgroundColor = convert_vec4(io.theme->backColor1), + .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1) }) { gui.new_id("menu top toolbar", [&] { global_log(); @@ -760,14 +562,14 @@ void Toolbar::top_toolbar() { CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(100), .height = CLAY_SIZING_FIT(0) }, - .padding = CLAY_PADDING_ALL(io->theme->padding1), + .padding = CLAY_PADDING_ALL(io.theme->padding1), .childGap = 1, .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, - .backgroundColor = convert_vec4(io->theme->backColor1), - .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), - .floating = {.offset = {.x = 0, .y = static_cast(io->theme->padding1)}, .attachPoints = {.element = CLAY_ATTACH_POINT_LEFT_TOP, .parent = CLAY_ATTACH_POINT_LEFT_BOTTOM}, .attachTo = CLAY_ATTACH_TO_PARENT} + .backgroundColor = convert_vec4(io.theme->backColor1), + .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1), + .floating = {.offset = {.x = 0, .y = static_cast(io.theme->padding1)}, .attachPoints = {.element = CLAY_ATTACH_POINT_LEFT_TOP, .parent = CLAY_ATTACH_POINT_LEFT_BOTTOM}, .attachTo = CLAY_ATTACH_TO_PARENT} }) { auto menu_popup_text_button = [&](const char* id, const char* str, const std::function& onClick) { text_button(gui, id, str, { @@ -864,16 +666,19 @@ void Toolbar::top_toolbar() { } void Toolbar::web_version_welcome() { + auto& gui = main.g.gui; + auto& io = gui.io; + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(700), .height = CLAY_SIZING_FIT(0) }, - .padding = CLAY_PADDING_ALL(io->theme->padding1), - .childGap = io->theme->childGap1, + .padding = CLAY_PADDING_ALL(io.theme->padding1), + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, - .backgroundColor = convert_vec4(io->theme->backColor1), - .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), + .backgroundColor = convert_vec4(io.theme->backColor1), + .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1), .floating = {.attachPoints = {.element = CLAY_ATTACH_POINT_CENTER_CENTER, .parent = CLAY_ATTACH_POINT_CENTER_CENTER}, .attachTo = CLAY_ATTACH_TO_PARENT} }) { gui.new_id("web version welcome gui", [&] { @@ -890,7 +695,7 @@ If you like this app, consider downloading the native version for your system)") text_button(gui, "got it", "Got It", { .wide = true, .onClick = [&] { - viewWebVersionWelcome = false; + main.conf.viewWebVersionWelcome = false; } }); }); @@ -898,16 +703,19 @@ If you like this app, consider downloading the native version for your system)") } void Toolbar::still_connecting_center_message() { + auto& gui = main.g.gui; + auto& io = gui.io; + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0) }, - .padding = CLAY_PADDING_ALL(io->theme->padding1), - .childGap = io->theme->childGap1, + .padding = CLAY_PADDING_ALL(io.theme->padding1), + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, - .backgroundColor = convert_vec4(io->theme->backColor1), - .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), + .backgroundColor = convert_vec4(io.theme->backColor1), + .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1), .floating = {.attachPoints = {.element = CLAY_ATTACH_POINT_CENTER_CENTER, .parent = CLAY_ATTACH_POINT_CENTER_CENTER}, .attachTo = CLAY_ATTACH_TO_PARENT} }) { text_label(gui, "Connecting to server..."); @@ -915,16 +723,19 @@ void Toolbar::still_connecting_center_message() { } void Toolbar::no_layers_being_edited_message() { + auto& gui = main.g.gui; + auto& io = gui.io; + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0) }, - .padding = CLAY_PADDING_ALL(io->theme->padding1), - .childGap = io->theme->childGap1, + .padding = CLAY_PADDING_ALL(io.theme->padding1), + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, - .backgroundColor = convert_vec4(io->theme->backColor1), - .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), + .backgroundColor = convert_vec4(io.theme->backColor1), + .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1), .floating = {.attachPoints = {.element = CLAY_ATTACH_POINT_CENTER_CENTER, .parent = CLAY_ATTACH_POINT_CENTER_CENTER}, .attachTo = CLAY_ATTACH_TO_PARENT} }) { text_label(gui, "Select a layer to edit"); @@ -934,7 +745,7 @@ void Toolbar::no_layers_being_edited_message() { #ifndef __EMSCRIPTEN__ void Toolbar::update_notification_check() { if(!updateCheckerData.updateCheckDone) { - if(updateCheckerData.checkForUpdates) { + if(main.conf.checkForUpdates) { if(!updateCheckerData.versionFile) updateCheckerData.versionFile = FileDownloader::download_data_from_url(UPDATE_NOTIFICATION_URL); else { @@ -976,16 +787,19 @@ void Toolbar::update_notification_check() { } void Toolbar::update_notification_gui() { + auto& gui = main.g.gui; + auto& io = gui.io; + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(700), .height = CLAY_SIZING_FIT(0) }, - .padding = CLAY_PADDING_ALL(io->theme->padding1), - .childGap = io->theme->childGap1, + .padding = CLAY_PADDING_ALL(io.theme->padding1), + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, - .backgroundColor = convert_vec4(io->theme->backColor1), - .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), + .backgroundColor = convert_vec4(io.theme->backColor1), + .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1), .floating = {.attachPoints = {.element = CLAY_ATTACH_POINT_CENTER_CENTER, .parent = CLAY_ATTACH_POINT_CENTER_CENTER}, .attachTo = CLAY_ATTACH_TO_PARENT} }) { gui.new_id("update notification gui", [&] { @@ -1000,7 +814,7 @@ void Toolbar::update_notification_gui() { text_button(gui, "ignore forever", "Ignore and don't notify again (can be changed in settings)", { .wide = true, .onClick = [&]{ - updateCheckerData.checkForUpdates = false; + main.conf.checkForUpdates = false; updateCheckerData.showGui = false; } }); @@ -1016,19 +830,22 @@ void Toolbar::update_notification_gui() { #endif void Toolbar::grid_menu(bool justOpened) { + auto& gui = main.g.gui; + auto& io = gui.io; + if(main.world->gridMan.grids) { gui.new_id("grid menu", [&] { //CLAY(localId, { // .layout = { // .sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0, 600) }, - // .padding = CLAY_PADDING_ALL(io->theme->padding1), - // .childGap = io->theme->childGap1, + // .padding = CLAY_PADDING_ALL(io.theme->padding1), + // .childGap = io.theme->childGap1, // .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, // .layoutDirection = CLAY_TOP_TO_BOTTOM // }, - // .backgroundColor = convert_vec4(io->theme->backColor1), - // .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), - // .floating = {.offset = {.x = 0, .y = static_cast(io->theme->padding1)}, .attachPoints = {.element = CLAY_ATTACH_POINT_RIGHT_TOP, .parent = CLAY_ATTACH_POINT_RIGHT_BOTTOM}, .attachTo = CLAY_ATTACH_TO_PARENT} + // .backgroundColor = convert_vec4(io.theme->backColor1), + // .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1), + // .floating = {.offset = {.x = 0, .y = static_cast(io.theme->padding1)}, .attachPoints = {.element = CLAY_ATTACH_POINT_RIGHT_TOP, .parent = CLAY_ATTACH_POINT_RIGHT_BOTTOM}, .attachTo = CLAY_ATTACH_TO_PARENT} //}) { // gui.obstructing_window(localId); // text_label_centered(gui, "Grids"); @@ -1046,7 +863,7 @@ void Toolbar::grid_menu(bool justOpened) { // .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER}, // .layoutDirection = CLAY_LEFT_TO_RIGHT // }, - // .backgroundColor = selectedEntry ? convert_vec4(io->theme->backColor1) : convert_vec4(io->theme->backColor2) + // .backgroundColor = selectedEntry ? convert_vec4(io.theme->backColor1) : convert_vec4(io.theme->backColor2) // }) { // text_label(gui, grid->get_display_name()); // bool miniButtonClicked = false; @@ -1073,9 +890,9 @@ void Toolbar::grid_menu(bool justOpened) { // toDelete = i; // } // } - // if(Clay_Hovered() && io->mouse.leftClick && isListHovered && !miniButtonClicked) { + // if(Clay_Hovered() && io.mouse.leftClick && isListHovered && !miniButtonClicked) { // gridMenu.selectedGrid = i; - // if(io->mouse.leftClick >= 2) { + // if(io.mouse.leftClick >= 2) { // main.world->drawProg.modify_grid(grid); // stop_displaying_grid_menu(); // } @@ -1087,7 +904,7 @@ void Toolbar::grid_menu(bool justOpened) { // gui.left_to_right_line_layout([&]() { // bool addByEnter = false; // gui.input_text("grid text input", &gridMenu.newName, true, [&](GUIStuff::SelectionHelper& s) { - // addByEnter = s.selected && io->key.enter; + // addByEnter = s.selected && io.key.enter; // }); // if(gui.svg_icon_button("grid add button", "data/icons/plusbold.svg", false, GUIStuff::GUIManager::SMALL_BUTTON_SIZE) || (addByEnter && !gridMenu.newName.empty())) { // main.world->gridMan.add_default_grid(gridMenu.newName); @@ -1097,7 +914,7 @@ void Toolbar::grid_menu(bool justOpened) { // }); // bool dropdownHover = false; - // if(io->mouse.leftClick && !Clay_Hovered() && !justOpened && !dropdownHover) + // if(io.mouse.leftClick && !Clay_Hovered() && !justOpened && !dropdownHover) // stop_displaying_grid_menu(); //} }); @@ -1111,24 +928,27 @@ void Toolbar::stop_displaying_grid_menu() { } void Toolbar::bookmark_menu(bool justOpened) { + auto& gui = main.g.gui; + auto& io = gui.io; + gui.new_id("bookmark menu", [&] { //Clay_ElementId localId = CLAY_ID_LOCAL("INFINIPAINT BOOKMARK MENU"); //CLAY(localId, { // .layout = { // .sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0, 600) }, - // .padding = CLAY_PADDING_ALL(io->theme->padding1), - // .childGap = io->theme->childGap1, + // .padding = CLAY_PADDING_ALL(io.theme->padding1), + // .childGap = io.theme->childGap1, // .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, // .layoutDirection = CLAY_TOP_TO_BOTTOM // }, - // .backgroundColor = convert_vec4(io->theme->backColor1), - // .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), - // .floating = {.offset = {.x = 0, .y = static_cast(io->theme->padding1)}, .attachPoints = {.element = CLAY_ATTACH_POINT_RIGHT_TOP, .parent = CLAY_ATTACH_POINT_RIGHT_BOTTOM}, .attachTo = CLAY_ATTACH_TO_PARENT} + // .backgroundColor = convert_vec4(io.theme->backColor1), + // .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1), + // .floating = {.offset = {.x = 0, .y = static_cast(io.theme->padding1)}, .attachPoints = {.element = CLAY_ATTACH_POINT_RIGHT_TOP, .parent = CLAY_ATTACH_POINT_RIGHT_BOTTOM}, .attachTo = CLAY_ATTACH_TO_PARENT} //}) { // gui.obstructing_window(localId); // text_label_centered(gui, "Bookmarks"); // main.world->bMan.setup_list_gui("bookmark menu list"); - // if(io->mouse.leftClick && !Clay_Hovered() && !justOpened) { + // if(io.mouse.leftClick && !Clay_Hovered() && !justOpened) { // bookmarkMenuPopupOpen = false; // main.world->bMan.refresh_gui_data(); // } @@ -1137,25 +957,28 @@ void Toolbar::bookmark_menu(bool justOpened) { } void Toolbar::layer_menu(bool justOpened) { + auto& gui = main.g.gui; + auto& io = gui.io; + gui.new_id("layer menu", [&] { //Clay_ElementId localId = CLAY_ID_LOCAL("INFINIPAINT LAYER MENU"); //CLAY(localId, { // .layout = { // .sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0, 600) }, - // .padding = CLAY_PADDING_ALL(io->theme->padding1), - // .childGap = io->theme->childGap1, + // .padding = CLAY_PADDING_ALL(io.theme->padding1), + // .childGap = io.theme->childGap1, // .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, // .layoutDirection = CLAY_TOP_TO_BOTTOM // }, - // .backgroundColor = convert_vec4(io->theme->backColor1), - // .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), - // .floating = {.offset = {.x = 0, .y = static_cast(io->theme->padding1)}, .attachPoints = {.element = CLAY_ATTACH_POINT_RIGHT_TOP, .parent = CLAY_ATTACH_POINT_RIGHT_BOTTOM}, .attachTo = CLAY_ATTACH_TO_PARENT} + // .backgroundColor = convert_vec4(io.theme->backColor1), + // .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1), + // .floating = {.offset = {.x = 0, .y = static_cast(io.theme->padding1)}, .attachPoints = {.element = CLAY_ATTACH_POINT_RIGHT_TOP, .parent = CLAY_ATTACH_POINT_RIGHT_BOTTOM}, .attachTo = CLAY_ATTACH_TO_PARENT} //}) { // gui.obstructing_window(localId); // text_label_centered(gui, "Layers"); // bool hoveringOverDropdown = false; // main.world->drawProg.layerMan.listGUI.setup_list_gui("layer menu list", hoveringOverDropdown); - // if(io->mouse.leftClick && !Clay_Hovered() && !justOpened && !hoveringOverDropdown) { + // if(io.mouse.leftClick && !Clay_Hovered() && !justOpened && !hoveringOverDropdown) { // layerMenuPopupOpen = false; // main.world->drawProg.layerMan.listGUI.refresh_gui_data(); // } @@ -1164,16 +987,19 @@ void Toolbar::layer_menu(bool justOpened) { } std::unique_ptr Toolbar::build_paragraph_from_chat_message(const ChatMessage& message, float alpha) { + auto& gui = main.g.gui; + auto& io = gui.io; + skia::textlayout::ParagraphStyle pStyle; pStyle.setTextAlign(skia::textlayout::TextAlign::kLeft); skia::textlayout::TextStyle tStyle; - tStyle.setFontSize(io->fontSize); + tStyle.setFontSize(io.fontSize); tStyle.setFontFamilies(main.fonts->get_default_font_families()); tStyle.setFontStyle(SkFontStyle::Bold()); - tStyle.setForegroundColor(SkPaint{color_mul_alpha(message.type == ChatMessage::JOIN ? io->theme->warningColor : io->theme->frontColor1, alpha)}); + tStyle.setForegroundColor(SkPaint{color_mul_alpha(message.type == ChatMessage::JOIN ? io.theme->warningColor : io.theme->frontColor1, alpha)}); pStyle.setTextStyle(tStyle); - skia::textlayout::ParagraphBuilderImpl a(pStyle, io->fonts->collection, SkUnicodes::ICU::Make()); + skia::textlayout::ParagraphBuilderImpl a(pStyle, io.fonts->collection, SkUnicodes::ICU::Make()); if(message.type == ChatMessage::JOIN) { std::string messageName = message.name + " "; a.addText(messageName.c_str(), messageName.length()); @@ -1198,7 +1024,7 @@ void Toolbar::chat_box() { // .layout = { // .layoutDirection = CLAY_LEFT_TO_RIGHT // }, - // .floating = {.offset = {static_cast(io->theme->padding1), -static_cast(io->theme->padding1)}, .attachPoints = {.element = CLAY_ATTACH_POINT_LEFT_BOTTOM, .parent = CLAY_ATTACH_POINT_LEFT_BOTTOM}, .attachTo = CLAY_ATTACH_TO_PARENT} + // .floating = {.offset = {static_cast(io.theme->padding1), -static_cast(io.theme->padding1)}, .attachPoints = {.element = CLAY_ATTACH_POINT_LEFT_BOTTOM, .parent = CLAY_ATTACH_POINT_LEFT_BOTTOM}, .attachTo = CLAY_ATTACH_TO_PARENT} // }) { // gui.obstructing_window(localId); // gui.push_id("chat box open button"); @@ -1219,7 +1045,7 @@ void Toolbar::chat_box() { // .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_BOTTOM}, // .layoutDirection = CLAY_TOP_TO_BOTTOM // }, - // .floating = {.offset = {60 + static_cast(io->theme->padding1), -static_cast(io->theme->padding1)}, .attachPoints = {.element = CLAY_ATTACH_POINT_LEFT_BOTTOM, .parent = CLAY_ATTACH_POINT_LEFT_BOTTOM}, .attachTo = CLAY_ATTACH_TO_PARENT} + // .floating = {.offset = {60 + static_cast(io.theme->padding1), -static_cast(io.theme->padding1)}, .attachPoints = {.element = CLAY_ATTACH_POINT_LEFT_BOTTOM, .parent = CLAY_ATTACH_POINT_LEFT_BOTTOM}, .attachTo = CLAY_ATTACH_TO_PARENT} //}) { // gui.obstructing_window(localId); // gui.push_id("chat box"); @@ -1233,7 +1059,7 @@ void Toolbar::chat_box() { // .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_BOTTOM}, // .layoutDirection = CLAY_TOP_TO_BOTTOM // }, - // .backgroundColor = convert_vec4(io->theme->backColor1) + // .backgroundColor = convert_vec4(io.theme->backColor1) // }) { // int id = 0; // for(auto& chatMessage : main.world->chatMessages | std::views::reverse) { @@ -1260,9 +1086,9 @@ void Toolbar::chat_box() { // t.selection.selected = true; // chatBoxState = CHATBOXSTATE_OPEN; // } - // if(io->key.escape) + // if(io.key.escape) // t.selection.selected = false; - // if(io->key.enter) { + // if(io.key.enter) { // main.world->send_chat_message(chatMessageInput); // t.selection.selected = false; // } @@ -1289,7 +1115,7 @@ void Toolbar::chat_box() { // .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP}, // .layoutDirection = CLAY_TOP_TO_BOTTOM // }, - // .backgroundColor = convert_vec4(color_mul_alpha(io->theme->backColor1, a)), + // .backgroundColor = convert_vec4(color_mul_alpha(io.theme->backColor1, a)), // }) { // gui.push_id(id); // gui.obstructing_window(elemId); @@ -1306,10 +1132,13 @@ void Toolbar::chat_box() { } void Toolbar::global_log() { + auto& gui = main.g.gui; + auto& io = gui.io; + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIXED(300), .height = CLAY_SIZING_FIT(0) }, - .childGap = io->theme->childGap1, + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_RIGHT, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, @@ -1326,22 +1155,22 @@ void Toolbar::global_log() { // CLAY(elemId, { // .layout = { // .sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0) }, - // .padding = CLAY_PADDING_ALL(io->theme->padding1), + // .padding = CLAY_PADDING_ALL(io.theme->padding1), // .childGap = 0, // .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP}, // .layoutDirection = CLAY_TOP_TO_BOTTOM // }, - // .backgroundColor = convert_vec4(color_mul_alpha(io->theme->backColor1, a)), - // .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1) + // .backgroundColor = convert_vec4(color_mul_alpha(io.theme->backColor1, a)), + // .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1) // }) { // gui.obstructing_window(elemId); // SkColor4f c{0, 0, 0, 0}; // switch(logM.color) { // case LogMessage::COLOR_NORMAL: - // c = io->theme->frontColor1; + // c = io.theme->frontColor1; // break; // case LogMessage::COLOR_ERROR: - // c = io->theme->errorColor; + // c = io.theme->errorColor; // break; // } // gui.text_label_color(logM.text, color_mul_alpha(c, a)); @@ -1354,10 +1183,13 @@ void Toolbar::global_log() { } void Toolbar::drawing_program_gui() { + auto& gui = main.g.gui; + auto& io = gui.io; + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) }, - .childGap = io->theme->childGap1, + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER}, .layoutDirection = CLAY_LEFT_TO_RIGHT }, @@ -1374,19 +1206,19 @@ void Toolbar::drawing_program_gui() { // CLAY(localId, { // .layout = { // .sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0)}, - // .padding = CLAY_PADDING_ALL(io->theme->padding1), - // .childGap = io->theme->childGap1, + // .padding = CLAY_PADDING_ALL(io.theme->padding1), + // .childGap = io.theme->childGap1, // .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, // .layoutDirection = CLAY_TOP_TO_BOTTOM // }, - // .backgroundColor = convert_vec4(io->theme->backColor1), - // .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1) + // .backgroundColor = convert_vec4(io.theme->backColor1), + // .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1) // }) { // gui.obstructing_window(localId); - // isUpdatingColorLeft |= gui.color_picker_items("colorpickerleft", colorLeft, true, 300.0f - io->theme->padding1 * 2.0f); + // isUpdatingColorLeft |= gui.color_picker_items("colorpickerleft", colorLeft, true, 300.0f - io.theme->padding1 * 2.0f); // bool hoveringOnDropdown = false; // isUpdatingColorLeft |= color_palette("colorpickerleftpalette", colorLeft, hoveringOnDropdown); - // if(!Clay_Hovered() && !justAssignedColorLeft && !hoveringOnDropdown && io->mouse.leftClick) + // if(!Clay_Hovered() && !justAssignedColorLeft && !hoveringOnDropdown && io.mouse.leftClick) // colorLeft = nullptr; // } // } @@ -1406,19 +1238,19 @@ void Toolbar::drawing_program_gui() { // CLAY(localID, { // .layout = { // .sizing = {.width = CLAY_SIZING_FIT(300), .height = CLAY_SIZING_FIT(0)}, - // .padding = CLAY_PADDING_ALL(io->theme->padding1), - // .childGap = io->theme->childGap1, + // .padding = CLAY_PADDING_ALL(io.theme->padding1), + // .childGap = io.theme->childGap1, // .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, // .layoutDirection = CLAY_TOP_TO_BOTTOM // }, - // .backgroundColor = convert_vec4(io->theme->backColor1), - // .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1) + // .backgroundColor = convert_vec4(io.theme->backColor1), + // .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1) // }) { // gui.obstructing_window(localID); - // isUpdatingColorRight |= gui.color_picker_items("colorpickerright", colorRight, true, 300.0f - io->theme->padding1 * 2.0f); + // isUpdatingColorRight |= gui.color_picker_items("colorpickerright", colorRight, true, 300.0f - io.theme->padding1 * 2.0f); // bool hoveringOnDropdown = false; // isUpdatingColorRight |= color_palette("colorpickerrightpalette", colorRight, hoveringOnDropdown); - // if(!Clay_Hovered() && !justAssignedColorRight && !hoveringOnDropdown && io->mouse.leftClick) + // if(!Clay_Hovered() && !justAssignedColorRight && !hoveringOnDropdown && io.mouse.leftClick) // colorRight = nullptr; // } // } @@ -1428,6 +1260,9 @@ void Toolbar::drawing_program_gui() { } bool Toolbar::color_palette(const char* id, Vector4f* color, bool& hoveringOnDropdown) { + auto& gui = main.g.gui; + auto& io = gui.io; + bool isUpdating = false; gui.new_id(id, [&] { //auto& palette = paletteData.palettes[paletteData.selectedPalette].colors; @@ -1439,7 +1274,7 @@ bool Toolbar::color_palette(const char* id, Vector4f* color, bool& hoveringOnDro // CLAY_AUTO_ID({ // .layout = { // .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, - // .childGap = io->theme->childGap1, + // .childGap = io.theme->childGap1, // .layoutDirection = CLAY_TOP_TO_BOTTOM // } // }) { @@ -1448,7 +1283,7 @@ bool Toolbar::color_palette(const char* id, Vector4f* color, bool& hoveringOnDro // CLAY_AUTO_ID({ // .layout = { // .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIXED(COLOR_BUTTON_SIZE)}, - // .childGap = io->theme->childGap1, + // .childGap = io.theme->childGap1, // .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER}, // .layoutDirection = CLAY_LEFT_TO_RIGHT // } @@ -1487,7 +1322,7 @@ bool Toolbar::color_palette(const char* id, Vector4f* color, bool& hoveringOnDro // .layout = { // .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0)}, // .padding = {.top = 3, .bottom = 3}, - // .childGap = io->theme->childGap1, + // .childGap = io.theme->childGap1, // .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER}, // .layoutDirection = CLAY_LEFT_TO_RIGHT // } @@ -1508,7 +1343,7 @@ bool Toolbar::color_palette(const char* id, Vector4f* color, bool& hoveringOnDro // .layout = { // .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0)}, // .padding = {.top = 3, .bottom = 3}, - // .childGap = io->theme->childGap1, + // .childGap = io.theme->childGap1, // .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER}, // .layoutDirection = CLAY_LEFT_TO_RIGHT // } @@ -1542,11 +1377,14 @@ bool Toolbar::color_palette(const char* id, Vector4f* color, bool& hoveringOnDro } void Toolbar::performance_metrics() { + auto& gui = main.g.gui; + auto& io = gui.io; + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0) }, - .padding = CLAY_PADDING_ALL(io->theme->padding1), - .childGap = io->theme->childGap1, + .padding = CLAY_PADDING_ALL(io.theme->padding1), + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_BOTTOM}, .layoutDirection = CLAY_LEFT_TO_RIGHT }, @@ -1555,12 +1393,12 @@ void Toolbar::performance_metrics() { CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0) }, - .padding = CLAY_PADDING_ALL(io->theme->padding1), - .childGap = io->theme->childGap1, + .padding = CLAY_PADDING_ALL(io.theme->padding1), + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_RIGHT, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, - .backgroundColor = convert_vec4(color_mul_alpha(io->theme->backColor1, 0.7f)), + .backgroundColor = convert_vec4(color_mul_alpha(io.theme->backColor1, 0.7f)), }) { text_label(gui, "Undo queue"); std::vector undoList = main.world->undo.get_front_undo_queue_names(10); @@ -1570,12 +1408,12 @@ void Toolbar::performance_metrics() { CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(0), .height = CLAY_SIZING_FIT(0) }, - .padding = CLAY_PADDING_ALL(io->theme->padding1), - .childGap = io->theme->childGap1, + .padding = CLAY_PADDING_ALL(io.theme->padding1), + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_RIGHT, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, - .backgroundColor = convert_vec4(color_mul_alpha(io->theme->backColor1, 0.7f)), + .backgroundColor = convert_vec4(color_mul_alpha(io.theme->backColor1, 0.7f)), }) { std::stringstream a; a << "FPS: " << std::fixed << std::setprecision(0) << (1.0 / main.deltaTime); @@ -1595,16 +1433,19 @@ void Toolbar::performance_metrics() { } void Toolbar::player_list() { + auto& gui = main.g.gui; + auto& io = gui.io; + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(500), .height = CLAY_SIZING_FIT(0) }, - .padding = CLAY_PADDING_ALL(io->theme->padding1), - .childGap = io->theme->childGap1, + .padding = CLAY_PADDING_ALL(io.theme->padding1), + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, - .backgroundColor = convert_vec4(io->theme->backColor1), - .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), + .backgroundColor = convert_vec4(io.theme->backColor1), + .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1), .floating = {.attachPoints = {.element = CLAY_ATTACH_POINT_CENTER_CENTER, .parent = CLAY_ATTACH_POINT_CENTER_CENTER}, .attachTo = CLAY_ATTACH_TO_PARENT} }) { gui.new_id("client list", [&] { @@ -1686,17 +1527,20 @@ void Toolbar::open_world_file(bool isClient, const std::string& netSource, const } void Toolbar::center_obstructing_window_gui(const char* id, Clay_SizingAxis x, Clay_SizingAxis y, const std::function& innerContent) { + auto& gui = main.g.gui; + auto& io = gui.io; + gui.element(id, [&] { CLAY_AUTO_ID({ .layout = { .sizing = {.width = x, .height = y }, - .padding = CLAY_PADDING_ALL(io->theme->padding1), - .childGap = io->theme->childGap1, + .padding = CLAY_PADDING_ALL(io.theme->padding1), + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, - .backgroundColor = convert_vec4(io->theme->backColor1), - .cornerRadius = CLAY_CORNER_RADIUS(io->theme->windowCorners1), + .backgroundColor = convert_vec4(io.theme->backColor1), + .cornerRadius = CLAY_CORNER_RADIUS(io.theme->windowCorners1), .floating = {.attachPoints = {.element = CLAY_ATTACH_POINT_CENTER_CENTER, .parent = CLAY_ATTACH_POINT_CENTER_CENTER}, .attachTo = CLAY_ATTACH_TO_PARENT} }) { innerContent(); @@ -1705,6 +1549,9 @@ void Toolbar::center_obstructing_window_gui(const char* id, Clay_SizingAxis x, C } void Toolbar::text_button_wide(const char* id, const char* str, const std::function& onClick) { + auto& gui = main.g.gui; + auto& io = gui.io; + text_button(gui, id, str, { .wide = true, .onClick = onClick @@ -1712,6 +1559,9 @@ void Toolbar::text_button_wide(const char* id, const char* str, const std::funct } void Toolbar::options_menu() { + auto& gui = main.g.gui; + auto& io = gui.io; + switch(optionsMenuType) { case HOST_MENU: { center_obstructing_window_gui("host menu", CLAY_SIZING_FIT(650), CLAY_SIZING_FIT(0), [&] { @@ -1815,11 +1665,14 @@ void Toolbar::options_menu() { } void Toolbar::general_settings_inner_gui() { + auto& gui = main.g.gui; + auto& io = gui.io; + CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0)}, - .padding = CLAY_PADDING_ALL(io->theme->padding1), - .childGap = io->theme->childGap1, + .padding = CLAY_PADDING_ALL(io.theme->padding1), + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_LEFT_TO_RIGHT } @@ -1827,7 +1680,7 @@ void Toolbar::general_settings_inner_gui() { CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(150), .height = CLAY_SIZING_GROW(0) }, - .padding = CLAY_PADDING_ALL(io->theme->padding1), + .padding = CLAY_PADDING_ALL(io.theme->padding1), .childGap = 2, .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM @@ -1839,7 +1692,7 @@ void Toolbar::general_settings_inner_gui() { .isSelected = generalSettingsOptions == opt, .wide = true, .onClick = [&] { - load_theme(); + main.g.load_theme(main.configPath, main.conf.themeCurrentlyLoaded); themeData.selectedThemeIndex = std::nullopt; generalSettingsOptions = opt; } @@ -1867,8 +1720,8 @@ void Toolbar::general_settings_inner_gui() { CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_GROW(0) }, - .padding = CLAY_PADDING_ALL(io->theme->padding1), - .childGap = io->theme->childGap1, + .padding = CLAY_PADDING_ALL(io.theme->padding1), + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM } @@ -1876,53 +1729,53 @@ void Toolbar::general_settings_inner_gui() { switch(generalSettingsOptions) { case GSETTINGS_GENERAL: { gui.new_id("general settings", [&] { - input_text_field(gui, "display name input", "Display name", &main.displayName); + input_text_field(gui, "display name input", "Display name", &main.conf.displayName); main.update_display_names(); - color_picker_button_field(gui, "defaultCanvasBackgroundColor", "Default canvas background color", &main.defaultCanvasBackgroundColor, { .hasAlpha = false }); + color_picker_button_field(gui, "defaultCanvasBackgroundColor", "Default canvas background color", &main.conf.defaultCanvasBackgroundColor, { .hasAlpha = false }); #ifndef __EMSCRIPTEN__ - checkbox_boolean_field(gui, "native file pick", "Use native file picker", &useNativeFilePicker); - checkbox_boolean_field(gui, "update notifications enable", "Check for updates on startup", &updateCheckerData.checkForUpdates); + checkbox_boolean_field(gui, "native file pick", "Use native file picker", &main.conf.useNativeFilePicker); + checkbox_boolean_field(gui, "update notifications enable", "Check for updates on startup", &main.conf.checkForUpdates); #endif - slider_scalar_field(gui, "drag zoom slider", "Drag zoom speed", &dragZoomSpeed, 0.0, 1.0, {.decimalPrecision = 3}); - slider_scalar_field(gui, "scroll zoom slider", "Scroll zoom speed", &scrollZoomSpeed, 0.0, 1.0, {.decimalPrecision = 3}); - checkbox_boolean_field(gui, "flip zoom tool direction", "Flip zoom tool direction", &flipZoomToolDirection); + slider_scalar_field(gui, "drag zoom slider", "Drag zoom speed", &main.conf.dragZoomSpeed, 0.0, 1.0, {.decimalPrecision = 3}); + slider_scalar_field(gui, "scroll zoom slider", "Scroll zoom speed", &main.conf.scrollZoomSpeed, 0.0, 1.0, {.decimalPrecision = 3}); + checkbox_boolean_field(gui, "flip zoom tool direction", "Flip zoom tool direction", &main.conf.flipZoomToolDirection); checkbox_boolean_field(gui, "make all tools share same size", "Make all tools share size", &main.toolConfig.globalConf.useGlobalRelativeWidth); #ifndef __EMSCRIPTEN__ - checkbox_boolean_field(gui, "disable graphics driver workarounds", "Disable graphics driver workarounds (enabling or disabling this might fix some graphical glitches, requires restart)", &main.window.disableGraphicsDriverWorkarounds); + checkbox_boolean_field(gui, "disable graphics driver workarounds", "Disable graphics driver workarounds (enabling or disabling this might fix some graphical glitches, requires restart)", &main.conf.disableGraphicsDriverWorkarounds); #endif - input_scalar_field(gui, "jump transition time", "Jump transition time", &jumpTransitionTime, 0.01f, 1000.0f, {.decimalPrecision = 2}); - input_scalar_field(gui, "Max GUI Scale", "Max GUI Scale", &guiScale, 0.5f, 5.0f, {.decimalPrecision = 1}); + input_scalar_field(gui, "jump transition time", "Jump transition time", &main.conf.jumpTransitionTime, 0.01f, 1000.0f, {.decimalPrecision = 2}); + input_scalar_field(gui, "Max GUI Scale", "Max GUI Scale", &main.conf.guiScale, 0.5f, 5.0f, {.decimalPrecision = 1}); text_label(gui, "Anti-aliasing:"); - radio_button_selector(gui, "Antialiasing selector", &main.antialiasing, { - {"None", MainProgram::AntiAliasing::NONE}, - {"Skia", MainProgram::AntiAliasing::SKIA}, - {"Dynamic MSAA", MainProgram::AntiAliasing::DYNAMIC_MSAA} + radio_button_selector(gui, "Antialiasing selector", &main.conf.antialiasing, { + {"None", GlobalConfig::AntiAliasing::NONE}, + {"Skia", GlobalConfig::AntiAliasing::SKIA}, + {"Dynamic MSAA", GlobalConfig::AntiAliasing::DYNAMIC_MSAA} }, [&] { main.refresh_draw_surfaces(); }); text_label(gui, "VSync:"); - radio_button_selector(gui, "VSync selector", &main.window.vsyncValue, { + radio_button_selector(gui, "VSync selector", &main.conf.vsyncValue, { {"On", 1}, {"Off", 0}, {"Adaptive", -1} }, [&] { - main.set_vsync_value(main.window.vsyncValue); + main.set_vsync_value(main.conf.vsyncValue); }); #ifndef __EMSCRIPTEN__ - checkbox_boolean_field(gui, "apply display scale", "Apply display scale", &main.window.applyDisplayScale); + checkbox_boolean_field(gui, "apply display scale", "Apply display scale", &main.conf.applyDisplayScale); #endif }); break; } case GSETTINGS_TABLET: { gui.new_id("tablet settings", [&] { - checkbox_boolean_field(gui, "pen pressure width", "Pen pressure affects brush size", &tabletOptions.pressureAffectsBrushWidth); - slider_scalar_field(gui, "smoothing time", "Smoothing sampling time", &tabletOptions.smoothingSamplingTime, 0.001f, 1.0f, {.decimalPrecision = 3}); - input_scalar_field(gui, "middle click", "Middle click pen button", &tabletOptions.middleClickButton, 1, 255); - input_scalar_field(gui, "right click", "Right click pen button", &tabletOptions.rightClickButton, 1, 255); - slider_scalar_field(gui, "tablet brush minimum size", "Brush relative minimum size", &tabletOptions.brushMinimumSize, 0.0f, 1.0f, {.decimalPrecision = 3}); - checkbox_boolean_field(gui, "tablet zoom with button method", "Zoom when pen touching tablet and pen button assigned to middle click is held", &tabletOptions.zoomWhilePenDownAndButtonHeld); + checkbox_boolean_field(gui, "pen pressure width", "Pen pressure affects brush size", &main.conf.tabletOptions.pressureAffectsBrushWidth); + slider_scalar_field(gui, "smoothing time", "Smoothing sampling time", &main.conf.tabletOptions.smoothingSamplingTime, 0.001f, 1.0f, {.decimalPrecision = 3}); + input_scalar_field(gui, "middle click", "Middle click pen button", &main.conf.tabletOptions.middleClickButton, 1, 255); + input_scalar_field(gui, "right click", "Right click pen button", &main.conf.tabletOptions.rightClickButton, 1, 255); + slider_scalar_field(gui, "tablet brush minimum size", "Brush relative minimum size", &main.conf.tabletOptions.brushMinimumSize, 0.0f, 1.0f, {.decimalPrecision = 3}); + checkbox_boolean_field(gui, "tablet zoom with button method", "Zoom when pen touching tablet and pen button assigned to middle click is held", &main.conf.tabletOptions.zoomWhilePenDownAndButtonHeld); #ifdef _WIN32 checkbox_boolean_field(gui, "mouse ignore when pen proximity", "Ignore mouse movement when pen in proximity", &tabletOptions.ignoreMouseMovementWhenPenInProximity); #endif @@ -1935,7 +1788,7 @@ void Toolbar::general_settings_inner_gui() { reload_theme_list(); CLAY_AUTO_ID({.layout = { - .childGap = io->theme->childGap1, + .childGap = io.theme->childGap1, .childAlignment = {.x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_CENTER}, .layoutDirection = CLAY_LEFT_TO_RIGHT, } @@ -1943,7 +1796,7 @@ void Toolbar::general_settings_inner_gui() { text_label(gui, "Theme: "); gui.element>("dropdownSelectThemes", &themeData.selectedThemeIndex.value(), themeData.themeDirList, DropdownOptions{ .onClick = [&]() { - themeData.themeCurrentlyLoaded = themeData.themeDirList[themeData.selectedThemeIndex.value()]; + main.conf.themeCurrentlyLoaded = themeData.themeDirList[themeData.selectedThemeIndex.value()]; reload_theme_list(); } }); @@ -1951,8 +1804,8 @@ void Toolbar::general_settings_inner_gui() { left_to_right_line_layout(gui, [&]() { if(themeData.selectedThemeIndex != 0) { text_button_wide("savethemebutton", "Save", [&] { - themeData.themeCurrentlyLoaded = themeData.themeDirList[themeData.selectedThemeIndex.value()]; - save_theme(); + main.conf.themeCurrentlyLoaded = themeData.themeDirList[themeData.selectedThemeIndex.value()]; + main.g.save_theme(main.configPath, main.conf.themeCurrentlyLoaded); reload_theme_list(); }); } @@ -1960,22 +1813,22 @@ void Toolbar::general_settings_inner_gui() { themeData.openedSaveAsMenu = !themeData.openedSaveAsMenu; }); text_button_wide("reloadthemebutton", "Reload", [&] { - themeData.themeCurrentlyLoaded = themeData.themeDirList[themeData.selectedThemeIndex.value()]; + main.conf.themeCurrentlyLoaded = themeData.themeDirList[themeData.selectedThemeIndex.value()]; reload_theme_list(); }); if(themeData.selectedThemeIndex != 0) { text_button_wide("deletethemebutton", "Delete", [&] { try { std::filesystem::remove(main.configPath / "themes" / (themeData.themeDirList[themeData.selectedThemeIndex.value()] + ".json")); } catch(...) { } - themeData.themeCurrentlyLoaded = "Default"; + main.conf.themeCurrentlyLoaded = "Default"; reload_theme_list(); }); } }); if(themeData.openedSaveAsMenu) { - input_text_field(gui, "Theme name:", "Theme name: ", &themeData.themeCurrentlyLoaded); + input_text_field(gui, "Theme name:", "Theme name: ", &main.conf.themeCurrentlyLoaded); left_to_right_line_layout(gui, [&]() { text_button_wide("saveasdone", "Done", [&] { - save_theme(); + main.g.save_theme(main.configPath, main.conf.themeCurrentlyLoaded); reload_theme_list(); }); text_button_wide("saveascancel", "Cancel", [&] { @@ -1985,18 +1838,18 @@ void Toolbar::general_settings_inner_gui() { } text_label(gui, "Edit theme:"); text_label_light(gui, "Note: Changes only remain if theme is saved"); - color_picker_button_field(gui, "fillColor1", "Fill Color 1", &io->theme->fillColor1); - color_picker_button_field(gui, "fillColor2", "Fill Color 2", &io->theme->fillColor2); - color_picker_button_field(gui, "backColor1", "Back Color 1", &io->theme->backColor1); - color_picker_button_field(gui, "backColor2", "Back Color 2", &io->theme->backColor2); - color_picker_button_field(gui, "frontColor1", "Front Color 1", &io->theme->frontColor1); - color_picker_button_field(gui, "frontColor2", "Front Color 2", &io->theme->frontColor2); - color_picker_button_field(gui, "warningColor", "Warning Color", &io->theme->warningColor); - color_picker_button_field(gui, "errorColor", "Error Color", &io->theme->errorColor); - //gui.slider_scalar_field("hoverExpandTime", "Hover Expand Time", &io->theme->hoverExpandTime, 0.001f, 1.0f); - input_scalar_field(gui, "childGap1", "Gap between child elements", &io->theme->childGap1, 0, 30); - input_scalar_field(gui, "padding1", "Window padding", &io->theme->padding1, 0, 30); - slider_scalar_field(gui, "windowCorners1", "Window corner radius", &io->theme->windowCorners1, 0, 30); + color_picker_button_field(gui, "fillColor1", "Fill Color 1", &io.theme->fillColor1); + color_picker_button_field(gui, "fillColor2", "Fill Color 2", &io.theme->fillColor2); + color_picker_button_field(gui, "backColor1", "Back Color 1", &io.theme->backColor1); + color_picker_button_field(gui, "backColor2", "Back Color 2", &io.theme->backColor2); + color_picker_button_field(gui, "frontColor1", "Front Color 1", &io.theme->frontColor1); + color_picker_button_field(gui, "frontColor2", "Front Color 2", &io.theme->frontColor2); + color_picker_button_field(gui, "warningColor", "Warning Color", &io.theme->warningColor); + color_picker_button_field(gui, "errorColor", "Error Color", &io.theme->errorColor); + //gui.slider_scalar_field("hoverExpandTime", "Hover Expand Time", &io.theme->hoverExpandTime, 0.001f, 1.0f); + input_scalar_field(gui, "childGap1", "Gap between child elements", &io.theme->childGap1, 0, 30); + input_scalar_field(gui, "padding1", "Window padding", &io.theme->padding1, 0, 30); + slider_scalar_field(gui, "windowCorners1", "Window corner radius", &io.theme->windowCorners1, 0, 30); }); break; } @@ -2025,7 +1878,7 @@ void Toolbar::general_settings_inner_gui() { .layout = { .sizing = {.width = CLAY_SIZING_GROW(0), .height = CLAY_SIZING_FIT(0) }, .padding = CLAY_PADDING_ALL(0), - .childGap = io->theme->childGap1, + .childGap = io.theme->childGap1, .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER}, .layoutDirection = CLAY_LEFT_TO_RIGHT } @@ -2051,9 +1904,9 @@ void Toolbar::general_settings_inner_gui() { case GSETTINGS_DEBUG: { gui.new_id("debug settings menu", [&] { checkbox_boolean_field(gui, "show performance metrics", "Show metrics", &showPerformance); - input_scalars_field(gui, "jump transition easing", "Jump easing", &jumpTransitionEasing, 4, -10.0f, 10.0f, { .decimalPrecision = 2 }); + input_scalars_field(gui, "jump transition easing", "Jump easing", &main.conf.jumpTransitionEasing, 4, -10.0f, 10.0f, { .decimalPrecision = 2 }); #ifndef __EMSCRIPTEN__ - input_scalar_field(gui, "fps cap slider", "FPS cap", &main.fpsLimit, 3.0f, 10000.0f); + input_scalar_field(gui, "fps cap slider", "FPS cap", &main.conf.fpsLimit, 3.0f, 10000.0f); #endif input_scalar_field(gui, "image load max threads", "Maximum image loading threads", &ImageResourceDisplay::IMAGE_LOAD_THREAD_COUNT_MAX, 1, 10000); text_label_light(gui, "Cache related settings"); @@ -2077,7 +1930,7 @@ void Toolbar::general_settings_inner_gui() { }); text_button_wide("done menu", "Done", [&] { main.save_config(); - load_theme(); + main.g.load_theme(main.configPath, main.conf.themeCurrentlyLoaded); themeData.selectedThemeIndex = std::nullopt; optionsMenuOpen = false; }); @@ -2086,12 +1939,15 @@ void Toolbar::general_settings_inner_gui() { } void Toolbar::about_menu_inner_gui() { + auto& gui = main.g.gui; + auto& io = gui.io; + left_to_right_line_layout(gui, [&]() { gui.new_id("Menu Selector", [&] { CLAY_AUTO_ID({ .layout = { .sizing = {.width = CLAY_SIZING_FIT(200), .height = CLAY_SIZING_FIT(0) }, - .padding = CLAY_PADDING_ALL(io->theme->padding1), + .padding = CLAY_PADDING_ALL(io.theme->padding1), .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM } @@ -2159,18 +2015,20 @@ void Toolbar::reload_theme_list() { std::string name = theme.path().stem().string(); if(name != "Default") { themeData.themeDirList.emplace_back(name); - if(name == themeData.themeCurrentlyLoaded) + if(name == main.conf.themeCurrentlyLoaded) themeData.selectedThemeIndex = themeData.themeDirList.size() - 1; } } } - if(!load_theme()) + if(!main.g.load_theme(main.configPath, main.conf.themeCurrentlyLoaded)) themeData.selectedThemeIndex = 0; themeData.openedSaveAsMenu = false; } void Toolbar::file_picker_gui_refresh_entries() { + auto& gui = main.g.gui; + filePicker.entries.clear(); for(;;) { try { @@ -2229,6 +2087,9 @@ void Toolbar::file_picker_gui_done() { } void Toolbar::file_picker_gui() { + auto& gui = main.g.gui; + auto& io = gui.io; + center_obstructing_window_gui("file picker gui window", CLAY_SIZING_FIXED(700), CLAY_SIZING_FIXED(500), [&] { text_label_centered(gui, filePicker.filePickerWindowName); left_to_right_line_layout(gui, [&]() { @@ -2250,7 +2111,7 @@ void Toolbar::file_picker_gui() { .childAlignment = { .x = CLAY_ALIGN_X_CENTER, .y = CLAY_ALIGN_Y_TOP}, .layoutDirection = CLAY_TOP_TO_BOTTOM }, - .backgroundColor = convert_vec4(io->theme->backColor2) + .backgroundColor = convert_vec4(io.theme->backColor2) }) { constexpr float entryHeight = 25.0f; scroll_area_many_entries(gui, "file picker entries", { @@ -2268,7 +2129,7 @@ void Toolbar::file_picker_gui() { .childAlignment = { .x = CLAY_ALIGN_X_LEFT, .y = CLAY_ALIGN_Y_CENTER}, .layoutDirection = CLAY_LEFT_TO_RIGHT }, - .backgroundColor = selectedEntry ? convert_vec4(io->theme->backColor1) : convert_vec4(io->theme->backColor2) + .backgroundColor = selectedEntry ? convert_vec4(io.theme->backColor1) : convert_vec4(io.theme->backColor2) }) { CLAY_AUTO_ID({ .layout = { @@ -2319,84 +2180,6 @@ void Toolbar::file_picker_gui() { }); } -void Toolbar::input_key_callback(const InputManager::KeyCallbackArgs& key) { - if(key.down) { - switch(key.key) { - case InputManager::KEY_SAVE: { - save_func(); - break; - } - case InputManager::KEY_SAVE_AS: { - save_as_func(); - break; - } - case InputManager::KEY_SHOW_METRICS: { - showPerformance = !showPerformance; - gui.set_to_layout(); - break; - } - case InputManager::KEY_OPEN_CHAT: { - if(chatBoxState == CHATBOXSTATE_CLOSE) - chatBoxState = CHATBOXSTATE_JUSTOPEN; - gui.set_to_layout(); - break; - } - case InputManager::KEY_SHOW_PLAYER_LIST: { - playerMenuOpen = !playerMenuOpen; - gui.set_to_layout(); - break; - } - } - } -} - -void Toolbar::input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button) { - //if(button.deviceType != InputManager::MouseDeviceType::TOUCH) { - // if(button.down) { - // switch(button.button) { - // case InputManager::MouseButton::LEFT: { - // io->mouse.leftClick = std::max(io->mouse.leftClick, button.clicks); - // io->mouse.leftHeld = true; - // break; - // } - // case InputManager::MouseButton::RIGHT: { - // io->mouse.rightClick = std::max(io->mouse.rightClick, button.clicks); - // io->mouse.rightHeld = true; - // break; - // } - // default: - // break; - // } - // } - // else { - // switch(button.button) { - // case InputManager::MouseButton::LEFT: { - // io->mouse.leftHeld = false; - // break; - // } - // case InputManager::MouseButton::RIGHT: { - // io->mouse.rightHeld = false; - // break; - // } - // default: - // break; - // } - // } - //} -} - -void Toolbar::input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion) { -} - -void Toolbar::input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel) { -} - -void Toolbar::input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch) { -} - -void Toolbar::input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion) { -} - float Toolbar::final_gui_scale() { return finalCalculatedGuiScale; } @@ -2408,12 +2191,5 @@ void Toolbar::calculate_final_gui_scale() { } float Toolbar::final_gui_scale_not_fit() { - return guiScale * main.get_scale_and_density_factor_gui(); -} - -void Toolbar::draw(SkCanvas* canvas, bool skiaAA) { - canvas->save(); - canvas->scale(final_gui_scale(), final_gui_scale()); - gui.draw(canvas, skiaAA); - canvas->restore(); + return main.conf.guiScale * main.get_scale_and_density_factor_gui(); } diff --git a/src/Toolbar.hpp b/src/Toolbar.hpp index db3b29e..a1c2b13 100644 --- a/src/Toolbar.hpp +++ b/src/Toolbar.hpp @@ -40,15 +40,8 @@ class Toolbar { std::string chatMessageInput; Toolbar(MainProgram& initMain); - void input_key_callback(const InputManager::KeyCallbackArgs& key); - void input_mouse_button_callback(const InputManager::MouseButtonCallbackArgs& button); - void input_mouse_motion_callback(const InputManager::MouseMotionCallbackArgs& motion); - void input_mouse_wheel_callback(const InputManager::MouseWheelCallbackArgs& wheel); - void input_finger_touch_callback(const InputManager::FingerTouchCallbackArgs& touch); - void input_finger_motion_callback(const InputManager::FingerMotionCallbackArgs& motion); void update(); void layout_run(); - void draw(SkCanvas* canvas, bool skiaAA); void color_selector_left(Vector4f* color); void color_selector_right(Vector4f* color); void paint_popup(Vector2f popupPos); @@ -58,34 +51,11 @@ class Toolbar { void save_func(); void save_as_func(); std::filesystem::path& file_selector_path(); - std::shared_ptr io; - GUIStuff::GUIManager gui; - - nlohmann::json get_config_json(); - void set_config_json(const nlohmann::json& j, VersionNumber version); void save_palettes(); void load_palettes(); - void save_theme(); - bool load_theme(); void load_licenses(); - double dragZoomSpeed = 0.02; - double scrollZoomSpeed = 0.4; - float jumpTransitionTime = 0.5f; - Vector4f jumpTransitionEasing{0.75, 0.25, 0.25, 0.75}; - bool viewWebVersionWelcome = false; - - struct TabletOptions { - bool pressureAffectsBrushWidth = true; - float smoothingSamplingTime = 0.04f; - uint8_t middleClickButton = 1; - uint8_t rightClickButton = 2; - bool ignoreMouseMovementWhenPenInProximity = false; - float brushMinimumSize = 0.0f; - bool zoomWhilePenDownAndButtonHeld = true; - } tabletOptions; - Vector4f* colorLeft = nullptr; Vector4f* colorRight = nullptr; bool isUpdatingColorLeft = false; @@ -93,7 +63,6 @@ class Toolbar { std::optional rightClickPopupLocation; - bool flipZoomToolDirection = false; float final_gui_scale(); @@ -146,7 +115,6 @@ class Toolbar { void update_notification_gui(); void update_notification_check(); struct UpdateCheckerData { - bool checkForUpdates = true; bool showGui = false; bool updateCheckDone = false; std::string newVersionStr; @@ -177,7 +145,6 @@ class Toolbar { struct ThemeData { std::vector themeDirList; std::optional selectedThemeIndex; - std::string themeCurrentlyLoaded = "Default"; bool openedSaveAsMenu = false; } themeData; @@ -190,7 +157,6 @@ class Toolbar { bool optionsMenuOpen = false; bool playerMenuOpen = false; - float guiScale = 1.0f; float finalCalculatedGuiScale = 1.0f; enum { @@ -225,7 +191,6 @@ class Toolbar { uint32_t selectedGrid = std::numeric_limits::max(); } gridMenu; - bool useNativeFilePicker = true; struct FilePicker { bool isOpen = false; std::string filePickerWindowName; @@ -249,8 +214,6 @@ class Toolbar { std::optional keybindWaiting; - std::filesystem::path testing; - std::unique_ptr build_paragraph_from_chat_message(const ChatMessage& message, float alpha); void load_icons_at(const std::filesystem::path& pathToLoad); diff --git a/src/World.cpp b/src/World.cpp index 1c7d32f..44d6a8c 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -80,7 +80,7 @@ void World::init_client_data_list() { clients = netObjMan.make_obj>(); ownClientData = clients->emplace_direct(clients, ClientData::InitStruct{ .cursorColor = get_random_cursor_color(), - .displayName = main.displayName + .displayName = main.conf.displayName }); init_client_data_list_callbacks(); } @@ -161,7 +161,7 @@ void World::init_client(const std::string& serverFullID) { netClient->add_recv_callback(CLIENT_KEEP_ALIVE, [&](cereal::PortableBinaryInputArchive& message) { }); - netClient->send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_INITIAL_DATA, main.displayName); + netClient->send_items_to_server(RELIABLE_COMMAND_CHANNEL, SERVER_INITIAL_DATA, main.conf.displayName); } void World::focus_update() { diff --git a/src/World.hpp b/src/World.hpp index e505281..a6b3545 100644 --- a/src/World.hpp +++ b/src/World.hpp @@ -19,8 +19,6 @@ class MainProgram; //#define ENABLE_ORDERED_LIST_TEST -#define DEFAULT_CANVAS_BACKGROUND_COLOR Vector3f{0.07f, 0.07f, 0.07f} - class World { public: static constexpr std::string FILE_EXTENSION = "infpnt"; diff --git a/src/WorldGrid.cpp b/src/WorldGrid.cpp index ef5c436..6000cab 100644 --- a/src/WorldGrid.cpp +++ b/src/WorldGrid.cpp @@ -353,12 +353,12 @@ void WorldGrid::draw_coordinates(SkCanvas* canvas, const DrawData& drawData, Vec const WorldVec& worldWindowTopLeftClipPos = coordinatesAxisOnBounds ? bounds.value().min : drawData.cam.c.pos; SCollision::AABB boundsCamSpace; - float coordFontSize = drawData.main->toolbar.final_gui_scale() * drawData.main->toolbar.io->fontSize; + float coordFontSize = drawData.main->toolbar.final_gui_scale() * drawData.main->g.gui.io.fontSize; if(coordinatesAxisOnBounds) boundsCamSpace = SCollision::AABB(drawData.cam.c.to_space(bounds.value().min), drawData.cam.c.to_space(bounds.value().max)); else { - float toolbarXLength = drawData.main->drawGui ? drawData.main->toolbar.final_gui_scale() * (50.0f + drawData.main->toolbar.io->theme->padding1 * 3.0f) : 0.0f; + float toolbarXLength = drawData.main->drawGui ? drawData.main->toolbar.final_gui_scale() * (50.0f + drawData.main->g.gui.io.theme->padding1 * 3.0f) : 0.0f; boundsCamSpace = SCollision::AABB({toolbarXLength + axisOffset.x(), 0.0f}, {drawData.cam.viewingArea.x(), drawData.cam.viewingArea.y() - axisOffset.y()}); if(boundsCamSpace.width() < 100.0f || boundsCamSpace.height() < 100.0f) return; @@ -371,7 +371,7 @@ void WorldGrid::draw_coordinates(SkCanvas* canvas, const DrawData& drawData, Vec return; } - SkFont f = drawData.main->toolbar.io->get_font(coordFontSize); + SkFont f = drawData.main->g.gui.io.get_font(coordFontSize); SkFontMetrics metrics; f.getMetrics(&metrics); float fontHeight = (-metrics.fAscent + metrics.fDescent); @@ -493,9 +493,9 @@ void WorldGrid::draw_coordinates(SkCanvas* canvas, const DrawData& drawData, Vec canvas->clipRect(SkRect::MakeLTRB(boundsCamSpace.min.x(), boundsCamSpace.min.y(), boundsCamSpace.max.x(), boundsCamSpace.max.y())); } - canvas->drawRect(SkRect::MakeXYWH(boundsCamSpace.min.x(), boundsCamSpace.min.y(), yAxisMaxXLength, boundsCamSpace.max.y() - boundsCamSpace.min.y()), SkPaint{color_mul_alpha(drawData.main->toolbar.io->theme->backColor1, 0.9f)}); + canvas->drawRect(SkRect::MakeXYWH(boundsCamSpace.min.x(), boundsCamSpace.min.y(), yAxisMaxXLength, boundsCamSpace.max.y() - boundsCamSpace.min.y()), SkPaint{color_mul_alpha(drawData.main->g.gui.io.theme->backColor1, 0.9f)}); if(!xAxisLabels.empty()) - canvas->drawRect(SkRect::MakeLTRB(boundsCamSpace.min.x() + yAxisMaxXLength, xAxisYPosRect, boundsCamSpace.max.x(), boundsCamSpace.max.y()), SkPaint{color_mul_alpha(drawData.main->toolbar.io->theme->backColor1, 0.9f)}); + canvas->drawRect(SkRect::MakeLTRB(boundsCamSpace.min.x() + yAxisMaxXLength, xAxisYPosRect, boundsCamSpace.max.x(), boundsCamSpace.max.y()), SkPaint{color_mul_alpha(drawData.main->g.gui.io.theme->backColor1, 0.9f)}); for(auto& l : xAxisLabels) { canvas->drawSimpleText(l.mainText.c_str(), l.mainText.length(), SkTextEncoding::kUTF8, l.mainPos, xAxisYPosLabels, f, labelColor); diff --git a/src/main.cpp b/src/main.cpp index cd341ba..5336203 100755 --- a/src/main.cpp +++ b/src/main.cpp @@ -499,7 +499,7 @@ SDL_AppResult SDL_AppInit(void **appstate, int argc, char **argv) { GrContextOptions opts; opts.fSuppressPrints = true; - opts.fDisableDriverCorrectnessWorkarounds = mS.m->window.disableGraphicsDriverWorkarounds; // Driver workarounds causing glitches on intel drivers on windows, but are required in the Emscripten version. Good idea to have a toggle for it + opts.fDisableDriverCorrectnessWorkarounds = mS.m->conf.disableGraphicsDriverWorkarounds; // Driver workarounds causing glitches on intel drivers on windows, but are required in the Emscripten version. Good idea to have a toggle for it mS.ctx = GrDirectContexts::MakeGL(iface, opts); if(!mS.ctx)