Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

Merge remote-tracking branch 'origin/main' into fix-470

Brandon Thomasba0e66c6d33c
diff --cc crates/ui-egui/src/panels/effect_controls.rs
index ff1497945,b4142ca45..b3c691bf7
--- a/crates/ui-egui/src/panels/effect_controls.rs
+++ b/crates/ui-egui/src/panels/effect_controls.rs
@@@ -28,32 -28,31 +28,44 @@@ fn timeline_time_of(it: &TrackItem, m:
it.start + Tick(((m - it.source_in).0 as f64 / it.speed.abs().max(1e-6)) as i64)
}
+// The press frame can include movement before the button went down. Start from the press
+// origin so that only gesture motion enters the preview, including same-frame movement.
+fn graph_drag_offset(ui: &egui::Ui, response: &egui::Response, previous: egui::Vec2) -> egui::Vec2 {
+ if response.drag_started() {
+ response
+ .interact_pointer_pos()
+ .zip(ui.input(|i| i.pointer.press_origin()))
+ .map_or_else(|| response.drag_delta(), |(position, origin)| position - origin)
+ } else {
+ previous + response.drag_delta()
+ }
+}
+
- fn selected_clip(app: &FilmcraftApp) -> Option<(ClipId, TrackItem, filmcraft_project::TrackKind)> {
- let seq = app.session.active_sequence()?;
- let mut best = None;
- for c in &app.session.state.selection {
- if let Some((tid, it)) = seq.find_item(*c) {
- let kind = seq.track(tid)?.kind;
- if kind == filmcraft_project::TrackKind::Video {
- return Some((*c, it.clone(), kind));
- }
- best.get_or_insert((*c, it.clone(), kind));
- }
+ fn selected_clip(app: &FilmcraftApp) -> Option<(ClipId, TrackItem, TrackKind)> {
+ selected_clips(app).into_iter().next()
+ }
+
+ /// The selected clip (video first) and, for a video clip, the selected audio linked to it.
+ fn selected_clips(app: &FilmcraftApp) -> Vec<(ClipId, TrackItem, TrackKind)> {
+ let Some(seq) = app.session.active_sequence() else { return Vec::new() };
+ let picked: Vec<(ClipId, &TrackItem, TrackKind)> = app
+ .session
+ .state
+ .selection
+ .iter()
+ .filter_map(|c| {
+ let (tid, it) = seq.find_item(*c)?;
+ Some((*c, it, seq.track(tid)?.kind))
+ })
+ .collect();
+ let Some(&(clip, it, kind)) = picked.iter().find(|p| p.2 == TrackKind::Video).or(picked.first()) else { return Vec::new() };
+ let mut out = vec![(clip, it.clone(), kind)];
+ if kind == TrackKind::Video
+ && let Some(&(ac, ai, ak)) = picked.iter().find(|p| p.2 == TrackKind::Audio && p.1.link.is_some() && p.1.link == it.link)
+ {
+ out.push((ac, ai.clone(), ak));
}
- best
+ out
}
pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
@@@ -957,11 -975,11 +988,11 @@@ pub(crate) fn graph_rows
let hdx: f32 = ui.data(|d| d.get_temp(hid)).unwrap_or(0.0);
let hx = c.x + side * (infl * seg + hdx * side).clamp(seg * 0.01, seg);
let hp = pos2(hx, c.y);
- p.line_segment([c, hp], Stroke::new(1.0, Color32::from_rgb(0x90, 0x90, 0x90)));
- p.circle_filled(hp, 3.5, Color32::from_rgb(0xd0, 0xd0, 0xd0));
+ p.line_segment([c, hp], Stroke::new(1.0, t.plot_handle_dim));
+ p.circle_filled(hp, 3.5, t.keyframe_handle);
let hr = ui.interact(Rect::from_center_size(hp, vec2(10.0, 10.0)), hid.with("h"), Sense::drag());
if hr.dragged() {
- let nx = hdx + hr.drag_delta().x;
+ let nx = graph_drag_offset(ui, &hr, vec2(hdx, 0.0)).x;
ui.data_mut(|d| d.insert_temp(hid, nx));
}
if hr.drag_stopped() {
@@@ -971,9 -989,9 +1002,9 @@@
actions.push(("effects.setKeyframe".into(), with_mask(json!({"clip": clip.0, "effect": idx, "param": pd.id, "mediaTime": k.time.0, key: ni}))));
}
}
- p.circle_filled(c, 4.5, if resp.dragged() { t.hot_text } else { Color32::from_rgb(0xe0, 0xe0, 0xe0) });
+ p.circle_filled(c, 4.5, if resp.dragged() { t.hot_text } else { t.plot_handle });
if resp.dragged() {
- let ny = dy + resp.drag_delta().y;
+ let ny = graph_drag_offset(ui, &resp, vec2(0.0, dy)).y;
ui.data_mut(|d| d.insert_temp(id, ny));
p.text(c + vec2(8.0, -10.0), Align2::LEFT_BOTTOM, format!("{:.dec$}", v_of(c.y)), Tokens::ui(10.5), t.hot_text);
}