Shapes: drawing with a shape tool adds to the selected shape layer (#227)
With a shape layer selected, the Rectangle, Rounded Rectangle, Ellipse,
Polygon and Star tools made a new shape layer for every shape. After
Effects draws into the selected shape layer instead: the shape becomes a
new group on top of its Contents ("Rectangle 2", ...), placed by the
group's Transform. The new shape.newShape command does that (in the
layer's space, so a moved or scaled layer still gets the shape where it
was drawn), and makes a new shape layer only when no unlocked shape
layer is selected. The viewer's shape tools use it; masks on other
selected layers are unchanged. layer.newShape and the Pen's
shape.newPath share its layer and Contents helpers.
Test: shape_tools_draw_into_the_selected_shape_layer,
shape_tool_draws_into_the_selected_shape_layer.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
7e4a7cd863
commit
9968950b71
@@ -247,6 +247,39 @@ fn layer_drag_snaps_to_comp_centre_and_ctrl_disables() {
|
||||
assert!((p[0] - 320.0).abs() > 1.0, "{p:?}");
|
||||
}
|
||||
|
||||
/// With a shape layer selected the Rectangle tool draws a new group into its Contents (After
|
||||
/// Effects' behaviour); with nothing selected it draws a new shape layer (#227).
|
||||
#[test]
|
||||
fn shape_tool_draws_into_the_selected_shape_layer() {
|
||||
let mut h = harness();
|
||||
let l = h.state_mut().session.execute("layer.newShape", json!({"kind": "rect", "size": [100, 100], "position": [320, 180]})).unwrap()["layer"]
|
||||
.as_u64()
|
||||
.unwrap();
|
||||
h.state_mut().ui.tool = Tool::Rectangle;
|
||||
h.run_steps(2);
|
||||
let n0 = h.state().session.active_comp().unwrap().layers.len();
|
||||
let (a, b) = (screen(&h, [100.0, 100.0]), screen(&h, [200.0, 160.0]));
|
||||
drag(&mut h, a, b);
|
||||
let comp = h.state().session.active_comp().unwrap().clone();
|
||||
assert_eq!(comp.layers.len(), n0, "no new layer");
|
||||
let contents = comp.layer(LayerId(l)).unwrap().props.sub("contents").unwrap().clone();
|
||||
let names: Vec<&str> = contents.groups().map(|g| g.name.as_str()).collect();
|
||||
assert_eq!(names, ["Rectangle 2", "Rectangle 1"]);
|
||||
// Placed where it was drawn (centred near comp (150, 130)), in the layer's space: the layer
|
||||
// sits at the comp centre.
|
||||
let g = contents.groups().next().unwrap();
|
||||
let at = g.sub("transform").unwrap().get("position").unwrap().value.components();
|
||||
assert!((at[0] + 170.0).abs() < 8.0 && (at[1] + 50.0).abs() < 8.0, "{at:?}");
|
||||
// Nothing selected: a new shape layer.
|
||||
h.state_mut().session.execute("edit.deselectAll", json!({})).unwrap();
|
||||
let (a, b) = (screen(&h, [400.0, 250.0]), screen(&h, [500.0, 300.0]));
|
||||
drag(&mut h, a, b);
|
||||
let comp = h.state().session.active_comp().unwrap();
|
||||
assert_eq!(comp.layers.len(), n0 + 1);
|
||||
assert!(matches!(comp.layers[0].source, effectcraft_engine::project::LayerSource::Shape));
|
||||
assert_ne!(comp.layers[0].id, LayerId(l));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shape_pen_draws_a_closed_shape_layer() {
|
||||
let mut h = harness();
|
||||
|
||||
Reference in New Issue
Block a user