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.

ZBrush-style UI, workstream A: shell, layout, palettes, theme

islandmedd534828c2c56
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3a9eae53..e1906666 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -129,6 +129,10 @@ 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/PanelMasking.cpp
src/app/PanelPolygroups.cpp
src/app/PanelBrushes.cpp
@@ -305,7 +309,8 @@ 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(MSVC)
@@ -331,5 +336,9 @@ if(SCULPTFORGE_BUILD_TESTS)
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)
endif()
endif()
diff --git a/src/app/App.cpp b/src/app/App.cpp
index 7617ab4c..2330243a 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -4,6 +4,9 @@
#include "ai/AiCommands.h"
#include "app/Demo.h"
+#include "app/Shell.h"
+#include "app/Theme.h"
+#include "app/Ui.h"
#include <IconsLucide.h>
@@ -65,28 +68,6 @@ const char* kExamplePrompts[] = {
bool ctrlDown(SDL_Keymod mod) { return (mod & (SDL_KMOD_CTRL | SDL_KMOD_GUI)) != 0; }
-void applyStyle() {
- ImGui::StyleColorsDark();
- ImGuiStyle& s = ImGui::GetStyle();
- s.WindowRounding = 6.0f;
- s.FrameRounding = 4.0f;
- s.GrabRounding = 4.0f;
- s.WindowBorderSize = 0.0f;
- s.FramePadding = ImVec2(8, 5);
- s.ItemSpacing = ImVec2(8, 6);
- ImVec4* c = s.Colors;
- c[ImGuiCol_WindowBg] = ImVec4(0.11f, 0.11f, 0.12f, 0.94f);
- c[ImGuiCol_Button] = ImVec4(0.22f, 0.22f, 0.25f, 1.0f);
- c[ImGuiCol_ButtonHovered] = ImVec4(0.85f, 0.50f, 0.25f, 0.85f);
- c[ImGuiCol_ButtonActive] = ImVec4(0.95f, 0.55f, 0.25f, 1.0f);
- c[ImGuiCol_SliderGrab] = ImVec4(0.90f, 0.55f, 0.25f, 1.0f);
- c[ImGuiCol_SliderGrabActive] = ImVec4(1.00f, 0.62f, 0.30f, 1.0f);
- c[ImGuiCol_CheckMark] = ImVec4(1.00f, 0.62f, 0.30f, 1.0f);
- c[ImGuiCol_Header] = ImVec4(0.85f, 0.50f, 0.25f, 0.45f);
- c[ImGuiCol_HeaderHovered] = ImVec4(0.85f, 0.50f, 0.25f, 0.70f);
- c[ImGuiCol_FrameBg] = ImVec4(0.18f, 0.18f, 0.20f, 1.0f);
-}
-
} // namespace
App::App() = default;
@@ -170,6 +151,7 @@ bool App::init(const AppOptions& options) {
}
ai::registerAiCommands(commands_, [this] { return aiSettings_; });
registerPaintUiCommands();
+ registerShellActions();
std::snprintf(falKey_, sizeof falKey_, "%s", aiSettings_.falKey.c_str());
std::snprintf(falModel_, sizeof falModel_, "%s", aiSettings_.falModel.c_str());
std::snprintf(meshyKey_, sizeof meshyKey_, "%s", aiSettings_.meshyKey.c_str());
@@ -182,7 +164,7 @@ bool App::init(const AppOptions& options) {
if (scale <= 0.0f) scale = 1.0f;
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;
@@ -202,6 +184,34 @@ bool App::init(const AppOptions& options) {
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);
+ }
if (recording) {
fontCaption_ = io.Fonts->AddFontFromMemoryTTF(const_cast<unsigned char*>(assets::fontSemiBold),
int(assets::fontSemiBold_size), float(options.height) * 0.042f,
@@ -322,7 +332,7 @@ int App::runUiTest(int w, int h, int fps) {
pollBrushRequest();
pollUnreal();
pollGenerator();
- camera_.aspect = float(w) / float(h);
+ updateCameraAspect();
Demo::beginFrame();
ImGui_ImplOpenGL3_NewFrame();
@@ -346,7 +356,7 @@ int App::runUiTest(int w, int h, int fps) {
SDL_Log("%s", err.c_str());
return 1;
}
- renderer_.draw(camera_, w, h, renderSettings_);
+ renderer_.draw(camera_, w, h, renderSettings_, canvasViewport(w, h));
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
renderer_.endCapture(rgba);
Image img;
@@ -400,7 +410,7 @@ int App::runRecording() {
animateLayers(dt);
pollBrushRequest();
pollUnreal();
- camera_.aspect = float(w) / float(h);
+ updateCameraAspect();
Demo::beginFrame();
ImGui_ImplOpenGL3_NewFrame();
@@ -422,7 +432,7 @@ int App::runRecording() {
SDL_Log("%s", err.c_str());
break;
}
- renderer_.draw(camera_, w, h, renderSettings_);
+ renderer_.draw(camera_, w, h, renderSettings_, canvasViewport(w, h));
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
renderer_.endCapture(rgba);
fwrite(rgba.data(), 1, rgba.size(), ff);
@@ -462,7 +472,7 @@ int App::run() {
SDL_Delay(16);
continue;
}
- camera_.aspect = float(fbW) / float(fbH);
+ updateCameraAspect();
ImGui_ImplOpenGL3_NewFrame();
ImGui_ImplSDL3_NewFrame();
@@ -471,7 +481,7 @@ int App::run() {
ImGui::Render();
syncScene();
- renderer_.draw(camera_, fbW, fbH, renderSettings_);
+ renderer_.draw(camera_, fbW, fbH, renderSettings_, canvasViewport(fbW, fbH));
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
SDL_GL_SwapWindow(window_);
tickProject(dt);
@@ -503,7 +513,9 @@ void App::handleEvent(const SDL_Event& e) {
break;
case SDL_EVENT_MOUSE_BUTTON_DOWN:
lastInputPen_ = e.button.which == SDL_PEN_MOUSEID;
- if (!io.WantCaptureMouse) onMouseDown(e.button.x, e.button.y, e.button.button);
+ // Strokes and navigation start only on the canvas, never on the shell around it.
+ if (!io.WantCaptureMouse && canvasRect().contains(e.button.x, e.button.y))
+ onMouseDown(e.button.x, e.button.y, e.button.button);
break;
case SDL_EVENT_MOUSE_BUTTON_UP:
onMouseUp();
@@ -512,7 +524,7 @@ void App::handleEvent(const SDL_Event& e) {
onMouseMove(e.motion.x, e.motion.y, e.motion.xrel, e.motion.yrel, e.motion.which == SDL_PEN_MOUSEID);
break;
case SDL_EVENT_MOUSE_WHEEL:
- if (!io.WantCaptureMouse) camera_.zoom(e.wheel.y);
+ if (!io.WantCaptureMouse && canvasRect().contains(e.wheel.mouse_x, e.wheel.mouse_y)) camera_.zoom(e.wheel.y);
break;
case SDL_EVENT_KEY_DOWN:
if (!io.WantCaptureKeyboard && !e.key.repeat) onKey(e.key.key, e.key.mod);
@@ -529,10 +541,8 @@ void App::handleEvent(const SDL_Event& e) {
bool App::pick(float x, float y, RayHit& hit) const {
if (!doc_.activeSubtoolInfo().visible) return false; // you can't sculpt what you can't see
- int w = 0, h = 0;
- SDL_GetWindowSize(window_, &w, &h);
glm::vec3 origin, dir;
- camera_.screenRay(x, y, float(w), float(h), origin, dir);
+ canvasRay(x, y, origin, dir);
return doc_.bvh.raycast(doc_.mesh, origin, dir, hit);
}
@@ -584,12 +594,10 @@ void App::onMouseMove(float x, float y, float dx, float dy, bool fromPen) {
mouseX_ = x;
mouseY_ = y;
lastInputPen_ = fromPen;
- int w = 0, h = 0;
- SDL_GetWindowSize(window_, &w, &h);
switch (drag_) {
case Drag::Stroke: strokeTo(x, y); break;
case Drag::Orbit: camera_.orbit(dx, dy); break;
- case Drag::Pan: camera_.pan(dx, dy, float(h)); break;
+ case Drag::Pan: camera_.pan(dx, dy, canvasHeight()); break;
case Drag::Zoom: camera_.zoom(-dy * 0.05f); break;
case Drag::MaskCanvas: maskCanvasMove(x, y); break;
case Drag::SubToolClick: subtoolClickMove(x, y); break;
@@ -606,6 +614,7 @@ void App::onMouseUp() {
}
void App::onKey(SDL_Keycode key, SDL_Keymod mod) {
+ if (actions_.handleKey(key, mod)) return;
const bool ctrl = ctrlDown(mod);
const bool shift = (mod & SDL_KMOD_SHIFT) != 0;
if (ctrl) {
@@ -628,12 +637,15 @@ void App::onKey(SDL_Keycode key, SDL_Keymod mod) {
case SDLK_RIGHTBRACKET: radiusPx_ = std::min(800.0f, radiusPx_ * 1.1f); break;
case SDLK_X: symmetry_.x = !symmetry_.x; break;
case SDLK_W: renderSettings_.wireframe = !renderSettings_.wireframe; break;
- case SDLK_F: camera_.frame(sceneBounds()); break;
- case SDLK_F1: showHelp_ = !showHelp_; break;
- case SDLK_P:
- paintMode_ = !paintMode_;
- if (paintMode_) showPolypaintPanel_ = true; // colour picker at hand
+ case SDLK_F:
+ if (shift) renderSettings_.wireframe = !renderSettings_.wireframe; // ZBrush PolyF
+ else camera_.frame(sceneBounds());
+ break;
+ case SDLK_TAB:
+ if (const Action* a = actions_.find("ui.toggle_shelves")) a->run();
break;
+ case SDLK_F1: showHelp_ = !showHelp_; break;
+ case SDLK_P: paintMode_ = !paintMode_; break; // the colour picker is on the left shelf
case SDLK_C: pickColorUnderCursor(); break;
default:
// 1-9 pick the first nine brushes, 0 the tenth.
@@ -676,13 +688,11 @@ void App::beginStroke(float x, float y, const RayHit& hit) {
residual_ = 0.0f;
if (strokeBrush_ == BrushType::Move && !recipe && strokeSculpt_) {
- int w = 0, h = 0;
- SDL_GetWindowSize(window_, &w, &h);
float pressure = lastInputPen_ && pressureSize_ ? penPressure_ : 1.0f;
DabParams p;
p.center = hit.position;
p.viewDir = camera_.forward();
- p.radius = radiusPx_ * pressure * camera_.worldPerPixel(hit.position, float(h));
+ p.radius = radiusPx_ * pressure * camera_.worldPerPixel(hit.position, canvasHeight());
p.strength = strength_;
doc_.sculptor.beginGrab(doc_.mesh, doc_.bvh, p, symmetry_);
grabPlanePoint_ = grabLast_ = hit.position;
@@ -704,10 +714,8 @@ void App::beginStroke(float x, float y, const RayHit& hit) {
void App::strokeTo(float x, float y) {
const BrushRecipe* recipe = strokeRecipe();
if (strokeBrush_ == BrushType::Move && !recipe && strokeSculpt_) {
- int w = 0, h = 0;
- SDL_GetWindowSize(window_, &w, &h);
glm::vec3 origin, dir;
- camera_.screenRay(x, y, float(w), float(h), origin, dir);
+ canvasRay(x, y, origin, dir);
glm::vec3 n = camera_.forward();
float denom = glm::dot(dir, n);
if (std::abs(denom) < 1e-6f) return;
@@ -771,15 +779,13 @@ void App::dabAt(float x, float y) {
}
RayHit hit;
if (!pick(x, y, hit)) return;
- int w = 0, h = 0;
- SDL_GetWindowSize(window_, &w, &h);
const float pressure = lastInputPen_ ? std::clamp(penPressure_, 0.0f, 1.0f) : 1.0f;
DabParams p;
p.center = hit.position;
p.viewDir = camera_.forward();
p.radius = radiusPx_ * (pressureSize_ ? std::max(pressure, 0.05f) : 1.0f) *
- camera_.worldPerPixel(hit.position, float(h)) * dabRadiusScale_;
+ camera_.worldPerPixel(hit.position, canvasHeight()) * dabRadiusScale_;
p.strength = strength_ * dabStrengthScale_;
p.pressure = pressureStrength_ ? pressure : 1.0f;
p.invert = strokeInvert_;
@@ -1044,29 +1050,28 @@ void App::updateTitle() {
void App::drawUi() {
drawProjectPopups();
if (hideUi_) return; // demos: clean beauty shots
- drawMenuBar();
- drawToolPanel();
- if (showSubToolsPanel_) drawSubToolsPanel();
+ // Draw order (ui-spec §12): shells, LightBox, floating windows, then pop-ups and help.
+ drawShell();
+ lightbox_.draw(*this, canvasRect());
drawSubToolPopups();
- if (showLayersPanel_) drawLayersPanel();
- if (showGamePanel_) drawGameExportPanel();
- drawSplatSection();
if (showBrushLab_) drawBrushLab();
drawBrushGallery();
if (showImageTo3D_) drawImageTo3D();
- if (showPolypaintPanel_) drawPolypaintPanel();
+ pollAlphaFile();
if (previewLod_ >= 0) {
- const ImGuiViewport* vp = ImGui::GetMainViewport();
+ const CanvasRect c = canvasRect();
std::string banner = "Previewing LOD" + std::to_string(previewLod_) + " - " +
std::to_string(lods_[previewLod_].triangleCount()) + " tris (sculpting paused)";
ImVec2 size = ImGui::CalcTextSize(banner.c_str());
- ImGui::GetForegroundDrawList()->AddText(
- ImVec2(vp->Pos.x + (vp->Size.x - size.x) * 0.5f, vp->Pos.y + vp->Size.y - size.y - 16.0f),
- IM_COL32(255, 190, 120, 255), banner.c_str());
+ ImGui::GetForegroundDrawList()->AddText(ImVec2(c.x + (c.w - size.x) * 0.5f, c.y + c.h - size.y - 16.0f * uiScale_),
+ IM_COL32(255, 190, 120, 255), banner.c_str());
}
- if (!ImGui::GetIO().WantCaptureMouse || drag_ == Drag::Stroke) drawBrushCursor();
+ const ImVec2 mouse(mouseX_, mouseY_);
+ if ((!ImGui::GetIO().WantCaptureMouse && canvasRect().contains(mouse.x, mouse.y)) || drag_ == Drag::Stroke)
+ drawBrushCursor();
drawPolygroupOverlay();
drawBrushLibraryPopups();
+ drawPickers(*this);
autosaveBrush();
if (showAbout_) {
@@ -1130,81 +1135,8 @@ void App::drawUi() {
}
}
-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}});
@@ -1246,7 +1178,6 @@ void App::drawLayersPanel() {
ImGuiInputTextFlags_EnterReturnsTrue);
ImGui::SameLine();
if (ImGui::Button("+ Add") || enter) runCommand("layer_add", {{"name", std::string(newLayerName_)}});
- ImGui::End();
}
void App::sendToUnreal() {
@@ -1283,15 +1214,7 @@ void App::pollUnreal() {
status_ = pendingUnreal_.get();
}
-void App::drawGameExportPanel() {
- const float scale = uiScale_;
- const ImGuiViewport* vp = ImGui::GetMainViewport();
- ImGui::SetNextWindowPos(ImVec2(vp->Pos.x + vp->Size.x - 290 * scale, vp->Pos.y + 330 * scale),
- ImGuiCond_FirstUseEver);
- if (!beginPanel("Game Ready", nullptr, 280 * scale)) {
- ImGui::End();
- return;
- }
+void App::drawGameExportContents() {
ImGui::PushItemWidth(-ImGui::CalcTextSize("Reduction").x - ImGui::GetStyle().ItemInnerSpacing.x);
if (ImGui::SliderInt("LODs", &lodLevels_, 2, 6)) clearLods();
if (ImGui::SliderFloat("Reduction", &lodRatio_, 0.1f, 0.9f, "x%.2f / level")) clearLods();
@@ -1361,7 +1284,6 @@ void App::drawGameExportPanel() {
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));
ImGui::TextWrapped("Unreal, Unity, Godot, Blender, three.js");
ImGui::PopStyleColor();
- ImGui::End();
}
// ---------------------------------------------------------------------------
@@ -1581,10 +1503,9 @@ void App::drawAiSettings() {
void App::drawBrushLab() {
const float scale = uiScale_;
const ImGuiViewport* vp = ImGui::GetMainViewport();
- // First use: bottom of the window, right of the Tools panel.
- ImGui::SetNextWindowPos(ImVec2(vp->Pos.x + 270 * scale, std::max(vp->Pos.y + 34 * scale,
- vp->Pos.y + vp->Size.y - 470 * scale)),
- ImGuiCond_FirstUseEver);
+ // First use: the canvas's top-left corner, clear of the model.
+ const CanvasRect canvas = canvasRect();
+ ImGui::SetNextWindowPos(ImVec2(vp->Pos.x + canvas.x + 16 * scale, vp->Pos.y + canvas.y + 16 * scale), ImGuiCond_FirstUseEver);
if (!beginPanel("Brush Lab", &showBrushLab_, 420 * scale)) {
ImGui::End();
return;
@@ -1702,15 +1623,14 @@ bool App::loadReferenceImage(const std::string& path) {
void App::projectImageFromView() {
if (refImage_.empty()) return;
- int w = 0, h = 0;
- SDL_GetWindowSize(window_, &w, &h);
+ const CanvasRect view = canvasRect();
const AABB b = doc_.mesh.bounds();
ProjectOptions o;
o.depth = projectDepth_ * glm::length(b.extent());
o.invert = projectInvert_;
Mesh m = doc_.mesh;
size_t n = projectImage(m, doc_.activeLayer, refImage_, camera_.projection() * camera_.view(),
- float(w) / float(std::max(h, 1)), camera_.position(), o);
+ view.w / std::max(view.h, 1.0f), camera_.position(), o);
if (n == 0) {
status_ = "The image didn't land on the model - aim the view at it first";
return;
@@ -1856,7 +1776,9 @@ void App::drawComfyUi() {
void App::drawImageTo3D() {
const float scale = uiScale_;
const ImGuiViewport* vp = ImGui::GetMainViewport();
- ImGui::SetNextWindowPos(ImVec2(vp->Pos.x + vp->Size.x - 590 * scale, vp->Pos.y + 34 * scale), ImGuiCond_FirstUseEver);
+ const CanvasRect canvas = canvasRect(); // first use: the canvas's top-right corner
+ ImGui::SetNextWindowPos(ImVec2(vp->Pos.x + canvas.x + canvas.w - 306 * scale, vp->Pos.y + canvas.y + 16 * scale),
+ ImGuiCond_FirstUseEver);
if (!beginPanel("Generate 3D", &showImageTo3D_, 290 * scale)) {
ImGui::End();
return;
@@ -2036,100 +1958,8 @@ void App::drawImageTo3D() {
ImGui::End();
}
-void App::drawToolPanel() {
- const float scale = uiScale_;
- ImGui::SetNextWindowPos(ImVec2(10 * scale, 34 * scale), ImGuiCond_FirstUseEver);
- if (!beginPanel("Tools", nullptr, 250 * scale)) {
- ImGui::End();
- return;
- }
-
- ImGui::SeparatorText("Brush");
- const float bw = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) * 0.5f;
- for (int i = 0; i < int(BrushType::Count); ++i) {
- const auto type = BrushType(i);
- const bool selected = brush_ == type && doc_.activeBrush < 0 && !paintMode_;
- if (selected) ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive));
- // Hotkeys 1-9 and 0 cover the first ten brushes.
- std::string label = (i < 9 ? std::to_string(i + 1) : i == 9 ? std::string("0") : std::string(" ")) + " " +
- brushName(type);
- if (ImGui::Button(label.c_str(), ImVec2(bw, 0))) {
- brush_ = type;
- doc_.activeBrush = -1;
- paintMode_ = false;
- }
- if (selected) ImGui::PopStyleColor();
- if (i % 2 == 0) ImGui::SameLine();
- }
-
- drawCustomBrushes(); // PanelBrushLibrary.cpp
- if (ImGui::Button(showBrushLab_ ? "Hide Brush Lab" : "Brush Lab (AI)...", ImVec2(-1, 0)))
- showBrushLab_ = !showBrushLab_;
- if (ImGui::Button(showImageTo3D_ ? "Hide Generate 3D" : "Generate 3D...", ImVec2(-1, 0)))
- showImageTo3D_ = !showImageTo3D_;
- if (ImGui::Button(showPolypaintPanel_ ? "Hide Polypaint" : "Polypaint & Materials...", ImVec2(-1, 0)))
- showPolypaintPanel_ = !showPolypaintPanel_;
-
- ImGui::PushItemWidth(-ImGui::CalcTextSize("Strength").x - ImGui::GetStyle().ItemInnerSpacing.x);
- ImGui::SliderFloat("Size", &radiusPx_, 2.0f, 800.0f, "%.0f px", ImGuiSliderFlags_Logarithmic);
- ImGui::SliderFloat("Strength", &strength_, 0.01f, 1.0f, "%.2f");
- ImGui::PopItemWidth();
- ImGui::Checkbox("Invert (Alt)", &invertToggle_);
- ImGui::Checkbox("Front faces only", &frontFacesOnly_);
- drawBrushOptions();
-
- ImGui::SeparatorText("Symmetry");
- ImGui::Checkbox("X", &symmetry_.x);
- ImGui::SameLine();
- ImGui::Checkbox("Y", &symmetry_.y);
- ImGui::SameLine();
- ImGui::Checkbox("Z", &symmetry_.z);
-
- ImGui::SeparatorText("Tablet");
- ImGui::Checkbox("Pressure > strength", &pressureStrength_);
- ImGui::Checkbox("Pressure > size", &pressureSize_);
- if (penSeen_) ImGui::Text("Pen pressure: %.2f", penPressure_);
- else ImGui::TextDisabled("No pen detected");
-
- drawMaskingSection();
-
- ImGui::SeparatorText("Mesh");
- if (ImGui::Button("Subdivide (Ctrl+D)", ImVec2(-1, 0))) runCommand("subdivide");
- if (ImGui::Button("Voxel remesh", ImVec2(ImGui::GetContentRegionAvail().x * 0.5f, 0)))
- runCommand("remesh", {{"resolution", double(voxelResolution_)}});
- if (ImGui::IsItemHovered())
- ImGui::SetTooltip("Rebuild as an even, watertight surface (like DynaMesh): merges parts, fixes scans and generated models.");
- ImGui::SameLine();
- ImGui::SetNextItemWidth(-1);
- ImGui::SliderInt("##voxres", &voxelResolution_, 64, 400, "res %d");
- ImGui::Checkbox("Wireframe", &renderSettings_.wireframe);
- ImGui::ColorEdit3("Material", &renderSettings_.baseColor.x, ImGuiColorEditFlags_NoInputs);
- drawPolygroupsSection();
-
- ImGui::Separator();
- ImGui::Text("%zu verts %zu tris", doc_.mesh.vertexCount(), doc_.mesh.triangleCount());
- ImGui::Text("%.0f fps", ImGui::GetIO().Framerate);
- if (!status_.empty()) ImGui::TextWrapped("%s", status_.c_str());
- ImGui::End();
-}
-
-void App::drawSplatSection() {
- // Opens by itself whenever splats arrive (file, command or AI agent).
- if (doc_.splatsVersion != seenSplatsVersion_) {
- seenSplatsVersion_ = doc_.splatsVersion;
- if (!doc_.splats.empty()) showSplatsPanel_ = true;
- }
- if (!showSplatsPanel_) return;
- const float scale = uiScale_;
- const ImGuiViewport* vp = ImGui::GetMainViewport();
- ImGui::SetNextWindowPos(ImVec2(vp->Pos.x + vp->Size.x - 590 * scale, vp->Pos.y + 34 * scale), ImGuiCond_FirstUseEver);
- if (!beginPanel("Gaussian Splats", &showSplatsPanel_, 280 * scale)) {
- ImGui::End();
- return;
- }
- struct EndWindow {
- ~EndWindow() { ImGui::End(); }
- } endWindow;
+// The Splats palette (it comes into the right tray by itself when splats arrive, see drawShell).
+void App::drawPalette_Splats() {
if (doc_.splats.empty()) {
ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));
ImGui::TextWrapped("Open or drop a .ply capture (Polycam, Luma, Postshot, Scaniverse...) to sculpt against it.");
@@ -2166,6 +1996,12 @@ void App::drawSplatSection() {
void App::drawBrushCursor() {
ImDrawList* dl = ImGui::GetForegroundDrawList();
+ const CanvasRect canvas = canvasRect();
+ dl->PushClipRect(ImVec2(canvas.x, canvas.y), ImVec2(canvas.x + canvas.w, canvas.y + canvas.h), true);
+ struct PopClip {
+ ImDrawList* dl;
+ ~PopClip() { dl->PopClipRect(); }
+ } popClip{dl};
const float r = radiusPx_ * (pressureSize_ && lastInputPen_ ? std::max(penPressure_, 0.05f) : 1.0f);
const ImVec2 c(mouseX_, mouseY_);
const bool inverted = invertToggle_ != ((SDL_GetModState() & SDL_KMOD_ALT) != 0);
diff --git a/src/app/App.h b/src/app/App.h
index 3191704c..b0721b92 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -6,6 +6,7 @@
#include "app/Actions.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"
@@ -102,7 +103,6 @@ private:
void saveFileDialog(FileAction action);
AABB sceneBounds() const; // mesh plus the main body of any splats
bool onScreen(const AABB& box) const; // whole box inside the viewport
- void drawSplatSection();
void processPendingFiles();
void setLayerWeight(int index, float weight);
@@ -113,10 +113,6 @@ private:
void syncScene(); // uploads every SubTool (the active one as displayedMesh()) and the splats to the renderer
void drawUi();
- void drawToolPanel();
- void drawMenuBar();
- void drawLayersPanel();
- void drawGameExportPanel();
void drawBrushLab();
void drawImageTo3D();
void drawComfyUi();
@@ -189,10 +185,7 @@ private:
DialogRequest dialogRequests_[int(FileAction::Count)];
// Brush Lab (AI brush designer)
- bool showBrushLab_ = true;
- bool showLayersPanel_ = true;
- bool showGamePanel_ = true;
- bool showSplatsPanel_ = false;
+ bool showBrushLab_ = false; // floating; opened from the top shelf's AI Brush or the Brush palette
bool hideUi_ = false;
uint64_t seenSplatsVersion_ = 0;
ai::AiSettings aiSettings_;
@@ -307,7 +300,6 @@ private:
size_t visibleGroups_ = 0;
std::array<uint64_t, 6> visibleGroupsKey_{};
// Stroke types, alphas and the extra brushes (PanelBrushes.cpp).
- void drawBrushOptions();
void snakeHookTo(float x, float y);
void dragRectTo(float x, float y);
glm::vec3 screenUpVector(float angle) const; // camera up rotated by `angle` around the view axis
@@ -351,9 +343,7 @@ private:
bool paintMode_ = false; // Paint brush: colour only, no sculpting (ZBrush Rgb on, Zadd off)
bool paintRgb_ = false; // also paint the colour while sculpting (ZBrush Rgb + Zadd)
bool strokePaint_ = false, strokeSculpt_ = true;
- bool showPolypaintPanel_ = false; // off by default (keeps the viewport and demo videos clear)
void registerPaintUiCommands();
- void drawPolypaintPanel();
void paintAt(const DabParams& p);
void pickColorUnderCursor();
// First paint stroke on a mesh without polypaint: undo restores this snapshot so the attribute goes away again.
@@ -408,13 +398,11 @@ private:
bool autosaveWritten_ = false;
std::string windowTitle_;
// SubTools (PanelSubTools.cpp): the panel, and Alt+click in the viewport to select one.
- void drawSubToolsPanel();
void drawSubToolPopups();
// Index of the nearest visible SubTool under the cursor (-1: none); builds stale BVHs on the way.
int pickSubtool(float x, float y, RayHit* hit = nullptr);
void subtoolClickMove(float x, float y); // Alt press on another SubTool: dragging turns it into a stroke
void subtoolClickRelease(); // ... and releasing without dragging selects it
- bool showSubToolsPanel_ = true;
int subtoolClickTarget_ = -1;
float subtoolClickX_ = 0.0f, subtoolClickY_ = 0.0f;
uint32_t renamingSubtool_ = 0; // SubTool id being renamed inline (0: none)
@@ -440,7 +428,97 @@ 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 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 --git a/src/app/Demo.cpp b/src/app/Demo.cpp
index b0785dd5..59f7c907 100644
--- a/src/app/Demo.cpp
+++ b/src/app/Demo.cpp
@@ -35,8 +35,10 @@ struct ItemTable {
ImGuiID id, seed;
std::string window;
Placed placed;
+ std::vector<std::string> scopes;
};
std::vector<Seeded> frame;
+ std::vector<std::string> scopes; // Demo::pushScope: panels drawn inside the shell's trays and drop-downs
};
ItemTable& items() {
static ItemTable t;
@@ -55,7 +57,7 @@ void ImGuiTestEngineHook_ItemAdd(ImGuiContext* ctx, ImGuiID id, const ImRect& bb
if (id && ctx && ctx->CurrentWindow && !ctx->CurrentWindow->IDStack.empty()) {
std::string window = ctx->CurrentWindow->RootWindow->Name; // a child (list, table) counts as its panel
if (const size_t hash = window.find("##"); hash != std::string::npos) window.resize(hash);
- items().frame.push_back({id, ctx->CurrentWindow->IDStack.back(), std::move(window), {bb, clip}});
+ items().frame.push_back({id, ctx->CurrentWindow->IDStack.back(), std::move(window), {bb, clip}, items().scopes});
}
}
@@ -68,9 +70,21 @@ void ImGuiTestEngineHook_ItemInfo(ImGuiContext* ctx, ImGuiID id, const char* lab
auto add = [&](const std::string& key) {
items().byLabel[key] = it->second;
if (!window.empty()) items().byLabel[window + "/" + key] = it->second;
+ for (const auto& scope : items().scopes) items().byLabel[scope + "/" + key] = it->second;
};
add(text);
if (const size_t hash = text.find("##"); hash != std::string::npos && hash > 0) add(text.substr(0, hash));
+ // Labels that start with an icon (ICON_LC_*: UTF-8 private-use characters, U+E000-U+F8FF) are also found
+ // by their words: "AI Brush" for "<sparkles> AI Brush".
+ if (text.size() > 3 && static_cast<unsigned char>(text[0]) == 0xEE) {
+ size_t start = 3;
+ while (start < text.size() && text[start] == ' ') ++start;
+ const std::string words = text.substr(start);
+ if (!words.empty() && words.compare(0, 2, "##") != 0) {
+ add(words);
+ if (const size_t hash = words.find("##"); hash != std::string::npos && hash > 0) add(words.substr(0, hash));
+ }
+ }
}
void ImGuiTestEngineHook_Log(ImGuiContext*, const char*, ...) {}
@@ -100,6 +114,13 @@ glm::vec3 onSphere(float latDeg, float lonDeg, float r = 1.0f) {
void Demo::beginFrame() {
items().byLabel.clear();
items().frame.clear();
+ items().scopes.clear();
+}
+
+void Demo::pushScope(const char* name) { items().scopes.emplace_back(name); }
+
+void Demo::popScope() {
+ if (!items().scopes.empty()) items().scopes.pop_back();
}
std::vector<std::string> Demo::similarItems(const std::string& label) {
@@ -131,7 +152,9 @@ bool Demo::findItem(const std::string& label, ImVec2& center, bool* visible, ImV
name = label.substr(slash + 1);
}
for (auto s = items().frame.rbegin(); s != items().frame.rend(); ++s) {
- if (!window.empty() && s->window != window) continue;
+ if (!window.empty() && s->window != window &&
+ std::find(s->scopes.begin(), s->scopes.end(), window) == s->scopes.end())
+ continue;
if (ImHashStr(name.c_str(), 0, s->seed) == s->id) return found(s->placed);
}
return false;
@@ -199,11 +222,10 @@ void Demo::mouseButton(bool down, int button) {
}
ImVec2 Demo::project(const glm::vec3& p) const {
- int w = 0, h = 0;
- SDL_GetWindowSize(app_.window_, &w, &h);
+ const CanvasRect r = app_.canvasRect();
const glm::vec4 c = app_.camera_.projection() * app_.camera_.view() * glm::vec4(p, 1.0f);
const glm::vec2 ndc = glm::vec2(c) / c.w;
- return ImVec2((ndc.x * 0.5f + 0.5f) * float(w), (0.5f - ndc.y * 0.5f) * float(h));
+ return ImVec2(r.x + (ndc.x * 0.5f + 0.5f) * r.w, r.y + (0.5f - ndc.y * 0.5f) * r.h);
}
ImVec2 Demo::onModel(float u, float v) const {
@@ -252,7 +274,10 @@ void Demo::moveToItem(const std::string& label, float seconds) {
auto from = std::make_shared<ImVec2>();
steps_.push_back([this, label, seconds, from](float t) {
ImVec2 to;
- if (!findItem(label, to)) return t > 3.0f; // not on screen yet: give the UI a moment
+ if (!findItem(label, to)) { // not on screen yet: give the UI a moment
+ if (t > 3.0f) SDL_Log("Demo: no UI item \"%s\" to move to", label.c_str());
+ return t > 3.0f;
+ }
if (t == 0.0f || (from->x == 0 && from->y == 0)) *from = mouse_;
const float u = smooth(t / seconds);
mouseMotion(from->x + (to.x - from->x) * u, from->y + (to.y - from->y) * u);
@@ -436,6 +461,9 @@ void Demo::buildShowcase() {
run([this, k] {
app_.radiusPx_ = 70.0f * k;
app_.strength_ = 0.9f;
+ // Custom brushes sit on the bottom shelf next to the built-in ones.
+ auto& shelf = app_.layout_.bottomShelf;
+ shelf.insert(std::find(shelf.begin(), shelf.end(), "widget.add_brush"), "recipe:Edge Wear");
});
click("Edge Wear");
stroke(line(0.16f, 0.30f, 0.20f, 0.70f), 1.4f);
@@ -487,7 +515,7 @@ void Demo::buildSculpt() {
// Horns: drag the upper skull out with the Move brush (mirrored by symmetry).
run([this, k] { app_.radiusPx_ = 110.0f * k; });
- click("4 Move");
+ click("Move##brush.move");
stroke(pull(52, -38, -150 * k, -170 * k), 1.6f);
run([this, k] { app_.radiusPx_ = 70.0f * k; });
stroke(pull(70, -48, -140 * k, -150 * k), 1.3f);
@@ -495,7 +523,7 @@ void Demo::buildSculpt() {
// Heavy brow and cheekbones with Clay.
run([this, k] { app_.radiusPx_ = 62.0f * k; });
- click("2 Clay");
+ click("Clay##brush.clay");
for (int pass = 0; pass < 3; ++pass) stroke(arc(24, -52, 30, -4), 0.9f);
for (int pass = 0; pass < 2; ++pass) stroke(arc(-14, -58, -6, -24), 0.9f);
@@ -504,23 +532,23 @@ void Demo::buildSculpt() {
app_.radiusPx_ = 40.0f * k;
app_.strength_ = 0.9f;
});
- click("1 Standard");
+ click("Standard##brush.standard");
stroke(arc(10, -30, 10, -16), 0.7f, true);
stroke(arc(6, -32, 6, -14), 0.7f, true);
// Turn to the side and pull a snout forward.
orbit(-330.0f * k, 0.0f, 1.6f);
run([this, k] { app_.radiusPx_ = 120.0f * k; });
- click("4 Move");
+ click("Move##brush.move");
stroke(pull(-14, 0, -190 * k, 30 * k), 1.6f);
orbit(250.0f * k, 0.0f, 1.4f);
// Nostrils and a mouth line.
run([this, k] { app_.radiusPx_ = 30.0f * k; });
- click("6 Crease");
+ click("Crease##brush.crease");
stroke(arc(-36, -30, -33, 0), 1.0f, true);
run([this, k] { app_.radiusPx_ = 34.0f * k; });
- click("5 Inflate");
+ click("Inflate##brush.inflate");
stroke(arc(-6, -10, -4, -6), 0.5f);
// Soften.
@@ -528,7 +556,7 @@ void Demo::buildSculpt() {
app_.radiusPx_ = 80.0f * k;
app_.strength_ = 0.35f;
});
- click("3 Smooth");
+ click("Smooth##brush.smooth");
stroke(arc(-45, -60, 45, -60), 1.0f);
caption("Smooth, fast and scriptable", "Unlimited undo, layers, voxel remesh, one-click LODs", 5.0f);
orbit(-760.0f * k, 30.0f * k, 6.0f);
@@ -569,7 +597,7 @@ void Demo::buildImageTo3D() {
app_.radiusPx_ = 55.0f;
app_.symmetry_.x = true;
});
- click("2 Clay");
+ click("Clay##brush.clay");
stroke([this](float u) { return project(glm::vec3(-0.25f + 0.15f * u, 0.15f - 0.3f * u, 0.38f)); }, 1.2f);
orbit(-260.0f, 30.0f, 2.5f);
}
@@ -579,8 +607,6 @@ void Demo::buildBrushLab() {
app_.runCommand("new_plane", {{"resolution", 320.0}});
app_.runCommand("subdivide");
app_.showBrushLab_ = true;
- app_.showGamePanel_ = false;
- app_.showLayersPanel_ = false;
app_.camera_.yaw = glm::radians(-20.0f);
app_.camera_.pitch = glm::radians(-50.0f);
app_.camera_.distance *= 0.62f;
@@ -624,12 +650,13 @@ void Demo::buildGameReady() {
app_.camera_.pitch = glm::radians(-6.0f);
app_.camera_.distance *= 0.85f;
std::snprintf(app_.newLayerName_, sizeof app_.newLayerName_, "Grin");
+ app_.layout_.openSubpalettes = {"tool.layers", "tool.export"}; // the Tool palette's Layers and Export
});
caption("Built for game & animation pipelines", "Sculpt layers become blend shapes / morph targets", 4.0f);
click("+ Add");
const float k = float(app_.options_.height) / 1080.0f;
run([this, k] { app_.radiusPx_ = 70.0f * k; });
- click("4 Move");
+ click("Move##brush.move");
// Pull the mouth corners up and back into a grin, on the new layer only.
stroke([this, k](float u) {
const ImVec2 p = project(onSphere(-32.0f, -28.0f));
@@ -651,12 +678,12 @@ void Demo::buildGameReady() {
wait(1.0f);
click("LOD3");
wait(1.5f);
- click("Sculpt");
+ click("Game Ready/Sculpt");
run([this] { app_.renderSettings_.wireframe = false; });
caption("Send to Unreal Engine", "FBX with LODs and morph targets, straight into the editor", 4.5f);
- moveToItem("Send to Unreal", 0.8f);
+ moveToItem("Game Ready/Send to Unreal", 0.8f);
wait(1.5f);
- moveToItem("Export FBX for Unreal...", 0.6f);
+ moveToItem("Game Ready/Export FBX for Unreal...", 0.6f);
wait(1.0f);
caption("Plus glTF, USD/USDZ and OBJ", "Validated with the Khronos and OpenUSD tools", 3.5f);
orbit(500.0f * k, 0.0f, 3.5f);
@@ -666,19 +693,19 @@ void Demo::buildSplats() {
run([this] {
app_.openPath(app_.options_.demoAsset);
app_.showBrushLab_ = false;
- app_.showSplatsPanel_ = true;
+ app_.layout_.rightTray = {"splats", "tool"}; // the Splats palette first in the tray
app_.camera_.frame(app_.sceneBounds());
app_.camera_.yaw = glm::radians(-30.0f);
});
caption("Gaussian splats", "Turn a sculpt into splats for web viewers and engines", 4.0f);
wait(1.0f);
- click("Sculpt to splats");
- click("Show mesh");
+ click("Gaussian Splats/Sculpt to splats");
+ click("Gaussian Splats/Show mesh");
orbit(450.0f, 20.0f, 4.0f);
caption("And captures back into meshes", "Splat -> watertight, sculptable mesh in under a second", 4.0f);
- click("Convert to mesh");
- click("Show mesh");
- click("Show##splats");
+ click("Gaussian Splats/Convert to mesh");
+ click("Gaussian Splats/Show mesh");
+ click("Gaussian Splats/Show##splats");
orbit(-450.0f, -20.0f, 4.0f);
caption("Open standards", "PLY, .splat, glTF KHR_gaussian_splatting, OpenUSD ParticleField", 3.5f);
wait(2.0f);
diff --git a/src/app/Demo.h b/src/app/Demo.h
index ecb033c7..8e5a503f 100644
--- a/src/app/Demo.h
+++ b/src/app/Demo.h
@@ -45,6 +45,10 @@ public:
// "Window/label" picks the item in one window).
bool findItem(const std::string& label, ImVec2& center, bool* visible = nullptr, ImVec4* clip = nullptr) const;
static void beginFrame(); // clears the item table (called before ImGui::NewFrame)
+ // Items drawn between these are also found as "NAME/label" (palettes in the shell's trays and drop-downs,
+ // whose ImGui window is the tray, keep their panel names: "SubTools/Append").
+ static void pushScope(const char* name);
+ static void popScope();
static std::vector<std::string> similarItems(const std::string& label); // for test failure messages
// UI tests (UiTest.cpp). Steps that fail stop the run; failures() lists why.
diff --git a/src/app/Palettes.cpp b/src/app/Palettes.cpp
new file mode 100644
index 00000000..3ce426a6
--- /dev/null
+++ b/src/app/Palettes.cpp
@@ -0,0 +1,437 @@
+// 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/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]);
+ }
+}
+
+// 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)) {
+ // 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() {
+ 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"});
+ 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.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"});
+ 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"});
+ actionRow(*this, {"view.frame", "subtool.solo"});
+ actionRow(*this, {"view.polyf"});
+}
+
+} // namespace sf
diff --git a/src/app/PanelBrushes.cpp b/src/app/PanelBrushes.cpp
index 2116a7b5..cccfefdd 100644
--- a/src/app/PanelBrushes.cpp
+++ b/src/app/PanelBrushes.cpp
@@ -4,6 +4,9 @@
// Brush options panel (stroke type, lazy mouse, spray, alpha) and the
// stroke handling of the SnakeHook brush and the DragRect stroke.
#include "app/App.h"
+#include "app/Ui.h"
+
+#include <iterator>
#include <algorithm>
#include <cmath>
@@ -28,73 +31,110 @@ glm::vec3 App::screenUpVector(float angle) const {
return q * glm::vec3(-std::sin(angle), std::cos(angle), 0.0f);
}
-void App::drawBrushOptions() {
+void App::pollAlphaFile() {
std::string alphaPath;
{
std::lock_guard lock(alphaMutex_);
alphaPath.swap(pendingAlphaPath_);
}
if (!alphaPath.empty()) runCommand("brush_set_alpha", {{"path", alphaPath}, {"invert", alphaInvert_}});
+}
- ImGui::SeparatorText("Stroke");
- ImGui::SetNextItemWidth(-1);
- if (ImGui::BeginCombo("##stroke", strokeTypeName(strokeType_))) {
- for (int i = 0; i < int(StrokeType::Count); ++i)
- if (ImGui::Selectable(strokeTypeName(StrokeType(i)), strokeType_ == StrokeType(i))) strokeType_ = StrokeType(i);
- ImGui::EndCombo();
+// Stroke palette (and the stroke picker's settings): how dabs follow the cursor.
+void App::drawStrokeSection() {
+ static const char* const kHelp[] = {
+ "Even dabs along the path.",
+ "Click and drag one stamp: the drag's length is the size, its direction the rotation.",
+ "Scattered dabs of random size and strength.",
+ "The brush trails the cursor on a string, for smooth lines.",
+ };
+ const ImGuiStyle& style = ImGui::GetStyle();
+ const float half = (ImGui::GetContentRegionAvail().x - style.ItemSpacing.x) * 0.5f;
+ for (int i = 0; i < int(StrokeType::Count); ++i) {
+ const bool on = strokeType_ == StrokeType(i);
+ if (on) {
+ ImGui::PushStyleColor(ImGuiCol_Button, style.Colors[ImGuiCol_SliderGrab]);
+ ImGui::PushStyleColor(ImGuiCol_ButtonHovered, style.Colors[ImGuiCol_SliderGrabActive]);
+ ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1, 1, 1, 1));
+ }
+ if (i % 2) ImGui::SameLine();
+ if (ImGui::Button((std::string(strokeTypeName(StrokeType(i))) + "##stroke").c_str(), ImVec2(half, 0)))
+ strokeType_ = StrokeType(i);
+ if (on) ImGui::PopStyleColor(3);
+ ui::HelpText(strokeTypeName(StrokeType(i)), nullptr, kHelp[i < int(std::size(kHelp)) ? i : 0], "Stroke");
}
- if (ImGui::IsItemHovered())
- ImGui::SetTooltip("Dots: even dabs along the path\nDragRect: click-drag one stamp (length = size, direction = "
- "rotation)\nSpray: scattered dabs of random size and strength\nLazyMouse: the brush trails the "
- "cursor for smooth lines");
if (strokeType_ == StrokeType::Spray) {
ImGui::SetNextItemWidth(-1);
- ImGui::SliderFloat("##scatter", &sprayScatter_, 0.0f, 2.0f, "scatter %.2f");
+ ui::SliderInside("##scatter", &sprayScatter_, 0.0f, 2.0f, "Scatter %.2f");
+ ui::HelpText("Scatter", nullptr, "How far spray dabs jump from the path, as a fraction of the brush size.", "Stroke");
} else if (strokeType_ == StrokeType::LazyMouse) {
ImGui::SetNextItemWidth(-1);
- ImGui::SliderFloat("##lazy", &lazyMouse_.radius, 1.0f, 300.0f, "lazy radius %.0f px");
+ ui::SliderInside("##lazy", &lazyMouse_.radius, 1.0f, 300.0f, "Lazy Radius %.0f px");
+ ui::HelpText("Lazy Radius", nullptr, "Length of the string the brush is pulled on; longer = smoother lines.", "Stroke");
}
+}
- ImGui::SeparatorText("Alpha");
+// Alpha palette: the stamp that shapes the brush (ZBrush alpha).
+void App::drawAlphaSection() {
const BrushAlpha& alpha = doc_.brushAlpha;
- const float preview = ImGui::GetFrameHeight() * 2.0f;
- {
- // Thumbnail of the stamp.
- const ImVec2 p0 = ImGui::GetCursorScreenPos();
- ImDrawList* dl = ImGui::GetWindowDrawList();
- constexpr int kCells = 20;
- const float cell = preview / kCells;
- 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(alpha.sample(u, v), 0.0f, 1.0f) * 255.0f);
- dl->AddRectFilled(ImVec2(p0.x + x * cell, p0.y + y * cell), ImVec2(p0.x + (x + 1) * cell, p0.y + (y + 1) * cell),
- IM_COL32(g, g, g, 255));
+ const float s = uiScale_;
+ auto preview = [](ImDrawList* dl, const BrushAlpha& a, ImVec2 p0, float size, int cells) {
+ const float cell = size / float(cells);
+ dl->AddRectFilled(p0, ImVec2(p0.x + size, p0.y + size), IM_COL32(0, 0, 0, 255), 3.0f);
+ for (int y = 0; y < cells; ++y)
+ for (int x = 0; x < cells; ++x) {
+ const float u = (float(x) + 0.5f) / float(cells) * 2.0f - 1.0f, v = 1.0f - (float(y) + 0.5f) / float(cells) * 2.0f;
+ const int g = int(std::clamp(a.sample(u, v), 0.0f, 1.0f) * 255.0f);
+ if (g < 3) continue;
+ dl->AddRectFilled(ImVec2(p0.x + float(x) * cell, p0.y + float(y) * cell),
+ ImVec2(p0.x + float(x + 1) * cell + 0.5f, p0.y + float(y + 1) * cell + 0.5f), IM_COL32(g, g, g, 255));
}
- ImGui::Dummy(ImVec2(preview, preview));
- }
- ImGui::SameLine();
- ImGui::BeginGroup();
- ImGui::SetNextItemWidth(-1);
- if (ImGui::BeginCombo("##alpha", alpha.name.c_str())) {
- for (const char* name : {"Round", "Square", "Noise"})
- if (ImGui::Selectable(name, alpha.name == name)) runCommand("brush_set_alpha", {{"name", std::string(name)}});
- ImGui::EndCombo();
+ };
+ // Large preview of the current alpha, with its name.
+ const float big = std::min(128.0f * s, ImGui::GetContentRegionAvail().x);
+ ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (ImGui::GetContentRegionAvail().x - big) * 0.5f);
+ const ImVec2 p0 = ImGui::GetCursorScreenPos();
+ ImGui::Dummy(ImVec2(big, big));
+ if (ImTextureID tex = thumbs_.alpha(alpha))
+ ImGui::GetWindowDrawList()->AddImage(tex, p0, ImVec2(p0.x + big, p0.y + big));
+ else
+ preview(ImGui::GetWindowDrawList(), alpha, p0, big, 40);
+ const ImVec2 nameSize = ImGui::CalcTextSize(alpha.name.c_str());
+ ImGui::SetCursorPosX(ImGui::GetCursorPosX() + (ImGui::GetContentRegionAvail().x - nameSize.x) * 0.5f);
+ ImGui::TextUnformatted(alpha.name.c_str());
+
+ // Built-in alphas as small tiles.
+ static const BrushAlpha kBuiltins[] = {BrushAlpha::round(), BrushAlpha::square(), BrushAlpha::noise()};
+ const float tile = 52.0f * s;
+ for (int i = 0; i < 3; ++i) {
+ const BrushAlpha& a = kBuiltins[i];
+ if (i) ImGui::SameLine();
+ ImGui::PushID(i);
+ const ImVec2 t0 = ImGui::GetCursorScreenPos();
+ if (ImGui::InvisibleButton((a.name + "##alpha").c_str(), ImVec2(tile, tile)))
+ runCommand("brush_set_alpha", {{"name", a.name}});
+ ImDrawList* dl = ImGui::GetWindowDrawList();
+ if (ImTextureID tex = thumbs_.alpha(a)) dl->AddImage(tex, t0, ImVec2(t0.x + tile, t0.y + tile));
+ else preview(dl, a, t0, tile, 20);
+ if (alpha.name == a.name || ImGui::IsItemHovered())
+ dl->AddRect(t0, ImVec2(t0.x + tile, t0.y + tile), ImGui::GetColorU32(ImGuiCol_SliderGrab, alpha.name == a.name ? 1.0f : 0.6f),
+ 3.0f, 0, 2.0f * s);
+ ui::HelpText(a.name.c_str(), nullptr, "Use this built-in alpha.", "Alpha");
+ ImGui::PopID();
}
- if (ImGui::Button("Load image...", ImVec2(-1, 0)))
+ if (ImGui::Button("Load image...##alpha", ImVec2(-1, 0)))
SDL_ShowOpenFileDialog(onAlphaChosen, this, window_, kAlphaFilters, 2, nullptr, false);
- if (ImGui::IsItemHovered()) ImGui::SetTooltip("Grayscale image: white = full effect, black = none");
- ImGui::EndGroup();
+ ui::HelpText("Load image", nullptr, "Use a grayscale image as the alpha: white = full effect, black = none.", "Alpha");
ImGui::Checkbox("Invert loaded image", &alphaInvert_);
+ ui::HelpText("Invert loaded image", nullptr, "Swap black and white when loading an image as an alpha.", "Alpha");
}
// SnakeHook: pull the region under the click along with the cursor, like Move,
// but re-centred on the pulled tip every step so it can be dragged out into horns.
void App::snakeHookTo(float x, float y) {
- int w = 0, h = 0;
- SDL_GetWindowSize(window_, &w, &h);
+ const float h = canvasHeight();
glm::vec3 origin, dir;
- camera_.screenRay(x, y, float(w), float(h), origin, dir);
+ canvasRay(x, y, origin, dir);
const glm::vec3 n = camera_.forward();
const float denom = glm::dot(dir, n);
if (std::abs(denom) < 1e-6f) return;
@@ -103,7 +143,7 @@ void App::snakeHookTo(float x, float y) {
const float pressure = lastInputPen_ ? std::clamp(penPressure_, 0.0f, 1.0f) : 1.0f;
DabParams p;
p.viewDir = n;
- p.radius = radiusPx_ * (pressureSize_ ? std::max(pressure, 0.05f) : 1.0f) * camera_.worldPerPixel(grabLast_, float(h));
+ p.radius = radiusPx_ * (pressureSize_ ? std::max(pressure, 0.05f) : 1.0f) * camera_.worldPerPixel(grabLast_, h);
p.strength = strength_;
p.pressure = pressureStrength_ ? pressure : 1.0f;
p.invert = strokeInvert_;
@@ -126,15 +166,13 @@ void App::dragRectTo(float x, float y) {
const glm::vec2 drag = glm::vec2(x, y) - dragAnchor_;
const float len = glm::length(drag);
if (len < 2.0f) return;
- int w = 0, h = 0;
- SDL_GetWindowSize(window_, &w, &h);
const glm::quat q = camera_.orientation();
const float pressure = lastInputPen_ ? std::clamp(penPressure_, 0.0f, 1.0f) : 1.0f;
DabParams p;
p.center = dragAnchorHit_;
p.viewDir = camera_.forward();
- p.radius = len * camera_.worldPerPixel(dragAnchorHit_, float(h));
+ p.radius = len * camera_.worldPerPixel(dragAnchorHit_, canvasHeight());
p.strength = strength_;
p.pressure = pressureStrength_ ? pressure : 1.0f;
p.invert = strokeInvert_;
diff --git a/src/app/PanelMasking.cpp b/src/app/PanelMasking.cpp
index 32d11163..13a73272 100644
--- a/src/app/PanelMasking.cpp
+++ b/src/app/PanelMasking.cpp
@@ -5,6 +5,7 @@
// "Masking" section of the Tools panel. The operations themselves are the
// mask_* commands (core/Masking.cpp).
#include "app/App.h"
+#include "app/Ui.h"
#include <algorithm>
#include <cmath>
@@ -54,12 +55,11 @@ void App::maskCanvasRelease() {
}
void App::drawMaskingSection() {
- ImGui::SeparatorText("Masking");
ImGui::Checkbox("Show mask", &renderSettings_.showMask);
ImGui::SameLine();
ImGui::TextDisabled("(Ctrl paints, Ctrl+Alt erases)");
ImGui::SetNextItemWidth(-1);
- ImGui::SliderFloat("##maskstrength", &maskStrength_, 0.01f, 1.0f, "mask strength %.2f");
+ ui::SliderInside("##maskstrength", &maskStrength_, 0.01f, 1.0f, "Mask Strength %.2f");
const ImGuiStyle& style = ImGui::GetStyle();
const float third = (ImGui::GetContentRegionAvail().x - 2 * style.ItemSpacing.x) / 3.0f;
diff --git a/src/app/PanelPolygroups.cpp b/src/app/PanelPolygroups.cpp
index 48ba41d3..4471c8c2 100644
--- a/src/app/PanelPolygroups.cpp
+++ b/src/app/PanelPolygroups.cpp
@@ -46,9 +46,8 @@ bool App::polygroupMouseDown(float x, float y, SDL_Keymod mod) {
void App::polygroupMouseUp() {
hideRectActive_ = false;
const bool alt = (SDL_GetModState() & SDL_KMOD_ALT) != 0;
- int w = 0, h = 0;
- SDL_GetWindowSize(window_, &w, &h);
- if (w <= 0 || h <= 0) return;
+ const CanvasRect c = canvasRect();
+ if (c.w <= 0.0f || c.h <= 0.0f) return;
if (std::abs(mouseX_ - hideRectX_) < kClickSlopPx && std::abs(mouseY_ - hideRectY_) < kClickSlopPx) {
// Click: isolate the group under the cursor (again: invert), Alt hides it,
@@ -67,7 +66,7 @@ void App::polygroupMouseUp() {
}
// Drag: rectangle in normalised device coordinates (y up).
- auto ndc = [&](float px, float py) { return glm::vec2(px / float(w) * 2.0f - 1.0f, 1.0f - py / float(h) * 2.0f); };
+ auto ndc = [&](float px, float py) { return glm::vec2((px - c.x) / c.w * 2.0f - 1.0f, 1.0f - (py - c.y) / c.h * 2.0f); };
const glm::vec2 a = ndc(hideRectX_, hideRectY_), b = ndc(mouseX_, mouseY_);
runCommand("hide_rect", {{"x0", double(a.x)},
{"y0", double(a.y)},
@@ -92,7 +91,6 @@ void App::drawPolygroupOverlay() {
}
void App::drawPolygroupsSection() {
- ImGui::SeparatorText("Polygroups");
ImGui::Checkbox("Show polygroups", &renderSettings_.showPolygroups);
ImGui::SameLine();
const Mesh& m = doc_.mesh;
@@ -125,7 +123,10 @@ void App::drawPolygroupsSection() {
if (ImGui::Button("Merge visible", ImVec2(half, 0))) group("polygroup_merge_visible");
ImGui::SameLine();
if (ImGui::Button("Clear groups", ImVec2(half, 0))) runCommand("polygroup_clear");
+}
+void App::drawVisibilitySection() {
+ const float half = (ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x) * 0.5f;
ImGui::BeginDisabled(!doc_.mesh.hasHidden());
if (ImGui::Button("Show all", ImVec2(half, 0))) runCommand("show_all");
ImGui::EndDisabled();
diff --git a/src/app/PanelPolypaint.cpp b/src/app/PanelPolypaint.cpp
index a86c165e..3a2dc0cc 100644
--- a/src/app/PanelPolypaint.cpp
+++ b/src/app/PanelPolypaint.cpp
@@ -4,6 +4,7 @@
// Polypaint & Materials panel: the Paint brush (ZBrush Rgb / Zadd), colour
// picker and swatches, fills, and the viewport MatCap material picker.
#include "app/App.h"
+#include "app/Ui.h"
#include "core/Matcap.h"
#include "core/Polypaint.h"
@@ -69,23 +70,14 @@ void App::pickColorUnderCursor() {
status_ = "Paint colour " + colorToHex(doc_.paintColor);
}
-void App::drawPolypaintPanel() {
- const float scale = uiScale_;
- const ImGuiViewport* vp = ImGui::GetMainViewport();
- ImGui::SetNextWindowPos(ImVec2(vp->Pos.x + 270 * scale, vp->Pos.y + 34 * scale), ImGuiCond_FirstUseEver);
- if (!beginPanel("Polypaint & Materials", &showPolypaintPanel_, 250 * scale)) {
- ImGui::End();
- return;
- }
-
+// Color palette: the Paint brush (ZBrush Rgb / Zadd), the colour, swatches and fills.
+void App::drawPalette_Color() {
ImGui::SeparatorText("Paint");
const bool painting = paintMode_;
if (painting) ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyleColorVec4(ImGuiCol_ButtonActive));
if (ImGui::Button("Paint brush (P)", ImVec2(-1, 0))) paintMode_ = !paintMode_;
if (painting) ImGui::PopStyleColor();
- if (ImGui::IsItemHovered())
- ImGui::SetTooltip("Paint colour without sculpting. Size, strength, pressure and symmetry come from Tools;\n"
- "Alt paints back to white, Shift smooths the surface, masked areas are protected.");
+ ui::HelpAction(*this, "draw.paint");
ImGui::Checkbox("RGB while sculpting", &paintRgb_);
if (ImGui::IsItemHovered()) ImGui::SetTooltip("Sculpt brushes also paint the colour (ZBrush Rgb with Zadd)");
@@ -128,34 +120,49 @@ void App::drawPolypaintPanel() {
if (ImGui::Button("Clear", ImVec2(half, 0))) runCommand("paint_clear");
ImGui::EndDisabled();
ImGui::Checkbox("Show polypaint", &renderSettings_.showPolypaint);
+}
- ImGui::SeparatorText("Material");
+// Material palette grid: Studio plus every MatCap, `tile` px square.
+void App::drawMaterialGrid(float tile) {
+ const float scale = uiScale_;
const float spacing = ImGui::GetStyle().ItemSpacing.x;
- const float tile = (ImGui::GetContentRegionAvail().x - 3 * spacing) / 4.0f;
+ const int columns = std::max(1, int((ImGui::GetContentRegionAvail().x + spacing) / (tile + spacing)));
+ tile = (ImGui::GetContentRegionAvail().x - float(columns - 1) * spacing) / float(columns);
auto outline = [&](bool selected) {
- if (!selected) return;
+ if (!selected && !ImGui::IsItemHovered()) return;
ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(),
- ImGui::GetColorU32(ImGuiCol_ButtonActive), 4.0f, 0, 2.0f * scale);
+ ImGui::GetColorU32(ImGuiCol_SliderGrab, selected ? 1.0f : 0.6f), 4.0f, 0,
+ 2.0f * scale);
};
- if (ImGui::Button("Studio", ImVec2(tile, tile))) renderSettings_.matcap = -1;
- if (ImGui::IsItemHovered()) ImGui::SetTooltip("Studio lights with the Tools material colour");
+ if (ImGui::Button("Studio##material", ImVec2(tile, tile))) renderSettings_.matcap = -1;
+ ui::HelpText("Studio", nullptr, "Studio lights with the base colour below (polypaint shows on top).", "Material");
outline(renderSettings_.matcap < 0);
for (int i = 0; i < matcapCount(); ++i) {
- if ((i + 1) % 4 != 0) ImGui::SameLine();
+ if ((i + 1) % columns != 0) ImGui::SameLine();
const GLuint tex = renderer_.matcapTexture(i);
if (!tex) continue;
ImGui::PushID(i);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(0, 0));
// Textures are stored bottom-up: flip V for display.
- if (ImGui::ImageButton("##matcap", ImTextureID(uintptr_t(tex)), ImVec2(tile, tile), ImVec2(0, 1), ImVec2(1, 0)))
+ ImTextureID thumb = thumbs_.material(i);
+ if (ImGui::ImageButton(matcapName(i), thumb ? thumb : ImTextureID(uintptr_t(tex)), ImVec2(tile, tile),
+ thumb ? ImVec2(0, 0) : ImVec2(0, 1), thumb ? ImVec2(1, 1) : ImVec2(1, 0)))
renderSettings_.matcap = i;
ImGui::PopStyleVar();
ImGui::PopID();
+ ui::HelpText(matcapName(i), nullptr, "MatCap material: lighting baked into a sphere picture. Polypaint multiplies it.",
+ "Material");
if (ImGui::IsItemHovered()) ImGui::SetTooltip("%s", matcapName(i));
outline(renderSettings_.matcap == i);
}
+}
+
+// Material palette: the material grid and the studio material's colour.
+void App::drawPalette_Material() {
+ drawMaterialGrid(54.0f * uiScale_);
ImGui::Text("%s", renderSettings_.matcap < 0 ? "Studio" : matcapName(renderSettings_.matcap));
- ImGui::End();
+ ImGui::ColorEdit3("Base colour", &renderSettings_.baseColor.x, ImGuiColorEditFlags_NoInputs);
+ ui::HelpText("Base colour", nullptr, "Colour of the Studio material (the clay colour).", "Material");
}
} // namespace sf
diff --git a/src/app/PanelSubTools.cpp b/src/app/PanelSubTools.cpp
index 3fb6eb86..c7e4ed9e 100644
--- a/src/app/PanelSubTools.cpp
+++ b/src/app/PanelSubTools.cpp
@@ -58,10 +58,8 @@ void drawEye(ImDrawList* dl, ImVec2 c, float size, bool open, ImU32 col) {
} // namespace
int App::pickSubtool(float x, float y, RayHit* out) {
- int w = 0, h = 0;
- SDL_GetWindowSize(window_, &w, &h);
glm::vec3 origin, dir;
- camera_.screenRay(x, y, float(w), float(h), origin, dir);
+ canvasRay(x, y, origin, dir);
int best = -1;
RayHit nearest;
for (int i = 0; i < doc_.subtoolCount(); ++i) {
@@ -98,10 +96,8 @@ void App::subtoolClickMove(float x, float y) {
beginStroke(subtoolClickX_, subtoolClickY_, hit);
if (drag_ == Drag::Stroke) strokeTo(x, y);
} else {
- int w = 0, h = 0;
- SDL_GetWindowSize(window_, &w, &h);
drag_ = Drag::Pan;
- camera_.pan(x - subtoolClickX_, y - subtoolClickY_, float(h));
+ camera_.pan(x - subtoolClickX_, y - subtoolClickY_, canvasHeight());
}
}
@@ -111,15 +107,8 @@ void App::subtoolClickRelease() {
subtoolClickTarget_ = -1;
}
-void App::drawSubToolsPanel() {
+void App::drawSubToolsContents() {
const float scale = uiScale_;
- const ImGuiViewport* vp = ImGui::GetMainViewport();
- // First use: top right, beside the Layers and Game Ready column.
- ImGui::SetNextWindowPos(ImVec2(vp->Pos.x + vp->Size.x - 548 * scale, vp->Pos.y + 34 * scale), ImGuiCond_FirstUseEver);
- if (!beginPanel("SubTools", &showSubToolsPanel_, 250 * scale)) {
- ImGui::End();
- return;
- }
const int count = doc_.subtoolCount();
const int active = doc_.activeSubtool;
const ImGuiStyle& style = ImGui::GetStyle();
@@ -164,7 +153,7 @@ void App::drawSubToolsPanel() {
if (!s.visible) ImGui::PushStyleColor(ImGuiCol_Text, style.Colors[ImGuiCol_TextDisabled]);
if (ImGui::Selectable(s.name.c_str(), isActive,
ImGuiSelectableFlags_SpanAllColumns | ImGuiSelectableFlags_AllowOverlap |
- ImGuiSelectableFlags_AllowDoubleClick) &&
+ ImGuiSelectableFlags_AllowDoubleClick | ImGuiSelectableFlags_NoAutoClosePopups) &&
!isActive)
selectIndex = i;
if (!s.visible) ImGui::PopStyleColor();
@@ -323,7 +312,6 @@ void App::drawSubToolsPanel() {
if (ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenDisabled | ImGuiHoveredFlags_DelayNormal))
ImGui::SetTooltip("One SubTool per disconnected piece");
ImGui::TextDisabled("Alt+click a SubTool to select it");
- ImGui::End();
}
void App::drawSubToolPopups() {
diff --git a/src/app/Shell.cpp b/src/app/Shell.cpp
new file mode 100644
index 00000000..7ae6caea
--- /dev/null
+++ b/src/app/Shell.cpp
@@ -0,0 +1,1551 @@
+// 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("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) {
+ 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;
+ }
+ // 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_,
+ "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("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", "",
+ [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,
+ "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;
+}
+
+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;
+ 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));
+ 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)) {
+ 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;
+ std::memcpy(&item, p->Data, std::min(size_t(p->DataSize), sizeof item));
+ item.item[sizeof item.item - 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) {
+ 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));
+ 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 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::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();
+ }
+ ImGui::PopID();
+}
+
+void App::finishShelfDrag() {
+ const ImGuiPayload* payload = ImGui::GetDragDropPayload();
+ if (payload && payload->IsDataType("SF_UIITEM")) {
+ 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::HelpAction(*this, "color.fill");
+ ImGui::EndGroup();
+}
+
+} // namespace sf
diff --git a/src/app/Shell.h b/src/app/Shell.h
new file mode 100644
index 00000000..54e95d20
--- /dev/null
+++ b/src/app/Shell.h
@@ -0,0 +1,46 @@
+// 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);
+
+// Brush type of a "brush.<name>" action id, or -1.
+int brushTypeOfAction(std::string_view id);
+
+} // namespace sf
diff --git a/src/app/ShellGeometry.cpp b/src/app/ShellGeometry.cpp
new file mode 100644
index 00000000..7c95f5a5
--- /dev/null
+++ b/src/app/ShellGeometry.cpp
@@ -0,0 +1,69 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+#include "app/ShellGeometry.h"
+
+#include <algorithm>
+
+namespace sf {
+
+using namespace shell;
+
+float trayWidth(float stored, float logicalWindowWidth) {
+ if (stored == 300.0f && logicalWindowWidth >= kWideWidth) return 320.0f;
+ return std::clamp(stored, kTrayMinW, kTrayMaxW);
+}
+
+ShellGeometry computeShell(const UiLayout& l, float W, float H, float s) {
+ ShellGeometry g;
+ g.scale = s;
+ const float logicalW = s > 0.0f ? W / s : W;
+ g.narrow = logicalW < kNarrowWidth;
+ g.shelves = l.shelvesVisible;
+
+ g.title = {0, 0, W, kTitleH * s};
+ const float barH = l.paletteBarVisible ? kPaletteBarH * s : 0.0f;
+ g.paletteBar = {0, g.title.h, W, barH};
+ const float top = g.title.h + barH;
+
+ float left = 0.0f, right = W; // the span between the dividers
+ if (g.shelves) {
+ const float lw = l.leftTrayOpen ? trayWidth(l.leftTrayWidth, logicalW) * s : 0.0f;
+ const float rw = l.rightTrayOpen && !g.narrow ? trayWidth(l.rightTrayWidth, logicalW) * s : 0.0f;
+ const float dw = kDividerW * s;
+ g.leftTray = {0, top, lw, H - top};
+ g.leftDivider = {lw, top, dw, H - top};
+ g.rightTray = {W - rw, top, rw, H - top};
+ g.rightDivider = {W - rw - dw, top, dw, H - top};
+ left = lw + dw;
+ right = W - rw - dw;
+ } else {
+ g.leftTray = {0, top, 0, H - top};
+ g.rightTray = {W, top, 0, H - top};
+ g.leftDivider = {0, top, 0, H - top};
+ g.rightDivider = {W, top, 0, H - top};
+ }
+ const float span = std::max(0.0f, right - left);
+
+ const float topH = g.shelves ? kTopShelfH * s : 0.0f;
+ const float bottomH = g.shelves ? kBottomShelfH * s : 0.0f;
+ g.topShelf = {left, top, span, topH};
+ g.bottomShelf = {left, H - bottomH, span, bottomH};
+ const float consoleH = l.consoleOpen ? std::clamp(l.consoleHeight, kConsoleMinH, kConsoleMaxH) * s : 0.0f;
+ g.console = {left, g.bottomShelf.y - consoleH, span, consoleH};
+
+ const float y0 = top + topH, y1 = std::max(y0, g.console.y);
+ const float leftW = g.shelves ? (g.narrow ? kLeftShelfNarrowW : kLeftShelfW) * s : 0.0f;
+ const float rightW = g.shelves ? kRightShelfW * s : 0.0f;
+ g.leftShelf = {left, y0, leftW, y1 - y0};
+ g.rightShelf = {right - rightW, y0, rightW, y1 - y0};
+ g.canvas = {left + leftW, y0, std::max(1.0f, span - leftW - rightW), std::max(1.0f, y1 - y0)};
+
+ if (l.leftHanded) { // Nomad's mirrored layout: everything swaps sides
+ for (CanvasRect* r : {&g.topShelf, &g.leftShelf, &g.rightShelf, &g.bottomShelf, &g.console, &g.leftDivider,
+ &g.rightDivider, &g.leftTray, &g.rightTray, &g.canvas})
+ r->x = W - r->x - r->w;
+ }
+ return g;
+}
+
+} // namespace sf
diff --git a/src/app/ShellGeometry.h b/src/app/ShellGeometry.h
new file mode 100644
index 00000000..be642245
--- /dev/null
+++ b/src/app/ShellGeometry.h
@@ -0,0 +1,39 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// Where every region of the ZBrush-style shell goes for a window size: title
+// strip, palette bar, the four shelves around the canvas, the console, the tray
+// dividers and trays. Pure arithmetic (no ImGui), so it can be unit tested and
+// used by input handling before a frame is drawn. See docs/ui-design.md §2.
+#pragma once
+
+#include "app/UiLayout.h"
+
+namespace sf {
+
+struct ShellGeometry {
+ CanvasRect title, paletteBar;
+ CanvasRect topShelf, leftShelf, rightShelf, bottomShelf;
+ CanvasRect console; // h 0 when closed
+ CanvasRect leftDivider, rightDivider; // w 0 when the shelves are hidden
+ CanvasRect leftTray, rightTray; // w 0 when closed
+ CanvasRect canvas; // the 3D view
+ bool narrow = false; // < 1280 logical px: right tray collapsed, smaller tiles
+ bool shelves = true; // shelves and trays shown (Tab hides them)
+ float scale = 1.0f;
+};
+
+// Logical sizes at scale 1 (docs/ui-design.md §2.1).
+namespace shell {
+constexpr float kTitleH = 24, kPaletteBarH = 22, kTopShelfH = 64, kLeftShelfW = 88, kLeftShelfNarrowW = 72;
+constexpr float kRightShelfW = 52, kBottomShelfH = 60, kDividerW = 8, kTrayMinW = 240, kTrayMaxW = 480;
+constexpr float kConsoleMinH = 100, kConsoleMaxH = 400, kNarrowWidth = 1280, kWideWidth = 1920;
+} // namespace shell
+
+// Effective tray width in logical px: the stored width, except that the standard 300 grows to 320 on
+// windows 1920 logical px wide or more.
+float trayWidth(float stored, float logicalWindowWidth);
+
+ShellGeometry computeShell(const UiLayout& layout, float width, float height, float scale);
+
+} // namespace sf
diff --git a/src/app/Theme.cpp b/src/app/Theme.cpp
new file mode 100644
index 00000000..8bc10d35
--- /dev/null
+++ b/src/app/Theme.cpp
@@ -0,0 +1,85 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+#include "app/Theme.h"
+
+namespace sf::theme {
+
+void applyStyle() {
+ ImGui::StyleColorsDark();
+ ImGuiStyle& s = ImGui::GetStyle();
+ s.WindowRounding = 0.0f; // shells; floating windows keep square corners too, like ZBrush
+ s.ChildRounding = 0.0f;
+ s.PopupRounding = 6.0f;
+ s.FrameRounding = 3.0f;
+ s.GrabRounding = 2.0f;
+ s.TabRounding = 3.0f;
+ s.ScrollbarRounding = 3.0f;
+ s.WindowBorderSize = 1.0f;
+ s.PopupBorderSize = 1.0f;
+ s.ChildBorderSize = 1.0f;
+ s.FrameBorderSize = 0.0f;
+ s.WindowPadding = ImVec2(8, 8);
+ s.FramePadding = ImVec2(6, 3);
+ s.ItemSpacing = ImVec2(4, 4);
+ s.ItemInnerSpacing = ImVec2(4, 4);
+ s.IndentSpacing = 14.0f;
+ s.ScrollbarSize = 10.0f;
+ s.GrabMinSize = 6.0f;
+ s.SeparatorTextBorderSize = 1.0f;
+ s.SeparatorTextPadding = ImVec2(10, 2);
+ s.WindowTitleAlign = ImVec2(0.0f, 0.5f);
+
+ ImVec4* c = s.Colors;
+ c[ImGuiCol_Text] = text;
+ c[ImGuiCol_TextDisabled] = textDim;
+ c[ImGuiCol_WindowBg] = rgb(0x252528, 0.98f);
+ c[ImGuiCol_ChildBg] = ImVec4(0, 0, 0, 0);
+ c[ImGuiCol_PopupBg] = rgb(0x252528, 0.98f);
+ c[ImGuiCol_Border] = rgb(0x3a3a3f, 0.9f);
+ c[ImGuiCol_BorderShadow] = ImVec4(0, 0, 0, 0);
+ c[ImGuiCol_FrameBg] = frame;
+ c[ImGuiCol_FrameBgHovered] = frameHover;
+ c[ImGuiCol_FrameBgActive] = rgb(0x3e3e44);
+ c[ImGuiCol_TitleBg] = header;
+ c[ImGuiCol_TitleBgActive] = rgb(0x333338);
+ c[ImGuiCol_TitleBgCollapsed] = header;
+ c[ImGuiCol_MenuBarBg] = shellBg;
+ c[ImGuiCol_ScrollbarBg] = rgb(0x1a1a1c, 0.6f);
+ c[ImGuiCol_ScrollbarGrab] = rgb(0x48484e);
+ c[ImGuiCol_ScrollbarGrabHovered] = rgb(0x58585f);
+ c[ImGuiCol_ScrollbarGrabActive] = accent;
+ c[ImGuiCol_CheckMark] = accent;
+ c[ImGuiCol_SliderGrab] = accent;
+ c[ImGuiCol_SliderGrabActive] = accentHover;
+ c[ImGuiCol_Button] = button;
+ c[ImGuiCol_ButtonHovered] = buttonHover;
+ c[ImGuiCol_ButtonActive] = buttonPressed;
+ c[ImGuiCol_Header] = rgb(0xf0882e, 0.55f);
+ c[ImGuiCol_HeaderHovered] = headerHover;
+ c[ImGuiCol_HeaderActive] = rgb(0xf0882e, 0.75f);
+ c[ImGuiCol_Separator] = rgb(0x3a3a3f);
+ c[ImGuiCol_SeparatorHovered] = accentHover;
+ c[ImGuiCol_SeparatorActive] = accent;
+ c[ImGuiCol_ResizeGrip] = rgb(0x48484e, 0.5f);
+ c[ImGuiCol_ResizeGripHovered] = accentHover;
+ c[ImGuiCol_ResizeGripActive] = accent;
+ c[ImGuiCol_Tab] = header;
+ c[ImGuiCol_TabHovered] = headerHover;
+ c[ImGuiCol_TabSelected] = rgb(0x45454b);
+ c[ImGuiCol_TabSelectedOverline] = accent;
+ c[ImGuiCol_TabDimmed] = header;
+ c[ImGuiCol_TabDimmedSelected] = rgb(0x3a3a3f);
+ c[ImGuiCol_PlotHistogram] = accent;
+ c[ImGuiCol_PlotHistogramHovered] = accentHover;
+ c[ImGuiCol_TableHeaderBg] = header;
+ c[ImGuiCol_TableBorderStrong] = rgb(0x3a3a3f);
+ c[ImGuiCol_TableBorderLight] = rgb(0x323236);
+ c[ImGuiCol_TableRowBg] = ImVec4(0, 0, 0, 0);
+ c[ImGuiCol_TableRowBgAlt] = rgb(0xffffff, 0.025f);
+ c[ImGuiCol_TextSelectedBg] = rgb(0xf0882e, 0.35f);
+ c[ImGuiCol_DragDropTarget] = accentHover;
+ c[ImGuiCol_NavCursor] = accent;
+ c[ImGuiCol_ModalWindowDimBg] = rgb(0x000000, 0.45f);
+}
+
+} // namespace sf::theme
diff --git a/src/app/Theme.h b/src/app/Theme.h
new file mode 100644
index 00000000..db2f577d
--- /dev/null
+++ b/src/app/Theme.h
@@ -0,0 +1,40 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// Colours and style of the ZBrush-like shell (docs/ui-design.md §10): dense,
+// grey, with the SculptForge orange as the accent.
+#pragma once
+
+#include <imgui.h>
+
+namespace sf::theme {
+
+constexpr ImVec4 rgb(unsigned hex, float a = 1.0f) {
+ return ImVec4(float((hex >> 16) & 0xff) / 255.0f, float((hex >> 8) & 0xff) / 255.0f, float(hex & 0xff) / 255.0f, a);
+}
+
+constexpr ImVec4 shellBg = rgb(0x1e1e20); // shelves, trays, title strip, around the canvas
+constexpr ImVec4 panelBg = rgb(0x252528); // palette drop-downs, tray contents, pop-ups
+constexpr ImVec4 header = rgb(0x2e2e32); // palette and sub-palette headers
+constexpr ImVec4 headerHover = rgb(0x3a3a3f);
+constexpr ImVec4 frame = rgb(0x2b2b2f); // slider and input frames
+constexpr ImVec4 frameHover = rgb(0x36363b);
+constexpr ImVec4 button = rgb(0x38383c);
+constexpr ImVec4 buttonHover = rgb(0x47474c);
+constexpr ImVec4 buttonPressed = rgb(0xe8812a);
+constexpr ImVec4 accent = rgb(0xf0882e); // toggled-on buttons, grabs, checks, selection, active tab
+constexpr ImVec4 accentHover = rgb(0xff9a45);
+constexpr ImVec4 text = rgb(0xd8d8d8);
+constexpr ImVec4 textDim = rgb(0x8c8c90);
+constexpr ImVec4 textOnAccent = rgb(0xffffff);
+constexpr ImVec4 border = rgb(0x121214); // 1 px between regions
+constexpr ImVec4 danger = rgb(0xe5604a); // errors
+constexpr ImVec4 canvasBorder = rgb(0x0e0e10);
+constexpr ImVec4 tile = rgb(0x2a2a2e); // thumbnail placeholders
+
+inline ImU32 u32(const ImVec4& c, float alpha = 1.0f) { return ImGui::ColorConvertFloat4ToU32(ImVec4(c.x, c.y, c.z, c.w * alpha)); }
+
+// Sets the colours, rounding and spacing (unscaled; call ImGuiStyle::ScaleAllSizes afterwards).
+void applyStyle();
+
+} // namespace sf::theme
diff --git a/src/app/Ui.cpp b/src/app/Ui.cpp
index 873dc931..0d77633c 100644
--- a/src/app/Ui.cpp
+++ b/src/app/Ui.cpp
@@ -3,6 +3,11 @@
#include "app/Ui.h"
#include "app/App.h"
+#include "app/Shell.h"
+#include "app/Theme.h"
+
+#include <algorithm>
+#include <cmath>
#include <cstdio>
@@ -11,12 +16,12 @@ 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.
-bool ActionButton(App& app, const char* actionId, ImVec2 size, Look) {
+bool ActionButton(App& app, const char* actionId, ImVec2 size, Look look) {
const Action* a = app.actions().find(actionId);
if (!a) return false;
const bool enabled = !a->enabled || a->enabled();
ImGui::BeginDisabled(!enabled);
- const bool clicked = ImGui::Button((a->label + "##" + a->id).c_str(), size);
+ const bool clicked = drawActionLook(app, *a, size, int(look)); // Shell.cpp: label, icon and tile looks
ImGui::EndDisabled();
if (clicked && a->run) {
app.actions().touch(a->id);
@@ -30,7 +35,23 @@ 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) {
- return ImGui::SliderFloat(id, v, lo, hi, format, flags);
+ // ZBrush look: the label and value inside the frame, the position as a thin accent bar along its bottom.
+ 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);
+ 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);
+ return changed;
}
} // namespace sf::ui
diff --git a/src/app/UiLayout.cpp b/src/app/UiLayout.cpp
index b4e5d943..204decf3 100644
--- a/src/app/UiLayout.cpp
+++ b/src/app/UiLayout.cpp
@@ -22,10 +22,23 @@ void readStrings(const Json& j, std::vector<std::string>& out) {
} // namespace
UiLayout standardLayout() {
- // Phase 0 placeholder; the shell workstream fills in the shelf contents (ui-spec section 3).
+ // docs/ui-design.md §3: what a ZBrush user expects to find around the canvas.
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",
+ "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 --git a/src/app/UiTest.cpp b/src/app/UiTest.cpp
index 8c2e8ecb..eb99e624 100644
--- a/src/app/UiTest.cpp
+++ b/src/app/UiTest.cpp
@@ -29,7 +29,8 @@
// 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); OP is == != < <= > >=
+// one in --ui-out/brush-library), 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"
@@ -163,6 +164,9 @@ double Demo::query(const std::string& name, bool& known) const {
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;
const Document& doc = app_.doc_;
if (name == "subtools") return double(doc.subtoolCount());
if (name == "active_subtool") return double(doc.activeSubtool);
diff --git a/src/render/GL.h b/src/render/GL.h
index a21e1137..b3cba389 100644
--- a/src/render/GL.h
+++ b/src/render/GL.h
@@ -43,6 +43,7 @@ constexpr GLenum GL_RENDERER = 0x1F01;
constexpr GLenum GL_VERSION = 0x1F02;
constexpr GLenum GL_POLYGON_OFFSET_FILL = 0x8037;
constexpr GLenum GL_MULTISAMPLE = 0x809D;
+constexpr GLenum GL_SCISSOR_TEST = 0x0C11;
constexpr GLenum GL_ARRAY_BUFFER = 0x8892;
constexpr GLenum GL_ELEMENT_ARRAY_BUFFER = 0x8893;
constexpr GLenum GL_STATIC_DRAW = 0x88E4;
@@ -88,6 +89,7 @@ constexpr GLbitfield GL_COLOR_BUFFER_BIT = 0x4000;
X(void, Clear, GLbitfield) \
X(void, ClearColor, GLfloat, GLfloat, GLfloat, GLfloat) \
X(void, Viewport, GLint, GLint, GLsizei, GLsizei) \
+ X(void, Scissor, GLint, GLint, GLsizei, GLsizei) \
X(void, Enable, GLenum) \
X(void, Disable, GLenum) \
X(void, DepthFunc, GLenum) \
diff --git a/src/render/Renderer.cpp b/src/render/Renderer.cpp
index cbca892b..665cce77 100644
--- a/src/render/Renderer.cpp
+++ b/src/render/Renderer.cpp
@@ -682,11 +682,27 @@ void Renderer::endCapture(std::vector<uint8_t>& rgba) {
gl::BindFramebuffer(GL_FRAMEBUFFER, 0);
}
-void Renderer::draw(const Camera& camera, int fbWidth, int fbHeight, const RenderSettings& settings) {
- gl::Viewport(0, 0, fbWidth, fbHeight);
+void Renderer::draw(const Camera& camera, int targetWidth, int targetHeight, const RenderSettings& settings,
+ const Viewport& viewport) {
+ gl::Viewport(0, 0, targetWidth, targetHeight);
+ const bool inset = viewport.w > 0 && viewport.h > 0;
+ if (inset) {
+ gl::ClearColor(viewport.surround.x, viewport.surround.y, viewport.surround.z, 1.0f);
+ gl::Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ gl::Viewport(viewport.x, viewport.y, viewport.w, viewport.h);
+ gl::Scissor(viewport.x, viewport.y, viewport.w, viewport.h);
+ gl::Enable(GL_SCISSOR_TEST);
+ }
+ const int fbWidth = inset ? viewport.w : targetWidth, fbHeight = inset ? viewport.h : targetHeight;
gl::ClearColor(0.1f, 0.1f, 0.11f, 1.0f);
gl::Clear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
gl::Enable(GL_MULTISAMPLE);
+ struct ScissorOff {
+ bool on;
+ ~ScissorOff() {
+ if (on) gl::Disable(GL_SCISSOR_TEST);
+ }
+ } scissorOff{inset};
// Background gradient.
gl::Disable(GL_DEPTH_TEST);
diff --git a/src/render/Renderer.h b/src/render/Renderer.h
index a82d21d3..b6a707bc 100644
--- a/src/render/Renderer.h
+++ b/src/render/Renderer.h
@@ -34,6 +34,13 @@ struct SceneMesh {
bool visible = true; // hidden meshes keep their GPU slot but aren't drawn (or uploaded)
};
+// Part of the target the 3D view is drawn into (framebuffer pixels, origin bottom-left); the rest is
+// cleared to `surround`. w == 0: the whole target.
+struct RenderViewport {
+ int x = 0, y = 0, w = 0, h = 0;
+ glm::vec3 surround{0.118f, 0.118f, 0.125f};
+};
+
// Display colour of a polygroup id (linear RGB): a stable hash spread over
// pleasant hues. The mesh shader uses the same formula.
glm::vec3 polygroupColor(uint32_t id);
@@ -54,7 +61,8 @@ public:
void syncScene(const std::vector<SceneMesh>& scene);
// Re-uploads the splats when `version` differs from the last upload.
void syncSplats(const SplatCloud& splats, uint64_t version);
- void draw(const Camera& camera, int fbWidth, int fbHeight, const RenderSettings& settings);
+ using Viewport = RenderViewport;
+ void draw(const Camera& camera, int fbWidth, int fbHeight, const RenderSettings& settings, const Viewport& viewport = {});
// Offscreen render (4x MSAA) into top-down RGBA8 pixels.
bool renderToImage(const Camera& camera, int width, int height, const RenderSettings& settings,
std::vector<uint8_t>& rgba, std::string& error);
diff --git a/tests/test_shell_layout.cpp b/tests/test_shell_layout.cpp
new file mode 100644
index 00000000..e93ac7af
--- /dev/null
+++ b/tests/test_shell_layout.cpp
@@ -0,0 +1,109 @@
+// SculptForge - open source digital sculpting
+// SPDX-License-Identifier: GPL-3.0-or-later
+//
+// The ZBrush-style shell's layout math (docs/ui-design.md §2): where the canvas,
+// shelves and trays go for the standard layout, hidden shelves, narrow and
+// wide windows, and the left-handed mirror; plus the layout JSON round trip.
+#include "TestHarness.h"
+
+#include "app/ShellGeometry.h"
+
+#include <cmath>
+
+using namespace sf;
+
+namespace {
+
+bool near(float a, float b) { return std::abs(a - b) < 0.01f; }
+
+bool rectIs(const CanvasRect& r, float x, float y, float w, float h) {
+ return near(r.x, x) && near(r.y, y) && near(r.w, w) && near(r.h, h);
+}
+
+} // namespace
+
+TEST(shell_standard_layout_1600x960) {
+ const ShellGeometry g = computeShell(standardLayout(), 1600, 960, 1.0f);
+ CHECK(!g.narrow);
+ CHECK(rectIs(g.canvas, 96, 110, 1144, 790)); // §2.2
+ CHECK(rectIs(g.rightTray, 1300, 46, 300, 914));
+ CHECK(rectIs(g.rightDivider, 1292, 46, 8, 914));
+ CHECK(rectIs(g.rightShelf, 1240, 110, 52, 790));
+ CHECK(rectIs(g.leftShelf, 8, 110, 88, 790));
+ CHECK(rectIs(g.topShelf, 8, 46, 1284, 64));
+ CHECK(rectIs(g.bottomShelf, 8, 900, 1284, 60));
+ CHECK(near(g.leftTray.w, 0));
+}
+
+TEST(shell_standard_layout_1920x1080) {
+ const ShellGeometry g = computeShell(standardLayout(), 1920, 1080, 1.0f);
+ CHECK(rectIs(g.canvas, 96, 110, 1444, 910)); // §2.3: the extra width goes to the canvas
+ CHECK(near(g.rightTray.w, 320));
+ CHECK(near(g.rightDivider.x, 1592));
+}
+
+TEST(shell_scales_with_the_ui) {
+ const ShellGeometry g = computeShell(standardLayout(), 3200, 1920, 2.0f);
+ CHECK(rectIs(g.canvas, 192, 220, 2288, 1580));
+}
+
+TEST(shell_hidden_shelves_console_and_trays) {
+ UiLayout l = standardLayout();
+ l.shelvesVisible = false; // Tab
+ ShellGeometry g = computeShell(l, 1600, 960, 1.0f);
+ CHECK(rectIs(g.canvas, 0, 46, 1600, 914));
+
+ l = standardLayout();
+ l.consoleOpen = true;
+ l.consoleHeight = 160;
+ g = computeShell(l, 1600, 960, 1.0f);
+ CHECK(near(g.canvas.y + g.canvas.h, 740)); // §2.2: the console pushes the canvas bottom up
+ CHECK(rectIs(g.console, 8, 740, 1284, 160));
+ l.consoleHeight = 9000;
+ CHECK(near(computeShell(l, 1600, 960, 1.0f).console.h, 400)); // clamped
+
+ l = standardLayout();
+ l.leftTrayOpen = true;
+ l.rightTrayOpen = false;
+ l.paletteBarVisible = false;
+ g = computeShell(l, 1600, 960, 1.0f);
+ CHECK(rectIs(g.leftTray, 0, 24, 300, 936));
+ CHECK(near(g.canvas.x, 300 + 8 + 88));
+ CHECK(near(g.canvas.x + g.canvas.w, 1600 - 8 - 52));
+ CHECK(near(g.canvas.y, 24 + 64));
+}
+
+TEST(shell_narrow_and_left_handed) {
+ ShellGeometry g = computeShell(standardLayout(), 1200, 800, 1.0f);
+ CHECK(g.narrow);
+ CHECK(near(g.rightTray.w, 0)); // collapses to its divider
+ CHECK(near(g.leftShelf.w, 72));
+
+ UiLayout l = standardLayout();
+ l.leftHanded = true;
+ g = computeShell(l, 1600, 960, 1.0f);
+ CHECK(rectIs(g.rightTray, 0, 46, 300, 914)); // the tray swaps sides
+ CHECK(near(g.rightShelf.x, 308));
+ CHECK(rectIs(g.canvas, 360, 110, 1144, 790));
+}
+
+TEST(shell_tray_width_and_layout_json) {
+ CHECK(near(trayWidth(300, 1600), 300));
+ CHECK(near(trayWidth(300, 1920), 320));
+ CHECK(near(trayWidth(100, 1600), 240));
+ CHECK(near(trayWidth(900, 1600), 480));
+
+ UiLayout l = standardLayout();
+ CHECK(l.bottomShelf.size() > 10);
+ CHECK(l.rightTray.size() == 1 && l.rightTray[0] == "tool");
+ l.leftTray = {"brush", "stroke"};
+ l.leftTrayOpen = true;
+ l.bottomShelf.push_back("recipe:Dragon Scales");
+ UiLayout back;
+ std::string err;
+ CHECK(fromJson(toJson(l), back, err));
+ CHECK(back.leftTray == l.leftTray);
+ CHECK(back.leftTrayOpen);
+ CHECK(back.bottomShelf == l.bottomShelf);
+ CHECK(back.topShelf == l.topShelf);
+}
diff --git a/tests/ui/ai_provider.sfui b/tests/ui/ai_provider.sfui
index af200447..cf1aa17a 100644
--- a/tests/ui/ai_provider.sfui
+++ b/tests/ui/ai_provider.sfui
@@ -1,4 +1,7 @@
# Brush Lab's AI provider panel: Free by default, local-model helpers for OpenAI-compatible.
+# Brush Lab floats over the canvas, closed until the top shelf's AI Brush opens it.
+expect_not "Brush Lab/Create"
+click "AI Brush"
expect "Brush Lab"
click "AI provider"
expect_text Free - no account or key
diff --git a/tests/ui/brush_gallery.sfui b/tests/ui/brush_gallery.sfui
index a66ae15e..fcd87f30 100644
--- a/tests/ui/brush_gallery.sfui
+++ b/tests/ui/brush_gallery.sfui
@@ -3,8 +3,8 @@
# gallery that can't be reached shows a clear error instead of an empty window.
env SCULPTFORGE_BRUSH_GALLERY $SCRIPT_DIR/../../tools/brush-gallery/repo
expect_value brushes == 7
-click View
-click "Community brushes"
+click "Brush##palette.brush"
+click "Community brushes##ui.brush_gallery"
wait_idle 30
expect_text 21 brushes
expect "Community brushes/Share yours"
diff --git a/tests/ui/brush_sharing.sfui b/tests/ui/brush_sharing.sfui
index e5698901..74df7fc0 100644
--- a/tests/ui/brush_sharing.sfui
+++ b/tests/ui/brush_sharing.sfui
@@ -3,6 +3,10 @@
# UI tests get an empty library of their own in --ui-out/brush-library.
expect_value user_brushes == 0
expect_value library_files == 0
+# The Brush palette (with the custom brushes) goes into the right tray; Brush Lab opens from the top shelf.
+click "Brush##palette.brush"
+click "Brush/##totray"
+click "AI Brush"
# A brush made this session is marked unsaved until it's refined in Brush Lab.
run brush_create name="Bark Ridges" depth=0.3 pattern=ridges patternAmount=0.6
diff --git a/tests/ui/sculpt_basics.sfui b/tests/ui/sculpt_basics.sfui
index 546d39d9..3da99808 100644
--- a/tests/ui/sculpt_basics.sfui
+++ b/tests/ui/sculpt_basics.sfui
@@ -1,7 +1,7 @@
# Core loop on the real UI: sculpt, undo/redo, masking, polygroups, visibility.
run new_sphere subdivisions=5
expect_value can_undo == 0
-click "2 Clay"
+click "Clay##brush.clay"
stroke 0.35 0.4 0.65 0.6
expect_value can_undo == 1
expect_value dirty == 1
@@ -11,11 +11,12 @@ expect_value can_undo == 0
key ctrl+shift+z
expect_value can_undo == 1
-# Ctrl paints the mask, the Masking buttons edit it.
+# Ctrl paints the mask, the Tool palette's Masking buttons edit it.
hold ctrl
stroke 0.3 0.3 0.7 0.3
hold none
expect_value masked > 50
+click "Masking"
click "Invert##mask"
expect_value masked > 1000
click "Clear##mask"
@@ -23,16 +24,18 @@ expect_value masked == 0
# Polygroups by normals on a cube-ish shape, then hide one with Ctrl+Shift+click.
run new_sphere subdivisions=1
+click "Polygroups"
click "By normals"
expect_value groups > 1
expect_value show_polygroups == 1 # grouping turns the colours on
shot polygroups
click "Show polygroups"
expect_value show_polygroups == 0
+click "Visibility"
click "Show all"
expect_value hidden == 0
-# Menus open panels.
-click "View"
-click "Polypaint & Materials"
-expect "Polypaint & Materials"
+# Palettes open as drop-downs from the palette bar.
+click "Color##palette.color"
+expect "Polypaint & Materials/Paint brush (P)"
+expect "Polypaint & Materials/Fill masked"
diff --git a/tests/ui/shell_layout.sfui b/tests/ui/shell_layout.sfui
new file mode 100644
index 00000000..94f23128
--- /dev/null
+++ b/tests/ui/shell_layout.sfui
@@ -0,0 +1,107 @@
+# The ZBrush-style shell (docs/ui-design.md §2-3): the canvas framed by shelves, the alphabetical palette bar,
+# palettes in drop-downs and trays, the tray dividers, Tab and the layout presets. CMake also runs this script
+# at 1920x1080 (ui_shell_layout_1080).
+run new_sphere subdivisions=4
+expect "SubTools/Append" # right tray: the Tool palette with its SubTool sub-palette open
+expect_value right_tray == 1
+expect_value left_tray == -1
+expect "Clay##brush.clay" # bottom shelf: quick brushes
+expect "PolyF##view.polyf" # right shelf
+expect "##tile.brush" # left shelf
+expect "##drawsize" # top shelf
+expect_not "Brush Lab/Create" # floating windows stay closed: nothing covers the model
+shot standard
+
+# Shelf buttons act and show their state.
+click "Clay##brush.clay"
+stroke 0.35 0.4 0.65 0.6
+expect_value can_undo == 1
+click "PolyF##view.polyf"
+expect_value wireframe == 1
+click "PolyF##view.polyf"
+expect_value wireframe == 0
+click "Groups##view.polygroups"
+expect_value show_polygroups == 1
+click "Groups##view.polygroups"
+
+# Tab hides the shelves and trays; the palette bar stays.
+key tab
+expect_value shelves == 0
+expect_not "Clay##brush.clay"
+expect_not "SubTools/Append"
+expect "Tool##palette.tool"
+shot no-shelves
+key tab
+expect "Clay##brush.clay"
+expect "SubTools/Append"
+
+# The divider opens and closes the right tray.
+click "##rightdivider"
+expect_not "SubTools/Append"
+expect_value right_tray == -1
+shot tray-closed
+click "##rightdivider"
+expect "SubTools/Append"
+
+# A palette opens as a drop-down from the bar; its icon puts it in the tray, and back.
+click "Stroke##palette.stroke"
+expect "Stroke/DragRect"
+shot dropdown
+# Clicking another name switches drop-downs; Escape closes them.
+click "Draw##palette.draw"
+expect "Draw/Zadd"
+expect_not "Stroke/DragRect"
+key escape
+expect_not "Draw/Zadd"
+click "Stroke##palette.stroke"
+click "Stroke/##totray"
+expect "Stroke/DragRect"
+expect "SubTools/Append"
+expect_value right_tray == 2
+shot palette-in-tray
+click "Stroke/##totray"
+expect_not "Stroke/DragRect"
+expect_value right_tray == 1
+# Shift+click sends it to the left tray, which opens.
+hold shift
+click "Alpha##palette.alpha"
+click "Alpha/##totray"
+hold none
+expect "Alpha/Load image..."
+expect_value left_tray == 1
+expect_value right_tray == 1
+shot left-tray
+
+# Tool sub-palettes: one open at a time.
+click "Tool/Geometry"
+expect "Subdivide"
+expect_not "SubTools/Append"
+click "Subdivide"
+expect_value triangles == 20480
+click "Tool/SubTool"
+expect "SubTools/Append"
+
+# Bottom shelf: remove a brush with its menu, add it back with [+].
+right_click "Clay##brush.clay"
+click "Remove from shelf"
+expect_not "Clay##brush.clay"
+click "##addbrush"
+click "Clay"
+expect "Clay##brush.clay"
+
+# Layout presets (title strip 1 2 3).
+click "2##ui.preset.2"
+expect_value left_tray == -1
+expect_value right_tray == -1
+expect_not "SubTools/Append"
+expect_not "Alpha/Load image..."
+shot preset-sculpt
+click "3##ui.preset.3"
+expect_value left_tray == 3
+expect_value right_tray == 2
+expect "Stroke/DragRect"
+expect "Material/Studio"
+shot preset-wide
+click "1##ui.preset.1"
+expect "SubTools/Append"
+expect_not "Stroke/DragRect"
diff --git a/tests/ui/subtools.sfui b/tests/ui/subtools.sfui
index c299466c..9b8689f6 100644
--- a/tests/ui/subtools.sfui
+++ b/tests/ui/subtools.sfui
@@ -1,7 +1,7 @@
# SubTools: the panel, Alt+click in the viewport, sculpting and undo per SubTool,
# visibility, rename, duplicate, delete, merge and split.
run new_sphere subdivisions=4 ; subtool_rename to=Body
-expect "SubTools"
+expect "SubTools/Append"
expect_value subtools == 1
expect "SubTools/Body"
shot one-subtool
@@ -40,7 +40,7 @@ expect_value edited_subtools == 0
shot alt-click
# A stroke changes only the active SubTool; undo history is per SubTool.
-click "2 Clay"
+click "Clay##brush.clay"
stroke 0.3 0.4 0.6 0.6
expect_value can_undo == 1
expect_value edited_subtools == 1
@@ -132,24 +132,25 @@ expect_value subtools == 3
expect_status Split into 3 SubTools
shot split-parts
-# The View menu hides and shows the panel.
-click "View"
-click "SubTools Panel"
+# The Tool palette's SubTool sub-palette closes and opens.
+click "SubTool##tool.subtool"
expect_not "SubTools/Append"
-click "View"
-click "SubTools Panel"
+click "SubTool##tool.subtool"
expect "SubTools/Append"
# Wireframe, polygroup colours and the LOD preview are for the active SubTool only.
key w
expect_value wireframe == 1
+click "Polygroups"
click "Show polygroups"
shot active-overlays
click "Show polygroups"
key w
+click "Export"
click "Generate LOD chain"
shot lod-preview
click "Game Ready/Sculpt"
+click "SubTool##tool.subtool"
# Past six SubTools the list scrolls; clicks scroll it like a person would.
run subtool_append ; subtool_append ; subtool_append ; subtool_append