authoravatarclover caruso<git@paperclover.net>2026-11-30 21:06:03-08:00
committeravatarclover caruso<git@paperclover.net>2026-11-30 21:16:22-08:00
logd702f0abe89e0236e840be2dedb07dd5010e5669
tree08dbf657d21da6d85f13d9fde69a8106c8a3821e
parent22b81476d7a6aae5efca63a734822ad5d21da5b8
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

Fix Flow wire-drop ports, Cmd+backquote, Spline rotate/modal, busy-spin, and UI polish

Assisted-by: claude-sonnet-5.5

9 files changed, 427 insertions(+), 100 deletions(-)

crates/app/src/keyframes.rs+41
...@@ -288,6 +288,20 @@ impl KeyframesView {...@@ -288,6 +288,20 @@ impl KeyframesView {
288 true288 true
289 }289 }
290290
291 fn cancel_retime_drag(&mut self, comp: &mut Comp) -> bool {
292 let Some(drag) = self.retime_drag.take() else { return false };
293 for (sname, keyframes) in drag.saved_splines {
294 if let Some(sp) = comp.splines.get_mut(&sname) {
295 sp.keyframes = keyframes;
296 }
297 }
298 self.selected_keys = drag.orig_selected;
299 if drag.moved {
300 comp.revision += 1;
301 }
302 drag.moved
303 }
304
291 fn delete_selected(&mut self, comp: &mut Comp, history: &mut CompHistory) -> bool {305 fn delete_selected(&mut self, comp: &mut Comp, history: &mut CompHistory) -> bool {
292 if self.selected_keys.is_empty() {306 if self.selected_keys.is_empty() {
293 return false;307 return false;
...@@ -492,6 +506,11 @@ impl KeyframesView {...@@ -492,6 +506,11 @@ impl KeyframesView {
492 ) {506 ) {
493 let plain = !kmod.super_key() && !kmod.control_key() && !kmod.alt_key();507 let plain = !kmod.super_key() && !kmod.control_key() && !kmod.alt_key();
494 match key {508 match key {
509 Key::Named(NamedKey::Escape) => {
510 if self.cancel_retime_drag(comp) {
511 actions.push(KeyframesAction::KeyframesEdited);
512 }
513 }
495 Key::Named(NamedKey::Delete | NamedKey::Backspace) => {514 Key::Named(NamedKey::Delete | NamedKey::Backspace) => {
496 if self.delete_selected(comp, history) {515 if self.delete_selected(comp, history) {
497 actions.push(KeyframesAction::KeyframesEdited);516 actions.push(KeyframesAction::KeyframesEdited);
...@@ -680,6 +699,28 @@ mod tests {...@@ -680,6 +699,28 @@ mod tests {
680 assert!((comp.splines["XF1Size"].keyframes[1].time - 40.0).abs() < 1e-6);699 assert!((comp.splines["XF1Size"].keyframes[1].time - 40.0).abs() < 1e-6);
681 }700 }
682701
702 #[test]
703 fn escape_cancels_an_active_retime_drag() {
704 let mut comp = sample_animated_comp();
705 let mut history = CompHistory::new();
706 let mut view = KeyframesView::new(&ui::Theme::dark());
707 view.resize([800.0, 300.0]);
708 let key = DopeKeyRef { spline: "XF1Size".to_owned(), key_idx: 0 };
709 view.selected_keys.insert(key.clone());
710 view.begin_retime_drag(&comp);
711 view.pointer_local[0] += 60.0;
712 assert!(view.apply_retime_drag(&mut comp));
713 assert_ne!(comp.splines["XF1Size"].keyframes[0].time, 10.0);
714
715 let mut actions = Vec::new();
716 view.handle_key(&mut comp, &mut history, &Key::Named(NamedKey::Escape), ModifiersState::empty(), &mut actions);
717
718 assert_eq!(comp.splines["XF1Size"].keyframes[0].time, 10.0);
719 assert!(view.retime_drag.is_none());
720 assert_eq!(view.selected_keys, HashSet::from([key]));
721 assert_eq!(actions.len(), 1);
722 }
723
683 #[test]724 #[test]
684 fn retime_past_a_neighbour_keeps_curve_sorted_and_selection_on_the_key() {725 fn retime_past_a_neighbour_keeps_curve_sorted_and_selection_on_the_key() {
685 let mut comp = sample_animated_comp();726 let mut comp = sample_animated_comp();
crates/app/src/main.rs+60-17
...@@ -400,6 +400,9 @@ impl Studio {...@@ -400,6 +400,9 @@ impl Studio {
400 }400 }
401 self.flow.sanitize_ids(&self.comp);401 self.flow.sanitize_ids(&self.comp);
402 self.flow.viewed_nodes = self.viewers.each_ref().map(|v| v.viewed_node);402 self.flow.viewed_nodes = self.viewers.each_ref().map(|v| v.viewed_node);
403 for v in &mut self.viewers {
404 v.selected_node = self.flow.primary;
405 }
403 self.keyframes.sanitize_ids(&self.comp);406 self.keyframes.sanitize_ids(&self.comp);
404 self.inspector.reset();407 self.inspector.reset();
405 self.renaming_node = None;408 self.renaming_node = None;
...@@ -775,6 +778,8 @@ impl Studio {...@@ -775,6 +778,8 @@ impl Studio {
775 for ev in sig.events {778 for ev in sig.events {
776 acts.extend(self.flow.input(&mut self.comp, &mut self.history, ev, rect, ptr, mods));779 acts.extend(self.flow.input(&mut self.comp, &mut self.history, ev, rect, ptr, mods));
777 }780 }
781 // Ids carried by actions predate a delete in the same batch and may now name another node.
782 let deleted = self.comp.nodes.len() < node_count;
778 if self.comp.nodes.len() != node_count {783 if self.comp.nodes.len() != node_count {
779 self.reconcile_node_refs(prev_viewed);784 self.reconcile_node_refs(prev_viewed);
780 }785 }
...@@ -783,6 +788,7 @@ impl Studio {...@@ -783,6 +788,7 @@ impl Studio {
783 FlowAction::SelectionChanged(sel) => {788 FlowAction::SelectionChanged(sel) => {
784 self.spline.set_target_node(&self.comp, sel);789 self.spline.set_target_node(&self.comp, sel);
785 }790 }
791 FlowAction::ViewNode(_, id) | FlowAction::RequestRename(id) if deleted || id.0 >= self.comp.nodes.len() => {}
786 FlowAction::ViewNode(slot, id) => {792 FlowAction::ViewNode(slot, id) => {
787 self.viewers[slot].viewed_node = Some(id);793 self.viewers[slot].viewed_node = Some(id);
788 self.viewers[slot].dirty = true;794 self.viewers[slot].dirty = true;
...@@ -877,6 +883,10 @@ impl Studio {...@@ -877,6 +883,10 @@ impl Studio {
877 }883 }
878 }884 }
879 KeyframesAction::SelectNode(id) => {885 KeyframesAction::SelectNode(id) => {
886 // Dope sheet tracks are root-level nodes; the canvas must show the one it selects.
887 if !self.flow.scope_path().is_empty() {
888 self.flow.exit_to_depth(&self.comp, 0);
889 }
880 self.flow.selected.clear();890 self.flow.selected.clear();
881 self.flow.selected.insert(id);891 self.flow.selected.insert(id);
882 self.flow.primary = Some(id);892 self.flow.primary = Some(id);
...@@ -890,6 +900,12 @@ impl Studio {...@@ -890,6 +900,12 @@ impl Studio {
890 }900 }
891 }901 }
892902
903 // Mutations above (add, rename, undo, drags) must not paint a frame with stale labels.
904 self.flow.prepare_labels(&self.comp);
905 self.spline.prepare_labels(&self.comp);
906 self.keyframes.sync_tracks(&self.comp, self.flow.primary);
907 self.keyframes.prepare_labels();
908
893 // Immediately re-render any dirty visible viewer before painting this frame!909 // Immediately re-render any dirty visible viewer before painting this frame!
894 self.render_visible_viewers(true);910 self.render_visible_viewers(true);
895911
...@@ -1022,6 +1038,20 @@ struct WindowHost {...@@ -1022,6 +1038,20 @@ struct WindowHost {
1022 studio: Studio,1038 studio: Studio,
1023 access: Accessibility,1039 access: Accessibility,
1024 occluded: bool,1040 occluded: bool,
1041 /// When background work (export, prefetch) next gets a repaint; `None` while there is none.
1042 next_bg_poll: Option<Instant>,
1043}
1044
1045const BG_POLL: Duration = Duration::from_millis(100);
1046
1047/// Advances the background poll deadline; returns whether it has arrived and the next wake time.
1048fn poll_background(next: &mut Option<Instant>, now: Instant) -> (bool, Instant) {
1049 let due = *next.get_or_insert(now + BG_POLL);
1050 if now < due {
1051 return (false, due);
1052 }
1053 *next = Some(now + BG_POLL);
1054 (true, now + BG_POLL)
1025}1055}
10261056
1027struct App {1057struct App {
...@@ -1090,7 +1120,7 @@ impl WindowHost {...@@ -1090,7 +1120,7 @@ impl WindowHost {
1090 let quit = proxy.clone();1120 let quit = proxy.clone();
1091 ui::host::macos::quit(move || { let _ = quit.send_event(UserEvent::Quit); });1121 ui::host::macos::quit(move || { let _ = quit.send_event(UserEvent::Quit); });
1092 }1122 }
1093 Ok(Self { window, surface, studio, access, occluded: false })1123 Ok(Self { window, surface, studio, access, occluded: false, next_bg_poll: None })
1094 }1124 }
10951125
1096 fn redraw(&mut self) -> Result<(), Box<dyn Error>> {1126 fn redraw(&mut self) -> Result<(), Box<dyn Error>> {
...@@ -1211,25 +1241,25 @@ impl ApplicationHandler<UserEvent> for App {...@@ -1211,25 +1241,25 @@ impl ApplicationHandler<UserEvent> for App {
1211 }1241 }
12121242
1213 fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) {1243 fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) {
1214 if let Some(host) = &self.host {1244 if let Some(host) = &mut self.host
1215 if !host.occluded {1245 && !host.occluded
1216 if host.studio.playback.playing {1246 {
1217 let wake = host.studio.playback.next_wake(&host.studio.comp);1247 if host.studio.playback.playing {
1218 event_loop.set_control_flow(ControlFlow::WaitUntil(Instant::now() + wake));1248 host.next_bg_poll = None;
1219 host.window.request_redraw();1249 let wake = host.studio.playback.next_wake(&host.studio.comp);
1220 return;1250 event_loop.set_control_flow(ControlFlow::WaitUntil(Instant::now() + wake));
1221 }1251 host.window.request_redraw();
1222 if host.studio.active_export.is_some() {1252 return;
1223 event_loop.set_control_flow(ControlFlow::WaitUntil(Instant::now() + Duration::from_millis(100)));1253 }
1224 host.window.request_redraw();1254 if host.studio.active_export.is_some() || host.studio.prefetcher.as_ref().is_some_and(RamPrefetcher::is_busy) {
1225 return;1255 let (due, wake) = poll_background(&mut host.next_bg_poll, Instant::now());
1226 }1256 if due {
1227 if host.studio.prefetcher.as_ref().is_some_and(RamPrefetcher::is_busy) {
1228 event_loop.set_control_flow(ControlFlow::WaitUntil(Instant::now() + Duration::from_millis(200)));
1229 host.window.request_redraw();1257 host.window.request_redraw();
1230 return;
1231 }1258 }
1259 event_loop.set_control_flow(ControlFlow::WaitUntil(wake));
1260 return;
1232 }1261 }
1262 host.next_bg_poll = None;
1233 }1263 }
1234 event_loop.set_control_flow(ControlFlow::Wait);1264 event_loop.set_control_flow(ControlFlow::Wait);
1235 }1265 }
...@@ -1311,6 +1341,19 @@ mod tests {...@@ -1311,6 +1341,19 @@ mod tests {
1311 studio.comp.find_node(name).unwrap()1341 studio.comp.find_node(name).unwrap()
1312 }1342 }
13131343
1344 #[test]
1345 fn background_poll_repaints_at_ten_hertz_instead_of_spinning() {
1346 let t0 = Instant::now();
1347 let mut next = None;
1348 assert_eq!(poll_background(&mut next, t0), (false, t0 + BG_POLL));
1349 // Event-loop wakeups before the deadline neither repaint nor move it.
1350 let early = t0 + BG_POLL / 2;
1351 assert_eq!(poll_background(&mut next, early), (false, t0 + BG_POLL));
1352 let due = t0 + BG_POLL;
1353 assert_eq!(poll_background(&mut next, due), (true, due + BG_POLL));
1354 assert_eq!(poll_background(&mut next, due), (false, due + BG_POLL));
1355 }
1356
1314 #[test]1357 #[test]
1315 fn deleting_nodes_under_a_viewer_reconciles_it_by_name() {1358 fn deleting_nodes_under_a_viewer_reconciles_it_by_name() {
1316 let mut studio = studio();1359 let mut studio = studio();
crates/app/src/menus.rs+25-14
...@@ -78,7 +78,7 @@ pub(crate) fn build_flow_toolbar(...@@ -78,7 +78,7 @@ pub(crate) fn build_flow_toolbar(
78 can_undo: bool,78 can_undo: bool,
79 can_redo: bool,79 can_redo: bool,
80 comp_unsaved: bool,80 comp_unsaved: bool,
81 renaming_node: &Option<NodeId>,81 renaming_node: &mut Option<NodeId>,
82 rename_buf: &mut String,82 rename_buf: &mut String,
83 rename_needs_focus: &mut bool,83 rename_needs_focus: &mut bool,
84) -> FlowToolbarActions {84) -> FlowToolbarActions {
...@@ -184,6 +184,8 @@ pub(crate) fn build_flow_toolbar(...@@ -184,6 +184,8 @@ pub(crate) fn build_flow_toolbar(
184 if *rename_needs_focus {184 if *rename_needs_focus {
185 ui.set_focus(Some(rn_field_id));185 ui.set_focus(Some(rn_field_id));
186 *rename_needs_focus = false;186 *rename_needs_focus = false;
187 } else if !rn_sig.focused {
188 *renaming_node = None;
187 }189 }
188 for ev in &rn_sig.events {190 for ev in &rn_sig.events {
189 if let ui::Event::Key { key, .. } = ev {191 if let ui::Event::Key { key, .. } = ev {
...@@ -275,12 +277,17 @@ pub(crate) fn handle_global_shortcut(studio: &mut Studio, event: &ui::Event) ->...@@ -275,12 +277,17 @@ pub(crate) fn handle_global_shortcut(studio: &mut Studio, event: &ui::Event) ->
275 return true;277 return true;
276 }278 }
277279
280 // Canvas panes draw their own popups, which `popups_open` doesn't see.
281 let popup_open = studio.ui.popups_open()
282 || studio.add_tool.open
283 || studio.spline.is_popup_open()
284 || studio.viewers.iter().any(|v| v.is_context_menu_open());
278 // Shift+Space opens Add Tool launcher (when not typing in a text field)285 // Shift+Space opens Add Tool launcher (when not typing in a text field)
279 if !typing {286 if !typing && !popup_open {
280 let is_shift_space = match event {287 let is_shift_space = match event {
281 ui::Event::KeyInput { key: Key::Named(NamedKey::Space), modifiers, state: ElementState::Pressed, repeat: false, .. }288 ui::Event::KeyInput { key: Key::Named(NamedKey::Space), modifiers, state: ElementState::Pressed, repeat: false, .. }
282 | ui::Event::Key { key: Key::Named(NamedKey::Space), modifiers, .. } => {289 | ui::Event::Key { key: Key::Named(NamedKey::Space), modifiers, .. } => {
283 modifiers.shift_key() && !modifiers.super_key() && !modifiers.control_key()290 modifiers.shift_key() && !modifiers.super_key() && !modifiers.control_key() && !modifiers.alt_key()
284 }291 }
285 _ => false,292 _ => false,
286 };293 };
...@@ -292,21 +299,25 @@ pub(crate) fn handle_global_shortcut(studio: &mut Studio, event: &ui::Event) ->...@@ -292,21 +299,25 @@ pub(crate) fn handle_global_shortcut(studio: &mut Studio, event: &ui::Event) ->
292 let is_space = match event {299 let is_space = match event {
293 ui::Event::KeyInput { key: Key::Named(NamedKey::Space), modifiers, state: ElementState::Pressed, repeat: false, .. }300 ui::Event::KeyInput { key: Key::Named(NamedKey::Space), modifiers, state: ElementState::Pressed, repeat: false, .. }
294 | ui::Event::Key { key: Key::Named(NamedKey::Space), modifiers, .. } => {301 | ui::Event::Key { key: Key::Named(NamedKey::Space), modifiers, .. } => {
295 !modifiers.shift_key() && !modifiers.super_key() && !modifiers.control_key()302 !modifiers.shift_key() && !modifiers.super_key() && !modifiers.control_key() && !modifiers.alt_key()
296 }303 }
297 _ => false,304 _ => false,
298 };305 };
299 if is_space && !studio.add_tool.open {306 if is_space {
300 studio.playback.toggle_play_with_comp(&studio.comp, Instant::now());307 studio.playback.toggle_play_with_comp(&studio.comp, Instant::now());
301 studio.sync_audio(true, false);308 studio.sync_audio(true, false);
302 return true;309 return true;
303 }310 }
304 let is_backquote = match event {311 let is_backquote = match event {
305 ui::Event::KeyInput { physical: PhysicalKey::Code(KeyCode::Backquote), state: ElementState::Pressed, repeat: false, .. } => true,312 ui::Event::KeyInput { physical: PhysicalKey::Code(KeyCode::Backquote), modifiers, state: ElementState::Pressed, repeat: false, .. } => {
306 ui::Event::Key { key: Key::Character(c), .. } if c.as_str() == "`" || c.as_str() == "~" => true,313 !modifiers.super_key() && !modifiers.control_key() && !modifiers.alt_key()
314 }
315 ui::Event::Key { key: Key::Character(c), modifiers, .. } => {
316 (c.as_str() == "`" || c.as_str() == "~") && !modifiers.super_key() && !modifiers.control_key() && !modifiers.alt_key()
317 }
307 _ => false,318 _ => false,
308 };319 };
309 if is_backquote && !studio.add_tool.open {320 if is_backquote {
310 studio.clear_viewers();321 studio.clear_viewers();
311 return true;322 return true;
312 }323 }
...@@ -427,6 +438,7 @@ impl Studio {...@@ -427,6 +438,7 @@ impl Studio {
427 self.reconcile_node_refs([None, None]);438 self.reconcile_node_refs([None, None]);
428 self.history.clear();439 self.history.clear();
429 self.history.mark_saved(&self.comp);440 self.history.mark_saved(&self.comp);
441 self.spline.hidden_splines.clear();
430 self.engine.bust_all_caches();442 self.engine.bust_all_caches();
431 self.playback.init_from_comp(&self.comp);443 self.playback.init_from_comp(&self.comp);
432444
...@@ -440,7 +452,7 @@ impl Studio {...@@ -440,7 +452,7 @@ impl Studio {
440 }452 }
441 }453 }
442 self.flow.reset_for_comp(&self.comp);454 self.flow.reset_for_comp(&self.comp);
443 self.flow.viewed_nodes = [self.viewers[0].viewed_node, None];455 self.flow.viewed_nodes = self.viewers.each_ref().map(|v| v.viewed_node);
444 let default_sel = self456 let default_sel = self
445 .comp457 .comp
446 .nodes458 .nodes
...@@ -457,12 +469,11 @@ impl Studio {...@@ -457,12 +469,11 @@ impl Studio {
457 self.keyframes.cached_ranges.clear();469 self.keyframes.cached_ranges.clear();
458 self.keyframes.fit_comp(&self.comp);470 self.keyframes.fit_comp(&self.comp);
459 self.keyframes.sync_tracks(&self.comp, default_sel);471 self.keyframes.sync_tracks(&self.comp, default_sel);
460 self.viewers[0].audio_peaks.clear();472 for v in &mut self.viewers {
461 self.ram_cache.clear();473 v.audio_peaks.clear();
462 if let Some(pf) = &self.prefetcher {
463 pf.cancel();
464 }474 }
465 self.last_prefetch_sig = None;475 self.ram_cache.clear();
476 self.cancel_prefetch();
466 self.loaded_audio_track = None;477 self.loaded_audio_track = None;
467 self.last_audio_offset = self.comp.audio_offset;478 self.last_audio_offset = self.comp.audio_offset;
468 self.last_fps = self.comp.fps;479 self.last_fps = self.comp.fps;
crates/app/src/playback_ui.rs+25-13
...@@ -41,7 +41,9 @@ pub(crate) fn load_snapshot_audio_peaks(studio: &mut Studio) {...@@ -41,7 +41,9 @@ pub(crate) fn load_snapshot_audio_peaks(studio: &mut Studio) {
41 studio.comp.render_range[0],41 studio.comp.render_range[0],
42 studio.comp.render_range[1],42 studio.comp.render_range[1],
43 );43 );
44 studio.viewers[0].audio_peaks = peaks.clone();44 for v in &mut studio.viewers {
45 v.audio_peaks = peaks.clone();
46 }
45 studio.keyframes.audio_peaks = peaks;47 studio.keyframes.audio_peaks = peaks;
46 studio.keyframes.audio_range = studio.comp.render_range;48 studio.keyframes.audio_range = studio.comp.render_range;
47 }49 }
...@@ -62,7 +64,9 @@ impl Studio {...@@ -62,7 +64,9 @@ impl Studio {
62 self.comp.render_range[0],64 self.comp.render_range[0],
63 self.comp.render_range[1],65 self.comp.render_range[1],
64 );66 );
65 self.viewers[0].audio_peaks = peaks.clone();67 for v in &mut self.viewers {
68 v.audio_peaks = peaks.clone();
69 }
66 self.keyframes.audio_peaks = peaks;70 self.keyframes.audio_peaks = peaks;
67 self.keyframes.audio_range = self.comp.render_range;71 self.keyframes.audio_range = self.comp.render_range;
68 }72 }
...@@ -129,7 +133,9 @@ impl Studio {...@@ -129,7 +133,9 @@ impl Studio {
129 if self.comp.audio_filename != self.last_audio_filename {133 if self.comp.audio_filename != self.last_audio_filename {
130 self.last_audio_filename = self.comp.audio_filename.clone();134 self.last_audio_filename = self.comp.audio_filename.clone();
131 self.loaded_audio_track = None;135 self.loaded_audio_track = None;
132 self.viewers[0].audio_peaks.clear();136 for v in &mut self.viewers {
137 v.audio_peaks.clear();
138 }
133 self.keyframes.audio_peaks.clear();139 self.keyframes.audio_peaks.clear();
134 if self.enable_audio {140 if self.enable_audio {
135 if let Some(player) = &mut self.audio_player {141 if let Some(player) = &mut self.audio_player {
...@@ -179,16 +185,21 @@ impl Studio {...@@ -179,16 +185,21 @@ impl Studio {
179 self.engine.bust_gpu_cache();185 self.engine.bust_gpu_cache();
180 }186 }
181 self.ram_cache.invalidate_other_revisions(self.comp.revision);187 self.ram_cache.invalidate_other_revisions(self.comp.revision);
182 if let Some(pf) = &self.prefetcher {188 self.cancel_prefetch();
183 pf.cancel();
184 }
185 self.last_prefetch_sig = None;
186 for v in &mut self.viewers {189 for v in &mut self.viewers {
187 v.cached_frames.clear();190 v.cached_frames.clear();
188 v.dirty = true;191 v.dirty = true;
189 }192 }
190 }193 }
191194
195 /// Aborts in-flight lookahead and forces the next sync to re-plan it.
196 pub(crate) fn cancel_prefetch(&mut self) {
197 if let Some(pf) = &self.prefetcher {
198 pf.cancel();
199 }
200 self.last_prefetch_sig = None;
201 }
202
192 pub(crate) fn sync_ram_ranges_and_prefetch(&mut self) {203 pub(crate) fn sync_ram_ranges_and_prefetch(&mut self) {
193 let sel = self.flow.primary;204 let sel = self.flow.primary;
194 for v in &mut self.viewers {205 for v in &mut self.viewers {
...@@ -216,13 +227,14 @@ impl Studio {...@@ -216,13 +227,14 @@ impl Studio {
216 if let (Some(target), Some(pf)) = (target, &mut self.prefetcher) {227 if let (Some(target), Some(pf)) = (target, &mut self.prefetcher) {
217 if self.engine.cache.mode == CacheMode::Enabled {228 if self.engine.cache.mode == CacheMode::Enabled {
218 let cur_f = self.playback.current_frame.round() as i64;229 let cur_f = self.playback.current_frame.round() as i64;
230 let range = self.playback.effective_preview_range(&self.comp);
219 let key = (231 let key = (
220 target,232 target,
221 self.comp.revision,233 self.comp.revision,
222 self.engine.proxy_scale,234 self.engine.proxy_scale,
223 self.engine.hiq,235 self.engine.hiq,
224 self.engine.use_proxy_clips,236 self.engine.use_proxy_clips,
225 self.comp.render_range,237 range,
226 );238 );
227 // Re-plan only when the job changes or the playhead leaves the half of the window239 // Re-plan only when the job changes or the playhead leaves the half of the window
228 // already being filled, so steady playback never re-clones the comp per frame.240 // already being filled, so steady playback never re-clones the comp per frame.
...@@ -236,7 +248,7 @@ impl Studio {...@@ -236,7 +248,7 @@ impl Studio {
236 comp: self.comp.clone(),248 comp: self.comp.clone(),
237 target,249 target,
238 center_frame: cur_f,250 center_frame: cur_f,
239 range: self.comp.render_range,251 range,
240 lookahead: PREFETCH_LOOKAHEAD,252 lookahead: PREFETCH_LOOKAHEAD,
241 proxy_scale: self.engine.proxy_scale,253 proxy_scale: self.engine.proxy_scale,
242 hiq: self.engine.hiq,254 hiq: self.engine.hiq,
...@@ -360,8 +372,8 @@ impl Studio {...@@ -360,8 +372,8 @@ impl Studio {
360 }372 }
361 ViewerAction::BustFrame(f) => {373 ViewerAction::BustFrame(f) => {
362 self.engine.bust_frame(f);374 self.engine.bust_frame(f);
375 self.cancel_prefetch();
363 self.ram_cache.clear();376 self.ram_cache.clear();
364 self.last_prefetch_sig = None;
365 for v in &mut self.viewers {377 for v in &mut self.viewers {
366 v.cached_frames.remove(&f);378 v.cached_frames.remove(&f);
367 v.dirty = true;379 v.dirty = true;
...@@ -371,8 +383,8 @@ impl Studio {...@@ -371,8 +383,8 @@ impl Studio {
371 if let Some(id) = self.flow.primary.or(self.viewers[slot].viewed_node) {383 if let Some(id) = self.flow.primary.or(self.viewers[slot].viewed_node) {
372 self.engine.bust_subtree(id);384 self.engine.bust_subtree(id);
373 }385 }
386 self.cancel_prefetch();
374 self.ram_cache.clear();387 self.ram_cache.clear();
375 self.last_prefetch_sig = None;
376 for v in &mut self.viewers {388 for v in &mut self.viewers {
377 v.cached_frames.clear();389 v.cached_frames.clear();
378 v.dirty = true;390 v.dirty = true;
...@@ -380,8 +392,8 @@ impl Studio {...@@ -380,8 +392,8 @@ impl Studio {
380 }392 }
381 ViewerAction::BustGpu => {393 ViewerAction::BustGpu => {
382 self.engine.bust_gpu_cache();394 self.engine.bust_gpu_cache();
395 self.cancel_prefetch();
383 self.ram_cache.clear();396 self.ram_cache.clear();
384 self.last_prefetch_sig = None;
385 for v in &mut self.viewers {397 for v in &mut self.viewers {
386 v.cached_frames.clear();398 v.cached_frames.clear();
387 v.dirty = true;399 v.dirty = true;
...@@ -389,8 +401,8 @@ impl Studio {...@@ -389,8 +401,8 @@ impl Studio {
389 }401 }
390 ViewerAction::BustAll => {402 ViewerAction::BustAll => {
391 self.engine.bust_all_caches();403 self.engine.bust_all_caches();
404 self.cancel_prefetch();
392 self.ram_cache.clear();405 self.ram_cache.clear();
393 self.last_prefetch_sig = None;
394 for v in &mut self.viewers {406 for v in &mut self.viewers {
395 v.cached_frames.clear();407 v.cached_frames.clear();
396 v.dirty = true;408 v.dirty = true;
crates/flow/src/hit.rs+120-17
...@@ -100,23 +100,7 @@ impl FlowView {...@@ -100,23 +100,7 @@ impl FlowView {
100 if !self.scope.shows(n) { continue; }100 if !self.scope.shows(n) { continue; }
101 let r = self.node_rect_local(n.pos);101 let r = self.node_rect_local(n.pos);
102 if local[0] >= r[0] - 10.0 && local[0] <= r[2] + 10.0 && local[1] >= r[1] - 10.0 && local[1] <= r[3] + 10.0 {102 if local[0] >= r[0] - 10.0 && local[0] <= r[2] + 10.0 && local[1] >= r[1] - 10.0 && local[1] <= r[3] + 10.0 {
103 // Pick Background/Foreground/Mask cleanly based on approach edge for Merge/Displace!103 return Some((n.id, drop_port(n, local[1] < r[1] + 2.0, local[1] > r[3] - 2.0)));
104 if n.kind == "Merge" || n.kind == "Displace" || n.kind == "Dissolve" {
105 if local[1] < r[1] + 2.0 {
106 return Some((n.id, "Foreground"));
107 }
108 if local[1] > r[3] - 2.0 {
109 return Some((n.id, "EffectMask"));
110 }
111 return Some((n.id, "Background"));
112 }
113 if n.kind == "Merge3D" || n.kind == "Renderer3D" {
114 return Some((n.id, "SceneInput1"));
115 }
116 if local[1] > r[3] - 1.5 && n.kind != "PipeRouter" {
117 return Some((n.id, "EffectMask"));
118 }
119 return Some((n.id, default_main_input_port(&n.kind)));
120 }104 }
121 }105 }
122 None106 None
...@@ -175,6 +159,65 @@ impl FlowView {...@@ -175,6 +159,65 @@ impl FlowView {
175 }159 }
176}160}
177161
162const SCENE_INPUTS: [&str; 32] = [
163 "SceneInput1", "SceneInput2", "SceneInput3", "SceneInput4", "SceneInput5", "SceneInput6", "SceneInput7", "SceneInput8",
164 "SceneInput9", "SceneInput10", "SceneInput11", "SceneInput12", "SceneInput13", "SceneInput14", "SceneInput15", "SceneInput16",
165 "SceneInput17", "SceneInput18", "SceneInput19", "SceneInput20", "SceneInput21", "SceneInput22", "SceneInput23", "SceneInput24",
166 "SceneInput25", "SceneInput26", "SceneInput27", "SceneInput28", "SceneInput29", "SceneInput30", "SceneInput31", "SceneInput32",
167];
168
169const INPUTS: [&str; 33] = [
170 "Input0", "Input1", "Input2", "Input3", "Input4", "Input5", "Input6", "Input7", "Input8", "Input9", "Input10", "Input11",
171 "Input12", "Input13", "Input14", "Input15", "Input16", "Input17", "Input18", "Input19", "Input20", "Input21", "Input22",
172 "Input23", "Input24", "Input25", "Input26", "Input27", "Input28", "Input29", "Input30", "Input31", "Input32",
173];
174
175/// Port a wire dropped on `n` lands on; `top`/`bottom` are the node's mask/foreground approach bands.
176fn drop_port(n: &model::Node, top: bool, bottom: bool) -> &'static str {
177 let free = |names: &[&'static str]| {
178 names
179 .iter()
180 .copied()
181 .find(|p| n.inputs.get(*p).is_none_or(|b| b.source_op.is_none()))
182 .unwrap_or(names[names.len() - 1])
183 };
184 match n.kind.as_str() {
185 "Merge" | "Dissolve" | "ChannelBoolean" => {
186 if top {
187 "Foreground"
188 } else if bottom {
189 "EffectMask"
190 } else {
191 "Background"
192 }
193 }
194 "Displace" => {
195 if top {
196 "Foreground"
197 } else if bottom {
198 "EffectMask"
199 } else {
200 "Input"
201 }
202 }
203 "Renderer3D" | "Transform3D" | "ReplaceMaterial3D" | "Override3D" | "ReplaceNormals3D" | "Displace3D" | "Duplicate3D" => {
204 "SceneInput"
205 }
206 "Merge3D" => free(&SCENE_INPUTS),
207 "sMerge" | "pMerge" => free(&INPUTS[1..]),
208 "sBoolean" => free(&INPUTS[1..=2]),
209 "Fuse.Switch" => free(&INPUTS[1..]),
210 "Switch" => {
211 let zero_indexed = n.inputs.contains_key("Source") || n.inputs.contains_key("Input0") || !n.inputs.contains_key("Which");
212 free(if zero_indexed { &INPUTS[..] } else { &INPUTS[1..] })
213 }
214 "BitmapMask" => "Image",
215 "ImagePlane3D" | "TextureTransformOperator" => "MaterialInput",
216 kind if bottom && kind != "PipeRouter" => "EffectMask",
217 kind => default_main_input_port(kind),
218 }
219}
220
178/// Picks the closest node edge facing vector `(dx, dy)` accounting for thin rectangular bar aspect.221/// Picks the closest node edge facing vector `(dx, dy)` accounting for thin rectangular bar aspect.
179fn closest_edge(dx: f32, dy: f32) -> Edge {222fn closest_edge(dx: f32, dy: f32) -> Edge {
180 // Nodes are 84x21 (4:1 aspect), so require a balanced X bias so horizontal rows snap Left/Right223 // Nodes are 84x21 (4:1 aspect), so require a balanced X bias so horizontal rows snap Left/Right
...@@ -226,3 +269,63 @@ pub(crate) fn dist_to_seg(p: [f32; 2], a: [f32; 2], b: [f32; 2]) -> f32 {...@@ -226,3 +269,63 @@ pub(crate) fn dist_to_seg(p: [f32; 2], a: [f32; 2], b: [f32; 2]) -> f32 {
226 let q = [a[0] + ab[0] * t, a[1] + ab[1] * t];269 let q = [a[0] + ab[0] * t, a[1] + ab[1] * t];
227 ((p[0] - q[0]).powi(2) + (p[1] - q[1]).powi(2)).sqrt()270 ((p[0] - q[0]).powi(2) + (p[1] - q[1]).powi(2)).sqrt()
228}271}
272
273#[cfg(test)]
274mod tests {
275 use super::*;
276
277 fn port(comp: &Comp, name: &str) -> &'static str {
278 drop_port(comp.node(comp.find_node(name).unwrap()), false, false)
279 }
280
281 fn comp(src: &str) -> Comp {
282 Comp::from_fusion_str(&format!("Composition {{ Tools = ordered() {{ {src} }} }}")).expect("parse comp")
283 }
284
285 #[test]
286 fn single_input_kinds_use_engine_port_names() {
287 let c = comp(
288 "R = Renderer3D { }, D = Displace { }, CB = ChannelBoolean { }, Dis = Dissolve { },
289 BM = BitmapMask { }, T = Transform3D { }, Plane = ImagePlane3D { }",
290 );
291 assert_eq!(port(&c, "R"), "SceneInput");
292 assert_eq!(port(&c, "D"), "Input");
293 assert_eq!(port(&c, "CB"), "Background");
294 assert_eq!(port(&c, "Dis"), "Background");
295 assert_eq!(port(&c, "BM"), "Image");
296 assert_eq!(port(&c, "T"), "SceneInput");
297 assert_eq!(port(&c, "Plane"), "MaterialInput");
298 let d = c.node(c.find_node("D").unwrap());
299 assert_eq!(drop_port(d, true, false), "Foreground");
300 assert_eq!(drop_port(d, false, true), "EffectMask");
301 let cb = c.node(c.find_node("CB").unwrap());
302 assert_eq!(drop_port(cb, true, false), "Foreground");
303 }
304
305 #[test]
306 fn multi_input_kinds_pick_next_free_port() {
307 let c = comp(
308 r#"A = Background { }, B = Background { },
309 M3 = Merge3D { Inputs = { SceneInput1 = Input { SourceOp = "A", Source = "Output" } } },
310 M3b = Merge3D { },
311 S = Switch { Inputs = { Input0 = Input { SourceOp = "A", Source = "Output" } } },
312 SW = Switch { Inputs = { Which = Input { Value = 1 } } },
313 SB = sBoolean { Inputs = { Input1 = Input { SourceOp = "A", Source = "Output" } } },
314 SB0 = sBoolean { },
315 FS = Fuse.Switch { }"#,
316 );
317 assert_eq!(port(&c, "M3b"), "SceneInput1");
318 assert_eq!(port(&c, "M3"), "SceneInput2");
319 assert_eq!(port(&c, "S"), "Input1");
320 assert_eq!(port(&c, "SW"), "Input1");
321 assert_eq!(port(&c, "SB"), "Input2");
322 assert_eq!(port(&c, "SB0"), "Input1");
323 assert_eq!(port(&c, "FS"), "Input1");
324 }
325
326 #[test]
327 fn native_switch_without_which_starts_at_input0() {
328 let c = comp("S = Switch { }");
329 assert_eq!(port(&c, "S"), "Input0");
330 }
331}
crates/flow/src/lib.rs+8-7
...@@ -509,10 +509,11 @@ impl FlowView {...@@ -509,10 +509,11 @@ impl FlowView {
509 if (self.modal.is_some() || self.wire_drag.is_some()) && !steering {509 if (self.modal.is_some() || self.wire_drag.is_some()) && !steering {
510 return;510 return;
511 }511 }
512 let cmd = kmod.super_key() || kmod.control_key();
513 let plain = !cmd && !kmod.alt_key();
512 // Shift+Space: open Add Tool launcher514 // Shift+Space: open Add Tool launcher
513 if kmod.shift_key()515 if kmod.shift_key()
514 && !kmod.super_key()516 && plain
515 && !kmod.control_key()
516 && matches!(key, Key::Named(NamedKey::Space))517 && matches!(key, Key::Named(NamedKey::Space))
517 {518 {
518 actions.push(FlowAction::OpenAddTool);519 actions.push(FlowAction::OpenAddTool);
...@@ -524,12 +525,12 @@ impl FlowView {...@@ -524,12 +525,12 @@ impl FlowView {
524 return;525 return;
525 }526 }
526 if physical == Some(PhysicalKey::Code(KeyCode::Backquote)) {527 if physical == Some(PhysicalKey::Code(KeyCode::Backquote)) {
527 self.viewed_nodes = [None, None];528 if plain {
528 actions.push(FlowAction::ClearViewers);529 self.viewed_nodes = [None, None];
530 actions.push(FlowAction::ClearViewers);
531 }
529 return;532 return;
530 }533 }
531 let cmd = kmod.super_key() || kmod.control_key();
532 let plain = !cmd && !kmod.alt_key();
533 match key {534 match key {
534 Key::Named(NamedKey::Escape) => {535 Key::Named(NamedKey::Escape) => {
535 if self.modal.is_some() || self.wire_drag.is_some() {536 if self.modal.is_some() || self.wire_drag.is_some() {
...@@ -576,7 +577,7 @@ impl FlowView {...@@ -576,7 +577,7 @@ impl FlowView {
576 }577 }
577 }578 }
578 Key::Character(c) => match c.to_ascii_lowercase().as_str() {579 Key::Character(c) => match c.to_ascii_lowercase().as_str() {
579 "`" | "~" => {580 "`" | "~" if plain => {
580 self.viewed_nodes = [None, None];581 self.viewed_nodes = [None, None];
581 actions.push(FlowAction::ClearViewers);582 actions.push(FlowAction::ClearViewers);
582 }583 }
crates/spline/src/lib.rs+82-6
...@@ -583,14 +583,16 @@ impl SplineView {...@@ -583,14 +583,16 @@ impl SplineView {
583 let Some(kf) = sp.keyframes.get_mut(pref.key_idx) else { continue };583 let Some(kf) = sp.keyframes.get_mut(pref.key_idx) else { continue };
584 match pref.part {584 match pref.part {
585 HandlePart::Key => {585 HandlePart::Key => {
586 kf.time = snap_t(piv[0] + (kf.time - piv[0]) * st);586 let raw_t = piv[0] + (kf.time - piv[0]) * st;
587 kf.time = snap_t(raw_t);
588 let snap = kf.time - raw_t;
587 kf.value = piv_val + (kf.value - piv_val) * sv;589 kf.value = piv_val + (kf.value - piv_val) * sv;
588 if let Some(lh) = &mut kf.lh {590 if let Some(lh) = &mut kf.lh {
589 lh[0] = piv[0] + (lh[0] - piv[0]) * st;591 lh[0] = (piv[0] + (lh[0] - piv[0]) * st + snap).min(kf.time - 0.01);
590 lh[1] = piv_val + (lh[1] - piv_val) * sv;592 lh[1] = piv_val + (lh[1] - piv_val) * sv;
591 }593 }
592 if let Some(rh) = &mut kf.rh {594 if let Some(rh) = &mut kf.rh {
593 rh[0] = piv[0] + (rh[0] - piv[0]) * st;595 rh[0] = (piv[0] + (rh[0] - piv[0]) * st + snap).max(kf.time + 0.01);
594 rh[1] = piv_val + (rh[1] - piv_val) * sv;596 rh[1] = piv_val + (rh[1] - piv_val) * sv;
595 }597 }
596 }598 }
...@@ -648,8 +650,13 @@ impl SplineView {...@@ -648,8 +650,13 @@ impl SplineView {
648 kf.flags.linear = false;650 kf.flags.linear = false;
649 } else {651 } else {
650 let nk = rot([kf.time, kf.value], sp_px, bounds);652 let nk = rot([kf.time, kf.value], sp_px, bounds);
653 let lh = kf.lh.map(|h| rot(h, sp_px, bounds));
654 let rh = kf.rh.map(|h| rot(h, sp_px, bounds));
651 kf.time = snap_t(nk[0]);655 kf.time = snap_t(nk[0]);
656 let snap = kf.time - nk[0];
652 kf.value = nk[1];657 kf.value = nk[1];
658 kf.lh = lh.map(|h| [(h[0] + snap).min(kf.time - 0.01), h[1]]);
659 kf.rh = rh.map(|h| [(h[0] + snap).max(kf.time + 0.01), h[1]]);
653 }660 }
654 }661 }
655 HandlePart::LeftHandle => {662 HandlePart::LeftHandle => {
...@@ -716,6 +723,10 @@ impl SplineView {...@@ -716,6 +723,10 @@ impl SplineView {
716 }723 }
717 }724 }
718725
726 pub fn is_popup_open(&self) -> bool {
727 self.popup.is_some()
728 }
729
719 fn popup_rect(&self, popup: &PopupMenu) -> [f32; 4] {730 fn popup_rect(&self, popup: &PopupMenu) -> [f32; 4] {
720 let count = match popup.kind {731 let count = match popup.kind {
721 PopupKind::HandleType => HANDLE_MENU_ITEMS.len(),732 PopupKind::HandleType => HANDLE_MENU_ITEMS.len(),
...@@ -900,7 +911,7 @@ impl SplineView {...@@ -900,7 +911,7 @@ impl SplineView {
900 }911 }
901 }912 }
902 Key::Named(NamedKey::Delete | NamedKey::Backspace) => {913 Key::Named(NamedKey::Delete | NamedKey::Backspace) => {
903 if self.delete_selected(comp, history) {914 if self.modal.is_none() && self.delete_selected(comp, history) {
904 actions.push(SplineAction::SplineEdited);915 actions.push(SplineAction::SplineEdited);
905 }916 }
906 }917 }
...@@ -987,7 +998,7 @@ impl SplineView {...@@ -987,7 +998,7 @@ impl SplineView {
987 actions.push(SplineAction::SplineEdited);998 actions.push(SplineAction::SplineEdited);
988 }999 }
989 }1000 }
990 "a" if plain => {1001 "a" if plain && self.modal.is_none() => {
991 if !self.selected.is_empty() {1002 if !self.selected.is_empty() {
992 self.selected.clear();1003 self.selected.clear();
993 } else {1004 } else {
...@@ -1007,7 +1018,7 @@ impl SplineView {...@@ -1007,7 +1018,7 @@ impl SplineView {
1007 }1018 }
1008 }1019 }
1009 }1020 }
1010 "l" if plain => {1021 "l" if plain && self.modal.is_none() => {
1011 let by_spline = self.selected_keys_by_spline(comp);1022 let by_spline = self.selected_keys_by_spline(comp);
1012 if !by_spline.is_empty() {1023 if !by_spline.is_empty() {
1013 if let Some(h) = history.as_deref_mut() {1024 if let Some(h) = history.as_deref_mut() {
...@@ -1694,4 +1705,69 @@ mod tests {...@@ -1694,4 +1705,69 @@ mod tests {
1694 }1705 }
1695 assert_eq!(comp.splines["Gain"].keyframes.len(), 3);1706 assert_eq!(comp.splines["Gain"].keyframes.len(), 3);
1696 }1707 }
1708
1709 #[test]
1710 fn multi_key_rotate_carries_handles_with_their_keys() {
1711 let mut comp = test_comp();
1712 {
1713 let kfs = &mut comp.splines.get_mut("Gain").unwrap().keyframes;
1714 kfs[0].lh = Some([-10.0, 10.0]);
1715 kfs[0].rh = Some([10.0, 10.0]);
1716 kfs[1].lh = Some([40.0, 110.0]);
1717 kfs[1].rh = Some([60.0, 110.0]);
1718 }
1719 let orig = comp.splines["Gain"].keyframes.clone();
1720 let mut view = SplineView::new(&ui::Theme::dark());
1721 view.resize([800.0, 360.0]);
1722 view.set_target_node(&comp, None);
1723 view.selected.insert(key_ref(0, HandlePart::Key));
1724 view.selected.insert(key_ref(1, HandlePart::Key));
1725
1726 let bounds = (10.0, 110.0);
1727 let pivot_data = [25.0, 60.0];
1728 let piv = view.spline_to_local(pivot_data[0], pivot_data[1], bounds);
1729 view.pointer_local = [piv[0] + 100.0, piv[1]];
1730 view.begin_modal(&comp, false, TransformMode::Rotate);
1731 let theta = 0.1_f32;
1732 view.pointer_local = [piv[0] + 100.0 * theta.cos(), piv[1] + 100.0 * theta.sin()];
1733 assert!(view.apply_modal(&mut comp, true));
1734
1735 let rotated = |pt: [f64; 2]| {
1736 let p = view.spline_to_local(pt[0], pt[1], bounds);
1737 let (rx, ry) = (p[0] - piv[0], p[1] - piv[1]);
1738 let np = [piv[0] + rx * theta.cos() - ry * theta.sin(), piv[1] + rx * theta.sin() + ry * theta.cos()];
1739 let d = view.local_to_data(np);
1740 [d[0], display_to_value(d[1], bounds, false)]
1741 };
1742 let kfs = &comp.splines["Gain"].keyframes;
1743 for (i, o) in orig.iter().take(2).enumerate() {
1744 for (got, want) in [(kfs[i].lh, o.lh), (kfs[i].rh, o.rh)] {
1745 let want = rotated(want.unwrap());
1746 let got = got.unwrap();
1747 assert!((got[0] - want[0]).abs() < 1e-2 && (got[1] - want[1]).abs() < 1e-2, "key {i}: {got:?} vs {want:?}");
1748 }
1749 }
1750 }
1751
1752 #[test]
1753 fn destructive_keys_are_ignored_while_a_modal_is_active() {
1754 let mut comp = test_comp();
1755 let mut view = SplineView::new(&ui::Theme::dark());
1756 view.resize([800.0, 360.0]);
1757 view.set_target_node(&comp, None);
1758 view.selected.insert(key_ref(1, HandlePart::Key));
1759 view.begin_modal(&comp, false, TransformMode::Grab);
1760 let rect = [0.0, 0.0, 800.0, 360.0];
1761 let revision = comp.revision;
1762 let linear = comp.splines["Gain"].keyframes[1].flags.linear;
1763 let named = |k| ui::Event::Key { key: Key::Named(k), modifiers: ModifiersState::empty(), text: None };
1764 for ev in [named(NamedKey::Delete), named(NamedKey::Backspace), key_event("l"), key_event("a")] {
1765 view.input(&mut comp, 5.0, ev, rect, [300.0, 150.0], ModifiersState::empty());
1766 }
1767 assert!(view.modal.is_some());
1768 assert_eq!(comp.splines["Gain"].keyframes.len(), 3);
1769 assert_eq!(view.selected, HashSet::from([key_ref(1, HandlePart::Key)]));
1770 assert_eq!(comp.splines["Gain"].keyframes[1].flags.linear, linear);
1771 assert_eq!(comp.revision, revision);
1772 }
1697}1773}
crates/viewer/src/gizmos.rs+18-5
...@@ -498,13 +498,14 @@ impl GizmoState {...@@ -498,13 +498,14 @@ impl GizmoState {
498 let poly_col = [0.34, 0.88, 0.98, 0.90];498 let poly_col = [0.34, 0.88, 0.98, 0.90];
499 let handle_col = [0.88, 0.56, 0.98, 0.75];499 let handle_col = [0.88, 0.56, 0.98, 0.75];
500 if pts.len() >= 2 {500 if pts.len() >= 2 {
501 let place = |dx: f64, dy: f64| rotate_about(Self::fu_to_local([p.center[0] + dx, p.center[1] + dy], img_rect), c, rad);
501 for i in 0..pts.len() {502 for i in 0..pts.len() {
502 let a = &pts[i];503 let a = &pts[i];
503 let b = &pts[(i + 1) % pts.len()];504 let b = &pts[(i + 1) % pts.len()];
504 let p0 = Self::fu_to_local([p.center[0] + a.x, p.center[1] + a.y], img_rect);505 let p0 = place(a.x, a.y);
505 let p1 = Self::fu_to_local([p.center[0] + a.x + a.rx, p.center[1] + a.y + a.ry], img_rect);506 let p1 = place(a.x + a.rx, a.y + a.ry);
506 let p2 = Self::fu_to_local([p.center[0] + b.x + b.lx, p.center[1] + b.y + b.ly], img_rect);507 let p2 = place(b.x + b.lx, b.y + b.ly);
507 let p3 = Self::fu_to_local([p.center[0] + b.x, p.center[1] + b.y], img_rect);508 let p3 = place(b.x, b.y);
508 let curved = a.rx.abs() + a.ry.abs() + b.lx.abs() + b.ly.abs() > 1e-5;509 let curved = a.rx.abs() + a.ry.abs() + b.lx.abs() + b.ly.abs() > 1e-5;
509 if curved {510 if curved {
510 let mut prev = p0;511 let mut prev = p0;
...@@ -526,7 +527,7 @@ impl GizmoState {...@@ -526,7 +527,7 @@ impl GizmoState {
526 push_handle_dot(&mut out, p1, 2.8, handle_col, false);527 push_handle_dot(&mut out, p1, 2.8, handle_col, false);
527 }528 }
528 if a.lx.abs() + a.ly.abs() > 1e-4 {529 if a.lx.abs() + a.ly.abs() > 1e-4 {
529 let pl = Self::fu_to_local([p.center[0] + a.x + a.lx, p.center[1] + a.y + a.ly], img_rect);530 let pl = place(a.x + a.lx, a.y + a.ly);
530 out.push(Primitive::Segment { from: p0, to: pl, width: 1.0, color: handle_col });531 out.push(Primitive::Segment { from: p0, to: pl, width: 1.0, color: handle_col });
531 push_handle_dot(&mut out, pl, 2.8, handle_col, false);532 push_handle_dot(&mut out, pl, 2.8, handle_col, false);
532 }533 }
...@@ -551,6 +552,12 @@ struct NodeGizmoParams {...@@ -551,6 +552,12 @@ struct NodeGizmoParams {
551 height: f64,552 height: f64,
552}553}
553554
555/// Rotates screen point `p` about `c` counter-clockwise as Fusion sees it (screen Y points down).
556fn rotate_about(p: [f32; 2], c: [f32; 2], rad: f32) -> [f32; 2] {
557 let (rx, ry) = (p[0] - c[0], p[1] - c[1]);
558 [c[0] + rx * rad.cos() + ry * rad.sin(), c[1] - rx * rad.sin() + ry * rad.cos()]
559}
560
554fn extract_polyline_points(comp: &Comp, node: &Node, time: f64) -> Vec<model::PolyPoint> {561fn extract_polyline_points(comp: &Comp, node: &Node, time: f64) -> Vec<model::PolyPoint> {
555 if let Some(src) = node.connected_node("Polyline") {562 if let Some(src) = node.connected_node("Polyline") {
556 if let Some(pts) = comp.eval_polyline_spline(src, time) {563 if let Some(pts) = comp.eval_polyline_spline(src, time) {
...@@ -783,4 +790,10 @@ mod tests {...@@ -783,4 +790,10 @@ mod tests {
783 assert!((full - 0.5).abs() < 1e-4, "full = {full}");790 assert!((full - 0.5).abs() < 1e-4, "full = {full}");
784 assert!((fine - 0.42).abs() < 1e-4, "fine = {fine}");791 assert!((fine - 0.42).abs() < 1e-4, "fine = {fine}");
785 }792 }
793
794 #[test]
795 fn polyline_rotation_is_counter_clockwise_on_screen() {
796 let r = rotate_about([110.0, 50.0], [100.0, 50.0], 90.0_f32.to_radians());
797 assert!((r[0] - 100.0).abs() < 1e-4 && (r[1] - 40.0).abs() < 1e-4, "{r:?}");
798 }
786}799}
crates/viewer/src/lib.rs+48-21
...@@ -419,47 +419,42 @@ impl ViewerState {...@@ -419,47 +419,42 @@ impl ViewerState {
419 }419 }
420 return;420 return;
421 }421 }
422 let bare = !kmod.super_key() && !kmod.control_key() && !kmod.alt_key();
422 if physical == Some(PhysicalKey::Code(KeyCode::NumpadDecimal)) {423 if physical == Some(PhysicalKey::Code(KeyCode::NumpadDecimal)) {
423 self.fit();424 self.fit();
424 return;425 return;
425 }426 }
426 if physical == Some(PhysicalKey::Code(KeyCode::Backquote)) {427 if physical == Some(PhysicalKey::Code(KeyCode::Backquote)) {
427 actions.push(ViewerAction::ClearViewers);428 if bare {
429 actions.push(ViewerAction::ClearViewers);
430 }
428 return;431 return;
429 }432 }
430 if physical == Some(PhysicalKey::Code(KeyCode::KeyX))433 if physical == Some(PhysicalKey::Code(KeyCode::KeyX)) && kmod.alt_key() && !kmod.super_key() && !kmod.control_key() {
431 && kmod.alt_key()
432 && !kmod.super_key()
433 && !kmod.control_key()
434 {
435 actions.push(ViewerAction::ClearInOut);434 actions.push(ViewerAction::ClearInOut);
436 return;435 return;
437 }436 }
438 match key {437 match key {
439 Key::Named(NamedKey::Space) => actions.push(ViewerAction::TogglePlay),438 Key::Named(NamedKey::Space) if bare => actions.push(ViewerAction::TogglePlay),
440 Key::Named(NamedKey::ArrowLeft) => actions.push(ViewerAction::SetFrame(clock.current_frame - 1.0)),439 Key::Named(NamedKey::ArrowLeft) if bare => actions.push(ViewerAction::SetFrame(clock.current_frame - 1.0)),
441 Key::Named(NamedKey::ArrowRight) => actions.push(ViewerAction::SetFrame(clock.current_frame + 1.0)),440 Key::Named(NamedKey::ArrowRight) if bare => actions.push(ViewerAction::SetFrame(clock.current_frame + 1.0)),
442 Key::Character(c) => match c.to_ascii_lowercase().as_str() {441 Key::Character(c) => match c.to_ascii_lowercase().as_str() {
443 "`" | "~" => actions.push(ViewerAction::ClearViewers),442 "`" | "~" if bare => actions.push(ViewerAction::ClearViewers),
444 "i" if !kmod.super_key() && !kmod.control_key() && !kmod.alt_key() => {443 "i" if bare => actions.push(ViewerAction::SetInPoint),
445 actions.push(ViewerAction::SetInPoint);444 "o" if bare => actions.push(ViewerAction::SetOutPoint),
446 }
447 "o" if !kmod.super_key() && !kmod.control_key() && !kmod.alt_key() => {
448 actions.push(ViewerAction::SetOutPoint);
449 }
450 "x" | "≈" if kmod.alt_key() && !kmod.super_key() && !kmod.control_key() => {445 "x" | "≈" if kmod.alt_key() && !kmod.super_key() && !kmod.control_key() => {
451 actions.push(ViewerAction::ClearInOut);446 actions.push(ViewerAction::ClearInOut);
452 }447 }
453 "f" if kmod.super_key() => self.fit(),448 "f" if kmod.super_key() => self.fit(),
454 "f" | "." if !kmod.super_key() => self.fit(),449 "f" | "." if !kmod.super_key() && !kmod.control_key() && !kmod.alt_key() => self.fit(),
455 "0" => {450 "0" if bare => {
456 self.fit_mode = false;451 self.fit_mode = false;
457 self.zoom = 1.0;452 self.zoom = 1.0;
458 self.pan = [0.0, 0.0];453 self.pan = [0.0, 0.0];
459 self.dirty = true;454 self.dirty = true;
460 }455 }
461 "[" => actions.push(ViewerAction::SetFrame(clock.current_frame - 1.0)),456 "[" if bare => actions.push(ViewerAction::SetFrame(clock.current_frame - 1.0)),
462 "]" => actions.push(ViewerAction::SetFrame(clock.current_frame + 1.0)),457 "]" if bare => actions.push(ViewerAction::SetFrame(clock.current_frame + 1.0)),
463 _ => {}458 _ => {}
464 },459 },
465 _ => {}460 _ => {}
...@@ -576,7 +571,9 @@ impl ViewerState {...@@ -576,7 +571,9 @@ impl ViewerState {
576 let factor = (1.0 + delta).clamp(0.7, 1.4);571 let factor = (1.0 + delta).clamp(0.7, 1.4);
577 self.zoom_at(comp, factor, self.pointer_local);572 self.zoom_at(comp, factor, self.pointer_local);
578 }573 }
579 ui::Event::KeyInput { physical, key, state: ElementState::Pressed, repeat: false, modifiers: kmod, .. } => {574 ui::Event::KeyInput { physical, key, state: ElementState::Pressed, repeat, modifiers: kmod, .. }
575 if !repeat || matches!(key, Key::Named(NamedKey::ArrowLeft | NamedKey::ArrowRight)) =>
576 {
580 self.handle_key(clock, Some(physical), &key, kmod, &mut actions);577 self.handle_key(clock, Some(physical), &key, kmod, &mut actions);
581 }578 }
582 ui::Event::Key { key, modifiers: kmod, .. } => {579 ui::Event::Key { key, modifiers: kmod, .. } => {
...@@ -775,4 +772,34 @@ mod tests {...@@ -775,4 +772,34 @@ mod tests {
775 assert!(matches!(run(&mut viewer, false).as_slice(), [ViewerAction::SetInPoint]));772 assert!(matches!(run(&mut viewer, false).as_slice(), [ViewerAction::SetInPoint]));
776 assert!(run(&mut viewer, true).is_empty());773 assert!(run(&mut viewer, true).is_empty());
777 }774 }
775
776 #[test]
777 fn arrows_repeat_and_modified_keys_do_not_trigger_single_key_bindings() {
778 let comp = test_comp();
779 let mut clock = PlaybackClock::new();
780 clock.init_from_comp(&comp);
781 let theme = ui::Theme::new(&theme::KNIFE, true);
782 let mut viewer = ViewerState::new(0, &theme);
783 let ev = |physical, key: Key, modifiers, repeat| ui::Event::KeyInput {
784 physical: PhysicalKey::Code(physical),
785 key: key.clone(),
786 text: None,
787 unshifted: key,
788 modifiers,
789 state: ElementState::Pressed,
790 repeat,
791 };
792 let rect = [0.0, 0.0, 640.0, 400.0];
793 let mut run = |e| viewer.input(&comp, &clock, e, rect, [0.0, 0.0], ModifiersState::empty());
794 let right = Key::Named(NamedKey::ArrowRight);
795 assert_eq!(run(ev(KeyCode::ArrowRight, right, ModifiersState::empty(), true)).len(), 1);
796 let cmd = ModifiersState::SUPER;
797 assert!(run(ev(KeyCode::Backquote, Key::Character("`".into()), cmd, false)).is_empty());
798 assert!(run(ev(KeyCode::Space, Key::Named(NamedKey::Space), cmd, false)).is_empty());
799 let bare = ModifiersState::empty();
800 assert!(matches!(
801 run(ev(KeyCode::Backquote, Key::Character("`".into()), bare, false)).as_slice(),
802 [ViewerAction::ClearViewers]
803 ));
804 }
778}805}