Skip to content

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

Merge pull request #984 from MarekSpodBiedry/issue-957

Brandon Thomas84c6281da9bf
diff --cc crates/ui-egui/src/panels/timeline.rs
index 186ebef7a,ce44cde5a..032037b76
--- a/crates/ui-egui/src/panels/timeline.rs
+++ b/crates/ui-egui/src/panels/timeline.rs
@@@ -3494,24 -3442,21 +3494,37 @@@ fn prop_menu
item(ui, "essentialGraphics", "Add Property to Essential Graphics", false, "essential.addProperty", json!({"comp": comp.0, "layer": l, "prop": uid}));
}
+/// A layer row's or bar's context menu. As in After Effects, right-clicking a layer that is part
+/// of the selection keeps the selection and the menu acts on all of it; right-clicking an
+/// unselected layer selects only that layer.
+pub(crate) fn vector_footage_layer(project: &effectcraft_engine::project::Project, layer: &Layer) -> bool {
+ layer
+ .source
+ .item()
+ .and_then(|item| project.item(item))
+ .is_some_and(|item| matches!(&item.kind, effectcraft_engine::project::ItemKind::Footage(footage) if effectcraft_engine::vector::is_vector(footage)))
+}
+
+ /// Whether the Collapse Transformations / Continuously Rasterize switch applies: precomps, shape and text
+ /// layers, and vector footage (SVG, PDF, AI, EPS), which the renderer re-rasterizes at the layer's scale.
+ fn collapse_applies(layer: &Layer, project: &effectcraft_engine::project::Project) -> bool {
+ match &layer.source {
+ LayerSource::Comp { .. } | LayerSource::Shape | LayerSource::Text => true,
+ LayerSource::Footage { item } => {
+ let kind = project.item(*item).map(|i| &i.kind);
+ matches!(kind, Some(effectcraft_engine::project::ItemKind::Footage(f)) if effectcraft_engine::render::is_vector_footage(f))
+ }
+ _ => false,
+ }
+ }
+
-fn layer_context_menu(resp: &egui::Response, layer: &Layer, actions: &mut Vec<(String, serde_json::Value)>) {
- resp.context_menu(|ui| layer_menu(ui, &[layer.id.0], actions));
+fn layer_context_menu(resp: &egui::Response, comp: &Comp, layer: &Layer, selected: &[LayerId], vector: bool, actions: &mut Vec<(String, serde_json::Value)>) {
+ let in_selection = selected.contains(&layer.id);
+ if resp.secondary_clicked() && !in_selection && !layer.switches.locked {
+ actions.push(("layer.select".into(), json!({"layers": [layer.id.0]})));
+ }
+ let targets: Vec<u64> = if in_selection { comp.layers.iter().filter(|l| selected.contains(&l.id)).map(|l| l.id.0).collect() } else { vec![layer.id.0] };
+ crate::widgets::context_menu(resp, |ui| layer_menu(ui, &targets, vector, actions));
}
/// Shared layer actions for Timeline rows and Composition context menus.
@@@ -3801,40 -3711,24 +3814,58 @@@ mod tests
assert!(edge_scroll_speed_x(100.0, 500.0, 600.0) > edge_scroll_speed_x(100.0, 500.0, 520.0));
}
+ /// #864: picking only a mode in a layer's Track Matte menu sets a matte (the layer above);
+ /// it used to close the menu and change nothing.
+ #[test]
+ fn a_track_matte_mode_without_a_matte_takes_the_layer_above() {
+ let mut s = effectcraft_engine::Session::default();
+ s.execute("comp.new", json!({"name": "T", "width": 64, "height": 64, "duration": 1})).unwrap();
+ for name in ["Chain Bottom", "Matte", "Chain Top"] {
+ s.execute("layer.newSolid", json!({"name": name, "color": "#ffffff", "width": 64, "height": 64})).unwrap();
+ }
+ let find = |s: &effectcraft_engine::Session, n: &str| s.active_comp().unwrap().layers.iter().find(|l| l.name == n).unwrap().clone();
+ let (bottom, matte, top) = (find(&s, "Chain Bottom"), find(&s, "Matte"), find(&s, "Chain Top"));
+ let candidates = [top.id, matte.id];
+ let pick = |s: &mut effectcraft_engine::Session, name: &str, i: usize, choice: &str| {
+ let (id, params) = track_matte_pick(&find(s, name), &candidates, i, choice).expect("a menu item is an action");
+ s.execute(&id, params)
+ };
+ pick(&mut s, "Chain Bottom", 5, "Alpha Inverted Matte").unwrap();
+ let m = find(&s, "Chain Bottom").track_matte.expect("a matte");
+ assert_eq!((m.layer, m.kind), (matte.id, MatteKind::AlphaInverted));
+ assert!(!find(&s, "Matte").switches.video, "the matte layer is hidden");
+ // A mode change keeps the matte layer; a matte change keeps the mode.
+ pick(&mut s, "Chain Bottom", 6, "Luma Matte").unwrap();
+ assert_eq!(find(&s, "Chain Bottom").track_matte.map(|m| (m.layer, m.kind)), Some((matte.id, MatteKind::Luma)));
+ pick(&mut s, "Chain Bottom", 2, "1. Chain Top").unwrap();
+ assert_eq!(find(&s, "Chain Bottom").track_matte.map(|m| (m.layer, m.kind)), Some((top.id, MatteKind::Luma)));
+ assert!(s.undo());
+ assert_eq!(find(&s, "Chain Bottom").track_matte.map(|m| m.layer), Some(matte.id), "one undo step per pick");
+ // The top layer has nothing above it: an error for the status bar, not a silent no-op.
+ assert!(pick(&mut s, "Chain Top", 5, "Alpha Matte").is_err());
+ pick(&mut s, "Chain Bottom", 0, "No Track Matte").unwrap();
+ assert!(find(&s, "Chain Bottom").track_matte.is_none());
+ assert!(track_matte_pick(&bottom, &candidates, 1, "-").is_none(), "a separator does nothing");
+ }
+
+ /// #957: vector footage gets the Continuously Rasterize switch; raster footage does not.
+ #[test]
+ fn collapse_switch_shows_for_vector_footage_only() {
+ use effectcraft_engine::color::Label;
+ use effectcraft_engine::project::{Footage, ItemKind, Project};
+ let mut p = Project::default();
+ let mut layer_for = |name: &str, codec: &str| {
+ let footage = Footage { path: name.into(), codec: codec.into(), ..Default::default() };
+ let item = p.add_item(name, Label::SeaFoam, None, ItemKind::Footage(footage));
+ let comp = Comp::new(64, 36, effectcraft_engine::time::FrameRate::new(30, 1), Tick::from_seconds_f64(1.0));
+ effectcraft_engine::project::build::layer(&mut p, &comp, name, LayerSource::Footage { item }, (0, 0), None)
+ };
+ let svg = layer_for("logo.svg", "SVG");
+ let png = layer_for("photo.png", "PNG");
+ assert!(collapse_applies(&svg, &p));
+ assert!(!collapse_applies(&png, &p));
+ }
+
/// A comp with two solids; "Box" has an animated Position and a Gaussian Blur.
fn app() -> EffectcraftApp {
let mut s = effectcraft_engine::Session::default();