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.

Bottom shelf Add a brush: the + drawn from pixel-snapped bars centred on the circle, not a glyph (#150)

islandmeda14f65c45d69
diff --git a/changes/fix-plus-icon-center.md b/changes/fix-plus-icon-center.md
new file mode 100644
index 00000000..afb38485
--- /dev/null
+++ b/changes/fix-plus-icon-center.md
@@ -0,0 +1,9 @@
+---
+fixed: The bottom shelf's **Add a brush** button draws its + exactly in the middle of the circle at every UI scale
+ and on Retina screens; it was a font glyph that sat off centre (#150, thanks @tristratos).
+testers:
+ - macOS Retina, and Windows at 125% / 150% scaling: the circled + at the end of the bottom shelf has the + dead
+ centre, horizontally and vertically, hovered or not.
+---
+Drawn from pixel-snapped rects sharing the circle's centre (circledPlus in ShellGeometry); test_ui_scale checks
+scales 1-2 at fractional positions. Other circled pluses (Stroke popup Add) are a single icon-font glyph, ink-centred.
diff --git a/src/app/Shell.cpp b/src/app/Shell.cpp
index 17fc28b7..f7912d03 100644
--- a/src/app/Shell.cpp
+++ b/src/app/Shell.cpp
@@ -2283,10 +2283,13 @@ void App::drawShelfItem(int shelf, int index, const std::string& item, bool vert
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);
+ const CircledPlus p = circledPlus((a.x + b.x) * 0.5f, a.y + 4.0f * s + r, r, s); // lines, not a glyph (#150)
+ dl->AddCircle(ImVec2(p.cx, p.cy), p.r, theme::u32(hovered ? theme::accent : theme::textDim, hovered ? 1.0f : 0.6f), 48,
+ p.stroke);
+ const ImU32 fg = theme::u32(hovered ? theme::accent : theme::textDim);
+ dl->AddRectFilled(ImVec2(p.barX0, p.barY0), ImVec2(p.barX1, p.barY1), fg);
+ dl->AddRectFilled(ImVec2(p.colX0, p.colY0), ImVec2(p.colX1, p.barY0), fg); // no overlap: a dimmed + stays even
+ dl->AddRectFilled(ImVec2(p.colX0, p.barY1), ImVec2(p.colX1, p.colY1), fg);
ui::HelpText("Add a brush", nullptr, "Put another brush (built-in or one of yours) on this shelf.", "Bottom shelf");
} 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
diff --git a/src/app/ShellGeometry.cpp b/src/app/ShellGeometry.cpp
index a3e24f78..c81860ed 100644
--- a/src/app/ShellGeometry.cpp
+++ b/src/app/ShellGeometry.cpp
@@ -14,6 +14,24 @@ float trayWidth(float stored, float logicalWindowWidth) {
return std::clamp(stored, kTrayMinW, kTrayMaxW);
}
+CircledPlus circledPlus(float cx, float cy, float r, float scale) {
+ const float s = scale > 0.0f ? scale : 1.0f;
+ CircledPlus p;
+ const float t = std::max(1.0f, std::round(1.5f * s)); // whole-pixel bars: crisp, no half-covered rows
+ // An odd width centres on a pixel's middle, an even one on a pixel edge: then both bars cover whole pixels and
+ // the circle shares their centre exactly.
+ const float half = t * 0.5f;
+ const bool odd = std::fmod(t, 2.0f) != 0.0f;
+ p.cx = odd ? std::floor(cx) + 0.5f : std::round(cx);
+ p.cy = odd ? std::floor(cy) + 0.5f : std::round(cy);
+ p.r = std::round(r);
+ p.stroke = t;
+ const float arm = std::max(2.0f, std::round(r * 0.5f)); // half the + (arms of equal length both ways)
+ p.barX0 = p.cx - arm, p.barX1 = p.cx + arm, p.barY0 = p.cy - half, p.barY1 = p.cy + half;
+ p.colX0 = p.cx - half, p.colX1 = p.cx + half, p.colY0 = p.cy - arm, p.colY1 = p.cy + arm;
+ return p;
+}
+
WindowFit fitWindow(WindowRect win, bool stored, bool placed, float storedScale, const WindowRect& usable,
const WindowBorders& b, float scale) {
WindowFit fit;
diff --git a/src/app/ShellGeometry.h b/src/app/ShellGeometry.h
index e2c01e7f..514b1b60 100644
--- a/src/app/ShellGeometry.h
+++ b/src/app/ShellGeometry.h
@@ -91,4 +91,15 @@ ShellMetrics sculptForgeMetrics(float gap); // the SculptForge layout: menus in
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
diff --git a/tests/test_ui_scale.cpp b/tests/test_ui_scale.cpp
index 443dfb99..23d32eb2 100644
--- a/tests/test_ui_scale.cpp
+++ b/tests/test_ui_scale.cpp
@@ -57,3 +57,23 @@ TEST(ui_scale_matrix_shell_sizes) {
CHECK(near(g.rightShelf.w, base.rightShelf.w * 2.0f, 1.0f));
CHECK(near(g.title.h, base.title.h * 2.0f, 1.0f));
}
+
+TEST(ui_scale_circled_plus_is_centred) {
+ // #150: the bottom shelf's Add a brush + sat off centre in its circle (a font glyph). Drawn from lines now: at
+ // every scale, and wherever the tile lands (fractional item rects), the bars cover whole pixels, have equal arms
+ // both ways and share the circle's centre.
+ const auto whole = [](float v) { return near(v, std::round(v), 1e-4f); };
+ for (float s : {1.0f, 1.25f, 1.5f, 1.75f, 2.0f})
+ for (float x : {100.0f, 100.3f, 100.5f, 100.75f})
+ for (float y : {40.0f, 40.2f, 40.5f, 40.9f}) {
+ const CircledPlus p = circledPlus(x, y + 4.0f * s + 15.0f * s, 15.0f * s, s);
+ CHECK(p.stroke >= 1.0f && whole(p.stroke));
+ for (float e : {p.barX0, p.barX1, p.barY0, p.barY1, p.colX0, p.colX1, p.colY0, p.colY1}) CHECK(whole(e));
+ CHECK(near((p.barX0 + p.barX1) * 0.5f, p.cx, 1e-4f) && near((p.barY0 + p.barY1) * 0.5f, p.cy, 1e-4f));
+ CHECK(near((p.colX0 + p.colX1) * 0.5f, p.cx, 1e-4f) && near((p.colY0 + p.colY1) * 0.5f, p.cy, 1e-4f));
+ CHECK(near(p.barX1 - p.barX0, p.colY1 - p.colY0, 1e-4f)); // as wide as tall
+ CHECK(near(p.barY1 - p.barY0, p.stroke, 1e-4f) && near(p.colX1 - p.colX0, p.stroke, 1e-4f));
+ CHECK(std::abs(p.cx - x) <= 0.5f && std::abs(p.cy - (y + 19.0f * s)) <= 0.5f); // moved at most half a px
+ CHECK(p.barX1 - p.barX0 < 2.0f * p.r); // inside the circle
+ }
+}