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.

#138: the S / O pop-up draws the brush ring where it opened, at the size or Falloff being set (dragged or typed)

islandmed7a901827fc4c
diff --git a/changes/feat-size-popup-ring.md b/changes/feat-size-popup-ring.md
new file mode 100644
index 00000000..a2d241f5
--- /dev/null
+++ b/changes/feat-size-popup-ring.md
@@ -0,0 +1,15 @@
+---
+whats_new: **The brush ring shows the new size while you set it**: with the **S** pop-up open, dragging or typing a
+ size draws the ring at that size on the model, where you pressed S; **O** shows the Falloff ring the same way.
+added: While the **S** (Size) pop-up is open, the brush ring stays on the model at the point where it was opened and
+ shows the size being set, live while dragging and before Enter while typing a number (#138).
+ **O** (Falloff) draws the inner Falloff ring the same way. The ring lies under the pop-up so its number stays readable.
+testers:
+ - Any OS: point at the model, press S and drag the knob far left and right: the ring on the model grows and shrinks
+ live where you pressed S. Press S again and type 150: the ring shows 150 px before Enter.
+ - Any OS: press O and type 80 (or -80): the inner ring shows that Falloff on a big brush.
+---
+Reviewer notes: PickerUi::sliderPreview (Pickers.cpp) gives the pop-up's anchor and the value being set (typed number
+parsed as Enter would apply it); App::drawBrushCursor draws at that anchor (drawSurfaceCursor now takes the point and
+the Falloff) on the background draw list, without the mm readout (the pop-up shows the size). At a small brush the
+Falloff ring sits mostly behind the pop-up bar. tests/ui/size_popup_ring.sfui (size_ring_preview / size_ring_px).
diff --git a/src/app/App.cpp b/src/app/App.cpp
index 4affd97b..e8fdd66f 100644
--- a/src/app/App.cpp
+++ b/src/app/App.cpp
@@ -1,6 +1,7 @@
// SculptForge - open source digital sculpting
// SPDX-License-Identifier: GPL-3.0-or-later
#include "app/App.h"
+#include "app/Pickers.h"
#include "app/BrandMark.h"
#include "io/BridgeProtocol.h"
#include "core/LayerStack.h"
@@ -2876,7 +2877,14 @@ void App::drawUi() {
// In Gizmo mode (and with the QRemesh Guides brush) the brush ring shows only while Ctrl masks or Shift smooths.
const bool ringOff = gizmoActive() || (guidesMode_ && !(inputMods() & SDL_KMOD_SHIFT)) || sculptableHot() || forgesphereActive() ||
uvToolActive();
- if (((!ImGui::GetIO().WantCaptureMouse && canvasRect().contains(mouse.x, mouse.y)) || drag_ == Drag::Stroke) &&
+ // (The S / O pop-up holds the mouse, but its ring shows where it opened, #138.)
+ ImVec2 sliderOpened;
+ PickerUi::Slider sliderWhich;
+ float sliderValue;
+ const bool sliderRing = PickerUi::sliderPreview(*this, sliderOpened, sliderWhich, sliderValue) &&
+ canvasRect().contains(sliderOpened.x, sliderOpened.y);
+ if (!sliderRing) sizeRingPreview_ = false;
+ if (((!ImGui::GetIO().WantCaptureMouse && canvasRect().contains(mouse.x, mouse.y)) || drag_ == Drag::Stroke || sliderRing) &&
!hideBrushCursor_ && radial_.menu < 0 && !strokePopup_.open && drag_ != Drag::Select && drag_ != Drag::Guide && // (no ring under a pie or the stroke popup)
(!ringOff || drag_ == Drag::Stroke || ctrlDown(inputMods())))
drawBrushCursor();
@@ -3918,14 +3926,14 @@ void App::drawPalette_Splats() {
drawSculptableSection(); // Make sculptable (PanelSculptable.cpp)
}
-bool App::drawSurfaceCursor(ImDrawList* dl, float radiusPx, ImU32 col, bool ring) {
+bool App::drawSurfaceCursor(ImDrawList* dl, float x, float y, float radiusPx, float focal, ImU32 col, bool ring) {
// Only what brushes work on: the active, visible Part with an up-to-date BVH (a stale one, after a
// whole-mesh change, is rebuilt at the next press; until then the flat ring shows), not an LOD preview.
if (previewLod_ >= 0 || doc_.bvhDirty) return false;
// Not while the solver thread is moving this mesh (predictive strokes): reading it then races the dabs.
if (solverBusy() || (asyncStroke_ && drag_ == Drag::Stroke)) return false;
RayHit hit;
- if (!pick(mouseX_, mouseY_, hit)) return false; // one ray, as a press would cast
+ if (!pick(x, y, hit)) return false; // one ray, as a press would cast
// The world radius a dab here gets (App::firstDab / the brushes: Size times world size of a pixel).
const float radius = radiusPx * camera_.worldPerPixel(hit.position, canvasHeight());
if (!(radius > 0.0f) || !std::isfinite(radius)) return false;
@@ -3933,7 +3941,7 @@ bool App::drawSurfaceCursor(ImDrawList* dl, float radiusPx, ImU32 col, bool ring
// that plane (#88): no per-point pressing, so bumps can't bend or break the ring. Never a pass over the mesh.
const glm::vec3 n = surfaceCursorNormal(doc_.mesh, doc_.bvh, hit, radius);
surfaceCursorCircle(hit.position, n, radius, 64, cursorRing_);
- surfaceCursorCircle(hit.position, n, radius * focalRingFraction(focalShift_), 48, cursorInner_);
+ surfaceCursorCircle(hit.position, n, radius * focalRingFraction(focal), 48, cursorInner_);
const glm::vec3 eye = camera_.position(), forward = camera_.forward();
const bool ortho = camera_.ortho;
@@ -4092,15 +4100,28 @@ void App::drawViewFigure() {
}
void App::drawBrushCursor() {
- ImDrawList* dl = ImGui::GetForegroundDrawList();
+ // The S / O pop-up (#138): the ring stays where the pop-up opened, at the size or falloff being set, under the
+ // pop-up (the background list) so its number stays readable.
+ ImVec2 opened;
+ PickerUi::Slider which;
+ float value;
+ sizeRingPreview_ = drag_ != Drag::Stroke && PickerUi::sliderPreview(*this, opened, which, value);
+ ImDrawList* dl = sizeRingPreview_ ? ImGui::GetBackgroundDrawList() : ImGui::GetForegroundDrawList();
const CanvasRect canvas = canvasRect();
dl->PushClipRect(ImVec2(canvas.x, canvas.y), ImVec2(canvas.x + canvas.w, canvas.y + canvas.h), true);
struct PopClip {
ImDrawList* dl;
~PopClip() { dl->PopClipRect(); }
} popClip{dl};
- const float r = radiusPx_ * (pressureSizeOn() && lastInputPen_ ? std::max(strokePressure(), 0.05f) : 1.0f);
- const glm::vec2 at = predictedPointer(); // during a predictive stroke, where the pen will be as this frame shows
+ float r = radiusPx_ * (pressureSizeOn() && lastInputPen_ ? std::max(strokePressure(), 0.05f) : 1.0f);
+ float focal = focalShift_;
+ glm::vec2 at = predictedPointer(); // during a predictive stroke, where the pen will be as this frame shows
+ if (sizeRingPreview_) {
+ at = glm::vec2(opened.x, opened.y);
+ if (which == PickerUi::Slider::DrawSize) r = value;
+ else focal = value;
+ sizeRingPreviewPx_ = r;
+ }
const ImVec2 c(at.x, at.y);
const SDL_Keymod mod = inputMods();
const bool inverted = drag_ == Drag::Stroke ? strokeInvert_
@@ -4124,18 +4145,18 @@ void App::drawBrushCursor() {
}
// Preferences > Cursor > Hide ring while stroking (#88): the dot and the symmetry dots stay.
const bool ring = !(uiPrefs_.hideRingWhileStroking && drag_ == Drag::Stroke);
- surfaceCursorShown_ = uiPrefs_.cursorFollowsSurface && drawSurfaceCursor(dl, r, col, ring);
+ surfaceCursorShown_ = uiPrefs_.cursorFollowsSurface && drawSurfaceCursor(dl, c.x, c.y, r, focal, col, ring);
ringShown_ = ring;
if (!surfaceCursorShown_) {
if (ring) {
dl->AddCircle(c, r, col, 64, 1.5f);
// The inner ring is Falloff: where the falloff drops to half.
- dl->AddCircle(c, r * focalRingFraction(focalShift_), IM_COL32(255, 255, 255, 90), 48, 1.0f);
+ dl->AddCircle(c, r * focalRingFraction(focal), IM_COL32(255, 255, 255, 90), 48, 1.0f);
} else {
dl->AddCircleFilled(c, 2.0f * uiScale_, col);
}
}
- drawPrecisionCursor(dl, c, r, col); // Steady Stroke's string, the precision drag, the size in mm (Precision.cpp)
+ if (!sizeRingPreview_) drawPrecisionCursor(dl, c, r, col); // Steady Stroke's string, the precision drag, the size in mm (Precision.cpp; the pop-up shows the size itself)
}
} // namespace sf
diff --git a/src/app/App.h b/src/app/App.h
index a63c1f29..951d9aa4 100644
--- a/src/app/App.h
+++ b/src/app/App.h
@@ -236,11 +236,15 @@ private:
void sendBrushRequest(const std::string& text);
void pollBrushRequest();
const BrushRecipe* activeRecipe() const;
+ // The brush ring at the pointer; while the S / O pop-up is open (#138), at the point it opened from, with the
+ // size or falloff being set (dragged or typed).
void drawBrushCursor();
- // The brush ring lying on the surface under the pointer (#25, Preferences > Cursor > Cursor follows surface);
- // false when the pointer is off the model (the flat screen ring is drawn instead). `ring` false: only the
- // centre and the symmetry copies' dots (Hide ring while stroking).
- bool drawSurfaceCursor(ImDrawList* dl, float radiusPx, ImU32 col, bool ring);
+ // The brush ring lying on the surface under (x, y) (#25, Preferences > Cursor > Cursor follows surface);
+ // false when that point is off the model (the flat screen ring is drawn instead). `ring` false: only the
+ // centre and the symmetry copies' dots (Hide ring while stroking). `focal`: the Falloff the inner ring shows.
+ bool drawSurfaceCursor(ImDrawList* dl, float x, float y, float radiusPx, float focal, ImU32 col, bool ring);
+ bool sizeRingPreview_ = false; // the last ring drawn was the S / O pop-up's preview (UI tests: size_ring_preview)
+ float sizeRingPreviewPx_ = 0.0f; // its radius, pixels (UI tests: size_ring_px)
std::vector<glm::vec3> cursorRing_, cursorInner_; // scratch, kept to avoid allocating per frame
bool surfaceCursorShown_ = false; // the last cursor drawn lay on the surface (UI tests: surface_cursor)
bool ringShown_ = true; // the last cursor drawn had its ring (UI tests: cursor_ring)
diff --git a/src/app/Pickers.cpp b/src/app/Pickers.cpp
index 00a3408d..863e0985 100644
--- a/src/app/Pickers.cpp
+++ b/src/app/Pickers.cpp
@@ -1472,6 +1472,19 @@ void drawPickers(App& app) {
}
}
+bool PickerUi::sliderPreview(const App& app, ImVec2& at, Slider& which, float& value) {
+ const State& s = st();
+ if (s.slider != int(Slider::DrawSize) && s.slider != int(Slider::FocalShift)) return false;
+ which = Slider(s.slider);
+ at = s.sliderAt;
+ value = which == Slider::DrawSize ? app.radiusPx_ : app.focalShift_;
+ if (!s.sliderTyped.empty() && s.sliderTyped != "-" && s.sliderTyped != ".") {
+ const float v = std::strtof(s.sliderTyped.c_str(), nullptr); // as Enter would apply it
+ value = which == Slider::DrawSize ? std::clamp(v, kMinDrawSizePx, kMaxDrawSizePx) : std::clamp(v / 100.0f, -1.0f, 1.0f);
+ }
+ return true;
+}
+
bool PickerUi::sliderKnob(ImVec2& knob) {
const State& s = st();
if (s.slider < 0 || !s.sliderPlaced) return false;
diff --git a/src/app/Pickers.h b/src/app/Pickers.h
index 895933b5..728a0619 100644
--- a/src/app/Pickers.h
+++ b/src/app/Pickers.h
@@ -63,6 +63,9 @@ struct PickerUi {
static void sizePopup(App& app, Slider which);
// The open slider's knob (its current value) in window coordinates, as last drawn; false when none is open.
static bool sliderKnob(ImVec2& knob);
+ // While Size (S) or Falloff (O) is open (#138): where it opened (window coordinates), which, and the value it is
+ // setting: the number being typed (not applied before Enter), else the current one. False otherwise.
+ static bool sliderPreview(const App& app, ImVec2& at, Slider& which, float& value);
};
// The sort menu of an asset list: a small "A-Z v" button that opens A-Z, Recent and (with `packs`) Pack. `pref`
diff --git a/src/app/UiTest.cpp b/src/app/UiTest.cpp
index 7251fa87..b30fa82b 100644
--- a/src/app/UiTest.cpp
+++ b/src/app/UiTest.cpp
@@ -120,6 +120,7 @@
// stroke_continuous (Stroke > Continuous, 1 on),
// stroking (1 while a stroke is open), cursor_x / cursor_y (the brush cursor, pixels),
// surface_cursor (1 when the brush ring last drawn lay on the surface, #25),
+// size_ring_preview / size_ring_px (the ring the S / O pop-up shows where it opened, #138),
// cursor_ring (1 when the last brush cursor drawn had its ring; 0: the dot only, #88),
// hide_ring_while_stroking (Preferences > Cursor, 1 on),
// cursor_follows_surface (Preferences > Input, 1 on),
@@ -1002,6 +1003,8 @@ double Demo::query(const std::string& name, bool& known) const {
if (name == "cursor_x") return app_.mouseX_;
if (name == "cursor_y") return app_.mouseY_;
if (name == "surface_cursor") return app_.surfaceCursorShown_ ? 1.0 : 0.0;
+ if (name == "size_ring_preview") return app_.sizeRingPreview_ ? 1.0 : 0.0; // the S / O pop-up's ring (#138)
+ if (name == "size_ring_px") return double(app_.sizeRingPreviewPx_);
if (name == "cursor_ring") return app_.ringShown_ ? 1.0 : 0.0;
if (name == "hide_ring_while_stroking") return app_.uiPrefs_.hideRingWhileStroking ? 1.0 : 0.0;
if (name == "cursor_follows_surface") return app_.uiPrefs_.cursorFollowsSurface ? 1.0 : 0.0;
diff --git a/tests/ui/size_popup_ring.sfui b/tests/ui/size_popup_ring.sfui
new file mode 100644
index 00000000..9c2eafc2
--- /dev/null
+++ b/tests/ui/size_popup_ring.sfui
@@ -0,0 +1,57 @@
+# #138: while the S pop-up is open (dragged or typed), the brush ring stays on the model where it was opened and
+# shows the new size live; O shows the Falloff ring the same way.
+run new_sphere subdivisions=4
+key f
+camera 0 0
+
+# Opened over the model: the ring lies on the surface there, at the current size.
+mouse_move 0.5 0.5
+remember draw_size s0
+key s
+expect_value size_popup_open == 1
+expect_value size_ring_preview == 1
+expect_value surface_cursor == 1
+expect_value size_ring_px == $s0
+shot opened
+
+# Dragging the knob away: the ring stays at the opening point and grows with the size, live.
+drag_path 0.5 0.5 0.9 0.5 keep
+expect_value size_popup_open == 1
+expect_value draw_size > $s0
+remember draw_size s1
+expect_value size_ring_px == $s1
+expect_value size_ring_preview == 1
+expect_value surface_cursor == 1
+shot dragging
+release
+expect_value size_popup_open == 0
+
+# Typing a size: the ring shows it before Enter applies it.
+mouse_move 0.5 0.5
+key s
+key 4
+key 0
+expect_value size_ring_px == 40
+expect_value draw_size == $s1
+shot typed
+key enter
+expect_value size_popup_open == 0
+expect_value draw_size == 40
+
+# Falloff (O): the inner ring follows the number typed; the ring keeps the brush size.
+mouse_move 0.5 0.5
+key o
+expect_value size_ring_preview == 1
+expect_value size_ring_px == 40
+key 8
+key 0
+shot falloff
+key escape
+expect_value size_popup_open == 0
+
+# Opened beside the model: the flat ring there.
+hover_window 0.2 0.75
+key s
+expect_value size_ring_preview == 1
+expect_value surface_cursor == 0
+key escape