mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Background Eraser: read the resize readout's Opacity row from the Tolerance
The row was merged fixed at 50 %, the Tolerance after Reset Tool, before the measurement in #18053 arrived. Measured, it reads the tool's Tolerance at every value, 0 and 100 % included, and the drag leaves it there. Refs #18053
This commit is contained in:
1 parent
234688b335
commit
99deb3ac67
2 files changed
+25
-22
No files matched your search
@@ -33,10 +33,6 @@ const OPACITY_TRAVEL: f32 = 200.0;
|
||||
const TOLERANCE_TRAVEL: f32 = 400.0;
|
||||
/// The overlay alpha of the preview tint.
|
||||
const TINT_ALPHA: u8 = 110;
|
||||
/// The Background Eraser's third readout row: the reference shows "Opacity : 50 %" there, the
|
||||
/// tool's Tolerance after Reset Tool and not an opacity the tool has (#18053). Unmeasured for other
|
||||
/// Tolerance values, so the row stays at 50 until they are (#18053).
|
||||
const BACKGROUND_ERASER_READOUT_OPACITY: f64 = 50.0;
|
||||
|
||||
/// The brush resize drag of the painting tools, kept in `PhotocraftApp::brush_resize`. The painting tool takes it
|
||||
/// out of the app for each call, so its methods get the app as an argument.
|
||||
@@ -152,7 +148,8 @@ impl PaintResize {
|
||||
|
||||
/// Asks for the diameter and level readout beside the pointer while a resize runs. `hud`, not `readout`: Show
|
||||
/// Transformation Values never hides it. The request lasts one pass, so the tool repeats it every pass.
|
||||
/// The Background Eraser gets a third row, Opacity (#18053); so does Color Replacement, showing its Tolerance (#17760).
|
||||
/// The Background Eraser gets a third row, Opacity, which reads the tool's Tolerance (#18053); so does Color
|
||||
/// Replacement, showing its Tolerance (#17760).
|
||||
pub(crate) fn hud(&self, app: &PhotocraftApp, cx: &mut ToolContext<'_>) {
|
||||
if !self.resize.active() {
|
||||
return;
|
||||
@@ -162,8 +159,9 @@ impl PaintResize {
|
||||
let mut rows = self.resize.readout_rows(&cx.units(), &words);
|
||||
// The reference's third row is there beside a Hardness row; with "Vary Round Brush Hardness on HUD" off the
|
||||
// level row is already Opacity, and a second one would repeat it.
|
||||
// The tool has no opacity: the row shows its Tolerance, at every value, 0 and 100 % included (#18053).
|
||||
if app.ui.tool == Tool::BackgroundEraser && varies_hardness(app) {
|
||||
let opacity = cx.units().percent(BACKGROUND_ERASER_READOUT_OPACITY);
|
||||
let opacity = cx.units().percent(f64::from(app.ui.tool_options.bg_tolerance));
|
||||
rows.push((words.opacity.clone(), opacity));
|
||||
}
|
||||
if levels_tolerance(app) && varies_hardness(app) {
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
//! #18053: the Background Eraser's Ctrl+Alt+drag (Alt+right-drag) readout has a third row,
|
||||
//! "Opacity : 50 %", after Diameter and Hardness, as the reference application does. The row does
|
||||
//! not follow the drag or the tool's Tolerance (not measured), and the gesture still changes only
|
||||
//! the diameter and the hardness, erases nothing and adds no history state.
|
||||
//! "Opacity : 50 %", after Diameter and Hardness, as the reference application does. The tool has
|
||||
//! no opacity: the row reads its Tolerance, at every value, and the drag never changes it. The
|
||||
//! gesture still changes only the diameter and the hardness, erases nothing and adds no history
|
||||
//! state.
|
||||
|
||||
use serde_json::json;
|
||||
|
||||
@@ -39,9 +40,9 @@ fn values(rows: &[(String, String)]) -> Vec<&str> {
|
||||
}
|
||||
|
||||
/// Done when 1: after Reset Tool's brush, three rows in the order Diameter, Hardness, Opacity, and
|
||||
/// the Opacity row reads 50 %.
|
||||
/// the Opacity row reads the Tolerance, 50 % after Reset Tool.
|
||||
#[test]
|
||||
fn the_background_eraser_readout_has_a_fifty_percent_opacity_row() {
|
||||
fn the_background_eraser_readout_has_a_third_opacity_row() {
|
||||
let mut a = app(Tool::BackgroundEraser, 1.0);
|
||||
let got = readout(&mut a, ToolEvent::Down { x: 100.0, y: 50.0, pressure: 1.0 });
|
||||
assert_eq!(
|
||||
@@ -52,10 +53,10 @@ fn the_background_eraser_readout_has_a_fifty_percent_opacity_row() {
|
||||
readout(&mut a, ToolEvent::Up { x: 100.0, y: 50.0 });
|
||||
}
|
||||
|
||||
/// Done when 2: horizontal and vertical movement leave the Opacity row at 50 %, the diameter and
|
||||
/// the hardness following their own axes.
|
||||
/// Done when 2: horizontal and vertical movement leave the Opacity row on the Tolerance, the
|
||||
/// diameter and the hardness following their own axes.
|
||||
#[test]
|
||||
fn the_opacity_row_stays_at_fifty_percent_through_the_drag() {
|
||||
fn the_opacity_row_stays_on_the_tolerance_through_the_drag() {
|
||||
let mut a = app(Tool::BackgroundEraser, 0.5);
|
||||
readout(&mut a, ToolEvent::Down { x: 100.0, y: 50.0, pressure: 1.0 });
|
||||
let right = readout(&mut a, ToolEvent::Move { x: 130.0, y: 50.0, pressure: 1.0 });
|
||||
@@ -68,15 +69,19 @@ fn the_opacity_row_stays_at_fifty_percent_through_the_drag() {
|
||||
readout(&mut a, ToolEvent::Up { x: 130.0, y: 30.0 });
|
||||
}
|
||||
|
||||
/// Done when 3: the row stays at 50 % for another Tolerance. The 50 is the Tolerance after Reset
|
||||
/// Tool, but the reference's row was not measured for other values, so it does not follow it yet.
|
||||
/// Done when 3: the row reads the Tolerance at every value, 0 and 100 % included, as measured in
|
||||
/// the reference application, and a drag leaves it there.
|
||||
#[test]
|
||||
fn another_tolerance_leaves_the_row_at_fifty_percent() {
|
||||
let mut a = app(Tool::BackgroundEraser, 1.0);
|
||||
a.ui.tool_options.bg_tolerance = 85.0;
|
||||
let got = readout(&mut a, ToolEvent::Down { x: 100.0, y: 50.0, pressure: 1.0 });
|
||||
assert_eq!(values(&got), vec!["40 px", "100%", "50%"], "Tolerance 85 %: the row still reads 50 %");
|
||||
readout(&mut a, ToolEvent::Up { x: 100.0, y: 50.0 });
|
||||
fn the_opacity_row_follows_the_tolerance() {
|
||||
for (tolerance, shown) in [(0.0, "0%"), (20.0, "20%"), (37.0, "37%"), (80.0, "80%"), (100.0, "100%")] {
|
||||
let mut a = app(Tool::BackgroundEraser, 1.0);
|
||||
a.ui.tool_options.bg_tolerance = tolerance;
|
||||
let got = readout(&mut a, ToolEvent::Down { x: 100.0, y: 50.0, pressure: 1.0 });
|
||||
assert_eq!(values(&got), vec!["40 px", "100%", shown], "Tolerance {tolerance} %: the row reads it");
|
||||
let drag = readout(&mut a, ToolEvent::Move { x: 130.0, y: 50.0, pressure: 1.0 });
|
||||
assert_eq!(values(&drag), vec!["100 px", "100%", shown], "Tolerance {tolerance} %: the drag leaves it there");
|
||||
readout(&mut a, ToolEvent::Up { x: 130.0, y: 50.0 });
|
||||
}
|
||||
}
|
||||
|
||||
/// Done when 2: the gesture changes only the diameter and the hardness, erases nothing and adds no
|
||||
|
||||
Reference in new issue
Block a user