PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Free Transform: the box is the selection, and the marching ants follow it (#5297) (#5337)
Michael Higgins3ee78a368b10
diff --git a/crates/engine/src/transform_cmds.rs b/crates/engine/src/transform_cmds.rsindex dfc3375d0..1c0153a42 100644--- a/crates/engine/src/transform_cmds.rs+++ b/crates/engine/src/transform_cmds.rs@@ -36,6 +36,23 @@ pub fn transform_bounds(doc: &Document, layer: &Layer) -> Rect {}}+/// The box Free Transform opens on `layer`, and the Move tool's transform controls show (#5297).+/// With a selection that limits the transform it is the selection's own bounds, as in Photoshop:+/// the box and the marching ants are one rectangle, however little of the selection the layer+/// fills. Empty, like [`transform_bounds`], when the selection holds none of the layer.+pub fn transform_frame(doc: &Document, layer: &Layer) -> Rect {+ let b = transform_bounds(doc, layer);+ if moves_whole(layer) { b } else { framed_by_selection(doc, b) }+}++/// `bounds` (what a selection left of a transform's content), or the selection's own bounds.+fn framed_by_selection(doc: &Document, bounds: Rect) -> Rect {+ match &doc.selection {+ Some(sel) if !bounds.is_empty() => sel.content_bounds(),+ _ => bounds,+ }+}+/// A group moves all its descendants, so its frame must not clip raster children to the selection.fn whole_layer_bounds(layer: &Layer) -> Rect {let content = match &layer.content {@@ -199,6 +216,12 @@ pub fn target_bounds(doc: &Document, surf: &Surface) -> Rect {}}+/// The box Free Transform opens on a lone target: like [`transform_frame`], the selection's own+/// bounds when there is one (#5297).+pub fn target_frame(doc: &Document, surf: &Surface) -> Rect {+ framed_by_selection(doc, target_bounds(doc, surf))+}+/// The locks `id` inherits from the groups around it.pub(crate) fn group_locks(doc: &Document, id: LayerId) -> Locks {doc.path_of(id).and_then(|p| Some(doc.locks_at(p.split_last()?.1))).unwrap_or_default()@@ -1164,6 +1187,32 @@ mod tests {assert_eq!(transform_bounds(&st.doc, st.doc.layer(st.active_layer.unwrap()).unwrap()), Rect::new(10, 10, 15, 20));}+ /// #5297: the box Free Transform opens with a selection is the selection's own rectangle,+ /// not the part of it the layer fills; type still moves whole, and a selection that holds none+ /// of the layer leaves nothing to transform.+ #[test]+ fn the_frame_is_the_selections_own_bounds() {+ let mut s = session();+ let frame = |s: &Session| {+ let st = s.active().unwrap();+ let l = st.doc.layer(st.active_layer.unwrap()).unwrap();+ (transform_frame(&st.doc, l), transform_bounds(&st.doc, l))+ };+ let content = Rect::new(10, 10, 30, 20);+ assert_eq!(frame(&s), (content, content), "no selection: the content");+ s.execute("select.rect", json!({"x": 5, "y": 5, "width": 15, "height": 40})).unwrap();+ assert_eq!(frame(&s), (Rect::new(5, 5, 20, 45), Rect::new(10, 10, 20, 20)));+ s.execute("select.rect", json!({"x": 60, "y": 60, "width": 10, "height": 10})).unwrap();+ assert!(frame(&s).0.is_empty(), "nothing of the layer is selected");++ let mut s = Session::new();+ s.execute("file.new", json!({"width": 200, "height": 120})).unwrap();+ s.execute("type.create", json!({"x": 20, "y": 60, "text": "Hello", "size": 36})).unwrap();+ let whole = active_bounds(&s);+ s.execute("select.rect", json!({"x": whole.x0, "y": whole.y0, "width": whole.width() / 2, "height": whole.height()})).unwrap();+ assert_eq!(frame(&s), (whole, whole), "type moves whole");+ }+#[test]fn group_transform_ignores_selections_inside_its_children() {group_transform_with_selection(Rect::new(10, 10, 15, 15));diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex 3af62be74..3fe97a1fc 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -3070,12 +3070,19 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:// The view centre can be any finite number (`ui.set`, #980). Past ±2³⁰ there is no document// to outline, and the padding below (at most 2 · 256 · 64) can't overflow i32 from there.let px = |v: f64| v.clamp(-f64::from(1 << 30), f64::from(1 << 30)) as i32;- let vis = photocraft_geom::Rect::new(- px(x0.floor()).div_euclid(q) * q - q,- px(y0.floor()).div_euclid(q) * q - q,- (px(x1.ceil()).div_euclid(q) + 2) * q,- (px(y1.ceil()).div_euclid(q) + 2) * q,- );+ // A Free Transform carries the selection to wherever its box goes (#5297), so all of+ // it is outlined: the part now in view may have started out of it.+ let carried = app.session.active_index() == Some(idx) && crate::transform_tool::carries_selection_of(app, doc.id);+ let vis = if carried {+ photocraft_geom::Rect::new(-(1 << 30), -(1 << 30), 1 << 30, 1 << 30)+ } else {+ photocraft_geom::Rect::new(+ px(x0.floor()).div_euclid(q) * q - q,+ px(y0.floor()).div_euclid(q) * q - q,+ (px(x1.ceil()).div_euclid(q) + 2) * q,+ (px(y1.ceil()).div_euclid(q) + 2) * q,+ )+ };let key = crate::surface_fingerprint(sel)^ (step as u64) << 56^ doc.id.0.rotate_left(17)@@ -3109,7 +3116,10 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:if let Some((dx, dy)) = selection_shown_offset(app) {shown.center = [xf.center[0] - dx as f32, xf.center[1] - dy as f32];}- marching_ants_segments(&painter, &shown, segs, time);+ // Under a Free Transform box they are where the box puts them (#5297).+ if !(carried && crate::transform_tool::draw_selection(app, &painter, &xf, doc.id, segs, time)) {+ marching_ants_segments(&painter, &shown, segs, time);+ }ctx.request_repaint_after(std::time::Duration::from_millis(100));}}@@ -4103,6 +4113,31 @@ fn marching_ants_segments(painter: &egui::Painter, xf: &ViewXform, segs: &[crate/// [`marching_ants_segments`] with each outline point placed on screen by `to_screen` (a/// transformed outline: Content-Aware Move's Transform On Drop).pub(crate) fn marching_ants_mapped(painter: &egui::Painter, segs: &[crate::outline::Segment], time: f64, to_screen: impl Fn([i32; 2]) -> Pos2) {+ marching_ants_lines(painter, segs.iter().map(|(a, b)| (to_screen(*a), to_screen(*b))), time);+}++/// The part of the line `a`–`b` inside `r` (Liang–Barsky), if any.+fn clip_line(r: Rect, a: Pos2, b: Pos2) -> Option<(Pos2, Pos2)> {+ let d = b - a;+ let (mut t0, mut t1) = (0.0f32, 1.0f32);+ for (p, q) in [(-d.x, a.x - r.min.x), (d.x, r.max.x - a.x), (-d.y, a.y - r.min.y), (d.y, r.max.y - a.y)] {+ if p == 0.0 {+ if q < 0.0 {+ return None;+ }+ } else if p < 0.0 {+ t0 = t0.max(q / p);+ } else {+ t1 = t1.min(q / p);+ }+ }+ (t0 <= t1).then(|| (a + d * t0, a + d * t1))+}++/// Marching ants along lines already placed on screen (a warped outline is a run of short ones).+pub(crate) fn marching_ants_lines(painter: &egui::Painter, lines: impl Iterator<Item = (Pos2, Pos2)>, time: f64) {+ // Longer than any line that fits the view: only its part in view is dashed.+ const LONG: f32 = 8192.0;let dash = 4.0f32;let phase = ((time * 10.0) % (dash as f64 * 2.0)) as f32;let clip = painter.clip_rect();@@ -4120,12 +4155,17 @@ pub(crate) fn marching_ants_mapped(painter: &egui::Painter, segs: &[crate::outlimesh.add_triangle(i, i + 1, i + 2);mesh.add_triangle(i, i + 2, i + 3);};- for (a, b) in segs {- let pa = to_screen(*a);- let pb = to_screen(*b);- if !clip.intersects(Rect::from_two_pos(pa, pb).expand(1.0)) {+ for (pa, pb) in lines {+ // A transformed outline can land anywhere, or nowhere (a point on a Distort's horizon).+ if !(pa.is_finite() && pb.is_finite()) || !clip.intersects(Rect::from_two_pos(pa, pb).expand(1.0)) {continue;}+ let (pa, pb) = if pa.distance(pb) > LONG {+ let Some(inside) = clip_line(clip.expand(4.0 * dash), pa, pb) else { continue };+ inside+ } else {+ (pa, pb)+ };let pa = pos2(pa.x.round() + 0.5, pa.y.round() + 0.5);let pb = pos2(pb.x.round() + 0.5, pb.y.round() + 0.5);let len = pa.distance(pb);@@ -4501,7 +4541,7 @@ pub(crate) fn layer_edges_rect(app: &PhotocraftApp, idx: usize) -> Option<photocSome(b.translate(dx, dy))}-/// Move tool › Show Transform Controls: the active layer's transform bounds.+/// Move tool › Show Transform Controls: the box Free Transform would open on the active layer.fn transform_controls_rect(app: &PhotocraftApp, xf: &ViewXform) -> Option<Rect> {if app.ui.tool != Tool::Move || !app.ui.tool_options.move_show_transform || app.ui.transform.is_some() || app.drag.is_some() {return None;@@ -4511,7 +4551,7 @@ fn transform_controls_rect(app: &PhotocraftApp, xf: &ViewXform) -> Option<Rect>if crate::doc_props_ui::is_background(&st.doc, l) {return None;}- let b = photocraft_engine::transform_cmds::transform_bounds(&st.doc, l);+ let b = photocraft_engine::transform_cmds::transform_frame(&st.doc, l);let (dx, dy) = crate::move_ui::floating_offset(app).unwrap_or((0, 0));let b = b.translate(dx, dy);if b.is_empty() {@@ -7761,6 +7801,27 @@ mod transform_controls_tests {assert_eq!(app.ui.transform.as_ref().unwrap().rect, [200.0, 150.0, 300.0, 210.0]);}+ /// #5297: with a selection the Move tool's transform controls are the selection's rectangle,+ /// though the layer fills only part of it, and a press on them opens that box.+ #[test]+ fn move_transform_controls_frame_the_selection() {+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ app.run("file.new", json!({"width": 400, "height": 300})).unwrap();+ app.run("layer.new.layer", json!({})).unwrap();+ app.run("select.rect", json!({"x": 100, "y": 100, "width": 100, "height": 60})).unwrap();+ app.run("edit.fill", json!({"color": "#ff0000"})).unwrap();+ app.run("select.rect", json!({"x": 60, "y": 80, "width": 100, "height": 120})).unwrap();+ app.ui.tool = Tool::Move;+ app.ui.tool_options.move_show_transform = true;+ let xf =+ ViewXform { rect: Rect::from_min_size(Pos2::ZERO, vec2(400.0, 300.0)), zoom: 1.0, center: [200.0, 150.0], flip: false, rotation: 0.0, aspect: 1.0 };+ let r = transform_controls_rect(&app, &xf).unwrap();+ assert_eq!(r, Rect::from_min_max(pos2(60.0, 80.0), pos2(160.0, 200.0)));+ let ctx = egui::Context::default();+ assert!(begin_transform_controls_at(&mut app, &ctx, &xf, r.right_bottom()));+ assert_eq!(app.ui.transform.as_ref().unwrap().rect, [60.0, 80.0, 160.0, 200.0]);+ }+/// #2585: Free Transform on a position-locked layer is refused before the box opens, with/// Photoshop's alert, from ⌘T and from the Move tool's transform controls alike. It used to/// open, preview every drag and fail only at commit.diff --git a/crates/ui-egui/src/transform_tool.rs b/crates/ui-egui/src/transform_tool.rsindex 000a943ad..d4f58ef3a 100644--- a/crates/ui-egui/src/transform_tool.rs+++ b/crates/ui-egui/src/transform_tool.rs@@ -195,7 +195,8 @@ pub fn begin(app: &mut PhotocraftApp, ctx: &egui::Context) -> Result<(), String>if matches!(layer.content, LayerContent::Adjustment(_)) && layer.mask.is_none() {return Err("Adjustment layers have nothing to transform".into());}- let b = photocraft_engine::transform_cmds::transform_bounds(&doc, layer);+ // With a selection the box is the selection's (#5297).+ let b = photocraft_engine::transform_cmds::transform_frame(&doc, layer);if b.is_empty() {return Err("Could not transform: the layer is empty".into());}@@ -410,7 +411,7 @@ fn fold_made(app: &mut PhotocraftApp, document: DocId, made: MadeLayer) {}/// Free Transform of a targeted unlinked layer mask, alpha channel or Quick Mask by itself: the-/// box frames its content (within the selection) and previews the moving values in grey over the+/// box frames its content (or the selection) and previews the moving values in grey over the/// document with them vacated.fn begin_lone(app: &mut PhotocraftApp,@@ -420,7 +421,7 @@ fn begin_lone(target: serde_json::Value,) -> Result<(), String> {use photocraft_engine::transform_cmds as tc;- let b = tc::target_bounds(&doc, &surf);+ let b = tc::target_frame(&doc, &surf);if b.is_empty() {return Err("Could not transform: nothing is selected".into());}@@ -2166,6 +2167,72 @@ pub fn draw_overlay(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform}}+/// Applying the open box moves the selection outline with it: `edit.transform` and+/// `edit.transform.warp` map it like the pixels. Not Transform Selection (its ants are hidden), a+/// path, Content-Aware Scale or a type layer's Warp Text, which leave the selection alone.+fn carries_selection(app: &PhotocraftApp, t: &TransformSession) -> bool {+ !t.selection && t.path.is_none() && t.content_aware.is_none() && !(t.warp.is_some() && warps_type(app))+}++/// A transform of `document` is open that carries its selection along (#5297): the canvas traces+/// the whole outline, not only the part in view where it started, for [`draw_selection`].+pub(crate) fn carries_selection_of(app: &PhotocraftApp, document: DocId) -> bool {+ matches!((&app.ui.transform, &app.transform_preview), (Some(t), Some(pv)) if pv.doc.id == document && carries_selection(app, t))+}++/// The marching ants where the open box puts them (#5297): the selection follows a move, scale,+/// rotation, skew, distort, perspective or warp while it is made, to where applying it leaves it.+/// `segs` is the outline of `document`'s selection at rest. False when no open transform carries+/// that selection: the caller draws it where it is.+pub(crate) fn draw_selection(+ app: &PhotocraftApp,+ painter: &egui::Painter,+ xf: &ViewXform,+ document: DocId,+ segs: &[crate::outline::Segment],+ time: f64,+) -> bool {+ let Some(t) = app.ui.transform.as_ref().filter(|_| carries_selection_of(app, document)) else { return false };+ let scr = |(x, y): (f64, f64)| xf.to_screen(x as f32, y as f32);+ let doc = |p: [i32; 2]| [f64::from(p[0]), f64::from(p[1])];+ let along = |a: [f64; 2], b: [f64; 2], k: f64| [a[0] + (b[0] - a[0]) * k, a[1] + (b[1] - a[1]) * k];+ if let Some(w) = &t.warp {+ // A warp bends the outline's straight runs: each is drawn in pieces about 8 points long.+ let piece = (8.0 / f64::from(xf.zoom.max(1e-3))).max(1.0);+ let lines = segs.iter().flat_map(|(a, b)| {+ let (a, b) = (doc(*a), doc(*b));+ let n = (((b[0] - a[0]).abs() + (b[1] - a[1]).abs()) / piece).ceil().clamp(1.0, 256.0) as usize;+ let at = move |i: usize| {+ let p = along(a, b, i as f64 / n as f64);+ scr(w.map(p[0], p[1]))+ };+ (0..n).map(move |i| (at(i), at(i + 1)))+ });+ crate::canvas::marching_ants_lines(painter, lines, time);+ } else if let Some(h) = Homography::rect_to_quad(t.rect, t.quad) {+ // Past a Distort's horizon the outline has no place, like the pixels (#4863): a run that+ // crosses it stops short of it, where its points are still a finite way off.+ let front = h.front_side(t.rect);+ let depth = |p: [f64; 2]| front * h.w(p[0], p[1]);+ let near = corners(t.rect).iter().map(|c| depth(*c)).fold(0.0, f64::max) * 1e-3;+ let lines = segs.iter().filter_map(|(a, b)| {+ let (mut a, mut b) = (doc(*a), doc(*b));+ let (da, db) = (depth(a), depth(b));+ if da < near && db < near {+ return None;+ }+ if da < near {+ a = along(a, b, (near - da) / (db - da));+ } else if db < near {+ b = along(b, a, (near - db) / (da - db));+ }+ Some((scr(h.apply(a[0], a[1])), scr(h.apply(b[0], b[1]))))+ });+ crate::canvas::marching_ants_lines(painter, lines, time);+ }+ true+}+/// What the styled preview of the moving layer is drawn from (transform_fx.rs), at `zoom` screen/// pixels per document pixel. `None` for a layer without a style (also once it is switched off/// while the box is open) or a hidden one: the bare pixels are drawn instead. The style, opacity@@ -3995,6 +4062,123 @@ mod tests {assert_eq!((t.layer, t.rect), (second.0, [40.0, 40.0, 56.0, 60.0]), "the next box is on the selected layer");}+ /// The screen rectangle the marching ants cover as [`draw_selection`] paints them over the+ /// active document's selection; `None` when it leaves them to the canvas.+ fn ants_bounds(app: &PhotocraftApp, xf: &ViewXform) -> Option<egui::Rect> {+ let st = app.session.active().unwrap();+ let sel = st.doc.selection.as_ref().unwrap();+ let segs = crate::outline::outline(sel, sel.content_bounds());+ let ctx = egui::Context::default();+ let mut drawn = false;+ let mut output = ctx.run_ui(Default::default(), |ui| {+ let painter = ui.ctx().layer_painter(egui::LayerId::new(egui::Order::Foreground, egui::Id::new("ants-test")));+ drawn = draw_selection(app, &painter, xf, st.doc.id, &segs, 0.0);+ });+ output.textures_delta.clear();+ // The ants are a mesh of straight dashes and line shapes for the slanted ones.+ let ants = output.shapes.iter().filter(|s| matches!(s.shape, egui::Shape::Mesh(_) | egui::Shape::LineSegment { .. }));+ drawn.then(|| ants.map(|s| s.shape.visual_bounding_rect()).fold(egui::Rect::NOTHING, egui::Rect::union))+ }++ /// The screen rectangle around document points.+ fn screen_bounds(xf: &ViewXform, points: &[[f64; 2]]) -> egui::Rect {+ egui::Rect::from_points(&points.iter().map(|p| xf.to_screen(p[0] as f32, p[1] as f32)).collect::<Vec<_>>())+ }++ fn rects_match(a: egui::Rect, b: egui::Rect) -> bool {+ (a.min - b.min).abs().max_elem() <= 2.0 && (a.max - b.max).abs().max_elem() <= 2.0+ }++ /// #5297: with a selection, Free Transform's box is the selection's own rectangle (wider here+ /// than the pixels it holds), and the marching ants stay on the box through a move, a scale, a+ /// rotation and a distort, before anything is applied. Applying leaves them there.+ #[test]+ fn the_box_is_the_selection_and_the_ants_follow_it() {+ let ctx = gpu_ctx();+ let mut app = app_with_square(64, photocraft_geom::Rect::new(8, 8, 24, 24));+ let xf = ViewXform {+ rect: egui::Rect::from_min_size(egui::Pos2::ZERO, vec2(400.0, 400.0)),+ zoom: 2.0,+ center: [32.0, 32.0],+ flip: false,+ rotation: 0.0,+ aspect: 1.0,+ };+ app.run("select.rect", json!({"x": 4, "y": 4, "width": 30, "height": 26})).unwrap();+ assert_eq!(ants_bounds(&app, &xf), None, "no box open: the canvas draws them where they are");+ begin(&mut app, &ctx).unwrap();+ let rest = corners([4.0, 4.0, 34.0, 30.0]);+ assert_eq!(app.ui.transform.as_ref().unwrap().quad, rest, "the box is the selection, not the 16 px square in it");+ assert!(rects_match(ants_bounds(&app, &xf).unwrap(), screen_bounds(&xf, &rest)), "untouched, the ants are where they were");++ let on_the_box = |app: &PhotocraftApp, what: &str| {+ let quad = app.ui.transform.as_ref().unwrap().quad;+ let (ants, boxed) = (ants_bounds(app, &xf).unwrap(), screen_bounds(&xf, &quad));+ assert!(rects_match(ants, boxed), "{what}: ants {ants:?}, box {boxed:?}");+ };+ if let Some(t) = app.ui.transform.as_mut() {+ t.quad = t.quad.map(|[x, y]| [x + 20.0, y + 10.0]);+ t.pivot = [t.pivot[0] + 20.0, t.pivot[1] + 10.0];+ }+ on_the_box(&app, "moved");+ let moved = app.ui.transform.as_ref().unwrap().quad;+ scale_about_pivot(&mut app, 0.5, 1.5);+ on_the_box(&app, "scaled");+ rotate_about_pivot(&mut app, 0.6);+ on_the_box(&app, "rotated");+ if let Some(t) = app.ui.transform.as_mut() {+ t.quad[2] = [t.quad[2][0] + 9.0, t.quad[2][1] + 13.0];+ }+ on_the_box(&app, "distorted");++ // Applied as moved only: the outline is where the ants showed it.+ if let Some(t) = app.ui.transform.as_mut() {+ t.quad = moved;+ }+ commit(&mut app);+ assert!(app.ui.transform.is_none());+ let st = app.session.active().unwrap();+ assert_eq!(st.doc.selection.as_ref().unwrap().content_bounds(), photocraft_geom::Rect::new(24, 14, 54, 40));+ assert_eq!(st.doc.layer(st.active_layer.unwrap()).unwrap().surface().unwrap().content_bounds(), photocraft_geom::Rect::new(28, 18, 44, 34));+ }++ /// #5297: in Warp mode the ants bend with the mesh, and past a Distort's horizon they stop+ /// rather than run off to infinity.+ #[test]+ fn the_ants_follow_a_warp_and_stop_at_a_distorts_horizon() {+ let ctx = gpu_ctx();+ let mut app = app_with_square(64, photocraft_geom::Rect::new(8, 8, 56, 56));+ let xf = ViewXform {+ rect: egui::Rect::from_min_size(egui::Pos2::ZERO, vec2(400.0, 400.0)),+ zoom: 2.0,+ center: [32.0, 32.0],+ flip: false,+ rotation: 0.0,+ aspect: 1.0,+ };+ app.run("select.rect", json!({"x": 12, "y": 12, "width": 40, "height": 40})).unwrap();+ begin(&mut app, &ctx).unwrap();+ let rest = corners([12.0, 12.0, 52.0, 52.0]);++ // Two corners dragged across each other put half the box past the horizon.+ if let Some(t) = app.ui.transform.as_mut() {+ t.quad = [[12.0, 12.0], [52.0, 12.0], [20.0, 40.0], [44.0, 40.0]];+ }+ let ants = ants_bounds(&app, &xf).unwrap();+ assert!(ants == egui::Rect::NOTHING || (ants.is_finite() && ants.width() < 1e5 && ants.height() < 1e5), "{ants:?}");++ if let Some(t) = app.ui.transform.as_mut() {+ t.quad = rest;+ }+ enter_warp(&mut app, &ctx);+ let arc = Warp::preset(WarpStyle::Arc, 50.0, [12.0, 12.0, 52.0, 52.0]);+ app.ui.transform.as_mut().unwrap().warp = Some(arc.clone());+ let ants = ants_bounds(&app, &xf).unwrap();+ assert!(!rects_match(ants, screen_bounds(&xf, &rest)), "the outline left its place: {ants:?}");+ let warped: Vec<[f64; 2]> = rest.iter().map(|p| arc.map(p[0], p[1])).map(|(x, y)| [x, y]).collect();+ assert!(ants.expand(2.0).contains_rect(screen_bounds(&xf, &warped)), "the warped corners are on it: {ants:?}");+ }+/// Transform Selection moves the selection outline, not a layer: selecting a layer keeps it open.#[test]fn selecting_another_layer_keeps_a_transform_selection_open() {diff --git a/crates/ui-egui/src/transform_undo_tests.rs b/crates/ui-egui/src/transform_undo_tests.rsindex 832b22190..b863eb8ff 100644--- a/crates/ui-egui/src/transform_undo_tests.rs+++ b/crates/ui-egui/src/transform_undo_tests.rs@@ -343,3 +343,46 @@ fn the_first_drag_from_the_move_tools_controls_undoes() {key(&mut h, Modifiers::COMMAND, Key::Z);assert!(close(quad(&h), [[100.0, 100.0], [200.0, 100.0], [200.0, 160.0], [100.0, 160.0]]), "{:?}", quad(&h));}++/// #3402's layer-switch case (#5297): selected pixels moved with the Move tool, then moved again+/// in the Free Transform box, land where the box left them when another layer is picked.+#[test]+fn picking_another_layer_applies_the_transform_of_moved_selected_pixels() {+ let mut h = harness();+ let layer = h.state().session.active().unwrap().active_layer.unwrap();+ h.state_mut().run("select.rect", json!({"x": 100, "y": 100, "width": 100, "height": 60})).unwrap();+ drag(&mut h, [150.0, 130.0], [250.0, 180.0]);+ begin(&mut h);+ // Away from the centre, where a press would take the reference point instead.+ drag(&mut h, [220.0, 165.0], [240.0, 175.0]);+ assert_eq!(quad(&h), [[220.0, 160.0], [320.0, 160.0], [320.0, 220.0], [220.0, 220.0]]);+ let other = h.state().session.active().unwrap().doc.layers.iter().map(|l| l.id).find(|id| *id != layer).unwrap();+ h.state_mut().run("layer.select", json!({"layer": other.0})).unwrap();+ crate::transform_tool::end_if_left(h.state_mut());+ h.run_steps(3);+ assert!(h.state().ui.transform.is_none(), "picking another layer applies the transform");+ let st = h.state().session.active().unwrap();+ let landed = photocraft_geom::Rect::new(220, 160, 320, 220);+ let (pixels, selection) = (st.doc.layer(layer).unwrap().surface().unwrap().content_bounds(), st.doc.selection.as_ref().map(|s| s.content_bounds()));+ assert_eq!((pixels, selection), (landed, Some(landed)));+}++/// #5297 through the real canvas: ⌘T with a selection wider than the layer opens the box on the+/// selection, and dragging it moves the selected pixels and the selection together.+#[test]+fn free_transform_opens_on_the_selection_and_moves_it_with_the_pixels() {+ let mut h = harness();+ let layer = h.state().session.active().unwrap().active_layer.unwrap();+ // The left 60 px of the red rectangle, and empty layer to its left, above and below.+ h.state_mut().run("select.rect", json!({"x": 60, "y": 80, "width": 100, "height": 120})).unwrap();+ begin(&mut h);+ assert_eq!(quad(&h), [[60.0, 80.0], [160.0, 80.0], [160.0, 200.0], [60.0, 200.0]]);+ drag(&mut h, [80.0, 100.0], [130.0, 130.0]);+ assert_eq!(quad(&h), [[110.0, 110.0], [210.0, 110.0], [210.0, 230.0], [110.0, 230.0]]);+ key(&mut h, Modifiers::NONE, Key::Enter);+ assert!(h.state().ui.transform.is_none());+ let st = h.state().session.active().unwrap();+ assert_eq!(st.doc.selection.as_ref().unwrap().content_bounds(), photocraft_geom::Rect::new(110, 110, 210, 230));+ // What stayed (160..200 × 100..160) and what moved (to 150..210 × 130..190).+ assert_eq!(st.doc.layer(layer).unwrap().surface().unwrap().content_bounds(), photocraft_geom::Rect::new(150, 100, 210, 190));+}diff --git a/docs/ui-parity.md b/docs/ui-parity.mdindex 9905925a8..41ce47177 100644--- a/docs/ui-parity.md+++ b/docs/ui-parity.md@@ -1,6 +1,6 @@# UI parity: tools, handles, modifiers and feel-> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-14 · **Change:** minor (History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed) · **Target:** Adobe Photoshop 2026+> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-14 · **Change:** minor (Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed) · **Target:** Adobe Photoshop 2026How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, thehandles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation,@@ -66,6 +66,7 @@ Triangle and Curvature Pen (minus legacy Rounded Rectangle and Targeted Adjustme| ⌘-corner distort, ⌘-edge skew, ⌘⌥⇧ perspective, ⇧ rotate in 15° steps | done | || Warp: presets, bend, split crosswise/vertical/horizontal, 3×3–5×5 and custom grids | done | || Options bar X/Y, W/H % with link, angle | done | |+| With a selection, the box is the selection's rectangle and the marching ants follow the box live | done | `transform_frame`, `transform_tool.rs` (`draw_selection`): move, scale, rotate, skew, distort, perspective and warp, before the transform is applied; also the Move tool's Show Transform Controls (#5297) || Options bar H/V skew fields | done | `transform_tool.rs` (`Parts`, `skew_about_pivot`): W/H, angle and skew read as Photoshop decomposes the box; `skew_fields_lean_the_box_about_the_reference_point` || Interpolation in the options bar | partial | Bicubic/Bilinear/Nearest; no Bicubic Smoother/Sharper/Automatic, Preserve Details || Commit/cancel buttons in the options bar | missing | #2442 |@@ -234,3 +235,4 @@ Paragraph; the rest open as in-app floating windows.| 2026-10-12 | minor | Smart filter rows can be selected, and dragged (⌥: copied) onto another smart object or onto Delete (#4271) || 2026-10-12 | minor | Free Transform options bar: H and V skew fields; a sheared box reads as skew instead of a taller H || 2026-10-13 | minor | Smart filter rows can be dragged up or down their stack to reorder the filters |+| 2026-10-13 | minor | Free Transform with a selection: the box is the selection's rectangle, and the marching ants follow it while it is transformed (#5297) |