| author | |
| committer | |
| log | b963cf28697a2c2c823007e0409102b078aec931 |
| tree | 9643f16837428ab2975601d620f1c858feff1d43 |
| parent | 5432bcf4b7db251c55263591b6ccf9d81738923c |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
Viewers, flow, keyframes, inspector, and spline views now re-resolve node
references through Studio::reconcile_node_refs after delete/undo/redo/reload,
so stale NodeIds can no longer index out of bounds. Spline refreshes on every
comp replacement, keeps keys sorted while dragging with selection following
them, and no longer mutates the comp on plain clicks. Rotated gizmo axes, fine
mode, gizmo undo coalescing, animated gizmo edits, loop remainder, and the
per-frame prefetch re-plan are fixed; group scope blocks Add Tool and internal
tracks; fallible edits use history groups.
Assisted-by: claude-sonnet-5.511 files changed, 958 insertions(+), 220 deletions(-)
crates/app/src/inspector/mod.rs+7-1| ... | ... | @@ -72,6 +72,8 @@ pub struct InspectorState { |
| 72 | 72 | text_bufs: HashMap<(usize, String), String>, |
| 73 | 73 | /// Active scrub slider drag. |
| 74 | 74 | drag: Option<DragState>, |
| 75 | /// Text field that had the keys last frame, so losing them ends its coalesced undo step. | |
| 76 | text_focus: Option<ui::Id>, | |
| 75 | 77 | /// Last click timestamp per slider key for double-click reset. |
| 76 | 78 | last_click: HashMap<String, Instant>, |
| 77 | 79 | } |
| ... | ... | @@ -85,6 +87,7 @@ impl InspectorState { |
| 85 | 87 | name_buf: String::new(), |
| 86 | 88 | text_bufs: HashMap::new(), |
| 87 | 89 | drag: None, |
| 90 | text_focus: None, | |
| 88 | 91 | last_click: HashMap::new(), |
| 89 | 92 | } |
| 90 | 93 | } |
| ... | ... | @@ -98,6 +101,7 @@ impl InspectorState { |
| 98 | 101 | self.name_buf.clear(); |
| 99 | 102 | self.text_bufs.clear(); |
| 100 | 103 | self.drag = None; |
| 104 | self.text_focus = None; | |
| 101 | 105 | } |
| 102 | 106 | |
| 103 | 107 | pub fn build_ui( |
| ... | ... | @@ -222,13 +226,15 @@ impl InspectorState { |
| 222 | 226 | }); |
| 223 | 227 | if enter_pressed && self.name_buf.trim() != current_name { |
| 224 | 228 | let desired = self.name_buf.trim().to_owned(); |
| 225 | history.push_snapshot(comp, "Rename Node"); | |
| 229 | history.begin_group(comp, "Rename Node"); | |
| 226 | 230 | match comp.rename_node(node_id, &desired) { |
| 227 | 231 | Ok(applied) => { |
| 232 | history.commit_group(comp); | |
| 228 | 233 | self.name_buf = applied; |
| 229 | 234 | actions.push(InspectorAction::NodeRenamed(node_id)); |
| 230 | 235 | } |
| 231 | 236 | Err(e) => { |
| 237 | history.cancel_group(comp); | |
| 232 | 238 | self.name_buf = current_name.clone(); |
| 233 | 239 | actions.push(InspectorAction::StatusNotice(e)); |
| 234 | 240 | } |
crates/app/src/inspector/widgets.rs+24-4| ... | ... | @@ -655,6 +655,10 @@ impl InspectorState { |
| 655 | 655 | actions: &mut Vec<InspectorAction>, |
| 656 | 656 | ) { |
| 657 | 657 | let field_id = pane_id.child(("txt", node_id.0, input_name)); |
| 658 | if self.text_focus == Some(field_id) && ui.focused() != Some(field_id) { | |
| 659 | self.text_focus = None; | |
| 660 | history.break_coalescing(); | |
| 661 | } | |
| 658 | 662 | let key = (node_id.0, input_name.to_owned()); |
| 659 | 663 | let model_val = comp |
| 660 | 664 | .node(node_id) |
| ... | ... | @@ -688,7 +692,7 @@ impl InspectorState { |
| 688 | 692 | ..ui::Spec::default() |
| 689 | 693 | }, |
| 690 | 694 | ); |
| 691 | ui::text_field( | |
| 695 | let sig = ui::text_field( | |
| 692 | 696 | ui, |
| 693 | 697 | field_id, |
| 694 | 698 | buf, |
| ... | ... | @@ -704,6 +708,12 @@ impl InspectorState { |
| 704 | 708 | ..ui::Spec::default() |
| 705 | 709 | }, |
| 706 | 710 | ); |
| 711 | if ui.focused() == Some(field_id) { | |
| 712 | self.text_focus = Some(field_id); | |
| 713 | } | |
| 714 | let committed = sig.events.iter().any(|ev| { | |
| 715 | matches!(ev, ui::Event::Key { key: winit::keyboard::Key::Named(winit::keyboard::NamedKey::Enter), .. }) | |
| 716 | }); | |
| 707 | 717 | if *buf != prev { |
| 708 | 718 | history.push_coalesced( |
| 709 | 719 | comp, |
| ... | ... | @@ -713,6 +723,9 @@ impl InspectorState { |
| 713 | 723 | comp.set_input_value(node_id, input_name, ParamValue::Text(buf.clone())); |
| 714 | 724 | actions.push(InspectorAction::ParamEdited(node_id)); |
| 715 | 725 | } |
| 726 | if committed { | |
| 727 | history.break_coalescing(); | |
| 728 | } | |
| 716 | 729 | ui.close(); |
| 717 | 730 | } |
| 718 | 731 | |
| ... | ... | @@ -881,18 +894,25 @@ impl InspectorState { |
| 881 | 894 | .get(input_name) |
| 882 | 895 | .and_then(|b| b.source_op.clone()) |
| 883 | 896 | { |
| 884 | history.push_snapshot(comp, format!("Delete Keyframe {input_name}")); | |
| 897 | history.begin_group(comp, format!("Delete Keyframe {input_name}")); | |
| 885 | 898 | if comp.delete_keyframe(&sp_name, current_frame) { |
| 886 | 899 | actions.push(InspectorAction::KeyframeEdited(node_id)); |
| 887 | 900 | actions.push(InspectorAction::StatusNotice(format!( |
| 888 | 901 | "Deleted keyframe on {input_name} @ f{current_frame:.0}" |
| 889 | 902 | ))); |
| 890 | 903 | } |
| 904 | history.commit_group(comp); | |
| 891 | 905 | } |
| 892 | 906 | } |
| 893 | 907 | KeyframeState::Static | KeyframeState::AnimatedOtherFrame => { |
| 894 | history.push_snapshot(comp, format!("Set Keyframe {input_name}")); | |
| 895 | match comp.set_keyframe(node_id, input_name, current_frame, cur_val) { | |
| 908 | history.begin_group(comp, format!("Set Keyframe {input_name}")); | |
| 909 | let result = comp.set_keyframe(node_id, input_name, current_frame, cur_val); | |
| 910 | if result.is_ok() { | |
| 911 | history.commit_group(comp); | |
| 912 | } else { | |
| 913 | history.cancel_group(comp); | |
| 914 | } | |
| 915 | match result { | |
| 896 | 916 | Ok(_) => { |
| 897 | 917 | actions.push(InspectorAction::KeyframeEdited(node_id)); |
| 898 | 918 | actions.push(InspectorAction::StatusNotice(format!( |
crates/app/src/keyframes.rs+110-10| ... | ... | @@ -8,6 +8,8 @@ use std::sync::Arc; |
| 8 | 8 | use winit::event::{ElementState, MouseButton}; |
| 9 | 9 | use winit::keyboard::{Key, KeyCode, ModifiersState, NamedKey, PhysicalKey}; |
| 10 | 10 | |
| 11 | /// Layout entries kept before the label cache is rebuilt. | |
| 12 | const TEXT_CACHE_CAP: usize = 512; | |
| 11 | 13 | const RULER_H: f32 = 26.0; |
| 12 | 14 | const AUDIO_ROW_H: f32 = 24.0; |
| 13 | 15 | const ROW_H: f32 = 22.0; |
| ... | ... | @@ -46,6 +48,8 @@ pub enum TrackRow { |
| 46 | 48 | struct RetimeDrag { |
| 47 | 49 | start_frame: f64, |
| 48 | 50 | saved_splines: HashMap<String, Vec<Keyframe>>, |
| 51 | /// Selection when the drag began; indices refer to `saved_splines`. | |
| 52 | orig_selected: HashSet<DopeKeyRef>, | |
| 49 | 53 | pre_edit_comp: Comp, |
| 50 | 54 | moved: bool, |
| 51 | 55 | } |
| ... | ... | @@ -146,6 +150,16 @@ impl KeyframesView { |
| 146 | 150 | self.fitted = true; |
| 147 | 151 | } |
| 148 | 152 | |
| 153 | /// Drops node ids and key refs that no longer exist after undo, redo, delete, or reload. | |
| 154 | pub fn sanitize_ids(&mut self, comp: &Comp) { | |
| 155 | self.collapsed_nodes.retain(|id| id.0 < comp.nodes.len()); | |
| 156 | self.selected_keys | |
| 157 | .retain(|k| comp.splines.get(&k.spline).is_some_and(|sp| k.key_idx < sp.keyframes.len())); | |
| 158 | self.hovered_key = None; | |
| 159 | self.retime_drag = None; | |
| 160 | self.box_select = None; | |
| 161 | } | |
| 162 | ||
| 149 | 163 | pub fn sync_tracks(&mut self, comp: &Comp, selected_node: Option<NodeId>) { |
| 150 | 164 | if !self.fitted { |
| 151 | 165 | self.fit_comp(comp); |
| ... | ... | @@ -244,6 +258,7 @@ impl KeyframesView { |
| 244 | 258 | self.retime_drag = Some(RetimeDrag { |
| 245 | 259 | start_frame: self.x_to_time(self.pointer_local[0]).round(), |
| 246 | 260 | saved_splines: saved, |
| 261 | orig_selected: self.selected_keys.clone(), | |
| 247 | 262 | pre_edit_comp: comp.clone(), |
| 248 | 263 | moved: false, |
| 249 | 264 | }); |
| ... | ... | @@ -257,7 +272,7 @@ impl KeyframesView { |
| 257 | 272 | return false; |
| 258 | 273 | } |
| 259 | 274 | drag.moved = true; |
| 260 | retime_selected_keys(comp, &drag.saved_splines, &self.selected_keys, dt); | |
| 275 | self.selected_keys = retime_selected_keys(comp, &drag.saved_splines, &drag.orig_selected, dt); | |
| 261 | 276 | true |
| 262 | 277 | } |
| 263 | 278 | |
| ... | ... | @@ -266,11 +281,6 @@ impl KeyframesView { |
| 266 | 281 | if !drag.moved { |
| 267 | 282 | return false; |
| 268 | 283 | } |
| 269 | for sname in drag.saved_splines.keys() { | |
| 270 | if let Some(sp) = comp.splines.get_mut(sname) { | |
| 271 | sp.sort(); | |
| 272 | } | |
| 273 | } | |
| 274 | 284 | comp.revision += 1; |
| 275 | 285 | history.push_snapshot(&drag.pre_edit_comp, "Retime Keyframes"); |
| 276 | 286 | true |
| ... | ... | @@ -478,6 +488,7 @@ impl KeyframesView { |
| 478 | 488 | kmod: ModifiersState, |
| 479 | 489 | actions: &mut Vec<KeyframesAction>, |
| 480 | 490 | ) { |
| 491 | let plain = !kmod.super_key() && !kmod.control_key() && !kmod.alt_key(); | |
| 481 | 492 | match key { |
| 482 | 493 | Key::Named(NamedKey::Delete | NamedKey::Backspace) => { |
| 483 | 494 | if self.delete_selected(comp, history) { |
| ... | ... | @@ -485,8 +496,8 @@ impl KeyframesView { |
| 485 | 496 | } |
| 486 | 497 | } |
| 487 | 498 | Key::Character(c) => match c.to_ascii_lowercase().as_str() { |
| 488 | "f" | "." => self.fit_comp(comp), | |
| 489 | "x" if !kmod.super_key() => { | |
| 499 | "f" | "." if plain => self.fit_comp(comp), | |
| 500 | "x" if plain => { | |
| 490 | 501 | if self.delete_selected(comp, history) { |
| 491 | 502 | actions.push(KeyframesAction::KeyframesEdited); |
| 492 | 503 | } |
| ... | ... | @@ -498,6 +509,9 @@ impl KeyframesView { |
| 498 | 509 | } |
| 499 | 510 | |
| 500 | 511 | pub fn prepare_labels(&mut self) { |
| 512 | if self.text_cache.len() > TEXT_CACHE_CAP { | |
| 513 | self.text_cache.clear(); | |
| 514 | } | |
| 501 | 515 | let font_sm = text::Font { |
| 502 | 516 | families: Arc::from([text::Family::Mono]), |
| 503 | 517 | size: 10.0, |
| ... | ... | @@ -889,7 +903,8 @@ pub fn build_tracks( |
| 889 | 903 | }; |
| 890 | 904 | |
| 891 | 905 | for id in iter_ids { |
| 892 | if id.0 >= comp.nodes.len() { | |
| 906 | // Group-internal tools are not on the root flow, so they cannot be selected from here. | |
| 907 | if comp.nodes.get(id.0).is_none_or(|n| n.internal) { | |
| 893 | 908 | continue; |
| 894 | 909 | } |
| 895 | 910 | let channels: Vec<(String, String)> = comp |
| ... | ... | @@ -939,7 +954,7 @@ pub fn retime_selected_keys( |
| 939 | 954 | saved_splines: &HashMap<String, Vec<Keyframe>>, |
| 940 | 955 | selected: &HashSet<DopeKeyRef>, |
| 941 | 956 | dt: f64, |
| 942 | ) { | |
| 957 | ) -> HashSet<DopeKeyRef> { | |
| 943 | 958 | for (sname, orig) in saved_splines { |
| 944 | 959 | if let Some(sp) = comp.splines.get_mut(sname) { |
| 945 | 960 | sp.keyframes = orig.clone(); |
| ... | ... | @@ -956,7 +971,19 @@ pub fn retime_selected_keys( |
| 956 | 971 | rh[0] += dt; |
| 957 | 972 | } |
| 958 | 973 | } |
| 974 | // Keep curves sorted while dragging; the returned selection follows its keys to their new slots. | |
| 975 | let remaps: HashMap<&String, Vec<usize>> = saved_splines | |
| 976 | .keys() | |
| 977 | .filter_map(|sname| Some((sname, spline::sort_keyframes(comp.splines.get_mut(sname)?)))) | |
| 978 | .collect(); | |
| 959 | 979 | comp.revision += 1; |
| 980 | selected | |
| 981 | .iter() | |
| 982 | .map(|k| DopeKeyRef { | |
| 983 | spline: k.spline.clone(), | |
| 984 | key_idx: remaps.get(&k.spline).and_then(|r| r.get(k.key_idx)).copied().unwrap_or(k.key_idx), | |
| 985 | }) | |
| 986 | .collect() | |
| 960 | 987 | } |
| 961 | 988 | |
| 962 | 989 | fn nice_step(raw: f64) -> f64 { |
| ... | ... | @@ -1029,4 +1056,77 @@ mod tests { |
| 1029 | 1056 | assert!(history.undo(&mut comp)); |
| 1030 | 1057 | assert!((comp.splines["XF1Size"].keyframes[1].time - 40.0).abs() < 1e-6); |
| 1031 | 1058 | } |
| 1059 | ||
| 1060 | #[test] | |
| 1061 | fn retime_past_a_neighbour_keeps_curve_sorted_and_selection_on_the_key() { | |
| 1062 | let mut comp = sample_animated_comp(); | |
| 1063 | let saved = HashMap::from([("XF1Size".to_owned(), comp.splines["XF1Size"].keyframes.clone())]); | |
| 1064 | let sel = HashSet::from([DopeKeyRef { spline: "XF1Size".to_owned(), key_idx: 0 }]); | |
| 1065 | ||
| 1066 | let moved = retime_selected_keys(&mut comp, &saved, &sel, 50.0); | |
| 1067 | ||
| 1068 | let times: Vec<f64> = comp.splines["XF1Size"].keyframes.iter().map(|k| k.time).collect(); | |
| 1069 | assert_eq!(times, [40.0, 60.0]); | |
| 1070 | assert_eq!(moved, HashSet::from([DopeKeyRef { spline: "XF1Size".to_owned(), key_idx: 1 }])); | |
| 1071 | } | |
| 1072 | ||
| 1073 | #[test] | |
| 1074 | fn group_internal_tools_get_no_tracks() { | |
| 1075 | let comp = Comp::from_fusion_str( | |
| 1076 | r#"Composition { | |
| 1077 | Tools = ordered() { | |
| 1078 | Outer = GroupOperator { | |
| 1079 | ViewInfo = GroupInfo { Pos = { 0, 0 } }, | |
| 1080 | Tools = ordered() { | |
| 1081 | Inner = Blur { | |
| 1082 | Inputs = { Size = Input { SourceOp = "InnerSize", Source = "Value", }, }, | |
| 1083 | }, | |
| 1084 | InnerSize = BezierSpline { | |
| 1085 | KeyFrames = { | |
| 1086 | [0] = { 1.0, Flags = { Linear = true } }, | |
| 1087 | [10] = { 2.0, Flags = { Linear = true } }, | |
| 1088 | }, | |
| 1089 | }, | |
| 1090 | }, | |
| 1091 | }, | |
| 1092 | }, | |
| 1093 | }"#, | |
| 1094 | ) | |
| 1095 | .expect("group comp"); | |
| 1096 | let inner = comp.nodes.iter().find(|n| n.internal && n.name == "Inner").expect("internal tool").id; | |
| 1097 | assert!(!comp.node_splines(inner).is_empty()); | |
| 1098 | ||
| 1099 | assert!(build_tracks(&comp, None, false, &HashSet::new()).is_empty()); | |
| 1100 | assert!(build_tracks(&comp, Some(inner), true, &HashSet::new()).is_empty()); | |
| 1101 | } | |
| 1102 | ||
| 1103 | #[test] | |
| 1104 | fn sanitize_drops_refs_to_vanished_nodes_and_keys() { | |
| 1105 | let comp = sample_animated_comp(); | |
| 1106 | let mut view = KeyframesView::new(&ui::Theme::dark()); | |
| 1107 | view.collapsed_nodes.insert(NodeId(0)); | |
| 1108 | view.collapsed_nodes.insert(NodeId(7)); | |
| 1109 | view.selected_keys.insert(DopeKeyRef { spline: "XF1Size".to_owned(), key_idx: 1 }); | |
| 1110 | view.selected_keys.insert(DopeKeyRef { spline: "XF1Size".to_owned(), key_idx: 5 }); | |
| 1111 | view.selected_keys.insert(DopeKeyRef { spline: "Gone".to_owned(), key_idx: 0 }); | |
| 1112 | ||
| 1113 | view.sanitize_ids(&comp); | |
| 1114 | ||
| 1115 | assert_eq!(view.collapsed_nodes, HashSet::from([NodeId(0)])); | |
| 1116 | assert_eq!(view.selected_keys, HashSet::from([DopeKeyRef { spline: "XF1Size".to_owned(), key_idx: 1 }])); | |
| 1117 | } | |
| 1118 | ||
| 1119 | #[test] | |
| 1120 | fn letter_shortcuts_ignore_ctrl_alt_and_cmd() { | |
| 1121 | let mut comp = sample_animated_comp(); | |
| 1122 | let mut history = CompHistory::new(); | |
| 1123 | let mut view = KeyframesView::new(&ui::Theme::dark()); | |
| 1124 | view.selected_keys.insert(DopeKeyRef { spline: "XF1Size".to_owned(), key_idx: 0 }); | |
| 1125 | for mods in [ModifiersState::CONTROL, ModifiersState::ALT, ModifiersState::SUPER] { | |
| 1126 | let mut acts = Vec::new(); | |
| 1127 | view.handle_key(&mut comp, &mut history, &Key::Character("x".into()), mods, &mut acts); | |
| 1128 | assert!(acts.is_empty(), "x with {mods:?}"); | |
| 1129 | } | |
| 1130 | assert_eq!(comp.splines["XF1Size"].keyframes.len(), 2); | |
| 1131 | } | |
| 1032 | 1132 | } |
crates/app/src/main.rs+181-20| ... | ... | @@ -17,7 +17,7 @@ use inspector::{InspectorAction, InspectorState}; |
| 17 | 17 | use keyframes::{KeyframesAction, KeyframesView}; |
| 18 | 18 | use menus::{build_flow_toolbar, handle_global_shortcut}; |
| 19 | 19 | use model::{Comp, CompHistory, NodeId, default_main_input_port}; |
| 20 | use playback_ui::{load_snapshot_audio_peaks, spawn_audio_loader}; | |
| 20 | use playback_ui::{PrefetchSig, load_snapshot_audio_peaks, spawn_audio_loader}; | |
| 21 | 21 | use spline::{SplineAction, SplineView}; |
| 22 | 22 | use std::collections::HashMap; |
| 23 | 23 | use std::error::Error; |
| ... | ... | @@ -140,7 +140,7 @@ struct Studio { |
| 140 | 140 | add_tool: AddToolLauncher, |
| 141 | 141 | ram_cache: RamFrameCache, |
| 142 | 142 | prefetcher: Option<RamPrefetcher>, |
| 143 | last_prefetch_sig: Option<(NodeId, i64, u64, u32, bool, bool)>, | |
| 143 | last_prefetch_sig: Option<PrefetchSig>, | |
| 144 | 144 | renaming_node: Option<NodeId>, |
| 145 | 145 | rename_buf: String, |
| 146 | 146 | rename_needs_focus: bool, |
| ... | ... | @@ -362,7 +362,49 @@ impl Studio { |
| 362 | 362 | self.status_notice = Some((msg.into(), Instant::now())); |
| 363 | 363 | } |
| 364 | 364 | |
| 365 | /// Group contents are read-only; reports why `verb` can't happen and returns `true` inside one. | |
| 366 | fn reject_in_group(&mut self, verb: &str) -> bool { | |
| 367 | let in_group = !self.flow.scope_path().is_empty(); | |
| 368 | if in_group { | |
| 369 | self.set_notice(format!("Group contents are read-only; press Esc to leave the group before {verb}")); | |
| 370 | } | |
| 371 | in_group | |
| 372 | } | |
| 373 | ||
| 374 | fn open_add_tool(&mut self) { | |
| 375 | if !self.reject_in_group("adding tools") { | |
| 376 | self.add_tool.open(); | |
| 377 | } | |
| 378 | } | |
| 379 | ||
| 380 | /// Names of the nodes shown in each viewer; capture before any edit that can renumber `NodeId`s. | |
| 381 | fn viewed_names(&self) -> [Option<String>; 2] { | |
| 382 | self.viewers | |
| 383 | .each_ref() | |
| 384 | .map(|v| v.viewed_node.and_then(|id| self.comp.nodes.get(id.0)).map(|n| n.name.clone())) | |
| 385 | } | |
| 386 | ||
| 387 | /// Re-points every `NodeId` held by the UI after `comp` was edited, undone, redone, or reloaded: | |
| 388 | /// viewers follow their node by name, and drags, renames, and selections of vanished state are dropped. | |
| 389 | fn reconcile_node_refs(&mut self, prev_viewed: [Option<String>; 2]) { | |
| 390 | for (v, name) in self.viewers.iter_mut().zip(prev_viewed) { | |
| 391 | v.viewed_node = name.and_then(|n| self.comp.find_node(&n)); | |
| 392 | v.gizmos.end_drag(); | |
| 393 | v.gizmos.hovered = None; | |
| 394 | v.dirty = true; | |
| 395 | } | |
| 396 | self.flow.sanitize_ids(&self.comp); | |
| 397 | self.flow.viewed_nodes = self.viewers.each_ref().map(|v| v.viewed_node); | |
| 398 | self.keyframes.sanitize_ids(&self.comp); | |
| 399 | self.inspector.reset(); | |
| 400 | self.renaming_node = None; | |
| 401 | self.spline.refresh_for_comp(&self.comp, self.flow.primary, false); | |
| 402 | } | |
| 403 | ||
| 365 | 404 | fn add_tool_from_entry(&mut self, entry: ToolEntry) { |
| 405 | if self.reject_in_group("adding tools") { | |
| 406 | return; | |
| 407 | } | |
| 366 | 408 | let prev_sel = self.flow.primary.filter(|id| id.0 < self.comp.nodes.len()); |
| 367 | 409 | let pos = self.flow.spawn_position(&self.comp, entry.is_generator); |
| 368 | 410 | self.history.push_snapshot(&self.comp, format!("Add {}", entry.display)); |
| ... | ... | @@ -636,7 +678,7 @@ impl Studio { |
| 636 | 678 | self.status_notice = None; |
| 637 | 679 | } |
| 638 | 680 | if req_open_add_tool { |
| 639 | self.add_tool.open(); | |
| 681 | self.open_add_tool(); | |
| 640 | 682 | } |
| 641 | 683 | if let Some(depth) = req_exit_to_depth |
| 642 | 684 | && self.flow.exit_to_depth(&self.comp, depth) |
| ... | ... | @@ -662,14 +704,18 @@ impl Studio { |
| 662 | 704 | self.renaming_node = None; |
| 663 | 705 | self.ui.set_focus(Some(flow_canvas_id())); |
| 664 | 706 | if !new_name.is_empty() && rn_id.0 < self.comp.nodes.len() && new_name != self.comp.node(rn_id).name { |
| 665 | self.history.push_snapshot(&self.comp, "Rename Node"); | |
| 707 | self.history.begin_group(&self.comp, "Rename Node"); | |
| 666 | 708 | match self.comp.rename_node(rn_id, &new_name) { |
| 667 | 709 | Ok(applied) => { |
| 668 | self.spline.set_target_node(&self.comp, self.flow.primary); | |
| 710 | self.history.commit_group(&self.comp); | |
| 711 | self.spline.refresh_for_comp(&self.comp, self.flow.primary, false); | |
| 669 | 712 | self.invalidate_node(Some(rn_id)); |
| 670 | 713 | self.set_notice(format!("Renamed to {applied}")); |
| 671 | 714 | } |
| 672 | Err(e) => self.set_notice(e), | |
| 715 | Err(e) => { | |
| 716 | self.history.cancel_group(&mut self.comp); | |
| 717 | self.set_notice(e); | |
| 718 | } | |
| 673 | 719 | } |
| 674 | 720 | } |
| 675 | 721 | } else if cancel_rename { |
| ... | ... | @@ -685,12 +731,8 @@ impl Studio { |
| 685 | 731 | InspectorAction::ParamEdited(id) => { |
| 686 | 732 | self.invalidate_node(Some(id)); |
| 687 | 733 | } |
| 688 | InspectorAction::KeyframeEdited(id) => { | |
| 689 | self.spline.set_target_node(&self.comp, self.flow.primary); | |
| 690 | self.invalidate_node(Some(id)); | |
| 691 | } | |
| 692 | InspectorAction::NodeRenamed(id) => { | |
| 693 | self.spline.set_target_node(&self.comp, self.flow.primary); | |
| 734 | InspectorAction::KeyframeEdited(id) | InspectorAction::NodeRenamed(id) => { | |
| 735 | self.spline.refresh_for_comp(&self.comp, self.flow.primary, false); | |
| 694 | 736 | self.invalidate_node(Some(id)); |
| 695 | 737 | } |
| 696 | 738 | InspectorAction::StatusNotice(msg) => { |
| ... | ... | @@ -723,9 +765,14 @@ impl Studio { |
| 723 | 765 | let ptr = self.ui.last_pointer(); |
| 724 | 766 | let mods = self.ui.modifiers(); |
| 725 | 767 | let mut acts = Vec::new(); |
| 768 | let prev_viewed = self.viewed_names(); | |
| 769 | let node_count = self.comp.nodes.len(); | |
| 726 | 770 | for ev in sig.events { |
| 727 | 771 | acts.extend(self.flow.input(&mut self.comp, &mut self.history, ev, rect, ptr, mods)); |
| 728 | 772 | } |
| 773 | if self.comp.nodes.len() != node_count { | |
| 774 | self.reconcile_node_refs(prev_viewed); | |
| 775 | } | |
| 729 | 776 | for a in acts { |
| 730 | 777 | match a { |
| 731 | 778 | FlowAction::SelectionChanged(sel) => { |
| ... | ... | @@ -746,7 +793,7 @@ impl Studio { |
| 746 | 793 | self.invalidate_node(node); |
| 747 | 794 | } |
| 748 | 795 | FlowAction::OpenAddTool => { |
| 749 | self.add_tool.open(); | |
| 796 | self.open_add_tool(); | |
| 750 | 797 | } |
| 751 | 798 | FlowAction::RequestRename(id) => { |
| 752 | 799 | self.begin_inline_rename(id); |
| ... | ... | @@ -783,13 +830,7 @@ impl Studio { |
| 783 | 830 | for a in acts { |
| 784 | 831 | match a { |
| 785 | 832 | SplineAction::SplineEdited => { |
| 786 | if let Some(id) = self.flow.primary { | |
| 787 | self.engine.bust_subtree(id); | |
| 788 | } | |
| 789 | for v in &mut self.viewers { | |
| 790 | v.cached_frames.clear(); | |
| 791 | v.dirty = true; | |
| 792 | } | |
| 833 | self.invalidate_node(None); | |
| 793 | 834 | } |
| 794 | 835 | SplineAction::ScrubFrame(f) => { |
| 795 | 836 | if self.playback.set_frame(&self.comp, f, now) { |
| ... | ... | @@ -837,6 +878,7 @@ impl Studio { |
| 837 | 878 | self.spline.set_target_node(&self.comp, Some(id)); |
| 838 | 879 | } |
| 839 | 880 | KeyframesAction::KeyframesEdited => { |
| 881 | self.spline.refresh_for_comp(&self.comp, self.flow.primary, false); | |
| 840 | 882 | self.invalidate_node(None); |
| 841 | 883 | } |
| 842 | 884 | } |
| ... | ... | @@ -1220,3 +1262,122 @@ fn studio_btn(ui: &mut ui::Ui, part: impl std::hash::Hash, label: &str, active: |
| 1220 | 1262 | }, |
| 1221 | 1263 | ) |
| 1222 | 1264 | } |
| 1265 | ||
| 1266 | #[cfg(test)] | |
| 1267 | mod tests { | |
| 1268 | use super::*; | |
| 1269 | use winit::event::ElementState; | |
| 1270 | use winit::keyboard::{Key, ModifiersState, NamedKey, PhysicalKey}; | |
| 1271 | ||
| 1272 | const COMP: &str = r#"Composition { | |
| 1273 | Tools = ordered() { | |
| 1274 | BG1 = Background { Inputs = { Width = Input { Value = 64, }, Height = Input { Value = 64, }, }, }, | |
| 1275 | Blur1 = Blur { | |
| 1276 | Inputs = { Input = Input { SourceOp = "BG1", Source = "Output", }, }, | |
| 1277 | ViewInfo = OperatorInfo { Pos = { 110, 0 } }, | |
| 1278 | }, | |
| 1279 | Merge1 = Merge { | |
| 1280 | Inputs = { Background = Input { SourceOp = "Blur1", Source = "Output", }, }, | |
| 1281 | ViewInfo = OperatorInfo { Pos = { 220, 0 } }, | |
| 1282 | }, | |
| 1283 | Outer = GroupOperator { | |
| 1284 | ViewInfo = GroupInfo { Pos = { 330, 0 } }, | |
| 1285 | Tools = ordered() { Inner = Blur { ViewInfo = OperatorInfo { Pos = { 0, 50 } }, }, }, | |
| 1286 | }, | |
| 1287 | }, | |
| 1288 | }"#; | |
| 1289 | ||
| 1290 | fn studio() -> Studio { | |
| 1291 | let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::new_without_display_handle()); | |
| 1292 | let adapter = pollster::block_on(instance.request_adapter(&Default::default())).expect("adapter"); | |
| 1293 | let (device, queue) = pollster::block_on(adapter.request_device(&Default::default())).expect("device"); | |
| 1294 | let renderer = draw::Renderer::new(device, queue, wgpu::TextureFormat::Rgba8Unorm); | |
| 1295 | let comp = Comp::from_fusion_str(COMP).expect("comp"); | |
| 1296 | Studio::new(renderer, comp, None, None, true, false, false) | |
| 1297 | } | |
| 1298 | ||
| 1299 | fn id(studio: &Studio, name: &str) -> NodeId { | |
| 1300 | studio.comp.find_node(name).unwrap() | |
| 1301 | } | |
| 1302 | ||
| 1303 | #[test] | |
| 1304 | fn deleting_nodes_under_a_viewer_reconciles_it_by_name() { | |
| 1305 | let mut studio = studio(); | |
| 1306 | let (bg, merge) = (id(&studio, "BG1"), id(&studio, "Merge1")); | |
| 1307 | studio.viewers[0].viewed_node = Some(merge); | |
| 1308 | studio.viewers[1].viewed_node = Some(bg); | |
| 1309 | let node_count = studio.comp.nodes.len(); | |
| 1310 | ||
| 1311 | // Deleting an earlier node renumbers the viewed one: it must follow by name. | |
| 1312 | let prev = studio.viewed_names(); | |
| 1313 | studio.comp.delete_nodes(&[bg]); | |
| 1314 | studio.reconcile_node_refs(prev); | |
| 1315 | assert_eq!(studio.comp.nodes.len(), node_count - 1); | |
| 1316 | assert_eq!(studio.viewers[0].viewed_node, studio.comp.find_node("Merge1")); | |
| 1317 | assert!(studio.viewers[0].viewed_node.is_some_and(|id| id.0 < studio.comp.nodes.len())); | |
| 1318 | assert_eq!(studio.viewers[1].viewed_node, None); | |
| 1319 | assert_eq!(studio.flow.viewed_nodes, [studio.viewers[0].viewed_node, None]); | |
| 1320 | ||
| 1321 | // Deleting the viewed node itself clears the viewer; the HUD never indexes a stale id. | |
| 1322 | let prev = studio.viewed_names(); | |
| 1323 | let merge = id(&studio, "Merge1"); | |
| 1324 | studio.comp.delete_nodes(&[merge]); | |
| 1325 | studio.reconcile_node_refs(prev); | |
| 1326 | assert_eq!(studio.viewers[0].viewed_node, None); | |
| 1327 | studio.viewers[0].prepare_hud(&studio.comp, &studio.engine, &studio.playback); | |
| 1328 | studio.render_visible_viewers(false); | |
| 1329 | } | |
| 1330 | ||
| 1331 | #[test] | |
| 1332 | fn undo_and_redo_reconcile_viewers_and_clear_transient_state() { | |
| 1333 | let mut studio = studio(); | |
| 1334 | let merge = id(&studio, "Merge1"); | |
| 1335 | let node_count = studio.comp.nodes.len(); | |
| 1336 | studio.viewers[0].viewed_node = Some(merge); | |
| 1337 | studio.history.push_snapshot(&studio.comp, "Delete Nodes"); | |
| 1338 | studio.comp.delete_nodes(&[merge]); | |
| 1339 | studio.renaming_node = Some(merge); | |
| 1340 | ||
| 1341 | studio.undo(); | |
| 1342 | assert_eq!(studio.comp.nodes.len(), node_count); | |
| 1343 | assert_eq!(studio.renaming_node, None); | |
| 1344 | assert!(studio.viewers.iter().all(|v| v.viewed_node.is_none_or(|id| id.0 < studio.comp.nodes.len()))); | |
| 1345 | ||
| 1346 | studio.redo(); | |
| 1347 | assert!(studio.viewers.iter().all(|v| v.viewed_node.is_none_or(|id| id.0 < studio.comp.nodes.len()))); | |
| 1348 | } | |
| 1349 | ||
| 1350 | #[test] | |
| 1351 | fn ctrl_tab_works_from_canvas_and_regular_panes() { | |
| 1352 | let mut studio = studio(); | |
| 1353 | let key_input = |mods| ui::Event::KeyInput { | |
| 1354 | physical: PhysicalKey::Code(winit::keyboard::KeyCode::Tab), | |
| 1355 | key: Key::Named(NamedKey::Tab), | |
| 1356 | text: None, | |
| 1357 | unshifted: Key::Named(NamedKey::Tab), | |
| 1358 | modifiers: mods, | |
| 1359 | state: ElementState::Pressed, | |
| 1360 | repeat: false, | |
| 1361 | }; | |
| 1362 | let key = |mods| ui::Event::Key { key: Key::Named(NamedKey::Tab), text: None, modifiers: mods }; | |
| 1363 | ||
| 1364 | assert!(handle_global_shortcut(&mut studio, &key_input(ModifiersState::CONTROL))); | |
| 1365 | assert!(handle_global_shortcut(&mut studio, &key_input(ModifiersState::CONTROL | ModifiersState::SHIFT))); | |
| 1366 | assert!(handle_global_shortcut(&mut studio, &key(ModifiersState::CONTROL))); | |
| 1367 | assert!(!handle_global_shortcut(&mut studio, &key_input(ModifiersState::empty()))); | |
| 1368 | } | |
| 1369 | ||
| 1370 | #[test] | |
| 1371 | fn group_scope_blocks_add_tool() { | |
| 1372 | let mut studio = studio(); | |
| 1373 | let outer = id(&studio, "Outer"); | |
| 1374 | studio.open_add_tool(); | |
| 1375 | assert!(studio.add_tool.open); | |
| 1376 | studio.add_tool.close(); | |
| 1377 | ||
| 1378 | assert!(studio.flow.enter_group(&studio.comp, outer)); | |
| 1379 | studio.open_add_tool(); | |
| 1380 | assert!(!studio.add_tool.open); | |
| 1381 | assert!(studio.status_notice.as_ref().is_some_and(|(m, _)| m.contains("read-only"))); | |
| 1382 | } | |
| 1383 | } |
crates/app/src/menus.rs+26-37| ... | ... | @@ -36,9 +36,13 @@ pub(crate) fn sanitize_filename(name: &str) -> String { |
| 36 | 36 | } |
| 37 | 37 | } |
| 38 | 38 | |
| 39 | fn applescript_escape(s: &str) -> String { | |
| 40 | s.replace('\\', "\\\\").replace('"', "\\\"") | |
| 41 | } | |
| 42 | ||
| 39 | 43 | pub(crate) fn native_save_file_dialog(prompt: &str, default_name: &str) -> Option<PathBuf> { |
| 40 | let safe_prompt = prompt.replace('"', ""); | |
| 41 | let safe_name = default_name.replace('"', ""); | |
| 44 | let safe_prompt = applescript_escape(prompt); | |
| 45 | let safe_name = applescript_escape(default_name); | |
| 42 | 46 | let script = format!( |
| 43 | 47 | r#"POSIX path of (choose file name with prompt "{safe_prompt}" default name "{safe_name}")"# |
| 44 | 48 | ); |
| ... | ... | @@ -281,7 +285,7 @@ pub(crate) fn handle_global_shortcut(studio: &mut Studio, event: &ui::Event) -> |
| 281 | 285 | _ => false, |
| 282 | 286 | }; |
| 283 | 287 | if is_shift_space { |
| 284 | studio.add_tool.open(); | |
| 288 | studio.open_add_tool(); | |
| 285 | 289 | return true; |
| 286 | 290 | } |
| 287 | 291 | // Global Space toggles playback (synced with audio) and `` ` `` clears both viewers from any focused pane! |
| ... | ... | @@ -307,17 +311,17 @@ pub(crate) fn handle_global_shortcut(studio: &mut Studio, event: &ui::Event) -> |
| 307 | 311 | return true; |
| 308 | 312 | } |
| 309 | 313 | } |
| 310 | if !studio.ui.popups_open() && !studio.add_tool.open && let ui::Event::Key { key, modifiers, .. } = event { | |
| 311 | let cmd = match key { | |
| 312 | Key::Named(NamedKey::Tab) if modifiers.control_key() => { | |
| 313 | Some(if modifiers.shift_key() { Command::Previous } else { Command::Next }) | |
| 314 | } | |
| 315 | _ => None, | |
| 316 | }; | |
| 317 | if let Some(cmd) = cmd { | |
| 318 | let _ = studio.dock.at(&mut studio.layout, &mut studio.seen, &String::clone).run(cmd); | |
| 319 | return true; | |
| 320 | } | |
| 314 | // Canvas panes receive `KeyInput`; every other pane receives `Key`. | |
| 315 | if !studio.ui.popups_open() | |
| 316 | && !studio.add_tool.open | |
| 317 | && let ui::Event::KeyInput { key, modifiers, state: ElementState::Pressed, repeat: false, .. } | |
| 318 | | ui::Event::Key { key, modifiers, .. } = event | |
| 319 | && matches!(key, Key::Named(NamedKey::Tab)) | |
| 320 | && modifiers.control_key() | |
| 321 | { | |
| 322 | let cmd = if modifiers.shift_key() { Command::Previous } else { Command::Next }; | |
| 323 | let _ = studio.dock.at(&mut studio.layout, &mut studio.seen, &String::clone).run(cmd); | |
| 324 | return true; | |
| 321 | 325 | } |
| 322 | 326 | false |
| 323 | 327 | } |
| ... | ... | @@ -325,16 +329,9 @@ pub(crate) fn handle_global_shortcut(studio: &mut Studio, event: &ui::Event) -> |
| 325 | 329 | impl Studio { |
| 326 | 330 | pub(crate) fn undo(&mut self) { |
| 327 | 331 | let label = self.history.undo_label().unwrap_or("Edit").to_owned(); |
| 332 | let prev_viewed = self.viewed_names(); | |
| 328 | 333 | if self.history.undo(&mut self.comp) { |
| 329 | self.flow.sanitize_ids(&self.comp); | |
| 330 | for slot in [0usize, 1] { | |
| 331 | if self.viewers[slot].viewed_node.is_some_and(|id| id.0 >= self.comp.nodes.len()) { | |
| 332 | self.viewers[slot].viewed_node = self.comp.default_output_node(); | |
| 333 | } | |
| 334 | } | |
| 335 | self.flow.viewed_nodes = [self.viewers[0].viewed_node, self.viewers[1].viewed_node]; | |
| 336 | self.spline.set_target_node(&self.comp, self.flow.primary); | |
| 337 | self.renaming_node = None; | |
| 334 | self.reconcile_node_refs(prev_viewed); | |
| 338 | 335 | self.invalidate_node(None); |
| 339 | 336 | self.set_notice(format!("Undo: {label}")); |
| 340 | 337 | } else { |
| ... | ... | @@ -344,16 +341,9 @@ impl Studio { |
| 344 | 341 | |
| 345 | 342 | pub(crate) fn redo(&mut self) { |
| 346 | 343 | let label = self.history.redo_label().unwrap_or("Edit").to_owned(); |
| 344 | let prev_viewed = self.viewed_names(); | |
| 347 | 345 | if self.history.redo(&mut self.comp) { |
| 348 | self.flow.sanitize_ids(&self.comp); | |
| 349 | for slot in [0usize, 1] { | |
| 350 | if self.viewers[slot].viewed_node.is_some_and(|id| id.0 >= self.comp.nodes.len()) { | |
| 351 | self.viewers[slot].viewed_node = self.comp.default_output_node(); | |
| 352 | } | |
| 353 | } | |
| 354 | self.flow.viewed_nodes = [self.viewers[0].viewed_node, self.viewers[1].viewed_node]; | |
| 355 | self.spline.set_target_node(&self.comp, self.flow.primary); | |
| 356 | self.renaming_node = None; | |
| 346 | self.reconcile_node_refs(prev_viewed); | |
| 357 | 347 | self.invalidate_node(None); |
| 358 | 348 | self.set_notice(format!("Redo: {label}")); |
| 359 | 349 | } else { |
| ... | ... | @@ -433,6 +423,8 @@ impl Studio { |
| 433 | 423 | self.sync_audio(true, false); |
| 434 | 424 | } |
| 435 | 425 | self.comp = new_comp; |
| 426 | // The old viewed nodes mean nothing in the new comp; viewers fall back to its output below. | |
| 427 | self.reconcile_node_refs([None, None]); | |
| 436 | 428 | self.history.clear(); |
| 437 | 429 | self.history.mark_saved(&self.comp); |
| 438 | 430 | self.engine.bust_all_caches(); |
| ... | ... | @@ -460,7 +452,7 @@ impl Studio { |
| 460 | 452 | self.flow.selected.insert(id); |
| 461 | 453 | self.flow.primary = Some(id); |
| 462 | 454 | } |
| 463 | self.spline.set_target_node(&self.comp, default_sel); | |
| 455 | self.spline.refresh_for_comp(&self.comp, default_sel, true); | |
| 464 | 456 | self.keyframes.audio_peaks.clear(); |
| 465 | 457 | self.keyframes.cached_ranges.clear(); |
| 466 | 458 | self.keyframes.fit_comp(&self.comp); |
| ... | ... | @@ -471,8 +463,6 @@ impl Studio { |
| 471 | 463 | pf.cancel(); |
| 472 | 464 | } |
| 473 | 465 | self.last_prefetch_sig = None; |
| 474 | self.inspector.reset(); | |
| 475 | self.renaming_node = None; | |
| 476 | 466 | self.loaded_audio_track = None; |
| 477 | 467 | self.last_audio_offset = self.comp.audio_offset; |
| 478 | 468 | self.last_fps = self.comp.fps; |
| ... | ... | @@ -493,8 +483,7 @@ impl Studio { |
| 493 | 483 | } |
| 494 | 484 | |
| 495 | 485 | pub(crate) fn paste_nodes(&mut self) { |
| 496 | if !self.flow.scope_path().is_empty() { | |
| 497 | self.set_notice("Group contents are read-only; press Esc to leave the group before pasting"); | |
| 486 | if self.reject_in_group("pasting") { | |
| 498 | 487 | return; |
| 499 | 488 | } |
| 500 | 489 | let Some(text) = self.ui.clipboard.text() else { |
crates/app/src/playback_ui.rs+76-39| ... | ... | @@ -1,15 +1,21 @@ |
| 1 | 1 | //! Live playback tick/audio sync, RAM cache prefetcher management, and viewer rendering/routing helpers. |
| 2 | 2 | |
| 3 | use crate::inspector::{KeyframeState, keyframe_state}; | |
| 3 | 4 | use crate::{Studio, viewer_canvas_id}; |
| 4 | 5 | use dock::Place; |
| 5 | 6 | use dock::Side; |
| 6 | 7 | use engine::{AudioTrack, CacheMode, PrefetchJob}; |
| 7 | use model::{Comp, NodeId}; | |
| 8 | use model::{Comp, NodeId, ParamValue}; | |
| 8 | 9 | use std::path::PathBuf; |
| 9 | 10 | use std::sync::{Arc, mpsc}; |
| 10 | 11 | use std::time::Instant; |
| 11 | 12 | use viewer::{SyncMode, ViewerAction}; |
| 12 | 13 | |
| 14 | const PREFETCH_LOOKAHEAD: i64 = 24; | |
| 15 | ||
| 16 | /// What a lookahead job renders, plus the playhead frame it was centered on. | |
| 17 | pub(crate) type PrefetchSig = ((NodeId, u64, u32, bool, bool, [i64; 2]), i64); | |
| 18 | ||
| 13 | 19 | pub(crate) fn spawn_audio_loader(comp: &Comp) -> Option<mpsc::Receiver<Result<AudioTrack, String>>> { |
| 14 | 20 | comp.audio_filename.as_ref().and_then(|af| { |
| 15 | 21 | let p = PathBuf::from(af); |
| ... | ... | @@ -144,11 +150,19 @@ impl Studio { |
| 144 | 150 | if self.playback.playing { |
| 145 | 151 | if let Some(player) = &mut self.audio_player { |
| 146 | 152 | let expected = self.playback.expected_audio_secs(&self.comp, now); |
| 147 | if !player.is_playing() { | |
| 153 | let frame_dur = 1.0 / self.comp.fps.max(1.0); | |
| 154 | // Every-frame playback that renders slower than realtime would re-seek the audio on | |
| 155 | // every frame; hold it silent until rendering keeps up again. | |
| 156 | let falling_behind = self.playback.sync_mode == SyncMode::EveryFrame | |
| 157 | && self.viewers[0].last_stats.eval_ms / 1000.0 > frame_dur; | |
| 158 | if falling_behind { | |
| 159 | if player.is_playing() { | |
| 160 | player.pause(); | |
| 161 | } | |
| 162 | } else if !player.is_playing() { | |
| 148 | 163 | player.play_from(expected); |
| 149 | 164 | } else { |
| 150 | 165 | let actual = player.current_time_secs(); |
| 151 | let frame_dur = 1.0 / self.comp.fps.max(1.0); | |
| 152 | 166 | let max_drift = (frame_dur * 1.25).max(0.045); |
| 153 | 167 | if (actual - expected).abs() > max_drift { |
| 154 | 168 | player.seek(expected); |
| ... | ... | @@ -180,47 +194,55 @@ impl Studio { |
| 180 | 194 | for v in &mut self.viewers { |
| 181 | 195 | v.selected_node = sel; |
| 182 | 196 | } |
| 183 | if let Some(target) = self.viewers[0].viewed_node { | |
| 184 | let ranges = self.ram_cache.cached_frame_ranges( | |
| 185 | target, | |
| 186 | self.comp.revision, | |
| 187 | self.engine.proxy_scale, | |
| 188 | self.engine.hiq, | |
| 189 | self.engine.use_proxy_clips, | |
| 190 | ); | |
| 191 | self.viewers[0].ram_cached_ranges = ranges.clone(); | |
| 192 | self.keyframes.cached_ranges = ranges; | |
| 193 | ||
| 194 | if let Some(pf) = &mut self.prefetcher { | |
| 195 | if self.engine.cache.mode == CacheMode::Enabled { | |
| 196 | let cur_f = self.playback.current_frame.round() as i64; | |
| 197 | let sig = ( | |
| 198 | target, | |
| 199 | cur_f, | |
| 197 | for v in &mut self.viewers { | |
| 198 | v.ram_cached_ranges = v | |
| 199 | .viewed_node | |
| 200 | .filter(|id| id.0 < self.comp.nodes.len()) | |
| 201 | .map(|id| { | |
| 202 | self.ram_cache.cached_frame_ranges( | |
| 203 | id, | |
| 200 | 204 | self.comp.revision, |
| 201 | 205 | self.engine.proxy_scale, |
| 202 | 206 | self.engine.hiq, |
| 203 | 207 | self.engine.use_proxy_clips, |
| 204 | ); | |
| 205 | if self.last_prefetch_sig != Some(sig) { | |
| 206 | self.last_prefetch_sig = Some(sig); | |
| 207 | self.ram_cache.invalidate_other_revisions(self.comp.revision); | |
| 208 | pf.request_lookahead(PrefetchJob { | |
| 209 | comp: self.comp.clone(), | |
| 210 | target, | |
| 211 | center_frame: cur_f, | |
| 212 | range: self.comp.render_range, | |
| 213 | lookahead: 24, | |
| 214 | proxy_scale: self.engine.proxy_scale, | |
| 215 | hiq: self.engine.hiq, | |
| 216 | use_proxy_clips: self.engine.use_proxy_clips, | |
| 217 | }); | |
| 218 | } | |
| 208 | ) | |
| 209 | }) | |
| 210 | .unwrap_or_default(); | |
| 211 | } | |
| 212 | self.keyframes.cached_ranges = self.viewers[0].ram_cached_ranges.clone(); | |
| 213 | ||
| 214 | let target = self.viewers[0].viewed_node.filter(|id| id.0 < self.comp.nodes.len()); | |
| 215 | if let (Some(target), Some(pf)) = (target, &mut self.prefetcher) { | |
| 216 | if self.engine.cache.mode == CacheMode::Enabled { | |
| 217 | let cur_f = self.playback.current_frame.round() as i64; | |
| 218 | let key = ( | |
| 219 | target, | |
| 220 | self.comp.revision, | |
| 221 | self.engine.proxy_scale, | |
| 222 | self.engine.hiq, | |
| 223 | self.engine.use_proxy_clips, | |
| 224 | self.comp.render_range, | |
| 225 | ); | |
| 226 | // Re-plan only when the job changes or the playhead leaves the half of the window | |
| 227 | // already being filled, so steady playback never re-clones the comp per frame. | |
| 228 | let covered = self.last_prefetch_sig.is_some_and(|(k, center)| { | |
| 229 | k == key && (center..=center + PREFETCH_LOOKAHEAD / 2).contains(&cur_f) | |
| 230 | }); | |
| 231 | if !covered { | |
| 232 | self.last_prefetch_sig = Some((key, cur_f)); | |
| 233 | self.ram_cache.invalidate_other_revisions(self.comp.revision); | |
| 234 | pf.request_lookahead(PrefetchJob { | |
| 235 | comp: self.comp.clone(), | |
| 236 | target, | |
| 237 | center_frame: cur_f, | |
| 238 | range: self.comp.render_range, | |
| 239 | lookahead: PREFETCH_LOOKAHEAD, | |
| 240 | proxy_scale: self.engine.proxy_scale, | |
| 241 | hiq: self.engine.hiq, | |
| 242 | use_proxy_clips: self.engine.use_proxy_clips, | |
| 243 | }); | |
| 219 | 244 | } |
| 220 | 245 | } |
| 221 | } else { | |
| 222 | self.viewers[0].ram_cached_ranges.clear(); | |
| 223 | self.keyframes.cached_ranges.clear(); | |
| 224 | 246 | } |
| 225 | 247 | } |
| 226 | 248 | |
| ... | ... | @@ -403,10 +425,25 @@ impl Studio { |
| 403 | 425 | self.clear_viewers(); |
| 404 | 426 | } |
| 405 | 427 | ViewerAction::GizmoEdited(edit) => { |
| 428 | if edit.node_id.0 >= self.comp.nodes.len() { | |
| 429 | continue; | |
| 430 | } | |
| 406 | 431 | self.history.push_coalesced(&self.comp, edit.label, &edit.coalesce_key); |
| 407 | self.comp.set_input_value(edit.node_id, edit.input, edit.value); | |
| 432 | let frame = self.playback.current_frame; | |
| 433 | match edit.value { | |
| 434 | // A spline-driven scalar would ignore a static write, so key it like the Inspector does. | |
| 435 | ParamValue::Number(v) | |
| 436 | if keyframe_state(&self.comp, edit.node_id, edit.input, frame) != KeyframeState::Static => | |
| 437 | { | |
| 438 | let _ = self.comp.set_keyframe(edit.node_id, edit.input, frame, v); | |
| 439 | } | |
| 440 | value => { | |
| 441 | self.comp.set_input_value(edit.node_id, edit.input, value); | |
| 442 | } | |
| 443 | } | |
| 408 | 444 | self.invalidate_node(Some(edit.node_id)); |
| 409 | 445 | } |
| 446 | ViewerAction::GizmoDragEnded => self.history.break_coalescing(), | |
| 410 | 447 | ViewerAction::ExportPreviewMp4(v_slot) => { |
| 411 | 448 | let _ = self.export_viewer_mp4(v_slot); |
| 412 | 449 | } |
crates/flow/src/lib.rs+111-33| ... | ... | @@ -22,8 +22,10 @@ use winit::keyboard::{Key, KeyCode, ModifiersState, NamedKey, PhysicalKey}; |
| 22 | 22 | const NODE_W: f32 = 84.0; |
| 23 | 23 | const NODE_H: f32 = 21.0; |
| 24 | 24 | const DOUBLE_CLICK: Duration = Duration::from_millis(400); |
| 25 | /// Stale label layouts (renamed nodes) tolerated before the cache is rebuilt. | |
| 26 | const LABEL_CACHE_SLACK: usize = 512; | |
| 25 | 27 | |
| 26 | const HUD_ROOT: &str = "Shift+Space: Add Tool G/R/S: Transform Shift+Drag: Splice Del: Delete Cmd+C/V: Copy/Paste Cmd+D: Dup F2: Rename Ctrl+P: Bypass 1/2: Viewer Dbl-click group: Enter"; | |
| 28 | const HUD_ROOT: &str = "Shift+Space: Add Tool G/R/S: Transform Shift+Drag: Splice Del: Delete Cmd+C/V: Copy/Paste Cmd+D: Dup F2: Rename P: Bypass 1/2: Viewer Dbl-click group: Enter"; | |
| 27 | 29 | const HUD_GROUP: &str = "Group contents are read-only Dbl-click nested group: Enter Cmd+C: Copy 1/2: Viewer F: Fit Esc: Back"; |
| 28 | 30 | |
| 29 | 31 | #[derive(Clone, Copy, Debug, PartialEq, Eq)] |
| ... | ... | @@ -655,6 +657,13 @@ impl FlowView { |
| 655 | 657 | self.hovered_wire = None; |
| 656 | 658 | } |
| 657 | 659 | |
| 660 | /// Drops an in-flight wire drag; a detached input is wired back. | |
| 661 | fn cancel_wire_drag(&mut self, comp: &mut Comp, history: &mut CompHistory, actions: &mut Vec<FlowAction>) { | |
| 662 | if self.wire_drag.take().is_some_and(|wd| wd.detached_from.is_some()) && history.cancel_group(comp) { | |
| 663 | actions.push(FlowAction::GraphMutated(None)); | |
| 664 | } | |
| 665 | } | |
| 666 | ||
| 658 | 667 | fn handle_key( |
| 659 | 668 | &mut self, |
| 660 | 669 | comp: &mut Comp, |
| ... | ... | @@ -664,6 +673,13 @@ impl FlowView { |
| 664 | 673 | kmod: ModifiersState, |
| 665 | 674 | actions: &mut Vec<FlowAction>, |
| 666 | 675 | ) { |
| 676 | // An open modal or wire drag owns a history group; only keys that end or steer it may act. | |
| 677 | let steering = matches!(key, Key::Named(NamedKey::Escape | NamedKey::Enter)) | |
| 678 | || (self.modal.is_some() | |
| 679 | && matches!(key, Key::Character(c) if matches!(c.to_ascii_lowercase().as_str(), "x" | "y"))); | |
| 680 | if (self.modal.is_some() || self.wire_drag.is_some()) && !steering { | |
| 681 | return; | |
| 682 | } | |
| 667 | 683 | // Shift+Space: open Add Tool launcher |
| 668 | 684 | if kmod.shift_key() |
| 669 | 685 | && !kmod.super_key() |
| ... | ... | @@ -684,13 +700,14 @@ impl FlowView { |
| 684 | 700 | return; |
| 685 | 701 | } |
| 686 | 702 | let cmd = kmod.super_key() || kmod.control_key(); |
| 703 | let plain = !cmd && !kmod.alt_key(); | |
| 687 | 704 | match key { |
| 688 | 705 | Key::Named(NamedKey::Escape) => { |
| 689 | 706 | if self.modal.is_some() || self.wire_drag.is_some() { |
| 690 | 707 | if self.modal.is_some() { |
| 691 | 708 | self.cancel_modal(comp, history); |
| 692 | 709 | } |
| 693 | self.wire_drag = None; | |
| 710 | self.cancel_wire_drag(comp, history, actions); | |
| 694 | 711 | } else if self.exit_group(comp) { |
| 695 | 712 | actions.push(FlowAction::SelectionChanged(self.primary)); |
| 696 | 713 | actions.push(FlowAction::ScopeChanged); |
| ... | ... | @@ -764,34 +781,33 @@ impl FlowView { |
| 764 | 781 | } |
| 765 | 782 | } |
| 766 | 783 | } |
| 767 | "f" if kmod.super_key() => self.fit_all(comp), | |
| 768 | "f" if !kmod.super_key() => self.fit_all(comp), | |
| 769 | "." if !kmod.super_key() => self.fit_all(comp), | |
| 770 | "g" if !cmd && self.modal.is_none() && !self.scope.is_root() => read_only_notice(actions), | |
| 771 | "g" if !cmd && self.modal.is_none() => { | |
| 784 | "f" if !kmod.control_key() && !kmod.alt_key() => self.fit_all(comp), | |
| 785 | "." if plain => self.fit_all(comp), | |
| 786 | "g" if plain && self.modal.is_none() && !self.scope.is_root() => read_only_notice(actions), | |
| 787 | "g" if plain && self.modal.is_none() => { | |
| 772 | 788 | self.begin_modal(comp, history, TransformMode::Grab); |
| 773 | 789 | } |
| 774 | "r" if !cmd && self.modal.is_none() && !self.scope.is_root() => read_only_notice(actions), | |
| 775 | "r" if !cmd && self.modal.is_none() => { | |
| 790 | "r" if plain && self.modal.is_none() && !self.scope.is_root() => read_only_notice(actions), | |
| 791 | "r" if plain && self.modal.is_none() => { | |
| 776 | 792 | self.begin_modal(comp, history, TransformMode::Rotate); |
| 777 | 793 | } |
| 778 | "s" if !cmd && self.modal.is_none() && !self.scope.is_root() => read_only_notice(actions), | |
| 779 | "s" if !cmd && self.modal.is_none() => { | |
| 794 | "s" if plain && self.modal.is_none() && !self.scope.is_root() => read_only_notice(actions), | |
| 795 | "s" if plain && self.modal.is_none() => { | |
| 780 | 796 | self.begin_modal(comp, history, TransformMode::Scale); |
| 781 | 797 | } |
| 782 | "x" if self.modal.is_some() => { | |
| 798 | "x" if plain && self.modal.is_some() => { | |
| 783 | 799 | if let Some(m) = &mut self.modal { |
| 784 | 800 | m.axis = if m.axis == AxisLock::X { AxisLock::None } else { AxisLock::X }; |
| 785 | 801 | } |
| 786 | 802 | self.apply_modal(comp, kmod.shift_key()); |
| 787 | 803 | } |
| 788 | "y" if self.modal.is_some() => { | |
| 804 | "y" if plain && self.modal.is_some() => { | |
| 789 | 805 | if let Some(m) = &mut self.modal { |
| 790 | 806 | m.axis = if m.axis == AxisLock::Y { AxisLock::None } else { AxisLock::Y }; |
| 791 | 807 | } |
| 792 | 808 | self.apply_modal(comp, kmod.shift_key()); |
| 793 | 809 | } |
| 794 | "a" if !kmod.super_key() => { | |
| 810 | "a" if plain => { | |
| 795 | 811 | let visible = self.scope.visible(comp); |
| 796 | 812 | if self.selected.len() == visible.len() { |
| 797 | 813 | self.selected.clear(); |
| ... | ... | @@ -802,20 +818,20 @@ impl FlowView { |
| 802 | 818 | } |
| 803 | 819 | actions.push(FlowAction::SelectionChanged(self.primary)); |
| 804 | 820 | } |
| 805 | "1" if !cmd => { | |
| 821 | "1" if plain => { | |
| 806 | 822 | if let Some(id) = self.primary { |
| 807 | 823 | self.viewed_nodes[0] = Some(id); |
| 808 | 824 | actions.push(FlowAction::ViewNode(0, id)); |
| 809 | 825 | } |
| 810 | 826 | } |
| 811 | "2" if !cmd => { | |
| 827 | "2" if plain => { | |
| 812 | 828 | if let Some(id) = self.primary { |
| 813 | 829 | self.viewed_nodes[1] = Some(id); |
| 814 | 830 | actions.push(FlowAction::ViewNode(1, id)); |
| 815 | 831 | } |
| 816 | 832 | } |
| 817 | "p" if !kmod.super_key() && !self.scope.is_root() => read_only_notice(actions), | |
| 818 | "p" if !kmod.super_key() => { | |
| 833 | "p" if plain && !self.scope.is_root() => read_only_notice(actions), | |
| 834 | "p" if plain => { | |
| 819 | 835 | if !self.selected.is_empty() { |
| 820 | 836 | let ids: Vec<NodeId> = self.selected.iter().copied().collect(); |
| 821 | 837 | history.push_snapshot(comp, "Toggle Passthrough"); |
| ... | ... | @@ -898,13 +914,13 @@ impl FlowView { |
| 898 | 914 | if pressed && self.modal.is_some() { |
| 899 | 915 | self.cancel_modal(comp, history); |
| 900 | 916 | } else if pressed && self.wire_drag.is_some() { |
| 901 | self.wire_drag = None; | |
| 917 | self.cancel_wire_drag(comp, history, &mut actions); | |
| 902 | 918 | } else if pressed { |
| 903 | 919 | // Right-click a hovered wire or connected input port to disconnect it! |
| 904 | 920 | if !self.scope.is_root() { |
| 905 | 921 | read_only_notice(&mut actions); |
| 906 | 922 | } else if let Some(w) = self.hit_wire(comp, self.pointer_local, None) { |
| 907 | history.push_snapshot(comp, "Disconnect"); | |
| 923 | history.begin_group(comp, "Disconnect"); | |
| 908 | 924 | if comp.disconnect(w.dst, &w.port) { |
| 909 | 925 | self.hovered_wire = None; |
| 910 | 926 | actions.push(FlowAction::GraphMutated(Some(w.dst))); |
| ... | ... | @@ -914,6 +930,7 @@ impl FlowView { |
| 914 | 930 | w.port |
| 915 | 931 | ))); |
| 916 | 932 | } |
| 933 | history.commit_group(comp); | |
| 917 | 934 | } |
| 918 | 935 | } |
| 919 | 936 | } else if button == MouseButton::Left { |
| ... | ... | @@ -929,7 +946,7 @@ impl FlowView { |
| 929 | 946 | }); |
| 930 | 947 | } else if let Some((dst, port, src)) = self.hit_connected_input_port(comp, self.pointer_local).filter(|_| self.scope.is_root()) { |
| 931 | 948 | // Dragging an existing input port detaches it so user can drop to disconnect or rewire! |
| 932 | history.push_snapshot(comp, "Disconnect"); | |
| 949 | history.begin_group(comp, "Rewire"); | |
| 933 | 950 | comp.disconnect(dst, &port); |
| 934 | 951 | actions.push(FlowAction::GraphMutated(Some(dst))); |
| 935 | 952 | self.wire_drag = Some(WireDrag { |
| ... | ... | @@ -982,25 +999,30 @@ impl FlowView { |
| 982 | 999 | } |
| 983 | 1000 | } |
| 984 | 1001 | if let Some(wd) = self.wire_drag.take() { |
| 1002 | let detached = wd.detached_from.is_some(); | |
| 985 | 1003 | if let Some((dst, port)) = self.hit_input_port(comp, self.pointer_local) { |
| 986 | if comp.would_create_cycle(wd.src, dst) { | |
| 987 | actions.push(FlowAction::StatusNotice( | |
| 988 | "Cycle rejected: cannot connect downstream to upstream".to_owned(), | |
| 989 | )); | |
| 1004 | if !detached { | |
| 1005 | history.begin_group(comp, "Connect"); | |
| 1006 | } | |
| 1007 | let result = if comp.would_create_cycle(wd.src, dst) { | |
| 1008 | Err("Cycle rejected: cannot connect downstream to upstream".to_owned()) | |
| 990 | 1009 | } else { |
| 991 | if wd.detached_from.is_none() { | |
| 992 | history.push_snapshot(comp, "Connect"); | |
| 1010 | comp.connect_output(wd.src, "Output", dst, port) | |
| 1011 | }; | |
| 1012 | match result { | |
| 1013 | Ok(()) => { | |
| 1014 | history.commit_group(comp); | |
| 1015 | actions.push(FlowAction::GraphMutated(Some(dst))); | |
| 993 | 1016 | } |
| 994 | match comp.connect_output(wd.src, "Output", dst, port) { | |
| 995 | Ok(()) => { | |
| 996 | actions.push(FlowAction::GraphMutated(Some(dst))); | |
| 997 | } | |
| 998 | Err(e) => { | |
| 999 | actions.push(FlowAction::StatusNotice(e)); | |
| 1017 | Err(e) => { | |
| 1018 | if history.cancel_group(comp) && detached { | |
| 1019 | actions.push(FlowAction::GraphMutated(None)); | |
| 1000 | 1020 | } |
| 1021 | actions.push(FlowAction::StatusNotice(e)); | |
| 1001 | 1022 | } |
| 1002 | 1023 | } |
| 1003 | 1024 | } else if let Some((dst, port)) = wd.detached_from { |
| 1025 | history.commit_group(comp); | |
| 1004 | 1026 | actions.push(FlowAction::StatusNotice(format!( |
| 1005 | 1027 | "Disconnected {}.{}", |
| 1006 | 1028 | comp.node(dst).name, |
| ... | ... | @@ -1095,6 +1117,9 @@ impl FlowView { |
| 1095 | 1117 | } |
| 1096 | 1118 | .layout() |
| 1097 | 1119 | }; |
| 1120 | if self.label_cache.len() > comp.nodes.len() + LABEL_CACHE_SLACK { | |
| 1121 | self.label_cache.clear(); | |
| 1122 | } | |
| 1098 | 1123 | for n in &comp.nodes { |
| 1099 | 1124 | self.label_cache.entry(n.name.clone()).or_insert_with(|| make_layout(&n.name, &label_font)); |
| 1100 | 1125 | } |
| ... | ... | @@ -1929,4 +1954,57 @@ mod tests { |
| 1929 | 1954 | assert!(flow.scope_path().is_empty()); |
| 1930 | 1955 | assert!(flow.selected.is_empty()); |
| 1931 | 1956 | } |
| 1957 | ||
| 1958 | #[test] | |
| 1959 | fn escape_during_wire_detach_restores_the_wire_without_an_undo_entry() { | |
| 1960 | let mut comp = test_comp(); | |
| 1961 | let mut history = CompHistory::new(); | |
| 1962 | let theme = ui::Theme::new(&theme::KNIFE, true); | |
| 1963 | let mut flow = FlowView::new(&theme); | |
| 1964 | flow.size = [800.0, 600.0]; | |
| 1965 | flow.pan = [80.0, 0.0]; | |
| 1966 | flow.zoom = 1.0; | |
| 1967 | let (bg, merge) = (id(&comp, "BG1"), id(&comp, "Merge1")); | |
| 1968 | let (_, _, b, be) = flow.wire_endpoints(&comp, bg, merge, PortRole::Background); | |
| 1969 | let n = be.normal(); | |
| 1970 | let port = [b[0] + n[0] * 4.0, b[1] + n[1] * 4.0]; | |
| 1971 | let rect = [0.0, 0.0, 800.0, 600.0]; | |
| 1972 | ||
| 1973 | flow.input( | |
| 1974 | &mut comp, | |
| 1975 | &mut history, | |
| 1976 | ui::Event::Button { button: MouseButton::Left, pressed: true, at: Instant::now() }, | |
| 1977 | rect, | |
| 1978 | port, | |
| 1979 | ModifiersState::empty(), | |
| 1980 | ); | |
| 1981 | assert!(flow.wire_drag.is_some()); | |
| 1982 | assert!(comp.node(merge).inputs["Background"].source_op.is_none()); | |
| 1983 | ||
| 1984 | let acts = key(&mut flow, &mut comp, &mut history, Key::Named(NamedKey::Escape), ModifiersState::empty()); | |
| 1985 | assert!(flow.wire_drag.is_none()); | |
| 1986 | assert_eq!(comp.node(merge).inputs["Background"].source_op.as_deref(), Some("BG1")); | |
| 1987 | assert!(acts.iter().any(|a| matches!(a, FlowAction::GraphMutated(_)))); | |
| 1988 | assert!(!history.can_undo() && !history.in_group()); | |
| 1989 | } | |
| 1990 | ||
| 1991 | #[test] | |
| 1992 | fn letter_shortcuts_ignore_ctrl_and_alt() { | |
| 1993 | let (mut comp, mut flow) = group_flow(); | |
| 1994 | let mut history = CompHistory::new(); | |
| 1995 | let bg = id(&comp, "BG1"); | |
| 1996 | flow.selected.insert(bg); | |
| 1997 | flow.primary = Some(bg); | |
| 1998 | ||
| 1999 | for mods in [ModifiersState::CONTROL, ModifiersState::ALT] { | |
| 2000 | for k in ["g", "r", "s", "p", "1"] { | |
| 2001 | let acts = key(&mut flow, &mut comp, &mut history, Key::Character(k.into()), mods); | |
| 2002 | assert!(flow.modal.is_none() && acts.is_empty(), "{k} with {mods:?}"); | |
| 2003 | } | |
| 2004 | } | |
| 2005 | assert!(!comp.node(bg).bypassed); | |
| 2006 | key(&mut flow, &mut comp, &mut history, Key::Character("g".into()), ModifiersState::empty()); | |
| 2007 | assert!(flow.modal.is_some()); | |
| 2008 | assert!(history.in_group()); | |
| 2009 | } | |
| 1932 | 2010 | } |
crates/spline/src/lib.rs+245-42| ... | ... | @@ -13,7 +13,7 @@ pub mod presets; |
| 13 | 13 | |
| 14 | 14 | pub use presets::EasingPreset; |
| 15 | 15 | |
| 16 | use model::{Comp, CompHistory, HandleMode, Keyframe, NodeId}; | |
| 16 | use model::{BezierSpline, Comp, CompHistory, HandleMode, Keyframe, NodeId}; | |
| 17 | 17 | use presets::{ |
| 18 | 18 | apply_easing_preset, apply_handle_mode, compute_curve_bounds, display_to_value, |
| 19 | 19 | enforce_aligned_handle, value_to_display, |
| ... | ... | @@ -22,6 +22,8 @@ use std::collections::{HashMap, HashSet}; |
| 22 | 22 | use winit::event::{ElementState, MouseButton}; |
| 23 | 23 | use winit::keyboard::{Key, KeyCode, ModifiersState, NamedKey, PhysicalKey}; |
| 24 | 24 | |
| 25 | /// Layout entries kept before the label cache is rebuilt; panning and zooming mint new tick labels. | |
| 26 | const TEXT_CACHE_CAP: usize = 512; | |
| 25 | 27 | const RULER_H: f32 = 24.0; |
| 26 | 28 | const SIDEBAR_W: f32 = 172.0; |
| 27 | 29 | const POPUP_W: f32 = 156.0; |
| ... | ... | @@ -66,6 +68,9 @@ struct ModalEdit { |
| 66 | 68 | /// Pointer at modal start in display coordinates `(time, display_value)`. |
| 67 | 69 | start_pointer: [f64; 2], |
| 68 | 70 | saved_splines: HashMap<String, Vec<Keyframe>>, |
| 71 | /// Selection when the modal began; indices refer to `saved_splines`, while `SplineView::selected` | |
| 72 | /// follows the keys through each re-sort. | |
| 73 | orig_selected: HashSet<PointRef>, | |
| 69 | 74 | /// Frozen per-spline `(min_v, max_v)` bounds captured when the modal began so normalized |
| 70 | 75 | /// drags stay stable without shifting scale mid-drag. |
| 71 | 76 | saved_bounds: HashMap<String, (f64, f64)>, |
| ... | ... | @@ -203,15 +208,25 @@ impl SplineView { |
| 203 | 208 | self.palette.bg |
| 204 | 209 | } |
| 205 | 210 | |
| 211 | /// Retargets the editor; a no-op while the same node is already showing channels. | |
| 206 | 212 | pub fn set_target_node(&mut self, comp: &Comp, selected_node: Option<NodeId>) { |
| 207 | 213 | if self.current_node == selected_node && !self.channels.is_empty() { |
| 208 | 214 | return; |
| 209 | 215 | } |
| 216 | self.refresh_for_comp(comp, selected_node, true); | |
| 217 | } | |
| 218 | ||
| 219 | /// Rebuilds the channel list from `comp` and drops selection and in-flight edits that may | |
| 220 | /// refer to splines or keys that no longer exist (undo, redo, reload, rename, key add/delete). | |
| 221 | pub fn refresh_for_comp(&mut self, comp: &Comp, selected_node: Option<NodeId>, reset_view: bool) { | |
| 222 | let selected_node = selected_node.filter(|id| id.0 < comp.nodes.len()); | |
| 210 | 223 | self.current_node = selected_node; |
| 211 | 224 | self.selected.clear(); |
| 225 | self.hovered = None; | |
| 212 | 226 | self.modal = None; |
| 213 | 227 | self.popup = None; |
| 214 | 228 | self.lmb_drag_point = None; |
| 229 | self.box_select = None; | |
| 215 | 230 | |
| 216 | 231 | let mut ch = selected_node |
| 217 | 232 | .map(|id| comp.node_splines(id)) |
| ... | ... | @@ -231,7 +246,9 @@ impl SplineView { |
| 231 | 246 | } |
| 232 | 247 | } |
| 233 | 248 | self.channels = ch; |
| 234 | self.fit_all(comp); | |
| 249 | if reset_view { | |
| 250 | self.fit_all(comp); | |
| 251 | } | |
| 235 | 252 | } |
| 236 | 253 | |
| 237 | 254 | pub fn toggle_normalized(&mut self, comp: &Comp) { |
| ... | ... | @@ -444,6 +461,7 @@ impl SplineView { |
| 444 | 461 | pivot: [sum_t / count as f64, sum_v / count as f64], |
| 445 | 462 | start_pointer: self.local_to_data(self.pointer_local), |
| 446 | 463 | saved_splines: saved, |
| 464 | orig_selected: self.selected.clone(), | |
| 447 | 465 | saved_bounds, |
| 448 | 466 | pre_edit_snapshot: capture_history.then(|| comp.clone()), |
| 449 | 467 | }); |
| ... | ... | @@ -463,6 +481,13 @@ impl SplineView { |
| 463 | 481 | } |
| 464 | 482 | } |
| 465 | 483 | |
| 484 | // A selected key carries its handles, so a handle also in the selection must not move twice. | |
| 485 | let selected = &m.orig_selected; | |
| 486 | let moves = |pref: &PointRef| { | |
| 487 | pref.part == HandlePart::Key | |
| 488 | || !selected.contains(&PointRef { spline: pref.spline.clone(), key_idx: pref.key_idx, part: HandlePart::Key }) | |
| 489 | }; | |
| 490 | ||
| 466 | 491 | let snap_t = |t: f64| if fine { t } else { t.round() }; |
| 467 | 492 | |
| 468 | 493 | // Helper: convert Auto/Vector handles to Aligned/Free when manually dragged (Blender behavior), |
| ... | ... | @@ -498,7 +523,7 @@ impl SplineView { |
| 498 | 523 | AxisLock::X => (dt, 0.0), |
| 499 | 524 | AxisLock::Y => (0.0, dv_disp), |
| 500 | 525 | }; |
| 501 | for pref in &self.selected { | |
| 526 | for pref in selected.iter().filter(|p| moves(p)) { | |
| 502 | 527 | let Some(sp) = comp.splines.get_mut(&pref.spline) else { continue }; |
| 503 | 528 | let bounds = m.saved_bounds.get(&pref.spline).copied().unwrap_or((0.0, 1.0)); |
| 504 | 529 | let mv = if normalized { |
| ... | ... | @@ -527,14 +552,14 @@ impl SplineView { |
| 527 | 552 | h[0] = (h[0] + mt).min(kf.time - 0.01); |
| 528 | 553 | h[1] += mv; |
| 529 | 554 | kf.lh = Some(h); |
| 530 | finalize_handle_drag(kf, pref, &self.selected); | |
| 555 | finalize_handle_drag(kf, pref, selected); | |
| 531 | 556 | } |
| 532 | 557 | HandlePart::RightHandle => { |
| 533 | 558 | let mut h = kf.rh.unwrap_or([kf.time + 5.0, kf.value]); |
| 534 | 559 | h[0] = (h[0] + mt).max(kf.time + 0.01); |
| 535 | 560 | h[1] += mv; |
| 536 | 561 | kf.rh = Some(h); |
| 537 | finalize_handle_drag(kf, pref, &self.selected); | |
| 562 | finalize_handle_drag(kf, pref, selected); | |
| 538 | 563 | } |
| 539 | 564 | } |
| 540 | 565 | } |
| ... | ... | @@ -551,7 +576,7 @@ impl SplineView { |
| 551 | 576 | AxisLock::X => (f, 1.0), |
| 552 | 577 | AxisLock::Y => (1.0, f), |
| 553 | 578 | }; |
| 554 | for pref in &self.selected { | |
| 579 | for pref in selected.iter().filter(|p| moves(p)) { | |
| 555 | 580 | let Some(sp) = comp.splines.get_mut(&pref.spline) else { continue }; |
| 556 | 581 | let bounds = m.saved_bounds.get(&pref.spline).copied().unwrap_or((0.0, 1.0)); |
| 557 | 582 | let piv_val = display_to_value(piv[1], bounds, normalized); |
| ... | ... | @@ -574,14 +599,14 @@ impl SplineView { |
| 574 | 599 | lh[0] = (kf.time + (lh[0] - kf.time) * st).min(kf.time - 0.01); |
| 575 | 600 | lh[1] = kf.value + (lh[1] - kf.value) * sv; |
| 576 | 601 | } |
| 577 | finalize_handle_drag(kf, pref, &self.selected); | |
| 602 | finalize_handle_drag(kf, pref, selected); | |
| 578 | 603 | } |
| 579 | 604 | HandlePart::RightHandle => { |
| 580 | 605 | if let Some(rh) = &mut kf.rh { |
| 581 | 606 | rh[0] = (kf.time + (rh[0] - kf.time) * st).max(kf.time + 0.01); |
| 582 | 607 | rh[1] = kf.value + (rh[1] - kf.value) * sv; |
| 583 | 608 | } |
| 584 | finalize_handle_drag(kf, pref, &self.selected); | |
| 609 | finalize_handle_drag(kf, pref, selected); | |
| 585 | 610 | } |
| 586 | 611 | } |
| 587 | 612 | } |
| ... | ... | @@ -603,13 +628,13 @@ impl SplineView { |
| 603 | 628 | [disp[0], display_to_value(disp[1], bounds, normalized)] |
| 604 | 629 | }; |
| 605 | 630 | |
| 606 | for pref in &self.selected { | |
| 631 | for pref in selected.iter().filter(|p| moves(p)) { | |
| 607 | 632 | let Some(sp) = comp.splines.get_mut(&pref.spline) else { continue }; |
| 608 | 633 | let bounds = m.saved_bounds.get(&pref.spline).copied().unwrap_or((0.0, 1.0)); |
| 609 | 634 | let Some(kf) = sp.keyframes.get_mut(pref.key_idx) else { continue }; |
| 610 | 635 | match pref.part { |
| 611 | 636 | HandlePart::Key => { |
| 612 | if self.selected.len() == 1 { | |
| 637 | if selected.len() == 1 { | |
| 613 | 638 | let kp = self.spline_to_local(kf.time, kf.value, bounds); |
| 614 | 639 | ensure_handles(kf); |
| 615 | 640 | if let Some(lh) = kf.lh { |
| ... | ... | @@ -632,7 +657,7 @@ impl SplineView { |
| 632 | 657 | if let Some(lh) = kf.lh { |
| 633 | 658 | let nl = rot(lh, kp, bounds); |
| 634 | 659 | kf.lh = Some([nl[0].min(kf.time - 0.01), nl[1]]); |
| 635 | finalize_handle_drag(kf, pref, &self.selected); | |
| 660 | finalize_handle_drag(kf, pref, selected); | |
| 636 | 661 | } |
| 637 | 662 | } |
| 638 | 663 | HandlePart::RightHandle => { |
| ... | ... | @@ -640,13 +665,27 @@ impl SplineView { |
| 640 | 665 | if let Some(rh) = kf.rh { |
| 641 | 666 | let nr = rot(rh, kp, bounds); |
| 642 | 667 | kf.rh = Some([nr[0].max(kf.time + 0.01), nr[1]]); |
| 643 | finalize_handle_drag(kf, pref, &self.selected); | |
| 668 | finalize_handle_drag(kf, pref, selected); | |
| 644 | 669 | } |
| 645 | 670 | } |
| 646 | 671 | } |
| 647 | 672 | } |
| 648 | 673 | } |
| 649 | 674 | } |
| 675 | // Keep curves sorted while dragging; selection follows its keys to their new slots. | |
| 676 | let remaps: HashMap<&String, Vec<usize>> = m | |
| 677 | .saved_splines | |
| 678 | .keys() | |
| 679 | .filter_map(|sname| Some((sname, sort_keyframes(comp.splines.get_mut(sname)?)))) | |
| 680 | .collect(); | |
| 681 | let new_selected: HashSet<PointRef> = selected | |
| 682 | .iter() | |
| 683 | .map(|p| PointRef { | |
| 684 | key_idx: remaps.get(&p.spline).and_then(|r| r.get(p.key_idx)).copied().unwrap_or(p.key_idx), | |
| 685 | ..p.clone() | |
| 686 | }) | |
| 687 | .collect(); | |
| 688 | self.selected = new_selected; | |
| 650 | 689 | comp.revision += 1; |
| 651 | 690 | true |
| 652 | 691 | } |
| ... | ... | @@ -658,17 +697,13 @@ impl SplineView { |
| 658 | 697 | sp.keyframes = orig; |
| 659 | 698 | } |
| 660 | 699 | } |
| 700 | self.selected = m.orig_selected; | |
| 661 | 701 | comp.revision += 1; |
| 662 | 702 | } |
| 663 | 703 | } |
| 664 | 704 | |
| 665 | 705 | fn confirm_modal(&mut self, comp: &mut Comp, history: Option<&mut CompHistory>) { |
| 666 | 706 | if let Some(m) = self.modal.take() { |
| 667 | for sname in m.saved_splines.keys() { | |
| 668 | if let Some(sp) = comp.splines.get_mut(sname) { | |
| 669 | sp.sort(); | |
| 670 | } | |
| 671 | } | |
| 672 | 707 | comp.revision += 1; |
| 673 | 708 | if let (Some(h), Some(snap)) = (history, m.pre_edit_snapshot) { |
| 674 | 709 | let label = match m.mode { |
| ... | ... | @@ -850,6 +885,7 @@ impl SplineView { |
| 850 | 885 | self.fit_all(comp); |
| 851 | 886 | return; |
| 852 | 887 | } |
| 888 | let plain = !kmod.super_key() && !kmod.control_key() && !kmod.alt_key(); | |
| 853 | 889 | match key { |
| 854 | 890 | Key::Named(NamedKey::Escape) => { |
| 855 | 891 | if self.modal.is_some() { |
| ... | ... | @@ -869,27 +905,27 @@ impl SplineView { |
| 869 | 905 | } |
| 870 | 906 | } |
| 871 | 907 | Key::Character(c) => match c.to_ascii_lowercase().as_str() { |
| 872 | "f" if kmod.super_key() => self.fit_all(comp), | |
| 873 | "f" | "." if !kmod.super_key() => self.fit_all(comp), | |
| 874 | "n" if !kmod.super_key() && self.modal.is_none() => { | |
| 908 | "f" if !kmod.control_key() && !kmod.alt_key() => self.fit_all(comp), | |
| 909 | "." if plain => self.fit_all(comp), | |
| 910 | "n" if plain && self.modal.is_none() => { | |
| 875 | 911 | self.toggle_normalized(comp); |
| 876 | 912 | } |
| 877 | "v" if !kmod.super_key() && self.modal.is_none() => { | |
| 913 | "v" if plain && self.modal.is_none() => { | |
| 878 | 914 | self.open_popup(PopupKind::HandleType); |
| 879 | 915 | } |
| 880 | "t" if !kmod.super_key() && self.modal.is_none() => { | |
| 916 | "t" if plain && self.modal.is_none() => { | |
| 881 | 917 | self.open_popup(PopupKind::Easing); |
| 882 | 918 | } |
| 883 | "g" if !kmod.super_key() && self.modal.is_none() => { | |
| 919 | "g" if plain && self.modal.is_none() => { | |
| 884 | 920 | self.begin_modal(comp, history.is_some(), TransformMode::Grab); |
| 885 | 921 | } |
| 886 | "r" if !kmod.super_key() && self.modal.is_none() => { | |
| 922 | "r" if plain && self.modal.is_none() => { | |
| 887 | 923 | self.begin_modal(comp, history.is_some(), TransformMode::Rotate); |
| 888 | 924 | } |
| 889 | "s" if !kmod.super_key() && self.modal.is_none() => { | |
| 925 | "s" if plain && self.modal.is_none() => { | |
| 890 | 926 | self.begin_modal(comp, history.is_some(), TransformMode::Scale); |
| 891 | 927 | } |
| 892 | "x" if self.modal.is_some() => { | |
| 928 | "x" if plain && self.modal.is_some() => { | |
| 893 | 929 | if let Some(m) = &mut self.modal { |
| 894 | 930 | m.axis = if m.axis == AxisLock::X { AxisLock::None } else { AxisLock::X }; |
| 895 | 931 | } |
| ... | ... | @@ -897,13 +933,13 @@ impl SplineView { |
| 897 | 933 | actions.push(SplineAction::SplineEdited); |
| 898 | 934 | } |
| 899 | 935 | } |
| 900 | "x" if self.modal.is_none() && !kmod.super_key() => { | |
| 936 | "x" if plain && self.modal.is_none() => { | |
| 901 | 937 | // Blender `X` deletes selected keys when not in a modal transform! |
| 902 | 938 | if self.delete_selected(comp, history) { |
| 903 | 939 | actions.push(SplineAction::SplineEdited); |
| 904 | 940 | } |
| 905 | 941 | } |
| 906 | "y" if self.modal.is_some() => { | |
| 942 | "y" if plain && self.modal.is_some() => { | |
| 907 | 943 | if let Some(m) = &mut self.modal { |
| 908 | 944 | m.axis = if m.axis == AxisLock::Y { AxisLock::None } else { AxisLock::Y }; |
| 909 | 945 | } |
| ... | ... | @@ -911,7 +947,7 @@ impl SplineView { |
| 911 | 947 | actions.push(SplineAction::SplineEdited); |
| 912 | 948 | } |
| 913 | 949 | } |
| 914 | "i" if !kmod.super_key() && self.modal.is_none() => { | |
| 950 | "i" if plain && self.modal.is_none() => { | |
| 915 | 951 | // Blender `I` inserts keyframe at current integer frame on all visible channels |
| 916 | 952 | let t = current_frame.round(); |
| 917 | 953 | let will_insert = self.channels.iter().any(|(_, sname)| { |
| ... | ... | @@ -932,8 +968,18 @@ impl SplineView { |
| 932 | 968 | if let Some(sp) = comp.splines.get_mut(sname) { |
| 933 | 969 | if !sp.keyframes.iter().any(|k| (k.time - t).abs() < 0.5) { |
| 934 | 970 | let v = sp.eval(t); |
| 935 | sp.keyframes.push(Keyframe::new(t, v)); | |
| 936 | sp.sort(); | |
| 971 | let at = sp.keyframes.partition_point(|k| k.time < t); | |
| 972 | sp.keyframes.insert(at, Keyframe::new(t, v)); | |
| 973 | self.selected = self | |
| 974 | .selected | |
| 975 | .drain() | |
| 976 | .map(|mut p| { | |
| 977 | if p.spline == *sname && p.key_idx >= at { | |
| 978 | p.key_idx += 1; | |
| 979 | } | |
| 980 | p | |
| 981 | }) | |
| 982 | .collect(); | |
| 937 | 983 | } |
| 938 | 984 | } |
| 939 | 985 | } |
| ... | ... | @@ -941,7 +987,7 @@ impl SplineView { |
| 941 | 987 | actions.push(SplineAction::SplineEdited); |
| 942 | 988 | } |
| 943 | 989 | } |
| 944 | "a" if !kmod.super_key() => { | |
| 990 | "a" if plain => { | |
| 945 | 991 | if !self.selected.is_empty() { |
| 946 | 992 | self.selected.clear(); |
| 947 | 993 | } else { |
| ... | ... | @@ -961,7 +1007,7 @@ impl SplineView { |
| 961 | 1007 | } |
| 962 | 1008 | } |
| 963 | 1009 | } |
| 964 | "l" => { | |
| 1010 | "l" if plain => { | |
| 965 | 1011 | let by_spline = self.selected_keys_by_spline(comp); |
| 966 | 1012 | if !by_spline.is_empty() { |
| 967 | 1013 | if let Some(h) = history.as_deref_mut() { |
| ... | ... | @@ -1167,15 +1213,6 @@ impl SplineView { |
| 1167 | 1213 | self.selected.clear(); |
| 1168 | 1214 | self.selected.insert(hit); |
| 1169 | 1215 | } |
| 1170 | for pref in &self.selected { | |
| 1171 | if let Some(sp) = comp.splines.get_mut(&pref.spline) { | |
| 1172 | if let Some(kf) = sp.keyframes.get_mut(pref.key_idx) { | |
| 1173 | if !kf.flags.linear { | |
| 1174 | ensure_handles(kf); | |
| 1175 | } | |
| 1176 | } | |
| 1177 | } | |
| 1178 | } | |
| 1179 | 1216 | // Allow direct drag right from mouse down! |
| 1180 | 1217 | self.lmb_drag_point = Some((self.pointer_local, false)); |
| 1181 | 1218 | } else { |
| ... | ... | @@ -1275,6 +1312,18 @@ fn point_in_rect(p: [f32; 2], r: [f32; 4]) -> bool { |
| 1275 | 1312 | p[0] >= r[0] && p[0] <= r[2] && p[1] >= r[1] && p[1] <= r[3] |
| 1276 | 1313 | } |
| 1277 | 1314 | |
| 1315 | /// Sorts `sp.keyframes` by time (stable) and returns each old index's new index. | |
| 1316 | pub fn sort_keyframes(sp: &mut BezierSpline) -> Vec<usize> { | |
| 1317 | let mut order: Vec<usize> = (0..sp.keyframes.len()).collect(); | |
| 1318 | order.sort_by(|&a, &b| sp.keyframes[a].time.total_cmp(&sp.keyframes[b].time)); | |
| 1319 | let mut new_index = vec![0; order.len()]; | |
| 1320 | for (new, &old) in order.iter().enumerate() { | |
| 1321 | new_index[old] = new; | |
| 1322 | } | |
| 1323 | sp.keyframes = order.iter().map(|&old| sp.keyframes[old].clone()).collect(); | |
| 1324 | new_index | |
| 1325 | } | |
| 1326 | ||
| 1278 | 1327 | fn ensure_handles(kf: &mut Keyframe) { |
| 1279 | 1328 | if kf.lh.is_none() { |
| 1280 | 1329 | kf.lh = Some([kf.time - 8.0, kf.value]); |
| ... | ... | @@ -1491,4 +1540,158 @@ mod tests { |
| 1491 | 1540 | ); |
| 1492 | 1541 | assert_eq!(history.undo_len(), 1); |
| 1493 | 1542 | } |
| 1543 | ||
| 1544 | const ANIMATED_COMP: &str = r#"Composition { | |
| 1545 | Tools = ordered() { | |
| 1546 | XF1 = Transform { | |
| 1547 | Inputs = { Size = Input { SourceOp = "XF1Size", Source = "Value", }, }, | |
| 1548 | }, | |
| 1549 | XF1Size = BezierSpline { | |
| 1550 | KeyFrames = { | |
| 1551 | [10] = { 1.0, Flags = { Linear = true } }, | |
| 1552 | [40] = { 2.0, Flags = { Linear = true } }, | |
| 1553 | }, | |
| 1554 | }, | |
| 1555 | }, | |
| 1556 | }"#; | |
| 1557 | ||
| 1558 | fn press(view: &mut SplineView, comp: &mut Comp, at: [f32; 2], pressed: bool) { | |
| 1559 | view.input( | |
| 1560 | comp, | |
| 1561 | 0.0, | |
| 1562 | ui::Event::Button { button: MouseButton::Left, pressed, at: std::time::Instant::now() }, | |
| 1563 | [0.0, 0.0, 800.0, 360.0], | |
| 1564 | at, | |
| 1565 | ModifiersState::empty(), | |
| 1566 | ); | |
| 1567 | } | |
| 1568 | ||
| 1569 | fn key_ref(idx: usize, part: HandlePart) -> PointRef { | |
| 1570 | PointRef { spline: "Gain".to_owned(), key_idx: idx, part } | |
| 1571 | } | |
| 1572 | ||
| 1573 | #[test] | |
| 1574 | fn same_node_id_refreshes_channels_after_comp_replaced() { | |
| 1575 | let animated = Comp::from_fusion_str(ANIMATED_COMP).expect("animated comp"); | |
| 1576 | let static_comp = Comp::from_fusion_str("Composition { Tools = ordered() { XF1 = Transform {}, } }").expect("static comp"); | |
| 1577 | let xf = animated.find_node("XF1").unwrap(); | |
| 1578 | assert_eq!(static_comp.find_node("XF1"), Some(xf)); | |
| 1579 | ||
| 1580 | let mut view = SplineView::new(&ui::Theme::dark()); | |
| 1581 | view.set_target_node(&animated, Some(xf)); | |
| 1582 | assert_eq!(view.channels.len(), 1); | |
| 1583 | view.selected.insert(PointRef { spline: "XF1Size".to_owned(), key_idx: 0, part: HandlePart::Key }); | |
| 1584 | ||
| 1585 | // Same numeric id, different comp (undo/reload): the lazy path keeps stale channels... | |
| 1586 | view.set_target_node(&static_comp, Some(xf)); | |
| 1587 | assert_eq!(view.channels.len(), 1); | |
| 1588 | ||
| 1589 | // ...the explicit refresh never does, and drops selection that pointed into them. | |
| 1590 | view.refresh_for_comp(&static_comp, Some(xf), false); | |
| 1591 | assert!(view.channels.is_empty()); | |
| 1592 | assert!(view.selected.is_empty()); | |
| 1593 | } | |
| 1594 | ||
| 1595 | #[test] | |
| 1596 | fn stale_node_id_never_panics_in_labels_and_paint() { | |
| 1597 | let comp = test_comp(); | |
| 1598 | let mut view = SplineView::new(&ui::Theme::dark()); | |
| 1599 | view.current_node = Some(NodeId(99)); | |
| 1600 | view.prepare_labels(&comp); | |
| 1601 | let _ = view.paint(&comp, 0.0); | |
| 1602 | view.refresh_for_comp(&comp, Some(NodeId(99)), true); | |
| 1603 | assert_eq!(view.current_node, None); | |
| 1604 | } | |
| 1605 | ||
| 1606 | #[test] | |
| 1607 | fn dragging_a_key_past_its_neighbour_keeps_curve_sorted_and_selection_on_the_key() { | |
| 1608 | let mut comp = test_comp(); | |
| 1609 | let mut view = SplineView::new(&ui::Theme::dark()); | |
| 1610 | view.resize([800.0, 360.0]); | |
| 1611 | view.set_target_node(&comp, None); | |
| 1612 | view.selected.insert(key_ref(0, HandlePart::Key)); | |
| 1613 | ||
| 1614 | view.pointer_local = view.spline_to_local(0.0, 10.0, (10.0, 110.0)); | |
| 1615 | view.begin_modal(&comp, false, TransformMode::Grab); | |
| 1616 | view.pointer_local = view.spline_to_local(70.0, 10.0, (10.0, 110.0)); | |
| 1617 | assert!(view.apply_modal(&mut comp, false)); | |
| 1618 | ||
| 1619 | let times: Vec<f64> = comp.splines["Gain"].keyframes.iter().map(|k| k.time).collect(); | |
| 1620 | assert_eq!(times, [50.0, 70.0, 100.0]); | |
| 1621 | assert_eq!(view.selected, HashSet::from([key_ref(1, HandlePart::Key)])); | |
| 1622 | ||
| 1623 | // Cancel puts both the keys and the selection back. | |
| 1624 | view.cancel_modal(&mut comp); | |
| 1625 | assert_eq!(comp.splines["Gain"].keyframes[0].time, 0.0); | |
| 1626 | assert_eq!(view.selected, HashSet::from([key_ref(0, HandlePart::Key)])); | |
| 1627 | } | |
| 1628 | ||
| 1629 | #[test] | |
| 1630 | fn grabbing_a_key_and_its_own_handle_moves_the_handle_once() { | |
| 1631 | let mut comp = test_comp(); | |
| 1632 | comp.splines.get_mut("Gain").unwrap().keyframes[1].lh = Some([40.0, 110.0]); | |
| 1633 | let mut view = SplineView::new(&ui::Theme::dark()); | |
| 1634 | view.resize([800.0, 360.0]); | |
| 1635 | view.set_target_node(&comp, None); | |
| 1636 | view.selected.insert(key_ref(1, HandlePart::Key)); | |
| 1637 | view.selected.insert(key_ref(1, HandlePart::LeftHandle)); | |
| 1638 | ||
| 1639 | view.pointer_local = view.spline_to_local(50.0, 110.0, (10.0, 110.0)); | |
| 1640 | view.begin_modal(&comp, false, TransformMode::Grab); | |
| 1641 | view.pointer_local = view.spline_to_local(60.0, 110.0, (10.0, 110.0)); | |
| 1642 | view.apply_modal(&mut comp, false); | |
| 1643 | ||
| 1644 | let kf = &comp.splines["Gain"].keyframes[1]; | |
| 1645 | assert!((kf.time - 60.0).abs() < 1e-6); | |
| 1646 | assert!((kf.lh.unwrap()[0] - 50.0).abs() < 1e-6, "handle shifted {:?}", kf.lh); | |
| 1647 | } | |
| 1648 | ||
| 1649 | #[test] | |
| 1650 | fn inserting_a_key_before_the_selection_shifts_selected_indices() { | |
| 1651 | let mut comp = test_comp(); | |
| 1652 | let mut view = SplineView::new(&ui::Theme::dark()); | |
| 1653 | view.resize([800.0, 360.0]); | |
| 1654 | view.set_target_node(&comp, None); | |
| 1655 | view.selected.insert(key_ref(1, HandlePart::Key)); | |
| 1656 | ||
| 1657 | let acts = view.input(&mut comp, 25.0, key_event("i"), [0.0, 0.0, 800.0, 360.0], [300.0, 150.0], ModifiersState::empty()); | |
| 1658 | assert_eq!(acts.len(), 1); | |
| 1659 | let times: Vec<f64> = comp.splines["Gain"].keyframes.iter().map(|k| k.time).collect(); | |
| 1660 | assert_eq!(times, [0.0, 25.0, 50.0, 100.0]); | |
| 1661 | assert_eq!(view.selected, HashSet::from([key_ref(2, HandlePart::Key)])); | |
| 1662 | } | |
| 1663 | ||
| 1664 | #[test] | |
| 1665 | fn plain_click_selection_does_not_touch_the_comp() { | |
| 1666 | let mut comp = test_comp(); | |
| 1667 | let mut view = SplineView::new(&ui::Theme::dark()); | |
| 1668 | view.resize([800.0, 360.0]); | |
| 1669 | view.set_target_node(&comp, None); | |
| 1670 | let before = comp.revision; | |
| 1671 | let at = view.spline_to_local(50.0, 110.0, (10.0, 110.0)); | |
| 1672 | ||
| 1673 | press(&mut view, &mut comp, at, true); | |
| 1674 | press(&mut view, &mut comp, at, false); | |
| 1675 | ||
| 1676 | assert!(view.selected.contains(&key_ref(1, HandlePart::Key))); | |
| 1677 | assert_eq!(comp.revision, before); | |
| 1678 | assert!(comp.splines["Gain"].keyframes[1].lh.is_none()); | |
| 1679 | } | |
| 1680 | ||
| 1681 | #[test] | |
| 1682 | fn letter_shortcuts_ignore_ctrl_alt_and_cmd() { | |
| 1683 | let mut comp = test_comp(); | |
| 1684 | let mut view = SplineView::new(&ui::Theme::dark()); | |
| 1685 | view.set_target_node(&comp, None); | |
| 1686 | view.selected.insert(key_ref(0, HandlePart::Key)); | |
| 1687 | let rect = [0.0, 0.0, 800.0, 360.0]; | |
| 1688 | for mods in [ModifiersState::CONTROL, ModifiersState::ALT, ModifiersState::SUPER] { | |
| 1689 | for k in ["g", "x", "n", "v", "i"] { | |
| 1690 | let ev = ui::Event::Key { key: Key::Character(k.into()), modifiers: mods, text: None }; | |
| 1691 | view.input(&mut comp, 5.0, ev, rect, [300.0, 150.0], mods); | |
| 1692 | assert!(view.modal.is_none() && view.popup.is_none() && !view.normalized, "{k} with {mods:?}"); | |
| 1693 | } | |
| 1694 | } | |
| 1695 | assert_eq!(comp.splines["Gain"].keyframes.len(), 3); | |
| 1696 | } | |
| 1494 | 1697 | } |
crates/spline/src/paint.rs+11-8| ... | ... | @@ -32,7 +32,16 @@ impl SplineView { |
| 32 | 32 | } |
| 33 | 33 | } |
| 34 | 34 | |
| 35 | fn header_label(&self, comp: &Comp) -> String { | |
| 36 | self.current_node | |
| 37 | .and_then(|id| comp.nodes.get(id.0)) | |
| 38 | .map_or_else(|| "Splines (Comp)".to_owned(), |n| format!("Splines: {}", n.name)) | |
| 39 | } | |
| 40 | ||
| 35 | 41 | pub fn prepare_labels(&mut self, comp: &Comp) { |
| 42 | if self.text_cache.len() > super::TEXT_CACHE_CAP { | |
| 43 | self.text_cache.clear(); | |
| 44 | } | |
| 36 | 45 | let font_sm = text::Font { |
| 37 | 46 | families: Arc::from([text::Family::Mono]), |
| 38 | 47 | size: 10.0, |
| ... | ... | @@ -63,10 +72,7 @@ impl SplineView { |
| 63 | 72 | for (label, _) in &self.channels { |
| 64 | 73 | self.text_cache.entry(label.clone()).or_insert_with(|| make_layout(label, &font_ch)); |
| 65 | 74 | } |
| 66 | let header = self | |
| 67 | .current_node | |
| 68 | .map(|id| format!("Splines: {}", comp.node(id).name)) | |
| 69 | .unwrap_or_else(|| "Splines (Comp)".to_owned()); | |
| 75 | let header = self.header_label(comp); | |
| 70 | 76 | self.text_cache.entry(header.clone()).or_insert_with(|| make_layout(&header, &font_ch)); |
| 71 | 77 | self.text_cache |
| 72 | 78 | .entry("Norm".to_owned()) |
| ... | ... | @@ -161,10 +167,7 @@ impl SplineView { |
| 161 | 167 | out.push(Primitive::Rect { rect: [SIDEBAR_W, 0.0, w, RULER_H], color: self.palette.ruler }); |
| 162 | 168 | out.push(Primitive::Segment { from: [0.0, RULER_H], to: [w, RULER_H], width: 1.0, color: self.palette.rule }); |
| 163 | 169 | |
| 164 | let header = self | |
| 165 | .current_node | |
| 166 | .map(|id| format!("Splines: {}", comp.node(id).name)) | |
| 167 | .unwrap_or_else(|| "Splines (Comp)".to_owned()); | |
| 170 | let header = self.header_label(comp); | |
| 168 | 171 | if let Some(hl) = self.text_cache.get(&header) { |
| 169 | 172 | out.push(Primitive::Text { |
| 170 | 173 | text: hl as &dyn Glyphs, |
crates/viewer/src/gizmos.rs+77-16| ... | ... | @@ -254,23 +254,23 @@ impl GizmoState { |
| 254 | 254 | coalesce_key: format!("gizmo:{}:Center", d.node_id.0), |
| 255 | 255 | }) |
| 256 | 256 | } |
| 257 | GizmoHandle::AxisX => { | |
| 258 | let nx = d.start_center[0] + dx_px / img_w; | |
| 259 | Some(GizmoEdit { | |
| 260 | node_id: d.node_id, | |
| 261 | input: "Center", | |
| 262 | value: ParamValue::Point([nx, d.start_center[1]]), | |
| 263 | label: "Move Center X", | |
| 264 | coalesce_key: format!("gizmo:{}:Center", d.node_id.0), | |
| 265 | }) | |
| 266 | } | |
| 267 | GizmoHandle::AxisY => { | |
| 268 | let ny = d.start_center[1] + dy_px / img_h; | |
| 257 | GizmoHandle::AxisX | GizmoHandle::AxisY => { | |
| 258 | // Constrain the pointer motion to the node's rotated axis (screen space, Y-down). | |
| 259 | let rad = d.start_angle.to_radians(); | |
| 260 | let (axis, label) = if d.handle == GizmoHandle::AxisX { | |
| 261 | ([rad.cos(), -rad.sin()], "Move Center X") | |
| 262 | } else { | |
| 263 | ([-rad.sin(), -rad.cos()], "Move Center Y") | |
| 264 | }; | |
| 265 | let t = dx_px * axis[0] + (-dy_px) * axis[1]; | |
| 269 | 266 | Some(GizmoEdit { |
| 270 | 267 | node_id: d.node_id, |
| 271 | 268 | input: "Center", |
| 272 | value: ParamValue::Point([d.start_center[0], ny]), | |
| 273 | label: "Move Center Y", | |
| 269 | value: ParamValue::Point([ | |
| 270 | d.start_center[0] + t * axis[0] / img_w, | |
| 271 | d.start_center[1] - t * axis[1] / img_h, | |
| 272 | ]), | |
| 273 | label: label, | |
| 274 | 274 | coalesce_key: format!("gizmo:{}:Center", d.node_id.0), |
| 275 | 275 | }) |
| 276 | 276 | } |
| ... | ... | @@ -308,7 +308,8 @@ impl GizmoState { |
| 308 | 308 | let rx = f64::from(pointer_local[0] - c[0]); |
| 309 | 309 | let ry = f64::from(pointer_local[1] - c[1]); |
| 310 | 310 | let proj = (rx * ux[0] + ry * ux[1]).abs(); |
| 311 | let new_w = ((proj * 2.0) / img_w).clamp(0.005, 4.0); | |
| 311 | let raw_w = ((proj * 2.0) / img_w).clamp(0.005, 4.0); | |
| 312 | let new_w = d.start_width + (raw_w - d.start_width) * sens; | |
| 312 | 313 | Some(GizmoEdit { |
| 313 | 314 | node_id: d.node_id, |
| 314 | 315 | input: "Width", |
| ... | ... | @@ -324,7 +325,8 @@ impl GizmoState { |
| 324 | 325 | let ry = f64::from(pointer_local[1] - c[1]); |
| 325 | 326 | let proj = (rx * uy[0] + ry * uy[1]).abs(); |
| 326 | 327 | let denom = if kind == "EllipseMask" { img_w } else { img_h }; |
| 327 | let new_h = ((proj * 2.0) / denom).clamp(0.005, 4.0); | |
| 328 | let raw_h = ((proj * 2.0) / denom).clamp(0.005, 4.0); | |
| 329 | let new_h = d.start_height + (raw_h - d.start_height) * sens; | |
| 328 | 330 | Some(GizmoEdit { |
| 329 | 331 | node_id: d.node_id, |
| 330 | 332 | input: "Height", |
| ... | ... | @@ -722,4 +724,63 @@ mod tests { |
| 722 | 724 | // RectangleMask Height=0.5 in frame-height units -> half_h = 0.25 * 400 = 100px above center (400, 200) -> (400, 100) |
| 723 | 725 | assert_eq!(gz.hit_test(&comp, rect_node, 0.0, img, [400.0, 100.0]), Some(GizmoHandle::Height)); |
| 724 | 726 | } |
| 727 | ||
| 728 | const ROTATED_COMP: &str = r#"Composition { | |
| 729 | Tools = ordered() { | |
| 730 | XF1 = Transform { | |
| 731 | Inputs = { | |
| 732 | Center = Input { Value = { 0.5, 0.5 }, }, | |
| 733 | Size = Input { Value = 1.0, }, | |
| 734 | Angle = Input { Value = 90.0, }, | |
| 735 | }, | |
| 736 | }, | |
| 737 | Ell1 = EllipseMask { | |
| 738 | Inputs = { | |
| 739 | Center = Input { Value = { 0.5, 0.5 }, }, | |
| 740 | Width = Input { Value = 0.4, }, | |
| 741 | Height = Input { Value = 0.2, }, | |
| 742 | }, | |
| 743 | }, | |
| 744 | }, | |
| 745 | }"#; | |
| 746 | ||
| 747 | #[test] | |
| 748 | fn rotated_axis_handles_move_only_along_their_rotated_axis() { | |
| 749 | let comp = Comp::from_fusion_str(ROTATED_COMP).expect("rotated comp"); | |
| 750 | let xf = comp.find_node("XF1").unwrap(); | |
| 751 | let rect = [0.0, 0.0, 800.0, 450.0]; | |
| 752 | let mut gz = GizmoState::new(); | |
| 753 | ||
| 754 | // At 90deg the X axis points up the screen: 58px above the center (400, 225). | |
| 755 | assert_eq!(gz.hit_test(&comp, xf, 0.0, rect, [400.0, 167.0]), Some(GizmoHandle::AxisX)); | |
| 756 | assert!(gz.begin_drag(&comp, xf, 0.0, rect, [400.0, 167.0])); | |
| 757 | let edit = gz.update_drag(&comp, rect, [430.0, 127.0], false).unwrap(); | |
| 758 | let ParamValue::Point([x, y]) = edit.value else { panic!("expected Point") }; | |
| 759 | assert!((x - 0.5).abs() < 1e-4, "perpendicular motion must be ignored, x = {x}"); | |
| 760 | assert!((y - (0.5 + 40.0 / 450.0)).abs() < 1e-4, "y = {y}"); | |
| 761 | gz.end_drag(); | |
| 762 | ||
| 763 | // The Y axis points left at 90deg: 58px left of center. | |
| 764 | assert_eq!(gz.hit_test(&comp, xf, 0.0, rect, [342.0, 225.0]), Some(GizmoHandle::AxisY)); | |
| 765 | assert!(gz.begin_drag(&comp, xf, 0.0, rect, [342.0, 225.0])); | |
| 766 | let edit = gz.update_drag(&comp, rect, [322.0, 235.0], false).unwrap(); | |
| 767 | let ParamValue::Point([x, y]) = edit.value else { panic!("expected Point") }; | |
| 768 | assert!((x - (0.5 - 20.0 / 800.0)).abs() < 1e-4, "x = {x}"); | |
| 769 | assert!((y - 0.5).abs() < 1e-4, "y = {y}"); | |
| 770 | } | |
| 771 | ||
| 772 | #[test] | |
| 773 | fn fine_mode_scales_mask_width_toward_the_start_value() { | |
| 774 | let comp = Comp::from_fusion_str(ROTATED_COMP).expect("comp"); | |
| 775 | let ell = comp.find_node("Ell1").unwrap(); | |
| 776 | let rect = [0.0, 0.0, 800.0, 400.0]; | |
| 777 | let mut gz = GizmoState::new(); | |
| 778 | ||
| 779 | assert!(gz.begin_drag(&comp, ell, 0.0, rect, [560.0, 200.0])); | |
| 780 | let full = gz.update_drag(&comp, rect, [600.0, 200.0], false).unwrap(); | |
| 781 | let fine = gz.update_drag(&comp, rect, [600.0, 200.0], true).unwrap(); | |
| 782 | let (ParamValue::Number(full), ParamValue::Number(fine)) = (full.value, fine.value) else { panic!("expected Number") }; | |
| 783 | assert!((full - 0.5).abs() < 1e-4, "full = {full}"); | |
| 784 | assert!((fine - 0.42).abs() < 1e-4, "fine = {fine}"); | |
| 785 | } | |
| 725 | 786 | } |
crates/viewer/src/lib.rs+90-10| ... | ... | @@ -269,8 +269,10 @@ impl PlaybackClock { |
| 269 | 269 | let wrapped = raw >= span; |
| 270 | 270 | let next = r0 + raw.rem_euclid(span); |
| 271 | 271 | if wrapped { |
| 272 | // Keep the sub-frame overshoot so looping never drifts behind the wall clock. | |
| 273 | let overshoot = Duration::from_secs_f64((elapsed * fps - adv) / fps); | |
| 272 | 274 | self.anchor_frame = next; |
| 273 | self.anchor_time = now; | |
| 275 | self.anchor_time = now.checked_sub(overshoot).unwrap_or(now); | |
| 274 | 276 | looped = true; |
| 275 | 277 | } |
| 276 | 278 | if (next - self.current_frame).abs() >= 1.0 { |
| ... | ... | @@ -331,6 +333,8 @@ pub enum ViewerAction { |
| 331 | 333 | ToggleHiQ, |
| 332 | 334 | ClearViewers, |
| 333 | 335 | GizmoEdited(GizmoEdit), |
| 336 | /// Gizmo drag finished or was cancelled: the next drag starts a new undo step. | |
| 337 | GizmoDragEnded, | |
| 334 | 338 | ExportPreviewMp4(usize), |
| 335 | 339 | SaveFramePng(usize), |
| 336 | 340 | SetInPoint, |
| ... | ... | @@ -563,7 +567,7 @@ impl ViewerState { |
| 563 | 567 | current_frame: f64, |
| 564 | 568 | dpi_scale: f32, |
| 565 | 569 | ) { |
| 566 | let Some(target) = self.viewed_node else { | |
| 570 | let Some(target) = self.viewed_node.filter(|id| id.0 < comp.nodes.len()) else { | |
| 567 | 571 | return; |
| 568 | 572 | }; |
| 569 | 573 | let frame_i = current_frame.round() as i64; |
| ... | ... | @@ -648,8 +652,8 @@ impl ViewerState { |
| 648 | 652 | self.in_out_range = clock.in_out_range; |
| 649 | 653 | let node_name = self |
| 650 | 654 | .viewed_node |
| 651 | .map(|id| comp.node(id).name.as_str()) | |
| 652 | .unwrap_or("(empty)"); | |
| 655 | .and_then(|id| comp.nodes.get(id.0)) | |
| 656 | .map_or("(empty)", |n| n.name.as_str()); | |
| 653 | 657 | let cache_lbl = match engine.cache.mode { |
| 654 | 658 | CacheMode::Enabled => "CACHE", |
| 655 | 659 | CacheMode::Bypass => "BYPASS", |
| ... | ... | @@ -1019,7 +1023,8 @@ impl ViewerState { |
| 1019 | 1023 | self.dirty = true; |
| 1020 | 1024 | } else { |
| 1021 | 1025 | let (img_rect, _, _, _) = self.image_layout(comp); |
| 1022 | self.gizmos.update_hover(comp, self.selected_node, clock.current_frame, img_rect, self.pointer_local); | |
| 1026 | let hover_node = self.selected_node.filter(|_| self.viewed_node.is_some()); | |
| 1027 | self.gizmos.update_hover(comp, hover_node, clock.current_frame, img_rect, self.pointer_local); | |
| 1023 | 1028 | } |
| 1024 | 1029 | } |
| 1025 | 1030 | ui::Event::Button { button, pressed, .. } => { |
| ... | ... | @@ -1027,7 +1032,10 @@ impl ViewerState { |
| 1027 | 1032 | if pressed { |
| 1028 | 1033 | self.scrubbing = false; |
| 1029 | 1034 | self.panning = None; |
| 1030 | self.gizmos.end_drag(); | |
| 1035 | if self.gizmos.is_dragging() { | |
| 1036 | self.gizmos.end_drag(); | |
| 1037 | actions.push(ViewerAction::GizmoDragEnded); | |
| 1038 | } | |
| 1031 | 1039 | self.context_menu = Some(self.pointer_local); |
| 1032 | 1040 | self.context_menu_hover = |
| 1033 | 1041 | self.hit_context_menu_item(self.pointer_local, self.pointer_local); |
| ... | ... | @@ -1056,13 +1064,16 @@ impl ViewerState { |
| 1056 | 1064 | } else if self.pointer_local[1] >= scrub[1] - 6.0 { |
| 1057 | 1065 | self.scrubbing = true; |
| 1058 | 1066 | actions.push(ViewerAction::SetFrame(self.frame_at_x(comp, self.pointer_local[0]))); |
| 1059 | } else if let Some(sel) = self.selected_node { | |
| 1067 | } else if let Some(sel) = self.selected_node.filter(|_| self.viewed_node.is_some()) { | |
| 1060 | 1068 | let (img_rect, _, _, _) = self.image_layout(comp); |
| 1061 | 1069 | self.gizmos.begin_drag(comp, sel, clock.current_frame, img_rect, self.pointer_local); |
| 1062 | 1070 | } |
| 1063 | 1071 | } else { |
| 1064 | 1072 | self.scrubbing = false; |
| 1065 | self.gizmos.end_drag(); | |
| 1073 | if self.gizmos.is_dragging() { | |
| 1074 | self.gizmos.end_drag(); | |
| 1075 | actions.push(ViewerAction::GizmoDragEnded); | |
| 1076 | } | |
| 1066 | 1077 | } |
| 1067 | 1078 | } |
| 1068 | 1079 | } |
| ... | ... | @@ -1087,8 +1098,8 @@ impl ViewerState { |
| 1087 | 1098 | let factor = (1.0 + delta).clamp(0.7, 1.4); |
| 1088 | 1099 | self.zoom_at(comp, factor, self.pointer_local); |
| 1089 | 1100 | } |
| 1090 | ui::Event::KeyInput { physical, key, state: ElementState::Pressed, .. } => { | |
| 1091 | self.handle_key(clock, Some(physical), &key, modifiers, &mut actions); | |
| 1101 | ui::Event::KeyInput { physical, key, state: ElementState::Pressed, repeat: false, modifiers: kmod, .. } => { | |
| 1102 | self.handle_key(clock, Some(physical), &key, kmod, &mut actions); | |
| 1092 | 1103 | } |
| 1093 | 1104 | ui::Event::Key { key, modifiers: kmod, .. } => { |
| 1094 | 1105 | self.handle_key(clock, None, &key, kmod, &mut actions); |
| ... | ... | @@ -1620,4 +1631,73 @@ mod tests { |
| 1620 | 1631 | "EveryFrame stalled expected_audio_secs should cap at {max_expected}, got {exp_stalled}" |
| 1621 | 1632 | ); |
| 1622 | 1633 | } |
| 1634 | ||
| 1635 | #[test] | |
| 1636 | fn loop_wraparound_keeps_the_sub_frame_overshoot() { | |
| 1637 | let comp = test_comp(); // 30 fps | |
| 1638 | let t0 = Instant::now(); | |
| 1639 | let step = Duration::from_secs_f64(1.0 / 30.0); | |
| 1640 | let mut clock = PlaybackClock::new(); | |
| 1641 | clock.init_from_comp(&comp); | |
| 1642 | clock.in_out_range = [Some(20), Some(24)]; | |
| 1643 | clock.set_frame(&comp, 20.0, t0); | |
| 1644 | clock.toggle_play_with_comp(&comp, t0); | |
| 1645 | ||
| 1646 | // Wrap with half a frame of overshoot... | |
| 1647 | let wrap = clock.tick_synced(&comp, t0 + step.mul_f64(5.5)); | |
| 1648 | assert!(wrap.looped); | |
| 1649 | assert_eq!(clock.current_frame, 20.0); | |
| 1650 | // ...so 0.6 frames later a whole frame has elapsed on the original timeline. | |
| 1651 | let next = clock.tick_synced(&comp, t0 + step.mul_f64(6.1)); | |
| 1652 | assert!(!next.looped); | |
| 1653 | assert_eq!(clock.current_frame, 21.0); | |
| 1654 | } | |
| 1655 | ||
| 1656 | #[test] | |
| 1657 | fn gizmo_needs_a_viewed_node_and_reports_drag_end() { | |
| 1658 | let comp = Comp::from_fusion_str( | |
| 1659 | r#"Composition { Tools = ordered() { XF1 = Transform { Inputs = { Center = Input { Value = { 0.5, 0.5 }, }, }, }, } }"#, | |
| 1660 | ) | |
| 1661 | .expect("comp"); | |
| 1662 | let xf = comp.find_node("XF1").unwrap(); | |
| 1663 | let clock = PlaybackClock::new(); | |
| 1664 | let theme = ui::Theme::new(&theme::KNIFE, true); | |
| 1665 | let mut viewer = ViewerState::new(0, &theme); | |
| 1666 | viewer.resize([640.0, 400.0]); | |
| 1667 | viewer.selected_node = Some(xf); | |
| 1668 | let rect = [0.0, 0.0, 640.0, 400.0]; | |
| 1669 | let (img, _, _, _) = viewer.image_layout(&comp); | |
| 1670 | let center = GizmoState::fu_to_local([0.5, 0.5], img); | |
| 1671 | let button = |pressed| ui::Event::Button { button: MouseButton::Left, pressed, at: Instant::now() }; | |
| 1672 | ||
| 1673 | viewer.input(&comp, &clock, button(true), rect, center, ModifiersState::empty()); | |
| 1674 | assert!(!viewer.gizmos.is_dragging(), "no viewed node, no gizmo"); | |
| 1675 | ||
| 1676 | viewer.viewed_node = Some(xf); | |
| 1677 | viewer.input(&comp, &clock, button(true), rect, center, ModifiersState::empty()); | |
| 1678 | assert!(viewer.gizmos.is_dragging()); | |
| 1679 | let acts = viewer.input(&comp, &clock, button(false), rect, center, ModifiersState::empty()); | |
| 1680 | assert!(matches!(acts.as_slice(), [ViewerAction::GizmoDragEnded])); | |
| 1681 | } | |
| 1682 | ||
| 1683 | #[test] | |
| 1684 | fn held_key_repeats_are_ignored() { | |
| 1685 | let comp = test_comp(); | |
| 1686 | let clock = PlaybackClock::new(); | |
| 1687 | let theme = ui::Theme::new(&theme::KNIFE, true); | |
| 1688 | let mut viewer = ViewerState::new(0, &theme); | |
| 1689 | let ev = |repeat| ui::Event::KeyInput { | |
| 1690 | physical: PhysicalKey::Code(KeyCode::KeyI), | |
| 1691 | key: Key::Character("i".into()), | |
| 1692 | text: None, | |
| 1693 | unshifted: Key::Character("i".into()), | |
| 1694 | modifiers: ModifiersState::empty(), | |
| 1695 | state: ElementState::Pressed, | |
| 1696 | repeat, | |
| 1697 | }; | |
| 1698 | let rect = [0.0, 0.0, 640.0, 400.0]; | |
| 1699 | let run = |v: &mut ViewerState, repeat| v.input(&comp, &clock, ev(repeat), rect, [0.0, 0.0], ModifiersState::empty()); | |
| 1700 | assert!(matches!(run(&mut viewer, false).as_slice(), [ViewerAction::SetInPoint])); | |
| 1701 | assert!(run(&mut viewer, true).is_empty()); | |
| 1702 | } | |
| 1623 | 1703 | } |