Skip to content

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

5.5 KB
Raw Blame
// SculptForge - open source digital sculpting
// SPDX-License-Identifier: GPL-3.0-or-later
//
// Where every region of the classic shell goes for a window size: title
// strip, palette bar, the four shelves around the canvas, the console, the tray
// dividers and trays. Pure arithmetic (no ImGui), so it can be unit tested and
// used by input handling before a frame is drawn. See docs/ui-design.md §2.
#pragma once

#include "app/UiLayout.h"

namespace sf {

// Whether a window saved as full screen opens full screen again (#35). Not on macOS (#41, #85): there full screen is a
// Space of its own, and entered at start-up the traffic lights and menu bar can't be revealed; the window comes back
// maximised instead.
#if defined(__APPLE__)
constexpr bool kMacWindows = true;
#else
constexpr bool kMacWindows = false;
#endif
constexpr bool restoresFullscreen(bool savedFullscreen, bool mac = kMacWindows) { return savedFullscreen && !mac; }

// Where a new or restored window goes (#105), in the window system's units: inside the display's usable area with
// its frame (`borders`: the title bar on top), title bar on screen. `scale` is the UI scale Automatic picks there.
// A window never stored opens 1600x960 logical px, centred, maximised when that doesn't fit; a
// stored one keeps its logical size: stored at another scale (`storedScale`; files before 0.10.11 have none: 100 %),
// it grows or shrinks with it (a 1600x960 window at Windows' 200 % was 800 logical px wide and the shelves ran off
// its right edge), maximised when that doesn't fit.
struct WindowRect {
    int x = 0, y = 0, w = 0, h = 0;
};
struct WindowBorders {
    int top = 0, left = 0, bottom = 0, right = 0;
};
struct WindowFit {
    WindowRect rect;
    bool maximize = false;
};
WindowFit fitWindow(WindowRect window, bool stored, bool placed, float storedScale, const WindowRect& usable,
                    const WindowBorders& borders, float scale);

struct ShellGeometry {
    CanvasRect notchBand;               // h 0 unless the top of the window is unsafe (camera notch)
    CanvasRect title, paletteBar;
    CanvasRect topShelf, leftShelf, rightShelf, bottomShelf;
    CanvasRect console;                 // h 0 when closed
    CanvasRect leftDivider, rightDivider; // w 0 when the shelves are hidden
    CanvasRect leftTray, rightTray;     // w 0 when closed
    CanvasRect canvas;                  // the 3D view
    bool narrow = false;                // < 1280 logical px: right tray collapsed, smaller tiles
    bool shelves = true;                // shelves and trays shown (Tab hides them)
    float scale = 1.0f;
};

// Logical sizes at scale 1 (docs/ui-design.md §2.1).
namespace shell {
constexpr float kTitleH = 24, kPaletteBarH = 22, kTopShelfH = 64, kLeftShelfW = 88, kLeftShelfNarrowW = 72;
constexpr float kRightShelfW = 52, kDividerW = 8, kTrayMinW = 240, kTrayMaxW = 480;
constexpr float kConsoleMinH = 100, kConsoleMaxH = 400, kNarrowWidth = 1280, kWideWidth = 1920;

// The bottom shelf for a Shelf tiles setting (UiLayout::shelfTiles): its height and its brush tiles' height and
// width range (tiles shrink to the minimum, the same for every size, before the shelf scrolls), logical px.
struct BottomShelfSize {
    float shelfH, tileH, tileMinW, tileMaxW;
};
constexpr BottomShelfSize bottomShelfSize(int tiles) {
    return tiles <= 0 ? BottomShelfSize{60, 54, 44, 58} : tiles == 1 ? BottomShelfSize{78, 72, 44, 78} : BottomShelfSize{96, 90, 44, 96};
}
} // namespace shell

// Effective tray width in logical px: the stored width, except that the standard 300 grows to 320 on
// windows 1920 logical px wide or more.
float trayWidth(float stored, float logicalWindowWidth);

// The sizes that differ between the Classic layout (the defaults: shell:: above) and the SculptForge layout,
// and the gap of a tiled look (Preferences > Interface > Look), logical px.
struct ShellMetrics {
    float titleH = shell::kTitleH, paletteBarH = shell::kPaletteBarH, topShelfH = shell::kTopShelfH;
    float dividerW = shell::kDividerW;
    float gap = 0.0f; // tiles: every region is inset so `gap` px of wallpaper shows between them and at the edges
                      // (bars and shelves grow by the gap first, so what's inside keeps its size); the dividers
                      // become the gaps beside the trays
    float grow = 0.0f; // (internal) added to the bars' and shelves' sizes
    float windowW = 0.0f; // (internal) the whole window's width when laying out inside the gaps: narrow and the
                          // tray width follow the window, not the gap-inset span (#107)
};
ShellMetrics sculptForgeMetrics(float gap); // the SculptForge layout: menus in the status bar, a one-row tool shelf

// `topInset` (window px) keeps everything below a camera notch or other unsafe band at the top.
ShellGeometry computeShell(const UiLayout& layout, float width, float height, float scale, float topInset = 0.0f,
                           const ShellMetrics& metrics = ShellMetrics());

// A circled + (the bottom shelf's Add a brush, #150), drawn from its centre, not a font glyph: the circle's centre
// and the bars' edges land on the pixel grid at every UI scale, so the + sits exactly in the middle. Window px.
struct CircledPlus {
    float cx = 0, cy = 0, r = 0; // the circle (its stroke `stroke` px wide)
    float stroke = 1;
    float barX0 = 0, barY0 = 0, barX1 = 0, barY1 = 0; // the horizontal bar
    float colX0 = 0, colY0 = 0, colX1 = 0, colY1 = 0; // the vertical bar
};
// `cx, cy, r`: the wanted circle; `scale`: the UI scale.
CircledPlus circledPlus(float cx, float cy, float r, float scale);

} // namespace sf