Viewer: resize cursors follow each handle and the layer's rotation (#393)
Every bounding-box handle in the Composition viewer showed the north-west / south-east resize cursor, so two corners and all four edges showed the wrong direction. Each handle now takes the cursor along the direction it scales, worked out from the on-screen box: a corner points between its two edges (the box's diagonal whatever its proportions), an edge handle across its edge. The cursors turn with the layer's rotation, as in After Effects. Tests: handle_cursors_follow_each_handle_and_the_layer_rotation (ui_viewer: a wide box at 0°, 90° and 45°). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
609ef9cacb
commit
fcf3bb5dca
@@ -295,6 +295,32 @@ fn handle_point(b: [f64; 4], handle: usize) -> [f64; 2] {
|
||||
}
|
||||
}
|
||||
|
||||
/// The resize cursor over bounding-box handle `handle` of the on-screen box `sq` (corners
|
||||
/// clockwise from the top left, handles as in [`handle_point`]): along the direction the handle
|
||||
/// scales, so it turns with the layer, as in After Effects. A corner points between its two
|
||||
/// edges (the box's diagonal whatever its proportions), an edge handle across its edge.
|
||||
fn handle_cursor(sq: &[Pos2], handle: usize) -> egui::CursorIcon {
|
||||
let at = |k: usize| sq.get(k % 4).copied().unwrap_or(Pos2::ZERO);
|
||||
let dir = if handle < 4 {
|
||||
let c = at(handle);
|
||||
(c - at(handle + 3)).normalized() + (c - at(handle + 1)).normalized()
|
||||
} else {
|
||||
let e = at(handle - 3) - at(handle - 4);
|
||||
vec2(-e.y, e.x)
|
||||
};
|
||||
// Screen y points down: 45° is the south-east diagonal.
|
||||
let a = dir.y.atan2(dir.x).to_degrees().rem_euclid(180.0);
|
||||
if !(22.5..157.5).contains(&a) {
|
||||
egui::CursorIcon::ResizeHorizontal
|
||||
} else if a < 67.5 {
|
||||
egui::CursorIcon::ResizeNwSe
|
||||
} else if a < 112.5 {
|
||||
egui::CursorIcon::ResizeVertical
|
||||
} else {
|
||||
egui::CursorIcon::ResizeNeSw
|
||||
}
|
||||
}
|
||||
|
||||
/// The scale ratio (x, y) that puts the point grabbed at `start` (relative to the anchor, layer
|
||||
/// pixels) under the pointer at `cur`. `uniform` (Shift on a corner) keeps the aspect ratio,
|
||||
/// following the pointer along the handle's diagonal. Dragging past the anchor flips the layer,
|
||||
@@ -748,7 +774,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
// Overlays + interaction.
|
||||
let selected = app.session.state.selected_layers.clone();
|
||||
let mut handle_hits: Vec<(LayerId, usize, Pos2)> = Vec::new();
|
||||
// Bounding-box handles: (layer, handle, screen point, its resize cursor).
|
||||
let mut handle_hits: Vec<(LayerId, usize, Pos2, egui::CursorIcon)> = Vec::new();
|
||||
let mut vertex_hits: Vec<VertexHit> = Vec::new();
|
||||
let mut key_hits: Vec<ov::KeyHit> = Vec::new();
|
||||
let mut paths: Vec<ov::PathInfo> = Vec::new();
|
||||
@@ -815,7 +842,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let hr = Rect::from_center_size(hp, vec2(hs, hs));
|
||||
painter.rect_filled(hr, 0.0, col);
|
||||
painter.rect_stroke(hr, 0.0, Stroke::new(1.0, Color32::from_black_alpha(120)), StrokeKind::Outside);
|
||||
handle_hits.push((l.id, i, hp));
|
||||
handle_hits.push((l.id, i, hp, handle_cursor(&sq, i)));
|
||||
app.auto.add(&format!("viewer.handle.{}.{i}", l.id.0), hr, "handle");
|
||||
}
|
||||
// Anchor point.
|
||||
@@ -1036,8 +1063,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
egui::CursorIcon::Move
|
||||
} else if let Some((_, vertical)) = vt::guide_at(app, &comp, &map, hp) {
|
||||
if vertical { egui::CursorIcon::ResizeHorizontal } else { egui::CursorIcon::ResizeVertical }
|
||||
} else if handle_hits.iter().any(|(_, _, h)| h.distance(hp) < HANDLE) {
|
||||
egui::CursorIcon::ResizeNwSe
|
||||
} else if let Some((.., cursor)) = handle_hits.iter().find(|(_, _, h, _)| h.distance(hp) < HANDLE) {
|
||||
*cursor
|
||||
} else {
|
||||
egui::CursorIcon::Default
|
||||
}
|
||||
@@ -1213,7 +1240,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
// far enough to count as a drag it may have left a small handle.
|
||||
Tool::Selection => {
|
||||
let cpt = map.to_comp(press);
|
||||
if let Some((lid, hi, _)) = handle_hits.iter().find(|(_, _, h)| h.distance(press) < HANDLE + 2.0).cloned() {
|
||||
if let Some((lid, hi, ..)) = handle_hits.iter().find(|(_, _, h, _)| h.distance(press) < HANDLE + 2.0).cloned() {
|
||||
let layer = comp.layer(lid).cloned();
|
||||
layer.and_then(|layer| {
|
||||
let tr = layer.transform()?;
|
||||
|
||||
@@ -1538,6 +1538,38 @@ fn handle_drags_snap_to_the_comp_edges() {
|
||||
assert!(close(s, [100.0, 100.0]), "{s:?}");
|
||||
}
|
||||
|
||||
/// Each bounding-box handle shows the resize cursor along the direction it scales, turning with
|
||||
/// the layer (#393: every handle showed the north-west / south-east cursor).
|
||||
#[test]
|
||||
fn handle_cursors_follow_each_handle_and_the_layer_rotation() {
|
||||
use egui::CursorIcon::{ResizeHorizontal as H, ResizeNeSw as NeSw, ResizeNwSe as NwSe, ResizeVertical as V};
|
||||
let mut h = harness();
|
||||
let box_id = h.state().session.active_comp().unwrap().layers[0].id.0;
|
||||
let set = |h: &mut Harness<'_, EffectcraftApp>, path: &str, v: serde_json::Value| {
|
||||
h.state_mut().session.execute("prop.set", json!({"layer": box_id, "path": path, "value": v})).unwrap();
|
||||
h.run_steps(2);
|
||||
};
|
||||
let cursors = |h: &mut Harness<'_, EffectcraftApp>| {
|
||||
(0..8)
|
||||
.map(|i| {
|
||||
let c = rect(h, &format!("viewer.handle.{box_id}.{i}")).center();
|
||||
h.input_mut().events.push(Event::PointerMoved(c));
|
||||
h.run_steps(2);
|
||||
h.output().platform_output.cursor_icon
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
};
|
||||
h.state_mut().session.execute("layer.select", json!({"layers": [box_id]})).unwrap();
|
||||
// A wide box: its corners still take the diagonal cursors.
|
||||
set(&mut h, "transform/scale", json!([300, 100, 100]));
|
||||
// Corners clockwise from the top left, then the top, right, bottom and left edges.
|
||||
assert_eq!(cursors(&mut h), [NwSe, NeSw, NwSe, NeSw, V, H, V, H]);
|
||||
set(&mut h, "transform/rotation", json!(90));
|
||||
assert_eq!(cursors(&mut h), [NeSw, NwSe, NeSw, NwSe, H, V, H, V], "turned a quarter");
|
||||
set(&mut h, "transform/rotation", json!(45));
|
||||
assert_eq!(cursors(&mut h), [V, H, V, H, NeSw, NwSe, NeSw, NwSe], "turned an eighth");
|
||||
}
|
||||
|
||||
/// The arrow keys over the Composition panel nudge the selected layer 1 pixel at the viewer's
|
||||
/// magnification (half a comp pixel at 200 %), Shift+arrow 10, one undo step each (#290).
|
||||
#[test]
|
||||
|
||||
Reference in New Issue
Block a user