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.
C++ 3d3d-sculptingcppdear-imguidigital-sculptingfbxgame-developmentgaussian-splattinggltfimage-to-3dmcpopenglopenusdsculptingtext-to-3dunreal-engine
Merge main (workstream B: LightBox, thumbnails, pickers) into ui-shell
islandmed18b1bdc815da
diff --cc CMakeLists.txtindex a2d748da,8faba9ba..b9a25fd2--- a/CMakeLists.txt+++ b/CMakeLists.txt@@@ -128,11 -128,6 +128,10 @@@ if(SCULPTFORGE_BUILD_APPsrc/app/Actions.cppsrc/app/Ui.cppsrc/app/UiLayout.cpp- src/app/LightBoxStubs.cpp+ src/app/Shell.cpp+ src/app/ShellGeometry.cpp+ src/app/Palettes.cpp+ src/app/Theme.cppsrc/app/CommandPalette.cppsrc/app/Console.cppsrc/app/Config.cpp@@@ -312,8 -311,7 +315,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 src/app/UiLayout.cpp- src/app/ShellGeometry.cpp)- add_executable(sculptforge_tests ${SCULPTFORGE_TEST_SOURCES} src/cli/McpServer.cpp src/app/AssetLibrary.cpp)++ add_executable(sculptforge_tests ${SCULPTFORGE_TEST_SOURCES} src/cli/McpServer.cpp src/app/AssetLibrary.cpp++ src/app/UiLayout.cpp src/app/ShellGeometry.cpp)target_include_directories(sculptforge_tests PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/tests)target_link_libraries(sculptforge_tests PRIVATE sculptforge_core sculptforge_ai)if(SCULPTFORGE_BUILD_APP) # the action registry (key chords, shortcut overrides) needs SDL's key namesdiff --cc src/app/App.cppindex 449eb4cd,8218a3ff..74be3332--- a/src/app/App.cpp+++ b/src/app/App.cpp@@@ -618,7 -613,8 +620,8 @@@ void App::onMouseUp()void App::onKey(SDL_Keycode key, SDL_Keymod mod) {if (captureShortcutKey(key, mod)) return; // Ctrl+Alt+click a button, then press its new key++ if (lightBoxKey(key, mod)) return; // , LightBox, B / M pickers, S / I pop-ups (LightBox.cpp)actions_.handleKey(key, mod); // the shortcut map: Config.cpp initActions()- initLightBox();}// ---------------------------------------------------------------------------@@@ -1012,10 -1014,14 +1015,10 @@@ void App::updateTitle()void App::drawUi() {drawProjectPopups();if (hideUi_) return; // demos: clean beauty shots- drawLightBoxUi();- drawMenuBar();- drawToolPanel();- if (showSubToolsPanel_) drawSubToolsPanel();+ // Draw order (ui-spec §12): shells, LightBox, floating windows, then pop-ups and help.+ drawShell();- lightbox_.draw(*this, canvasRect());++ drawLightBoxUi(); // thumbnails, the LightBox over the canvas, pickers, size / strength pop-upsdrawSubToolPopups();- if (showLayersPanel_) drawLayersPanel();- if (showGamePanel_) drawGameExportPanel();- drawSplatSection();if (showBrushLab_) drawBrushLab();drawBrushGallery();if (showImageTo3D_) drawImageTo3D();@@@ -1025,15 -1031,13 +1028,14 @@@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_) {diff --cc src/app/App.hindex 2540e422,8772aa32..c6674de5--- a/src/app/App.h+++ b/src/app/App.h@@@ -431,99 -444,24 +432,107 @@@ privatestd::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 drawShelfTile(App&, const Action&, ImVec2);+ friend const struct PaletteDef* palettes(int&);+ // Shell.cpp: title strip, palette bar, shelves, trays, dividers, drop-downs, customize drag and drop.+ void registerShellActions();+ void drawShell();+ void drawTitleStrip(const ShellGeometry& g);+ void drawPaletteBar(const ShellGeometry& g);+ void drawShelf(int shelf, const CanvasRect& rect);+ void drawShelfItem(int shelf, int index, const std::string& item, bool vertical);+ void drawTray(bool right, const CanvasRect& rect);+ void drawDivider(bool right, const CanvasRect& rect);+ void drawPaletteDropdown();+ bool paletteHeader(const char* id, bool inTray, bool right); // false: collapsed+ void drawPaletteBody(const std::string& id);+ void movePaletteToTray(const std::string& id, bool right);+ void removePaletteFromTrays(const std::string& id);+ void finishShelfDrag();+ void noteLayoutChanged();+ void applyPreset(int preset);+ void updateCameraAspect(); // camera_.aspect from the canvas+ // Ray through window point (x, y) of the canvas, and the canvas height for screen-size conversions.+ void canvasRay(float x, float y, glm::vec3& origin, glm::vec3& dir) const;+ float canvasHeight() const { return canvasRect().h; }+ Renderer::Viewport canvasViewport(int fbWidth, int fbHeight) const; // the canvas in framebuffer pixels+ void drawCanvasFrame();+ bool canvasNavButton(const char* id, const char* icon, const char* label, int mode); // right-shelf Move/Zoom/Rotate+ void drawBrushTile(const char* id, ImVec2 size);+ void drawStrokeTile(const char* id, ImVec2 size);+ void drawAlphaTile(const char* id, ImVec2 size);+ void drawMaterialTile(const char* id, ImVec2 size);+ void drawColorWidget(float width);- void drawAddToShelfPopup();+ // Palettes.cpp: every palette body, also used by the trays and drop-downs.+ bool subpalette(const char* id, const char* title); // Tool sub-palette header; true while open+ void drawPalette_Alpha();+ void drawPalette_Brush();+ void drawPalette_Color();+ void drawPalette_Draw();+ void drawPalette_Edit();+ void drawPalette_File();+ void drawPalette_Generate();+ void drawPalette_Help();+ void drawPalette_Material();+ void drawPalette_Preferences();+ void drawPalette_Render();+ void drawPalette_Script();+ void drawPalette_Splats();+ void drawPalette_Stroke();+ void drawPalette_Tool();+ void drawPalette_Transform();- void drawStrokeSection();+ void drawAlphaSection();- void drawMaterialGrid(float tile);+ void drawLayersContents();+ void drawGameExportContents();+ void drawVisibilitySection();+ void drawSubToolsContents();+ void pollAlphaFile();+ ShellGeometry shell_; // this frame's regions (drawShell)+ ImFont* fontSmall_ = nullptr, *fontTiny_ = nullptr, *fontIcons_ = nullptr, *fontBold_ = nullptr;+ std::string dropdown_; // palette open as a drop-down ("" = none)+ float dropdownX_ = 0.0f;+ bool openDropdown_ = false;+ float decimateRatio_ = 0.5f;+ std::string flashPalette_; // a tray palette that was clicked in the bar: scrolled to and flashed+ double flashStart_ = 0.0;+ std::vector<std::string> collapsedPalettes_; // tray palettes showing only their header+ void autoCollapseTray(bool right, const std::string& keep);+ 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 ----LightBox lightbox_;ThumbnailCache thumbs_;+ friend struct PickerUi;+ friend void drawAlphaGrid(App&, GridMode);+ friend void drawMaterialGrid(App&, GridMode);+ friend void drawStrokeGrid(App&, GridMode);+ void initLightBox(); // end of init(): library folders, thumbnail cache, actions, project thumbnails+ void drawLightBoxUi(); // every frame from drawUi: thumbnails, the LightBox, pickers, size / strength pop-ups+ // The LightBox / picker shortcuts (, B M S I) until the action registry dispatches keys.+ bool lightBoxKey(SDL_Keycode key, SDL_Keymod mod);- CanvasRect lightBoxCanvas() const; // the canvas until the shell provides canvasRect()+ void quickSave(); // file.quicksave: a timestamped project in <library>/QuickSave+ LibraryRoots library_;+ FolderScanner libraryScanner_;// ---- end LightBox (B) ----// ---- Help/Console/Config (C): actions, help, command palette, console, config ----diff --cc src/app/Config.cppindex 3177aaa0,ad728372..c3ac8ac9--- a/src/app/Config.cpp+++ b/src/app/Config.cpp@@@ -508,6 -512,6 +508,14 @@@ void App::drawHelpConsoleUi()console_.queueScriptFile(path);} else if (kind == kLibraryFolder) {uiPrefs_.libraryFolder = path;++ std::string libErr;++ if (ensureUserLibrary(path, libErr)) { // the LightBox's User folder, from now on++ library_.user = path;++ libraryScanner_.invalidate();++ status_ = "Library folder: " + path + " (Store Config keeps it)";++ } else {++ status_ = libErr;++ }}}}diff --cc src/app/Demo.cppindex 59f7c907,b0785dd5..538d4c4c--- a/src/app/Demo.cpp+++ b/src/app/Demo.cpp@@@ -461,9 -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");++ shelf.insert(std::find(shelf.begin(), shelf.end(), "widget.add_brush"), "brush.recipe.Edge Wear");});click("Edge Wear");stroke(line(0.16f, 0.30f, 0.20f, 0.70f), 1.4f);diff --cc src/app/LightBox.cppindex 00000000,50dd360a..69b5fe71mode 000000,100644..100644--- a/src/app/LightBox.cpp+++ b/src/app/LightBox.cpp@@@ -1,0 -1,1061 +1,1055 @@@+ // SculptForge - open source digital sculpting+ // SPDX-License-Identifier: GPL-3.0-or-later+ #include "app/LightBox.h"++ #include "app/App.h"+ #include "app/Pickers.h"+ #include "app/Ui.h"+ #include "core/Matcap.h"+ #include "core/Primitives.h"+ #include "core/Project.h"+ #include "render/GL.h"++ #include <IconsLucide.h>++ #include <imgui_internal.h>++ #include <algorithm>+ #include <cctype>+ #include <chrono>+ #include <cmath>+ #include <ctime>+ #include <filesystem>++ namespace sf {++ namespace {++ namespace fs = std::filesystem;++ constexpr float kTile = 96.0f; // thumbnail size (logical px)+ constexpr float kLabel = 22.0f; // label under it+ constexpr float kGap = 8.0f; // between tiles+ constexpr float kHeader = 28.0f; // tab row+ constexpr ImU32 kAccent = IM_COL32(240, 136, 46, 255);+ constexpr ImU32 kStripBg = IM_COL32(20, 20, 22, 250); // #141416 at 98%+ constexpr ImU32 kHeaderLine = IM_COL32(46, 46, 50, 255);++ fs::path fsPath(const std::string& p) { return fs::path(std::u8string(p.begin(), p.end())); }+ std::string utf8(const fs::path& p) {+ const std::u8string s = p.u8string();+ return std::string(s.begin(), s.end());+ }+ std::string lower(std::string s) {+ for (auto& c : s)+ c = char(std::tolower(static_cast<unsigned char>(c)));+ return s;+ }+ bool isUnder(const std::string& path, const std::string& root) {+ if (root.empty() || path.size() < root.size() || path.compare(0, root.size(), root) != 0) return false;+ return path.size() == root.size() || path[root.size()] == '/' || path[root.size()] == '\\';+ }++ const char* glyphFor(AssetKind k) {+ switch (k) {+ case AssetKind::Folder:+ return ICON_LC_FOLDER;+ case AssetKind::Up:+ return ICON_LC_FOLDER_UP;+ case AssetKind::Project:+ case AssetKind::Mesh:+ case AssetKind::Primitive:+ return ICON_LC_BOX;+ case AssetKind::BrushType:+ case AssetKind::Recipe:+ case AssetKind::BrushFile:+ return ICON_LC_BRUSH;+ case AssetKind::Alpha:+ case AssetKind::AlphaFile:+ return ICON_LC_CIRCLE_DASHED;+ case AssetKind::Material:+ return ICON_LC_SUN;+ case AssetKind::Image:+ return ICON_LC_IMAGE;+ case AssetKind::Splat:+ return ICON_LC_SPARKLES;+ }+ return ICON_LC_BOX;+ }++ std::string sizeText(uint64_t bytes) {+ char buf[32];+ if (bytes >= 1024ull * 1024ull)+ std::snprintf(buf, sizeof buf, "%.1f MB", double(bytes) / (1024.0 * 1024.0));+ else+ std::snprintf(buf, sizeof buf, "%.0f KB", std::max(1.0, double(bytes) / 1024.0));+ return buf;+ }+ std::string dateText(int64_t t) {+ const std::time_t tt = std::time_t(t);+ std::tm tm{};+ #if defined(_WIN32)+ localtime_s(&tm, &tt);+ #else+ localtime_r(&tt, &tm);+ #endif+ char buf[32];+ std::strftime(buf, sizeof buf, "%Y-%m-%d %H:%M", &tm);+ return buf;+ }++ const BrushAlpha& builtinAlpha(int i) {+ static const BrushAlpha alphas[] = {BrushAlpha::round(), BrushAlpha::square(), BrushAlpha::noise()};+ return alphas[std::clamp(i, 0, 2)];+ }+ const char* const kAlphaNames[] = {"Round", "Square", "Noise"};++ void SDLCALL onFolderChosen(void* userdata, const char* const* files, int) {+ if (files && files[0]) static_cast<LightBox*>(userdata)->folderChosen(files[0]);+ }++ } // namespace++ float LightBox::height(int rows, float scale) {+ return (kHeader + float(std::clamp(rows, 1, 4)) * (kTile + kLabel + 4.0f) + 12.0f) * scale;+ }++ void LightBox::show(LibraryTab tab) {+ open_ = true;+ if (place_.tab != tab || !place_.folder.empty()) {+ back_.push_back(place_);+ forward_.clear();+ place_ = {tab, ""};+ scrollTo_ = 0.0f;+ }+ }++ void LightBox::folderChosen(const std::string& path) {+ std::lock_guard lock(folderMutex_);+ chosenFolder_ = path;+ }++ void LightBox::navigate(App&, Place to) {+ if (to == place_) return;+ back_.push_back(place_);+ if (back_.size() > 64) back_.erase(back_.begin());+ forward_.clear();+ place_ = std::move(to);+ filter_[0] = 0;+ selected_.clear();+ scrollTo_ = 0.0f;+ }++ // ---------------------------------------------------------------------------+ // What a tab shows+ // ---------------------------------------------------------------------------++ void LightBox::rootEntries(App& app, std::vector<AssetEntry>& out) {+ const LibraryTab tab = place_.tab;+ const LibraryRoots& roots = app.library_;+ auto folderTile = [&](const std::string& name, const std::string& path) {+ AssetEntry e;+ e.kind = AssetKind::Folder;+ e.name = name;+ e.path = path;+ out.push_back(std::move(e));+ };+ auto scan = [&](const std::string& dir, bool newestFirst) -> std::vector<AssetEntry> {+ if (dir.empty()) return {};+ const auto* list = app.libraryScanner_.get(+ dir, libraryTabId(tab), [tab](const std::string& p) { return fileKindForTab(tab, p); }, newestFirst);+ std::vector<AssetEntry> files;+ if (list)+ for (const auto& e : *list)+ if (e.kind != AssetKind::Folder) files.push_back(e);+ return files;+ };+ const std::string userDir =+ roots.user.empty() || !*libraryTabFolder(tab) ? std::string() : roots.user + "/" + libraryTabFolder(tab);+ const std::string builtinDir = roots.builtin.empty() ? std::string() : roots.builtin + "/demo";+ // The Built-in and User folders (ZBrush: Maxon and User), and folders the artist added.+ const bool folders = tab == LibraryTab::Project || tab == LibraryTab::Tool || tab == LibraryTab::Alpha ||+ tab == LibraryTab::Image || tab == LibraryTab::Splats || tab == LibraryTab::Brush;+ if (folders) {+ const bool builtinHasFiles = !builtinDir.empty() && (tab == LibraryTab::Tool || tab == LibraryTab::Image);+ if (builtinHasFiles) folderTile("Built-in", builtinDir);+ if (!userDir.empty()) folderTile("User", userDir);+ for (const std::string& r : extraRoots_)+ folderTile(utf8(fsPath(r).filename()), r);+ }+ switch (tab) {+ case LibraryTab::Project: {+ std::vector<AssetEntry> files = scan(userDir, true);+ for (const std::string& p : app.recentFiles_)+ if (isProjectFile(p) &&+ std::none_of(files.begin(), files.end(), [&](const AssetEntry& e) { return e.path == p; })) {+ AssetEntry e;+ e.kind = AssetKind::Project;+ e.name = utf8(fsPath(p).stem());+ e.path = p;+ files.push_back(std::move(e));+ }+ out.insert(out.end(), files.begin(), files.end());+ break;+ }+ case LibraryTab::Tool: {+ for (int i = 0; i < int(Primitive::Count); ++i) {+ AssetEntry e;+ e.kind = AssetKind::Primitive;+ e.index = i;+ e.name = primitiveName(Primitive(i));+ out.push_back(std::move(e));+ }+ const auto files = scan(userDir, false);+ out.insert(out.end(), files.begin(), files.end());+ break;+ }+ case LibraryTab::Brush:+ for (const BrushItem& b : PickerUi::brushItems(app, true)) {+ AssetEntry e;+ e.name = b.name;+ e.path = b.path;+ switch (b.kind) {+ case BrushItem::Kind::Type:+ e.kind = AssetKind::BrushType, e.index = b.index;+ break;+ case BrushItem::Kind::Paint:+ e.kind = AssetKind::BrushType, e.index = kPaintBrush;+ break;+ case BrushItem::Kind::Recipe:+ e.kind = AssetKind::Recipe, e.index = b.index;+ break;+ case BrushItem::Kind::File:+ e.kind = AssetKind::BrushFile;+ break;+ }+ out.push_back(std::move(e));+ }+ break;+ case LibraryTab::Alpha: {+ for (int i = 0; i < 3; ++i) {+ AssetEntry e;+ e.kind = AssetKind::Alpha;+ e.index = i;+ e.name = kAlphaNames[i];+ out.push_back(std::move(e));+ }+ const auto files = scan(userDir, false);+ out.insert(out.end(), files.begin(), files.end());+ break;+ }+ case LibraryTab::Material:+ for (int i = -1; i < matcapCount(); ++i) {+ AssetEntry e;+ e.kind = AssetKind::Material;+ e.index = i;+ e.name = i < 0 ? "Studio" : matcapName(i);+ out.push_back(std::move(e));+ }+ break;+ case LibraryTab::Image:+ case LibraryTab::Splats: {+ const auto files = scan(userDir, false);+ out.insert(out.end(), files.begin(), files.end());+ break;+ }+ case LibraryTab::QuickSave: {+ // Autosave first (it is the newest by nature), then QuickSaves newest first.+ if (!app.prefDir_.empty()) {+ const std::string autosave = app.prefDir_ + "autosave.sfproj";+ std::error_code ec;+ if (fs::is_regular_file(fsPath(autosave), ec)) {+ AssetEntry e;+ e.kind = AssetKind::Project;+ e.name = "Autosave";+ e.path = autosave;+ e.mtime = modifiedTime(autosave);+ out.push_back(std::move(e));+ }+ }+ // "QuickSave 2026-10-21 23-15-04" reads better as its time: "Oct 21 23:15:04".+ for (AssetEntry e : scan(userDir, true)) {+ if (e.name.rfind("QuickSave ", 0) == 0 && e.mtime) {+ const std::time_t t = std::time_t(e.mtime);+ std::tm tm{};+ #if defined(_WIN32)+ localtime_s(&tm, &t);+ #else+ localtime_r(&t, &tm);+ #endif+ char buf[32];+ std::strftime(buf, sizeof buf, "%b %d %H:%M:%S", &tm);+ e.name = buf;+ }+ out.push_back(std::move(e));+ }+ break;+ }+ case LibraryTab::Recent:+ for (const std::string& p : app.recentFiles_) {+ AssetEntry e;+ e.kind = fileKindForTab(LibraryTab::Recent, p);+ if (e.kind == AssetKind::Folder) continue;+ e.name = utf8(fsPath(p).filename());+ e.path = p;+ out.push_back(std::move(e));+ }+ break;+ default:+ break;+ }+ }++ std::vector<AssetEntry> LightBox::entries(App& app) {+ std::vector<AssetEntry> out;+ if (place_.folder.empty()) {+ rootEntries(app, out);+ } else {+ AssetEntry up;+ up.kind = AssetKind::Up;+ up.name = "..";+ out.push_back(up);+ const LibraryTab tab = place_.tab;+ if (const auto* list = app.libraryScanner_.get(+ place_.folder, libraryTabId(tab), [tab](const std::string& p) { return fileKindForTab(tab, p); },+ tab == LibraryTab::QuickSave || tab == LibraryTab::Project))+ out.insert(out.end(), list->begin(), list->end());+ }+ if (filter_[0]) {+ const std::string f = lower(filter_);+ out.erase(std::remove_if(out.begin(), out.end(),+ [&](const AssetEntry& e) {+ return e.kind != AssetKind::Up && lower(e.name).find(f) == std::string::npos;+ }),+ out.end());+ }+ return out;+ }++ namespace {+ bool isActiveBrushType(const App& app, int index) {+ BrushItem b;+ b.kind = index == kPaintBrush ? BrushItem::Kind::Paint : BrushItem::Kind::Type;+ b.index = index;+ return PickerUi::isActive(app, b);+ }+ } // namespace++ ImTextureID LightBox::thumbnail(App& app, const AssetEntry& e) {+ ThumbnailCache& t = app.thumbs_;+ switch (e.kind) {+ case AssetKind::Project:+ case AssetKind::Mesh:+ case AssetKind::Image:+ case AssetKind::AlphaFile:+ return t.file(e.path);+ case AssetKind::Primitive:+ return t.primitive(e.index);+ case AssetKind::BrushType:+ return t.brush(e.index);+ case AssetKind::Recipe:+ return e.index >= 0 && e.index < int(app.doc_.brushes.size()) ? t.recipe(app.doc_.brushes[size_t(e.index)])+ : ImTextureID(0);+ case AssetKind::Alpha:+ return t.alpha(builtinAlpha(e.index));+ case AssetKind::Material:+ return t.material(e.index);+ default:+ return ImTextureID(0);+ }+ }++ // ---------------------------------------------------------------------------+ // Actions+ // ---------------------------------------------------------------------------++ void LightBox::activate(App& app, const AssetEntry& e, bool append) {+ switch (e.kind) {+ case AssetKind::Up: {+ const std::string parent = utf8(fsPath(place_.folder).parent_path());+ // Leaving the folder a tab started in goes back to the tab's root.+ const LibraryRoots& r = app.library_;+ const std::string tabUser = r.user.empty() ? std::string() : r.user + "/" + libraryTabFolder(place_.tab);+ const bool atTop = place_.folder == tabUser || place_.folder == r.builtin + "/demo" ||+ std::find(extraRoots_.begin(), extraRoots_.end(), place_.folder) != extraRoots_.end();+ navigate(app, {place_.tab, atTop ? std::string() : parent});+ return;+ }+ case AssetKind::Folder:+ navigate(app, {place_.tab, e.path});+ return;+ case AssetKind::Primitive: {+ if (append) {+ app.runCommand("subtool_append", {{"type", lower(primitiveName(Primitive(e.index)))}});+ return;+ }+ const Primitive p = Primitive(e.index);+ app.confirmDiscard([&app, p] {+ if (p == Primitive::Sphere)+ app.runCommand("new_sphere");+ else if (p == Primitive::Plane)+ app.runCommand("new_plane");+ else {+ app.runCommand("new_cube");+ if (app.lastCommandOk_) app.camera_.frame(app.sceneBounds());+ }+ });+ return;+ }+ case AssetKind::Project:+ case AssetKind::Mesh:+ if (append)+ app.runCommand("subtool_append", {{"path", e.path}});+ else+ app.openPathConfirmed(e.path);+ return;+ case AssetKind::BrushType: {+ BrushItem b;+ b.kind = e.index == kPaintBrush ? BrushItem::Kind::Paint : BrushItem::Kind::Type;+ b.index = e.index;+ b.name = e.name;+ PickerUi::select(app, b);+ return;+ }+ case AssetKind::Recipe: {+ BrushItem b;+ b.kind = BrushItem::Kind::Recipe;+ b.index = e.index;+ b.name = e.name;+ PickerUi::select(app, b);+ return;+ }+ case AssetKind::BrushFile:+ app.runCommand("brush_load", {{"path", e.path}});+ return;+ case AssetKind::Alpha:+ app.runCommand("brush_set_alpha", {{"name", lower(kAlphaNames[std::clamp(e.index, 0, 2)])}});+ return;+ case AssetKind::AlphaFile:+ app.runCommand("brush_set_alpha", {{"path", e.path}, {"invert", app.alphaInvert_}});+ return;+ case AssetKind::Material:+ app.runCommand("set_material", {{"name", std::string(e.index < 0 ? "studio" : matcapName(e.index))}});+ return;+ case AssetKind::Image:+ imageMenu_ = e.path;+ return; // what to do with it: a small menu+ case AssetKind::Splat:+ app.runCommand("open", {{"path", e.path}});+ return;+ }+ }++ void LightBox::contextMenu(App& app, const AssetEntry& e) {+ ImGui::TextDisabled("%s", e.name.c_str());+ ImGui::Separator();+ const bool mesh = e.kind == AssetKind::Mesh || e.kind == AssetKind::Project || e.kind == AssetKind::Primitive;+ if (ImGui::MenuItem(e.kind == AssetKind::Folder || e.kind == AssetKind::Up ? "Open folder" : "Open"))+ activate(app, e, false);+ if (mesh && ImGui::MenuItem("Append as SubTool", "Shift+double-click")) activate(app, e, true);+ if (e.kind == AssetKind::Image) {+ if (ImGui::MenuItem("Generate 3D...")) app.openPath(e.path);+ if (ImGui::MenuItem("Relief from image"))+ app.confirmDiscard([&app, p = e.path] { app.runCommand("image_relief", {{"path", p}}); });+ if (ImGui::MenuItem("Inflate image"))+ app.confirmDiscard([&app, p = e.path] { app.runCommand("image_inflate", {{"path", p}}); });+ if (ImGui::MenuItem("Project onto model")) app.runCommand("image_project", {{"path", e.path}});+ if (ImGui::MenuItem("Use as alpha"))+ app.runCommand("brush_set_alpha", {{"path", e.path}, {"invert", app.alphaInvert_}});+ }+ if (!e.path.empty() && e.kind != AssetKind::Up) {+ ImGui::Separator();+ if (ImGui::MenuItem("Show in file manager")) {+ const std::string dir = e.kind == AssetKind::Folder ? e.path : utf8(fsPath(e.path).parent_path());+ if (!SDL_OpenURL(("file://" + dir).c_str())) app.status_ = "Couldn't open " + dir + ": " + SDL_GetError();+ }+ if (e.kind != AssetKind::Folder && ImGui::MenuItem("Refresh thumbnail")) app.thumbs_.refresh(e.path);+ }+ }++ // ---------------------------------------------------------------------------+ // Drawing+ // ---------------------------------------------------------------------------++ std::string LightBox::folderLabel(const App& app, const std::string& folder) const {+ const LibraryRoots& r = app.library_;+ if (!r.builtin.empty() && isUnder(folder, r.builtin)) return "Built-in";+ if (!r.user.empty() && isUnder(folder, r.user)) return "User";+ return utf8(fsPath(folder).filename());+ }++ void LightBox::drawBreadcrumb(App& app) {+ // Tab > Built-in/User > sub > sub: each crumb goes back there.+ std::vector<std::pair<std::string, Place>> crumbs;+ crumbs.push_back({libraryTabName(place_.tab), {place_.tab, ""}});+ if (!place_.folder.empty()) {+ const LibraryRoots& r = app.library_;+ std::string top;+ const std::string tabUser = r.user.empty() ? std::string() : r.user + "/" + libraryTabFolder(place_.tab);+ if (!tabUser.empty() && isUnder(place_.folder, tabUser))+ top = tabUser;+ else if (!r.builtin.empty() && isUnder(place_.folder, r.builtin + "/demo"))+ top = r.builtin + "/demo";+ else+ for (const auto& x : extraRoots_)+ if (isUnder(place_.folder, x)) top = x;+ if (top.empty()) top = place_.folder;+ crumbs.push_back({folderLabel(app, top), {place_.tab, top}});+ const fs::path rel = fsPath(place_.folder).lexically_relative(fsPath(top));+ fs::path acc = fsPath(top);+ for (const auto& part : rel) {+ if (part == ".") continue;+ acc /= part;+ crumbs.push_back({utf8(part), {place_.tab, utf8(acc)}});+ }+ }+ for (size_t i = 0; i < crumbs.size(); ++i) {+ if (i) {+ ImGui::SameLine(0, 2);+ ImGui::TextDisabled(ICON_LC_CHEVRON_RIGHT);+ ImGui::SameLine(0, 2);+ }+ const bool last = i + 1 == crumbs.size();+ ImGui::PushID(int(i));+ ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0));+ ImGui::PushStyleColor(ImGuiCol_Text, last ? ImGui::GetStyleColorVec4(ImGuiCol_Text)+ : ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));+ if (ImGui::SmallButton(crumbs[i].first.c_str()) && !last) navigate(app, crumbs[i].second);+ ImGui::PopStyleColor(2);+ ImGui::PopID();+ }+ }++ void LightBox::drawHeader(App& app, float width) {+ const float scale = app.uiScale_;+ ImGuiStyle& style = ImGui::GetStyle();+ ImDrawList* dl = ImGui::GetWindowDrawList();+ const ImVec2 origin = ImGui::GetCursorScreenPos();++ // Title (an item, so tests and help find "LightBox").+ {+ const char* title = ICON_LC_IMAGES " LightBox";+ const ImVec2 ts = ImGui::CalcTextSize(title);+ const ImVec2 p = ImGui::GetCursorScreenPos();+ ImGui::InvisibleButton("LightBox", ImVec2(ts.x, ImGui::GetFrameHeight()));+ dl->AddText(ImVec2(p.x, p.y + (ImGui::GetFrameHeight() - ts.y) * 0.5f), ImGui::GetColorU32(ImGuiCol_Text),+ title);+ ui::HelpText("LightBox", ",",+ "Browse projects, models, brushes, alphas, materials, images and splats. Double-click to load; "+ "Shift+double-click a model to append it as a SubTool; drag sideways to scrub.",+ "LightBox");+ }+ ImGui::SameLine(0, 14 * scale);++ // Tabs: text buttons, the active one underlined in accent.+ for (int i = 0; i < int(LibraryTab::Count); ++i) {+ const auto tab = LibraryTab(i);+ const bool on = place_.tab == tab;+ ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0));+ ImGui::PushStyleColor(ImGuiCol_ButtonHovered, IM_COL32(255, 255, 255, 18));+ ImGui::PushStyleColor(ImGuiCol_ButtonActive, IM_COL32(255, 255, 255, 30));+ ImGui::PushStyleColor(ImGuiCol_Text,+ on ? IM_COL32(255, 255, 255, 255) : ImGui::GetColorU32(ImGuiCol_TextDisabled));+ if (ImGui::Button(libraryTabName(tab)) && !on) navigate(app, {tab, ""});+ ImGui::PopStyleColor(4);+ if (on) {+ const ImVec2 a = ImGui::GetItemRectMin(), b = ImGui::GetItemRectMax();+ dl->AddRectFilled(ImVec2(a.x + 4, b.y - 2), ImVec2(b.x - 4, b.y), kAccent, 1.0f);+ }+ static const char* const tips[] = {+ "Your projects (.sfproj) and recently opened projects.",+ "Models to start from or append as SubTools: primitives and model files.",+ "Every brush: built-in, custom and .sfbrush files in your library.",+ "Brush alphas: built-in stamps and images in your Alphas folder.",+ "Viewport materials: Studio and the MatCaps.",+ "Reference images: generate 3D, relief, inflate, project onto the model or use as an alpha.",+ "Gaussian splat captures (.ply, .splat) to sculpt against.",+ "QuickSaves and the autosave, newest first.",+ "Recently opened files of every kind.",+ };+ ui::HelpText(libraryTabName(tab), nullptr, tips[i], "LightBox");+ ImGui::SameLine(0, 0);+ }+ ImGui::SameLine(0, 10 * scale);++ // History.+ ImGui::PushStyleColor(ImGuiCol_Button, IM_COL32(0, 0, 0, 0));+ ImGui::BeginDisabled(back_.empty());+ if (ImGui::Button(ICON_LC_CHEVRON_LEFT "###Back")) {+ forward_.push_back(place_);+ place_ = back_.back();+ back_.pop_back();+ scrollTo_ = 0.0f;+ }+ ImGui::EndDisabled();+ ui::HelpText("Back", nullptr, "The previous tab or folder.", "LightBox");+ ImGui::SameLine(0, 2);+ ImGui::BeginDisabled(forward_.empty());+ if (ImGui::Button(ICON_LC_CHEVRON_RIGHT "###Forward")) {+ back_.push_back(place_);+ place_ = forward_.back();+ forward_.pop_back();+ scrollTo_ = 0.0f;+ }+ ImGui::EndDisabled();+ ui::HelpText("Forward", nullptr, "Forward again after going back.", "LightBox");+ ImGui::PopStyleColor();+ if (!place_.folder.empty()) {+ ImGui::SameLine(0, 8 * scale);+ drawBreadcrumb(app);+ }++ // Right side: [Save now] on the QuickSave tab, filter, rows, open folder, close. Narrow canvases+ // get icon-only buttons and a shorter filter first.+ const bool quickTab = place_.tab == LibraryTab::QuickSave;+ const float rowsW = 4 * (ImGui::GetFrameHeight() + 2.0f);+ const float closeW = ImGui::GetFrameHeight();+ const float right = origin.x + width;+ ImGui::SameLine();+ const float leftEnd = ImGui::GetCursorScreenPos().x;+ auto buttonW = [&](const char* text) {+ return ImGui::CalcTextSize(text, nullptr, true).x + style.FramePadding.x * 2;+ };+ float filterW = 160.0f * scale;+ bool compact = false;+ auto groupW = [&] {+ const float saveW =+ quickTab ? buttonW(compact ? ICON_LC_SAVE : ICON_LC_SAVE " Save now") + 8.0f * scale : 0.0f;+ const float folderW = buttonW(compact ? ICON_LC_FOLDER_PLUS : ICON_LC_FOLDER_PLUS " Open folder...");+ return saveW + filterW + rowsW + folderW + closeW + 3 * 8.0f * scale;+ };+ if (right - leftEnd - 8.0f < groupW()) compact = true;+ if (right - leftEnd - 8.0f < groupW())+ filterW = std::max(70.0f * scale, filterW - (groupW() - (right - leftEnd - 8.0f)));+ ImGui::SetCursorScreenPos(ImVec2(std::max(leftEnd + 8.0f, right - groupW()), origin.y));+ if (quickTab) {+ if (ImGui::Button(compact ? ICON_LC_SAVE "###QuickSave now" : ICON_LC_SAVE " Save now###QuickSave now"))+ app.quickSave();+ ui::HelpAction(app, "file.quicksave");+ ImGui::SameLine(0, 8 * scale);+ }+ ImGui::SetNextItemWidth(filterW);+ ImGui::InputTextWithHint("##lbfilter", ICON_LC_SEARCH " Filter", filter_, sizeof filter_);+ ui::HelpText("Filter", nullptr, "Show only the items whose names contain this text.", "LightBox");+ ImGui::SameLine(0, 8 * scale);+ for (int r = 1; r <= 4; ++r) {+ const bool on = app.layout_.lightboxRows == r;+ char label[16];+ std::snprintf(label, sizeof label, "%d##lbrows", r);+ if (on) ImGui::PushStyleColor(ImGuiCol_Button, ImGui::ColorConvertU32ToFloat4(kAccent));+ if (ImGui::Button(label, ImVec2(ImGui::GetFrameHeight(), 0))) app.layout_.lightboxRows = r;+ if (on) ImGui::PopStyleColor();+ ui::HelpText("Rows", nullptr, "How many rows of thumbnails the LightBox shows (1-4).", "LightBox");+ ImGui::SameLine(0, 2);+ }+ ImGui::SameLine(0, 8 * scale);+ if (ImGui::Button(compact ? ICON_LC_FOLDER_PLUS "###Open folder"+ : ICON_LC_FOLDER_PLUS " Open folder...###Open folder"))+ SDL_ShowOpenFolderDialog(onFolderChosen, this, app.window_, nullptr, false);+ ui::HelpText("Open folder", nullptr, "Add a folder of your own to the LightBox (shown at the root of every tab).",+ "LightBox");+ ImGui::SameLine(0, 8 * scale);+ if (ImGui::Button(ICON_LC_X "##lbclose", ImVec2(closeW, 0))) open_ = false;+ ui::HelpText("Close LightBox", ",", "Hide the LightBox (comma toggles it).", "LightBox");++ const float y = origin.y + kHeader * scale - 2.0f;+ dl->AddLine(ImVec2(origin.x - 8, y), ImVec2(right + 8, y), kHeaderLine, 1.0f);+ ImGui::SetCursorScreenPos(ImVec2(origin.x, origin.y + kHeader * scale + 2.0f));+ }++ void LightBox::draw(App& app, const CanvasRect& canvas) {+ {+ std::lock_guard lock(folderMutex_);+ if (!chosenFolder_.empty()) {+ if (std::find(extraRoots_.begin(), extraRoots_.end(), chosenFolder_) == extraRoots_.end())+ extraRoots_.push_back(chosenFolder_);+ app.status_ = "Added " + chosenFolder_ + " to the LightBox";+ Place to{place_.tab, chosenFolder_};+ chosenFolder_.clear();+ open_ = true;+ navigate(app, to);+ }+ }+ // The layout holds what Store Config saves (open, rows, tab, placement).+ UiLayout& layout = app.layout_;+ if (!syncedLayout_) {+ syncedLayout_ = true;+ place_.tab = libraryTabFromId(layout.lightboxTab);+ open_ = open_ || layout.lightboxOpen;+ }+ layout.lightboxOpen = open_;+ layout.lightboxTab = libraryTabId(place_.tab);+ layout.lightboxRows = std::clamp(layout.lightboxRows, 1, 4);+ app.libraryScanner_.poll(ImGui::GetTime());+ if (!open_) {+ pressing_ = tileDrag_ = false;+ return;+ }++ const float scale = app.uiScale_;+ const int rows = layout.lightboxRows;+ const float h = std::min(height(rows, scale), canvas.h);+ const float y = layout.lightboxBottom ? canvas.y + canvas.h - h : canvas.y;+ ImGui::SetNextWindowPos(ImVec2(canvas.x, y));+ ImGui::SetNextWindowSize(ImVec2(canvas.w, h));+ ImGui::PushStyleColor(ImGuiCol_WindowBg, kStripBg);+ ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8 * scale, 0));+ ImGui::PushStyleVar(ImGuiStyleVar_WindowBorderSize, 0.0f);+ ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 0.0f);+ const bool visible =+ ImGui::Begin("LightBox", nullptr,+ ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings |+ ImGuiWindowFlags_NoFocusOnAppearing | ImGuiWindowFlags_NoScrollWithMouse);+ ImGui::PopStyleVar(3);+ ImGui::PopStyleColor();+ if (!visible) {+ ImGui::End();+ return;+ }+ ImDrawList* wdl = ImGui::GetWindowDrawList();+ const ImVec2 wp = ImGui::GetWindowPos(), ws = ImGui::GetWindowSize();+ // 1 px edge toward the canvas.+ const float edge = layout.lightboxBottom ? wp.y : wp.y + ws.y - 1.0f;+ wdl->AddLine(ImVec2(wp.x, edge), ImVec2(wp.x + ws.x, edge), IM_COL32(14, 14, 16, 255));++ ImGui::SetCursorPosY(std::round((kHeader * scale - ImGui::GetFrameHeight()) * 0.5f));+ drawHeader(app, ws.x - 16.0f * scale);++ const std::vector<AssetEntry> items = entries(app);+ const float tile = kTile * scale, rowH = (kTile + kLabel + 4.0f) * scale, gap = kGap * scale;+ const int columns = int((items.size() + size_t(rows) - 1) / size_t(rows));+ const float contentW = float(columns) * (tile + gap);++ ImGui::PushStyleVar(ImGuiStyleVar_ScrollbarSize, 6.0f * scale);+ ImGui::SetNextWindowContentSize(ImVec2(contentW, float(rows) * rowH));+ ImGui::BeginChild("##lbstrip", ImVec2(0, float(rows) * rowH + 8.0f * scale), ImGuiChildFlags_None,+ ImGuiWindowFlags_HorizontalScrollbar | ImGuiWindowFlags_NoScrollWithMouse |+ ImGuiWindowFlags_NoBackground);+ ImGui::PopStyleVar();+ if (scrollTo_ >= 0.0f) {+ ImGui::SetScrollX(scrollTo_);+ scrollTo_ = -1.0f;+ }+ const ImGuiIO& io = ImGui::GetIO();+ const bool stripHovered = ImGui::IsWindowHovered(ImGuiHoveredFlags_AllowWhenBlockedByActiveItem);+ // The wheel scrolls sideways, a tile column per notch.+ if (stripHovered && (io.MouseWheel != 0.0f || io.MouseWheelH != 0.0f))+ ImGui::SetScrollX(ImGui::GetScrollX() - (io.MouseWheel + io.MouseWheelH) * (tile + gap));+ // Left-drag scrubs the strip (after 4 px, so a click stays a click).+ if (stripHovered && ImGui::IsMouseClicked(ImGuiMouseButton_Left)) {+ pressing_ = true;+ scrubbed_ = tileDrag_ = false;+ pressX_ = io.MousePos.x;+ pressY_ = io.MousePos.y;+ pressScroll_ = ImGui::GetScrollX();+ pressTile_ = -1;+ }+ if (pressing_ && ImGui::IsMouseDown(ImGuiMouseButton_Left) && !tileDrag_) {+ if (std::abs(io.MousePos.x - pressX_) > 4.0f) scrubbed_ = true;+ if (scrubbed_) ImGui::SetScrollX(pressScroll_ - (io.MousePos.x - pressX_));+ // Pulled out of the LightBox onto the canvas: drop it there to load it.+ const float outside = layout.lightboxBottom ? wp.y - io.MousePos.y : io.MousePos.y - (wp.y + ws.y);+ if (pressTile_ >= 0 && outside > 12.0f) {+ tileDrag_ = true;+ dragEntry_ = items[size_t(pressTile_)];+ ImGui::SetScrollX(pressScroll_);+ }+ }++ const float scrollX = ImGui::GetScrollX();+ const float viewW = ImGui::GetWindowWidth();+ const ImVec2 base = ImGui::GetCursorScreenPos();+ for (size_t i = 0; i < items.size(); ++i) {+ const AssetEntry& e = items[i];+ const int col = int(i) / rows, row = int(i) % rows;+ const float x = float(col) * (tile + gap);+ if (x + tile < scrollX - tile || x > scrollX + viewW + tile) continue; // off screen: no thumbnail work+ ImGui::SetCursorScreenPos(ImVec2(base.x + x, base.y + float(row) * rowH + 4.0f * scale));+ const ImTextureID tex = thumbnail(app, e);+ const std::string key = e.path.empty() ? e.name : e.path;+ const bool selected = key == selected_ ||+ (e.kind == AssetKind::Material && app.renderSettings_.matcap == e.index) ||+ (e.kind == AssetKind::BrushType && isActiveBrushType(app, e.index)) ||+ (e.kind == AssetKind::Recipe && !app.paintMode_ && app.doc_.activeBrush == e.index);+ const std::string id = e.name + "##lb" + std::to_string(i);+ const bool clicked = AssetTile(id.c_str(), tex, glyphFor(e.kind), e.name, tile, selected);+ if (ImGui::IsItemActivated()) pressTile_ = int(i);+ if (clicked && !scrubbed_) selected_ = key;+ const bool doubleClicked = ImGui::IsItemHovered() && ImGui::IsMouseDoubleClicked(ImGuiMouseButton_Left);+ if (doubleClicked && !scrubbed_) {+ selected_ = key;+ activate(app, e, (SDL_GetModState() & SDL_KMOD_SHIFT) != 0);+ }+ // Plain hover: the full name and path. Ctrl: the details.+ if (ImGui::IsItemHovered(ImGuiHoveredFlags_DelayNormal) && !io.KeyCtrl && !pressing_ &&+ !ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId)) {+ ImGui::BeginTooltip();+ ImGui::TextUnformatted(e.name.c_str());+ if (!e.path.empty()) ImGui::TextDisabled("%s", e.path.c_str());+ ImGui::EndTooltip();+ }+ std::string details =+ e.kind == AssetKind::Folder || e.kind == AssetKind::Up ? "Double-click to open the folder."+ : e.kind == AssetKind::Mesh || e.kind == AssetKind::Primitive || e.kind == AssetKind::Project+ ? "Double-click to open (replaces the scene); Shift+double-click appends it as a SubTool."+ : e.kind == AssetKind::Image ? "Double-click for what to do with the image."+ : "Double-click to use it.";+ if (e.size) details += "\n" + sizeText(e.size) + ", modified " + dateText(e.mtime);+ ui::HelpText(e.name.c_str(), nullptr, details.c_str(), e.path.empty() ? "LightBox" : e.path.c_str());+ if (ImGui::BeginPopupContextItem()) {+ contextMenu(app, e);+ ImGui::EndPopup();+ }+ }+ // Only folders (or nothing): say how things get here.+ const bool onlyFolders = std::all_of(items.begin(), items.end(), [](const AssetEntry& e) {+ return e.kind == AssetKind::Folder || e.kind == AssetKind::Up;+ });+ if (onlyFolders) {+ const char* hint = filter_[0] ? nullptr+ : place_.tab == LibraryTab::Project+ ? "Nothing here yet. Projects you save (Ctrl+S) into the User folder show up here."+ : place_.tab == LibraryTab::QuickSave+ ? "Nothing here yet. QuickSave keeps timestamped copies of your scene here."+ : place_.tab == LibraryTab::Recent ? "Nothing here yet. Files you open show up here."+ : place_.tab == LibraryTab::Image+ ? "Nothing here yet. Put reference images in the User folder."+ : place_.tab == LibraryTab::Splats+ ? "Nothing here yet. Put Gaussian splat captures (.ply, .splat) in the User folder."+ : "Nothing here yet.";+ const float x =+ base.x ++ (items.empty() ? 8.0f : float((items.size() + size_t(rows) - 1) / size_t(rows)) * (tile + gap) + 12.0f);+ ImGui::SetCursorScreenPos(ImVec2(x, base.y + 4.0f * scale + tile * 0.5f - ImGui::GetTextLineHeight() * 0.5f));+ if (hint)+ ImGui::TextDisabled("%s", hint);+ else+ ImGui::TextDisabled("Nothing here matches \"%s\".", filter_);+ }+ AssetTileHoverGlow();+ ImGui::EndChild();++ // Image tiles: what to do with the picture.+ if (!imageMenu_.empty()) {+ ImGui::OpenPopup("##lbimage");+ if (ImGui::BeginPopup("##lbimage")) {+ AssetEntry e;+ e.kind = AssetKind::Image;+ e.path = imageMenu_;+ e.name = utf8(fsPath(imageMenu_).filename());+ ImGui::TextDisabled("%s", e.name.c_str());+ ImGui::Separator();+ bool done = false;+ if (ImGui::MenuItem(ICON_LC_SPARKLES " Generate 3D...")) app.openPath(e.path), done = true;+ if (ImGui::MenuItem("Relief from image")) {+ app.confirmDiscard([&app, p = e.path] { app.runCommand("image_relief", {{"path", p}}); });+ done = true;+ }+ if (ImGui::MenuItem("Inflate image")) {+ app.confirmDiscard([&app, p = e.path] { app.runCommand("image_inflate", {{"path", p}}); });+ done = true;+ }+ if (ImGui::MenuItem("Project onto model")) app.runCommand("image_project", {{"path", e.path}}), done = true;+ if (ImGui::MenuItem("Use as alpha"))+ app.runCommand("brush_set_alpha", {{"path", e.path}, {"invert", app.alphaInvert_}}), done = true;+ if (done) imageMenu_.clear();+ ImGui::EndPopup();+ } else {+ imageMenu_.clear();+ }+ }+ ImGui::End();++ // A tile dragged out of the strip follows the cursor; releasing it over the canvas loads it.+ if (tileDrag_) {+ const ImTextureID tex = thumbnail(app, dragEntry_);+ const float s = 64.0f * scale;+ ImDrawList* fg = ImGui::GetForegroundDrawList();+ const ImVec2 a(io.MousePos.x - s * 0.5f, io.MousePos.y - s * 0.5f), b(a.x + s, a.y + s);+ fg->AddRectFilled(a, b, IM_COL32(42, 42, 46, 220), 4.0f);+ if (tex) fg->AddImageRounded(tex, a, b, ImVec2(0, 0), ImVec2(1, 1), IM_COL32(255, 255, 255, 220), 4.0f);+ fg->AddRect(a, b, kAccent, 4.0f, 0, 1.5f);+ }+ if (pressing_ && !ImGui::IsMouseDown(ImGuiMouseButton_Left)) {+ if (tileDrag_ && canvas.contains(io.MousePos.x, io.MousePos.y) && !ImGui::GetCurrentContext()->HoveredWindow)+ activate(app, dragEntry_, (SDL_GetModState() & SDL_KMOD_SHIFT) != 0);+ pressing_ = tileDrag_ = false;+ }+ }++ void LightBox::drawPreferences(App& app) {+ UiLayout& layout = app.layout_;+ ImGui::Checkbox("Show at startup##lightbox", &showAtStartup);+ ui::HelpText("Show at startup", nullptr,+ "Open the LightBox on the Project tab when SculptForge starts (as ZBrush does).",+ "Preferences > LightBox");+ ImGui::SetNextItemWidth(-1);+ ImGui::SliderInt("##lbrowspref", &layout.lightboxRows, 1, 4, "Rows %d");+ ui::HelpText("Rows", nullptr, "Rows of thumbnails in the LightBox strip.", "Preferences > LightBox");+ int placement = layout.lightboxBottom ? 1 : 0;+ ImGui::TextUnformatted("Placement");+ ImGui::SameLine();+ if (ImGui::RadioButton("Top##lbplace", placement == 0)) layout.lightboxBottom = false;+ ImGui::SameLine();+ if (ImGui::RadioButton("Bottom##lbplace", placement == 1)) layout.lightboxBottom = true;+ ui::HelpText("Placement", nullptr, "Show the LightBox along the top or the bottom of the canvas.",+ "Preferences > LightBox");+ ImGui::TextDisabled("Library folder");+ ImGui::TextWrapped("%s", app.library_.user.empty() ? "(none)" : app.library_.user.c_str());+ if (!app.library_.user.empty() && ImGui::Button(ICON_LC_FOLDER_OPEN " Show library folder"))+ SDL_OpenURL(("file://" + app.library_.user).c_str());+ }++ // ---------------------------------------------------------------------------+ // App glue: library folders, actions, QuickSave, project thumbnails+ // ---------------------------------------------------------------------------++ void App::initLightBox() {+ if (const char* base = SDL_GetBasePath()) library_.builtin = findBuiltinAssets(base);+ const bool recording = !options_.recordPath.empty() || !options_.renderPath.empty();+ if (!options_.uiTest.empty()) {+ // UI tests get an empty library of their own (like their brush library), never the artist's.+ const fs::path base =+ options_.uiOutDir.empty() ? fs::temp_directory_path() / "sculptforge-ui-test" : fsPath(options_.uiOutDir);+ library_.user = utf8(base / "library");+ std::error_code ec;+ fs::remove_all(fsPath(library_.user), ec);+ } else if (!recording) {+ const char* docs = SDL_GetUserFolder(SDL_FOLDER_DOCUMENTS);- library_.user = defaultUserLibrary(docs ? docs : "", prefDir_);++ library_.user = !uiPrefs_.libraryFolder.empty() ? uiPrefs_.libraryFolder // Preferences > LightBox++ : defaultUserLibrary(docs ? docs : "", prefDir_);+ }+ if (!library_.user.empty()) {+ std::string err;+ if (!ensureUserLibrary(library_.user, err)) {+ SDL_Log("LightBox library: %s", err.c_str());+ library_.user.clear();+ }+ }+ // Thumbnails are cached on disk for the artist; tests and recordings render fresh ones.+ if (interactive() && options_.uiTest.empty() && !prefDir_.empty()) thumbs_.setCacheDir(prefDir_ + "thumbs");+ if (const char* dir = SDL_getenv("SCULPTFORGE_THUMBNAIL_CACHE")) thumbs_.setCacheDir(dir); // to look at them++ // Cube is a LightBox primitive like Sphere and Plane (new_sphere / new_plane live in the core).+ commands_.add({"new_cube",+ "Replace the scene with a new cube ready for sculpting (one polygroup per side).",+ {{"resolution", ParamSpec::Type::Number, "Cells along each edge (1-256). Default 48.", false}},+ [](Document& doc, const Args& a) -> CommandResult {+ const int res = std::clamp(int(argNumber(a, "resolution", 48)), 1, 256);+ doc.setMesh(makeCube(res), "Cube");+ doc.path.clear();+ return {true, "Created cube with " + std::to_string(doc.mesh.triangleCount()) + " triangles"};+ }});++ // Projects carry a 256 px picture of the current view, so the LightBox shows them without loading.+ setProjectThumbnailProvider([this](const Document&, Image& out) {+ if (!glContext_ || SDL_GL_GetCurrentContext() != glContext_) return false; // not the UI thread+ constexpr GLenum kFramebufferBinding = 0x8CA6, kViewport = 0x0BA2;+ GLint fbo = 0, viewport[4] = {};+ gl::GetIntegerv(kFramebufferBinding, &fbo);+ gl::GetIntegerv(kViewport, viewport);+ Camera cam = camera_;+ cam.aspect = 1.0f;+ std::string err;+ out.width = out.height = kProjectThumbnailSize;+ const bool ok = renderer_.renderToImage(cam, out.width, out.height, renderSettings_, out.rgba, err);+ gl::BindFramebuffer(GL_FRAMEBUFFER, GLuint(fbo));+ gl::Viewport(viewport[0], viewport[1], viewport[2], viewport[3]);+ return ok;+ });++ auto add = [this](const char* id, const char* label, const char* icon, const char* palette, const char* shortcut,+ const char* description, std::function<void()> run, std::function<bool()> checked = nullptr) {+ Action a;+ a.id = id;+ a.label = label;+ a.icon = icon;+ a.palette = palette;+ a.shortcut = shortcut;+ a.description = description;+ a.run = std::move(run);+ a.checked = std::move(checked);+ actions_.add(std::move(a));+ };+ add(+ "ui.lightbox", "LightBox", ICON_LC_IMAGES, "LightBox", ",",+ "Show or hide the LightBox: thumbnails of your projects, models, brushes, alphas, materials, images, splats "+ "and "+ "QuickSaves along the top of the canvas. Double-click to load.",+ [this] { lightbox_.toggle(); }, [this] { return lightbox_.open(); });+ add("ui.picker.brush", "Brush picker", ICON_LC_BRUSH, "Brush", "B",+ "Pop up every brush under the cursor. Type the first letter of a brush, then the orange letter on its tile "+ "(B S T = Standard).",+ [] { openPicker(Picker::Brush, ImVec2(-1, -1)); });+ add("ui.picker.stroke", "Stroke picker", ICON_LC_SPLINE, "Stroke", "",+ "Pop up the stroke types: Dots, DragRect, Spray and LazyMouse.",+ [] { openPicker(Picker::Stroke, ImVec2(-1, -1)); });+ add("ui.picker.alpha", "Alpha picker", ICON_LC_CIRCLE_DASHED, "Alpha", "",+ "Pop up the brush alphas: built-in stamps and images from your library.",+ [] { openPicker(Picker::Alpha, ImVec2(-1, -1)); });+ add("ui.picker.material", "Material picker", ICON_LC_SUN, "Material", "M",+ "Pop up the materials under the cursor. Hover one to preview it on the model; click to keep it.",+ [] { openPicker(Picker::Material, ImVec2(-1, -1)); });+ add("ui.size_popup", "Draw Size at cursor", ICON_LC_CIRCLE, "Draw", "S",+ "A Draw Size slider under the cursor: drag it, or type a number and press Enter.",+ [this] { PickerUi::sizePopup(*this, false); });+ add("ui.strength_popup", "Strength at cursor", ICON_LC_CIRCLE_DOT, "Draw", "I",+ "A Strength slider under the cursor: drag it, or type a number and press Enter.",+ [this] { PickerUi::sizePopup(*this, true); });+ add("file.quicksave", "QuickSave", ICON_LC_SAVE, "File", "",+ "Save a timestamped copy of the whole scene to the QuickSave folder of your library (the last 10 are kept). "+ "Your project file is not changed. Find them in the LightBox QuickSave tab.",+ [this] { quickSave(); });++ // ZBrush opens the LightBox at startup on the Project tab (never in tests, renders or recordings).- if (lightbox_.showAtStartup && interactive() && options_.uiTest.empty() && options_.openPath.empty())++ if (uiPrefs_.lightboxAtStartup && interactive() && options_.uiTest.empty() && options_.openPath.empty())+ lightbox_.show(LibraryTab::Project);+ }+-CanvasRect App::lightBoxCanvas() const {- // Below the menu bar, the whole window wide (the shell replaces this with its canvasRect()).- const ImGuiViewport* vp = ImGui::GetMainViewport();- const float top = hideUi_ ? 0.0f : ImGui::GetFrameHeight();- return {vp->Pos.x, vp->Pos.y + top, vp->Size.x, vp->Size.y - top};-}-+ void App::drawLightBoxUi() {+ thumbs_.pump(renderer_);- lightbox_.draw(*this, lightBoxCanvas());++ lightbox_.draw(*this, canvasRect());+ drawPickers(*this);+ }++ bool App::lightBoxKey(SDL_Keycode key, SDL_Keymod mod) {+ if (mod & (SDL_KMOD_CTRL | SDL_KMOD_ALT | SDL_KMOD_GUI | SDL_KMOD_SHIFT)) return false;+ const char* id = key == SDLK_COMMA ? "ui.lightbox"+ : key == SDLK_B ? "ui.picker.brush"+ : key == SDLK_M ? "ui.picker.material"+ : key == SDLK_S ? "ui.size_popup"+ : key == SDLK_I ? "ui.strength_popup"+ : nullptr;+ const Action* a = id ? actions_.find(id) : nullptr;+ if (!a || !a->run) return false;+ actions_.touch(a->id);+ a->run();+ return true;+ }++ void App::quickSave() {+ if (library_.user.empty()) {+ status_ = "QuickSave needs a library folder (Preferences > LightBox)";+ return;+ }+ const std::string folder = library_.user + "/QuickSave";+ std::error_code ec;+ fs::create_directories(fsPath(folder), ec);+ const auto now = std::chrono::system_clock::now();+ const std::string path =+ nextQuickSavePath(folder, std::chrono::duration_cast<std::chrono::seconds>(now.time_since_epoch()).count());+ storeProjectSettings();+ std::string err;+ // A copy: the document keeps its own path and unsaved state, as with ZBrush's QuickSave.+ if (!saveProject(path, doc_, err)) {+ status_ = "QuickSave failed: " + err;+ lastCommandOk_ = false;+ return;+ }+ pruneQuickSaves(folder);+ libraryScanner_.invalidate();+ status_ = "QuickSaved " + utf8(fsPath(path).filename());+ lastCommandOk_ = true;+ }++ } // namespace sfdiff --cc src/app/Palettes.cppindex 22c5fa73,00000000..34ab6564mode 100644,000000..100644--- a/src/app/Palettes.cpp+++ b/src/app/Palettes.cpp@@@ -1,406 -1,0 +1,408 @@@+// SculptForge - open source digital sculpting+// SPDX-License-Identifier: GPL-3.0-or-later+//+// The palettes of the palette bar (docs/ui-design.md §3.2), listed+// alphabetically like ZBrush's. Each body is one function, drawn the same way+// in a drop-down and in a tray. ZBrush's Tool palette holds the SubTool,+// Layers, Geometry, Remesh, Masking, Polygroups, Visibility, Export and+// Display sub-palettes.+#include "app/App.h"++#include "app/Config.h"+#include "app/Demo.h"+#include "app/Shell.h"+#include "app/Theme.h"+#include "app/Ui.h"+#include "core/Matcap.h"++#include <IconsLucide.h>++#include <algorithm>+#include <cstdio>+#include <iterator>++namespace sf {++const PaletteDef* palettes(int& count) {+ // Sorted by name; a new palette lands in alphabetical order by being added in its place here.+ static const PaletteDef kPalettes[] = {+ {"alpha", "Alpha", ICON_LC_CIRCLE_DASHED, nullptr, &App::drawPalette_Alpha},+ {"brush", "Brush", ICON_LC_BRUSH, nullptr, &App::drawPalette_Brush},+ {"color", "Color", ICON_LC_PALETTE, "Polypaint & Materials", &App::drawPalette_Color},+ {"draw", "Draw", ICON_LC_PENCIL, nullptr, &App::drawPalette_Draw},+ {"edit", "Edit", ICON_LC_UNDO_2, nullptr, &App::drawPalette_Edit},+ {"file", "File", ICON_LC_FILE, nullptr, &App::drawPalette_File},+ {"generate", "Generate", ICON_LC_WAND_SPARKLES, nullptr, &App::drawPalette_Generate},+ {"help", "Help", ICON_LC_CIRCLE_HELP, nullptr, &App::drawPalette_Help},+ {"material", "Material", ICON_LC_SUN, "Polypaint & Materials", &App::drawPalette_Material},+ {"preferences", "Preferences", ICON_LC_SETTINGS, nullptr, &App::drawPalette_Preferences},+ {"render", "Render", ICON_LC_EYE, nullptr, &App::drawPalette_Render},+ {"script", "Script", ICON_LC_SQUARE_TERMINAL, nullptr, &App::drawPalette_Script},+ {"splats", "Splats", ICON_LC_SPARKLE, "Gaussian Splats", &App::drawPalette_Splats},+ {"stroke", "Stroke", ICON_LC_SPLINE, nullptr, &App::drawPalette_Stroke},+ {"tool", "Tool", ICON_LC_BOXES, nullptr, &App::drawPalette_Tool},+ {"transform", "Transform", ICON_LC_MOVE_3D, nullptr, &App::drawPalette_Transform},+ };+ count = int(std::size(kPalettes));+ return kPalettes;+}++const PaletteDef* findPalette(std::string_view id) {+ int count = 0;+ const PaletteDef* list = palettes(count);+ for (int i = 0; i < count; ++i)+ if (id == list[i].id) return &list[i];+ return nullptr;+}++namespace {++// A row of equal-width action buttons filling the line.+void actionRow(App& app, std::initializer_list<const char*> ids) {+ std::vector<const char*> present;+ for (const char* id : ids)+ if (app.actions().find(id)) present.push_back(id);+ if (present.empty()) return;+ const float spacing = ImGui::GetStyle().ItemSpacing.x;+ const float w = (ImGui::GetContentRegionAvail().x - spacing * float(present.size() - 1)) / float(present.size());+ for (size_t i = 0; i < present.size(); ++i) {+ if (i) ImGui::SameLine();+ const Action* a = app.actions().find(present[i]);+ ui::ActionButton(app, present[i], ImVec2(w, 0), a && a->icon ? ui::Look::IconLabel : ui::Look::Label);+ }+}++// Adjacent toggle buttons that read as one control (Zadd | Zsub, X | Y | Z).+void segmented(App& app, std::initializer_list<const char*> ids, float width = -1.0f) {+ const float total = width > 0.0f ? width : ImGui::GetContentRegionAvail().x;+ const float w = (total - float(ids.size() - 1)) / float(ids.size());+ ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(1.0f, ImGui::GetStyle().ItemSpacing.y));+ bool first = true;+ for (const char* id : ids) {+ if (!first) ImGui::SameLine();+ first = false;+ ui::ActionButton(app, id, ImVec2(w, 0));+ ui::HelpAction(app, id);+ }+ ImGui::PopStyleVar();+}++// A menu-style row for an action: label, shortcut on the right, check mark for toggles.+void menuAction(App& app, const char* id) {+ const Action* a = app.actions().find(id);+ if (!a) return;+ const std::string shortcut = app.actions().shortcutText(id);+ const bool enabled = !a->enabled || a->enabled();+ const bool checked = a->checked && a->checked();+ const std::string label = a->label + "##" + a->id; // no icons: they'd misalign with the plain project items+ if (ImGui::MenuItem(label.c_str(), shortcut.empty() ? nullptr : shortcut.c_str(), checked, enabled) && a->run) {+ app.actions().touch(a->id);+ a->run();+ }+ ui::HelpAction(app, id);+}++void hint(const char* text) {+ ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));+ ImGui::TextWrapped("%s", text);+ ImGui::PopStyleColor();+}++} // namespace++bool App::subpalette(const char* id, const char* title) {+ auto& open = layout_.openSubpalettes;+ bool isOpen = std::find(open.begin(), open.end(), id) != open.end();+ const float s = uiScale_;+ const float h = 22.0f * s;+ const ImVec2 p = ImGui::GetCursorScreenPos();+ const float w = ImGui::GetContentRegionAvail().x;+ const bool clicked = ImGui::InvisibleButton((std::string(title) + "##" + id).c_str(), ImVec2(w, h));+ const bool hovered = ImGui::IsItemHovered();+ ImDrawList* dl = ImGui::GetWindowDrawList();+ dl->AddRectFilled(p, ImVec2(p.x + w, p.y + h), theme::u32(hovered ? theme::headerHover : theme::header, isOpen ? 1.0f : 0.75f),+ 2.0f * s);+ if (isOpen) dl->AddRectFilled(p, ImVec2(p.x + 2.0f * s, p.y + h), theme::u32(theme::accent), 0.0f);+ const float ty = p.y + (h - ImGui::GetFontSize()) * 0.5f;+ dl->AddText(ImVec2(p.x + 6.0f * s, ty), theme::u32(isOpen ? theme::accent : theme::textDim),+ isOpen ? ICON_LC_CHEVRON_DOWN : ICON_LC_CHEVRON_RIGHT);+ dl->AddText(ImVec2(p.x + 24.0f * s, ty), theme::u32(isOpen || hovered ? theme::text : theme::text, isOpen ? 1.0f : 0.85f), title);+ ImGui::LogText("%s", title);+ ui::HelpText(title, nullptr,+ "Click to open or close. Opening one closes the others (Shift+click keeps them open; Preferences > "+ "Interface).",+ "Tool");+ if (clicked) {+ if (isOpen) {+ open.erase(std::remove(open.begin(), open.end(), id), open.end());+ } else {+ if (uiPrefs_.oneSubpalette && !(SDL_GetModState() & SDL_KMOD_SHIFT)) {+ // Close the siblings: sub-palettes that share this one's palette prefix ("tool.").+ const std::string prefix = std::string(id).substr(0, std::string(id).find('.') + 1);+ open.erase(std::remove_if(open.begin(), open.end(), [&](const std::string& o) { return o.rfind(prefix, 0) == 0; }),+ open.end());+ }+ open.push_back(id);+ }+ isOpen = !isOpen;+ }+ if (isOpen) ImGui::Dummy(ImVec2(0, 1.0f * s));+ return isOpen;+}++// ---------------------------------------------------------------------------++void App::drawPalette_Alpha() { drawAlphaSection(); }++void App::drawPalette_Brush() {- drawBrushGrid(*this, GridMode::Palette); // the picker's grid (Pickers.cpp)- drawCustomBrushes(); // PanelBrushLibrary.cpp: list, right-click menu++ // Your brushes first (PanelBrushLibrary.cpp: tags, and the right-click menu to share, rename or delete),++ // then every brush as thumbnails (Pickers.cpp, the same grid as the B picker).+ actionRow(*this, {"ui.brush_lab", "ui.brush_gallery"});+ actionRow(*this, {"brush.paste"});++ drawCustomBrushes();+ 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();+ }+ }+ }++ drawBrushGrid(*this, GridMode::Palette);+}++void App::drawPalette_Draw() {+ ImGui::SetNextItemWidth(-1);+ ui::SliderInside("##drawsize", &radiusPx_, 2.0f, 800.0f, "Draw Size %.0f", ImGuiSliderFlags_Logarithmic);+ ui::HelpText("Draw Size", "S", "Brush radius in screen pixels. [ and ] change it by 10%.", "Draw");+ ImGui::SetNextItemWidth(-1);+ ui::SliderInside("##strength", &strength_, 0.01f, 1.0f, "Strength %.2f");+ ui::HelpText("Strength", "I", "How strongly each dab changes the surface (ZBrush Z Intensity).", "Draw");+ segmented(*this, {"draw.sculpt", "draw.paint"});+ segmented(*this, {"draw.zadd", "draw.zsub"});+ actionRow(*this, {"draw.rgb", "draw.front_faces"});+ ImGui::SeparatorText("Tablet");+ ImGui::Checkbox("Pressure > strength", &pressureStrength_);+ ui::HelpAction(*this, "draw.pressure_strength");+ ImGui::Checkbox("Pressure > size", &pressureSize_);+ ui::HelpAction(*this, "draw.pressure_size");+ if (penSeen_) ImGui::Text("Pen pressure: %.2f", penPressure_);+ else ImGui::TextDisabled("No pen detected");+}++void App::drawPalette_Edit() {+ const std::string undoText = doc_.undo.canUndo() ? "Undo " + doc_.undo.undoLabel() : std::string("Undo");+ const std::string redoText = doc_.undo.canRedo() ? "Redo " + doc_.undo.redoLabel() : std::string("Redo");+ ImGui::BeginDisabled(!doc_.undo.canUndo());+ if (ImGui::MenuItem((undoText + "##edit.undo").c_str(), "Ctrl+Z")) runCommand("undo");+ ImGui::EndDisabled();+ ui::HelpAction(*this, "edit.undo");+ ImGui::BeginDisabled(!doc_.undo.canRedo());+ if (ImGui::MenuItem((redoText + "##edit.redo").c_str(), "Ctrl+Shift+Z")) runCommand("redo");+ ImGui::EndDisabled();+ ui::HelpAction(*this, "edit.redo");+ menuAction(*this, "brush.paste");+}++void App::drawPalette_File() {+ menuAction(*this, "file.new_sphere");+ menuAction(*this, "file.new_plane");+ ImGui::Separator();+ menuAction(*this, "file.open");+ drawFileMenuProjectItems(); // Open Recent, Save, Save As, autosave+ ImGui::SeparatorText("Import / Export");+ menuAction(*this, "file.import");+ menuAction(*this, "file.export_obj");+ menuAction(*this, "file.export_glb");+ menuAction(*this, "file.export_lods");+ menuAction(*this, "file.export_usd");+ menuAction(*this, "file.export_fbx");+ menuAction(*this, "file.send_unreal");+ menuAction(*this, "file.save_splats");+ ImGui::Separator();+ drawGozMenu();+ ImGui::Separator();+ menuAction(*this, "file.quit");+}++void App::drawPalette_Generate() {+ actionRow(*this, {"ui.generate3d"});+ hint("Image or text to a sculptable 3D model: Hugging Face (free), fal.ai, Meshy, your ComfyUI server, your own "+ "command, or an offline blockout.");+ ImGui::SeparatorText("From an image");+ if (ImGui::Button(refImage_.empty() ? "Choose image...##generate" : "Change image...##generate", ImVec2(-1, 0))) {+ static const SDL_DialogFileFilter filters[] = {{"Images", "png;jpg;jpeg;bmp;tga;psd;gif"}, {"All files", "*"}};+ SDL_ShowOpenFileDialog(+ [](void* user, const char* const* files, int) {+ if (files && files[0]) static_cast<App*>(user)->queueFile(FileAction::OpenImage, files[0]);+ },+ this, window_, filters, 2, nullptr, false);+ }+ ui::HelpText("Choose image", nullptr, "A sketch, concept, logo, photo or height map (or drop one on the window).", "Generate");+ ImGui::BeginDisabled(refImage_.empty());+ const float third = (ImGui::GetContentRegionAvail().x - 2.0f * ImGui::GetStyle().ItemSpacing.x) / 3.0f;+ if (ImGui::Button("Relief", ImVec2(third, 0)))+ runCommand("image_relief", {{"path", refImagePath_},+ {"depth", double(reliefDepth_)},+ {"resolution", double(reliefDetail_)},+ {"invert", reliefInvert_}});+ ui::HelpText("Relief", nullptr, "Light areas rise: logos, coins, emblems, height maps.", "Generate");+ ImGui::SameLine();+ if (ImGui::Button("Inflate", ImVec2(third, 0)))+ runCommand("image_inflate", {{"path", refImagePath_},+ {"thickness", double(inflateThickness_)},+ {"resolution", double(inflateDetail_)},+ {"subdivisions", 2.0}});+ ui::HelpText("Inflate", nullptr, "Inflates the outline into a rounded blockout.", "Generate");+ ImGui::SameLine();+ if (ImGui::Button("Stamp", ImVec2(third, 0))) projectImageFromView();+ ui::HelpText("Stamp", nullptr, "Projects the image onto the model from this view as surface detail.", "Generate");+ ImGui::EndDisabled();+ if (subpalette("generate.ai", "AI brush provider")) drawAiSettings();+}++void App::drawPalette_Help() {+ menuAction(*this, "help.controls");+ menuAction(*this, "ui.command_palette");+ menuAction(*this, "help.website");+ menuAction(*this, "help.report");+ ImGui::Separator();+ menuAction(*this, "help.about");+}++void App::drawPalette_Preferences() {+ // The sub-palettes come from Config.cpp (Store / Restore UI, interface preferences, hotkeys, LightBox).+ if (subpalette("preferences.config", "Config")) {+ config::drawConfigSection(*this);+ ImGui::TextDisabled("Layout");+ 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));+ }+ }+ if (subpalette("preferences.interface", "Interface")) config::drawInterfaceSection(*this);+ if (subpalette("preferences.hotkeys", "Hotkeys")) config::drawHotkeysSection(*this);+ if (subpalette("preferences.lightbox", "LightBox")) config::drawLightBoxSection(*this);+ if (subpalette("preferences.autosave", "Autosave")) {+ ImGui::SetNextItemWidth(-1);+ ImGui::SliderInt("##autosave", &autosaveMinutes_, 0, 60, autosaveMinutes_ ? "Every %d min" : "Autosave off");+ if (ImGui::IsItemDeactivatedAfterEdit()) saveProjectPrefs();+ ui::HelpText("Autosave", nullptr, "Save a recovery copy this often (0 = off). Restored after a crash.",+ "Preferences > Autosave");+ }+}++void App::drawPalette_Render() {+ ImGui::Checkbox("Wireframe", &renderSettings_.wireframe);+ ui::HelpAction(*this, "view.wireframe");+ ImGui::Checkbox("Show Mesh", &renderSettings_.showMesh);+ ui::HelpAction(*this, "view.mesh");+ ImGui::Checkbox("Show Polypaint", &renderSettings_.showPolypaint);+ ui::HelpAction(*this, "view.polypaint");+ ImGui::Checkbox("Show Mask", &renderSettings_.showMask);+ ui::HelpAction(*this, "view.mask");+ ImGui::Checkbox("Show Polygroups##render", &renderSettings_.showPolygroups);+ ui::HelpAction(*this, "view.polygroups");+ ImGui::BeginDisabled(doc_.splats.empty());+ ImGui::Checkbox("Show Splats", &renderSettings_.showSplats);+ ImGui::EndDisabled();+ ui::HelpAction(*this, "view.splats");+ actionRow(*this, {"view.frame"});+}++void App::drawPalette_Script() {+ const bool any = actions_.find("ui.console") || actions_.find("script.run_file");+ actionRow(*this, {"ui.console"});+ actionRow(*this, {"script.run_file"});+ actionRow(*this, {"script.copy_session", "script.clear_console"});+ if (!any)+ hint("Every action is a script command: run them with --script \"subdivide; remesh resolution=200\" or the "+ "sculptforge-cli tool.");+}+- void App::drawPalette_Stroke() { drawStrokeSection(); }++void App::drawPalette_Stroke() { drawStrokeGrid(*this, GridMode::Palette); } // Pickers.cpp, as in the stroke picker++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.symmetry_x", "transform.symmetry_y", "transform.symmetry_z"});+ actionRow(*this, {"view.frame", "subtool.solo"});+ actionRow(*this, {"view.polyf"});+}++} // namespace sfdiff --cc src/app/PanelBrushLibrary.cppindex 69c1d439,69c1d439..5f953eae--- a/src/app/PanelBrushLibrary.cpp+++ b/src/app/PanelBrushLibrary.cpp@@@ -44,21 -44,21 +44,6 @@@ const char* brushTag(const BrushRecipereturn nullptr;}--std::string brushOriginText(const BrushRecipe& b) {-- switch (b.origin.source) {-- case BrushSource::Builtin: return "Built-in brush";-- case BrushSource::User:-- return b.origin.overrides != BrushSource::Session-- ? std::string("Your version - replaces the ") + brushSourceName(b.origin.overrides) +-- " brush of the same name (delete it to go back)"-- : "In your brush library";-- case BrushSource::Gallery: return "From the community gallery, in your brush library";-- case BrushSource::Studio: return "Studio brush (shared folder, read-only)";-- case BrushSource::Project: return "From the open project, not in your brush library";-- case BrushSource::Session: return "Not saved - refine it in Brush Lab to keep it";-- }-- return "";--}// `text` shortened with "..." to fit `width` pixels.std::string fitText(const std::string& text, float width) {@@@ -86,6 -86,6 +71,23 @@@ std::string fileUrl(const std::string&} // namespace++// Where a brush comes from, in words (list tooltips, picker Quick Info).++std::string brushOriginText(const BrushRecipe& b) {++ switch (b.origin.source) {++ case BrushSource::Builtin: return "Built-in brush";++ case BrushSource::User:++ return b.origin.overrides != BrushSource::Session++ ? std::string("Your version - replaces the ") + brushSourceName(b.origin.overrides) +++ " brush of the same name (delete it to go back)"++ : "In your brush library";++ case BrushSource::Gallery: return "From the community gallery, in your brush library";++ case BrushSource::Studio: return "Studio brush (shared folder, read-only)";++ case BrushSource::Project: return "From the open project, not in your brush library";++ case BrushSource::Session: return "Not saved - refine it in Brush Lab to keep it";++ }++ return "";++}++void App::initBrushLibrary() {BrushLibraryPaths& paths = brushLibraryPaths();if (!options_.uiTest.empty()) {diff --cc src/app/PanelBrushes.cppindex cccfefdd,2116a7b5..d43ba205--- a/src/app/PanelBrushes.cpp+++ b/src/app/PanelBrushes.cpp@@@ -38,95 -35,57 +38,43 @@@ void App::pollAlphaFile()alphaPath.swap(pendingAlphaPath_);}if (!alphaPath.empty()) runCommand("brush_set_alpha", {{"path", alphaPath}, {"invert", alphaInvert_}});+}- // 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");- 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();-- }- 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);- 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");- ImGui::SliderFloat("##scatter", &sprayScatter_, 0.0f, 2.0f, "scatter %.2f");-- } else if (strokeType_ == StrokeType::LazyMouse) {-- ImGui::SetNextItemWidth(-1);- 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::SliderFloat("##lazy", &lazyMouse_.radius, 1.0f, 300.0f, "lazy radius %.0f px");-- }- }--- 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();- }- if (ImGui::Button("Load image...", ImVec2(-1, 0)))+ };+ // 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();- }++ drawAlphaGrid(*this, GridMode::Palette); // built-in and library alphas (Pickers.cpp), as in the alpha picker+ 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,diff --cc src/app/PanelPolypaint.cppindex 3a2dc0cc,a86c165e..2accc61c--- a/src/app/PanelPolypaint.cpp+++ b/src/app/PanelPolypaint.cpp@@@ -120,49 -128,34 +120,13 @@@ void App::drawPalette_Color()if (ImGui::Button("Clear", ImVec2(half, 0))) runCommand("paint_clear");ImGui::EndDisabled();ImGui::Checkbox("Show polypaint", &renderSettings_.showPolypaint);+}- // Material palette grid: Studio plus every MatCap, `tile` px square.- void App::drawMaterialGrid(float tile) {- const float scale = uiScale_;- ImGui::SeparatorText("Material");-- const float spacing = ImGui::GetStyle().ItemSpacing.x;- const int columns = std::max(1, int((ImGui::GetContentRegionAvail().x + spacing) / (tile + spacing)));- tile = (ImGui::GetContentRegionAvail().x - float(columns - 1) * spacing) / float(columns);- const float tile = (ImGui::GetContentRegionAvail().x - 3 * spacing) / 4.0f;-- auto outline = [&](bool selected) {- if (!selected && !ImGui::IsItemHovered()) return;- if (!selected) return;-- ImGui::GetWindowDrawList()->AddRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(),- ImGui::GetColorU32(ImGuiCol_SliderGrab, selected ? 1.0f : 0.6f), 4.0f, 0,- 2.0f * scale);- ImGui::GetColorU32(ImGuiCol_ButtonActive), 4.0f, 0, 2.0f * scale);-- };- 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");- if (ImGui::Button("Studio", ImVec2(tile, tile))) renderSettings_.matcap = -1;- if (ImGui::IsItemHovered()) ImGui::SetTooltip("Studio lights with the Tools material colour");-- outline(renderSettings_.matcap < 0);-- for (int i = 0; i < matcapCount(); ++i) {- if ((i + 1) % columns != 0) ImGui::SameLine();- if ((i + 1) % 4 != 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.- 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)))- if (ImGui::ImageButton("##matcap", ImTextureID(uintptr_t(tex)), ImVec2(tile, tile), ImVec2(0, 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);-- }- }-- ImGui::Text("%s", renderSettings_.matcap < 0 ? "Studio" : matcapName(renderSettings_.matcap));- ImGui::End();+// 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));++ sf::drawMaterialGrid(*this, GridMode::Palette); // Pickers.cpp, as in the material picker (M)+ ImGui::ColorEdit3("Base colour", &renderSettings_.baseColor.x, ImGuiColorEditFlags_NoInputs);+ ui::HelpText("Base colour", nullptr, "Colour of the Studio material (the clay colour).", "Material");}} // namespace sfdiff --cc src/app/Pickers.cppindex 00000000,00211b4d..a8385c1amode 000000,100644..100644--- a/src/app/Pickers.cpp+++ b/src/app/Pickers.cpp@@@ -1,0 -1,991 +1,1000 @@@+ // SculptForge - open source digital sculpting+ // SPDX-License-Identifier: GPL-3.0-or-later+ //+ // Pop-up pickers (ZBrush's brush, stroke, alpha and material pop-ups), the+ // Draw Size / Strength sliders at the cursor, and the thumbnail tile.+ #include "app/Pickers.h"++ #include "app/App.h"+ #include "app/AssetLibrary.h"+ #include "app/Ui.h"+ #include "core/BrushLibrary.h"+ #include "core/Matcap.h"++ #include <IconsLucide.h>++ #include <imgui_internal.h>++ #include <algorithm>+ #include <array>+ #include <cctype>+ #include <cmath>+ #include <cstring>++ namespace sf {++ namespace {++ // Theme tokens (docs/ui-design.md section 10).+ constexpr ImU32 kAccent = IM_COL32(240, 136, 46, 255);+ constexpr ImU32 kTileBg = IM_COL32(42, 42, 46, 255);+ constexpr ImU32 kTileHover = IM_COL32(54, 54, 59, 255);+ constexpr ImU32 kTileBorder = IM_COL32(18, 18, 20, 255);+ constexpr ImU32 kGlyph = IM_COL32(140, 140, 144, 255);+ constexpr ImU32 kText = IM_COL32(216, 216, 216, 255);+ constexpr ImU32 kTextDim = IM_COL32(140, 140, 144, 255);+ constexpr ImU32 kPanelBg = IM_COL32(37, 37, 40, 252); // #252528, pop-ups++ const SDL_DialogFileFilter kAlphaFilters[] = {{"Images", "png;jpg;jpeg;bmp;tga;psd;gif"}, {"All files", "*"}};++ std::string lower(std::string s) {+ for (auto& c : s)+ c = char(std::tolower(static_cast<unsigned char>(c)));+ return s;+ }+ // Shortens `text` with "..." to fit `width`.+ std::string elide(const std::string& text, float width) {+ if (ImGui::CalcTextSize(text.c_str()).x <= width) return text;+ std::string s = text;+ while (!s.empty() && ImGui::CalcTextSize((s + "...").c_str()).x > width) {+ s.pop_back();+ while (!s.empty() && (static_cast<unsigned char>(s.back()) & 0xC0) == 0x80)+ s.pop_back(); // whole UTF-8 chars+ }+ return s + "...";+ }++ struct Glow {+ int frame = -1;+ ImRect rect;+ ImTextureID tex = ImTextureID(0);+ std::string glyph;+ };+ Glow& glow() {+ static Glow g;+ return g;+ }++ // --- Picker state ---++ struct State {+ bool open = false;+ Picker picker = Picker::Brush;+ ImVec2 anchor{0, 0};+ bool underMouse = false;+ int openedFrame = -1, closedFrame = -1;+ int keysFrom = 0; // frame from which typed keys count (not the key that opened it)+ bool addToShelf = false;+ std::string typed; // brush picker: letters typed so far+ // Material hover preview: the material to go back to.+ bool previewing = false;+ int savedMatcap = -1;+ // Draw Size / Strength at the cursor.+ int slider = -1; // 0 = size, 1 = strength+ ImVec2 sliderAt{0, 0};+ int sliderFrame = -1;+ std::string sliderTyped;+ bool sliderWasActive = false;+ // Recently used brushes (ids, newest first).+ std::vector<std::string> recent;+ std::string lastActive;+ };+ State& st() {+ static State s;+ return s;+ }++ void closePicker() {+ State& s = st();+ if (!s.open) return;+ s.open = false;+ s.closedFrame = ImGui::GetFrameCount();+ s.typed.clear();+ }++ // Lays tiles out left to right, `columns` per row.+ void tileGrid(int& column, int columns) {+ if (column > 0 && column < columns) ImGui::SameLine(0.0f, 6.0f);+ if (column >= columns) column = 0;+ ++column;+ }++ int columnsFor(float tile, GridMode mode) {+ if (mode == GridMode::Popup) return 6;+ return std::max(1, int((ImGui::GetContentRegionAvail().x + 6.0f) / (tile + 6.0f)));+ }++ void sectionHeader(const char* text) {+ ImGui::Dummy(ImVec2(0, 2));+ ImGui::PushStyleColor(ImGuiCol_Text, ImGui::GetStyleColorVec4(ImGuiCol_TextDisabled));+ ImGui::SeparatorText(text);+ ImGui::PopStyleColor();+ }++ // Hover "Quick Info": a large thumbnail and the description, as ZBrush shows for palette items.+ void quickInfo(ImTextureID tex, const char* glyph, const std::string& title, const std::string& text,+ const std::string& footer = {}) {+ if (!ImGui::IsItemHovered(ImGuiHoveredFlags_DelayShort | ImGuiHoveredFlags_NoSharedDelay) ||+ ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId) || ImGui::GetIO().KeyCtrl)+ return;+ ImGui::SetNextWindowSizeConstraints(ImVec2(0, 0), ImVec2(340, FLT_MAX));+ ImGui::BeginTooltip();+ const float big = 192.0f * 0.75f;+ if (tex)+ ImGui::Image(tex, ImVec2(big, big));+ else if (glyph) {+ ImGui::Dummy(ImVec2(big, big));+ ImDrawList* dl = ImGui::GetWindowDrawList();+ dl->AddRectFilled(ImGui::GetItemRectMin(), ImGui::GetItemRectMax(), kTileBg, 4.0f);+ const float fs = ImGui::GetFontSize() * 3.0f;+ const ImVec2 sz = ImGui::GetFont()->CalcTextSizeA(fs, FLT_MAX, 0, glyph);+ const ImVec2 c = ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()).GetCenter();+ dl->AddText(ImGui::GetFont(), fs, ImVec2(c.x - sz.x * 0.5f, c.y - sz.y * 0.5f), kGlyph, glyph);+ }+ ImGui::TextUnformatted(title.c_str());+ if (!text.empty()) {+ ImGui::PushTextWrapPos(330.0f);+ ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.78f, 0.78f, 0.78f, 1.0f));+ ImGui::TextUnformatted(text.c_str());+ ImGui::PopStyleColor();+ ImGui::PopTextWrapPos();+ }+ if (!footer.empty()) ImGui::TextDisabled("%s", footer.c_str());+ ImGui::EndTooltip();+ }++ // Opens the picker's window at its anchor (or the mouse); returns false when it isn't showing.+ bool beginPickerWindow(const char* title, float width) {+ State& s = st();+ const ImGuiViewport* vp = ImGui::GetMainViewport();+ ImVec2 pos = s.anchor;+ if (s.underMouse) pos = ImVec2(s.anchor.x - 24.0f, s.anchor.y - 24.0f);+ ImGui::SetNextWindowPos(pos, ImGuiCond_Appearing);+ ImGui::SetNextWindowSizeConstraints(ImVec2(width, 0), ImVec2(width, vp->Size.y - 60.0f));+ if (s.openedFrame == ImGui::GetFrameCount()) ImGui::SetNextWindowFocus();+ ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);+ ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(10, 8));+ ImGui::PushStyleColor(ImGuiCol_WindowBg, kPanelBg);+ ImGui::PushStyleColor(ImGuiCol_Border, IM_COL32(64, 64, 70, 255));+ const bool visible = ImGui::Begin(title, nullptr,+ ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoResize |+ ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings |+ ImGuiWindowFlags_AlwaysAutoResize | ImGuiWindowFlags_NoCollapse);+ ImGui::PopStyleColor(2);+ ImGui::PopStyleVar(2);+ // Keep it inside the window (it may have opened near an edge).+ ImGuiWindow* w = ImGui::GetCurrentWindow();+ ImVec2 p = w->Pos;+ p.x = std::clamp(p.x, vp->Pos.x + 4.0f, std::max(vp->Pos.x + 4.0f, vp->Pos.x + vp->Size.x - w->Size.x - 4.0f));+ p.y = std::clamp(p.y, vp->Pos.y + 4.0f, std::max(vp->Pos.y + 4.0f, vp->Pos.y + vp->Size.y - w->Size.y - 4.0f));+ if (p.x != w->Pos.x || p.y != w->Pos.y) ImGui::SetWindowPos(p);+ // A click outside closes it (context menus of its tiles are part of it).+ const bool clicked = ImGui::IsMouseClicked(ImGuiMouseButton_Left) || ImGui::IsMouseClicked(ImGuiMouseButton_Right);+ if (clicked && s.openedFrame != ImGui::GetFrameCount() &&+ !ImGui::IsWindowHovered(ImGuiHoveredFlags_RootAndChildWindows | ImGuiHoveredFlags_AllowWhenBlockedByPopup) &&+ !ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId))+ closePicker();+ return visible;+ }++ void pickerTitle(const char* icon, const char* title, const char* hint) {+ ImGui::TextUnformatted(icon);+ ImGui::SameLine();+ ImGui::TextUnformatted(title);+ if (hint) {+ ImGui::SameLine();+ const float w = ImGui::CalcTextSize(hint).x;+ ImGui::SetCursorPosX(ImGui::GetCursorPosX() + std::max(0.0f, ImGui::GetContentRegionAvail().x - w));+ ImGui::TextDisabled("%s", hint);+ }+ }++ const BrushAlpha& builtinAlpha(int i) {+ static const std::array<BrushAlpha, 3> alphas = {BrushAlpha::round(), BrushAlpha::square(), BrushAlpha::noise()};+ return alphas[size_t(std::clamp(i, 0, 2))];+ }++ } // namespace++ // ---------------------------------------------------------------------------+ // Tiles+ // ---------------------------------------------------------------------------++ bool AssetTile(const char* id, ImTextureID texture, const char* glyph, const std::string& label, float thumbSize,+ bool selected, const char* badge, bool dim) {+ const float labelH = ImGui::GetFontSize() + 4.0f;+ const ImVec2 size(thumbSize, thumbSize + labelH);+ const ImVec2 p = ImGui::GetCursorScreenPos();+ const bool clicked = ImGui::InvisibleButton(id, size);+ const bool hovered = ImGui::IsItemHovered();+ ImDrawList* dl = ImGui::GetWindowDrawList();+ const ImVec2 t0 = p, t1(p.x + thumbSize, p.y + thumbSize);+ dl->AddRectFilled(t0, t1, hovered ? kTileHover : kTileBg, 4.0f);+ if (texture) {+ const float pad = 2.0f;+ dl->AddImageRounded(texture, ImVec2(t0.x + pad, t0.y + pad), ImVec2(t1.x - pad, t1.y - pad), ImVec2(0, 0),+ ImVec2(1, 1), dim ? IM_COL32(255, 255, 255, 110) : IM_COL32_WHITE, 3.0f);+ } else if (glyph) {+ const float fs = std::round(thumbSize * 0.36f);+ const ImVec2 gs = ImGui::GetFont()->CalcTextSizeA(fs, FLT_MAX, 0, glyph);+ dl->AddText(ImGui::GetFont(), fs,+ ImVec2(std::round((t0.x + t1.x - gs.x) * 0.5f), std::round((t0.y + t1.y - gs.y) * 0.5f)), kGlyph,+ glyph);+ }+ dl->AddRect(t0, t1,+ selected ? kAccent+ : hovered ? IM_COL32(90, 90, 96, 255)+ : kTileBorder,+ 4.0f, 0, selected ? 2.0f : 1.0f);+ if (badge && *badge) {+ // The orange key of the brush pop-up: press it to pick this tile.+ const float fs = ImGui::GetFontSize();+ const ImVec2 bs = ImGui::CalcTextSize(badge);+ const ImVec2 b1(t1.x - 3.0f, t0.y + 3.0f + fs + 2.0f), b0(b1.x - std::max(bs.x + 8.0f, fs + 2.0f), t0.y + 3.0f);+ dl->AddRectFilled(b0, b1, kAccent, 3.0f);+ dl->AddText(ImVec2(std::round((b0.x + b1.x - bs.x) * 0.5f), b0.y + 1.0f), IM_COL32(20, 20, 22, 255), badge);+ ImGui::LogText(" [%s]", badge);+ }+ const std::string shown = elide(label, thumbSize);+ const ImVec2 ls = ImGui::CalcTextSize(shown.c_str());+ dl->AddText(ImVec2(std::round(p.x + (thumbSize - ls.x) * 0.5f), t1.y + 2.0f),+ selected ? IM_COL32(255, 255, 255, 255)+ : dim ? kTextDim+ : kText,+ shown.c_str());+ ImGui::LogText(" %s", label.c_str()); // drawn directly: tell the log (UI tests read it) too+ if (hovered) {+ Glow& g = glow();+ g.frame = ImGui::GetFrameCount();+ g.rect = ImRect(t0, t1);+ g.tex = texture;+ g.glyph = glyph ? glyph : "";+ }+ return clicked;+ }++ void AssetTileHoverGlow() {+ Glow& g = glow();+ if (g.frame != ImGui::GetFrameCount() || !g.tex || ImGui::IsPopupOpen(nullptr, ImGuiPopupFlags_AnyPopupId)) return;+ if (ImGui::IsMouseDragging(ImGuiMouseButton_Left)) return;+ // ZBrush's thumbnail glow: the hovered thumbnail pops out at 1.5x.+ const float s = g.rect.GetWidth() * 1.5f;+ const ImVec2 c = g.rect.GetCenter();+ const ImGuiViewport* vp = ImGui::GetMainViewport();+ ImVec2 a(c.x - s * 0.5f, c.y - s * 0.5f);+ a.x = std::clamp(a.x, vp->Pos.x + 2.0f, vp->Pos.x + vp->Size.x - s - 2.0f);+ a.y = std::clamp(a.y, vp->Pos.y + 2.0f, vp->Pos.y + vp->Size.y - s - 2.0f);+ const ImVec2 b(a.x + s, a.y + s);+ // In the window's own draw list, unclipped: over the neighbouring tiles but under tooltips.+ ImDrawList* dl = ImGui::GetWindowDrawList();+ dl->PushClipRect(vp->Pos, ImVec2(vp->Pos.x + vp->Size.x, vp->Pos.y + vp->Size.y), false);+ struct PopClip {+ ImDrawList* dl;+ ~PopClip() { dl->PopClipRect(); }+ } pop{dl};+ dl->AddRectFilled(ImVec2(a.x + 3, a.y + 5), ImVec2(b.x + 3, b.y + 5), IM_COL32(0, 0, 0, 90), 8.0f);+ dl->AddRectFilled(a, b, IM_COL32(48, 48, 53, 255), 6.0f);+ dl->AddImageRounded(g.tex, ImVec2(a.x + 3, a.y + 3), ImVec2(b.x - 3, b.y - 3), ImVec2(0, 0), ImVec2(1, 1),+ IM_COL32_WHITE, 5.0f);+ dl->AddRect(a, b, IM_COL32(240, 136, 46, 160), 6.0f, 0, 1.5f);+ }++ // ---------------------------------------------------------------------------+ // Brushes+ // ---------------------------------------------------------------------------++ std::string BrushItem::id() const {+ switch (kind) {+ case Kind::Type:+ return std::string("type:") + brushName(BrushType(index));+ case Kind::Paint:+ return "paint";+ case Kind::Recipe:+ return "recipe:" + name;+ case Kind::File:+ return "file:" + path;+ }+ return {};+ }++ std::string brushActionId(const BrushItem& item) {+ switch (item.kind) {+ case BrushItem::Kind::Type:+ return "brush." + lower(brushName(BrushType(item.index)));+ case BrushItem::Kind::Paint:+ return "brush.paint";+ case BrushItem::Kind::Recipe:+ return "brush.recipe." + item.name;+ case BrushItem::Kind::File:+ return "brush.file." + item.path;+ }+ return {};+ }++ const char* brushTypeDescription(int type) {+ if (type == kPaintBrush) return "Polypaint: paints the current colour onto the surface without sculpting (P).";+ switch (BrushType(type)) {+ case BrushType::Standard:+ return "Pushes the surface out along its normal, building soft, rounded form. Alt carves.";+ case BrushType::Clay:+ return "Builds up flat-bottomed layers of clay that fill dents first, for blocking in form.";+ case BrushType::Smooth:+ return "Relaxes the surface and evens out bumps. Hold Shift with any brush to smooth.";+ case BrushType::Move:+ return "Grabs the area under the brush and drags it with the cursor, for big shape changes.";+ case BrushType::Inflate:+ return "Swells the surface outwards in every direction, like blowing up a balloon.";+ case BrushType::Crease:+ return "Cuts a sharp groove (or ridge with Alt), pinching the sides together.";+ case BrushType::Flatten:+ return "Presses the surface onto a plane, levelling hills and valleys.";+ case BrushType::Pinch:+ return "Pulls the surface toward the stroke, sharpening edges and creases.";+ case BrushType::DamStandard:+ return "A sharp V-shaped crease with the sides pinched in, for wrinkles and folds.";+ case BrushType::ClayBuildup:+ return "Square, flat-topped clay strokes that stack up quickly, for bold blocking.";+ case BrushType::SnakeHook:+ return "Pulls the surface out along the stroke into horns, tentacles and spikes.";+ case BrushType::Trim:+ return "Trim Dynamic: cuts away everything above a plane, for hard planar surfaces.";+ case BrushType::Layer:+ return "Raises the surface to one fixed height per stroke; overlapping passes never stack.";+ case BrushType::Nudge:+ return "Slides the surface sideways along the stroke without changing its height.";+ default:+ return "";+ }+ }++ std::vector<BrushItem> PickerUi::brushItems(App& app, bool libraryFiles) {+ std::vector<BrushItem> items;+ for (int i = 0; i < int(BrushType::Count); ++i) {+ BrushItem b;+ b.kind = BrushItem::Kind::Type;+ b.index = i;+ b.name = brushName(BrushType(i));+ b.description = brushTypeDescription(i);+ items.push_back(std::move(b));+ }+ BrushItem paint;+ paint.kind = BrushItem::Kind::Paint;+ paint.name = "Paint";+ paint.description = brushTypeDescription(kPaintBrush);+ items.push_back(std::move(paint));+ for (int i = 0; i < int(app.doc_.brushes.size()); ++i) {+ const BrushRecipe& r = app.doc_.brushes[size_t(i)];+ BrushItem b;+ b.kind = BrushItem::Kind::Recipe;+ b.index = i;+ b.name = r.name;+ b.path = r.origin.path;+ b.description = r.description;+ switch (r.origin.source) {+ case BrushSource::Studio:+ b.tag = "studio";+ break;+ case BrushSource::Gallery:+ b.tag = "gallery";+ break;+ case BrushSource::Project:+ b.tag = "project";+ break;+ case BrushSource::Session:+ b.tag = "unsaved";+ break;+ default:+ break;+ }+ items.push_back(std::move(b));+ }+ if (libraryFiles && !app.library_.user.empty()) {+ // .sfbrush files in the LightBox library that aren't loaded yet.+ const std::string dir = app.library_.user + "/Brushes";+ if (const auto* files = app.libraryScanner_.get(dir, "brush", [](const std::string& p) {+ return isBrushFile(p) ? AssetKind::BrushFile : AssetKind::Folder;+ }))+ for (const AssetEntry& e : *files) {+ if (e.kind != AssetKind::BrushFile) continue;+ const bool loaded =+ std::any_of(app.doc_.brushes.begin(), app.doc_.brushes.end(), [&](const BrushRecipe& r) {+ return r.origin.path == e.path || typedName(r.name) == typedName(e.name);+ });+ if (loaded) continue;+ BrushItem b;+ b.kind = BrushItem::Kind::File;+ b.name = e.name;+ b.path = e.path;+ b.description = "Brush file in your library: " + e.path;+ items.push_back(std::move(b));+ }+ }+ return items;+ }++ bool PickerUi::isActive(const App& app, const BrushItem& item) {+ switch (item.kind) {+ case BrushItem::Kind::Type:+ return !app.paintMode_ && app.doc_.activeBrush < 0 && int(app.brush_) == item.index;+ case BrushItem::Kind::Paint:+ return app.paintMode_;+ case BrushItem::Kind::Recipe:+ return !app.paintMode_ && app.doc_.activeBrush == item.index;+ case BrushItem::Kind::File:+ return false;+ }+ return false;+ }++ void PickerUi::select(App& app, const BrushItem& item) {+ switch (item.kind) {+ case BrushItem::Kind::Type:+ app.brush_ = BrushType(item.index);+ app.doc_.activeBrush = -1;+ app.paintMode_ = false;+ app.status_ = std::string("Brush: ") + item.name;+ break;+ case BrushItem::Kind::Paint:+ app.paintMode_ = true;+ app.status_ = "Brush: Paint";+ break;+ case BrushItem::Kind::Recipe:+ if (item.index < 0 || item.index >= int(app.doc_.brushes.size())) return;+ app.doc_.activeBrush = item.index;+ app.paintMode_ = false;+ app.status_ = "Brush: " + item.name;+ break;+ case BrushItem::Kind::File:+ app.runCommand("brush_load", {{"path", item.path}});+ if (app.lastCommandOk_) app.paintMode_ = false;+ break;+ }+ }++ ImTextureID PickerUi::thumbnail(App& app, const BrushItem& item) {+ switch (item.kind) {+ case BrushItem::Kind::Type:+ return app.thumbs_.brush(item.index);+ case BrushItem::Kind::Paint:+ return app.thumbs_.brush(kPaintBrush);+ case BrushItem::Kind::Recipe:+ return item.index >= 0 && item.index < int(app.doc_.brushes.size())+ ? app.thumbs_.recipe(app.doc_.brushes[size_t(item.index)])+ : ImTextureID(0);+ case BrushItem::Kind::File:+ return ImTextureID(0);+ }+ return ImTextureID(0);+ }++ void drawBrushGrid(App& app, GridMode mode) {+ State& s = st();+ const bool popup = mode == GridMode::Popup;+ const float tile = 64.0f * app.uiScale_;+ const std::vector<BrushItem> items = PickerUi::brushItems(app, true);++ static char paletteFilter[64] = "";+ if (!popup) {+ ImGui::SetNextItemWidth(-1);+ ImGui::InputTextWithHint("##brushfilter", ICON_LC_SEARCH " Filter brushes", paletteFilter,+ sizeof paletteFilter);+ }+ const std::string typed = popup ? s.typed : typedName(paletteFilter);+ std::vector<std::string> names;+ for (const auto& it : items)+ names.push_back(it.name);+ bool substring = false;+ const std::vector<size_t> shown = filterByTyped(names, typed, &substring);+ const auto badges = popup ? letterBadges(names, shown, typed) : std::vector<std::pair<char, size_t>>{};++ // Letter keys (pop-up only; the palette has a filter field instead).+ if (popup && ImGui::GetFrameCount() >= s.keysFrom) {+ for (int k = 0; k < 26; ++k) {+ if (!ImGui::IsKeyPressed(ImGuiKey(ImGuiKey_A + k), false)) continue;+ const char c = char('a' + k);+ if (auto b = std::find_if(badges.begin(), badges.end(), [c](const auto& x) { return x.first == c; });+ b != badges.end()) {+ const BrushItem pick = items[b->second];+ closePicker();+ PickerUi::select(app, pick);+ return;+ }+ s.typed += c;+ }+ if (ImGui::IsKeyPressed(ImGuiKey_Backspace) && !s.typed.empty()) s.typed.pop_back();+ if ((ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_KeypadEnter)) && !shown.empty() &&+ !typed.empty()) {+ const BrushItem pick = items[shown.front()];+ closePicker();+ PickerUi::select(app, pick);+ return;+ }+ }++ if (popup) {+ // What was typed, or how to type.+ if (typed.empty()) {+ ImGui::TextDisabled("Type a letter to narrow the brushes, then press its orange key");+ } else {+ std::string shownTyped = typed;+ for (auto& c : shownTyped)+ c = char(std::toupper(static_cast<unsigned char>(c)));+ ImGui::TextColored(ImVec4(0.94f, 0.53f, 0.18f, 1.0f), "%s", shownTyped.c_str());+ ImGui::SameLine();+ ImGui::TextDisabled(substring ? "(contains) Backspace: undo a letter Enter: first match"+ : "Backspace: undo a letter Enter: first match");+ }+ }++ // Letter index: A-Z chips with how many brushes start with each letter.+ {+ std::array<int, 26> counts{};+ for (const auto& it : items) {+ const std::string n = typedName(it.name);+ if (!n.empty() && n[0] >= 'a' && n[0] <= 'z') ++counts[size_t(n[0] - 'a')];+ }+ ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(4, 1));+ ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(3, 3));+ const float avail = ImGui::GetContentRegionAvail().x;+ float x = 0.0f;+ for (int k = 0; k < 26; ++k) {+ if (!counts[size_t(k)]) continue;+ char text[24];+ std::snprintf(text, sizeof text, "%c %d##chip", char('A' + k), counts[size_t(k)]);+ const float w = ImGui::CalcTextSize(text, std::strstr(text, "##")).x + 8.0f;+ if (x > 0.0f && x + w <= avail)+ ImGui::SameLine();+ else+ x = 0.0f;+ x += w + 3.0f;+ const bool on = !typed.empty() && typed[0] == char('a' + k);+ if (on) ImGui::PushStyleColor(ImGuiCol_Button, ImGui::ColorConvertU32ToFloat4(kAccent));+ if (ImGui::SmallButton(text)) {+ if (popup)+ s.typed = std::string(1, char('a' + k));+ else+ std::snprintf(paletteFilter, sizeof paletteFilter, "%c", char('a' + k));+ }+ if (on) ImGui::PopStyleColor();+ ui::HelpText("Letter index", nullptr,+ "Brushes whose names start with this letter. Click to show only them.", "Brush");+ }+ ImGui::PopStyleVar(2);+ }++ const int columns = columnsFor(tile, mode);+ auto drawItem = [&](size_t i, int& column, const char* section) {+ const BrushItem& b = items[i];+ tileGrid(column, columns);+ char badge[2] = {0, 0};+ for (const auto& [c, idx] : badges)+ if (idx == i) badge[0] = char(std::toupper(static_cast<unsigned char>(c)));+ const std::string id = b.name + "##" + section + std::to_string(i);+ const ImTextureID tex = PickerUi::thumbnail(app, b);+ const char* glyph = b.kind == BrushItem::Kind::Paint ? ICON_LC_PAINTBRUSH : ICON_LC_BRUSH;+ const bool picked = AssetTile(id.c_str(), tex, glyph, b.name, tile, PickerUi::isActive(app, b),+ badge[0] ? badge : nullptr, b.kind == BrushItem::Kind::File);+ std::string footer = b.kind == BrushItem::Kind::Recipe- ? (b.tag.empty() ? "Custom brush" : "Custom brush (" + b.tag + ")")++ ? brushOriginText(app.doc_.brushes[size_t(b.index)])+ : b.kind == BrushItem::Kind::File ? "Library file - pick to load it"+ : "Built-in brush";+ quickInfo(tex, glyph, b.name, b.description, footer);+ ui::HelpText(b.name.c_str(), nullptr, b.description.c_str(), "Brush");+ if (ImGui::BeginPopupContextItem()) {+ ImGui::TextDisabled("%s", b.name.c_str());+ ImGui::Separator();+ const std::string action = brushActionId(b);+ auto& shelf = app.layout_.bottomShelf;+ const bool onShelf = std::find(shelf.begin(), shelf.end(), action) != shelf.end();+ if (ImGui::MenuItem("Add to bottom shelf", nullptr, false, !onShelf && b.kind != BrushItem::Kind::File)) {- shelf.push_back(action);++ shelf.insert(std::find(shelf.begin(), shelf.end(), "widget.add_brush"), action); // before [+]+ app.status_ = "Added " + b.name + " to the bottom shelf";+ }+ if (b.kind == BrushItem::Kind::Recipe) {++ // The same menu as the Brush palette's custom-brush list (PanelBrushLibrary.cpp).++ if (ImGui::MenuItem("Copy brush code")) app.copyBrushCode(b.index);++ if (ImGui::IsItemHovered()) ImGui::SetTooltip("One line of text to share in chat, email or a forum");++ if (ImGui::MenuItem("Rename...##brush")) {++ app.brushPopup_ = App::BrushPopup::Rename;++ app.brushPopupName_ = app.doc_.brushes[size_t(b.index)].name;++ std::snprintf(app.brushRenameBuf_, sizeof app.brushRenameBuf_, "%s", app.brushPopupName_.c_str());++ }+ if (ImGui::MenuItem("Save as .sfbrush...")) {+ app.doc_.activeBrush = b.index;+ app.paintMode_ = false;+ app.saveFileDialog(App::FileAction::SaveBrush);+ }+ const BrushRecipe& r = app.doc_.brushes[size_t(b.index)];- if (ImGui::MenuItem("Delete...", nullptr, false, isUserLibraryBrush(r))) {++ if (ImGui::MenuItem("Delete...##brush", nullptr, false, isUserLibraryBrush(r))) {+ app.brushPopup_ = App::BrushPopup::Delete;+ app.brushPopupName_ = r.name;+ }+ if (ImGui::MenuItem("Reveal in folder", nullptr, false, !r.origin.path.empty()))+ app.revealBrushFile(b.index);+ }+ ImGui::EndPopup();+ }+ if (picked) {+ if (popup && s.addToShelf) {+ auto& shelf = app.layout_.bottomShelf;+ const std::string action = brushActionId(b);- if (std::find(shelf.begin(), shelf.end(), action) == shelf.end()) shelf.push_back(action);++ if (std::find(shelf.begin(), shelf.end(), action) == shelf.end())++ shelf.insert(std::find(shelf.begin(), shelf.end(), "widget.add_brush"), action); // before [+]+ app.status_ = "Added " + b.name + " to the bottom shelf";+ } else {+ PickerUi::select(app, b);+ }+ if (popup) closePicker();+ }+ };++ // Recent brushes first (the pop-up, before typing).+ if (popup && typed.empty() && !s.recent.empty()) {+ sectionHeader("Recent");+ int column = 0;+ for (const std::string& rid : s.recent)+ for (size_t i = 0; i < items.size(); ++i)+ if (items[i].id() == rid) {+ drawItem(i, column, "recent");+ break;+ }+ }+ struct Section {+ const char* title;+ bool (*match)(const BrushItem&);+ };+ const Section sections[] = {+ {"Built-in",+ [](const BrushItem& b) { return b.kind == BrushItem::Kind::Type || b.kind == BrushItem::Kind::Paint; }},+ {"Custom", [](const BrushItem& b) { return b.kind == BrushItem::Kind::Recipe; }},+ {"Library", [](const BrushItem& b) { return b.kind == BrushItem::Kind::File; }},+ };+ if (popup) {+ // The grid scrolls inside the pop-up when there are many custom brushes.+ const float rowH = tile + ImGui::GetFontSize() + 4.0f + ImGui::GetStyle().ItemSpacing.y;+ ImGui::SetNextWindowSizeConstraints(+ ImVec2(0, 0), ImVec2(FLT_MAX, std::min(rowH * 6.5f, ImGui::GetMainViewport()->Size.y * 0.6f)));+ ImGui::BeginChild("##brushgrid", ImVec2(columns * (tile + 6.0f), 0), ImGuiChildFlags_AutoResizeY,+ ImGuiWindowFlags_NoBackground);+ }+ for (const Section& sec : sections) {+ std::vector<size_t> in;+ for (size_t i : shown)+ if (sec.match(items[i])) in.push_back(i);+ if (in.empty()) continue;+ sectionHeader(sec.title);+ int column = 0;+ for (size_t i : in)+ drawItem(i, column, sec.title);+ }+ if (shown.empty()) ImGui::TextDisabled("No brush matches \"%s\"", typed.c_str());+ if (popup) ImGui::EndChild();+ AssetTileHoverGlow();+ }++ // ---------------------------------------------------------------------------+ // Stroke, alpha and material grids+ // ---------------------------------------------------------------------------++ void drawStrokeGrid(App& app, GridMode mode) {+ const float tile = 64.0f * app.uiScale_;+ static const char* const glyphs[] = {ICON_LC_ELLIPSIS, ICON_LC_SQUARE_DASHED_MOUSE_POINTER, ICON_LC_SPRAY_CAN,+ ICON_LC_SPLINE_POINTER};+ static const char* const help[] = {+ "Even dabs along the path: the classic brush stroke.",+ "Click and drag one stamp: the drag length sets its size and its direction the rotation (great with alphas).",+ "Scattered dabs of random size and strength, for organic texture.",+ "The brush trails the cursor on a string, for smooth, steady lines.",+ };+ int column = 0;+ const int columns = mode == GridMode::Popup ? 4 : columnsFor(tile, mode);+ for (int i = 0; i < int(StrokeType::Count); ++i) {+ tileGrid(column, columns);+ const std::string id = std::string(strokeTypeName(StrokeType(i))) + "##stroke";+ if (AssetTile(id.c_str(), ImTextureID(0), glyphs[i], strokeTypeName(StrokeType(i)), tile,+ app.strokeType_ == StrokeType(i))) {+ app.strokeType_ = StrokeType(i);+ app.status_ = std::string("Stroke: ") + strokeTypeName(StrokeType(i));+ }+ quickInfo(ImTextureID(0), glyphs[i], strokeTypeName(StrokeType(i)), help[i]);+ ui::HelpText(strokeTypeName(StrokeType(i)), nullptr, help[i], "Stroke");+ }+ if (app.strokeType_ == StrokeType::Spray) {+ ImGui::SetNextItemWidth(-1);+ ImGui::SliderFloat("##scatter", &app.sprayScatter_, 0.0f, 2.0f, "Scatter %.2f");+ ui::HelpText("Scatter", nullptr, "How far spray dabs land from the cursor, as a fraction of the brush size.",+ "Stroke");+ } else if (app.strokeType_ == StrokeType::LazyMouse) {+ ImGui::SetNextItemWidth(-1);+ ImGui::SliderFloat("##lazy", &app.lazyMouse_.radius, 1.0f, 300.0f, "Lazy radius %.0f px");+ ui::HelpText("Lazy radius", nullptr, "Length of the string the brush trails on: longer = steadier lines.",+ "Stroke");+ }+ }++ void drawAlphaGrid(App& app, GridMode mode) {+ const float tile = 64.0f * app.uiScale_;+ const int columns = columnsFor(tile, mode);+ const BrushAlpha& current = app.doc_.brushAlpha;+ static const char* const names[] = {"Round", "Square", "Noise"};+ static const char* const help[] = {"The plain round falloff (no alpha).", "A square stamp with soft edges.",+ "A noisy stamp for rough, organic texture."};+ sectionHeader("Built-in");+ int column = 0;+ for (int i = 0; i < 3; ++i) {+ tileGrid(column, columns);+ const bool on = lower(current.name) == lower(names[i]) || (i == 0 && current.empty());+ const ImTextureID tex = app.thumbs_.alpha(builtinAlpha(i));+ if (AssetTile((std::string(names[i]) + "##alpha").c_str(), tex, ICON_LC_CIRCLE_DASHED, names[i], tile, on))+ app.runCommand("brush_set_alpha", {{"name", lower(names[i])}});+ quickInfo(tex, ICON_LC_CIRCLE_DASHED, names[i], help[i]);+ ui::HelpText(names[i], nullptr, help[i], "Alpha");+ }+ // The loaded image alpha, then images in the library's Alphas folder.+ const bool custom = !current.empty() && lower(current.name) != "square" && lower(current.name) != "noise";+ std::vector<AssetEntry> files;+ if (!app.library_.user.empty()) {+ const std::string dir = app.library_.user + "/Alphas";+ if (const auto* list = app.libraryScanner_.get(dir, "alpha", [](const std::string& p) {+ return isImageFile(p) ? AssetKind::AlphaFile : AssetKind::Folder;+ }))+ for (const auto& e : *list)+ if (e.kind == AssetKind::AlphaFile) files.push_back(e);+ }+ if (custom || !files.empty()) {+ sectionHeader("Images");+ column = 0;+ if (custom) {+ tileGrid(column, columns);+ const ImTextureID tex = app.thumbs_.alpha(current);+ AssetTile((current.name + "##alphacur").c_str(), tex, ICON_LC_CIRCLE_DASHED, current.name, tile, true);+ quickInfo(tex, ICON_LC_CIRCLE_DASHED, current.name, "The loaded image alpha (white = full effect).");+ }+ for (const auto& e : files) {+ if (custom && lower(e.name) == lower(current.name)) continue;+ tileGrid(column, columns);+ const ImTextureID tex = app.thumbs_.file(e.path);+ if (AssetTile((e.name + "##alphafile").c_str(), tex, ICON_LC_IMAGE, e.name, tile, false))+ app.runCommand("brush_set_alpha", {{"path", e.path}, {"invert", app.alphaInvert_}});+ quickInfo(tex, ICON_LC_IMAGE, e.name, "Image in your library's Alphas folder.", e.path);+ }+ }+ ImGui::Dummy(ImVec2(0, 2));+ if (ImGui::Button(ICON_LC_FOLDER_OPEN " Load image...", ImVec2(mode == GridMode::Popup ? 0.0f : -1.0f, 0)))+ SDL_ShowOpenFileDialog(App::onAlphaChosen, &app, app.window_, kAlphaFilters, 2, nullptr, false);+ ui::HelpText("Load image", nullptr, "Use any grayscale image as the alpha: white = full effect, black = none.",+ "Alpha");+ if (mode == GridMode::Popup) ImGui::SameLine();+ ImGui::Checkbox("Invert loaded image", &app.alphaInvert_);+ ui::HelpText("Invert loaded image", nullptr, "Load image alphas as their negative (black = full effect).", "Alpha");+ AssetTileHoverGlow();+ }++ void drawMaterialGrid(App& app, GridMode mode) {+ State& s = st();+ const bool popup = mode == GridMode::Popup;+ const float tile = 64.0f * app.uiScale_;+ const int columns = columnsFor(tile, mode);+ int column = 0;+ int hovered = -2;+ const int active = s.previewing ? s.savedMatcap : app.renderSettings_.matcap;+ for (int i = -1; i < matcapCount(); ++i) {+ tileGrid(column, columns);+ const char* name = i < 0 ? "Studio" : matcapName(i);+ const ImTextureID tex = app.thumbs_.material(i);+ if (AssetTile((std::string(name) + "##mat").c_str(), tex, ICON_LC_SUN, name, tile, active == i)) {+ s.previewing = false;+ app.renderSettings_.matcap = s.savedMatcap = i; // runCommand below echoes it for scripts+ app.runCommand("set_material", {{"name", std::string(i < 0 ? "studio" : name)}});+ if (popup) closePicker();+ }+ if (ImGui::IsItemHovered()) hovered = i;+ ui::HelpText(name, nullptr,+ i < 0 ? "Clay lighting with cavity shading (the default)."+ : "MatCap material: the whole lit look in one image.",+ "Material");+ }+ // ZBrush's "Preview Material On Mesh": hovering a material shows it on the model until the pointer leaves.+ if (popup && st().open) {+ if (hovered >= -1) {+ if (!s.previewing) {+ s.previewing = true;+ s.savedMatcap = app.renderSettings_.matcap;+ }+ app.renderSettings_.matcap = hovered;+ } else if (s.previewing) {+ app.renderSettings_.matcap = s.savedMatcap;+ s.previewing = false;+ }+ }+ AssetTileHoverGlow();+ }++ // ---------------------------------------------------------------------------+ // The pop-ups+ // ---------------------------------------------------------------------------++ void openPicker(Picker picker, ImVec2 anchor) {+ State& s = st();+ // A click on the tile that opened it closes it (the click outside closed it this very frame).+ if ((s.open && s.picker == picker && s.openedFrame != ImGui::GetFrameCount()) ||+ (!s.open && s.picker == picker && s.closedFrame == ImGui::GetFrameCount())) {+ closePicker();+ return;+ }+ s.open = true;+ s.picker = picker;+ s.underMouse = anchor.x < 0.0f;+ s.anchor = s.underMouse ? ImGui::GetIO().MousePos : anchor;+ s.openedFrame = ImGui::GetFrameCount();+ // Opened by a key between frames: that key is still "pressed" in the next frame, so skip it.+ s.keysFrom = ImGui::GetFrameCount() + 2;+ s.typed.clear();+ s.addToShelf = false;+ }++ void openBrushPickerForShelf(ImVec2 anchor) {+ openPicker(Picker::Brush, anchor);+ st().addToShelf = st().open;+ }++ bool pickerOpen() { return st().open || st().slider >= 0; }++ void PickerUi::sizePopup(App&, bool strength) {+ State& s = st();+ s.slider = strength ? 1 : 0;+ s.sliderAt = ImGui::GetIO().MousePos;+ s.sliderFrame = ImGui::GetFrameCount();+ s.sliderTyped.clear();+ s.sliderWasActive = false;+ }++ void drawPickers(App& app) {+ State& s = st();+ // Remember what was picked recently, from anywhere (picker, shelf, keys, scripts).+ {+ BrushItem active;+ if (app.paintMode_)+ active.kind = BrushItem::Kind::Paint;+ else if (app.doc_.activeBrush >= 0 && app.doc_.activeBrush < int(app.doc_.brushes.size())) {+ active.kind = BrushItem::Kind::Recipe;+ active.name = app.doc_.brushes[size_t(app.doc_.activeBrush)].name;+ } else {+ active.kind = BrushItem::Kind::Type;+ active.index = int(app.brush_);+ }+ const std::string id = active.id();+ if (id != s.lastActive) {+ if (!s.lastActive.empty()) {+ s.recent.erase(std::remove(s.recent.begin(), s.recent.end(), id), s.recent.end());+ s.recent.insert(s.recent.begin(), id);+ if (s.recent.size() > 8) s.recent.resize(8);+ }+ s.lastActive = id;+ }+ }++ if (s.open) {+ // Pickers own the keyboard while open (letters choose brushes; Esc closes).+ ImGui::SetNextFrameWantCaptureKeyboard(true);+ if (ImGui::IsKeyPressed(ImGuiKey_Escape) && s.openedFrame != ImGui::GetFrameCount()) closePicker();+ }+ if (s.open) {+ const float scale = app.uiScale_;+ const float gridW = 6 * (64.0f * scale + 6.0f) + 20.0f + ImGui::GetStyle().ScrollbarSize;+ switch (s.picker) {+ case Picker::Brush:+ if (beginPickerWindow("Brushes##picker", gridW)) {+ pickerTitle(ICON_LC_BRUSH, s.addToShelf ? "Add a brush to the shelf" : "Brushes", "B");+ drawBrushGrid(app, GridMode::Popup);+ }+ ImGui::End();+ break;+ case Picker::Stroke:+ if (beginPickerWindow("Strokes##picker", 4 * (64.0f * scale + 6.0f) + 20.0f)) {+ pickerTitle(ICON_LC_SPLINE, "Stroke", nullptr);+ ImGui::Spacing();+ drawStrokeGrid(app, GridMode::Popup);+ }+ ImGui::End();+ break;+ case Picker::Alpha:+ if (beginPickerWindow("Alphas##picker", gridW)) {+ pickerTitle(ICON_LC_CIRCLE_DASHED, "Alpha", nullptr);+ drawAlphaGrid(app, GridMode::Popup);+ }+ ImGui::End();+ break;+ case Picker::Material:+ if (beginPickerWindow("Materials##picker", gridW)) {+ pickerTitle(ICON_LC_SUN, "Material", "M");+ ImGui::Spacing();+ drawMaterialGrid(app, GridMode::Popup);+ }+ ImGui::End();+ break;+ }+ }+ if (!s.open && s.previewing) { // closed without picking: put the material back+ app.renderSettings_.matcap = s.savedMatcap;+ s.previewing = false;+ }++ // Draw Size (S) / Strength (I) at the cursor.+ if (s.slider >= 0) {+ ImGui::SetNextFrameWantCaptureKeyboard(true);+ const bool size = s.slider == 0;+ const float w = 200.0f * app.uiScale_;+ ImGui::SetNextWindowPos(ImVec2(s.sliderAt.x - w * 0.5f, s.sliderAt.y + 14.0f), ImGuiCond_Appearing);+ if (s.sliderFrame == ImGui::GetFrameCount()) ImGui::SetNextWindowFocus();+ ImGui::PushStyleVar(ImGuiStyleVar_WindowRounding, 6.0f);+ ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(8, 8));+ ImGui::PushStyleColor(ImGuiCol_WindowBg, kPanelBg);+ bool close = false;+ if (ImGui::Begin(size ? "Draw Size##cursor" : "Strength##cursor", nullptr,+ ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoSavedSettings |+ ImGuiWindowFlags_AlwaysAutoResize)) {+ const bool first = ImGui::GetFrameCount() < s.sliderFrame + 2; // the S / I key itself+ // Typing a number sets it (Enter applies, Esc cancels); dragging the slider works too.+ if (!first) {+ for (int k = 0; k <= 9; ++k)+ if (ImGui::IsKeyPressed(ImGuiKey(ImGuiKey_0 + k), false) ||+ ImGui::IsKeyPressed(ImGuiKey(ImGuiKey_Keypad0 + k), false))+ s.sliderTyped += char('0' + k);+ if (ImGui::IsKeyPressed(ImGuiKey_Period, false) || ImGui::IsKeyPressed(ImGuiKey_KeypadDecimal, false))+ s.sliderTyped += '.';+ if (ImGui::IsKeyPressed(ImGuiKey_Backspace) && !s.sliderTyped.empty()) s.sliderTyped.pop_back();+ if (ImGui::IsKeyPressed(ImGuiKey_Enter) || ImGui::IsKeyPressed(ImGuiKey_KeypadEnter)) {+ if (!s.sliderTyped.empty()) {+ const float v = std::strtof(s.sliderTyped.c_str(), nullptr);+ if (size)+ app.radiusPx_ = std::clamp(v, 2.0f, 800.0f);+ else+ app.strength_ = std::clamp(v > 1.0f ? v / 100.0f : v, 0.01f, 1.0f);+ }+ close = true;+ }+ if (ImGui::IsKeyPressed(ImGuiKey_Escape)) close = true;+ }+ ImGui::SetNextItemWidth(w);+ char fmt[64];+ if (!s.sliderTyped.empty())+ std::snprintf(fmt, sizeof fmt, "%s %s_", size ? "Draw Size" : "Strength", s.sliderTyped.c_str());+ else+ std::snprintf(fmt, sizeof fmt, "%s", size ? "Draw Size %.0f" : "Strength %.2f");+ if (size)+ ImGui::SliderFloat("##cursorvalue", &app.radiusPx_, 2.0f, 800.0f, fmt, ImGuiSliderFlags_Logarithmic);+ else+ ImGui::SliderFloat("##cursorvalue", &app.strength_, 0.01f, 1.0f, fmt);+ ImGui::LogText(size ? "Draw Size %.0f" : "Strength %.2f", size ? app.radiusPx_ : app.strength_);+ ui::HelpText(+ size ? "Draw Size" : "Strength", size ? "S" : "I",+ size ? "Brush radius in screen pixels. Drag, or type a number and press Enter. [ and ] also change it."+ : "How strongly the brush works (0.01-1). Drag, or type a number and press Enter.",+ "Draw");+ if (ImGui::IsItemActive())+ s.sliderWasActive = true;+ else if (s.sliderWasActive)+ close = true; // closes on release, as in ZBrush+ const bool clicked =+ ImGui::IsMouseClicked(ImGuiMouseButton_Left) || ImGui::IsMouseClicked(ImGuiMouseButton_Right);+ if (clicked && !first && !ImGui::IsWindowHovered()) close = true;+ }+ ImGui::End();+ ImGui::PopStyleColor();+ ImGui::PopStyleVar(2);+ if (close) s.slider = -1;+ }+ }++ } // namespace sfdiff --cc src/app/Pickers.hindex 9c8f63d3,3f8a3f32..d9a8d76a--- a/src/app/Pickers.h+++ b/src/app/Pickers.h@@@ -18,5 -27,41 +27,43 @@@ bool pickerOpen(); // any picker or sizvoid drawPickers(App& app);// The brush grid, reused by the Brush palette.void drawBrushGrid(App& app, GridMode mode);+ // The alpha and material grids, reused by the Alpha and Material palettes.+ void drawAlphaGrid(App& app, GridMode mode);+ void drawMaterialGrid(App& app, GridMode mode);+ void drawStrokeGrid(App& app, GridMode mode);++ // One brush of the picker, the LightBox Brush tab and the shelves.+ struct BrushItem {+ enum class Kind { Type, Paint, Recipe, File } kind = Kind::Type;+ int index = -1; // BrushType (Type) or doc.brushes index (Recipe)+ std::string name; // shown under the tile+ std::string path; // .sfbrush (File)+ std::string description;+ std::string tag; // "gallery", "studio", "unsaved"... (Recipe)+ std::string id() const; // stable across frames: "type:Clay", "recipe:Dragon Scales", "file:<path>"+ };++ // Shared by the pickers, the LightBox and (through ui ids) the shelves; they read App internals.+ struct PickerUi {+ static std::vector<BrushItem> brushItems(App& app, bool libraryFiles);+ static bool isActive(const App& app, const BrushItem& item);+ static void select(App& app, const BrushItem& item);+ static ImTextureID thumbnail(App& app, const BrushItem& item);+ static void sizePopup(App& app, bool strength); // opens the S / I slider under the mouse+ };++ // Action id of a brush for the shelves ("brush.clay", "brush.paint", "brush.recipe.<name>").+ std::string brushActionId(const BrushItem& item);+ const char* brushTypeDescription(int brushType); // BrushType, or kPaintBrush++// Where a custom brush comes from, in words ("From the community gallery, ..."; PanelBrushLibrary.cpp).++std::string brushOriginText(const struct BrushRecipe& recipe);++ // A thumbnail tile: the image (or `glyph` on a dark square while it loads), the label under it,+ // accent outline when selected. `id` must be unique in the window. Returns true on click; check+ // ImGui::IsItemHovered() / IsMouseDoubleClicked() after it for more.+ bool AssetTile(const char* id, ImTextureID texture, const char* glyph, const std::string& label, float thumbSize,+ bool selected, const char* badge = nullptr, bool dim = false);+ // Draws the 1.5x hover "glow" of the tile under the mouse (call once the grid is drawn).+ void AssetTileHoverGlow();} // namespace sfdiff --cc src/app/Shell.cppindex 0917bd60,00000000..f921c387mode 100644,000000..100644--- a/src/app/Shell.cpp+++ b/src/app/Shell.cpp@@@ -1,1487 -1,0 +1,1458 @@@+// 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.symmetry_", 0) == 0) return 3;+ if (id.rfind("draw.pressure_", 0) == 0) return 4;+ return 0;+ };+ return group(a) != 0 && group(a) == group(b);+}++} // namespace++int brushTypeOfAction(std::string_view id) {+ for (int i = 0; i < int(BrushType::Count); ++i)+ if (id == brushActionId(BrushType(i))) return i;+ return -1;+}++// ---------------------------------------------------------------------------+// Button looks (ui::ActionButton)+// ---------------------------------------------------------------------------++bool drawShelfTile(App& app, const Action& a, ImVec2 size) {+ const bool on = a.checked && a.checked();+ const std::string id = a.label + "##" + a.id;+ const float s = app.uiScale_;+ const int type = brushTypeOfAction(a.id);+ const int look = type >= 0 || a.id == "draw.paint" ? 3 : 2; // picture tile, or icon over caption+ // Icon over a caption (right shelf) and thumbnail tiles (left and bottom shelves).+ if (size.x <= 0.0f) size.x = 44.0f * s;+ if (size.y <= 0.0f) size.y = 40.0f * s;+ const bool clicked = ImGui::InvisibleButton(id.c_str(), size);+ const bool hovered = ImGui::IsItemHovered(), held = ImGui::IsItemActive();+ const bool disabled = (ImGui::GetItemFlags() & ImGuiItemFlags_Disabled) != 0;+ const ImVec2 p0 = ImGui::GetItemRectMin(), p1 = ImGui::GetItemRectMax();+ ImDrawList* dl = ImGui::GetWindowDrawList();+ const float alpha = disabled ? 0.4f : 1.0f;+ ImFont* caption = look == int(ui::Look::IconLabel) ? app.fontTiny_ : app.fontSmall_;+ const float capH = caption ? caption->FontSize + 2.0f * s : 14.0f * s;+ if (look == int(ui::Look::IconLabel)) {+ const ImVec4 bg = on ? (hovered ? theme::accentHover : theme::accent)+ : held ? theme::buttonPressed : hovered ? theme::buttonHover : theme::frame;+ dl->AddRectFilled(p0, p1, theme::u32(bg, alpha), 4.0f * s);+ const ImU32 fg = theme::u32(on ? theme::textOnAccent : theme::text, alpha);+ centredText(dl, app.fontIcons_, p0, ImVec2(p1.x, p1.y - capH + 2.0f * s), fg, a.icon ? a.icon : "?");+ centredText(dl, caption, ImVec2(p0.x, p1.y - capH), ImVec2(p1.x, p1.y - 1.0f * s), fg,+ elide(caption ? caption : ImGui::GetFont(), a.label, size.x - 2.0f * s).c_str());+ return clicked;+ }+ // Tile: a square picture (brush thumbnail or icon) with the name under it.+ const float pic = std::min(size.x, size.y - capH);+ const ImVec2 q0(p0.x + (size.x - pic) * 0.5f, p0.y), q1(q0.x + pic, q0.y + pic);+ dl->AddRectFilled(p0, p1, theme::u32(hovered ? theme::buttonHover : theme::tile, hovered ? 0.55f : 0.0f), 4.0f * s);+ ImTextureID tex = type >= 0 ? app.thumbnails().brush(type) : ImTextureID(0);++ if (a.id == "draw.paint") { // the Paint brush's own preview (Pickers.cpp)++ BrushItem paint;++ paint.kind = BrushItem::Kind::Paint;++ tex = PickerUi::thumbnail(app, paint);++ }+ 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 > Strength", nullptr, "Draw > Tablet", "", &pressureStrength_,+ "Pen pressure scales the brush strength.");+ flag("draw.pressure_size", "Pressure > Size", nullptr, "Draw > Tablet", "", &pressureSize_,+ "Pen pressure scales the brush size.");+ flag("transform.symmetry_x", "X", nullptr, "Transform", "X", &symmetry_.x, "Mirror strokes across X (left and right).");+ flag("transform.symmetry_y", "Y", nullptr, "Transform", "", &symmetry_.y, "Mirror strokes across Y (top and bottom).");+ flag("transform.symmetry_z", "Z", nullptr, "Transform", "", &symmetry_.z, "Mirror strokes across Z (front and back).");+ flag("ui.brush_lab", "AI Brush", ICON_LC_SPARKLES, "Brush", "", &showBrushLab_,+ "Brush Lab: describe a brush in words and AI builds it; tweak the recipe with sliders.");+ flag("ui.generate3d", "Generate 3D", ICON_LC_WAND_SPARKLES, "Generate", "", &showImageTo3D_,+ "Turn an image or a description into a sculptable model (Hugging Face, fal.ai, Meshy, ComfyUI or offline).");+ flag("ui.brush_gallery", "Community brushes", ICON_LC_GLOBE, "Brush", "", &showBrushGallery_,+ "Browse, search and install brushes other sculptors shared.");++ // View (right shelf, Render palette). Frame keeps F; its short label fits the right shelf.+ add({"view.frame", "Frame", ICON_LC_SCAN, "Fit the whole model in the view.", "Transform", "F", "",+ [this] { camera_.frame(sceneBounds()); }, nullptr, nullptr});+ flag("view.polyf", "PolyF", ICON_LC_GRID_3X3, "Render", "", &renderSettings_.wireframe,+ "Polyframe: show the polygons of the active SubTool (same as W).");+ flag("view.polygroups", "Groups", ICON_LC_SHAPES, "Render", "", &renderSettings_.showPolygroups,+ "Colour each polygroup of the active SubTool.");+ flag("view.mask", "Mask", ICON_LC_DROPLET, "Render", "", &renderSettings_.showMask, "Darken masked areas.");+ flag("view.polypaint", "Paint", ICON_LC_PALETTE, "Render", "", &renderSettings_.showPolypaint,+ "Show polypaint colours (off: plain material).");+ flag("view.mesh", "Show Mesh", ICON_LC_BOX, "Render", "", &renderSettings_.showMesh, "Draw the sculpt.");+ add({"view.splats", "Splats", ICON_LC_SPARKLE, "Show the Gaussian splat capture.", "Render", "", "",+ [this] { renderSettings_.showSplats = !renderSettings_.showSplats; },+ [this] { return renderSettings_.showSplats; }, [this] { return !doc_.splats.empty(); }});+ add({"subtool.solo", "Solo", ICON_LC_SCAN_EYE, "Show only the active SubTool (again: show the others).",+ "Tool > SubTool", "", "subtool_solo", [this] { runCommand("subtool_solo"); },+ [this] {+ int visible = 0;+ for (const auto& s : doc_.subtools) visible += s.visible ? 1 : 0;+ return doc_.subtoolCount() > 1 && visible == 1 && doc_.activeSubtoolInfo().visible;+ },+ [this] { return doc_.subtoolCount() > 1; }});+ add({"nav.move", "Move", ICON_LC_HAND, "Drag on this button to pan the view (or Alt+drag the background).",+ "Transform", "", "", nullptr, nullptr, nullptr});+ add({"nav.zoom", "Zoom", ICON_LC_ZOOM_IN, "Drag up and down on this button to zoom (or use the mouse wheel).",+ "Transform", "", "", nullptr, nullptr, nullptr});+ add({"nav.rotate", "Rotate", ICON_LC_ROTATE_3D, "Drag on this button to orbit the view (or drag the background).",+ "Transform", "", "", nullptr, nullptr, nullptr});++ // Files and editing (File / Edit palettes).+ add({"file.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_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.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({"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});++ // 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);+}++// The one-time "Layout changed - Ctrl+Shift+I to keep it" hint comes from watchLayoutChanges (Config.cpp),+// which compares the layout with the stored one; shell edits only need to change layout_.+void App::noteLayoutChanged() {}++void App::applyPreset(int preset) {+ UiLayout l = standardLayout();+ l.customize = layout_.customize;+ l.consoleOpen = layout_.consoleOpen;+ l.consoleHeight = layout_.consoleHeight;+ l.lightboxOpen = layout_.lightboxOpen;+ l.lightboxRows = layout_.lightboxRows;+ l.lightboxTab = layout_.lightboxTab;+ l.lightboxBottom = layout_.lightboxBottom;+ l.leftHanded = layout_.leftHanded;+ static const char* const kNames[] = {"Standard", "Sculpt", "Wide"};+ if (preset == 1) {+ l.leftTrayOpen = l.rightTrayOpen = false;+ } else if (preset == 2) {+ l.leftTrayOpen = true;+ l.leftTray = {"brush", "stroke", "alpha"};+ l.rightTray = {"tool", "material"};+ }+ layout_ = std::move(l);+ collapsedPalettes_.clear();+ dropdown_.clear();+ status_ = std::string("Layout: ") + kNames[std::clamp(preset, 0, 2)] + " (Ctrl+Shift+I keeps it)";+ lastCommandOk_ = true;+}++void App::removePaletteFromTrays(const std::string& id) {+ for (auto* tray : {&layout_.leftTray, &layout_.rightTray}) tray->erase(std::remove(tray->begin(), tray->end(), id), tray->end());+}++void App::autoCollapseTray(bool right, const std::string& keep) {+ if (!(right ? uiPrefs_.autoCollapseRight : uiPrefs_.autoCollapseLeft)) return;+ for (const std::string& other : right ? layout_.rightTray : layout_.leftTray)+ if (other != keep && std::find(collapsedPalettes_.begin(), collapsedPalettes_.end(), other) == collapsedPalettes_.end())+ collapsedPalettes_.push_back(other);+}++void App::movePaletteToTray(const std::string& id, bool right) {+ removePaletteFromTrays(id);+ (right ? layout_.rightTray : layout_.leftTray).push_back(id);+ (right ? layout_.rightTrayOpen : layout_.leftTrayOpen) = true;+ collapsedPalettes_.erase(std::remove(collapsedPalettes_.begin(), collapsedPalettes_.end(), id), collapsedPalettes_.end());+ autoCollapseTray(right, id);+ if (dropdown_ == id) {+ dropdown_.clear();+ ImGui::ClosePopupsExceptModals();+ }+ flashPalette_ = id;+ flashStart_ = ImGui::GetTime();+ noteLayoutChanged();+}++// ---------------------------------------------------------------------------+// Drawing+// ---------------------------------------------------------------------------++void App::drawCanvasFrame() {+ const CanvasRect c = shell_.canvas;+ ImDrawList* dl = ImGui::GetBackgroundDrawList();+ dl->AddRect(ImVec2(c.x - 1.0f, c.y - 1.0f), ImVec2(c.x + c.w + 1.0f, c.y + c.h + 1.0f), theme::u32(theme::canvasBorder));+}++void App::drawShell() {+ const ImGuiViewport* vp = ImGui::GetMainViewport();+ shell_ = computeShell(layout_, vp->Size.x, vp->Size.y, uiScale_);+ // Splats arriving (file, command or AI agent) bring their palette into the right tray.+ if (doc_.splatsVersion != seenSplatsVersion_) {+ seenSplatsVersion_ = doc_.splatsVersion;+ if (!doc_.splats.empty() && std::count(layout_.leftTray.begin(), layout_.leftTray.end(), "splats") ++ std::count(layout_.rightTray.begin(), layout_.rightTray.end(), "splats") ==+ 0)+ layout_.rightTray.push_back("splats");+ }+ if (status_ != statusShown_) {+ statusShown_ = status_;+ statusSince_ = ImGui::GetTime();+ }+ drawCanvasFrame();+ drawTitleStrip(shell_);+ if (layout_.paletteBarVisible) drawPaletteBar(shell_);+ if (shell_.shelves) {+ drawShelf(kShelfTop, shell_.topShelf);+ drawShelf(kShelfLeft, shell_.leftShelf);+ drawShelf(kShelfRight, shell_.rightShelf);+ drawShelf(kShelfBottom, shell_.bottomShelf);+ if (shell_.leftTray.w > 0.0f) drawTray(false, shell_.leftTray);+ if (shell_.rightTray.w > 0.0f) drawTray(true, shell_.rightTray);+ drawDivider(false, shell_.leftDivider);+ drawDivider(true, shell_.rightDivider);+ }+ drawPaletteDropdown();+ finishShelfDrag();+}++void App::drawTitleStrip(const ShellGeometry& g) {+ const float s = uiScale_;+ if (!beginShellWindow("##TitleStrip", g.title, theme::shellBg, ImVec2(8.0f * s, 0.0f))) {+ ImGui::End();+ return;+ }+ ImDrawList* dl = ImGui::GetWindowDrawList();+ const float h = g.title.h;+ dl->AddLine(ImVec2(g.title.x, g.title.y + h - 1.0f), ImVec2(g.title.x + g.title.w, g.title.y + h - 1.0f),+ theme::u32(theme::border));+ const float textY = std::floor((h - ImGui::GetTextLineHeight()) * 0.5f);+ const float buttonH = h - 6.0f * s;+ ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6.0f * s, (buttonH - ImGui::GetFontSize()) * 0.5f));+ ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4.0f * s, 0.0f));++ // App mark and name.+ ImGui::SetCursorPos(ImVec2(8.0f * s, textY));+ ImGui::TextColored(theme::accent, ICON_LC_BOX);+ ImGui::SameLine(0.0f, 5.0f * s);+ if (fontBold_) ImGui::PushFont(fontBold_);+ ImGui::TextUnformatted("SculptForge");+ if (fontBold_) ImGui::PopFont();++ // Document name; click saves.+ ImGui::SameLine(0.0f, 16.0f * s);+ std::string name = doc_.path.empty() ? std::string("Untitled")+ : std::filesystem::path(std::u8string(doc_.path.begin(), doc_.path.end())).filename().string();+ if (doc_.dirty()) name += " *";+ ImGui::SetCursorPosY((h - buttonH) * 0.5f);+ ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0, 0, 0, 0));+ ImGui::PushStyleColor(ImGuiCol_ButtonHovered, theme::headerHover);+ if (ImGui::Button((name + "##docname").c_str(), ImVec2(0, buttonH))) saveProjectAs(false);+ ImGui::PopStyleColor(2);+ ui::HelpText("Project", "Ctrl+S", "Click to save the project. * means it has unsaved changes.", "Title");++ // Right-aligned controls: QuickSave, layout presets, Menus, search. Measured first.+ const ImGuiStyle& st = ImGui::GetStyle();+ auto buttonW = [&](const char* label) { return ImGui::CalcTextSize(label, nullptr, true).x + st.FramePadding.x * 2.0f; };+ const bool quickSave = actions_.find("file.quicksave") != nullptr;+ const float searchW = 150.0f * s;+ float rightW = searchW + buttonW(ICON_LC_MENU " Menus") + 3.0f * (buttonH + 2.0f * s) + 18.0f * s;+ if (quickSave) rightW += buttonW("QuickSave") + 8.0f * s;+ const float rightX = g.title.w - 8.0f * s - rightW;++ // Info readout and the status message, elided to fit.+ ImGui::SameLine(0.0f, 14.0f * s);+ const float infoX = ImGui::GetCursorPosX();+ ImGui::SetCursorPosY(textY);+ size_t tris = 0, verts = 0;+ for (int i = 0; i < doc_.subtoolCount(); ++i) {+ tris += doc_.subtoolMesh(i).triangleCount();+ verts += doc_.subtoolMesh(i).vertexCount();+ }+ char info[256];+ std::snprintf(info, sizeof info, "Verts %s Tris %s SubTool %s (%d/%d) Layer %s%s%s %.0f fps",+ shortCount(verts).c_str(), shortCount(tris).c_str(), doc_.activeSubtoolInfo().name.c_str(),+ doc_.activeSubtool + 1, doc_.subtoolCount(),+ doc_.activeLayer >= 0 && doc_.activeLayer < int(doc_.mesh.layers.size())+ ? doc_.mesh.layers[size_t(doc_.activeLayer)].name.c_str()+ : "Base",+ doc_.splats.empty() ? "" : " Splats ", doc_.splats.empty() ? "" : shortCount(doc_.splats.size()).c_str(),+ ImGui::GetIO().Framerate);+ const float avail = rightX - infoX - 16.0f * s;+ const float infoW = ImGui::CalcTextSize(info).x;+ if (infoW < avail) {+ ImGui::TextDisabled("%s", info);+ const std::string& msg = layout_.customize ? std::string("Customize: Ctrl+Alt+drag to move or remove items") : status_;+ if (!msg.empty() && avail - infoW > 60.0f * s) {+ ImGui::SameLine(0.0f, 20.0f * s);+ const bool error = !layout_.customize && !lastCommandOk_ && ImGui::GetTime() - statusSince_ < 6.0;+ ImGui::PushStyleColor(ImGuiCol_Text, layout_.customize ? theme::accent : error ? theme::danger : theme::text);+ ImGui::TextUnformatted(elide(ImGui::GetFont(), msg, avail - infoW - 20.0f * s).c_str());+ ImGui::PopStyleColor();+ if (ImGui::IsItemHovered() && msg.size() > 40) ImGui::SetTooltip("%s", msg.c_str());+ }+ } else {+ ImGui::TextDisabled("%s", elide(ImGui::GetFont(), info, std::max(0.0f, avail)).c_str());+ }++ ImGui::SetCursorPos(ImVec2(rightX, (h - buttonH) * 0.5f));+ if (quickSave) {+ ui::ActionButton(*this, "file.quicksave", ImVec2(0, buttonH));+ ImGui::SameLine(0.0f, 8.0f * s);+ }+ for (int i = 1; i <= 3; ++i) {+ ui::ActionButton(*this, ("ui.preset." + std::to_string(i)).c_str(), ImVec2(buttonH + 2.0f * s, buttonH));+ ui::HelpAction(*this, ("ui.preset." + std::to_string(i)).c_str());+ ImGui::SameLine(0.0f, 2.0f * s);+ }+ ImGui::SameLine(0.0f, 8.0f * s);+ ui::ActionButton(*this, "ui.menus", ImVec2(0, buttonH), ui::Look::IconLabel);+ ImGui::SameLine(0.0f, 8.0f * s);+ // Search: a field-looking button that opens the command palette (F3).+ {+ const ImVec2 p = ImGui::GetCursorScreenPos();+ const bool clicked = ImGui::InvisibleButton("##search", ImVec2(searchW, buttonH));+ const bool hovered = ImGui::IsItemHovered();+ dl->AddRectFilled(p, ImVec2(p.x + searchW, p.y + buttonH), theme::u32(hovered ? theme::frameHover : theme::frame), 3.0f * s);+ const float ty = p.y + (buttonH - ImGui::GetFontSize()) * 0.5f;+ dl->AddText(ImVec2(p.x + 7.0f * s, ty), theme::u32(theme::textDim), ICON_LC_SEARCH " Search");+ const ImVec2 kw = ImGui::CalcTextSize("F3");+ dl->AddText(ImVec2(p.x + searchW - kw.x - 7.0f * s, ty), theme::u32(theme::textDim, 0.8f), "F3");+ if (clicked) {+ if (const Action* a = actions_.find("ui.command_palette"); a && a->run) a->run();+ }+ ui::HelpText("Search", "F3", "Find any command, brush or material by name and run it.", "Title");+ }+ ImGui::PopStyleVar(2);+ ImGui::End();+}++void App::drawPaletteBar(const ShellGeometry& g) {+ const float s = uiScale_;+ if (!beginShellWindow("##PaletteBar", g.paletteBar, theme::shellBg, ImVec2(8.0f * s, 0.0f))) {+ ImGui::End();+ return;+ }+ ImDrawList* dl = ImGui::GetWindowDrawList();+ dl->AddLine(ImVec2(g.paletteBar.x, g.paletteBar.y + g.paletteBar.h - 1.0f),+ ImVec2(g.paletteBar.x + g.paletteBar.w, g.paletteBar.y + g.paletteBar.h - 1.0f), theme::u32(theme::border));+ ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0.0f, 0.0f));+ ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(8.0f * s, 0.0f));+ ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 0.0f);+ int count = 0;+ const PaletteDef* list = palettes(count);+ for (int i = 0; i < count; ++i) {+ const PaletteDef& p = list[i];+ const bool inTray = std::count(layout_.leftTray.begin(), layout_.leftTray.end(), p.id) ++ std::count(layout_.rightTray.begin(), layout_.rightTray.end(), p.id) >+ 0;+ const bool open = dropdown_ == p.id;+ ImGui::PushStyleColor(ImGuiCol_Button, open ? theme::header : ImVec4(0, 0, 0, 0));+ ImGui::PushStyleColor(ImGuiCol_ButtonHovered, theme::headerHover);+ ImGui::PushStyleColor(ImGuiCol_ButtonActive, theme::header);+ ImGui::PushStyleColor(ImGuiCol_Text, inTray ? theme::accent : open ? theme::textOnAccent : theme::text);+ if (i) ImGui::SameLine();+ const std::string label = std::string(p.name) + "##palette." + p.id;+ // While a drop-down is open, the click that closes it (ImGui swallows that one) opens another palette+ // when it lands on that palette's name, as in a menu bar; on the open palette's own name it just closes.+ const bool pressed = ImGui::Button(label.c_str(), ImVec2(0, g.paletteBar.h - 1.0f));+ const bool switchTo = !dropdown_.empty() && !open && ImGui::IsMouseClicked(ImGuiMouseButton_Left) &&+ ImGui::IsItemHovered(ImGuiHoveredFlags_AllowWhenBlockedByPopup);+ if (pressed || switchTo) {+ if (inTray) {+ flashPalette_ = p.id;+ flashStart_ = ImGui::GetTime();+ } else if (!open) {+ dropdown_ = p.id;+ dropdownX_ = ImGui::GetItemRectMin().x;+ openDropdown_ = true;+ }+ }+ ImGui::PopStyleColor(4);+ ui::HelpAction(*this, ("ui.palette." + std::string(p.id)).c_str());+ }+ ImGui::PopStyleVar(3);+ ImGui::End();+}++bool App::paletteHeader(const char* id, bool inTray, bool right) {+ const PaletteDef* def = findPalette(id);+ if (!def) return false;+ const float s = uiScale_;+ const float h = 24.0f * s;+ ImDrawList* dl = ImGui::GetWindowDrawList();+ const ImVec2 p = ImGui::GetCursorScreenPos();+ const float w = ImGui::GetContentRegionAvail().x;+ const bool collapsed = inTray && std::count(collapsedPalettes_.begin(), collapsedPalettes_.end(), id) > 0;+ dl->AddRectFilled(p, ImVec2(p.x + w, p.y + h), theme::u32(theme::header), 3.0f * s);++ // Tray icon: in a drop-down it moves the palette into the right tray (Shift: left) or can be dragged to one;+ // in a tray it sends the palette back to the bar.+ ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));+ const bool iconClicked = ImGui::InvisibleButton("##totray", ImVec2(h, h));+ const bool iconHovered = ImGui::IsItemHovered();+ if (!inTray && ImGui::BeginDragDropSource(ImGuiDragDropFlags_SourceNoDisableHover)) {+ ImGui::SetDragDropPayload("SF_PALETTE", id, std::strlen(id) + 1);+ ImGui::Text(ICON_LC_PANEL_RIGHT " %s", def->name);+ ImGui::EndDragDropSource();+ }+ if (inTray) ui::HelpText("Back to the palette bar", nullptr, "Take this palette out of the tray.", def->name);+ else+ ui::HelpText("Move to the tray", nullptr,+ "Keep this palette in the right tray (Shift+click: left tray), or drag the icon onto a tray.", def->name);+ centredText(dl, nullptr, p, ImVec2(p.x + h, p.y + h), theme::u32(iconHovered ? theme::accentHover : theme::accent),+ inTray ? (right ? ICON_LC_PANEL_RIGHT : ICON_LC_PANEL_LEFT) : ICON_LC_PANEL_RIGHT);+ ImGui::SameLine();+ const bool titleClicked = ImGui::InvisibleButton("##title", ImVec2(std::max(1.0f, w - 2.0f * h), h));+ const bool titleHovered = ImGui::IsItemHovered();+ if (fontBold_) ImGui::PushFont(fontBold_);+ dl->AddText(ImVec2(p.x + h + 2.0f * s, p.y + (h - ImGui::GetFontSize()) * 0.5f),+ theme::u32(titleHovered && inTray ? theme::textOnAccent : theme::text), def->name);+ ImGui::LogText("%s", def->name);+ if (fontBold_) ImGui::PopFont();+ ImGui::SameLine();+ const bool endClicked = ImGui::InvisibleButton(inTray ? "##collapse" : "##close", ImVec2(h, h));+ const bool endHovered = ImGui::IsItemHovered();+ centredText(dl, nullptr, ImVec2(p.x + w - h, p.y), ImVec2(p.x + w, p.y + h),+ theme::u32(endHovered ? theme::textOnAccent : theme::textDim),+ inTray ? (collapsed ? ICON_LC_CHEVRON_RIGHT : ICON_LC_CHEVRON_DOWN) : ICON_LC_X);+ ImGui::PopStyleVar();+ ImGui::Dummy(ImVec2(0, 2.0f * s));++ if (iconClicked) {+ if (inTray) {+ removePaletteFromTrays(id);+ noteLayoutChanged();+ return false;+ }+ movePaletteToTray(id, (SDL_GetModState() & SDL_KMOD_SHIFT) == 0);+ return false;+ }+ if (inTray && (titleClicked || endClicked)) {+ if (collapsed) {+ collapsedPalettes_.erase(std::remove(collapsedPalettes_.begin(), collapsedPalettes_.end(), id), collapsedPalettes_.end());+ autoCollapseTray(right, id);+ } else {+ collapsedPalettes_.push_back(id);+ }+ return collapsed;+ }+ if (!inTray && endClicked) {+ dropdown_.clear();+ ImGui::CloseCurrentPopup();+ return false;+ }+ return !collapsed;+}++void App::drawPaletteBody(const std::string& id) {+ const PaletteDef* def = findPalette(id);+ if (!def) return;+ ImGui::PushID(def->id);+ (this->*(def->draw))();+ ImGui::PopID();+}++void App::drawPaletteDropdown() {+ if (openDropdown_) {+ ImGui::OpenPopup("##palettedropdown");+ openDropdown_ = false;+ }+ if (dropdown_.empty()) return;+ const PaletteDef* def = findPalette(dropdown_);+ if (!def) {+ dropdown_.clear();+ return;+ }+ const float s = uiScale_;+ const ImGuiViewport* vp = ImGui::GetMainViewport();+ const float w = 300.0f * s;+ ImGui::SetNextWindowPos(ImVec2(std::clamp(dropdownX_, 4.0f * s, vp->Size.x - w - 4.0f * s),+ shell_.paletteBar.y + shell_.paletteBar.h));+ ImGui::SetNextWindowSizeConstraints(ImVec2(w, 0), ImVec2(w, vp->Size.y - 60.0f * s));+ // Whole-pixel padding: auto-fit truncates sizes, and a fraction of a pixel too little shows a scrollbar.+ ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(std::round(6.0f * s), std::round(6.0f * s)));+ const bool open = ImGui::BeginPopup("##palettedropdown");+ ImGui::PopStyleVar();+ if (!open) {+ dropdown_.clear();+ return;+ }+ Demo::pushScope(def->name);+ if (def->scope) Demo::pushScope(def->scope);+ const std::string id = dropdown_;+ if (paletteHeader(id.c_str(), false, true)) drawPaletteBody(id);+ if (def->scope) Demo::popScope();+ Demo::popScope();+ if (ImGui::IsKeyPressed(ImGuiKey_Escape) && !ImGui::IsAnyItemActive()) ImGui::CloseCurrentPopup();+ ImGui::EndPopup();+}++void App::drawTray(bool right, const CanvasRect& r) {+ const float s = uiScale_;+ std::vector<std::string>& list = right ? layout_.rightTray : layout_.leftTray;+ if (!beginShellWindow(right ? "##RightTray" : "##LeftTray", r, theme::panelBg, ImVec2(6.0f * s, 6.0f * s), 0)) {+ ImGui::End();+ return;+ }+ const std::vector<std::string> ids = list; // headers may move palettes out+ for (const std::string& id : ids) {+ const PaletteDef* def = findPalette(id);+ if (!def) continue;+ ImGui::PushID(id.c_str());+ Demo::pushScope(def->name);+ if (def->scope) Demo::pushScope(def->scope);+ const ImVec2 top = ImGui::GetCursorScreenPos();+ if (flashPalette_ == id) {+ const double t = ImGui::GetTime() - flashStart_;+ if (t < 0.05) ImGui::SetScrollHereY(0.0f);+ if (t < 0.9) {+ const float a = float(0.45 * (1.0 - t / 0.9));+ ImGui::GetWindowDrawList()->AddRectFilled(top, ImVec2(top.x + ImGui::GetContentRegionAvail().x, top.y + 24.0f * s),+ theme::u32(theme::accent, a), 3.0f * s);+ } else {+ flashPalette_.clear();+ }+ }+ if (paletteHeader(id.c_str(), true, right)) {+ drawPaletteBody(id);+ ImGui::Dummy(ImVec2(0, 4.0f * s));+ }+ if (def->scope) Demo::popScope();+ Demo::popScope();+ ImGui::PopID();+ }+ if (list.empty()) {+ const ImVec2 avail = ImGui::GetContentRegionAvail();+ const char* hint = "Click a palette's " ICON_LC_PANEL_RIGHT " icon\nor drag it here";+ const ImVec2 ts = ImGui::CalcTextSize(hint);+ ImGui::SetCursorPos(ImVec2((avail.x - ts.x) * 0.5f + 6.0f * s, std::max(ImGui::GetCursorPosY(), avail.y * 0.4f)));+ ImGui::TextDisabled("%s", hint);+ }+ // The whole tray accepts palettes dragged by their header icon.+ ImGuiWindow* window = ImGui::GetCurrentWindow();+ if (ImGui::BeginDragDropTargetCustom(window->Rect(), ImGui::GetID("##traydrop"))) {+ if (const ImGuiPayload* payload = ImGui::AcceptDragDropPayload("SF_PALETTE"))+ movePaletteToTray(static_cast<const char*>(payload->Data), right);+ ImGui::EndDragDropTarget();+ }+ ImGui::End();+}++void App::drawDivider(bool right, const CanvasRect& r) {+ if (r.w <= 0.0f) return;+ const float s = uiScale_;+ if (!beginShellWindow(right ? "##RightDivider" : "##LeftDivider", r, theme::shellBg, ImVec2(0, 0))) {+ ImGui::End();+ return;+ }+ const bool open = right ? layout_.rightTrayOpen && !shell_.narrow : layout_.leftTrayOpen;+ ImGui::InvisibleButton(right ? "##rightdivider" : "##leftdivider", ImVec2(r.w, r.h));+ const bool hovered = ImGui::IsItemHovered(), active = ImGui::IsItemActive();+ ImGuiIO& io = ImGui::GetIO();+ if ((hovered || active) && open) ImGui::SetMouseCursor(ImGuiMouseCursor_ResizeEW);+ if (active && open && ImGui::IsMouseDragging(ImGuiMouseButton_Left, 3.0f * s) && io.MouseDelta.x != 0.0f) {+ float& width = right ? layout_.rightTrayWidth : layout_.leftTrayWidth;+ const float logicalW = io.DisplaySize.x / s;+ width = std::clamp(trayWidth(width, logicalW) + (right ? -io.MouseDelta.x : io.MouseDelta.x) / s, shell::kTrayMinW,+ shell::kTrayMaxW);+ if (width == 300.0f) width = 300.5f; // a deliberate 300 isn't the "grow on wide screens" default+ noteLayoutChanged();+ }+ if (ImGui::IsItemDeactivated() && io.MouseDragMaxDistanceSqr[0] < 9.0f * s * s) {+ if (right && shell_.narrow) {+ status_ = "The window is too narrow for the tray - palettes open as drop-downs";+ } else {+ (right ? layout_.rightTrayOpen : layout_.leftTrayOpen) = !open;+ noteLayoutChanged();+ }+ }+ ui::HelpText(right ? "Right tray" : "Left tray", nullptr,+ "Click to open or close the tray, drag to resize it. Palettes go in trays from their header icon.",+ "Shell");+ ImDrawList* dl = ImGui::GetWindowDrawList();+ const float cx = std::floor(r.x + r.w * 0.5f), cy = r.y + r.h * 0.5f;+ const ImU32 grip = theme::u32(hovered || active ? theme::accent : theme::textDim, hovered || active ? 1.0f : 0.5f);+ dl->AddRectFilled(ImVec2(cx - 1.0f * s, cy - 16.0f * s), ImVec2(cx + 1.0f * s, cy + 16.0f * s), grip, 1.0f * s);+ ImGui::End();+}++// ---------------------------------------------------------------------------+// Shelves+// ---------------------------------------------------------------------------++void App::drawShelf(int shelf, const CanvasRect& r) {+ const float s = uiScale_;+ const bool vertical = shelf == kShelfLeft || shelf == kShelfRight;+ const ImVec2 pad = shelf == kShelfTop ? ImVec2(6.0f * s, 4.0f * s)+ : shelf == kShelfBottom ? ImVec2(6.0f * s, 3.0f * s)+ : shelf == kShelfLeft ? ImVec2(6.0f * s, 6.0f * s)+ : ImVec2(4.0f * s, 6.0f * s);+ if (!beginShellWindow(kShelfWindows[shelf], r, theme::shellBg, pad)) {+ ImGui::End();+ return;+ }+ std::vector<std::string>& items = shelf == kShelfTop ? layout_.topShelf+ : shelf == kShelfLeft ? layout_.leftShelf+ : shelf == kShelfRight ? layout_.rightShelf+ : layout_.bottomShelf;+ const std::vector<std::string> list = items; // items may be removed from their own context menu+ std::vector<ImRect> rects;+ std::vector<int> indices;+ if (shelf == kShelfBottom) {+ const int tiles = int(std::count_if(list.begin(), list.end(), [](const std::string& id) { return id != "sep" && id != "row"; }));+ const float avail = r.w - 2.0f * pad.x - 48.0f * s; // the [+] tile is narrower+ bottomTileW_ = std::clamp(avail / float(std::max(tiles - 1, 1)) - 4.0f * s, 44.0f * s, 58.0f * s);+ }+ ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4.0f * s, 4.0f * s));+ bool lineStart = true;+ for (int i = 0; i < int(list.size()); ++i) {+ const std::string& item = list[size_t(i)];+ if (item == "row") {+ lineStart = true;+ continue;+ }+ if (item == "view.splats" && doc_.splats.empty()) continue; // only when there's a capture+ if (!vertical && !lineStart) {+ const std::string& prev = list[size_t(i - 1)];+ ImGui::SameLine(0.0f, prev == "sep" || item == "sep" ? 0.0f : segmentPair(prev, item) ? 1.0f * s : 4.0f * s);+ }+ if (!vertical && item == "widget.points") { // right-aligned readout+ const float w = 170.0f * s;+ ImGui::SameLine(std::max(ImGui::GetCursorPosX(), ImGui::GetWindowContentRegionMax().x - w));+ }+ lineStart = false;+ drawShelfItem(shelf, i, item, vertical);+ rects.push_back(ImRect(ImGui::GetItemRectMin(), ImGui::GetItemRectMax()));+ indices.push_back(i);+ }+ ImGui::PopStyleVar();++ ImGuiWindow* window = ImGui::GetCurrentWindow();+ ImDrawList* dl = ImGui::GetWindowDrawList();+ // Bottom shelf: the wheel scrolls it sideways when it doesn't fit.+ if (shelf == kShelfBottom && ImGui::IsWindowHovered() && ImGui::GetIO().MouseWheel != 0.0f)+ ImGui::SetScrollX(ImGui::GetScrollX() - ImGui::GetIO().MouseWheel * 60.0f * s);+ if (layout_.customize)+ dashedRect(dl, ImVec2(r.x + 2.0f, r.y + 2.0f), ImVec2(r.x + r.w - 2.0f, r.y + r.h - 2.0f), theme::u32(theme::accent, 0.6f),+ 4.0f * s);+ // Customize: drop items between the shelf's items (an accent line shows where).+ const ImGuiPayload* payload = ImGui::GetDragDropPayload();+ if (payload && payload->IsDataType(ui::kUiItemPayload) && window->Rect().Contains(ImGui::GetIO().MousePos)) {+ const ImVec2 m = ImGui::GetIO().MousePos;+ int insert = int(list.size());+ ImVec2 a, b;+ for (size_t k = 0; k < rects.size(); ++k) {+ const ImRect& rc = rects[k];+ const bool before = vertical ? m.y < rc.GetCenter().y : (m.y < rc.Max.y + 2.0f * s && m.x < rc.GetCenter().x);+ if (before) {+ insert = indices[k];+ a = vertical ? ImVec2(rc.Min.x, rc.Min.y - 2.0f * s) : ImVec2(rc.Min.x - 2.0f * s, rc.Min.y);+ b = vertical ? ImVec2(rc.Max.x, rc.Min.y - 2.0f * s) : ImVec2(rc.Min.x - 2.0f * s, rc.Max.y);+ break;+ }+ }+ if (insert == int(list.size()) && !rects.empty()) {+ const ImRect& rc = rects.back();+ a = vertical ? ImVec2(rc.Min.x, rc.Max.y + 2.0f * s) : ImVec2(rc.Max.x + 2.0f * s, rc.Min.y);+ b = vertical ? ImVec2(rc.Max.x, rc.Max.y + 2.0f * s) : ImVec2(rc.Max.x + 2.0f * s, rc.Max.y);+ }+ if (ImGui::BeginDragDropTargetCustom(window->Rect(), ImGui::GetID("##shelfdrop"))) {+ ImGui::GetForegroundDrawList()->AddLine(a, b, theme::u32(theme::accent), 2.0f * s);+ if (const ImGuiPayload* p = ImGui::AcceptDragDropPayload(ui::kUiItemPayload, ImGuiDragDropFlags_AcceptNoDrawDefaultRect)) {+ ui::UiItemPayload item;+ std::memcpy(&item, p->Data, std::min(size_t(p->DataSize), sizeof item));+ item.id[sizeof item.id - 1] = 0;+ std::vector<std::string>* from = item.fromShelf == kShelfTop ? &layout_.topShelf+ : item.fromShelf == kShelfLeft ? &layout_.leftShelf+ : item.fromShelf == kShelfRight ? &layout_.rightShelf+ : item.fromShelf == kShelfBottom ? &layout_.bottomShelf+ : nullptr;+ if (from && item.fromIndex >= 0 && item.fromIndex < int(from->size()) && (*from)[size_t(item.fromIndex)] == item.id) {+ from->erase(from->begin() + item.fromIndex);+ if (from == &items && item.fromIndex < insert) --insert;+ }+ items.insert(items.begin() + std::clamp(insert, 0, int(items.size())), std::string(item.id));+ shelfDrag_.accepted = true;+ noteLayoutChanged();+ }+ ImGui::EndDragDropTarget();+ }+ }+ ImGui::End();+}++void App::drawShelfItem(int shelf, int index, const std::string& item, bool vertical) {+ const float s = uiScale_;+ const float winW = ImGui::GetWindowWidth();+ const float padX = ImGui::GetStyle().WindowPadding.x;+ ImGui::PushID(index);+ auto centre = [&](float w) {+ if (vertical) ImGui::SetCursorPosX(std::max(padX, (winW - w) * 0.5f));+ };+ const float rowH = 26.0f * s;+ if (item == "sep") {+ if (vertical) {+ ImGui::Dummy(ImVec2(winW - 2.0f * padX, 4.0f * s));+ const ImVec2 a = ImGui::GetItemRectMin(), b = ImGui::GetItemRectMax();+ ImGui::GetWindowDrawList()->AddLine(ImVec2(a.x + 6.0f * s, (a.y + b.y) * 0.5f), ImVec2(b.x - 6.0f * s, (a.y + b.y) * 0.5f),+ theme::u32(theme::header));+ } else {+ ImGui::Dummy(ImVec2(13.0f * s, rowH));+ const ImVec2 a = ImGui::GetItemRectMin(), b = ImGui::GetItemRectMax();+ const float x = std::floor((a.x + b.x) * 0.5f);+ ImGui::GetWindowDrawList()->AddLine(ImVec2(x, a.y + 4.0f * s), ImVec2(x, b.y - 4.0f * s), theme::u32(theme::header));+ }+ } else if (item == "widget.draw_size" || item == "widget.strength") {+ ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(8.0f * s, (rowH - ImGui::GetFontSize()) * 0.5f));+ ImGui::SetNextItemWidth(180.0f * s);+ if (item == "widget.draw_size") {+ ui::SliderInside("##drawsize", &radiusPx_, 2.0f, 800.0f, "Draw Size %.0f", ImGuiSliderFlags_Logarithmic);+ ui::HelpText("Draw Size", "S", "Brush radius in screen pixels. [ and ] change it by 10%; Ctrl+click to type.", "Draw");+ } else {+ ui::SliderInside("##strength", &strength_, 0.01f, 1.0f, "Strength %.2f");+ ui::HelpText("Strength", "I", "How strongly each dab changes the surface (ZBrush Z Intensity); Ctrl+click to type.",+ "Draw");+ }+ ImGui::PopStyleVar();+ } else if (item == "widget.points") {+ size_t total = 0;+ uint64_t key = doc_.undo.revision() * 0x9E3779B97F4A7C15ull ^ uint64_t(doc_.activeSubtool) ^+ (uint64_t(reinterpret_cast<uintptr_t>(doc_.mesh.hidden.data())) << 1);+ for (int i = 0; i < doc_.subtoolCount(); ++i) {+ total += doc_.subtoolMesh(i).triangleCount();+ key = key * 31 + doc_.subtoolMesh(i).triangleCount() * 2 + (doc_.subtools[size_t(i)].visible ? 1 : 0);+ }+ if (key != activeTrisKey_) { // hidden triangles only change through commands and undo+ activeTrisKey_ = key;+ activeTris_ = 0;+ for (int i = 0; i < doc_.subtoolCount(); ++i) {+ if (!doc_.subtools[size_t(i)].visible) continue;+ const Mesh& m = doc_.subtoolMesh(i);+ const size_t hidden = size_t(std::count_if(m.hidden.begin(), m.hidden.end(), [](uint8_t h) { return h != 0; }));+ activeTris_ += m.triangleCount() - std::min(hidden, m.triangleCount());+ }+ }+ const size_t active = activeTris_;+ ImGui::BeginGroup();+ if (fontSmall_) ImGui::PushFont(fontSmall_);+ const float lineH = ImGui::GetTextLineHeight();+ const ImVec2 p = ImGui::GetCursorScreenPos();+ ImGui::Dummy(ImVec2(170.0f * s, rowH));+ ImDrawList* dl = ImGui::GetWindowDrawList();+ const float y0 = p.y + (rowH - 2.0f * lineH) * 0.5f;+ dl->AddText(ImVec2(p.x, y0), theme::u32(theme::textDim), "ActiveTris");+ dl->AddText(ImVec2(p.x, y0 + lineH), theme::u32(theme::textDim), "TotalTris");+ const std::string a = shortCount(active), t = shortCount(total);+ dl->AddText(ImVec2(p.x + 70.0f * s, y0), theme::u32(theme::text), a.c_str());+ dl->AddText(ImVec2(p.x + 70.0f * s, y0 + lineH), theme::u32(theme::text), t.c_str());+ ImGui::LogText("ActiveTris %s TotalTris %s", a.c_str(), t.c_str());+ if (fontSmall_) ImGui::PopFont();+ ImGui::EndGroup();+ ui::HelpText("ActiveTris / TotalTris", nullptr,+ "Triangles you can see and sculpt (visible SubTools, hidden parts left out) and in the whole scene.",+ "Draw");+ } else if (item.rfind("widget.tile.", 0) == 0) {+ const float w = (shell_.narrow ? 60.0f : 76.0f) * s;+ const ImVec2 size(w, w + (fontSmall_ ? fontSmall_->FontSize : 12.0f) + 4.0f * s);+ centre(w);+ if (item == "widget.tile.brush") drawBrushTile("##tile.brush", size);+ else if (item == "widget.tile.stroke") drawStrokeTile("##tile.stroke", size);+ else if (item == "widget.tile.alpha") drawAlphaTile("##tile.alpha", size);+ else if (item == "widget.tile.material") drawMaterialTile("##tile.material", size);+ else ImGui::Dummy(size);+ } else if (item == "widget.color") {+ const float w = (shell_.narrow ? 60.0f : 76.0f) * s;+ centre(w);+ drawColorWidget(w);+ } else if (item == "widget.nav.move" || item == "widget.nav.zoom" || item == "widget.nav.rotate") {+ centre(44.0f * s);+ const int mode = item == "widget.nav.move" ? 0 : item == "widget.nav.zoom" ? 1 : 2;+ canvasNavButton(mode == 0 ? "nav.move" : mode == 1 ? "nav.zoom" : "nav.rotate",+ mode == 0 ? ICON_LC_HAND : mode == 1 ? ICON_LC_ZOOM_IN : ICON_LC_ROTATE_3D,+ mode == 0 ? "Move" : mode == 1 ? "Zoom" : "Rotate", mode);+ } else if (item == "widget.add_brush") {+ const ImVec2 size(48.0f * s, 54.0f * s);- if (ImGui::InvisibleButton("##addbrush", size)) ImGui::OpenPopup("##addtoshelf");++ if (ImGui::InvisibleButton("##addbrush", size)) // the brush picker in "add to shelf" mode (Pickers.cpp)++ openBrushPickerForShelf(ImVec2(ImGui::GetItemRectMin().x, ImGui::GetItemRectMin().y - 8.0f * s));+ 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);++ } else if (item.rfind("brush.recipe.", 0) == 0 || item.rfind("recipe:", 0) == 0) {++ const std::string name = item.substr(item[0] == 'r' ? 7 : 13); // custom brush, by name+ 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)) {++ } else if (const Action* a = actions_.find(item == "brush.paint" ? std::string("draw.paint") : item)) {+ const ui::Look look = shelf != kShelfTop ? ui::Look::Tile : a->icon ? ui::Look::IconLabel : ui::Look::Label;+ const ImVec2 size = shelf == kShelfTop ? ImVec2(0.0f, rowH)+ : shelf == kShelfRight ? ImVec2(44.0f * s, 40.0f * s)+ : shelf == kShelfBottom ? ImVec2(bottomTileW_, 54.0f * s)+ : ImVec2(winW - 2.0f * padX, 60.0f * s);+ centre(size.x);+ if (shelf == kShelfTop) ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10.0f * s, (rowH - ImGui::GetFontSize()) * 0.5f));+ ui::SetNextItemOrigin(shelf, index); // ActionButton is the Ctrl+Alt drag source, from this shelf slot+ ui::ActionButton(*this, a->id.c_str(), size, look);+ if (shelf == kShelfTop) ImGui::PopStyleVar();+ } 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: widgets (sliders, tiles, readouts) are Ctrl+Alt drag sources too.+ if (item != "sep" && !actions_.find(item)) {+ ui::SetNextItemOrigin(shelf, index);+ ui::UiItemDragSource(*this, item.c_str(), item.c_str());+ }+ ImGui::PopID();+}++void App::finishShelfDrag() {+ const ImGuiPayload* payload = ImGui::GetDragDropPayload();+ if (payload && payload->IsDataType(ui::kUiItemPayload)) {+ ui::UiItemPayload item;+ std::memcpy(&item, payload->Data, std::min(size_t(payload->DataSize), sizeof item));+ shelfDrag_.active = true;+ shelfDrag_.shelf = item.fromShelf;+ shelfDrag_.index = item.fromIndex;+ return;+ }+ if (!shelfDrag_.active) return;+ // The drag ended: dropped outside every shelf, an item that came from a shelf is removed (ZBrush).+ if (!shelfDrag_.accepted && shelfDrag_.shelf >= 0 && shelfDrag_.shelf < kShelfCount) {+ auto& list = shelfDrag_.shelf == kShelfTop ? layout_.topShelf+ : shelfDrag_.shelf == kShelfLeft ? layout_.leftShelf+ : shelfDrag_.shelf == kShelfRight ? layout_.rightShelf+ : layout_.bottomShelf;+ if (shelfDrag_.index >= 0 && shelfDrag_.index < int(list.size())) {+ status_ = "Removed " + list[size_t(shelfDrag_.index)] + " from the shelf";+ list.erase(list.begin() + shelfDrag_.index);+ noteLayoutChanged();+ }+ }+ shelfDrag_ = {};+}+- void App::drawAddToShelfPopup() {- if (!ImGui::BeginPopup("##addtoshelf")) return;- ImGui::TextDisabled("Add to the bottom shelf");- ImGui::Separator();- auto onShelf = [this](const std::string& id) {- return std::find(layout_.bottomShelf.begin(), layout_.bottomShelf.end(), id) != layout_.bottomShelf.end();- };- auto add = [this](const std::string& id) {- auto plus = std::find(layout_.bottomShelf.begin(), layout_.bottomShelf.end(), "widget.add_brush");- layout_.bottomShelf.insert(plus, id);- noteLayoutChanged();- };- bool any = false;- for (int i = 0; i < int(BrushType::Count); ++i) {- const std::string id = brushActionId(BrushType(i));- if (onShelf(id)) continue;- any = true;- if (ImGui::MenuItem(brushName(BrushType(i)))) add(id);- }- if (!onShelf("draw.paint") && ImGui::MenuItem("Paint")) add("draw.paint");- if (!doc_.brushes.empty()) {- ImGui::SeparatorText("Custom");- for (const auto& b : doc_.brushes) {- const std::string id = "recipe:" + b.name;- if (onShelf(id)) continue;- any = true;- if (ImGui::MenuItem((b.name + "##add").c_str())) add(id);- }- }- if (!any) ImGui::TextDisabled("Every brush is on the shelf");- ImGui::EndPopup();- }-+// Right-shelf Move / Zoom / Rotate: drag on the button to navigate, as in ZBrush.+bool App::canvasNavButton(const char* id, const char* icon, const char* label, int mode) {+ const float s = uiScale_;+ const ImVec2 size(44.0f * s, 40.0f * s);+ ImGui::InvisibleButton((std::string(label) + "##" + id).c_str(), size);+ const bool hovered = ImGui::IsItemHovered(), active = ImGui::IsItemActive();+ if (active) {+ const ImVec2 d = ImGui::GetIO().MouseDelta;+ const CanvasRect c = shell_.canvas;+ if (d.x != 0.0f || d.y != 0.0f) {+ if (mode == 0) camera_.pan(d.x, d.y, c.h);+ else if (mode == 1) camera_.zoom(-d.y * 0.05f);+ else camera_.orbit(d.x, d.y);+ }+ ImGui::SetMouseCursor(mode == 0 ? ImGuiMouseCursor_ResizeAll : mode == 1 ? ImGuiMouseCursor_ResizeNS : ImGuiMouseCursor_Hand);+ navDrag_ = mode;+ } else if (navDrag_ == mode) {+ navDrag_ = -1;+ }+ const ImVec2 a = ImGui::GetItemRectMin(), b = ImGui::GetItemRectMax();+ ImDrawList* dl = ImGui::GetWindowDrawList();+ dl->AddRectFilled(a, b, theme::u32(active ? theme::accent : hovered ? theme::buttonHover : theme::frame), 4.0f * s);+ const float capH = (fontTiny_ ? fontTiny_->FontSize : 10.0f) + 2.0f * s;+ const ImU32 fg = theme::u32(active ? theme::textOnAccent : theme::text);+ centredText(dl, fontIcons_, a, ImVec2(b.x, b.y - capH + 2.0f * s), fg, icon);+ centredText(dl, fontTiny_, ImVec2(a.x, b.y - capH), ImVec2(b.x, b.y - 1.0f * s), fg, label);+ ui::HelpAction(*this, id);+ return active;+}++// ---------------------------------------------------------------------------+// Left shelf tiles+// ---------------------------------------------------------------------------++namespace {++// Tile frame: the picture square and the caption under it. Returns true when clicked.+bool tileFrame(const char* id, ImVec2 size, ImFont* font, const std::string& caption, float s, ImVec2& pic0, ImVec2& pic1) {+ const bool clicked = ImGui::InvisibleButton(id, size);+ const bool hovered = ImGui::IsItemHovered();+ const ImVec2 a = ImGui::GetItemRectMin(), b = ImGui::GetItemRectMax();+ ImDrawList* dl = ImGui::GetWindowDrawList();+ const float capH = (font ? font->FontSize : 12.0f) + 4.0f * s;+ pic0 = a;+ pic1 = ImVec2(b.x, b.y - capH);+ dl->AddRectFilled(pic0, pic1, theme::u32(theme::tile), 4.0f * s);+ if (hovered) dl->AddRect(pic0, pic1, theme::u32(theme::accent, 0.8f), 4.0f * s, 0, 1.5f * s);+ centredText(dl, font, ImVec2(a.x, b.y - capH), b, theme::u32(hovered ? theme::text : theme::textDim),+ elide(font ? font : ImGui::GetFont(), caption, size.x).c_str());+ ImGui::LogText("%s", caption.c_str());+ return clicked;+}++} // namespace++void App::drawBrushTile(const char* id, ImVec2 size) {+ const float s = uiScale_;+ const BrushRecipe* recipe = activeRecipe();+ const std::string name = paintMode_ ? "Paint" : recipe ? recipe->name : brushName(brush_);+ ImVec2 a, b;+ const bool clicked = tileFrame(id, size, fontSmall_, name, s, a, b);+ ImDrawList* dl = ImGui::GetWindowDrawList();+ ImTextureID tex = paintMode_ ? ImTextureID(0) : recipe ? thumbs_.recipe(*recipe) : thumbs_.brush(int(brush_));+ const ImVec2 c((a.x + b.x) * 0.5f, (a.y + b.y) * 0.5f);+ const float r = (b.x - a.x) * 0.36f;+ if (tex) {+ dl->AddImageRounded(tex, ImVec2(a.x + 2 * s, a.y + 2 * s), ImVec2(b.x - 2 * s, b.y - 2 * s), ImVec2(0, 0), ImVec2(1, 1),+ IM_COL32_WHITE, 4.0f * s);+ } else if (paintMode_) {+ const glm::vec3 pc = linearToSrgb(doc_.paintColor);+ dl->AddCircleFilled(c, r, theme::u32(ImVec4(pc.x, pc.y, pc.z, 1.0f)), 32);+ centredText(dl, fontIcons_, a, b, IM_COL32(255, 255, 255, 220), ICON_LC_PAINTBRUSH);+ } else {+ drawBrushIcon(dl, c, r, recipe ? int(BrushType::Standard) : int(brush_));+ if (recipe) dl->AddText(fontSmall_, fontSmall_ ? fontSmall_->FontSize : 12.0f, ImVec2(a.x + 4 * s, a.y + 3 * s),+ theme::u32(theme::accent), ICON_LC_SPARKLE);+ }+ if (clicked) openPicker(Picker::Brush, ImVec2(ImGui::GetItemRectMax().x + 4.0f * s, ImGui::GetItemRectMin().y));+ ui::HelpText("Brush", "B", "The active brush. Click for the brush picker; the bottom shelf holds favourites.", "Left shelf");+}++void App::drawStrokeTile(const char* id, ImVec2 size) {+ const float s = uiScale_;+ ImVec2 a, b;+ const bool clicked = tileFrame(id, size, fontSmall_, strokeTypeName(strokeType_), s, a, b);+ ImDrawList* dl = ImGui::GetWindowDrawList();+ const ImU32 col = IM_COL32(235, 235, 235, 230);+ const float w = b.x - a.x, h = b.y - a.y;+ auto at = [&](float u, float v) { return ImVec2(a.x + w * u, a.y + h * v); };+ switch (strokeType_) {+ case StrokeType::Dots: // ZBrush's dotted arc+ for (int i = 0; i < 7; ++i) {+ const float u = float(i) / 6.0f;+ dl->AddCircleFilled(at(0.18f + 0.64f * u, 0.30f + 0.42f * std::sin(u * 2.4f) * (1.0f - u * 0.35f)), 3.2f * s, col);+ }+ break;+ case StrokeType::DragRect:+ dl->AddRect(at(0.22f, 0.26f), at(0.78f, 0.74f), col, 2.0f * s, 0, 1.5f * s);+ dl->AddLine(at(0.3f, 0.66f), at(0.7f, 0.34f), col, 1.5f * s);+ dl->AddTriangleFilled(at(0.7f, 0.34f), at(0.6f, 0.36f), at(0.67f, 0.44f), col);+ break;+ case StrokeType::Spray: {+ uint32_t seed = 7;+ for (int i = 0; i < 26; ++i) {+ seed = seed * 1664525u + 1013904223u;+ const float u = float((seed >> 8) & 0xffff) / 65535.0f;+ seed = seed * 1664525u + 1013904223u;+ const float v = float((seed >> 8) & 0xffff) / 65535.0f;+ seed = seed * 1664525u + 1013904223u;+ const float r = (1.0f + 2.5f * float((seed >> 8) & 0xff) / 255.0f) * s;+ dl->AddCircleFilled(at(0.2f + 0.6f * u, 0.22f + 0.56f * v), r, col);+ }+ break;+ }+ case StrokeType::LazyMouse: {+ ImVec2 pts[16];+ for (int i = 0; i < 16; ++i) {+ const float u = float(i) / 15.0f;+ pts[i] = at(0.16f + 0.62f * u, 0.62f - 0.3f * std::sin(u * 3.0f));+ }+ dl->AddPolyline(pts, 16, col, 0, 2.0f * s);+ dl->AddLine(pts[15], at(0.86f, 0.24f), IM_COL32(240, 136, 46, 220), 1.0f * s);+ dl->AddCircleFilled(at(0.86f, 0.24f), 3.0f * s, IM_COL32(240, 136, 46, 255));+ break;+ }+ default: break;+ }+ if (clicked) openPicker(Picker::Stroke, ImVec2(ImGui::GetItemRectMax().x + 4.0f * s, ImGui::GetItemRectMin().y));+ ui::HelpText("Stroke", nullptr, "How dabs follow the cursor: Dots, DragRect, Spray or LazyMouse. Click to choose.",+ "Left shelf");+}++void App::drawAlphaTile(const char* id, ImVec2 size) {+ const float s = uiScale_;+ ImVec2 a, b;+ const bool clicked = tileFrame(id, size, fontSmall_, doc_.brushAlpha.name, s, a, b);+ ImDrawList* dl = ImGui::GetWindowDrawList();+ ImTextureID tex = thumbs_.alpha(doc_.brushAlpha);+ if (tex) {+ dl->AddImageRounded(tex, ImVec2(a.x + 2 * s, a.y + 2 * s), ImVec2(b.x - 2 * s, b.y - 2 * s), ImVec2(0, 0), ImVec2(1, 1),+ IM_COL32_WHITE, 4.0f * s);+ } else {+ constexpr int kCells = 26;+ const float inset = 6.0f * s, cell = (b.x - a.x - 2.0f * inset) / kCells;+ dl->AddRectFilled(ImVec2(a.x + inset, a.y + inset), ImVec2(b.x - inset, b.y - inset), IM_COL32(0, 0, 0, 255), 3.0f * s);+ for (int y = 0; y < kCells; ++y)+ for (int x = 0; x < kCells; ++x) {+ const float u = (float(x) + 0.5f) / kCells * 2.0f - 1.0f, v = 1.0f - (float(y) + 0.5f) / kCells * 2.0f;+ const int g = int(std::clamp(doc_.brushAlpha.sample(u, v), 0.0f, 1.0f) * 255.0f);+ if (g < 4) continue;+ const ImVec2 p(a.x + inset + float(x) * cell, a.y + inset + float(y) * cell);+ dl->AddRectFilled(p, ImVec2(p.x + cell + 0.5f, p.y + cell + 0.5f), IM_COL32(g, g, g, 255));+ }+ }+ if (clicked) openPicker(Picker::Alpha, ImVec2(ImGui::GetItemRectMax().x + 4.0f * s, ImGui::GetItemRectMin().y));+ ui::HelpText("Alpha", nullptr, "The brush's stamp shape (white = full effect). Click for the alpha picker.", "Left shelf");+}++void App::drawMaterialTile(const char* id, ImVec2 size) {+ const float s = uiScale_;+ const int m = renderSettings_.matcap;+ ImVec2 a, b;+ const bool clicked = tileFrame(id, size, fontSmall_, m < 0 ? std::string("Studio") : std::string(matcapName(m)), s, a, b);+ ImDrawList* dl = ImGui::GetWindowDrawList();+ const ImVec2 c((a.x + b.x) * 0.5f, (a.y + b.y) * 0.5f);+ const float r = (b.x - a.x) * 0.4f;- ImTextureID tex = thumbs_.material(m);- if (!tex && m >= 0)- if (const GLuint t = renderer_.matcapTexture(m)) tex = ImTextureID(uintptr_t(t));- if (tex) {- // Matcaps are spheres already; textures are stored bottom-up.- dl->AddImageRounded(tex, ImVec2(c.x - r, c.y - r), ImVec2(c.x + r, c.y + r), ImVec2(0, m >= 0 ? 1.0f : 0.0f),- ImVec2(1, m >= 0 ? 0.0f : 1.0f), IM_COL32_WHITE, r);++ if (ImTextureID thumb = thumbs_.material(m)) { // a rendered sphere on a transparent background++ dl->AddImage(thumb, ImVec2(a.x + 2 * s, a.y + 2 * s), ImVec2(b.x - 2 * s, b.y - 2 * s));++ } else if (const GLuint t = m >= 0 ? renderer_.matcapTexture(m) : 0) {++ // Until then the raw matcap (a sphere picture already; stored bottom-up).++ dl->AddImageRounded(ImTextureID(uintptr_t(t)), ImVec2(c.x - r, c.y - r), ImVec2(c.x + r, c.y + r), ImVec2(0, 1),++ ImVec2(1, 0), 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::Look::IconLabel);+ ui::HelpAction(*this, "color.fill");+ ImGui::EndGroup();+}++} // namespace sfdiff --cc src/app/UiLayout.cppindex 2ce61493,b4e5d943..a1225bbf--- a/src/app/UiLayout.cpp+++ b/src/app/UiLayout.cpp@@@ -26,19 -26,6 +26,19 @@@ UiLayout standardLayout()UiLayout l;l.rightTray = {"tool"};l.openSubpalettes = {"tool.subtool"};+ l.topShelf = {"ui.lightbox", "sep", "draw.sculpt", "draw.paint", "sep",+ "draw.zadd", "draw.zsub", "draw.rgb", "sep", "widget.draw_size",+ "widget.strength", "row", "ui.brush_lab", "draw.front_faces", "sep",+ "transform.symmetry_x", "transform.symmetry_y", "transform.symmetry_z", "sep", "draw.pressure_strength",+ "draw.pressure_size", "widget.points"};+ l.leftShelf = {"widget.tile.brush", "widget.tile.stroke", "widget.tile.alpha", "widget.tile.material", "widget.color"};+ l.rightShelf = {"view.frame", "widget.nav.move", "widget.nav.zoom", "widget.nav.rotate", "sep",+ "view.polyf", "view.polygroups", "view.mask", "view.polypaint", "sep",+ "subtool.solo", "view.splats"};+ l.bottomShelf = {"brush.standard", "brush.clay", "brush.claybuildup", "brush.damstandard", "brush.move",+ "brush.smooth", "brush.inflate", "brush.pinch", "brush.flatten", "brush.crease",- "brush.trim", "brush.snakehook", "brush.layer", "brush.nudge", "draw.paint",++ "brush.trim", "brush.snakehook", "brush.layer", "brush.nudge", "brush.paint",+ "widget.add_brush"};return l;}diff --cc src/render/Renderer.cppindex 665cce77,d4922e28..791bc3e8--- a/src/render/Renderer.cpp+++ b/src/render/Renderer.cpp@@@ -682,27 -682,12 +682,28 @@@ void Renderer::endCapture(std::vector<ugl::BindFramebuffer(GL_FRAMEBUFFER, 0);}-void Renderer::draw(const Camera& camera, int fbWidth, int fbHeight, const RenderSettings& settings) {- gl::Viewport(0, 0, fbWidth, fbHeight);- if (thumbnailPass_) gl::ClearColor(0.0f, 0.0f, 0.0f, 0.0f);+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);++ if (thumbnailPass_) gl::ClearColor(0.0f, 0.0f, 0.0f, 0.0f); // renderMeshThumbnail: transparent background+ else 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 --cc tests/test_shell_layout.cppindex e93ac7af,00000000..172f5d8dmode 100644,000000..100644--- a/tests/test_shell_layout.cpp+++ b/tests/test_shell_layout.cpp@@@ -1,109 -1,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");++ l.bottomShelf.push_back("brush.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 --cc tests/ui/brush_sharing.sfuiindex 74df7fc0,e5698901..c30f0bd7--- a/tests/ui/brush_sharing.sfui+++ b/tests/ui/brush_sharing.sfui@@@ -3,10 -3,6 +3,10 @@@# UI tests get an empty library of their own in --ui-out/brush-library.expect_value user_brushes == 0expect_value library_files == 0+# The Brush palette (with the custom brushes) goes into the right tray; Brush Lab opens from the top shelf.++click "AI Brush"+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.6diff --cc tests/ui/lightbox.sfuiindex 00000000,b57411a0..b411d22cmode 000000,100644..100644--- a/tests/ui/lightbox.sfui+++ b/tests/ui/lightbox.sfui@@@ -1,0 -1,142 +1,144 @@@+ # LightBox (comma key): tabs, history, loading models, appending SubTools, materials,+ # brushes, QuickSave; then the ZBrush-style pickers: the brush pop-up (B, type letters,+ # press the orange key), the material pop-up (M) and Draw Size / Strength at the cursor (S / I).+ run new_plane resolution=8+ expect_value triangles == 128-expect_not "LightBox"++expect_value lightbox_open == 0 # (the window; "LightBox" is also the top-shelf button)++ key ,-expect "LightBox"++expect_value lightbox_open == 1+ click "LightBox/Tool"+ expect "LightBox/Sphere"+ expect "LightBox/Cube"+ expect "LightBox/Built-in"+ wait_idle 60+ shot lightbox-tool++ # Double-click a model to open it (replaces the scene), Shift+double-click to append it as a SubTool.+ double_click "LightBox/Sphere"+ expect_value triangles > 128+ expect_value subtools == 1+ hold shift+ double_click "LightBox/Cube"+ hold none+ expect_value subtools == 2+ expect_status Appended SubTool++ # A tile dragged out of the strip onto the canvas loads like a double-click (the Cube tile).+ drag_item "LightBox/Cube" 500 300+ expect_status Created cube+ expect_value subtools == 1++ # Folders: Built-in holds the bundled demo files; ".." and Back return to the tab's root.+ double_click "LightBox/Built-in"+ wait_idle 30+ expect "LightBox/lion-head"+ expect_not "LightBox/Sphere"+ double_click "LightBox/.."+ expect "LightBox/Sphere"+ double_click "LightBox/User"+ wait_idle 30+ expect "LightBox/.."+ click "LightBox/###Back"+ expect "LightBox/Sphere"++ # Materials and brushes load with a double-click too.+ click "LightBox/Material"+ expect "LightBox/Chrome"+ double_click "LightBox/Chrome"+ expect_status Material: Chrome+ click "LightBox/Brush"+ expect "LightBox/DamStandard"+ double_click "LightBox/DamStandard"+ expect_status Brush: DamStandard+ wait_idle 60+ shot lightbox-brush++ # Drag sideways to scrub the strip: brushes far to the right come into view.+ expect_not "LightBox/Skin Pores"+ drag_item "LightBox/Inflate" -700 0+ drag_item "LightBox/Nudge" -700 0+ expect "LightBox/Skin Pores"+ expect_status Brush: DamStandard++ # More rows, then back through the history to the Material tab.+ click "LightBox/3"+ wait_idle 60+ shot lightbox-3-rows+ click "LightBox/1"+ click "LightBox/###Back"+ expect "LightBox/Chrome"++ # QuickSave: a timestamped copy in the library's QuickSave folder, listed newest first.+ click "LightBox/QuickSave"+ expect_text QuickSave keeps timestamped copies+ click "LightBox/###QuickSave now"+ expect_status QuickSaved+ wait 6+ wait_idle 30+ expect_no_text QuickSave keeps timestamped copies+ shot lightbox-quicksave++ key ,-expect_not "LightBox"++expect_value lightbox_open == 0++ # Brush pop-up: B, then a letter narrows the grid and puts an orange key on each brush.+ key b+ expect "Brushes/Standard"+ expect "Brushes/Clay"+ wait_idle 60+ shot picker-brush+ key c+ expect_text [R]+ expect_not "Brushes/Standard"+ shot picker-brush-c+ key r+ expect_not "Brushes/Clay"+ expect_status Brush: Crease+ key b+ key s+ key t+ expect_status Brush: Standard+ # Backspace undoes a letter, Esc closes without picking.+ key b+ key s+ key n+ expect_status Brush: SnakeHook+ key b+ key z+ expect_text No brush matches+ key backspace+ expect "Brushes/Standard"+ # Brushes used lately come first.+ expect_text Recent+ wait_idle 30+ shot picker-brush-recent+ key escape+ expect_not "Brushes/Standard"++ # Material pop-up: hovering previews on the model, a click keeps it.+ key m+ expect "Materials/Red Wax"+ hover "Materials/Red Wax"+ shot picker-material-hover+ click "Materials/Bronze"+ expect_status Material: Bronze+ expect_not "Materials/Red Wax"++ # Draw Size / Strength at the cursor: type a number and press Enter.+ key s++expect "##cursorvalue"+ expect_text Draw Size 60+ key 1+ key 2+ key 0+ key enter+ key s+ expect_text Draw Size 120+ key escape+ key i++expect "##cursorvalue"+ expect_text Strength 0.50+ shot strength-popup+ key escape-expect_no_text Strength 0.50++expect_not "##cursorvalue" # (the top shelf always shows its own Strength slider)