Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge main into enhance/batch-parent-matte

tylerjenningsw9b57090b0082
diff --cc crates/ui-egui/src/i18n/ui.rs
index d56e0de77,a9c45bb99..a584839fd
--- a/crates/ui-egui/src/i18n/ui.rs
+++ b/crates/ui-egui/src/i18n/ui.rs
@@@ -383,8 -467,7 +467,8 @@@ const JAPANESE: &[(&str, &str)] = &
("Overlay", "オーバーレイ"),
("Parameter Name:", "パラメーター名:"),
("Parent pick whip: drag onto a layer", "親ピックウィップ:レイヤー上にドラッグ"),
+ ("Track Matte pick whip: drag onto a layer", "トラックマットピックウィップ:レイヤー上にドラッグ"),
- ("Pixel Aspect Ratio:", "ピクセルアスペクト比:"),
+ ("Pixel Aspect Ratio:", "ピクセル縦横比:"),
("Playing on Video Preview", "ビデオプレビューで再生中"),
("Post-Render Action: {}", "レンダリング後の処理:{}"),
("Preserve frame rate when nested or in render queue", "ネスト時またはレンダーキュー内でフレームレートを保持"),
diff --cc crates/ui-egui/src/panels/timeline.rs
index 49da29181,238071bda..c2c37aede
--- a/crates/ui-egui/src/panels/timeline.rs
+++ b/crates/ui-egui/src/panels/timeline.rs
@@@ -161,29 -162,11 +163,17 @@@ type PickWhip = (u8, u64, u64, Pos2)
const WHIP_PARENT: u8 = 0;
const WHIP_EXPR: u8 = 1;
const WHIP_PROP: u8 = 2;
+const WHIP_MATTE: u8 = 3;
fn pick_whip_id() -> egui::Id {
- egui::Id::new("tl-pickwhip")
+ egui::Id::unique("tl-pickwhip")
}
+/// The layers a layer pick whip (parent, track matte) links, taken as its drag starts.
+fn whip_layers_id() -> egui::Id {
- egui::Id::new("tl-pickwhip-layers")
- }
-
- /// The layers an edit made on `layer`'s row applies to (its parent, its track matte, moving its
- /// bar): the selection when the row is selected, else that layer alone (#1260).
- fn edited_layers(layer: LayerId, selected: &[LayerId]) -> Vec<u64> {
- if selected.contains(&layer) { selected.iter().map(|l| l.0).collect() } else { vec![layer.0] }
- }
-
- /// The layers a Track Matte edit on `layer`'s row applies to: [`edited_layers`] that can have a
- /// matte. Selected nulls, cameras and lights (no Track Matte on their rows) are left out.
- fn matte_layers(comp: &Comp, layer: LayerId, selected: &[LayerId]) -> Vec<u64> {
- edited_layers(layer, selected).into_iter().filter(|l| comp.layer(LayerId(*l)).is_some_and(|l| l.source.is_av())).collect()
++ egui::Id::unique("tl-pickwhip-layers")
+}
+
/// A pick whip at `rect`: dragging it starts a pick whip of `kind` from `layer`'s `prop` (0 for
/// the layer's own), drawn and dropped at the end of [`show`].
#[allow(clippy::too_many_arguments)]
@@@ -202,15 -185,7 +192,15 @@@ fn pick_whip
app.auto.add(auto, rect, label);
if resp.drag_started() {
let state: PickWhip = (kind, layer, prop, rect.center());
- ui.ctx().data_mut(|d| d.insert_temp(pick_whip_id(), state));
+ let selected = &app.session.state.selected_layers;
+ let layers = match (kind, app.session.active_comp()) {
- (WHIP_MATTE, Some(comp)) => matte_layers(comp, LayerId(layer), selected),
++ (WHIP_MATTE, Some(comp)) => video_targets(comp, LayerId(layer), selected),
+ _ => edited_layers(LayerId(layer), selected),
+ };
+ ui.ctx().data_mut(|d| {
+ d.insert_temp(pick_whip_id(), state);
+ d.insert_temp(whip_layers_id(), layers);
+ });
}
resp
}
@@@ -1341,6 -1365,39 +1380,41 @@@ fn switch_gesture(ui: &egui::Ui, resp:
(a.min(b) < row.max.y && a.max(b) >= row.min.y).then_some((d.value, d.merge))
}
-/// The layers an edit made on `layer`'s row applies to (a switch, its label, its blending mode):
-/// the selection when the row is selected, else that layer alone, as in After Effects.
++/// The layers an edit made on `layer`'s row applies to (a switch, its label, its blending mode,
++/// its parent or track matte, moving its bar): the selection when the row is selected, else that
++/// layer alone, as in After Effects (#1260).
+ fn edited_layers(layer: LayerId, selected: &[LayerId]) -> Vec<u64> {
+ if selected.contains(&layer) { selected.iter().map(|l| l.0).collect() } else { vec![layer.0] }
+ }
+
+ /// Whether the Timeline shows switch `name`'s cell on `layer`'s row (A/V Features and Switches
+ /// columns): a layer that has no such cell isn't one a click gives the switch to either.
+ fn switch_applies(layer: &Layer, name: &str, project: &Project) -> bool {
+ match name {
+ "video" | "lock" | "shy" => true,
+ "audio" => layer.props.sub("audio").is_some(),
+ "solo" | "quality" | "motionBlur" | "adjustment" => layer.source.is_av(),
+ "collapse" => collapse_applies(layer, project),
+ "fx" => layer.effects().is_some_and(|f| !f.children.is_empty()),
+ "frameBlend" => matches!(layer.source, LayerSource::Footage { .. } | LayerSource::Comp { .. }),
+ "threeD" => layer.source.is_av() || matches!(layer.source, LayerSource::Null),
+ _ => true,
+ }
+ }
+
+ /// The layers a click on the `name` switch of `layer`'s row acts on: [`edited_layers`] without
+ /// the layers the switch doesn't apply to.
+ fn switch_targets(comp: &Comp, project: &Project, selected: &[LayerId], layer: u64, name: &str) -> Vec<u64> {
+ edited_layers(LayerId(layer), selected).into_iter().filter(|l| comp.layer(LayerId(*l)).is_some_and(|l| switch_applies(l, name, project))).collect()
+ }
+
-/// The layers a Modes column edit on `layer`'s row (its blending mode, Preserve Transparency)
-/// acts on: [`edited_layers`] that have video.
-fn mode_targets(comp: &Comp, layer: LayerId, selected: &[LayerId]) -> Vec<u64> {
++/// The layers a Modes column edit (blending mode, Preserve Transparency) or a Track Matte edit
++/// on `layer`'s row acts on: [`edited_layers`] that have video. Selected nulls, cameras and
++/// lights (no Modes or Track Matte on their rows) are left out.
++fn video_targets(comp: &Comp, layer: LayerId, selected: &[LayerId]) -> Vec<u64> {
+ edited_layers(layer, selected).into_iter().filter(|l| comp.layer(LayerId(*l)).is_some_and(|l| l.source.is_av())).collect()
+ }
+
/// A layer's switch (A/V Features and Switches columns) in `row`, with the
/// [`switch_gesture`].
#[allow(clippy::too_many_arguments)]
@@@ -2170,25 -2327,24 +2344,35 @@@ pub fn show(app: &mut EffectcraftApp, u
.flat_map(|m| if m.ends_group() { vec![m.label().to_string(), "-".to_string()] } else { vec![m.label().to_string()] })
.collect();
if let Some(i) = widgets::popup_menu(ui, pop, mr.left_bottom(), &opts, opts.iter().position(|o| o == layer.blend_mode.label())) {
- actions.push(("layer.setBlendMode".into(), json!({"layers": [layer.id.0], "mode": opts[i]})));
- actions.push(("layer.setBlendMode".into(), json!({"layers": mode_targets(&comp, layer.id, &selected), "mode": opts[i]})));
++ actions.push(("layer.setBlendMode".into(), json!({"layers": video_targets(&comp, layer.id, &selected), "mode": opts[i]})));
}
let tr = Rect::from_center_size(pos2(cw.mode + 76.0 + 6.0, cy), vec2(14.0, 14.0));
- if widgets::checkbox(ui, tr, layer.preserve_transparency, &t, egui::Id::new(("pt", layer.id.0))).clicked() {
- actions.push(("layer.setSwitch".into(), json!({"layers": [layer.id.0], "switch": "preserveTransparency"})));
+ app.auto.add(&format!("timeline.layer.{}.preserveTransparency", layer.id.0), tr, "Preserve Transparency");
+ if widgets::checkbox(ui, tr, layer.preserve_transparency, &t, egui::Id::unique(("pt", layer.id.0))).clicked() {
+ // The click gives the selection the state the clicked row toggles to,
+ // whatever the first selected layer's value (as the switches do).
+ actions.push((
+ "layer.setSwitch".into(),
+ json!({
- "layers": mode_targets(&comp, layer.id, &selected),
++ "layers": video_targets(&comp, layer.id, &selected),
+ "switch": "preserveTransparency",
+ "value": !layer.preserve_transparency
+ }),
+ ));
}
- // Track matte: layer picker + kind.
- let mr = Rect::from_min_size(pos2(cw.trkmat + 2.0, cy - 9.0), vec2(104.0, 18.0));
+ // Track matte: a pick whip, then the layer picker with the mode. Like the parent,
+ // they set the matte of every selected layer when the row is selected (#1260).
+ pick_whip(
+ app,
+ ui,
+ &lp,
+ Rect::from_center_size(pos2(cw.trkmat + 9.0, cy), vec2(15.0, 15.0)),
+ (WHIP_MATTE, layer.id.0, 0),
+ &format!("timeline.layer.{}.trackMattePickWhip", layer.id.0),
+ "Track Matte pick whip",
+ crate::i18n::tr("Track Matte pick whip: drag onto a layer"),
+ );
+ let mr = Rect::from_min_size(pos2(cw.trkmat + 20.0, cy - 9.0), vec2(88.0, 18.0));
let label = match layer.track_matte {
Some(m) => comp.layer(m.layer).map(|l| format!("{} {}", idx_of(l.id), l.name)).unwrap_or("None".into()),
None => "No Track Matte".into(),
@@@ -2218,7 -2374,7 +2402,7 @@@
let current = layer.track_matte.and_then(|m| opts.iter().position(|o| o == m.kind.label()));
if let Some(i) = widgets::popup_menu(ui, pop, mr.left_bottom(), &opts, current) {
let ids: Vec<LayerId> = candidates.iter().map(|l| l.id).collect();
- if let Some(a) = opts.get(i).and_then(|o| track_matte_pick(&matte_layers(&comp, layer.id, &selected), &ids, i, o)) {
- if let Some(a) = opts.get(i).and_then(|o| track_matte_pick(layer, &ids, i, o)) {
++ if let Some(a) = opts.get(i).and_then(|o| track_matte_pick(&video_targets(&comp, layer.id, &selected), &ids, i, o)) {
actions.push(a);
}
}
diff --cc crates/ui-egui/tests/it/main.rs
index 000000000,b5492c1b5..a020d69cf
mode 000000,100644..100644
--- a/crates/ui-egui/tests/it/main.rs
+++ b/crates/ui-egui/tests/it/main.rs
@@@ -1,0 -1,104 +1,105 @@@
+ //! The crate's integration tests, one binary (each module is a former `tests/<name>.rs`).
+
+ mod render_queue_snapshot;
+ mod shared_docking_ui;
+ mod ui_3d;
+ mod ui_agent_audit;
+ mod ui_angles;
+ mod ui_audio_scrub;
+ mod ui_azerty_shortcuts;
++mod ui_batch_links;
+ mod ui_batch_switches;
+ mod ui_blank_context_menus;
+ mod ui_camera_tracker;
+ mod ui_character_eyedropper;
+ mod ui_color_hex;
+ mod ui_comp_presets;
+ mod ui_control_modifiers;
+ mod ui_dock_resize;
+ mod ui_drag_drop;
+ mod ui_effect_controls;
+ mod ui_effect_drop_highlight;
+ mod ui_effect_names;
+ mod ui_font_search;
+ mod ui_form_fit;
+ mod ui_frame_step;
+ mod ui_fx_editors;
+ mod ui_gpu;
+ mod ui_gradient_editor;
+ mod ui_gradient_handles;
+ mod ui_gradient_value;
+ mod ui_graph_fit;
+ mod ui_group_rename;
+ mod ui_guide_layers;
+ mod ui_inline_edit;
+ mod ui_keyframes;
+ mod ui_large_project;
+ mod ui_layer_panel_zoom;
+ mod ui_layer_source_picker;
+ mod ui_light_settings;
+ mod ui_live_preview;
+ mod ui_locked_color;
+ mod ui_media_browser_cache;
+ mod ui_media_browser_copy_path;
+ mod ui_menus;
+ mod ui_new_primitive;
+ mod ui_object_matte;
+ mod ui_panel_focus;
+ mod ui_panel_windows;
+ mod ui_panels;
+ mod ui_parameter_spacing;
+ mod ui_presets_folder;
+ mod ui_preview_align;
+ mod ui_project_delete;
+ mod ui_project_duplicate;
+ mod ui_project_keyboard;
+ mod ui_project_new_folder;
+ mod ui_project_rows;
+ mod ui_quick_offset;
+ mod ui_ram_preview;
+ mod ui_render_queue;
+ mod ui_script_console;
+ mod ui_scriptui;
+ mod ui_scrolling;
+ mod ui_settings_info;
+ mod ui_tabs;
+ mod ui_tail;
+ mod ui_text_edit;
+ mod ui_text_range_handles;
+ mod ui_theme_favorites;
+ mod ui_time_zoom_controls;
+ mod ui_timeline_effect_label;
+ mod ui_timeline_pan;
+ mod ui_timeline_shapes;
+ mod ui_timeline_switches;
+ mod ui_timeline_trim;
+ mod ui_timeline_zoom;
+ mod ui_toolbar_gradient;
+ mod ui_tracker;
+ mod ui_unreadable_footage;
+ mod ui_video_preview_off;
+ mod ui_viewer;
+ mod ui_viewers;
+ mod ui_visual_review;
+ mod ui_web_gpu_storage;
+ mod ui_web_job_gpu;
+ mod ui_web_offload;
+ mod ui_workflow_selection;
+ mod ui_workspace_focus;
+ mod viewer_geometry;
+ mod viewer_passive_display;
+
+ /// Register the managed build's canonical craft-fonts checkout (`CRAFT_FONTS_DIR/fonts`) through
+ /// the same directory source production scans for `EFFECTCRAFT_FONT_DIRS`. The UI tests then render
+ /// real Japanese glyphs from the canonical external input instead of relying on host fonts.
+ pub(crate) fn add_canonical_test_fonts() {
+ use effectcraft_text::fonts::{self, DirectorySource};
+ static REGISTER: std::sync::Once = std::sync::Once::new();
+ REGISTER.call_once(|| {
+ let Some(root) = std::env::var_os("CRAFT_FONTS_DIR") else { return };
+ let dir = std::path::PathBuf::from(root).join("fonts");
+ if dir.is_dir() {
+ fonts::add_source(&DirectorySource { dirs: vec![dir] });
+ }
+ });
+ }
diff --cc crates/ui-egui/tests/it/ui_batch_links.rs
index ce5845faa,000000000..5b2cea090
mode 100644,000000..100644
--- a/crates/ui-egui/tests/it/ui_batch_links.rs
+++ b/crates/ui-egui/tests/it/ui_batch_links.rs
@@@ -1,205 -1,0 +1,209 @@@
+//! Parent and Track Matte for several layers at once (#1260): on a selected layer's row, the
+//! Timeline's Parent and Track Matte menus and pick whips set every selected layer; on an
+//! unselected row, that layer alone. One undo step each; each layer keeps its own matte mode.
+
+use effectcraft_engine::Session;
+use effectcraft_engine::project::{LayerId, MatteKind};
+use effectcraft_ui_egui::EffectcraftApp;
+use egui::{Event, Modifiers, PointerButton, Pos2, Rect, pos2, vec2};
+use egui_kittest::Harness;
+use egui_kittest::kittest::Queryable as _;
+use serde_json::json;
+
+/// Solids A, B, C, P (moved and scaled, a parent) and the mattes X and Y; stacked Y, X, P, C, B, A
+/// from the top. The Track Matte column is shown.
+fn harness() -> (Harness<'static, EffectcraftApp>, [u64; 6]) {
+ let mut s = Session::default();
+ s.execute("comp.new", json!({"name": "Links", "width": 320, "height": 180, "duration": 4})).unwrap();
+ let ids = ["A", "B", "C", "P", "X", "Y"]
+ .map(|n| s.execute("layer.newSolid", json!({"name": n, "color": "#406080", "width": 40, "height": 40})).unwrap()["layer"].as_u64().unwrap());
+ s.execute("prop.set", json!({"layer": ids[3], "path": "transform/position", "value": [60, 40]})).unwrap();
+ s.execute("prop.set", json!({"layer": ids[3], "path": "transform/scale", "value": [50, 50]})).unwrap();
+ s.history.undo.clear();
+ let mut h = Harness::builder().with_size(vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
+ h.state_mut().ui.timeline.show_modes = true;
+ h.state_mut().ui.timeline.columns_w = 900.0;
+ h.run_steps(3);
+ (h, ids)
+}
+
+fn rect(h: &Harness<'_, EffectcraftApp>, id: &str) -> Rect {
+ let e = h.state().auto.find(id).unwrap_or_else(|| panic!("no {id}"));
+ Rect::from_min_size(pos2(e.rect[0], e.rect[1]), vec2(e.rect[2], e.rect[3]))
+}
+
+fn press(h: &mut Harness<'_, EffectcraftApp>, at: Pos2, pressed: bool) {
+ h.event(Event::PointerButton { pos: at, button: PointerButton::Primary, pressed, modifiers: Modifiers::NONE });
+}
+
+fn click(h: &mut Harness<'_, EffectcraftApp>, at: Pos2) {
+ h.event(Event::PointerMoved(at));
+ h.step();
+ press(h, at, true);
+ h.step();
+ press(h, at, false);
+ h.run_steps(3);
+}
+
+/// Open the menu at automation id `dropdown` and choose `item` in it.
+fn choose(h: &mut Harness<'_, EffectcraftApp>, dropdown: &str, item: &str) {
+ let menu = rect(h, dropdown);
++ // Other rows' menus show their choice as well ("No Track Matte"): the entry is a node the
++ // opened menu added.
++ let shown: Vec<Rect> = h.query_all_by_label(item).map(|n| n.rect()).collect();
+ click(h, menu.center());
+ // (The menu may open above it to fit the window: the entry nearest to it.)
+ let off = |r: &Rect| (r.center().y - menu.center().y).abs();
- let at = h.query_all_by_label(item).map(|n| n.rect()).min_by(|a, b| off(a).total_cmp(&off(b)));
++ let at = h.query_all_by_label(item).map(|n| n.rect()).filter(|r| !shown.contains(r)).min_by(|a, b| off(a).total_cmp(&off(b)));
+ let at = at.unwrap_or_else(|| panic!("no {item} in the {dropdown} menu")).center();
+ click(h, at);
+}
+
+/// Drag the pick whip `whip` onto layer `onto`'s row.
+fn whip(h: &mut Harness<'_, EffectcraftApp>, whip: &str, onto: u64) {
+ let (from, to) = (rect(h, whip).center(), rect(h, &format!("timeline.layer.{onto}.row")).center());
+ h.event(Event::PointerMoved(from));
+ h.step();
+ press(h, from, true);
+ h.step();
+ for i in 1..=10 {
+ h.event(Event::PointerMoved(from + (to - from) * (i as f32 / 10.0)));
+ h.step();
+ }
+ press(h, to, false);
+ h.run_steps(3);
+}
+
+fn select(h: &mut Harness<'_, EffectcraftApp>, ids: &[u64]) {
+ h.state_mut().session.execute("layer.select", json!({"layers": ids})).unwrap();
+ h.run_steps(2);
+}
+
+fn parent(h: &Harness<'_, EffectcraftApp>, id: u64) -> Option<u64> {
+ h.state().session.active_comp().unwrap().layer(LayerId(id)).unwrap().parent.map(|p| p.0)
+}
+
+fn position(h: &Harness<'_, EffectcraftApp>, id: u64) -> [f64; 3] {
+ h.state().session.active_comp().unwrap().layer(LayerId(id)).unwrap().props.prop("transform/position").unwrap().value.as_vec3()
+}
+
+fn matte(h: &Harness<'_, EffectcraftApp>, id: u64) -> Option<(u64, MatteKind)> {
+ h.state().session.active_comp().unwrap().layer(LayerId(id)).unwrap().track_matte.map(|m| (m.layer.0, m.kind))
+}
+
+/// The project and its undo steps as they are now, to compare with after an undo or a refusal.
+fn mark(h: &Harness<'_, EffectcraftApp>) -> (std::sync::Arc<effectcraft_engine::project::Project>, usize) {
+ (h.state().session.project.clone(), h.state().session.history.undo.len())
+}
+
+fn unchanged(h: &Harness<'_, EffectcraftApp>, m: &(std::sync::Arc<effectcraft_engine::project::Project>, usize)) -> bool {
+ h.state().session.project.same_content(&m.0) && h.state().session.history.undo.len() == m.1
+}
+
+#[test]
+fn parent_menu_and_pick_whip_parent_the_selected_layers() {
+ let (mut h, [a, b, c, p, ..]) = harness();
+ let start = position(&h, a);
+ select(&mut h, &[a, b]);
+ let before = mark(&h);
+ // The Parent menu on A's (selected) row parents A and B, kept where they are.
+ choose(&mut h, &format!("timeline.layer.{a}.parent"), "3. P");
+ assert_eq!([parent(&h, a), parent(&h, b), parent(&h, c)], [Some(p), Some(p), None]);
+ assert!(position(&h, a) != start && position(&h, a) == position(&h, b), "both re-expressed in P's space");
+ assert_eq!(h.state().session.history.undo.len(), before.1 + 1, "one undo step");
+ h.state_mut().session.execute("edit.undo", json!({})).unwrap();
+ h.run_steps(2);
+ assert!(unchanged(&h, &before), "one undo puts both back");
+ // The pick whip of an unselected row parents that layer alone.
+ whip(&mut h, &format!("timeline.layer.{c}.pickWhip"), p);
+ assert_eq!([parent(&h, a), parent(&h, b), parent(&h, c)], [None, None, Some(p)]);
+ // A selected row's whip parents the selection, less the parent itself if selected.
+ select(&mut h, &[a, b, p]);
+ whip(&mut h, &format!("timeline.layer.{a}.pickWhip"), p);
+ assert_eq!([parent(&h, a), parent(&h, b), parent(&h, p)], [Some(p), Some(p), None]);
+ // A cycle (P under A, while A is under P) is refused as a whole.
+ select(&mut h, &[p, c]);
+ let before = mark(&h);
+ choose(&mut h, &format!("timeline.layer.{p}.parent"), "6. A");
+ assert!(unchanged(&h, &before), "the refused parenting changed nothing");
+ assert_eq!([parent(&h, p), parent(&h, c)], [None, Some(p)]);
+}
+
+#[test]
+fn track_matte_menu_and_pick_whip_set_the_selected_layers_mattes() {
+ let (mut h, [a, b, c, _, x, y]) = harness();
+ h.state_mut().session.execute("layer.setTrackMatte", json!({"layer": a, "matte": x, "kind": "luma"})).unwrap();
+ h.state_mut().session.execute("layer.setTrackMatte", json!({"layer": b, "matte": x, "kind": "alpha"})).unwrap();
+ select(&mut h, &[a, b]);
+ let before = mark(&h);
+ // A new matte layer for both; each keeps its mode; C (not selected) keeps none.
+ choose(&mut h, &format!("timeline.layer.{a}.trackMatte"), "1. Y");
+ assert_eq!([matte(&h, a), matte(&h, b), matte(&h, c)], [Some((y, MatteKind::Luma)), Some((y, MatteKind::Alpha)), None]);
+ assert!(!h.state().session.active_comp().unwrap().layer(LayerId(y)).unwrap().switches.video, "Y is hidden as a matte");
+ h.state_mut().session.execute("edit.undo", json!({})).unwrap();
+ h.run_steps(2);
+ assert!(unchanged(&h, &before), "one undo puts both mattes and Y's visibility back");
+ // A mode for both, then No Track Matte for both.
+ choose(&mut h, &format!("timeline.layer.{b}.trackMatte"), "Luma Inverted Matte");
+ assert_eq!([matte(&h, a), matte(&h, b)], [Some((x, MatteKind::LumaInverted)), Some((x, MatteKind::LumaInverted))]);
+ choose(&mut h, &format!("timeline.layer.{a}.trackMatte"), "No Track Matte");
+ assert_eq!([matte(&h, a), matte(&h, b)], [None, None]);
+ // The track matte pick whip: a selected row's sets the selection's, an unselected row's
+ // its own.
+ whip(&mut h, &format!("timeline.layer.{a}.trackMattePickWhip"), y);
+ assert_eq!([matte(&h, a), matte(&h, b), matte(&h, c)], [Some((y, MatteKind::Alpha)), Some((y, MatteKind::Alpha)), None]);
+ whip(&mut h, &format!("timeline.layer.{c}.trackMattePickWhip"), x);
+ assert_eq!([matte(&h, a), matte(&h, c)], [Some((y, MatteKind::Alpha)), Some((x, MatteKind::Alpha))]);
+}
+
+fn video(h: &Harness<'_, EffectcraftApp>, id: u64) -> bool {
+ h.state().session.active_comp().unwrap().layer(LayerId(id)).unwrap().switches.video
+}
+
- /// A selected layer locked with its Lock switch stays selected, and keeps its parent, its
- /// transform and its matte while another selected row's menus and pick whips change the rest.
++/// A locked layer in the selection stays selected, and keeps its parent, its transform and its
++/// matte while another selected row's menus and pick whips change the rest.
+#[test]
+fn locked_selected_layers_keep_their_parent_and_matte() {
+ let (mut h, [a, b, c, _, x, _]) = harness();
+ select(&mut h, &[a, b]);
- let at = rect(&h, &format!("timeline.layer.{b}.lock")).center();
- click(&mut h, at);
++ // B alone (a click on its Lock switch locks the whole selection).
++ h.state_mut().session.execute("layer.setSwitch", json!({"layers": [b], "switch": "lock", "value": true})).unwrap();
++ h.run_steps(2);
+ let selected: Vec<u64> = h.state().session.state.selected_layers.iter().map(|l| l.0).collect();
+ assert!(h.state().session.active_comp().unwrap().layer(LayerId(b)).unwrap().switches.locked && selected == vec![a, b], "{selected:?}");
+ let b_position = position(&h, b);
+ choose(&mut h, &format!("timeline.layer.{a}.parent"), "3. P");
+ whip(&mut h, &format!("timeline.layer.{a}.pickWhip"), c);
+ choose(&mut h, &format!("timeline.layer.{a}.trackMatte"), "1. Y");
+ whip(&mut h, &format!("timeline.layer.{a}.trackMattePickWhip"), x);
+ assert_eq!((parent(&h, a), matte(&h, a)), (Some(c), Some((x, MatteKind::Alpha))), "A changed each time");
+ assert_eq!((parent(&h, b), matte(&h, b), position(&h, b)), (None, None, b_position), "locked B didn't");
+}
+
+/// Selected nulls (no Track Matte on their rows) get no matte from another row's menu or pick
+/// whip: at the top of the comp one used to refuse the whole mode change (nothing above it to
+/// take as a matte), at the bottom it took the layer above as its matte and hid it.
+#[test]
+fn selected_nulls_get_no_matte() {
+ let (mut h, [a, b, _, _, x, y]) = harness();
+ h.state_mut().session.execute("layer.setTrackMatte", json!({"layers": [a, b], "matte": x, "kind": "alpha"})).unwrap();
+ let n = h.state_mut().session.execute("layer.newNull", json!({"name": "N"})).unwrap()["layer"].as_u64().unwrap();
+ select(&mut h, &[a, b, n]);
+ choose(&mut h, &format!("timeline.layer.{a}.trackMatte"), "Luma Matte");
+ assert_eq!([matte(&h, a), matte(&h, b), matte(&h, n)], [Some((x, MatteKind::Luma)), Some((x, MatteKind::Luma)), None], "a null on top");
+ h.state_mut().session.execute("layer.arrange", json!({"layers": [n], "to": "back"})).unwrap();
+ select(&mut h, &[a, b, n]);
+ choose(&mut h, &format!("timeline.layer.{a}.trackMatte"), "Alpha Inverted Matte");
+ assert_eq!(
+ [matte(&h, a), matte(&h, b), matte(&h, n)],
+ [Some((x, MatteKind::AlphaInverted)), Some((x, MatteKind::AlphaInverted)), None],
+ "a null at the bottom"
+ );
+ assert!(video(&h, a), "A wasn't hidden as the null's matte");
+ whip(&mut h, &format!("timeline.layer.{a}.trackMattePickWhip"), y);
+ assert_eq!(
+ [matte(&h, a), matte(&h, b), matte(&h, n)],
+ [Some((y, MatteKind::AlphaInverted)), Some((y, MatteKind::AlphaInverted)), None],
+ "the pick whip too"
+ );
+}