Merge pull request #19027

Co-authored-by: autocraft-bot[bot] <354215646+autocraft-bot[bot]@users.noreply.github.com>
This commit is contained in:
davidmann4andautocraft-bot[bot] authored and autocraft-bot[bot] committed 2026-12-02 22:19:56 +00:00
commit 535dbe553e
3 files changed
+115 -4

No files matched your search

@@ -98,13 +98,13 @@ fn a_rightward_drag_only_changes_the_size() {
assert_eq!(hardness(&a), 0, "no vertical travel, no hardness change");
}
/// Done when 2: with the preference off the vertical drag changes the opacity at today's rate
/// (200 points from 0 % to 100 %), not the hardness.
/// With the preference off the vertical drag changes opacity at the rate measured in #19003
/// (400 points from 0 % to 100 %), leaving hardness alone.
#[test]
fn with_the_preference_off_the_vertical_drag_keeps_the_opacity_rate() {
let mut a = app(0.0, 0.5);
a.run("prefs.set", json!({"path": "tools.varyRoundBrushHardnessOnHud", "value": false})).unwrap();
drag(&mut a, 0.0, -50.0);
assert_eq!(opacity(&a), 25, "50 points of a 200-point travel, from 50 %");
assert_eq!(opacity(&a), 38, "50 points of a 400-point travel, from 50 %");
assert_eq!(hardness(&a), 0, "the hardness is left alone");
}
+5 -1
View File
@@ -27,7 +27,7 @@ use crate::state::Tool;
const HARDNESS_TRAVEL: f32 = 400.0;
/// Screen points of vertical drag that take the opacity from 0 % to 100 % when "Vary Round Brush
/// Hardness on HUD" is off.
const OPACITY_TRAVEL: f32 = 200.0;
const OPACITY_TRAVEL: f32 = 400.0;
/// Screen points of vertical drag that take the Color Replacement Tolerance from 0 % to 100 % when "Vary Round Brush
/// Hardness on HUD" is off: the reference's 0.25 % per screen point, where 50 points down from 30 % give 43 % (#17760).
const TOLERANCE_TRAVEL: f32 = 400.0;
@@ -226,3 +226,7 @@ mod color_replacement_tolerance_tests;
#[cfg(test)]
#[path = "../brush_resize_hardness_rate_tests.rs"]
mod brush_resize_hardness_rate_tests;
#[cfg(test)]
#[path = "brush_resize_opacity_rate_tests.rs"]
mod brush_resize_opacity_rate_tests;
@@ -0,0 +1,107 @@
//! #19003: the Brush resize HUD changes opacity by 0.25 % per screen point at every zoom.
use craft::behavior::PointerButton;
use craft::keymap::Mods;
use craft::ui::runtime::windows::{Released, WindowHost};
use egui::Pos2;
use serde_json::json;
use crate::PhotocraftApp;
use crate::canvas::testing;
use crate::state::Tool;
fn app(zoom: f32, vary_hardness: bool) -> Box<PhotocraftApp> {
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default());
app.run("file.new", json!({"width": 200, "height": 100, "background": "white"})).unwrap();
app.ui.tool = Tool::Brush;
crate::paint_mouse::sync_tool_brush(&mut app);
app.run("tools.setBrush", json!({"brush": {"size": 40, "hardness": 1.0, "opacity": 1.0}})).unwrap();
app.run("prefs.set", json!({"path": "tools.varyRoundBrushHardnessOnHud", "value": vary_hardness})).unwrap();
app.sync_views();
app.ui.views.first_mut().unwrap().zoom = zoom;
app
}
fn settle(app: &mut PhotocraftApp, host: &WindowHost) {
for _ in 0..64 {
testing::frame(app);
if host.injected_idle() {
return;
}
}
panic!("the injected resize input was not taken");
}
/// Begin the measured Alt+right-drag at the canvas centre, keeping subsequent offsets in screen points.
fn begin(app: &mut PhotocraftApp) -> (WindowHost, Pos2) {
testing::shown(app);
let host = WindowHost::of(&testing::ctx(app));
let start = testing::to_screen(app, [100.0, 50.0]);
host.inject_click(egui::ViewportId::ROOT, start, PointerButton::Secondary, 1, Mods::ALT, true);
settle(app, &host);
(host, start)
}
fn move_to(app: &mut PhotocraftApp, host: &WindowHost, at: Pos2) {
host.inject_move(egui::ViewportId::ROOT, at, Mods::ALT, 0.0);
settle(app, host);
}
fn release(app: &mut PhotocraftApp, host: &WindowHost, at: Pos2) {
host.inject_release(egui::ViewportId::ROOT, Some(at), Released::Button(PointerButton::Secondary));
settle(app, host);
}
fn opacity(app: &PhotocraftApp) -> i32 {
(app.session.tools.brush.opacity * 100.0).round() as i32
}
#[test]
fn sixty_points_up_then_forty_down_change_opacity_by_fifteen_then_ten_percent() {
for zoom in [1.0, 3.0] {
let mut app = app(zoom, false);
let history = app.session.active().unwrap().history.past_len();
let (host, start) = begin(&mut app);
move_to(&mut app, &host, start + egui::vec2(0.0, -60.0));
assert_eq!(opacity(&app), 85, "60 points up at {zoom}x zoom");
let end = start + egui::vec2(0.0, -20.0);
move_to(&mut app, &host, end);
assert_eq!(opacity(&app), 95, "40 points back down at {zoom}x zoom");
release(&mut app, &host, end);
assert_eq!(opacity(&app), 95, "release keeps opacity");
assert_eq!(app.session.tools.brush.hardness, 1.0);
assert_eq!(app.session.tools.brush.size, 40.0);
assert_eq!(app.session.active().unwrap().history.past_len(), history, "resizing paints nothing");
}
}
#[test]
fn one_hundred_points_up_from_full_opacity_give_seventy_five_percent() {
for zoom in [1.0, 3.0] {
let mut app = app(zoom, false);
let (host, start) = begin(&mut app);
let end = start + egui::vec2(0.0, -100.0);
move_to(&mut app, &host, end);
release(&mut app, &host, end);
assert_eq!(opacity(&app), 75, "100 screen points at {zoom}x zoom");
}
}
#[test]
fn hardness_preference_and_horizontal_size_keep_their_rates() {
let mut app = app(1.0, true);
let (host, start) = begin(&mut app);
let end = start + egui::vec2(0.0, -100.0);
move_to(&mut app, &host, end);
release(&mut app, &host, end);
assert_eq!((app.session.tools.brush.hardness * 100.0).round(), 75.0);
assert_eq!(opacity(&app), 100);
let (host, start) = begin(&mut app);
let end = start + egui::vec2(30.0, 0.0);
move_to(&mut app, &host, end);
release(&mut app, &host, end);
assert_eq!(app.session.tools.brush.size, 100.0, "30 points right add 60 pixels");
assert_eq!((app.session.tools.brush.hardness * 100.0).round(), 75.0);
assert_eq!(opacity(&app), 100);
}