EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust
Merge pull request #462 from storytold/fix/417-viewer-resolution
Brandon Thomasb2d05582e003
diff --cc crates/ui-egui/src/control.rsindex 724f34024,669ecd30d..9254226cd--- a/crates/ui-egui/src/control.rs+++ b/crates/ui-egui/src/control.rs@@@ -507,21 -515,11 +515,26 @@@ pub fn base64(data: &[u8]) -> Stringpub fn inspect(app: &EffectcraftApp, ctx: &egui::Context) -> Value {let size = ctx.content_rect().size();+ let keyboard_focus = ctx.memory(|m| m.focused()).map(|id| {+ let response = ctx.read_response(id);+ let rect = response.as_ref().map(|r| [r.rect.min.x, r.rect.min.y, r.rect.width(), r.rect.height()]);+ // The registry names screen elements independently of egui's internal ids. Report+ // exact rectangle matches rather than guessing which enclosing panel owns focus.+ let candidates: Vec<&str> = app+ .auto+ .previous+ .iter()+ .filter(|e| rect.is_some_and(|r| e.rect.iter().zip(r).all(|(a, b)| (*a - b).abs() < 0.01)))+ .map(|e| e.id.as_str())+ .collect();+ let automation_id = app.auto.elements.iter().chain(app.auto.previous.iter()).find(|e| e.response_id == Some(id)).map(|e| e.id.as_str());+ json!({"id": format!("{:016x}", id.value()), "rect": rect, "automationId": automation_id, "registryCandidates": candidates})+ });+ let mut ui = json!(app.ui);+ // The viewer's Resolution is the active comp's (kept in the project).+ if let Some(v) = ui.get_mut("viewer").and_then(Value::as_object_mut) {+ v.insert("res".into(), json!(app.viewer_res()));+ }json!({"window": [size.x, size.y],"pixelsPerPoint": ctx.pixels_per_point(),diff --cc crates/ui-egui/src/menus.rsindex 71f951dfb,ee09ae7a5..00fdc3892--- a/crates/ui-egui/src/menus.rs+++ b/crates/ui-egui/src/menus.rs@@@ -529,14 -458,6 +528,11 @@@ pub fn invoke(app: &mut EffectcraftAppcrate::panels::markers_ui::open_dialog(app, crate::panels::markers_ui::MarkerRef { layer, index })?;return Ok(json!({"dialog": id}));}- if id == "view.res.auto" {- app.ui.viewer.res = Resolution::Auto;- return Ok(Value::Null);- }+++ if id == "view.theme.toggle" {+ app.cycle_appearance(ctx);+ return Ok(json!({"appearanceMode": app.session.prefs.appearance.appearance_mode}));+ }if let Some(th) = id.strip_prefix("view.theme.") {let k = crate::theme::ThemeKind::from_name(th).ok_or("unknown theme")?;app.set_theme(ctx, k);@@@ -1450,12 -1255,7 +1432,9 @@@ pub(crate) fn entry_checked(app: &Effec"view.layerControls" => Some(v.show_layer_controls),"playback.cacheWhenIdle" => Some(app.ui.cache_when_idle),"playback.audio" => Some(app.session.prefs.preview.active().include_audio),- "view.res.full" | "view.res.half" | "view.res.third" | "view.res.quarter" => {- Some(v.res.label().eq_ignore_ascii_case(e.command.trim_start_matches("view.res.")))- }"window.workspace" => Some(pstr("name").is_some_and(|n| n == app.ui.workspace)),+ // The Tools panel is the header toolbar: always on screen.+ "window.panel" => Some(pstr("panel").is_some_and(|n| n.eq_ignore_ascii_case("tools") || PanelKind::from_name(n).is_some_and(|p| panel_shown(app, p)))),"view.panelBackground" if e.params.get("pick").is_none() => {let cur = match v.pasteboard {None => "mediumGray",diff --cc crates/ui-egui/src/native_menu.rsindex 10a75fbe6,2bd0b6374..874a72c60--- a/crates/ui-egui/src/native_menu.rs+++ b/crates/ui-egui/src/native_menu.rs@@@ -314,10 -310,7 +314,9 @@@ pub fn state_key(app: &EffectcraftApp)s.keymaps.active.hash(&mut h);let v = &app.ui.viewer;(v.rulers, v.guides, v.snap_guides, v.lock_guides, v.grid, v.snap_grid, v.show_layer_controls, v.pasteboard).hash(&mut h);- v.res.label().hash(&mut h);(app.ui.cache_when_idle, app.session.prefs.preview.active().include_audio, &app.ui.workspace, app.dialog.is_some()).hash(&mut h);+ // Window menu check marks: the panels on screen.+ crate::dock::PanelKind::ALL.iter().filter(|p| crate::menus::panel_shown(app, **p)).for_each(|p| p.hash(&mut h));h.finish()}diff --cc crates/ui-egui/src/panels/viewer_tools.rsindex 68b522f37,c2d6946a3..680d21995--- a/crates/ui-egui/src/panels/viewer_tools.rs+++ b/crates/ui-egui/src/panels/viewer_tools.rs@@@ -629,13 -574,14 +629,13 @@@ fn bottom_bar_contents(app: &mut Effect// Resolution / down-sample factor.let r = Rect::from_min_size(pos2(x, cy - 10.0), vec2(84.0, 20.0));let scale = app.viewer_scale(zoom, ppp);- let response = widgets::dropdown(ui, r, &resolution_label(app.ui.viewer.res, scale), &t, egui::Id::new("vw-res"))+ let res = app.viewer_res();- if widgets::dropdown(ui, r, &resolution_label(res, scale), &t, egui::Id::new("vw-res"))- .on_hover_text(crate::i18n::tr("Resolution/Down Sample Factor Popup"))- .clicked()- {++ let response = widgets::dropdown(ui, r, &resolution_label(res, scale), &t, egui::Id::new("vw-res"))+ .on_hover_text(crate::i18n::tr("Resolution/Down Sample Factor Popup"));+ if response.clicked() {toggle_popup(ui, "vw-res-pop");}- app.auto.add("viewer.resolution", r, "Resolution/Down Sample Factor");+ app.auto.add_response("viewer.resolution", &response, "Resolution/Down Sample Factor");- let res = app.ui.viewer.res;let items: Vec<(String, bool)> = vec![("Full".into(), res == Resolution::Full),("Half".into(), res == Resolution::Half),diff --cc crates/ui-egui/tests/ui_viewer.rsindex b7c732ce7,5d6088acc..0768b081b--- a/crates/ui-egui/tests/ui_viewer.rs+++ b/crates/ui-egui/tests/ui_viewer.rs@@@ -1887,90 -1669,6 +1937,90 @@@ fn full_resolution_frames_wider_than_th}std::thread::sleep(std::time::Duration::from_millis(5));}- assert!(full(&mut h), "the full-size frame is shown (and stays readable): {:?}", h.state().ui.viewer.res);+ assert!(full(&mut h), "the full-size frame is shown (and stays readable): {:?}", h.state().viewer_res());assert_eq!(h.state().viewer_texture_size(), Some([800, 134]), "2400×400 averaged by 3");}++/// #509: ⌘/Ctrl-drag in the Layer panel resizes the Roto Brush (as in After Effects) without+/// painting, the next stroke uses the new size, and the tool options show the Diameter.+#[test]+fn roto_brush_ctrl_drag_resizes_the_brush() {+ let mut h = harness();+ let id = h.state().session.active_comp().unwrap().layers.iter().find(|l| l.name == "Box").unwrap().id.0;+ h.state_mut().session.execute("layer.select", json!({"layers": [id]})).unwrap();+ h.state_mut().ui.layer_panel = Some(id);+ h.state_mut().show_panel(effectcraft_ui_egui::dock::PanelKind::Layer);+ h.state_mut().ui.tool = Tool::RotoBrush;+ h.run_steps(3);+ assert!(h.state().auto.find("header.roto.diameter").is_some(), "the Diameter field");+ let canvas = rect(&h, "layerPanel.canvas");+ let zoom = canvas.width() / 80.0;+ let c = canvas.center();+ h.input_mut().events.push(Event::ModifiersChanged(egui::Modifiers::COMMAND));+ drag(&mut h, c, c + vec2(20.0 * zoom, 0.0));+ h.input_mut().events.push(Event::ModifiersChanged(egui::Modifiers::NONE));+ h.run_steps(2);+ let dia = h.state().session.state.roto.diameter;+ assert!((dia - 40.0).abs() <= 1.0, "a 20 px drag makes a 40 px brush: {dia}");+ let strokes = |h: &Harness<'_, EffectcraftApp>| {+ let l = h.state().session.active_comp().unwrap().layer(LayerId(id)).unwrap().clone();+ let roto = effectcraft_engine::effects::roto::ID;+ let g = l+ .effects()+ .and_then(|fx| fx.groups().find(|g| matches!(&g.kind, effectcraft_engine::project::GroupKind::Effect { effect } if effect == roto)).cloned());+ g.map(|g| effectcraft_engine::effects::roto::data(&effectcraft_engine::effects::flatten_params(&g, &mut |p| p.value.clone())).strokes.clone())+ .unwrap_or_default()+ };+ assert!(strokes(&h).is_empty(), "resizing paints nothing");+ drag(&mut h, c - vec2(10.0 * zoom, 0.0), c + vec2(10.0 * zoom, 0.0));+ let s = strokes(&h);+ assert_eq!(s.len(), 1);+ assert!((s[0].radius - dia / 2.0).abs() < 1e-6, "{} vs {dia}", s[0].radius);+}++/// #553: the Pen slot's tools work on a motion path as in After Effects: Add Vertex (and the+/// Pen) add a keyframe where the path is clicked, Convert Vertex switches a keyframe between+/// Linear and Auto Bezier, Delete Vertex removes it; the pointer is the tool's pen.+#[test]+fn vertex_tools_edit_motion_path_keyframes() {+ let mut h = harness();+ let box_id: LayerId = h.state().session.active_comp().unwrap().layers[0].id;+ let s = &mut h.state_mut().session;+ s.execute("layer.select", json!({"layers": [box_id.0]})).unwrap();+ s.execute("prop.addKey", json!({"layer": box_id.0, "path": "transform/position", "time": 0.0, "value": [100, 100, 0]})).unwrap();+ s.execute("prop.addKey", json!({"layer": box_id.0, "path": "transform/position", "time": 2.0, "value": [500, 100, 0]})).unwrap();+ s.execute("view.snapping", json!({"value": false})).unwrap();+ s.set_time(effectcraft_engine::time::Tick::from_seconds_f64(3.0));+ let keys = |h: &Harness<'_, EffectcraftApp>| {+ h.state().session.active_comp().unwrap().layer(box_id).unwrap().props.prop("transform/position").unwrap().keys.clone()+ };+ h.state_mut().ui.tool = Tool::PenAdd;+ h.run_steps(3);+ let mid = screen(&h, [300.0, 100.0]);+ h.input_mut().events.push(Event::PointerMoved(mid));+ h.step();+ assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::None, "the pen is painted in place of the system pointer");+ click(&mut h, mid);+ let k = keys(&h);+ assert_eq!(k.len(), 3, "Add Vertex adds a keyframe on the path");+ let v = k[1].value.as_vec3();+ assert!((v[0] - 300.0).abs() < 10.0 && (v[1] - 100.0).abs() < 1.0, "{v:?}");+ assert!((k[1].time.seconds() - 1.0).abs() < 0.1, "{:?}", k[1].time);+ // Convert Vertex: the new key's handles go (Linear), then come back (Auto Bezier).+ h.state_mut().ui.tool = Tool::PenConvert;+ let at = screen(&h, [v[0] as f32, v[1] as f32]);+ click(&mut h, at);+ let k = keys(&h);+ assert!(!k[1].spatial_auto && k[1].spatial_in == [0.0; 3] && k[1].spatial_out == [0.0; 3], "Linear");+ click(&mut h, at);+ assert!(keys(&h)[1].spatial_auto, "Auto Bezier");+ // Delete Vertex removes it.+ h.state_mut().ui.tool = Tool::PenDelete;+ click(&mut h, at);+ assert_eq!(keys(&h).len(), 2);+ // The Pen adds one too.+ h.state_mut().ui.tool = Tool::Pen;+ let quarter = screen(&h, [200.0, 100.0]);+ click(&mut h, quarter);+ assert_eq!(keys(&h).len(), 3);+}diff --cc docs/architecture.mdindex bb61c6d53,23e684fac..72d8b7341--- a/docs/architecture.md+++ b/docs/architecture.md@@@ -183,18 -165,17 +183,21 @@@ editing one layer re-renders only thatfor its frames. Effects that read the clock directly are declared in`effects::TIME_DEPENDENT`, and a test checks every registered effect against that list.-The viewer's **RAM preview** (`ui-egui/src/frames.rs`) keeps finished frames keyed by project-revision, comp, frame, scale, 3D view / region of interest and a hash of the other render-options (Draft / Fast Previews, shadows, nested switches), so frames rendered under other-options are never shown. When the budget (Settings ▸ Memory & CPU) is full the least recently-shown frames go first, and frames of an older revision are dropped as soon as the project-changes. The timeline's green bar counts the frames of exactly what the viewer shows.+The viewer's **RAM preview** (`ui-egui/src/frames.rs`) keeps finished frames keyed by comp+content, frame, scale, 3D view / region of interest and a hash of the other render options+(Draft / Fast Previews, shadows, nested switches). Edits preserve unaffected comps' frames,+and undo can reuse earlier content. During rapid edits at the same time and view, the viewer+shows the newest completed revision while the exact requested revision renders; out-of-order+completions cannot move it backwards. This avoids freezing until a slider or layer drag stops.+Frames at other times or with other render options are never substituted. Obsolete queued jobs+are dropped; running jobs finish into the cache. When the budget (Settings ▸ Memory & CPU) is+full the least recently shown frames go first. The timeline's green bar counts cached frames+of the current content and viewer settings.Resolution Auto renders the pixels the magnification needs, as in After Effects (Full above- 50 %, Half down to 33.3 %, Third down to 25 %, then Quarter). Below 100 % the viewer averages+ 50 %, Half down to 33.3 %, Third down to 25 %, then Quarter). The Resolution is the comp's+ (`Comp::resolution`, saved with the project): setting it is no undo step (undo, redo and history+ jumps carry the current values over) and, like the Shy switches, it is outside+ `Comp::same_pixels`, so cached frames stay valid. Below 100 % the viewer averagesinstead of skipping pixels (Viewer Zoom Quality More Accurate): GPU frames carry a mip chainsampled trilinearly, CPU frames go up averaged down by the whole factor that leaves about onetexel per screen pixel.diff --cc docs/target-app-parity.mdindex edeb4d455,e2739504e..20b00dae2--- a/docs/target-app-parity.md+++ b/docs/target-app-parity.md@@@ -681,10 -417,17 +681,17 @@@ Fixes from measured reportstoo large (#390).- The viewer's Auto resolution renders the pixels the magnification needs (Full above 50 %), andframes shown below 100 % are averaged (GPU frames through mip levels, CPU frames by a whole- factor) instead of minified bilinearly (#417). Not yet: the viewer resolution and magnification- are not remembered between launches.+ factor) instead of minified bilinearly (#417).+ - Each composition keeps its Resolution (Auto, Full, Half, Third, Quarter or Custom) in the+ project, as in After Effects: switching to another comp and back, or saving and reopening the+ project, shows the same resolution. Changing it marks the project modified but adds no undo+ step (undo and redo keep it) and keeps the comp's cached frames; projects saved before open+ with Auto. View ▸ Resolution and the panel's popup run `view.res.full|half|third|quarter|auto`+ and `view.res.custom {factor}`, which now work headless too; `comp.info` reports `resolution`+ and `resolutionFactor` (#417). Not yet: the magnification is not saved per comp, and the+ Composition Settings dialog has no Resolution popup.-## Update: plug-ins and extensions as in After Effects; ease presets become a ScriptUI panel+### Update: plug-ins and extensions as in After Effects; ease presets become a ScriptUI panelEffectCraft's core keeps After Effects parity; what After Effects users get from third parties isan extension, on the same extension points After Effects has ([plugins.md](plugins.md) compares