| author | |
| committer | |
| log | d702f0abe89e0236e840be2dedb07dd5010e5669 |
| tree | 08dbf657d21da6d85f13d9fde69a8106c8a3821e |
| parent | 22b81476d7a6aae5efca63a734822ad5d21da5b8 |
| signature | Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU |
Assisted-by: claude-sonnet-5.59 files changed, 427 insertions(+), 100 deletions(-)
crates/app/src/keyframes.rs+41| ... | ... | @@ -288,6 +288,20 @@ impl KeyframesView { |
| 288 | 288 | true |
| 289 | 289 | } |
| 290 | 290 | |
| 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 | 305 | fn delete_selected(&mut self, comp: &mut Comp, history: &mut CompHistory) -> bool { |
| 292 | 306 | if self.selected_keys.is_empty() { |
| 293 | 307 | return false; |
| ... | ... | @@ -492,6 +506,11 @@ impl KeyframesView { |
| 492 | 506 | ) { |
| 493 | 507 | let plain = !kmod.super_key() && !kmod.control_key() && !kmod.alt_key(); |
| 494 | 508 | match key { |
| 509 | Key::Named(NamedKey::Escape) => { | |
| 510 | if self.cancel_retime_drag(comp) { | |
| 511 | actions.push(KeyframesAction::KeyframesEdited); | |
| 512 | } | |
| 513 | } | |
| 495 | 514 | Key::Named(NamedKey::Delete | NamedKey::Backspace) => { |
| 496 | 515 | if self.delete_selected(comp, history) { |
| 497 | 516 | actions.push(KeyframesAction::KeyframesEdited); |
| ... | ... | @@ -680,6 +699,28 @@ mod tests { |
| 680 | 699 | assert!((comp.splines["XF1Size"].keyframes[1].time - 40.0).abs() < 1e-6); |
| 681 | 700 | } |
| 682 | 701 | |
| 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 | 724 | #[test] |
| 684 | 725 | fn retime_past_a_neighbour_keeps_curve_sorted_and_selection_on_the_key() { |
| 685 | 726 | let mut comp = sample_animated_comp(); |
crates/app/src/main.rs+60-17| ... | ... | @@ -400,6 +400,9 @@ impl Studio { |
| 400 | 400 | } |
| 401 | 401 | self.flow.sanitize_ids(&self.comp); |
| 402 | 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 | 406 | self.keyframes.sanitize_ids(&self.comp); |
| 404 | 407 | self.inspector.reset(); |
| 405 | 408 | self.renaming_node = None; |
| ... | ... | @@ -775,6 +778,8 @@ impl Studio { |
| 775 | 778 | for ev in sig.events { |
| 776 | 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 | 783 | if self.comp.nodes.len() != node_count { |
| 779 | 784 | self.reconcile_node_refs(prev_viewed); |
| 780 | 785 | } |
| ... | ... | @@ -783,6 +788,7 @@ impl Studio { |
| 783 | 788 | FlowAction::SelectionChanged(sel) => { |
| 784 | 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 | 792 | FlowAction::ViewNode(slot, id) => { |
| 787 | 793 | self.viewers[slot].viewed_node = Some(id); |
| 788 | 794 | self.viewers[slot].dirty = true; |
| ... | ... | @@ -877,6 +883,10 @@ impl Studio { |
| 877 | 883 | } |
| 878 | 884 | } |
| 879 | 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 | 890 | self.flow.selected.clear(); |
| 881 | 891 | self.flow.selected.insert(id); |
| 882 | 892 | self.flow.primary = Some(id); |
| ... | ... | @@ -890,6 +900,12 @@ impl Studio { |
| 890 | 900 | } |
| 891 | 901 | } |
| 892 | 902 | |
| 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 | 909 | // Immediately re-render any dirty visible viewer before painting this frame! |
| 894 | 910 | self.render_visible_viewers(true); |
| 895 | 911 | |
| ... | ... | @@ -1022,6 +1038,20 @@ struct WindowHost { |
| 1022 | 1038 | studio: Studio, |
| 1023 | 1039 | access: Accessibility, |
| 1024 | 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 | ||
| 1045 | const BG_POLL: Duration = Duration::from_millis(100); | |
| 1046 | ||
| 1047 | /// Advances the background poll deadline; returns whether it has arrived and the next wake time. | |
| 1048 | fn 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 | } |
| 1026 | 1056 | |
| 1027 | 1057 | struct App { |
| ... | ... | @@ -1090,7 +1120,7 @@ impl WindowHost { |
| 1090 | 1120 | let quit = proxy.clone(); |
| 1091 | 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 | } |
| 1095 | 1125 | |
| 1096 | 1126 | fn redraw(&mut self) -> Result<(), Box<dyn Error>> { |
| ... | ... | @@ -1211,25 +1241,25 @@ impl ApplicationHandler<UserEvent> for App { |
| 1211 | 1241 | } |
| 1212 | 1242 | |
| 1213 | 1243 | fn about_to_wait(&mut self, event_loop: &ActiveEventLoop) { |
| 1214 | if let Some(host) = &self.host { | |
| 1215 | if !host.occluded { | |
| 1216 | if host.studio.playback.playing { | |
| 1217 | let wake = host.studio.playback.next_wake(&host.studio.comp); | |
| 1218 | event_loop.set_control_flow(ControlFlow::WaitUntil(Instant::now() + wake)); | |
| 1219 | host.window.request_redraw(); | |
| 1220 | return; | |
| 1221 | } | |
| 1222 | if host.studio.active_export.is_some() { | |
| 1223 | event_loop.set_control_flow(ControlFlow::WaitUntil(Instant::now() + Duration::from_millis(100))); | |
| 1224 | host.window.request_redraw(); | |
| 1225 | return; | |
| 1226 | } | |
| 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))); | |
| 1244 | if let Some(host) = &mut self.host | |
| 1245 | && !host.occluded | |
| 1246 | { | |
| 1247 | if host.studio.playback.playing { | |
| 1248 | host.next_bg_poll = None; | |
| 1249 | let wake = host.studio.playback.next_wake(&host.studio.comp); | |
| 1250 | event_loop.set_control_flow(ControlFlow::WaitUntil(Instant::now() + wake)); | |
| 1251 | host.window.request_redraw(); | |
| 1252 | return; | |
| 1253 | } | |
| 1254 | if host.studio.active_export.is_some() || host.studio.prefetcher.as_ref().is_some_and(RamPrefetcher::is_busy) { | |
| 1255 | let (due, wake) = poll_background(&mut host.next_bg_poll, Instant::now()); | |
| 1256 | if due { | |
| 1229 | 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 | 1264 | event_loop.set_control_flow(ControlFlow::Wait); |
| 1235 | 1265 | } |
| ... | ... | @@ -1311,6 +1341,19 @@ mod tests { |
| 1311 | 1341 | studio.comp.find_node(name).unwrap() |
| 1312 | 1342 | } |
| 1313 | 1343 | |
| 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 | 1357 | #[test] |
| 1315 | 1358 | fn deleting_nodes_under_a_viewer_reconciles_it_by_name() { |
| 1316 | 1359 | let mut studio = studio(); |
crates/app/src/menus.rs+25-14| ... | ... | @@ -78,7 +78,7 @@ pub(crate) fn build_flow_toolbar( |
| 78 | 78 | can_undo: bool, |
| 79 | 79 | can_redo: bool, |
| 80 | 80 | comp_unsaved: bool, |
| 81 | renaming_node: &Option<NodeId>, | |
| 81 | renaming_node: &mut Option<NodeId>, | |
| 82 | 82 | rename_buf: &mut String, |
| 83 | 83 | rename_needs_focus: &mut bool, |
| 84 | 84 | ) -> FlowToolbarActions { |
| ... | ... | @@ -184,6 +184,8 @@ pub(crate) fn build_flow_toolbar( |
| 184 | 184 | if *rename_needs_focus { |
| 185 | 185 | ui.set_focus(Some(rn_field_id)); |
| 186 | 186 | *rename_needs_focus = false; |
| 187 | } else if !rn_sig.focused { | |
| 188 | *renaming_node = None; | |
| 187 | 189 | } |
| 188 | 190 | for ev in &rn_sig.events { |
| 189 | 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 | 277 | return true; |
| 276 | 278 | } |
| 277 | 279 | |
| 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 | 285 | // Shift+Space opens Add Tool launcher (when not typing in a text field) |
| 279 | if !typing { | |
| 286 | if !typing && !popup_open { | |
| 280 | 287 | let is_shift_space = match event { |
| 281 | 288 | ui::Event::KeyInput { key: Key::Named(NamedKey::Space), modifiers, state: ElementState::Pressed, repeat: false, .. } |
| 282 | 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 | 292 | _ => false, |
| 286 | 293 | }; |
| ... | ... | @@ -292,21 +299,25 @@ pub(crate) fn handle_global_shortcut(studio: &mut Studio, event: &ui::Event) -> |
| 292 | 299 | let is_space = match event { |
| 293 | 300 | ui::Event::KeyInput { key: Key::Named(NamedKey::Space), modifiers, state: ElementState::Pressed, repeat: false, .. } |
| 294 | 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 | 304 | _ => false, |
| 298 | 305 | }; |
| 299 | if is_space && !studio.add_tool.open { | |
| 306 | if is_space { | |
| 300 | 307 | studio.playback.toggle_play_with_comp(&studio.comp, Instant::now()); |
| 301 | 308 | studio.sync_audio(true, false); |
| 302 | 309 | return true; |
| 303 | 310 | } |
| 304 | 311 | let is_backquote = match event { |
| 305 | ui::Event::KeyInput { physical: PhysicalKey::Code(KeyCode::Backquote), state: ElementState::Pressed, repeat: false, .. } => true, | |
| 306 | ui::Event::Key { key: Key::Character(c), .. } if c.as_str() == "`" || c.as_str() == "~" => true, | |
| 312 | ui::Event::KeyInput { physical: PhysicalKey::Code(KeyCode::Backquote), modifiers, state: ElementState::Pressed, repeat: false, .. } => { | |
| 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 | 318 | _ => false, |
| 308 | 319 | }; |
| 309 | if is_backquote && !studio.add_tool.open { | |
| 320 | if is_backquote { | |
| 310 | 321 | studio.clear_viewers(); |
| 311 | 322 | return true; |
| 312 | 323 | } |
| ... | ... | @@ -427,6 +438,7 @@ impl Studio { |
| 427 | 438 | self.reconcile_node_refs([None, None]); |
| 428 | 439 | self.history.clear(); |
| 429 | 440 | self.history.mark_saved(&self.comp); |
| 441 | self.spline.hidden_splines.clear(); | |
| 430 | 442 | self.engine.bust_all_caches(); |
| 431 | 443 | self.playback.init_from_comp(&self.comp); |
| 432 | 444 | |
| ... | ... | @@ -440,7 +452,7 @@ impl Studio { |
| 440 | 452 | } |
| 441 | 453 | } |
| 442 | 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 | 456 | let default_sel = self |
| 445 | 457 | .comp |
| 446 | 458 | .nodes |
| ... | ... | @@ -457,12 +469,11 @@ impl Studio { |
| 457 | 469 | self.keyframes.cached_ranges.clear(); |
| 458 | 470 | self.keyframes.fit_comp(&self.comp); |
| 459 | 471 | self.keyframes.sync_tracks(&self.comp, default_sel); |
| 460 | self.viewers[0].audio_peaks.clear(); | |
| 461 | self.ram_cache.clear(); | |
| 462 | if let Some(pf) = &self.prefetcher { | |
| 463 | pf.cancel(); | |
| 472 | for v in &mut self.viewers { | |
| 473 | v.audio_peaks.clear(); | |
| 464 | 474 | } |
| 465 | self.last_prefetch_sig = None; | |
| 475 | self.ram_cache.clear(); | |
| 476 | self.cancel_prefetch(); | |
| 466 | 477 | self.loaded_audio_track = None; |
| 467 | 478 | self.last_audio_offset = self.comp.audio_offset; |
| 468 | 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 | 41 | studio.comp.render_range[0], |
| 42 | 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 | 47 | studio.keyframes.audio_peaks = peaks; |
| 46 | 48 | studio.keyframes.audio_range = studio.comp.render_range; |
| 47 | 49 | } |
| ... | ... | @@ -62,7 +64,9 @@ impl Studio { |
| 62 | 64 | self.comp.render_range[0], |
| 63 | 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 | 70 | self.keyframes.audio_peaks = peaks; |
| 67 | 71 | self.keyframes.audio_range = self.comp.render_range; |
| 68 | 72 | } |
| ... | ... | @@ -129,7 +133,9 @@ impl Studio { |
| 129 | 133 | if self.comp.audio_filename != self.last_audio_filename { |
| 130 | 134 | self.last_audio_filename = self.comp.audio_filename.clone(); |
| 131 | 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 | 139 | self.keyframes.audio_peaks.clear(); |
| 134 | 140 | if self.enable_audio { |
| 135 | 141 | if let Some(player) = &mut self.audio_player { |
| ... | ... | @@ -179,16 +185,21 @@ impl Studio { |
| 179 | 185 | self.engine.bust_gpu_cache(); |
| 180 | 186 | } |
| 181 | 187 | self.ram_cache.invalidate_other_revisions(self.comp.revision); |
| 182 | if let Some(pf) = &self.prefetcher { | |
| 183 | pf.cancel(); | |
| 184 | } | |
| 185 | self.last_prefetch_sig = None; | |
| 188 | self.cancel_prefetch(); | |
| 186 | 189 | for v in &mut self.viewers { |
| 187 | 190 | v.cached_frames.clear(); |
| 188 | 191 | v.dirty = true; |
| 189 | 192 | } |
| 190 | 193 | } |
| 191 | 194 | |
| 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 | 203 | pub(crate) fn sync_ram_ranges_and_prefetch(&mut self) { |
| 193 | 204 | let sel = self.flow.primary; |
| 194 | 205 | for v in &mut self.viewers { |
| ... | ... | @@ -216,13 +227,14 @@ impl Studio { |
| 216 | 227 | if let (Some(target), Some(pf)) = (target, &mut self.prefetcher) { |
| 217 | 228 | if self.engine.cache.mode == CacheMode::Enabled { |
| 218 | 229 | let cur_f = self.playback.current_frame.round() as i64; |
| 230 | let range = self.playback.effective_preview_range(&self.comp); | |
| 219 | 231 | let key = ( |
| 220 | 232 | target, |
| 221 | 233 | self.comp.revision, |
| 222 | 234 | self.engine.proxy_scale, |
| 223 | 235 | self.engine.hiq, |
| 224 | 236 | self.engine.use_proxy_clips, |
| 225 | self.comp.render_range, | |
| 237 | range, | |
| 226 | 238 | ); |
| 227 | 239 | // Re-plan only when the job changes or the playhead leaves the half of the window |
| 228 | 240 | // already being filled, so steady playback never re-clones the comp per frame. |
| ... | ... | @@ -236,7 +248,7 @@ impl Studio { |
| 236 | 248 | comp: self.comp.clone(), |
| 237 | 249 | target, |
| 238 | 250 | center_frame: cur_f, |
| 239 | range: self.comp.render_range, | |
| 251 | range, | |
| 240 | 252 | lookahead: PREFETCH_LOOKAHEAD, |
| 241 | 253 | proxy_scale: self.engine.proxy_scale, |
| 242 | 254 | hiq: self.engine.hiq, |
| ... | ... | @@ -360,8 +372,8 @@ impl Studio { |
| 360 | 372 | } |
| 361 | 373 | ViewerAction::BustFrame(f) => { |
| 362 | 374 | self.engine.bust_frame(f); |
| 375 | self.cancel_prefetch(); | |
| 363 | 376 | self.ram_cache.clear(); |
| 364 | self.last_prefetch_sig = None; | |
| 365 | 377 | for v in &mut self.viewers { |
| 366 | 378 | v.cached_frames.remove(&f); |
| 367 | 379 | v.dirty = true; |
| ... | ... | @@ -371,8 +383,8 @@ impl Studio { |
| 371 | 383 | if let Some(id) = self.flow.primary.or(self.viewers[slot].viewed_node) { |
| 372 | 384 | self.engine.bust_subtree(id); |
| 373 | 385 | } |
| 386 | self.cancel_prefetch(); | |
| 374 | 387 | self.ram_cache.clear(); |
| 375 | self.last_prefetch_sig = None; | |
| 376 | 388 | for v in &mut self.viewers { |
| 377 | 389 | v.cached_frames.clear(); |
| 378 | 390 | v.dirty = true; |
| ... | ... | @@ -380,8 +392,8 @@ impl Studio { |
| 380 | 392 | } |
| 381 | 393 | ViewerAction::BustGpu => { |
| 382 | 394 | self.engine.bust_gpu_cache(); |
| 395 | self.cancel_prefetch(); | |
| 383 | 396 | self.ram_cache.clear(); |
| 384 | self.last_prefetch_sig = None; | |
| 385 | 397 | for v in &mut self.viewers { |
| 386 | 398 | v.cached_frames.clear(); |
| 387 | 399 | v.dirty = true; |
| ... | ... | @@ -389,8 +401,8 @@ impl Studio { |
| 389 | 401 | } |
| 390 | 402 | ViewerAction::BustAll => { |
| 391 | 403 | self.engine.bust_all_caches(); |
| 404 | self.cancel_prefetch(); | |
| 392 | 405 | self.ram_cache.clear(); |
| 393 | self.last_prefetch_sig = None; | |
| 394 | 406 | for v in &mut self.viewers { |
| 395 | 407 | v.cached_frames.clear(); |
| 396 | 408 | v.dirty = true; |
crates/flow/src/hit.rs+120-17| ... | ... | @@ -100,23 +100,7 @@ impl FlowView { |
| 100 | 100 | if !self.scope.shows(n) { continue; } |
| 101 | 101 | let r = self.node_rect_local(n.pos); |
| 102 | 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! | |
| 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))); | |
| 103 | return Some((n.id, drop_port(n, local[1] < r[1] + 2.0, local[1] > r[3] - 2.0))); | |
| 120 | 104 | } |
| 121 | 105 | } |
| 122 | 106 | None |
| ... | ... | @@ -175,6 +159,65 @@ impl FlowView { |
| 175 | 159 | } |
| 176 | 160 | } |
| 177 | 161 | |
| 162 | const 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 | ||
| 169 | const 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. | |
| 176 | fn 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 | 221 | /// Picks the closest node edge facing vector `(dx, dy)` accounting for thin rectangular bar aspect. |
| 179 | 222 | fn closest_edge(dx: f32, dy: f32) -> Edge { |
| 180 | 223 | // 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 | 269 | let q = [a[0] + ab[0] * t, a[1] + ab[1] * t]; |
| 227 | 270 | ((p[0] - q[0]).powi(2) + (p[1] - q[1]).powi(2)).sqrt() |
| 228 | 271 | } |
| 272 | ||
| 273 | #[cfg(test)] | |
| 274 | mod 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 | 509 | if (self.modal.is_some() || self.wire_drag.is_some()) && !steering { |
| 510 | 510 | return; |
| 511 | 511 | } |
| 512 | let cmd = kmod.super_key() || kmod.control_key(); | |
| 513 | let plain = !cmd && !kmod.alt_key(); | |
| 512 | 514 | // Shift+Space: open Add Tool launcher |
| 513 | 515 | if kmod.shift_key() |
| 514 | && !kmod.super_key() | |
| 515 | && !kmod.control_key() | |
| 516 | && plain | |
| 516 | 517 | && matches!(key, Key::Named(NamedKey::Space)) |
| 517 | 518 | { |
| 518 | 519 | actions.push(FlowAction::OpenAddTool); |
| ... | ... | @@ -524,12 +525,12 @@ impl FlowView { |
| 524 | 525 | return; |
| 525 | 526 | } |
| 526 | 527 | if physical == Some(PhysicalKey::Code(KeyCode::Backquote)) { |
| 527 | self.viewed_nodes = [None, None]; | |
| 528 | actions.push(FlowAction::ClearViewers); | |
| 528 | if plain { | |
| 529 | self.viewed_nodes = [None, None]; | |
| 530 | actions.push(FlowAction::ClearViewers); | |
| 531 | } | |
| 529 | 532 | return; |
| 530 | 533 | } |
| 531 | let cmd = kmod.super_key() || kmod.control_key(); | |
| 532 | let plain = !cmd && !kmod.alt_key(); | |
| 533 | 534 | match key { |
| 534 | 535 | Key::Named(NamedKey::Escape) => { |
| 535 | 536 | if self.modal.is_some() || self.wire_drag.is_some() { |
| ... | ... | @@ -576,7 +577,7 @@ impl FlowView { |
| 576 | 577 | } |
| 577 | 578 | } |
| 578 | 579 | Key::Character(c) => match c.to_ascii_lowercase().as_str() { |
| 579 | "`" | "~" => { | |
| 580 | "`" | "~" if plain => { | |
| 580 | 581 | self.viewed_nodes = [None, None]; |
| 581 | 582 | actions.push(FlowAction::ClearViewers); |
| 582 | 583 | } |
crates/spline/src/lib.rs+82-6| ... | ... | @@ -583,14 +583,16 @@ impl SplineView { |
| 583 | 583 | let Some(kf) = sp.keyframes.get_mut(pref.key_idx) else { continue }; |
| 584 | 584 | match pref.part { |
| 585 | 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 | 589 | kf.value = piv_val + (kf.value - piv_val) * sv; |
| 588 | 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 | 592 | lh[1] = piv_val + (lh[1] - piv_val) * sv; |
| 591 | 593 | } |
| 592 | 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 | 596 | rh[1] = piv_val + (rh[1] - piv_val) * sv; |
| 595 | 597 | } |
| 596 | 598 | } |
| ... | ... | @@ -648,8 +650,13 @@ impl SplineView { |
| 648 | 650 | kf.flags.linear = false; |
| 649 | 651 | } else { |
| 650 | 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 | 655 | kf.time = snap_t(nk[0]); |
| 656 | let snap = kf.time - nk[0]; | |
| 652 | 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 | 662 | HandlePart::LeftHandle => { |
| ... | ... | @@ -716,6 +723,10 @@ impl SplineView { |
| 716 | 723 | } |
| 717 | 724 | } |
| 718 | 725 | |
| 726 | pub fn is_popup_open(&self) -> bool { | |
| 727 | self.popup.is_some() | |
| 728 | } | |
| 729 | ||
| 719 | 730 | fn popup_rect(&self, popup: &PopupMenu) -> [f32; 4] { |
| 720 | 731 | let count = match popup.kind { |
| 721 | 732 | PopupKind::HandleType => HANDLE_MENU_ITEMS.len(), |
| ... | ... | @@ -900,7 +911,7 @@ impl SplineView { |
| 900 | 911 | } |
| 901 | 912 | } |
| 902 | 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 | 915 | actions.push(SplineAction::SplineEdited); |
| 905 | 916 | } |
| 906 | 917 | } |
| ... | ... | @@ -987,7 +998,7 @@ impl SplineView { |
| 987 | 998 | actions.push(SplineAction::SplineEdited); |
| 988 | 999 | } |
| 989 | 1000 | } |
| 990 | "a" if plain => { | |
| 1001 | "a" if plain && self.modal.is_none() => { | |
| 991 | 1002 | if !self.selected.is_empty() { |
| 992 | 1003 | self.selected.clear(); |
| 993 | 1004 | } else { |
| ... | ... | @@ -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 | 1022 | let by_spline = self.selected_keys_by_spline(comp); |
| 1012 | 1023 | if !by_spline.is_empty() { |
| 1013 | 1024 | if let Some(h) = history.as_deref_mut() { |
| ... | ... | @@ -1694,4 +1705,69 @@ mod tests { |
| 1694 | 1705 | } |
| 1695 | 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 | 498 | let poly_col = [0.34, 0.88, 0.98, 0.90]; |
| 499 | 499 | let handle_col = [0.88, 0.56, 0.98, 0.75]; |
| 500 | 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 | 502 | for i in 0..pts.len() { |
| 502 | 503 | let a = &pts[i]; |
| 503 | 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 p1 = Self::fu_to_local([p.center[0] + a.x + a.rx, p.center[1] + a.y + a.ry], img_rect); | |
| 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 p3 = Self::fu_to_local([p.center[0] + b.x, p.center[1] + b.y], img_rect); | |
| 505 | let p0 = place(a.x, a.y); | |
| 506 | let p1 = place(a.x + a.rx, a.y + a.ry); | |
| 507 | let p2 = place(b.x + b.lx, b.y + b.ly); | |
| 508 | let p3 = place(b.x, b.y); | |
| 508 | 509 | let curved = a.rx.abs() + a.ry.abs() + b.lx.abs() + b.ly.abs() > 1e-5; |
| 509 | 510 | if curved { |
| 510 | 511 | let mut prev = p0; |
| ... | ... | @@ -526,7 +527,7 @@ impl GizmoState { |
| 526 | 527 | push_handle_dot(&mut out, p1, 2.8, handle_col, false); |
| 527 | 528 | } |
| 528 | 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 | 531 | out.push(Primitive::Segment { from: p0, to: pl, width: 1.0, color: handle_col }); |
| 531 | 532 | push_handle_dot(&mut out, pl, 2.8, handle_col, false); |
| 532 | 533 | } |
| ... | ... | @@ -551,6 +552,12 @@ struct NodeGizmoParams { |
| 551 | 552 | height: f64, |
| 552 | 553 | } |
| 553 | 554 | |
| 555 | /// Rotates screen point `p` about `c` counter-clockwise as Fusion sees it (screen Y points down). | |
| 556 | fn 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 | ||
| 554 | 561 | fn extract_polyline_points(comp: &Comp, node: &Node, time: f64) -> Vec<model::PolyPoint> { |
| 555 | 562 | if let Some(src) = node.connected_node("Polyline") { |
| 556 | 563 | if let Some(pts) = comp.eval_polyline_spline(src, time) { |
| ... | ... | @@ -783,4 +790,10 @@ mod tests { |
| 783 | 790 | assert!((full - 0.5).abs() < 1e-4, "full = {full}"); |
| 784 | 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 | 419 | } |
| 420 | 420 | return; |
| 421 | 421 | } |
| 422 | let bare = !kmod.super_key() && !kmod.control_key() && !kmod.alt_key(); | |
| 422 | 423 | if physical == Some(PhysicalKey::Code(KeyCode::NumpadDecimal)) { |
| 423 | 424 | self.fit(); |
| 424 | 425 | return; |
| 425 | 426 | } |
| 426 | 427 | if physical == Some(PhysicalKey::Code(KeyCode::Backquote)) { |
| 427 | actions.push(ViewerAction::ClearViewers); | |
| 428 | if bare { | |
| 429 | actions.push(ViewerAction::ClearViewers); | |
| 430 | } | |
| 428 | 431 | return; |
| 429 | 432 | } |
| 430 | if physical == Some(PhysicalKey::Code(KeyCode::KeyX)) | |
| 431 | && kmod.alt_key() | |
| 432 | && !kmod.super_key() | |
| 433 | && !kmod.control_key() | |
| 434 | { | |
| 433 | if physical == Some(PhysicalKey::Code(KeyCode::KeyX)) && kmod.alt_key() && !kmod.super_key() && !kmod.control_key() { | |
| 435 | 434 | actions.push(ViewerAction::ClearInOut); |
| 436 | 435 | return; |
| 437 | 436 | } |
| 438 | 437 | match key { |
| 439 | Key::Named(NamedKey::Space) => actions.push(ViewerAction::TogglePlay), | |
| 440 | Key::Named(NamedKey::ArrowLeft) => actions.push(ViewerAction::SetFrame(clock.current_frame - 1.0)), | |
| 441 | Key::Named(NamedKey::ArrowRight) => actions.push(ViewerAction::SetFrame(clock.current_frame + 1.0)), | |
| 438 | Key::Named(NamedKey::Space) if bare => actions.push(ViewerAction::TogglePlay), | |
| 439 | Key::Named(NamedKey::ArrowLeft) if bare => 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 | 441 | Key::Character(c) => match c.to_ascii_lowercase().as_str() { |
| 443 | "`" | "~" => actions.push(ViewerAction::ClearViewers), | |
| 444 | "i" if !kmod.super_key() && !kmod.control_key() && !kmod.alt_key() => { | |
| 445 | actions.push(ViewerAction::SetInPoint); | |
| 446 | } | |
| 447 | "o" if !kmod.super_key() && !kmod.control_key() && !kmod.alt_key() => { | |
| 448 | actions.push(ViewerAction::SetOutPoint); | |
| 449 | } | |
| 442 | "`" | "~" if bare => actions.push(ViewerAction::ClearViewers), | |
| 443 | "i" if bare => actions.push(ViewerAction::SetInPoint), | |
| 444 | "o" if bare => actions.push(ViewerAction::SetOutPoint), | |
| 450 | 445 | "x" | "≈" if kmod.alt_key() && !kmod.super_key() && !kmod.control_key() => { |
| 451 | 446 | actions.push(ViewerAction::ClearInOut); |
| 452 | 447 | } |
| 453 | 448 | "f" if kmod.super_key() => self.fit(), |
| 454 | "f" | "." if !kmod.super_key() => self.fit(), | |
| 455 | "0" => { | |
| 449 | "f" | "." if !kmod.super_key() && !kmod.control_key() && !kmod.alt_key() => self.fit(), | |
| 450 | "0" if bare => { | |
| 456 | 451 | self.fit_mode = false; |
| 457 | 452 | self.zoom = 1.0; |
| 458 | 453 | self.pan = [0.0, 0.0]; |
| 459 | 454 | self.dirty = true; |
| 460 | 455 | } |
| 461 | "[" => actions.push(ViewerAction::SetFrame(clock.current_frame - 1.0)), | |
| 462 | "]" => actions.push(ViewerAction::SetFrame(clock.current_frame + 1.0)), | |
| 456 | "[" if bare => 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 | 571 | let factor = (1.0 + delta).clamp(0.7, 1.4); |
| 577 | 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 | 577 | self.handle_key(clock, Some(physical), &key, kmod, &mut actions); |
| 581 | 578 | } |
| 582 | 579 | ui::Event::Key { key, modifiers: kmod, .. } => { |
| ... | ... | @@ -775,4 +772,34 @@ mod tests { |
| 775 | 772 | assert!(matches!(run(&mut viewer, false).as_slice(), [ViewerAction::SetInPoint])); |
| 776 | 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 | } |