Skip to content

Free, open-source 3D sculpting for Linux, macOS and Windows: dense meshes, remeshing, painting, built-in AI (image/text to 3D), Send to Unreal, game-ready LODs, Gaussian splats and OpenUSD.

Merge main (workstream C: help, command palette, console, config) into ui-shell

islandmede4ff622149a3
diff --cc CMakeLists.txt
index e1906666,00e7c37e..a2d748da
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@@ -129,10 -129,9 +129,13 @@@ if(SCULPTFORGE_BUILD_APP
src/app/Ui.cpp
src/app/UiLayout.cpp
src/app/LightBoxStubs.cpp
+ src/app/Shell.cpp
+ src/app/ShellGeometry.cpp
+ src/app/Palettes.cpp
+ src/app/Theme.cpp
+ src/app/CommandPalette.cpp
+ src/app/Console.cpp
+ src/app/Config.cpp
src/app/PanelMasking.cpp
src/app/PanelPolygroups.cpp
src/app/PanelBrushes.cpp
@@@ -309,10 -308,14 +312,15 @@@ endif(
if(SCULPTFORGE_BUILD_TESTS)
# tests/test_main.cpp plus every tests/test_*.cpp (add a file to add tests; see tests/TestHarness.h).
file(GLOB SCULPTFORGE_TEST_SOURCES CONFIGURE_DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/tests/test_*.cpp)
- add_executable(sculptforge_tests ${SCULPTFORGE_TEST_SOURCES} src/cli/McpServer.cpp)
+ add_executable(sculptforge_tests ${SCULPTFORGE_TEST_SOURCES} src/cli/McpServer.cpp src/app/UiLayout.cpp
+ src/app/ShellGeometry.cpp)
target_include_directories(sculptforge_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests)
target_link_libraries(sculptforge_tests PRIVATE sculptforge_core sculptforge_ai)
+ if(SCULPTFORGE_BUILD_APP) # the action registry (key chords, shortcut overrides) needs SDL's key names
+ target_sources(sculptforge_tests PRIVATE src/app/Actions.cpp)
+ target_link_libraries(sculptforge_tests PRIVATE SDL3::SDL3)
+ target_compile_definitions(sculptforge_tests PRIVATE SF_TEST_ACTIONS)
+ endif()
if(MSVC)
target_compile_options(sculptforge_tests PRIVATE /utf-8)
endif()
@@@ -336,9 -339,5 +344,12 @@@
add_test(NAME ui_${name} COMMAND sculptforge --ui-test ${script} --ui-out ${CMAKE_CURRENT_BINARY_DIR}/ui-shots/${name})
set_tests_properties(ui_${name} PROPERTIES LABELS ui TIMEOUT 300)
endforeach()
+ # The shell layout again on a 1920x1080 window (docs/ui-design.md §2.3).
+ add_test(NAME ui_shell_layout_1080 COMMAND sculptforge --ui-test ${CMAKE_CURRENT_SOURCE_DIR}/tests/ui/shell_layout.sfui
+ --size 1920x1080 --ui-out ${CMAKE_CURRENT_BINARY_DIR}/ui-shots/shell_layout_1080)
+ set_tests_properties(ui_shell_layout_1080 PROPERTIES LABELS ui TIMEOUT 300)
++ add_test(NAME ui_help_console_1080 COMMAND sculptforge --ui-test ${CMAKE_CURRENT_SOURCE_DIR}/tests/ui/help_console.sfui
++ --size 1920x1080 --ui-out ${CMAKE_CURRENT_BINARY_DIR}/ui-shots/help_console_1080)
++ set_tests_properties(ui_help_console_1080 PROPERTIES LABELS ui TIMEOUT 300)
endif()
endif()
diff --cc src/app/App.cpp
index 2330243a,4b7a8f77..449eb4cd
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@@ -162,9 -180,11 +161,11 @@@ bool App::init(const AppOptions& option
float density = SDL_GetWindowPixelDensity(window_);
float scale = SDL_GetWindowDisplayScale(window_) / (density > 0.0f ? density : 1.0f);
if (scale <= 0.0f) scale = 1.0f;
+ initUiConfig(headless || !options.demo.empty()); // ui.json (layout, shortcuts, UI scale); never for tests and videos
+ if (!headless && uiPrefs_.uiScale > 0.0f) scale = uiPrefs_.uiScale;
if (recording) scale = float(options.height) / 900.0f; // UI sized for the video, not this screen
uiScale_ = scale;
- applyStyle();
+ theme::applyStyle();
ImGui::GetStyle().ScaleAllSizes(scale);
// Inter (SIL OFL), embedded in the binary. Rasterised at the final size for crisp text.
ImFontConfig fontConfig;
@@@ -184,34 -204,7 +185,35 @@@
io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontLucide), int(assets::fontLucide_size),
15.0f * scale, &icons, kIconRanges);
}
+ // Shell fonts: 12 px captions and 10 px right-shelf labels (with icons), large shelf icons, SemiBold titles.
+ {
+ auto addIcons = [&](float size) {
+ static const ImWchar kIconRanges[] = {ICON_MIN_LC, ICON_MAX_LC, 0};
+ ImFontConfig icons;
+ icons.MergeMode = true;
+ icons.PixelSnapH = true;
+ icons.FontDataOwnedByAtlas = false;
+ icons.GlyphMinAdvanceX = size * scale;
+ icons.GlyphOffset = ImVec2(0, size * 0.13f * scale);
+ io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontLucide), int(assets::fontLucide_size),
+ size * scale, &icons, kIconRanges);
+ };
+ fontSmall_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontRegular),
+ int(assets::fontRegular_size), 12.0f * scale, &fontConfig);
+ addIcons(12.0f);
+ fontTiny_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontRegular),
+ int(assets::fontRegular_size), 10.5f * scale, &fontConfig);
+ fontBold_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontSemiBold),
+ int(assets::fontSemiBold_size), 15.0f * scale, &fontConfig);
+ addIcons(15.0f);
+ static const ImWchar kIconRanges[] = {ICON_MIN_LC, ICON_MAX_LC, 0};
+ ImFontConfig big;
+ big.PixelSnapH = true;
+ big.FontDataOwnedByAtlas = false;
+ fontIcons_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontLucide), int(assets::fontLucide_size),
+ 20.0f * scale, &big, kIconRanges);
+ }
+ addHelpFonts(scale); // Ctrl-help titles (Inter SemiBold) and the console (ProggyClean)
if (recording) {
fontCaption_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontSemiBold),
int(assets::fontSemiBold_size), float(options.height) * 0.042f,
@@@ -1099,44 -1061,84 +1061,11 @@@ void App::drawUi()
}
ImGui::End();
}
- if (showHelp_) {
- ImGui::SetNextWindowSize(ImVec2(440, 0), ImGuiCond_FirstUseEver);
- if (ImGui::Begin("Controls", &showHelp_)) {
- ImGui::TextUnformatted(
- "Sculpt Left drag on the model\n"
- "Invert (subtract) Hold Alt while sculpting\n"
- "Smooth Hold Shift while sculpting\n"
- "Rotate Left drag on background / right drag\n"
- "Pan Alt + left drag background / middle drag\n"
- "Zoom Mouse wheel / Ctrl + middle drag\n"
- " (Ctrl + left drag background when nothing is masked)\n"
- "Paint mask Hold Ctrl while stroking (Ctrl+Alt erases)\n"
- "Invert mask Ctrl + click background\n"
- "Clear mask Ctrl + drag background\n"
- "Isolate polygroup Ctrl+Shift+click (again: invert)\n"
- "Hide polygroup Ctrl+Shift+Alt+click\n"
- "Show all Ctrl+Shift+click background\n"
- "Select SubTool Alt+click it\n"
- "Hide outside rect Ctrl+Shift+drag (Alt: inside)\n"
- "Brush size [ and ]\n"
- "Brushes 1-9, 0\n"
- "Paint brush P (colour only; Alt paints white)\n"
- "Pick colour C over the model\n"
- "Symmetry X X\n"
- "Wireframe W\n"
- "Frame model F\n"
- "Subdivide Ctrl+D\n"
- "Undo / Redo Ctrl+Z / Ctrl+Shift+Z\n"
- "Open / Save Ctrl+O / Ctrl+S (project; Shift: Save As)\n"
- "Tablet pressure is used automatically when a pen is detected.\n"
- "Drop a model (.obj/.glb), brush (.sfbrush) or image onto the window.");
- }
- ImGui::End();
- }
+ drawHelpConsoleUi(); // console, command palette, Controls (F1), Ctrl-hover help: last, on top
}
-void App::drawMenuBar() {
- if (!ImGui::BeginMainMenuBar()) return;
- if (ImGui::BeginMenu("File")) {
- if (ImGui::MenuItem("New Sphere", "Ctrl+N")) confirmDiscard([this] { runCommand("new_sphere"); });
- if (ImGui::MenuItem("New Plane")) confirmDiscard([this] { runCommand("new_plane"); });
- ImGui::Separator();
- if (ImGui::MenuItem("Open...", "Ctrl+O")) confirmDiscard([this] { openFileDialog(); });
- if (ImGui::MenuItem("Generate 3D..."))
- SDL_ShowOpenFileDialog(onFileChosen, &dialogRequests_[int(FileAction::OpenImage)], window_, kImageFilters, 2,
- nullptr, false);
- drawFileMenuProjectItems(); // Open Recent, Save, Save As, autosave
- ImGui::Separator();
- if (ImGui::MenuItem("Export OBJ...")) saveFileDialog(FileAction::SaveObj);
- if (ImGui::MenuItem("Export GLB (blend shapes)...", "Ctrl+E")) saveFileDialog(FileAction::ExportGlb);
- if (ImGui::MenuItem("Export LOD Chain...")) saveFileDialog(FileAction::ExportLods);
- if (ImGui::MenuItem("Export USD / USDZ...")) saveFileDialog(FileAction::ExportUsd);
- if (ImGui::MenuItem("Export FBX for Unreal...")) saveFileDialog(FileAction::ExportUnreal);
- if (ImGui::MenuItem("Send to Unreal", "Ctrl+U", false, !pendingUnreal_.valid())) sendToUnreal();
- if (ImGui::MenuItem("Save Splats...", nullptr, false, !doc_.splats.empty())) saveFileDialog(FileAction::SaveSplats);
- ImGui::Separator();
- drawGozMenu();
- ImGui::Separator();
- if (ImGui::MenuItem("Quit")) requestQuit();
- ImGui::EndMenu();
- }
- if (ImGui::BeginMenu("Edit")) {
- std::string undoText = doc_.undo.canUndo() ? "Undo " + doc_.undo.undoLabel() : "Undo";
- std::string redoText = doc_.undo.canRedo() ? "Redo " + doc_.undo.redoLabel() : "Redo";
- if (ImGui::MenuItem(undoText.c_str(), "Ctrl+Z", false, doc_.undo.canUndo())) runCommand("undo");
- if (ImGui::MenuItem(redoText.c_str(), "Ctrl+Shift+Z", false, doc_.undo.canRedo())) runCommand("redo");
- ImGui::EndMenu();
- }
- if (ImGui::BeginMenu("Mesh")) {
- if (ImGui::MenuItem("Subdivide", "Ctrl+D")) runCommand("subdivide");
- if (ImGui::MenuItem("Voxel Remesh")) runCommand("remesh", {{"resolution", double(voxelResolution_)}});
- if (ImGui::MenuItem("Sculpt to Splats")) runCommand("mesh_to_splats");
- ImGui::EndMenu();
- }
- if (ImGui::BeginMenu("View")) {
- ImGui::MenuItem("Wireframe", "W", &renderSettings_.wireframe);
- ImGui::MenuItem("Show Mesh", nullptr, &renderSettings_.showMesh);
- ImGui::MenuItem("Show Polypaint", nullptr, &renderSettings_.showPolypaint);
- ImGui::MenuItem("Show Mask", nullptr, &renderSettings_.showMask);
- ImGui::MenuItem("Show Polygroups", nullptr, &renderSettings_.showPolygroups);
- ImGui::Separator();
- ImGui::MenuItem("SubTools Panel", nullptr, &showSubToolsPanel_);
- ImGui::MenuItem("Layers Panel", nullptr, &showLayersPanel_);
- ImGui::MenuItem("Game Ready Panel", nullptr, &showGamePanel_);
- ImGui::MenuItem("Gaussian Splats", nullptr, &showSplatsPanel_);
- ImGui::MenuItem("Brush Lab", nullptr, &showBrushLab_);
- ImGui::MenuItem("Community brushes", nullptr, &showBrushGallery_);
- ImGui::MenuItem("Polypaint & Materials", nullptr, &showPolypaintPanel_);
- ImGui::MenuItem("Generate 3D", nullptr, &showImageTo3D_);
- ImGui::MenuItem("Show Splats", nullptr, &renderSettings_.showSplats, !doc_.splats.empty());
- if (ImGui::MenuItem("Frame Model", "F")) camera_.frame(sceneBounds());
- ImGui::EndMenu();
- }
- if (ImGui::BeginMenu("Help")) {
- ImGui::MenuItem("Controls", "F1", &showHelp_);
- ImGui::MenuItem("About SculptForge", nullptr, &showAbout_);
- if (ImGui::MenuItem("Website & documentation")) SDL_OpenURL("https://islandmed.github.io/SculptForge/");
- if (ImGui::MenuItem("Report a problem")) SDL_OpenURL("https://github.com/islandmed/SculptForge/issues");
- ImGui::EndMenu();
- }
- ImGui::EndMainMenuBar();
-}
-
-void App::drawLayersPanel() {
+void App::drawLayersContents() {
const float scale = uiScale_;
- const ImGuiViewport* vp = ImGui::GetMainViewport();
- ImGui::SetNextWindowPos(ImVec2(vp->Pos.x + vp->Size.x - 290 * scale, vp->Pos.y + 34 * scale), ImGuiCond_FirstUseEver);
- if (!beginPanel("Layers / Blend Shapes", nullptr, 280 * scale)) {
- ImGui::End();
- return;
- }
ImGui::TextDisabled("Sculpt expressions & correctives;\nexported as glTF morph targets.");
if (ImGui::RadioButton("Base mesh", doc_.activeLayer < 0)) runCommand("layer_set_active", {{"index", -1.0}});
diff --cc src/app/App.h
index b0721b92,341a93e7..2540e422
--- a/src/app/App.h
+++ b/src/app/App.h
@@@ -4,9 -4,11 +4,12 @@@
#include "ai/BrushAssistant.h"
#include "app/Actions.h"
+ #include "app/CommandPalette.h"
+ #include "app/Config.h"
+ #include "app/Console.h"
#include "app/LightBox.h"
#include "app/Pickers.h"
+#include "app/ShellGeometry.h"
#include "app/Thumbnails.h"
#include "app/UiLayout.h"
#include "ai/ComfyUI.h"
@@@ -428,97 -443,7 +431,94 @@@ private
std::unique_ptr<struct BrushGalleryState, void (*)(struct BrushGalleryState*)> gallery_{nullptr, &destroyBrushGallery};
// ---- Shell (A): layout, shelves, palettes, trays, theme ----
+public:
+ // The part of the window the 3D view uses (logical px); the whole window while the UI is hidden.
+ CanvasRect canvasRect() const;
+ ShellGeometry shellGeometry() const; // every shell region for the current window (console rect, trays...)
+ ImFont* smallFont() const { return fontSmall_; } // 12 px captions (shelf labels, tiles)
+ ImFont* boldFont() const { return fontBold_; } // SemiBold 15 (help titles)
+
+private:
UiLayout layout_ = standardLayout();
- friend bool drawActionLook(App&, const Action&, ImVec2, int);
++ friend bool drawShelfTile(App&, const Action&, ImVec2);
+ friend const struct PaletteDef* palettes(int&);
+ // Shell.cpp: title strip, palette bar, shelves, trays, dividers, drop-downs, customize drag and drop.
+ void registerShellActions();
+ void drawShell();
+ void drawTitleStrip(const ShellGeometry& g);
+ void drawPaletteBar(const ShellGeometry& g);
+ void drawShelf(int shelf, const CanvasRect& rect);
+ void drawShelfItem(int shelf, int index, const std::string& item, bool vertical);
+ void drawTray(bool right, const CanvasRect& rect);
+ void drawDivider(bool right, const CanvasRect& rect);
+ void drawPaletteDropdown();
+ bool paletteHeader(const char* id, bool inTray, bool right); // false: collapsed
+ void drawPaletteBody(const std::string& id);
+ void movePaletteToTray(const std::string& id, bool right);
+ void removePaletteFromTrays(const std::string& id);
+ void finishShelfDrag();
+ void noteLayoutChanged();
+ void applyPreset(int preset);
+ void updateCameraAspect(); // camera_.aspect from the canvas
+ // Ray through window point (x, y) of the canvas, and the canvas height for screen-size conversions.
+ void canvasRay(float x, float y, glm::vec3& origin, glm::vec3& dir) const;
+ float canvasHeight() const { return canvasRect().h; }
+ Renderer::Viewport canvasViewport(int fbWidth, int fbHeight) const; // the canvas in framebuffer pixels
+ void drawCanvasFrame();
+ bool canvasNavButton(const char* id, const char* icon, const char* label, int mode); // right-shelf Move/Zoom/Rotate
+ void drawBrushTile(const char* id, ImVec2 size);
+ void drawStrokeTile(const char* id, ImVec2 size);
+ void drawAlphaTile(const char* id, ImVec2 size);
+ void drawMaterialTile(const char* id, ImVec2 size);
+ void drawColorWidget(float width);
+ void drawAddToShelfPopup();
+ // Palettes.cpp: every palette body, also used by the trays and drop-downs.
+ bool subpalette(const char* id, const char* title); // Tool sub-palette header; true while open
+ void drawPalette_Alpha();
+ void drawPalette_Brush();
+ void drawPalette_Color();
+ void drawPalette_Draw();
+ void drawPalette_Edit();
+ void drawPalette_File();
+ void drawPalette_Generate();
+ void drawPalette_Help();
+ void drawPalette_Material();
+ void drawPalette_Preferences();
+ void drawPalette_Render();
+ void drawPalette_Script();
+ void drawPalette_Splats();
+ void drawPalette_Stroke();
+ void drawPalette_Tool();
+ void drawPalette_Transform();
+ void drawStrokeSection();
+ void drawAlphaSection();
+ void drawMaterialGrid(float tile);
+ void drawLayersContents();
+ void drawGameExportContents();
+ void drawVisibilitySection();
+ void drawSubToolsContents();
+ void pollAlphaFile();
+ ShellGeometry shell_; // this frame's regions (drawShell)
+ ImFont* fontSmall_ = nullptr, *fontTiny_ = nullptr, *fontIcons_ = nullptr, *fontBold_ = nullptr;
+ std::string dropdown_; // palette open as a drop-down ("" = none)
+ float dropdownX_ = 0.0f;
+ bool openDropdown_ = false;
+ float decimateRatio_ = 0.5f;
+ std::string flashPalette_; // a tray palette that was clicked in the bar: scrolled to and flashed
+ double flashStart_ = 0.0;
+ std::vector<std::string> collapsedPalettes_; // tray palettes showing only their header
- bool oneSubpalette_ = true; // ZBrush: opening a sub-palette closes the others (Shift+click keeps them)
- bool autoCollapse_[2] = {true, false}; // left, right tray: opening a palette there collapses the others (ZBrush)
+ void autoCollapseTray(bool right, const std::string& keep);
- bool layoutHintShown_ = false;
+ glm::vec3 secondaryColor_{1.0f, 1.0f, 1.0f}; // the left shelf's second swatch (click swaps, "Alternate")
+ uint64_t activeTrisKey_ = ~uint64_t(0); // the top shelf's ActiveTris, recounted when the scene changes
+ size_t activeTris_ = 0;
+ float bottomTileW_ = 58.0f; // bottom shelf tiles shrink (down to 44 px) before the shelf scrolls
+ int navDrag_ = -1; // right-shelf drag button being dragged (0 move, 1 zoom, 2 rotate)
+ std::string statusShown_; // for colouring fresh errors in the title strip
+ double statusSince_ = 0.0;
+ struct ShelfDrag {
+ bool active = false, accepted = false;
+ int shelf = -1, index = -1;
+ } shelfDrag_;
// ---- end Shell (A) ----
// ---- LightBox (B): LightBox, thumbnails, pickers ----
diff --cc src/app/Config.cpp
index 00000000,ad728372..3177aaa0
mode 000000,100644..100644
--- a/src/app/Config.cpp
+++ b/src/app/Config.cpp
@@@ -1,0 -1,788 +1,784 @@@
+ // SculptForge - open source digital sculpting
+ // SPDX-License-Identifier: GPL-3.0-or-later
+ //
+ // Default actions and shortcuts, Store Config / Restore / Save / Load UI,
+ // the Preferences > Config / Interface / Hotkeys / LightBox sections, the F1
+ // Controls sheet (generated from the action registry) and ZBrush-style
+ // shortcut assignment.
+ #include "app/Config.h"
+
+ #include "app/App.h"
+ #include "app/Ui.h"
+ #include "core/Script.h"
+
+ #include <IconsLucide.h>
+ #include <imgui_internal.h>
+
+ #include <algorithm>
+ #include <cctype>
+ #include <cfloat>
+ #include <cmath>
+ #include <filesystem>
+ #include <fstream>
+ #include <map>
+
+ namespace sf {
+
+ namespace assets {
+ extern const unsigned char fontSemiBold[];
+ extern const unsigned long long fontSemiBold_size;
+ extern const unsigned char fontLucide[];
+ extern const unsigned long long fontLucide_size;
+ } // namespace assets
+
+ Json toJson(const UiPrefs& p) {
+ Json j = Json::object();
+ j.set("popupInfo", p.popupInfo);
+ j.set("helpOpacity", double(p.helpOpacity));
+ j.set("tooltipDelay", double(p.tooltipDelay));
+ j.set("oneSubpalette", p.oneSubpalette);
+ j.set("autoCollapseLeft", p.autoCollapseLeft);
+ j.set("autoCollapseRight", p.autoCollapseRight);
+ j.set("uiScale", double(p.uiScale));
+ j.set("lightboxAtStartup", p.lightboxAtStartup);
+ j.set("libraryFolder", p.libraryFolder);
+ return j;
+ }
+
+ void fromJson(const Json& j, UiPrefs& p) {
+ if (!j.isObject()) return;
+ p.popupInfo = j["popupInfo"].asBool(p.popupInfo);
+ p.helpOpacity = std::clamp(float(j["helpOpacity"].asNumber(p.helpOpacity)), 0.3f, 1.0f);
+ p.tooltipDelay = std::clamp(float(j["tooltipDelay"].asNumber(p.tooltipDelay)), 0.0f, 3.0f);
+ p.oneSubpalette = j["oneSubpalette"].asBool(p.oneSubpalette);
+ p.autoCollapseLeft = j["autoCollapseLeft"].asBool(p.autoCollapseLeft);
+ p.autoCollapseRight = j["autoCollapseRight"].asBool(p.autoCollapseRight);
+ p.uiScale = std::clamp(float(j["uiScale"].asNumber(p.uiScale)), 0.0f, 3.0f);
+ p.lightboxAtStartup = j["lightboxAtStartup"].asBool(p.lightboxAtStartup);
+ if (j["libraryFolder"].isString()) p.libraryFolder = j["libraryFolder"].asString();
+ }
+
+ namespace {
+
+ enum UiFileKind { kSaveUi, kLoadUi, kRunScript, kLibraryFolder, kUiFileKinds };
+
+ struct UiFileRequest {
+ App* app = nullptr;
+ int kind = 0;
+ };
+ UiFileRequest g_requests[kUiFileKinds];
+
+ void SDLCALL onUiFileChosen(void* userdata, const char* const* files, int) {
+ if (!files || !files[0]) return;
+ auto* req = static_cast<UiFileRequest*>(userdata);
+ req->app->queueUiFile(req->kind, files[0]);
+ }
+
+ const SDL_DialogFileFilter kUiFilters[] = {{"SculptForge UI layout", "json"}};
+ const SDL_DialogFileFilter kScriptFilters[] = {{"SculptForge script", "sfscript;txt"}, {"All files", "*"}};
+
+ std::filesystem::path fsPath(const std::string& utf8) { return std::filesystem::path(std::u8string(utf8.begin(), utf8.end())); }
+
+ bool fileExists(const std::string& path) {
+ std::error_code ec;
+ return !path.empty() && std::filesystem::is_regular_file(fsPath(path), ec);
+ }
+
+ std::string lower(std::string s) {
+ for (auto& c : s) c = char(std::tolower(static_cast<unsigned char>(c)));
+ return s;
+ }
+
+ ImVec4 col(ImU32 c) { return ImGui::ColorConvertU32ToFloat4(c); }
+
+ // The mouse and pen gestures (not actions, so not in the registry).
+ struct Gesture {
+ const char* what;
+ const char* how;
+ };
+ constexpr Gesture kGestures[] = {
+ {"Sculpt", "Left drag on the model"},
+ {"Invert (subtract)", "Hold Alt while sculpting"},
+ {"Smooth", "Hold Shift while sculpting"},
+ {"Rotate", "Left drag on the background, or right drag"},
+ {"Pan", "Alt + left drag on the background, or middle drag"},
+ {"Zoom", "Mouse wheel, Ctrl + middle drag, or Ctrl + left drag on the background (nothing masked)"},
+ {"Paint mask", "Hold Ctrl while stroking (Ctrl+Alt erases)"},
+ {"Invert mask", "Ctrl + click the background"},
+ {"Clear mask", "Ctrl + drag on the background"},
+ {"Isolate polygroup", "Ctrl+Shift + click it (again: invert)"},
+ {"Hide polygroup", "Ctrl+Shift+Alt + click it"},
+ {"Show all", "Ctrl+Shift + click the background"},
+ {"Hide outside a rectangle", "Ctrl+Shift + drag (add Alt: inside)"},
+ {"Select a SubTool", "Alt + click it"},
+ {"Help on any control", "Hold Ctrl and point at it (Ctrl+Alt: scripting parameters)"},
+ {"Assign a shortcut", "Ctrl+Alt + click any button, then press the key"},
+ {"Tablet pressure", "Used automatically when a pen is detected"},
+ {"Open files", "Drop a model (.obj, .glb ...), brush (.sfbrush) or image onto the window"},
+ };
+
+ } // namespace
+
+ // ---------------------------------------------------------------------------
+ // Startup
+ // ---------------------------------------------------------------------------
+
+ void App::initUiConfig(bool deterministic) {
+ uiConfigDeterministic_ = deterministic;
+ if (char* pref = SDL_GetPrefPath("SculptForge", "SculptForge")) {
+ configDir_ = pref;
+ SDL_free(pref);
+ }
+ layout_ = standardLayout();
+ if (deterministic) return; // tests, renders and recordings always use the standard layout
+ std::string err;
+ if (fileExists(uiConfigPath()) && !readUiConfig(uiConfigPath(), err)) SDL_Log("%s", err.c_str());
+ }
+
+ void App::addHelpFonts(float scale) {
+ ImGuiIO& io = ImGui::GetIO();
+ ImFontConfig cfg;
+ cfg.FontDataOwnedByAtlas = false;
+ cfg.OversampleH = 2;
+ fontHelpTitle_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontSemiBold),
+ int(assets::fontSemiBold_size), 15.0f * scale, &cfg);
+ static const ImWchar kIconRanges[] = {ICON_MIN_LC, ICON_MAX_LC, 0};
+ ImFontConfig icons;
+ icons.MergeMode = true;
+ icons.PixelSnapH = true;
+ icons.FontDataOwnedByAtlas = false;
+ icons.GlyphMinAdvanceX = 15.0f * scale;
+ icons.GlyphOffset = ImVec2(0, 2.0f * scale);
+ io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontLucide), int(assets::fontLucide_size), 15.0f * scale,
+ &icons, kIconRanges);
+ // ProggyClean (ships inside Dear ImGui) is a pixel font: keep it at whole multiples of 13 px.
+ ImFontConfig mono;
+ mono.SizePixels = 13.0f * std::max(1.0f, std::floor(scale + 0.25f));
+ fontConsole_ = io.Fonts->AddFontDefault(&mono);
+ }
+
+ void App::initActions() {
+ for (int i = 0; i < kUiFileKinds; ++i) g_requests[i] = {this, i};
+ auto add = [&](const char* id, const char* label, const char* palette, const char* shortcut, std::function<void()> run,
+ const char* icon = nullptr, const char* command = nullptr, std::function<bool()> checked = nullptr,
+ std::function<bool()> enabled = nullptr, const char* description = nullptr) {
+ Action a;
+ a.id = id;
+ a.label = label;
+ a.palette = palette;
+ a.shortcut = shortcut ? shortcut : "";
+ a.run = std::move(run);
+ a.icon = icon;
+ a.command = command ? command : "";
+ a.checked = std::move(checked);
+ a.enabled = std::move(enabled);
+ if (description) a.description = description;
+ else if (const Command* c = a.command.empty() ? nullptr : commands_.find(a.command)) a.description = c->description;
+ actions_.add(std::move(a));
+ };
+
+ // --- The shortcuts SculptForge always had (unchanged meaning) ---
+ add("edit.undo", "Undo", "Edit", "Ctrl+Z", [this] { runCommand("undo"); }, ICON_LC_UNDO_2, "undo", nullptr,
+ [this] { return doc_.undo.canUndo(); });
+ add("edit.redo", "Redo", "Edit", "Ctrl+Shift+Z / Ctrl+Y", [this] { runCommand("redo"); }, ICON_LC_REDO_2, "redo", nullptr,
+ [this] { return doc_.undo.canRedo(); });
+ add("geometry.subdivide", "Subdivide", "Tool > Geometry", "Ctrl+D", [this] { runCommand("subdivide"); }, nullptr, "subdivide");
+ add("file.new_sphere", "New Sphere", "File", "Ctrl+N", [this] { confirmDiscard([this] { runCommand("new_sphere"); }); },
+ ICON_LC_FILE_PLUS, "new_sphere");
+ add("file.new_plane", "New Plane", "File", nullptr, [this] { confirmDiscard([this] { runCommand("new_plane"); }); }, nullptr,
+ "new_plane");
+ add("file.open", "Open...", "File", "Ctrl+O", [this] { confirmDiscard([this] { openFileDialog(); }); }, ICON_LC_FOLDER_OPEN,
+ nullptr, nullptr, nullptr, "Open a project (.sfproj), a model (.obj, .glb, .fbx, .stl, .ply, .usd ...) or splats.");
+ add("file.save", "Save", "File", "Ctrl+S", [this] { saveProjectAs(false); }, ICON_LC_SAVE, nullptr, nullptr, nullptr,
+ "Save the project (.sfproj: every SubTool, layer, brush and setting). Asks for a name the first time.");
+ add("file.save_as", "Save As...", "File", "Ctrl+Shift+S", [this] { saveProjectAs(true); }, nullptr, nullptr, nullptr, nullptr,
+ "Save the project under a new name.");
+ add("file.export_glb", "Export GLB...", "File > Export", "Ctrl+E", [this] { saveFileDialog(FileAction::ExportGlb); },
+ ICON_LC_PACKAGE, nullptr, nullptr, nullptr,
+ "Export the model as glTF binary, with sculpt layers as blend shapes (morph targets).");
+ add("file.send_unreal", "Send to Unreal", "File > Export", "Ctrl+U", [this] { sendToUnreal(); }, ICON_LC_SEND, nullptr,
+ nullptr, [this] { return !pendingUnreal_.valid(); },
+ "Export a game-ready FBX and import it into the running Unreal Editor (Python remote execution).");
+ add("brush.paste", "Paste brush", "Brush", "Ctrl+V", [this] { pasteBrush(); }, ICON_LC_CLIPBOARD_PASTE, nullptr, nullptr,
+ nullptr, "Add the brush on the clipboard: a brush code someone shared, or the text of a .sfbrush file.");
+ add("brush.size_down", "Smaller brush", "Draw", "[", [this] { radiusPx_ = std::max(2.0f, radiusPx_ / 1.1f); }, nullptr,
+ nullptr, nullptr, nullptr, "Make the brush 10% smaller (hold to repeat).");
+ add("brush.size_up", "Larger brush", "Draw", "]", [this] { radiusPx_ = std::min(800.0f, radiusPx_ * 1.1f); }, nullptr,
+ nullptr, nullptr, nullptr, "Make the brush 10% larger (hold to repeat).");
+ add("transform.symmetry_x", "Symmetry X", "Transform", "X", [this] { symmetry_.x = !symmetry_.x; }, ICON_LC_FLIP_HORIZONTAL_2,
+ nullptr, [this] { return symmetry_.x; }, nullptr, "Mirror strokes across the X axis (left / right).");
+ add("view.wireframe", "Wireframe", "Render", "W / Shift+F", [this] { renderSettings_.wireframe = !renderSettings_.wireframe; },
+ ICON_LC_GRID_3X3, nullptr, [this] { return renderSettings_.wireframe; }, nullptr,
+ "Show the mesh's triangles over the surface (ZBrush PolyFrame).");
+ add("view.frame", "Frame model", "Transform", "F", [this] { camera_.frame(sceneBounds()); }, ICON_LC_SCAN, nullptr, nullptr,
+ nullptr, "Fit the whole model in the view.");
- add("paint.toggle", "Paint mode", "Draw", "P",
- [this] {
- paintMode_ = !paintMode_;
- if (paintMode_) showPolypaintPanel_ = true; // colour picker at hand
- },
- ICON_LC_PAINTBRUSH, nullptr, [this] { return paintMode_; }, nullptr,
- "Switch between sculpting and polypainting (colour only; Alt paints white).");
+ add("color.pick", "Pick colour", "Color", "C", [this] { pickColorUnderCursor(); }, ICON_LC_PIPETTE, nullptr, nullptr, nullptr,
+ "Take the paint colour from the model under the cursor.");
+ for (int i = 0; i < int(BrushType::Count); ++i) {
+ const auto type = BrushType(i);
+ std::string id = "brush.";
+ for (const char* c = brushName(type); *c; ++c)
+ if (*c != ' ') id += char(std::tolower(static_cast<unsigned char>(*c)));
+ const std::string key = i < 9 ? std::to_string(i + 1) : i == 9 ? std::string("0") : std::string();
+ add(id.c_str(), brushName(type), "Brush", key.c_str(),
+ [this, type] {
+ brush_ = type;
+ doc_.activeBrush = -1;
+ paintMode_ = false;
+ },
+ ICON_LC_BRUSH, nullptr, [this, type] { return brush_ == type && doc_.activeBrush < 0 && !paintMode_; }, nullptr,
+ (std::string("Sculpt with the ") + brushName(type) + " brush.").c_str());
+ }
+
+ // --- Help ---
+ add("help.controls", "Controls", "Help", "F1", [this] { showHelp_ = !showHelp_; }, ICON_LC_KEYBOARD, nullptr,
+ [this] { return showHelp_; }, nullptr, "Every shortcut and mouse gesture, generated from the commands themselves.");
+ add("help.about", "About SculptForge", "Help", nullptr, [this] { showAbout_ = true; }, ICON_LC_INFO, nullptr, nullptr, nullptr,
+ "Version, licence and the open-source components SculptForge is built with.");
+ add("help.website", "Website & documentation", "Help", nullptr, [] { SDL_OpenURL("https://islandmed.github.io/SculptForge/"); },
+ ICON_LC_BOOK_OPEN, nullptr, nullptr, nullptr, "Open the SculptForge website and user guide in your browser.");
+ add("help.report", "Report a problem", "Help", nullptr, [] { SDL_OpenURL("https://github.com/islandmed/SculptForge/issues"); },
+ ICON_LC_CIRCLE_ALERT, nullptr, nullptr, nullptr, "Open the issue tracker in your browser.");
+
+ // --- Command palette and console ---
+ add("ui.command_palette", "Command palette", "Help", "F3 / Ctrl+Shift+P", [this] { palette_.open(); }, ICON_LC_SEARCH, nullptr,
+ nullptr, nullptr,
+ "Search every command, brush and setting by name and run it. Commands that need parameters open in the console.");
+ add("ui.console", "Console", "Script", "`", [this] { setConsoleOpen(!layout_.consoleOpen); }, ICON_LC_SQUARE_TERMINAL, nullptr,
+ [this] { return layout_.consoleOpen; }, nullptr,
+ "The script console: every command you run appears as a script line, and you can type commands yourself.");
+ add("script.run_file", "Run script file...", "Script", nullptr,
+ [this] {
+ SDL_ShowOpenFileDialog(onUiFileChosen, &g_requests[kRunScript], window_, kScriptFilters, 2, nullptr, false);
+ },
+ ICON_LC_FILE_CODE, nullptr, nullptr, nullptr, "Run a text file of script statements, one per line (# starts a comment).");
+ add("script.copy_session", "Copy session as script", "Script", nullptr,
+ [this] {
+ const std::string script = console_.sessionScript();
+ SDL_SetClipboardText(script.c_str());
+ status_ = script.empty() ? "No commands run yet" : "Session copied as a script - paste it into a file to run it again";
+ },
+ ICON_LC_COPY, nullptr, nullptr, nullptr,
+ "Put every command run this session on the clipboard as a script, ready to replay (a macro recorder).");
+ add("script.clear_console", "Clear console", "Script", nullptr, [this] { console_.clear(); }, ICON_LC_TRASH_2, nullptr, nullptr,
+ nullptr, "Empty the console log (the session script is kept).");
+
+ // --- Config (ZBrush: Preferences > Config) ---
+ add("config.store", "Store Config", "Preferences > Config", "Ctrl+Shift+I", [this] { storeConfig(); }, ICON_LC_SAVE, nullptr,
+ nullptr, nullptr,
+ "Keep the current layout, shortcuts and interface preferences for future sessions. Like ZBrush, SculptForge never "
+ "saves them on its own.");
+ add("config.restore_standard", "Restore Standard UI", "Preferences > Config", nullptr, [this] { restoreStandardUi(); },
+ ICON_LC_ROTATE_CCW, nullptr, nullptr, nullptr,
+ "Go back to the built-in layout and default shortcuts. Store Config afterwards to make it stick.");
+ add("config.restore_custom", "Restore Custom UI", "Preferences > Config", nullptr, [this] { restoreCustomUi(); },
+ ICON_LC_ARCHIVE_RESTORE, nullptr, nullptr, [this] { return fileExists(uiConfigPath()); },
+ "Go back to the layout and shortcuts saved by the last Store Config.");
+ add("config.load", "Load UI...", "Preferences > Config", "Ctrl+L", [this] { loadUiDialog(); }, ICON_LC_FOLDER_INPUT, nullptr,
+ nullptr, nullptr, "Load a layout file someone shared (or you saved with Save UI).");
+ add("config.save", "Save UI...", "Preferences > Config", nullptr, [this] { saveUiDialog(); }, ICON_LC_FOLDER_OUTPUT, nullptr,
+ nullptr, nullptr, "Save the layout, shortcuts and interface preferences to a file you can share.");
+ add("config.customize", "Enable Customize", "Preferences > Config", nullptr,
+ [this] {
+ layout_.customize = !layout_.customize;
+ status_ = layout_.customize ? "Customize: Ctrl+Alt+drag to move or remove items" : "Customize off";
+ },
+ ICON_LC_LAYOUT_TEMPLATE, nullptr, [this] { return layout_.customize; }, nullptr,
+ "Rearrange the shelves: Ctrl+Alt+drag any button onto a shelf to add or move it, or off the shelves to remove it.");
+
++ // The shell's actions (Shell.cpp: brushes, shelves, palettes, trays): they replace any of the above with
++ // the same id and own P (Paint), the symmetry toggles and Tab.
++ registerShellActions();
++
+ // Every command, so the command palette finds anything scriptable.
+ actions_.registerCommands(
+ commands_, [this](const std::string& name) { runCommand(name); },
+ [this](const std::string& name) { consolePrefill(name + " "); });
+
+ if (!uiConfigDeterministic_ && !configDir_.empty()) {
+ console_.loadHistory(configDir_ + "console_history.txt");
+ std::ifstream f(fsPath(configDir_ + "recent_actions.txt"));
+ std::vector<std::string> recent;
+ for (std::string line; std::getline(f, line);)
+ if (!line.empty()) recent.push_back(line);
+ actions_.setRecent(std::move(recent));
+ }
+ layoutBaseline_ = layoutKey();
+ }
+
+ void App::saveRecentActions() {
+ if (uiConfigDeterministic_ || configDir_.empty()) return;
+ std::ofstream f(fsPath(configDir_ + "recent_actions.txt"), std::ios::binary | std::ios::trunc);
+ for (const auto& id : actions_.recent()) f << id << "\n";
+ }
+
+ // ---------------------------------------------------------------------------
+ // Store / restore
+ // ---------------------------------------------------------------------------
+
+ std::string App::uiConfigPath() const { return configDir_.empty() ? std::string() : configDir_ + "ui.json"; }
+
+ bool App::writeUiConfig(const std::string& path, std::string& err) {
+ Json j = Json::object();
+ j.set("version", 1.0);
+ j.set("layout", toJson(layout_));
+ j.set("shortcuts", actions_.overridesToJson());
+ j.set("prefs", toJson(uiPrefs_));
+ std::ofstream f(fsPath(path), std::ios::binary | std::ios::trunc);
+ f << j.dump(true) << "\n";
+ if (!f) {
+ err = "Could not write " + path;
+ return false;
+ }
+ return true;
+ }
+
+ bool App::readUiConfig(const std::string& path, std::string& err) {
+ std::ifstream f(fsPath(path), std::ios::binary);
+ if (!f) {
+ err = "Could not read " + path;
+ return false;
+ }
+ Json j;
+ if (!Json::parse(std::string(std::istreambuf_iterator<char>(f), {}), j, err)) {
+ err = path + ": " + err;
+ return false;
+ }
+ if (!j.isObject() || !j["layout"].isObject()) {
+ err = path + " is not a SculptForge UI configuration";
+ return false;
+ }
+ UiLayout layout;
+ if (!fromJson(j["layout"], layout, err)) return false;
+ const bool customize = layout_.customize;
+ layout_ = std::move(layout);
+ layout_.customize = customize;
+ actions_.overridesFromJson(j["shortcuts"]);
+ fromJson(j["prefs"], uiPrefs_);
+ return true;
+ }
+
+ void App::storeConfig() {
+ std::string err;
+ if (uiConfigPath().empty()) {
+ status_ = "Can't store the UI configuration: no settings folder";
+ } else if (!writeUiConfig(uiConfigPath(), err)) {
+ status_ = err;
+ } else {
+ status_ = "UI configuration stored";
+ layoutBaseline_ = layoutKey();
+ }
+ }
+
+ void App::restoreStandardUi() {
+ const bool customize = layout_.customize;
+ layout_ = standardLayout();
+ layout_.customize = customize;
+ actions_.clearOverrides();
+ layoutBaseline_ = layoutKey();
+ status_ = "Standard UI restored - Store Config (Ctrl+Shift+I) to keep it";
+ }
+
+ void App::restoreCustomUi() {
+ std::string err;
+ if (!fileExists(uiConfigPath())) {
+ status_ = "No stored UI configuration yet - Store Config (Ctrl+Shift+I) first";
+ } else if (!readUiConfig(uiConfigPath(), err)) {
+ status_ = err;
+ } else {
+ layoutBaseline_ = layoutKey();
+ status_ = "Custom UI restored";
+ }
+ }
+
+ void App::saveUiDialog() {
+ SDL_ShowSaveFileDialog(onUiFileChosen, &g_requests[kSaveUi], window_, kUiFilters, 1, nullptr);
+ }
+
+ void App::loadUiDialog() {
+ SDL_ShowOpenFileDialog(onUiFileChosen, &g_requests[kLoadUi], window_, kUiFilters, 1, nullptr, false);
+ }
+
+ void App::queueUiFile(int kind, std::string path) {
+ std::lock_guard<std::mutex> lock(uiFileMutex_);
+ uiFiles_.emplace_back(kind, std::move(path));
+ }
+
+ std::string App::layoutKey() const {
+ UiLayout l = layout_; // what a session changes on its own doesn't count as a layout edit
+ l.consoleOpen = false;
+ l.consoleHeight = 0;
+ l.lightboxOpen = false;
+ l.lightboxTab.clear();
+ l.customize = false;
+ return toJson(l).dump();
+ }
+
+ void App::watchLayoutChanges() {
+ if (layoutHintShown_ || uiConfigDeterministic_ || ++layoutCheckFrame_ % 20 != 0) return;
+ if (layoutKey() == layoutBaseline_) return;
+ layoutHintShown_ = true; // once per session (ZBrush never saves the layout by itself)
+ status_ = "Layout changed - Ctrl+Shift+I to keep it";
+ }
+
+ // ---------------------------------------------------------------------------
+ // Console and command palette glue
+ // ---------------------------------------------------------------------------
+
+ void App::setConsoleOpen(bool open) {
+ layout_.consoleOpen = open;
+ if (open) console_.focusInput();
+ }
+
+ void App::consolePrefill(const std::string& text) {
+ layout_.consoleOpen = true;
+ console_.prefill(text);
+ }
+
+ void App::consoleEcho(const std::string& name, const Args& args, const CommandResult& r) {
+ console_.echo(formatStatement(name, args), r, commandSource_);
+ console_.seenStatus(status_);
+ }
+
-CanvasRect App::paletteArea() const {
- const ImGuiViewport* vp = ImGui::GetMainViewport();
- return {vp->WorkPos.x, vp->WorkPos.y, vp->WorkSize.x, vp->WorkSize.y};
-}
++CanvasRect App::paletteArea() const { return canvasRect(); } // top centre of the canvas
+
+ CanvasRect App::consoleRect() const {
- // The shell reserves this strip above the bottom shelf; on its own, the console spans the window bottom.
++ // The shell reserves this strip between the canvas and the bottom shelf (ShellGeometry::console);
++ // with the UI hidden (demos), the bottom of the window.
++ if (!hideUi_) return shellGeometry().console;
+ const ImGuiViewport* vp = ImGui::GetMainViewport();
+ const float h = std::min(std::clamp(layout_.consoleHeight, 100.0f, 400.0f) * uiScale_, vp->WorkSize.y * 0.6f);
+ return {vp->WorkPos.x, vp->WorkPos.y + vp->WorkSize.y - h, vp->WorkSize.x, h};
+ }
+
+ // ---------------------------------------------------------------------------
+ // Shortcut assignment (Ctrl+Alt+click a button, or Preferences > Hotkeys)
+ // ---------------------------------------------------------------------------
+
+ void App::beginShortcutCapture(const std::string& actionId) {
+ const Action* a = actions_.find(actionId);
+ if (!a) return;
+ capturingShortcut_ = actionId;
+ status_ = "Press a key for '" + a->label + "' (Esc cancels, Backspace clears)";
+ }
+
+ bool App::captureShortcutKey(SDL_Keycode key, SDL_Keymod mod) {
+ if (capturingShortcut_.empty()) return false;
+ if (isModifierKey(key)) return true;
+ const Action* a = actions_.find(capturingShortcut_);
+ const std::string label = a ? a->label : capturingShortcut_;
+ if (key == SDLK_ESCAPE) {
+ status_ = "Shortcut unchanged";
+ } else if (key == SDLK_BACKSPACE || key == SDLK_DELETE) {
+ actions_.setShortcut(capturingShortcut_, "");
+ status_ = label + ": no shortcut - Store Config (Ctrl+Shift+I) to keep it";
+ } else {
+ const std::string chord = chordText(chordFromEvent(key, mod));
+ const std::string lost = actions_.assignShortcut(capturingShortcut_, chord);
+ status_ = label + ": " + chord + (lost.empty() ? "" : " (was " + lost + ")") + " - Store Config (Ctrl+Shift+I) to keep it";
+ }
+ capturingShortcut_.clear();
+ return true;
+ }
+
+ // ---------------------------------------------------------------------------
+ // Per-frame UI
+ // ---------------------------------------------------------------------------
+
+ void App::drawHelpConsoleUi() {
+ {
+ std::vector<std::pair<int, std::string>> files;
+ {
+ std::lock_guard<std::mutex> lock(uiFileMutex_);
+ files.swap(uiFiles_);
+ }
+ for (auto& [kind, path] : files) {
+ std::string err;
+ if (kind == kSaveUi) {
+ if (fsPath(path).extension().empty()) path += ".json";
+ status_ = writeUiConfig(path, err) ? "UI layout saved to " + path : err;
+ } else if (kind == kLoadUi) {
+ if (readUiConfig(path, err)) {
+ status_ = "UI layout loaded - Store Config (Ctrl+Shift+I) to keep it";
+ } else {
+ status_ = err;
+ }
+ } else if (kind == kRunScript) {
+ setConsoleOpen(true);
+ console_.queueScriptFile(path);
+ } else if (kind == kLibraryFolder) {
+ uiPrefs_.libraryFolder = path;
+ }
+ }
+ }
+ console_.watchStatus(status_);
+ if (layout_.consoleOpen) console_.draw(*this, consoleRect());
+ palette_.draw(*this, paletteArea());
+ if (showHelp_) drawControlsWindow();
+ if (!capturingShortcut_.empty()) {
+ const Action* a = actions_.find(capturingShortcut_);
+ const CanvasRect area = paletteArea();
+ const float s = uiScale_;
+ ImGui::SetNextWindowPos(ImVec2(area.x + area.w * 0.5f, area.y + 60.0f * s), ImGuiCond_Always, ImVec2(0.5f, 0.0f));
+ ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(16.0f * s, 12.0f * s));
+ ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f * s);
+ ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 1.0f);
+ ImGui::PushStyleColor(ImGuiCol_WindowBg, col(IM_COL32(0x18, 0x18, 0x1a, 0xf8)));
+ ImGui::PushStyleColor(ImGuiCol_Border, col(IM_COL32(0xf0, 0x88, 0x2e, 0xa0)));
+ if (ImGui::Begin("##shortcut_capture", nullptr,
+ ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoSavedSettings |
+ ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoNav | ImGuiWindowFlags_NoInputs)) {
+ ImGui::PushFont(helpTitleFont());
+ ImGui::Text(ICON_LC_KEYBOARD " Press a key for '%s'", a ? a->label.c_str() : capturingShortcut_.c_str());
+ ImGui::PopFont();
+ const std::string now = actions_.shortcutText(capturingShortcut_);
+ ImGui::TextColored(col(ui::color::textDim), "Now:");
+ ImGui::SameLine();
+ if (now.empty()) ImGui::TextColored(col(ui::color::textDim), "none");
+ else ui::Keycaps(now);
+ ImGui::TextColored(col(ui::color::textDim), "Esc cancels, Backspace clears. A key that's taken moves here.");
+ }
+ ImGui::End();
+ ImGui::PopStyleColor(2);
+ ImGui::PopStyleVar(3);
+ }
+ watchLayoutChanges();
+ ui::DrawHelp(*this); // last: on top of everything
+ }
+
+ void App::drawControlsWindow() {
+ const float s = uiScale_;
+ ImGui::SetNextWindowSize(ImVec2(560.0f * s, 640.0f * s), ImGuiCond_FirstUseEver);
+ ImGui::SetNextWindowPos(ImGui::GetMainViewport()->GetCenter(), ImGuiCond_FirstUseEver, ImVec2(0.5f, 0.5f));
+ if (!ImGui::Begin("Controls", &showHelp_, ImGuiWindowFlags_NoCollapse)) {
+ ImGui::End();
+ return;
+ }
+ static char filter[96] = "";
+ ImGui::SetNextItemWidth(-FLT_MIN);
+ ImGui::InputTextWithHint("##controls_filter", ICON_LC_SEARCH " Filter shortcuts and gestures", filter, sizeof filter);
+ const std::string f = lower(filter);
+ auto matches = [&](const std::string& a, const std::string& b, const std::string& c) {
+ return f.empty() || lower(a).find(f) != std::string::npos || lower(b).find(f) != std::string::npos ||
+ lower(c).find(f) != std::string::npos;
+ };
+ ImGui::Spacing();
+ if (ImGui::BeginTabBar("##controls_tabs")) {
+ if (ImGui::BeginTabItem("Keyboard")) {
+ ImGui::BeginChild("##controls_keys", ImVec2(0, -ImGui::GetTextLineHeightWithSpacing() * 1.6f));
+ // Grouped by palette, alphabetically (as ZBrush lists its palettes).
+ std::map<std::string, std::vector<const Action*>> groups;
+ for (const auto& a : actions_.all()) {
+ const std::string chord = actions_.shortcutText(a.id);
+ if (chord.empty() || !matches(a.label, a.palette, chord)) continue;
+ const std::string top = a.palette.substr(0, a.palette.find(" > "));
+ groups[top.empty() ? "General" : top].push_back(&a);
+ }
+ if (groups.empty()) ImGui::TextColored(col(ui::color::textDim), "No shortcut matches \"%s\".", filter);
+ for (auto& [group, list] : groups) {
+ std::stable_sort(list.begin(), list.end(), [](const Action* x, const Action* y) { return x->label < y->label; });
+ ImGui::SeparatorText(group.c_str());
+ if (!ImGui::BeginTable(("##keys_" + group).c_str(), 2, ImGuiTableFlags_RowBg | ImGuiTableFlags_PadOuterX)) continue;
+ ImGui::TableSetupColumn("action", ImGuiTableColumnFlags_WidthStretch);
+ ImGui::TableSetupColumn("keys", ImGuiTableColumnFlags_WidthFixed, 190.0f * s);
+ for (const Action* a : list) {
+ ImGui::TableNextRow();
+ ImGui::TableNextColumn();
+ const ImVec2 p = ImGui::GetCursorScreenPos();
+ const float iconW = ImGui::GetFontSize() + 8.0f * s;
+ if (a->icon) ImGui::GetWindowDrawList()->AddText(p, ui::color::textDim, a->icon);
+ ImGui::SetCursorScreenPos(ImVec2(p.x + iconW, p.y));
+ ImGui::Selectable((a->label + "##ctl." + a->id).c_str(), capturingShortcut_ == a->id,
+ ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowDoubleClick);
+ if (ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left)) beginShortcutCapture(a->id);
+ ui::HelpAction(*this, a->id.c_str());
+ ImGui::TableNextColumn();
+ ui::Keycaps(actions_.shortcutText(a->id));
+ }
+ ImGui::EndTable();
+ ImGui::Spacing();
+ }
+ ImGui::EndChild();
+ ImGui::TextColored(col(ui::color::textDim), "Double-click a row, or Ctrl+Alt+click any button, to assign a key.");
+ ImGui::EndTabItem();
+ }
+ if (ImGui::BeginTabItem("Mouse & pen")) {
+ if (ImGui::BeginTable("##gestures", 2, ImGuiTableFlags_RowBg | ImGuiTableFlags_PadOuterX)) {
+ ImGui::TableSetupColumn("what", ImGuiTableColumnFlags_WidthFixed, 180.0f * s);
+ ImGui::TableSetupColumn("how", ImGuiTableColumnFlags_WidthStretch);
+ for (const auto& g : kGestures) {
+ if (!matches(g.what, g.how, "")) continue;
+ ImGui::TableNextRow();
+ ImGui::TableNextColumn();
+ ImGui::TextUnformatted(g.what);
+ ImGui::TableNextColumn();
+ ImGui::PushTextWrapPos(0.0f);
+ ImGui::TextColored(col(IM_COL32(0xc8, 0xc8, 0xc8, 0xff)), "%s", g.how);
+ ImGui::PopTextWrapPos();
+ }
+ ImGui::EndTable();
+ }
+ ImGui::EndTabItem();
+ }
+ ImGui::EndTabBar();
+ }
+ ImGui::End();
+ }
+
+ // ---------------------------------------------------------------------------
+ // Preferences sections (drawn inside the shell's Preferences palette)
+ // ---------------------------------------------------------------------------
+
+ namespace config {
+
+ void drawConfigSection(App& app) {
+ const ImVec2 full(-FLT_MIN, 0);
+ bool customize = app.layout().customize;
+ if (ImGui::Checkbox("Enable Customize", &customize)) app.actions().find("config.customize")->run();
+ ui::HelpAction(app, "config.customize");
+ ui::ActionButton(app, "config.store", full, ui::Look::IconLabel);
+ ui::ActionButton(app, "config.restore_custom", full, ui::Look::IconLabel);
+ ui::ActionButton(app, "config.restore_standard", full, ui::Look::IconLabel);
+ const float half = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) * 0.5f;
+ ui::ActionButton(app, "config.save", ImVec2(half, 0), ui::Look::IconLabel);
+ ImGui::SameLine();
+ ui::ActionButton(app, "config.load", ImVec2(half, 0), ui::Look::IconLabel);
+ ImGui::PushStyleColor(ImGuiCol_Text, col(ui::color::textDim));
+ ImGui::PushTextWrapPos(0.0f);
+ ImGui::TextUnformatted("Changes to the layout and shortcuts last until you quit. Store Config keeps them.");
+ ImGui::PopTextWrapPos();
+ ImGui::PopStyleColor();
+ }
+
+ void drawInterfaceSection(App& app) {
+ UiPrefs& p = app.uiPrefs();
+ ImGui::Checkbox("Popup Info (Ctrl+hover help)", &p.popupInfo);
+ ui::HelpText("Popup Info", nullptr,
+ "Hold Ctrl and point at any control to see what it does and its shortcut. Ctrl+Alt shows a command's "
+ "scripting parameters.",
+ "Preferences > Interface");
+ ImGui::BeginDisabled(!p.popupInfo);
+ ImGui::SetNextItemWidth(-FLT_MIN);
+ ui::SliderInside("##help_opacity", &p.helpOpacity, 0.3f, 1.0f, "Popup Info opacity %.2f");
+ ui::HelpText("Popup Info opacity", nullptr, "How solid the Ctrl-help box is (ZBrush: Quick Info Opacity).",
+ "Preferences > Interface");
+ ImGui::EndDisabled();
+ ImGui::SetNextItemWidth(-FLT_MIN);
+ ui::SliderInside("##tooltip_delay", &p.tooltipDelay, 0.0f, 2.0f, "Tooltip delay %.1f s");
+ ui::HelpText("Tooltip delay", nullptr,
+ "How long to point at an icon-only button (or a clipped label) before its name appears.",
+ "Preferences > Interface");
+ ImGui::Checkbox("One sub-palette open", &p.oneSubpalette);
+ ui::HelpText("One sub-palette open", nullptr,
+ "Opening a sub-palette closes the others in that palette. Shift+click opens more than one.",
+ "Preferences > Interface");
+ ImGui::Checkbox("Auto collapse left tray", &p.autoCollapseLeft);
+ ui::HelpText("Auto collapse left tray", nullptr,
+ "Opening a palette in the left tray collapses the others when they would not fit.", "Preferences > Interface");
+ ImGui::Checkbox("Auto collapse right tray", &p.autoCollapseRight);
+ ui::HelpText("Auto collapse right tray", nullptr,
+ "Opening a palette in the right tray collapses the others when they would not fit.", "Preferences > Interface");
+ ImGui::Checkbox("Left-handed layout", &app.layout().leftHanded);
+ ui::HelpText("Left-handed layout", nullptr, "Mirror the shelves and trays: tools on the left, navigation on the right.",
+ "Preferences > Interface");
+ static const char* kScales[] = {"Automatic", "100%", "125%", "150%", "175%", "200%"};
+ static const float kScaleValues[] = {0.0f, 1.0f, 1.25f, 1.5f, 1.75f, 2.0f};
+ int current = 0;
+ for (int i = 0; i < 6; ++i)
+ if (std::abs(kScaleValues[i] - p.uiScale) < 0.01f) current = i;
+ ImGui::SetNextItemWidth(-FLT_MIN);
+ if (ImGui::BeginCombo("##ui_scale", (std::string("UI scale: ") + kScales[current]).c_str())) {
+ for (int i = 0; i < 6; ++i)
+ if (ImGui::Selectable(kScales[i], i == current)) p.uiScale = kScaleValues[i];
+ ImGui::EndCombo();
+ }
+ ui::HelpText("UI scale", nullptr,
+ "Size of text and controls. Automatic follows the display. Takes effect the next time SculptForge starts "
+ "(Store Config to keep it).",
+ "Preferences > Interface");
+ }
+
+ void drawHotkeysSection(App& app) {
+ static char filter[64] = "";
+ ImGui::SetNextItemWidth(-FLT_MIN);
+ ImGui::InputTextWithHint("##hotkeys_filter", ICON_LC_SEARCH " Filter", filter, sizeof filter);
+ const std::string f = lower(filter);
+ ActionRegistry& reg = app.actions();
+ const float s = ImGui::GetFontSize() / 15.0f;
+ std::vector<const Action*> list;
+ for (const auto& a : reg.all()) {
+ if (!a.run || a.id.rfind("cmd.", 0) == 0) continue; // commands: through the command palette
+ if (!f.empty() && lower(a.label).find(f) == std::string::npos && lower(a.palette).find(f) == std::string::npos) continue;
+ list.push_back(&a);
+ }
+ std::stable_sort(list.begin(), list.end(), [](const Action* x, const Action* y) {
+ return x->palette != y->palette ? x->palette < y->palette : x->label < y->label;
+ });
+ const float listH = std::min(320.0f * s, float(list.size()) * ImGui::GetFrameHeightWithSpacing() + 8.0f * s);
+ if (ImGui::BeginTable("##hotkeys", 2, ImGuiTableFlags_RowBg | ImGuiTableFlags_ScrollY | ImGuiTableFlags_PadOuterX,
+ ImVec2(0, std::max(listH, 60.0f * s)))) {
+ ImGui::TableSetupColumn("action", ImGuiTableColumnFlags_WidthStretch);
+ ImGui::TableSetupColumn("key", ImGuiTableColumnFlags_WidthFixed, 110.0f * s);
+ for (const Action* a : list) {
+ ImGui::TableNextRow();
+ ImGui::TableNextColumn();
+ ImGui::AlignTextToFramePadding();
+ ImGui::TextUnformatted(a->label.c_str());
+ ui::HelpAction(app, a->id.c_str());
+ ImGui::TableNextColumn();
+ const std::string chord = reg.shortcutText(a->id);
+ const bool capturing = app.capturingShortcut() == a->id;
+ const std::string text = capturing ? "press a key..." : chord.empty() ? "-" : chord;
+ if (reg.hasOverride(a->id)) ImGui::PushStyleColor(ImGuiCol_Text, col(ui::color::accent));
+ if (ImGui::Button((text + "##hk." + a->id).c_str(), ImVec2(-FLT_MIN, 0))) app.beginShortcutCapture(a->id);
+ if (reg.hasOverride(a->id)) ImGui::PopStyleColor();
+ ui::HelpText(("Shortcut for " + a->label).c_str(), chord.c_str(),
+ "Click, then press the new key. Esc cancels, Backspace clears. Orange: changed from the default.",
+ "Preferences > Hotkeys");
+ }
+ ImGui::EndTable();
+ }
+ if (ImGui::Button(ICON_LC_ROTATE_CCW " Default shortcuts", ImVec2(-FLT_MIN, 0))) {
+ reg.clearOverrides();
+ app.status_ = "Default shortcuts restored - Store Config (Ctrl+Shift+I) to keep them";
+ }
+ ui::HelpText("Default shortcuts", nullptr, "Undo every shortcut change.", "Preferences > Hotkeys");
+ }
+
+ void drawLightBoxSection(App& app) {
+ UiPrefs& p = app.uiPrefs();
+ UiLayout& l = app.layout();
+ ImGui::Checkbox("Show at startup", &p.lightboxAtStartup);
+ ui::HelpText("Show LightBox at startup", nullptr, "Open LightBox on the Project tab when SculptForge starts (as ZBrush does).",
+ "Preferences > LightBox");
+ ImGui::AlignTextToFramePadding();
+ ImGui::TextUnformatted("Rows");
+ for (int r = 1; r <= 4; ++r) {
+ ImGui::SameLine();
+ const bool on = l.lightboxRows == r;
+ if (on) ImGui::PushStyleColor(ImGuiCol_Button, col(ui::color::accent));
+ if (ImGui::Button((std::to_string(r) + "##lbrows").c_str(), ImVec2(ImGui::GetFrameHeight() * 1.3f, 0))) l.lightboxRows = r;
+ if (on) ImGui::PopStyleColor();
+ ui::HelpText("LightBox rows", nullptr, "How many rows of thumbnails the LightBox strip shows.", "Preferences > LightBox");
+ }
+ ImGui::AlignTextToFramePadding();
+ ImGui::TextUnformatted("Placement");
+ ImGui::SameLine();
+ if (ImGui::RadioButton("Top", !l.lightboxBottom)) l.lightboxBottom = false;
+ ui::HelpText("LightBox at the top", nullptr, "LightBox opens along the top edge of the canvas.", "Preferences > LightBox");
+ ImGui::SameLine();
+ if (ImGui::RadioButton("Bottom", l.lightboxBottom)) l.lightboxBottom = true;
+ ui::HelpText("LightBox at the bottom", nullptr, "LightBox opens above the bottom shelf.", "Preferences > LightBox");
+ ImGui::TextColored(col(ui::color::textDim), "Library folder");
+ const std::string shown = p.libraryFolder.empty() ? std::string("Documents/SculptForge (default)") : p.libraryFolder;
+ if (ImGui::Button((std::string(ICON_LC_FOLDER_OPEN " ") + shown + "##libfolder").c_str(), ImVec2(-FLT_MIN, 0)))
+ SDL_ShowOpenFolderDialog(onUiFileChosen, &g_requests[kLibraryFolder], app.window_, nullptr, false);
+ ui::HelpText("Library folder", nullptr,
+ "Where your projects, tools, brushes, alphas, images, splats and QuickSaves live. LightBox shows it as User.",
+ "Preferences > LightBox");
+ if (!p.libraryFolder.empty() && ImGui::SmallButton("Use the default folder")) p.libraryFolder.clear();
+ }
+
+ } // namespace config
+
+ } // namespace sf
diff --cc src/app/Palettes.cpp
index 3ce426a6,00000000..22c5fa73
mode 100644,000000..100644
--- a/src/app/Palettes.cpp
+++ b/src/app/Palettes.cpp
@@@ -1,437 -1,0 +1,406 @@@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// The palettes of the palette bar (docs/ui-design.md §3.2), listed
+// alphabetically like ZBrush's. Each body is one function, drawn the same way
+// in a drop-down and in a tray. ZBrush's Tool palette holds the SubTool,
+// Layers, Geometry, Remesh, Masking, Polygroups, Visibility, Export and
+// Display sub-palettes.
+#include "app/App.h"
+
++#include "app/Config.h"
+#include "app/Demo.h"
+#include "app/Shell.h"
+#include "app/Theme.h"
+#include "app/Ui.h"
+#include "core/Matcap.h"
+
+#include <IconsLucide.h>
+
+#include <algorithm>
+#include <cstdio>
+#include <iterator>
+
+namespace sf {
+
+const PaletteDef* palettes(int& count) {
+ // Sorted by name; a new palette lands in alphabetical order by being added in its place here.
+ static const PaletteDef kPalettes[] = {
+ {"alpha", "Alpha", ICON_LC_CIRCLE_DASHED, nullptr, &App::drawPalette_Alpha},
+ {"brush", "Brush", ICON_LC_BRUSH, nullptr, &App::drawPalette_Brush},
+ {"color", "Color", ICON_LC_PALETTE, "Polypaint & Materials", &App::drawPalette_Color},
+ {"draw", "Draw", ICON_LC_PENCIL, nullptr, &App::drawPalette_Draw},
+ {"edit", "Edit", ICON_LC_UNDO_2, nullptr, &App::drawPalette_Edit},
+ {"file", "File", ICON_LC_FILE, nullptr, &App::drawPalette_File},
+ {"generate", "Generate", ICON_LC_WAND_SPARKLES, nullptr, &App::drawPalette_Generate},
+ {"help", "Help", ICON_LC_CIRCLE_HELP, nullptr, &App::drawPalette_Help},
+ {"material", "Material", ICON_LC_SUN, "Polypaint & Materials", &App::drawPalette_Material},
+ {"preferences", "Preferences", ICON_LC_SETTINGS, nullptr, &App::drawPalette_Preferences},
+ {"render", "Render", ICON_LC_EYE, nullptr, &App::drawPalette_Render},
+ {"script", "Script", ICON_LC_SQUARE_TERMINAL, nullptr, &App::drawPalette_Script},
+ {"splats", "Splats", ICON_LC_SPARKLE, "Gaussian Splats", &App::drawPalette_Splats},
+ {"stroke", "Stroke", ICON_LC_SPLINE, nullptr, &App::drawPalette_Stroke},
+ {"tool", "Tool", ICON_LC_BOXES, nullptr, &App::drawPalette_Tool},
+ {"transform", "Transform", ICON_LC_MOVE_3D, nullptr, &App::drawPalette_Transform},
+ };
+ count = int(std::size(kPalettes));
+ return kPalettes;
+}
+
+const PaletteDef* findPalette(std::string_view id) {
+ int count = 0;
+ const PaletteDef* list = palettes(count);
+ for (int i = 0; i < count; ++i)
+ if (id == list[i].id) return &list[i];
+ return nullptr;
+}
+
+namespace {
+
+// A row of equal-width action buttons filling the line.
+void actionRow(App& app, std::initializer_list<const char*> ids) {
+ std::vector<const char*> present;
+ for (const char* id : ids)
+ if (app.actions().find(id)) present.push_back(id);
+ if (present.empty()) return;
+ const float spacing = ImGui::GetStyle().ItemSpacing.x;
+ const float w = (ImGui::GetContentRegionAvail().x - spacing * float(present.size() - 1)) / float(present.size());
+ for (size_t i = 0; i < present.size(); ++i) {
+ if (i) ImGui::SameLine();
- ui::ActionButton(app, present[i], ImVec2(w, 0));
- ui::HelpAction(app, present[i]);
++ const Action* a = app.actions().find(present[i]);
++ ui::ActionButton(app, present[i], ImVec2(w, 0), a && a->icon ? ui::Look::IconLabel : ui::Look::Label);
+ }
+}
+
+// Adjacent toggle buttons that read as one control (Zadd | Zsub, X | Y | Z).
+void segmented(App& app, std::initializer_list<const char*> ids, float width = -1.0f) {
+ const float total = width > 0.0f ? width : ImGui::GetContentRegionAvail().x;
+ const float w = (total - float(ids.size() - 1)) / float(ids.size());
+ ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(1.0f, ImGui::GetStyle().ItemSpacing.y));
+ bool first = true;
+ for (const char* id : ids) {
+ if (!first) ImGui::SameLine();
+ first = false;
+ ui::ActionButton(app, id, ImVec2(w, 0));
+ ui::HelpAction(app, id);
+ }
+ ImGui::PopStyleVar();
+}
+
+// A menu-style row for an action: label, shortcut on the right, check mark for toggles.
+void menuAction(App& app, const char* id) {
+ const Action* a = app.actions().find(id);
+ if (!a) return;
+ const std::string shortcut = app.actions().shortcutText(id);
+ const bool enabled = !a->enabled || a->enabled();
+ const bool checked = a->checked && a->checked();
+ const std::string label = a->label + "##" + a->id; // no icons: they'd misalign with the plain project items
+ if (ImGui::MenuItem(label.c_str(), shortcut.empty() ? nullptr : shortcut.c_str(), checked, enabled) && a->run) {
+ app.actions().touch(a->id);
+ a->run();
+ }
+ ui::HelpAction(app, id);
+}
+
+void hint(const char* text) {
+ ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));
+ ImGui::TextWrapped("%s", text);
+ ImGui::PopStyleColor();
+}
+
+} // namespace
+
+bool App::subpalette(const char* id, const char* title) {
+ auto& open = layout_.openSubpalettes;
+ bool isOpen = std::find(open.begin(), open.end(), id) != open.end();
+ const float s = uiScale_;
+ const float h = 22.0f * s;
+ const ImVec2 p = ImGui::GetCursorScreenPos();
+ const float w = ImGui::GetContentRegionAvail().x;
+ const bool clicked = ImGui::InvisibleButton((std::string(title) + "##" + id).c_str(), ImVec2(w, h));
+ const bool hovered = ImGui::IsItemHovered();
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ dl->AddRectFilled(p, ImVec2(p.x + w, p.y + h), theme::u32(hovered ? theme::headerHover : theme::header, isOpen ? 1.0f : 0.75f),
+ 2.0f * s);
+ if (isOpen) dl->AddRectFilled(p, ImVec2(p.x + 2.0f * s, p.y + h), theme::u32(theme::accent), 0.0f);
+ const float ty = p.y + (h - ImGui::GetFontSize()) * 0.5f;
+ dl->AddText(ImVec2(p.x + 6.0f * s, ty), theme::u32(isOpen ? theme::accent : theme::textDim),
+ isOpen ? ICON_LC_CHEVRON_DOWN : ICON_LC_CHEVRON_RIGHT);
+ dl->AddText(ImVec2(p.x + 24.0f * s, ty), theme::u32(isOpen || hovered ? theme::text : theme::text, isOpen ? 1.0f : 0.85f), title);
+ ImGui::LogText("%s", title);
+ ui::HelpText(title, nullptr,
+ "Click to open or close. Opening one closes the others (Shift+click keeps them open; Preferences > "
+ "Interface).",
+ "Tool");
+ if (clicked) {
+ if (isOpen) {
+ open.erase(std::remove(open.begin(), open.end(), id), open.end());
+ } else {
- if (oneSubpalette_ && !(SDL_GetModState() & SDL_KMOD_SHIFT)) {
++ if (uiPrefs_.oneSubpalette && !(SDL_GetModState() & SDL_KMOD_SHIFT)) {
+ // Close the siblings: sub-palettes that share this one's palette prefix ("tool.").
+ const std::string prefix = std::string(id).substr(0, std::string(id).find('.') + 1);
+ open.erase(std::remove_if(open.begin(), open.end(), [&](const std::string& o) { return o.rfind(prefix, 0) == 0; }),
+ open.end());
+ }
+ open.push_back(id);
+ }
+ isOpen = !isOpen;
+ }
+ if (isOpen) ImGui::Dummy(ImVec2(0, 1.0f * s));
+ return isOpen;
+}
+
+// ---------------------------------------------------------------------------
+
+void App::drawPalette_Alpha() { drawAlphaSection(); }
+
+void App::drawPalette_Brush() {
+ drawBrushGrid(*this, GridMode::Palette); // the picker's grid (Pickers.cpp)
+ drawCustomBrushes(); // PanelBrushLibrary.cpp: list, right-click menu
+ actionRow(*this, {"ui.brush_lab", "ui.brush_gallery"});
+ actionRow(*this, {"brush.paste"});
+ ImGui::Checkbox("Front faces only", &frontFacesOnly_);
+ ui::HelpAction(*this, "draw.front_faces");
+ ImGui::SameLine();
+ ImGui::Checkbox("Invert (Alt)", &invertToggle_);
+ ui::HelpText("Invert", "Alt", "Brushes subtract instead of add (ZBrush Zsub). Holding Alt flips it for one stroke.", "Brush");
+ if (BrushRecipe* recipe = doc_.activeBrush >= 0 && doc_.activeBrush < int(doc_.brushes.size())
+ ? &doc_.brushes[size_t(doc_.activeBrush)]
+ : nullptr) {
+ if (subpalette("brush.recipe", ("Edit recipe: " + recipe->name).c_str())) {
+ drawRecipeEditor(*recipe);
+ if (!pendingRename_.empty()) {
+ runCommand("brush_rename", {{"to", pendingRename_}});
+ pendingRename_.clear();
+ }
+ }
+ }
+}
+
+void App::drawPalette_Draw() {
+ ImGui::SetNextItemWidth(-1);
+ ui::SliderInside("##drawsize", &radiusPx_, 2.0f, 800.0f, "Draw Size %.0f", ImGuiSliderFlags_Logarithmic);
+ ui::HelpText("Draw Size", "S", "Brush radius in screen pixels. [ and ] change it by 10%.", "Draw");
+ ImGui::SetNextItemWidth(-1);
+ ui::SliderInside("##strength", &strength_, 0.01f, 1.0f, "Strength %.2f");
+ ui::HelpText("Strength", "I", "How strongly each dab changes the surface (ZBrush Z Intensity).", "Draw");
+ segmented(*this, {"draw.sculpt", "draw.paint"});
+ segmented(*this, {"draw.zadd", "draw.zsub"});
+ actionRow(*this, {"draw.rgb", "draw.front_faces"});
+ ImGui::SeparatorText("Tablet");
+ ImGui::Checkbox("Pressure > strength", &pressureStrength_);
+ ui::HelpAction(*this, "draw.pressure_strength");
+ ImGui::Checkbox("Pressure > size", &pressureSize_);
+ ui::HelpAction(*this, "draw.pressure_size");
+ if (penSeen_) ImGui::Text("Pen pressure: %.2f", penPressure_);
+ else ImGui::TextDisabled("No pen detected");
+}
+
+void App::drawPalette_Edit() {
+ const std::string undoText = doc_.undo.canUndo() ? "Undo " + doc_.undo.undoLabel() : std::string("Undo");
+ const std::string redoText = doc_.undo.canRedo() ? "Redo " + doc_.undo.redoLabel() : std::string("Redo");
+ ImGui::BeginDisabled(!doc_.undo.canUndo());
+ if (ImGui::MenuItem((undoText + "##edit.undo").c_str(), "Ctrl+Z")) runCommand("undo");
+ ImGui::EndDisabled();
+ ui::HelpAction(*this, "edit.undo");
+ ImGui::BeginDisabled(!doc_.undo.canRedo());
+ if (ImGui::MenuItem((redoText + "##edit.redo").c_str(), "Ctrl+Shift+Z")) runCommand("redo");
+ ImGui::EndDisabled();
+ ui::HelpAction(*this, "edit.redo");
+ menuAction(*this, "brush.paste");
+}
+
+void App::drawPalette_File() {
+ menuAction(*this, "file.new_sphere");
+ menuAction(*this, "file.new_plane");
+ ImGui::Separator();
+ menuAction(*this, "file.open");
+ drawFileMenuProjectItems(); // Open Recent, Save, Save As, autosave
+ ImGui::SeparatorText("Import / Export");
+ menuAction(*this, "file.import");
+ menuAction(*this, "file.export_obj");
+ menuAction(*this, "file.export_glb");
+ menuAction(*this, "file.export_lods");
+ menuAction(*this, "file.export_usd");
+ menuAction(*this, "file.export_fbx");
+ menuAction(*this, "file.send_unreal");
+ menuAction(*this, "file.save_splats");
+ ImGui::Separator();
+ drawGozMenu();
+ ImGui::Separator();
+ menuAction(*this, "file.quit");
+}
+
+void App::drawPalette_Generate() {
+ actionRow(*this, {"ui.generate3d"});
+ hint("Image or text to a sculptable 3D model: Hugging Face (free), fal.ai, Meshy, your ComfyUI server, your own "
+ "command, or an offline blockout.");
+ ImGui::SeparatorText("From an image");
+ if (ImGui::Button(refImage_.empty() ? "Choose image...##generate" : "Change image...##generate", ImVec2(-1, 0))) {
+ static const SDL_DialogFileFilter filters[] = {{"Images", "png;jpg;jpeg;bmp;tga;psd;gif"}, {"All files", "*"}};
+ SDL_ShowOpenFileDialog(
+ [](void* user, const char* const* files, int) {
+ if (files && files[0]) static_cast<App*>(user)->queueFile(FileAction::OpenImage, files[0]);
+ },
+ this, window_, filters, 2, nullptr, false);
+ }
+ ui::HelpText("Choose image", nullptr, "A sketch, concept, logo, photo or height map (or drop one on the window).", "Generate");
+ ImGui::BeginDisabled(refImage_.empty());
+ const float third = (ImGui::GetContentRegionAvail().x - 2.0f * ImGui::GetStyle().ItemSpacing.x) / 3.0f;
+ if (ImGui::Button("Relief", ImVec2(third, 0)))
+ runCommand("image_relief", {{"path", refImagePath_},
+ {"depth", double(reliefDepth_)},
+ {"resolution", double(reliefDetail_)},
+ {"invert", reliefInvert_}});
+ ui::HelpText("Relief", nullptr, "Light areas rise: logos, coins, emblems, height maps.", "Generate");
+ ImGui::SameLine();
+ if (ImGui::Button("Inflate", ImVec2(third, 0)))
+ runCommand("image_inflate", {{"path", refImagePath_},
+ {"thickness", double(inflateThickness_)},
+ {"resolution", double(inflateDetail_)},
+ {"subdivisions", 2.0}});
+ ui::HelpText("Inflate", nullptr, "Inflates the outline into a rounded blockout.", "Generate");
+ ImGui::SameLine();
+ if (ImGui::Button("Stamp", ImVec2(third, 0))) projectImageFromView();
+ ui::HelpText("Stamp", nullptr, "Projects the image onto the model from this view as surface detail.", "Generate");
+ ImGui::EndDisabled();
+ if (subpalette("generate.ai", "AI brush provider")) drawAiSettings();
+}
+
+void App::drawPalette_Help() {
+ menuAction(*this, "help.controls");
+ menuAction(*this, "ui.command_palette");
+ menuAction(*this, "help.website");
+ menuAction(*this, "help.report");
+ ImGui::Separator();
+ menuAction(*this, "help.about");
+}
+
+void App::drawPalette_Preferences() {
++ // The sub-palettes come from Config.cpp (Store / Restore UI, interface preferences, hotkeys, LightBox).
+ if (subpalette("preferences.config", "Config")) {
- // Store / Restore / Load / Save UI come from the config actions when they're registered.
- ImGui::Checkbox("Enable Customize", &layout_.customize);
- ui::HelpText("Enable Customize", nullptr,
- "Ctrl+Alt+drag shelf items to move them, onto another shelf to copy them, or off the shelves to "
- "remove them.",
- "Preferences > Config");
- actionRow(*this, {"config.store", "config.restore_custom"});
- actionRow(*this, {"config.restore_standard"});
- actionRow(*this, {"config.save", "config.load"});
++ config::drawConfigSection(*this);
+ ImGui::TextDisabled("Layout");
- ImGui::SameLine();
+ for (int i = 1; i <= 3; ++i) {
+ ImGui::SameLine();
+ ui::ActionButton(*this, ("ui.preset." + std::to_string(i)).c_str(), ImVec2(ImGui::GetFrameHeight() * 1.4f, 0));
- ui::HelpAction(*this, ("ui.preset." + std::to_string(i)).c_str());
+ }
+ }
- if (subpalette("preferences.interface", "Interface")) {
- ImGui::Checkbox("One sub-palette open", &oneSubpalette_);
- ui::HelpText("One sub-palette open", nullptr, "Opening a sub-palette closes the others (Shift+click keeps them).",
- "Preferences > Interface");
- ImGui::Checkbox("Auto collapse left tray", &autoCollapse_[0]);
- ui::HelpText("Auto collapse", nullptr, "Opening a palette in the tray collapses the others there.", "Preferences > Interface");
- ImGui::Checkbox("Auto collapse right tray", &autoCollapse_[1]);
- ui::HelpText("Auto collapse right tray", nullptr, "Opening a palette in the right tray collapses the others there.",
- "Preferences > Interface");
- if (ImGui::Checkbox("Left-handed layout", &layout_.leftHanded)) noteLayoutChanged();
- ui::HelpText("Left-handed layout", nullptr, "Mirror the shelves and trays left to right.", "Preferences > Interface");
- bool shelves = layout_.shelvesVisible;
- if (ImGui::Checkbox("Shelves (Tab)", &shelves)) layout_.shelvesVisible = shelves;
- ui::HelpAction(*this, "ui.toggle_shelves");
- bool menus = layout_.paletteBarVisible;
- if (ImGui::Checkbox("Palette bar (Menus)", &menus)) layout_.paletteBarVisible = menus;
- ui::HelpAction(*this, "ui.menus");
- }
- if (subpalette("preferences.lightbox", "LightBox")) {
- ImGui::SetNextItemWidth(-1);
- ImGui::SliderInt("##lightboxrows", &layout_.lightboxRows, 1, 4, "Rows %d");
- ui::HelpText("LightBox rows", nullptr, "How many rows of thumbnails the LightBox shows.", "Preferences > LightBox");
- ImGui::Checkbox("Show at the bottom", &layout_.lightboxBottom);
- ui::HelpText("LightBox placement", nullptr, "Show the LightBox along the bottom of the canvas instead of the top.",
- "Preferences > LightBox");
- }
++ if (subpalette("preferences.interface", "Interface")) config::drawInterfaceSection(*this);
++ if (subpalette("preferences.hotkeys", "Hotkeys")) config::drawHotkeysSection(*this);
++ if (subpalette("preferences.lightbox", "LightBox")) config::drawLightBoxSection(*this);
+ if (subpalette("preferences.autosave", "Autosave")) {
+ ImGui::SetNextItemWidth(-1);
+ ImGui::SliderInt("##autosave", &autosaveMinutes_, 0, 60, autosaveMinutes_ ? "Every %d min" : "Autosave off");
+ if (ImGui::IsItemDeactivatedAfterEdit()) saveProjectPrefs();
+ ui::HelpText("Autosave", nullptr, "Save a recovery copy this often (0 = off). Restored after a crash.",
+ "Preferences > Autosave");
+ }
+}
+
+void App::drawPalette_Render() {
+ ImGui::Checkbox("Wireframe", &renderSettings_.wireframe);
+ ui::HelpAction(*this, "view.wireframe");
+ ImGui::Checkbox("Show Mesh", &renderSettings_.showMesh);
+ ui::HelpAction(*this, "view.mesh");
+ ImGui::Checkbox("Show Polypaint", &renderSettings_.showPolypaint);
+ ui::HelpAction(*this, "view.polypaint");
+ ImGui::Checkbox("Show Mask", &renderSettings_.showMask);
+ ui::HelpAction(*this, "view.mask");
+ ImGui::Checkbox("Show Polygroups##render", &renderSettings_.showPolygroups);
+ ui::HelpAction(*this, "view.polygroups");
+ ImGui::BeginDisabled(doc_.splats.empty());
+ ImGui::Checkbox("Show Splats", &renderSettings_.showSplats);
+ ImGui::EndDisabled();
+ ui::HelpAction(*this, "view.splats");
+ actionRow(*this, {"view.frame"});
+}
+
+void App::drawPalette_Script() {
+ const bool any = actions_.find("ui.console") || actions_.find("script.run_file");
+ actionRow(*this, {"ui.console"});
+ actionRow(*this, {"script.run_file"});
- actionRow(*this, {"script.copy_session", "script.clear"});
++ actionRow(*this, {"script.copy_session", "script.clear_console"});
+ if (!any)
+ hint("Every action is a script command: run them with --script \"subdivide; remesh resolution=200\" or the "
+ "sculptforge-cli tool.");
+}
+
+void App::drawPalette_Stroke() { drawStrokeSection(); }
+
+void App::drawPalette_Tool() {
+ const float s = uiScale_;
+ // Header: the active SubTool and its size, then Open / Save / Import.
+ {
+ const SubTool& st = doc_.activeSubtoolInfo();
+ if (fontBold_) ImGui::PushFont(fontBold_);
+ ImGui::TextUnformatted(st.name.c_str());
+ if (fontBold_) ImGui::PopFont();
+ char tris[64];
+ std::snprintf(tris, sizeof tris, "%zu tris", doc_.mesh.triangleCount());
+ ImGui::SameLine(ImGui::GetContentRegionMax().x - ImGui::CalcTextSize(tris).x);
+ ImGui::TextDisabled("%s", tris);
+ actionRow(*this, {"file.open", "file.save", "file.import"});
+ ImGui::Dummy(ImVec2(0, 2.0f * s));
+ }
+ if (subpalette("tool.subtool", "SubTool")) {
+ Demo::pushScope("SubTools");
+ drawSubToolsContents();
+ Demo::popScope();
+ }
+ if (subpalette("tool.layers", "Layers")) {
+ Demo::pushScope("Layers");
+ drawLayersContents();
+ Demo::popScope();
+ }
+ if (subpalette("tool.geometry", "Geometry")) {
+ actionRow(*this, {"geometry.subdivide"});
+ const float half = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) * 0.5f;
+ if (ImGui::Button("Decimate", ImVec2(half, 0))) runCommand("decimate", {{"ratio", double(decimateRatio_)}});
+ ui::HelpText("Decimate", nullptr, "Reduce the triangle count while keeping the shape. Sculpt layers are kept.",
+ "Tool > Geometry");
+ ImGui::SameLine();
+ ImGui::SetNextItemWidth(-1);
+ ui::SliderInside("##decimate", &decimateRatio_, 0.05f, 0.95f, "Keep %.2f");
+ ui::HelpText("Keep", nullptr, "Fraction of the triangles Decimate keeps.", "Tool > Geometry");
+ }
+ if (subpalette("tool.remesh", "Remesh")) {
+ const float half = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) * 0.5f;
+ ui::ActionButton(*this, "geometry.remesh", ImVec2(half, 0));
+ ui::HelpAction(*this, "geometry.remesh");
+ ImGui::SameLine();
+ ImGui::SetNextItemWidth(-1);
+ ImGui::SliderInt("##voxres", &voxelResolution_, 64, 400, "Resolution %d");
+ ui::HelpText("Resolution", nullptr, "Voxels across the model: higher keeps more detail and makes more triangles.",
+ "Tool > Remesh");
+ }
+ if (subpalette("tool.masking", "Masking")) drawMaskingSection();
+ if (subpalette("tool.polygroups", "Polygroups")) drawPolygroupsSection();
+ if (subpalette("tool.visibility", "Visibility")) drawVisibilitySection();
+ if (subpalette("tool.export", "Export")) {
+ Demo::pushScope("Game Ready");
+ drawGameExportContents();
+ Demo::popScope();
+ }
+ if (subpalette("tool.display", "Display")) {
+ ImGui::Checkbox("Wireframe##display", &renderSettings_.wireframe);
+ ui::HelpAction(*this, "view.wireframe");
+ ImGui::SameLine();
+ ImGui::Checkbox("Mask##display", &renderSettings_.showMask);
+ ui::HelpAction(*this, "view.mask");
+ ImGui::SameLine();
+ ImGui::Checkbox("Groups##display", &renderSettings_.showPolygroups);
+ ui::HelpAction(*this, "view.polygroups");
+ ImGui::ColorEdit3("Material colour", &renderSettings_.baseColor.x, ImGuiColorEditFlags_NoInputs);
+ ui::HelpText("Material colour", nullptr, "Colour of the Studio material (the clay colour).", "Tool > Display");
+ }
+}
+
+void App::drawPalette_Transform() {
+ ImGui::TextDisabled("Symmetry");
- segmented(*this, {"transform.sym_x", "transform.sym_y", "transform.sym_z"});
++ segmented(*this, {"transform.symmetry_x", "transform.symmetry_y", "transform.symmetry_z"});
+ actionRow(*this, {"view.frame", "subtool.solo"});
+ actionRow(*this, {"view.polyf"});
+}
+
+} // namespace sf
diff --cc src/app/Shell.cpp
index 7ae6caea,00000000..0917bd60
mode 100644,000000..100644
--- a/src/app/Shell.cpp
+++ b/src/app/Shell.cpp
@@@ -1,1551 -1,0 +1,1487 @@@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// The ZBrush-style shell (docs/ui-design.md §2, §3, §9): title strip, the
+// alphabetical palette bar with its drop-downs, the four shelves around the
+// canvas, the left and right trays with their dividers, customize-mode drag
+// and drop, layout presets, and the actions behind all of it.
+#include "app/App.h"
+
+#include "app/Demo.h"
+#include "app/Shell.h"
+#include "app/Theme.h"
+#include "app/Ui.h"
+#include "core/Matcap.h"
+#include "core/Polypaint.h"
+
+#include <IconsLucide.h>
+#include <imgui_internal.h>
+
+#include <glm/gtc/type_ptr.hpp>
+
+#include <algorithm>
+#include <cmath>
+#include <cstdio>
+#include <cstring>
+#include <filesystem>
+
+namespace sf {
+
+namespace {
+
+constexpr ImGuiWindowFlags kShellFlags = ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove |
+ ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoSavedSettings |
+ ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoFocusOnAppearing |
+ ImGuiWindowFlags_NoNav;
+
+const char* const kShelfWindows[kShelfCount] = {"##TopShelf", "##LeftShelf", "##RightShelf", "##BottomShelf"};
+
+bool beginShellWindow(const char* name, const CanvasRect& r, const ImVec4& bg, ImVec2 padding,
+ ImGuiWindowFlags extra = ImGuiWindowFlags_NoScrollbar | ImGuiWindowFlags_NoScrollWithMouse) {
+ ImGui::SetNextWindowPos(ImVec2(r.x, r.y));
+ ImGui::SetNextWindowSize(ImVec2(r.w, r.h));
+ ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, padding);
+ ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);
+ ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);
+ ImGui::PushStyleVar(ImGuiStyleVar_WindowMinSize, ImVec2(1.0f, 1.0f)); // the title strip is only 24 px high
+ ImGui::PushStyleColor(ImGuiCol_WindowBg, bg);
+ const bool open = ImGui::Begin(name, nullptr, kShellFlags | extra);
+ ImGui::PopStyleColor();
+ ImGui::PopStyleVar(4);
+ return open;
+}
+
+std::string lower(std::string s) {
+ for (auto& c : s) c = char(std::tolower(static_cast<unsigned char>(c)));
+ return s;
+}
+
+std::string brushActionId(BrushType t) {
+ std::string name = lower(brushName(t));
+ name.erase(std::remove(name.begin(), name.end(), ' '), name.end());
+ return "brush." + name;
+}
+
+std::string shortCount(size_t n) {
+ char buf[32];
+ if (n >= 1000000) std::snprintf(buf, sizeof buf, "%.2fM", double(n) / 1e6);
+ else if (n >= 10000) std::snprintf(buf, sizeof buf, "%.1fk", double(n) / 1e3);
+ else std::snprintf(buf, sizeof buf, "%zu", n);
+ return buf;
+}
+
+// Two dashed outlines are how customize mode marks what can be rearranged.
+void dashedRect(ImDrawList* dl, ImVec2 a, ImVec2 b, ImU32 col, float dash) {
+ auto line = [&](ImVec2 p, ImVec2 q) {
+ const float len = std::hypot(q.x - p.x, q.y - p.y);
+ for (float t = 0.0f; t < len; t += dash * 2.0f) {
+ const float u0 = t / len, u1 = std::min(len, t + dash) / len;
+ dl->AddLine(ImVec2(p.x + (q.x - p.x) * u0, p.y + (q.y - p.y) * u0),
+ ImVec2(p.x + (q.x - p.x) * u1, p.y + (q.y - p.y) * u1), col);
+ }
+ };
+ line(a, ImVec2(b.x, a.y));
+ line(ImVec2(b.x, a.y), b);
+ line(b, ImVec2(a.x, b.y));
+ line(ImVec2(a.x, b.y), a);
+}
+
+// A shaded clay ball with a mark that hints at what the brush does: the placeholder until a rendered
+// thumbnail is ready (ThumbnailCache).
+void drawBrushIcon(ImDrawList* dl, ImVec2 c, float r, int type) {
+ const ImVec4 clay(0.80f, 0.55f, 0.45f, 1.0f);
+ constexpr int kLayers = 14;
+ for (int k = 0; k < kLayers; ++k) {
+ const float t = float(k) / float(kLayers - 1);
+ const float rr = r * (1.0f - t * 0.82f);
+ const ImVec2 o(c.x - r * 0.32f * t, c.y - r * 0.34f * t);
+ const float shade = 0.32f + 0.80f * std::pow(t, 0.8f);
+ dl->AddCircleFilled(o, rr, theme::u32(ImVec4(clay.x * shade, clay.y * shade, clay.z * shade, 1.0f)), 32);
+ }
+ if (type < 0) return;
+ const ImU32 hi = IM_COL32(255, 236, 222, 150), lo = IM_COL32(60, 30, 20, 150);
+ auto curve = [&](float dy, ImU32 col, float thick) {
+ ImVec2 pts[12];
+ for (int i = 0; i < 12; ++i) {
+ const float u = float(i) / 11.0f;
+ pts[i] = ImVec2(c.x - r * 0.62f + r * 1.24f * u, c.y + dy + std::sin(u * 6.28f) * r * 0.16f);
+ }
+ dl->AddPolyline(pts, 12, col, 0, thick);
+ };
+ const float w = std::max(1.5f, r * 0.11f);
+ switch (BrushType(type)) {
+ case BrushType::Crease:
+ case BrushType::DamStandard: // a groove: dark line with a lit lower lip
+ curve(0.0f, lo, w);
+ curve(w * 0.9f, hi, w * 0.5f);
+ break;
+ case BrushType::Smooth: dl->AddCircleFilled(ImVec2(c.x - r * 0.2f, c.y - r * 0.2f), r * 0.35f, IM_COL32(255, 240, 230, 40), 24); break;
+ case BrushType::Move:
+ case BrushType::SnakeHook:
+ case BrushType::Nudge: {
+ const ImVec2 a(c.x - r * 0.45f, c.y + r * 0.35f), b(c.x + r * 0.45f, c.y - r * 0.35f);
+ dl->AddLine(a, b, hi, w);
+ dl->AddTriangleFilled(b, ImVec2(b.x - r * 0.32f, b.y + r * 0.02f), ImVec2(b.x - r * 0.05f, b.y + r * 0.3f), hi);
+ break;
+ }
+ case BrushType::Inflate: dl->AddCircle(c, r * 0.45f, hi, 24, w); break;
+ case BrushType::Pinch:
+ dl->AddLine(ImVec2(c.x - r * 0.5f, c.y - r * 0.4f), ImVec2(c.x, c.y), hi, w);
+ dl->AddLine(ImVec2(c.x + r * 0.5f, c.y - r * 0.4f), ImVec2(c.x, c.y), hi, w);
+ break;
+ case BrushType::Flatten:
+ case BrushType::Trim:
+ dl->AddLine(ImVec2(c.x - r * 0.55f, c.y - r * 0.25f), ImVec2(c.x + r * 0.55f, c.y - r * 0.25f), hi, w);
+ dl->AddLine(ImVec2(c.x - r * 0.55f, c.y - r * 0.25f + w), ImVec2(c.x + r * 0.55f, c.y - r * 0.25f + w), lo, w * 0.6f);
+ break;
+ default: // raised strokes: lit crest with a shadow under it
+ curve(w * 0.9f, lo, w * 0.8f);
+ curve(0.0f, hi, w);
+ break;
+ }
+}
+
+// Glyph centred in a box, in `font` (or the current one).
+void centredText(ImDrawList* dl, ImFont* font, ImVec2 a, ImVec2 b, ImU32 col, const char* text) {
+ if (!font) font = ImGui::GetFont();
+ const float size = font->FontSize;
+ const ImVec2 ts = font->CalcTextSizeA(size, FLT_MAX, 0.0f, text);
+ dl->AddText(font, size, ImVec2(std::floor((a.x + b.x - ts.x) * 0.5f), std::floor((a.y + b.y - ts.y) * 0.5f)), col, text);
+}
+
+// Text clipped to `width` with an ellipsis.
+std::string elide(ImFont* font, const std::string& text, float width) {
+ if (font->CalcTextSizeA(font->FontSize, FLT_MAX, 0.0f, text.c_str()).x <= width) return text;
+ std::string s = text;
+ while (!s.empty() && font->CalcTextSizeA(font->FontSize, FLT_MAX, 0.0f, (s + "...").c_str()).x > width) s.pop_back();
+ return s + "...";
+}
+
+bool segmentPair(const std::string& a, const std::string& b) {
+ auto group = [](const std::string& id) {
+ if (id == "draw.sculpt" || id == "draw.paint") return 1;
+ if (id == "draw.zadd" || id == "draw.zsub") return 2;
- if (id.rfind("transform.sym_", 0) == 0) return 3;
++ if (id.rfind("transform.symmetry_", 0) == 0) return 3;
+ if (id.rfind("draw.pressure_", 0) == 0) return 4;
+ return 0;
+ };
+ return group(a) != 0 && group(a) == group(b);
+}
+
+} // namespace
+
+int brushTypeOfAction(std::string_view id) {
+ for (int i = 0; i < int(BrushType::Count); ++i)
+ if (id == brushActionId(BrushType(i))) return i;
+ return -1;
+}
+
+// ---------------------------------------------------------------------------
+// Button looks (ui::ActionButton)
+// ---------------------------------------------------------------------------
+
- bool drawActionLook(App& app, const Action& a, ImVec2 size, int look) {
++bool drawShelfTile(App& app, const Action& a, ImVec2 size) {
+ const bool on = a.checked && a.checked();
+ const std::string id = a.label + "##" + a.id;
+ const float s = app.uiScale_;
- if (look == int(ui::Look::Label) || look == int(ui::Look::Icon)) {
- if (on) {
- ImGui::PushStyleColor(ImGuiCol_Button, theme::accent);
- ImGui::PushStyleColor(ImGuiCol_ButtonHovered, theme::accentHover);
- ImGui::PushStyleColor(ImGuiCol_Text, theme::textOnAccent);
- }
- bool clicked;
- if (look == int(ui::Look::Icon) && a.icon) {
- const float h = size.y > 0.0f ? size.y : ImGui::GetFrameHeight();
- clicked = ImGui::Button((std::string(a.icon) + "##" + a.id).c_str(), ImVec2(size.x > 0.0f ? size.x : h, h));
- } else {
- const std::string text = a.icon ? std::string(a.icon) + " " + id : id;
- clicked = ImGui::Button(text.c_str(), size);
- }
- if (on) ImGui::PopStyleColor(3);
- return clicked;
- }
++ const int type = brushTypeOfAction(a.id);
++ const int look = type >= 0 || a.id == "draw.paint" ? 3 : 2; // picture tile, or icon over caption
+ // Icon over a caption (right shelf) and thumbnail tiles (left and bottom shelves).
+ if (size.x <= 0.0f) size.x = 44.0f * s;
+ if (size.y <= 0.0f) size.y = 40.0f * s;
+ const bool clicked = ImGui::InvisibleButton(id.c_str(), size);
+ const bool hovered = ImGui::IsItemHovered(), held = ImGui::IsItemActive();
+ const bool disabled = (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled) != 0;
+ const ImVec2 p0 = ImGui::GetItemRectMin(), p1 = ImGui::GetItemRectMax();
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ const float alpha = disabled ? 0.4f : 1.0f;
+ ImFont* caption = look == int(ui::Look::IconLabel) ? app.fontTiny_ : app.fontSmall_;
+ const float capH = caption ? caption->FontSize + 2.0f * s : 14.0f * s;
+ if (look == int(ui::Look::IconLabel)) {
+ const ImVec4 bg = on ? (hovered ? theme::accentHover : theme::accent)
+ : held ? theme::buttonPressed : hovered ? theme::buttonHover : theme::frame;
+ dl->AddRectFilled(p0, p1, theme::u32(bg, alpha), 4.0f * s);
+ const ImU32 fg = theme::u32(on ? theme::textOnAccent : theme::text, alpha);
+ centredText(dl, app.fontIcons_, p0, ImVec2(p1.x, p1.y - capH + 2.0f * s), fg, a.icon ? a.icon : "?");
+ centredText(dl, caption, ImVec2(p0.x, p1.y - capH), ImVec2(p1.x, p1.y - 1.0f * s), fg,
+ elide(caption ? caption : ImGui::GetFont(), a.label, size.x - 2.0f * s).c_str());
+ return clicked;
+ }
+ // Tile: a square picture (brush thumbnail or icon) with the name under it.
+ const float pic = std::min(size.x, size.y - capH);
+ const ImVec2 q0(p0.x + (size.x - pic) * 0.5f, p0.y), q1(q0.x + pic, q0.y + pic);
+ dl->AddRectFilled(p0, p1, theme::u32(hovered ? theme::buttonHover : theme::tile, hovered ? 0.55f : 0.0f), 4.0f * s);
- const int type = brushTypeOfAction(a.id);
+ ImTextureID tex = type >= 0 ? app.thumbnails().brush(type) : ImTextureID(0);
+ if (tex) {
+ dl->AddImageRounded(tex, ImVec2(q0.x + 2 * s, q0.y + 2 * s), ImVec2(q1.x - 2 * s, q1.y - 2 * s), ImVec2(0, 0),
+ ImVec2(1, 1), IM_COL32(255, 255, 255, int(255 * alpha)), 4.0f * s);
+ } else if (type >= 0) {
+ drawBrushIcon(dl, ImVec2((q0.x + q1.x) * 0.5f, (q0.y + q1.y) * 0.5f), pic * 0.36f, type);
+ } else {
+ dl->AddCircleFilled(ImVec2((q0.x + q1.x) * 0.5f, (q0.y + q1.y) * 0.5f), pic * 0.36f, theme::u32(theme::tile), 32);
+ centredText(dl, app.fontIcons_, q0, q1, theme::u32(on ? theme::accent : theme::text, alpha), a.icon ? a.icon : "?");
+ }
+ if (on) dl->AddRect(p0, p1, theme::u32(theme::accent), 4.0f * s, 0, 2.0f * s);
+ // The hotkey digit (1-9, 0) in the corner, as ZBrush shows brush shortcuts.
+ const std::string key = app.actions().shortcutText(a.id);
+ if (key.size() == 1 && caption)
+ dl->AddText(caption, caption->FontSize, ImVec2(p0.x + 3 * s, p0.y + 1 * s), theme::u32(theme::textDim), key.c_str());
+ centredText(dl, caption, ImVec2(p0.x, p1.y - capH), p1, theme::u32(on ? theme::accent : theme::text, alpha),
+ elide(caption ? caption : ImGui::GetFont(), a.label, size.x).c_str());
+ return clicked;
+}
+
+// ---------------------------------------------------------------------------
+// Actions
+// ---------------------------------------------------------------------------
+
+void App::registerShellActions() {
+ auto add = [this](Action a) { actions_.add(std::move(a)); };
+ auto flag = [this](std::string id, std::string label, const char* icon, std::string palette, std::string shortcut,
+ bool* value, std::string description) {
+ Action a;
+ a.id = std::move(id);
+ a.label = std::move(label);
+ a.icon = icon;
+ a.palette = std::move(palette);
+ a.shortcut = std::move(shortcut);
+ a.description = std::move(description);
+ a.run = [value] { *value = !*value; };
+ a.checked = [value] { return *value; };
+ actions_.add(std::move(a));
+ };
+
+ // Brushes: 1-9 and 0 pick the first ten, as before.
+ static const char* const kBrushHelp[] = {
+ "Raises the surface along the stroke; Alt digs in.",
+ "Builds up clay that fills the hollows first.",
+ "Relaxes the surface. Hold Shift to smooth with any brush.",
+ "Grabs the surface under the cursor and pulls it along.",
+ "Swells the surface outward along its normals.",
+ "Cuts a sharp crease; Alt raises a ridge.",
+ "Presses the surface toward a plane.",
+ "Pulls the surface toward the stroke to tighten edges.",
+ "A sharp V-shaped crease with the sides pinched in (ZBrush DamStandard).",
+ "Square, flat-topped clay strokes for blocking in forms.",
+ "Pulls the surface out into horns and tendrils.",
+ "Trim Dynamic: shaves away everything above a plane.",
+ "Raises the surface to one fixed height per stroke; overlaps never stack.",
+ "Slides the surface sideways along the stroke.",
+ };
+ static_assert(std::size(kBrushHelp) == size_t(BrushType::Count));
+ for (int i = 0; i < int(BrushType::Count); ++i) {
+ const BrushType type = BrushType(i);
+ Action a;
+ a.id = brushActionId(type);
+ a.label = brushName(type);
+ a.icon = ICON_LC_BRUSH;
+ a.palette = "Brush";
+ a.shortcut = i < 9 ? std::to_string(i + 1) : i == 9 ? "0" : "";
+ a.description = kBrushHelp[i];
+ a.run = [this, type] {
+ brush_ = type;
+ doc_.activeBrush = -1;
+ paintMode_ = false;
+ };
+ a.checked = [this, type] { return brush_ == type && doc_.activeBrush < 0 && !paintMode_; };
+ add(std::move(a));
+ }
+ add({"draw.sculpt", "Sculpt", nullptr,
+ "Brushes change the shape (ZBrush Zadd/Zsub). Turn on Rgb to paint colour at the same time.", "Draw", "", "",
+ [this] { paintMode_ = false; }, [this] { return !paintMode_; }, nullptr});
+ add({"draw.paint", "Paint", ICON_LC_PAINTBRUSH,
+ "Paint colour without sculpting (ZBrush Rgb on, Zadd off). Alt paints back to white, Shift still smooths.",
+ "Draw", "P", "", [this] { paintMode_ = !paintMode_; }, [this] { return paintMode_; }, nullptr});
+ add({"draw.zadd", "Zadd", nullptr, "Brushes add to the surface. Hold Alt to subtract for one stroke.", "Draw", "", "",
+ [this] { invertToggle_ = false; }, [this] { return !invertToggle_; }, nullptr});
+ add({"draw.zsub", "Zsub", nullptr, "Brushes subtract from the surface. Hold Alt to add for one stroke.", "Draw", "", "",
+ [this] { invertToggle_ = true; }, [this] { return invertToggle_; }, nullptr});
+ flag("draw.rgb", "Rgb", nullptr, "Draw", "", &paintRgb_, "Sculpt brushes also paint the colour (ZBrush Rgb with Zadd).");
+ flag("draw.front_faces", "Front", nullptr, "Brush", "", &frontFacesOnly_,
+ "Front faces only: brushes leave the far side of thin parts alone.");
- flag("draw.pressure_strength", "Pressure > Str", nullptr, "Draw > Tablet", "", &pressureStrength_,
++ flag("draw.pressure_strength", "Pressure > Strength", nullptr, "Draw > Tablet", "", &pressureStrength_,
+ "Pen pressure scales the brush strength.");
+ flag("draw.pressure_size", "Pressure > Size", nullptr, "Draw > Tablet", "", &pressureSize_,
+ "Pen pressure scales the brush size.");
- add({"draw.size_down", "Smaller brush", nullptr, "Make the brush 10% smaller.", "Draw", "[", "",
- [this] { radiusPx_ = std::max(2.0f, radiusPx_ / 1.1f); }, nullptr, nullptr});
- add({"draw.size_up", "Larger brush", nullptr, "Make the brush 10% larger.", "Draw", "]", "",
- [this] { radiusPx_ = std::min(800.0f, radiusPx_ * 1.1f); }, nullptr, nullptr});
- flag("transform.sym_x", "X", nullptr, "Transform", "X", &symmetry_.x, "Mirror strokes across X (left and right).");
- flag("transform.sym_y", "Y", nullptr, "Transform", "", &symmetry_.y, "Mirror strokes across Y (top and bottom).");
- flag("transform.sym_z", "Z", nullptr, "Transform", "", &symmetry_.z, "Mirror strokes across Z (front and back).");
++ flag("transform.symmetry_x", "X", nullptr, "Transform", "X", &symmetry_.x, "Mirror strokes across X (left and right).");
++ flag("transform.symmetry_y", "Y", nullptr, "Transform", "", &symmetry_.y, "Mirror strokes across Y (top and bottom).");
++ flag("transform.symmetry_z", "Z", nullptr, "Transform", "", &symmetry_.z, "Mirror strokes across Z (front and back).");
+ flag("ui.brush_lab", "AI Brush", ICON_LC_SPARKLES, "Brush", "", &showBrushLab_,
+ "Brush Lab: describe a brush in words and AI builds it; tweak the recipe with sliders.");
+ flag("ui.generate3d", "Generate 3D", ICON_LC_WAND_SPARKLES, "Generate", "", &showImageTo3D_,
+ "Turn an image or a description into a sculptable model (Hugging Face, fal.ai, Meshy, ComfyUI or offline).");
+ flag("ui.brush_gallery", "Community brushes", ICON_LC_GLOBE, "Brush", "", &showBrushGallery_,
+ "Browse, search and install brushes other sculptors shared.");
+
- // View (right shelf, Render palette).
- add({"view.frame", "Frame", ICON_LC_SCAN, "Frame the visible model in the view.", "Transform", "F", "",
++ // View (right shelf, Render palette). Frame keeps F; its short label fits the right shelf.
++ add({"view.frame", "Frame", ICON_LC_SCAN, "Fit the whole model in the view.", "Transform", "F", "",
+ [this] { camera_.frame(sceneBounds()); }, nullptr, nullptr});
- flag("view.wireframe", "Wireframe", ICON_LC_GRID_3X3, "Render", "W", &renderSettings_.wireframe,
- "Show the polygons of the active SubTool.");
- flag("view.polyf", "PolyF", ICON_LC_GRID_3X3, "Render", "Shift+F", &renderSettings_.wireframe,
++ flag("view.polyf", "PolyF", ICON_LC_GRID_3X3, "Render", "", &renderSettings_.wireframe,
+ "Polyframe: show the polygons of the active SubTool (same as W).");
+ flag("view.polygroups", "Groups", ICON_LC_SHAPES, "Render", "", &renderSettings_.showPolygroups,
+ "Colour each polygroup of the active SubTool.");
+ flag("view.mask", "Mask", ICON_LC_DROPLET, "Render", "", &renderSettings_.showMask, "Darken masked areas.");
+ flag("view.polypaint", "Paint", ICON_LC_PALETTE, "Render", "", &renderSettings_.showPolypaint,
+ "Show polypaint colours (off: plain material).");
+ flag("view.mesh", "Show Mesh", ICON_LC_BOX, "Render", "", &renderSettings_.showMesh, "Draw the sculpt.");
+ add({"view.splats", "Splats", ICON_LC_SPARKLE, "Show the Gaussian splat capture.", "Render", "", "",
+ [this] { renderSettings_.showSplats = !renderSettings_.showSplats; },
+ [this] { return renderSettings_.showSplats; }, [this] { return !doc_.splats.empty(); }});
+ add({"subtool.solo", "Solo", ICON_LC_SCAN_EYE, "Show only the active SubTool (again: show the others).",
+ "Tool > SubTool", "", "subtool_solo", [this] { runCommand("subtool_solo"); },
+ [this] {
+ int visible = 0;
+ for (const auto& s : doc_.subtools) visible += s.visible ? 1 : 0;
+ return doc_.subtoolCount() > 1 && visible == 1 && doc_.activeSubtoolInfo().visible;
+ },
+ [this] { return doc_.subtoolCount() > 1; }});
+ add({"nav.move", "Move", ICON_LC_HAND, "Drag on this button to pan the view (or Alt+drag the background).",
+ "Transform", "", "", nullptr, nullptr, nullptr});
+ add({"nav.zoom", "Zoom", ICON_LC_ZOOM_IN, "Drag up and down on this button to zoom (or use the mouse wheel).",
+ "Transform", "", "", nullptr, nullptr, nullptr});
+ add({"nav.rotate", "Rotate", ICON_LC_ROTATE_3D, "Drag on this button to orbit the view (or drag the background).",
+ "Transform", "", "", nullptr, nullptr, nullptr});
+
+ // Files and editing (File / Edit palettes).
- add({"file.new_sphere", "New Sphere", ICON_LC_FILE_PLUS, "Start over with a sphere.", "File", "Ctrl+N", "new_sphere",
- [this] { confirmDiscard([this] { runCommand("new_sphere"); }); }, nullptr, nullptr});
- add({"file.new_plane", "New Plane", nullptr, "Start over with a flat plane (reliefs, tiles).", "File", "", "new_plane",
- [this] { confirmDiscard([this] { runCommand("new_plane"); }); }, nullptr, nullptr});
- add({"file.open", "Open...", ICON_LC_FOLDER_OPEN, "Open a project, model or splat capture.", "File", "Ctrl+O", "",
- [this] { confirmDiscard([this] { openFileDialog(); }); }, nullptr, nullptr});
- add({"file.save", "Save", ICON_LC_SAVE, "Save the project (.sfproj): every SubTool, layer, brush and setting.", "File",
- "Ctrl+S", "", [this] { saveProjectAs(false); }, nullptr, nullptr});
- add({"file.save_as", "Save As...", nullptr, "Save the project under a new name.", "File", "Ctrl+Shift+S", "",
- [this] { saveProjectAs(true); }, nullptr, nullptr});
+ add({"file.import", "Import", ICON_LC_IMPORT, "Add a model file as a new SubTool.", "Tool", "", "",
+ [this] {
+ static const SDL_DialogFileFilter filters[] = {
+ {"Models", "obj;fbx;glb;gltf;ply;stl;GoZ;goz;usda;usd;usdz"}, {"All files", "*"}};
+ SDL_ShowOpenFileDialog(
+ [](void* user, const char* const* files, int) {
+ if (files && files[0]) static_cast<App*>(user)->queueFile(FileAction::AppendSubtool, files[0]);
+ },
+ this, window_, filters, 2, nullptr, false);
+ },
+ nullptr, nullptr});
+ add({"file.export_obj", "Export OBJ...", nullptr, "Save the visible SubTools as Wavefront OBJ.", "File", "", "",
+ [this] { saveFileDialog(FileAction::SaveObj); }, nullptr, nullptr});
- add({"file.export_glb", "Export GLB (blend shapes)...", nullptr, "glTF binary with layers as blend shapes.", "File",
- "Ctrl+E", "", [this] { saveFileDialog(FileAction::ExportGlb); }, nullptr, nullptr});
+ add({"file.export_lods", "Export LOD Chain...", nullptr, "One GLB per level of detail.", "File", "", "",
+ [this] { saveFileDialog(FileAction::ExportLods); }, nullptr, nullptr});
+ add({"file.export_usd", "Export USD / USDZ...", nullptr, "OpenUSD for Apple, Omniverse and film pipelines.", "File",
+ "", "", [this] { saveFileDialog(FileAction::ExportUsd); }, nullptr, nullptr});
+ add({"file.export_fbx", "Export FBX for Unreal...", nullptr, "FBX sized and named for Unreal Engine, with LODs.",
+ "File", "", "", [this] { saveFileDialog(FileAction::ExportUnreal); }, nullptr, nullptr});
- add({"file.send_unreal", "Send to Unreal", ICON_LC_SEND, "Import (or update) the model in the open Unreal Editor.",
- "File", "Ctrl+U", "", [this] { sendToUnreal(); }, nullptr, [this] { return !pendingUnreal_.valid(); }});
+ add({"file.save_splats", "Save Splats...", nullptr, "Save the Gaussian splats (PLY, glTF or USD).", "File", "", "",
+ [this] { saveFileDialog(FileAction::SaveSplats); }, nullptr, [this] { return !doc_.splats.empty(); }});
+ add({"file.quit", "Quit", ICON_LC_LOG_OUT, "Close SculptForge (asks to save changes first).", "File", "", "",
+ [this] { requestQuit(); }, nullptr, nullptr});
- add({"edit.undo", "Undo", ICON_LC_UNDO_2, "Undo the last change of the active SubTool.", "Edit", "Ctrl+Z", "undo",
- [this] { runCommand("undo"); }, nullptr, [this] { return doc_.undo.canUndo(); }});
- add({"edit.redo", "Redo", ICON_LC_REDO_2, "Redo what was undone.", "Edit", "Ctrl+Shift+Z", "redo",
- [this] { runCommand("redo"); }, nullptr, [this] { return doc_.undo.canRedo(); }});
- add({"brush.paste", "Paste brush", nullptr,
- "Install a brush someone shared: a brush code (sfbrush1:...) or .sfbrush text on the clipboard.", "Brush",
- "Ctrl+V", "", [this] { pasteBrush(); }, nullptr, nullptr});
- add({"geometry.subdivide", "Subdivide", nullptr, "", "Tool > Geometry", "Ctrl+D", "subdivide",
- [this] { runCommand("subdivide"); }, nullptr, nullptr});
+ add({"geometry.remesh", "Voxel Remesh", nullptr,
+ "Rebuild as an even, watertight surface (like DynaMesh): merges parts, fixes scans and generated models.",
+ "Tool > Remesh", "", "remesh", [this] { runCommand("remesh", {{"resolution", double(voxelResolution_)}}); },
+ nullptr, nullptr});
+ add({"geometry.to_splats", "Sculpt to Splats", nullptr, "Turn the sculpt into Gaussian splats.", "Splats", "",
+ "mesh_to_splats", [this] { runCommand("mesh_to_splats"); }, nullptr, nullptr});
+ add({"color.fill", "Fill", ICON_LC_PAINT_BUCKET, "Fill the unmasked area with the colour (FillObject).", "Color", "",
+ "paint_fill", [this] { runCommand("paint_fill", {{"color", colorToHex(doc_.paintColor)}}); }, nullptr, nullptr});
- add({"color.pick", "Pick colour", ICON_LC_PIPETTE, "Take the colour under the cursor.", "Color", "C", "",
- [this] { pickColorUnderCursor(); }, nullptr, nullptr});
- flag("help.controls", "Controls", ICON_LC_KEYBOARD, "Help", "F1", &showHelp_, "Mouse, tablet and keyboard controls.");
- flag("help.about", "About SculptForge", ICON_LC_INFO, "Help", "", &showAbout_, "Version, licence and credits.");
- add({"help.website", "Website & documentation", ICON_LC_EXTERNAL_LINK, "Guides and the manual, in your browser.", "Help",
- "", "", [] { SDL_OpenURL("https://islandmed.github.io/SculptForge/"); }, nullptr, nullptr});
- add({"help.report", "Report a problem", ICON_LC_BUG, "Open the issue tracker in your browser.", "Help", "", "",
- [] { SDL_OpenURL("https://github.com/islandmed/SculptForge/issues"); }, nullptr, nullptr});
+
+ // The shell itself.
+ add({"ui.toggle_shelves", "Shelves", ICON_LC_MAXIMIZE, "Hide or show the shelves and trays around the canvas.", "Preferences",
+ "Tab", "",
+ [this] {
+ layout_.shelvesVisible = !layout_.shelvesVisible;
+ updateCameraAspect();
+ },
+ [this] { return layout_.shelvesVisible; }, nullptr});
+ add({"ui.menus", "Menus", ICON_LC_MENU, "Show or hide the palette bar under the title.", "Preferences", "", "",
+ [this] {
+ layout_.paletteBarVisible = !layout_.paletteBarVisible;
+ noteLayoutChanged();
+ },
+ [this] { return layout_.paletteBarVisible; }, nullptr});
+ add({"ui.tray.left", "Left tray", ICON_LC_PANEL_LEFT, "Open or close the left tray (or click its divider).",
+ "Preferences", "", "",
+ [this] {
+ layout_.leftTrayOpen = !layout_.leftTrayOpen;
+ noteLayoutChanged();
+ },
+ [this] { return layout_.leftTrayOpen; }, nullptr});
+ add({"ui.tray.right", "Right tray", ICON_LC_PANEL_RIGHT, "Open or close the right tray (or click its divider).",
+ "Preferences", "", "",
+ [this] {
+ layout_.rightTrayOpen = !layout_.rightTrayOpen;
+ noteLayoutChanged();
+ },
+ [this] { return layout_.rightTrayOpen; }, nullptr});
+ static const char* const kPresetHelp[] = {
+ "Standard layout: Tool palette in the right tray, shelves around the canvas.",
+ "Sculpt layout: both trays closed for the largest canvas.",
+ "Wide layout: Brush, Stroke and Alpha in the left tray, Tool and Material in the right one.",
+ };
+ for (int i = 0; i < 3; ++i)
+ add({"ui.preset." + std::to_string(i + 1), std::to_string(i + 1), nullptr, kPresetHelp[i], "Preferences > Layout", "",
+ "", [this, i] { applyPreset(i); }, nullptr, nullptr});
+ int count = 0;
+ const PaletteDef* list = palettes(count);
+ for (int i = 0; i < count; ++i) {
+ const std::string id = list[i].id;
+ add({"ui.palette." + id, list[i].name, list[i].icon,
+ std::string("Open the ") + list[i].name + " palette (click its tray icon to keep it in a tray).", "Palettes", "",
+ "",
+ [this, id] {
+ if (std::count(layout_.leftTray.begin(), layout_.leftTray.end(), id) +
+ std::count(layout_.rightTray.begin(), layout_.rightTray.end(), id)) {
+ flashPalette_ = id;
+ flashStart_ = ImGui::GetTime();
+ return;
+ }
+ int n = 0;
+ const PaletteDef* all = palettes(n);
+ float x = shell_.paletteBar.x + 8.0f * uiScale_;
+ for (int k = 0; k < n && all[k].id != id; ++k) // under its name in the bar
+ x += ImGui::CalcTextSize(all[k].name).x + 2.0f * 8.0f * uiScale_;
+ dropdown_ = id;
+ dropdownX_ = x;
+ openDropdown_ = true;
+ },
+ nullptr, nullptr});
+ }
+}
+
+// ---------------------------------------------------------------------------
+// Layout
+// ---------------------------------------------------------------------------
+
+ShellGeometry App::shellGeometry() const {
+ int w = 0, h = 0;
+ SDL_GetWindowSize(window_, &w, &h);
+ return computeShell(layout_, float(w), float(h), uiScale_);
+}
+
+CanvasRect App::canvasRect() const {
+ int w = 0, h = 0;
+ SDL_GetWindowSize(window_, &w, &h);
+ if (hideUi_) return {0.0f, 0.0f, float(std::max(w, 1)), float(std::max(h, 1))};
+ return computeShell(layout_, float(w), float(h), uiScale_).canvas;
+}
+
+void App::canvasRay(float x, float y, glm::vec3& origin, glm::vec3& dir) const {
+ const CanvasRect c = canvasRect();
+ camera_.screenRay(x - c.x, y - c.y, c.w, c.h, origin, dir);
+}
+
+Renderer::Viewport App::canvasViewport(int fbWidth, int fbHeight) const {
+ if (hideUi_) return {};
+ int w = 0, h = 0;
+ SDL_GetWindowSize(window_, &w, &h);
+ if (w <= 0 || h <= 0) return {};
+ const float sx = float(fbWidth) / float(w), sy = float(fbHeight) / float(h);
+ const CanvasRect c = canvasRect();
+ Renderer::Viewport v;
+ v.x = int(std::lround(c.x * sx));
+ v.w = std::max(1, int(std::lround((c.x + c.w) * sx)) - v.x);
+ const int top = int(std::lround(c.y * sy)), bottom = int(std::lround((c.y + c.h) * sy));
+ v.y = fbHeight - bottom;
+ v.h = std::max(1, bottom - top);
+ v.surround = glm::vec3(theme::shellBg.x, theme::shellBg.y, theme::shellBg.z);
+ return v;
+}
+
+void App::updateCameraAspect() {
+ const CanvasRect c = canvasRect();
+ camera_.aspect = c.w / std::max(c.h, 1.0f);
+}
+
- void App::noteLayoutChanged() {
- if (layoutHintShown_ || !interactive()) return;
- layoutHintShown_ = true;
- status_ = "Layout changed - Ctrl+Shift+I (Store Config) keeps it";
- lastCommandOk_ = true;
- }
++// The one-time "Layout changed - Ctrl+Shift+I to keep it" hint comes from watchLayoutChanges (Config.cpp),
++// which compares the layout with the stored one; shell edits only need to change layout_.
++void App::noteLayoutChanged() {}
+
+void App::applyPreset(int preset) {
+ UiLayout l = standardLayout();
+ l.customize = layout_.customize;
+ l.consoleOpen = layout_.consoleOpen;
+ l.consoleHeight = layout_.consoleHeight;
+ l.lightboxOpen = layout_.lightboxOpen;
+ l.lightboxRows = layout_.lightboxRows;
+ l.lightboxTab = layout_.lightboxTab;
+ l.lightboxBottom = layout_.lightboxBottom;
+ l.leftHanded = layout_.leftHanded;
+ static const char* const kNames[] = {"Standard", "Sculpt", "Wide"};
+ if (preset == 1) {
+ l.leftTrayOpen = l.rightTrayOpen = false;
+ } else if (preset == 2) {
+ l.leftTrayOpen = true;
+ l.leftTray = {"brush", "stroke", "alpha"};
+ l.rightTray = {"tool", "material"};
+ }
+ layout_ = std::move(l);
+ collapsedPalettes_.clear();
+ dropdown_.clear();
+ status_ = std::string("Layout: ") + kNames[std::clamp(preset, 0, 2)] + " (Ctrl+Shift+I keeps it)";
+ lastCommandOk_ = true;
+}
+
+void App::removePaletteFromTrays(const std::string& id) {
+ for (auto* tray : {&layout_.leftTray, &layout_.rightTray}) tray->erase(std::remove(tray->begin(), tray->end(), id), tray->end());
+}
+
+void App::autoCollapseTray(bool right, const std::string& keep) {
- if (!autoCollapse_[right ? 1 : 0]) return;
++ if (!(right ? uiPrefs_.autoCollapseRight : uiPrefs_.autoCollapseLeft)) return;
+ for (const std::string& other : right ? layout_.rightTray : layout_.leftTray)
+ if (other != keep && std::find(collapsedPalettes_.begin(), collapsedPalettes_.end(), other) == collapsedPalettes_.end())
+ collapsedPalettes_.push_back(other);
+}
+
+void App::movePaletteToTray(const std::string& id, bool right) {
+ removePaletteFromTrays(id);
+ (right ? layout_.rightTray : layout_.leftTray).push_back(id);
+ (right ? layout_.rightTrayOpen : layout_.leftTrayOpen) = true;
+ collapsedPalettes_.erase(std::remove(collapsedPalettes_.begin(), collapsedPalettes_.end(), id), collapsedPalettes_.end());
+ autoCollapseTray(right, id);
+ if (dropdown_ == id) {
+ dropdown_.clear();
+ ImGui::ClosePopupsExceptModals();
+ }
+ flashPalette_ = id;
+ flashStart_ = ImGui::GetTime();
+ noteLayoutChanged();
+}
+
+// ---------------------------------------------------------------------------
+// Drawing
+// ---------------------------------------------------------------------------
+
+void App::drawCanvasFrame() {
+ const CanvasRect c = shell_.canvas;
+ ImDrawList* dl = ImGui::GetBackgroundDrawList();
+ dl->AddRect(ImVec2(c.x - 1.0f, c.y - 1.0f), ImVec2(c.x + c.w + 1.0f, c.y + c.h + 1.0f), theme::u32(theme::canvasBorder));
+}
+
+void App::drawShell() {
+ const ImGuiViewport* vp = ImGui::GetMainViewport();
+ shell_ = computeShell(layout_, vp->Size.x, vp->Size.y, uiScale_);
+ // Splats arriving (file, command or AI agent) bring their palette into the right tray.
+ if (doc_.splatsVersion != seenSplatsVersion_) {
+ seenSplatsVersion_ = doc_.splatsVersion;
+ if (!doc_.splats.empty() && std::count(layout_.leftTray.begin(), layout_.leftTray.end(), "splats") +
+ std::count(layout_.rightTray.begin(), layout_.rightTray.end(), "splats") ==
+ 0)
+ layout_.rightTray.push_back("splats");
+ }
+ if (status_ != statusShown_) {
+ statusShown_ = status_;
+ statusSince_ = ImGui::GetTime();
+ }
+ drawCanvasFrame();
+ drawTitleStrip(shell_);
+ if (layout_.paletteBarVisible) drawPaletteBar(shell_);
+ if (shell_.shelves) {
+ drawShelf(kShelfTop, shell_.topShelf);
+ drawShelf(kShelfLeft, shell_.leftShelf);
+ drawShelf(kShelfRight, shell_.rightShelf);
+ drawShelf(kShelfBottom, shell_.bottomShelf);
+ if (shell_.leftTray.w > 0.0f) drawTray(false, shell_.leftTray);
+ if (shell_.rightTray.w > 0.0f) drawTray(true, shell_.rightTray);
+ drawDivider(false, shell_.leftDivider);
+ drawDivider(true, shell_.rightDivider);
+ }
+ drawPaletteDropdown();
+ finishShelfDrag();
+}
+
+void App::drawTitleStrip(const ShellGeometry& g) {
+ const float s = uiScale_;
+ if (!beginShellWindow("##TitleStrip", g.title, theme::shellBg, ImVec2(8.0f * s, 0.0f))) {
+ ImGui::End();
+ return;
+ }
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ const float h = g.title.h;
+ dl->AddLine(ImVec2(g.title.x, g.title.y + h - 1.0f), ImVec2(g.title.x + g.title.w, g.title.y + h - 1.0f),
+ theme::u32(theme::border));
+ const float textY = std::floor((h - ImGui::GetTextLineHeight()) * 0.5f);
+ const float buttonH = h - 6.0f * s;
+ ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6.0f * s, (buttonH - ImGui::GetFontSize()) * 0.5f));
+ ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4.0f * s, 0.0f));
+
+ // App mark and name.
+ ImGui::SetCursorPos(ImVec2(8.0f * s, textY));
+ ImGui::TextColored(theme::accent, ICON_LC_BOX);
+ ImGui::SameLine(0.0f, 5.0f * s);
+ if (fontBold_) ImGui::PushFont(fontBold_);
+ ImGui::TextUnformatted("SculptForge");
+ if (fontBold_) ImGui::PopFont();
+
+ // Document name; click saves.
+ ImGui::SameLine(0.0f, 16.0f * s);
+ std::string name = doc_.path.empty() ? std::string("Untitled")
+ : std::filesystem::path(std::u8string(doc_.path.begin(), doc_.path.end())).filename().string();
+ if (doc_.dirty()) name += " *";
+ ImGui::SetCursorPosY((h - buttonH) * 0.5f);
+ ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));
+ ImGui::PushStyleColor(ImGuiCol_ButtonHovered, theme::headerHover);
+ if (ImGui::Button((name + "##docname").c_str(), ImVec2(0, buttonH))) saveProjectAs(false);
+ ImGui::PopStyleColor(2);
+ ui::HelpText("Project", "Ctrl+S", "Click to save the project. * means it has unsaved changes.", "Title");
+
+ // Right-aligned controls: QuickSave, layout presets, Menus, search. Measured first.
+ const ImGuiStyle& st = ImGui::GetStyle();
+ auto buttonW = [&](const char* label) { return ImGui::CalcTextSize(label, nullptr, true).x + st.FramePadding.x * 2.0f; };
+ const bool quickSave = actions_.find("file.quicksave") != nullptr;
+ const float searchW = 150.0f * s;
+ float rightW = searchW + buttonW(ICON_LC_MENU " Menus") + 3.0f * (buttonH + 2.0f * s) + 18.0f * s;
+ if (quickSave) rightW += buttonW("QuickSave") + 8.0f * s;
+ const float rightX = g.title.w - 8.0f * s - rightW;
+
+ // Info readout and the status message, elided to fit.
+ ImGui::SameLine(0.0f, 14.0f * s);
+ const float infoX = ImGui::GetCursorPosX();
+ ImGui::SetCursorPosY(textY);
+ size_t tris = 0, verts = 0;
+ for (int i = 0; i < doc_.subtoolCount(); ++i) {
+ tris += doc_.subtoolMesh(i).triangleCount();
+ verts += doc_.subtoolMesh(i).vertexCount();
+ }
+ char info[256];
+ std::snprintf(info, sizeof info, "Verts %s Tris %s SubTool %s (%d/%d) Layer %s%s%s %.0f fps",
+ shortCount(verts).c_str(), shortCount(tris).c_str(), doc_.activeSubtoolInfo().name.c_str(),
+ doc_.activeSubtool + 1, doc_.subtoolCount(),
+ doc_.activeLayer >= 0 && doc_.activeLayer < int(doc_.mesh.layers.size())
+ ? doc_.mesh.layers[size_t(doc_.activeLayer)].name.c_str()
+ : "Base",
+ doc_.splats.empty() ? "" : " Splats ", doc_.splats.empty() ? "" : shortCount(doc_.splats.size()).c_str(),
+ ImGui::GetIO().Framerate);
+ const float avail = rightX - infoX - 16.0f * s;
+ const float infoW = ImGui::CalcTextSize(info).x;
+ if (infoW < avail) {
+ ImGui::TextDisabled("%s", info);
+ const std::string& msg = layout_.customize ? std::string("Customize: Ctrl+Alt+drag to move or remove items") : status_;
+ if (!msg.empty() && avail - infoW > 60.0f * s) {
+ ImGui::SameLine(0.0f, 20.0f * s);
+ const bool error = !layout_.customize && !lastCommandOk_ && ImGui::GetTime() - statusSince_ < 6.0;
+ ImGui::PushStyleColor(ImGuiCol_Text, layout_.customize ? theme::accent : error ? theme::danger : theme::text);
+ ImGui::TextUnformatted(elide(ImGui::GetFont(), msg, avail - infoW - 20.0f * s).c_str());
+ ImGui::PopStyleColor();
+ if (ImGui::IsItemHovered() && msg.size() > 40) ImGui::SetTooltip("%s", msg.c_str());
+ }
+ } else {
+ ImGui::TextDisabled("%s", elide(ImGui::GetFont(), info, std::max(0.0f, avail)).c_str());
+ }
+
+ ImGui::SetCursorPos(ImVec2(rightX, (h - buttonH) * 0.5f));
+ if (quickSave) {
+ ui::ActionButton(*this, "file.quicksave", ImVec2(0, buttonH));
+ ImGui::SameLine(0.0f, 8.0f * s);
+ }
+ for (int i = 1; i <= 3; ++i) {
+ ui::ActionButton(*this, ("ui.preset." + std::to_string(i)).c_str(), ImVec2(buttonH + 2.0f * s, buttonH));
+ ui::HelpAction(*this, ("ui.preset." + std::to_string(i)).c_str());
+ ImGui::SameLine(0.0f, 2.0f * s);
+ }
+ ImGui::SameLine(0.0f, 8.0f * s);
- ui::ActionButton(*this, "ui.menus", ImVec2(0, buttonH));
++ ui::ActionButton(*this, "ui.menus", ImVec2(0, buttonH), ui::Look::IconLabel);
+ ImGui::SameLine(0.0f, 8.0f * s);
+ // Search: a field-looking button that opens the command palette (F3).
+ {
+ const ImVec2 p = ImGui::GetCursorScreenPos();
+ const bool clicked = ImGui::InvisibleButton("##search", ImVec2(searchW, buttonH));
+ const bool hovered = ImGui::IsItemHovered();
+ dl->AddRectFilled(p, ImVec2(p.x + searchW, p.y + buttonH), theme::u32(hovered ? theme::frameHover : theme::frame), 3.0f * s);
+ const float ty = p.y + (buttonH - ImGui::GetFontSize()) * 0.5f;
+ dl->AddText(ImVec2(p.x + 7.0f * s, ty), theme::u32(theme::textDim), ICON_LC_SEARCH " Search");
+ const ImVec2 kw = ImGui::CalcTextSize("F3");
+ dl->AddText(ImVec2(p.x + searchW - kw.x - 7.0f * s, ty), theme::u32(theme::textDim, 0.8f), "F3");
+ if (clicked) {
+ if (const Action* a = actions_.find("ui.command_palette"); a && a->run) a->run();
+ }
+ ui::HelpText("Search", "F3", "Find any command, brush or material by name and run it.", "Title");
+ }
+ ImGui::PopStyleVar(2);
+ ImGui::End();
+}
+
+void App::drawPaletteBar(const ShellGeometry& g) {
+ const float s = uiScale_;
+ if (!beginShellWindow("##PaletteBar", g.paletteBar, theme::shellBg, ImVec2(8.0f * s, 0.0f))) {
+ ImGui::End();
+ return;
+ }
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ dl->AddLine(ImVec2(g.paletteBar.x, g.paletteBar.y + g.paletteBar.h - 1.0f),
+ ImVec2(g.paletteBar.x + g.paletteBar.w, g.paletteBar.y + g.paletteBar.h - 1.0f), theme::u32(theme::border));
+ ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));
+ ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(8.0f * s, 0.0f));
+ ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0.0f);
+ int count = 0;
+ const PaletteDef* list = palettes(count);
+ for (int i = 0; i < count; ++i) {
+ const PaletteDef& p = list[i];
+ const bool inTray = std::count(layout_.leftTray.begin(), layout_.leftTray.end(), p.id) +
+ std::count(layout_.rightTray.begin(), layout_.rightTray.end(), p.id) >
+ 0;
+ const bool open = dropdown_ == p.id;
+ ImGui::PushStyleColor(ImGuiCol_Button, open ? theme::header : ImVec4(0, 0, 0, 0));
+ ImGui::PushStyleColor(ImGuiCol_ButtonHovered, theme::headerHover);
+ ImGui::PushStyleColor(ImGuiCol_ButtonActive, theme::header);
+ ImGui::PushStyleColor(ImGuiCol_Text, inTray ? theme::accent : open ? theme::textOnAccent : theme::text);
+ if (i) ImGui::SameLine();
+ const std::string label = std::string(p.name) + "##palette." + p.id;
+ // While a drop-down is open, the click that closes it (ImGui swallows that one) opens another palette
+ // when it lands on that palette's name, as in a menu bar; on the open palette's own name it just closes.
+ const bool pressed = ImGui::Button(label.c_str(), ImVec2(0, g.paletteBar.h - 1.0f));
+ const bool switchTo = !dropdown_.empty() && !open && ImGui::IsMouseClicked(ImGuiMouseButton_Left) &&
+ ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup);
+ if (pressed || switchTo) {
+ if (inTray) {
+ flashPalette_ = p.id;
+ flashStart_ = ImGui::GetTime();
+ } else if (!open) {
+ dropdown_ = p.id;
+ dropdownX_ = ImGui::GetItemRectMin().x;
+ openDropdown_ = true;
+ }
+ }
+ ImGui::PopStyleColor(4);
+ ui::HelpAction(*this, ("ui.palette." + std::string(p.id)).c_str());
+ }
+ ImGui::PopStyleVar(3);
+ ImGui::End();
+}
+
+bool App::paletteHeader(const char* id, bool inTray, bool right) {
+ const PaletteDef* def = findPalette(id);
+ if (!def) return false;
+ const float s = uiScale_;
+ const float h = 24.0f * s;
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ const ImVec2 p = ImGui::GetCursorScreenPos();
+ const float w = ImGui::GetContentRegionAvail().x;
+ const bool collapsed = inTray && std::count(collapsedPalettes_.begin(), collapsedPalettes_.end(), id) > 0;
+ dl->AddRectFilled(p, ImVec2(p.x + w, p.y + h), theme::u32(theme::header), 3.0f * s);
+
+ // Tray icon: in a drop-down it moves the palette into the right tray (Shift: left) or can be dragged to one;
+ // in a tray it sends the palette back to the bar.
+ ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
+ const bool iconClicked = ImGui::InvisibleButton("##totray", ImVec2(h, h));
+ const bool iconHovered = ImGui::IsItemHovered();
+ if (!inTray && ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceNoDisableHover)) {
+ ImGui::SetDragDropPayload("SF_PALETTE", id, std::strlen(id) + 1);
+ ImGui::Text(ICON_LC_PANEL_RIGHT " %s", def->name);
+ ImGui::EndDragDropSource();
+ }
+ if (inTray) ui::HelpText("Back to the palette bar", nullptr, "Take this palette out of the tray.", def->name);
+ else
+ ui::HelpText("Move to the tray", nullptr,
+ "Keep this palette in the right tray (Shift+click: left tray), or drag the icon onto a tray.", def->name);
+ centredText(dl, nullptr, p, ImVec2(p.x + h, p.y + h), theme::u32(iconHovered ? theme::accentHover : theme::accent),
+ inTray ? (right ? ICON_LC_PANEL_RIGHT : ICON_LC_PANEL_LEFT) : ICON_LC_PANEL_RIGHT);
+ ImGui::SameLine();
+ const bool titleClicked = ImGui::InvisibleButton("##title", ImVec2(std::max(1.0f, w - 2.0f * h), h));
+ const bool titleHovered = ImGui::IsItemHovered();
+ if (fontBold_) ImGui::PushFont(fontBold_);
+ dl->AddText(ImVec2(p.x + h + 2.0f * s, p.y + (h - ImGui::GetFontSize()) * 0.5f),
+ theme::u32(titleHovered && inTray ? theme::textOnAccent : theme::text), def->name);
+ ImGui::LogText("%s", def->name);
+ if (fontBold_) ImGui::PopFont();
+ ImGui::SameLine();
+ const bool endClicked = ImGui::InvisibleButton(inTray ? "##collapse" : "##close", ImVec2(h, h));
+ const bool endHovered = ImGui::IsItemHovered();
+ centredText(dl, nullptr, ImVec2(p.x + w - h, p.y), ImVec2(p.x + w, p.y + h),
+ theme::u32(endHovered ? theme::textOnAccent : theme::textDim),
+ inTray ? (collapsed ? ICON_LC_CHEVRON_RIGHT : ICON_LC_CHEVRON_DOWN) : ICON_LC_X);
+ ImGui::PopStyleVar();
+ ImGui::Dummy(ImVec2(0, 2.0f * s));
+
+ if (iconClicked) {
+ if (inTray) {
+ removePaletteFromTrays(id);
+ noteLayoutChanged();
+ return false;
+ }
+ movePaletteToTray(id, (SDL_GetModState() & SDL_KMOD_SHIFT) == 0);
+ return false;
+ }
+ if (inTray && (titleClicked || endClicked)) {
+ if (collapsed) {
+ collapsedPalettes_.erase(std::remove(collapsedPalettes_.begin(), collapsedPalettes_.end(), id), collapsedPalettes_.end());
+ autoCollapseTray(right, id);
+ } else {
+ collapsedPalettes_.push_back(id);
+ }
+ return collapsed;
+ }
+ if (!inTray && endClicked) {
+ dropdown_.clear();
+ ImGui::CloseCurrentPopup();
+ return false;
+ }
+ return !collapsed;
+}
+
+void App::drawPaletteBody(const std::string& id) {
+ const PaletteDef* def = findPalette(id);
+ if (!def) return;
+ ImGui::PushID(def->id);
+ (this->*(def->draw))();
+ ImGui::PopID();
+}
+
+void App::drawPaletteDropdown() {
+ if (openDropdown_) {
+ ImGui::OpenPopup("##palettedropdown");
+ openDropdown_ = false;
+ }
+ if (dropdown_.empty()) return;
+ const PaletteDef* def = findPalette(dropdown_);
+ if (!def) {
+ dropdown_.clear();
+ return;
+ }
+ const float s = uiScale_;
+ const ImGuiViewport* vp = ImGui::GetMainViewport();
+ const float w = 300.0f * s;
+ ImGui::SetNextWindowPos(ImVec2(std::clamp(dropdownX_, 4.0f * s, vp->Size.x - w - 4.0f * s),
+ shell_.paletteBar.y + shell_.paletteBar.h));
+ ImGui::SetNextWindowSizeConstraints(ImVec2(w, 0), ImVec2(w, vp->Size.y - 60.0f * s));
+ // Whole-pixel padding: auto-fit truncates sizes, and a fraction of a pixel too little shows a scrollbar.
+ ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(std::round(6.0f * s), std::round(6.0f * s)));
+ const bool open = ImGui::BeginPopup("##palettedropdown");
+ ImGui::PopStyleVar();
+ if (!open) {
+ dropdown_.clear();
+ return;
+ }
+ Demo::pushScope(def->name);
+ if (def->scope) Demo::pushScope(def->scope);
+ const std::string id = dropdown_;
+ if (paletteHeader(id.c_str(), false, true)) drawPaletteBody(id);
+ if (def->scope) Demo::popScope();
+ Demo::popScope();
+ if (ImGui::IsKeyPressed(ImGuiKey_Escape) && !ImGui::IsAnyItemActive()) ImGui::CloseCurrentPopup();
+ ImGui::EndPopup();
+}
+
+void App::drawTray(bool right, const CanvasRect& r) {
+ const float s = uiScale_;
+ std::vector<std::string>& list = right ? layout_.rightTray : layout_.leftTray;
+ if (!beginShellWindow(right ? "##RightTray" : "##LeftTray", r, theme::panelBg, ImVec2(6.0f * s, 6.0f * s), 0)) {
+ ImGui::End();
+ return;
+ }
+ const std::vector<std::string> ids = list; // headers may move palettes out
+ for (const std::string& id : ids) {
+ const PaletteDef* def = findPalette(id);
+ if (!def) continue;
+ ImGui::PushID(id.c_str());
+ Demo::pushScope(def->name);
+ if (def->scope) Demo::pushScope(def->scope);
+ const ImVec2 top = ImGui::GetCursorScreenPos();
+ if (flashPalette_ == id) {
+ const double t = ImGui::GetTime() - flashStart_;
+ if (t < 0.05) ImGui::SetScrollHereY(0.0f);
+ if (t < 0.9) {
+ const float a = float(0.45 * (1.0 - t / 0.9));
+ ImGui::GetWindowDrawList()->AddRectFilled(top, ImVec2(top.x + ImGui::GetContentRegionAvail().x, top.y + 24.0f * s),
+ theme::u32(theme::accent, a), 3.0f * s);
+ } else {
+ flashPalette_.clear();
+ }
+ }
+ if (paletteHeader(id.c_str(), true, right)) {
+ drawPaletteBody(id);
+ ImGui::Dummy(ImVec2(0, 4.0f * s));
+ }
+ if (def->scope) Demo::popScope();
+ Demo::popScope();
+ ImGui::PopID();
+ }
+ if (list.empty()) {
+ const ImVec2 avail = ImGui::GetContentRegionAvail();
+ const char* hint = "Click a palette's " ICON_LC_PANEL_RIGHT " icon\nor drag it here";
+ const ImVec2 ts = ImGui::CalcTextSize(hint);
+ ImGui::SetCursorPos(ImVec2((avail.x - ts.x) * 0.5f + 6.0f * s, std::max(ImGui::GetCursorPosY(), avail.y * 0.4f)));
+ ImGui::TextDisabled("%s", hint);
+ }
+ // The whole tray accepts palettes dragged by their header icon.
+ ImGuiWindow* window = ImGui::GetCurrentWindow();
+ if (ImGui::BeginDragDropTargetCustom(window->Rect(), ImGui::GetID("##traydrop"))) {
+ if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("SF_PALETTE"))
+ movePaletteToTray(static_cast<const char*>(payload->Data), right);
+ ImGui::EndDragDropTarget();
+ }
+ ImGui::End();
+}
+
+void App::drawDivider(bool right, const CanvasRect& r) {
+ if (r.w <= 0.0f) return;
+ const float s = uiScale_;
+ if (!beginShellWindow(right ? "##RightDivider" : "##LeftDivider", r, theme::shellBg, ImVec2(0, 0))) {
+ ImGui::End();
+ return;
+ }
+ const bool open = right ? layout_.rightTrayOpen && !shell_.narrow : layout_.leftTrayOpen;
+ ImGui::InvisibleButton(right ? "##rightdivider" : "##leftdivider", ImVec2(r.w, r.h));
+ const bool hovered = ImGui::IsItemHovered(), active = ImGui::IsItemActive();
+ ImGuiIO& io = ImGui::GetIO();
+ if ((hovered || active) && open) ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW);
+ if (active && open && ImGui::IsMouseDragging(ImGuiMouseButton_Left, 3.0f * s) && io.MouseDelta.x != 0.0f) {
+ float& width = right ? layout_.rightTrayWidth : layout_.leftTrayWidth;
+ const float logicalW = io.DisplaySize.x / s;
+ width = std::clamp(trayWidth(width, logicalW) + (right ? -io.MouseDelta.x : io.MouseDelta.x) / s, shell::kTrayMinW,
+ shell::kTrayMaxW);
+ if (width == 300.0f) width = 300.5f; // a deliberate 300 isn't the "grow on wide screens" default
+ noteLayoutChanged();
+ }
+ if (ImGui::IsItemDeactivated() && io.MouseDragMaxDistanceSqr[0] < 9.0f * s * s) {
+ if (right && shell_.narrow) {
+ status_ = "The window is too narrow for the tray - palettes open as drop-downs";
+ } else {
+ (right ? layout_.rightTrayOpen : layout_.leftTrayOpen) = !open;
+ noteLayoutChanged();
+ }
+ }
+ ui::HelpText(right ? "Right tray" : "Left tray", nullptr,
+ "Click to open or close the tray, drag to resize it. Palettes go in trays from their header icon.",
+ "Shell");
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ const float cx = std::floor(r.x + r.w * 0.5f), cy = r.y + r.h * 0.5f;
+ const ImU32 grip = theme::u32(hovered || active ? theme::accent : theme::textDim, hovered || active ? 1.0f : 0.5f);
+ dl->AddRectFilled(ImVec2(cx - 1.0f * s, cy - 16.0f * s), ImVec2(cx + 1.0f * s, cy + 16.0f * s), grip, 1.0f * s);
+ ImGui::End();
+}
+
+// ---------------------------------------------------------------------------
+// Shelves
+// ---------------------------------------------------------------------------
+
+void App::drawShelf(int shelf, const CanvasRect& r) {
+ const float s = uiScale_;
+ const bool vertical = shelf == kShelfLeft || shelf == kShelfRight;
+ const ImVec2 pad = shelf == kShelfTop ? ImVec2(6.0f * s, 4.0f * s)
+ : shelf == kShelfBottom ? ImVec2(6.0f * s, 3.0f * s)
+ : shelf == kShelfLeft ? ImVec2(6.0f * s, 6.0f * s)
+ : ImVec2(4.0f * s, 6.0f * s);
+ if (!beginShellWindow(kShelfWindows[shelf], r, theme::shellBg, pad)) {
+ ImGui::End();
+ return;
+ }
+ std::vector<std::string>& items = shelf == kShelfTop ? layout_.topShelf
+ : shelf == kShelfLeft ? layout_.leftShelf
+ : shelf == kShelfRight ? layout_.rightShelf
+ : layout_.bottomShelf;
+ const std::vector<std::string> list = items; // items may be removed from their own context menu
+ std::vector<ImRect> rects;
+ std::vector<int> indices;
+ if (shelf == kShelfBottom) {
+ const int tiles = int(std::count_if(list.begin(), list.end(), [](const std::string& id) { return id != "sep" && id != "row"; }));
+ const float avail = r.w - 2.0f * pad.x - 48.0f * s; // the [+] tile is narrower
+ bottomTileW_ = std::clamp(avail / float(std::max(tiles - 1, 1)) - 4.0f * s, 44.0f * s, 58.0f * s);
+ }
+ ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4.0f * s, 4.0f * s));
+ bool lineStart = true;
+ for (int i = 0; i < int(list.size()); ++i) {
+ const std::string& item = list[size_t(i)];
+ if (item == "row") {
+ lineStart = true;
+ continue;
+ }
+ if (item == "view.splats" && doc_.splats.empty()) continue; // only when there's a capture
+ if (!vertical && !lineStart) {
+ const std::string& prev = list[size_t(i - 1)];
+ ImGui::SameLine(0.0f, prev == "sep" || item == "sep" ? 0.0f : segmentPair(prev, item) ? 1.0f * s : 4.0f * s);
+ }
+ if (!vertical && item == "widget.points") { // right-aligned readout
+ const float w = 170.0f * s;
+ ImGui::SameLine(std::max(ImGui::GetCursorPosX(), ImGui::GetWindowContentRegionMax().x - w));
+ }
+ lineStart = false;
+ drawShelfItem(shelf, i, item, vertical);
+ rects.push_back(ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()));
+ indices.push_back(i);
+ }
+ ImGui::PopStyleVar();
+
+ ImGuiWindow* window = ImGui::GetCurrentWindow();
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ // Bottom shelf: the wheel scrolls it sideways when it doesn't fit.
+ if (shelf == kShelfBottom && ImGui::IsWindowHovered() && ImGui::GetIO().MouseWheel != 0.0f)
+ ImGui::SetScrollX(ImGui::GetScrollX() - ImGui::GetIO().MouseWheel * 60.0f * s);
+ if (layout_.customize)
+ dashedRect(dl, ImVec2(r.x + 2.0f, r.y + 2.0f), ImVec2(r.x + r.w - 2.0f, r.y + r.h - 2.0f), theme::u32(theme::accent, 0.6f),
+ 4.0f * s);
+ // Customize: drop items between the shelf's items (an accent line shows where).
+ const ImGuiPayload* payload = ImGui::GetDragDropPayload();
- if (payload && payload->IsDataType("SF_UIITEM") && window->Rect().Contains(ImGui::GetIO().MousePos)) {
++ if (payload && payload->IsDataType(ui::kUiItemPayload) && window->Rect().Contains(ImGui::GetIO().MousePos)) {
+ const ImVec2 m = ImGui::GetIO().MousePos;
+ int insert = int(list.size());
+ ImVec2 a, b;
+ for (size_t k = 0; k < rects.size(); ++k) {
+ const ImRect& rc = rects[k];
+ const bool before = vertical ? m.y < rc.GetCenter().y : (m.y < rc.Max.y + 2.0f * s && m.x < rc.GetCenter().x);
+ if (before) {
+ insert = indices[k];
+ a = vertical ? ImVec2(rc.Min.x, rc.Min.y - 2.0f * s) : ImVec2(rc.Min.x - 2.0f * s, rc.Min.y);
+ b = vertical ? ImVec2(rc.Max.x, rc.Min.y - 2.0f * s) : ImVec2(rc.Min.x - 2.0f * s, rc.Max.y);
+ break;
+ }
+ }
+ if (insert == int(list.size()) && !rects.empty()) {
+ const ImRect& rc = rects.back();
+ a = vertical ? ImVec2(rc.Min.x, rc.Max.y + 2.0f * s) : ImVec2(rc.Max.x + 2.0f * s, rc.Min.y);
+ b = vertical ? ImVec2(rc.Max.x, rc.Max.y + 2.0f * s) : ImVec2(rc.Max.x + 2.0f * s, rc.Max.y);
+ }
+ if (ImGui::BeginDragDropTargetCustom(window->Rect(), ImGui::GetID("##shelfdrop"))) {
+ ImGui::GetForegroundDrawList()->AddLine(a, b, theme::u32(theme::accent), 2.0f * s);
- if (const ImGuiPayload* p = ImGui::AcceptDragDropPayload("SF_UIITEM", ImGuiDragDropFlags_AcceptNoDrawDefaultRect)) {
- UiItemPayload item;
++ if (const ImGuiPayload* p = ImGui::AcceptDragDropPayload(ui::kUiItemPayload, ImGuiDragDropFlags_AcceptNoDrawDefaultRect)) {
++ ui::UiItemPayload item;
+ std::memcpy(&item, p->Data, std::min(size_t(p->DataSize), sizeof item));
- item.item[sizeof item.item - 1] = 0;
++ item.id[sizeof item.id - 1] = 0;
+ std::vector<std::string>* from = item.fromShelf == kShelfTop ? &layout_.topShelf
+ : item.fromShelf == kShelfLeft ? &layout_.leftShelf
+ : item.fromShelf == kShelfRight ? &layout_.rightShelf
+ : item.fromShelf == kShelfBottom ? &layout_.bottomShelf
+ : nullptr;
- if (from && item.fromIndex >= 0 && item.fromIndex < int(from->size()) && (*from)[size_t(item.fromIndex)] == item.item) {
++ if (from && item.fromIndex >= 0 && item.fromIndex < int(from->size()) && (*from)[size_t(item.fromIndex)] == item.id) {
+ from->erase(from->begin() + item.fromIndex);
+ if (from == &items && item.fromIndex < insert) --insert;
+ }
- items.insert(items.begin() + std::clamp(insert, 0, int(items.size())), std::string(item.item));
++ items.insert(items.begin() + std::clamp(insert, 0, int(items.size())), std::string(item.id));
+ shelfDrag_.accepted = true;
+ noteLayoutChanged();
+ }
+ ImGui::EndDragDropTarget();
+ }
+ }
+ ImGui::End();
+}
+
+void App::drawShelfItem(int shelf, int index, const std::string& item, bool vertical) {
+ const float s = uiScale_;
+ const float winW = ImGui::GetWindowWidth();
+ const float padX = ImGui::GetStyle().WindowPadding.x;
+ ImGui::PushID(index);
+ auto centre = [&](float w) {
+ if (vertical) ImGui::SetCursorPosX(std::max(padX, (winW - w) * 0.5f));
+ };
+ const float rowH = 26.0f * s;
+ if (item == "sep") {
+ if (vertical) {
+ ImGui::Dummy(ImVec2(winW - 2.0f * padX, 4.0f * s));
+ const ImVec2 a = ImGui::GetItemRectMin(), b = ImGui::GetItemRectMax();
+ ImGui::GetWindowDrawList()->AddLine(ImVec2(a.x + 6.0f * s, (a.y + b.y) * 0.5f), ImVec2(b.x - 6.0f * s, (a.y + b.y) * 0.5f),
+ theme::u32(theme::header));
+ } else {
+ ImGui::Dummy(ImVec2(13.0f * s, rowH));
+ const ImVec2 a = ImGui::GetItemRectMin(), b = ImGui::GetItemRectMax();
+ const float x = std::floor((a.x + b.x) * 0.5f);
+ ImGui::GetWindowDrawList()->AddLine(ImVec2(x, a.y + 4.0f * s), ImVec2(x, b.y - 4.0f * s), theme::u32(theme::header));
+ }
+ } else if (item == "widget.draw_size" || item == "widget.strength") {
+ ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(8.0f * s, (rowH - ImGui::GetFontSize()) * 0.5f));
+ ImGui::SetNextItemWidth(180.0f * s);
+ if (item == "widget.draw_size") {
+ ui::SliderInside("##drawsize", &radiusPx_, 2.0f, 800.0f, "Draw Size %.0f", ImGuiSliderFlags_Logarithmic);
+ ui::HelpText("Draw Size", "S", "Brush radius in screen pixels. [ and ] change it by 10%; Ctrl+click to type.", "Draw");
+ } else {
+ ui::SliderInside("##strength", &strength_, 0.01f, 1.0f, "Strength %.2f");
+ ui::HelpText("Strength", "I", "How strongly each dab changes the surface (ZBrush Z Intensity); Ctrl+click to type.",
+ "Draw");
+ }
+ ImGui::PopStyleVar();
+ } else if (item == "widget.points") {
+ size_t total = 0;
+ uint64_t key = doc_.undo.revision() * 0x9E3779B97F4A7C15ull ^ uint64_t(doc_.activeSubtool) ^
+ (uint64_t(reinterpret_cast<uintptr_t>(doc_.mesh.hidden.data())) << 1);
+ for (int i = 0; i < doc_.subtoolCount(); ++i) {
+ total += doc_.subtoolMesh(i).triangleCount();
+ key = key * 31 + doc_.subtoolMesh(i).triangleCount() * 2 + (doc_.subtools[size_t(i)].visible ? 1 : 0);
+ }
+ if (key != activeTrisKey_) { // hidden triangles only change through commands and undo
+ activeTrisKey_ = key;
+ activeTris_ = 0;
+ for (int i = 0; i < doc_.subtoolCount(); ++i) {
+ if (!doc_.subtools[size_t(i)].visible) continue;
+ const Mesh& m = doc_.subtoolMesh(i);
+ const size_t hidden = size_t(std::count_if(m.hidden.begin(), m.hidden.end(), [](uint8_t h) { return h != 0; }));
+ activeTris_ += m.triangleCount() - std::min(hidden, m.triangleCount());
+ }
+ }
+ const size_t active = activeTris_;
+ ImGui::BeginGroup();
+ if (fontSmall_) ImGui::PushFont(fontSmall_);
+ const float lineH = ImGui::GetTextLineHeight();
+ const ImVec2 p = ImGui::GetCursorScreenPos();
+ ImGui::Dummy(ImVec2(170.0f * s, rowH));
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ const float y0 = p.y + (rowH - 2.0f * lineH) * 0.5f;
+ dl->AddText(ImVec2(p.x, y0), theme::u32(theme::textDim), "ActiveTris");
+ dl->AddText(ImVec2(p.x, y0 + lineH), theme::u32(theme::textDim), "TotalTris");
+ const std::string a = shortCount(active), t = shortCount(total);
+ dl->AddText(ImVec2(p.x + 70.0f * s, y0), theme::u32(theme::text), a.c_str());
+ dl->AddText(ImVec2(p.x + 70.0f * s, y0 + lineH), theme::u32(theme::text), t.c_str());
+ ImGui::LogText("ActiveTris %s TotalTris %s", a.c_str(), t.c_str());
+ if (fontSmall_) ImGui::PopFont();
+ ImGui::EndGroup();
+ ui::HelpText("ActiveTris / TotalTris", nullptr,
+ "Triangles you can see and sculpt (visible SubTools, hidden parts left out) and in the whole scene.",
+ "Draw");
+ } else if (item.rfind("widget.tile.", 0) == 0) {
+ const float w = (shell_.narrow ? 60.0f : 76.0f) * s;
+ const ImVec2 size(w, w + (fontSmall_ ? fontSmall_->FontSize : 12.0f) + 4.0f * s);
+ centre(w);
+ if (item == "widget.tile.brush") drawBrushTile("##tile.brush", size);
+ else if (item == "widget.tile.stroke") drawStrokeTile("##tile.stroke", size);
+ else if (item == "widget.tile.alpha") drawAlphaTile("##tile.alpha", size);
+ else if (item == "widget.tile.material") drawMaterialTile("##tile.material", size);
+ else ImGui::Dummy(size);
+ } else if (item == "widget.color") {
+ const float w = (shell_.narrow ? 60.0f : 76.0f) * s;
+ centre(w);
+ drawColorWidget(w);
+ } else if (item == "widget.nav.move" || item == "widget.nav.zoom" || item == "widget.nav.rotate") {
+ centre(44.0f * s);
+ const int mode = item == "widget.nav.move" ? 0 : item == "widget.nav.zoom" ? 1 : 2;
+ canvasNavButton(mode == 0 ? "nav.move" : mode == 1 ? "nav.zoom" : "nav.rotate",
+ mode == 0 ? ICON_LC_HAND : mode == 1 ? ICON_LC_ZOOM_IN : ICON_LC_ROTATE_3D,
+ mode == 0 ? "Move" : mode == 1 ? "Zoom" : "Rotate", mode);
+ } else if (item == "widget.add_brush") {
+ const ImVec2 size(48.0f * s, 54.0f * s);
+ if (ImGui::InvisibleButton("##addbrush", size)) ImGui::OpenPopup("##addtoshelf");
+ const bool hovered = ImGui::IsItemHovered();
+ const ImVec2 a = ImGui::GetItemRectMin(), b = ImGui::GetItemRectMax();
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ const float r = 15.0f * s;
+ const ImVec2 c((a.x + b.x) * 0.5f, a.y + 4.0f * s + r);
+ dl->AddCircle(c, r, theme::u32(hovered ? theme::accent : theme::textDim, hovered ? 1.0f : 0.6f), 32, 1.5f * s);
+ centredText(dl, fontIcons_, ImVec2(c.x - r, c.y - r), ImVec2(c.x + r, c.y + r),
+ theme::u32(hovered ? theme::accent : theme::textDim), ICON_LC_PLUS);
+ ui::HelpText("Add a brush", nullptr, "Put another brush (built-in or one of yours) on this shelf.", "Bottom shelf");
+ drawAddToShelfPopup();
+ } else if (item.rfind("recipe:", 0) == 0) {
+ const std::string name = item.substr(7);
+ int found = -1;
+ for (int i = 0; i < int(doc_.brushes.size()); ++i)
+ if (doc_.brushes[size_t(i)].name == name) found = i;
+ const ImVec2 size(bottomTileW_, 54.0f * s);
+ const bool clicked = ImGui::InvisibleButton((name + "##" + item).c_str(), size);
+ const ImVec2 a = ImGui::GetItemRectMin(), b = ImGui::GetItemRectMax();
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ const bool on = found >= 0 && doc_.activeBrush == found && !paintMode_;
+ if (ImGui::IsItemHovered()) dl->AddRectFilled(a, b, theme::u32(theme::buttonHover, 0.55f), 4.0f * s);
+ const float capH = (fontSmall_ ? fontSmall_->FontSize : 12.0f) + 2.0f * s;
+ const float pic = size.y - capH;
+ ImTextureID tex = found >= 0 ? thumbs_.recipe(doc_.brushes[size_t(found)]) : ImTextureID(0);
+ const ImVec2 c((a.x + b.x) * 0.5f, a.y + pic * 0.5f);
+ if (tex) dl->AddImageRounded(tex, ImVec2(c.x - pic * 0.5f, a.y), ImVec2(c.x + pic * 0.5f, a.y + pic), ImVec2(0, 0), ImVec2(1, 1),
+ IM_COL32_WHITE, 4.0f * s);
+ else drawBrushIcon(dl, c, pic * 0.36f, int(BrushType::Standard));
+ dl->AddText(fontSmall_, fontSmall_ ? fontSmall_->FontSize : 12.0f, ImVec2(a.x + 2.0f * s, a.y), theme::u32(theme::accent),
+ ICON_LC_SPARKLE);
+ if (on) dl->AddRect(a, b, theme::u32(theme::accent), 4.0f * s, 0, 2.0f * s);
+ centredText(dl, fontSmall_, ImVec2(a.x, b.y - capH), b, theme::u32(found < 0 ? theme::textDim : on ? theme::accent : theme::text),
+ elide(fontSmall_ ? fontSmall_ : ImGui::GetFont(), name, size.x).c_str());
+ if (clicked && found >= 0) {
+ doc_.activeBrush = found;
+ paintMode_ = false;
+ }
+ ui::HelpText(name.c_str(), nullptr,
+ found >= 0 && !doc_.brushes[size_t(found)].description.empty() ? doc_.brushes[size_t(found)].description.c_str()
+ : "One of your custom brushes.",
+ "Bottom shelf");
+ } else if (const Action* a = actions_.find(item)) {
- const ui::Look look = shelf == kShelfTop ? ui::Look::Label : shelf == kShelfRight ? ui::Look::IconLabel : ui::Look::Tile;
++ const ui::Look look = shelf != kShelfTop ? ui::Look::Tile : a->icon ? ui::Look::IconLabel : ui::Look::Label;
+ const ImVec2 size = shelf == kShelfTop ? ImVec2(0.0f, rowH)
+ : shelf == kShelfRight ? ImVec2(44.0f * s, 40.0f * s)
+ : shelf == kShelfBottom ? ImVec2(bottomTileW_, 54.0f * s)
+ : ImVec2(winW - 2.0f * padX, 60.0f * s);
+ centre(size.x);
+ if (shelf == kShelfTop) ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10.0f * s, (rowH - ImGui::GetFontSize()) * 0.5f));
++ ui::SetNextItemOrigin(shelf, index); // ActionButton is the Ctrl+Alt drag source, from this shelf slot
+ ui::ActionButton(*this, a->id.c_str(), size, look);
+ if (shelf == kShelfTop) ImGui::PopStyleVar();
- ui::HelpAction(*this, a->id.c_str());
+ } else {
+ ImGui::Dummy(ImVec2(0, 0)); // an id this version doesn't know: keep its place in the list
+ }
+ if (item != "sep" && ImGui::BeginPopupContextItem("##shelfitem")) {
+ if (ImGui::MenuItem("Remove from shelf")) {
+ auto& list = shelf == kShelfTop ? layout_.topShelf
+ : shelf == kShelfLeft ? layout_.leftShelf
+ : shelf == kShelfRight ? layout_.rightShelf
+ : layout_.bottomShelf;
+ if (index < int(list.size()) && list[size_t(index)] == item) list.erase(list.begin() + index);
+ noteLayoutChanged();
+ }
+ ImGui::EndPopup();
+ }
- // Customize mode: Ctrl+Alt+drag moves the item to another place, or off the shelf to remove it.
- const SDL_Keymod mods = SDL_GetModState();
- if (layout_.customize && (mods & (SDL_KMOD_CTRL | SDL_KMOD_GUI)) && (mods & SDL_KMOD_ALT) && item != "sep" &&
- ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) {
- UiItemPayload payload;
- std::snprintf(payload.item, sizeof payload.item, "%s", item.c_str());
- payload.fromShelf = shelf;
- payload.fromIndex = index;
- ImGui::SetDragDropPayload("SF_UIITEM", &payload, sizeof payload);
- const Action* a = actions_.find(item);
- ImGui::TextUnformatted(a ? a->label.c_str() : item.c_str());
- ImGui::EndDragDropSource();
++ // Customize mode: widgets (sliders, tiles, readouts) are Ctrl+Alt drag sources too.
++ if (item != "sep" && !actions_.find(item)) {
++ ui::SetNextItemOrigin(shelf, index);
++ ui::UiItemDragSource(*this, item.c_str(), item.c_str());
+ }
+ ImGui::PopID();
+}
+
+void App::finishShelfDrag() {
+ const ImGuiPayload* payload = ImGui::GetDragDropPayload();
- if (payload && payload->IsDataType("SF_UIITEM")) {
- UiItemPayload item;
++ if (payload && payload->IsDataType(ui::kUiItemPayload)) {
++ ui::UiItemPayload item;
+ std::memcpy(&item, payload->Data, std::min(size_t(payload->DataSize), sizeof item));
+ shelfDrag_.active = true;
+ shelfDrag_.shelf = item.fromShelf;
+ shelfDrag_.index = item.fromIndex;
+ return;
+ }
+ if (!shelfDrag_.active) return;
+ // The drag ended: dropped outside every shelf, an item that came from a shelf is removed (ZBrush).
+ if (!shelfDrag_.accepted && shelfDrag_.shelf >= 0 && shelfDrag_.shelf < kShelfCount) {
+ auto& list = shelfDrag_.shelf == kShelfTop ? layout_.topShelf
+ : shelfDrag_.shelf == kShelfLeft ? layout_.leftShelf
+ : shelfDrag_.shelf == kShelfRight ? layout_.rightShelf
+ : layout_.bottomShelf;
+ if (shelfDrag_.index >= 0 && shelfDrag_.index < int(list.size())) {
+ status_ = "Removed " + list[size_t(shelfDrag_.index)] + " from the shelf";
+ list.erase(list.begin() + shelfDrag_.index);
+ noteLayoutChanged();
+ }
+ }
+ shelfDrag_ = {};
+}
+
+void App::drawAddToShelfPopup() {
+ if (!ImGui::BeginPopup("##addtoshelf")) return;
+ ImGui::TextDisabled("Add to the bottom shelf");
+ ImGui::Separator();
+ auto onShelf = [this](const std::string& id) {
+ return std::find(layout_.bottomShelf.begin(), layout_.bottomShelf.end(), id) != layout_.bottomShelf.end();
+ };
+ auto add = [this](const std::string& id) {
+ auto plus = std::find(layout_.bottomShelf.begin(), layout_.bottomShelf.end(), "widget.add_brush");
+ layout_.bottomShelf.insert(plus, id);
+ noteLayoutChanged();
+ };
+ bool any = false;
+ for (int i = 0; i < int(BrushType::Count); ++i) {
+ const std::string id = brushActionId(BrushType(i));
+ if (onShelf(id)) continue;
+ any = true;
+ if (ImGui::MenuItem(brushName(BrushType(i)))) add(id);
+ }
+ if (!onShelf("draw.paint") && ImGui::MenuItem("Paint")) add("draw.paint");
+ if (!doc_.brushes.empty()) {
+ ImGui::SeparatorText("Custom");
+ for (const auto& b : doc_.brushes) {
+ const std::string id = "recipe:" + b.name;
+ if (onShelf(id)) continue;
+ any = true;
+ if (ImGui::MenuItem((b.name + "##add").c_str())) add(id);
+ }
+ }
+ if (!any) ImGui::TextDisabled("Every brush is on the shelf");
+ ImGui::EndPopup();
+}
+
+// Right-shelf Move / Zoom / Rotate: drag on the button to navigate, as in ZBrush.
+bool App::canvasNavButton(const char* id, const char* icon, const char* label, int mode) {
+ const float s = uiScale_;
+ const ImVec2 size(44.0f * s, 40.0f * s);
+ ImGui::InvisibleButton((std::string(label) + "##" + id).c_str(), size);
+ const bool hovered = ImGui::IsItemHovered(), active = ImGui::IsItemActive();
+ if (active) {
+ const ImVec2 d = ImGui::GetIO().MouseDelta;
+ const CanvasRect c = shell_.canvas;
+ if (d.x != 0.0f || d.y != 0.0f) {
+ if (mode == 0) camera_.pan(d.x, d.y, c.h);
+ else if (mode == 1) camera_.zoom(-d.y * 0.05f);
+ else camera_.orbit(d.x, d.y);
+ }
+ ImGui::SetMouseCursor(mode == 0 ? ImGuiMouseCursor_ResizeAll : mode == 1 ? ImGuiMouseCursor_ResizeNS : ImGuiMouseCursor_Hand);
+ navDrag_ = mode;
+ } else if (navDrag_ == mode) {
+ navDrag_ = -1;
+ }
+ const ImVec2 a = ImGui::GetItemRectMin(), b = ImGui::GetItemRectMax();
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ dl->AddRectFilled(a, b, theme::u32(active ? theme::accent : hovered ? theme::buttonHover : theme::frame), 4.0f * s);
+ const float capH = (fontTiny_ ? fontTiny_->FontSize : 10.0f) + 2.0f * s;
+ const ImU32 fg = theme::u32(active ? theme::textOnAccent : theme::text);
+ centredText(dl, fontIcons_, a, ImVec2(b.x, b.y - capH + 2.0f * s), fg, icon);
+ centredText(dl, fontTiny_, ImVec2(a.x, b.y - capH), ImVec2(b.x, b.y - 1.0f * s), fg, label);
+ ui::HelpAction(*this, id);
+ return active;
+}
+
+// ---------------------------------------------------------------------------
+// Left shelf tiles
+// ---------------------------------------------------------------------------
+
+namespace {
+
+// Tile frame: the picture square and the caption under it. Returns true when clicked.
+bool tileFrame(const char* id, ImVec2 size, ImFont* font, const std::string& caption, float s, ImVec2& pic0, ImVec2& pic1) {
+ const bool clicked = ImGui::InvisibleButton(id, size);
+ const bool hovered = ImGui::IsItemHovered();
+ const ImVec2 a = ImGui::GetItemRectMin(), b = ImGui::GetItemRectMax();
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ const float capH = (font ? font->FontSize : 12.0f) + 4.0f * s;
+ pic0 = a;
+ pic1 = ImVec2(b.x, b.y - capH);
+ dl->AddRectFilled(pic0, pic1, theme::u32(theme::tile), 4.0f * s);
+ if (hovered) dl->AddRect(pic0, pic1, theme::u32(theme::accent, 0.8f), 4.0f * s, 0, 1.5f * s);
+ centredText(dl, font, ImVec2(a.x, b.y - capH), b, theme::u32(hovered ? theme::text : theme::textDim),
+ elide(font ? font : ImGui::GetFont(), caption, size.x).c_str());
+ ImGui::LogText("%s", caption.c_str());
+ return clicked;
+}
+
+} // namespace
+
+void App::drawBrushTile(const char* id, ImVec2 size) {
+ const float s = uiScale_;
+ const BrushRecipe* recipe = activeRecipe();
+ const std::string name = paintMode_ ? "Paint" : recipe ? recipe->name : brushName(brush_);
+ ImVec2 a, b;
+ const bool clicked = tileFrame(id, size, fontSmall_, name, s, a, b);
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ ImTextureID tex = paintMode_ ? ImTextureID(0) : recipe ? thumbs_.recipe(*recipe) : thumbs_.brush(int(brush_));
+ const ImVec2 c((a.x + b.x) * 0.5f, (a.y + b.y) * 0.5f);
+ const float r = (b.x - a.x) * 0.36f;
+ if (tex) {
+ dl->AddImageRounded(tex, ImVec2(a.x + 2 * s, a.y + 2 * s), ImVec2(b.x - 2 * s, b.y - 2 * s), ImVec2(0, 0), ImVec2(1, 1),
+ IM_COL32_WHITE, 4.0f * s);
+ } else if (paintMode_) {
+ const glm::vec3 pc = linearToSrgb(doc_.paintColor);
+ dl->AddCircleFilled(c, r, theme::u32(ImVec4(pc.x, pc.y, pc.z, 1.0f)), 32);
+ centredText(dl, fontIcons_, a, b, IM_COL32(255, 255, 255, 220), ICON_LC_PAINTBRUSH);
+ } else {
+ drawBrushIcon(dl, c, r, recipe ? int(BrushType::Standard) : int(brush_));
+ if (recipe) dl->AddText(fontSmall_, fontSmall_ ? fontSmall_->FontSize : 12.0f, ImVec2(a.x + 4 * s, a.y + 3 * s),
+ theme::u32(theme::accent), ICON_LC_SPARKLE);
+ }
+ if (clicked) openPicker(Picker::Brush, ImVec2(ImGui::GetItemRectMax().x + 4.0f * s, ImGui::GetItemRectMin().y));
+ ui::HelpText("Brush", "B", "The active brush. Click for the brush picker; the bottom shelf holds favourites.", "Left shelf");
+}
+
+void App::drawStrokeTile(const char* id, ImVec2 size) {
+ const float s = uiScale_;
+ ImVec2 a, b;
+ const bool clicked = tileFrame(id, size, fontSmall_, strokeTypeName(strokeType_), s, a, b);
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ const ImU32 col = IM_COL32(235, 235, 235, 230);
+ const float w = b.x - a.x, h = b.y - a.y;
+ auto at = [&](float u, float v) { return ImVec2(a.x + w * u, a.y + h * v); };
+ switch (strokeType_) {
+ case StrokeType::Dots: // ZBrush's dotted arc
+ for (int i = 0; i < 7; ++i) {
+ const float u = float(i) / 6.0f;
+ dl->AddCircleFilled(at(0.18f + 0.64f * u, 0.30f + 0.42f * std::sin(u * 2.4f) * (1.0f - u * 0.35f)), 3.2f * s, col);
+ }
+ break;
+ case StrokeType::DragRect:
+ dl->AddRect(at(0.22f, 0.26f), at(0.78f, 0.74f), col, 2.0f * s, 0, 1.5f * s);
+ dl->AddLine(at(0.3f, 0.66f), at(0.7f, 0.34f), col, 1.5f * s);
+ dl->AddTriangleFilled(at(0.7f, 0.34f), at(0.6f, 0.36f), at(0.67f, 0.44f), col);
+ break;
+ case StrokeType::Spray: {
+ uint32_t seed = 7;
+ for (int i = 0; i < 26; ++i) {
+ seed = seed * 1664525u + 1013904223u;
+ const float u = float((seed >> 8) & 0xffff) / 65535.0f;
+ seed = seed * 1664525u + 1013904223u;
+ const float v = float((seed >> 8) & 0xffff) / 65535.0f;
+ seed = seed * 1664525u + 1013904223u;
+ const float r = (1.0f + 2.5f * float((seed >> 8) & 0xff) / 255.0f) * s;
+ dl->AddCircleFilled(at(0.2f + 0.6f * u, 0.22f + 0.56f * v), r, col);
+ }
+ break;
+ }
+ case StrokeType::LazyMouse: {
+ ImVec2 pts[16];
+ for (int i = 0; i < 16; ++i) {
+ const float u = float(i) / 15.0f;
+ pts[i] = at(0.16f + 0.62f * u, 0.62f - 0.3f * std::sin(u * 3.0f));
+ }
+ dl->AddPolyline(pts, 16, col, 0, 2.0f * s);
+ dl->AddLine(pts[15], at(0.86f, 0.24f), IM_COL32(240, 136, 46, 220), 1.0f * s);
+ dl->AddCircleFilled(at(0.86f, 0.24f), 3.0f * s, IM_COL32(240, 136, 46, 255));
+ break;
+ }
+ default: break;
+ }
+ if (clicked) openPicker(Picker::Stroke, ImVec2(ImGui::GetItemRectMax().x + 4.0f * s, ImGui::GetItemRectMin().y));
+ ui::HelpText("Stroke", nullptr, "How dabs follow the cursor: Dots, DragRect, Spray or LazyMouse. Click to choose.",
+ "Left shelf");
+}
+
+void App::drawAlphaTile(const char* id, ImVec2 size) {
+ const float s = uiScale_;
+ ImVec2 a, b;
+ const bool clicked = tileFrame(id, size, fontSmall_, doc_.brushAlpha.name, s, a, b);
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ ImTextureID tex = thumbs_.alpha(doc_.brushAlpha);
+ if (tex) {
+ dl->AddImageRounded(tex, ImVec2(a.x + 2 * s, a.y + 2 * s), ImVec2(b.x - 2 * s, b.y - 2 * s), ImVec2(0, 0), ImVec2(1, 1),
+ IM_COL32_WHITE, 4.0f * s);
+ } else {
+ constexpr int kCells = 26;
+ const float inset = 6.0f * s, cell = (b.x - a.x - 2.0f * inset) / kCells;
+ dl->AddRectFilled(ImVec2(a.x + inset, a.y + inset), ImVec2(b.x - inset, b.y - inset), IM_COL32(0, 0, 0, 255), 3.0f * s);
+ for (int y = 0; y < kCells; ++y)
+ for (int x = 0; x < kCells; ++x) {
+ const float u = (float(x) + 0.5f) / kCells * 2.0f - 1.0f, v = 1.0f - (float(y) + 0.5f) / kCells * 2.0f;
+ const int g = int(std::clamp(doc_.brushAlpha.sample(u, v), 0.0f, 1.0f) * 255.0f);
+ if (g < 4) continue;
+ const ImVec2 p(a.x + inset + float(x) * cell, a.y + inset + float(y) * cell);
+ dl->AddRectFilled(p, ImVec2(p.x + cell + 0.5f, p.y + cell + 0.5f), IM_COL32(g, g, g, 255));
+ }
+ }
+ if (clicked) openPicker(Picker::Alpha, ImVec2(ImGui::GetItemRectMax().x + 4.0f * s, ImGui::GetItemRectMin().y));
+ ui::HelpText("Alpha", nullptr, "The brush's stamp shape (white = full effect). Click for the alpha picker.", "Left shelf");
+}
+
+void App::drawMaterialTile(const char* id, ImVec2 size) {
+ const float s = uiScale_;
+ const int m = renderSettings_.matcap;
+ ImVec2 a, b;
+ const bool clicked = tileFrame(id, size, fontSmall_, m < 0 ? std::string("Studio") : std::string(matcapName(m)), s, a, b);
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ const ImVec2 c((a.x + b.x) * 0.5f, (a.y + b.y) * 0.5f);
+ const float r = (b.x - a.x) * 0.4f;
+ ImTextureID tex = thumbs_.material(m);
+ if (!tex && m >= 0)
+ if (const GLuint t = renderer_.matcapTexture(m)) tex = ImTextureID(uintptr_t(t));
+ if (tex) {
+ // Matcaps are spheres already; textures are stored bottom-up.
+ dl->AddImageRounded(tex, ImVec2(c.x - r, c.y - r), ImVec2(c.x + r, c.y + r), ImVec2(0, m >= 0 ? 1.0f : 0.0f),
+ ImVec2(1, m >= 0 ? 0.0f : 1.0f), IM_COL32_WHITE, r);
+ } else {
+ const glm::vec3 base = linearToSrgb(renderSettings_.baseColor);
+ constexpr int kLayers = 16;
+ for (int k = 0; k < kLayers; ++k) {
+ const float t = float(k) / float(kLayers - 1);
+ const float shade = 0.3f + 0.85f * std::pow(t, 0.7f);
+ dl->AddCircleFilled(ImVec2(c.x - r * 0.3f * t, c.y - r * 0.32f * t), r * (1.0f - t * 0.85f),
+ theme::u32(ImVec4(std::min(1.0f, base.x * shade), std::min(1.0f, base.y * shade),
+ std::min(1.0f, base.z * shade), 1.0f)),
+ 32);
+ }
+ }
+ if (clicked) openPicker(Picker::Material, ImVec2(ImGui::GetItemRectMax().x + 4.0f * s, ImGui::GetItemRectMin().y));
+ ui::HelpText("Material", "M", "How the model is shaded in the view. Click for the material picker.", "Left shelf");
+}
+
+void App::drawColorWidget(float width) {
+ const float s = uiScale_;
+ ImGui::BeginGroup();
+ glm::vec3 srgb = linearToSrgb(doc_.paintColor);
+ ImGui::SetNextItemWidth(width);
+ if (ImGui::ColorPicker3("##shelfcolor", glm::value_ptr(srgb),
+ ImGuiColorEditFlags_NoSidePreview | ImGuiColorEditFlags_NoInputs | ImGuiColorEditFlags_NoLabel |
+ ImGuiColorEditFlags_NoAlpha | ImGuiColorEditFlags_PickerHueBar))
+ doc_.paintColor = srgbToLinear(srgb);
+ ui::HelpText("Colour", "C", "The polypaint colour (C over the model picks one).", "Left shelf");
+ // Two swatches, like ZBrush's main and secondary colour: clicking swaps them ("Alternate").
+ const float sw = (width - ImGui::GetStyle().ItemSpacing.x) * 0.5f;
+ const glm::vec3 second = linearToSrgb(secondaryColor_);
+ bool swap = ImGui::ColorButton("##primary", ImVec4(srgb.x, srgb.y, srgb.z, 1.0f), ImGuiColorEditFlags_NoTooltip, ImVec2(sw, 22.0f * s));
+ ui::HelpText("Main colour", nullptr, "Click to swap with the second colour.", "Left shelf");
+ ImGui::SameLine();
+ swap |= ImGui::ColorButton("##secondary", ImVec4(second.x, second.y, second.z, 1.0f), ImGuiColorEditFlags_NoTooltip,
+ ImVec2(sw, 22.0f * s));
+ ui::HelpText("Second colour", nullptr, "Click to swap it with the main colour (ZBrush Alternate).", "Left shelf");
+ if (swap) std::swap(doc_.paintColor, secondaryColor_);
- ui::ActionButton(*this, "color.fill", ImVec2(width, 0));
++ ui::ActionButton(*this, "color.fill", ImVec2(width, 0), ui::Look::IconLabel);
+ ui::HelpAction(*this, "color.fill");
+ ImGui::EndGroup();
+}
+
+} // namespace sf
diff --cc src/app/Shell.h
index 54e95d20,00000000..08b9151b
mode 100644,000000..100644
--- a/src/app/Shell.h
+++ b/src/app/Shell.h
@@@ -1,46 -1,0 +1,38 @@@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// Pieces of the ZBrush-style shell shared between Shell.cpp, Palettes.cpp and
+// the ui:: widgets: the palette table, shelf ids and the button looks.
+#pragma once
+
+#include "app/Actions.h"
+
+#include <imgui.h>
+
+#include <string>
+#include <string_view>
+
+namespace sf {
+
+class App;
+
+enum ShelfId { kShelfTop = 0, kShelfLeft, kShelfRight, kShelfBottom, kShelfCount };
+
- // Customize-mode drag and drop: ImGui payload "SF_UIITEM" (an item, from a shelf or anywhere else) and
- // "SF_PALETTE" (a palette, from its header icon; only trays accept it).
- struct UiItemPayload {
- char item[96] = {};
- int fromShelf = -1; // -1: not from a shelf (a palette or picker): dropping it adds a copy
- int fromIndex = -1;
- };
-
+struct PaletteDef {
+ const char* id; // "tool", also the UiLayout tray entry
+ const char* name; // "Tool", shown in the palette bar (sorted by it)
+ const char* icon; // ICON_LC_*
+ const char* scope; // extra name UI tests find its items under ("SubTools/Append"), or nullptr
+ void (App::*draw)();
+};
+const PaletteDef* palettes(int& count); // alphabetical
+const PaletteDef* findPalette(std::string_view id);
+
- // Draws an action as a button in one of the ui::Look styles (0 Label, 1 Icon, 2 IconLabel, 3 Tile).
- // Returns true when clicked. ui::ActionButton calls it.
- bool drawActionLook(App& app, const Action& action, ImVec2 size, int look);
++// ui::ActionButton's Tile look: a brush thumbnail with its name (brush actions), or a large icon over a
++// small caption (right shelf). Returns true when clicked.
++bool drawShelfTile(App& app, const Action& action, ImVec2 size);
+
+// Brush type of a "brush.<name>" action id, or -1.
+int brushTypeOfAction(std::string_view id);
+
+} // namespace sf
diff --cc src/app/Ui.cpp
index 0d77633c,09e560fd..42d94ea2
--- a/src/app/Ui.cpp
+++ b/src/app/Ui.cpp
@@@ -3,54 -3,324 +3,333 @@@
#include "app/Ui.h"
#include "app/App.h"
+#include "app/Shell.h"
- #include "app/Theme.h"
+
+ #include <imgui_internal.h>
#include <algorithm>
+ #include <cfloat>
#include <cmath>
-
#include <cstdio>
+ #include <cstring>
namespace sf::ui {
- // Phase 0 stubs: plain buttons and sliders. The help/console workstream adds Ctrl-hover help and
- // customize-mode dragging; the shell workstream adds icon and tile looks.
+ namespace {
+
+ // The Ctrl-help request for this frame: the last hovered item that asked for help wins.
+ struct HelpRequest {
+ bool active = false;
+ std::string title, shortcut, description, path, command;
+ const char* icon = nullptr;
+ bool disabled = false;
+ std::vector<ParamSpec> params;
+ bool hasCommand = false;
+ };
+
+ HelpRequest g_help;
+ std::string g_shown;
+ bool g_popupInfo = true;
+ int g_nextShelf = ShelfNone, g_nextIndex = -1;
+
+ ImVec4 rgba(ImU32 c, float alpha = -1.0f) {
+ ImVec4 v = ImGui::ColorConvertU32ToFloat4(c);
+ if (alpha >= 0.0f) v.w = alpha;
+ return v;
+ }
+
+ float uiScale() { return ImGui::GetFontSize() / 15.0f; }
+
+ bool itemHoveredForHelp() {
+ return ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled | ImGuiHoveredFlags_AllowWhenBlockedByActiveItem);
+ }
+
+ bool wantHelp() { return g_popupInfo && CtrlHeld(); }
+
+ const char* typeName(ParamSpec::Type t) {
+ switch (t) {
+ case ParamSpec::Type::Bool: return "true/false";
+ case ParamSpec::Type::Number: return "number";
+ case ParamSpec::Type::String: return "text";
+ }
+ return "";
+ }
+
+ void takeOrigin(int& shelf, int& index) {
+ shelf = g_nextShelf;
+ index = g_nextIndex;
+ g_nextShelf = ShelfNone;
+ g_nextIndex = -1;
+ }
+
+ bool dragSource(App& app, const char* itemId, const char* label, int shelf, int index) {
+ if (!app.layout().customize || !CtrlHeld() || !AltHeld()) return false;
+ if (!ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceAllowNullID)) return false;
+ UiItemPayload p;
+ std::snprintf(p.id, sizeof p.id, "%s", itemId);
+ p.fromShelf = shelf;
+ p.fromIndex = index;
+ ImGui::SetDragDropPayload(kUiItemPayload, &p, sizeof p);
+ ImGui::TextUnformatted(label);
+ ImGui::TextColored(rgba(color::textDim), shelf >= 0 ? "Drop on a shelf to move, elsewhere to remove" : "Drop on a shelf to add");
+ ImGui::EndDragDropSource();
+ return true;
+ }
+
+ } // namespace
+
+ bool CtrlHeld() {
+ const ImGuiIO& io = ImGui::GetIO();
+ return io.KeyCtrl || io.KeySuper || (SDL_GetModState() & (SDL_KMOD_CTRL | SDL_KMOD_GUI)) != 0;
+ }
+
+ bool AltHeld() { return ImGui::GetIO().KeyAlt || (SDL_GetModState() & SDL_KMOD_ALT) != 0; }
+
+ void SetNextItemOrigin(int shelf, int index) {
+ g_nextShelf = shelf;
+ g_nextIndex = index;
+ }
+
+ bool UiItemDragSource(App& app, const char* itemId, const char* label) {
+ int shelf, index;
+ takeOrigin(shelf, index);
+ return dragSource(app, itemId, label, shelf, index);
+ }
+
+ void HelpText(const char* title, const char* shortcut, const char* description, const char* path) {
+ if (!wantHelp() || !itemHoveredForHelp()) return;
+ g_help = HelpRequest{};
+ g_help.active = true;
+ g_help.title = title ? title : "";
+ g_help.shortcut = shortcut ? shortcut : "";
+ g_help.description = description ? description : "";
+ g_help.path = path ? path : "";
+ g_help.disabled = (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled) != 0;
+ }
+
+ void HelpAction(App& app, const char* actionId) {
+ if (!wantHelp() || !itemHoveredForHelp()) return;
+ const Action* a = app.actions().find(actionId);
+ if (!a) return;
+ g_help = HelpRequest{};
+ g_help.active = true;
+ g_help.title = a->label;
+ g_help.icon = a->icon;
+ g_help.shortcut = app.actions().shortcutText(a->id);
+ g_help.path = a->palette;
+ g_help.command = a->command;
+ g_help.disabled = a->enabled && !a->enabled();
+ g_help.description = a->description;
+ if (const Command* c = a->command.empty() ? nullptr : app.commands().find(a->command)) {
+ if (g_help.description.empty()) g_help.description = c->description;
+ g_help.params = c->params;
+ g_help.hasCommand = true;
+ }
+ }
+
+ float KeycapsWidth(const std::string& chord) {
+ const float s = uiScale(), pad = 5.0f * s, gap = 3.0f * s;
+ float w = 0.0f;
+ size_t start = 0;
+ bool firstChord = true;
+ while (start <= chord.size()) {
+ const size_t at = chord.find(" / ", start);
+ const std::string part = chord.substr(start, at == std::string::npos ? std::string::npos : at - start);
+ if (!firstChord) w += ImGui::CalcTextSize("/").x + 2 * gap;
+ firstChord = false;
+ const auto keys = chordKeys(part);
+ for (size_t i = 0; i < keys.size(); ++i) {
+ if (i) w += ImGui::CalcTextSize("+").x + 2 * gap;
+ w += ImGui::CalcTextSize(keys[i].c_str()).x + 2 * pad;
+ }
+ if (at == std::string::npos) break;
+ start = at + 3;
+ }
+ return w;
+ }
+
+ float KeycapsAt(ImDrawList* dl, ImVec2 p, const std::string& chord) {
+ const float s = uiScale(), pad = 5.0f * s, gap = 3.0f * s;
+ const float h = ImGui::GetTextLineHeight() + 2.0f * s;
+ const float x0 = p.x;
+ auto dimText = [&](const char* t) {
+ p.x += gap;
+ dl->AddText(ImVec2(p.x, p.y + 1.0f * s), color::textDim, t);
+ p.x += ImGui::CalcTextSize(t).x + gap;
+ };
+ size_t start = 0;
+ bool firstChord = true;
+ while (start <= chord.size()) {
+ const size_t at = chord.find(" / ", start);
+ const std::string part = chord.substr(start, at == std::string::npos ? std::string::npos : at - start);
+ if (!firstChord) dimText("/");
+ firstChord = false;
+ const auto keys = chordKeys(part);
+ for (size_t i = 0; i < keys.size(); ++i) {
+ if (i) dimText("+");
+ const ImVec2 ts = ImGui::CalcTextSize(keys[i].c_str());
+ const ImVec2 a = p, b(p.x + ts.x + 2 * pad, p.y + h);
+ dl->AddRectFilled(a, b, IM_COL32(0x2c, 0x2c, 0x30, 0xff), 3.0f * s);
+ dl->AddRect(a, b, IM_COL32(0x4a, 0x4a, 0x50, 0xff), 3.0f * s);
+ dl->AddText(ImVec2(a.x + pad, a.y + 1.0f * s), color::accent, keys[i].c_str());
+ p.x = b.x;
+ }
+ if (at == std::string::npos) break;
+ start = at + 3;
+ }
+ return p.x - x0;
+ }
+
+ void Keycaps(const std::string& chord) {
+ if (chord.empty()) return;
+ const float w = KeycapsAt(ImGui::GetWindowDrawList(), ImGui::GetCursorScreenPos(), chord);
+ ImGui::Dummy(ImVec2(w, ImGui::GetTextLineHeight() + 2.0f * uiScale()));
+ if (ImGui::GetCurrentContext()->LogEnabled) ImGui::LogText(" %s", chord.c_str());
+ }
+
+ void DelayedTooltip(const char* text) {
+ if (!text || !*text || CtrlHeld()) return;
+ if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayNormal | ImGuiHoveredFlags_NoSharedDelay)) ImGui::SetTooltip("%s", text);
+ }
bool ActionButton(App& app, const char* actionId, ImVec2 size, Look look) {
+ int shelf, index;
+ takeOrigin(shelf, index);
const Action* a = app.actions().find(actionId);
- if (!a) return false;
+ if (!a) {
+ ImGui::BeginDisabled();
+ ImGui::Button((std::string("?") + actionId).c_str(), size);
+ ImGui::EndDisabled();
+ return false;
+ }
+ // Copy what we need: running the action may add or replace actions.
+ const std::string id = a->id, label = a->label;
+ const char* icon = a->icon;
+ const std::function<void()> run = a->run;
const bool enabled = !a->enabled || a->enabled();
+ const bool checked = a->checked && a->checked();
+ const float s = uiScale();
+ if (look == Look::Icon && !icon) look = Look::Label;
+ if (look == Look::IconLabel && !icon) look = Look::Label;
+ if (look == Look::Icon && size.x <= 0.0f) size = ImVec2(ImGui::GetFrameHeight(), ImGui::GetFrameHeight());
+ if (look == Look::Tile && size.x <= 0.0f) size = ImVec2(44.0f * s, 40.0f * s);
+
+ int colors = 0;
+ if (checked) {
+ ImGui::PushStyleColor(ImGuiCol_Button, rgba(color::accent));
+ ImGui::PushStyleColor(ImGuiCol_ButtonHovered, rgba(color::accentHover));
+ ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1, 1, 1, 1));
+ colors = 3;
+ }
ImGui::BeginDisabled(!enabled);
- const bool clicked = drawActionLook(app, *a, size, int(look)); // Shell.cpp: label, icon and tile looks
+ bool clicked = false;
+ const std::string itemLabel = label + "##" + id;
+ bool clipped = false;
+ if (look == Look::Label) {
+ clicked = ImGui::Button(itemLabel.c_str(), size);
+ const float textW = ImGui::CalcTextSize(itemLabel.c_str(), nullptr, true).x + 2.0f * ImGui::GetStyle().FramePadding.x;
+ clipped = size.x > 0.0f && textW > size.x + 0.5f;
+ } else if (look == Look::IconLabel) {
+ // Drawn by hand so the item keeps the plain label as its name ("Store Config", not glyph + label).
+ const std::string text = std::string(icon) + " " + label;
+ const ImGuiStyle& st = ImGui::GetStyle();
+ const ImVec2 ts = ImGui::CalcTextSize(text.c_str());
+ const ImVec2 full = ImGui::CalcItemSize(size, ts.x + st.FramePadding.x * 2.0f, ts.y + st.FramePadding.y * 2.0f);
+ ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0, 0, 0, 0));
+ clicked = ImGui::Button(itemLabel.c_str(), full);
+ ImGui::PopStyleColor();
+ const ImRect r(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
+ ImGui::RenderTextClipped(ImVec2(r.Min.x + st.FramePadding.x, r.Min.y + st.FramePadding.y),
+ ImVec2(r.Max.x - st.FramePadding.x, r.Max.y - st.FramePadding.y), text.c_str(), nullptr, &ts,
+ st.ButtonTextAlign, &r);
+ clipped = ts.x + st.FramePadding.x * 2.0f > full.x + 0.5f;
++ } else if (look == Look::Tile) {
++ // Shelf tiles (Shell.cpp): brush thumbnails on the bottom shelf, a large icon over a caption on the
++ // right shelf. The item keeps the plain label as its name.
++ clicked = drawShelfTile(app, *a, size);
+ } else {
- // Icon / Tile: the label stays the item's name (for tests and screen readers) but is drawn by hand.
++ // Icon: the label stays the item's name (for tests and screen readers) but is drawn by hand.
+ ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0, 0, 0, 0));
+ clicked = ImGui::Button(itemLabel.c_str(), size);
+ ImGui::PopStyleColor();
+ const ImRect r(ImGui::GetItemRectMin(), ImGui::GetItemRectMax());
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ const ImU32 fg = !enabled ? color::textDim : checked ? IM_COL32_WHITE : color::text;
+ if (look == Look::Icon) {
+ const ImVec2 is = ImGui::CalcTextSize(icon);
+ dl->AddText(ImVec2(std::floor(r.GetCenter().x - is.x * 0.5f), std::floor(r.GetCenter().y - is.y * 0.5f)), fg, icon);
+ } else {
+ const ImVec2 is = ImGui::CalcTextSize(icon ? icon : "");
+ const float small = 0.8f;
+ ImFont* font = ImGui::GetFont();
+ const float fs = ImGui::GetFontSize() * small;
+ const ImVec2 ls = font->CalcTextSizeA(fs, FLT_MAX, 0.0f, label.c_str());
+ const float total = (icon ? is.y : 0.0f) + ls.y;
+ float y = r.GetCenter().y - total * 0.5f;
+ if (icon) {
+ dl->AddText(ImVec2(std::floor(r.GetCenter().x - is.x * 0.5f), std::floor(y)), fg, icon);
+ y += is.y;
+ }
+ const float maxW = r.GetWidth() - 2.0f * s;
+ clipped = ls.x > maxW;
+ const float x = clipped ? r.Min.x + 1.0f * s : r.GetCenter().x - ls.x * 0.5f;
+ const ImVec4 clip(r.Min.x + 1.0f * s, r.Min.y, r.Max.x - 1.0f * s, r.Max.y);
+ dl->AddText(font, fs, ImVec2(std::floor(x), std::floor(y)), fg, label.c_str(), nullptr, 0.0f, &clip);
+ }
+ clipped = clipped || look == Look::Icon;
+ }
ImGui::EndDisabled();
- if (clicked && a->run) {
- app.actions().touch(a->id);
- a->run();
+ if (colors) ImGui::PopStyleColor(colors);
+
+ const bool customize = app.layout().customize;
+ dragSource(app, id.c_str(), label.c_str(), shelf, index);
+ HelpAction(app, id.c_str());
+ if (clipped) {
+ const std::string chord = app.actions().shortcutText(id);
+ DelayedTooltip((chord.empty() ? label : label + " " + chord).c_str());
}
- return clicked;
+ if (!clicked) return false;
+ if (CtrlHeld() && AltHeld()) {
+ // Ctrl+Alt+click: customize mode drags instead; otherwise it assigns a shortcut (ZBrush).
+ if (!customize) app.beginShortcutCapture(id);
+ return false;
+ }
+ if (run) run();
+ return true;
}
- void HelpText(const char*, const char*, const char*, const char*) {}
-
- void HelpAction(App&, const char*) {}
-
bool SliderInside(const char* id, float* v, float lo, float hi, const char* format, ImGuiSliderFlags flags) {
- // ZBrush look: the label and value inside the frame, the position as a thin accent bar along its bottom.
- const float s = uiScale();
+ const float w = ImGui::CalcItemWidth(), h = ImGui::GetFrameHeight();
+ const ImVec2 p = ImGui::GetCursorScreenPos();
+ ImDrawList* dl = ImGui::GetWindowDrawList();
- // Frame and fill go underneath the slider (which draws a transparent frame and a thin grab on top).
++ // Frame and fill go underneath the slider (which draws a transparent frame on top).
+ dl->ChannelsSplit(2);
+ dl->ChannelsSetCurrent(1);
+ ImGui::PushStyleColor(ImGuiCol_FrameBg, ImVec4(0, 0, 0, 0));
+ ImGui::PushStyleColor(ImGuiCol_FrameBgHovered, ImVec4(1, 1, 1, 0.04f));
+ ImGui::PushStyleColor(ImGuiCol_FrameBgActive, ImVec4(1, 1, 1, 0.06f));
- ImGui::PushStyleVar(ImGuiStyleVar_GrabMinSize, 3.0f * s);
++ // No grab over the label: the position shows as the fill and a thin accent bar along the bottom (ZBrush).
+ ImGui::PushStyleColor(ImGuiCol_SliderGrab, ImVec4(0, 0, 0, 0));
+ ImGui::PushStyleColor(ImGuiCol_SliderGrabActive, ImVec4(0, 0, 0, 0));
const bool changed = ImGui::SliderFloat(id, v, lo, hi, format, flags);
- ImGui::PopStyleColor(2);
- const ImVec2 a = ImGui::GetItemRectMin(), b = ImGui::GetItemRectMax();
- float t = hi > lo ? (*v - lo) / (hi - lo) : 0.0f;
- if ((flags & ImGuiSliderFlags_Logarithmic) && lo > 0.0f && hi > lo) t = std::log(*v / lo) / std::log(hi / lo);
- ImGui::PopStyleVar();
- ImGui::PopStyleColor(3);
++ const bool active = ImGui::IsItemActive();
++ ImGui::PopStyleColor(5);
+ dl->ChannelsSetCurrent(0);
+ float t = 0.0f;
+ if (hi > lo) {
+ if ((flags & ImGuiSliderFlags_Logarithmic) && lo > 0.0f)
+ t = std::log(std::max(*v, lo) / lo) / std::log(hi / lo);
+ else
+ t = (*v - lo) / (hi - lo);
+ }
t = std::clamp(t, 0.0f, 1.0f);
- const float r = ImGui::GetStyle().FrameRounding, bar = std::max(2.0f, (b.y - a.y) * 0.12f);
- const float x = a.x + (b.x - a.x) * t;
- ImDrawList* dl = ImGui::GetWindowDrawList();
- dl->AddRectFilled(a, ImVec2(x, b.y), theme::u32(theme::accent, ImGui::IsItemActive() ? 0.22f : 0.12f), r,
- ImDrawFlags_RoundCornersLeft);
- dl->AddRectFilled(ImVec2(a.x, b.y - bar), ImVec2(x, b.y), theme::u32(ImGui::IsItemActive() ? theme::accentHover : theme::accent),
- r, ImDrawFlags_RoundCornersBottomLeft);
+ const float rounding = ImGui::GetStyle().FrameRounding;
+ dl->AddRectFilled(p, ImVec2(p.x + w, p.y + h), ImGui::GetColorU32(ImGuiCol_FrameBg), rounding);
- dl->AddRectFilled(p, ImVec2(p.x + w * t, p.y + h), IM_COL32(0xf0, 0x88, 0x2e, 0x38), rounding);
++ dl->AddRectFilled(p, ImVec2(p.x + w * t, p.y + h), IM_COL32(0xf0, 0x88, 0x2e, active ? 0x48 : 0x30), rounding);
++ const float bar = std::max(2.0f, std::floor(h * 0.1f));
++ dl->AddRectFilled(ImVec2(p.x, p.y + h - bar), ImVec2(p.x + w * t, p.y + h), active ? color::accentHover : color::accent,
++ rounding, ImDrawFlags_RoundCornersBottomLeft);
+ dl->ChannelsMerge();
return changed;
}
diff --cc src/app/UiLayout.cpp
index 204decf3,b4e5d943..2ce61493
--- a/src/app/UiLayout.cpp
+++ b/src/app/UiLayout.cpp
@@@ -26,19 -26,6 +26,19 @@@ UiLayout standardLayout()
UiLayout l;
l.rightTray = {"tool"};
l.openSubpalettes = {"tool.subtool"};
+ l.topShelf = {"ui.lightbox", "sep", "draw.sculpt", "draw.paint", "sep",
+ "draw.zadd", "draw.zsub", "draw.rgb", "sep", "widget.draw_size",
+ "widget.strength", "row", "ui.brush_lab", "draw.front_faces", "sep",
- "transform.sym_x", "transform.sym_y", "transform.sym_z", "sep", "draw.pressure_strength",
++ "transform.symmetry_x", "transform.symmetry_y", "transform.symmetry_z", "sep", "draw.pressure_strength",
+ "draw.pressure_size", "widget.points"};
+ l.leftShelf = {"widget.tile.brush", "widget.tile.stroke", "widget.tile.alpha", "widget.tile.material", "widget.color"};
+ l.rightShelf = {"view.frame", "widget.nav.move", "widget.nav.zoom", "widget.nav.rotate", "sep",
+ "view.polyf", "view.polygroups", "view.mask", "view.polypaint", "sep",
+ "subtool.solo", "view.splats"};
+ l.bottomShelf = {"brush.standard", "brush.clay", "brush.claybuildup", "brush.damstandard", "brush.move",
+ "brush.smooth", "brush.inflate", "brush.pinch", "brush.flatten", "brush.crease",
+ "brush.trim", "brush.snakehook", "brush.layer", "brush.nudge", "draw.paint",
+ "widget.add_brush"};
return l;
}
diff --cc src/app/UiTest.cpp
index eb99e624,2b948a6b..85e676cb
--- a/src/app/UiTest.cpp
+++ b/src/app/UiTest.cpp
@@@ -29,8 -30,9 +30,10 @@@
// subtools (count), active_subtool (index, 0 = top), visible_subtools,
// edited_subtools (SubTools with undo history), user_brushes (brushes in the
// user library), library_files (.sfbrush files in it; UI tests get an empty
- // one in --ui-out/brush-library), shelves (1 shown), left_tray / right_tray
- // (palettes in the tray, -1 when closed); OP is == != < <= > >=
+ // one in --ui-out/brush-library), ui_config (1 once Store Config wrote ui.json),
+ // console_open, command_palette_open, customize, shelves_visible,
-// right_tray_open, left_tray_open, lightbox_open; OP is == != < <= > >=
++// right_tray_open, left_tray_open, lightbox_open, shelves (1 shown), left_tray / right_tray (palettes in
++// the tray, -1 when closed); OP is == != < <= > >=
// (mesh values are the active SubTool's)
// shot NAME save a screenshot NAME.png (to --ui-out)
#include "app/App.h"
@@@ -164,9 -167,18 +168,21 @@@ double Demo::query(const std::string& n
if (name == "show_polygroups") return app_.renderSettings_.showPolygroups ? 1.0 : 0.0;
if (name == "show_mask") return app_.renderSettings_.showMask ? 1.0 : 0.0;
if (name == "wireframe") return app_.renderSettings_.wireframe ? 1.0 : 0.0;
+ if (name == "shelves") return app_.layout_.shelvesVisible ? 1.0 : 0.0;
+ if (name == "left_tray") return app_.layout_.leftTrayOpen ? double(app_.layout_.leftTray.size()) : -1.0;
+ if (name == "right_tray") return app_.layout_.rightTrayOpen ? double(app_.layout_.rightTray.size()) : -1.0;
+ if (name == "ui_config") {
+ std::error_code ec;
+ const std::string p = app_.uiConfigPath();
+ return !p.empty() && std::filesystem::is_regular_file(std::filesystem::path(std::u8string(p.begin(), p.end())), ec) ? 1.0 : 0.0;
+ }
+ if (name == "console_open") return app_.layout_.consoleOpen ? 1.0 : 0.0;
+ if (name == "command_palette_open") return app_.palette_.isOpen() ? 1.0 : 0.0;
+ if (name == "customize") return app_.layout_.customize ? 1.0 : 0.0;
+ if (name == "shelves_visible") return app_.layout_.shelvesVisible ? 1.0 : 0.0;
+ if (name == "right_tray_open") return app_.layout_.rightTrayOpen ? 1.0 : 0.0;
+ if (name == "left_tray_open") return app_.layout_.leftTrayOpen ? 1.0 : 0.0;
+ if (name == "lightbox_open") return app_.lightbox_.open() ? 1.0 : 0.0;
const Document& doc = app_.doc_;
if (name == "subtools") return double(doc.subtoolCount());
if (name == "active_subtool") return double(doc.activeSubtool);