mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 20:16:29 -05:00
Merge pull request #19116
Co-authored-by: autocraft-bot[bot] <354215646+autocraft-bot[bot]@users.noreply.github.com>
This commit is contained in:
commit
76f25ee638
4 files changed
+159
-23
No files matched your search
@@ -0,0 +1,130 @@
|
||||
//! #12864: with Object Finder off, an Object Selection click (and a drag under 2 px) selects
|
||||
//! nothing, adds no History state and shows no status-bar message: no Quick Selection dab.
|
||||
//! Rectangle drags with the option off, and clicks and rectangles with it on, keep today's behaviour.
|
||||
|
||||
use egui::Modifiers;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::cam_no_pixels_alert_tests::{drag, selected, steps};
|
||||
use crate::canvas::{ToolEvent, tool_event};
|
||||
use crate::state::Tool;
|
||||
|
||||
/// A click at `at` with `mods` held.
|
||||
fn click(app: &mut PhotocraftApp, at: [f64; 2], mods: Modifiers) {
|
||||
tool_event(app, ToolEvent::Down { x: at[0], y: at[1], pressure: 1.0 }, mods);
|
||||
tool_event(app, ToolEvent::Up { x: at[0], y: at[1] }, mods);
|
||||
}
|
||||
|
||||
/// The issue's document: 800 x 600 white Background and the active pixel layer Shapes with a red
|
||||
/// rectangle 100,100-300,250, a blue disc (centre 500,175, radius 75) and a grey ramp at y
|
||||
/// 350-450, transparent elsewhere. Object Selection, Sample All Layers off; `finder` sets the
|
||||
/// Object Finder option.
|
||||
fn app(finder: bool) -> Box<PhotocraftApp> {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 800, "height": 600, "background": "white"})).unwrap();
|
||||
app.run("layer.new.layer", json!({"name": "Shapes"})).unwrap();
|
||||
app.session
|
||||
.edit("paint", |doc, a| {
|
||||
let s = doc.layer_mut(a.unwrap()).unwrap().surface_mut().unwrap();
|
||||
s.fill_rect(photocraft_geom::Rect::new(100, 100, 300, 250), &[220.0 / 255.0, 30.0 / 255.0, 30.0 / 255.0, 1.0]);
|
||||
for y in 100..250 {
|
||||
for x in 425..575 {
|
||||
let (dx, dy) = (x as f32 + 0.5 - 500.0, y as f32 + 0.5 - 175.0);
|
||||
if dx * dx + dy * dy <= 75.0 * 75.0 {
|
||||
s.fill_rect(photocraft_geom::Rect::new(x, y, x + 1, y + 1), &[30.0 / 255.0, 30.0 / 255.0, 220.0 / 255.0, 1.0]);
|
||||
}
|
||||
}
|
||||
}
|
||||
for x in 0..800 {
|
||||
let v = x as f32 / 799.0;
|
||||
s.fill_rect(photocraft_geom::Rect::new(x, 350, x + 1, 450), &[v, v, v, 1.0]);
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
.unwrap();
|
||||
app.ui.tool = Tool::ObjectSelection;
|
||||
app.ui.tool_options.object_finder = finder;
|
||||
app.ui.tool_options.sample_all.object_selection = false;
|
||||
app
|
||||
}
|
||||
|
||||
/// The centre of the blue disc.
|
||||
const ON_DISC: [f64; 2] = [500.0, 175.0];
|
||||
/// A point on the white Background where Shapes has no pixels.
|
||||
const OVER_WHITE: [f64; 2] = [700.0, 50.0];
|
||||
/// A rectangle around the blue disc, with white Background all around it.
|
||||
const DISC_BOX: &[[f64; 2]] = &[[400.0, 80.0], [600.0, 270.0]];
|
||||
|
||||
#[test]
|
||||
fn a_click_on_the_disc_with_finder_off_changes_nothing() {
|
||||
let mut app = app(false);
|
||||
let before = steps(&app);
|
||||
click(&mut app, ON_DISC, Modifiers::NONE);
|
||||
assert!(!selected(&app), "a click with Object Finder off selects nothing");
|
||||
assert_eq!(steps(&app), before, "no History state");
|
||||
assert!(app.ui.status.is_empty(), "no status-bar message: {}", app.ui.status);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_sub_2_px_drag_with_finder_off_changes_nothing() {
|
||||
let mut app = app(false);
|
||||
let before = steps(&app);
|
||||
drag(&mut app, &[[500.0, 175.0], [501.0, 175.5]]);
|
||||
assert!(!selected(&app), "a drag under 2 px selects nothing");
|
||||
assert_eq!(steps(&app), before, "no History state");
|
||||
assert!(app.ui.status.is_empty(), "no status-bar message: {}", app.ui.status);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_on_empty_white_with_finder_off_stays_silent() {
|
||||
let mut app = app(false);
|
||||
let before = steps(&app);
|
||||
click(&mut app, OVER_WHITE, Modifiers::NONE);
|
||||
assert!(!selected(&app), "nothing selected");
|
||||
assert_eq!(steps(&app), before, "no History state");
|
||||
assert!(app.ui.status.is_empty(), "no \"found nothing\" message: {}", app.ui.status);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shift_or_alt_click_with_finder_off_keeps_the_selection_as_it_is() {
|
||||
// Not measured in the issue: treated like the plain click, so no dab and the selection stays.
|
||||
for (name, mods) in [("Shift", Modifiers::SHIFT), ("Alt", Modifiers::ALT)] {
|
||||
let mut app = app(false);
|
||||
drag(&mut app, DISC_BOX);
|
||||
assert!(selected(&app), "{name}: the rectangle selected the disc");
|
||||
let before = steps(&app);
|
||||
click(&mut app, ON_DISC, mods);
|
||||
assert!(selected(&app), "{name}: the selection stays");
|
||||
assert_eq!(steps(&app), before, "{name}: no History state");
|
||||
assert!(app.ui.status.is_empty(), "{name}: no status-bar message: {}", app.ui.status);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_rectangle_with_finder_off_still_selects_the_disc() {
|
||||
let mut app = app(false);
|
||||
let before = steps(&app);
|
||||
drag(&mut app, DISC_BOX);
|
||||
assert!(selected(&app), "the rectangle selected something");
|
||||
assert_eq!(steps(&app), before + 1, "one History state");
|
||||
assert_eq!(app.session.active().unwrap().history.undo_label(), Some("Object Selection"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_click_with_finder_on_still_selects_the_disc() {
|
||||
let mut app = app(true);
|
||||
let before = steps(&app);
|
||||
click(&mut app, ON_DISC, Modifiers::NONE);
|
||||
assert!(selected(&app), "the click selected the object under the pointer");
|
||||
assert_eq!(steps(&app), before + 1, "one History state");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_rectangle_with_finder_on_still_selects_the_disc() {
|
||||
let mut app = app(true);
|
||||
let before = steps(&app);
|
||||
drag(&mut app, DISC_BOX);
|
||||
assert!(selected(&app), "the rectangle selected something");
|
||||
assert_eq!(steps(&app), before + 1, "one History state");
|
||||
}
|
||||
@@ -152,14 +152,17 @@ fn reset_tool_sets_the_mode_back_to_new() {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn object_finder_off_keeps_quick_selection_and_the_rectangle_inside_the_selection() {
|
||||
fn object_finder_off_click_does_nothing_inside_the_selection_and_the_rectangle_still_runs() {
|
||||
let mut app = app();
|
||||
click(&mut app, RED, Modifiers::NONE);
|
||||
app.ui.tool_options.object_finder = false;
|
||||
// A New-mode click inside the selection is still a Quick Selection dab, not Deselect.
|
||||
// A New-mode click inside the selection is not a Quick Selection dab any more (#12864): it
|
||||
// runs no command, so it neither replaces the selection nor deselects.
|
||||
let steps_before = app.session.active().unwrap().history.past_len();
|
||||
click(&mut app, RED, Modifiers::NONE);
|
||||
assert_eq!(app.session.journal.last().map(|(id, _)| id.as_str()), Some("select.quick"));
|
||||
assert!(selected(&app, RED));
|
||||
assert_ne!(app.session.journal.last().map(|(id, _)| id.as_str()), Some("select.quick"), "no dab");
|
||||
assert!(selected(&app, RED), "the selection stays");
|
||||
assert_eq!(app.session.active().unwrap().history.past_len(), steps_before, "no History state");
|
||||
// A drag inside it is still a rectangle Object Selection, not Move Selection.
|
||||
drag(&mut app, [100.0, 100.0], [300.0, 260.0], Modifiers::NONE);
|
||||
assert_eq!(app.session.journal.last().map(|(id, _)| id.as_str()), Some("select.object"));
|
||||
@@ -167,18 +170,19 @@ fn object_finder_off_keeps_quick_selection_and_the_rectangle_inside_the_selectio
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn object_finder_off_dab_subtracts_with_alt_and_in_subtract_mode() {
|
||||
fn object_finder_off_click_with_alt_or_in_subtract_mode_leaves_the_selection_as_it_is() {
|
||||
// The issue's not-measured case, ruled as the plain click: no dab, so nothing is subtracted.
|
||||
let mut app = app();
|
||||
app.ui.tool_options.object_finder = false;
|
||||
let shift_alt = Modifiers { shift: true, alt: true, ..Default::default() };
|
||||
for (bar, mods) in [(0, Modifiers::ALT), (0, shift_alt), (2, Modifiers::NONE)] {
|
||||
app.run("select.all", json!({})).unwrap();
|
||||
app.ui.selection_mode = bar;
|
||||
let steps_before = app.session.active().unwrap().history.past_len();
|
||||
click(&mut app, RED, mods);
|
||||
assert!(!selected(&app, RED), "bar mode {bar}, {mods:?} subtracts");
|
||||
// The rest is what the layer has: (20, 20) is transparent on it, which a Quick Selection stroke now drops from
|
||||
// the selection (#12919); the blue disc is opaque and stays.
|
||||
assert!(selected(&app, BLUE), "bar mode {bar}, {mods:?} keeps the rest");
|
||||
assert!(selected(&app, RED), "bar mode {bar}, {mods:?}: the click keeps the selection");
|
||||
assert!(selected(&app, BLUE), "bar mode {bar}, {mods:?}: and keeps the rest");
|
||||
assert_eq!(app.session.active().unwrap().history.past_len(), steps_before, "bar mode {bar}, {mods:?}: no History state");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -703,12 +703,12 @@ pub fn content_aware_move_params(app: &PhotocraftApp, offset: [i64; 2]) -> Value
|
||||
|
||||
/// Object Selection: the dragged rectangle. A click (or a sub-2 px nudge) cannot be a
|
||||
/// rectangle: with Object Finder on it selects the object under the pointer, the one hovering
|
||||
/// highlighted (#4087), and finding nothing stays silent. With it off it falls back to a Quick
|
||||
/// Selection dab at the brush size instead of looking dead (⌥ or Subtract mode subtracts,
|
||||
/// otherwise it adds). Larger drags run the rectangle GrabCut; one that finds nothing opens the
|
||||
/// reference application's alert with "Don't show again" (#12861). Both combine as the options
|
||||
/// bar's New / Add / Subtract / Intersect buttons say, with ⇧ adding, ⌥ subtracting and ⇧⌥
|
||||
/// intersecting (#12853).
|
||||
/// highlighted (#4087), and finding nothing stays silent. With it off a click or a nudge does
|
||||
/// nothing at all: no selection, no History state and no message, so the tool is not mistaken
|
||||
/// for a Quick Selection brush (#12864). Larger drags run the rectangle GrabCut; one that finds
|
||||
/// nothing opens the reference application's alert with "Don't show again" (#12861). Both
|
||||
/// combine as the options bar's New / Add / Subtract / Intersect buttons say, with ⇧ adding, ⌥
|
||||
/// subtracting and ⇧⌥ intersecting (#12853).
|
||||
pub fn finish_object_selection(app: &mut PhotocraftApp, start: [f64; 2], end: [f64; 2], mods: Mods) {
|
||||
// Indexed Color and Bitmap: the reference application's alert with OK (#12867), and nothing runs.
|
||||
if let Some(why) = app.session.active().and_then(|st| photocraft_engine::smartselect_cmds::object_mode_refusal(st.doc.mode)) {
|
||||
@@ -742,10 +742,7 @@ pub fn finish_object_selection(app: &mut PhotocraftApp, start: [f64; 2], end: [f
|
||||
return;
|
||||
}
|
||||
if w < 2.0 || h < 2.0 {
|
||||
let size = app.session.tools.brush.size;
|
||||
let mode = if mods.alt || mode == "subtract" { "subtract" } else { "add" };
|
||||
let r = app.run("select.quick", json!({"points": [[end[0], end[1]]], "size": size, "mode": mode, "sampleAllLayers": sample_all}));
|
||||
report_smart_result(app, r, tl!("Quick Selection found nothing there"));
|
||||
// Object Finder off: the click has nothing to select from, so it does nothing (#12864).
|
||||
return;
|
||||
}
|
||||
let r = app.run(
|
||||
@@ -838,6 +835,10 @@ mod remove_options_bar_labels_tests;
|
||||
#[path = "remove_pending_undo_tests.rs"]
|
||||
mod remove_pending_undo_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "object_selection_finder_off_tests.rs"]
|
||||
mod object_selection_finder_off_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "../smudge_bar_angle_tests.rs"]
|
||||
mod smudge_bar_angle_tests;
|
||||
|
||||
@@ -393,13 +393,14 @@ struct SelectionRow {
|
||||
#[test]
|
||||
fn selection_tools_send_their_bar_values() {
|
||||
let rows = [
|
||||
// A click cannot be a rectangle: it selects at the cursor instead of looking dead.
|
||||
// A click cannot be a rectangle: with Object Finder on it selects the object under the
|
||||
// cursor (#12864 removed the Quick Selection dab the click used when the option was off).
|
||||
SelectionRow {
|
||||
name: "Object Selection click without Object Finder",
|
||||
name: "Object Selection click with Object Finder",
|
||||
tool: Tool::ObjectSelection,
|
||||
setup: |app| app.ui.tool_options.object_finder = false,
|
||||
setup: |app| app.ui.tool_options.object_finder = true,
|
||||
points: &[[50.0, 30.0]],
|
||||
cmd: "select.quick",
|
||||
cmd: "select.object",
|
||||
want: json!({}),
|
||||
},
|
||||
SelectionRow {
|
||||
|
||||
Reference in new issue
Block a user