diff --git a/crates/algo/src/selection.rs b/crates/algo/src/selection.rs index 8493f2c1e8..f740687c1a 100644 --- a/crates/algo/src/selection.rs +++ b/crates/algo/src/selection.rs @@ -778,6 +778,8 @@ pub fn tone_range(px: &[[f32; 4]], lo: f32, hi: f32, falloff: f32) -> Vec { } mod distance; +#[cfg(test)] +mod ellipse_aa_edge_tests; mod inverse; mod lasso; mod marquee; diff --git a/crates/algo/src/selection/ellipse_aa_edge_tests.rs b/crates/algo/src/selection/ellipse_aa_edge_tests.rs new file mode 100644 index 0000000000..7b3e08cfa0 --- /dev/null +++ b/crates/algo/src/selection/ellipse_aa_edge_tests.rs @@ -0,0 +1,100 @@ +//! The Elliptical Marquee's anti-aliased edge against the reference measurement (#11391): +//! document 400 × 350, ellipse 100,100–300,250, the patch x 127–132, y 119–124 on the 45° part +//! of its top-left edge. Grids hold what a black fill of the selection reads there (255 outside, +//! 0 fully selected), as the issue's tables do. + +use photocraft_geom::Rect; +use photocraft_raster::Surface; + +use super::ellipse_surface; + +const AREA: Rect = Rect { x0: 0, y0: 0, x1: 400, y1: 350 }; +const ELLIPSE: Rect = Rect { x0: 100, y0: 100, x1: 300, y1: 250 }; +const PATCH: (i32, i32) = (127, 119); + +/// The reference with Anti-alias on. +const SOFT: [[u8; 6]; 6] = [ + [255, 255, 255, 255, 255, 152], + [255, 255, 255, 212, 106, 0], + [255, 255, 172, 64, 0, 0], + [247, 137, 26, 0, 0, 0], + [105, 0, 0, 0, 0, 0], + [0, 0, 0, 0, 0, 0], +]; + +/// Anti-alias off: the reference and PhotoCraft before #11391 agree. +const HARD: [[u8; 6]; 6] = + [[255, 255, 255, 255, 255, 255], [255, 255, 255, 255, 0, 0], [255, 255, 255, 0, 0, 0], [255, 255, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0]]; + +/// The grey a black fill of selection `s` gives at `(x, y)` on white. +fn grey(s: &Surface, x: i32, y: i32) -> u8 { + let v = s.pixel(x, y).first().copied().unwrap_or(0.0); + (255.0 - v * 255.0).round() as u8 +} + +fn patch(s: &Surface) -> [[u8; 6]; 6] { + std::array::from_fn(|j| std::array::from_fn(|i| grey(s, PATCH.0 + i as i32, PATCH.1 + j as i32))) +} + +#[test] +fn the_anti_aliased_patch_matches_the_reference_within_three_levels() { + let got = patch(&ellipse_surface(ELLIPSE, AREA, true)); + for (j, (row, want)) in got.iter().zip(&SOFT).enumerate() { + for (i, (g, w)) in row.iter().zip(want).enumerate() { + assert!(g.abs_diff(*w) <= 3, "{},{}: {g} vs reference {w}\n{got:?}", PATCH.0 + i as i32, PATCH.1 + j as i32); + } + } +} + +#[test] +fn the_other_three_quadrants_mirror_the_measured_one() { + let s = ellipse_surface(ELLIPSE, AREA, true); + // Symmetric about x = 200 and y = 175: pixel x mirrors to 399 - x, y to 349 - y. + for y in PATCH.1..PATCH.1 + 6 { + for x in PATCH.0..PATCH.0 + 6 { + let here = s.pixel(x, y); + assert_eq!(s.pixel(399 - x, y), here, "{x},{y} mirrored across x"); + assert_eq!(s.pixel(x, 349 - y), here, "{x},{y} mirrored across y"); + assert_eq!(s.pixel(399 - x, 349 - y), here, "{x},{y} mirrored through the centre"); + } + } + // A few partial pixels, so the mirror is not of 0s and 1s alone. + assert_eq!(grey(&s, 399 - 129, 122), grey(&s, 129, 122)); + assert!((1..255).contains(&grey(&s, 399 - 129, 349 - 121))); +} + +#[test] +fn the_hard_edge_is_unchanged() { + assert_eq!(patch(&ellipse_surface(ELLIPSE, AREA, false)), HARD); +} + +/// Fully inside reads exactly 1 and outside exactly 0, so Add / Subtract / Intersect combine as +/// before; the edge is soft only in a band at most √2 px wide. +#[test] +fn inside_is_exactly_selected_and_outside_exactly_empty() { + let s = ellipse_surface(ELLIPSE, AREA, true); + // Every pixel whose square lies inside, here all of the axes but the end pixels (whose + // corners poke out by a sliver). + for x in 101..299 { + assert_eq!(s.pixel(x, 175), vec![1.0], "{x},175 on the horizontal axis"); + } + for y in 101..249 { + assert_eq!(s.pixel(200, y), vec![1.0], "200,{y} on the vertical axis"); + } + for (x, y) in [(100, 175), (299, 175), (200, 100), (200, 249)] { + assert!(s.pixel(x, y)[0] > 0.99, "{x},{y}: the axis ends are all but full"); + } + for (x, y) in [(99, 175), (300, 175), (200, 99), (200, 250), (100, 100), (299, 249), (0, 0)] { + assert_eq!(s.pixel(x, y), vec![0.0], "{x},{y} outside"); + } + let partial = (0..350).flat_map(|y| (0..400).map(move |x| (x, y))).filter(|&(x, y)| (1..255).contains(&grey(&s, x, y))).count(); + let (hard_in, soft_in) = { + let h = ellipse_surface(ELLIPSE, AREA, false); + let sum = |s: &Surface| s.read_region(AREA).iter().map(|v| f64::from(*v)).sum::(); + (sum(&h), sum(&s)) + }; + // The perimeter (≈ 556 px) times a band 1 to √2 px across, and the hard ellipse's area. + assert!((556..787).contains(&partial), "{partial} partial pixels"); + let exact = std::f64::consts::PI * 100.0 * 75.0; + assert!((soft_in - exact).abs() < 0.002 * exact && (hard_in - exact).abs() < 0.002 * exact, "{soft_in} {hard_in} vs {exact}"); +} diff --git a/crates/algo/src/selection/marquee.rs b/crates/algo/src/selection/marquee.rs index 7afd788fdc..6afff4ab50 100644 --- a/crates/algo/src/selection/marquee.rs +++ b/crates/algo/src/selection/marquee.rs @@ -30,14 +30,22 @@ fn decode8(b: u8) -> f32 { } /// An ellipse inscribed in a rectangle, tested in `f32` exactly as the Elliptical Marquee -/// always has (so its anti-aliased edge keeps the same bytes). +/// always has (so its hard edge keeps the same bytes). struct Ellipse { cx: f32, cy: f32, rx: f32, ry: f32, + /// At most 3 px across: the anti-aliased edge keeps its 4×4 sub-samples (#11391 measured + /// only larger ellipses). + small: bool, + /// `1 / rx`, `1 / ry`, `1 / rx²` and `1 / ry²` for [`Ellipse::ramp`]. + inv: [f64; 4], } +/// The widest an ellipse is across and still [`Ellipse::small`]. +const SMALL: u32 = 3; + impl Ellipse { fn new(r: Rect) -> Self { Self { @@ -45,42 +53,82 @@ impl Ellipse { cy: (i64::from(r.y0) + i64::from(r.y1)) as f32 / 2.0, rx: r.width() as f32 / 2.0, ry: r.height() as f32 / 2.0, + small: r.width().min(r.height()) <= SMALL, + inv: { + let (rx, ry) = (f64::from(r.width()) / 2.0, f64::from(r.height()) / 2.0); + [1.0 / rx, 1.0 / ry, 1.0 / (rx * rx), 1.0 / (ry * ry)] + }, } } + /// The anti-aliased edge's coverage of pixel `(x, y)`, as Photoshop draws it (#11391): with + /// `F` the normalised radius at the pixel's centre, `(F - 1) / (|∂F/∂x| + |∂F/∂y|)` is the + /// centre's distance to the edge measured in the pixel's own width across the edge, and the + /// coverage ramps linearly over that width. An axis-aligned edge gets the pixel's exact + /// area; a 45° edge ramps over √2 px. 1 exactly at and around the centre. + #[inline] + fn ramp(&self, x: i32, y: i32) -> f64 { + let [irx, iry, irx2, iry2] = self.inv; + let (dx, dy) = (f64::from(x) + 0.5 - f64::from(self.cx), f64::from(y) + 0.5 - f64::from(self.cy)); + let (u, v) = (dx * irx, dy * iry); + let f = (u * u + v * v).sqrt(); + // `f · (|∂F/∂x| + |∂F/∂y|)`; 0 only at the centre itself. + let across = dx.abs() * irx2 + dy.abs() * iry2; + if across <= 0.0 { + return 1.0; + } + (0.5 - (f - 1.0) * f / across).clamp(0.0, 1.0) + } + #[inline] fn inside(&self, x: f32, y: f32) -> bool { let (dx, dy) = ((x - self.cx) / self.rx, (y - self.cy) / self.ry); dx * dx + dy * dy <= 1.0 } - /// Whether every point of pixel `(x, y)` that the coverage samples is inside: its four - /// corners (anti-aliased) or its centre. Along a row the pixels where this holds form one - /// run: each test is monotonic in the distance from the centre (IEEE rounding is monotonic). + /// Whether pixel `(x, y)` is fully selected: its centre is inside (hard edge), its four + /// corners are (a small anti-aliased ellipse), or its [`Ellipse::ramp`] is 1. Along a row + /// the pixels where this holds form one run: each test grows with the distance from the + /// centre; [`row_span`] checks both ends of the run. #[inline] fn full(&self, x: i32, y: i32, aa: bool) -> bool { let (fx, fy) = (x as f32, y as f32); if !aa { return self.inside(fx + 0.5, fy + 0.5); } - self.inside(fx, fy) && self.inside(fx + 1.0, fy) && self.inside(fx, fy + 1.0) && self.inside(fx + 1.0, fy + 1.0) + if self.small { + return self.inside(fx, fy) && self.inside(fx + 1.0, fy) && self.inside(fx, fy + 1.0) && self.inside(fx + 1.0, fy + 1.0); + } + self.ramp(x, y) >= 1.0 } - /// Coverage of pixel `(x, y)` in sixteenths: 16 when [`Ellipse::full`], else (anti-aliased) - /// the number of its 4×4 sub-samples inside. + /// The byte pixel `(x, y)` stores: `one` when [`Ellipse::full`], 0 outside a hard edge, and + /// otherwise the fraction of its 4×4 sub-samples inside (small) or its [`Ellipse::ramp`]. #[inline] - fn coverage(&self, x: i32, y: i32, aa: bool) -> u8 { + fn coverage(&self, x: i32, y: i32, aa: bool, enc: &[u8; 17]) -> u8 { + let one = enc[16]; + if aa && !self.small { + // One ramp: a full pixel's is 1, which encodes as `one`. + // `encode8`'s rounding, inline: this runs for every edge pixel. + return (self.ramp(x, y) as f32 * 255.0 + 0.5) as u8; + } if self.full(x, y, aa) { - return 16; + return one; } if !aa { return 0; } let (fx, fy) = (x as f32, y as f32); - (0..16u8).filter(|i| self.inside(fx + ((i % 4) as f32 + 0.5) / 4.0, fy + ((i / 4) as f32 + 0.5) / 4.0)).count() as u8 + let n = (0..16u8).filter(|i| self.inside(fx + ((i % 4) as f32 + 0.5) / 4.0, fy + ((i / 4) as f32 + 0.5) / 4.0)).count(); + enc.get(n).copied().unwrap_or(one) } } +/// The bytes for 0/16 … 16/16 coverage. +fn sixteenths() -> [u8; 17] { + std::array::from_fn(|n| encode8(n as f32 / 16.0)) +} + /// One row of the ellipse: nothing outside `lo..hi`, fully selected in `full_lo..full_hi`, and /// the edge pixels in between (`lo..full_lo`, `full_hi..hi`) need the exact coverage test. #[derive(Clone, Copy)] @@ -94,7 +142,7 @@ struct RowSpan { /// Bounds row `y` of `e` within `cut.x0..cut.x1` from the exact (f64) ellipse, widened by a /// margin that covers the f32 tests' rounding. The bounds are then checked with the exact tests /// (the fully selected run at both ends, nothing just outside); any doubt evaluates the whole row. -fn row_span(e: &Ellipse, y: i32, cut: Rect, aa: bool) -> RowSpan { +fn row_span(e: &Ellipse, y: i32, cut: Rect, aa: bool, enc: &[u8; 17]) -> RowSpan { let exact = RowSpan { lo: cut.x0, full_lo: cut.x1, full_hi: cut.x1, hi: cut.x1 }; let (cx, cy, rx, ry) = (f64::from(e.cx), f64::from(e.cy), f64::from(e.rx), f64::from(e.ry)); // Every point the tests sample in this row lies in `y..y + 1`. @@ -118,14 +166,15 @@ fn row_span(e: &Ellipse, y: i32, cut: Rect, aa: bool) -> RowSpan { if inner < 0.0 || full_lo >= full_hi { (full_lo, full_hi) = (hi, hi); } - let empty = |x: i32| e.coverage(x, y, aa) == 0; + let empty = |x: i32| e.coverage(x, y, aa, enc) == 0; let ok = (lo <= cut.x0 || empty(lo - 1)) && (hi >= cut.x1 || empty(hi)) && (full_lo >= full_hi || (e.full(full_lo, y, aa) && e.full(full_hi - 1, y, aa))); if ok { RowSpan { lo, full_lo, full_hi, hi } } else { exact } } /// The Elliptical Marquee's shape: the ellipse inscribed in `r`, cut to `clip`, as a GRAY8 -/// selection. Anti-aliased edge pixels hold the fraction of their 4×4 sub-samples inside; -/// without anti-aliasing a pixel is selected when its centre is inside. +/// selection. Anti-aliased edge pixels ramp across the edge as in Photoshop ([`Ellipse::ramp`]; +/// an ellipse at most 3 px across keeps the fraction of 4×4 sub-samples inside); without +/// anti-aliasing a pixel is selected when its centre is inside. pub fn ellipse_surface(r: Rect, clip: Rect, anti_alias: bool) -> Surface { let mut s = Surface::new(PixelFormat::GRAY8); let cut = r.intersect(&clip); @@ -133,9 +182,9 @@ pub fn ellipse_surface(r: Rect, clip: Rect, anti_alias: bool) -> Surface { return s; } let e = Ellipse::new(r); - let enc: [u8; 17] = std::array::from_fn(|n| encode8(n as f32 / 16.0)); + let enc = sixteenths(); let one = encode8(1.0); - let rows = par_map(cut.height() as usize, |i| row_span(&e, cut.y0 + i as i32, cut, anti_alias)); + let rows = par_map(cut.height() as usize, |i| row_span(&e, cut.y0 + i as i32, cut, anti_alias, &enc)); let span = |y: i32| rows.get(usize::try_from(y - cut.y0).ok()?); let full = s.solid_tile(&[1.0]); let blank = s.solid_tile(&[0.0]); @@ -159,11 +208,11 @@ pub fn ellipse_surface(r: Rect, clip: Rect, anti_alias: bool) -> Surface { d.fill(one); } for x in (sp.lo.max(tr.x0)..sp.full_lo.min(tr.x1)).chain(sp.full_hi.max(tr.x0)..sp.hi.min(tr.x1)) { - let n = e.coverage(x, y, anti_alias); + let n = e.coverage(x, y, anti_alias, &enc); if n > 0 && let Some(d) = tile.get_or_insert_with(|| Tile::clone(&blank)).bytes_mut().get_mut(at(x)) { - *d = enc.get(usize::from(n)).copied().unwrap_or(one); + *d = n; } } } @@ -302,7 +351,8 @@ pub fn combine_sparse(a: &Surface, b: &Surface, area: Rect, f: impl Fn(f32, f32) mod tests { use super::*; - /// The Elliptical Marquee as it was: every pixel tested and written one at a time. + /// The Elliptical Marquee one pixel at a time: every pixel tested and written on its own (the + /// anti-aliased ramp through [`Ellipse::ramp`]). fn old_ellipse(r: Rect, area: Rect, aa: bool) -> Surface { let cut = r.intersect(&area); let mut shape = Surface::new(PixelFormat::GRAY8); @@ -318,6 +368,8 @@ mod tests { let corners = [(fx, fy), (fx + 1.0, fy), (fx, fy + 1.0), (fx + 1.0, fy + 1.0)].iter().filter(|(a, b)| inside(*a, *b)).count(); let cov = if !aa { if inside(fx + 0.5, fy + 0.5) { 1.0 } else { 0.0 } + } else if r.width().min(r.height()) > SMALL { + Ellipse::new(r).ramp(x, y) as f32 } else if corners == 4 { 1.0 } else { diff --git a/crates/automation/src/workspace/tests.rs b/crates/automation/src/workspace/tests.rs index 252a687d7a..1750623eae 100644 --- a/crates/automation/src/workspace/tests.rs +++ b/crates/automation/src/workspace/tests.rs @@ -762,6 +762,8 @@ fn documents_filesystem_path_params(id: &str, params: &str) -> bool { | "layer.combineShapes.excludeOverlappingShapes" | "layer.combineShapes.mergeShapeComponents" | "layer.new.frame" + // `"stepName":"Transform Path"` names the History step, not a host file. + | "edit.transform" ) || id.starts_with("layer.newFillLayer.") || id.starts_with("layer.newAdjustmentLayer.") { diff --git a/crates/engine/src/cmd/artboard_cmds.rs b/crates/engine/src/cmd/artboard_cmds.rs index f9e31e4cd0..470971831a 100644 --- a/crates/engine/src/cmd/artboard_cmds.rs +++ b/crates/engine/src/cmd/artboard_cmds.rs @@ -289,10 +289,19 @@ fn new_artboard(s: &mut Session, p: &Value) -> Result { }; let background = background_param(p, cmd)?.unwrap_or_default(); let name = p.get("name").and_then(Value::as_str).filter(|n| !n.is_empty()).map(str::to_string); + let take_background = match p.get("takeBackground") { + None => false, + Some(v) => v.as_bool().ok_or_else(|| bad(cmd, "`takeBackground` must be true or false"))?, + }; let id = s.edit("New Artboard", |doc, active| { let mut g = Layer::group(name.unwrap_or_else(|| next_artboard_name(doc)), vec![]); set_artboard(&mut g, Artboard { rect, background, preset }); + // Only the first board takes the Background in (decided before the board exists). + let take = take_background && doc.artboards().is_empty() && doc.background().is_some(); let id = doc.insert_above(None, g); + if take { + move_background_into(doc, id); + } fit_canvas(doc); *active = Some(id); Ok(id) @@ -301,6 +310,19 @@ fn new_artboard(s: &mut Session, p: &Value) -> Result { Ok(json!({"layer": id.0, "rect": [rect.x0, rect.y0, rect.width(), rect.height()]})) } +/// Turns the Background into a normal layer ("Layer 0") and makes it the child of board `board`, +/// as the reference does when the first artboard is drawn. Does nothing without a Background. +fn move_background_into(doc: &mut Document, board: LayerId) { + let Some(bg) = doc.background().map(|l| l.id) else { return }; + let Some(mut layer) = doc.remove(bg) else { return }; + crate::extra_cmds::unlock_background(&mut layer); + match doc.layer_mut(board).and_then(Layer::children_mut) { + Some(children) => children.push(layer), + // Unreachable for a group; put the layer back rather than lose it. + None => doc.layers.insert(0, layer), + } +} + /// Convert a plain group at its content bounds; recorded guide IDs are ignored session metadata. fn artboard_from_group(s: &mut Session, p: &Value) -> Result { let cmd = "layer.new.artboardFromGroup"; @@ -705,7 +727,7 @@ pub fn specs() -> Vec { "layer.new.artboard", "Artboard…", &["Layer", "New"], - r##"{"rect":[x,y,w,h]? | "x","y","width","height"? (default: canvas size, right of the last board),"preset":"iPhone 14|Web 1920|A4|…"?,"name":str?,"background":"white|black|transparent|custom"="white","color":[r,g,b]|"#rrggbb"? (custom)} → {layer, rect}"##, + r##"{"rect":[x,y,w,h]? | "x","y","width","height"? (default: canvas size, right of the last board),"preset":"iPhone 14|Web 1920|A4|…"?,"name":str?,"background":"white|black|transparent|custom"="white","color":[r,g,b]|"#rrggbb"? (custom),"takeBackground":bool=false (the first board in the document also takes in the Background as a normal layer "Layer 0"; the Artboard tool's drag sets it)} → {layer, rect}"##, has_doc, new_artboard ), @@ -768,6 +790,9 @@ pub fn specs() -> Vec { ] } +#[cfg(test)] +#[path = "artboard_cmds/first_board_background_tests.rs"] +mod first_board_background_tests; #[cfg(test)] #[path = "artboard_cmds/tests.rs"] mod tests; diff --git a/crates/engine/src/cmd/artboard_cmds/first_board_background_tests.rs b/crates/engine/src/cmd/artboard_cmds/first_board_background_tests.rs new file mode 100644 index 0000000000..5d1f50206f --- /dev/null +++ b/crates/engine/src/cmd/artboard_cmds/first_board_background_tests.rs @@ -0,0 +1,127 @@ +//! The first drawn artboard takes the Background in as "Layer 0" (#11387): `takeBackground` on +//! `layer.new.artboard`, at 8, 16 and 32 bit, with the cases that keep today's result. + +use super::*; +use photocraft_geom::Rect; + +/// 800 x 600 with the white Background and a pixel layer "Red" at 100,100 to 300,250. +fn session(depth: u32) -> Session { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 800, "height": 600, "depth": depth, "background": "white"})).unwrap(); + s.edit("Red", |doc, active| { + let fmt = doc.pixel_format(); + let mut l = Layer::raster("Red", fmt); + l.surface_mut().unwrap().fill_rect(Rect { x0: 100, y0: 100, x1: 300, y1: 250 }, &photocraft_raster::from_rgba(&fmt, [1.0, 0.0, 0.0, 1.0])); + let id = doc.insert_above(None, l); + *active = Some(id); + Ok(id) + }) + .unwrap(); + s +} + +const WHITE: [f32; 4] = [1.0, 1.0, 1.0, 1.0]; + +fn doc(s: &Session) -> &Document { + &s.active().unwrap().doc +} + +fn names(layers: &[Layer]) -> Vec<&str> { + layers.iter().map(|l| l.name.as_str()).collect() +} + +fn steps(s: &Session) -> Vec { + s.active().unwrap().history.entries() +} + +fn draw(s: &mut Session, take: serde_json::Value) -> Result { + s.execute("layer.new.artboard", json!({"rect": [400, 300, 200, 200], "takeBackground": take})) +} + +#[test] +fn the_first_board_takes_the_background_in_as_layer_0() { + for depth in [8, 16, 32] { + let mut s = session(depth); + let before = steps(&s).len(); + let r = draw(&mut s, json!(true)).unwrap(); + let board = LayerId(r["layer"].as_u64().unwrap()); + let d = doc(&s); + assert_eq!(names(&d.layers), ["Red", "Artboard 1"], "{depth} bit"); + assert!(d.background().is_none(), "{depth} bit"); + let b = d.layer(board).unwrap(); + assert_eq!(r["rect"], json!([400, 300, 200, 200])); + let kids = b.children().unwrap(); + assert_eq!(names(kids), ["Layer 0"], "{depth} bit"); + let l0 = kids.first().unwrap(); + assert!(!l0.locks.transparency && !l0.locks.position, "{depth} bit"); + // The Background's own pixels travel with it: white at both samples, and Red still red. + assert_eq!(l0.surface().unwrap().rgba(150, 150), WHITE, "{depth} bit"); + assert_eq!(l0.surface().unwrap().rgba(700, 500), WHITE, "{depth} bit"); + let red = d.layers.first().unwrap(); + assert_eq!(red.surface().unwrap().rgba(150, 150), [1.0, 0.0, 0.0, 1.0], "{depth} bit"); + assert_eq!((d.size.width, d.size.height), (800, 600), "{depth} bit"); + assert_eq!(s.active().unwrap().active_layer, Some(board)); + let after = steps(&s); + assert_eq!(after.len(), before + 1, "one history step"); + assert_eq!(after.last().map(String::as_str), Some("New Artboard")); + // One undo brings the Background back at the bottom with its name and locks. + s.undo(); + let d = doc(&s); + assert_eq!(names(&d.layers), ["Background", "Red"], "{depth} bit"); + let bg = d.background().unwrap(); + assert!(bg.locks.transparency && bg.locks.position, "{depth} bit"); + assert_eq!(bg.surface().unwrap().rgba(150, 150), WHITE, "{depth} bit"); + assert_eq!(bg.surface().unwrap().rgba(700, 500), WHITE, "{depth} bit"); + assert!(d.artboards().is_empty()); + assert_eq!((d.size.width, d.size.height), (800, 600)); + } +} + +#[test] +fn without_the_param_or_with_false_the_background_stays_outside() { + for p in [json!({"rect": [400, 300, 200, 200]}), json!({"rect": [400, 300, 200, 200], "takeBackground": false})] { + let mut s = session(8); + s.execute("layer.new.artboard", p).unwrap(); + assert_eq!(names(&doc(&s).layers), ["Background", "Red", "Artboard 1"]); + assert!(doc(&s).background().is_some()); + } +} + +#[test] +fn with_a_board_already_present_the_result_is_as_today() { + let mut s = session(8); + s.execute("layer.new.artboard", json!({"rect": [0, 0, 100, 100]})).unwrap(); + draw(&mut s, json!(true)).unwrap(); + let d = doc(&s); + assert_eq!(names(&d.layers), ["Background", "Red", "Artboard 1", "Artboard 2"]); + assert!(d.background().is_some()); + assert!(d.artboards().iter().all(|b| b.1 != "Layer 0")); +} + +#[test] +fn without_a_background_the_result_is_as_today() { + let mut s = session(8); + s.execute("layer.new.layerFromBackground", json!({})).unwrap(); + assert!(doc(&s).background().is_none()); + draw(&mut s, json!(true)).unwrap(); + assert_eq!(names(&doc(&s).layers), ["Layer 0", "Red", "Artboard 1"]); + assert!(doc(&s).layers.last().unwrap().children().unwrap().is_empty()); +} + +#[test] +fn a_non_boolean_take_background_is_an_error_and_changes_nothing() { + for bad in [json!("true"), json!(1), json!([true])] { + let mut s = session(8); + let (n, count) = (steps(&s).len(), doc(&s).layers.len()); + assert!(draw(&mut s, bad.clone()).is_err(), "{bad}"); + assert_eq!(steps(&s).len(), n, "{bad}"); + assert_eq!(doc(&s).layers.len(), count, "{bad}"); + assert!(doc(&s).background().is_some(), "{bad}"); + } +} + +#[test] +fn the_param_is_listed_in_the_command_params_doc() { + let spec = specs().into_iter().find(|c| c.id == "layer.new.artboard").unwrap(); + assert!(spec.params.contains("takeBackground")); +} diff --git a/crates/engine/src/cmd/atn_cmds.rs b/crates/engine/src/cmd/atn_cmds.rs index 54d8b9995d..a51022dceb 100644 --- a/crates/engine/src/cmd/atn_cmds.rs +++ b/crates/engine/src/cmd/atn_cmds.rs @@ -48,13 +48,16 @@ mod steps_layer; mod steps_layer_style; mod steps_lookup; mod steps_make; +mod steps_perspective_warp; mod steps_type_path; mod steps_other; mod steps_render; mod steps_selection; mod steps_shape_blur; +mod steps_stack; mod steps_stylize; +mod steps_video; mod tables; #[cfg(test)] diff --git a/crates/engine/src/cmd/atn_cmds/convert.rs b/crates/engine/src/cmd/atn_cmds/convert.rs index 922c6125a6..8757b6ba04 100644 --- a/crates/engine/src/cmd/atn_cmds/convert.rs +++ b/crates/engine/src/cmd/atn_cmds/convert.rs @@ -77,6 +77,8 @@ fn convert_action(file: &AtnFile, a: &AtnAction, set: &str, unsupported: &mut Ve let (new_steps, enabled) = match mapped { Mapped::Steps(mut s) => { super::steps_gallery::remember_event(item, &mut s); + super::steps_stack::remember_item(item, &mut s); + super::steps_video::remember(item, &mut s); (s, item.enabled) } Mapped::Unsupported { harmless } => { @@ -165,7 +167,9 @@ pub(super) fn export_item(id: &str, params: &Value, set: &str) -> Option bool { + d.name.0.len() <= 1024 && d.items.len() == keys.len() && keys.iter().all(|key| d.items.iter().filter(|(id, _)| id.is(key)).count() == 1) +} + +fn coordinate(value: f64) -> bool { + value.abs() <= f64::from(WARP_REACH) +} + +fn rect_valid([left, top, right, bottom]: [f64; 4]) -> bool { + [left, top, right, bottom].into_iter().all(coordinate) && left < right && top < bottom +} + +fn reference_rect(d: &Descriptor) -> Option<[f64; 4]> { + let r = get_obj(d, "referenceRect")?; + if !r.class_id.is("Rctn") || !exact_keys(r, &["Top ", "Left", "Btom", "Rght"]) { + return None; + } + let number = |key| match r.get(key)? { + D::UnitFloat { unit: [b'#', b'P', b'x', b'l'], value } => Some(*value), + _ => None, + }; + let r = [number("Left")?, number("Top ")?, number("Rght")?, number("Btom")?]; + rect_valid(r).then_some(r) +} + +fn objects<'a>(d: &'a Descriptor, key: &str, class: &str, keys: &[&str], max: usize) -> Option<&'a [D]> { + let D::List(items) = d.get(key)? else { return None }; + (!items.is_empty() && items.len() <= max && items.iter().all(|item| matches!(item, D::Descriptor(d) if d.class_id.is(class) && exact_keys(d, keys)))) + .then_some(items) +} + +/// Each recorded index must link exactly the corners the native command would link. Edges +/// shared by two faces must have opposite winding, since the native map has one neighbour per edge. +fn same_topology(planes: &[Plane], indices: &[[usize; 4]], vertices: usize) -> Option<()> { + let at = |plane: usize, corner: usize| indices.get(plane)?.get(corner); + let mut linked = BTreeSet::new(); + for group in linked_corners(planes) { + let &(plane, corner) = group.first()?; + let index = at(plane, corner)?; + if !linked.insert(*index) || !group.iter().all(|&(p, c)| at(p, c) == Some(index)) { + return None; + } + } + let mut edges = BTreeSet::new(); + let distinct = indices.iter().all(|&[a, b, c, d]| [(a, b), (b, c), (c, d), (d, a)].into_iter().all(|edge| edges.insert(edge))); + (linked.len() == vertices && distinct).then_some(()) +} + +/// Decodes the recorded target and its document-space planes, retaining the reference rectangle +/// for export. Unmodelled references and geometry stay as kept steps. +fn parameters(d: &Descriptor) -> Option { + if !(d.class_id.is(EVENT) || d.class_id.is("null")) || !exact_keys(d, &["null", "Md ", "referenceRect", "vertices", "warpedVertices", "quads"]) { + return None; + } + if !matches!(d.get("Md ")?, D::Enumerated { type_id, value } if type_id.is("perspectiveWarpMode") && value.is("warp")) { + return None; + } + let target = get_ref(d, "null")?; + if target.len() != 1 || ref_class(target).as_deref() != Some("Lyr") { + return None; + } + match target.first()? { + ReferenceItem::Enumerated { type_id, value, .. } if type_id.is("Ordn") && value.is("Trgt") => {} + ReferenceItem::Name { name, .. } if name.0.len() <= 1024 && String::from_utf16(&name.0).is_ok() && !name.to_string_lossy().is_empty() => {} + ReferenceItem::Property { key, .. } if key.is("Bckg") => {} + _ => return None, + } + let mut p = layer_target(target)?; + let rect = reference_rect(d)?; + let src = objects(d, "vertices", "Pnt ", &["Hrzn", "Vrtc"], 4 * MAX_PLANES)?; + objects(d, "warpedVertices", "Pnt ", &["Hrzn", "Vrtc"], 4 * MAX_PLANES)?; + objects(d, "quads", "perspectiveWarpQuad", &["indices"], MAX_PLANES)?; + let (planes, indices) = perspective_warp_indexed_geometry(d)?; + if !planes.iter().all(|p| p.src.iter().chain(&p.dst).flatten().copied().all(coordinate) && convex_quad(&p.src) && convex_quad(&p.dst)) { + return None; + } + same_topology(&planes, &indices, src.len())?; + p.insert("planes".into(), json!(planes)); + p.insert("target".into(), json!("pixels")); + p.insert(RECT.into(), json!(rect)); + Some(Value::Object(p)) +} + +/// Keep the exact recorded descriptor after decoding its executable settings. +pub(super) fn from(d: &Descriptor) -> Mapped { + let mapped = || { + let mut p = parameters(d)?; + let bytes = d.to_bytes(); + if bytes.len() > MAX_DESCRIPTOR_BYTES { + return None; + } + p[SOURCE] = json!(crate::paint::tile::b64_encode(&bytes)); + Some(p) + }; + mapped().map_or(Mapped::Unsupported { harmless: false }, |p| step(PERSPECTIVE, p)) +} + +/// Emits the measured field order when the caller supplies the original reference rectangle. +fn canonical(p: &Value) -> Option { + let [left, top, right, bottom] = serde_json::from_value(p.get(RECT)?.clone()).ok()?; + if !rect_valid([left, top, right, bottom]) { + return None; + } + let planes = p.get("planes")?.as_array().filter(|planes| (1..=MAX_PLANES).contains(&planes.len()))?; + let planes: Vec = serde_json::from_value(Value::Array(planes.clone())).ok()?; + let rect = desc("Rctn").with("Top ", px(top)).with("Left", px(left)).with("Btom", px(bottom)).with("Rght", px(right)); + let (src, dst, quads) = perspective_warp_geometry(&planes); + Some( + desc(EVENT) + .with("null", layer_ref(p)?) + .with("Md ", enm("perspectiveWarpMode", "warp")) + .with("referenceRect", D::Descriptor(rect)) + .with("vertices", src) + .with("warpedVertices", dst) + .with("quads", quads), + ) +} + +/// Reuses source bytes only while they still describe the same target, rectangle and planes. +/// A changed recorded mesh cannot silently replace its indexed topology. +pub(super) fn to(_: &str, p: &Value) -> Option { + if !pixel_target(p) || !p.as_object()?.keys().all(|k| ["layer", "planes", "target", "interpolation", RECT, SOURCE].contains(&k.as_str())) { + return None; + } + if p.get("interpolation").is_some_and(|v| v.as_str() != Some("bicubic")) { + return None; + } + let descriptor = if let Some(source) = p.get(SOURCE) { + let text = source.as_str().filter(|v| v.len() <= MAX_DESCRIPTOR_BYTES * 2)?; + let bytes = crate::paint::tile::b64_decode(text)?; + if bytes.len() > MAX_DESCRIPTOR_BYTES { + return None; + } + Descriptor::from_bytes(&bytes).ok()? + } else { + canonical(p)? + }; + let mut expected = parameters(&descriptor)?; + let mut actual = p.clone(); + let m = actual.as_object_mut()?; + m.remove(SOURCE); + m.remove("interpolation"); + if m.get("layer").is_some_and(Value::is_null) { + m.remove("layer"); + } + m.insert("target".into(), json!("pixels")); + normalise(&mut actual); + normalise(&mut expected); + (actual == expected).then_some(descriptor) +} diff --git a/crates/engine/src/cmd/atn_cmds/steps_stack.rs b/crates/engine/src/cmd/atn_cmds/steps_stack.rs new file mode 100644 index 0000000000..9fcb9a6f9b --- /dev/null +++ b/crates/engine/src/cmd/atn_cmds/steps_stack.rs @@ -0,0 +1,128 @@ +//! Recorded Smart Object Stack Modes use the existing native mode commands. + +use photocraft_doc::StackMode; + +use super::descriptors::{class, desc, jstr, text}; +use super::fields::{Mapped, step}; +use super::{AtnItem, D, Descriptor, Value, json}; + +const PREFIX: &str = "layer.smartObjects.stackMode."; +const SOURCE: &str = "_atnStackDescriptor"; +pub(super) const NONE: &str = "layer.smartObjects.stackMode.none"; + +pub(super) const MODE_IDS: &[&str] = &[ + "layer.smartObjects.stackMode.range", + "layer.smartObjects.stackMode.entropy", + "layer.smartObjects.stackMode.kurtosis", + "layer.smartObjects.stackMode.maximum", + "layer.smartObjects.stackMode.median", + "layer.smartObjects.stackMode.minimum", + "layer.smartObjects.stackMode.mean", + "layer.smartObjects.stackMode.skewness", + "layer.smartObjects.stackMode.standardDeviation", + "layer.smartObjects.stackMode.summation", + "layer.smartObjects.stackMode.variance", +]; + +const MODES: &[(&str, StackMode)] = &[ + ("rang", StackMode::Range), + ("entr", StackMode::Entropy), + ("kurt", StackMode::Kurtosis), + ("maxx", StackMode::Maximum), + ("medn", StackMode::Median), + ("minn", StackMode::Minimum), + ("avrg", StackMode::Mean), + ("skew", StackMode::Skewness), + ("stdv", StackMode::StandardDeviation), + ("summ", StackMode::Summation), + ("vari", StackMode::Variance), +]; + +/// The plug-in class selects the mode; its localized display name does not. +fn recorded_mode(d: &Descriptor) -> Option<(&'static str, StackMode)> { + if d.items.len() != 2 { + return None; + } + let (Some(D::Class(plugin)), Some(D::Text(_))) = (d.get("imageStackPlugin"), d.get("Nm ")) else { return None }; + MODES.iter().copied().find(|(code, _)| plugin.class_id.is(code)) +} + +fn descriptor(code: &str, mode: StackMode) -> Descriptor { + desc("null").with("imageStackPlugin", D::Class(class(code))).with("Nm ", text(mode.label())) +} + +/// Keep descriptor names, key order, class encodings and original UTF-16 text on unchanged saves. +fn params(d: &Descriptor, canonical: &Descriptor) -> Value { + let mut p = json!({}); + if d != canonical { + p[SOURCE] = photocraft_paint::tile::b64_encode(&d.to_bytes()).into(); + } + p +} + +fn original(p: &Value) -> Option { + Descriptor::from_bytes(&photocraft_paint::tile::b64_decode(jstr(p, SOURCE)?)?).ok() +} + +/// The descriptorless form reaches the mapper as a default empty `null` descriptor. +fn is_none_descriptor(d: &Descriptor) -> bool { + d.items.is_empty() && d.class_id.is("null") +} + +/// Unknown mode classes, types, duplicate keys and extra settings stay complete kept steps. +pub(super) fn mode_from(d: &Descriptor) -> Mapped { + let Some((code, mode)) = recorded_mode(d) else { return Mapped::Unsupported { harmless: false } }; + step(&format!("{PREFIX}{}", mode.id()), params(d, &descriptor(code, mode))) +} + +/// The measured form targets the active Smart Object; explicit native targets refuse export. +pub(super) fn mode_to(id: &str, p: &Value) -> Option { + if p.as_object()?.keys().any(|key| key != SOURCE) { + return None; + } + let suffix = id.strip_prefix(PREFIX)?; + let (code, mode) = MODES.iter().copied().find(|(_, mode)| suffix == mode.id())?; + let canonical = descriptor(code, mode); + if p.get(SOURCE).is_none() { + return Some(canonical); + } + let source = original(p)?; + if is_none_descriptor(&source) { + return Some(canonical); + } + let (_, recorded) = recorded_mode(&source)?; + Some(if recorded == mode { source } else { canonical }) +} + +/// None has no recorded settings and removes the native Smart Object stack mode. +pub(super) fn none_from(d: &Descriptor) -> Mapped { + if is_none_descriptor(d) { step(NONE, json!({})) } else { Mapped::Unsupported { harmless: false } } +} + +pub(super) fn none_to(_: &str, p: &Value) -> Option { + if p.as_object()?.keys().any(|key| key != SOURCE) { + return None; + } + if p.get(SOURCE).is_none() { + return Some(desc("null")); + } + let source = original(p)?; + if is_none_descriptor(&source) { + return Some(source); + } + recorded_mode(&source).map(|_| desc("null")) +} + +/// Import otherwise presents an absent descriptor as an empty one. Retain the distinction for None. +pub(super) fn remember_item(item: &AtnItem, steps: &mut [(String, Value)]) { + if let [(id, Value::Object(p))] = steps + && id.as_str() == NONE + && let Some(d) = &item.descriptor + { + p.insert(SOURCE.into(), photocraft_paint::tile::b64_encode(&d.to_bytes()).into()); + } +} + +pub(super) fn without_descriptor(id: &str, p: &Value) -> bool { + id == NONE && p.get(SOURCE).is_none() +} diff --git a/crates/engine/src/cmd/atn_cmds/steps_video.rs b/crates/engine/src/cmd/atn_cmds/steps_video.rs new file mode 100644 index 0000000000..af3158a978 --- /dev/null +++ b/crates/engine/src/cmd/atn_cmds/steps_video.rs @@ -0,0 +1,41 @@ +//! The three measured, option-free edits of the active video layer's current frame. +use super::{ + AtnItem, Descriptor, Value, + fields::{Mapped, step}, + json, +}; + +const NO_DESCRIPTOR: &str = "_atnVideoFrameNoDescriptor"; + +/// These events edit video footage, separately from document frame animation. +fn frame_command(id: &str) -> bool { + matches!(id, "layer.videoLayers.insertBlankFrame" | "layer.videoLayers.duplicateFrame" | "layer.videoLayers.deleteFrame") +} + +/// Only the measured empty descriptor is executable; extra settings remain kept. +pub(super) fn from(d: &Descriptor, id: &str) -> Mapped { + if *d == Descriptor::default() { step(id, json!({})) } else { Mapped::Unsupported { harmless: false } } +} + +/// Import's absent-descriptor placeholder must not become a descriptor on save. +pub(super) fn remember(item: &AtnItem, steps: &mut [(String, Value)]) { + if item.descriptor.is_none() { + for (id, params) in steps { + if frame_command(id) + && let Some(params) = params.as_object_mut() + { + params.insert(NO_DESCRIPTOR.into(), Value::Bool(true)); + } + } + } +} + +/// Refuse native options and malformed transport data that have no wire field. +pub(super) fn to(p: &Value) -> Option { + p.as_object()?.iter().all(|(key, value)| key == NO_DESCRIPTOR && value == &Value::Bool(true)).then(Descriptor::default) +} + +/// Called only after `to` has validated the complete native parameter object. +pub(super) fn omitted(id: &str, p: &Value) -> bool { + frame_command(id) && p.get(NO_DESCRIPTOR) == Some(&Value::Bool(true)) +} diff --git a/crates/engine/src/cmd/atn_cmds/tests.rs b/crates/engine/src/cmd/atn_cmds/tests.rs index b7c3764346..a65404324f 100644 --- a/crates/engine/src/cmd/atn_cmds/tests.rs +++ b/crates/engine/src/cmd/atn_cmds/tests.rs @@ -658,6 +658,11 @@ fn settings_at_the_value_the_event_plays_still_export() { /// Each mapped command retains its parameters through its corresponding ATN descriptor. fn every_mapped_command_exports_and_imports_back() { let cases: Vec<(&str, Value)> = vec![ + ( + "edit.perspectiveWarp", + json!({"planes":[{"src":[[4,4],[16,4],[16,20],[4,20]],"dst":[[5,5],[17,4],[18,20],[4,19]]}], + "target":"pixels","__atnPerspectiveWarpRect":[0,0,32,24]}), + ), ( "paint.gradient", json!({"from":[1,1],"to":[6,2],"style":"linear","method":"classic","smoothness":100, @@ -680,6 +685,18 @@ fn every_mapped_command_exports_and_imports_back() { ), ("edit.fade", json!({"opacity":50,"mode":"Multiply"})), ("layer.linkLayers", json!({})), + ("layer.smartObjects.stackMode.range", json!({})), + ("layer.smartObjects.stackMode.entropy", json!({})), + ("layer.smartObjects.stackMode.kurtosis", json!({})), + ("layer.smartObjects.stackMode.maximum", json!({})), + ("layer.smartObjects.stackMode.median", json!({})), + ("layer.smartObjects.stackMode.minimum", json!({})), + ("layer.smartObjects.stackMode.mean", json!({})), + ("layer.smartObjects.stackMode.skewness", json!({})), + ("layer.smartObjects.stackMode.standardDeviation", json!({})), + ("layer.smartObjects.stackMode.summation", json!({})), + ("layer.smartObjects.stackMode.variance", json!({})), + ("layer.smartObjects.stackMode.none", json!({})), ("layer.distribute.leftEdges", json!({})), ("layer.distribute.horizontalCenters", json!({})), ("layer.distribute.rightEdges", json!({})), @@ -826,6 +843,9 @@ fn every_mapped_command_exports_and_imports_back() { ("type.loadDefaultTypeStyles", json!({})), ("type.saveDefaultTypeStyles", json!({})), ("image.analysis.recordMeasurements", json!({})), + ("layer.videoLayers.insertBlankFrame", json!({})), + ("layer.videoLayers.duplicateFrame", json!({})), + ("layer.videoLayers.deleteFrame", json!({})), ("file.automate.cropAndStraightenPhotos", json!({})), ("file.automate.cropAndStraightenPhotos", json!({"_atnNoTarget": true})), ("layer.new.artboardFromGroup", json!({})), @@ -1054,7 +1074,9 @@ fn every_mapped_command_exports_and_imports_back() { continue; } let e = event_for(&item.event).unwrap_or_else(|| panic!("{id} exported as an unknown event {}", item.event.id())); - match (e.from)(item.descriptor.as_ref().unwrap()) { + assert_eq!(item.descriptor.is_none(), *id == super::steps_stack::NONE, "{id}: unexpected descriptor presence"); + let descriptor = item.descriptor.unwrap_or_default(); + match (e.from)(&descriptor) { Mapped::Steps(steps) => { assert_eq!(steps.len(), 1, "{id}: {steps:?}"); let navigation = match *id { @@ -1080,6 +1102,9 @@ fn every_mapped_command_exports_and_imports_back() { // Executable values match; independent public tests verify the source carrier. back.as_object_mut().unwrap().remove("__atnClassicGradient"); } + if *id == "edit.perspectiveWarp" { + back.as_object_mut().unwrap().remove("__atnPerspectiveWarp"); + } normalise(&mut back); if *id == "actions.play" || *id == "actions.conditional" { back["set"] = json!("S"); diff --git a/crates/engine/src/cmd/distort_cmds.rs b/crates/engine/src/cmd/distort_cmds.rs index 156095288f..7d820f0620 100644 --- a/crates/engine/src/cmd/distort_cmds.rs +++ b/crates/engine/src/cmd/distort_cmds.rs @@ -407,7 +407,7 @@ pub fn specs() -> Vec { CommandSpec { id: PUPPET_SMART, label: "Puppet Warp", - menu: &["Layer", "Smart Objects"], + menu: &[], shortcut: None, params: P, enabled: smart_layer, @@ -427,7 +427,7 @@ pub fn specs() -> Vec { CommandSpec { id: PERSPECTIVE_SMART, label: "Perspective Warp", - menu: &["Layer", "Smart Objects"], + menu: &[], shortcut: None, params: Q, enabled: smart_layer, diff --git a/crates/engine/src/cmd/fill_cmds.rs b/crates/engine/src/cmd/fill_cmds.rs index 88bbafe878..e6f7e77b9d 100644 --- a/crates/engine/src/cmd/fill_cmds.rs +++ b/crates/engine/src/cmd/fill_cmds.rs @@ -279,7 +279,7 @@ fn content_aware_native_with_options( let window = sampling_window(hole_bounds, canvas); let n = surf.format().channels(); let (w, h) = window_size(window)?; - let img = surf.read_region(window); + let img = crate::allocation::read_region(surf, window, "Content-Aware fill samples")?; let len = w.checked_mul(h).ok_or_else(|| EngineError::Other("the area is too large for Content-Aware fill".into()))?; let mut hole = crate::allocation::filled(len, false, "Content-Aware fill")?; let mut source = crate::allocation::filled(len, false, "Content-Aware fill")?; diff --git a/crates/engine/src/cmd/float_cmds.rs b/crates/engine/src/cmd/float_cmds.rs index bb93f233cb..0700fb30c8 100644 --- a/crates/engine/src/cmd/float_cmds.rs +++ b/crates/engine/src/cmd/float_cmds.rs @@ -243,6 +243,8 @@ pub struct Floating { /// The piece has been moved at least once, even if it is back where it was cut (nudged away /// and back): its selection is the moved pixels' then, as each of Photoshop's nudges leaves it. pub moved: bool, + /// History step name when dropped; `None` is "Move". The Move tool names a ⌥-drag copy "Duplicate". + pub step_name: Option, } /// The floating piece of `st`, if it is still valid (the document hasn't changed under it). @@ -289,12 +291,14 @@ pub fn locked_for_float(doc: &Document, l: &photocraft_doc::Layer) -> bool { fn float(s: &mut Session, p: &Value) -> Result { let (dx, dy) = (int_param(p, "dx"), int_param(p, "dy")); let copy = p.get("copy").and_then(Value::as_bool).unwrap_or(false); + // A name for the History step that drops the piece: short and not blank, else the default. + let step_name = p.get("stepName").and_then(Value::as_str).map(str::trim).filter(|s| !s.is_empty() && s.chars().count() <= 64).map(str::to_string); let background = s.tools.background; let st = s.active_mut().ok_or(EngineError::NoDocument)?; if floating(st).is_none() { let layer = st.active_layer.ok_or_else(|| EngineError::Other("no active layer".into()))?; let parts = CutParts::new(&st.doc, layer, copy, background, crate::channel_cmds::target_of(p) == crate::channel_cmds::Target::Mask)?; - st.floating = Some(Floating { layer, offset: (0, 0), revision: st.revision, parts: Arc::new(parts), moved: false }); + st.floating = Some(Floating { layer, offset: (0, 0), revision: st.revision, parts: Arc::new(parts), moved: false, step_name }); } let f = st.floating.as_mut().ok_or(EngineError::NoDocument)?; f.offset = (f.offset.0.saturating_add(dx), f.offset.1.saturating_add(dy)); @@ -311,20 +315,21 @@ pub fn drop_floating(s: &mut Session) -> Result { return Ok(json!({"dropped": false})); }; st.floating = None; + let name = f.step_name.clone().unwrap_or_else(|| "Move".to_string()); let (dx, dy) = f.offset; if (dx, dy) == (0, 0) { // Back where it was cut: the pixels are as they were. A piece that never moved (a click) // changes nothing; one nudged away and back keeps the moved pixels' selection (#7538). if let Some(outline) = f.parts.outline().filter(|_| f.moved) { let outline = outline.clone(); - s.edit("Move", |doc, _| { + s.edit(&name, |doc, _| { doc.selection = Some(outline); Ok(()) })?; } return Ok(json!({"dropped": true, "offset": [0, 0]})); } - s.edit("Move", |doc, _| { + s.edit(&name, |doc, _| { f.parts.place(doc, dx, dy)?; let sel = f.parts.outline().or(doc.selection.as_ref()); doc.selection = sel.map(|sel| photocraft_algo::resample::translate_surface(sel, dx, dy)); @@ -374,7 +379,7 @@ pub fn specs() -> Vec { label: "Float Selection", menu: &[], shortcut: None, - params: r##"{"dx":px=0,"dy":px=0,"copy":bool=false,"target":"pixels"|"mask"="pixels" (mask: float the selected part of the layer's mask, the hole takes the background colour)} → {layer, offset} (cuts the selected pixels of the active layer into a floating piece the first time, or with copy leaves them and floats a duplicate; on the Background the hole takes the background colour; then moves it by whole pixels; dropped by select.drop or any other command, put back by edit.undo)"##, + params: r##"{"dx":px=0,"dy":px=0,"copy":bool=false,"stepName":string="Move" (History name of the step that drops the piece; blank or over 64 characters falls back to Move),"target":"pixels"|"mask"="pixels" (mask: float the selected part of the layer's mask, the hole takes the background colour)} → {layer, offset} (cuts the selected pixels of the active layer into a floating piece the first time, or with copy leaves them and floats a duplicate; on the Background the hole takes the background colour; then moves it by whole pixels; dropped by select.drop or any other command, put back by edit.undo)"##, enabled: can_float, journal: true, run: float, diff --git a/crates/engine/src/cmd/image_cmds.rs b/crates/engine/src/cmd/image_cmds.rs index ffe55a995c..60c7587207 100644 --- a/crates/engine/src/cmd/image_cmds.rs +++ b/crates/engine/src/cmd/image_cmds.rs @@ -798,6 +798,7 @@ fn crop_with(s: &mut Session, p: &Value, keep_background: bool) -> Result // Only the Crop tool's frame (an explicit rectangle) resizes a canvas-sized artboard; a // selection crop leaves boards as they are. let tool_frame = explicit.is_some(); + let mut filled = false; s.edit("Crop", |doc, active| { let original = doc.size; let board = if tool_frame { canvas_artboard(doc) } else { None }; @@ -809,11 +810,14 @@ fn crop_with(s: &mut Session, p: &Value, keep_background: bool) -> Result // A straight crop fills all of the area past the old canvas, pixels an earlier Delete Cropped // Pixels off crop hid there included, as Photoshop does; only a turned frame keeps them (#8060). if content_aware { - crate::crop_fill::fill_uncovered(doc, *active, &crate::crop_fill::Coverage::crop(r, original.width, original.height))?; + filled = crate::crop_fill::fill_uncovered(doc, *active, &crate::crop_fill::Coverage::crop(r, original.width, original.height), delete)?; } doc.selection = None; target.apply(doc) })?; + if filled && let Some(st) = s.active_mut() { + st.history.set_current_label("Content-aware Crop"); + } Ok(crop_result(s, json!({ "x": r.x0, "y": r.y0, "width": r.width(), "height": r.height() }))) } @@ -981,6 +985,7 @@ fn rotated_crop(s: &mut Session, r: Rect, angle: f64, delete: bool, content_awar }; // The canvas board, found before the turn, fits the frame as in a straight crop. let board = s.active().and_then(|d| canvas_artboard(&d.doc)); + let mut filled = false; crate::analysis_cmds::compound(s, "Crop", |s| { // Pixels the crop deletes needn't be turned first: keeping only what lands in the frame // makes the rotation cost the frame's size, not the canvas's (a small turned crop of a @@ -1018,12 +1023,15 @@ fn rotated_crop(s: &mut Session, r: Rect, angle: f64, delete: bool, content_awar crop_doc(doc, CMD, target, delete, extension)?; fit_canvas_artboard(doc, board); if content_aware { - crate::crop_fill::fill_uncovered(doc, *active, &coverage)?; + filled = crate::crop_fill::fill_uncovered(doc, *active, &coverage, delete)?; } doc.selection = None; crop_target.apply(doc) }) })?; + if filled && let Some(st) = s.active_mut() { + st.history.set_current_label("Content-aware Crop"); + } Ok(crop_result(s, json!({ "x": r.x0, "y": r.y0, "width": r.width(), "height": r.height(), "angle": angle }))) } @@ -1192,7 +1200,7 @@ pub fn specs() -> Vec { "image.crop", "Crop", ["Image"], - r##"{"x":px,"y":px,"width":px,"height":px,"angle":-3600..3600=0,"deleteCroppedPixels":bool=true,"contentAware":bool=false,"targetWidth":px,"targetHeight":px,"resolution":ppi,"resample":"bicubic|bilinear|nearest|lanczos|preserveDetails"="bicubic"} → {x,y,width,height,documentWidth,documentHeight,resolution} (targetWidth/targetHeight, both or neither: the cropped area is resampled to exactly that size, as Image Size, in the same undo step; resolution: the document's new ppi; deleteCroppedPixels false: the pixels past the frame are kept and, unless contentAware, the Background becomes a normal layer, "Layer 0", so an extension is transparent on every layer (with contentAware the Background stays); contentAware: the Crop tool's Fill › Content-Aware Fill, the area a rotated or extending crop uncovers filled from its surroundings on the Background, else the active pixel layer)"##, + r##"{"x":px,"y":px,"width":px,"height":px,"angle":-3600..3600=0,"deleteCroppedPixels":bool=true,"contentAware":bool=false,"targetWidth":px,"targetHeight":px,"resolution":ppi,"resample":"bicubic|bilinear|nearest|lanczos|preserveDetails"="bicubic"} → {x,y,width,height,documentWidth,documentHeight,resolution} (targetWidth/targetHeight, both or neither: the cropped area is resampled to exactly that size, as Image Size, in the same undo step; resolution: the document's new ppi; deleteCroppedPixels false: the pixels past the frame are kept and, unless contentAware, the Background becomes a normal layer, "Layer 0", so an extension is transparent on every layer (with contentAware the Background stays); contentAware: the Crop tool's Fill › Content-Aware Fill uses surrounding pixels to fill areas uncovered by a rotated or extending crop. The fill targets the Background, or the active pixel layer if there is no Background. With Delete Cropped Pixels on, it also targets a separate active pixel layer if it is visible and unlocked.)"##, has_doc, crop ), diff --git a/crates/engine/src/cmd/layer_multi_cmds.rs b/crates/engine/src/cmd/layer_multi_cmds.rs index f85423c048..4ca3074b13 100644 --- a/crates/engine/src/cmd/layer_multi_cmds.rs +++ b/crates/engine/src/cmd/layer_multi_cmds.rs @@ -158,7 +158,7 @@ pub fn specs() -> Vec { "layer.lockLayers", "Lock Layers…", &["Layer"], - None, + Some("Cmd+/"), r##"{"transparency":bool?,"pixels":bool?,"position":bool?,"artboard":bool?,"all":bool?} (none given: toggle lock all)"##, has_layer, lock_layers diff --git a/crates/engine/src/cmd/select_extra_cmds.rs b/crates/engine/src/cmd/select_extra_cmds.rs index 55e2ec10d9..9fd0d65356 100644 --- a/crates/engine/src/cmd/select_extra_cmds.rs +++ b/crates/engine/src/cmd/select_extra_cmds.rs @@ -163,6 +163,11 @@ fn affine_params(cmd: &str, p: &Value, r: [f64; 4]) -> Result { /// scale/rotate/move, refused when the result would not fit the transform budget. fn transform_selection(s: &mut Session, p: &Value) -> Result { const CMD: &str = "select.transformSelection"; + let step_name = match p.get("stepName") { + None | Some(Value::Null) => "Transform Selection", + Some(Value::String(n)) if n == "Move Selection" => "Move Selection", + Some(_) => return Err(bad(CMD, "`stepName` must be \"Move Selection\"")), + }; let d = s.active().ok_or(EngineError::NoDocument)?; let sel = d.doc.selection.as_ref().ok_or_else(|| EngineError::Other("no selection".into()))?; let b = sel.content_bounds(); @@ -206,7 +211,7 @@ fn transform_selection(s: &mut Session, p: &Value) -> Result { if h.0.iter().zip(Homography::IDENTITY.0).all(|(a, b)| (a - b).abs() < 1e-12) { return Ok(json!({"changed": false, "selected": true})); } - let selected = s.edit("Transform Selection", |doc, _| { + let selected = s.edit(step_name, |doc, _| { if let Some(sel) = &doc.selection { crate::transform_cmds::check_budget(sel.content_bounds(), &h, "selection", sel.format())?; doc.selection = Some(crate::transform_cmds::warp_gray(sel, &h, interp)?).filter(|s| !s.content_bounds().is_empty()); @@ -250,7 +255,7 @@ pub fn specs() -> Vec { label: "Transform Selection", menu: &["Select"], shortcut: None, - params: r##"{"rect":[x0,y0,x1,y1]? (frame; default = selection bounds),"quad"|"corners":[[x,y]×4]? (where the frame's corners go: distort/perspective),"matrix":[a,b,c,d,e,f]?,"scaleX":%=100,"scaleY":%=100,"rotate":deg=0,"skewX":deg=0,"skewY":deg=0,"dx":px=0,"dy":px=0,"reference":"center|topLeft|top|topRight|left|right|bottomLeft|bottom|bottomRight"|[x,y]="center","style"|"mesh"|"grid"|"warp":… (warp, as edit.transform.warp),"interpolation":"bilinear|bicubic|nearest|bicubicSharper|bicubicSmoother|bicubicAutomatic"="bilinear" (Photoshop's bicubic variants render as Bicubic)}"##, + params: r##"{"rect":[x0,y0,x1,y1]? (frame; default = selection bounds),"quad"|"corners":[[x,y]×4]? (where the frame's corners go: distort/perspective),"matrix":[a,b,c,d,e,f]?,"scaleX":%=100,"scaleY":%=100,"rotate":deg=0,"skewX":deg=0,"skewY":deg=0,"dx":px=0,"dy":px=0,"stepName":"Move Selection"? (History step name for a plain move; the UI sends it for a drag of the outline; default "Transform Selection"; any other value is refused),"reference":"center|topLeft|top|topRight|left|right|bottomLeft|bottom|bottomRight"|[x,y]="center","style"|"mesh"|"grid"|"warp":… (warp, as edit.transform.warp),"interpolation":"bilinear|bicubic|nearest|bicubicSharper|bicubicSmoother|bicubicAutomatic"="bilinear" (Photoshop's bicubic variants render as Bicubic)}"##, enabled: has_selection, run: transform_selection, journal: true, @@ -422,6 +427,23 @@ mod tests { assert!(s.execute("select.transformSelection", json!({"scaleX": 0})).is_err()); } + #[test] + fn transform_selection_step_name_is_restricted() { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 60, "height": 40})).unwrap(); + s.execute("select.rect", json!({"x": 10, "y": 10, "width": 20, "height": 20})).unwrap(); + let last = |s: &Session| s.active().unwrap().history.entries().last().cloned().unwrap(); + s.execute("select.transformSelection", json!({"dx": 5, "dy": 0})).unwrap(); + assert_eq!(last(&s), "Transform Selection"); + s.execute("select.transformSelection", json!({"dx": 5, "dy": 0, "stepName": "Move Selection"})).unwrap(); + assert_eq!(last(&s), "Move Selection"); + let n = s.active().unwrap().history.past_len(); + for bad_name in [json!("Crop"), json!(""), json!(7)] { + assert!(s.execute("select.transformSelection", json!({"dx": 5, "dy": 0, "stepName": bad_name})).is_err()); + } + assert_eq!(s.active().unwrap().history.past_len(), n); + } + #[test] fn transform_selection_needs_a_selection() { let mut s = Session::new(); diff --git a/crates/engine/src/cmd/selection_cmds.rs b/crates/engine/src/cmd/selection_cmds.rs index 927beba121..13737e70bd 100644 --- a/crates/engine/src/cmd/selection_cmds.rs +++ b/crates/engine/src/cmd/selection_cmds.rs @@ -621,7 +621,9 @@ fn lasso(s: &mut Session, p: &Value) -> Result { if pts.len() < 3 { return Err(EngineError::BadParams { cmd: "select.lasso".into(), msg: "needs at least 3 points".into() }); } - polygon_selection(s, "select.lasso", "Lasso", &pts, p) + // The History step is named after the tool: the Polygonal Lasso sends `polygonal` (Photoshop). + let step = if b(p, "polygonal", false) { "Polygonal Lasso" } else { "Lasso" }; + polygon_selection(s, "select.lasso", step, &pts, p) } /// Selects the polygon `pts` with the lasso tools' `mode`, `antiAlias` and `feather` params, as @@ -754,7 +756,7 @@ pub fn specs() -> Vec { "select.lasso", "Lasso", [], - r##"{"points":[[x,y],…],"mode":"replace|add|subtract|intersect"="replace","antiAlias":bool=true,"feather":px=0}"##, + r##"{"points":[[x,y],…],"mode":"replace|add|subtract|intersect"="replace","antiAlias":bool=true,"feather":px=0,"polygonal":bool=false}"##, has_doc, lasso ), diff --git a/crates/engine/src/cmd/smart_cmds.rs b/crates/engine/src/cmd/smart_cmds.rs index fd9234fc3e..a79927652c 100644 --- a/crates/engine/src/cmd/smart_cmds.rs +++ b/crates/engine/src/cmd/smart_cmds.rs @@ -101,6 +101,48 @@ fn has_linked(s: &Session) -> std::result::Result<(), String> { _ => Err("the smart object is embedded".into()), } } +fn linked_layers(doc: &Document) -> Vec { + doc.walk() + .into_iter() + .filter(|(_, _, l)| matches!(&l.content, LayerContent::Smart(sm) if matches!(sm.source, SmartSource::Linked { .. }))) + .map(|(_, _, l)| l.id) + .collect() +} +fn has_any_linked(s: &Session) -> std::result::Result<(), String> { + let d = s.active().ok_or("no document open")?; + if linked_layers(&d.doc).is_empty() { Err("the document has no linked smart object".into()) } else { Ok(()) } +} +/// Embed All Linked: reads every linked file first, so a missing one refuses the whole step. +fn embed_all_linked(s: &mut Session, _p: &Value) -> Result { + let doc = &s.active().ok_or(EngineError::NoDocument)?.doc; + let ids = linked_layers(doc); + if ids.is_empty() { + return Err(other("the document has no linked smart object")); + } + let mut sources = Vec::with_capacity(ids.len()); + for id in &ids { + let src = &smart(doc, *id)?.source; + let (file_name, bytes) = source_bytes(&doc.metadata, src).ok_or_else(|| { + let path = match src { + SmartSource::Linked { path } => path.as_str(), + SmartSource::Embedded { .. } => "", + }; + other(format!("the linked file can't be read: {path}")) + })?; + sources.push(SmartSource::Embedded { file_name, bytes }); + } + let parent = doc.id; + let contents: Vec = ids.iter().map(|id| smart(doc, *id).map(|sm| sm.contents_id)).collect::>()?; + s.edit("Embed All Linked", |doc, _| { + for (id, src) in ids.iter().zip(sources) { + smart_mut(doc, *id)?.source = src; + refresh_or_fail(doc, *id)?; + } + Ok(()) + })?; + s.smart_links.retain(|l| l.parent != parent || !contents.contains(&l.contents_id)); + Ok(json!({"embedded": ids.iter().map(|l| l.0).collect::>()})) +} fn has_doc(s: &Session) -> std::result::Result<(), String> { s.active().map(|_| ()).ok_or_else(|| "no document open".into()) } @@ -146,7 +188,6 @@ mod source; pub(crate) use contents::on_close; pub use contents::{commit_child, contents_of, replace_contents_bytes, replace_contents_from_bytes}; use contents::{edit_contents, export_contents, is_smart_child, path_param, replace_contents, set_source, update_all}; -#[cfg(test)] use filters::smart_mut; pub(crate) use filters::{add_smart_filter, add_smart_filter_in, filter_mask_paintable, filter_mask_surface, refresh_after_filter_mask_edit}; use filters::{blending_options, delete_filter, edit_filters, move_filter, set_filter_params, set_filter_visible, smart, transfer_filters}; @@ -244,12 +285,20 @@ pub fn specs() -> Vec { has_smart, unpack::convert_to_layers ), - spec!("layer.smartObjects.convertToEmbedded", "Convert to Embedded", SO, r##"{"layer":id?}"##, has_linked, |s, p| { + spec!("layer.smartObjects.convertToEmbedded", "Embed Linked", SO, r##"{"layer":id?}"##, has_linked, |s, p| { set_source(s, p, "Convert to Embedded", true, |meta, src| { let (file_name, bytes) = source_bytes(meta, src).ok_or_else(|| other("the linked file can't be read"))?; Ok(SmartSource::Embedded { file_name, bytes }) }) }), + spec!( + "layer.smartObjects.embedAllLinked", + "Embed All Linked", + SO, + "{} (every linked smart object of the active document becomes embedded in one history step; a linked file that can't be read refuses the whole step and the error names it) -> {embedded: [layer ids]}", + has_any_linked, + embed_all_linked + ), spec!( "layer.smartObjects.convertToLinked", "Convert to Linked…", diff --git a/crates/engine/src/cmd/transform_cmds.rs b/crates/engine/src/cmd/transform_cmds.rs index 211c64668f..f0d7150567 100644 --- a/crates/engine/src/cmd/transform_cmds.rs +++ b/crates/engine/src/cmd/transform_cmds.rs @@ -17,6 +17,9 @@ fn has_layer(s: &Session) -> std::result::Result<(), String> { s.active().and_then(|d| d.active_layer).map(|_| ()).ok_or_else(|| "no active layer".into()) } +/// The History step name of a shape-tool bounding box scale (`edit.transform` `stepName`). +pub const TRANSFORM_PATH: &str = "Transform Path"; + fn bad(msg: impl Into) -> EngineError { EngineError::BadParams { cmd: "edit.transform".into(), msg: msg.into() } } @@ -841,6 +844,13 @@ fn with_panel_target(s: &Session, p: &Value) -> Value { } fn transform(s: &mut Session, p: &Value) -> Result { + // The shape tools' bounding box scales live shapes with this command and names the step as + // the reference does. Passed in, not renamed after: the edit may land later as a job. + let step_name = match p.get("stepName") { + None | Some(Value::Null) => "Free Transform", + Some(Value::String(n)) if n == TRANSFORM_PATH => TRANSFORM_PATH, + Some(_) => return Err(bad("`stepName` must be \"Transform Path\"")), + }; let p = &with_panel_target(s, p); let st = s.active().ok_or(EngineError::NoDocument)?; let many = layers_param(&st.doc, p)?; @@ -920,7 +930,7 @@ fn transform(s: &mut Session, p: &Value) -> Result { // on a worker with progress, and can be cancelled. crate::jobs::edit_job( s, - "Free Transform", + step_name, move |doc, _, ctx| ctx.stage(0.0, 1.0, "Transforming", |ctl| transform_doc(doc, id, &ids, &p, lone, &h, affine, interp, ctl)), move |()| json!({"rect": rect, "layers": layers}), ) @@ -1006,7 +1016,7 @@ pub fn specs() -> Vec { label: "Free Transform", menu: &[], shortcut: None, - params: r##"{"layer":id?,"layers":[id,…]? (several layers moved by one box, one step; default with neither = the selected layers but the Background, as Photoshop's Free Transform with several selected),"rect":[x0,y0,x1,y1]? (source frame; default = the layers' content ∩ selection),"quad":[[x,y]×4]? (where the frame's corners go, clockwise from top-left),"matrix":[a,b,c,d,e,f]? (affine alternative),"scaleX":%?,"scaleY":%?,"rotate":deg?,"dx":px?,"dy":px?,"reference":"center|topLeft|top|topRight|left|right|bottomLeft|bottom|bottomRight"|[x,y]="center" (relative alternative: scale and rotate about this point, then move),"interpolation":"bicubic|bilinear|nearest|bicubicSharper|bicubicSmoother|bicubicAutomatic"="bicubic" (Photoshop's bicubic variants render as Bicubic),"target":"pixels"|"mask"|"quickMask"|{"channel":i}=Channels panel target (an unlinked mask, an alpha channel or the Quick Mask transforms alone; a linked mask moves with its layer)}"##, + params: r##"{"layer":id?,"layers":[id,…]? (several layers moved by one box, one step; default with neither = the selected layers but the Background, as Photoshop's Free Transform with several selected),"rect":[x0,y0,x1,y1]? (source frame; default = the layers' content ∩ selection),"quad":[[x,y]×4]? (where the frame's corners go, clockwise from top-left),"matrix":[a,b,c,d,e,f]? (affine alternative),"scaleX":%?,"scaleY":%?,"rotate":deg?,"dx":px?,"dy":px?,"reference":"center|topLeft|top|topRight|left|right|bottomLeft|bottom|bottomRight"|[x,y]="center" (relative alternative: scale and rotate about this point, then move),"interpolation":"bicubic|bilinear|nearest|bicubicSharper|bicubicSmoother|bicubicAutomatic"="bicubic" (Photoshop's bicubic variants render as Bicubic),"stepName":"Transform Path"? (History step name; the shape tools' bounding box sends it; default "Free Transform"; any other value is refused),"target":"pixels"|"mask"|"quickMask"|{"channel":i}=Channels panel target (an unlinked mask, an alpha channel or the Quick Mask transforms alone; a linked mask moves with its layer)}"##, enabled: has_layer, journal: true, run: transform, diff --git a/crates/engine/src/cmd/transform_cmds/tests.rs b/crates/engine/src/cmd/transform_cmds/tests.rs index 10aecc0b4b..124e69198d 100644 --- a/crates/engine/src/cmd/transform_cmds/tests.rs +++ b/crates/engine/src/cmd/transform_cmds/tests.rs @@ -970,3 +970,24 @@ fn split_selected_lifts_up_to_the_selection_and_leaves_the_rest() { assert!((l + r - a).abs() < 1e-6, "k = {k}: lifted {l} + left {r} != {a}"); } } + +/// `stepName` names the step "Transform Path" (the shape tools' bounding box); without it the +/// step stays "Free Transform"; any other name is refused and changes nothing. +#[test] +fn step_name_transform_path_is_the_only_name_taken() { + let mut s = session(); + let p = json!({"scaleX": 50, "scaleY": 50}); + s.execute("edit.transform", p.clone()).unwrap(); + assert_eq!(s.active().unwrap().history.entries().last().map(String::as_str), Some("Free Transform")); + let mut named = p.clone(); + named["stepName"] = json!("Transform Path"); + s.execute("edit.transform", named).unwrap(); + assert_eq!(s.active().unwrap().history.entries().last().map(String::as_str), Some("Transform Path")); + let steps = s.active().unwrap().history.past_len(); + for bad_name in [json!("Free Transform"), json!("Move"), json!(""), json!(3), json!(["Transform Path"])] { + let mut wrong = p.clone(); + wrong["stepName"] = bad_name.clone(); + assert!(s.execute("edit.transform", wrong).is_err(), "{bad_name}"); + } + assert_eq!(s.active().unwrap().history.past_len(), steps, "a refused name changes nothing"); +} diff --git a/crates/engine/src/cmd/vector_cmds.rs b/crates/engine/src/cmd/vector_cmds.rs index c4cb0d9471..cd18abb315 100644 --- a/crates/engine/src/cmd/vector_cmds.rs +++ b/crates/engine/src/cmd/vector_cmds.rs @@ -315,13 +315,13 @@ pub fn specs() -> Vec { "subtract", "Subtract Front Shape" )), - spec!("layer.combineShapes.intersectShapeAreas", "Intersect Shape Areas", [], COMBINE_PARAMS, has_layer, |s, p| combine_shapes( + spec!("layer.combineShapes.intersectShapeAreas", "Unite Shapes at Overlap", [], COMBINE_PARAMS, has_layer, |s, p| combine_shapes( s, p, "intersect", "Intersect Shape Areas" )), - spec!("layer.combineShapes.excludeOverlappingShapes", "Exclude Overlapping Shapes", [], COMBINE_PARAMS, has_layer, |s, p| { + spec!("layer.combineShapes.excludeOverlappingShapes", "Subtract Shapes at Overlap", [], COMBINE_PARAMS, has_layer, |s, p| { combine_shapes(s, p, "exclude", "Exclude Overlapping Shapes") }), spec!( diff --git a/crates/engine/src/cmd/video_cmds.rs b/crates/engine/src/cmd/video_cmds.rs index d5540c1f79..3b1a631c81 100644 --- a/crates/engine/src/cmd/video_cmds.rs +++ b/crates/engine/src/cmd/video_cmds.rs @@ -110,6 +110,15 @@ fn blank_of(fmt: photocraft_color::PixelFormat) -> Surface { Surface::new(fmt) } +/// Both the altered and original footage stacks must have room for an added frame. +fn check_frame_growth(frames: usize, original_frames: Option) -> Result<()> { + let limit = crate::timeline_cmds::MAX_DURATION; + if frames.max(original_frames.unwrap_or(0)) >= limit { + return Err(EngineError::Other(format!("a video layer is limited to {limit} frames"))); + } + Ok(()) +} + fn new_blank(s: &mut Session, _p: &Value) -> Result { let id = s.edit("New Blank Video Layer", |doc, active| { store(doc); @@ -138,7 +147,8 @@ fn new_blank(s: &mut Session, _p: &Value) -> Result { fn insert_blank(s: &mut Session, _p: &Value) -> Result { let fmt = s.active().ok_or(EngineError::NoDocument)?.doc.pixel_format(); edit_video(s, "Insert Blank Frame", move |v, cur| { - let at = (cur + 1).min(v.frames.len()); + check_frame_growth(v.frames.len(), v.original_frames.as_ref().map(Vec::len))?; + let at = cur.saturating_add(1).min(v.frames.len()); v.frames.insert(at, blank_of(fmt)); if let Some(original) = &mut v.original_frames { // The stacks stay aligned, but never index past a shorter one. @@ -150,7 +160,9 @@ fn insert_blank(s: &mut Session, _p: &Value) -> Result { fn duplicate_frame(s: &mut Session, _p: &Value) -> Result { edit_video(s, "Duplicate Frame", |v, cur| { - if let Some(f) = v.frames.get(cur).cloned() { + if let Some(f) = v.frames.get(cur) { + check_frame_growth(v.frames.len(), v.original_frames.as_ref().map(Vec::len))?; + let f = f.clone(); if let Some(original) = &mut v.original_frames { let orig = original.get(cur).cloned().unwrap_or_else(|| blank_of(f.format())); original.insert((cur + 1).min(original.len()), orig); diff --git a/crates/engine/src/cmd/video_cmds/tests.rs b/crates/engine/src/cmd/video_cmds/tests.rs index f2acb0bd0f..d7feacb06a 100644 --- a/crates/engine/src/cmd/video_cmds/tests.rs +++ b/crates/engine/src/cmd/video_cmds/tests.rs @@ -29,6 +29,17 @@ fn new_blank_insert_duplicate_delete_frames() { assert!(s.active().unwrap().doc.timeline.as_ref().unwrap().duration >= frames(&s, id)); } +/// Check the shared growth limit without constructing a million-frame document. +#[test] +fn frame_growth_stops_at_the_limit_of_either_stack() { + let limit = crate::timeline_cmds::MAX_DURATION; + assert!(check_frame_growth(limit - 1, None).is_ok()); + assert!(check_frame_growth(limit - 1, Some(limit - 1)).is_ok()); + assert!(check_frame_growth(limit, None).is_err()); + assert!(check_frame_growth(limit - 1, Some(limit)).is_err()); + assert!(check_frame_growth(limit + 1, None).is_err()); +} + #[test] fn rasterize_drops_the_stack() { let mut s = session(); diff --git a/crates/engine/src/cmd/warp_cmds.rs b/crates/engine/src/cmd/warp_cmds.rs index c2f434fb1e..4b94af82a9 100644 --- a/crates/engine/src/cmd/warp_cmds.rs +++ b/crates/engine/src/cmd/warp_cmds.rs @@ -664,7 +664,7 @@ pub fn specs() -> Vec { CommandSpec { id: "layer.smartObjects.warp", label: "Warp", - menu: &["Layer", "Smart Objects"], + menu: &[], shortcut: None, params: P, enabled: active_smart, diff --git a/crates/engine/src/crop_fill.rs b/crates/engine/src/crop_fill.rs index 339da83ce9..f5da0de07b 100644 --- a/crates/engine/src/crop_fill.rs +++ b/crates/engine/src/crop_fill.rs @@ -3,9 +3,10 @@ //! strips an extension adds) is filled from its surroundings instead of holding the background //! colour or transparency. //! -//! Which layer: the Background when the document has one (the layer the crop filled with the -//! background colour), otherwise the active pixel layer (where the crop left transparency). Other -//! layers keep their transparency there, as after a plain crop. Each connected piece of the +//! Which layers: the Background and the active pixel layer, each sampled independently. Unmeasured +//! cases (Delete Cropped Pixels off, or a hidden, locked or nonpixel active layer) retain the +//! Background-else-active target. Other layers keep their transparency, as after a plain crop. +//! Each connected piece of the //! uncovered area (each corner, each edge strip) is filled on its own, with Photoshop's sampling //! window around that piece, and only pixels the image covers are sampled. //! @@ -27,6 +28,9 @@ const SEED: u64 = 1; /// The largest canvas (pixels) the uncovered area is worked out for: the Content-Aware window cap. const MAX_PIXELS: u64 = 400_000_000; +/// Limit for the dense native-float input read when reaching beyond the normal sampling window. +const MAX_WIDENED_SAMPLE_BYTES: usize = 512 << 20; + /// Where the cropped canvas came from in the original document. #[derive(Clone, Debug)] pub(crate) struct Coverage { @@ -38,10 +42,10 @@ pub(crate) struct Coverage { pub height: f64, /// Whether the map rotates (its resampled edge is antialiased against the background colour). pub rotated: bool, - /// The filled layer's pixels before a turned crop (original document px), set by + /// Each candidate target's pixels before a turned crop (original document px), set by /// [`Coverage::holding`]: where they lie past the old canvas they are hidden image, not /// uncovered area. A straight crop has none: Photoshop fills over hidden pixels there. - pub held: Option, + pub held: Option>, } impl Coverage { @@ -53,7 +57,14 @@ impl Coverage { /// Takes the pixels of the layer the fill will go to from `doc` before a turned crop (the /// surface is shared, not copied), so hidden pixels past the old canvas count as covered. pub fn holding(mut self, doc: &Document, active: Option) -> Self { - self.held = target_layer(doc, active).ok().and_then(|id| doc.layer(id)).and_then(|l| l.surface()).cloned(); + self.held = Some( + target_layer(doc, active) + .ok() + .into_iter() + .chain(additional_target(doc, active)) + .filter_map(|id| doc.layer(id).and_then(|l| l.surface()).map(|surface| (id, surface.clone()))) + .collect(), + ); self } @@ -61,19 +72,19 @@ impl Coverage { /// the original canvas by at least half the pixel's projected size (exact for an unrotated /// crop); a rotated crop also refills the one-pixel antialiased edge, which the resampling /// blended with the background colour. - fn covered(&self, u: i32, v: i32, margin: f64) -> bool { + fn covered(&self, u: i32, v: i32, margin: f64, held: Option<&Surface>) -> bool { let [a, b, c, d, e, f] = self.map; let (cu, cv) = (f64::from(u) + 0.5, f64::from(v) + 0.5); let (x, y) = (a * cu + b * cv + e, c * cu + d * cv + f); - (x >= margin && y >= margin && x <= self.width - margin && y <= self.height - margin) || self.holds(x, y) + (x >= margin && y >= margin && x <= self.width - margin && y <= self.height - margin) || Self::holds(held, x, y) } /// Whether the layer held an image pixel at original document point (x, y) past the canvas /// (#8060): mostly opaque there and one pixel around it too (the turned edge is blended with /// the background colour, as at the canvas edge). Without an alpha channel /// hidden pixels can't be told from empty ones: nothing is held. - fn holds(&self, x: f64, y: f64) -> bool { - let Some(surf) = &self.held else { return false }; + fn holds(held: Option<&Surface>, x: f64, y: f64) -> bool { + let Some(surf) = held else { return false }; let format = surf.format(); if !(format.alpha && x.is_finite() && y.is_finite()) { return false; @@ -100,8 +111,20 @@ const UNLABELLED: u32 = u32::MAX; /// Fills the area of the cropped `doc` that `cov` says the original image doesn't cover (see the /// module docs). Nothing uncovered: nothing changes. Errors leave `doc` to be rolled back by the -/// caller's history step. -pub(crate) fn fill_uncovered(doc: &mut Document, active: Option, cov: &Coverage) -> Result<()> { +/// caller's history step. Returns whether any uncovered pixels were filled, for the history name. +pub(crate) fn fill_uncovered(doc: &mut Document, active: Option, cov: &Coverage, delete: bool) -> Result { + let first = target_layer(doc, active); + let additional = if delete { additional_target(doc, active) } else { None }; + let mut filled = fill_layer(doc, first, cov, false)?; + if let Some(id) = additional { + filled |= fill_layer(doc, Ok(id), cov, true)?; + } + Ok(filled) +} + +/// One target at a time keeps the label/window allocations bounded to one canvas. The caller's +/// existing edit/compound transaction rolls every target back if a later fill fails. +fn fill_layer(doc: &mut Document, id: Result, cov: &Coverage, own_pixels: bool) -> Result { let canvas = doc.bounds(); let (w, h) = (canvas.width(), canvas.height()); if u64::from(w) * u64::from(h) > MAX_PIXELS { @@ -110,62 +133,131 @@ pub(crate) fn fill_uncovered(doc: &mut Document, active: Option, cov: & let (w, h) = (w as usize, h as usize); let len = w.checked_mul(h).ok_or_else(|| EngineError::Other("the crop is too large for Content-Aware fill".into()))?; if len == 0 { - return Ok(()); + return Ok(false); } let margin = cov.margin(); + let held = id.as_ref().ok().and_then(|id| cov.held.as_ref()?.iter().find(|(held_id, _)| held_id == id).map(|(_, surface)| surface)); let mut labels = crate::allocation::filled(len, 0u32, "Content-Aware crop fill")?; labels.par_chunks_mut(w).enumerate().for_each(|(y, row)| { for (x, l) in row.iter_mut().enumerate() { - if !cov.covered(x as i32, y as i32, margin) { + if !cov.covered(x as i32, y as i32, margin, held) { *l = UNLABELLED; } } }); if !labels.contains(&UNLABELLED) { - return Ok(()); + return Ok(false); } if !labels.contains(&0) { - return Err(EngineError::Other("Content-Aware fill needs some of the image inside the crop to sample from".into())); + return if own_pixels { + Ok(false) + } else { + Err(EngineError::Other("Content-Aware fill needs some of the image inside the crop to sample from".into())) + }; } - let id = target_layer(doc, active)?; - let pieces = label_components(&mut labels, w, h)?; + // Resolve an absent target only after the no-fill/sample checks, preserving the legacy path. + let id = id?; let surf = doc.layer(id).and_then(|l| l.surface()).ok_or_else(|| EngineError::Other("Content-Aware fill needs a pixel layer".into()))?; + let n = surf.format().channels().max(1); + let has_alpha = surf.format().alpha; + let has_pixel = |x, y| !has_alpha || surf.sample_channel(x, y, n - 1) > 0.0; + let donor_bounds = own_pixels.then(|| if has_alpha { surf.content_bounds().intersect(&canvas) } else { canvas }); + // The added target is optional when it has no covered pixels of its own to sample. + // This check does not absorb errors from synthesis or allocation. + if donor_bounds.is_some_and(|bounds| { + !contains_donor(bounds, |x, y| { + let at = usize::try_from(y).ok().and_then(|y| y.checked_mul(w)).zip(usize::try_from(x).ok()).and_then(|(r, x)| r.checked_add(x)); + at.and_then(|i| labels.get(i)) == Some(&0) && has_pixel(x, y) + }) + }) { + return Ok(false); + } + let pieces = label_components(&mut labels, w, h)?; let label = |x: i32, y: i32| -> u32 { if x < 0 || y < 0 { return 0; } (y as usize).checked_mul(w).and_then(|i| i.checked_add(x as usize)).and_then(|i| labels.get(i)).copied().unwrap_or(0) }; - let n = surf.format().channels().max(1); - let filled: Vec<(Rect, Vec)> = pieces - .par_iter() - .enumerate() - .map(|(k, bounds)| -> Result<(Rect, Vec)> { - let k = k as u32 + 1; - let (window, px) = crate::fill_cmds::content_aware_native(surf, *bounds, canvas, true, SEED, |x, y| label(x, y) == k, |x, y| label(x, y) == 0)?; - // The piece's bounds, its pixels from the fill and the rest as they were. - let mut out = surf.read_region(*bounds); - let ww = window.width() as usize; - for y in bounds.y0..bounds.y1 { - for x in bounds.x0..bounds.x1 { - if label(x, y) != k || !window.contains(x, y) { - continue; - } - let src = ((y - window.y0) as usize * ww + (x - window.x0) as usize) * n; - let dst = ((y - bounds.y0) as usize * bounds.width() as usize + (x - bounds.x0) as usize) * n; - if let (Some(s), Some(d)) = (px.get(src..src + n), out.get_mut(dst..dst + n)) { - d.copy_from_slice(s); - } + let fill_piece = |(k, bounds): (usize, &Rect)| -> Result<(Rect, Vec)> { + let k = k as u32 + 1; + // A partial active layer can have no donor near a distant turned corner. Only that + // added target may widen its sampling envelope; its hole and output stay unchanged. + let usable = |x, y| label(x, y) == 0 && (!own_pixels || has_pixel(x, y)); + let sampling_bounds = if let Some(donor_bounds) = donor_bounds { + let window = crate::fill_cmds::sampling_window(*bounds, canvas).intersect(&donor_bounds); + if contains_donor(window, usable) { *bounds } else { widened_sampling_bounds(*bounds, donor_bounds, canvas, n)? } + } else { + *bounds + }; + let (window, px) = crate::fill_cmds::content_aware_native( + surf, + sampling_bounds, + canvas, + true, + SEED, + |x, y| label(x, y) == k, + // A partial active layer (EdgeHalf in #10868) must extend its own image, not + // sample its empty canvas rows into the new strip. Keep legacy sampling intact. + usable, + )?; + // The piece's bounds, its pixels from the fill and the rest as they were. + let mut out = crate::allocation::read_region(surf, *bounds, "Content-Aware crop output")?; + let ww = window.width() as usize; + for y in bounds.y0..bounds.y1 { + for x in bounds.x0..bounds.x1 { + if label(x, y) != k || !window.contains(x, y) { + continue; + } + let src = ((y - window.y0) as usize * ww + (x - window.x0) as usize) * n; + let dst = ((y - bounds.y0) as usize * bounds.width() as usize + (x - bounds.x0) as usize) * n; + if let (Some(s), Some(d)) = (px.get(src..src + n), out.get_mut(dst..dst + n)) { + d.copy_from_slice(s); } } - Ok((*bounds, out)) - }) - .collect::>()?; + } + Ok((*bounds, out)) + }; + let filled: Vec<(Rect, Vec)> = if own_pixels { + // A fallback window can span the canvas: keep only one added-target window live. + pieces.iter().enumerate().map(fill_piece).collect::>()? + } else { + pieces.par_iter().enumerate().map(fill_piece).collect::>()? + }; let surf = doc.layer_mut(id).and_then(|l| l.surface_mut()).ok_or_else(|| EngineError::Other("Content-Aware fill needs a pixel layer".into()))?; for (r, px) in filled { surf.write_region(r, &px); } - Ok(()) + Ok(true) +} + +/// Checks the candidate rectangle for a covered pixel that passes the target's donor policy. +fn contains_donor(bounds: Rect, usable: impl Fn(i32, i32) -> bool) -> bool { + (bounds.y0..bounds.y1).any(|y| (bounds.x0..bounds.x1).any(|x| usable(x, y))) +} + +/// Widens the sampling envelope to include distant donors, after pricing the actual float read. +fn widened_sampling_bounds(piece: Rect, donors: Rect, canvas: Rect, channels: usize) -> Result { + let expanded = piece.union(&donors); + let window = crate::fill_cmds::sampling_window(expanded, canvas); + let bytes = (window.width() as usize) + .checked_mul(window.height() as usize) + .and_then(|pixels| pixels.checked_mul(channels)) + .and_then(|samples| samples.checked_mul(std::mem::size_of::())); + if bytes.is_none_or(|bytes| bytes > MAX_WIDENED_SAMPLE_BYTES) { + return Err(EngineError::Other("the expanded Content-Aware crop sampling window is too large".into())); + } + Ok(expanded) +} + +/// Only the measured, editable active-raster case adds a target to the Background. Ancestor +/// visibility and locks count too; all unmeasured cases keep the original target selection. +fn additional_target(doc: &Document, active: Option) -> Option { + let background = doc.background()?.id; + let id = active.filter(|id| *id != background)?; + let path = doc.path_of(id)?; + let layer = doc.layer_at(&path)?; + (matches!(layer.content, photocraft_doc::LayerContent::Raster(_)) && doc.shown_at(&path) && !doc.locks_at(&path).any()).then_some(id) } /// The Background, else the active pixel layer. @@ -242,9 +334,9 @@ mod tests { fn unrotated_coverage_is_exact() { let c = Coverage::crop(Rect::new(-2, 0, 8, 4), 5, 4); let m = c.margin(); - assert!(!c.covered(1, 0, m), "x = -1"); - assert!(c.covered(2, 0, m), "x = 0"); - assert!(c.covered(6, 0, m), "x = 4"); - assert!(!c.covered(7, 0, m), "x = 5"); + assert!(!c.covered(1, 0, m, None), "x = -1"); + assert!(c.covered(2, 0, m, None), "x = 0"); + assert!(c.covered(6, 0, m, None), "x = 4"); + assert!(!c.covered(7, 0, m, None), "x = 5"); } } diff --git a/crates/engine/src/embed_all_linked_tests.rs b/crates/engine/src/embed_all_linked_tests.rs new file mode 100644 index 0000000000..70bed5c0c1 --- /dev/null +++ b/crates/engine/src/embed_all_linked_tests.rs @@ -0,0 +1,144 @@ +//! Layer > Smart Objects > Embed Linked and Embed All Linked (#11401). + +use photocraft_doc::{LayerContent, SmartSource}; +use serde_json::json; + +use crate::Session; +use crate::cmd::command_specs; + +fn label(id: &str) -> &'static str { + command_specs().iter().find(|c| c.id == id).map(|c| c.label).unwrap_or_else(|| panic!("{id} is not registered")) +} + +/// Adds a layer with a few painted pixels (an empty layer can't become a smart object). +fn painted_layer(s: &mut Session, red: f32) { + s.execute("layer.new.layer", json!({})).unwrap(); + s.edit("setup", |doc, active| { + let surf = doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap(); + surf.fill_rect(photocraft_geom::Rect::new(2, 2, 10, 10), &[red, 1.0 - red, 0.0, 1.0]); + Ok(()) + }) + .unwrap(); +} + +/// Three smart objects: the first two linked to files in `dir`, the third embedded. +fn three(dir: &std::path::Path) -> (Session, [u64; 3]) { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 32, "height": 24})).unwrap(); + let mut ids = [0u64; 3]; + for (i, slot) in ids.iter_mut().enumerate() { + painted_layer(&mut s, 0.25 * (i + 1) as f32); + *slot = s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap()["layer"].as_u64().unwrap(); + if i < 2 { + let path = dir.join(format!("linked{i}.pcraft")); + s.execute("layer.smartObjects.convertToLinked", json!({"path": path.to_str().unwrap()})).unwrap(); + } + } + (s, ids) +} + +fn is_linked(s: &Session, id: u64) -> bool { + let doc = &s.active().unwrap().doc; + let layer = doc.walk().into_iter().map(|(_, _, l)| l).find(|l| l.id.0 == id).unwrap(); + match &layer.content { + LayerContent::Smart(sm) => matches!(sm.source, SmartSource::Linked { .. }), + other => panic!("not smart: {}", other.kind_name()), + } +} + +/// The file name and bytes an embedded smart object carries. +fn embedded(s: &Session, id: u64) -> (String, Vec) { + let doc = &s.active().unwrap().doc; + let layer = doc.walk().into_iter().map(|(_, _, l)| l).find(|l| l.id.0 == id).unwrap(); + match &layer.content { + LayerContent::Smart(sm) => match &sm.source { + SmartSource::Embedded { file_name, bytes } => (file_name.clone(), bytes.to_vec()), + SmartSource::Linked { .. } => panic!("still linked"), + }, + other => panic!("not smart: {}", other.kind_name()), + } +} + +fn temp_dir(name: &str) -> std::path::PathBuf { + let dir = std::env::temp_dir().join(format!("pc-embed-all-{name}-{}", std::process::id())); + std::fs::remove_dir_all(&dir).ok(); + std::fs::create_dir_all(&dir).unwrap(); + dir +} + +#[test] +fn embed_linked_and_embed_all_linked_are_named_in_the_engine() { + assert_eq!(label("layer.smartObjects.convertToEmbedded"), "Embed Linked"); + assert_eq!(label("layer.smartObjects.embedAllLinked"), "Embed All Linked"); + // The warp commands stay registered for scripts and the Edit menu routes. + for id in ["layer.smartObjects.warp", "layer.smartObjects.perspectiveWarp", "layer.smartObjects.puppetWarp"] { + label(id); + } +} + +#[test] +fn embed_all_linked_embeds_both_linked_objects_in_one_undoable_step() { + let dir = temp_dir("both"); + let (mut s, ids) = three(&dir); + assert!(is_linked(&s, ids[0]) && is_linked(&s, ids[1]) && !is_linked(&s, ids[2])); + assert!(s.is_enabled("layer.smartObjects.embedAllLinked")); + let before = s.active().unwrap().history.entries().len(); + let files: Vec> = (0..2).map(|i| photocraft_format::read_file(&dir.join(format!("linked{i}.pcraft"))).unwrap()).collect(); + assert_ne!(files[0], files[1], "the fixtures differ"); + let third = embedded(&s, ids[2]); + + let r = s.execute("layer.smartObjects.embedAllLinked", json!({})).unwrap(); + assert_eq!(r["embedded"], json!([ids[0], ids[1]])); + assert!(ids.iter().all(|&id| !is_linked(&s, id))); + for (i, file) in files.iter().enumerate() { + let (name, bytes) = embedded(&s, ids[i]); + assert_eq!(name, format!("linked{i}.pcraft"), "object {i} keeps its own file name"); + assert_eq!(&bytes, file, "object {i} carries its own linked file's bytes"); + } + assert_eq!(embedded(&s, ids[2]), third, "the already embedded object is untouched"); + let entries = s.active().unwrap().history.entries(); + assert_eq!(entries.len(), before + 1, "one history step"); + assert_eq!(entries.last().map(String::as_str), Some("Embed All Linked")); + assert!(!s.is_enabled("layer.smartObjects.embedAllLinked"), "nothing left to embed"); + + s.execute("edit.undo", json!({})).unwrap(); + assert!(is_linked(&s, ids[0]) && is_linked(&s, ids[1]) && !is_linked(&s, ids[2])); + assert_eq!(s.active().unwrap().history.entries().len(), before); + std::fs::remove_dir_all(&dir).ok(); +} + +#[test] +fn embed_all_linked_with_no_linked_object_is_an_error_not_a_panic() { + let mut s = Session::new(); + assert!(!s.is_enabled("layer.smartObjects.embedAllLinked"), "no document"); + assert!(s.execute("layer.smartObjects.embedAllLinked", json!({})).is_err()); + s.execute("file.new", json!({"width": 16, "height": 16})).unwrap(); + painted_layer(&mut s, 1.0); + s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + assert!(!s.is_enabled("layer.smartObjects.embedAllLinked"), "only embedded objects"); + let before = s.active().unwrap().history.entries().len(); + assert!(s.execute("layer.smartObjects.embedAllLinked", json!({})).is_err()); + assert_eq!(s.active().unwrap().history.entries().len(), before); +} + +#[test] +fn embed_all_linked_refuses_the_whole_step_when_a_linked_file_is_missing() { + let dir = temp_dir("missing"); + let (mut s, ids) = three(&dir); + std::fs::remove_file(dir.join("linked1.pcraft")).unwrap(); + let before = s.active().unwrap().history.entries().len(); + let err = s.execute("layer.smartObjects.embedAllLinked", json!({})).unwrap_err().to_string(); + assert!(err.contains("linked1.pcraft"), "the error names the missing file: {err}"); + assert!(is_linked(&s, ids[0]) && is_linked(&s, ids[1]), "nothing was embedded"); + assert_eq!(s.active().unwrap().history.entries().len(), before); + std::fs::remove_dir_all(&dir).ok(); +} + +#[test] +fn embed_linked_still_embeds_one_object_under_its_old_id() { + let dir = temp_dir("one"); + let (mut s, ids) = three(&dir); + s.execute("layer.smartObjects.convertToEmbedded", json!({"layer": ids[0]})).unwrap(); + assert!(!is_linked(&s, ids[0]) && is_linked(&s, ids[1])); + std::fs::remove_dir_all(&dir).ok(); +} diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs index e74b784519..468efec851 100644 --- a/crates/engine/src/lib.rs +++ b/crates/engine/src/lib.rs @@ -332,11 +332,15 @@ pub struct Session { pub damage_misses: usize, } +#[cfg(test)] +mod embed_all_linked_tests; #[cfg(test)] mod fill_layer_mode_tests; #[cfg(test)] mod pattern_mode_tests; #[cfg(test)] +mod second_keys_zoom_actions_tests; +#[cfg(test)] mod tests; #[cfg(test)] diff --git a/crates/engine/src/prefs/cmds.rs b/crates/engine/src/prefs/cmds.rs index 2c15505fab..fa695e1e92 100644 --- a/crates/engine/src/prefs/cmds.rs +++ b/crates/engine/src/prefs/cmds.rs @@ -177,7 +177,7 @@ pub fn specs() -> Vec { section!("edit.preferences.transparencyAndGamut", "Transparency & Gamut…"), section!("edit.preferences.unitsAndRulers", "Units & Rulers…"), section!("edit.preferences.guidesGridAndSlices", "Guides, Grid & Slices…"), - section!("edit.preferences.plugIns", "Plug-ins…"), + section!("edit.preferences.plugIns", "Plugins…"), section!("edit.preferences.type", "Type…"), section!("edit.preferences.enhancedControls", "Enhanced Controls…"), section!("edit.preferences.rawDefaults", "Camera Raw…"), diff --git a/crates/engine/src/prefs/shortcuts.rs b/crates/engine/src/prefs/shortcuts.rs index 337c8e3754..f2a69c30ce 100644 --- a/crates/engine/src/prefs/shortcuts.rs +++ b/crates/engine/src/prefs/shortcuts.rs @@ -124,6 +124,8 @@ pub const TEMPORARY_TOOLS: &[(&str, &str, &str)] = &[ /// legacy function keys F2 Cut, F3 Copy, F4 Paste and Shift+F7 Inverse; Shift+Backspace /// (Shift+Delete on a Mac) for Fill; ⌘+ beside ⌘= for Zoom In; and off the Mac, Ctrl+F4 beside /// Ctrl+W for Close (Windows' close-document key; macOS keeps Ctrl+F4 for window focus). +/// Also Alt+Ctrl+0 beside Ctrl+1 for 100% and F9 beside Alt+F9 for Window > Actions (#11396; +/// measured on Windows, so the Mac gets the usual Cmd mapping of the first). pub const ALTERNATE_SHORTCUTS: &[(&str, &str)] = &[ ("edit.cut", "F2"), ("edit.copy", "F3"), @@ -131,6 +133,8 @@ pub const ALTERNATE_SHORTCUTS: &[(&str, &str)] = &[ ("edit.fill", "Shift+Backspace"), ("select.inverse", "Shift+F7"), ("view.zoomIn", "Cmd++"), + ("view.actualPixels", "Cmd+Alt+0"), + ("window.panel.actions", "F9"), #[cfg(not(target_os = "macos"))] ("file.close", "Cmd+F4"), ]; diff --git a/crates/engine/src/prefs/validate.rs b/crates/engine/src/prefs/validate.rs index 1baa1d9994..175d33f26a 100644 --- a/crates/engine/src/prefs/validate.rs +++ b/crates/engine/src/prefs/validate.rs @@ -21,7 +21,7 @@ pub const SECTIONS: [(&str, &str); 18] = [ ("transparencyAndGamut", "Transparency & Gamut"), ("unitsAndRulers", "Units & Rulers"), ("guidesGridAndSlices", "Guides, Grid & Slices"), - ("plugIns", "Plug-ins"), + ("plugIns", "Plugins"), ("type", "Type"), ("enhancedControls", "Enhanced Controls"), ("rawDefaults", "Camera Raw Defaults"), diff --git a/crates/engine/src/proof_sim.rs b/crates/engine/src/proof_sim.rs index 6c7afc15d9..c7e8bcabf0 100644 --- a/crates/engine/src/proof_sim.rs +++ b/crates/engine/src/proof_sim.rs @@ -305,8 +305,8 @@ pub fn specs() -> Vec { kind_spec!("view.proofSetup.workingMagentaPlate", "Working Magenta Plate"), kind_spec!("view.proofSetup.workingYellowPlate", "Working Yellow Plate"), kind_spec!("view.proofSetup.workingBlackPlate", "Working Black Plate"), - kind_spec!("view.proofSetup.workingCmyPlate", "Working CMY Plate"), - kind_spec!("view.proofSetup.legacyMacintoshRgb", "Legacy Macintosh RGB"), + kind_spec!("view.proofSetup.workingCmyPlate", "Working CMY Plates"), + kind_spec!("view.proofSetup.legacyMacintoshRgb", "Legacy Macintosh RGB (Gamma 1.8)"), kind_spec!("view.proofSetup.colorBlindnessProtanopia", "Color Blindness — Protanopia-type"), kind_spec!("view.proofSetup.colorBlindnessDeuteranopia", "Color Blindness — Deuteranopia-type"), CommandSpec { diff --git a/crates/engine/src/second_keys_zoom_actions_tests.rs b/crates/engine/src/second_keys_zoom_actions_tests.rs new file mode 100644 index 0000000000..92d3b820cf --- /dev/null +++ b/crates/engine/src/second_keys_zoom_actions_tests.rs @@ -0,0 +1,95 @@ +//! The reference application's second default keys for View > 100% and Window > Actions (#11396): +//! Alt+Ctrl+0 beside Ctrl+1, and F9 beside Alt+F9. +//! +//! The engine owns the key tables and the Keyboard Shortcuts command. The zoom itself and the +//! Actions panel are UI state (`window.panel.actions` is a menu item the engine does not run), so +//! these tests check that each key resolves to its command exactly as the main key does and +//! that the user can remove it. They do not exercise key dispatch; `alternate_keys_run_their_command` +//! in the UI crate's `shortcut_dispatch` tests does, and lists both keys. + +use crate::Session; +use crate::prefs::{ALTERNATE_SHORTCUTS, default_alternates, normalize_shortcut}; +use serde_json::json; + +/// The menus' main keys (`menu_catalog.rs`): what View > 100% and Window > Actions show. +const ACTUAL_PIXELS_MAIN: &str = "Cmd+1"; +const ACTIONS_MAIN: &str = "Alt+F9"; + +/// Our notation: `Cmd` is Ctrl off the Mac, so this is Ctrl+Alt+0 on Windows and Linux. +const ACTUAL_PIXELS_ALT: &str = "Cmd+Alt+0"; + +fn session() -> Session { + let mut s = Session::new(); + s.execute("file.new", json!({"width": 32, "height": 32})).unwrap(); + s +} + +/// The command a key press runs among the engine's bindable commands and the two this issue +/// adds keys to: a command's main key (given for the UI-only one), else its alternates in effect. +fn resolve(s: &Session, key: &str) -> Vec<&'static str> { + let want = normalize_shortcut(key).unwrap(); + let mains = [("view.actualPixels", Some(ACTUAL_PIXELS_MAIN)), ("window.panel.actions", Some(ACTIONS_MAIN))]; + let mut ids: Vec<&'static str> = Vec::new(); + for (id, main) in mains { + let main_in_effect = s.prefs().shortcut(id, main); + let is_main = main_in_effect.and_then(normalize_shortcut).as_ref() == Some(&want); + if is_main || s.prefs().alternates(id, main_in_effect).contains(&want) { + ids.push(id); + } + } + ids +} + +#[test] +fn both_keys_are_default_alternates() { + assert!(ALTERNATE_SHORTCUTS.contains(&("view.actualPixels", "Cmd+Alt+0"))); + assert!(ALTERNATE_SHORTCUTS.contains(&("window.panel.actions", "F9"))); + assert_eq!(default_alternates("view.actualPixels").collect::>(), ["Cmd+Alt+0"]); + assert_eq!(default_alternates("window.panel.actions").collect::>(), ["F9"]); + let s = session(); + let zoom = s.prefs().alternates("view.actualPixels", Some(ACTUAL_PIXELS_MAIN)); + assert_eq!(zoom, [normalize_shortcut(ACTUAL_PIXELS_ALT).unwrap()]); + assert_eq!(s.prefs().alternates("window.panel.actions", Some(ACTIONS_MAIN)), ["F9"]); +} + +#[test] +fn each_key_resolves_to_its_command_like_the_main_key() { + let s = session(); + assert_eq!(resolve(&s, ACTUAL_PIXELS_ALT), ["view.actualPixels"]); + assert_eq!(resolve(&s, ACTUAL_PIXELS_MAIN), ["view.actualPixels"]); + assert_eq!(resolve(&s, "F9"), ["window.panel.actions"]); + assert_eq!(resolve(&s, ACTIONS_MAIN), ["window.panel.actions"]); +} + +#[test] +fn the_menu_shows_only_the_main_key() { + // The menus print the catalogue's key, and an alternate is never the main key in effect. + let s = session(); + assert_eq!(s.prefs().shortcut("view.actualPixels", Some(ACTUAL_PIXELS_MAIN)), Some(ACTUAL_PIXELS_MAIN)); + assert_eq!(s.prefs().shortcut("window.panel.actions", Some(ACTIONS_MAIN)), Some(ACTIONS_MAIN)); + assert_eq!(crate::shell_commands::SHELL_COMMANDS.iter().find(|c| c.0 == "view.actualPixels").and_then(|c| c.3), Some(ACTUAL_PIXELS_MAIN)); +} + +#[test] +fn keyboard_shortcuts_lists_the_second_key_and_removing_it_stops_it() { + let mut s = session(); + let r = s.execute("edit.keyboardShortcuts", json!({"filter": "view.actualPixels"})).unwrap(); + let row = r["commands"].as_array().unwrap().iter().find(|c| c["id"] == "view.actualPixels").unwrap().clone(); + assert_eq!(row["shortcut"], ACTUAL_PIXELS_MAIN); + assert_eq!(row["alternates"], json!([normalize_shortcut(ACTUAL_PIXELS_ALT).unwrap()])); + assert_eq!(row["defaultAlternates"], json!(["Cmd+Alt+0"])); + + s.execute("edit.keyboardShortcuts", json!({"alternates": {"view.actualPixels": []}})).unwrap(); + assert!(resolve(&s, ACTUAL_PIXELS_ALT).is_empty()); + assert_eq!(resolve(&s, ACTUAL_PIXELS_MAIN), ["view.actualPixels"], "the main key still works"); + + // Window > Actions is a menu item, so it is not in the engine's list, but its second key can + // still be set and removed, as the Keyboard Shortcuts dialog does. + s.execute("edit.keyboardShortcuts", json!({"alternates": {"window.panel.actions": []}})).unwrap(); + assert!(resolve(&s, "F9").is_empty()); + assert_eq!(resolve(&s, ACTIONS_MAIN), ["window.panel.actions"]); + + s.execute("edit.keyboardShortcuts", json!({"reset": true})).unwrap(); + assert_eq!(resolve(&s, "F9"), ["window.panel.actions"]); + assert_eq!(resolve(&s, ACTUAL_PIXELS_ALT), ["view.actualPixels"]); +} diff --git a/crates/engine/src/shell_commands.rs b/crates/engine/src/shell_commands.rs index 3b52c03a03..f2af5eb5e9 100644 --- a/crates/engine/src/shell_commands.rs +++ b/crates/engine/src/shell_commands.rs @@ -42,7 +42,9 @@ pub const SHELL_COMMANDS: &[(&str, &str, &[&str], Option<&str>)] = &[ ("view.show.grid", "Grid", &["View", "Show"], Some("Cmd+'")), ("view.show.guides", "Guides", &["View", "Show"], Some("Cmd+;")), ("view.snap", "Snap", &["View"], Some("Cmd+Shift+;")), - ("view.lockGuides", "Lock Guides", &["View"], Some("Cmd+Alt+;")), + ("view.lockGuides", "Lock Guides", &["View", "Guides"], Some("Cmd+Alt+;")), + ("view.editSelectedGuides", "Edit Selected Guides", &["View", "Guides"], None), + ("view.clearSelectedGuides", "Clear Selected Guides", &["View", "Guides"], None), ("view.extras", "Extras", &["View"], Some("Cmd+H")), ("view.show.targetPath", "Target Path", &["View", "Show"], Some("Cmd+Shift+H")), ("view.screenMode.cycle", "Cycle Screen Mode", &[], Some("F")), @@ -57,7 +59,7 @@ pub const SHELL_COMMANDS: &[(&str, &str, &[&str], Option<&str>)] = &[ ("view.actualPixels", "100%", &["View"], Some("Cmd+1")), ("view.rotateView", "Rotate View", &[], None), ("view.resetView", "Reset View", &["View"], None), - ("window.newWindowForDocument", "New Window for Document", &["Window", "Arrange"], None), + ("window.newWindowForDocument", "New Window", &["Window", "Arrange"], None), ("window.toggle.layers", "Layers", &["Window"], Some("F7")), ("window.toggle.history", "History", &["Window"], None), ("window.toggle.properties", "Properties", &["Window"], None), @@ -122,8 +124,8 @@ pub const TOOLS: &[(&str, &str, Option<&str>)] = &[ ("tools.select.count", "Count Tool", Some("I")), ("tools.select.brush", "Brush Tool", Some("B")), ("tools.select.pencil", "Pencil Tool", Some("B")), - ("tools.select.mixerBrush", "Mixer Brush Tool", Some("B")), ("tools.select.colorReplacement", "Color Replacement Tool", Some("B")), + ("tools.select.mixerBrush", "Mixer Brush Tool", Some("B")), ("tools.select.eraser", "Eraser Tool", Some("E")), ("tools.select.backgroundEraser", "Background Eraser Tool", Some("E")), ("tools.select.magicEraser", "Magic Eraser Tool", Some("E")), @@ -136,8 +138,8 @@ pub const TOOLS: &[(&str, &str, Option<&str>)] = &[ ("tools.select.hand", "Hand Tool", Some("H")), ("tools.select.rotateView", "Rotate View Tool", Some("R")), ("tools.select.zoom", "Zoom Tool", Some("Z")), - ("tools.select.remove", "Remove Tool", Some("J")), ("tools.select.spotHealing", "Spot Healing Brush Tool", Some("J")), + ("tools.select.remove", "Remove Tool", Some("J")), ("tools.select.healing", "Healing Brush Tool", Some("J")), ("tools.select.patch", "Patch Tool", Some("J")), ("tools.select.contentAwareMove", "Content-Aware Move Tool", Some("J")), @@ -157,9 +159,9 @@ pub const TOOLS: &[(&str, &str, Option<&str>)] = &[ ("tools.select.pen", "Pen Tool", Some("P")), ("tools.select.freeformPen", "Freeform Pen Tool", Some("P")), ("tools.select.curvaturePen", "Curvature Pen Tool", Some("P")), - ("tools.select.addAnchorPoint", "Add Anchor Point Tool", Some("P")), - ("tools.select.deleteAnchorPoint", "Delete Anchor Point Tool", Some("P")), - ("tools.select.convertPoint", "Convert Point Tool", Some("P")), + ("tools.select.addAnchorPoint", "Add Anchor Point Tool", None), + ("tools.select.deleteAnchorPoint", "Delete Anchor Point Tool", None), + ("tools.select.convertPoint", "Convert Point Tool", None), ("tools.select.pathSelection", "Path Selection Tool", Some("A")), ("tools.select.directSelection", "Direct Selection Tool", Some("A")), ("tools.select.rectangle", "Rectangle Tool", Some("U")), diff --git a/crates/engine/tests/it/atn_perspective_warp.rs b/crates/engine/tests/it/atn_perspective_warp.rs new file mode 100644 index 0000000000..2967285842 --- /dev/null +++ b/crates/engine/tests/it/atn_perspective_warp.rs @@ -0,0 +1,202 @@ +//! The measured Perspective Warp descriptor shape through ATN conversion and action playback. + +use photocraft_doc::{LayerContent, LayerId}; +use photocraft_engine::{Session, actions_cmds::Action, atn_cmds}; +use photocraft_geom::Rect; +use photocraft_psd::{ + atn::{self, AtnAction, AtnEvent, AtnFile, AtnItem}, + descriptor::{Class, Descriptor, Id, ReferenceItem, UnicodeString, Value as D}, +}; +use serde_json::{Value, json}; + +const EVENT: &str = "perspectiveWarpTransform"; +const COMMAND: &str = "edit.perspectiveWarp"; + +fn px(value: f64) -> D { + D::UnitFloat { unit: *b"#Pxl", value } +} + +fn points(points: &[[f64; 2]]) -> D { + D::List(points.iter().map(|&[x, y]| D::Descriptor(Descriptor::new("Pnt ").with("Hrzn", px(x)).with("Vrtc", px(y)))).collect()) +} + +fn quad(indices: [i32; 4]) -> D { + D::Descriptor(Descriptor::new("perspectiveWarpQuad").with("indices", D::List(indices.into_iter().map(D::Integer).collect()))) +} + +/// Two planes sharing a seam. Vertices appear out of corner order to distinguish exact export. +fn fixture(name: Option<&str>) -> Descriptor { + let class = Class { class_id: Id::new("Lyr "), name: UnicodeString::new_nul("") }; + let target = match name { + Some(name) => ReferenceItem::Name { class, name: UnicodeString::new_nul(name) }, + None => ReferenceItem::Enumerated { class, type_id: Id::new("Ordn"), value: Id::new("Trgt") }, + }; + let rect = Descriptor::new("Rctn").with("Top ", px(0.0)).with("Left", px(0.0)).with("Btom", px(24.0)).with("Rght", px(32.0)); + Descriptor::new(EVENT) + .with("null", D::Reference(vec![target])) + .with("Md ", D::Enumerated { type_id: Id::new("perspectiveWarpMode"), value: Id::new("warp") }) + .with("referenceRect", D::Descriptor(rect)) + .with("vertices", points(&[[16.0, 20.0], [4.0, 4.0], [28.0, 4.0], [4.0, 20.0], [16.0, 4.0], [28.0, 20.0]])) + .with("warpedVertices", points(&[[17.0, 20.0], [5.5, 5.0], [27.0, 6.0], [4.0, 19.0], [18.0, 4.0], [26.0, 17.0]])) + .with("quads", D::List(vec![quad([1, 4, 0, 3]), quad([4, 2, 5, 0])])) +} + +fn imported(d: Descriptor, with_dialog: bool, enabled: bool) -> atn_cmds::Imported { + let item = + AtnItem { event: AtnEvent::name(EVENT), dictionary: b"Perspective Warp".to_vec(), descriptor: Some(d), with_dialog, enabled, ..Default::default() }; + let file = AtnFile { + name: UnicodeString::new_nul("Set"), + actions: vec![AtnAction { name: UnicodeString::new_nul("Warp"), items: vec![item], ..Default::default() }], + ..Default::default() + }; + atn_cmds::import(&atn::write(&file).unwrap()).unwrap() +} + +fn saved(action: &Action) -> AtnItem { + let (bytes, skipped) = atn_cmds::export("Set", &[action], &[], false).unwrap(); + assert!(skipped.is_empty()); + atn::parse(&bytes).unwrap().actions[0].items[0].clone() +} + +fn planes() -> Value { + json!([ + {"src":[[4,4],[16,4],[16,20],[4,20]],"dst":[[5.5,5],[18,4],[17,20],[4,19]]}, + {"src":[[16,4],[28,4],[28,20],[16,20]],"dst":[[18,4],[27,6],[26,17],[17,20]]} + ]) +} + +fn value_mut<'a>(d: &'a mut Descriptor, key: &str) -> &'a mut D { + &mut d.items.iter_mut().find(|(id, _)| id.is(key)).unwrap().1 +} + +/// Exact export preserves the original indexed mesh, target, rectangle and step flags. +#[test] +fn descriptor_round_trip_preserves_shared_indices_and_flags() { + for name in [None, Some("Façade")] { + let d = fixture(name); + let loaded = imported(d.clone(), true, false); + assert!(loaded.unsupported.is_empty()); + let action = &loaded.actions[0]; + assert_eq!(action.steps[0].0, COMMAND); + let params = &action.steps[0].1; + assert_eq!(params["planes"], planes()); + assert_eq!(params["layer"].as_str(), name); + assert_eq!(params["target"], "pixels"); + assert_eq!(params["__atnPerspectiveWarpRect"], json!([0, 0, 32, 24])); + let item = saved(action); + assert_eq!(item.event.id(), EVENT); + assert_eq!(item.descriptor.unwrap().to_bytes(), d.to_bytes()); + assert!(item.with_dialog); + assert!(!item.enabled); + } +} + +/// Unsupported targets, units, modes and geometry retain the original bytes as kept steps. +#[test] +fn unsupported_recordings_are_kept_without_partial_mapping() { + let d = fixture(None); + let mut layout = d.clone(); + *value_mut(&mut layout, "Md ") = D::Enumerated { type_id: Id::new("perspectiveWarpMode"), value: Id::new("layout") }; + let mut wrong_target = d.clone(); + *value_mut(&mut wrong_target, "null") = D::Reference(vec![ReferenceItem::Class(Class { class_id: Id::new("Chnl"), name: UnicodeString::new_nul("") })]); + let mut bad_index = d.clone(); + *value_mut(&mut bad_index, "quads") = D::List(vec![quad([1, 4, 99, 3])]); + let mut wrong_units = d.clone(); + let D::Descriptor(rect) = value_mut(&mut wrong_units, "referenceRect") else { panic!("reference rectangle") }; + *value_mut(rect, "Rght") = D::UnitFloat { unit: *b"#Prc", value: 32.0 }; + let mut incompatible_topology = d.clone(); + for key in ["vertices", "warpedVertices"] { + let D::List(points) = value_mut(&mut incompatible_topology, key) else { panic!("vertex list") }; + points.push(points[4].clone()); + } + *value_mut(&mut incompatible_topology, "quads") = D::List(vec![quad([1, 4, 0, 3]), quad([6, 2, 5, 0])]); + let mut duplicate = d.clone(); + duplicate.items.push((Id::new("quads"), d.get("quads").unwrap().clone())); + for descriptor in [layout, wrong_target, bad_index, wrong_units, incompatible_topology, duplicate] { + let loaded = imported(descriptor.clone(), false, true); + assert_eq!(loaded.unsupported.len(), 1, "{descriptor:?}"); + assert_eq!(loaded.actions[0].steps[0].0, "actions.photoshopStep"); + assert_eq!(saved(&loaded.actions[0]).descriptor.unwrap().to_bytes(), descriptor.to_bytes()); + } +} + +/// Native export needs a reference rectangle. A stale recorded topology must not be substituted. +#[test] +fn native_export_requires_known_rectangle_and_rejects_stale_source() { + let mut action = Action::new("Warp", vec![(COMMAND.into(), json!({"planes": planes()}))]); + assert!(atn_cmds::export("Set", &[&action], &[], false).is_err()); + action.steps[0].1["__atnPerspectiveWarpRect"] = json!([0, 0, 32, 24]); + let d = saved(&action).descriptor.unwrap(); + let keys: Vec<_> = d.items.iter().map(|(id, _)| id.as_bytes()).collect(); + assert_eq!(keys, [b"null".as_slice(), b"Md ", b"referenceRect", b"vertices", b"warpedVertices", b"quads"]); + let mut recorded = imported(d, false, true).actions.remove(0); + recorded.steps[0].1["planes"][0]["dst"][0][0] = json!(6); + assert!(atn_cmds::export("Set", &[&recorded], &[], false).is_err()); + action.steps[0].1["interpolation"] = json!("nearest"); + assert!(atn_cmds::export("Set", &[&action], &[], false).is_err()); +} + +fn session(depth: u8) -> (Session, LayerId) { + let mut s = Session::new(); + s.execute("file.new", json!({"width":32,"height":24,"depth":depth})).unwrap(); + s.execute("layer.new.layer", json!({})).unwrap(); + let id = s.active().unwrap().active_layer.unwrap(); + s.edit("Fixture", |doc, _| { + let layer = doc.layer_mut(id).unwrap(); + layer.name = "Facade".into(); + let surf = layer.surface_mut().unwrap(); + let fmt = surf.format(); + surf.fill_rect(Rect::new(4, 4, 16, 20), &photocraft_raster::from_rgba(&fmt, [0.9, 0.2, 0.1, 1.0])); + surf.fill_rect(Rect::new(16, 4, 28, 20), &photocraft_raster::from_rgba(&fmt, [0.1, 0.2, 0.9, 1.0])); + Ok(()) + }) + .unwrap(); + (s, id) +} + +/// A named raster is warped, while the active decoy stays unchanged. +#[test] +fn action_playback_matches_the_native_raster_warp() { + for depth in [8, 16, 32] { + let (mut actual, id) = session(depth); + let (mut direct, did) = session(depth); + let before = actual.active().unwrap().doc.layer(id).unwrap().surface().unwrap().clone(); + for s in [&mut actual, &mut direct] { + s.execute("layer.new.layer", json!({})).unwrap(); + } + let decoy = actual.active().unwrap().active_layer.unwrap(); + let decoy_before = actual.active().unwrap().doc.layer(decoy).unwrap().clone(); + actual.actions.list.extend(imported(fixture(Some("Facade")), false, true).actions); + actual.execute("actions.play", json!({"action":0})).unwrap(); + direct.execute(COMMAND, json!({"planes":planes(),"layer":"Facade","target":"pixels"})).unwrap(); + let result = actual.active().unwrap().doc.layer(id).unwrap().surface().unwrap(); + assert_ne!(*result, before); + assert_eq!(result, direct.active().unwrap().doc.layer(did).unwrap().surface().unwrap()); + assert_eq!(actual.active().unwrap().doc.layer(decoy), Some(&decoy_before)); + actual.execute("edit.undo", json!({})).unwrap(); + assert_eq!(actual.active().unwrap().doc.layer(id).unwrap().surface(), Some(&before)); + } +} + +/// The same active-layer recording adds a native Smart Filter and keeps PSD export available. +#[test] +fn active_smart_object_playback_matches_the_native_filter() { + let (mut actual, _) = session(8); + let (mut direct, _) = session(8); + for s in [&mut actual, &mut direct] { + s.execute("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + } + actual.actions.list.extend(imported(fixture(None), false, true).actions); + actual.execute("actions.play", json!({"action":0})).unwrap(); + direct.execute("layer.smartObjects.perspectiveWarp", json!({"planes":planes()})).unwrap(); + let [actual, direct] = [&actual, &direct].map(|s| { + let st = s.active().unwrap(); + let LayerContent::Smart(sm) = &st.doc.layer(st.active_layer.unwrap()).unwrap().content else { panic!("smart object") }; + sm + }); + assert_eq!(actual.cache, direct.cache); + assert_eq!(actual.smart_filters.len(), 1); + assert_eq!(actual.smart_filters[0].command, COMMAND); + assert_eq!(actual.smart_filters[0].params["planes"], planes()); + assert!(photocraft_io::smart_map::item_for_filter(&actual.smart_filters[0]).is_ok()); +} diff --git a/crates/engine/tests/it/atn_stack_modes.rs b/crates/engine/tests/it/atn_stack_modes.rs new file mode 100644 index 0000000000..2de2d887df --- /dev/null +++ b/crates/engine/tests/it/atn_stack_modes.rs @@ -0,0 +1,243 @@ +//! The measured Smart Object Stack Mode events retain their descriptor and native behavior. + +use photocraft_doc::{Group, Layer, LayerContent, StackMode}; +use photocraft_engine::{Session, actions_cmds::Action, atn_cmds}; +use photocraft_geom::Rect; +use photocraft_psd::{ + atn::{self, AtnAction, AtnEvent, AtnFile, AtnItem}, + descriptor::{Class, Descriptor, Id, UnicodeString, Value as D}, +}; +use serde_json::json; + +const APPLY: &str = "applyImageStackPluginRenderer"; +const CLEAR: &str = "imageStackConvertSmartObject"; +const ORIGIN: &str = "_atnStackDescriptor"; + +/// Independent pairs from the measured table in docs/atn.md. +const MODES: &[(&str, &str, StackMode)] = &[ + ("rang", "Range", StackMode::Range), + ("entr", "Entropy", StackMode::Entropy), + ("kurt", "Kurtosis", StackMode::Kurtosis), + ("maxx", "Maximum", StackMode::Maximum), + ("medn", "Median", StackMode::Median), + ("minn", "Minimum", StackMode::Minimum), + ("avrg", "Mean", StackMode::Mean), + ("skew", "Skewness", StackMode::Skewness), + ("stdv", "Standard Deviation", StackMode::StandardDeviation), + ("summ", "Summation", StackMode::Summation), + ("vari", "Variance", StackMode::Variance), +]; + +fn descriptor(code: &str, name: &str) -> Descriptor { + Descriptor::new("null") + .with("imageStackPlugin", D::Class(Class { name: UnicodeString::new_nul(""), class_id: Id::new(code) })) + .with("Nm ", D::Text(UnicodeString::new_nul(name))) +} + +fn item(event: &str, descriptor: Option) -> AtnItem { + AtnItem { event: AtnEvent::name(event), descriptor, ..Default::default() } +} + +fn load(item: AtnItem) -> atn_cmds::Imported { + let file = AtnFile { + name: UnicodeString::new_nul("Stacks"), + actions: vec![AtnAction { name: UnicodeString::new_nul("Mode"), items: vec![item], ..Default::default() }], + ..Default::default() + }; + atn_cmds::import(&atn::write(&file).unwrap()).unwrap() +} + +fn saved(action: &Action) -> AtnItem { + let (bytes, skipped) = atn_cmds::export("Stacks", &[action], &[], false).unwrap(); + assert!(skipped.is_empty()); + atn::parse(&bytes).unwrap().actions.remove(0).items.remove(0) +} + +/// Exercise actual load/save bytes for all plugin classes and the separate None event. +#[test] +fn measured_stack_modes_and_none_import_export_and_reload() { + for &(code, name, mode) in MODES { + let original = item(APPLY, Some(descriptor(code, name))); + let imported = load(original.clone()); + assert!(imported.unsupported.is_empty()); + assert_eq!(imported.actions[0].steps, vec![(format!("layer.smartObjects.stackMode.{}", mode.id()), json!({}))]); + let out = saved(&imported.actions[0]); + assert_eq!(out.event, original.event); + assert_eq!(out.descriptor, original.descriptor); + assert_eq!(load(out).actions[0].steps, imported.actions[0].steps); + } + for original in [item(CLEAR, None), item(CLEAR, Some(Descriptor::new("null")))] { + let imported = load(original.clone()); + assert!(imported.unsupported.is_empty()); + assert_eq!(imported.actions[0].steps[0].0, "layer.smartObjects.stackMode.none"); + let out = saved(&imported.actions[0]); + assert_eq!(out.event, original.event); + assert_eq!(out.descriptor, original.descriptor); + assert_eq!(load(out).actions[0].steps, imported.actions[0].steps); + } + let native = Action::new("Mode", vec![("layer.smartObjects.stackMode.none".into(), json!({}))]); + let out = saved(&native); + assert_eq!(out.event, AtnEvent::name(CLEAR)); + assert!(out.descriptor.is_none()); +} + +/// Localized names and noncanonical wire metadata still replay the class-selected mode. +#[test] +fn localized_stack_descriptors_keep_original_metadata_and_flags() { + for name in [UnicodeString::new("Moyenne"), UnicodeString::new_nul("平均值"), UnicodeString(vec![0xd800, 0, 0])] { + let mut d = descriptor("avrg", "Mean"); + d.name = UnicodeString::new_nul("Recorded stack"); + d.class_id = Id::Str(b"null".to_vec()); + d.items[1].1 = D::Text(name); + d.items[1].0 = Id::Str(b"Nm ".to_vec()); + d.items.reverse(); + let mut original = item(APPLY, Some(d)); + original.enabled = false; + original.with_dialog = true; + original.dialog_options = 2; + let imported = load(original.clone()); + assert!(imported.unsupported.is_empty()); + assert_eq!(imported.actions[0].steps[0].0, "layer.smartObjects.stackMode.mean"); + let out = saved(&imported.actions[0]); + assert_eq!(out.descriptor, original.descriptor); + assert!(!out.enabled); + assert!(out.with_dialog); + assert_eq!(out.dialog_options, 2); + } + let mut d = Descriptor::new("null"); + d.name = UnicodeString(vec![0xd800, 0]); + d.class_id = Id::Str(b"null".to_vec()); + let imported = load(item(CLEAR, Some(d.clone()))); + assert!(imported.unsupported.is_empty()); + assert_eq!(saved(&imported.actions[0]).descriptor, Some(d)); +} + +fn stack(depth: u32) -> Session { + let mut s = Session::new(); + s.execute("file.new", json!({"width":3,"height":2,"depth":depth})).unwrap(); + s.edit("Fixture", |doc, active| { + let fmt = doc.pixel_format(); + let children = [0.2, 0.2, 0.8] + .into_iter() + .enumerate() + .map(|(index, value)| { + let mut layer = Layer::raster(format!("Frame {index}"), fmt); + let pixel = photocraft_raster::from_rgba(&fmt, [value, value, value, 1.0]); + layer.surface_mut().unwrap().write_region(Rect::new(0, 0, 3, 2), &pixel.repeat(6)); + layer + }) + .collect(); + let group = Layer::new("Stack", LayerContent::Group(Group { children, expanded: true, artboard: None, frame_stroke: None })); + let smart = photocraft_engine::smart_cmds::layer_to_smart(doc, &group)?; + *active = Some(smart.id); + doc.layers = vec![smart]; + Ok(()) + }) + .unwrap(); + s +} + +/// Compare the adapter with existing native commands, including pixel output and one Undo/Redo. +#[test] +fn stack_recordings_play_native_modes_and_undo_at_each_depth() { + for depth in [8, 16, 32] { + let mut s = stack(depth); + let modes = MODES.iter().map(|&(code, _, mode)| (item(APPLY, Some(descriptor(code, "Recorded name"))), Some(mode))); + let clear_forms = [None, Some(Descriptor::new("null"))].into_iter().map(|d| (item(CLEAR, d), None)); + for (source, mode) in modes.chain(clear_forms) { + let starting = if mode == Some(StackMode::Maximum) { "none" } else { "maximum" }; + s.execute(&format!("layer.smartObjects.stackMode.{starting}"), json!({})).unwrap(); + let before = s.active().unwrap().doc.clone(); + let before_steps = s.active().unwrap().history.past_len(); + let command = format!("layer.smartObjects.stackMode.{}", mode.map_or("none", StackMode::id)); + s.execute(&command, json!({})).unwrap(); + let expected = s.active().unwrap().doc.clone(); + s.execute("edit.undo", json!({})).unwrap(); + let imported = load(source); + s.actions.list = imported.actions; + let result = s.execute("actions.play", json!({"action":"Mode","set":"Stacks"})).unwrap(); + assert_eq!(result["ran"], 1, "{result}"); + let actual = s.active().unwrap(); + assert_eq!(actual.doc.layers, expected.layers, "{command} at {depth}-bit"); + assert_eq!(actual.history.past_len(), before_steps + 1); + s.execute("edit.undo", json!({})).unwrap(); + assert_eq!(s.active().unwrap().doc.layers, before.layers); + s.execute("edit.redo", json!({})).unwrap(); + assert_eq!(s.active().unwrap().doc.layers, expected.layers); + } + } +} + +/// Unrepresented types, duplicate keys and extra settings stay complete kept steps. +#[test] +fn unsupported_stack_recordings_save_whole_and_refuse_playback() { + let canonical = descriptor("medn", "Median"); + let mut duplicate = canonical.clone(); + duplicate.items.push(duplicate.items[0].clone()); + let mut wrong_name = canonical.clone(); + wrong_name.items[1].1 = D::Integer(5); + let mut global_class = canonical.clone(); + let D::Class(class) = global_class.items[0].1.clone() else { unreachable!() }; + global_class.items[0].1 = D::GlobalClass(class); + let extra = canonical.clone().with("unknown", D::Boolean(true)); + for original in [ + item(APPLY, Some(duplicate)), + item(APPLY, Some(wrong_name)), + item(APPLY, Some(global_class)), + item(APPLY, Some(extra)), + item(APPLY, Some(descriptor("nope", "Median"))), + item(APPLY, None), + item(CLEAR, Some(canonical)), + item(CLEAR, Some(Descriptor::new("nope"))), + ] { + let imported = load(original.clone()); + assert_eq!(imported.unsupported.len(), 1); + assert_eq!(imported.actions[0].steps[0].0, atn_cmds::PHOTOSHOP_STEP); + let out = saved(&imported.actions[0]); + assert_eq!(out.event, original.event); + assert_eq!(out.descriptor, original.descriptor); + let mut s = stack(8); + s.execute("layer.smartObjects.stackMode.maximum", json!({})).unwrap(); + let before = s.active().unwrap().doc.clone(); + let history = s.active().unwrap().history.past_len(); + s.actions.list = imported.actions; + let result = s.execute("actions.play", json!({"action":"Mode","set":"Stacks"})).unwrap(); + assert!(result.get("failed").is_some(), "{result}"); + assert_eq!(s.active().unwrap().doc.layers, before.layers); + assert_eq!(s.active().unwrap().history.past_len(), history); + } +} + +/// Native mode edits replace the old class; explicit targets and damaged origin metadata refuse export. +#[test] +fn stack_mode_edits_and_unrepresented_native_parameters_are_safe() { + let imported = load(item(APPLY, Some(descriptor("medn", "Médiane")))); + let mut action = imported.actions[0].clone(); + action.steps[0].0 = "layer.smartObjects.stackMode.maximum".into(); + assert_eq!(saved(&action).descriptor, Some(descriptor("maxx", "Maximum"))); + + action.steps[0].0 = "layer.smartObjects.stackMode.none".into(); + let cleared = saved(&action); + assert_eq!(cleared.event, AtnEvent::name(CLEAR)); + assert_eq!(cleared.descriptor, Some(Descriptor::new("null"))); + + let mut action = load(item(CLEAR, Some(Descriptor::new("null")))).actions.remove(0); + action.steps[0].0 = "layer.smartObjects.stackMode.mean".into(); + let applied = saved(&action); + assert_eq!(applied.event, AtnEvent::name(APPLY)); + assert_eq!(applied.descriptor, Some(descriptor("avrg", "Mean"))); + + let unknown_empty = photocraft_engine::paint::tile::b64_encode(&Descriptor::new("nope").to_bytes()); + let unknown_class = photocraft_engine::paint::tile::b64_encode(&descriptor("nope", "Mean").to_bytes()); + for command in ["layer.smartObjects.stackMode.mean", "layer.smartObjects.stackMode.none"] { + for params in [json!(null), json!([]), json!({"layer":12}), json!({"layer":"Named"}), json!({"target":"mask"}), json!({"unknown":true})] { + let action = Action::new("Mode", vec![(command.into(), params)]); + assert!(atn_cmds::export("Stacks", &[&action], &[], false).is_err()); + } + for origin in [json!(false), json!("!invalid-base64"), json!(""), json!(unknown_class), json!(unknown_empty)] { + let mut action = Action::new("Mode", vec![(command.into(), json!({}))]); + action.steps[0].1[ORIGIN] = origin; + assert!(atn_cmds::export("Stacks", &[&action], &[], false).is_err()); + } + } +} diff --git a/crates/engine/tests/it/atn_video_frames.rs b/crates/engine/tests/it/atn_video_frames.rs new file mode 100644 index 0000000000..43c9261ae1 --- /dev/null +++ b/crates/engine/tests/it/atn_video_frames.rs @@ -0,0 +1,224 @@ +//! #10723: recorded frame edits use the active video layer and the current playhead. +use photocraft_doc::{LayerContent, LayerId}; +use photocraft_engine::{Session, actions_cmds::Action, atn_cmds}; +use photocraft_psd::{ + atn::{self, AtnAction, AtnEvent, AtnFile, AtnItem}, + descriptor::{Descriptor, UnicodeString, Value as D}, +}; +use serde_json::json; +use std::sync::Arc; + +const EVENTS: [(&str, &str); 3] = [ + ("insertBlankFrame", "layer.videoLayers.insertBlankFrame"), + ("duplicateFrame", "layer.videoLayers.duplicateFrame"), + ("deleteFrame", "layer.videoLayers.deleteFrame"), +]; + +/// Build typed source fixtures without asking the mapper to generate its own oracle. +fn file(item: AtnItem) -> Vec { + atn::write(&AtnFile { + name: UnicodeString::new_nul("Video"), + actions: vec![AtnAction { name: UnicodeString::new_nul("Frame edit"), items: vec![item], ..Default::default() }], + ..Default::default() + }) + .unwrap() +} + +fn item(event: &str, descriptor: Option) -> AtnItem { + AtnItem { event: AtnEvent::name(event), descriptor, ..Default::default() } +} + +/// Exercise strict public export: skipping an unrepresentable step cannot pass this check. +fn saved(action: &Action) -> AtnItem { + let (bytes, skipped) = atn_cmds::export("Video", &[action], &[], false).unwrap(); + assert!(skipped.is_empty()); + atn::parse(&bytes).unwrap().actions[0].items[0].clone() +} + +/// Playback tests require a native mapping, rather than a successfully loaded kept step. +fn load(s: &mut Session, source: AtnItem) { + let bytes = file(source); + let report = s.execute("actions.load", json!({"data":photocraft_engine::paint::tile::b64_encode(&bytes)})).unwrap(); + assert_eq!(report["unsupported"], json!([])); +} + +/// Compare actual pixel markers; VideoData equality checks only stack shape. +fn pixels(s: &Session, id: LayerId, original: bool) -> Vec> { + let video = s.active().unwrap().doc.layer(id).unwrap().video.as_ref().unwrap(); + let frames = if original { video.original_frames.as_ref().unwrap() } else { &video.frames }; + frames.iter().map(|frame| frame.pixel(0, 0)).collect() +} + +/// Distinguish both frame order and original footage from the altered display cache. +fn fixture(depth: u32) -> (Session, LayerId) { + let mut s = Session::new(); + s.execute("file.new", json!({"width":2,"height":2,"depth":depth,"background":"transparent"})).unwrap(); + s.execute("timeline.create", json!({"duration":3,"fps":24})).unwrap(); + let result = s.execute("layer.videoLayers.newBlankVideoLayer", json!({})).unwrap(); + let id = LayerId(result["layer"].as_u64().unwrap()); + let state = s.active_mut().unwrap(); + let doc = Arc::make_mut(&mut state.doc); + let mut frames = Vec::new(); + for red in [0.25, 0.5, 0.75] { + let mut frame = photocraft_raster::Surface::new(doc.pixel_format()); + frame.write_pixel(0, 0, &[red, 0.0, 0.0, 1.0]); + frames.push(frame); + } + let layer = doc.layer_mut(id).unwrap(); + layer.content = LayerContent::Raster(frames[1].clone()); + let video = layer.video.as_mut().unwrap(); + video.original_frames = Some( + frames + .iter() + .rev() + .map(|frame| { + let mut original = frame.clone(); + let red = original.pixel(0, 0)[0]; + original.write_pixel(0, 0, &[red, 1.0, 0.0, 1.0]); + original + }) + .collect(), + ); + video.frames = frames; + let timeline = doc.timeline.as_mut().unwrap(); + timeline.current = 1; + timeline.work_start = 1; + timeline.work_end = 2; + (s, id) +} + +#[test] +/// Import's empty placeholder must not erase the wire's descriptor-presence distinction. +fn descriptors_and_step_flags_round_trip_including_an_absent_descriptor() { + for (event, command) in EVENTS { + for descriptor in [None, Some(Descriptor::default())] { + for enabled in [false, true] { + let mut source = item(event, descriptor.clone()); + source.enabled = enabled; + source.with_dialog = true; + let imported = atn_cmds::import(&file(source)).unwrap(); + assert!(imported.unsupported.is_empty()); + let action = &imported.actions[0]; + assert_eq!(action.steps[0].0, command); + assert_eq!(action.disabled.contains(&0), !enabled); + assert!(action.dialogs.contains(&0)); + let back = saved(action); + assert_eq!(back.event, AtnEvent::name(event)); + assert_eq!(back.descriptor, descriptor); + assert_eq!(back.enabled, enabled); + assert!(back.with_dialog); + } + } + } +} + +#[test] +/// One recorded command must change the correct stack position and remain one undoable edit. +fn playback_edits_the_current_frame_and_original_stack_with_undo_redo_at_each_depth() { + for (depth, has_descriptor) in [(8, true), (16, true), (32, true), (8, false)] { + for (event, _) in EVENTS { + let (mut s, id) = fixture(depth); + let before = pixels(&s, id, false); + let originals = pixels(&s, id, true); + let timeline = s.active().unwrap().doc.timeline.clone(); + let expected = |frames: &[Vec]| match event { + "insertBlankFrame" => vec![frames[0].clone(), frames[1].clone(), vec![0.0; 4], frames[2].clone()], + "duplicateFrame" => vec![frames[0].clone(), frames[1].clone(), frames[1].clone(), frames[2].clone()], + "deleteFrame" => vec![frames[0].clone(), frames[2].clone()], + _ => panic!("fixture event"), + }; + load(&mut s, item(event, has_descriptor.then(Descriptor::default))); + let report = s.execute("actions.play", json!({"action":0})).unwrap(); + assert!(report.get("failed").is_none(), "{depth}/{event}: {report}"); + assert_eq!(report["ran"], 1); + assert_eq!(pixels(&s, id, false), expected(&before), "{depth}/{event}"); + assert_eq!(pixels(&s, id, true), expected(&originals), "original {depth}/{event}"); + let t = s.active().unwrap().doc.timeline.as_ref().unwrap(); + assert_eq!((t.current, t.work_start, t.work_end), (1, 1, 2)); + assert_eq!(t.duration, if event == "deleteFrame" { 3 } else { 4 }); + let LayerContent::Raster(display) = &s.active().unwrap().doc.layer(id).unwrap().content else { panic!("video display") }; + assert_eq!(display.pixel(0, 0), expected(&before)[1]); + s.execute("history.undo", json!({})).unwrap(); + assert_eq!(pixels(&s, id, false), before); + assert_eq!(pixels(&s, id, true), originals); + assert_eq!(s.active().unwrap().doc.timeline, timeline); + s.execute("history.redo", json!({})).unwrap(); + assert_eq!(pixels(&s, id, false), expected(&before)); + assert_eq!(pixels(&s, id, true), expected(&originals)); + } + } +} + +#[test] +/// The native last-frame protection must also hold through recorded playback. +fn deleting_the_last_frame_keeps_its_pixels() { + let (mut s, id) = fixture(8); + let state = s.active_mut().unwrap(); + let doc = Arc::make_mut(&mut state.doc); + let layer = doc.layer_mut(id).unwrap(); + let video = layer.video.as_mut().unwrap(); + video.frames.truncate(1); + video.original_frames.as_mut().unwrap().truncate(1); + layer.content = LayerContent::Raster(video.frames[0].clone()); + let t = doc.timeline.as_mut().unwrap(); + *t = photocraft_doc::video::Timeline::new(1, 24.0); + let before = pixels(&s, id, false); + let original = pixels(&s, id, true); + load(&mut s, item("deleteFrame", Some(Descriptor::default()))); + let report = s.execute("actions.play", json!({"action":0})).unwrap(); + assert!(report.get("failed").is_none(), "{report}"); + assert_eq!(pixels(&s, id, false), before); + assert_eq!(pixels(&s, id, true), original); +} + +#[test] +/// Recognizing an event name must never discard settings or reinterpret its unknown header. +fn unrepresented_settings_and_descriptor_metadata_stay_complete_kept_steps() { + let named = Descriptor { name: UnicodeString::new_nul("Unmeasured metadata"), ..Default::default() }; + for (event, _) in EVENTS { + for descriptor in [Descriptor::default().with("frame", D::Integer(2)), Descriptor::new("other"), named.clone()] { + let imported = atn_cmds::import(&file(item(event, Some(descriptor.clone())))).unwrap(); + assert_eq!(imported.unsupported.len(), 1); + assert_eq!(imported.actions[0].steps[0].0, "actions.photoshopStep"); + assert_eq!(saved(&imported.actions[0]).descriptor, Some(descriptor)); + } + } +} + +#[test] +/// Current-frame recordings cannot serialize an explicit frame, layer or mask selector. +fn native_options_and_damaged_absence_metadata_refuse_export() { + for (_, command) in EVENTS { + for params in [ + json!({"frame":2}), + json!({"layer":3}), + json!({"target":"mask"}), + json!({"_atnVideoFrameNoDescriptor":false}), + json!({"_atnVideoFrameNoDescriptor":"true"}), + ] { + let action = Action::new("Invalid", vec![(command.into(), params)]); + assert!(atn_cmds::export("Video", &[&action], &[], false).is_err(), "{command}"); + } + } +} + +#[test] +/// Mapping a known event cannot bypass the native video-target precondition. +fn playback_without_a_video_target_fails_without_editing_a_document() { + for (event, _) in EVENTS { + for document in [false, true] { + let mut s = Session::new(); + if document { + s.execute("file.new", json!({"width":2,"height":2})).unwrap(); + } + let before = s.active().map(|state| state.doc.clone()); + load(&mut s, item(event, Some(Descriptor::default()))); + let report = s.execute("actions.play", json!({"action":0})).unwrap(); + assert!(report.get("failed").is_some(), "{event}: {report}"); + match before { + Some(before) => assert!(Arc::ptr_eq(&before, &s.active().unwrap().doc)), + None => assert!(s.active().is_none()), + } + } + } +} diff --git a/crates/engine/tests/it/crop_content_aware_layers.rs b/crates/engine/tests/it/crop_content_aware_layers.rs new file mode 100644 index 0000000000..bd3ee0db2c --- /dev/null +++ b/crates/engine/tests/it/crop_content_aware_layers.rs @@ -0,0 +1,392 @@ +//! #10868: crop fill samples the Background and editable active raster independently. + +use photocraft_doc::{Document, Layer, LayerContent, LayerId, TextLayer}; +use photocraft_engine::Session; +use photocraft_geom::Rect; +use serde_json::{Value, json}; + +const WHITE: [f32; 4] = [1.0, 1.0, 1.0, 1.0]; +const RED: [f32; 4] = [1.0, 0.0, 0.0, 1.0]; +const GREEN: [f32; 4] = [0.0, 1.0, 0.0, 1.0]; +const BLUE: [f32; 4] = [0.0, 0.0, 1.0, 1.0]; +const YELLOW: [f32; 4] = [1.0, 1.0, 0.0, 1.0]; + +struct Layers { + background: LayerId, + quads: LayerId, + small: LayerId, + edge: LayerId, + hidden: LayerId, + text: LayerId, +} + +fn doc(s: &Session) -> &Document { + &s.active().unwrap().doc +} + +fn raster(d: &Document, name: &str, bounds: Rect, color: [f32; 4]) -> Layer { + let fmt = d.pixel_format(); + let mut layer = Layer::raster(name, fmt); + layer.surface_mut().unwrap().fill_rect(bounds, &photocraft_raster::from_rgba(&fmt, color)); + layer +} + +/// Keeps the measured straight geometry and fits turned controls under the 1 MiB transform limit +/// that the preference test can set process-wide. +fn scene_divisor(turned: bool) -> i32 { + if turned { 2 } else { 1 } +} + +/// The measured scene, with a deliberately different crop extension colour. +fn scene(turned: bool) -> (Session, Layers) { + let divisor = scene_divisor(turned); + let rect = |x0, y0, x1, y1| Rect::new(x0 / divisor, y0 / divisor, x1 / divisor, y1 / divisor); + let mut s = Session::new(); + s.execute("file.new", json!({"width":800/divisor,"height":500/divisor,"depth":8,"background":"white"})).unwrap(); + s.execute("tools.setColors", json!({"background":"#ff00ff"})).unwrap(); + let ids = s + .edit("Fixture", |d, _| { + let background = d.background().unwrap().id; + let mut quads = raster(d, "Quads", rect(0, 0, 800, 500), RED); + let fmt = d.pixel_format(); + let surf = quads.surface_mut().unwrap(); + for (bounds, color) in [(rect(400, 0, 800, 250), GREEN), (rect(0, 250, 400, 500), BLUE), (rect(400, 250, 800, 500), YELLOW)] { + surf.fill_rect(bounds, &photocraft_raster::from_rgba(&fmt, color)); + } + let small = raster(d, "Small", rect(350, 200, 450, 300), RED); + let edge = raster(d, "EdgeHalf", rect(600, 0, 800, 250), BLUE); + let mut hidden = raster(d, "Hidden", rect(0, 0, 800, 500), RED); + hidden.visible = false; + let text = Layer::new("T", LayerContent::Text(TextLayer { text: "T".into(), ..Default::default() })); + let ids = Layers { background, quads: quads.id, small: small.id, edge: edge.id, hidden: hidden.id, text: text.id }; + d.layers.extend([quads, small, edge, hidden, text]); + Ok(ids) + }) + .unwrap(); + (s, ids) +} + +fn select(s: &mut Session, id: LayerId) { + s.execute("layer.select", json!({"layer":id.0})).unwrap(); +} + +/// Extends the frame to the right by one eighth of the original width. +fn frame(turned: bool) -> Value { + let divisor = scene_divisor(turned); + json!({"x":0,"y":0,"width":900/divisor,"height":500/divisor,"angle":if turned { 10 } else { 0 },"deleteCroppedPixels":true}) +} + +/// Samples the same relative point inside the new strip in both fixture sizes. +fn extension_sample(turned: bool) -> (i32, i32) { + let divisor = scene_divisor(turned); + (850 / divisor, 400 / divisor) +} + +fn crop(s: &mut Session, mut p: Value, aware: bool) { + p["contentAware"] = json!(aware); + s.execute("image.crop", p).unwrap(); +} + +fn plain_control(s: &mut Session, p: &Value) -> Document { + crop(s, p.clone(), false); + let plain = doc(s).clone(); + s.execute("edit.undo", json!({})).unwrap(); + plain +} + +/// Checks donor colour with room for the resampling and synthesis tolerance. +fn pixel(d: &Document, id: LayerId, x: i32, y: i32, want: [f32; 4]) { + let actual = d.layer(id).unwrap().surface().unwrap().rgba(x, y); + assert!(actual.iter().zip(want).all(|(a, b)| (a - b).abs() < 0.06), "layer {id:?} at ({x},{y}): {actual:?}, expected {want:?}"); +} + +/// Compares complete layers with plain crop, including any legitimate turn or clipping. +fn unchanged(d: &Document, plain: &Document, ids: &[LayerId]) { + for id in ids { + // Includes bounds, pixels and metadata; turned crops legitimately transform these layers. + assert_eq!(d.layer(*id), plain.layer(*id), "non-target {id:?} differs from plain crop"); + } +} + +/// Every pixel of `id` inside `area` (the old canvas) is the plain crop's. +fn covered_as_plain(d: &Document, plain: &Document, id: LayerId, area: Rect) { + let (got, want) = (d.layer(id).unwrap().surface().unwrap(), plain.layer(id).unwrap().surface().unwrap()); + for y in (area.y0..area.y1).step_by(7) { + for x in (area.x0..area.x1).step_by(7) { + assert_eq!(got.rgba(x, y), want.rgba(x, y), "layer {id:?} at ({x},{y}) differs from the plain crop"); + } + } +} + +fn named_one_step(s: &Session, past: usize, name: &str) { + let st = s.active().unwrap(); + assert_eq!(st.history.past_len(), past + 1); + assert_eq!(st.history.undo_label(), Some(name)); +} + +fn undo_redo(s: &mut Session, before: &Document) { + let after = doc(s).clone(); + s.execute("edit.undo", json!({})).unwrap(); + assert_eq!(doc(s), before); + s.execute("edit.redo", json!({})).unwrap(); + assert_eq!(doc(s), &after); + assert_eq!(s.active().unwrap().history.undo_label(), Some("Content-aware Crop")); +} + +/// Matches the three measured rows at their original size, bounds and sample points. +#[test] +fn measured_straight_rows_fill_background_and_only_the_active_raster() { + for row in 0..3 { + let (mut s, ids) = scene(false); + let active = if row == 1 { ids.edge } else { ids.quads }; + if row == 2 { + s.edit("Layer 0", |d, _| { + let bg = d.layer_mut(ids.background).unwrap(); + bg.name = "Layer 0".into(); + bg.locks = Default::default(); + Ok(()) + }) + .unwrap(); + } + select(&mut s, active); + let before = doc(&s).clone(); + let p = frame(false); + let plain = plain_control(&mut s, &p); + let past = s.active().unwrap().history.past_len(); + crop(&mut s, p, true); + let d = doc(&s); + assert_eq!((d.size.width, d.size.height), (900, 500)); + let mut untouched = vec![ids.small, ids.hidden, ids.text]; + untouched.push(if row == 1 { ids.quads } else { ids.edge }); + if row == 2 { + assert!(d.background().is_none()); + untouched.push(ids.background); + } else { + assert_eq!(d.layer(ids.background).unwrap().surface().unwrap().content_bounds(), Rect::new(0, 0, 900, 500)); + pixel(d, ids.background, 850, 400, WHITE); + } + let bounds = if row == 1 { Rect::new(600, 0, 900, 500) } else { Rect::new(0, 0, 900, 500) }; + assert_eq!(d.layer(active).unwrap().surface().unwrap().content_bounds(), bounds); + pixel(d, active, 850, if row == 1 { 400 } else { 125 }, if row == 1 { BLUE } else { GREEN }); + // The fill adds pixels only where the crop uncovered the canvas: the active layer's own + // pixels inside the old canvas are the plain crop's. + covered_as_plain(d, &plain, active, Rect::new(0, 0, 800, 500)); + unchanged(d, &plain, &untouched); + named_one_step(&s, past, "Content-aware Crop"); + undo_redo(&mut s, &before); + } +} + +/// Checks own-layer donors and exact non-target parity after rotation. +#[test] +fn turned_rows_sample_each_target_and_leave_other_layers_at_plain_crop() { + let (x, y) = extension_sample(true); + for row in 0..3 { + let (mut s, ids) = scene(true); + // Uniform donors isolate target selection from the existing turned-fill sampling policy. + s.edit("Uniform Quads", |d, _| { + let fmt = d.pixel_format(); + let bounds = d.bounds(); + d.layer_mut(ids.quads).unwrap().surface_mut().unwrap().fill_rect(bounds, &photocraft_raster::from_rgba(&fmt, GREEN)); + if row == 2 { + d.layer_mut(ids.background).unwrap().locks = Default::default(); + } + Ok(()) + }) + .unwrap(); + let active = if row == 1 { ids.edge } else { ids.quads }; + select(&mut s, active); + let before = doc(&s).clone(); + let p = frame(true); + let plain = plain_control(&mut s, &p); + let past = s.active().unwrap().history.past_len(); + let mut p = p; + p["contentAware"] = json!(true); + s.execute("image.crop", p).unwrap_or_else(|error| panic!("turned row {row}, active {active:?}: {error}")); + let d = doc(&s); + pixel(d, active, x, y, if row == 1 { BLUE } else { GREEN }); + assert!(d.layer(active).unwrap().surface().unwrap().content_bounds().contains(x, y)); + let mut untouched = vec![ids.small, ids.hidden, ids.text, if row == 1 { ids.quads } else { ids.edge }]; + if row == 2 { + untouched.push(ids.background); + } else { + pixel(d, ids.background, x, y, WHITE); + } + unchanged(d, &plain, &untouched); + named_one_step(&s, past, "Content-aware Crop"); + undo_redo(&mut s, &before); + } +} + +/// Selecting the Background leaves each other layer identical to its plain crop. +#[test] +fn background_active_is_not_a_second_target() { + for turned in [false, true] { + let (x, y) = extension_sample(turned); + let (mut s, ids) = scene(turned); + select(&mut s, ids.background); + let p = frame(turned); + let plain = plain_control(&mut s, &p); + let past = s.active().unwrap().history.past_len(); + crop(&mut s, p, true); + pixel(doc(&s), ids.background, x, y, WHITE); + unchanged(doc(&s), &plain, &[ids.quads, ids.small, ids.edge, ids.hidden, ids.text]); + named_one_step(&s, past, "Content-aware Crop"); + } +} + +/// Verifies Background-only fill for ineligible active layers and Delete Cropped Pixels off. +#[test] +fn unmeasured_active_targets_and_delete_off_keep_the_legacy_target() { + for turned in [false, true] { + let (x, y) = extension_sample(turned); + for case in 0..10 { + let (mut s, ids) = scene(turned); + let active = match case { + 0 => ids.text, + 1 => ids.hidden, + _ => ids.quads, + }; + if (2..7).contains(&case) { + s.edit("Lock active", |d, _| { + assert!(d.layer_mut(active).unwrap().locks.set(["all", "pixels", "transparency", "position", "artboard"][case - 2], true)); + Ok(()) + }) + .unwrap(); + } + if case >= 8 { + s.edit("Group active", |d, _| { + let i = d.layers.iter().position(|layer| layer.id == active).unwrap(); + let child = d.layers.remove(i); + let mut group = Layer::group("Ancestor", vec![child]); + if case == 8 { + group.visible = false; + } else { + assert!(group.locks.set("pixels", true)); + } + d.layers.insert(i, group); + Ok(()) + }) + .unwrap(); + } + select(&mut s, active); + let mut p = frame(turned); + if case == 7 { + p["deleteCroppedPixels"] = json!(false); + } + let plain = plain_control(&mut s, &p); + crop(&mut s, p, true); + pixel(doc(&s), ids.background, x, y, WHITE); + unchanged(doc(&s), &plain, &[ids.quads, ids.small, ids.edge, ids.hidden, ids.text]); + } + } +} + +/// Checks the plain history name for interior crops and crops with synthesis disabled. +#[test] +fn no_fill_or_content_aware_off_keeps_the_crop_history_name() { + for (p, aware, turned) in [ + (json!({"x":20,"y":20,"width":40,"height":30}), true, false), + (json!({"x":20,"y":20,"width":40,"height":30,"angle":10}), true, true), + (frame(false), false, false), + (frame(true), false, true), + ] { + let (mut s, ids) = scene(turned); + select(&mut s, ids.quads); + let past = s.active().unwrap().history.past_len(); + crop(&mut s, p, aware); + named_one_step(&s, past, "Crop"); + } +} + +/// Gives exactly one target a strip of held pixels outside the original canvas. +fn overhang_scene(held_active: bool) -> (Session, LayerId, LayerId) { + let mut s = Session::new(); + s.execute("file.new", json!({"width":64,"height":48,"background":"white"})).unwrap(); + s.execute("tools.setColors", json!({"background":"#ff00ff"})).unwrap(); + let (bg, active) = s + .edit("Distinct hidden pixels", |d, active| { + let bg = d.background().unwrap().id; + let mut layer = raster(d, "Active", Rect::new(0, 0, 64, 48), GREEN); + let fmt = d.pixel_format(); + let surf = if held_active { layer.surface_mut().unwrap() } else { d.layer_mut(bg).unwrap().surface_mut().unwrap() }; + surf.fill_rect(Rect::new(-16, 0, 0, 48), &photocraft_raster::from_rgba(&fmt, if held_active { BLUE } else { RED })); + let id = layer.id; + d.layers.push(layer); + *active = Some(id); + Ok((bg, id)) + }) + .unwrap(); + (s, bg, active) +} + +/// Confirms that held pixels protect only the layer that owned them before the turn. +#[test] +fn turned_hidden_overhang_coverage_belongs_to_each_layer() { + for held_active in [false, true] { + let (mut s, bg, active) = overhang_scene(held_active); + crop(&mut s, json!({"x":-10,"y":14,"width":20,"height":20,"angle":45}), true); + let mut held_pixels = 0; + for y in 0..20 { + for x in 0..20 { + let (held, other, want) = if held_active { (active, bg, WHITE) } else { (bg, active, GREEN) }; + pixel(doc(&s), other, x, y, want); + let px = doc(&s).layer(held).unwrap().surface().unwrap().rgba(x, y); + let color = if held_active { BLUE } else { RED }; + held_pixels += usize::from(px.iter().zip(color).all(|(a, b)| (a - b).abs() < 0.06)); + } + } + assert!(held_pixels >= 100, "the target's own hidden pixels survive: {held_pixels}"); + } +} + +/// An empty active raster leaves the successful Background fill and undo step intact. +#[test] +fn donorless_added_target_keeps_the_background_fill() { + for turned in [false, true] { + let (x, y) = extension_sample(turned); + let (mut s, ids) = scene(turned); + let empty = s + .edit("Empty target", |d, active| { + let layer = Layer::raster("Empty", d.pixel_format()); + let id = layer.id; + d.layers.push(layer); + *active = Some(id); + Ok(id) + }) + .unwrap(); + assert_ne!(empty, ids.background); + let before = doc(&s).clone(); + let p = frame(turned); + let plain = plain_control(&mut s, &p); + let past = s.active().unwrap().history.past_len(); + crop(&mut s, p, true); + pixel(doc(&s), ids.background, x, y, WHITE); + unchanged(doc(&s), &plain, &[empty, ids.quads, ids.small, ids.edge, ids.hidden, ids.text]); + assert_eq!(s.active().unwrap().active_layer, Some(empty)); + named_one_step(&s, past, "Content-aware Crop"); + undo_redo(&mut s, &before); + } +} + +/// Confirms both layers synthesize their own colours at every RGB depth. +#[test] +fn both_target_colours_remain_native_at_each_rgb_depth() { + for depth in [8, 16, 32] { + let mut s = Session::new(); + s.execute("file.new", json!({"width":32,"height":24,"depth":depth,"background":"white"})).unwrap(); + let (bg, active) = s + .edit("Own colours", |d, active| { + let bg = d.background().unwrap().id; + let layer = raster(d, "Green", Rect::new(0, 0, 32, 24), GREEN); + let id = layer.id; + d.layers.push(layer); + *active = Some(id); + Ok((bg, id)) + }) + .unwrap(); + crop(&mut s, json!({"x":0,"y":0,"width":40,"height":24}), true); + pixel(doc(&s), bg, 36, 12, WHITE); + pixel(doc(&s), active, 36, 12, GREEN); + } +} diff --git a/crates/engine/tests/it/main.rs b/crates/engine/tests/it/main.rs index c65e58ddca..7cad24d146 100644 --- a/crates/engine/tests/it/main.rs +++ b/crates/engine/tests/it/main.rs @@ -13,15 +13,18 @@ mod atn_dialog_filters; mod atn_direct_adjustments; mod atn_layer_style; mod atn_newer_events; +mod atn_perspective_warp; mod atn_reference_forms; mod atn_review_regressions; mod atn_ripple_amount; mod atn_selective_color; mod atn_shape_blur; mod atn_shear; +mod atn_stack_modes; mod atn_stroke_width; mod atn_type_path; mod atn_v12; +mod atn_video_frames; mod background_and_mask_depth; mod background_layer_consistency; mod brush_smoothing; @@ -35,6 +38,7 @@ mod convert_keeps_references; mod copy_shape_placement; mod corpus_atn; mod crop_content_aware; +mod crop_content_aware_layers; mod crop_delete_off_background; mod current_affinity_artboards; mod duplicate_layer_comps; diff --git a/crates/io/src/perspective_warp_map.rs b/crates/io/src/perspective_warp_map.rs index 654de23b32..cb5815bb81 100644 --- a/crates/io/src/perspective_warp_map.rs +++ b/crates/io/src/perspective_warp_map.rs @@ -38,7 +38,7 @@ const FILTER_ID: i32 = 1023; const NAME: &str = "Perspective Warp..."; pub(super) const TEMPLATE_KEY: &str = "__perspectiveWarpPsd"; /// Far more planes than anyone lays out by hand; bounds the corner linking (quadratic). -const MAX_QUADS: usize = 256; +pub const MAX_QUADS: usize = 256; const MAX_VERTICES: usize = 4 * MAX_QUADS; const MAX_TEMPLATE_BYTES: usize = 1 << 20; @@ -74,29 +74,29 @@ fn quads(f: &Descriptor) -> Option> { .map(|q| { let Value::Descriptor(q) = q else { return None }; let Some(Value::List(ix)) = q.get("indices") else { return None }; - let ix: Vec = ix - .iter() - .map(|i| match i { - Value::Integer(i) => usize::try_from(*i).ok(), - _ => None, - }) - .collect::>()?; - ix.try_into().ok() + let [Value::Integer(a), Value::Integer(b), Value::Integer(c), Value::Integer(d)] = ix.as_slice() else { return None }; + Some([usize::try_from(*a).ok()?, usize::try_from(*b).ok()?, usize::try_from(*c).ok()?, usize::try_from(*d).ok()?]) }) .collect() } -/// The planes a `perspectiveWarpTransform` descriptor describes; `None` when it is inconsistent. -fn planes_of(f: &Descriptor) -> Option> { +/// Reads the document-space planes and original corner indices from Perspective Warp geometry. +/// Callers validate the enclosing descriptor and target according to the file format. +pub fn indexed_geometry(f: &Descriptor) -> Option<(Vec, Vec<[usize; 4]>)> { let (src, dst) = (points(f, "vertices")?, points(f, "warpedVertices")?); if src.len() != dst.len() { return None; } let corners = |list: &[[f64; 2]], q: &[usize; 4]| -> Option<[[f64; 2]; 4]> { Some([*list.get(q[0])?, *list.get(q[1])?, *list.get(q[2])?, *list.get(q[3])?]) }; - let planes: Vec = quads(f)?.iter().map(|q| Some(Plane { src: corners(&src, q)?, dst: corners(&dst, q)? })).collect::>()?; + let indices = quads(f)?; + let planes: Vec = indices.iter().map(|q| Some(Plane { src: corners(&src, q)?, dst: corners(&dst, q)? })).collect::>()?; PerspectiveMap::new(&planes)?; - Some(planes) + Some((planes, indices)) +} + +fn planes_of(f: &Descriptor) -> Option> { + indexed_geometry(f).map(|(planes, _)| planes) } /// `layer.smartObjects.perspectiveWarp` params for a Perspective Warp item. @@ -137,7 +137,8 @@ fn template(params: &J) -> Result, String> { /// The planes to write: as rendered, so a `straighten` is baked in. fn export_planes(params: &J) -> Result, String> { let object = params.as_object().ok_or("Perspective Warp parameters must be an object")?; - if let Some(k) = object.keys().find(|k| !super::is_meta(k) && !["planes", "straighten", "interpolation"].contains(&k.as_str())) { + let supported = |k: &str| super::is_meta(k) || ["planes", "straighten", "interpolation"].contains(&k) || (k == "target" && params["target"] == "pixels"); + if let Some(k) = object.keys().find(|k| !supported(k)) { return Err(format!("Perspective Warp setting `{k}` has no PSD equivalent")); } let mut planes: Vec = @@ -161,7 +162,7 @@ fn pnt(p: [f64; 2]) -> Value { /// `vertices`, `warpedVertices` and `quads` for `planes`; a corner shared by several planes (same /// layout and warped position) is written once. -fn geometry(planes: &[Plane]) -> (Value, Value, Value) { +pub fn geometry(planes: &[Plane]) -> (Value, Value, Value) { let mut corners: Vec<([f64; 2], [f64; 2])> = Vec::new(); let mut quads = Vec::with_capacity(planes.len()); for p in planes { diff --git a/crates/io/src/smart_map.rs b/crates/io/src/smart_map.rs index cacce2b7cb..3b19606c94 100644 --- a/crates/io/src/smart_map.rs +++ b/crates/io/src/smart_map.rs @@ -51,6 +51,9 @@ mod hue_sat; mod perspective_warp; pub use displace::{embed_map as displace_embed_map, embedded_map as displace_embedded_map, without_map as displace_without_map}; +pub use perspective_warp::{ + MAX_QUADS as MAX_PERSPECTIVE_WARP_PLANES, geometry as perspective_warp_geometry, indexed_geometry as perspective_warp_indexed_geometry, +}; mod export; mod import; diff --git a/crates/ui-egui/src/app/commands.rs b/crates/ui-egui/src/app/commands.rs index df4bc77986..12f3274046 100644 --- a/crates/ui-egui/src/app/commands.rs +++ b/crates/ui-egui/src/app/commands.rs @@ -313,6 +313,8 @@ impl PhotocraftApp { self.ui.selected_path = None; } self.path_document = document; + // A shape box handle drag belongs to its document, revision and tool. + crate::shape_bounds_box::cancel_stale(self); vector_ui::cancel_stale_pen(self); crate::direct_select::cancel_stale(self); canvas::cancel_stale_vector_drag(self); diff --git a/crates/ui-egui/src/artboard_add_mode_tests.rs b/crates/ui-egui/src/artboard_add_mode_tests.rs new file mode 100644 index 0000000000..3b98287d41 --- /dev/null +++ b/crates/ui-egui/src/artboard_add_mode_tests.rs @@ -0,0 +1,219 @@ +//! The Artboard tool's Add New Artboard placing mode (#11386): with the mode on, a click on empty +//! canvas puts a board of the bar's size with its top-left corner at the click. + +use egui::Modifiers; +use photocraft_geom::Rect; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::{ToolEvent, tool_event}; +use crate::state::Tool; + +/// The measured document: two boards, the 750 x 1334 one selected, the other one apart from it. +fn app_with_selected_board() -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 800, "height": 600, "background": "white"})).unwrap(); + app.run("layer.new.artboard", json!({"rect": [2000, 0, 300, 300]})).unwrap(); + app.run("layer.new.artboard", json!({"rect": [900, 0, 750, 1334]})).unwrap(); + app.sync_views(); + app.ui.extras.snap = false; + app.ui.view.show.smart_guides = false; + app.ui.tool = Tool::Artboard; + app +} + +fn click(app: &mut PhotocraftApp, x: f64, y: f64) { + let m = Modifiers::NONE; + tool_event(app, ToolEvent::Down { x, y, pressure: 1.0 }, m); + tool_event(app, ToolEvent::Up { x, y }, m); +} + +fn boards(app: &PhotocraftApp) -> Vec { + app.session.active().unwrap().doc.artboards().iter().map(|b| b.2.rect).collect() +} + +fn last_step(app: &PhotocraftApp) -> Option { + app.session.active().unwrap().history.entries().last().cloned() +} + +#[test] +fn a_click_with_the_mode_on_puts_a_bar_sized_board_at_the_click() { + let mut app = app_with_selected_board(); + app.ui.artboard_tool.adding = true; + let before = boards(&app); + click(&mut app, 222.0, 600.0); + assert!(!app.ui.status_error, "{}", app.ui.status); + let after = boards(&app); + assert_eq!(after.len(), before.len() + 1); + // 750 x 1334, top-left at the click, over the selected board (it did not move aside). + assert_eq!(after.last().copied(), Some(Rect::new(222, 600, 972, 1934))); + assert_eq!(after.get(..before.len()), Some(before.as_slice())); + let st = app.session.active().unwrap(); + assert_eq!(st.doc.layers.last().map(|l| l.name.as_str()), Some("Artboard 3")); + assert_eq!(st.active_layer, Some(st.doc.artboards().last().unwrap().0)); + assert_eq!(last_step(&app).as_deref(), Some("New Artboard")); + // One undo step. + app.run("edit.undo", json!({})).unwrap(); + assert_eq!(boards(&app), before); +} + +#[test] +fn the_click_is_rounded_to_whole_pixels() { + let mut app = app_with_selected_board(); + app.ui.artboard_tool.adding = true; + click(&mut app, 222.4, 600.6); + assert_eq!(boards(&app).last().copied(), Some(Rect::new(222, 601, 972, 1935))); +} + +#[test] +fn the_mode_stays_on_after_a_board_is_placed() { + let mut app = app_with_selected_board(); + app.ui.artboard_tool.adding = true; + click(&mut app, 222.0, 600.0); + assert!(app.ui.artboard_tool.adding); + // The next click is another placement, at the new selected board's size. + click(&mut app, 3000.0, 100.0); + assert_eq!(boards(&app).last().copied(), Some(Rect::new(3000, 100, 3750, 1434))); +} + +#[test] +fn a_click_with_the_mode_off_still_places_nothing() { + let mut app = app_with_selected_board(); + let before = boards(&app); + click(&mut app, 222.0, 600.0); + assert_eq!(boards(&app), before); +} + +#[test] +fn with_no_board_the_click_uses_the_canvas_size() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 800, "height": 600, "background": "white"})).unwrap(); + app.sync_views(); + app.ui.tool = Tool::Artboard; + app.ui.artboard_tool.adding = true; + click(&mut app, 40.0, 50.0); + assert_eq!(boards(&app), vec![Rect::new(40, 50, 840, 650)]); +} + +#[test] +fn a_drag_with_the_mode_on_still_draws_the_dragged_board() { + let mut app = app_with_selected_board(); + app.ui.artboard_tool.adding = true; + let m = Modifiers::NONE; + tool_event(&mut app, ToolEvent::Down { x: 20.0, y: 30.0, pressure: 1.0 }, m); + tool_event(&mut app, ToolEvent::Move { x: 80.0, y: 70.0, pressure: 1.0 }, m); + tool_event(&mut app, ToolEvent::Move { x: 120.0, y: 110.0, pressure: 1.0 }, m); + tool_event(&mut app, ToolEvent::Up { x: 120.0, y: 110.0 }, m); + assert_eq!(boards(&app).last().copied(), Some(Rect::new(20, 30, 120, 110))); +} + +#[test] +fn a_click_on_an_existing_board_selects_it_and_places_nothing() { + let mut app = app_with_selected_board(); + app.ui.artboard_tool.adding = true; + let before = boards(&app); + click(&mut app, 2100.0, 100.0); + assert_eq!(boards(&app), before); + let st = app.session.active().unwrap(); + assert_eq!(st.active_layer, Some(st.doc.artboards()[0].0)); +} + +#[test] +fn another_tool_turns_the_mode_off() { + let mut app = app_with_selected_board(); + app.ui.artboard_tool.adding = true; + assert_eq!(serde_json::to_value(&app.ui.artboard_tool).unwrap()["adding"], json!(true)); + app.ui.tool = Tool::Move; + click(&mut app, 3000.0, 100.0); + assert!(!app.ui.artboard_tool.adding); + app.ui.tool = Tool::Artboard; + let before = boards(&app); + click(&mut app, 3000.0, 100.0); + assert_eq!(boards(&app), before); +} + +#[test] +fn ui_inspect_reports_the_mode_on_and_off() { + let ctx = egui::Context::default(); + let mut app = app_with_selected_board(); + let adding = |app: &mut PhotocraftApp| { + let (req, _) = crate::control::ControlRequest::new("ui.inspect", json!({})); + let crate::control::Outcome::Done(v) = crate::control::handle(app, &ctx, &req) else { panic!("inspect") }; + v["result"]["artboardTool"]["adding"].clone() + }; + assert_eq!(adding(&mut app), json!(false)); + app.ui.artboard_tool.adding = true; + assert_eq!(adding(&mut app), json!(true)); +} + +#[test] +fn selecting_another_tool_and_coming_back_leaves_the_mode_off() { + let mut app = app_with_selected_board(); + app.ui.artboard_tool.adding = true; + // Both changes in one pass, with no pointer or options-bar call between them. + crate::tool_memory::select(&mut app, Tool::Move); + crate::tool_memory::select(&mut app, Tool::Artboard); + assert!(!app.ui.artboard_tool.adding); + let before = boards(&app); + click(&mut app, 222.0, 600.0); + assert_eq!(boards(&app), before); +} + +#[test] +fn the_add_new_artboard_button_toggles_the_mode_and_adds_no_board() { + use egui_kittest::Harness; + use egui_kittest::kittest::Queryable; + + let mut app = app_with_selected_board(); + app.ui.tool = Tool::Artboard; + let before = boards(&app); + let mut h = Harness::builder().with_size(egui::vec2(1400.0, 200.0)).build_ui_state( + |ui, app: &mut PhotocraftApp| { + if ui.ctx().fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) { + crate::panels::options_bar(app, ui); + } + }, + app, + ); + PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::Pro); + h.run_steps(4); + assert!(!h.state().ui.artboard_tool.adding); + h.get_by_label("Add New Artboard").click(); + h.run_steps(4); + assert!(h.state().ui.artboard_tool.adding, "the first click turns the mode on"); + assert_eq!(boards(h.state()), before); + h.get_by_label("Add New Artboard").click(); + h.run_steps(4); + assert!(!h.state().ui.artboard_tool.adding, "the second click turns it off"); + assert_eq!(boards(h.state()), before); +} + +#[test] +fn the_tool_shortcuts_away_and_back_leave_the_mode_off() { + let mut app = app_with_selected_board(); + app.ui.artboard_tool.adding = true; + let ctx = egui::Context::default(); + let press = |app: &mut PhotocraftApp, modifiers| { + let key = egui::Key::V; + let raw = egui::RawInput { + events: vec![ + egui::Event::ModifiersChanged(modifiers), + egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers }, + egui::Event::Key { key, physical_key: None, pressed: false, repeat: false, modifiers }, + ], + ..Default::default() + }; + ctx.begin_pass(raw); + crate::shortcuts::handle(app, &ctx); + ctx.end_pass().textures_delta.clear(); + }; + // Shift+V leaves the Artboard tool for Move, and Shift+V again comes back, with no pointer or options-bar call between. + press(&mut app, Modifiers::SHIFT); + assert_eq!(app.ui.tool, Tool::Move); + press(&mut app, Modifiers::SHIFT); + assert_eq!(app.ui.tool, Tool::Artboard); + assert!(!app.ui.artboard_tool.adding); + let before = boards(&app); + click(&mut app, 222.0, 600.0); + assert_eq!(boards(&app), before); +} diff --git a/crates/ui-egui/src/artboard_first_board_tests.rs b/crates/ui-egui/src/artboard_first_board_tests.rs new file mode 100644 index 0000000000..7db69e7b32 --- /dev/null +++ b/crates/ui-egui/src/artboard_first_board_tests.rs @@ -0,0 +1,35 @@ +//! The Artboard tool's first drag takes the Background in as "Layer 0" (#11387): the drag over +//! the measured 800 x 600 document gives Artboard 1 (holding Layer 0) and Red at the top level. + +use egui::Modifiers; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::{ToolEvent, tool_event}; +use crate::state::Tool; + +#[test] +fn the_tools_first_drag_moves_the_background_into_the_board() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.run("file.new", json!({"width": 800, "height": 600, "background": "white"})).unwrap(); + app.run("layer.new.layer", json!({"name": "Red"})).unwrap(); + app.run("select.rect", json!({"x": 100, "y": 100, "width": 200, "height": 150})).unwrap(); + app.run("edit.fill", json!({"color": "#ff0000"})).unwrap(); + app.run("select.deselect", json!({})).unwrap(); + app.ui.tool = Tool::Artboard; + let m = Modifiers::NONE; + tool_event(&mut app, ToolEvent::Down { x: 400.0, y: 300.0, pressure: 1.0 }, m); + tool_event(&mut app, ToolEvent::Move { x: 500.0, y: 400.0, pressure: 1.0 }, m); + tool_event(&mut app, ToolEvent::Move { x: 600.0, y: 500.0, pressure: 1.0 }, m); + tool_event(&mut app, ToolEvent::Up { x: 600.0, y: 500.0 }, m); + assert!(!app.ui.status_error, "{}", app.ui.status); + let st = app.session.active().unwrap(); + let top: Vec<&str> = st.doc.layers.iter().map(|l| l.name.as_str()).collect(); + assert_eq!(top, ["Red", "Artboard 1"]); + assert!(st.doc.background().is_none()); + let board = st.doc.layers.last().unwrap(); + let kids: Vec<&str> = board.children().unwrap().iter().map(|l| l.name.as_str()).collect(); + assert_eq!(kids, ["Layer 0"]); + assert_eq!((st.doc.size.width, st.doc.size.height), (800, 600)); + assert_eq!(st.history.entries().last().map(String::as_str), Some("New Artboard")); +} diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs index ae4f7a45e0..c0b4f5d883 100644 --- a/crates/ui-egui/src/canvas.rs +++ b/crates/ui-egui/src/canvas.rs @@ -45,7 +45,7 @@ mod selection; pub mod snap_ui; mod start_screen; mod strokes; -mod tabs; +pub(crate) mod tabs; mod textures; pub(super) mod tile_overlay; pub mod tool_cursor; @@ -1422,6 +1422,9 @@ fn draw_canvas_tool_cursor(app: &mut PhotocraftApp, ui: &mut egui::Ui, input: &C // corner badge, as Photoshop's corner radius cursor. ui.ctx().set_cursor_icon(egui::CursorIcon::Default); crate::icons::cursor_badge(ctx, "scan", p); + } else if let Some(c) = response.hover_pos().and_then(|p| crate::shape_bounds_box::cursor(app, xf, xf.to_doc(p))) { + // Over a handle of the box round several selected shapes: its scale cursor. + ui.ctx().set_cursor_icon(c); } else if let Some((r, p, c)) = response.hover_pos().and_then(|p| transform_controls_rect(app, xf).and_then(|r| transform_controls_cursor(r, p).map(|c| (r, p, c)))) { diff --git a/crates/ui-egui/src/canvas/canvas_tool_menu.rs b/crates/ui-egui/src/canvas/canvas_tool_menu.rs index 5cfa676b66..f633dc91e0 100644 --- a/crates/ui-egui/src/canvas/canvas_tool_menu.rs +++ b/crates/ui-egui/src/canvas/canvas_tool_menu.rs @@ -184,9 +184,9 @@ const ENDS_TYPE_EDIT: [&str; 5] = pub const PASTEBOARD_PICK: &str = "pasteboard.selectCustomColor"; /// The guide menu's Edit Selected Guides row: New Guide's dialog on the selected guide. -pub const GUIDE_EDIT: &str = "guides.editSelected"; +pub const GUIDE_EDIT: &str = "view.editSelectedGuides"; /// The guide menu's Clear Selected Guides row. -pub const GUIDE_CLEAR: &str = "guides.clearSelected"; +pub const GUIDE_CLEAR: &str = "view.clearSelectedGuides"; /// Photoshop's guide menu (right-click on a guide), in its order. Its two Selected Guides rows act /// on the guide the right-click selected; the rest are the View menu's. @@ -753,14 +753,9 @@ pub fn open_guide(app: &mut PhotocraftApp, ctx: &Context, tool: Tool, mods: egui true } -/// A guide row: the two Selected Guides rows act on the selected guide; the rest are the View -/// menu's commands. +/// A guide row: every row is a View › Guides command, the two Selected Guides ones included. fn choose_guide(app: &mut PhotocraftApp, ctx: &Context, command: &str) -> Result<(), String> { - match command { - GUIDE_EDIT => crate::new_guide_ui::open_edit(app).map(|_| ()), - GUIDE_CLEAR => crate::guide_select::delete_selected(app).map(|_| ()), - _ => crate::menus::invoke(app, ctx, command, json!({})).map(|_| ()), - } + crate::menus::invoke(app, ctx, command, json!({})).map(|_| ()) } /// A pasteboard row: set the colour, or open the Color Picker on the custom one. diff --git a/crates/ui-egui/src/canvas/drag.rs b/crates/ui-egui/src/canvas/drag.rs index 8325b5add7..aae9dbdb86 100644 --- a/crates/ui-egui/src/canvas/drag.rs +++ b/crates/ui-egui/src/canvas/drag.rs @@ -37,6 +37,10 @@ pub struct Drag { /// Freeform Pen and Path Selection gestures belong to their source document and target. pub(super) vector_owner: Option, pub(super) pen_owner: Option, + /// The document had a selection (one with content) when the drag was pressed. A modifier held + /// at the press picks the selection mode only then; without one it constrains the shape from + /// the first move (#11389). `true` until recorded, which keeps that rule for drags that don't. + pub selection_at_press: bool, } impl Drag { @@ -58,9 +62,16 @@ impl Drag { lasso: None, vector_owner: None, pen_owner: None, + selection_at_press: true, } } + /// Record whether the document has a selection at the press; an empty one counts as none, as + /// `tool_feedback::document_selection_mode` counts it (#11389). + pub(crate) fn capture_selection_at_press(&mut self, app: &PhotocraftApp) { + self.selection_at_press = app.session.active().and_then(|st| st.doc.selection.as_ref()).is_some_and(|s| !s.content_bounds().is_empty()); + } + /// Vector drags capture their owner at the press, the Freeform Pen also its destination, before /// later ⌥-clicks or a temporary Direct Selection can finish them. pub(crate) fn capture_vector_owners(&mut self, app: &PhotocraftApp) { @@ -96,13 +107,22 @@ impl Drag { self.released.alt |= !mods.alt; } - /// ⇧ (square / circle) and ⌥ (from the centre) for a marquee drag. A modifier held at the press - /// picks the selection mode instead (add / subtract, #188) until it is released and pressed - /// again, as in Photoshop. + /// ⇧ (square / circle) and ⌥ (from the centre) for a marquee drag. With a selection at the + /// press, a modifier held at the press picks the selection mode instead (add / subtract, #188) + /// until it is released and pressed again, as in Photoshop; without one it constrains the + /// shape from the first move (#11389). pub fn marquee_mods(&self) -> (bool, bool) { - let fresh = |now: bool, at_press: bool, released: bool| now && (!at_press || released); + let picks_mode = self.selection_at_press; + let fresh = |now: bool, at_press: bool, released: bool| now && (!at_press || released || !picks_mode); (fresh(self.live.shift, self.modifiers.shift, self.released.shift), fresh(self.live.alt, self.modifiers.alt, self.released.alt)) } + + /// ⇧ held since the press with no selection: the square takes the drag's shorter side, as the + /// reference application does (a 200 × 100 drag selects 100 × 100, #11389). ⇧ pressed during + /// the drag keeps the longer side (not measured, so as before). + fn square_from_press(&self) -> bool { + !self.selection_at_press && self.modifiers.shift && !self.released.shift && self.live.shift + } } /// The marquee dragged from `d.start` to `end` as two document-space corners: the options-bar @@ -117,7 +137,13 @@ pub fn marquee_corners(o: &crate::state::ToolOptions, d: &Drag, end: [f64; 2]) - let a = if alt { [end[0] - w / 2.0, end[1] - h / 2.0] } else { end }; return (a, [a[0] + w, a[1] + h]); } - let e = crate::chrome_ui::marquee_end(&o.marquee_style, o.marquee_width as f64, o.marquee_height as f64, shift, d.start, end); + let e = if shift && d.square_from_press() && !matches!(o.marquee_style.as_str(), "fixedRatio" | "fixedSize") { + let (dx, dy) = (end[0] - d.start[0], end[1] - d.start[1]); + let m = dx.abs().min(dy.abs()); + [d.start[0] + m.copysign(dx), d.start[1] + m.copysign(dy)] + } else { + crate::chrome_ui::marquee_end(&o.marquee_style, o.marquee_width as f64, o.marquee_height as f64, shift, d.start, end) + }; if !alt { return (d.start, e); } diff --git a/crates/ui-egui/src/canvas/gesture.rs b/crates/ui-egui/src/canvas/gesture.rs index 2a2889848e..04ad55a3a7 100644 --- a/crates/ui-egui/src/canvas/gesture.rs +++ b/crates/ui-egui/src/canvas/gesture.rs @@ -209,6 +209,8 @@ pub(crate) fn selection_mode(app: &PhotocraftApp, m: egui::Modifiers) -> &'stati /// Shift constrains a Polygonal Lasso segment to Photoshop's 45° directions. /// Work in document coordinates so zoom, view rotation and mirroring cannot skew it. +/// A diagonal keeps the shorter of the two offsets on both axes, as Photoshop does (#11393); +/// a horizontal or vertical snap keeps the segment's length. pub(crate) fn constrained_polygon_point(from: [f64; 2], point: [f64; 2]) -> [f64; 2] { let dx = point[0] - from[0]; let dy = point[1] - from[1]; @@ -219,7 +221,12 @@ pub(crate) fn constrained_polygon_point(from: [f64; 2], point: [f64; 2]) -> [f64 if length == 0.0 { return point; } - let angle = (dy.atan2(dx) / std::f64::consts::FRAC_PI_4).round() * std::f64::consts::FRAC_PI_4; + let octant = (dy.atan2(dx) / std::f64::consts::FRAC_PI_4).round(); + let angle = octant * std::f64::consts::FRAC_PI_4; + if octant.rem_euclid(2.0) == 1.0 { + let m = dx.abs().min(dy.abs()); + return [from[0] + m * angle.cos().signum(), from[1] + m * angle.sin().signum()]; + } [from[0] + length * angle.cos(), from[1] + length * angle.sin()] } @@ -294,7 +301,7 @@ pub fn commit_polygon(app: &mut PhotocraftApp) { if pts.len() >= 3 { let mode = if mode.is_empty() { selection_mode(app, egui::Modifiers::NONE).to_owned() } else { mode }; let o = &app.ui.tool_options; - let _ = app.run("select.lasso", json!({"points": pts, "mode": mode, "antiAlias": o.anti_alias, "feather": o.feather})); + let _ = app.run("select.lasso", json!({"points": pts, "mode": mode, "antiAlias": o.anti_alias, "feather": o.feather, "polygonal": true})); } } diff --git a/crates/ui-egui/src/canvas/move_ui.rs b/crates/ui-egui/src/canvas/move_ui.rs index 2f702575aa..2a70bd6a7a 100644 --- a/crates/ui-egui/src/canvas/move_ui.rs +++ b/crates/ui-egui/src/canvas/move_ui.rs @@ -36,9 +36,19 @@ pub(crate) fn moves_selected_pixels_with(app: &PhotocraftApp, tool: Tool) -> boo /// time, or with `copy` (⌥) floats a duplicate and leaves them; `copy` on a piece already floating /// drops it where it is and floats a copy of it. False when it failed (reported in the status bar). pub(crate) fn float_selected(app: &mut PhotocraftApp, copy: bool, dx: f64, dy: f64) -> bool { + float_selected_as(app, copy, dx, dy, None) +} + +/// The start of a Move-tool drag of the selected pixels. An ⌥-drag copy is one "Duplicate" step, +/// as in Photoshop (#11383); a plain drag is "Move". +pub(crate) fn float_selected_for_drag(app: &mut PhotocraftApp, copy: bool) -> bool { + float_selected_as(app, copy, 0.0, 0.0, copy.then(|| tl!("Duplicate"))) +} + +fn float_selected_as(app: &mut PhotocraftApp, copy: bool, dx: f64, dy: f64, step_name: Option<&str>) -> bool { let floating = app.session.active().is_some_and(|st| photocraft_engine::float_cmds::floating(st).is_some()); let dropped = if copy && floating { app.run("select.drop", json!({})) } else { Ok(json!(null)) }; - match dropped.and_then(|_| app.run("select.float", json!({"dx": dx, "dy": dy, "copy": copy}))) { + match dropped.and_then(|_| app.run("select.float", json!({"dx": dx, "dy": dy, "copy": copy, "stepName": step_name}))) { Ok(_) => { crate::snap_ui::follow_cut(app); true diff --git a/crates/ui-egui/src/canvas/selection.rs b/crates/ui-egui/src/canvas/selection.rs index 67577e2a27..b3e37d1f18 100644 --- a/crates/ui-egui/src/canvas/selection.rs +++ b/crates/ui-egui/src/canvas/selection.rs @@ -96,7 +96,7 @@ pub(super) fn finish_selection_drag(app: &mut PhotocraftApp, floating: bool, sta (false, true) if app.session.is_enabled("select.deselect") => app.run("select.deselect", json!({})), (false, true) => return, (true, false) => app.run("select.float", json!({"dx": dx, "dy": dy})), - (false, false) => app.run("select.transformSelection", json!({"dx": dx, "dy": dy})), + (false, false) => app.run("select.transformSelection", json!({"dx": dx, "dy": dy, "stepName": "Move Selection"})), }; if let Err(e) = r { app.ui.status = e; diff --git a/crates/ui-egui/src/canvas/tabs.rs b/crates/ui-egui/src/canvas/tabs.rs index 3dffe11cc4..7389104f6c 100644 --- a/crates/ui-egui/src/canvas/tabs.rs +++ b/crates/ui-egui/src/canvas/tabs.rs @@ -327,25 +327,39 @@ fn tab_close_clicked(resp: &egui::Response, xresp: &egui::Response) -> bool { xresp.clicked() || xresp.middle_clicked() || resp.middle_clicked() } -/// All tab actions go through the same guarded File commands as the menu bar, including the +/// Rows of the document tab menu after which a separator is drawn: after Move to New Window and +/// after Open Document…, as in the reference (#11403). +pub(crate) const TAB_MENU_SEPARATORS_AFTER: [usize; 2] = [4, 6]; + +pub(crate) type TabMenuItem = (&'static str, &'static str, serde_json::Value, bool); + +/// All tab actions go through the same guarded commands as the menu bar, including the /// unsaved-changes prompt. The clicked tab is explicit even when another document is active. -pub(super) fn tab_context_items(index: usize, count: usize, has_path: bool) -> [(&'static str, &'static str, serde_json::Value, bool); 4] { +/// Order and separators follow the reference application (#11403); see [`TAB_MENU_SEPARATORS_AFTER`]. +pub(crate) fn tab_context_items(index: usize, count: usize, has_path: bool) -> [TabMenuItem; 8] { [ + ("Consolidate All to Here", "window.arrange.consolidateAllToTabs", json!({}), count > 1), ("Close", "file.close", json!({"document": index}), true), - ("Close Others", "file.closeOthers", json!({"document": index}), count > 1), ("Close All", "file.closeAll", json!({}), true), + ("Close Others", "file.closeOthers", json!({"document": index}), count > 1), + ("Move to New Window", "window.arrange.floatInWindow", json!({"document": index}), true), + ("New Document…", "file.new", json!({}), true), + ("Open Document…", "file.open", json!({}), true), (crate::menus::reveal_label(), "file.revealInFinder", json!({"document": index}), has_path), ] } -fn tab_context_menu(ui: &mut egui::Ui, index: usize, count: usize, has_path: bool) -> Option<(&'static str, serde_json::Value)> { +pub(crate) fn tab_context_menu(ui: &mut egui::Ui, index: usize, count: usize, has_path: bool) -> Option<(&'static str, serde_json::Value)> { crate::widgets::menu_scroll(ui, |ui| { ui.set_min_width(170.0); - for (label, id, params, enabled) in tab_context_items(index, count, has_path) { + for (row, (label, id, params, enabled)) in tab_context_items(index, count, has_path).into_iter().enumerate() { if ui.add_enabled(enabled, egui::Button::new(tl!(label))).clicked() { ui.close(); return Some((id, params)); } + if TAB_MENU_SEPARATORS_AFTER.contains(&row) { + ui.separator(); + } } None }) diff --git a/crates/ui-egui/src/canvas/tests.rs b/crates/ui-egui/src/canvas/tests.rs index 7882fc43c9..661da5d277 100644 --- a/crates/ui-egui/src/canvas/tests.rs +++ b/crates/ui-egui/src/canvas/tests.rs @@ -935,20 +935,38 @@ fn navigator_damage_updates_match_a_full_thumbnail() { #[test] fn tab_context_uses_clicked_document_and_existing_close_commands() { let items = tab_context_items(2, 3, true); - assert_eq!(items.iter().map(|(_, id, _, _)| *id).collect::>(), ["file.close", "file.closeOthers", "file.closeAll", "file.revealInFinder"]); - assert_eq!(items[0].2, json!({"document": 2})); + assert_eq!( + items.iter().map(|(_, id, _, _)| *id).collect::>(), + [ + "window.arrange.consolidateAllToTabs", + "file.close", + "file.closeAll", + "file.closeOthers", + "window.arrange.floatInWindow", + "file.new", + "file.open", + "file.revealInFinder" + ] + ); assert_eq!(items[1].2, json!({"document": 2})); - assert_eq!(items[2].2, json!({})); assert_eq!(items[3].2, json!({"document": 2})); - assert!(items[3].3, "a saved document can be revealed in the file manager"); - assert!(!tab_context_items(2, 3, false)[3].3, "an unsaved document cannot"); - assert!(!tab_context_items(0, 1, false)[1].3); - assert!(items.iter().all(|(_, id, _, _)| photocraft_engine::commands::find(id).is_some())); + assert_eq!(items[2].2, json!({})); + assert_eq!(items[7].2, json!({"document": 2})); + assert!(items[7].3, "a saved document can be revealed in the file manager"); + assert!(!tab_context_items(2, 3, false)[7].3, "an unsaved document cannot"); + assert!(!tab_context_items(0, 1, false)[3].3); + // The window.* rows and file.new / file.open are UI commands; the doc_tab_menu tests check them. + assert!( + items + .iter() + .filter(|r| r.1.starts_with("file.close") || r.1 == "file.revealInFinder") + .all(|(_, id, _, _)| photocraft_engine::commands::find(id).is_some()) + ); } #[test] fn tab_context_reveal_names_the_platform_file_manager() { - let (label, id, _, _) = &tab_context_items(0, 1, true)[3]; + let (label, id, _, _) = &tab_context_items(0, 1, true)[7]; assert_eq!((*label, *id), (crate::menus::reveal_label(), "file.revealInFinder")); } @@ -1099,7 +1117,7 @@ fn tab_close_others_prompts_for_unsaved_nonactive_document() { app.run("file.new", json!({"width": 8, "height": 8, "name": "Edited"})).unwrap(); app.run("edit.fill", json!({"color": "#ff0000"})).unwrap(); assert_eq!(app.session.active_index(), Some(1)); - let (_, id, params, _) = tab_context_items(0, 2, false)[1].clone(); + let (_, id, params, _) = tab_context_items(0, 2, false)[3].clone(); crate::menus::invoke(&mut app, &egui::Context::default(), id, params).unwrap(); assert!(app.discard.is_some(), "close others must ask before discarding the edited tab"); assert_eq!(app.session.documents().len(), 2); diff --git a/crates/ui-egui/src/canvas/tool_input.rs b/crates/ui-egui/src/canvas/tool_input.rs index 19758b6691..08aff7dd70 100644 --- a/crates/ui-egui/src/canvas/tool_input.rs +++ b/crates/ui-egui/src/canvas/tool_input.rs @@ -166,6 +166,11 @@ fn filter_event_before_tool(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui:: if crate::corner_radius::pointer(app, raw, mods) { return None; } + // The box round several selected shape layers: its handles scale them (Path Selection and the + // shape tools). + if crate::shape_bounds_box::pointer(app, raw, mods) { + return None; + } // Direct Selection, and the Pen's ⌘ (Direct Selection) and ⌥ (Convert Point) modes (#790). if crate::direct_select::pointer(app, ev, mods) { return None; @@ -282,7 +287,7 @@ fn handle_move_pointer(app: &mut PhotocraftApp, ev: ToolEvent, tool: Tool, mods: // With a selection: cut the selected pixels (⌥ copies them) and drag them as a floating // piece, from anywhere, as a marquee ⌘-drag does. if crate::move_ui::moves_selected_pixels_with(app, tool) { - if crate::move_ui::float_selected(app, mods.alt, 0.0, 0.0) { + if crate::move_ui::float_selected_for_drag(app, mods.alt) { let mut d = Drag::new(tool, [x, y], vec![[x, y, pressure as f64]], mods, false); d.sel_move = Some(true); app.drag = Some(d); @@ -521,6 +526,7 @@ pub fn tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers) let tool = crate::retouch_ui::alt_flipped(tool, mods.alt); let mut drag = Drag { clear, ..Drag::new(tool, from.map_or([x, y], |p| [p[0], p[1]]), points, mods, erase) }; drag.capture_vector_owners(app); + drag.capture_selection_at_press(app); app.drag = Some(drag); app.trail = None; app.stylus.begin_stroke(); diff --git a/crates/ui-egui/src/control/inspect.rs b/crates/ui-egui/src/control/inspect.rs index 53df5d373f..5b3b952f65 100644 --- a/crates/ui-egui/src/control/inspect.rs +++ b/crates/ui-egui/src/control/inspect.rs @@ -35,6 +35,7 @@ pub fn inspect(app: &PhotocraftApp, ctx: &egui::Context) -> Value { "memory": photocraft_raster::memory::stats(), "tool": app.ui.tool, "toolOptions": app.ui.tool_options, + "artboardTool": app.ui.artboard_tool, "perspectiveCrop": app.ui.perspective_crop, "strokeEditor": app.ui.stroke_editor, "magnetic": app.ui.magnetic, diff --git a/crates/ui-egui/src/dialogs/select_mask_ui.rs b/crates/ui-egui/src/dialogs/select_mask_ui.rs index ebef97f740..a37d94d5a8 100644 --- a/crates/ui-egui/src/dialogs/select_mask_ui.rs +++ b/crates/ui-egui/src/dialogs/select_mask_ui.rs @@ -1408,6 +1408,11 @@ pub fn keys(app: &mut PhotocraftApp, ctx: &egui::Context) { w.pick(t); } } + // E cycles the tool mode (add, subtract); Hand and Zoom edit nothing, so it leaves them alone. + let bare_e = ctx.input(|i| i.events.iter().any(|e| matches!(e, egui::Event::Key { key: Key::E, pressed: true, modifiers, .. } if modifiers.is_none()))); + if bare_e && w.tool.edits() && pressed(Key::E, Modifiers::NONE) { + w.add = !w.add; + } if pressed(Key::OpenBracket, Modifiers::NONE) { let s = w.size(); w.set_size((s * 0.9).min(s - 1.0)); @@ -1973,5 +1978,7 @@ pub fn show(app: &mut PhotocraftApp, ctx: &egui::Context) { } } +#[cfg(test)] +mod cycle_tool_mode_tests; #[cfg(test)] mod tests; diff --git a/crates/ui-egui/src/dialogs/select_mask_ui/cycle_tool_mode_tests.rs b/crates/ui-egui/src/dialogs/select_mask_ui/cycle_tool_mode_tests.rs new file mode 100644 index 0000000000..de138c5801 --- /dev/null +++ b/crates/ui-egui/src/dialogs/select_mask_ui/cycle_tool_mode_tests.rs @@ -0,0 +1,158 @@ +use super::*; +use egui::{Key, Modifiers}; + +fn opened() -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.session.execute("file.new", json!({"width": 160, "height": 100, "depth": 8})).unwrap(); + app.session.execute("select.rect", json!({"x": 0, "y": 0, "width": 20, "height": 20})).unwrap(); + app.session.prefs.edit(|p| { + p.dialogs.remove(REMEMBERED); + }); + app.sync_views(); + open(&mut app).unwrap(); + app +} + +fn ws(app: &PhotocraftApp) -> &SelectMaskWorkspace { + app.distort.select_mask.as_ref().unwrap() +} + +fn ui_selected(app: &mut PhotocraftApp) -> u64 { + control(app, &json!({"waitPreview": true})).unwrap()["selectedProxyPixels"].as_u64().unwrap() +} + +fn press(app: &mut PhotocraftApp, ctx: &egui::Context, key: Key, modifiers: Modifiers) { + let ev = egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers }; + let input = egui::RawInput { events: vec![ev], ..Default::default() }; + ctx.run_ui(input, |ui| keys(app, ui.ctx())).textures_delta.clear(); +} + +#[test] +fn e_switches_between_add_and_subtract_and_back() { + let mut app = opened(); + let ctx = egui::Context::default(); + assert!(ws(&app).add); + press(&mut app, &ctx, Key::E, Modifiers::NONE); + assert!(!ws(&app).add); + assert_eq!(ws(&app).describe()["mode"].as_str(), Some("subtract")); + press(&mut app, &ctx, Key::E, Modifiers::NONE); + assert!(ws(&app).add); + assert_eq!(ws(&app).describe()["mode"].as_str(), Some("add")); +} + +#[test] +fn e_works_with_every_editing_tool_and_keeps_the_tool() { + let ctx = egui::Context::default(); + for tool in [SmTool::Quick, SmTool::RefineEdge, SmTool::Brush, SmTool::Object, SmTool::Lasso, SmTool::PolygonalLasso] { + let mut app = opened(); + app.distort.select_mask.as_mut().unwrap().pick(tool); + press(&mut app, &ctx, Key::E, Modifiers::NONE); + assert!(!ws(&app).add, "{tool:?}"); + assert_eq!(ws(&app).tool, tool); + } +} + +#[test] +fn e_does_nothing_with_hand_or_zoom() { + let ctx = egui::Context::default(); + for tool in [SmTool::Hand, SmTool::Zoom] { + let mut app = opened(); + app.distort.select_mask.as_mut().unwrap().pick(tool); + press(&mut app, &ctx, Key::E, Modifiers::NONE); + assert!(ws(&app).add, "{tool:?}"); + } +} + +#[test] +fn e_with_command_alt_or_shift_does_nothing_new() { + let ctx = egui::Context::default(); + for m in [Modifiers::COMMAND, Modifiers::ALT, Modifiers::SHIFT, Modifiers::CTRL] { + let mut app = opened(); + press(&mut app, &ctx, Key::E, m); + assert!(ws(&app).add, "{m:?}"); + } +} + +#[test] +fn e_is_ignored_while_a_popup_has_the_keys() { + let mut app = opened(); + let ctx = egui::Context::default(); + ctx.run_ui(egui::RawInput::default(), |ui| { + egui::Popup::open_id(ui.ctx(), egui::Id::unique("sm-test-popup")); + }) + .textures_delta + .clear(); + assert!(egui::Popup::is_any_open(&ctx)); + press(&mut app, &ctx, Key::E, Modifiers::NONE); + assert!(ws(&app).add); +} + +#[test] +fn e_chooses_the_mode_alt_swaps_while_held() { + let mut app = opened(); + let ctx = egui::Context::default(); + press(&mut app, &ctx, Key::E, Modifiers::NONE); + assert!(!ws(&app).add); + // Alt held on top of subtract: the stroke adds, so the pixel under it becomes selected. + let before = ui_selected(&mut app); + let stroke = json!({"tool": "brush", "size": 10, "hardness": 50, "stroke": {"points": [[100.0, 10.0], [100.0, 90.0]], "alt": true}}); + control(&mut app, &stroke).unwrap(); + assert!(!ws(&app).add, "Alt does not change the chosen mode"); + assert!(ui_selected(&mut app) > before, "Alt over subtract adds"); +} + +#[test] +fn a_polygon_in_progress_keeps_its_starting_mode() { + let mut app = opened(); + let ctx = egui::Context::default(); + app.distort.select_mask.as_mut().unwrap().pick(SmTool::PolygonalLasso); + app.distort.select_mask.as_mut().unwrap().poly = Some((true, vec![[10.0, 10.0], [50.0, 10.0], [50.0, 50.0]])); + press(&mut app, &ctx, Key::E, Modifiers::NONE); + assert!(!ws(&app).add); + assert_eq!(ws(&app).poly.as_ref().map(|(a, _)| *a), Some(true)); + assert!(enter(&mut app), "Enter closes the polygon"); + let edit = ws(&app).edits.last().expect("the closed polygon is recorded"); + assert_eq!(edit["tool"].as_str(), Some("lasso")); + assert_eq!(edit["mode"].as_str(), Some("add"), "the mode the polygon started with"); + assert!(!ws(&app).add, "the workspace mode is still the one E chose"); +} + +fn e_event() -> egui::RawInput { + let ev = egui::Event::Key { key: Key::E, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE }; + egui::RawInput { events: vec![ev], ..Default::default() } +} + +/// Through the shortcut handler, as the app runs it: a focused text field keeps the E. +#[test] +fn e_through_handle_is_ignored_while_a_text_field_has_focus() { + let mut app = opened(); + let ctx = egui::Context::default(); + let mut text = String::new(); + ctx.run_ui(Default::default(), |ui| { + ui.text_edit_singleline(&mut text).request_focus(); + }) + .textures_delta + .clear(); + ctx.run_ui(e_event(), |ui| { + assert!(ui.ctx().text_edit_focused()); + crate::shortcuts::handle(&mut app, ui.ctx()); + ui.text_edit_singleline(&mut text); + }) + .textures_delta + .clear(); + assert!(ws(&app).add); +} + +/// The same path with no text field focused: E flips the mode. +#[test] +fn e_through_handle_flips_the_mode_without_a_focused_text_field() { + let mut app = opened(); + let ctx = egui::Context::default(); + ctx.run_ui(e_event(), |ui| { + assert!(!ui.ctx().text_edit_focused()); + crate::shortcuts::handle(&mut app, ui.ctx()); + }) + .textures_delta + .clear(); + assert!(!ws(&app).add); +} diff --git a/crates/ui-egui/src/doc_tab_menu_tests.rs b/crates/ui-egui/src/doc_tab_menu_tests.rs new file mode 100644 index 0000000000..090455bd59 --- /dev/null +++ b/crates/ui-egui/src/doc_tab_menu_tests.rs @@ -0,0 +1,219 @@ +//! #11403: the document tab's right-click menu lists the reference application's eight entries in +//! order, with its two separators, and each entry runs the command it names on the clicked tab. + +use std::cell::RefCell; +use std::rc::Rc; + +use egui::vec2; +use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT, Queryable}; +use serde_json::{Value, json}; + +use crate::canvas::tabs::{TAB_MENU_SEPARATORS_AFTER, tab_context_items, tab_context_menu}; +use crate::state::DialogKind; +use crate::{FileDialogRequest, PhotocraftApp, Services}; + +/// The app, what the menu is drawn for, and the command the last click returned. +struct Probe { + app: PhotocraftApp, + index: usize, + has_path: bool, + picked: Option<(&'static str, Value)>, +} + +type Requests = Rc>>; + +fn probe(documents: usize, index: usize, has_path: bool) -> (Harness<'static, Probe>, Requests) { + let requests: Requests = Default::default(); + let held = requests.clone(); + let services = Services { file_dialog: Some(Box::new(move |request, _parent, _reply| held.borrow_mut().push(request))), ..Default::default() }; + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), services); + for n in 0..documents { + app.run("file.new", json!({"width": 10 + n, "height": 8})).unwrap(); + } + let state = Probe { app, index, has_path, picked: None }; + let mut h = Harness::builder().with_size(vec2(400.0, 500.0)).build_ui_state( + |ui, p: &mut Probe| { + let count = p.app.session.documents().len(); + if let Some(hit) = tab_context_menu(ui, p.index, count, p.has_path) { + p.picked = Some(hit); + } + }, + state, + ); + PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]); + h.run_steps(3); + (h, requests) +} + +/// The drawn rows top to bottom: label, top edge, enabled. +fn rows(h: &Harness<'static, Probe>) -> Vec<(String, f32, bool)> { + let mut rows: Vec<(String, f32, bool)> = h + .query_all_by_role(egui::accesskit::Role::Button) + .map(|n| { + let a = n.accesskit_node(); + (a.label().unwrap_or_default().to_string(), n.rect().top(), !a.is_disabled()) + }) + .collect(); + rows.sort_by(|a, b| a.1.total_cmp(&b.1)); + rows +} + +/// Each document's width, which tells the documents apart (`probe` makes them 10, 11, 12 wide). +fn widths(h: &Harness<'static, Probe>) -> Vec { + h.state().app.session.documents().iter().map(|d| d.doc.size.width).collect() +} + +fn click(h: &mut Harness<'static, Probe>, label: &str) -> (&'static str, Value) { + h.get_by_label(label).click(); + h.run_steps(3); + h.state_mut().picked.take().unwrap_or_else(|| panic!("clicking {label} returned no command")) +} + +#[test] +fn the_menu_lists_the_eight_reference_entries_in_order() { + let (h, _) = probe(1, 0, false); + let labels: Vec = rows(&h).into_iter().map(|r| r.0).collect(); + assert_eq!( + labels, + [ + "Consolidate All to Here", + "Close", + "Close All", + "Close Others", + "Move to New Window", + "New Document…", + "Open Document…", + crate::menus::reveal_label(), + ] + ); +} + +#[test] +fn separators_follow_move_to_new_window_and_open_document() { + assert_eq!(TAB_MENU_SEPARATORS_AFTER, [4, 6]); + let (h, _) = probe(1, 0, false); + let tops: Vec = rows(&h).into_iter().map(|r| r.1).collect(); + let gaps: Vec = tops.windows(2).map(|w| w[1] - w[0]).collect(); + let plain = gaps[0]; + for (i, gap) in gaps.iter().enumerate() { + let separated = TAB_MENU_SEPARATORS_AFTER.contains(&i); + assert_eq!(*gap > plain + 1.0, separated, "gap after row {i} is {gap} against a plain {plain}"); + } +} + +#[test] +fn each_row_names_its_command_and_the_clicked_tabs_index() { + let items = tab_context_items(2, 3, true); + let menu = crate::menus::menu_items(&PhotocraftApp::new(photocraft_engine::Session::new(), Services::default())); + let want = [ + ("Consolidate All to Here", "window.arrange.consolidateAllToTabs", json!({})), + ("Close", "file.close", json!({"document": 2})), + ("Close All", "file.closeAll", json!({})), + ("Close Others", "file.closeOthers", json!({"document": 2})), + ("Move to New Window", "window.arrange.floatInWindow", json!({"document": 2})), + ("New Document…", "file.new", json!({})), + ("Open Document…", "file.open", json!({})), + (crate::menus::reveal_label(), "file.revealInFinder", json!({"document": 2})), + ]; + for ((label, id, params, _), (wl, wi, wp)) in items.iter().zip(want) { + assert_eq!((*label, *id, params), (wl, wi, &wp)); + assert!(menu.iter().any(|i| i.id == *id) || photocraft_engine::commands::find(id).is_some(), "{id} is a command"); + } +} + +#[test] +fn enabled_states_for_one_saved_one_unsaved_and_two_documents() { + let enabled = |documents: usize, has_path: bool| -> Vec { + let (h, _) = probe(documents, 0, has_path); + rows(&h).into_iter().map(|r| r.2).collect() + }; + // Consolidate, Close, Close All, Close Others, Move, New, Open, Reveal. + assert_eq!(enabled(1, true), [false, true, true, false, true, true, true, true], "one saved document"); + assert_eq!(enabled(1, false), [false, true, true, false, true, true, true, false], "one unsaved document"); + assert_eq!(enabled(2, true), [true, true, true, true, true, true, true, true], "two documents"); + assert_eq!(enabled(2, false), [true, true, true, true, true, true, true, false], "two documents, the clicked one unsaved"); +} + +#[test] +fn close_close_all_and_close_others_act_on_the_clicked_tab() { + let (mut h, _) = probe(3, 1, true); + let (id, params) = click(&mut h, "Close"); + assert_eq!((id, ¶ms), ("file.close", &json!({"document": 1}))); + let ctx = h.ctx.clone(); + crate::menus::invoke(&mut h.state_mut().app, &ctx, id, params).unwrap(); + let names = widths(&h); + assert_eq!(names, [10, 12]); + + let (mut h, _) = probe(3, 1, true); + let (id, params) = click(&mut h, "Close Others"); + crate::menus::invoke(&mut h.state_mut().app, &ctx, id, params).unwrap(); + let names = widths(&h); + assert_eq!(names, [11]); + + let (mut h, _) = probe(3, 1, true); + let (id, params) = click(&mut h, "Close All"); + crate::menus::invoke(&mut h.state_mut().app, &ctx, id, params).unwrap(); + assert!(h.state().app.session.documents().is_empty()); +} + +#[test] +fn move_to_new_window_floats_the_clicked_tab_even_with_one_document() { + let ctx = egui::Context::default(); + let (mut h, _) = probe(1, 0, false); + let (id, params) = click(&mut h, "Move to New Window"); + assert_eq!((id, ¶ms), ("window.arrange.floatInWindow", &json!({"document": 0}))); + crate::menus::invoke(&mut h.state_mut().app, &ctx, id, params).unwrap(); + assert!(h.state().app.ui.windows.iter().any(|w| w.floating && w.document == 0)); + + // The clicked tab (2) is not the active document (0). + let (mut h, _) = probe(3, 2, true); + h.state_mut().app.session.set_active(0); + assert_eq!(h.state().app.session.active_index(), Some(0)); + let (id, params) = click(&mut h, "Move to New Window"); + crate::menus::invoke(&mut h.state_mut().app, &ctx, id, params).unwrap(); + let windows = &h.state().app.ui.windows; + assert!(windows.iter().any(|w| w.floating && w.document == 2), "the clicked tab floats"); + assert!(!windows.iter().any(|w| w.document == 0), "the active document does not float"); +} + +#[test] +fn consolidate_all_to_here_brings_floating_windows_back() { + let ctx = egui::Context::default(); + let (mut h, _) = probe(2, 0, true); + crate::menus::invoke(&mut h.state_mut().app, &ctx, "window.arrange.floatAllInWindows", json!({})).unwrap(); + assert_eq!(h.state().app.ui.windows.len(), 2); + let (id, params) = click(&mut h, "Consolidate All to Here"); + assert_eq!((id, ¶ms), ("window.arrange.consolidateAllToTabs", &json!({}))); + crate::menus::invoke(&mut h.state_mut().app, &ctx, id, params).unwrap(); + assert!(h.state().app.ui.windows.is_empty()); +} + +#[test] +fn new_document_opens_the_new_document_dialog() { + let ctx = egui::Context::default(); + let (mut h, _) = probe(1, 0, false); + let (id, params) = click(&mut h, "New Document…"); + assert_eq!((id, ¶ms), ("file.new", &json!({}))); + crate::menus::invoke(&mut h.state_mut().app, &ctx, id, params).unwrap(); + assert!(h.state().app.ui.dialogs.iter().any(|d| d.kind == DialogKind::NewDocument)); +} + +#[test] +fn open_document_asks_for_files_like_file_open() { + let ctx = egui::Context::default(); + let (mut h, requests) = probe(1, 0, false); + let (id, params) = click(&mut h, "Open Document…"); + assert_eq!((id, ¶ms), ("file.open", &json!({}))); + crate::menus::invoke(&mut h.state_mut().app, &ctx, id, params).unwrap(); + h.state_mut().app.poll_file_dialog(&ctx, None); + let asked = requests.borrow(); + assert!(matches!(asked.as_slice(), [FileDialogRequest::Open { multiple: true, .. }]), "{asked:?}"); +} + +#[test] +fn reveal_keeps_its_platform_label_and_command() { + let (mut h, _) = probe(1, 0, true); + let (id, params) = click(&mut h, crate::menus::reveal_label()); + assert_eq!((id, ¶ms), ("file.revealInFinder", &json!({"document": 0}))); +} diff --git a/crates/ui-egui/src/i18n/ar.tsv b/crates/ui-egui/src/i18n/ar.tsv index 9703ae5b3d..80c41fe82b 100644 --- a/crates/ui-egui/src/i18n/ar.tsv +++ b/crates/ui-egui/src/i18n/ar.tsv @@ -81,6 +81,7 @@ Right يمين Open Recent فتح الملفات الأخيرة Clear Recent Files مسح الملفات الأخيرة + Clear Recent File List مسح الملفات الأخيرة Remove from Recent إزالة من الملفات الأخيرة Remove {name} from Recent إزالة {name} من الملفات الأخيرة Close إغلاق @@ -89,6 +90,10 @@ Restore استعادة Close All إغلاق الكل Close Others إغلاق المستندات الأخرى + New Document… مستند جديد… + Open Document… فتح… + Consolidate All to Here توحيد الكل هنا + Move to New Window نقل إلى نافذة جديدة Save حفظ Save As… حفظ باسم… Save a Copy… حفظ نسخة… @@ -141,6 +146,7 @@ Create Smart Object after Loading Layers إنشاء كائن ذكي بعد تحميل الطبقات Reveal in Finder إظهار في Finder Show in Explorer إظهار في Explorer + Reveal in Explorer إظهار في Explorer Show in Folder إظهار في المجلد File Info… معلومات الملف… Print… طباعة… @@ -229,6 +235,7 @@ Units & Rulers… الوحدات والمساطر… Guides, Grid & Slices… خطوط التوجيه والشبكة والشرائح… Plug-ins… المكونات الإضافية… + Plugins… المكونات الإضافية… Type… النص… Enhanced Controls… عناصر التحكم المحسنة… Camera Raw… Camera Raw… @@ -386,6 +393,8 @@ Smart Object كائن ذكي Convert to Smart Object تحويل إلى كائن ذكي Convert to Embedded تحويل إلى مضمّن + Embed Linked تضمين المرتبط + Embed All Linked تضمين كل المرتبط Convert to Layers تحويل إلى طبقات Convert to Linked… تحويل إلى مرتبط… Edit Contents تحرير المحتويات @@ -459,7 +468,9 @@ Unite Shapes توحيد الأشكال Subtract Front Shape طرح الشكل الأمامي Intersect Shape Areas تقاطع مناطق الأشكال + Unite Shapes at Overlap تقاطع مناطق الأشكال Exclude Overlapping Shapes استبعاد الأشكال المتداخلة + Subtract Shapes at Overlap استبعاد الأشكال المتداخلة Merge Shape Components دمج مكونات الشكل Align محاذاة Top Edges الحواف العلوية @@ -660,6 +671,7 @@ Minimum… الحد الأدنى… Offset… إزاحة… Plug-ins المكونات الإضافية + Plugins المكونات الإضافية Proof Setup إعداد المعاينة الطباعية Proof Colors ألوان المعاينة الطباعية Gamut Warning تحذير النطاق اللوني @@ -668,9 +680,9 @@ Working Magenta Plate لوح الأرجواني العامل Working Yellow Plate لوح الأصفر العامل Working Black Plate لوح الأسود العامل - Working CMY Plate لوح CMY العامل - Legacy Macintosh RGB RGB القديم لنظام Macintosh - Internet Standard RGB RGB القياسي للإنترنت + Working CMY Plates لوح CMY العامل + Legacy Macintosh RGB (Gamma 1.8) RGB القديم لنظام Macintosh (Gamma 1.8) + Internet Standard RGB (sRGB) RGB القياسي للإنترنت (sRGB) Monitor RGB RGB الشاشة Color Blindness — Protanopia-type عمى الألوان — نوع بروتانوبيا Color Blindness — Deuteranopia-type عمى الألوان — نوع ديوتيرانوبيا @@ -752,7 +764,7 @@ Consolidate All to Tabs توحيد الكل في علامات تبويب Float in Window تعويم في نافذة Float All in Windows تعويم الكل في نوافذ - New Window for Document نافذة جديدة للمستند + New Window نافذة جديدة للمستند Workspace مساحة العمل Essentials الأساسيات Graphic and Web الرسومات والويب @@ -1924,6 +1936,11 @@ Show canvas dots إظهار نقاط مساحة الرسم Clip thumbnails to layer bounds قصر الصور المصغرة على حدود الطبقة Clip Thumbnails to Layer Bounds قصر الصور المصغرة على حدود الطبقة + No Thumbnails بلا صور مصغرة + Small Thumbnails صور مصغرة صغيرة + Medium Thumbnails صور مصغرة متوسطة + Large Thumbnails صور مصغرة كبيرة + Clip Thumbnails to Document Bounds قصر الصور المصغرة على حدود المستند Canvas color لون مساحة الرسم Canvas custom color لون مخصص لمساحة الرسم Color picker منتقي الألوان diff --git a/crates/ui-egui/src/i18n/bs.tsv b/crates/ui-egui/src/i18n/bs.tsv index 1381bb150c..6fc8c62e6a 100644 --- a/crates/ui-egui/src/i18n/bs.tsv +++ b/crates/ui-egui/src/i18n/bs.tsv @@ -64,6 +64,7 @@ Right Desno Open Recent Otvori nedavno Clear Recent Files Očisti nedavne datoteke + Clear Recent File List Očisti nedavne datoteke Remove from Recent Ukloni iz nedavnih Remove {name} from Recent Ukloni {name} iz nedavnih Close Zatvori @@ -72,6 +73,10 @@ Restore Vrati Close All Zatvori sve Close Others Zatvori ostale + New Document… Novi dokument… + Open Document… Otvori… + Consolidate All to Here Objedini sve ovdje + Move to New Window Premjesti u novi prozor Save Sačuvaj Save As… Sačuvaj kao… Save a Copy… Sačuvaj kopiju… @@ -123,6 +128,7 @@ Create Smart Object after Loading Layers Kreiraj pametni objekat nakon učitavanja slojeva Reveal in Finder Prikaži u Finderu Show in Explorer Prikaži u Exploreru + Reveal in Explorer Prikaži u Exploreru Show in Folder Prikaži u folderu File Info… Informacije o datoteci… Print… Štampaj… @@ -207,6 +213,7 @@ Units & Rulers… Jedinice i ravnala… Guides, Grid & Slices… Vodilice, mreža i isječci… Plug-ins… Dodaci… + Plugins… Dodaci… Type… Vrsta… Enhanced Controls… Poboljšane kontrole… Camera Raw… Camera Raw… @@ -355,6 +362,8 @@ Smart Object Pametni objekat Convert to Smart Object Pretvori u pametni objekat Convert to Embedded Pretvori u ugrađeno + Embed Linked Ugradi povezano + Embed All Linked Ugradi sve povezano Convert to Layers Pretvori u slojeve Convert to Linked… Pretvori u povezano… Edit Contents Uredi sadržaj @@ -605,6 +614,7 @@ Minimum… Minimum… Offset… Pomak… Plug-ins Dodaci + Plugins Dodaci Proof Setup Postavke probnog prikaza Proof Colors Probne boje Gamut Warning Upozorenje o gamutu @@ -613,9 +623,9 @@ Working Magenta Plate Radna magenta ploča Working Yellow Plate Radna žuta ploča Working Black Plate Radna crna ploča - Working CMY Plate Radna CMY ploča - Legacy Macintosh RGB Naslijeđeni Macintosh RGB - Internet Standard RGB Internet standardni RGB + Working CMY Plates Radna CMY ploča + Legacy Macintosh RGB (Gamma 1.8) Naslijeđeni Macintosh RGB (Gamma 1.8) + Internet Standard RGB (sRGB) Internet standardni RGB (sRGB) Monitor RGB RGB monitora Color Blindness — Protanopia-type Daltonizam — tip protanopije Color Blindness — Deuteranopia-type Daltonizam — tip deuteranopije @@ -707,7 +717,6 @@ Consolidate All to Tabs Objedini sve u kartice Float in Window Odvoji u prozor Float All in Windows Odvoji sve u prozore - New Window for Document Novi prozor za dokument Workspace Radni prostor Essentials Osnove Graphic and Web Grafika i web @@ -1851,6 +1860,11 @@ Show canvas dots Prikaži tačke platna Clip thumbnails to layer bounds Ograniči sličice na granice sloja Clip Thumbnails to Layer Bounds Ograniči sličice na granice sloja + No Thumbnails Bez sličica + Small Thumbnails Male sličice + Medium Thumbnails Srednje sličice + Large Thumbnails Velike sličice + Clip Thumbnails to Document Bounds Ograniči sličice na granice dokumenta Canvas color Boja platna Canvas custom color Prilagođena boja platna Color picker Birač boja diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv index 18d3e4401c..a23681f867 100644 --- a/crates/ui-egui/src/i18n/cs.tsv +++ b/crates/ui-egui/src/i18n/cs.tsv @@ -203,6 +203,7 @@ Right Vpravo Open Recent Otevřít nedávné Clear Recent Files Vymazat nedávné soubory + Clear Recent File List Vymazat nedávné soubory Remove from Recent Odebrat z nedávných Remove {name} from Recent Odebrat {name} z nedávných Close Zavřít @@ -211,6 +212,10 @@ Restore Obnovit Close All Zavřít vše Close Others Zavřít ostatní + New Document… Nový dokument… + Open Document… Otevřít… + Consolidate All to Here Sloučit vše sem + Move to New Window Přesunout do nového okna Save Uložit Save As… Uložit jako… Save a Copy… Uložit kopii… @@ -262,6 +267,7 @@ Create Smart Object after Loading Layers Po načtení vrstev vytvořit chytrý objekt Reveal in Finder Zobrazit ve Finderu Show in Explorer Zobrazit v Průzkumníkovi + Reveal in Explorer Zobrazit v Průzkumníkovi Show in Folder Zobrazit ve složce File Info… Informace o souboru… Print… Tisk… @@ -350,6 +356,7 @@ Units & Rulers… Jednotky a pravítka… Guides, Grid & Slices… Vodítka, mřížka a řezy… Plug-ins… Zásuvné moduly… + Plugins… Zásuvné moduly… Type… Text… Enhanced Controls… Rozšířené ovládání… Camera Raw… Camera Raw… @@ -507,6 +514,8 @@ Smart Object Chytrý objekt Convert to Smart Object Převést na chytrý objekt Convert to Embedded Převést na vložený + Embed Linked Vložit propojené + Embed All Linked Vložit všechna propojená Convert to Layers Převést na vrstvy Convert to Linked… Převést na propojený… Edit Contents Upravit obsah @@ -764,6 +773,7 @@ Minimum… Minimum… Offset… Posun… Plug-ins Zásuvné moduly + Plugins Zásuvné moduly Proof Setup Nastavení nátisku Proof Colors Nátiskové barvy Gamut Warning Upozornění na gamut @@ -772,9 +782,9 @@ Working Magenta Plate Pracovní purpurový výtažek Working Yellow Plate Pracovní žlutý výtažek Working Black Plate Pracovní černý výtažek - Working CMY Plate Pracovní výtažky CMY - Legacy Macintosh RGB Starší Macintosh RGB - Internet Standard RGB Internetový standard RGB + Working CMY Plates Pracovní výtažky CMY + Legacy Macintosh RGB (Gamma 1.8) Starší Macintosh RGB (Gamma 1.8) + Internet Standard RGB (sRGB) Internetový standard RGB (sRGB) Monitor RGB RGB monitoru Color Blindness — Protanopia-type Barvoslepost — protanopie Color Blindness — Deuteranopia-type Barvoslepost — deuteranopie @@ -866,7 +876,7 @@ Consolidate All to Tabs Sloučit vše do záložek Float in Window Uvolnit do plovoucího okna Float All in Windows Uvolnit vše do plovoucích oken - New Window for Document Nové okno dokumentu + New Window Nové okno dokumentu Workspace Pracovní prostor Essentials Základy Graphic and Web Grafika a web @@ -2041,6 +2051,11 @@ Show canvas dots Zobrazit tečky plátna Clip thumbnails to layer bounds Oříznout miniatury na hranice vrstvy Clip Thumbnails to Layer Bounds Oříznout miniatury na hranice vrstvy + No Thumbnails Bez miniatur + Small Thumbnails Malé miniatury + Medium Thumbnails Střední miniatury + Large Thumbnails Velké miniatury + Clip Thumbnails to Document Bounds Oříznout miniatury na hranice dokumentu Canvas color Barva plátna Canvas custom color Vlastní barva plátna Color picker Výběr barvy diff --git a/crates/ui-egui/src/i18n/da.tsv b/crates/ui-egui/src/i18n/da.tsv index c84caa3fe8..89deab4287 100644 --- a/crates/ui-egui/src/i18n/da.tsv +++ b/crates/ui-egui/src/i18n/da.tsv @@ -86,6 +86,7 @@ Right Højre Open Recent Åbn seneste Clear Recent Files Ryd seneste filer + Clear Recent File List Ryd seneste filer Remove from Recent Fjern fra seneste Remove {name} from Recent Fjern {name} fra seneste Close Luk @@ -94,6 +95,10 @@ Restore Gendan Close All Luk alle Close Others Luk andre + New Document… Nyt dokument… + Open Document… Åbn… + Consolidate All to Here Saml alle her + Move to New Window Flyt til nyt vindue Save Gem Save As… Gem som… Save a Copy… Gem en kopi… @@ -508,7 +513,6 @@ Match Location Afstem placering Match Rotation Afstem rotation Match All Afstem alle - New Window for Document Nyt vindue til dokument Workspace Arbejdsområde Extensions Udvidelser Panels Paneler @@ -686,6 +690,7 @@ Units & Rulers… Enheder og linealer… Guides, Grid & Slices… Hjælpelinjer, gitter og udsnit… Plug-ins… Plug-ins… + Plugins… Plug-ins… Technology Previews Teknologieksempler Scratch Disks… Arbejdsdiske… Export Preferences… Eksportpræferencer… @@ -920,8 +925,8 @@ ACES ACES Industry Standard Industristandard Web Web - Internet Standard RGB Internetstandard-RGB - Legacy Macintosh RGB Ældre Macintosh RGB + Internet Standard RGB (sRGB) Internetstandard-RGB (sRGB) + Legacy Macintosh RGB (Gamma 1.8) Ældre Macintosh RGB (Gamma 1.8) Monitor RGB Skærm-RGB Windows LCD Windows LCD Coated CMYK Bestrøget CMYK @@ -1742,6 +1747,7 @@ Saved Gemt Reveal in Finder Vis i Finder Show in Explorer Vis i Stifinder + Reveal in Explorer Vis i Stifinder Show in Folder Vis i mappe Before (Y) Før (Y) Save Settings… Gem indstillinger… @@ -1921,6 +1927,8 @@ Combine Shapes Kombinér former Contract… Formindsk… Convert to Embedded Konvertér til indlejret + Embed Linked Indlejr sammenkædet + Embed All Linked Indlejr alle sammenkædede Convert to Layers Konvertér til lag Convert to Linked… Konvertér til sammenkædet… Count Optælling @@ -2008,6 +2016,7 @@ Pixelate Pixelér Place Scale Marker… Placér skalamarkør… Plug-ins Plug-ins + Plugins Plug-ins Print One Copy Udskriv én kopi Print… Udskriv… Range Spændvidde @@ -2052,7 +2061,7 @@ Vertical Centers Lodrette midtpunkter Video Frames to Layers… Videobilleder til lag… WIA Support… WIA-support… - Working CMY Plate Arbejds-CMY-plade + Working CMY Plates Arbejds-CMY-plade # tl! literals (third pass) Absolute Absolut @@ -2338,6 +2347,11 @@ Show canvas dots Vis lærredsprikker Clip thumbnails to layer bounds Klip miniaturer til laggrænser Clip Thumbnails to Layer Bounds Klip miniaturer til laggrænser + No Thumbnails Ingen miniaturer + Small Thumbnails Små miniaturer + Medium Thumbnails Mellemstore miniaturer + Large Thumbnails Store miniaturer + Clip Thumbnails to Document Bounds Klip miniaturer til dokumentgrænser Canvas color Lærredsfarve Canvas custom color Brugerdefineret lærredsfarve Classic Klassisk diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv index 24419a2a44..39147f17c9 100644 --- a/crates/ui-egui/src/i18n/de.tsv +++ b/crates/ui-egui/src/i18n/de.tsv @@ -173,6 +173,7 @@ Right Rechts Open Recent Zuletzt geöffnete Dateien Clear Recent Files Zuletzt geöffnete Dateien leeren + Clear Recent File List Zuletzt geöffnete Dateien leeren Remove from Recent Aus zuletzt geöffneten Dateien entfernen Remove {name} from Recent {name} aus zuletzt geöffneten Dateien entfernen Close Schließen @@ -181,6 +182,10 @@ Restore Wiederherstellen Close All Alle schließen Close Others Andere schließen + New Document… Neues Dokument… + Open Document… Öffnen… + Consolidate All to Here Alle hier zusammenfassen + Move to New Window In neues Fenster verschieben Save Speichern Save As… Speichern unter… Save a Copy… Kopie speichern… @@ -233,6 +238,7 @@ Create Smart Object after Loading Layers Nach dem Laden der Ebenen Smart-Objekt erstellen Reveal in Finder Im Finder anzeigen Show in Explorer Im Explorer anzeigen + Reveal in Explorer Im Explorer anzeigen Show in Folder Im Ordner anzeigen File Info… Dateiinformationen… Print… Drucken… @@ -321,6 +327,7 @@ Units & Rulers… Einheiten & Lineale… Guides, Grid & Slices… Hilfslinien, Raster & Slices… Plug-ins… Plug-ins… + Plugins… Plug-ins… Type… Text… Enhanced Controls… Erweiterte Bedienelemente… Camera Raw… Camera Raw… @@ -478,6 +485,8 @@ Smart Object Smart-Objekt Convert to Smart Object In Smart-Objekt konvertieren Convert to Embedded In eingebettetes Smart-Objekt konvertieren + Embed Linked Verknüpftes einbetten + Embed All Linked Alle verknüpften einbetten Convert to Layers In Ebenen konvertieren Convert to Linked… In verknüpftes Smart-Objekt konvertieren… Edit Contents Inhalt bearbeiten @@ -551,7 +560,9 @@ Unite Shapes Formen vereinigen Subtract Front Shape Vordere Form subtrahieren Intersect Shape Areas Schnittmenge der Formen + Unite Shapes at Overlap Schnittmenge der Formen Exclude Overlapping Shapes Überlappende Formen ausschließen + Subtract Shapes at Overlap Überlappende Formen ausschließen Merge Shape Components Formkomponenten zusammenfügen Path operations Pfadvorgänge Align Ausrichten @@ -735,6 +746,7 @@ Minimum… Minimum… Offset… Versatz… Plug-ins Plug-ins + Plugins Plug-ins Proof Setup Proof-Setup Proof Colors Proof-Farben Gamut Warning Farbumfang-Warnung @@ -743,9 +755,9 @@ Working Magenta Plate Arbeits-Magenta-Druckplatte Working Yellow Plate Arbeits-Gelb-Druckplatte Working Black Plate Arbeits-Schwarz-Druckplatte - Working CMY Plate Arbeits-CMY-Druckplatte - Legacy Macintosh RGB Legacy-Macintosh-RGB - Internet Standard RGB Internet-Standard-RGB + Working CMY Plates Arbeits-CMY-Druckplatte + Legacy Macintosh RGB (Gamma 1.8) Legacy-Macintosh-RGB (Gamma 1.8) + Internet Standard RGB (sRGB) Internet-Standard-RGB (sRGB) Monitor RGB Monitor-RGB Color Blindness — Protanopia-type Farbenblindheit — Protanopie-Typ Color Blindness — Deuteranopia-type Farbenblindheit — Deuteranopie-Typ @@ -827,7 +839,7 @@ Consolidate All to Tabs Alle in Registerkarten zusammenfassen Float in Window In Fenster schweben lassen Float All in Windows Alle in Fenstern schweben lassen - New Window for Document Neues Fenster für Dokument + New Window Neues Fenster für Dokument Workspace Arbeitsbereich Essentials Essentials Graphic and Web Grafik und Web @@ -2000,6 +2012,11 @@ Show canvas dots Punkte der Zeichenfläche anzeigen Clip thumbnails to layer bounds Miniaturbilder auf Ebenenbegrenzung beschneiden Clip Thumbnails to Layer Bounds Miniaturbilder auf Ebenenbegrenzung beschneiden + No Thumbnails Keine Miniaturbilder + Small Thumbnails Kleine Miniaturbilder + Medium Thumbnails Mittlere Miniaturbilder + Large Thumbnails Große Miniaturbilder + Clip Thumbnails to Document Bounds Miniaturbilder auf Dokumentbegrenzung beschneiden Canvas color Zeichenflächenfarbe Canvas custom color Benutzerdefinierte Zeichenflächenfarbe Color picker Farbwähler diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv index ad261185bb..d2f684e3ae 100644 --- a/crates/ui-egui/src/i18n/el.tsv +++ b/crates/ui-egui/src/i18n/el.tsv @@ -144,6 +144,7 @@ Right Δεξιά Open Recent Πρόσφατα αρχεία Clear Recent Files Εκκαθάριση πρόσφατων αρχείων + Clear Recent File List Εκκαθάριση πρόσφατων αρχείων Remove from Recent Αφαίρεση από τα πρόσφατα Remove {name} from Recent Αφαίρεση του {name} από τα πρόσφατα Close Κλείσιμο @@ -152,6 +153,10 @@ Restore Επαναφορά Close All Κλείσιμο όλων Close Others Κλείσιμο των υπόλοιπων + New Document… Νέο έγγραφο… + Open Document… Άνοιγμα… + Consolidate All to Here Συγκέντρωση όλων εδώ + Move to New Window Μετακίνηση σε νέο παράθυρο Save Αποθήκευση Save As… Αποθήκευση ως… Save a Copy… Αποθήκευση αντιγράφου… @@ -203,6 +208,7 @@ Create Smart Object after Loading Layers Δημιουργία έξυπνου αντικειμένου μετά τη φόρτωση επιπέδων Reveal in Finder Εμφάνιση στο Finder Show in Explorer Εμφάνιση στην Εξερεύνηση αρχείων + Reveal in Explorer Εμφάνιση στην Εξερεύνηση αρχείων Show in Folder Εμφάνιση στον φάκελο File Info… Πληροφορίες αρχείου… Print… Εκτύπωση… @@ -1766,6 +1772,11 @@ Show canvas dots Εμφάνιση κουκκίδων καμβά Clip thumbnails to layer bounds Περικοπή μικρογραφιών στα όρια του επιπέδου Clip Thumbnails to Layer Bounds Περικοπή μικρογραφιών στα όρια του επιπέδου + No Thumbnails Χωρίς μικρογραφίες + Small Thumbnails Μικρές μικρογραφίες + Medium Thumbnails Μεσαίες μικρογραφίες + Large Thumbnails Μεγάλες μικρογραφίες + Clip Thumbnails to Document Bounds Περικοπή μικρογραφιών στα όρια του εγγράφου Canvas color Χρώμα καμβά Canvas custom color Προσαρμοσμένο χρώμα καμβά Color picker Επιλογέας χρώματος @@ -1847,6 +1858,7 @@ Units & Rulers… Μονάδες και χάρακες… Guides, Grid & Slices… Οδηγοί, πλέγμα και τομές… Plug-ins… Πρόσθετα… + Plugins… Πρόσθετα… Type… Κείμενο… Enhanced Controls… Προηγμένα χειριστήρια… Raw Defaults… Προεπιλογές RAW… @@ -1951,6 +1963,8 @@ Hide Selection Απόκρυψη επιλογής From Transparency Από διαφάνεια Convert to Embedded Μετατροπή σε ενσωματωμένο + Embed Linked Ενσωμάτωση συνδεδεμένου + Embed All Linked Ενσωμάτωση όλων των συνδεδεμένων Convert to Linked… Μετατροπή σε συνδεδεμένο… Edit Contents Επεξεργασία περιεχομένου Replace Contents… Αντικατάσταση περιεχομένου… @@ -2009,7 +2023,9 @@ Unite Shapes Ένωση σχημάτων Subtract Front Shape Αφαίρεση μπροστινού σχήματος Intersect Shape Areas Τομή περιοχών σχημάτων + Unite Shapes at Overlap Τομή περιοχών σχημάτων Exclude Overlapping Shapes Εξαίρεση επικαλυπτόμενων σχημάτων + Subtract Shapes at Overlap Εξαίρεση επικαλυπτόμενων σχημάτων Merge Shape Components Συγχώνευση συστατικών σχήματος Path operations Λειτουργίες διαδρομών Top Edges Επάνω ακμές @@ -2665,7 +2681,7 @@ Install Plug-in Εγκατάσταση προσθέτου Integrations Ενσωματώσεις Interlaced Πεπλεγμένο - Internet Standard RGB Τυπικό RGB διαδικτύου + Internet Standard RGB (sRGB) Τυπικό RGB διαδικτύου (sRGB) Interpolation: Παρεμβολή: Interpret Footage Ερμηνεία πλάνων Intersect with selection ({key}) Τομή με την επιλογή ({key}) @@ -2718,7 +2734,7 @@ Leave as is (don't color manage) Διατήρηση ως έχει (χωρίς διαχείριση χρώματος) Left align text Αριστερή στοίχιση κειμένου Legacy Παλαιού τύπου - Legacy Macintosh RGB Παλαιό Macintosh RGB + Legacy Macintosh RGB (Gamma 1.8) Παλαιό Macintosh RGB (Gamma 1.8) Legacy compositing Παλαιός τρόπος σύνθεσης Legal Μέγεθος Legal Length: Μήκος: @@ -2855,7 +2871,6 @@ New Video Group Νέα ομάδα βίντεο New Video Layer Νέο επίπεδο βίντεο New Video Layer from File Νέο επίπεδο βίντεο από αρχείο - New Window for Document Νέο παράθυρο για το έγγραφο New Workspace Νέος χώρος εργασίας New Workspace… Νέος χώρος εργασίας… New document… Νέο έγγραφο… @@ -2948,6 +2963,7 @@ Play Αναπαραγωγή Play selection Αναπαραγωγή επιλογής Plug-ins Πρόσθετα + Plugins Πρόσθετα Point size Μέγεθος σε σημεία Pointillize Πουαντιγισμός Pointillize… Πουαντιγισμός… @@ -3371,7 +3387,7 @@ Word Spacing Διάστημα λέξεων Work Path Διαδρομή εργασίας Working Black Plate Κανάλι μαύρου εργασίας - Working CMY Plate Κανάλια CMY εργασίας + Working CMY Plates Κανάλια CMY εργασίας Working CMYK Χώρος εργασίας CMYK Working Cyan Plate Κανάλι κυανού εργασίας Working Gray Plate Κανάλι γκρι εργασίας diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv index 8f8c2d3ae8..8f5c57e3bd 100644 --- a/crates/ui-egui/src/i18n/es.tsv +++ b/crates/ui-egui/src/i18n/es.tsv @@ -139,6 +139,7 @@ Right Derecha Open Recent Abrir recientes Clear Recent Files Vaciar archivos recientes + Clear Recent File List Vaciar archivos recientes Remove from Recent Quitar de recientes Remove {name} from Recent Quitar {name} de recientes Close Cerrar @@ -147,6 +148,10 @@ Restore Restaurar Close All Cerrar todo Close Others Cerrar otros + New Document… Documento nuevo… + Open Document… Abrir… + Consolidate All to Here Consolidar todo aquí + Move to New Window Mover a una nueva ventana Save Guardar Save As… Guardar como… Save a Copy… Guardar una copia… @@ -199,6 +204,7 @@ Create Smart Object after Loading Layers Crear objeto inteligente tras cargar las capas Reveal in Finder Mostrar en Finder Show in Explorer Mostrar en el Explorador + Reveal in Explorer Mostrar en el Explorador Show in Folder Mostrar en la carpeta File Info… Información del archivo… Print… Imprimir… @@ -287,6 +293,7 @@ Units & Rulers… Unidades y reglas… Guides, Grid & Slices… Guías, cuadrícula y sectores… Plug-ins… Plugins… + Plugins… Plugins… Type… Texto… Enhanced Controls… Controles mejorados… Camera Raw… Camera Raw… @@ -444,6 +451,8 @@ Smart Object Objeto inteligente Convert to Smart Object Convertir en objeto inteligente Convert to Embedded Convertir en incrustado + Embed Linked Incrustar vinculado + Embed All Linked Incrustar todos los vinculados Convert to Layers Convertir en capas Convert to Linked… Convertir en vinculado… Edit Contents Editar contenido @@ -702,6 +711,7 @@ Minimum… Mínimo… Offset… Desplazamiento… Plug-ins Plugins + Plugins Plugins Proof Setup Ajuste de prueba Proof Colors Colores de prueba Gamut Warning Advertencia de gama @@ -710,9 +720,9 @@ Working Magenta Plate Placa magenta de trabajo Working Yellow Plate Placa amarilla de trabajo Working Black Plate Placa negra de trabajo - Working CMY Plate Placa CMY de trabajo - Legacy Macintosh RGB RGB heredado de Macintosh - Internet Standard RGB RGB estándar de Internet + Working CMY Plates Placa CMY de trabajo + Legacy Macintosh RGB (Gamma 1.8) RGB heredado de Macintosh (Gamma 1.8) + Internet Standard RGB (sRGB) RGB estándar de Internet (sRGB) Monitor RGB RGB del monitor Color Blindness — Protanopia-type Daltonismo — tipo protanopia Color Blindness — Deuteranopia-type Daltonismo — tipo deuteranopia @@ -804,7 +814,6 @@ Consolidate All to Tabs Consolidar todo en pestañas Float in Window Hacer flotante en ventana Float All in Windows Hacer flotantes todas en ventanas - New Window for Document Nueva ventana para el documento Workspace Espacio de trabajo Essentials Esenciales Graphic and Web Gráficos y web @@ -1973,6 +1982,11 @@ Show canvas dots Mostrar puntos del lienzo Clip thumbnails to layer bounds Recortar miniaturas a los límites de la capa Clip Thumbnails to Layer Bounds Recortar miniaturas a los límites de la capa + No Thumbnails Sin miniaturas + Small Thumbnails Miniaturas pequeñas + Medium Thumbnails Miniaturas medianas + Large Thumbnails Miniaturas grandes + Clip Thumbnails to Document Bounds Recortar miniaturas a los límites del documento Canvas color Color del lienzo Canvas custom color Color personalizado del lienzo Color picker Selector de color diff --git a/crates/ui-egui/src/i18n/fi.tsv b/crates/ui-egui/src/i18n/fi.tsv index 90de37b0bf..d89ea90673 100644 --- a/crates/ui-egui/src/i18n/fi.tsv +++ b/crates/ui-egui/src/i18n/fi.tsv @@ -87,6 +87,7 @@ Right Oikea Open Recent Viimeksi avatut Clear Recent Files Tyhjennä viimeisimmät tiedostot + Clear Recent File List Tyhjennä viimeisimmät tiedostot Remove from Recent Poista viimeisimmistä Remove {name} from Recent Poista {name} viimeisimmistä Close Sulje @@ -95,6 +96,10 @@ Restore Palauta Close All Sulje kaikki Close Others Sulje muut + New Document… Uusi asiakirja… + Open Document… Avaa… + Consolidate All to Here Kokoa kaikki tähän + Move to New Window Siirrä uuteen ikkunaan Save Tallenna Save As… Tallenna nimellä… Save a Copy… Tallenna kopio… @@ -509,7 +514,6 @@ Match Location Täsmäytä sijainti Match Rotation Täsmäytä kierto Match All Täsmäytä kaikki - New Window for Document Uusi ikkuna asiakirjalle Workspace Työtila Extensions Laajennukset Panels Paneelit @@ -687,6 +691,7 @@ Units & Rulers… Yksiköt ja viivaimet… Guides, Grid & Slices… Apuviivat, ruudukko ja viipaleet… Plug-ins… Laajennukset… + Plugins… Laajennukset… Technology Previews Teknologian esikatselut Scratch Disks… Työlevyt… Export Preferences… Vientiasetukset… @@ -921,8 +926,8 @@ ACES ACES Industry Standard Alan standardi Web Verkko - Internet Standard RGB Internetin standardi-RGB - Legacy Macintosh RGB Vanha Macintosh RGB + Internet Standard RGB (sRGB) Internetin standardi-RGB (sRGB) + Legacy Macintosh RGB (Gamma 1.8) Vanha Macintosh RGB (Gamma 1.8) Monitor RGB Näytön RGB Windows LCD Windows LCD Coated CMYK CMYK, päällystetty paperi @@ -1743,6 +1748,7 @@ Saved Tallennettu Reveal in Finder Näytä Finderissa Show in Explorer Näytä Resurssienhallinnassa + Reveal in Explorer Näytä Resurssienhallinnassa Show in Folder Näytä kansiossa Before (Y) Ennen (Y) Save Settings… Tallenna asetukset… @@ -1922,6 +1928,8 @@ Combine Shapes Yhdistä muodot Contract… Supista… Convert to Embedded Muunna upotetuksi + Embed Linked Upota linkitetty + Embed All Linked Upota kaikki linkitetyt Convert to Layers Muunna tasoiksi Convert to Linked… Muunna linkitetyksi… Count Laskuri @@ -2009,6 +2017,7 @@ Pixelate Pikselöinti Place Scale Marker… Sijoita mittakaavamerkki… Plug-ins Laajennukset + Plugins Laajennukset Print One Copy Tulosta yksi kopio Print… Tulosta… Range Alue @@ -2053,7 +2062,7 @@ Vertical Centers Pystykeskikohdat Video Frames to Layers… Videoruudut tasoiksi… WIA Support… WIA-tuki… - Working CMY Plate Työ-CMY-levy + Working CMY Plates Työ-CMY-levy # tl! literals (third pass) Absolute Absoluuttinen @@ -2339,6 +2348,11 @@ Show canvas dots Näytä kankaan pisteet Clip thumbnails to layer bounds Rajaa pikkukuvat tason rajoihin Clip Thumbnails to Layer Bounds Rajaa pikkukuvat tason rajoihin + No Thumbnails Ei pikkukuvia + Small Thumbnails Pienet pikkukuvat + Medium Thumbnails Keskikokoiset pikkukuvat + Large Thumbnails Suuret pikkukuvat + Clip Thumbnails to Document Bounds Rajaa pikkukuvat asiakirjan rajoihin Canvas color Kankaan väri Canvas custom color Kankaan mukautettu väri Classic Klassinen diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv index 75b955f0d7..050f58d308 100644 --- a/crates/ui-egui/src/i18n/fr.tsv +++ b/crates/ui-egui/src/i18n/fr.tsv @@ -171,6 +171,7 @@ Right Droite Open Recent Ouvrir un fichier récent Clear Recent Files Effacer la liste des fichiers récents + Clear Recent File List Effacer la liste des fichiers récents Remove from Recent Retirer des fichiers récents Remove {name} from Recent Retirer {name} des fichiers récents Close Fermer @@ -179,6 +180,10 @@ Restore Restaurer Close All Tout fermer Close Others Fermer les autres + New Document… Nouveau document… + Open Document… Ouvrir… + Consolidate All to Here Tout regrouper ici + Move to New Window Déplacer vers une nouvelle fenêtre Save Enregistrer Save As… Enregistrer sous… Save a Copy… Enregistrer une copie… @@ -231,6 +236,7 @@ Create Smart Object after Loading Layers Créer un objet intelligent après le chargement des calques Reveal in Finder Afficher dans le Finder Show in Explorer Afficher dans l'Explorateur + Reveal in Explorer Afficher dans l'Explorateur Show in Folder Afficher dans le dossier File Info… Informations sur le fichier… Print… Imprimer… @@ -317,6 +323,7 @@ Units & Rulers… Unités et règles… Guides, Grid & Slices… Repères, grille et tranches… Plug-ins… Extensions… + Plugins… Extensions… Type… Texte… Enhanced Controls… Commandes avancées… Camera Raw… Camera Raw… @@ -466,6 +473,8 @@ Smart Object Objet intelligent Convert to Smart Object Convertir en objet intelligent Convert to Embedded Convertir en objet incorporé + Embed Linked Incorporer le lié + Embed All Linked Incorporer tous les liés Convert to Layers Convertir en calques Convert to Linked… Convertir en objet lié… Edit Contents Modifier le contenu @@ -718,6 +727,7 @@ Minimum… Minimum… Offset… Décalage… Plug-ins Extensions + Plugins Extensions Proof Setup Configuration d'épreuve Proof Colors Couleurs d'épreuve Gamut Warning Alerte de gamut @@ -726,9 +736,9 @@ Working Magenta Plate Plaque magenta de travail Working Yellow Plate Plaque jaune de travail Working Black Plate Plaque noire de travail - Working CMY Plate Plaque CMJ de travail - Legacy Macintosh RGB RVB Macintosh (ancien) - Internet Standard RGB RVB standard d'Internet + Working CMY Plates Plaque CMJ de travail + Legacy Macintosh RGB (Gamma 1.8) RVB Macintosh (ancien) (Gamma 1.8) + Internet Standard RGB (sRGB) RVB standard d'Internet (sRGB) Monitor RGB RVB du moniteur Color Blindness — Protanopia-type Daltonisme — type protanopie Color Blindness — Deuteranopia-type Daltonisme — type deutéranopie @@ -820,7 +830,6 @@ Consolidate All to Tabs Tout regrouper dans des onglets Float in Window Flottante dans une fenêtre Float All in Windows Toutes flottantes dans des fenêtres - New Window for Document Nouvelle fenêtre pour le document Workspace Espace de travail Essentials Essentiel Graphic and Web Graphisme et Web @@ -1979,6 +1988,11 @@ Show canvas dots Afficher les points du canevas Clip thumbnails to layer bounds Rogner les vignettes aux limites du calque Clip Thumbnails to Layer Bounds Rogner les vignettes aux limites du calque + No Thumbnails Aucune vignette + Small Thumbnails Petites vignettes + Medium Thumbnails Vignettes moyennes + Large Thumbnails Grandes vignettes + Clip Thumbnails to Document Bounds Rogner les vignettes aux limites du document Canvas color Couleur du canevas Canvas custom color Couleur personnalisée du canevas Color picker Sélecteur de couleurs diff --git a/crates/ui-egui/src/i18n/hi.tsv b/crates/ui-egui/src/i18n/hi.tsv index f7a712b0e4..aa79f03063 100644 --- a/crates/ui-egui/src/i18n/hi.tsv +++ b/crates/ui-egui/src/i18n/hi.tsv @@ -65,6 +65,10 @@ Close बंद करें Close All सभी बंद करें Close Others अन्य सभी बंद करें + New Document… New Document… + Open Document… खोलें… + Consolidate All to Here सभी को यहाँ समेकित करें + Move to New Window नई विंडो में ले जाएँ Save सहेजें Save As… इस रूप में सहेजें… Save a Copy… एक प्रति सहेजें… @@ -630,6 +634,8 @@ cameraRaw Yellow पीला @plural {n} action file loaded|{n} action files loaded {n} एक्शन फ़ाइल लोड हुई|{n} एक्शन फ़ाइलें लोड हुईं {set} from {file} replaced the one from {earlier} {file} के सेट {set} ने {earlier} वाले सेट की जगह ले ली @plural {n} file could not be loaded: {errors}|{n} files could not be loaded: {errors} {n} फ़ाइल लोड नहीं हो सकी: {errors}|{n} फ़ाइलें लोड नहीं हो सकीं: {errors} + Embed Linked लिंक किए गए को एम्बेड करें + Embed All Linked सभी लिंक किए गए को एम्बेड करें Toggle reference point संदर्भ बिंदु दिखाएँ/छिपाएँ # Action Stop message (#8386) diff --git a/crates/ui-egui/src/i18n/hu.tsv b/crates/ui-egui/src/i18n/hu.tsv index debfdd6747..b54afb204c 100644 --- a/crates/ui-egui/src/i18n/hu.tsv +++ b/crates/ui-egui/src/i18n/hu.tsv @@ -158,6 +158,10 @@ Clipboard Vágólap Close All Összes bezárása Close Others Többi bezárása + New Document… Új dokumentum… + Open Document… Megnyitás… + Consolidate All to Here Összes ide + Move to New Window Áthelyezés új ablakba Color Balance… Színegyensúly… Color Lookup Tables… Színleképezési táblák… Color Lookup… Színleképezés… @@ -257,6 +261,7 @@ Place Linked… Csatolt elhelyezése… Place Scale Marker… Méretarány-jelölő elhelyezése… Plug-ins… Bővítmények… + Plugins… Bővítmények… Posterize… Poszterizálás… Preferences Beállítások Preset Manager… Előbeállítás-kezelő… @@ -342,6 +347,8 @@ Combine Shapes Alakzatok kombinálása Contract… Szűkítés… Convert to Embedded Átalakítás beágyazottá + Embed Linked Csatolt beágyazása + Embed All Linked Összes csatolt beágyazása Convert to Layers Átalakítás rétegekké Convert to Linked… Átalakítás csatolttá… Convert to Smart Object Átalakítás intelligens objektummá @@ -550,6 +557,7 @@ Clear Canvas Guides Vászon-segédvonalak törlése Clear Guides Segédvonalak törlése Clear Recent Files Legutóbbi fájlok listájának törlése + Clear Recent File List Legutóbbi fájlok listájának törlése Clear Selected Artboard Guides Kijelölt rajztábla segédvonalainak törlése Clear Slices Szeletek törlése Clipping Mask Vágómaszk @@ -681,7 +689,7 @@ Info Információ Install Plug-in Bővítmény telepítése Install Plug-in… Bővítmény telepítése… - Internet Standard RGB Internetes szabványos RGB + Internet Standard RGB (sRGB) Internetes szabványos RGB (sRGB) Inverse Megfordítás Iris Blur… Íriszelmosás… Join the ArtCraft Discord Csatlakozás az ArtCraft Discordhoz @@ -698,7 +706,7 @@ Layer From Background… Réteg a háttérből… Layers Rétegek Layers to Files Rétegek fájlokba - Legacy Macintosh RGB Régi Macintosh RGB + Legacy Macintosh RGB (Gamma 1.8) Régi Macintosh RGB (Gamma 1.8) Lens Blur… Objektívelmosás… Lens Flare… Lencsecsillanás… Light gray Világosszürke @@ -746,7 +754,6 @@ New Type Layer Új szövegréteg New Video Layer Új videoréteg New Window Új ablak - New Window for Document Új ablak a dokumentumhoz New Workspace… Új munkaterület… Next Appearance Mode Következő megjelenési mód Next Document Következő dokumentum @@ -791,6 +798,7 @@ Pixel Grid Pixelrács Pixelate Pixelesítés Plug-ins Bővítmények + Plugins Bővítmények Pointillize… Pontozás… Polar Coordinates… Polárkoordináták… Preferences… Beállítások… @@ -854,6 +862,7 @@ Show All Összes megjelenítése Show Extras Options… Segédelemek beállításai… Show in Explorer Megjelenítés az Intézőben + Reveal in Explorer Megjelenítés az Intézőben Show in Folder Megjelenítés mappában Show menu colors Menüszínek megjelenítése Show/Hide All Panels Összes panel megjelenítése/elrejtése @@ -919,7 +928,7 @@ Windows LCD Windows LCD Wind… Szél… Working Black Plate Fekete munkalemez - Working CMY Plate CMY munkalemezek + Working CMY Plates CMY munkalemezek Working CMYK Munka-CMYK Working Cyan Plate Cián munkalemez Working Magenta Plate Magenta munkalemez @@ -3630,6 +3639,11 @@ cameraRaw Yellow Sárga Show canvas dots Vászonpontok megjelenítése Clip thumbnails to layer bounds Bélyegképek levágása a réteg határaira Clip Thumbnails to Layer Bounds Bélyegképek levágása a réteg határaira + No Thumbnails Nincs bélyegkép + Small Thumbnails Kis bélyegképek + Medium Thumbnails Közepes bélyegképek + Large Thumbnails Nagy bélyegképek + Clip Thumbnails to Document Bounds Bélyegképek levágása a dokumentum határaira Show channels in color Csatornák megjelenítése színesen Show crosshair in brush tip Szálkereszt az ecsethegyben Show extension panels Bővítménypanelek megjelenítése diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv index c6af32b023..b2f51040e8 100644 --- a/crates/ui-egui/src/i18n/id.tsv +++ b/crates/ui-egui/src/i18n/id.tsv @@ -164,6 +164,7 @@ Right Kanan Open Recent Terakhir Dibuka Clear Recent Files Hapus Daftar Berkas Terakhir + Clear Recent File List Hapus Daftar Berkas Terakhir Remove from Recent Hapus dari Daftar Terakhir Remove {name} from Recent Hapus {name} dari Daftar Terakhir Close Tutup @@ -172,6 +173,10 @@ Restore Pulihkan Close All Tutup Semua Close Others Tutup Lainnya + New Document… Dokumen Baru… + Open Document… Buka… + Consolidate All to Here Gabungkan Semua ke Sini + Move to New Window Pindahkan ke Jendela Baru Save Simpan Save As… Simpan Sebagai… Save a Copy… Simpan Salinan… @@ -224,6 +229,7 @@ Create Smart Object after Loading Layers Buat Smart Object setelah Memuat Layer Reveal in Finder Tampilkan di Finder Show in Explorer Tampilkan di Explorer + Reveal in Explorer Tampilkan di Explorer Show in Folder Tampilkan di Folder File Info… Info Berkas… Print… Cetak… @@ -310,6 +316,7 @@ Units & Rulers… Satuan & Penggaris… Guides, Grid & Slices… Panduan, Grid & Slice… Plug-ins… Plug-in… + Plugins… Plug-in… Type… Teks… Enhanced Controls… Kontrol Lanjutan… Camera Raw… Camera Raw… @@ -459,6 +466,8 @@ Smart Object Smart Object Convert to Smart Object Konversi ke Smart Object Convert to Embedded Konversi ke Tertanam + Embed Linked Tanamkan yang Tertaut + Embed All Linked Tanamkan Semua yang Tertaut Convert to Layers Konversi ke Layer Convert to Linked… Konversi ke Tertaut… Edit Contents Edit Isi @@ -526,7 +535,9 @@ Unite Shapes Satukan Bentuk Subtract Front Shape Kurangi Bentuk Depan Intersect Shape Areas Irisan Area Bentuk + Unite Shapes at Overlap Irisan Area Bentuk Exclude Overlapping Shapes Kecualikan Bentuk yang Tumpang Tindih + Subtract Shapes at Overlap Kecualikan Bentuk yang Tumpang Tindih Merge Shape Components Gabungkan Komponen Bentuk Path operations Operasi path Align Rata @@ -711,6 +722,7 @@ Minimum… Minimum… Offset… Offset… Plug-ins Plug-in + Plugins Plug-in Proof Setup Pengaturan Proof Proof Colors Warna Proof Gamut Warning Peringatan Gamut @@ -719,9 +731,9 @@ Working Magenta Plate Pelat Magenta Kerja Working Yellow Plate Pelat Kuning Kerja Working Black Plate Pelat Hitam Kerja - Working CMY Plate Pelat CMY Kerja - Legacy Macintosh RGB RGB Macintosh Lawas - Internet Standard RGB RGB Standar Internet + Working CMY Plates Pelat CMY Kerja + Legacy Macintosh RGB (Gamma 1.8) RGB Macintosh Lawas (Gamma 1.8) + Internet Standard RGB (sRGB) RGB Standar Internet (sRGB) Monitor RGB RGB Monitor Color Blindness — Protanopia-type Buta Warna — Tipe Protanopia Color Blindness — Deuteranopia-type Buta Warna — Tipe Deuteranopia @@ -813,7 +825,7 @@ Consolidate All to Tabs Gabungkan Semua ke Tab Float in Window Mengambang di Jendela Float All in Windows Mengambangkan Semua di Jendela - New Window for Document Jendela Baru untuk Dokumen + New Window Jendela Baru untuk Dokumen Workspace Ruang Kerja Essentials Esensial Graphic and Web Grafis dan Web @@ -1987,6 +1999,11 @@ Show canvas dots Tampilkan titik kanvas Clip thumbnails to layer bounds Pangkas thumbnail ke batas layer Clip Thumbnails to Layer Bounds Pangkas Thumbnail ke Batas Layer + No Thumbnails Tanpa Thumbnail + Small Thumbnails Thumbnail Kecil + Medium Thumbnails Thumbnail Sedang + Large Thumbnails Thumbnail Besar + Clip Thumbnails to Document Bounds Pangkas Thumbnail ke Batas Dokumen Canvas color Warna kanvas Canvas custom color Warna kustom kanvas Color picker Pemilih warna diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv index b120d5a32c..a42efb170f 100644 --- a/crates/ui-egui/src/i18n/it.tsv +++ b/crates/ui-egui/src/i18n/it.tsv @@ -186,6 +186,7 @@ Right Destra Open Recent Apri recenti Clear Recent Files Cancella file recenti + Clear Recent File List Cancella file recenti Remove from Recent Rimuovi dai recenti Remove {name} from Recent Rimuovi {name} dai recenti Close Chiudi @@ -194,6 +195,10 @@ Restore Ripristina Close All Chiudi tutto Close Others Chiudi altri + New Document… Nuovo documento… + Open Document… Apri… + Consolidate All to Here Raggruppa tutto qui + Move to New Window Sposta in una nuova finestra Save Salva Save As… Salva con nome… Save a Copy… Salva una copia… @@ -245,6 +250,7 @@ Create Smart Object after Loading Layers Crea oggetto avanzato dopo il caricamento dei livelli Reveal in Finder Mostra nel Finder Show in Explorer Mostra in Esplora file + Reveal in Explorer Mostra in Esplora file Show in Folder Mostra nella cartella File Info… Info file… Print… Stampa… @@ -333,6 +339,7 @@ Units & Rulers… Unità e righelli… Guides, Grid & Slices… Guide, griglia e sezioni… Plug-ins… Plug-in… + Plugins… Plug-in… Type… Testo… Enhanced Controls… Controlli avanzati… Camera Raw… Camera Raw… @@ -490,6 +497,8 @@ Smart Object Oggetto avanzato Convert to Smart Object Converti in oggetto avanzato Convert to Embedded Converti in incorporato + Embed Linked Incorpora collegato + Embed All Linked Incorpora tutti i collegati Convert to Linked… Converti in oggetto collegato… Edit Contents Modifica contenuto Replace Contents… Sostituisci contenuto… @@ -745,6 +754,7 @@ Minimum… Minimo… Offset… Scostamento… Plug-ins Plug-in + Plugins Plug-in Proof Setup Configurazione prova Proof Colors Colori di prova Gamut Warning Avviso gamma @@ -753,9 +763,9 @@ Working Magenta Plate Lastra magenta di lavoro Working Yellow Plate Lastra gialla di lavoro Working Black Plate Lastra nera di lavoro - Working CMY Plate Lastra CMY di lavoro - Legacy Macintosh RGB RGB legacy Macintosh - Internet Standard RGB RGB standard Internet + Working CMY Plates Lastra CMY di lavoro + Legacy Macintosh RGB (Gamma 1.8) RGB legacy Macintosh (Gamma 1.8) + Internet Standard RGB (sRGB) RGB standard Internet (sRGB) Monitor RGB RGB monitor Color Blindness — Protanopia-type Daltonismo — tipo protanopia Color Blindness — Deuteranopia-type Daltonismo — tipo deuteranopia @@ -847,7 +857,6 @@ Consolidate All to Tabs Raggruppa tutto in schede Float in Window Flottante in finestra Float All in Windows Flottante tutto in finestre - New Window for Document Nuova finestra per documento Workspace Area di lavoro Essentials Essenziali Graphic and Web Grafica e web @@ -2018,6 +2027,11 @@ Show canvas dots Mostra punti del quadro Clip thumbnails to layer bounds Ritaglia le miniature ai limiti del livello Clip Thumbnails to Layer Bounds Ritaglia le miniature ai limiti del livello + No Thumbnails Nessuna miniatura + Small Thumbnails Miniature piccole + Medium Thumbnails Miniature medie + Large Thumbnails Miniature grandi + Clip Thumbnails to Document Bounds Ritaglia le miniature ai limiti del documento Canvas color Colore quadro Canvas custom color Colore personalizzato quadro Color picker Selettore colore diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv index 36c5bc1470..919d1f0977 100644 --- a/crates/ui-egui/src/i18n/ja.tsv +++ b/crates/ui-egui/src/i18n/ja.tsv @@ -195,6 +195,7 @@ Right 右 Open Recent 最近使ったファイルを開く Clear Recent Files 最近使ったファイルを消去 + Clear Recent File List 最近使ったファイルを消去 Remove from Recent 最近使ったファイルから削除 Remove {name} from Recent {name} を最近使ったファイルから削除 Close 閉じる @@ -203,6 +204,10 @@ Restore 元に戻す (縮小) Close All すべて閉じる Close Others ほかを閉じる + New Document… 新規ドキュメント… + Open Document… 開く… + Consolidate All to Here すべてをここに統合 + Move to New Window 新規ウィンドウに移動 Save 保存 Save As… 名前を付けて保存… Save a Copy… コピーを保存… @@ -255,6 +260,7 @@ Create Smart Object after Loading Layers レイヤーの読み込み後にスマートオブジェクトを作成 Reveal in Finder Finder で表示 Show in Explorer エクスプローラーで表示 + Reveal in Explorer エクスプローラーで表示 Show in Folder フォルダーで表示 File Info… ファイル情報… Print… プリント… @@ -343,6 +349,7 @@ Units & Rulers… 単位・定規… Guides, Grid & Slices… ガイド・グリッド・スライス… Plug-ins… プラグイン… + Plugins… プラグイン… Type… 文字… Enhanced Controls… 拡張コントロール… Camera Raw… Camera Raw… @@ -499,6 +506,8 @@ Smart Object スマートオブジェクト Convert to Smart Object スマートオブジェクトに変換 Convert to Embedded 埋め込みに変換 + Embed Linked リンクを埋め込む + Embed All Linked すべてのリンクを埋め込む Convert to Layers レイヤーに変換 Convert to Linked… リンクに変換… Edit Contents コンテンツを編集 @@ -572,7 +581,9 @@ Unite Shapes シェイプを結合 Subtract Front Shape 前面シェイプで型抜き Intersect Shape Areas シェイプの重なりを抽出 + Unite Shapes at Overlap シェイプの重なりを抽出 Exclude Overlapping Shapes シェイプの重なりを除外 + Subtract Shapes at Overlap シェイプの重なりを除外 Merge Shape Components シェイプの構成要素を結合 Path operations パスの操作 Align 整列 @@ -756,6 +767,7 @@ Minimum… 最小値… Offset… オフセット… Plug-ins プラグイン + Plugins プラグイン Proof Setup 校正設定 Proof Colors 色の校正 Gamut Warning 色域外警告 @@ -764,9 +776,9 @@ Working Magenta Plate 作業用マゼンタ版 Working Yellow Plate 作業用イエロー版 Working Black Plate 作業用ブラック版 - Working CMY Plate 作業用 CMY 版 - Legacy Macintosh RGB 旧 Macintosh RGB - Internet Standard RGB インターネット標準 RGB + Working CMY Plates 作業用 CMY 版 + Legacy Macintosh RGB (Gamma 1.8) 旧 Macintosh RGB (Gamma 1.8) + Internet Standard RGB (sRGB) インターネット標準 RGB (sRGB) Monitor RGB モニター RGB Color Blindness — Protanopia-type 色覚特性 — 1 型(P 型) Color Blindness — Deuteranopia-type 色覚特性 — 2 型(D 型) @@ -858,7 +870,7 @@ Consolidate All to Tabs すべてをタブに統合 Float in Window ウィンドウ内に浮動 Float All in Windows すべてをウィンドウ内に浮動 - New Window for Document ドキュメントの新規ウィンドウ + New Window ドキュメントの新規ウィンドウ Workspace ワークスペース Essentials 基本 Graphic and Web グラフィックと Web @@ -2026,6 +2038,11 @@ Show canvas dots カンバスのドットを表示 Clip thumbnails to layer bounds サムネールをレイヤーの境界でクリップ Clip Thumbnails to Layer Bounds サムネールをレイヤーの境界でクリップ + No Thumbnails サムネールなし + Small Thumbnails 小さいサムネール + Medium Thumbnails 中サイズのサムネール + Large Thumbnails 大きいサムネール + Clip Thumbnails to Document Bounds サムネールをドキュメントの境界でクリップ Canvas color カンバスの色 Canvas custom color カンバスのカスタム色 Color picker カラーピッカー diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv index 8c67685211..b7f16a941e 100644 --- a/crates/ui-egui/src/i18n/ko.tsv +++ b/crates/ui-egui/src/i18n/ko.tsv @@ -166,6 +166,7 @@ Right 오른쪽 Open Recent 최근 파일 열기 Clear Recent Files 최근 파일 목록 지우기 + Clear Recent File List 최근 파일 목록 지우기 Remove from Recent 최근 항목에서 제거 Remove {name} from Recent 최근 항목에서 {name} 제거 Close 닫기 @@ -174,6 +175,10 @@ Restore 이전 크기로 복원 Close All 모두 닫기 Close Others 다른 문서 닫기 + New Document… 새 문서… + Open Document… 열기… + Consolidate All to Here 모두 여기로 통합 + Move to New Window 새 창으로 이동 Save 저장 Save As… 다른 이름으로 저장… Save a Copy… 사본 저장… @@ -226,6 +231,7 @@ Create Smart Object after Loading Layers 레이어를 불러온 후 스마트 오브젝트 만들기 Reveal in Finder Finder에서 보기 Show in Explorer 파일 탐색기에서 보기 + Reveal in Explorer 파일 탐색기에서 보기 Show in Folder 폴더에서 보기 File Info… 파일 정보… Print… 인쇄… @@ -314,6 +320,7 @@ Units & Rulers… 단위 및 눈금자… Guides, Grid & Slices… 안내선, 격자 및 분할 영역… Plug-ins… 플러그인… + Plugins… 플러그인… Type… 문자… Enhanced Controls… 고급 컨트롤… Camera Raw… Camera Raw… @@ -464,6 +471,8 @@ Smart Object 스마트 오브젝트 Convert to Smart Object 스마트 오브젝트로 변환 Convert to Embedded 포함된 오브젝트로 변환 + Embed Linked 연결된 항목 포함 + Embed All Linked 모든 연결된 항목 포함 Convert to Layers 레이어로 변환 Convert to Linked… 연결된 오브젝트로 변환… Edit Contents 내용 편집 @@ -537,7 +546,9 @@ Unite Shapes 모양 합치기 Subtract Front Shape 앞쪽 모양 빼기 Intersect Shape Areas 모양 영역 교차 + Unite Shapes at Overlap 모양 영역 교차 Exclude Overlapping Shapes 겹치는 모양 제외 + Subtract Shapes at Overlap 겹치는 모양 제외 Merge Shape Components 모양 구성 요소 병합 Path operations 패스 작업 Align 정렬 @@ -721,6 +732,7 @@ Minimum… 최소값… Offset… 오프셋… Plug-ins 플러그인 + Plugins 플러그인 Proof Setup 교정 설정 Proof Colors 교정 색상 Gamut Warning 색상 범위 경고 @@ -729,9 +741,9 @@ Working Magenta Plate 작업용 마젠타 판 Working Yellow Plate 작업용 노랑 판 Working Black Plate 작업용 검정 판 - Working CMY Plate 작업용 CMY 판 - Legacy Macintosh RGB 기존 Macintosh RGB - Internet Standard RGB 인터넷 표준 RGB + Working CMY Plates 작업용 CMY 판 + Legacy Macintosh RGB (Gamma 1.8) 기존 Macintosh RGB (Gamma 1.8) + Internet Standard RGB (sRGB) 인터넷 표준 RGB (sRGB) Monitor RGB 모니터 RGB Color Blindness — Protanopia-type 색각 이상 — 적색맹 Color Blindness — Deuteranopia-type 색각 이상 — 녹색맹 @@ -813,7 +825,7 @@ Consolidate All to Tabs 모두 탭으로 통합 Float in Window 별도 창으로 띄우기 Float All in Windows 모두 별도 창으로 띄우기 - New Window for Document 문서의 새 창 + New Window 문서의 새 창 Workspace 작업 영역 Essentials 필수 Graphic and Web 그래픽 및 웹 @@ -1999,6 +2011,11 @@ Show canvas dots 캔버스 점 표시 Clip thumbnails to layer bounds 썸네일을 레이어 경계로 자르기 Clip Thumbnails to Layer Bounds 썸네일을 레이어 경계로 자르기 + No Thumbnails 썸네일 없음 + Small Thumbnails 작은 썸네일 + Medium Thumbnails 중간 썸네일 + Large Thumbnails 큰 썸네일 + Clip Thumbnails to Document Bounds 썸네일을 문서 경계로 자르기 Canvas color 캔버스 색상 Canvas custom color 캔버스 사용자 정의 색상 Color picker 색상 피커 diff --git a/crates/ui-egui/src/i18n/nb.tsv b/crates/ui-egui/src/i18n/nb.tsv index 05057c9f12..73f521675a 100644 --- a/crates/ui-egui/src/i18n/nb.tsv +++ b/crates/ui-egui/src/i18n/nb.tsv @@ -86,6 +86,7 @@ Right Høyre Open Recent Åpne nylig brukte Clear Recent Files Tøm nylig brukte filer + Clear Recent File List Tøm nylig brukte filer Remove from Recent Fjern fra nylig brukte Remove {name} from Recent Fjern {name} fra nylig brukte Close Lukk @@ -94,6 +95,10 @@ Restore Gjenopprett Close All Lukk alle Close Others Lukk andre + New Document… Nytt dokument… + Open Document… Åpne… + Consolidate All to Here Samle alle her + Move to New Window Flytt til nytt vindu Save Lagre Save As… Lagre som… Save a Copy… Lagre en kopi… @@ -508,7 +513,6 @@ Match Location Samkjør plassering Match Rotation Samkjør rotasjon Match All Samkjør alle - New Window for Document Nytt vindu for dokument Workspace Arbeidsområde Extensions Utvidelser Panels Paneler @@ -686,6 +690,7 @@ Units & Rulers… Enheter og linjaler… Guides, Grid & Slices… Hjelpelinjer, rutenett og segmenter… Plug-ins… Programtillegg… + Plugins… Programtillegg… Technology Previews Teknologiforhåndsvisninger Scratch Disks… Arbeidsdisker… Export Preferences… Eksportinnstillinger… @@ -920,8 +925,8 @@ ACES ACES Industry Standard Bransjestandard Web Web - Internet Standard RGB Internettstandard RGB - Legacy Macintosh RGB Eldre Macintosh RGB + Internet Standard RGB (sRGB) Internettstandard RGB (sRGB) + Legacy Macintosh RGB (Gamma 1.8) Eldre Macintosh RGB (Gamma 1.8) Monitor RGB Skjerm-RGB Windows LCD Windows LCD Coated CMYK Bestrøket CMYK @@ -1742,6 +1747,7 @@ Saved Lagret Reveal in Finder Vis i Finder Show in Explorer Vis i Utforsker + Reveal in Explorer Vis i Utforsker Show in Folder Vis i mappe Before (Y) Før (Y) Save Settings… Lagre innstillinger… @@ -1921,6 +1927,8 @@ Combine Shapes Kombiner former Contract… Trekk sammen… Convert to Embedded Konverter til innebygd + Embed Linked Bygg inn koblet + Embed All Linked Bygg inn alle koblede Convert to Layers Konverter til lag Convert to Linked… Konverter til koblet… Count Telling @@ -2008,6 +2016,7 @@ Pixelate Pikseler Place Scale Marker… Plasser skalamarkør… Plug-ins Programtillegg + Plugins Programtillegg Print One Copy Skriv ut ett eksemplar Print… Skriv ut… Range Område @@ -2052,7 +2061,7 @@ Vertical Centers Loddrette sentre Video Frames to Layers… Videorammer til lag… WIA Support… WIA-støtte… - Working CMY Plate Arbeidsplate for CMY + Working CMY Plates Arbeidsplate for CMY # tl! literals (third pass) Absolute Absolutt @@ -2338,6 +2347,11 @@ Show canvas dots Vis lerretprikker Clip thumbnails to layer bounds Klipp miniatyrer til laggrensene Clip Thumbnails to Layer Bounds Klipp miniatyrer til laggrensene + No Thumbnails Ingen miniatyrer + Small Thumbnails Små miniatyrer + Medium Thumbnails Middels miniatyrer + Large Thumbnails Store miniatyrer + Clip Thumbnails to Document Bounds Klipp miniatyrer til dokumentgrensene Canvas color Lerretfarge Canvas custom color Egendefinert lerretfarge Classic Klassisk diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv index 0788559d67..169db2173c 100644 --- a/crates/ui-egui/src/i18n/nl.tsv +++ b/crates/ui-egui/src/i18n/nl.tsv @@ -128,6 +128,7 @@ Right Rechts Open Recent Recent geopend Clear Recent Files Recente bestanden wissen + Clear Recent File List Recente bestanden wissen Remove from Recent Verwijderen uit recente bestanden Remove {name} from Recent {name} verwijderen uit recente bestanden Close Sluiten @@ -136,6 +137,10 @@ Restore Herstellen Close All Alles sluiten Close Others Andere sluiten + New Document… Nieuw document… + Open Document… Openen… + Consolidate All to Here Alles hier samenvoegen + Move to New Window Verplaatsen naar nieuw venster Save Opslaan Save As… Opslaan als… Save a Copy… Kopie opslaan… @@ -187,6 +192,7 @@ Create Smart Object after Loading Layers Slim object maken na laden van lagen Reveal in Finder Weergeven in Finder Show in Explorer Weergeven in Verkenner + Reveal in Explorer Weergeven in Verkenner Show in Folder Weergeven in map File Info… Bestandsinformatie… Print… Afdrukken… @@ -275,6 +281,7 @@ Units & Rulers… Eenheden en linialen… Guides, Grid & Slices… Hulplijnen, raster en segmenten… Plug-ins… Plug-ins… + Plugins… Plug-ins… Type… Tekst… Enhanced Controls… Uitgebreide bediening… Camera Raw… Camera Raw… @@ -431,6 +438,8 @@ Smart Object Slim object Convert to Smart Object Omzetten naar slim object Convert to Embedded Omzetten naar ingesloten + Embed Linked Gekoppeld insluiten + Embed All Linked Alles gekoppeld insluiten Convert to Layers Omzetten naar lagen Convert to Linked… Omzetten naar gekoppeld… Edit Contents Inhoud bewerken @@ -504,7 +513,9 @@ Unite Shapes Vormen verenigen Subtract Front Shape Voorste vorm aftrekken Intersect Shape Areas Overlappende vormgebieden + Unite Shapes at Overlap Overlappende vormgebieden Exclude Overlapping Shapes Overlappende vormen uitsluiten + Subtract Shapes at Overlap Overlappende vormen uitsluiten Merge Shape Components Vormcomponenten samenvoegen Path operations Padbewerkingen Align Uitlijnen @@ -687,6 +698,7 @@ Minimum… Minimum… Offset… Verschuiving… Plug-ins Plug-ins + Plugins Plug-ins Proof Setup Proefinstellingen Proof Colors Proefkleuren Gamut Warning Waarschuwing kleurbereik @@ -695,9 +707,9 @@ Working Magenta Plate Werkplaat magenta Working Yellow Plate Werkplaat geel Working Black Plate Werkplaat zwart - Working CMY Plate Werkplaat CMY - Legacy Macintosh RGB Verouderde Macintosh RGB - Internet Standard RGB Internetstandaard RGB + Working CMY Plates Werkplaat CMY + Legacy Macintosh RGB (Gamma 1.8) Verouderde Macintosh RGB (Gamma 1.8) + Internet Standard RGB (sRGB) Internetstandaard RGB (sRGB) Monitor RGB Monitor-RGB Color Blindness — Protanopia-type Kleurenblindheid — type protanopie Color Blindness — Deuteranopia-type Kleurenblindheid — type deuteranopie @@ -779,7 +791,6 @@ Consolidate All to Tabs Alles samenvoegen in tabbladen Float in Window Zwevend in venster Float All in Windows Alles zwevend in vensters - New Window for Document Nieuw venster voor document Workspace Werkruimte Essentials Basis Graphic and Web Grafisch en web @@ -1948,6 +1959,11 @@ Show canvas dots Canvasstippen tonen Clip thumbnails to layer bounds Miniaturen bijsnijden tot laaggrenzen Clip Thumbnails to Layer Bounds Miniaturen bijsnijden tot laaggrenzen + No Thumbnails Geen miniaturen + Small Thumbnails Kleine miniaturen + Medium Thumbnails Middelgrote miniaturen + Large Thumbnails Grote miniaturen + Clip Thumbnails to Document Bounds Miniaturen bijsnijden tot documentgrenzen Canvas color Canvaskleur Canvas custom color Aangepaste canvaskleur Color picker Kleurkiezer diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv index eb95ddf40b..6aae9b3d84 100644 --- a/crates/ui-egui/src/i18n/pl.tsv +++ b/crates/ui-egui/src/i18n/pl.tsv @@ -171,6 +171,7 @@ Right Prawa Open Recent Otwórz ostatnie Clear Recent Files Wyczyść listę ostatnich plików + Clear Recent File List Wyczyść listę ostatnich plików Remove from Recent Usuń z ostatnich plików Remove {name} from Recent Usuń {name} z ostatnich plików Close Zamknij @@ -179,6 +180,10 @@ Restore Przywróć Close All Zamknij wszystko Close Others Zamknij pozostałe + New Document… Nowy dokument… + Open Document… Otwórz… + Consolidate All to Here Połącz wszystko tutaj + Move to New Window Przenieś do nowego okna Save Zapisz Save As… Zapisz jako… Save a Copy… Zapisz kopię… @@ -231,6 +236,7 @@ Create Smart Object after Loading Layers Utwórz obiekt inteligentny po wczytaniu warstw Reveal in Finder Pokaż w Finderze Show in Explorer Pokaż w Eksploratorze + Reveal in Explorer Pokaż w Eksploratorze Show in Folder Pokaż w folderze File Info… Informacje o pliku… Print… Drukuj… @@ -318,6 +324,7 @@ Units & Rulers… Jednostki i linijki… Guides, Grid & Slices… Prowadnice, siatka i plasterki… Plug-ins… Wtyczki… + Plugins… Wtyczki… Type… Tekst… Enhanced Controls… Ulepszone elementy sterujące… Camera Raw… Camera Raw… @@ -474,6 +481,8 @@ Smart Object Obiekt inteligentny Convert to Smart Object Konwertuj na obiekt inteligentny Convert to Embedded Konwertuj na osadzony + Embed Linked Osadź połączony + Embed All Linked Osadź wszystkie połączone Convert to Layers Konwertuj na warstwy Convert to Linked… Konwertuj na połączony… Edit Contents Edytuj zawartość @@ -547,7 +556,9 @@ Unite Shapes Złącz kształty Subtract Front Shape Odejmij kształt z przodu Intersect Shape Areas Część wspólna obszarów kształtów + Unite Shapes at Overlap Część wspólna obszarów kształtów Exclude Overlapping Shapes Wyklucz nakładające się kształty + Subtract Shapes at Overlap Wyklucz nakładające się kształty Merge Shape Components Scal składniki kształtu Path operations Operacje na ścieżkach Align Wyrównaj @@ -732,6 +743,7 @@ Minimum… Minimum… Offset… Przesunięcie… Plug-ins Wtyczki + Plugins Wtyczki Proof Setup Ustawienia próbnego wydruku Proof Colors Kolory próbne Gamut Warning Ostrzeżenie o gamucie @@ -740,9 +752,9 @@ Working Magenta Plate Robocza płyta magenty Working Yellow Plate Robocza płyta żółci Working Black Plate Robocza płyta czerni - Working CMY Plate Robocza płyta CMY - Legacy Macintosh RGB Starszy Macintosh RGB - Internet Standard RGB Standardowy RGB dla Internetu + Working CMY Plates Robocza płyta CMY + Legacy Macintosh RGB (Gamma 1.8) Starszy Macintosh RGB (Gamma 1.8) + Internet Standard RGB (sRGB) Standardowy RGB dla Internetu (sRGB) Monitor RGB RGB monitora Color Blindness — Protanopia-type Ślepota barw — typ protanopii Color Blindness — Deuteranopia-type Ślepota barw — typ deuteranopii @@ -834,7 +846,7 @@ Consolidate All to Tabs Połącz wszystko w karty Float in Window Odłącz do okna Float All in Windows Odłącz wszystko do okien - New Window for Document Nowe okno dla dokumentu + New Window Nowe okno dla dokumentu Workspace Obszar roboczy Essentials Podstawowe Graphic and Web Grafika i Internet @@ -2012,6 +2024,11 @@ Show canvas dots Pokaż kropki płótna Clip thumbnails to layer bounds Przycinaj miniatury do granic warstwy Clip Thumbnails to Layer Bounds Przycinaj miniatury do granic warstwy + No Thumbnails Bez miniaturek + Small Thumbnails Małe miniaturki + Medium Thumbnails Średnie miniaturki + Large Thumbnails Duże miniaturki + Clip Thumbnails to Document Bounds Przycinaj miniatury do granic dokumentu Canvas color Kolor płótna Canvas custom color Własny kolor płótna Color picker Próbnik kolorów diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv index 8579545a54..bee618bcbd 100644 --- a/crates/ui-egui/src/i18n/pt-br.tsv +++ b/crates/ui-egui/src/i18n/pt-br.tsv @@ -168,6 +168,7 @@ Right Direita Open Recent Abrir recentes Clear Recent Files Limpar arquivos recentes + Clear Recent File List Limpar arquivos recentes Remove from Recent Remover dos recentes Remove {name} from Recent Remover {name} dos recentes Close Fechar @@ -176,6 +177,10 @@ Restore Restaurar Close All Fechar tudo Close Others Fechar outros + New Document… Novo documento… + Open Document… Abrir… + Consolidate All to Here Consolidar tudo aqui + Move to New Window Mover para nova janela Save Salvar Save As… Salvar como… Save a Copy… Salvar uma cópia… @@ -227,6 +232,7 @@ Create Smart Object after Loading Layers Criar objeto inteligente após carregar as camadas Reveal in Finder Mostrar no Finder Show in Explorer Mostrar no Explorador + Reveal in Explorer Mostrar no Explorador Show in Folder Mostrar na pasta File Info… Informações do arquivo… Print… Imprimir… @@ -313,6 +319,7 @@ Units & Rulers… Unidades e réguas… Guides, Grid & Slices… Guias, grade e fatias… Plug-ins… Plug-ins… + Plugins… Plug-ins… Type… Tipo… Enhanced Controls… Controles aprimorados… Camera Raw… Camera Raw… @@ -462,6 +469,8 @@ Smart Object Objeto inteligente Convert to Smart Object Converter em objeto inteligente Convert to Embedded Converter em incorporado + Embed Linked Incorporar vinculado + Embed All Linked Incorporar todos os vinculados Convert to Layers Converter em camadas Convert to Linked… Converter em vinculado… Edit Contents Editar conteúdo @@ -712,6 +721,7 @@ Minimum… Mínimo… Offset… Deslocamento… Plug-ins Plug-ins + Plugins Plug-ins Proof Setup Configuração de prova Proof Colors Cores de prova Gamut Warning Aviso de gama @@ -720,9 +730,9 @@ Working Magenta Plate Chapa magenta de trabalho Working Yellow Plate Chapa amarela de trabalho Working Black Plate Chapa preta de trabalho - Working CMY Plate Chapa CMY de trabalho - Legacy Macintosh RGB RGB Macintosh legado - Internet Standard RGB RGB padrão da Internet + Working CMY Plates Chapa CMY de trabalho + Legacy Macintosh RGB (Gamma 1.8) RGB Macintosh legado (Gamma 1.8) + Internet Standard RGB (sRGB) RGB padrão da Internet (sRGB) Monitor RGB RGB do monitor Color Blindness — Protanopia-type Daltonismo — tipo protanopia Color Blindness — Deuteranopia-type Daltonismo — tipo deuteranopia @@ -814,7 +824,6 @@ Consolidate All to Tabs Consolidar tudo em guias Float in Window Flutuar na janela Float All in Windows Flutuar tudo em janelas - New Window for Document Nova janela para o documento Workspace Espaço de trabalho Essentials Essenciais Graphic and Web Gráficos e Web @@ -1973,6 +1982,11 @@ Show canvas dots Mostrar pontos da tela de pintura Clip thumbnails to layer bounds Recortar miniaturas aos limites da camada Clip Thumbnails to Layer Bounds Recortar miniaturas aos limites da camada + No Thumbnails Sem miniaturas + Small Thumbnails Miniaturas pequenas + Medium Thumbnails Miniaturas médias + Large Thumbnails Miniaturas grandes + Clip Thumbnails to Document Bounds Recortar miniaturas aos limites do documento Canvas color Cor da tela de pintura Canvas custom color Cor personalizada da tela de pintura Color picker Seletor de cores diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv index 4b32187aa2..a9daa9c8f4 100644 --- a/crates/ui-egui/src/i18n/ru.tsv +++ b/crates/ui-egui/src/i18n/ru.tsv @@ -272,6 +272,7 @@ Right Правый Open Recent Открыть недавние Clear Recent Files Очистить список недавних файлов + Clear Recent File List Очистить список недавних файлов Remove from Recent Удалить из недавних Remove {name} from Recent Удалить {name} из недавних Close Закрыть @@ -280,6 +281,10 @@ Restore Свернуть в окно Close All Закрыть все Close Others Закрыть остальные + New Document… Новый документ… + Open Document… Открыть… + Consolidate All to Here Объединить всё здесь + Move to New Window Переместить в новое окно Save Сохранить Save As… Сохранить как… Save a Copy… Сохранить копию… @@ -676,7 +681,6 @@ Match Location Согласовать положение Match Rotation Согласовать поворот Match All Согласовать всё - New Window for Document Новое окно документа Workspace Рабочая среда Extensions Расширения Panels Панели @@ -846,6 +850,7 @@ Units & Rulers… Единицы и линейки… Guides, Grid & Slices… Направляющие, сетка и фрагменты… Plug-ins… Плагины… + Plugins… Плагины… Technology Previews Предпросмотр технологий Scratch Disks… Рабочие диски… Export Preferences… Экспорт настроек… @@ -1068,8 +1073,8 @@ ACES ACES Industry Standard Отраслевой стандарт Web Web - Internet Standard RGB Стандартный RGB для Интернета - Legacy Macintosh RGB Устаревший RGB Macintosh + Internet Standard RGB (sRGB) Стандартный RGB для Интернета (sRGB) + Legacy Macintosh RGB (Gamma 1.8) Устаревший RGB Macintosh (Gamma 1.8) Monitor RGB Монитор RGB Windows LCD Windows LCD Coated CMYK Мелованная бумага CMYK @@ -1853,6 +1858,7 @@ Saved Сохранено Reveal in Finder Показать в Finder Show in Explorer Показать в Проводнике + Reveal in Explorer Показать в Проводнике Show in Folder Показать в папке Before (Y) До (Y) Save Settings… Сохранить настройки… @@ -2018,6 +2024,8 @@ Combine Shapes Комбинировать фигуры Contract… Сжать… Convert to Embedded Преобразовать во встроенный + Embed Linked Встроить связанный + Embed All Linked Встроить все связанные Convert to Layers Преобразовать в слои Convert to Linked… Преобразовать в связанный… Count Счёт @@ -2106,6 +2114,7 @@ Pixelate Оформление пикселями Place Scale Marker… Шкала масштаба… Plug-ins Плагины + Plugins Плагины Print One Copy Печать одной копии Print… Печать… Range Диапазон @@ -2150,7 +2159,7 @@ Vertical Centers Центры по вертикали Video Frames to Layers… Видеокадры в слои… WIA Support… Поддержка WIA… - Working CMY Plate Рабочая голубая форма + Working CMY Plates Рабочая голубая форма Absolute Абсолютный Action Операция Adaptive Адаптивный @@ -2431,6 +2440,11 @@ Show canvas dots Показывать точки холста Clip thumbnails to layer bounds Обрезать миниатюры по границам слоя Clip Thumbnails to Layer Bounds Обрезать миниатюры по границам слоя + No Thumbnails Без миниатюр + Small Thumbnails Мелкие миниатюры + Medium Thumbnails Средние миниатюры + Large Thumbnails Крупные миниатюры + Clip Thumbnails to Document Bounds Обрезать миниатюры по границам документа Canvas color Цвет холста Canvas custom color Свой цвет холста Classic Классическая diff --git a/crates/ui-egui/src/i18n/sr.tsv b/crates/ui-egui/src/i18n/sr.tsv index ce8b82ae26..4ff32db75a 100644 --- a/crates/ui-egui/src/i18n/sr.tsv +++ b/crates/ui-egui/src/i18n/sr.tsv @@ -196,6 +196,7 @@ Right Desno Open Recent Otvori nedavno Clear Recent Files Obriši spisak nedavnih datoteka + Clear Recent File List Obriši spisak nedavnih datoteka Remove from Recent Ukloni iz nedavnih Remove {name} from Recent Ukloni {name} iz nedavnih Close Zatvori @@ -204,6 +205,10 @@ Restore Vrati Close All Zatvori sve Close Others Zatvori ostale + New Document… Novi dokument… + Open Document… Otvori… + Consolidate All to Here Objedini sve ovde + Move to New Window Premesti u novi prozor Save Sačuvaj Save As… Sačuvaj kao… Save a Copy… Sačuvaj kopiju… @@ -255,6 +260,7 @@ Create Smart Object after Loading Layers Napravi pametni objekat posle učitavanja slojeva Reveal in Finder Prikaži u Finderu Show in Explorer Prikaži u Exploreru + Reveal in Explorer Prikaži u Exploreru Show in Folder Prikaži u fascikli File Info… Informacije o datoteci… Print… Štampaj… @@ -339,6 +345,7 @@ Units & Rulers… Jedinice i lenjiri… Guides, Grid & Slices… Vodilje, mreža i isečci… Plug-ins… Dodaci… + Plugins… Dodaci… Type… Tekst… Enhanced Controls… Napredne kontrole… Camera Raw… Camera Raw… @@ -487,6 +494,8 @@ Smart Object Pametni objekat Convert to Smart Object Pretvori u pametni objekat Convert to Embedded Pretvori u ugrađeni + Embed Linked Ugradi povezani + Embed All Linked Ugradi sve povezane Convert to Layers Pretvori u slojeve Convert to Linked… Pretvori u povezani… Edit Contents Uredi sadržaj @@ -738,6 +747,7 @@ Minimum… Minimum… Offset… Pomak… Plug-ins Dodaci + Plugins Dodaci Proof Setup Podešavanje probnog prikaza Proof Colors Probne boje Gamut Warning Upozorenje o gamutu @@ -746,9 +756,9 @@ Working Magenta Plate Radna magenta ploča Working Yellow Plate Radna žuta ploča Working Black Plate Radna crna ploča - Working CMY Plate Radna CMY ploča - Legacy Macintosh RGB Stari Macintosh RGB - Internet Standard RGB Internet standard RGB + Working CMY Plates Radna CMY ploča + Legacy Macintosh RGB (Gamma 1.8) Stari Macintosh RGB (Gamma 1.8) + Internet Standard RGB (sRGB) Internet standard RGB (sRGB) Monitor RGB RGB monitora Color Blindness — Protanopia-type Daltonizam — tip protanopije Color Blindness — Deuteranopia-type Daltonizam — tip deuteranopije @@ -840,7 +850,6 @@ Consolidate All to Tabs Objedini sve u kartice Float in Window Odvoji u prozor Float All in Windows Odvoji sve u prozore - New Window for Document Novi prozor za dokument Workspace Radni prostor Essentials Osnovno Graphic and Web Grafika i veb @@ -1989,6 +1998,11 @@ Show canvas dots Prikaži tačke na platnu Clip thumbnails to layer bounds Iseci sličice prema granicama sloja Clip Thumbnails to Layer Bounds Iseci sličice prema granicama sloja + No Thumbnails Bez sličica + Small Thumbnails Male sličice + Medium Thumbnails Srednje sličice + Large Thumbnails Velike sličice + Clip Thumbnails to Document Bounds Iseci sličice prema granicama dokumenta Canvas color Boja platna Canvas custom color Prilagođena boja platna Color picker Birač boja diff --git a/crates/ui-egui/src/i18n/sv.tsv b/crates/ui-egui/src/i18n/sv.tsv index e7f1f83489..4c9e6a12f6 100644 --- a/crates/ui-egui/src/i18n/sv.tsv +++ b/crates/ui-egui/src/i18n/sv.tsv @@ -84,6 +84,7 @@ Right Höger Open Recent Öppna senaste Clear Recent Files Rensa senaste filer + Clear Recent File List Rensa senaste filer Remove from Recent Ta bort från senaste Remove {name} from Recent Ta bort {name} från senaste Close Stäng @@ -92,6 +93,10 @@ Restore Återställ Close All Stäng alla Close Others Stäng övriga + New Document… Nytt dokument… + Open Document… Öppna… + Consolidate All to Here Samla alla här + Move to New Window Flytta till nytt fönster Save Spara Save As… Spara som… Save a Copy… Spara en kopia… @@ -506,7 +511,6 @@ Match Location Matcha plats Match Rotation Matcha rotation Match All Matcha alla - New Window for Document Nytt fönster för dokument Workspace Arbetsyta Extensions Tillägg Panels Paneler @@ -684,6 +688,7 @@ Units & Rulers… Enheter och linjaler… Guides, Grid & Slices… Stödlinjer, rutnät och skivor… Plug-ins… Plugin-program… + Plugins… Plugin-program… Technology Previews Teknikförhandsgranskningar Scratch Disks… Arbetsdiskar… Export Preferences… Exportinställningar… @@ -918,8 +923,8 @@ ACES ACES Industry Standard Branschstandard Web Webb - Internet Standard RGB Internetstandard-RGB - Legacy Macintosh RGB Äldre Macintosh RGB + Internet Standard RGB (sRGB) Internetstandard-RGB (sRGB) + Legacy Macintosh RGB (Gamma 1.8) Äldre Macintosh RGB (Gamma 1.8) Monitor RGB Bildskärms-RGB Windows LCD Windows LCD Coated CMYK Bestruket CMYK @@ -1740,6 +1745,7 @@ Saved Sparat Reveal in Finder Visa i Finder Show in Explorer Visa i Utforskaren + Reveal in Explorer Visa i Utforskaren Show in Folder Visa i mapp Before (Y) Före (Y) Save Settings… Spara inställningar… @@ -1919,6 +1925,8 @@ Combine Shapes Kombinera former Contract… Dra ihop… Convert to Embedded Konvertera till inbäddat + Embed Linked Bädda in länkat + Embed All Linked Bädda in alla länkade Convert to Layers Konvertera till lager Convert to Linked… Konvertera till länkat… Count Antal @@ -2006,6 +2014,7 @@ Pixelate Pixla Place Scale Marker… Placera skalmarkör… Plug-ins Plugin-program + Plugins Plugin-program Print One Copy Skriv ut en kopia Print… Skriv ut… Range Intervall @@ -2050,7 +2059,7 @@ Vertical Centers Lodräta mittpunkter Video Frames to Layers… Videobildrutor till lager… WIA Support… WIA-stöd… - Working CMY Plate CMY-arbetsplåt + Working CMY Plates CMY-arbetsplåt # tl! literals (third pass) Absolute Absolut @@ -2336,6 +2345,11 @@ Show canvas dots Visa punkter på arbetsytan Clip thumbnails to layer bounds Begränsa miniatyrer till lagergränser Clip Thumbnails to Layer Bounds Begränsa miniatyrer till lagergränser + No Thumbnails Inga miniatyrer + Small Thumbnails Små miniatyrer + Medium Thumbnails Medelstora miniatyrer + Large Thumbnails Stora miniatyrer + Clip Thumbnails to Document Bounds Begränsa miniatyrer till dokumentgränser Canvas color Arbetsytans färg Canvas custom color Anpassad färg för arbetsytan Classic Klassisk diff --git a/crates/ui-egui/src/i18n/tr.tsv b/crates/ui-egui/src/i18n/tr.tsv index 331eb4e2b3..7b7108878d 100644 --- a/crates/ui-egui/src/i18n/tr.tsv +++ b/crates/ui-egui/src/i18n/tr.tsv @@ -95,6 +95,7 @@ Right Sağ Open Recent Son Kullanılanları Aç Clear Recent Files Son Dosyaları Temizle + Clear Recent File List Son Dosyaları Temizle Remove from Recent Son Kullanılanlardan Kaldır Remove {name} from Recent {name} öğesini Son Kullanılanlardan kaldır Close Kapat @@ -103,6 +104,10 @@ Restore Geri yükle Close All Tümünü Kapat Close Others Diğerlerini Kapat + New Document… Yeni Belge… + Open Document… Aç… + Consolidate All to Here Tümünü Buraya Birleştir + Move to New Window Yeni Pencereye Taşı Save Kaydet Save As… Farklı Kaydet… Save a Copy… Bir Kopyasını Kaydet… @@ -154,6 +159,7 @@ Create Smart Object after Loading Layers Katmanları Yükledikten Sonra Akıllı Nesne Oluştur Reveal in Finder Finder'da Göster Show in Explorer Explorer'da Göster + Reveal in Explorer Explorer'da Göster Show in Folder Klasörde Göster File Info… Dosya Bilgileri… Print… Yazdır… @@ -242,6 +248,7 @@ Units & Rulers… Birimler ve Cetveller… Guides, Grid & Slices… Kılavuzlar, Izgaralar ve Dilimler… Plug-ins… Eklentiler… + Plugins… Eklentiler… Type… Metin… Enhanced Controls… Gelişmiş Kontroller… Camera Raw… Camera Raw… @@ -397,6 +404,8 @@ Smart Object Akıllı Nesne Convert to Smart Object Akıllı Nesneye Dönüştür Convert to Embedded Gömülüye Dönüştür + Embed Linked Bağlantılıyı Göm + Embed All Linked Tüm Bağlantılıları Göm Convert to Layers Katmanlara Dönüştür Convert to Linked… Bağlantılıya Dönüştür… Edit Contents İçeriği Düzenle @@ -469,7 +478,9 @@ Unite Shapes Şekil Alanlarını Birleştir Subtract Front Shape Ön Şekli Çıkar Intersect Shape Areas Şekil Alanlarını Kesiştir + Unite Shapes at Overlap Şekil Alanlarını Kesiştir Exclude Overlapping Shapes Çakışan Şekilleri Hariç Tut + Subtract Shapes at Overlap Çakışan Şekilleri Hariç Tut Merge Shape Components Şekil Bileşenlerini Birleştir Path operations Yol işlemleri Align Hizala @@ -652,6 +663,7 @@ Minimum… Minimum… Offset… Kaydırma… Plug-ins Eklentiler + Plugins Eklentiler Proof Setup Prova Kurulumu Proof Colors Prova Renkleri Gamut Warning Gamut Uyarısı @@ -660,9 +672,9 @@ Working Magenta Plate Çalışma Macenta Plakası Working Yellow Plate Çalışma Sarı Plakası Working Black Plate Çalışma Siyah Plakası - Working CMY Plate Çalışma CMY Plakası - Legacy Macintosh RGB Eski Macintosh RGB - Internet Standard RGB İnternet Standardı RGB + Working CMY Plates Çalışma CMY Plakası + Legacy Macintosh RGB (Gamma 1.8) Eski Macintosh RGB (Gamma 1.8) + Internet Standard RGB (sRGB) İnternet Standardı RGB (sRGB) Monitor RGB Monitör RGB Color Blindness — Protanopia-type Renk Körlüğü — Protanopi tipi Color Blindness — Deuteranopia-type Renk Körlüğü — Döteranopi tipi @@ -744,7 +756,6 @@ Consolidate All to Tabs Tümünü Sekmelerde Birleştir Float in Window Pencerede Yüzdür Float All in Windows Tümünü Pencerelerde Yüzdür - New Window for Document Belge için Yeni Pencere Workspace Çalışma alanı Essentials Temel Öğeler Graphic and Web Grafik ve Web @@ -1901,6 +1912,11 @@ Show canvas dots Tuval noktalarını göster Clip thumbnails to layer bounds Küçük resimleri katman sınırlarına kırp Clip Thumbnails to Layer Bounds Küçük resimleri katman sınırlarına kırp + No Thumbnails Küçük Resim Yok + Small Thumbnails Küçük Boyutlu Küçük Resimler + Medium Thumbnails Orta Boyutlu Küçük Resimler + Large Thumbnails Büyük Boyutlu Küçük Resimler + Clip Thumbnails to Document Bounds Küçük resimleri belge sınırlarına kırp Canvas color Tuval rengi Canvas custom color Tuval özel rengi Color picker Renk seçici diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv index cf51dca7f8..327d20fb7f 100644 --- a/crates/ui-egui/src/i18n/uk.tsv +++ b/crates/ui-egui/src/i18n/uk.tsv @@ -255,6 +255,7 @@ Right Правий Open Recent Нещодавні файли Clear Recent Files Очистити список нещодавніх файлів + Clear Recent File List Очистити список нещодавніх файлів Remove from Recent Вилучити з нещодавніх Remove {name} from Recent Вилучити {name} з нещодавніх Close Закрити @@ -263,6 +264,10 @@ Restore Відновити Close All Закрити всі Close Others Закрити інші + New Document… Новий документ… + Open Document… Відкрити… + Consolidate All to Here Об'єднати все тут + Move to New Window Перемістити в нове вікно Save Зберегти Save As… Зберегти як… Save a Copy… Зберегти копію… @@ -646,7 +651,7 @@ Match Location Узгодити розташування Match Rotation Узгодити поворот Match All Узгодити все - New Window for Document Нове вікно для документа + New Window Нове вікно для документа Workspace Робочий простір Extensions Розширення Panels Панелі @@ -816,6 +821,7 @@ Units & Rulers… Одиниці та лінійки… Guides, Grid & Slices… Напрямні, сітка та фрагменти… Plug-ins… Плагіни… + Plugins… Плагіни… Technology Previews Попередній перегляд технологій Scratch Disks… Робочі диски… Export Preferences… Налаштування експорту… @@ -1038,8 +1044,8 @@ ACES ACES Industry Standard Галузевий стандарт Web Веб - Internet Standard RGB Стандартний RGB для інтернету - Legacy Macintosh RGB Застарілий Macintosh RGB + Internet Standard RGB (sRGB) Стандартний RGB для інтернету (sRGB) + Legacy Macintosh RGB (Gamma 1.8) Застарілий Macintosh RGB (Gamma 1.8) Monitor RGB RGB монітора Windows LCD Windows LCD Coated CMYK CMYK для крейдованого паперу @@ -1822,6 +1828,7 @@ Saved Збережено Reveal in Finder Показати у Finder Show in Explorer Показати у Провіднику + Reveal in Explorer Показати у Провіднику Show in Folder Показати в теці Before (Y) До (Y) Save Settings… Зберегти налаштування… @@ -1985,6 +1992,8 @@ Combine Shapes Об'єднати фігури Contract… Стиснути… Convert to Embedded Перетворити на вбудований + Embed Linked Вбудувати пов'язаний + Embed All Linked Вбудувати всі пов'язані Convert to Layers Перетворити на шари Convert to Linked… Перетворити на пов'язаний… Count Підрахунок @@ -2007,6 +2016,7 @@ Enhanced Controls… Розширені елементи керування… Entropy Ентропія Exclude Overlapping Shapes Виключити перекриття фігур + Subtract Shapes at Overlap Виключити перекриття фігур Exit Вийти Expand… Розширити… Extra Large Дуже великий @@ -2032,6 +2042,7 @@ Indexed Color… Індексований колір… Integrations… Інтеграції… Intersect Shape Areas Перетин областей фігур + Unite Shapes at Overlap Перетин областей фігур Kurtosis Ексцес Large Великий Layer Edges Краї шару @@ -2073,6 +2084,7 @@ Pixelate Пікселізація Place Scale Marker… Розмістити маркер масштабу… Plug-ins Плагіни + Plugins Плагіни Print One Copy Надрукувати одну копію Print… Друк… Range Діапазон @@ -2117,7 +2129,7 @@ Vertical Centers Вертикальні центри Video Frames to Layers… Відеокадри в шари… WIA Support… Підтримка WIA… - Working CMY Plate Робоча форма CMY + Working CMY Plates Робоча форма CMY Absolute Абсолютний Action Дія Adaptive Адаптивний @@ -2394,6 +2406,11 @@ Show canvas dots Показувати крапки полотна Clip thumbnails to layer bounds Обрізати мініатюри до меж шару Clip Thumbnails to Layer Bounds Обрізати мініатюри до меж шару + No Thumbnails Без мініатюр + Small Thumbnails Малі мініатюри + Medium Thumbnails Середні мініатюри + Large Thumbnails Великі мініатюри + Clip Thumbnails to Document Bounds Обрізати мініатюри до меж документа Canvas color Колір полотна Canvas custom color Довільний колір полотна Classic Класична diff --git a/crates/ui-egui/src/i18n/vi.tsv b/crates/ui-egui/src/i18n/vi.tsv index ea6c94395f..9890267d85 100644 --- a/crates/ui-egui/src/i18n/vi.tsv +++ b/crates/ui-egui/src/i18n/vi.tsv @@ -188,10 +188,15 @@ Check Spelling… Kiểm tra chính tả… Clear Xóa Clear Recent Files Xóa tệp gần đây + Clear Recent File List Xóa tệp gần đây Clipboard Bảng tạm Close Đóng Close All Đóng tất cả Close Others Đóng các tệp khác + New Document… Tài liệu mới… + Open Document… Mở… + Consolidate All to Here Gom tất cả vào đây + Move to New Window Di chuyển sang cửa sổ mới Color Lookup Tables… Bảng tra màu… Color Settings… Cài đặt màu… Conditional Mode Change… Đổi chế độ có điều kiện… @@ -275,6 +280,7 @@ Place Embedded… Đặt nhúng… Place Linked… Đặt liên kết… Plug-ins… Plug-in… + Plugins… Plug-in… Preferences Tùy chọn Preset Manager… Quản lý thiết lập sẵn… Presets Thiết lập sẵn @@ -373,6 +379,8 @@ Color Table… Bảng màu… Combine Shapes Kết hợp hình Convert to Embedded Chuyển thành nhúng + Embed Linked Nhúng mục liên kết + Embed All Linked Nhúng tất cả mục liên kết Convert to Layers Chuyển thành lớp Convert to Linked… Chuyển thành liên kết… Convert to Smart Object Chuyển thành đối tượng thông minh @@ -404,6 +412,7 @@ Entropy Entropy Equalize Cân bằng histogram Exclude Overlapping Shapes Loại phần chồng hình + Subtract Shapes at Overlap Loại phần chồng hình Export Contents… Xuất nội dung… Exposure… Phơi sáng… Fill Content Nội dung tô @@ -438,6 +447,7 @@ Insert Blank Frame Chèn khung trống Interpret Footage… Diễn giải footage… Intersect Shape Areas Giao vùng hình + Unite Shapes at Overlap Giao vùng hình Invert Đảo màu Invert… Đảo màu… Kurtosis Kurtosis @@ -733,10 +743,10 @@ Grid Lưới Guides Đường căn HDV 1080/DVCPRO HD 720 (1.33) HDV 1080/DVCPRO HD 720 (1.33) - Internet Standard RGB RGB chuẩn Internet + Internet Standard RGB (sRGB) RGB chuẩn Internet (sRGB) Layer Edges Cạnh lớp Layers Các lớp - Legacy Macintosh RGB RGB Macintosh cũ + Legacy Macintosh RGB (Gamma 1.8) RGB Macintosh cũ (Gamma 1.8) Lock Guides Khóa đường căn Lock Slices Khóa lát cắt Mesh Lưới @@ -766,7 +776,7 @@ Standard Screen Mode Chế độ màn hình chuẩn Target Path Đường dẫn đích Working Black Plate Bản Black làm việc - Working CMY Plate Bản CMY làm việc + Working CMY Plates Bản CMY làm việc Working CMYK CMYK làm việc Working Cyan Plate Bản Cyan làm việc Working Magenta Plate Bản Magenta làm việc @@ -813,7 +823,7 @@ Modifier Keys Phím bổ trợ Motion Chuyển động Navigator Điều hướng - New Window for Document Cửa sổ mới cho tài liệu + New Window Cửa sổ mới cho tài liệu New Workspace… Không gian làm việc mới… Next Theme Chủ đề tiếp theo Options Thanh tùy chọn @@ -1605,6 +1615,7 @@ cameraRaw Shadows Vùng tối Picas Pica Pixels Pixel Plug-ins Plug-in + Plugins Plug-in Png PNG Point size Cỡ point Points Point @@ -2614,6 +2625,7 @@ shape Appearance Diện mạo (coming soon) (sắp có) Add beauty precomp from the AOVs Thêm precomp beauty từ các AOV Show in Explorer Hiện trong Explorer + Reveal in Explorer Hiện trong Explorer Show in Folder Hiện trong thư mục Delete and Fill Selection Xoá và tô vùng chọn Transform Again on a Copy Biến đổi lại trên một bản sao @@ -2755,6 +2767,11 @@ shape Appearance Diện mạo Show canvas dots Hiện chấm vùng vẽ Clip thumbnails to layer bounds Cắt hình thu nhỏ theo biên của lớp Clip Thumbnails to Layer Bounds Cắt hình thu nhỏ theo biên của lớp + No Thumbnails Không có hình thu nhỏ + Small Thumbnails Hình thu nhỏ cỡ nhỏ + Medium Thumbnails Hình thu nhỏ cỡ vừa + Large Thumbnails Hình thu nhỏ cỡ lớn + Clip Thumbnails to Document Bounds Cắt hình thu nhỏ theo biên của tài liệu Color picker Bộ chọn màu Color space Không gian màu Column width Độ rộng cột diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv index 7cd411fe7e..e1039a735d 100644 --- a/crates/ui-egui/src/i18n/zh-hans.tsv +++ b/crates/ui-egui/src/i18n/zh-hans.tsv @@ -174,6 +174,7 @@ Right 右 Open Recent 打开最近文件 Clear Recent Files 清除最近文件 + Clear Recent File List 清除最近文件 Remove from Recent 从最近文件中移除 Remove {name} from Recent 从最近文件中移除 {name} Close 关闭 @@ -182,6 +183,10 @@ Restore 向下还原 Close All 关闭全部 Close Others 关闭其他 + New Document… 新建文档… + Open Document… 打开… + Consolidate All to Here 将所有窗口合并到此处 + Move to New Window 移到新窗口 Save 保存 Save As… 另存为… Save a Copy… 保存副本… @@ -234,6 +239,7 @@ Create Smart Object after Loading Layers 载入图层后创建智能对象 Reveal in Finder 在 Finder 中显示 Show in Explorer 在文件资源管理器中显示 + Reveal in Explorer 在文件资源管理器中显示 Show in Folder 在文件夹中显示 File Info… 文件信息… Print… 打印… @@ -323,6 +329,7 @@ Units & Rulers… 单位与标尺… Guides, Grid & Slices… 参考线、网格与切片… Plug-ins… 插件… + Plugins… 插件… Type… 文字… 3D… 3D… Enhanced Controls… 增强控件… @@ -482,6 +489,8 @@ Smart Object 智能对象 Convert to Smart Object 转换为智能对象 Convert to Embedded 转换为嵌入对象 + Embed Linked 嵌入链接对象 + Embed All Linked 嵌入所有链接对象 Convert to Layers 转换为图层 Convert to Linked… 转换为链接对象… Edit Contents 编辑内容 @@ -555,7 +564,9 @@ Unite Shapes 合并形状 Subtract Front Shape 减去前面形状 Intersect Shape Areas 形状区域相交 + Unite Shapes at Overlap 形状区域相交 Exclude Overlapping Shapes 排除重叠形状 + Subtract Shapes at Overlap 排除重叠形状 Merge Shape Components 合并形状组件 Path operations 路径操作 Align 对齐 @@ -740,6 +751,7 @@ Minimum… 最小值… Offset… 位移… Plug-ins 插件 + Plugins 插件 Proof Setup 校样设置 Proof Colors 校样颜色 Gamut Warning 色域警告 @@ -748,9 +760,9 @@ Working Magenta Plate 工作洋红版 Working Yellow Plate 工作黄色版 Working Black Plate 工作黑色版 - Working CMY Plate 工作 CMY 版 - Legacy Macintosh RGB 旧版 Macintosh RGB - Internet Standard RGB 互联网标准 RGB + Working CMY Plates 工作 CMY 版 + Legacy Macintosh RGB (Gamma 1.8) 旧版 Macintosh RGB (Gamma 1.8) + Internet Standard RGB (sRGB) 互联网标准 RGB (sRGB) Monitor RGB 显示器 RGB Color Blindness — Protanopia-type 色盲 — 红色盲型 Color Blindness — Deuteranopia-type 色盲 — 绿色盲型 @@ -842,7 +854,7 @@ Consolidate All to Tabs 将所有窗口合并为选项卡 Float in Window 在窗口中浮动 Float All in Windows 使所有文档在窗口中浮动 - New Window for Document 为文档新建窗口 + New Window 为文档新建窗口 Workspace 工作区 Essentials 基本功能 Graphic and Web 图形与 Web @@ -2052,6 +2064,11 @@ Show canvas dots 显示画布圆点 Clip thumbnails to layer bounds 将缩略图裁剪到图层边界 Clip Thumbnails to Layer Bounds 将缩略图裁剪到图层边界 + No Thumbnails 无缩略图 + Small Thumbnails 小缩略图 + Medium Thumbnails 中缩略图 + Large Thumbnails 大缩略图 + Clip Thumbnails to Document Bounds 将缩略图裁剪到文档边界 Canvas color 画布颜色 Canvas custom color 画布自定颜色 Color picker 拾色器 diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv index b365497064..0630f30f06 100644 --- a/crates/ui-egui/src/i18n/zh-hant.tsv +++ b/crates/ui-egui/src/i18n/zh-hant.tsv @@ -176,6 +176,7 @@ Right 右 Open Recent 最近開啟的檔案 Clear Recent Files 清除最近檔案 + Clear Recent File List 清除最近檔案 Remove from Recent 從最近檔案中移除 Remove {name} from Recent 從最近檔案中移除 {name} Close 關閉 @@ -184,6 +185,10 @@ Restore 向下還原 Close All 全部關閉 Close Others 關閉其他 + New Document… 新增文件… + Open Document… 開啟… + Consolidate All to Here 將所有視窗合併至此處 + Move to New Window 移至新視窗 Save 儲存 Save As… 另存新檔… Save a Copy… 儲存拷貝… @@ -236,6 +241,7 @@ Create Smart Object after Loading Layers 載入圖層後建立智慧型物件 Reveal in Finder 在 Finder 中顯示 Show in Explorer 在檔案總管中顯示 + Reveal in Explorer 在檔案總管中顯示 Show in Folder 在資料夾中顯示 File Info… 檔案資訊… Print… 列印… @@ -324,6 +330,7 @@ Units & Rulers… 單位和尺標… Guides, Grid & Slices… 參考線、格點和切片… Plug-ins… 增效模組… + Plugins… 增效模組… Type… 文字… Enhanced Controls… 增強控制項… Camera Raw… Camera Raw… @@ -481,6 +488,8 @@ Smart Object 智慧型物件 Convert to Smart Object 轉換為智慧型物件 Convert to Embedded 轉換為嵌入 + Embed Linked 嵌入連結 + Embed All Linked 嵌入所有連結 Convert to Layers 轉換為圖層 Convert to Linked… 轉換為連結… Edit Contents 編輯內容 @@ -554,7 +563,9 @@ Unite Shapes 聯集形狀 Subtract Front Shape 減去前方形狀 Intersect Shape Areas 交集形狀區域 + Unite Shapes at Overlap 交集形狀區域 Exclude Overlapping Shapes 排除重疊形狀 + Subtract Shapes at Overlap 排除重疊形狀 Merge Shape Components 合併形狀元件 Path operations 路徑操作 Align 對齊 @@ -739,6 +750,7 @@ Minimum… 最小… Offset… 畫面錯位… Plug-ins 增效模組 + Plugins 增效模組 Proof Setup 校樣設定 Proof Colors 校樣色彩 Gamut Warning 色域警告 @@ -747,9 +759,9 @@ Working Magenta Plate 使用中的洋紅版 Working Yellow Plate 使用中的黃色版 Working Black Plate 使用中的黑色版 - Working CMY Plate 使用中的 CMY 版 - Legacy Macintosh RGB 舊版 Macintosh RGB - Internet Standard RGB 網際網路標準 RGB + Working CMY Plates 使用中的 CMY 版 + Legacy Macintosh RGB (Gamma 1.8) 舊版 Macintosh RGB (Gamma 1.8) + Internet Standard RGB (sRGB) 網際網路標準 RGB (sRGB) Monitor RGB 顯示器 RGB Color Blindness — Protanopia-type 色盲 — 紅色盲型 Color Blindness — Deuteranopia-type 色盲 — 綠色盲型 @@ -841,7 +853,7 @@ Consolidate All to Tabs 全部合併至標籤頁 Float in Window 在視窗中浮動 Float All in Windows 全部在視窗中浮動 - New Window for Document 為文件新增視窗 + New Window 為文件新增視窗 Workspace 工作區 Essentials 基本功能 Graphic and Web 繪圖和網頁 @@ -2020,6 +2032,11 @@ Show canvas dots 顯示畫布圓點 Clip thumbnails to layer bounds 將縮圖裁切至圖層邊界 Clip Thumbnails to Layer Bounds 將縮圖裁切至圖層邊界 + No Thumbnails 無縮圖 + Small Thumbnails 小縮圖 + Medium Thumbnails 中縮圖 + Large Thumbnails 大縮圖 + Clip Thumbnails to Document Bounds 將縮圖裁切至文件邊界 Canvas color 畫布顏色 Canvas custom color 畫布自訂顏色 Color picker 檢色器 diff --git a/crates/ui-egui/src/input/hold_keys/tests.rs b/crates/ui-egui/src/input/hold_keys/tests.rs index 8a2fbec54e..61d78d9ed3 100644 --- a/crates/ui-egui/src/input/hold_keys/tests.rs +++ b/crates/ui-egui/src/input/hold_keys/tests.rs @@ -612,7 +612,8 @@ fn cmd_alt_drag_duplicates_the_layer_then_moves_the_copy() { assert_eq!(bounds(&h, orig), Rect::new(100, 100, 160, 160), "the original stays"); assert_eq!(bounds(&h, copy), Rect::new(140, 120, 200, 180), "the copy moved"); assert_eq!(st.history.past_len(), h0 + 1, "one undo step"); - assert_eq!(st.history.undo_label(), Some(crate::move_mods::DUPLICATE_MOVE_LABEL)); + // A drag that copies a layer is one "Move" step, as in Photoshop (#11383). + assert_eq!(st.history.undo_label(), Some(tl!("Move"))); assert_eq!(h.state().ui.tool, tool); } } diff --git a/crates/ui-egui/src/input/shortcut_dispatch/tests.rs b/crates/ui-egui/src/input/shortcut_dispatch/tests.rs index 633bb89ca8..ce7e3fcc39 100644 --- a/crates/ui-egui/src/input/shortcut_dispatch/tests.rs +++ b/crates/ui-egui/src/input/shortcut_dispatch/tests.rs @@ -386,6 +386,8 @@ fn alternate_keys_run_their_command() { ("Cmd+Shift+I", "select.inverse"), ("Cmd++", "view.zoomIn"), ("Shift+Backspace", "edit.fill"), + ("Cmd+Alt+0", "view.actualPixels"), + ("F9", "window.panel.actions"), ] { press(&mut h, key); let log = take_log(&h.ctx); diff --git a/crates/ui-egui/src/input/shortcuts.rs b/crates/ui-egui/src/input/shortcuts.rs index 8cf978e36c..b0304b8237 100644 --- a/crates/ui-egui/src/input/shortcuts.rs +++ b/crates/ui-egui/src/input/shortcuts.rs @@ -708,6 +708,11 @@ fn handle_pen_and_work_path_keys(app: &mut PhotocraftApp, ctx: &egui::Context, f crate::vector_ui::pen_end(app); return true; } + // A shape box handle drag: Esc drops it, the shapes keep their size (#11107). + if app.ui.shape_box.is_some() && ctx.input_mut(|i| i.consume_key(Modifiers::NONE, Key::Escape)) { + crate::shape_bounds_box::cancel(app); + return true; + } // A finished work path shown by the Pen or Path Selection: ⌫/Delete deletes it, as in // Photoshop (#5702), never Edit › Clear on the pixels under it. if focus != crate::shortcut_dispatch::Focus::DeletingWidget && crate::vector_ui::delete_key_deletes_work_path(app) { @@ -909,12 +914,18 @@ fn select_tool_by_key(app: &mut PhotocraftApp, ctx: &egui::Context, pressed: &im let cycle_shift = shift_switch && ctx.input_mut(|i| i.consume_key(Modifiers::SHIFT, k)); if cycle_shift || pressed(k) { let before = app.ui.tool; - let group: Vec = Tool::ALL.iter().copied().filter(|x| x.key() == t.key() && crate::tool_shortcuts::uses_default(app, *x)).collect(); + let mut group: Vec = Tool::ALL.iter().copied().filter(|x| x.key() == t.key() && crate::tool_shortcuts::uses_default(app, *x)).collect(); + // Shift+key (the cycle and the fallback to the group's first tool) uses the toolbar + // flyout's order; plain keys keep the `Tool::ALL` order. + if cycle_shift { + group.sort_by_key(|x| crate::panels::toolbar::toolbar_position(*x)); + } app.ui.tool = match group.iter().position(|x| *x == app.ui.tool) { Some(i) if shift_switch && !cycle_shift => group[i], Some(i) => group[(i + 1) % group.len()], None => app.ui.group_tool(t.key()).filter(|last| group.contains(last)).unwrap_or(group[0]), }; + crate::tool_memory::ended_by_tool(app); // `consume_key` ignores extra ⇧ and ⌥: a ⇧/⌥ switch is never spring-loaded. let (plain, now) = ctx.input(|i| (!cycle_shift && !i.modifiers.shift && !i.modifiers.alt, i.time)); crate::spring_tools::pressed(app, t.key(), before, plain, now); diff --git a/crates/ui-egui/src/input/stylus.rs b/crates/ui-egui/src/input/stylus.rs index 73191e4ebd..b6725af5ea 100644 --- a/crates/ui-egui/src/input/stylus.rs +++ b/crates/ui-egui/src/input/stylus.rs @@ -336,6 +336,8 @@ impl Stylus { Some(true) if app.ui.tool != Tool::Eraser => { app.stylus.tool_before_eraser = Some(app.ui.tool); app.ui.tool = Tool::Eraser; + // A tool switch like any other: Add New Artboard's placing mode ends (#11386). + crate::tool_memory::ended_by_tool(app); true } Some(false) => match app.stylus.tool_before_eraser.take() { diff --git a/crates/ui-egui/src/input/stylus/tests.rs b/crates/ui-egui/src/input/stylus/tests.rs index f5c872f4af..8e1a71dfa4 100644 --- a/crates/ui-egui/src/input/stylus/tests.rs +++ b/crates/ui-egui/src/input/stylus/tests.rs @@ -350,3 +350,22 @@ fn eraser_end_switches_tools_once_and_never_mid_drag() { assert!(!Stylus::sync_eraser_tool(&mut app)); assert_eq!(app.ui.tool, Tool::Eraser); } + +/// The pen's eraser end is a tool switch like any other: Add New Artboard's placing mode ends +/// (#11386), and coming back to the Artboard tool on the tip leaves it off. +#[test] +fn the_eraser_end_ends_the_artboard_placing_mode() { + use crate::state::Tool; + let mut app = crate::PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); + app.session.execute("file.new", serde_json::json!({"width": 60, "height": 60})).unwrap(); + app.ui.tool = Tool::Artboard; + app.ui.artboard_tool.adding = true; + let pen = |eraser| Some(PenSample { pressure: 0.5, eraser, ..Default::default() }); + app.stylus.feed.set(pen(true)); + assert!(Stylus::sync_eraser_tool(&mut app)); + assert!(!app.ui.artboard_tool.adding, "the eraser end ends the mode"); + app.stylus.feed.set(pen(false)); + assert!(Stylus::sync_eraser_tool(&mut app)); + assert_eq!(app.ui.tool, Tool::Artboard); + assert!(!app.ui.artboard_tool.adding); +} diff --git a/crates/ui-egui/src/layers_empty_area_menu_tests.rs b/crates/ui-egui/src/layers_empty_area_menu_tests.rs new file mode 100644 index 0000000000..10b0c52212 --- /dev/null +++ b/crates/ui-egui/src/layers_empty_area_menu_tests.rs @@ -0,0 +1,184 @@ +//! #11404: a right-click on the empty area below the last layer row opens the thumbnail size and +//! clipping choices; a left click there still deselects, and a layer row keeps its own menu. + +use egui::{PointerButton, Pos2, pos2}; +use egui_kittest::Harness; +use egui_kittest::kittest::{NodeT, Queryable}; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::state::LayerThumbnailSize; + +const SIZES: [&str; 4] = ["No Thumbnails", "Small Thumbnails", "Medium Thumbnails", "Large Thumbnails"]; +const CLIPS: [&str; 2] = ["Clip Thumbnails to Layer Bounds", "Clip Thumbnails to Document Bounds"]; + +fn panel(open_document: bool) -> Harness<'static, PhotocraftApp> { + let mut s = photocraft_engine::Session::new(); + if open_document { + s.execute("file.new", json!({"width": 8, "height": 8})).unwrap(); + s.execute("layer.new.layer", json!({})).unwrap(); + } + let mut h = Harness::builder().with_size(egui::vec2(1200.0, 800.0)).with_max_steps(64).build_eframe(|cc| { + PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); + PhotocraftApp::new(s, crate::Services::default()) + }); + h.run_steps(6); + h +} + +/// A point in the Layers panel well below its last row (above the panel's bottom buttons). +fn empty_point(h: &Harness<'static, PhotocraftApp>) -> Pos2 { + let button = h.get_by_label("Create a new layer").rect(); + pos2(button.center().x - 20.0, button.top() - 80.0) +} + +fn click(h: &mut Harness<'static, PhotocraftApp>, p: Pos2, button: PointerButton) { + h.event(egui::Event::PointerMoved(p)); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: p, button, pressed: true, modifiers: egui::Modifiers::NONE }); + h.run_steps(1); + h.event(egui::Event::PointerButton { pos: p, button, pressed: false, modifiers: egui::Modifiers::NONE }); + h.run_steps(3); +} + +fn open_menu(h: &mut Harness<'static, PhotocraftApp>) { + let p = empty_point(h); + click(h, p, PointerButton::Secondary); +} + +fn pick(h: &mut Harness<'static, PhotocraftApp>, label: &str) { + h.get_by_label(label).click(); + h.run_steps(4); +} + +fn menu_open(h: &Harness<'static, PhotocraftApp>) -> bool { + SIZES.iter().chain(CLIPS.iter()).any(|l| h.query_by_label(l).is_some()) +} + +fn checked(h: &Harness<'static, PhotocraftApp>, label: &str) -> bool { + h.get_by_label(label).accesskit_node().toggled() == Some(egui::accesskit::Toggled::True) +} + +fn size(h: &Harness<'static, PhotocraftApp>) -> LayerThumbnailSize { + h.state().ui.layers_panel_options.thumbnail_size +} + +fn clip(h: &Harness<'static, PhotocraftApp>) -> bool { + h.state().session.prefs().interface.clip_thumbnails_to_layer_bounds +} + +#[test] +fn the_menu_lists_the_six_entries_in_order_with_a_separator() { + let mut h = panel(true); + open_menu(&mut h); + let ys: Vec = SIZES.iter().chain(CLIPS.iter()).map(|l| h.get_by_label(l).rect().top()).collect(); + assert_eq!(ys.len(), 6); + assert!(ys.windows(2).all(|w| w[0] < w[1]), "entries top to bottom in the issue's order: {ys:?}"); + let step = ys[1] - ys[0]; + assert!(ys[4] - ys[3] > step + 1.0, "the separator sits between Large Thumbnails and the clip entries: {ys:?}"); +} + +#[test] +fn the_current_size_and_clip_choice_are_the_ones_checked() { + let mut h = panel(true); + h.state_mut().ui.layers_panel_options.thumbnail_size = LayerThumbnailSize::Large; + h.state_mut().run("prefs.set", json!({"path": "interface.clipThumbnailsToLayerBounds", "value": true})).unwrap(); + h.run_steps(2); + open_menu(&mut h); + assert!(menu_open(&h)); + assert!(checked(&h, "Large Thumbnails"), "Large is the current size"); + for other in ["No Thumbnails", "Small Thumbnails", "Medium Thumbnails"] { + assert!(!checked(&h, other), "{other}"); + } + assert!(checked(&h, "Clip Thumbnails to Layer Bounds")); + assert!(!checked(&h, "Clip Thumbnails to Document Bounds")); + + pick(&mut h, "Clip Thumbnails to Document Bounds"); + assert!(!clip(&h)); + open_menu(&mut h); + assert!(checked(&h, "Clip Thumbnails to Document Bounds")); + assert!(!checked(&h, "Clip Thumbnails to Layer Bounds")); +} + +#[test] +fn each_size_pick_sets_the_panel_option_and_saves_it() { + for (label, want) in [ + ("No Thumbnails", LayerThumbnailSize::None), + ("Small Thumbnails", LayerThumbnailSize::Small), + ("Large Thumbnails", LayerThumbnailSize::Large), + ("Medium Thumbnails", LayerThumbnailSize::Medium), + ] { + let mut h = panel(true); + h.state_mut().ui.layers_panel_options.thumbnail_size = + if want == LayerThumbnailSize::Large { LayerThumbnailSize::Small } else { LayerThumbnailSize::Large }; + h.run_steps(2); + open_menu(&mut h); + pick(&mut h, label); + assert_eq!(size(&h), want, "{label}"); + assert!(!menu_open(&h), "{label}: the menu closes"); + let saved = h.state().session.prefs().dialogs.get("ui.layersPanelOptions").cloned(); + let saved = saved.expect("the choice is saved as Panel Options saves it"); + assert_eq!(saved, serde_json::to_value(&h.state().ui.layers_panel_options).unwrap(), "{label}"); + } +} + +#[test] +fn each_clip_pick_sets_the_preference() { + let mut h = panel(true); + assert!(!clip(&h)); + open_menu(&mut h); + pick(&mut h, "Clip Thumbnails to Layer Bounds"); + assert!(clip(&h)); + assert_eq!(crate::panels::layers_panel_ui::thumbnail_contents(h.state()), crate::state::LayerThumbnailContents::LayerBounds, "Panel Options agrees"); + open_menu(&mut h); + pick(&mut h, "Clip Thumbnails to Document Bounds"); + assert!(!clip(&h)); + assert_eq!(crate::panels::layers_panel_ui::thumbnail_contents(h.state()), crate::state::LayerThumbnailContents::EntireDocument); +} + +#[test] +fn a_left_click_on_the_empty_area_still_deselects_and_a_right_click_does_not() { + let mut h = panel(true); + let selected = |h: &Harness<'static, PhotocraftApp>| h.state().session.active().unwrap().selected_layers().len(); + h.run_steps(3); + let before = selected(&h); + assert!(before > 0); + open_menu(&mut h); + assert!(menu_open(&h)); + assert_eq!(selected(&h), before, "a right-click does not deselect"); + h.key_press(egui::Key::Escape); + h.run_steps(3); + let p = empty_point(&h); + click(&mut h, p, PointerButton::Primary); + assert_eq!(selected(&h), 0, "a left click deselects every layer"); +} + +#[test] +fn with_no_document_nothing_opens() { + let mut h = panel(false); + let p = pos2(1100.0, 400.0); + click(&mut h, p, PointerButton::Secondary); + assert!(!menu_open(&h)); +} + +#[test] +fn a_right_click_on_a_layer_row_still_opens_the_layer_menu() { + let mut h = panel(true); + let row = h.get_all_by_label("Layer 1").next().expect("the new layer's row").rect(); + click(&mut h, row.center(), PointerButton::Secondary); + assert!(h.query_by_label("Duplicate Layer…").is_some() || h.query_by_label("Duplicate Layer").is_some(), "the layer menu opened"); + assert!(h.query_by_label("No Thumbnails").is_none(), "not the empty-area menu"); +} + +/// A filter that matches no layer draws no row: the whole list is empty space, and its +/// right-click still opens the menu. +#[test] +fn with_no_row_shown_by_the_filter_the_right_click_still_opens_the_menu() { + let mut h = panel(true); + h.state_mut().ui.layer_filter_by = crate::layer_filter_ui::FilterBy::Name; + h.state_mut().ui.layer_filter_name = "no layer has this name".into(); + h.run_steps(4); + assert!(h.query_by_label("Layer 1").is_none(), "the filter hides every row"); + open_menu(&mut h); + assert!(menu_open(&h), "the empty list's right-click opens the menu"); +} diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs index 3819430d7f..25d77a32e2 100644 --- a/crates/ui-egui/src/lib.rs +++ b/crates/ui-egui/src/lib.rs @@ -306,6 +306,7 @@ pub use tools::perspective_crop_ui; pub use tools::perspective_ui; pub use tools::puppet_ui; pub use tools::retouch_ui; +pub use tools::shape_bounds_box; use tools::shape_gradient_ui; use tools::shape_options; use tools::shape_paint_ui; @@ -757,6 +758,11 @@ impl SyntheticTarget { } } +#[cfg(test)] +mod artboard_add_mode_tests; +#[cfg(test)] +mod shape_bounds_box_tests; + #[cfg(test)] mod lifecycle_tests; @@ -793,11 +799,19 @@ mod layer_shortcut_tests; #[cfg(test)] mod live_retouch_tests; #[cfg(test)] +mod lock_layers_shortcut_tests; +#[cfg(test)] mod pencil_tests; #[cfg(test)] +mod smart_objects_menu_tests; +#[cfg(test)] mod tool_options_theme_tests; #[cfg(test)] +mod tool_shift_cycle_order_tests; +#[cfg(test)] mod tool_shortcut_tests; +#[cfg(test)] +mod toolbar_group_order_tests; #[cfg(test)] mod pixel_aspect_tests; @@ -839,6 +853,11 @@ mod save_identity_tests; #[cfg(test)] mod move_auto_select_tests; +#[cfg(test)] +mod move_history_names_tests; +#[cfg(test)] +mod move_shift_diagonal_tests; + #[cfg(test)] mod new_group_button_tests; @@ -893,6 +912,8 @@ mod field_wheel_app_tests; #[cfg(test)] mod dropdown_press_tests; +#[cfg(test)] +mod marquee_press_mods_tests; #[cfg(test)] mod marquee_tests; @@ -920,10 +941,14 @@ mod stamp_tests; #[cfg(test)] mod alt_click_tests; #[cfg(test)] +mod artboard_first_board_tests; +#[cfg(test)] mod status_bar_tests; #[cfg(test)] mod stroke_timing_tests; +#[cfg(test)] +mod polygon_lasso_step_snap_tests; #[cfg(test)] mod polygon_lasso_tests; @@ -942,5 +967,18 @@ mod select_and_mask_button_tests; #[cfg(test)] mod saved_path_edit_tests; +#[cfg(test)] +mod menu_item_labels_tests; #[cfg(test)] mod pen_path_ownership_tests; + +#[cfg(test)] +mod doc_tab_menu_tests; +#[cfg(test)] +mod layers_empty_area_menu_tests; +#[cfg(test)] +mod preferences_submenu_tests; +#[cfg(test)] +mod selection_move_step_tests; +#[cfg(test)] +mod view_guides_submenu_tests; diff --git a/crates/ui-egui/src/lock_layers_shortcut_tests.rs b/crates/ui-egui/src/lock_layers_shortcut_tests.rs new file mode 100644 index 0000000000..8d5f215e19 --- /dev/null +++ b/crates/ui-egui/src/lock_layers_shortcut_tests.rs @@ -0,0 +1,143 @@ +//! Ctrl+/ (Cmd+/ on the Mac) opens Layer > Lock Layers..., and the Layer menu and the Layers panel +//! menu show the command's current key. Plain / still toggles Lock Transparent Pixels (#11397). + +use egui::{Key, Modifiers}; +use serde_json::json; + +use crate::PhotocraftApp; + +fn app() -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 20, "height": 10})).unwrap(); + app.run("layer.new.layer", json!({})).unwrap(); + app +} + +fn press(app: &mut PhotocraftApp, key: Key, modifiers: Modifiers) { + let ctx = egui::Context::default(); + let raw = egui::RawInput { + events: vec![egui::Event::ModifiersChanged(modifiers), egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers }], + ..Default::default() + }; + ctx.begin_pass(raw); + crate::shortcuts::handle(app, &ctx); + ctx.end_pass().textures_delta.clear(); +} + +fn locks(app: &PhotocraftApp) -> photocraft_doc::Locks { + let st = app.session.active().unwrap(); + st.doc.layer(st.active_layer.unwrap()).unwrap().locks +} + +fn set_shortcut(app: &mut PhotocraftApp, value: &str) { + app.session.prefs.edit(|prefs| prefs.shortcuts.insert("layer.lockLayers".into(), value.into())); +} + +#[test] +fn lock_layers_defaults_to_command_slash_in_the_engine_and_the_menu() { + assert_eq!(photocraft_engine::commands::find("layer.lockLayers").unwrap().shortcut, Some("Cmd+/")); + let row = crate::menu_catalog::CATALOG.iter().find(|c| c.3 == "layer.lockLayers").unwrap(); + assert_eq!(row.2, Some("Cmd+/")); + assert_eq!(crate::shortcuts::default_shortcut("layer.lockLayers").as_deref(), Some("Cmd+/")); +} + +#[test] +fn command_slash_runs_what_the_menu_item_runs() { + let mut via_key = app(); + press(&mut via_key, Key::Slash, Modifiers::COMMAND); + let mut via_menu = app(); + crate::menus::invoke(&mut via_menu, &egui::Context::default(), "layer.lockLayers", json!({})).unwrap(); + assert_eq!(locks(&via_key), locks(&via_menu)); + assert!(locks(&via_key).all, "Lock Layers... with no choices locks the layer"); +} + +#[test] +fn command_slash_does_nothing_when_the_menu_item_is_greyed() { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + assert!(!crate::menus::is_enabled(&app, "layer.lockLayers")); + press(&mut app, Key::Slash, Modifiers::COMMAND); + assert!(app.session.active().is_none()); + assert!(app.ui.layers_panel_dialog.is_none()); +} + +/// Every text the Layers panel menu paints in one frame (the row labels and their shortcut texts). +fn painted_text(app: &mut PhotocraftApp) -> Vec { + fn collect(shape: &egui::Shape, out: &mut Vec) { + match shape { + egui::Shape::Text(text) => out.push(text.galley.job.text.clone()), + egui::Shape::Vec(shapes) => shapes.iter().for_each(|s| collect(s, out)), + _ => {} + } + } + let ctx = egui::Context::default(); + ctx.begin_pass(egui::RawInput::default()); + let mut ui = egui::Ui::new( + ctx.clone(), + egui::Id::unique("lock-layers-panel-menu"), + egui::UiBuilder::new().max_rect(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(300.0, 900.0))), + ); + crate::panels::layer_row_ui::panel_menu(app, &mut ui); + // The texture deltas go nowhere in a test: clear them, or epaint's drop check complains. + let mut pass = ctx.end_pass(); + pass.textures_delta.clear(); + let mut out = Vec::new(); + for clipped in pass.shapes { + collect(&clipped.shape, &mut out); + } + out +} + +#[test] +fn panel_menu_row_shows_the_current_key_and_follows_a_change() { + let mut app = app(); + let default_key = crate::shortcuts::pretty("Cmd+/"); + assert_eq!(crate::shortcuts::shortcut_label(&app, "layer.lockLayers"), Some(default_key.clone())); + // The panel menu paints the key beside Lock Layers… + let texts = painted_text(&mut app); + assert!(texts.iter().any(|t| t == "Lock Layers…"), "{texts:?}"); + assert!(texts.contains(&default_key), "the default key is painted: {texts:?}"); + // A changed key is painted instead of the default. + set_shortcut(&mut app, "Cmd+Shift+L"); + let changed = crate::shortcuts::pretty("Cmd+Shift+L"); + assert_eq!(crate::shortcuts::shortcut_label(&app, "layer.lockLayers"), Some(changed.clone())); + let texts = painted_text(&mut app); + assert!(texts.contains(&changed), "{texts:?}"); + assert!(!texts.contains(&default_key), "the old key is gone: {texts:?}"); + // A removed key paints no key at all. + let mut app = app_with_removed_key(); + let texts = painted_text(&mut app); + assert!(texts.iter().any(|t| t == "Lock Layers…"), "{texts:?}"); + assert!(!texts.contains(&default_key) && !texts.contains(&changed), "{texts:?}"); +} + +#[test] +fn the_key_can_be_changed_and_removed() { + let mut app = app(); + set_shortcut(&mut app, "Cmd+Shift+L"); + press(&mut app, Key::Slash, Modifiers::COMMAND); + assert!(!locks(&app).all, "the old key no longer runs the command"); + press(&mut app, Key::L, Modifiers::COMMAND | Modifiers::SHIFT); + assert!(locks(&app).all, "the new key does"); + let mut app = app_with_removed_key(); + press(&mut app, Key::Slash, Modifiers::COMMAND); + assert!(!locks(&app).all); + assert_eq!(crate::shortcuts::shortcut_label(&app, "layer.lockLayers"), None); +} + +fn app_with_removed_key() -> PhotocraftApp { + let mut app = app(); + set_shortcut(&mut app, ""); + app +} + +#[test] +fn plain_slash_toggles_lock_transparency_and_command_slash_does_not() { + let mut app = app(); + press(&mut app, Key::Slash, Modifiers::NONE); + assert!(locks(&app).transparency && !locks(&app).all); + press(&mut app, Key::Slash, Modifiers::NONE); + assert!(!locks(&app).transparency); + press(&mut app, Key::Slash, Modifiers::COMMAND); + assert!(locks(&app).all); + assert!(!locks(&app).transparency, "Ctrl+/ leaves Lock Transparent Pixels alone"); +} diff --git a/crates/ui-egui/src/marquee_press_mods_tests.rs b/crates/ui-egui/src/marquee_press_mods_tests.rs new file mode 100644 index 0000000000..235dc2dfe4 --- /dev/null +++ b/crates/ui-egui/src/marquee_press_mods_tests.rs @@ -0,0 +1,163 @@ +//! A Shift or Alt held from the start of a Rectangular or Elliptical Marquee drag picks the +//! selection mode only when the document already has a selection (#11389). Without one the same +//! keys constrain the shape from the first move, as in the reference application: Shift squares to +//! the drag's shorter side, Alt draws from the centre. + +use egui::{Modifiers, PointerButton, Pos2, vec2}; +use egui_kittest::Harness; +use egui_kittest::kittest::Queryable; +use photocraft_geom::Rect; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::ViewXform; +use crate::state::Tool; + +fn harness(tool: Tool) -> Harness<'static, PhotocraftApp> { + harness_with_step_dt(tool, 0.25) +} + +fn harness_with_step_dt(tool: Tool, step_dt: f32) -> Harness<'static, PhotocraftApp> { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 800, "height": 600})).unwrap(); + app.sync_views(); + app.ui.extras.rulers = false; + app.ui.tool = tool; + let mut h = Harness::builder().with_size(vec2(1100.0, 800.0)).with_step_dt(step_dt).build_ui_state( + |ui, app: &mut PhotocraftApp| { + let ctx = ui.ctx().clone(); + if !ctx.fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) { + return; + } + crate::shortcuts::handle(app, &ctx); + egui::CentralPanel::default().show(ui, |ui| crate::canvas::document_area(app, ui)); + }, + app, + ); + PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]); + h.run_steps(4); + // 100 %: one document pixel per point, so drags land on whole pixels. + let v = &mut h.state_mut().ui.views[0]; + v.zoom = 1.0; + v.center = [400.0, 300.0]; + v.fit_pending = false; + h.run_steps(2); + h +} + +fn view_xform(h: &Harness<'static, PhotocraftApp>) -> ViewXform { + let app = h.state(); + let v = &app.ui.views[0]; + ViewXform { + rect: crate::rulers::content_rect(app, app.last_canvas_rect), + zoom: v.zoom, + center: v.center, + flip: app.ui.view.flip_horizontal, + rotation: v.rotation, + aspect: app.ui.view.display_aspect(), + } +} + +fn screen(h: &Harness<'static, PhotocraftApp>, x: f32, y: f32) -> Pos2 { + view_xform(h).to_screen(x, y) +} + +fn mods(h: &mut Harness<'static, PhotocraftApp>, m: Modifiers) { + h.event(egui::Event::ModifiersChanged(m)); + h.run_steps(1); +} + +fn button(h: &mut Harness<'static, PhotocraftApp>, p: Pos2, down: bool, m: Modifiers) { + h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: down, modifiers: m }); + h.run_steps(1); +} + +/// Move the pointer to document point `(x, y)` in a few steps. +fn move_to(h: &mut Harness<'static, PhotocraftApp>, x: f32, y: f32) { + let p = screen(h, x, y); + h.event(egui::Event::PointerMoved(p)); + h.run_steps(2); +} + +fn press_at(h: &mut Harness<'static, PhotocraftApp>, x: f32, y: f32, m: Modifiers) { + let p = screen(h, x, y); + h.event(egui::Event::PointerMoved(p)); + h.run_steps(1); + button(h, p, true, m); + // Past egui's click distance, so the drag starts at the press point. + move_to(h, x + 8.0, y + 6.0); +} + +fn release_at(h: &mut Harness<'static, PhotocraftApp>, x: f32, y: f32, m: Modifiers) { + move_to(h, x, y); + button(h, screen(h, x, y), false, m); + h.run_steps(2); +} + +fn selection(h: &Harness<'static, PhotocraftApp>) -> Rect { + h.state().session.active().unwrap().doc.selection.as_ref().map_or(Rect::EMPTY, |s| s.content_bounds()) +} + +/// The two-row readout shows `W: {w} px` and `H: {ht} px` (Photoshop's format). +fn readout(h: &Harness<'static, PhotocraftApp>, w: i32, ht: i32) -> bool { + let labels = h.query_by_label("W:").is_some() && h.query_by_label("H:").is_some(); + let count = |v: i32| h.query_all_by_label(&format!("{v} px")).count(); + let values = if w == ht { count(w) == 2 } else { count(w) == 1 && count(ht) == 1 }; + labels && values && h.query_all_by_label_contains(" px").count() == 2 +} + +/// Drag a marquee from `from` to `to` with `m` held from before the press to after the release. +fn drag_held(h: &mut Harness<'static, PhotocraftApp>, m: Modifiers, from: [f32; 2], to: [f32; 2]) { + mods(h, m); + press_at(h, from[0], from[1], m); + move_to(h, to[0], to[1]); + release_at(h, to[0], to[1], m); + mods(h, Modifiers::NONE); +} + +#[test] +fn without_a_selection_keys_held_from_the_press_constrain_the_shape() { + let shift_alt = Modifiers { shift: true, alt: true, ..Modifiers::NONE }; + let cases = [ + // ⇧ from the press: a 200 × 100 drag selects a 100 × 100 square (the shorter side). + (Modifiers::SHIFT, [100.0, 100.0], [300.0, 200.0], Rect::new(100, 100, 200, 200)), + // ⌥ from the press: drawn from the centre. + (Modifiers::ALT, [400.0, 300.0], [500.0, 350.0], Rect::new(300, 250, 500, 350)), + // Both: a square from the centre, half extent the shorter drag. + (shift_alt, [400.0, 300.0], [500.0, 350.0], Rect::new(350, 250, 450, 350)), + ]; + for tool in [Tool::RectMarquee, Tool::EllipseMarquee] { + for (m, from, to, want) in cases { + let mut h = harness(tool); + h.state_mut().ui.extras.snap = false; + drag_held(&mut h, m, from, to); + assert_eq!(selection(&h), want, "{tool:?} with {m:?} held from the press"); + } + } +} + +#[test] +fn the_live_readout_shows_the_constrained_shape_from_the_first_move() { + let mut h = harness(Tool::RectMarquee); + h.state_mut().ui.extras.snap = false; + mods(&mut h, Modifiers::SHIFT); + press_at(&mut h, 100.0, 100.0, Modifiers::SHIFT); + move_to(&mut h, 300.0, 200.0); + assert!(readout(&h, 100, 100), "the readout agrees with what the release selects"); + release_at(&mut h, 300.0, 200.0, Modifiers::SHIFT); + mods(&mut h, Modifiers::NONE); + assert_eq!(selection(&h), Rect::new(100, 100, 200, 200)); +} + +#[test] +fn with_a_selection_keys_held_from_the_press_still_pick_the_mode() { + let mut h = harness(Tool::RectMarquee); + h.state_mut().ui.extras.snap = false; + h.state_mut().run("select.rect", json!({"x": 100, "y": 100, "width": 200, "height": 200})).unwrap(); + // ⇧ adds, and the added rectangle is as drawn, not squared: the union reaches 600. + drag_held(&mut h, Modifiers::SHIFT, [400.0, 100.0], [600.0, 150.0]); + assert_eq!(selection(&h), Rect::new(100, 100, 600, 300)); + let st = h.state().session.active().unwrap(); + let sel = st.doc.selection.as_ref().unwrap(); + assert!(sel.sample_channel(150, 150, 0) > 0.99 && sel.sample_channel(550, 125, 0) > 0.99 && sel.sample_channel(550, 250, 0) < 0.01); +} diff --git a/crates/ui-egui/src/menu_catalog.rs b/crates/ui-egui/src/menu_catalog.rs index 328fe24fc5..179c51fd00 100644 --- a/crates/ui-egui/src/menu_catalog.rs +++ b/crates/ui-egui/src/menu_catalog.rs @@ -149,6 +149,7 @@ pub static CATALOG: &[(&[&str], &str, Option<&str>, &str)] = &[ (&["Edit"], "Toolbar…", None, "edit.toolbar"), (&["Edit"], "---", None, "---"), (&["Edit", "Preferences"], "Settings…", Some("Cmd+K"), "edit.preferences.general"), + (&["Edit", "Preferences"], "---", None, "---"), (&["Edit", "Preferences"], "AI Integrations…", None, "edit.preferences.integrations"), (&["Edit", "Preferences"], "Interface…", None, "edit.preferences.interface"), (&["Edit", "Preferences"], "Workspace…", None, "edit.preferences.workspace"), @@ -162,10 +163,11 @@ pub static CATALOG: &[(&[&str], &str, Option<&str>, &str)] = &[ (&["Edit", "Preferences"], "Transparency & Gamut…", None, "edit.preferences.transparencyAndGamut"), (&["Edit", "Preferences"], "Units & Rulers…", None, "edit.preferences.unitsAndRulers"), (&["Edit", "Preferences"], "Guides, Grid & Slices…", None, "edit.preferences.guidesGridAndSlices"), - (&["Edit", "Preferences"], "Plug-ins…", None, "edit.preferences.plugIns"), + (&["Edit", "Preferences"], "Plugins…", None, "edit.preferences.plugIns"), (&["Edit", "Preferences"], "Type…", None, "edit.preferences.type"), (&["Edit", "Preferences"], "Enhanced Controls…", None, "edit.preferences.enhancedControls"), - (&["Edit", "Preferences"], "Raw Defaults…", None, "edit.preferences.rawDefaults"), + (&["Edit", "Preferences"], "---", None, "---"), + (&["Edit", "Preferences"], "Camera Raw…", None, "edit.preferences.rawDefaults"), (&["Image", "Mode"], "Bitmap", None, "image.mode.bitmap"), (&["Image", "Mode"], "Grayscale", None, "image.mode.grayscale"), (&["Image", "Mode"], "Duotone", None, "image.mode.duotone"), @@ -350,8 +352,9 @@ pub static CATALOG: &[(&[&str], &str, Option<&str>, &str)] = &[ (&["Layer", "Smart Objects"], "Replace Contents…", None, "layer.smartObjects.replaceContents"), (&["Layer", "Smart Objects"], "Export Contents…", None, "layer.smartObjects.exportContents"), (&["Layer", "Smart Objects"], "---", None, "---"), + (&["Layer", "Smart Objects"], "Embed Linked", None, "layer.smartObjects.convertToEmbedded"), + (&["Layer", "Smart Objects"], "Embed All Linked", None, "layer.smartObjects.embedAllLinked"), (&["Layer", "Smart Objects"], "Convert to Linked…", None, "layer.smartObjects.convertToLinked"), - (&["Layer", "Smart Objects"], "Convert to Embedded", None, "layer.smartObjects.convertToEmbedded"), (&["Layer", "Smart Objects"], "Convert to Layers", None, "layer.smartObjects.convertToLayers"), (&["Layer", "Smart Objects"], "---", None, "---"), (&["Layer", "Smart Objects", "Stack Mode"], "Entropy", None, "layer.smartObjects.stackMode.entropy"), @@ -367,10 +370,6 @@ pub static CATALOG: &[(&[&str], &str, Option<&str>, &str)] = &[ (&["Layer", "Smart Objects", "Stack Mode"], "Variance", None, "layer.smartObjects.stackMode.variance"), (&["Layer", "Smart Objects"], "---", None, "---"), (&["Layer", "Smart Objects"], "Rasterize", None, "layer.smartObjects.rasterize"), - (&["Layer", "Smart Objects"], "---", None, "---"), - (&["Layer", "Smart Objects"], "Warp", None, "layer.smartObjects.warp"), - (&["Layer", "Smart Objects"], "Perspective Warp", None, "layer.smartObjects.perspectiveWarp"), - (&["Layer", "Smart Objects"], "Puppet Warp", None, "layer.smartObjects.puppetWarp"), (&["Layer", "Video Layers"], "New Blank Video Layer", None, "layer.videoLayers.newBlankVideoLayer"), (&["Layer", "Video Layers"], "New Video Layer from File…", None, "layer.videoLayers.newVideoLayerFromFile"), (&["Layer", "Video Layers"], "---", None, "---"), @@ -413,8 +412,8 @@ pub static CATALOG: &[(&[&str], &str, Option<&str>, &str)] = &[ (&["Layer", "Arrange"], "Reverse", None, "layer.arrange.reverse"), (&["Layer", "Combine Shapes"], "Unite Shapes", None, "layer.combineShapes.unite"), (&["Layer", "Combine Shapes"], "Subtract Front Shape", None, "layer.combineShapes.subtractFrontShape"), - (&["Layer", "Combine Shapes"], "Intersect Shape Areas", None, "layer.combineShapes.intersectShapeAreas"), - (&["Layer", "Combine Shapes"], "Exclude Overlapping Shapes", None, "layer.combineShapes.excludeOverlappingShapes"), + (&["Layer", "Combine Shapes"], "Unite Shapes at Overlap", None, "layer.combineShapes.intersectShapeAreas"), + (&["Layer", "Combine Shapes"], "Subtract Shapes at Overlap", None, "layer.combineShapes.excludeOverlappingShapes"), (&["Layer", "Combine Shapes"], "---", None, "---"), (&["Layer", "Combine Shapes"], "Merge Shape Components", None, "layer.combineShapes.mergeShapeComponents"), (&["Layer", "Align"], "Top Edges", None, "layer.align.topEdges"), @@ -435,7 +434,7 @@ pub static CATALOG: &[(&[&str], &str, Option<&str>, &str)] = &[ (&["Layer", "Distribute"], "Horizontally", None, "layer.distribute.horizontally"), (&["Layer", "Distribute"], "Vertically", None, "layer.distribute.vertically"), (&["Layer"], "---", None, "---"), - (&["Layer"], "Lock Layers…", None, "layer.lockLayers"), + (&["Layer"], "Lock Layers…", Some("Cmd+/"), "layer.lockLayers"), (&["Layer"], "---", None, "---"), (&["Layer"], "Link Layers", None, "layer.linkLayers"), (&["Layer"], "Select Linked Layers", None, "layer.selectLinkedLayers"), @@ -650,10 +649,10 @@ pub static CATALOG: &[(&[&str], &str, Option<&str>, &str)] = &[ (&["View", "Proof Setup"], "Working Magenta Plate", None, "view.proofSetup.workingMagentaPlate"), (&["View", "Proof Setup"], "Working Yellow Plate", None, "view.proofSetup.workingYellowPlate"), (&["View", "Proof Setup"], "Working Black Plate", None, "view.proofSetup.workingBlackPlate"), - (&["View", "Proof Setup"], "Working CMY Plate", None, "view.proofSetup.workingCmyPlate"), + (&["View", "Proof Setup"], "Working CMY Plates", None, "view.proofSetup.workingCmyPlate"), (&["View", "Proof Setup"], "---", None, "---"), - (&["View", "Proof Setup"], "Legacy Macintosh RGB", None, "view.proofSetup.legacyMacintoshRgb"), - (&["View", "Proof Setup"], "Internet Standard RGB", None, "view.proofSetup.internetStandardRgb"), + (&["View", "Proof Setup"], "Legacy Macintosh RGB (Gamma 1.8)", None, "view.proofSetup.legacyMacintoshRgb"), + (&["View", "Proof Setup"], "Internet Standard RGB (sRGB)", None, "view.proofSetup.internetStandardRgb"), (&["View", "Proof Setup"], "Monitor RGB", None, "view.proofSetup.monitorRgb"), (&["View", "Proof Setup"], "---", None, "---"), (&["View", "Proof Setup"], "Color Blindness — Protanopia-type", None, "view.proofSetup.colorBlindnessProtanopia"), @@ -720,13 +719,15 @@ pub static CATALOG: &[(&[&str], &str, Option<&str>, &str)] = &[ (&["View", "Snap To"], "---", None, "---"), (&["View", "Snap To"], "All", None, "view.snapTo.all"), (&["View"], "---", None, "---"), - (&["View"], "Lock Guides", Some("Cmd+Alt+;"), "view.lockGuides"), - (&["View"], "Clear Guides", None, "view.clearGuides"), - (&["View"], "Clear Selected Artboard Guides", None, "view.clearSelectedArtboardGuides"), - (&["View"], "Clear Canvas Guides", None, "view.clearCanvasGuides"), - (&["View"], "New Guide…", None, "view.newGuide"), - (&["View"], "New Guide Layout…", None, "view.newGuideLayout"), - (&["View"], "New Guides From Shape", None, "view.newGuidesFromShape"), + (&["View", "Guides"], "Edit Selected Guides", None, "view.editSelectedGuides"), + (&["View", "Guides"], "Lock Guides", Some("Cmd+Alt+;"), "view.lockGuides"), + (&["View", "Guides"], "Clear Guides", None, "view.clearGuides"), + (&["View", "Guides"], "Clear Selected Guides", None, "view.clearSelectedGuides"), + (&["View", "Guides"], "Clear Selected Artboard Guides", None, "view.clearSelectedArtboardGuides"), + (&["View", "Guides"], "Clear Canvas Guides", None, "view.clearCanvasGuides"), + (&["View", "Guides"], "New Guide…", None, "view.newGuide"), + (&["View", "Guides"], "New Guide Layout…", None, "view.newGuideLayout"), + (&["View", "Guides"], "New Guides From Shape", None, "view.newGuidesFromShape"), (&["View"], "---", None, "---"), (&["View"], "Lock Slices", None, "view.lockSlices"), (&["View"], "Clear Slices", None, "view.clearSlices"), @@ -750,7 +751,7 @@ pub static CATALOG: &[(&[&str], &str, Option<&str>, &str)] = &[ (&["Window", "Arrange"], "Float in Window", None, "window.arrange.floatInWindow"), (&["Window", "Arrange"], "Float All in Windows", None, "window.arrange.floatAllInWindows"), (&["Window", "Arrange"], "---", None, "---"), - (&["Window", "Arrange"], "New Window for Document", None, "window.arrange.newWindowForDocument"), + (&["Window", "Arrange"], "New Window", None, "window.arrange.newWindowForDocument"), (&["Window", "Arrange"], "---", None, "---"), (&["Window", "Arrange"], "Match Zoom", None, "window.arrange.matchZoom"), (&["Window", "Arrange"], "Match Location", None, "window.arrange.matchLocation"), diff --git a/crates/ui-egui/src/menu_item_labels_tests.rs b/crates/ui-egui/src/menu_item_labels_tests.rs new file mode 100644 index 0000000000..6e09df739f --- /dev/null +++ b/crates/ui-egui/src/menu_item_labels_tests.rs @@ -0,0 +1,82 @@ +//! #11399: the Combine Shapes, Open Recent, Arrange and Proof Setup items carry the reference +//! application's names, in the live menu tree and in the engine's command labels. + +use crate::PhotocraftApp; +use crate::menus::menu_items; + +/// (command id, label the live menu must show). +const LABELS: [(&str, &str); 7] = [ + ("layer.combineShapes.intersectShapeAreas", "Unite Shapes at Overlap"), + ("layer.combineShapes.excludeOverlappingShapes", "Subtract Shapes at Overlap"), + ("file.clearRecent", "Clear Recent File List"), + ("window.arrange.newWindowForDocument", "New Window"), + ("view.proofSetup.workingCmyPlate", "Working CMY Plates"), + ("view.proofSetup.legacyMacintoshRgb", "Legacy Macintosh RGB (Gamma 1.8)"), + ("view.proofSetup.internetStandardRgb", "Internet Standard RGB (sRGB)"), +]; + +fn app() -> PhotocraftApp { + PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()) +} + +#[test] +fn live_menu_shows_the_reference_names() { + let app = app(); + let items = menu_items(&app); + for (id, label) in LABELS { + let item = items.iter().find(|i| i.id == id).unwrap_or_else(|| panic!("{id} is in the menu tree")); + assert_eq!(item.label, label, "{id}"); + } +} + +#[test] +fn open_recent_clear_item_is_labelled_with_and_without_recent_files() { + let mut app = app(); + app.ui.recent_files = vec!["/tmp/a.png".into()]; + let items = menu_items(&app); + let clear = items.iter().find(|i| i.id == "file.clearRecent").expect("clear item"); + assert_eq!(clear.label, "Clear Recent File List"); + assert!(clear.enabled); + assert_eq!(clear.path, vec!["File".to_string(), "Open Recent".to_string()]); + // With nothing to clear the item stays in the submenu, greyed. + app.ui.recent_files.clear(); + let items = menu_items(&app); + let clear = items.iter().find(|i| i.id == "file.clearRecent").expect("clear item"); + assert_eq!(clear.label, "Clear Recent File List"); + assert!(!clear.enabled); +} + +#[test] +fn engine_command_labels_match_the_menu() { + let specs = photocraft_engine::cmd::command_specs(); + // The two Combine Shapes and the three Proof Setup commands have an engine command under the + // same id as the menu row. + for (id, label) in LABELS { + if let Some(spec) = specs.iter().find(|s| s.id == id) { + assert_eq!(spec.label, label, "engine label of {id}"); + } + } + let engine_ids = [ + "layer.combineShapes.intersectShapeAreas", + "layer.combineShapes.excludeOverlappingShapes", + "view.proofSetup.workingCmyPlate", + "view.proofSetup.legacyMacintoshRgb", + ]; + for id in engine_ids { + assert!(specs.iter().any(|s| s.id == id), "{id} is an engine command"); + } + // The shell command for the extra window is registered under its own id. + let shell = photocraft_engine::shell_commands::SHELL_COMMANDS.iter().find(|c| c.0 == "window.newWindowForDocument").expect("shell command"); + assert_eq!(shell.1, "New Window"); +} + +#[test] +fn history_step_names_and_other_labels_are_unchanged() { + // The Home screen keeps its own button label (#11399 "not measured"). + let src = include_str!("home_recent_ui.rs"); + assert!(src.contains("tl!(\"Clear Recent Files\")")); + // Merge Shape Components stays in Combine Shapes. + let app = app(); + let items = menu_items(&app); + assert!(items.iter().any(|i| i.id == "layer.combineShapes.mergeShapeComponents")); +} diff --git a/crates/ui-egui/src/menus.rs b/crates/ui-egui/src/menus.rs index 01195598c0..95a57d9588 100644 --- a/crates/ui-egui/src/menus.rs +++ b/crates/ui-egui/src/menus.rs @@ -203,7 +203,7 @@ mod reveal_label_tests { let expected = if cfg!(target_os = "macos") { "Reveal in Finder" } else if cfg!(windows) { - "Show in Explorer" + "Reveal in Explorer" } else { "Show in Folder" }; diff --git a/crates/ui-egui/src/menus/invoke.rs b/crates/ui-egui/src/menus/invoke.rs index 0539b4cb0a..b7e8e812d7 100644 --- a/crates/ui-egui/src/menus/invoke.rs +++ b/crates/ui-egui/src/menus/invoke.rs @@ -626,6 +626,10 @@ fn type_command_target(app: &PhotocraftApp) -> Option { fn invoke_view_command(app: &mut PhotocraftApp, ctx: &egui::Context, id: &str, params: &Value) -> Option> { match id { "view.zoomIn" | "view.zoomOut" | "view.fitOnScreen" | "view.actualPixels" => Some(app.run(id, params.clone())), + "view.editSelectedGuides" => Some(crate::new_guide_ui::open_edit(app).map(|_| Value::Null)), + "view.clearSelectedGuides" => { + Some(crate::guide_select::delete_selected(app).and_then(|done| if done { Ok(Value::Null) } else { Err("No guide is selected".to_string()) })) + } "view.rulers" | "view.show.grid" | "view.show.guides" | "view.snap" | "view.lockGuides" => { let extras = &mut app.ui.extras; let slot = match id { diff --git a/crates/ui-egui/src/menus/items.rs b/crates/ui-egui/src/menus/items.rs index 37944cca5f..fabce59420 100644 --- a/crates/ui-egui/src/menus/items.rs +++ b/crates/ui-egui/src/menus/items.rs @@ -154,7 +154,7 @@ pub fn menu_items(app: &PhotocraftApp) -> Vec { } recent.push(MenuItem { id: "file.clearRecent".into(), - label: "Clear Recent Files".into(), + label: "Clear Recent File List".into(), path: rp.clone(), shortcut: None, enabled: !app.ui.recent_files.is_empty(), diff --git a/crates/ui-egui/src/menus/native_menu.rs b/crates/ui-egui/src/menus/native_menu.rs index 4dad63c448..88106d1304 100644 --- a/crates/ui-egui/src/menus/native_menu.rs +++ b/crates/ui-egui/src/menus/native_menu.rs @@ -761,6 +761,8 @@ pub(crate) fn state_hash(app: &PhotocraftApp, input: Option) -> u64 { let ui = &app.ui; (&ui.recent_files, &ui.workspace, ui.palette_open, ui.transform.is_some(), ui.text_edit.is_some(), ui.dialogs.len()).hash(&mut h); (app.discard.is_some(), app.camera_raw.is_some(), crate::distort_ui::modal_workspace(app)).hash(&mut h); + // Edit / Clear Selected Guides are enabled only while a guide is selected. + crate::guide_select::selected(app).hash(&mut h); serde_json::to_string(&(&ui.panels, &ui.extras, &ui.view, ui.theme, ui.tool)).unwrap_or_default().hash(&mut h); s.prefs().interface.language.hash(&mut h); h.finish() diff --git a/crates/ui-egui/src/menus/state.rs b/crates/ui-egui/src/menus/state.rs index c932ca092c..f6a3c55534 100644 --- a/crates/ui-egui/src/menus/state.rs +++ b/crates/ui-egui/src/menus/state.rs @@ -80,6 +80,7 @@ pub fn is_enabled(app: &PhotocraftApp, id: &str) -> bool { // "Custom…" is the full Proof Setup dialog. "view.proofSetup.custom" => app.session.active().is_some(), "view.rulers" | "view.show.grid" | "view.show.guides" | "view.snap" | "view.lockGuides" => true, + "view.editSelectedGuides" | "view.clearSelectedGuides" => crate::guide_select::selected(app).is_some(), "edit.cut" | "edit.copy" if app.ui.text_edit.is_some() => crate::type_tool::selected_range(app).is_some(), "edit.paste" | "select.all" if app.ui.text_edit.is_some() => true, // An image copied in another app can only be seen by reading the OS clipboard, which happens @@ -211,7 +212,7 @@ pub(crate) fn reveal_label() -> &'static str { if cfg!(target_os = "macos") { "Reveal in Finder" } else if cfg!(windows) { - "Show in Explorer" + "Reveal in Explorer" } else { "Show in Folder" } diff --git a/crates/ui-egui/src/move_history_names_tests.rs b/crates/ui-egui/src/move_history_names_tests.rs new file mode 100644 index 0000000000..520414bef3 --- /dev/null +++ b/crates/ui-egui/src/move_history_names_tests.rs @@ -0,0 +1,173 @@ +//! #11383: the Move tool's History steps have the reference application's names: a drag and an +//! Alt+drag copy of a layer are "Move", arrow-key nudges are "Nudge" (one per press, or one per +//! run with Bundle Arrow-Key Nudges on), an Alt+drag of selected pixels is "Duplicate". An +//! Alt+arrow nudge keeps "Duplicate + Move" (not measured). + +use photocraft_geom::Rect; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::ToolEvent; +use crate::state::Tool; + +/// A 64x64 document with one painted layer (8..24)^2, selected, and the Move tool active. +fn app() -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.session.execute("file.new", json!({"width": 64, "height": 64})).unwrap(); + app.sync_views(); + app.session.execute("layer.new.layer", json!({})).unwrap(); + app.session + .edit("paint", |doc, a| { + doc.layer_mut(a.unwrap()).unwrap().surface_mut().unwrap().fill_rect(Rect::new(8, 8, 24, 24), &[1.0, 0.0, 0.0, 1.0]); + Ok(()) + }) + .unwrap(); + app.ui.tool = Tool::Move; + app.ui.tool_options.move_auto_select = false; + // Snapping (to the document centre with a 1:1 test view) would shift the expected offsets. + app.ui.extras.snap = false; + app.ui.view.show.smart_guides = false; + app +} + +fn bounds(app: &PhotocraftApp, id: photocraft_doc::LayerId) -> Rect { + app.session.active().unwrap().doc.layer(id).unwrap().surface().unwrap().content_bounds() +} + +fn drag(app: &mut PhotocraftApp, from: [f64; 2], by: [f64; 2], mods: egui::Modifiers) { + crate::canvas::tool_event(app, ToolEvent::Down { x: from[0], y: from[1], pressure: 1.0 }, mods); + let mid = [from[0] + by[0] / 2.0, from[1] + by[1] / 2.0]; + crate::canvas::tool_event(app, ToolEvent::Move { x: mid[0], y: mid[1], pressure: 1.0 }, mods); + let end = [from[0] + by[0], from[1] + by[1]]; + crate::canvas::tool_event(app, ToolEvent::Move { x: end[0], y: end[1], pressure: 1.0 }, mods); + crate::canvas::tool_event(app, ToolEvent::Up { x: end[0], y: end[1] }, mods); +} + +fn press(app: &mut PhotocraftApp, key: egui::Key, mods: egui::Modifiers, time: f64) { + let ctx = egui::Context::default(); + ctx.input_mut(|i| { + i.time = time; + i.modifiers = mods; + i.events.push(egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers: mods }); + }); + assert!(crate::move_mods::arrow_keys(app, &ctx)); +} + +fn history(app: &PhotocraftApp) -> usize { + app.session.active().unwrap().history.past_len() +} + +fn newest(app: &PhotocraftApp) -> Option { + app.session.active().unwrap().history.entries().pop() +} + +/// The five presses of the reference measurement: ->, Shift+->, down, Shift+down, <-. +fn five_presses(app: &mut PhotocraftApp) { + let keys = [ + (egui::Key::ArrowRight, egui::Modifiers::NONE), + (egui::Key::ArrowRight, egui::Modifiers::SHIFT), + (egui::Key::ArrowDown, egui::Modifiers::NONE), + (egui::Key::ArrowDown, egui::Modifiers::SHIFT), + (egui::Key::ArrowLeft, egui::Modifiers::NONE), + ]; + for (i, (key, mods)) in keys.into_iter().enumerate() { + press(app, key, mods, 1.0 + 0.1 * i as f64); + } +} + +#[test] +fn a_drag_of_a_layer_is_one_move_step() { + let mut app = app(); + let id = app.session.active().unwrap().active_layer.unwrap(); + let h0 = history(&app); + drag(&mut app, [16.0, 16.0], [10.0, 4.0], egui::Modifiers::NONE); + assert_eq!(bounds(&app, id), Rect::new(18, 12, 34, 28)); + assert_eq!(history(&app), h0 + 1); + assert_eq!(newest(&app).as_deref(), Some("Move")); +} + +#[test] +fn an_alt_drag_copy_of_a_layer_is_one_move_step() { + let mut app = app(); + let orig = app.session.active().unwrap().active_layer.unwrap(); + let h0 = history(&app); + drag(&mut app, [16.0, 16.0], [20.0, 10.0], egui::Modifiers::ALT); + let copy = app.session.active().unwrap().active_layer.unwrap(); + assert_ne!(copy, orig, "the copy is selected"); + assert_eq!(bounds(&app, copy), Rect::new(28, 18, 44, 34), "at the offset"); + assert_eq!(bounds(&app, orig), Rect::new(8, 8, 24, 24), "the original stays"); + assert_eq!(history(&app), h0 + 1, "the copy and the move are one step"); + assert_eq!(newest(&app).as_deref(), Some("Move")); +} + +#[test] +fn five_arrow_presses_with_bundling_off_are_five_nudge_steps() { + let mut app = app(); + app.session.edit_prefs(|p| p.tools.bundle_nudges = false); + let id = app.session.active().unwrap().active_layer.unwrap(); + let h0 = history(&app); + five_presses(&mut app); + assert_eq!(bounds(&app, id), Rect::new(8 + 1 + 10 - 1, 8 + 1 + 10, 24 + 10, 24 + 11)); + assert_eq!(history(&app), h0 + 5); + let entries = app.session.active().unwrap().history.entries(); + assert_eq!(&entries[entries.len() - 5..], ["Nudge"; 5]); +} + +#[test] +fn five_arrow_presses_with_bundling_on_are_one_nudge_step() { + let mut app = app(); + app.session.edit_prefs(|p| p.tools.bundle_nudges = true); + let h0 = history(&app); + five_presses(&mut app); + assert_eq!(history(&app), h0 + 1); + assert_eq!(newest(&app).as_deref(), Some("Nudge")); +} + +#[test] +fn an_alt_drag_of_selected_pixels_is_one_duplicate_step() { + let mut app = app(); + app.session.execute("select.rect", json!({"x": 8, "y": 8, "width": 16, "height": 16})).unwrap(); + let h0 = history(&app); + drag(&mut app, [16.0, 16.0], [20.0, 10.0], egui::Modifiers::ALT); + // The copied piece floats until something drops it. + app.session.execute("select.drop", json!({})).unwrap(); + assert_eq!(history(&app), h0 + 1, "the copy and its move are one step"); + assert_eq!(newest(&app).as_deref(), Some("Duplicate")); +} + +#[test] +fn a_blank_or_overlong_step_name_drops_as_move() { + let mut app = app(); + app.session.execute("select.rect", json!({"x": 8, "y": 8, "width": 16, "height": 16})).unwrap(); + for name in [" ", &"x".repeat(65)] { + app.session.execute("select.float", json!({"dx": 2, "dy": 0, "copy": true, "stepName": name})).unwrap(); + app.session.execute("select.drop", json!({})).unwrap(); + assert_eq!(newest(&app).as_deref(), Some("Move"), "{name:?}"); + } + app.session.execute("select.float", json!({"dx": 2, "dy": 0, "copy": true, "stepName": "Duplicate"})).unwrap(); + app.session.execute("select.drop", json!({})).unwrap(); + assert_eq!(newest(&app).as_deref(), Some("Duplicate")); +} + +#[test] +fn an_alt_arrow_nudge_keeps_duplicate_plus_move() { + let mut app = app(); + let h0 = history(&app); + press(&mut app, egui::Key::ArrowRight, egui::Modifiers::ALT, 1.0); + assert_eq!(history(&app), h0 + 1); + assert_eq!(newest(&app).as_deref(), Some("Duplicate + Move")); +} + +/// A zero offset moves nothing: no step is added, and the step on top (here the paint) keeps its +/// name. +#[test] +fn a_zero_nudge_renames_no_earlier_step() { + let mut app = app(); + for bundle in [false, true] { + app.session.edit_prefs(|p| p.tools.bundle_nudges = bundle); + let before: Vec = app.session.active().unwrap().history.entries().to_vec(); + crate::move_mods::nudge(&mut app, 0.0, 0.0, false); + let after: Vec = app.session.active().unwrap().history.entries().to_vec(); + assert_eq!(after, before, "bundle {bundle}"); + } +} diff --git a/crates/ui-egui/src/move_shift_diagonal_tests.rs b/crates/ui-egui/src/move_shift_diagonal_tests.rs new file mode 100644 index 0000000000..0929069ede --- /dev/null +++ b/crates/ui-egui/src/move_shift_diagonal_tests.rs @@ -0,0 +1,112 @@ +//! Shift+drag of a layer with the Move tool locks to the nearest of the eight directions (#11382). +//! +//! Measured in the reference application (layer Red, 300x200 px, Auto-Select on, target Layer): +//! Shift+drag +100,+30 moves +100,0 and Shift+drag +80,+80 moves +80,+80, each as one "Move" +//! step. With Alt as well, the copy lands at the same offset. + +use photocraft_doc::LayerId; +use photocraft_geom::Rect; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::ToolEvent; +use crate::state::Tool; + +/// A 400x300 document with one painted layer covering (20, 20, 120, 80), selected. The drag +/// starts inside it, so Auto-Select picks the same layer. +fn app() -> (PhotocraftApp, LayerId) { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.session.execute("file.new", json!({"width": 400, "height": 300})).unwrap(); + app.sync_views(); + app.session.execute("layer.new.layer", json!({})).unwrap(); + app.session + .edit("paint", |doc, a| { + doc.layer_mut(a.unwrap()).unwrap().surface_mut().unwrap().fill_rect(Rect::new(20, 20, 120, 80), &[1.0, 0.0, 0.0, 1.0]); + Ok(()) + }) + .unwrap(); + let id = app.session.active().unwrap().active_layer.unwrap(); + app.ui.tool = Tool::Move; + // Snapping would shift the expected offsets. + app.ui.extras.snap = false; + app.ui.view.show.smart_guides = false; + (app, id) +} + +fn bounds(app: &PhotocraftApp, id: LayerId) -> Rect { + app.session.active().unwrap().doc.layer(id).unwrap().surface().unwrap().content_bounds() +} + +fn drag(app: &mut PhotocraftApp, from: [f64; 2], by: [f64; 2], mods: egui::Modifiers) { + crate::canvas::tool_event(app, ToolEvent::Down { x: from[0], y: from[1], pressure: 1.0 }, mods); + let mid = [from[0] + by[0] / 2.0, from[1] + by[1] / 2.0]; + crate::canvas::tool_event(app, ToolEvent::Move { x: mid[0], y: mid[1], pressure: 1.0 }, mods); + let end = [from[0] + by[0], from[1] + by[1]]; + crate::canvas::tool_event(app, ToolEvent::Move { x: end[0], y: end[1], pressure: 1.0 }, mods); + crate::canvas::tool_event(app, ToolEvent::Up { x: end[0], y: end[1] }, mods); +} + +const START: Rect = Rect::new(20, 20, 120, 80); +const FROM: [f64; 2] = [60.0, 50.0]; + +fn shifted(dx: i32, dy: i32) -> Rect { + Rect::new(START.x0 + dx, START.y0 + dy, START.x1 + dx, START.y1 + dy) +} + +/// Runs a plain Shift drag and checks the layer moved by `expect`. +fn shift_drag(by: [f64; 2], expect: [i32; 2]) { + let (mut app, id) = app(); + assert_eq!(bounds(&app, id), START); + drag(&mut app, FROM, by, egui::Modifiers::SHIFT); + assert_eq!(bounds(&app, id), shifted(expect[0], expect[1])); + assert_eq!(app.session.active().unwrap().active_layer, Some(id)); +} + +/// Runs an Alt+Shift drag and checks the copy landed at `expect` and is selected. +fn alt_shift_drag(by: [f64; 2], expect: [i32; 2]) { + let (mut app, id) = app(); + assert_eq!(bounds(&app, id), START); + let n0 = app.session.active().unwrap().doc.layers.len(); + drag(&mut app, FROM, by, egui::Modifiers::SHIFT | egui::Modifiers::ALT); + let st = app.session.active().unwrap(); + assert_eq!(st.doc.layers.len(), n0 + 1, "one copy"); + let copy = st.active_layer.unwrap(); + assert_ne!(copy, id, "the copy is selected"); + assert_eq!(bounds(&app, copy), shifted(expect[0], expect[1])); + assert_eq!(bounds(&app, id), START, "the original stays"); +} + +#[test] +fn shift_drag_mostly_horizontal_locks_to_the_axis() { + // Reference: Shift+drag +100,+30 moves +100,0. + shift_drag([100.0, 30.0], [100, 0]); +} + +#[test] +fn shift_drag_on_the_diagonal_moves_along_it() { + // Reference: Shift+drag +80,+80 moves +80,+80 (it was 0,+80 before). + shift_drag([80.0, 80.0], [80, 80]); +} + +#[test] +fn shift_drag_near_the_axis_stays_on_the_axis() { + // Same rule as the +100,+30 case: a small offset off the axis does not leave it. + shift_drag([100.0, 5.0], [100, 0]); +} + +#[test] +fn alt_shift_drag_mostly_horizontal_copies_along_the_axis() { + // Reference rule for +100,+30, applied to the duplicate and move. + alt_shift_drag([100.0, 30.0], [100, 0]); +} + +#[test] +fn alt_shift_drag_on_the_diagonal_copies_along_it() { + // Reference: the copy lands at +80,+80. + alt_shift_drag([80.0, 80.0], [80, 80]); +} + +#[test] +fn alt_shift_drag_near_the_axis_copies_along_the_axis() { + alt_shift_drag([100.0, 5.0], [100, 0]); +} diff --git a/crates/ui-egui/src/nudge_bundle_tests.rs b/crates/ui-egui/src/nudge_bundle_tests.rs index d18bbddafa..1e1f0542ba 100644 --- a/crates/ui-egui/src/nudge_bundle_tests.rs +++ b/crates/ui-egui/src/nudge_bundle_tests.rs @@ -48,8 +48,8 @@ fn tapping_an_arrow_key_ten_times_is_one_history_step() { assert_eq!(bounds(&h).x0, start.x0 + 10); assert_eq!(steps(&h), n0 + 1, "ten taps, one state"); let entries = h.state().session.active().unwrap().history.entries(); - assert_eq!(entries.last().map(String::as_str), Some("Move")); - assert_eq!(entries.iter().filter(|e| *e == "Move").count(), 1); + assert_eq!(entries.last().map(String::as_str), Some("Nudge")); + assert_eq!(entries.iter().filter(|e| *e == "Nudge").count(), 1); h.state_mut().session.undo(); assert_eq!(bounds(&h), start, "one Undo takes all ten pixels back"); } diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index 9011b4f97a..9fd21b2f20 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -44,6 +44,7 @@ pub mod layer_row_ui; pub(super) mod layer_transfer; pub mod layer_tree_ui; mod layers; +mod layers_empty_menu; pub mod layers_panel_ui; pub(super) mod mask_props_ui; pub mod mask_thumbs_ui; @@ -60,7 +61,7 @@ pub mod swatches_ui; pub(super) mod timeline_ui; pub(crate) mod title_bar; pub(super) mod titlebar; -mod toolbar; +pub(crate) mod toolbar; pub mod type_panels_ui; pub(super) mod variables_ui; diff --git a/crates/ui-egui/src/panels/layer_row_ui.rs b/crates/ui-egui/src/panels/layer_row_ui.rs index 060b12a223..18258c46ea 100644 --- a/crates/ui-egui/src/panels/layer_row_ui.rs +++ b/crates/ui-egui/src/panels/layer_row_ui.rs @@ -279,7 +279,11 @@ pub fn panel_menu(app: &mut crate::PhotocraftApp, ui: &mut egui::Ui) { ui.separator(); run_menu_command(app, ui, tl!("Flatten Image"), "layer.flattenImage", Some(json!({}))); ui.separator(); - if ui.add_enabled(app.session.is_enabled("layer.lockLayers"), egui::Button::new(tl!("Lock Layers…"))).clicked() { + let mut lock_layers = egui::Button::new(tl!("Lock Layers…")); + if let Some(key) = crate::shortcuts::shortcut_label(app, "layer.lockLayers") { + lock_layers = lock_layers.shortcut_text(key); + } + if ui.add_enabled(app.session.is_enabled("layer.lockLayers"), lock_layers).clicked() { app.ui.layers_panel_dialog = Some(LayersPanelDialog::LockLayers { transparency: false, pixels: false, position: false, artboard: false, all: true }); ui.close(); } diff --git a/crates/ui-egui/src/panels/layers.rs b/crates/ui-egui/src/panels/layers.rs index 7dfa2ad6cd..856f5a09ff 100644 --- a/crates/ui-egui/src/panels/layers.rs +++ b/crates/ui-egui/src/panels/layers.rs @@ -318,8 +318,21 @@ pub(super) fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) { // A click on that empty space deselects every layer, as in Photoshop (#8100). It // starts under the last layer's sub-rows, which take their own clicks. let empty = Rect::from_min_max(pos2(below.left(), rows_bottom), below.max); - if empty.height() > 0.0 && ui.interact(empty, ui.scope_id().with("layers-empty-space"), Sense::click()).clicked() && !selection.is_empty() { - actions.push(("select.deselectLayers".into(), json!({}))); + if empty.height() > 0.0 { + let response = ui.interact(empty, ui.scope_id().with("layers-empty-space"), Sense::click()); + if response.clicked() && !selection.is_empty() { + actions.push(("select.deselectLayers".into(), json!({}))); + } + // A right-click there opens the thumbnail size and clipping choices (#11404). + response.context_menu(|ui| super::layers_empty_menu::show(app, ui)); + } + } else { + // No row drawn (a filter that matches no layer): the whole list is empty space, + // and its right-click opens the same menu. + let empty = Rect::from_min_max(pos2(ui.max_rect().left(), rows_bottom), pos2(ui.max_rect().right(), ui.clip_rect().bottom())); + if empty.height() > 0.0 && empty.width() > 0.0 { + let response = ui.interact(empty, ui.scope_id().with("layers-empty-space"), Sense::click()); + response.context_menu(|ui| super::layers_empty_menu::show(app, ui)); } } // Tab / ⇧Tab in a rename: rename the layer below / above next, as in Photoshop. The diff --git a/crates/ui-egui/src/panels/layers_empty_menu.rs b/crates/ui-egui/src/panels/layers_empty_menu.rs new file mode 100644 index 0000000000..17c1c0d6e0 --- /dev/null +++ b/crates/ui-egui/src/panels/layers_empty_menu.rs @@ -0,0 +1,43 @@ +//! The menu a right-click on the empty area below the last layer row opens (#11404): the +//! thumbnail size and what a thumbnail frames. Both are the settings Panel Options... edits. + +use serde_json::json; + +use crate::PhotocraftApp; +use crate::state::LayerThumbnailSize; + +/// The four sizes, in menu order. +pub(super) fn sizes() -> [(LayerThumbnailSize, &'static str); 4] { + [ + (LayerThumbnailSize::None, tl!("No Thumbnails")), + (LayerThumbnailSize::Small, tl!("Small Thumbnails")), + (LayerThumbnailSize::Medium, tl!("Medium Thumbnails")), + (LayerThumbnailSize::Large, tl!("Large Thumbnails")), + ] +} + +pub(super) fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui) { + let current = app.ui.layers_panel_options.thumbnail_size; + for (size, label) in sizes() { + let mut on = current == size; + if crate::widgets::checkbox(ui, &mut on, label).clicked() { + app.ui.layers_panel_options.thumbnail_size = size; + super::layers_panel_ui::persist_options(app); + ui.close(); + } + } + ui.separator(); + let clip = app.session.prefs().interface.clip_thumbnails_to_layer_bounds; + for (to_layer, label) in [(true, tl!("Clip Thumbnails to Layer Bounds")), (false, tl!("Clip Thumbnails to Document Bounds"))] { + let mut on = clip == to_layer; + if crate::widgets::checkbox(ui, &mut on, label).clicked() { + if clip != to_layer + && let Err(e) = app.run("prefs.set", json!({"path": "interface.clipThumbnailsToLayerBounds", "value": to_layer})) + { + app.ui.status = e; + app.ui.status_error = true; + } + ui.close(); + } + } +} diff --git a/crates/ui-egui/src/panels/toolbar.rs b/crates/ui-egui/src/panels/toolbar.rs index c8f62a602e..839e461177 100644 --- a/crates/ui-egui/src/panels/toolbar.rs +++ b/crates/ui-egui/src/panels/toolbar.rs @@ -6,7 +6,7 @@ use super::{Align2, Color32, PhotocraftApp, Pos2, Rect, Sense, Stroke, StrokeKin /// Tool groups separated by hairlines, Photoshop order. /// Photoshop toolbar: divider-separated sections of slots; each slot is a flyout group whose button /// shows the group's last-used tool. -pub(super) const TOOL_SECTIONS: &[&[&[Tool]]] = &[ +pub(crate) const TOOL_SECTIONS: &[&[&[Tool]]] = &[ &[&[Tool::Move, Tool::Artboard]], &[ &[Tool::RectMarquee, Tool::EllipseMarquee, Tool::SingleRowMarquee, Tool::SingleColumnMarquee], @@ -17,8 +17,8 @@ pub(super) const TOOL_SECTIONS: &[&[&[Tool]]] = &[ &[Tool::Eyedropper, Tool::ColorSampler, Tool::Ruler, Tool::Note, Tool::Count], ], &[ - &[Tool::Remove, Tool::SpotHealing, Tool::Healing, Tool::Patch, Tool::ContentAwareMove, Tool::RedEye], - &[Tool::Brush, Tool::Pencil, Tool::MixerBrush, Tool::ColorReplacement], + &[Tool::SpotHealing, Tool::Remove, Tool::Healing, Tool::Patch, Tool::ContentAwareMove, Tool::RedEye], + &[Tool::Brush, Tool::Pencil, Tool::ColorReplacement, Tool::MixerBrush], &[Tool::CloneStamp, Tool::PatternStamp], &[Tool::HistoryBrush, Tool::ArtHistoryBrush], &[Tool::Eraser, Tool::BackgroundEraser, Tool::MagicEraser], @@ -46,11 +46,17 @@ fn slot_tool(ui: &egui::Ui, current: Tool, slot: &[Tool], key: egui::Id) -> Tool /// Next tool in a toolbar flyout slot after `from`, wrapping (Photoshop Alt/Option-click). An /// empty slot returns `from` unchanged rather than dividing by zero. -pub(super) fn next_slot_tool(slot: &[Tool], from: Tool) -> Tool { +pub(crate) fn next_slot_tool(slot: &[Tool], from: Tool) -> Tool { let i = slot.iter().position(|&t| t == from).unwrap_or(0); i.checked_add(1).and_then(|n| n.checked_rem(slot.len())).and_then(|n| slot.get(n)).copied().unwrap_or(from) } +/// Position of `tool` in [`TOOL_SECTIONS`] read top to bottom, slot by slot. Tools outside the +/// toolbar sort last. Shift+letter orders a key's group by this so it steps like the flyout. +pub(crate) fn toolbar_position(tool: Tool) -> usize { + TOOL_SECTIONS.iter().flat_map(|section| section.iter()).flat_map(|slot| slot.iter()).position(|&t| t == tool).unwrap_or(usize::MAX) +} + /// [`TOOL_SECTIONS`] without the tools hidden in Edit › Toolbar (`hidden` holds tool names: the /// dialog writes `Tool` debug names, `edit.toolbar` takes any name `Tool::from_name` reads). A /// slot keeps only its visible tools, so its flyout lists just those; a slot with none left is diff --git a/crates/ui-egui/src/panels/type_flyout_tests.rs b/crates/ui-egui/src/panels/type_flyout_tests.rs index 5144379a3e..9e13f66169 100644 --- a/crates/ui-egui/src/panels/type_flyout_tests.rs +++ b/crates/ui-egui/src/panels/type_flyout_tests.rs @@ -293,8 +293,8 @@ fn red_eye_is_in_the_j_flyout() { let j = TOOL_SECTIONS.iter().flat_map(|section| section.iter()).find(|slot| slot.contains(&Tool::SpotHealing)).expect("J group"); assert!(j.contains(&Tool::RedEye), "{j:?}"); assert_eq!(j.last(), Some(&Tool::RedEye)); - // Remove leads the flyout, so the slot shows it until another J tool is picked. - assert_eq!(j.first(), Some(&Tool::Remove)); + // Spot Healing Brush leads the flyout, so the slot shows it until another J tool is picked. + assert_eq!(j.first(), Some(&Tool::SpotHealing)); } #[test] @@ -348,8 +348,8 @@ fn long_press_brush_selects_color_replacement() { frame(&mut app, &ctx, 0.1, vec![]); let index = TOOL_SECTIONS.iter().flat_map(|section| section.iter()).position(|slot| slot.contains(&Tool::Brush)).unwrap(); let slot = TOOL_SECTIONS.iter().flat_map(|section| section.iter()).nth(index).copied().unwrap(); - // Photoshop's Brush group, Color Replacement after the Mixer Brush. - assert_eq!(slot, &[Tool::Brush, Tool::Pencil, Tool::MixerBrush, Tool::ColorReplacement]); + // Photoshop's Brush group, Color Replacement before the Mixer Brush. + assert_eq!(slot, &[Tool::Brush, Tool::Pencil, Tool::ColorReplacement, Tool::MixerBrush]); let bx = if Tokens::get(&ctx).pro { 30.0 } else { 36.0 }; let mut buttons: Vec = ctx.viewport(|v| { v.prev_pass @@ -369,8 +369,8 @@ fn long_press_brush_selects_color_replacement() { frame(&mut app, &ctx, 1.45, vec![]); let key = egui::Id::unique(("tool-slot", index)); let menu = ctx.memory(|m| m.area_rect(key.with("flyout"))).unwrap(); - // The last of the four 26-point rows. - let row = egui::pos2(menu.left() + 65.0, menu.bottom() - 20.0); + // The third of the four 26-point rows. + let row = egui::pos2(menu.left() + 65.0, menu.bottom() - 46.0); frame(&mut app, &ctx, 2.0, vec![egui::Event::PointerMoved(row), pointer(row, true)]); frame(&mut app, &ctx, 2.05, vec![pointer(row, false)]); assert_eq!(app.ui.tool, Tool::ColorReplacement); diff --git a/crates/ui-egui/src/pencil_tests.rs b/crates/ui-egui/src/pencil_tests.rs index aea5743215..6cc618e8fa 100644 --- a/crates/ui-egui/src/pencil_tests.rs +++ b/crates/ui-egui/src/pencil_tests.rs @@ -259,7 +259,7 @@ fn the_eraser_in_block_mode_erases_a_16_screen_px_square() { } #[test] -fn b_cycles_brush_pencil_mixer_brush_and_color_replacement() { +fn b_cycles_brush_pencil_color_replacement_and_mixer_brush() { let mut h = Harness::builder().with_size(vec2(1280.0, 800.0)).with_max_steps(64).build_eframe(|cc| { PhotocraftApp::setup_context(&cc.egui_ctx, Default::default()); let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), Default::default()); @@ -279,9 +279,9 @@ fn b_cycles_brush_pencil_mixer_brush_and_color_replacement() { press(&mut h, Modifiers::NONE); assert_eq!(h.state().ui.tool, Tool::Pencil); press(&mut h, Modifiers::NONE); - assert_eq!(h.state().ui.tool, Tool::MixerBrush); - press(&mut h, Modifiers::NONE); assert_eq!(h.state().ui.tool, Tool::ColorReplacement); + press(&mut h, Modifiers::NONE); + assert_eq!(h.state().ui.tool, Tool::MixerBrush); // Use Shift Key for Tool Switch: ⇧B cycles, B keeps the group's tool. h.state_mut().session.edit_prefs(|p| p.tools.use_shift_key_for_tool_switch = true); press(&mut h, Modifiers::SHIFT); @@ -289,11 +289,11 @@ fn b_cycles_brush_pencil_mixer_brush_and_color_replacement() { press(&mut h, Modifiers::SHIFT); assert_eq!(h.state().ui.tool, Tool::Pencil); press(&mut h, Modifiers::SHIFT); - assert_eq!(h.state().ui.tool, Tool::MixerBrush); + assert_eq!(h.state().ui.tool, Tool::ColorReplacement); press(&mut h, Modifiers::SHIFT); - assert_eq!(h.state().ui.tool, Tool::ColorReplacement); + assert_eq!(h.state().ui.tool, Tool::MixerBrush); press(&mut h, Modifiers::NONE); - assert_eq!(h.state().ui.tool, Tool::ColorReplacement); + assert_eq!(h.state().ui.tool, Tool::MixerBrush); assert_eq!(Tool::from_name("pencil"), Some(Tool::Pencil)); assert_eq!(Tool::from_name("mixerBrush"), Some(Tool::MixerBrush)); } diff --git a/crates/ui-egui/src/polygon_lasso_step_snap_tests.rs b/crates/ui-egui/src/polygon_lasso_step_snap_tests.rs new file mode 100644 index 0000000000..cedd61c69e --- /dev/null +++ b/crates/ui-egui/src/polygon_lasso_step_snap_tests.rs @@ -0,0 +1,192 @@ +//! Polygonal Lasso History step and Shift snap (#11393): the step is named "Polygonal Lasso" +//! however the polygon closes, and a Shift diagonal keeps the shorter of the two offsets on both +//! axes, as Photoshop does. + +use egui::{Modifiers, PointerButton, Pos2, vec2}; +use egui_kittest::Harness; +use photocraft_geom::Rect; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::{ToolEvent, ViewXform, constrained_polygon_point, tool_event}; +use crate::state::Tool; + +fn app_with(tool: Tool) -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 800, "height": 600, "background": "transparent"})).unwrap(); + app.sync_views(); + app.ui.extras.snap = false; + app.ui.tool = tool; + app +} + +fn ev(app: &mut PhotocraftApp, e: ToolEvent, m: Modifiers) { + tool_event(app, e, m); +} + +fn click(app: &mut PhotocraftApp, x: f64, y: f64, m: Modifiers) { + ev(app, ToolEvent::Down { x, y, pressure: 1.0 }, m); + ev(app, ToolEvent::Up { x, y }, m); +} + +fn last_step(app: &PhotocraftApp) -> Option { + app.session.active().unwrap().history.entries().last().cloned() +} + +fn bounds(app: &PhotocraftApp) -> Option { + app.session.active().unwrap().doc.selection.as_ref().map(|s| s.content_bounds()) +} + +fn harness() -> Harness<'static, PhotocraftApp> { + let mut app = app_with(Tool::PolygonLasso); + app.ui.extras.rulers = false; + // 60 fps, so a double-click's two clicks fall inside egui's 0.3 s window. + let mut h = Harness::builder().with_size(vec2(1000.0, 700.0)).with_step_dt(1.0 / 60.0).build_ui_state( + |ui, app: &mut PhotocraftApp| { + let ctx = ui.ctx().clone(); + if !ctx.fonts(|f| f.families().contains(&egui::FontFamily::Name("medium".into()))) { + return; + } + crate::shortcuts::handle(app, &ctx); + egui::CentralPanel::default().show(ui, |ui| crate::canvas::document_area(app, ui)); + crate::dialogs::show(app, &ctx); + }, + app, + ); + PhotocraftApp::setup_context(&h.ctx, crate::theme::ThemeKind::ALL[0]); + h.run_steps(4); + // 100 %: one document pixel per point, the area around (200, 200) in view. + let v = &mut h.state_mut().ui.views[0]; + v.zoom = 1.0; + v.center = [200.0, 200.0]; + v.fit_pending = false; + h.run_steps(2); + h +} + +fn screen(h: &Harness<'static, PhotocraftApp>, x: f32, y: f32) -> Pos2 { + let app = h.state(); + let v = &app.ui.views[0]; + let xf = ViewXform { + rect: crate::rulers::content_rect(app, app.last_canvas_rect), + zoom: v.zoom, + center: v.center, + flip: app.ui.view.flip_horizontal, + rotation: v.rotation, + aspect: app.ui.view.display_aspect(), + }; + xf.to_screen(x, y) +} + +fn screen_click(h: &mut Harness<'static, PhotocraftApp>, x: f32, y: f32) { + let p = screen(h, x, y); + h.event(egui::Event::PointerMoved(p)); + h.run_steps(1); + for pressed in [true, false] { + h.event(egui::Event::PointerButton { pos: p, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE }); + h.run_steps(1); + } +} + +/// Three corners, well apart in time so they aren't a double-click. +fn three_corners(h: &mut Harness<'static, PhotocraftApp>) { + for (x, y) in [(100.0, 100.0), (300.0, 100.0), (300.0, 300.0)] { + screen_click(h, x, y); + h.run_steps(30); + } +} + +#[test] +fn closing_on_the_start_point_records_a_polygonal_lasso_step() { + let mut app = app_with(Tool::PolygonLasso); + for (x, y) in [(100.0, 100.0), (300.0, 100.0), (300.0, 300.0), (100.0, 100.0)] { + click(&mut app, x, y, Modifiers::NONE); + } + assert!(app.ui.polygon.is_empty(), "the start point closes the polygon"); + assert_eq!(bounds(&app), Some(Rect::new(100, 100, 300, 300))); + assert_eq!(last_step(&app).as_deref(), Some("Polygonal Lasso")); +} + +#[test] +fn closing_with_enter_records_a_polygonal_lasso_step() { + let mut h = harness(); + three_corners(&mut h); + let before = h.state().session.active().unwrap().history.entries().len(); + h.key_press(egui::Key::Enter); + h.run_steps(2); + assert!(h.state().ui.polygon.is_empty(), "Enter closes the polygon"); + assert!(bounds(h.state()).is_some()); + assert_eq!(h.state().session.active().unwrap().history.entries().len(), before + 1, "one step"); + assert_eq!(last_step(h.state()).as_deref(), Some("Polygonal Lasso")); +} + +#[test] +fn closing_with_a_double_click_records_a_polygonal_lasso_step() { + let mut h = harness(); + three_corners(&mut h); + screen_click(&mut h, 100.0, 300.0); + screen_click(&mut h, 100.0, 300.0); + h.run_steps(1); + assert!(h.state().ui.polygon.is_empty(), "the double-click closes the polygon"); + assert!(bounds(h.state()).is_some()); + assert_eq!(last_step(h.state()).as_deref(), Some("Polygonal Lasso")); +} + +#[test] +fn the_freehand_lasso_still_records_a_lasso_step() { + let mut app = app_with(Tool::Lasso); + ev(&mut app, ToolEvent::Down { x: 100.0, y: 100.0, pressure: 1.0 }, Modifiers::NONE); + for (x, y) in [(200.0, 100.0), (300.0, 100.0), (300.0, 200.0), (300.0, 300.0), (200.0, 300.0)] { + ev(&mut app, ToolEvent::Move { x, y, pressure: 1.0 }, Modifiers::NONE); + } + ev(&mut app, ToolEvent::Up { x: 200.0, y: 300.0 }, Modifiers::NONE); + assert!(bounds(&app).is_some()); + assert_eq!(last_step(&app).as_deref(), Some("Lasso")); + // And the engine's own default, for scripts that leave `polygonal` out. + app.run("select.lasso", json!({"points": [[10, 10], [60, 10], [10, 60]]})).unwrap(); + assert_eq!(last_step(&app).as_deref(), Some("Lasso")); +} + +/// The reference measurement: from 100,100 a Shift-click at 200,170 lands on (170,170), and the +/// closed selection's right edge is at 170. +#[test] +fn a_shift_click_at_200_170_from_100_100_places_the_vertex_at_170_170() { + let mut app = app_with(Tool::PolygonLasso); + click(&mut app, 100.0, 100.0, Modifiers::NONE); + click(&mut app, 200.0, 170.0, Modifiers::SHIFT); + assert_eq!(app.ui.polygon, vec![[100.0, 100.0], [170.0, 170.0]]); + click(&mut app, 100.0, 300.0, Modifiers::NONE); + crate::canvas::commit_polygon(&mut app); + assert_eq!(bounds(&app).map(|r| (r.x0, r.x1)), Some((100, 170)), "{:?}", bounds(&app)); + assert_eq!(last_step(&app).as_deref(), Some("Polygonal Lasso")); +} + +#[test] +fn each_diagonal_keeps_the_shorter_offset_with_its_signs() { + let from = [100.0, 100.0]; + // One case per diagonal, the shorter offset on either axis. + for (to, want) in [ + ([200.0, 170.0], [170.0, 170.0]), // down-right, dy shorter + ([30.0, 200.0], [30.0, 170.0]), // down-left, dx shorter + ([0.0, 30.0], [30.0, 30.0]), // up-left, dy shorter + ([170.0, 0.0], [170.0, 30.0]), // up-right, dx shorter + ] { + assert_eq!(constrained_polygon_point(from, to), want, "{to:?}"); + } +} + +/// Axis snaps aren't measured in the reference, so they keep today's rule: the segment's length. +#[test] +fn horizontal_and_vertical_snaps_keep_the_segment_length() { + let from = [100.0, 100.0]; + let length = 100.0_f64.hypot(20.0); + for (to, want) in [ + ([200.0, 120.0], [100.0 + length, 100.0]), + ([80.0, 200.0], [100.0, 100.0 + length]), + ([0.0, 80.0], [100.0 - length, 100.0]), + ([120.0, 0.0], [100.0, 100.0 - length]), + ] { + let got = constrained_polygon_point(from, to); + assert!((got[0] - want[0]).abs() < 1e-9 && (got[1] - want[1]).abs() < 1e-9, "{to:?} → {got:?}"); + } +} diff --git a/crates/ui-egui/src/polygon_lasso_tests.rs b/crates/ui-egui/src/polygon_lasso_tests.rs index f3f713ed6f..55fb30ca30 100644 --- a/crates/ui-egui/src/polygon_lasso_tests.rs +++ b/crates/ui-egui/src/polygon_lasso_tests.rs @@ -635,7 +635,8 @@ fn shift_constrains_polygonal_lasso_segments_but_unmodified_clicks_remain_free() ev(&mut app, "up", 140.0, 120.0, Modifiers::SHIFT); let diagonal = app.ui.polygon[1]; assert!((diagonal[0] - diagonal[1]).abs() < 1e-8, "45-degree direction: {diagonal:?}"); - assert!((diagonal[0] - 100.0 - 40.0_f64.hypot(20.0) / 2.0_f64.sqrt()).abs() < 1e-8); + // The diagonal keeps the shorter offset (20) on both axes (#11393). + assert!((diagonal[0] - 120.0).abs() < 1e-8, "{diagonal:?}"); // Releasing Shift restores free placement rather than constraining subsequent points. ev(&mut app, "down", 155.0, 175.0, Modifiers::NONE); ev(&mut app, "up", 155.0, 175.0, Modifiers::NONE); @@ -652,7 +653,9 @@ fn shift_polygonal_lasso_snap_has_all_eight_directions_and_handles_zero_length() let dy = end[1] - origin[1]; let angle = dy.atan2(dx) / std::f64::consts::FRAC_PI_4; assert!((angle - angle.round()).abs() < 1e-9, "{delta:?} → {end:?}"); - assert!((dx.hypot(dy) - delta[0].hypot(delta[1])).abs() < 1e-8); + // Axis snaps keep the length; diagonals keep the shorter offset on both axes (#11393). + let kept = if angle.round().rem_euclid(2.0) == 1.0 { delta[0].abs().min(delta[1].abs()) * std::f64::consts::SQRT_2 } else { delta[0].hypot(delta[1]) }; + assert!((dx.hypot(dy) - kept).abs() < 1e-8, "{delta:?} → {end:?}"); } assert_eq!(crate::canvas::constrained_polygon_point(origin, origin), origin); } diff --git a/crates/ui-egui/src/preferences_submenu_tests.rs b/crates/ui-egui/src/preferences_submenu_tests.rs new file mode 100644 index 0000000000..65b54dc4eb --- /dev/null +++ b/crates/ui-egui/src/preferences_submenu_tests.rs @@ -0,0 +1,87 @@ +//! #11398: Edit › Preferences says "Plugins…" and "Camera Raw…" and has the reference +//! application's two separators (after the first entry and before Camera Raw…). + +use crate::menu_catalog::CATALOG; + +/// The submenu's rows, top to bottom: (label or "---", command id). +fn rows() -> Vec<(&'static str, &'static str)> { + CATALOG.iter().filter(|e| e.0 == ["Edit", "Preferences"]).map(|e| (e.1, e.3)).collect() +} + +#[test] +fn preferences_submenu_reads_in_the_reference_order_with_two_separators() { + let labels: Vec<&str> = rows().into_iter().map(|r| r.0).collect(); + // Row 1 ("Settings…") is #8239's: whatever it says, it is first and followed by a separator. + assert_eq!( + &labels[1..], + [ + "---", + "AI Integrations…", + "Interface…", + "Workspace…", + "Tools…", + "History Log…", + "File Handling…", + "Export…", + "Performance…", + "Scratch Disks…", + "Cursors…", + "Transparency & Gamut…", + "Units & Rulers…", + "Guides, Grid & Slices…", + "Plugins…", + "Type…", + "Enhanced Controls…", + "---", + "Camera Raw…", + ] + ); +} + +#[test] +fn preferences_submenu_ids_are_unchanged() { + let ids: Vec<&str> = rows().into_iter().map(|r| r.1).collect(); + assert_eq!( + ids, + [ + "edit.preferences.general", + "---", + "edit.preferences.integrations", + "edit.preferences.interface", + "edit.preferences.workspace", + "edit.preferences.tools", + "edit.preferences.historyLog", + "edit.preferences.fileHandling", + "edit.preferences.export", + "edit.preferences.performance", + "edit.preferences.scratchDisks", + "edit.preferences.cursors", + "edit.preferences.transparencyAndGamut", + "edit.preferences.unitsAndRulers", + "edit.preferences.guidesGridAndSlices", + "edit.preferences.plugIns", + "edit.preferences.type", + "edit.preferences.enhancedControls", + "---", + "edit.preferences.rawDefaults", + ] + ); +} + +#[test] +fn engine_labels_match_the_catalogue_for_the_renamed_rows() { + for id in ["edit.preferences.plugIns", "edit.preferences.rawDefaults"] { + let catalogue = CATALOG.iter().find(|e| e.3 == id).unwrap_or_else(|| panic!("{id} missing from the catalogue")).1; + let engine = photocraft_engine::commands::find(id).unwrap_or_else(|| panic!("{id} missing from the engine")).label; + assert_eq!(engine, catalogue, "{id}"); + } + assert_eq!(photocraft_engine::commands::find("edit.preferences.plugIns").unwrap().label, "Plugins…"); + assert_eq!(photocraft_engine::commands::find("edit.preferences.rawDefaults").unwrap().label, "Camera Raw…"); +} + +#[test] +fn preferences_dialog_page_names_follow_the_menu() { + let title = |key: &str| photocraft_engine::prefs::SECTIONS.iter().find(|(k, _)| *k == key).map(|(_, t)| *t); + assert_eq!(title("plugIns"), Some("Plugins")); + assert_eq!(title("rawDefaults"), Some("Camera Raw Defaults")); +} diff --git a/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs b/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs index f59bf278e8..20a2695a97 100644 --- a/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs +++ b/crates/ui-egui/src/prefs/prefs_ui/shortcut_capture_tests.rs @@ -106,7 +106,7 @@ fn toolbar_shortcut_overrides_remove_old_keys_and_skip_removed_group_members() { press(&mut app, Key::B, Modifiers::NONE); assert_eq!(app.ui.tool, Tool::Brush, "a removed tool cannot return through group memory"); press(&mut app, Key::B, Modifiers::SHIFT); - assert_eq!(app.ui.tool, Tool::MixerBrush, "Shift cycling skips a removed tool"); + assert_eq!(app.ui.tool, Tool::ColorReplacement, "Shift cycling skips a removed tool"); app.run("edit.keyboardShortcuts", json!({"reset": true})).unwrap(); app.ui.tool = Tool::Brush; @@ -114,7 +114,7 @@ fn toolbar_shortcut_overrides_remove_old_keys_and_skip_removed_group_members() { assert_eq!(app.ui.tool, Tool::Pencil, "reset restores the default group"); app.session.edit_prefs(|p| p.tools.use_shift_key_for_tool_switch = false); press(&mut app, Key::B, Modifiers::NONE); - assert_eq!(app.ui.tool, Tool::MixerBrush, "plain-key cycling still follows the preference"); + assert_eq!(app.ui.tool, Tool::ColorReplacement, "plain-key cycling still follows the preference"); } #[test] diff --git a/crates/ui-egui/src/selection_move_step_tests.rs b/crates/ui-egui/src/selection_move_step_tests.rs new file mode 100644 index 0000000000..5c3ec336fd --- /dev/null +++ b/crates/ui-egui/src/selection_move_step_tests.rs @@ -0,0 +1,99 @@ +//! #11390: dragging the selection outline with a marquee or lasso records "Move Selection", as the +//! reference application does; Select > Transform Selection keeps "Transform Selection". + +use egui::Modifiers; +use photocraft_geom::Rect; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::{ToolEvent, tool_event}; +use crate::state::Tool; + +/// A 400 x 300 document with 100,100 to 300,300 selected and `tool` active. +fn app_with_selection(tool: Tool) -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 400, "height": 400})).unwrap(); + app.sync_views(); + app.ui.extras.snap = false; + app.ui.tool = tool; + app.run("select.rect", json!({"x": 100, "y": 100, "width": 200, "height": 200})).unwrap(); + app +} + +fn drag(app: &mut PhotocraftApp, from: [f64; 2], to: [f64; 2]) { + let m = Modifiers::NONE; + tool_event(app, ToolEvent::Down { x: from[0], y: from[1], pressure: 1.0 }, m); + tool_event(app, ToolEvent::Move { x: to[0], y: to[1], pressure: 1.0 }, m); + tool_event(app, ToolEvent::Up { x: to[0], y: to[1] }, m); +} + +fn bounds(app: &PhotocraftApp) -> Option { + app.session.active().unwrap().doc.selection.as_ref().map(|s| s.content_bounds()) +} + +fn last_step(app: &PhotocraftApp) -> String { + app.session.active().unwrap().history.entries().last().cloned().unwrap() +} + +fn past(app: &PhotocraftApp) -> usize { + app.session.active().unwrap().history.past_len() +} + +fn check_drag_records_move_selection(tool: Tool) { + let mut app = app_with_selection(tool); + let before = past(&app); + drag(&mut app, [200.0, 200.0], [300.0, 250.0]); + assert_eq!(bounds(&app), Some(Rect::new(200, 150, 400, 350)), "moved by +100,+50"); + assert_eq!(past(&app), before + 1, "one step"); + assert_eq!(last_step(&app), "Move Selection"); +} + +#[test] +fn rectangular_marquee_drag_inside_records_move_selection() { + check_drag_records_move_selection(Tool::RectMarquee); +} + +#[test] +fn elliptical_marquee_drag_inside_records_move_selection() { + check_drag_records_move_selection(Tool::EllipseMarquee); +} + +#[test] +fn lasso_drag_inside_records_move_selection() { + check_drag_records_move_selection(Tool::Lasso); +} + +#[test] +fn undo_after_the_drag_restores_the_outline() { + let mut app = app_with_selection(Tool::RectMarquee); + drag(&mut app, [200.0, 200.0], [300.0, 250.0]); + app.run("edit.undo", json!({})).unwrap(); + assert_eq!(bounds(&app), Some(Rect::new(100, 100, 300, 300))); +} + +#[test] +fn transform_selection_keeps_its_step_name() { + let mut app = app_with_selection(Tool::RectMarquee); + app.run("select.transformSelection", json!({"dx": 100, "dy": 50})).unwrap(); + assert_eq!(bounds(&app), Some(Rect::new(200, 150, 400, 350))); + assert_eq!(last_step(&app), "Transform Selection"); +} + +#[test] +fn a_click_without_moving_still_deselects() { + let mut app = app_with_selection(Tool::RectMarquee); + drag(&mut app, [200.0, 200.0], [200.0, 200.0]); + assert_eq!(bounds(&app), None); + assert_eq!(last_step(&app), "Deselect"); +} + +#[test] +fn an_unknown_step_name_is_refused() { + let mut app = app_with_selection(Tool::RectMarquee); + let before = past(&app); + for name in [json!("Delete Layer"), json!(""), json!(3)] { + assert!(app.run("select.transformSelection", json!({"dx": 10, "dy": 0, "stepName": name})).is_err()); + } + assert_eq!(past(&app), before); + assert_eq!(bounds(&app), Some(Rect::new(100, 100, 300, 300))); +} diff --git a/crates/ui-egui/src/shape_bounds_box_tests.rs b/crates/ui-egui/src/shape_bounds_box_tests.rs new file mode 100644 index 0000000000..7e4dbb8902 --- /dev/null +++ b/crates/ui-egui/src/shape_bounds_box_tests.rs @@ -0,0 +1,325 @@ +//! #11107: the box round several selected shape layers (Path Selection and the shape tools), its +//! handles scaling them, measured against the reference application: two rectangles +//! 100,98–403,301 and 420,318–723,451 scaled by dragging the bottom-right handle by (−100, −60). + +use egui::Modifiers; +use photocraft_doc::LayerContent; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::{ToolEvent, ViewXform, tool_event}; +use crate::shape_bounds_box::scale_for; +use crate::state::Tool; + +const NONE: Modifiers = Modifiers::NONE; + +/// A 1:1 view of the 1000 × 700 document, turned by `rotation` degrees. +fn view(rotation: f32) -> ViewXform { + ViewXform { + rect: egui::Rect::from_min_size(egui::pos2(0.0, 0.0), egui::vec2(1000.0, 700.0)), + zoom: 1.0, + center: [500.0, 350.0], + flip: false, + rotation, + aspect: 1.0, + } +} + +fn cursor(app: &PhotocraftApp, p: [f64; 2]) -> Option { + crate::shape_bounds_box::cursor(app, &view(0.0), p) +} + +/// A 1000 × 700 document with the two measured rectangles, both selected. +fn app_with_two_shapes(tool: Tool) -> (PhotocraftApp, u64, u64) { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 1000, "height": 700, "background": "white"})).unwrap(); + app.run("shape.create", json!({"kind": "rect", "rect": [100, 98, 303, 203], "fill": "#e02020"})).unwrap(); + let a = app.session.active().unwrap().active_layer.unwrap(); + app.run("shape.create", json!({"kind": "rect", "rect": [420, 318, 303, 133], "fill": "#2050e0"})).unwrap(); + let b = app.session.active().unwrap().active_layer.unwrap(); + app.run("layer.select", json!({"layer": a.0})).unwrap(); + app.run("layer.select", json!({"layer": b.0, "mode": "toggle"})).unwrap(); + app.ui.tool = tool; + (app, a.0, b.0) +} + +fn bounds(app: &PhotocraftApp, id: u64) -> (f64, f64, f64, f64) { + let st = app.session.active().unwrap(); + let LayerContent::Shape(sh) = &st.doc.layer(photocraft_doc::LayerId(id)).unwrap().content else { panic!("a shape layer") }; + sh.path.control_bounds().unwrap() +} + +fn near(got: (f64, f64, f64, f64), want: [f64; 4]) { + let got = [got.0, got.1, got.2, got.3]; + assert!(got.iter().zip(want).all(|(g, w)| (g - w).abs() <= 1.0), "{got:?} vs {want:?}"); +} + +fn drag(app: &mut PhotocraftApp, from: [f64; 2], to: [f64; 2]) { + tool_event(app, ToolEvent::Down { x: from[0], y: from[1], pressure: 1.0 }, NONE); + let mid = [(from[0] + to[0]) / 2.0, (from[1] + to[1]) / 2.0]; + tool_event(app, ToolEvent::Move { x: mid[0], y: mid[1], pressure: 1.0 }, NONE); + tool_event(app, ToolEvent::Move { x: to[0], y: to[1], pressure: 1.0 }, NONE); + tool_event(app, ToolEvent::Up { x: to[0], y: to[1] }, NONE); +} + +#[test] +fn the_measured_drag_gives_the_reference_bounds_with_every_tool() { + for tool in [Tool::Rectangle, Tool::PathSelection, Tool::EllipseShape, Tool::Triangle, Tool::Polygon, Tool::Line] { + let (mut app, a, b) = app_with_two_shapes(tool); + let steps = app.session.active().unwrap().history.past_len(); + drag(&mut app, [723.0, 451.0], [623.0, 391.0]); + near(bounds(&app, a), [100.0, 98.0, 354.0, 268.0]); + near(bounds(&app, b), [368.0, 282.0, 621.0, 394.0]); + let st = app.session.active().unwrap(); + assert_eq!(st.history.past_len(), steps + 1, "{tool:?}: one history step"); + assert_eq!(st.history.entries().last().map(String::as_str), Some("Transform Path"), "{tool:?}"); + assert!(app.ui.transform.is_none() && app.ui.shape_box.is_none(), "{tool:?}: no Free Transform session opens"); + // The shapes stay live. + for id in [a, b] { + let LayerContent::Shape(sh) = &app.session.active().unwrap().doc.layer(photocraft_doc::LayerId(id)).unwrap().content else { panic!() }; + assert!(sh.live.is_some(), "{tool:?}: still a live shape"); + } + } +} + +#[test] +fn an_edge_handle_scales_one_way_and_undo_restores_both_shapes() { + let (mut app, a, b) = app_with_two_shapes(Tool::PathSelection); + // The right edge's middle, dragged 100 px left: x scales about the left edge (100). + drag(&mut app, [723.0, 274.5], [623.0, 274.5]); + let s = 523.0 / 623.0; + near(bounds(&app, a), [100.0, 98.0, 100.0 + 303.0 * s, 301.0]); + near(bounds(&app, b), [100.0 + 320.0 * s, 318.0, 100.0 + 623.0 * s, 451.0]); + app.run("edit.undo", json!({})).unwrap(); + near(bounds(&app, a), [100.0, 98.0, 403.0, 301.0]); + near(bounds(&app, b), [420.0, 318.0, 723.0, 451.0]); +} + +#[test] +fn a_click_without_movement_changes_nothing() { + let (mut app, ..) = app_with_two_shapes(Tool::Rectangle); + let steps = app.session.active().unwrap().history.past_len(); + drag(&mut app, [723.0, 451.0], [723.0, 451.0]); + assert_eq!(app.session.active().unwrap().history.past_len(), steps); + assert!(app.ui.shape_box.is_none()); +} + +#[test] +fn one_selected_shape_gets_the_box_and_other_tools_none() { + // Photoshop shows the box for a single shape too: its corner handle scales that shape. + let (mut app, a, b) = app_with_two_shapes(Tool::PathSelection); + app.run("layer.select", json!({"layer": a})).unwrap(); + assert_eq!(cursor(&app, [403.0, 301.0]), Some(egui::CursorIcon::ResizeNwSe)); + assert!(cursor(&app, [723.0, 451.0]).is_none(), "the other shape's corner is not a handle"); + drag(&mut app, [403.0, 301.0], [303.0, 241.0]); + let s = 1.0 + (-100.0 * 303.0 + -60.0 * 203.0) / (303.0f64 * 303.0 + 203.0 * 203.0); + near(bounds(&app, a), [100.0, 98.0, 100.0 + 303.0 * s, 98.0 + 203.0 * s]); + near(bounds(&app, b), [420.0, 318.0, 723.0, 451.0]); + assert_eq!(app.session.active().unwrap().history.entries().last().map(String::as_str), Some("Transform Path")); + + // Another tool has none. + let (mut app, ..) = app_with_two_shapes(Tool::Move); + assert!(cursor(&app, [723.0, 451.0]).is_none()); + app.ui.tool = Tool::Brush; + assert!(cursor(&app, [723.0, 451.0]).is_none()); +} + +#[test] +fn the_handles_show_their_scale_cursors() { + use egui::CursorIcon::{ResizeHorizontal, ResizeNeSw, ResizeNwSe, ResizeVertical}; + let (app, ..) = app_with_two_shapes(Tool::PathSelection); + let at = |p: [f64; 2]| cursor(&app, p); + assert_eq!(at([100.0, 98.0]), Some(ResizeNwSe)); + assert_eq!(at([723.0, 451.0]), Some(ResizeNwSe)); + assert_eq!(at([723.0, 98.0]), Some(ResizeNeSw)); + assert_eq!(at([100.0, 451.0]), Some(ResizeNeSw)); + assert_eq!(at([411.5, 98.0]), Some(ResizeVertical)); + assert_eq!(at([723.0, 274.5]), Some(ResizeHorizontal)); + assert_eq!(at([411.5, 274.5]), None, "inside the box the tool's own arrow stays, and outside it nothing rotates"); + assert_eq!(at([760.0, 480.0]), None); +} + +#[test] +fn a_corner_radius_widget_wins_over_the_box() { + // The widget of the second rectangle's bottom-right corner sits inside the corner, not on the + // box's handle: a press on it rounds the corners, no scale starts. + let (mut app, ..) = app_with_two_shapes(Tool::Rectangle); + let widget = [713.0, 441.0]; + tool_event(&mut app, ToolEvent::Down { x: widget[0], y: widget[1], pressure: 1.0 }, NONE); + assert!(app.ui.corner_radius.is_some() && app.ui.shape_box.is_none()); + tool_event(&mut app, ToolEvent::Up { x: widget[0], y: widget[1] }, NONE); + // A press right on the handle scales, not rounds. + tool_event(&mut app, ToolEvent::Down { x: 723.0, y: 451.0, pressure: 1.0 }, NONE); + assert!(app.ui.shape_box.is_some() && app.ui.corner_radius.is_none()); +} + +#[test] +fn scale_for_projects_a_corner_drag_onto_the_diagonal() { + let r = [100.0, 98.0, 723.0, 451.0]; + // The measured drag: both ways by the same factor, (−100, −60) on this 623 × 353 box. + let [sx, sy] = scale_for(r, [1, 1], [-100.0, -60.0]); + assert_eq!(sx, sy); + assert!((sx - 0.8372).abs() < 1e-3, "{sx}"); + // The top-left corner pulls the other way. + let [s, _] = scale_for(r, [-1, -1], [100.0, 60.0]); + assert!((s - 0.8372).abs() < 1e-3, "{s}"); + // A drag along the other diagonal changes nothing. + assert_eq!(scale_for(r, [1, 1], [353.0, -623.0]), [1.0, 1.0]); + // Edges scale one way; the box can't be flipped or blown up without bound. + assert_eq!(scale_for(r, [1, 0], [-100.0, 500.0]), [1.0 - 100.0 / 623.0, 1.0]); + assert_eq!(scale_for(r, [0, 1], [50.0, -60.0]), [1.0, 1.0 - 60.0 / 353.0]); + assert_eq!(scale_for(r, [1, 0], [-9000.0, 0.0]), [0.01, 1.0]); + assert_eq!(scale_for(r, [1, 1], [f64::NAN, 0.0]), [1.0, 1.0]); + assert_eq!(scale_for(r, [0, 0], [10.0, 10.0]), [1.0, 1.0]); +} + +#[test] +fn a_rotated_view_turns_the_handle_cursors() { + use egui::CursorIcon::{ResizeHorizontal, ResizeNeSw, ResizeNwSe, ResizeVertical}; + let (app, ..) = app_with_two_shapes(Tool::PathSelection); + let at = |rotation: f32, p: [f64; 2]| crate::shape_bounds_box::cursor(&app, &view(rotation), p); + assert_eq!(at(0.0, [723.0, 451.0]), Some(ResizeNwSe)); + // A quarter turn swaps the diagonals and the edge arrows. + assert_eq!(at(90.0, [723.0, 451.0]), Some(ResizeNeSw)); + assert_eq!(at(90.0, [723.0, 98.0]), Some(ResizeNwSe)); + assert_eq!(at(90.0, [723.0, 274.5]), Some(ResizeVertical)); + assert_eq!(at(90.0, [411.5, 98.0]), Some(ResizeHorizontal)); +} + +#[test] +fn hidden_paths_hide_the_box_and_its_handles_take_no_press() { + // View › Extras off, or View › Show › Target Path off. + for (extras, target_path) in [(false, true), (true, false)] { + let (mut app, a, b) = app_with_two_shapes(Tool::PathSelection); + app.ui.view.extras = extras; + app.ui.view.show.target_path = target_path; + assert!(cursor(&app, [723.0, 451.0]).is_none(), "extras {extras}"); + tool_event(&mut app, ToolEvent::Down { x: 723.0, y: 451.0, pressure: 1.0 }, NONE); + assert!(app.ui.shape_box.is_none(), "extras {extras}: no scale drag starts"); + tool_event(&mut app, ToolEvent::Up { x: 723.0, y: 451.0 }, NONE); + near(bounds(&app, a), [100.0, 98.0, 403.0, 301.0]); + near(bounds(&app, b), [420.0, 318.0, 723.0, 451.0]); + } +} + +/// Press the bottom-right handle and drag it, without releasing. +fn press_and_drag(app: &mut PhotocraftApp) { + tool_event(app, ToolEvent::Down { x: 723.0, y: 451.0, pressure: 1.0 }, NONE); + tool_event(app, ToolEvent::Move { x: 623.0, y: 391.0, pressure: 1.0 }, NONE); + assert!(app.ui.shape_box.is_some()); +} + +fn release_changes_nothing(app: &mut PhotocraftApp, a: u64, b: u64, steps: usize, why: &str) { + tool_event(app, ToolEvent::Up { x: 623.0, y: 391.0 }, NONE); + assert!(app.ui.shape_box.is_none(), "{why}"); + near(bounds(app, a), [100.0, 98.0, 403.0, 301.0]); + near(bounds(app, b), [420.0, 318.0, 723.0, 451.0]); + assert_eq!(app.session.active().unwrap().history.past_len(), steps, "{why}: no history step"); +} + +#[test] +fn escape_or_a_tool_change_cancels_a_handle_drag() { + // Esc. + let (mut app, a, b) = app_with_two_shapes(Tool::PathSelection); + let steps = app.session.active().unwrap().history.past_len(); + press_and_drag(&mut app); + // Through the shortcut handler, as the key arrives in the app. + let ctx = egui::Context::default(); + ctx.begin_pass(egui::RawInput { + events: vec![egui::Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: NONE }], + ..Default::default() + }); + crate::shortcuts::handle(&mut app, &ctx); + ctx.end_pass().textures_delta.clear(); + assert!(app.ui.shape_box.is_none()); + release_changes_nothing(&mut app, a, b, steps, "Esc"); + // The next press works again. + drag(&mut app, [723.0, 451.0], [623.0, 391.0]); + near(bounds(&app, a), [100.0, 98.0, 354.0, 268.0]); + + // Another tool, picked mid-drag. + let (mut app, a, b) = app_with_two_shapes(Tool::Rectangle); + let steps = app.session.active().unwrap().history.past_len(); + press_and_drag(&mut app); + app.ui.tool = Tool::Brush; + app.sync_views(); + assert!(app.ui.shape_box.is_none()); + release_changes_nothing(&mut app, a, b, steps, "tool change"); + + // Even without a frame between the change and the release. + let (mut app, a, b) = app_with_two_shapes(Tool::Rectangle); + let steps = app.session.active().unwrap().history.past_len(); + press_and_drag(&mut app); + app.ui.tool = Tool::Move; + release_changes_nothing(&mut app, a, b, steps, "tool change, same frame"); +} + +#[test] +fn a_document_switch_or_an_undo_cancels_a_handle_drag() { + let (mut app, a, b) = app_with_two_shapes(Tool::PathSelection); + let steps = app.session.active().unwrap().history.past_len(); + press_and_drag(&mut app); + app.run("file.new", json!({"width": 1000, "height": 700, "background": "white"})).unwrap(); + app.sync_views(); + assert!(app.ui.shape_box.is_none()); + let other = app.session.active().unwrap().history.past_len(); + tool_event(&mut app, ToolEvent::Up { x: 623.0, y: 391.0 }, NONE); + assert_eq!(app.session.active().unwrap().history.past_len(), other, "nothing lands in the other document"); + assert!(app.session.set_active(0)); + near(bounds(&app, a), [100.0, 98.0, 403.0, 301.0]); + near(bounds(&app, b), [420.0, 318.0, 723.0, 451.0]); + assert_eq!(app.session.active().unwrap().history.past_len(), steps); + + // An edit under the drag (Undo here): the release applies nothing to the changed shapes. + let (mut app, ..) = app_with_two_shapes(Tool::PathSelection); + press_and_drag(&mut app); + app.run("edit.undo", json!({})).unwrap(); + let steps = app.session.active().unwrap().history.past_len(); + tool_event(&mut app, ToolEvent::Up { x: 623.0, y: 391.0 }, NONE); + assert!(app.ui.shape_box.is_none()); + assert_eq!(app.session.active().unwrap().history.past_len(), steps); +} + +/// With background jobs on, as in the desktop app, `edit.transform` lands after `run` returns. +/// The scale is still one step named "Transform Path", and the step before it (the second +/// shape's "New Shape Layer") keeps its name. Renaming the top step after `run` named the +/// shape's step "Transform Path" and left the scale as "Free Transform". +#[test] +fn with_background_jobs_the_scale_step_is_named_and_the_one_before_is_kept() { + let (mut app, a, b) = app_with_two_shapes(Tool::Rectangle); + app.background_jobs = true; + let before: Vec = app.session.active().unwrap().history.entries().to_vec(); + drag(&mut app, [723.0, 451.0], [623.0, 391.0]); + let ctx = egui::Context::default(); + for _ in 0..2000 { + crate::jobs_ui::tick(&mut app, &ctx); + if !app.session.has_jobs() { + break; + } + std::thread::sleep(std::time::Duration::from_millis(5)); + } + assert!(!app.session.has_jobs(), "the transform job never landed"); + near(bounds(&app, a), [100.0, 98.0, 354.0, 268.0]); + near(bounds(&app, b), [368.0, 282.0, 621.0, 394.0]); + let after: Vec = app.session.active().unwrap().history.entries().to_vec(); + assert_eq!(after.len(), before.len() + 1, "one history step: {after:?}"); + assert_eq!(after[..before.len()], before[..], "the earlier steps keep their names"); + assert_eq!(after.last().map(String::as_str), Some("Transform Path")); +} + +/// A switch to another tool during a handle drag ends the drag, also when the new tool shows the +/// box too; the release scales nothing and is still the box's (it doesn't reach the new tool). +#[test] +fn a_tool_switch_during_a_drag_ends_it_and_takes_its_release() { + let (mut app, a, b) = app_with_two_shapes(Tool::Rectangle); + let steps = app.session.active().unwrap().history.past_len(); + let (ba, bb) = (bounds(&app, a), bounds(&app, b)); + tool_event(&mut app, ToolEvent::Down { x: 723.0, y: 451.0, pressure: 1.0 }, NONE); + tool_event(&mut app, ToolEvent::Move { x: 623.0, y: 391.0, pressure: 1.0 }, NONE); + assert!(app.ui.shape_box.is_some()); + app.ui.tool = Tool::PathSelection; + assert!(crate::shape_bounds_box::pointer(&mut app, ToolEvent::Up { x: 623.0, y: 391.0 }, NONE), "the release is the box's"); + assert!(app.ui.shape_box.is_none()); + assert_eq!(app.session.active().unwrap().history.past_len(), steps); + assert_eq!((bounds(&app, a), bounds(&app, b)), (ba, bb)); +} diff --git a/crates/ui-egui/src/smart_objects_menu_tests.rs b/crates/ui-egui/src/smart_objects_menu_tests.rs new file mode 100644 index 0000000000..dd6d7947a6 --- /dev/null +++ b/crates/ui-egui/src/smart_objects_menu_tests.rs @@ -0,0 +1,103 @@ +//! Layer > Smart Objects menu rows, labels and order (#11401). + +use serde_json::json; + +use crate::PhotocraftApp; +use crate::menus::{MenuItem, menu_items}; + +fn app() -> PhotocraftApp { + PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()) +} + +fn submenu(app: &PhotocraftApp) -> Vec { + menu_items(app).into_iter().filter(|i| i.path == ["Layer", "Smart Objects"]).collect() +} + +fn reveal() -> &'static str { + if cfg!(target_os = "macos") { + "Reveal in Finder" + } else if cfg!(windows) { + "Reveal in Explorer" + } else { + "Show in Folder" + } +} + +#[test] +fn the_rows_follow_the_reference_order() { + let labels: Vec = submenu(&app()).into_iter().map(|i| i.label).collect(); + let expected = [ + "Convert to Smart Object", + "New Smart Object via Copy", + "---", + reveal(), + "---", + "Update Modified Content", + "Update All Modified Content", + "---", + "Edit Contents", + "Relink to File…", + "Replace Contents…", + "Export Contents…", + "---", + "Embed Linked", + "Embed All Linked", + "Convert to Linked…", + "Convert to Layers", + "---", + "---", + "Rasterize", + ]; + assert_eq!(labels, expected, "{labels:?}"); +} + +#[test] +fn embed_rows_use_the_new_labels_and_the_ids_stay() { + let items = submenu(&app()); + let by_id = |id: &str| items.iter().find(|i| i.id == id).unwrap_or_else(|| panic!("{id} missing")); + assert_eq!(by_id("layer.smartObjects.convertToEmbedded").label, "Embed Linked"); + assert_eq!(by_id("layer.smartObjects.embedAllLinked").label, "Embed All Linked"); + assert_eq!(by_id("layer.smartObjects.revealInFinder").label, reveal()); +} + +#[cfg(windows)] +#[test] +fn windows_says_reveal_in_explorer() { + assert_eq!(crate::menus::reveal_label(), "Reveal in Explorer"); +} + +#[test] +fn the_warp_rows_are_gone_from_the_submenu_but_the_commands_stay() { + let app = app(); + for id in ["layer.smartObjects.warp", "layer.smartObjects.perspectiveWarp", "layer.smartObjects.puppetWarp"] { + assert!(!submenu(&app).iter().any(|i| i.id == id), "{id}"); + assert!(photocraft_engine::cmd::command_specs().iter().any(|c| c.id == id), "{id} stays registered"); + } + let all = menu_items(&app); + for id in ["edit.puppetWarp", "edit.perspectiveWarp", "edit.transform.warp"] { + assert!(all.iter().any(|i| i.id == id), "{id} stays in the Edit menu"); + } +} + +#[test] +fn embed_all_linked_is_disabled_without_a_linked_smart_object_and_enabled_with_one() { + let mut app = app(); + app.run("file.new", json!({"width": 32, "height": 24})).unwrap(); + app.run("layer.new.layer", json!({})).unwrap(); + app.session + .edit("setup", |doc, active| { + doc.layer_mut(active.unwrap()).unwrap().surface_mut().unwrap().fill_rect(photocraft_geom::Rect::new(2, 2, 10, 10), &[1.0, 0.0, 0.0, 1.0]); + Ok(()) + }) + .unwrap(); + app.run("layer.smartObjects.convertToSmartObject", json!({})).unwrap(); + app.sync_views(); + let enabled = |app: &PhotocraftApp, id: &str| submenu(app).iter().find(|i| i.id == id).unwrap().enabled; + assert!(!enabled(&app, "layer.smartObjects.embedAllLinked")); + let path = std::env::temp_dir().join(format!("pc-so-menu-{}.pcraft", std::process::id())); + app.run("layer.smartObjects.convertToLinked", json!({"path": path.to_str().unwrap()})).unwrap(); + app.sync_views(); + assert!(enabled(&app, "layer.smartObjects.embedAllLinked")); + assert!(enabled(&app, "layer.smartObjects.convertToEmbedded")); + std::fs::remove_file(&path).ok(); +} diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index ca0259a434..be7123f04a 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -338,6 +338,9 @@ pub struct UiState { /// A live rectangle's corner radius widget being dragged (TOOL-214-12). #[serde(skip)] pub corner_radius: Option, + /// The bounding box of several selected shape layers, a handle being dragged. + #[serde(skip)] + pub shape_box: Option, /// Selected row in the Paths panel ("work" or a saved path name). #[serde(default)] pub selected_path: Option, @@ -596,6 +599,7 @@ impl Default for UiState { stroke_editor: None, direct_selection: Default::default(), corner_radius: None, + shape_box: None, selected_path: None, hidden_work_path: None, panels: Panels::default(), @@ -739,10 +743,10 @@ mod tests { assert_eq!(Tool::from_name("Vertical Type Mask Tool"), Some(Tool::VerticalTypeMask)); assert_eq!(Tool::from_name("addAnchorPoint"), Some(Tool::AddAnchorPoint)); assert_eq!(Tool::from_name("Delete Anchor Point Tool"), Some(Tool::DeleteAnchorPoint)); - assert_eq!(Tool::DeleteAnchorPoint.key(), 'P'); + assert_eq!(Tool::DeleteAnchorPoint.key(), ''); assert_eq!(Tool::from_name("convertPoint"), Some(Tool::ConvertPoint)); assert_eq!(Tool::from_name("Convert Point Tool"), Some(Tool::ConvertPoint)); - assert_eq!(Tool::ConvertPoint.key(), 'P', "it shares the Pen's key"); + assert_eq!(Tool::ConvertPoint.key(), '', "P never reaches it"); assert!(!Tool::ConvertPoint.is_brushlike()); assert_eq!(Tool::from_name("Remove Tool"), Some(Tool::Remove)); assert_eq!(Tool::Remove.key(), 'J'); diff --git a/crates/ui-egui/src/state/tool.rs b/crates/ui-egui/src/state/tool.rs index cd96f525a1..8dda7ce231 100644 --- a/crates/ui-egui/src/state/tool.rs +++ b/crates/ui-egui/src/state/tool.rs @@ -99,8 +99,8 @@ impl Tool { Tool::Count, Tool::Brush, Tool::Pencil, - Tool::MixerBrush, Tool::ColorReplacement, + Tool::MixerBrush, Tool::Eraser, Tool::BackgroundEraser, Tool::MagicEraser, @@ -113,8 +113,8 @@ impl Tool { Tool::Hand, Tool::RotateView, Tool::Zoom, - Tool::Remove, Tool::SpotHealing, + Tool::Remove, Tool::Healing, Tool::Patch, Tool::ContentAwareMove, @@ -284,7 +284,9 @@ impl Tool { Tool::SingleRowMarquee | Tool::SingleColumnMarquee => '\0', Tool::Dodge | Tool::Burn | Tool::Sponge => 'O', Tool::QuickSelection | Tool::ObjectSelection => 'W', - Tool::Pen | Tool::FreeformPen | Tool::CurvaturePen | Tool::AddAnchorPoint | Tool::DeleteAnchorPoint | Tool::ConvertPoint => 'P', + Tool::Pen | Tool::FreeformPen | Tool::CurvaturePen => 'P', + // In the Pen flyout, but P never reaches them. + Tool::AddAnchorPoint | Tool::DeleteAnchorPoint | Tool::ConvertPoint => '', Tool::PathSelection | Tool::DirectSelection => 'A', Tool::Rectangle | Tool::EllipseShape | Tool::Triangle | Tool::Polygon | Tool::Line | Tool::CustomShape => 'U', } diff --git a/crates/ui-egui/src/tool_memory.rs b/crates/ui-egui/src/tool_memory.rs index 960fb83a07..08259200fe 100644 --- a/crates/ui-egui/src/tool_memory.rs +++ b/crates/ui-egui/src/tool_memory.rs @@ -29,6 +29,15 @@ pub(crate) fn select(app: &mut PhotocraftApp, tool: Tool) { crate::frame_tool::cancel(app); } app.ui.tool = tool; + ended_by_tool(app); +} + +/// Add New Artboard's placing mode ends with the Artboard tool (#11386): every place that sets +/// `ui.tool` calls this right after, so there is one rule. +pub(crate) fn ended_by_tool(app: &mut PhotocraftApp) { + if app.ui.tool != Tool::Artboard { + app.ui.artboard_tool.adding = false; + } } /// Temporary canvas overrides do not change `ui.tool`. Spring-loaded letters and the pen's diff --git a/crates/ui-egui/src/tool_shift_cycle_order_tests.rs b/crates/ui-egui/src/tool_shift_cycle_order_tests.rs new file mode 100644 index 0000000000..83c3ca33cc --- /dev/null +++ b/crates/ui-egui/src/tool_shift_cycle_order_tests.rs @@ -0,0 +1,164 @@ +//! Shift+letter steps through a key's tool group in the toolbar flyout's order, wrapping, and the +//! anchor point tools have no letter so P never reaches them. + +use egui::{Key, Modifiers}; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::panels::toolbar::{TOOL_SECTIONS, toolbar_position}; +use crate::state::Tool; + +fn app() -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 20, "height": 10})).unwrap(); + app.run("layer.new.layer", json!({})).unwrap(); + app +} + +fn shift_press(app: &mut PhotocraftApp, key: Key) { + let modifiers = Modifiers::SHIFT; + let ctx = egui::Context::default(); + let raw = egui::RawInput { + events: vec![egui::Event::ModifiersChanged(modifiers), egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers }], + ..Default::default() + }; + ctx.begin_pass(raw); + crate::shortcuts::handle(app, &ctx); + ctx.end_pass().textures_delta.clear(); +} + +/// Every lettered tool group in toolbar order, with its letter. +fn groups() -> Vec<(char, Vec)> { + let mut keys: Vec = Tool::ALL.iter().map(|t| t.key()).filter(|k| *k != '\0').collect(); + keys.sort_unstable(); + keys.dedup(); + keys.into_iter() + .map(|k| { + let mut group: Vec = Tool::ALL.iter().copied().filter(|t| t.key() == k && toolbar_position(*t) != usize::MAX).collect(); + group.sort_by_key(|t| toolbar_position(*t)); + (k, group) + }) + .collect() +} + +fn key_for(letter: char) -> Key { + crate::spring_tools::key_of(letter).unwrap() +} + +fn sequence(letter: char, steps: usize) -> Vec { + let mut app = app(); + app.ui.tool = Tool::Hand; + (0..steps) + .map(|_| { + shift_press(&mut app, key_for(letter)); + app.ui.tool + }) + .collect() +} + +#[test] +fn from_every_tool_shift_letter_lands_on_the_next_tool_in_toolbar_order() { + for (letter, group) in groups() { + for (i, from) in group.iter().enumerate() { + let mut app = app(); + app.ui.tool = *from; + shift_press(&mut app, key_for(letter)); + let want = group[(i + 1) % group.len()]; + assert_eq!(app.ui.tool, want, "Shift+{letter} from {from:?}"); + } + } +} + +#[test] +fn shift_letter_wraps_from_the_last_tool_to_the_first() { + for (letter, group) in groups() { + let mut app = app(); + app.ui.tool = *group.last().unwrap(); + shift_press(&mut app, key_for(letter)); + assert_eq!(app.ui.tool, group[0], "Shift+{letter} wraps"); + } +} + +#[test] +fn the_first_shift_letter_from_another_tool_lands_on_the_groups_first_tool() { + for (letter, group) in groups() { + let mut app = app(); + app.ui.tool = Tool::Hand; + if group.contains(&Tool::Hand) { + continue; + } + shift_press(&mut app, key_for(letter)); + assert_eq!(app.ui.tool, group[0], "Shift+{letter} from the Hand tool"); + } +} + +#[test] +fn w_cycles_object_selection_quick_selection_magic_wand() { + assert_eq!(sequence('W', 4), vec![Tool::ObjectSelection, Tool::QuickSelection, Tool::MagicWand, Tool::ObjectSelection]); +} + +#[test] +fn t_cycles_horizontal_vertical_vertical_mask_horizontal_mask() { + assert_eq!(sequence('T', 5), vec![Tool::Type, Tool::VerticalType, Tool::VerticalTypeMask, Tool::HorizontalTypeMask, Tool::Type]); +} + +#[test] +fn p_cycles_the_three_pens_and_never_reaches_an_anchor_point_tool() { + let seen = sequence('P', 7); + assert_eq!(&seen[..4], &[Tool::Pen, Tool::FreeformPen, Tool::CurvaturePen, Tool::Pen]); + for t in seen { + assert!(!matches!(t, Tool::AddAnchorPoint | Tool::DeleteAnchorPoint | Tool::ConvertPoint), "{t:?}"); + } +} + +#[test] +fn the_anchor_point_tools_have_no_letter_but_stay_in_the_pen_flyout() { + for t in [Tool::AddAnchorPoint, Tool::DeleteAnchorPoint, Tool::ConvertPoint] { + assert_eq!(t.key(), '\0', "{t:?}"); + assert!(TOOL_SECTIONS.iter().flat_map(|s| s.iter()).any(|slot| slot.contains(&t)), "{t:?} stays in the toolbar"); + } +} + +#[test] +fn the_cycle_order_is_the_flattened_toolbar_order() { + let flat: Vec = TOOL_SECTIONS.iter().flat_map(|s| s.iter()).flat_map(|slot| slot.iter().copied()).collect(); + for (i, t) in flat.iter().enumerate() { + assert_eq!(toolbar_position(*t), i, "{t:?}"); + } +} + +#[test] +fn with_the_shift_switch_preference_off_plain_w_keeps_the_old_order() { + let mut app = app(); + app.session.edit_prefs(|p| p.tools.use_shift_key_for_tool_switch = false); + app.ui.tool = Tool::MagicWand; + let mut seen = Vec::new(); + for _ in 0..3 { + let ctx = egui::Context::default(); + let modifiers = Modifiers::NONE; + let raw = egui::RawInput { + events: vec![egui::Event::Key { key: Key::W, physical_key: None, pressed: true, repeat: false, modifiers }], + ..Default::default() + }; + ctx.begin_pass(raw); + crate::shortcuts::handle(&mut app, &ctx); + ctx.end_pass().textures_delta.clear(); + seen.push(app.ui.tool); + } + assert_eq!(seen, vec![Tool::QuickSelection, Tool::ObjectSelection, Tool::MagicWand]); +} + +#[test] +fn a_plain_w_from_outside_the_group_keeps_selecting_what_it_selected_before() { + let mut app = app(); + app.ui.tool = Tool::Move; + let ctx = egui::Context::default(); + let raw = egui::RawInput { + events: vec![egui::Event::Key { key: Key::W, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE }], + ..Default::default() + }; + ctx.begin_pass(raw); + crate::shortcuts::handle(&mut app, &ctx); + ctx.end_pass().textures_delta.clear(); + assert_eq!(app.ui.tool, Tool::MagicWand, "the first W tool in Tool::ALL, not the first in the flyout"); +} diff --git a/crates/ui-egui/src/toolbar_group_order_tests.rs b/crates/ui-egui/src/toolbar_group_order_tests.rs new file mode 100644 index 0000000000..46db63bcb3 --- /dev/null +++ b/crates/ui-egui/src/toolbar_group_order_tests.rs @@ -0,0 +1,145 @@ +//! The healing and brush slots list their tools in the reference order, the healing slot starts on +//! Spot Healing Brush, and J, B, Alt-click and Shift+letter all follow that order. + +use egui::{Key, Modifiers}; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::panels::toolbar::{TOOL_SECTIONS, next_slot_tool, toolbar}; +use crate::state::Tool; + +const HEALING: [Tool; 6] = [Tool::SpotHealing, Tool::Remove, Tool::Healing, Tool::Patch, Tool::ContentAwareMove, Tool::RedEye]; +const BRUSH: [Tool; 4] = [Tool::Brush, Tool::Pencil, Tool::ColorReplacement, Tool::MixerBrush]; + +fn app() -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 20, "height": 10})).unwrap(); + app.run("layer.new.layer", json!({})).unwrap(); + app +} + +fn press(app: &mut PhotocraftApp, key: Key, modifiers: Modifiers) { + let ctx = egui::Context::default(); + let raw = egui::RawInput { + events: vec![egui::Event::ModifiersChanged(modifiers), egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers }], + ..Default::default() + }; + ctx.begin_pass(raw); + crate::shortcuts::handle(app, &ctx); + ctx.end_pass().textures_delta.clear(); +} + +fn slot_with(tool: Tool) -> &'static [Tool] { + TOOL_SECTIONS.iter().flat_map(|s| s.iter()).find(|slot| slot.contains(&tool)).copied().unwrap() +} + +fn shift_sequence(key: Key, steps: usize) -> Vec { + let mut app = app(); + app.ui.tool = Tool::Hand; + (0..steps) + .map(|_| { + press(&mut app, key, Modifiers::SHIFT); + app.ui.tool + }) + .collect() +} + +#[test] +fn the_healing_slot_lists_spot_healing_first() { + assert_eq!(slot_with(Tool::Healing), &HEALING); +} + +#[test] +fn the_brush_slot_lists_color_replacement_before_mixer_brush() { + assert_eq!(slot_with(Tool::Brush), &BRUSH); +} + +#[test] +fn a_fresh_healing_slot_shows_spot_healing() { + assert_eq!(slot_with(Tool::Remove)[0], Tool::SpotHealing); +} + +#[test] +fn j_on_fresh_settings_selects_spot_healing() { + let mut app = app(); + app.ui.tool = Tool::Hand; + press(&mut app, Key::J, Modifiers::NONE); + assert_eq!(app.ui.tool, Tool::SpotHealing); +} + +#[test] +fn tool_all_orders_the_two_pairs_like_the_slots() { + let pos = |t: Tool| Tool::ALL.iter().position(|x| *x == t).unwrap(); + assert!(pos(Tool::SpotHealing) < pos(Tool::Remove)); + assert!(pos(Tool::ColorReplacement) < pos(Tool::MixerBrush)); +} + +#[test] +fn alt_click_steps_both_slots_in_the_new_order_and_wraps() { + for order in [&HEALING[..], &BRUSH[..]] { + for (i, from) in order.iter().enumerate() { + assert_eq!(next_slot_tool(slot_with(*from), *from), order[(i + 1) % order.len()], "from {from:?}"); + } + } +} + +#[test] +fn shift_j_follows_the_reference_sequence() { + let want: Vec = HEALING.iter().chain(&HEALING[..1]).copied().collect(); + assert_eq!(shift_sequence(Key::J, 7), want); +} + +#[test] +fn shift_b_follows_the_reference_sequence() { + let want: Vec = BRUSH.iter().chain(&BRUSH[..1]).copied().collect(); + assert_eq!(shift_sequence(Key::B, 5), want); +} + +fn frame(app: &mut PhotocraftApp, ctx: &egui::Context, time: f64, events: Vec) { + let mut out = ctx.run_ui( + egui::RawInput { + time: Some(time), + events, + screen_rect: Some(egui::Rect::from_min_size(egui::Pos2::ZERO, egui::vec2(1200.0, 1800.0))), + ..Default::default() + }, + |ui| toolbar(app, ui), + ); + out.textures_delta.clear(); +} + +/// Alt-click on the slot button, through the pointer, steps the reordered healing and brush slots. +#[test] +fn pointer_alt_click_steps_the_healing_and_brush_slots_in_the_new_order() { + let mut app = app(); + let ctx = egui::Context::default(); + PhotocraftApp::setup_context(&ctx, crate::theme::ThemeKind::ALL[0]); + frame(&mut app, &ctx, 0.0, vec![]); + frame(&mut app, &ctx, 0.1, vec![]); + let bx = if crate::theme::Tokens::get(&ctx).pro { 30.0 } else { 36.0 }; + let mut buttons: Vec = ctx.viewport(|v| { + v.prev_pass + .widgets + .layers() + .flat_map(|(_, w)| w.iter()) + .filter(|w| w.rect.size() == egui::Vec2::splat(bx) && w.sense.senses_click()) + .map(|w| w.rect) + .collect() + }); + buttons.sort_by(|a, b| a.top().total_cmp(&b.top())); + let alt = Modifiers { alt: true, ..Default::default() }; + let pointer = |pos, pressed, modifiers| egui::Event::PointerButton { pos, button: egui::PointerButton::Primary, pressed, modifiers }; + let mut t = 1.0; + for order in [&HEALING[..], &BRUSH[..]] { + let index = TOOL_SECTIONS.iter().flat_map(|s| s.iter()).position(|slot| slot.contains(&order[0])).unwrap(); + let at = buttons[index].center(); + app.ui.tool = order[0]; + for want in order.iter().cycle().skip(1).take(order.len()) { + frame(&mut app, &ctx, t, vec![egui::Event::ModifiersChanged(alt), egui::Event::PointerMoved(at), pointer(at, true, alt)]); + frame(&mut app, &ctx, t + 0.05, vec![egui::Event::ModifiersChanged(Default::default()), pointer(at, false, alt)]); + frame(&mut app, &ctx, t + 0.1, vec![]); + assert_eq!(app.ui.tool, *want, "alt-click at {t}"); + t += 0.5; + } + } +} diff --git a/crates/ui-egui/src/tools.rs b/crates/ui-egui/src/tools.rs index e53d2ecb0b..537ecd342e 100644 --- a/crates/ui-egui/src/tools.rs +++ b/crates/ui-egui/src/tools.rs @@ -34,6 +34,7 @@ pub mod perspective_crop_ui; pub mod perspective_ui; pub mod puppet_ui; pub mod retouch_ui; +pub mod shape_bounds_box; pub(super) mod shape_gradient_ui; pub(super) mod shape_options; pub(super) mod shape_paint_ui; diff --git a/crates/ui-egui/src/tools/anchor_tools/tests.rs b/crates/ui-egui/src/tools/anchor_tools/tests.rs index 02d0f45dc8..d7cd7256a4 100644 --- a/crates/ui-egui/src/tools/anchor_tools/tests.rs +++ b/crates/ui-egui/src/tools/anchor_tools/tests.rs @@ -44,13 +44,9 @@ fn click(app: &mut PhotocraftApp, at: [f64; 2], mods: Modifiers) { } #[test] -fn both_tools_join_the_pen_group() { +fn the_anchor_tools_have_no_letter() { let group: Vec = Tool::ALL.iter().copied().filter(|t| t.key() == 'P').collect(); - assert_eq!( - group, - vec![Tool::Pen, Tool::FreeformPen, Tool::CurvaturePen, Tool::AddAnchorPoint, Tool::DeleteAnchorPoint, Tool::ConvertPoint], - "P cycles Pen → Freeform → Curvature → Add → Delete → Convert Point" - ); + assert_eq!(group, vec![Tool::Pen, Tool::FreeformPen, Tool::CurvaturePen], "P cycles Pen → Freeform → Curvature and never reaches the anchor point tools"); let mut app = app(Tool::Brush); app.ui.tool = Tool::from_name("addAnchorPoint").unwrap(); assert_eq!(app.ui.tool, Tool::AddAnchorPoint); diff --git a/crates/ui-egui/src/tools/artboard_tool.rs b/crates/ui-egui/src/tools/artboard_tool.rs index 81dd67bd02..80e8d4779a 100644 --- a/crates/ui-egui/src/tools/artboard_tool.rs +++ b/crates/ui-egui/src/tools/artboard_tool.rs @@ -3,9 +3,10 @@ //! selected board's edge and corner handles to resize it (⇧ on a corner keeps its proportions). //! The "+" buttons beside the selected board's sides add a board of the same size there (⌥: a copy //! with its contents). The options bar sets the selected board's size (preset, W/H, -//! portrait/landscape) and adds a board of the same size beside the last one. Every change is one -//! engine command (`layer.new.artboard`, `layer.artboard.set`, `layer.artboard.addBeside`), so each -//! gesture is one undo step; this module only turns pointer gestures into them. +//! portrait/landscape) and switches on Add New Artboard's placing mode (a click puts a board of the +//! bar's size at the click). Every change is one engine command (`layer.new.artboard`, +//! `layer.artboard.set`, `layer.artboard.addBeside`), so each gesture is one undo step; this module +//! only turns pointer gestures into them. use egui::{CursorIcon, Pos2, Rect, Stroke, vec2}; use photocraft_doc::{Document, Layer, LayerId}; @@ -18,6 +19,8 @@ use crate::crop_ui::{Hit, hit}; use crate::state::Tool; use crate::theme::Tokens; +mod add_mode; + /// How far from an edge (screen points) a press still grabs its handle. const HANDLE_PX: f64 = 6.0; /// A press that moves less than this (screen points) is a click, not a drawn board. @@ -34,6 +37,8 @@ const SIDES: [(&str, [f64; 2]); 4] = [("top", [0.0, -1.0]), ("right", [1.0, 0.0] #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] #[serde(default)] pub struct ArtboardToolUi { + /// Add New Artboard's placing mode: a click on empty canvas puts a board there (#11386). + pub adding: bool, #[serde(skip)] pub drag: Option, } @@ -184,7 +189,11 @@ fn follow(d: &mut ArtboardDrag, p: [f64; 2], mods: egui::Modifiers) { pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers) -> bool { // ⌘ is the Move tool (`hold_keys::cmd_moves`): a press with it held is not this tool's, // so it drags a guide or the layer (#6288). A drag already under way keeps its events. - if app.ui.tool != Tool::Artboard || (app.ui.artboard_tool.drag.is_none() && crate::canvas::event_tool(app, mods) != Tool::Artboard) { + if app.ui.tool != Tool::Artboard { + add_mode::leave(app); + return false; + } + if app.ui.artboard_tool.drag.is_none() && crate::canvas::event_tool(app, mods) != Tool::Artboard { return false; } let Some(doc) = app.session.active().map(|d| d.doc.clone()) else { return true }; @@ -222,10 +231,17 @@ pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers) -> let result = match d { ArtboardDrag::New { start, cur } => { let screen = (cur[0] - start[0]).hypot(cur[1] - start[1]) * f64::from(app.point_zoom()); - if screen < CLICK_PX || r[2] <= r[0] || r[3] <= r[1] { + if screen < CLICK_PX { + // A click: with Add New Artboard's mode on, it places a board. + if let Some(placed) = add_mode::click(app, start) { + report(app, placed); + } return true; } - app.run("layer.new.artboard", json!({"rect": xywh(r)})) + if r[2] <= r[0] || r[3] <= r[1] { + return true; + } + app.run("layer.new.artboard", json!({"rect": xywh(r), "takeBackground": true})) } ArtboardDrag::Move { id, rect, .. } if r != rect => app.run("layer.artboard.set", json!({"layer": id.0, "x": r[0], "y": r[1]})), // Resizing leaves the contents where they are, as in Photoshop. @@ -292,6 +308,7 @@ pub fn draw_overlay(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform /// Landscape, and Add New Artboard. pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bool { if tool != Tool::Artboard { + add_mode::leave(app); return false; } let t = Tokens::get(ui.ctx()); @@ -328,12 +345,19 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo } crate::widgets::vline(ui, 22.0); let has_doc = app.session.active().is_some(); - if ui.add_enabled_ui(has_doc, |ui| crate::widgets::secondary_button(ui, tl!("Add New Artboard"), 0.0)).inner.clicked() { - // A board the size of the selected one, right of the rightmost board (the canvas size - // without a selected board). - let p = board.map_or(json!({}), |(_, r)| json!({"width": r[2] - r[0], "height": r[3] - r[1]})); - let r = app.run("layer.new.artboard", p); - report(app, r); + // Drawn as the primary button while the placing mode is on. + let adding = add_mode::active(app); + let button = ui + .add_enabled_ui(has_doc, |ui| { + if adding { + crate::widgets::primary_button(ui, tl!("Add New Artboard"), 0.0) + } else { + crate::widgets::secondary_button(ui, tl!("Add New Artboard"), 0.0) + } + }) + .inner; + if button.clicked() { + add_mode::toggle(app); } true } diff --git a/crates/ui-egui/src/tools/artboard_tool/add_mode.rs b/crates/ui-egui/src/tools/artboard_tool/add_mode.rs new file mode 100644 index 0000000000..c46d6d737d --- /dev/null +++ b/crates/ui-egui/src/tools/artboard_tool/add_mode.rs @@ -0,0 +1,46 @@ +//! The options bar's Add New Artboard placing mode (#11386): the button switches the mode on, and +//! while it is on a click on empty canvas puts a board of the bar's size with its top-left corner +//! at the click. The engine's `layer.new.artboard` does the work; this only turns the click into +//! its `rect`. + +use serde_json::{Value, json}; + +use super::active_board; +use crate::PhotocraftApp; +use crate::state::Tool; + +/// True while the Artboard tool is current and its placing mode is on. +pub(super) fn active(app: &PhotocraftApp) -> bool { + app.ui.tool == Tool::Artboard && app.ui.artboard_tool.adding +} + +/// The Add New Artboard button: turns the mode on, or off when it is already on. +pub(super) fn toggle(app: &mut PhotocraftApp) { + app.ui.artboard_tool.adding = !app.ui.artboard_tool.adding; +} + +/// Another tool is current: the mode ends. +pub(super) fn leave(app: &mut PhotocraftApp) { + app.ui.artboard_tool.adding = false; +} + +/// The size the options bar shows: the selected board's, else the canvas size (the engine's +/// fallback for a board with no size). +fn bar_size(app: &PhotocraftApp) -> Option<[i64; 2]> { + if let Some((_, r)) = active_board(app) { + return Some([r[2].saturating_sub(r[0]), r[3].saturating_sub(r[1])]); + } + let size = app.session.active()?.doc.size; + Some([i64::from(size.width), i64::from(size.height)]) +} + +/// A click at document point `p` on empty canvas: one `layer.new.artboard` with the bar's size and +/// its top-left corner at the click, rounded to whole pixels. None when the mode is off. +pub(super) fn click(app: &mut PhotocraftApp, p: [f64; 2]) -> Option> { + if !active(app) { + return None; + } + let [w, h] = bar_size(app)?; + let rect = [p[0].round() as i64, p[1].round() as i64, w, h]; + Some(app.run("layer.new.artboard", json!({"rect": rect}))) +} diff --git a/crates/ui-egui/src/tools/move_mods.rs b/crates/ui-egui/src/tools/move_mods.rs index 4c96702694..9c91eff38c 100644 --- a/crates/ui-egui/src/tools/move_mods.rs +++ b/crates/ui-egui/src/tools/move_mods.rs @@ -1,12 +1,14 @@ //! Move-tool modifier keys, as in Photoshop (#90): //! -//! - ⇧ while dragging locks the move to the dominant axis (horizontal or vertical). The axis is -//! re-evaluated as the drag goes on, so moving far enough the other way switches it; a small -//! hysteresis keeps it from flickering near the diagonal. Free Transform uses the same rule with -//! eight directions ([`constrain`]). +//! - ⇧ while dragging locks the move to the nearest of the eight directions (the axes and the 45° +//! diagonals), as the reference application does when a layer is dragged (#11382): +100,+30 +//! moves +100,0 and +80,+80 moves +80,+80. The direction is re-evaluated as the drag goes on, +//! so moving far enough another way switches it; a small hysteresis keeps it from flickering +//! near the switch-over angle. Free Transform uses the same rule ([`constrain`]). //! - ⌥ held when the drag starts duplicates the selected layer(s) (groups included) once the //! pointer actually moves, and the drag then moves the copies. Duplicate and move land as one -//! history step ("Duplicate + Move"). ⇧⌥ combines both. +//! history step ("Move", as in Photoshop; an ⌥-arrow nudge keeps "Duplicate + Move"). ⇧⌥ +//! combines both. //! - Arrow keys nudge the selected layers 1 px (⇧: 10 px); ⌥ duplicates first. While Free //! Transform is active they nudge the box instead. A run of nudges is one History state //! (`nudge_bundle`, #2259). @@ -23,8 +25,10 @@ use crate::PhotocraftApp; use crate::canvas::ToolEvent; use crate::state::Tool; -/// Directions ⇧ locks a Move-tool drag to: horizontal and vertical (Photoshop's Move tool). -pub const MOVE_DIRECTIONS: u32 = 4; +/// Directions ⇧ locks a Move-tool drag of a layer to: the axes and the 45° diagonals. The +/// reference application moves +80,+80 for a ⇧-drag of +80,+80, so an axis-only lock (four +/// directions) does not match it (#11382). +pub const MOVE_DIRECTIONS: u32 = 8; /// Directions ⇧ locks a Free Transform body drag, or a Move-tool drag of selected pixels, to: the /// axes and the 45° diagonals. pub const TRANSFORM_DIRECTIONS: u32 = 8; @@ -34,7 +38,7 @@ const HYSTERESIS_DEG: f64 = 8.0; /// ⌥-drag duplicates only once the pointer has moved this far (screen points), so an ⌥-click /// without a drag doesn't make a copy (Photoshop). const DUPLICATE_THRESHOLD: f64 = 2.0; -/// History label of an ⌥-drag / ⌥-nudge. +/// History label of an ⌥-nudge. An ⌥-drag of a layer is a plain "Move", as in Photoshop (#11383). pub const DUPLICATE_MOVE_LABEL: &str = "Duplicate + Move"; /// Locks the drag offset `d` to the nearest of `n` evenly spaced directions (0° = right). `prev` @@ -105,8 +109,8 @@ fn duplicate(app: &mut PhotocraftApp) -> Option { } } -/// Merges every history step after `from` into one "Duplicate + Move" step. -fn fold_history(app: &mut PhotocraftApp, from: usize) { +/// Merges every history step after `from` into one step called `label`. +fn fold_history(app: &mut PhotocraftApp, from: usize, label: &str) { let Some(st) = app.session.active_mut() else { return }; while st.history.past_len() > from + 1 { if !st.history.purge_last() { @@ -114,7 +118,7 @@ fn fold_history(app: &mut PhotocraftApp, from: usize) { } } if st.history.past_len() == from + 1 { - st.history.set_current_label(DUPLICATE_MOVE_LABEL); + st.history.set_current_label(label); } } @@ -185,7 +189,7 @@ pub(crate) fn duplicated(app: &PhotocraftApp) -> bool { pub fn finish(app: &mut PhotocraftApp) { let st = std::mem::take(&mut app.move_mods); if let Some(from) = st.dup_from { - fold_history(app, from); + fold_history(app, from, tl!("Move")); } } @@ -269,6 +273,7 @@ pub fn nudge(app: &mut PhotocraftApp, dx: f64, dy: f64, duplicate_first: bool) { return; } let from = if duplicate_first { duplicate(app) } else { None }; + let revision = app.session.active().map(|st| st.revision); let moved = if duplicate_first { // A copy is a state of its own, folded with its move below. app.nudge_bundle.reset(); @@ -276,11 +281,20 @@ pub fn nudge(app: &mut PhotocraftApp, dx: f64, dy: f64, duplicate_first: bool) { } else { crate::nudge_bundle::run(app, "layers", "layer.translate", json!({"dx": dx, "dy": dy})) }; - if let Err(e) = moved { - app.ui.status = e; + match moved { + // The reference names an arrow-key move "Nudge"; a bundled run is one step with that name. + // Only a move that changed the document: a zero offset records nothing, and the state + // on top is then another edit's. + Ok(_) if from.is_none() => { + if let Some(st) = app.session.active_mut().filter(|st| Some(st.revision) != revision) { + st.history.set_current_label(tl!("Nudge")); + } + } + Ok(_) => {} + Err(e) => app.ui.status = e, } if let Some(from) = from { - fold_history(app, from); + fold_history(app, from, DUPLICATE_MOVE_LABEL); } } diff --git a/crates/ui-egui/src/tools/move_mods/tests.rs b/crates/ui-egui/src/tools/move_mods/tests.rs index e42e24875e..1e4c45b784 100644 --- a/crates/ui-egui/src/tools/move_mods/tests.rs +++ b/crates/ui-egui/src/tools/move_mods/tests.rs @@ -90,7 +90,7 @@ fn alt_drag_duplicates_and_moves_the_copy_in_one_step() { assert_eq!(bounds(&app, copy), photocraft_geom::Rect::new(18, 13, 34, 29)); let st = app.session.active().unwrap(); assert_eq!(st.history.past_len(), h0 + 1, "one undo step"); - assert_eq!(st.history.undo_label(), Some(DUPLICATE_MOVE_LABEL)); + assert_eq!(st.history.undo_label(), Some("Move")); assert!(app.session.undo()); assert_eq!(app.session.active().unwrap().doc.layers.len(), n0); assert_eq!(bounds(&app, orig), photocraft_geom::Rect::new(8, 8, 24, 24)); @@ -115,7 +115,7 @@ fn alt_drag_keeps_the_later_states_in_non_linear_history() { assert!(app.session.undo()); let mut expected = app.session.active().unwrap().history.entries(); expected.extend(app.session.active().unwrap().history.redo_labels().map(str::to_string)); - expected.push(DUPLICATE_MOVE_LABEL.into()); + expected.push("Move".into()); drag(&mut app, &[[16.0, 16.0], [20.0, 16.0], [26.0, 21.0]], egui::Modifiers::ALT); assert_eq!(app.session.active().unwrap().history.entries(), expected, "the later state stays"); } @@ -328,7 +328,7 @@ fn a_run_of_arrow_nudges_is_one_history_step() { assert!(press_at(&mut app, egui::Key::ArrowDown, egui::Modifiers::SHIFT, 7.6)); assert_eq!(bounds(&app, id), photocraft_geom::Rect::new(20, 18, 36, 34)); assert_eq!(history(&app), h0 + 1, "thirteen presses, one state"); - assert_eq!(app.session.active().unwrap().history.undo_label(), Some("Move")); + assert_eq!(app.session.active().unwrap().history.undo_label(), Some("Nudge")); assert!(app.session.undo()); assert_eq!(bounds(&app, id), photocraft_geom::Rect::new(8, 8, 24, 24), "one Undo takes back the run"); assert!(app.session.redo()); @@ -434,7 +434,7 @@ fn alt_nudges_do_not_join_a_run() { press(&mut app, egui::Key::ArrowRight, egui::Modifiers::ALT); press(&mut app, egui::Key::ArrowRight, egui::Modifiers::NONE); assert_eq!(history(&app), h0 + 3); - assert_eq!(app.session.active().unwrap().history.undo_label(), Some("Move"), "the run after the copy is a state of its own"); + assert_eq!(app.session.active().unwrap().history.undo_label(), Some("Nudge"), "the run after the copy is a state of its own"); } /// #2259: nudges of the selection outline bundle the same way. diff --git a/crates/ui-egui/src/tools/retouch_ui/tests.rs b/crates/ui-egui/src/tools/retouch_ui/tests.rs index f2293d6bc7..4a084bc80a 100644 --- a/crates/ui-egui/src/tools/retouch_ui/tests.rs +++ b/crates/ui-egui/src/tools/retouch_ui/tests.rs @@ -762,16 +762,16 @@ fn create_a_new_layer_sends_new_layer_to_the_command() { #[test] fn red_eye_is_in_the_j_flyout() { - let j = [Tool::Remove, Tool::SpotHealing, Tool::Healing, Tool::Patch, Tool::ContentAwareMove, Tool::RedEye]; + let j = [Tool::SpotHealing, Tool::Remove, Tool::Healing, Tool::Patch, Tool::ContentAwareMove, Tool::RedEye]; assert!(j.contains(&Tool::RedEye)); assert!(j.iter().all(|t| t.key() == 'J')); } #[test] -fn j_cycles_from_remove() { +fn j_cycles_from_spot_healing() { // J from another group picks the first J tool, and repeated J goes on in this order. let group: Vec = Tool::ALL.iter().copied().filter(|t| t.key() == 'J').collect(); - assert_eq!(group, [Tool::Remove, Tool::SpotHealing, Tool::Healing, Tool::Patch, Tool::ContentAwareMove, Tool::RedEye]); + assert_eq!(group, [Tool::SpotHealing, Tool::Remove, Tool::Healing, Tool::Patch, Tool::ContentAwareMove, Tool::RedEye]); } #[test] diff --git a/crates/ui-egui/src/tools/shape_bounds_box.rs b/crates/ui-egui/src/tools/shape_bounds_box.rs new file mode 100644 index 0000000000..4814e11e2d --- /dev/null +++ b/crates/ui-egui/src/tools/shape_bounds_box.rs @@ -0,0 +1,264 @@ +//! A bounding box with eight handles over the selected shape layers, as in Photoshop: with +//! Path Selection or a shape tool (Rectangle, Ellipse, Triangle, Polygon, Line) active and one or +//! more shape layers selected, the union of their path bounds shows as a box. Dragging a handle +//! previews the scaled outlines and, on release, scales every selected shape about the opposite +//! handle with one `edit.transform` (which keeps live shapes live), as one History step named +//! "Transform Path". No Free Transform session opens, and there is no rotate zone. A corner +//! scales both ways, the pointer projected onto the box diagonal as Free Transform's corner does +//! (#11096); an edge middle scales one way. The corner radius widgets (`corner_radius`) keep +//! priority on a press. + +use egui::{Color32, CursorIcon, Modifiers, Pos2, Stroke, vec2}; +use photocraft_doc::LayerContent; +use photocraft_geom::Affine; +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas::{ToolEvent, ViewXform}; +use crate::state::Tool; +use crate::tool_cursor; + +/// The scale a drag can reach, as `path.transform`'s. +const MIN_SCALE: f64 = 0.01; +const MAX_SCALE: f64 = 100.0; +/// A handle is grabbed within this many screen points. +const GRAB_PX: f64 = 7.0; + +/// A handle drag in progress. +#[derive(Clone, Debug, PartialEq)] +pub struct Drag { + /// The document and its revision at the press: a drag outlives neither a switch to another + /// document nor an edit under it (Undo, say). + doc: photocraft_doc::DocId, + revision: u64, + /// The tool it started with: a switch to another tool ends it, even one that shows the box. + tool: Tool, + /// The selected shape layers, as at the press. + layers: Vec, + /// Their union box `[x0, y0, x1, y1]` at the press. + rect: [f64; 4], + /// The grabbed handle: `-1` left or top, `1` right or bottom, `0` the middle. + handle: [i8; 2], + /// Where the press was. + start: [f64; 2], + /// The scale so far, per axis. + scale: [f64; 2], +} + +/// The tools that show the box, while View › Extras and View › Show › Target Path show paths +/// (the overlay draws it only then, so a hidden handle must not take a press either). +fn shows(app: &PhotocraftApp) -> bool { + app.ui.transform.is_none() + && app.ui.view.shows(app.ui.view.show.target_path) + && matches!(app.ui.tool, Tool::PathSelection | Tool::Rectangle | Tool::EllipseShape | Tool::Triangle | Tool::Polygon | Tool::Line) +} + +/// The selected shape layers and the box round their paths. `None` unless at least one layer is +/// selected and all are shape layers. +fn selection(app: &PhotocraftApp) -> Option<(Vec, [f64; 4])> { + let st = app.session.active()?; + let ids = st.selected_layers(); + if ids.is_empty() { + return None; + } + let mut layers = Vec::with_capacity(ids.len()); + let mut rect: Option<[f64; 4]> = None; + for id in ids { + let l = st.doc.layer(id)?; + let LayerContent::Shape(sh) = &l.content else { return None }; + let (x0, y0, x1, y1) = sh.path.control_bounds()?; + rect = Some(rect.map_or([x0, y0, x1, y1], |r| [r[0].min(x0), r[1].min(y0), r[2].max(x1), r[3].max(y1)])); + layers.push(l.id.0); + } + let r = rect.filter(|r| r.iter().all(|v| v.is_finite()) && r[2] > r[0] && r[3] > r[1])?; + Some((layers, r)) +} + +/// The eight handles of `r`: their `[hx, hy]` and where they sit. +fn handles(r: [f64; 4]) -> [([i8; 2], [f64; 2]); 8] { + let [x0, y0, x1, y1] = r; + let (cx, cy) = ((x0 + x1) / 2.0, (y0 + y1) / 2.0); + [ + ([-1, -1], [x0, y0]), + ([0, -1], [cx, y0]), + ([1, -1], [x1, y0]), + ([1, 0], [x1, cy]), + ([1, 1], [x1, y1]), + ([0, 1], [cx, y1]), + ([-1, 1], [x0, y1]), + ([-1, 0], [x0, cy]), + ] +} + +/// The point a handle's drag scales about: the opposite handle (the box's centre on a middle axis). +fn fixed_point(r: [f64; 4], handle: [i8; 2]) -> [f64; 2] { + let pick = |h: i8, lo: f64, hi: f64| match h { + 1 => lo, + -1 => hi, + _ => (lo + hi) / 2.0, + }; + [pick(handle[0], r[0], r[2]), pick(handle[1], r[1], r[3])] +} + +/// The scale a drag of `handle` by `d` document px gives the box `r`, per axis. A corner scales +/// both ways by the same factor, the drag projected onto the box diagonal; an edge middle scales +/// one way. +pub(crate) fn scale_for(r: [f64; 4], handle: [i8; 2], d: [f64; 2]) -> [f64; 2] { + let (w, h) = (r[2] - r[0], r[3] - r[1]); + let clamp = |s: f64| if s.is_finite() { s.clamp(MIN_SCALE, MAX_SCALE) } else { 1.0 }; + match handle { + [0, 0] => [1.0, 1.0], + [hx, 0] => [clamp(1.0 + d[0] * f64::from(hx) / w), 1.0], + [0, hy] => [1.0, clamp(1.0 + d[1] * f64::from(hy) / h)], + [hx, hy] => { + let diag = [f64::from(hx) * w, f64::from(hy) * h]; + let s = clamp(1.0 + (d[0] * diag[0] + d[1] * diag[1]) / (diag[0] * diag[0] + diag[1] * diag[1])); + [s, s] + } + } +} + +/// `r` after scaling by `s` about `fixed`. +fn scaled_rect(r: [f64; 4], fixed: [f64; 2], s: [f64; 2]) -> [f64; 4] { + let at = |v: f64, f: f64, s: f64| f + (v - f) * s; + let (a, b) = (at(r[0], fixed[0], s[0]), at(r[2], fixed[0], s[0])); + let (c, d) = (at(r[1], fixed[1], s[1]), at(r[3], fixed[1], s[1])); + [a.min(b), c.min(d), a.max(b), c.max(d)] +} + +fn zoom(app: &PhotocraftApp) -> f64 { + f64::from(app.point_zoom().max(0.01)) +} + +/// The handle within grabbing distance of document point `p`, the nearest. +fn hit(app: &PhotocraftApp, p: [f64; 2]) -> Option<[i8; 2]> { + if !shows(app) { + return None; + } + let (_, r) = selection(app)?; + let tol = GRAB_PX / zoom(app); + handles(r).into_iter().map(|(h, at)| (h, (at[0] - p[0]).hypot(at[1] - p[1]))).filter(|(_, d)| *d <= tol).min_by(|a, b| a.1.total_cmp(&b.1)).map(|(h, _)| h) +} + +/// The scale cursor over a handle at document point `p`, or while one is dragged, turned with the +/// view (its rotation, flip and pixel aspect) as Free Transform's. +pub fn cursor(app: &PhotocraftApp, xf: &ViewXform, p: [f64; 2]) -> Option { + let (handle, r) = match app.ui.shape_box.as_ref() { + Some(d) => (d.handle, d.rect), + None => (hit(app, p)?, selection(app)?.1), + }; + let [x0, y0, x1, y1] = r; + let quad = [[x0, y0], [x1, y0], [x1, y1], [x0, y1]]; + Some(match handle { + [-1, -1] => tool_cursor::corner_resize(&quad, 0, xf), + [1, -1] => tool_cursor::corner_resize(&quad, 1, xf), + [1, 1] => tool_cursor::corner_resize(&quad, 2, xf), + [-1, 1] => tool_cursor::corner_resize(&quad, 3, xf), + [_, 0] => tool_cursor::resize([1.0, 0.0], xf), + _ => tool_cursor::resize([0.0, 1.0], xf), + }) +} + +/// Drop a handle drag without applying it (Esc, or its document or tool gone); the rest of the +/// press, its moves and release, does nothing. +pub fn cancel(app: &mut PhotocraftApp) { + if app.ui.shape_box.take().is_some() { + app.cancelled_vector_drag = true; + } +} + +/// Cancel a handle drag whose tool, document or document revision is no longer the one it +/// started on, or whose box is hidden now. Run every frame from `sync_views`. +pub fn cancel_stale(app: &mut PhotocraftApp) { + let Some(d) = app.ui.shape_box.as_ref() else { return }; + let current = app.session.active().is_some_and(|st| st.doc.id == d.doc && st.revision == d.revision); + if !current || app.ui.tool != d.tool || !shows(app) { + cancel(app); + } +} + +/// Canvas pointer events for the box; false when the event is not its. +pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: Modifiers) -> bool { + match ev { + ToolEvent::Down { x, y, .. } => { + if mods.command { + return false; + } + let Some(handle) = hit(app, [x, y]) else { return false }; + let Some((layers, rect)) = selection(app) else { return false }; + let Some((doc, revision)) = app.session.active().map(|st| (st.doc.id, st.revision)) else { return false }; + app.ui.shape_box = Some(Drag { doc, revision, tool: app.ui.tool, layers, rect, handle, start: [x, y], scale: [1.0, 1.0] }); + // The press may have started the Move tool's snapping, which a box drag has none of. + app.prefs_rt.snap = None; + app.prefs_rt.snap_lines.clear(); + app.move_mods = Default::default(); + true + } + ToolEvent::Move { x, y, .. } => { + let Some(d) = app.ui.shape_box.as_mut() else { return false }; + d.scale = scale_for(d.rect, d.handle, [x - d.start[0], y - d.start[1]]); + true + } + ToolEvent::Up { x, y } => { + let had = app.ui.shape_box.is_some(); + cancel_stale(app); + if app.ui.shape_box.is_none() { + // The release of a drag that was just dropped is still the box's: it must not + // reach the tool that is active now. + return had; + } + pointer(app, ToolEvent::Move { x, y, pressure: 1.0 }, mods); + let Some(d) = app.ui.shape_box.take() else { return true }; + // A click without movement changes nothing. + if d.scale == [1.0, 1.0] { + return true; + } + let fixed = fixed_point(d.rect, d.handle); + let params = json!({ + "layers": d.layers, + "rect": d.rect, + "scaleX": d.scale[0] * 100.0, + "scaleY": d.scale[1] * 100.0, + "reference": fixed, + // Named by the command: with background jobs on, the step lands after `run` + // returns, so a rename here would rename the step before it. + "stepName": photocraft_engine::transform_cmds::TRANSFORM_PATH, + }); + if let Err(e) = app.run("edit.transform", params) { + app.ui.status = e; + app.ui.status_error = true; + } + true + } + } +} + +/// The box and its handles, and while a handle is dragged the scaled outlines. +pub fn draw(app: &PhotocraftApp, painter: &egui::Painter, to_scr: &dyn Fn([f64; 2]) -> Pos2, accent: Color32) { + if !shows(app) { + return; + } + let Some((_, rect)) = selection(app) else { return }; + let mut shown = rect; + if let Some(d) = app.ui.shape_box.as_ref() { + let fixed = fixed_point(d.rect, d.handle); + shown = scaled_rect(d.rect, fixed, d.scale); + let map = Affine { m: [d.scale[0], 0.0, 0.0, d.scale[1], fixed[0] * (1.0 - d.scale[0]), fixed[1] * (1.0 - d.scale[1])] }; + if let Some(st) = app.session.active() { + for id in &d.layers { + if let Some(LayerContent::Shape(sh)) = st.doc.layer(photocraft_doc::LayerId(*id)).map(|l| &l.content) { + crate::vector_ui::draw_outline(painter, &sh.path.transform(&map), to_scr, accent); + } + } + } + } + // Through all four corners: under a rotated view two opposite ones don't span the box. + let [x0, y0, x1, y1] = shown; + let corners = [[x0, y0], [x1, y0], [x1, y1], [x0, y1]].map(to_scr); + painter.add(egui::Shape::closed_line(corners.to_vec(), Stroke::new(1.0, accent))); + for (_, at) in handles(shown) { + let h = egui::Rect::from_center_size(to_scr(at), vec2(7.0, 7.0)); + painter.rect_filled(h, 0.0, Color32::WHITE); + painter.rect_stroke(h, 0.0, Stroke::new(1.0, accent), egui::StrokeKind::Inside); + } +} diff --git a/crates/ui-egui/src/tools/vector_ui/overlay.rs b/crates/ui-egui/src/tools/vector_ui/overlay.rs index 6bc967e34e..1e50b63b47 100644 --- a/crates/ui-egui/src/tools/vector_ui/overlay.rs +++ b/crates/ui-egui/src/tools/vector_ui/overlay.rs @@ -194,6 +194,10 @@ pub fn draw_overlay(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform draw_anchor(painter, to_scr([k.anchor.x, k.anchor.y]), true, accent); } } + // Only over the active document, whose selected layers the box frames. + if st.is_some_and(|s| s.doc.id == doc.id) { + crate::shape_bounds_box::draw(app, painter, &to_scr, accent); + } crate::corner_radius::draw(app, painter, &to_scr, accent); } // Pen path in progress, with handles of the last knot and a rubber band to the pointer. While diff --git a/crates/ui-egui/src/view_guides_submenu_tests.rs b/crates/ui-egui/src/view_guides_submenu_tests.rs new file mode 100644 index 0000000000..ef9834cecf --- /dev/null +++ b/crates/ui-egui/src/view_guides_submenu_tests.rs @@ -0,0 +1,113 @@ +//! #11400: View › Guides holds the nine guide commands in the reference's order, and its two +//! Selected Guides rows act on the selected guide. + +use serde_json::json; + +use crate::PhotocraftApp; +use crate::canvas_tool_menu::{GUIDE_CLEAR, GUIDE_EDIT, GUIDE_MENU}; + +const ORDER: [(&str, &str); 9] = [ + ("Edit Selected Guides", "view.editSelectedGuides"), + ("Lock Guides", "view.lockGuides"), + ("Clear Guides", "view.clearGuides"), + ("Clear Selected Guides", "view.clearSelectedGuides"), + ("Clear Selected Artboard Guides", "view.clearSelectedArtboardGuides"), + ("Clear Canvas Guides", "view.clearCanvasGuides"), + ("New Guide…", "view.newGuide"), + ("New Guide Layout…", "view.newGuideLayout"), + ("New Guides From Shape", "view.newGuidesFromShape"), +]; + +fn app() -> PhotocraftApp { + let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default()); + app.run("file.new", json!({"width": 200, "height": 100})).unwrap(); + app.run("view.newGuide", json!({"orientation": "vertical", "position": 10})).unwrap(); + app.run("view.newGuide", json!({"orientation": "vertical", "position": 20})).unwrap(); + app +} + +fn item(app: &PhotocraftApp, id: &str) -> crate::menus::MenuItem { + crate::menus::menu_items(app).into_iter().find(|i| i.id == id).unwrap_or_else(|| panic!("{id} is not in the menu")) +} + +fn vertical(app: &PhotocraftApp) -> Vec { + app.session.active().unwrap().doc.guides.vertical.clone() +} + +#[test] +fn guides_submenu_lists_the_nine_rows_in_order() { + let app = app(); + let path = vec!["View".to_string(), "Guides".to_string()]; + let rows: Vec<(String, String)> = crate::menus::menu_items(&app).into_iter().filter(|i| i.path == path).map(|i| (i.label, i.id)).collect(); + let want: Vec<(String, String)> = ORDER.iter().map(|(l, i)| (l.to_string(), i.to_string())).collect(); + assert_eq!(rows, want); + assert_eq!(item(&app, "view.lockGuides").shortcut.as_deref(), Some("Cmd+Alt+;")); +} + +#[test] +fn no_guide_row_is_left_flat_in_view() { + let app = app(); + let items = crate::menus::menu_items(&app); + let guides = vec!["View".to_string(), "Guides".to_string()]; + for (_, id) in ORDER { + let rows: Vec<_> = items.iter().filter(|i| i.id == id).collect(); + assert_eq!(rows.len(), 1, "{id} appears exactly once"); + assert_eq!(rows[0].path, guides, "{id} is in View > Guides, not flat in View"); + } +} + +#[test] +fn the_menu_cache_follows_the_selected_guide() { + let mut app = app(); + let none = crate::native_menu::state_hash(&app, None); + crate::guide_select::select(&mut app, true, 0); + let one = crate::native_menu::state_hash(&app, None); + assert_ne!(none, one, "selecting a guide changes the menu state"); + assert!(item(&app, "view.clearSelectedGuides").enabled); + crate::guide_select::clear(&mut app); + assert_eq!(crate::native_menu::state_hash(&app, None), none); + assert!(!item(&app, "view.clearSelectedGuides").enabled); +} + +#[test] +fn selected_rows_are_greyed_without_a_selected_guide_and_enabled_with_one() { + let mut app = app(); + for id in ["view.editSelectedGuides", "view.clearSelectedGuides"] { + assert!(!item(&app, id).enabled, "{id} with no guide selected"); + assert!(crate::menus::invoke(&mut app, &egui::Context::default(), id, json!({})).is_err(), "{id} errors, not a crash"); + } + crate::guide_select::select(&mut app, true, 0); + for id in ["view.editSelectedGuides", "view.clearSelectedGuides"] { + assert!(item(&app, id).enabled, "{id} with a guide selected"); + } +} + +#[test] +fn clear_selected_guides_removes_only_the_selected_guide() { + let mut app = app(); + crate::guide_select::select(&mut app, true, 1); + let ctx = egui::Context::default(); + crate::menus::invoke(&mut app, &ctx, "view.clearSelectedGuides", json!({})).unwrap(); + assert_eq!(vertical(&app), vec![10.0]); +} + +#[test] +fn edit_selected_guides_opens_the_right_click_menus_dialog() { + let mut app = app(); + crate::guide_select::select(&mut app, true, 0); + let ctx = egui::Context::default(); + crate::menus::invoke(&mut app, &ctx, "view.editSelectedGuides", json!({})).unwrap(); + assert_eq!(app.ui.dialogs.len(), 1); + let from_menu = app.ui.dialogs[0].fields.clone(); + let id = app.ui.dialogs[0].id; + crate::dialogs::cancel(&mut app, id).unwrap(); + let id = crate::new_guide_ui::open_edit(&mut app).unwrap(); + assert_eq!(app.ui.dialog_mut(id).unwrap().fields, from_menu); +} + +#[test] +fn right_click_guide_menu_keeps_both_selected_rows() { + let ids: Vec<&str> = GUIDE_MENU.iter().flatten().map(|(_, id)| *id).collect(); + assert!(ids.contains(&GUIDE_EDIT) && ids.contains(&GUIDE_CLEAR)); + assert_eq!((GUIDE_EDIT, GUIDE_CLEAR), ("view.editSelectedGuides", "view.clearSelectedGuides")); +} diff --git a/docs/atn.md b/docs/atn.md index 0e72430eeb..3dfe9a658b 100644 --- a/docs/atn.md +++ b/docs/atn.md @@ -90,6 +90,7 @@ row; the action still adds only one Undo entry. | `Btch` | batch | Batch (supported folder and naming forms) | `file.automate.batch` | | (string ID only) | shapeBlur | Shape Blur (custom shape by installed ID) | `filter.blur.shapeBlur` | | (string ID only) | cafWorkspace | Content-Aware Fill | `edit.contentAwareFill` | +| (string ID only) | perspectiveWarpTransform | Perspective Warp (indexed layout and warp planes) | `edit.perspectiveWarp` | | `Cntc` | contract | Contract | `select.modify.contract` | | `CnvM` | convertMode | Convert Mode | `image.mode.rgb`, `image.mode.grayscale`, `image.mode.cmyk`, `image.mode.lab`, `image.mode.multichannel`, `image.mode.bits8`, `image.mode.bits16`, `image.mode.bits32`, `image.mode.bitmap` | | (string ID only) | convertToProfile | Convert to Profile | `edit.convertToProfile` | @@ -213,6 +214,8 @@ row; the action still adds only one Undo entry. | (string ID only) | ungroupLayersEvent | Ungroup Layers | `layer.ungroupLayers` | | `UnsM` | unsharpMask | Unsharp Mask | `filter.sharpen.unsharpMask` | | (string ID only) | updatePlacedLayer | Update Smart Objects | `layer.smartObjects.updateModifiedContent` | +| (string ID only) | applyImageStackPluginRenderer | Smart Object Stack Mode | `layer.smartObjects.stackMode.*` (eleven measured modes) | +| (string ID only) | imageStackConvertSmartObject | Stack Mode: None | `layer.smartObjects.stackMode.none` | | (string ID only) | vibrance | Vibrance | `image.adjustments.vibrance` | | `Wave` | wave | Wave | `filter.distort.wave` | | `ZgZg` | zigZag | ZigZag | `filter.distort.zigZag` | @@ -227,6 +230,9 @@ row; the action still adds only one Undo entry. | (string ID only) | placedLayerUpdateAllModified | Update All Modified Content | `layer.smartObjects.updateAllModifiedContent` | | (string ID only) | rasterizeAll | Rasterize All Layers | `layer.rasterize.allLayers` | | (string ID only) | addBlankVideoLayer | New Blank Video Layer | `layer.videoLayers.newBlankVideoLayer` | +| (string ID only) | insertBlankFrame | Insert Blank Frame | `layer.videoLayers.insertBlankFrame` | +| (string ID only) | duplicateFrame | Duplicate Frame | `layer.videoLayers.duplicateFrame` | +| (string ID only) | deleteFrame | Delete Frame | `layer.videoLayers.deleteFrame` | | (string ID only) | isolateLayers | Isolate Layers | `select.isolateLayers` | | (string ID only) | textLoadDefaultTypeStyles | Load Default Type Styles | `type.loadDefaultTypeStyles` | | (string ID only) | textSaveDefaultTypeStyles | Save Default Type Styles | `type.saveDefaultTypeStyles` | @@ -278,6 +284,19 @@ identity, and is omitted on save under the normalization rule below. Undecodable paths or extra keys keep the entire step. File access happens at playback; a missing or unusable file reports the native command's error. +Stack Mode uses the active Smart Object. For `applyImageStackPluginRenderer`, +the measured `imageStackPlugin` class selects the mode; the localized `Nm ` +label is preserved on save. Stack Mode: None uses +`imageStackConvertSmartObject` with no settings. Save preserves whether an +imported None step had an empty descriptor or no descriptor. Unknown classes, +extra settings and unrecognized descriptor forms stay as kept steps. Native +steps with explicit layer targets cannot be exported to these forms. + +Insert Blank Frame, Duplicate Frame and Delete Frame use the active video layer +and current playhead. They take no settings. Extra keys or unrecognized +descriptor metadata stay as kept steps. Save retains whether the recorded item +had an empty descriptor or no descriptor. + Convert Type to Shape retains Make's `contentLayer` class reference and `Usng` target `textLayer` reference; it does not export a separate `convertToShape` event. Other Make mappings, including Solid Color and Pattern fills, are unchanged. @@ -295,6 +314,24 @@ The separate `CropPhotos0001` helper remains a complete kept Photoshop step. Playback stops at that enabled helper before subsequent duplicate/crop steps can run. This covers the parent event, not complete recordings with generated helpers. +### Perspective Warp recordings + +`perspectiveWarpTransform` maps Layout and Warp to one `edit.perspectiveWarp` +step. It warps a raster layer in place or adds a Perspective Warp Smart Filter to +a Smart Object. The active layer, a named layer or the Background can be the +recorded target. + +The recorded fields are `null` (layer target), `Md ` (`perspectiveWarpMode`: +`warp`), `referenceRect` (pixel rectangle), `vertices`, `warpedVertices` (document +pixel points), and `quads` (four indices per plane). Unchanged steps save the +original descriptor, including its reference rectangle, vertex order and shared +indices. Playback uses the recorded document-pixel coordinates. A native export +requires an explicit reference rectangle and representable planes. + +Unsupported targets, modes, units, degenerate quads and meshes with different +corner sharing stay kept steps. Export refuses a changed recorded mesh if the +stored descriptor no longer describes it. + ### Content-Aware Fill recordings `cafWorkspace` maps Rectangular / Default color adaptation / None rotation with New Layer or @@ -944,7 +981,6 @@ the recorded steps back from the saved Actions panel. Ranges come from the dialo | New Group with a colour | `Usng` (`Clr ` label), `layerSectionStart`, `layerSectionEnd`, top-level `Nm ` | | | Shear (`Shr `) | `ShrP` list of `Pnt ` (`Hrzn`, `Vrtc` doubles), `UndA` (`WrpA` wrap around, `RptE` repeat edge pixels), `ShrS` long, `ShrE` long | The dialog writes whole numbers: `Hrzn` -64..63 (dragging past the grid clamps), `Vrtc` 1..128 with the first point at 1 and the last at 128; dragging a point out of the grid deletes it. `ShrS` is 0 and `ShrE` the last point's index (count - 1). Script runs take any value unclamped and crashed on far-off `ShrE`/`ShrS` or a first `Vrtc` below 1. | | Gradient tool, default mode | two steps: Make (`null` = class `contentLayer`, `Usng` = `Type` gradient layer object) then Set (`null` = `contentLayer` target, `T ` = the same object plus `Algn` false) | The object: `Dthr`, `gradientsInterpolationMethod`, `Angl` angle, `Type`, `Scl ` percent, `Ofst` (`Hrzn`, `Vrtc` percent), `Grad`. The new tool makes a gradient fill layer; Make holds the first click, Set the finished drag. | -| Perspective Warp (`perspectiveWarpTransform`) | `null` = layer target, `Md ` (`perspectiveWarpMode`: `warp`), `referenceRect` rectangle in pixels, `vertices` list of points in pixels (the layout quad), `warpedVertices` (the same points after warping), `quads` list of `indices` (4 vertex indexes each) | Layout and warp are one step. | | Print (`print`) then Print One Copy (`printOneCopy`) | `print`: `null` = reference `printOutput` property of the target document; `printOutput` (`PstS`, `Inte`, `printSixteenBit`, `printerName` text, `printProofSetup`), `printViewProofSetup`, `printOutputOptions` (caption, marks, `Bckg` colour, `BrdT`, `Bld `, `Rslt`, `vectorData`, `PgPs`, `Left`, `Top `, `Scl `, crop rectangle), `osSpecificPrintInfo` raw data, `Cptn` text. `printOneCopy` has no keys. | Pressing Print in the dialog records both steps. | | Create Droplet (`CrtD`) | `In ` alias: the droplet file; `Fldr` bool (include subfolders); `Usng` reference to the action; then the Batch keys below (destination, file naming, error log) when set | The same settings as Batch, with the droplet file instead of a source folder. | | Sky Replacement (`skyReplacement`) | `shiftEdge` double, `borderSmoothness` long (fade edge, default 50), `Brgh` long, `temperature` long, `harmonizationOpacity` long (35), `foregroundLightingOpacity` long, `lightingMode` blend mode (`Mltp`), `edgeLightingOpacity` long (70), `skyReplacementOutput` (`skyReplacementOutputToNewSheets` new layers, …), `Idnt` text (the sky preset's id), `Nm ` text (its name), `File` alias (the sky image) | Scale and Flip are **not** in the step: with 150 % and Flip on, the returned keys were the same. `foregroundLightingOpacity` is computed from the sky (44 and 29 for two skies). Without a chosen sky the dialog returns no keys. | diff --git a/docs/parity-checklist.md b/docs/parity-checklist.md index ccc77e95bc..2bf3a70644 100644 --- a/docs/parity-checklist.md +++ b/docs/parity-checklist.md @@ -9,11 +9,11 @@ Generated by `cargo xtask parity` from `crates/ui-egui/src/menu_catalog.rs` (Pho | File | 52 | 52 | 100% | | Edit | 75 | 75 | 100% | | Image | 61 | 61 | 100% | -| Layer | 163 | 163 | 100% | +| Layer | 161 | 161 | 100% | | Type | 74 | 74 | 100% | | Select | 25 | 25 | 100% | | Filter | 75 | 75 | 100% | -| View | 74 | 74 | 100% | +| View | 76 | 76 | 100% | | Window | 61 | 61 | 100% | ## Not yet implemented