Skip to content

The truly free, open-source, local-first, cross-platform CapCut replacement. Scriptable through a JSON-RPC API & MCP.

Select, move, scale and turn pictures on the stage

Jareerc86bac1fd023
diff --git a/engine/crates/concat/src/main.rs b/engine/crates/concat/src/main.rs
index 5661b89f..5b99cb48 100644
--- a/engine/crates/concat/src/main.rs
+++ b/engine/crates/concat/src/main.rs
@@ -120,6 +120,7 @@ fn main() -> Result<(), slint::PlatformError> {
editor.set_timeline_tabs(ModelRc::from(models.tabs.clone()));
editor.set_tracks(ModelRc::from(models.tracks.clone()));
editor.set_clips(ModelRc::from(models.clips.clone()));
+ editor.set_stage_items(ModelRc::from(models.stage.clone()));
editor.set_media(ModelRc::from(models.media.clone()));
editor.set_video_effects(ModelRc::from(models.video_effects.clone()));
editor.set_audio_effects(ModelRc::from(models.audio_effects.clone()));
@@ -662,6 +663,22 @@ fn main() -> Result<(), slint::PlatformError> {
state.play_toggle();
}));
+ // ── the stage ──
+ editor.on_stage_pressed(on_window!(|state, x: f32, y: f32, additive: bool| {
+ state.stage_pressed(x, y, additive);
+ }));
+ editor.on_stage_grip_pressed(on_window!(
+ |state, id: SharedString, grip: i32, x: f32, y: f32| {
+ state.stage_grip_pressed(id.as_str(), grip, x, y);
+ }
+ ));
+ editor.on_stage_dragged(on_lanes!(|state, x: f32, y: f32, snap: bool| {
+ state.stage_dragged(x, y, snap);
+ }));
+ editor.on_stage_released(on_window!(|state| {
+ state.stage_released();
+ }));
+
// ── the context menu ──
editor.on_clip_context(on_window!(|state, id: SharedString| {
state.menu_token += 1;
diff --git a/engine/crates/concat/src/studio.rs b/engine/crates/concat/src/studio.rs
index b535c17d..c6c9fd87 100644
--- a/engine/crates/concat/src/studio.rs
+++ b/engine/crates/concat/src/studio.rs
@@ -270,6 +270,68 @@ pub enum Gesture {
duration: f32,
source_start: f32,
},
+ /// A drag on the stage: every selected picture under the playhead slides
+ /// with the pointer, from where each one was when the press landed.
+ StageMove {
+ origins: Vec<StageOrigin>,
+ /// The press, in fractions of the frame.
+ from: (f64, f64),
+ },
+ /// A corner grip dragged: the picture scales about its centre, by the
+ /// ratio of the pointer's distance from that centre to what it was.
+ StageScale {
+ clip: String,
+ scale: f64,
+ /// The centre, in frame pixels — the unit the ratio is taken in, so
+ /// a tall frame and a wide one scale at the same rate.
+ centre: (f64, f64),
+ from: f64,
+ },
+ /// The rotation grip dragged: the picture turns by the angle the pointer
+ /// has swept about the centre since the press.
+ StageRotate {
+ clip: String,
+ rotation: f64,
+ centre: (f64, f64),
+ from: f64,
+ },
+}
+
+/// Where a picture was when a stage move began.
+pub struct StageOrigin {
+ pub clip: String,
+ pub offset_x: f64,
+ pub offset_y: f64,
+}
+
+/// A picture's footprint in the output frame, in fractions of it: where the
+/// centre is, how much of the frame's width and height it covers before it
+/// is turned, and the clockwise turn. The one place the monitor's box and
+/// the compositor's quad agree, so the outline lands on the pixels.
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct Footprint {
+ pub cx: f64,
+ pub cy: f64,
+ pub w: f64,
+ pub h: f64,
+ pub rotation: f64,
+}
+
+impl Footprint {
+ /// True when the frame point `(x, y)`, in fractions, is inside the turned
+ /// box. `frame` is the output size, because the box is not square in
+ /// pixels and the turn has to happen in pixels.
+ pub fn contains(&self, x: f64, y: f64, frame: (u32, u32)) -> bool {
+ let (width, height) = (f64::from(frame.0), f64::from(frame.1));
+ let dx = (x - self.cx) * width;
+ let dy = (y - self.cy) * height;
+ let (sin, cos) = self.rotation.to_radians().sin_cos();
+ // The inverse of the compositor's forward map: undo the clockwise
+ // turn to land in the box's own frame, then it is an axis test.
+ let lx = dx * cos + dy * sin;
+ let ly = -dx * sin + dy * cos;
+ lx.abs() <= self.w * width / 2.0 && ly.abs() <= self.h * height / 2.0
+ }
}
/// A drag from the library, resolved against the timeline: the ghost the
@@ -293,6 +355,7 @@ pub struct Models {
pub tabs: Rc<VecModel<TimelineTabData>>,
pub tracks: Rc<VecModel<TrackData>>,
pub clips: Rc<VecModel<ClipData>>,
+ pub stage: Rc<VecModel<StageItemData>>,
pub media: Rc<VecModel<MediaItemData>>,
pub video_effects: Rc<VecModel<EffectData>>,
pub audio_effects: Rc<VecModel<EffectData>>,
@@ -312,6 +375,7 @@ impl Models {
tabs: Rc::new(VecModel::default()),
tracks: Rc::new(VecModel::default()),
clips: Rc::new(VecModel::default()),
+ stage: Rc::new(VecModel::default()),
media: Rc::new(VecModel::default()),
video_effects: Rc::new(VecModel::default()),
audio_effects: Rc::new(VecModel::default()),
@@ -853,6 +917,10 @@ impl Studio {
let Some(session) = self.session.as_ref() else {
return;
};
+ // The echo when there is one: a picture being dragged on the stage
+ // is drawn where the pointer has it, not where the document last
+ // had it. Same flattening the session does for itself.
+ let clips = concat_export::flatten::flatten_timeline(self.project(), None);
let (width, height) = self.output_size();
let scale = match self.quality {
0 => 1.0,
@@ -866,7 +934,6 @@ impl Studio {
width,
height,
};
- let clips = session.flattened_clips();
let settings = session.settings().clone();
let monitor = self.host.monitor.clone();
self.preview_busy = true;
@@ -1583,7 +1650,12 @@ impl Studio {
}
}
}
- Gesture::None => {}
+ // A stage gesture is the monitor's; the lanes have nothing to
+ // add to it.
+ Gesture::None
+ | Gesture::StageMove { .. }
+ | Gesture::StageScale { .. }
+ | Gesture::StageRotate { .. } => {}
}
self.gesture = gesture;
}
@@ -1640,6 +1712,12 @@ impl Studio {
Gesture::None => {
self.echo = None;
}
+ // Not a lane gesture: hand it back untouched, echo and all.
+ other @ (Gesture::StageMove { .. }
+ | Gesture::StageScale { .. }
+ | Gesture::StageRotate { .. }) => {
+ self.gesture = other;
+ }
}
}
@@ -1818,6 +1896,333 @@ impl Studio {
}
}
+ // ── the stage ──
+ //
+ // The monitor as a place to edit, not only to look: the pictures under
+ // the playhead can be grabbed, slid, scaled and turned where they are
+ // drawn. The same echo-then-command shape as the lanes and the
+ // inspector, with one difference: the echo is composited too, so the
+ // frame follows the pointer and not only the outline does.
+
+ /// Where `clip` lands in the output frame. The compositor's own rule —
+ /// contain-fitted, then the transform — restated in fractions.
+ pub fn footprint(&self, clip: &Clip) -> Footprint {
+ let (width, height) = self.output_size();
+ let (width, height) = (f64::from(width.max(1)), f64::from(height.max(1)));
+ let (w, h) = if clip.kind == model::ClipKind::Text {
+ // The engine does not report where a title's glyphs landed, so
+ // this is a reading of the style: an em is `font_size` of the
+ // frame's height, a glyph runs about six tenths of one, and a
+ // little air is left around the block the way the plate would.
+ let text = clip.text.clone().unwrap_or_default();
+ let lines: Vec<&str> = text.content.lines().collect();
+ let rows = lines.len().max(1) as f64;
+ let longest = lines
+ .iter()
+ .map(|line| line.chars().count())
+ .max()
+ .unwrap_or(0)
+ .max(1) as f64;
+ let em = text.font_size.max(0.005) * height;
+ let glyph = 0.6 * em + text.tracking * height;
+ (
+ (longest * glyph + 0.6 * em) * clip.scale / width,
+ (rows * em * text.line_height.max(0.5) + 0.5 * em) * clip.scale / height,
+ )
+ } else {
+ let media = self.project().media_by_id(&clip.media_id);
+ let source = media
+ .and_then(|item| Some((item.width?, item.height?)))
+ .filter(|(w, h)| *w > 0 && *h > 0)
+ .map(|(w, h)| (f64::from(w), f64::from(h)));
+ match source {
+ Some((sw, sh)) => {
+ let fit = (width / sw).min(height / sh);
+ (
+ sw * fit * clip.scale / width,
+ sh * fit * clip.scale / height,
+ )
+ }
+ // Dimensions never learnt: the frame's own shape, which is
+ // what the compositor falls back to as well.
+ None => (clip.scale, clip.scale),
+ }
+ };
+ Footprint {
+ cx: 0.5 + clip.offset_x,
+ cy: 0.5 + clip.offset_y,
+ w,
+ h,
+ rotation: clip.rotation,
+ }
+ }
+
+ /// The pictures under the playhead on lanes that are showing, bottom of
+ /// the stack first — the order the compositor lays them down, and the
+ /// order the overlay draws them in.
+ fn stage_clips(&self) -> Vec<&Clip> {
+ let timeline = self.timeline();
+ let playhead = f64::from(self.playhead);
+ let showing: HashSet<&str> = timeline
+ .tracks
+ .iter()
+ .filter(|track| track.visible)
+ .map(|track| track.id.as_str())
+ .collect();
+ let mut clips: Vec<&Clip> = timeline
+ .clips
+ .iter()
+ .filter(|clip| {
+ clip.kind != model::ClipKind::Audio
+ && showing.contains(clip.track_id.as_str())
+ && clip.start <= playhead
+ && playhead < clip.start + clip.duration
+ })
+ .collect();
+ // Rows count from the top; the bottom of the stack is the highest.
+ clips.sort_by_key(|clip| std::cmp::Reverse(self.row_of(&clip.track_id)));
+ clips
+ }
+
+ pub fn stage_items(&self) -> Vec<StageItemData> {
+ self.stage_clips()
+ .into_iter()
+ .map(|clip| {
+ let footprint = self.footprint(clip);
+ StageItemData {
+ id: clip.id.as_str().into(),
+ kind: kind_of(clip),
+ selected: self.selection.iter().any(|id| id == &clip.id),
+ cx: footprint.cx as f32,
+ cy: footprint.cy as f32,
+ w: footprint.w as f32,
+ h: footprint.h as f32,
+ rotation: footprint.rotation as f32,
+ scale: clip.scale as f32,
+ }
+ })
+ .collect()
+ }
+
+ /// The topmost picture under a frame point, skipping locked lanes the
+ /// way a press on the lanes does.
+ fn stage_hit(&self, x: f64, y: f64) -> Option<String> {
+ let frame = self.output_size();
+ self.stage_clips()
+ .into_iter()
+ .rev()
+ .filter(|clip| !self.locked(&clip.track_id))
+ .find(|clip| self.footprint(clip).contains(x, y, frame))
+ .map(|clip| clip.id.clone())
+ }
+
+ /// A press on the stage floor: resolve the selection, then arm a move
+ /// of everything selected that is under the playhead. Empty stage
+ /// clears the selection, as an empty lane does.
+ pub fn stage_pressed(&mut self, x: f32, y: f32, additive: bool) {
+ let (x, y) = (f64::from(x), f64::from(y));
+ let Some(id) = self.stage_hit(x, y) else {
+ if !additive {
+ self.selection.clear();
+ }
+ self.gesture = Gesture::None;
+ return;
+ };
+ let already = self.selection.iter().any(|held| held == &id);
+ if additive {
+ if already {
+ self.selection.retain(|held| held != &id);
+ } else {
+ self.selection.push(id.clone());
+ }
+ } else if !already {
+ self.selection = vec![id.clone()];
+ }
+ if !self.selection.iter().any(|held| held == &id) {
+ self.gesture = Gesture::None;
+ return;
+ }
+ let origins: Vec<StageOrigin> = self
+ .stage_clips()
+ .into_iter()
+ .filter(|clip| {
+ self.selection.iter().any(|held| held == &clip.id) && !self.locked(&clip.track_id)
+ })
+ .map(|clip| StageOrigin {
+ clip: clip.id.clone(),
+ offset_x: clip.offset_x,
+ offset_y: clip.offset_y,
+ })
+ .collect();
+ self.begin_echo();
+ self.gesture = Gesture::StageMove {
+ origins,
+ from: (x, y),
+ };
+ }
+
+ /// A press on a grip of `id`'s box: a corner scales, the handle above
+ /// turns. Both work about the picture's centre, in frame pixels.
+ pub fn stage_grip_pressed(&mut self, id: &str, grip: i32, x: f32, y: f32) {
+ let Some(clip) = self.clip(id).cloned() else {
+ return;
+ };
+ if self.locked(&clip.track_id) {
+ return;
+ }
+ let footprint = self.footprint(&clip);
+ let (width, height) = self.output_size();
+ let centre = (
+ footprint.cx * f64::from(width),
+ footprint.cy * f64::from(height),
+ );
+ let dx = f64::from(x) * f64::from(width) - centre.0;
+ let dy = f64::from(y) * f64::from(height) - centre.1;
+ self.begin_echo();
+ self.gesture = if grip == 4 {
+ Gesture::StageRotate {
+ clip: id.to_owned(),
+ rotation: clip.rotation,
+ centre,
+ from: dy.atan2(dx),
+ }
+ } else {
+ Gesture::StageScale {
+ clip: id.to_owned(),
+ scale: clip.scale,
+ centre,
+ from: dx.hypot(dy).max(1.0),
+ }
+ };
+ }
+
+ /// The pointer moved with a stage gesture live: the echo follows, and
+ /// the monitor composites it.
+ pub fn stage_dragged(&mut self, x: f32, y: f32, snap: bool) {
+ let (x, y) = (f64::from(x), f64::from(y));
+ let (width, height) = self.output_size();
+ let gesture = std::mem::replace(&mut self.gesture, Gesture::None);
+ match &gesture {
+ Gesture::StageMove { origins, from } => {
+ let (mut dx, mut dy) = (x - from.0, y - from.1);
+ if snap {
+ // Shift holds the axis the drag is mostly along, measured
+ // in pixels so a tall frame does not bias it.
+ if (dx * f64::from(width)).abs() >= (dy * f64::from(height)).abs() {
+ dy = 0.0;
+ } else {
+ dx = 0.0;
+ }
+ }
+ for origin in origins {
+ if let Some(clip) = self.echo_clip_mut(&origin.clip) {
+ clip.offset_x = (origin.offset_x + dx).clamp(-1.0, 1.0);
+ clip.offset_y = (origin.offset_y + dy).clamp(-1.0, 1.0);
+ }
+ }
+ }
+ Gesture::StageScale {
+ clip,
+ scale,
+ centre,
+ from,
+ } => {
+ let dx = x * f64::from(width) - centre.0;
+ let dy = y * f64::from(height) - centre.1;
+ let mut next = scale * dx.hypot(dy) / from;
+ if snap {
+ next = (next * 20.0).round() / 20.0;
+ }
+ if let Some(clip) = self.echo_clip_mut(clip) {
+ clip.scale = next.clamp(0.05, 8.0);
+ }
+ }
+ Gesture::StageRotate {
+ clip,
+ rotation,
+ centre,
+ from,
+ } => {
+ let dx = x * f64::from(width) - centre.0;
+ let dy = y * f64::from(height) - centre.1;
+ let swept = (dy.atan2(dx) - from).to_degrees();
+ let mut next = rotation + swept;
+ if snap {
+ next = (next / 15.0).round() * 15.0;
+ }
+ // Kept in the inspector's range, wrapping rather than
+ // stopping: a turn through the bottom carries on.
+ next = (next + 180.0).rem_euclid(360.0) - 180.0;
+ if let Some(clip) = self.echo_clip_mut(clip) {
+ clip.rotation = next;
+ }
+ }
+ _ => {
+ self.gesture = gesture;
+ return;
+ }
+ }
+ self.gesture = gesture;
+ self.request_preview();
+ }
+
+ /// The stage gesture is over: whatever the echo moved becomes one
+ /// transform command per picture, batched when there are several.
+ pub fn stage_released(&mut self) {
+ let gesture = std::mem::replace(&mut self.gesture, Gesture::None);
+ let touched: Vec<String> = match gesture {
+ Gesture::StageMove { origins, .. } => {
+ origins.into_iter().map(|origin| origin.clip).collect()
+ }
+ Gesture::StageScale { clip, .. } | Gesture::StageRotate { clip, .. } => vec![clip],
+ other => {
+ // Not ours to end; a lane gesture is still live.
+ self.gesture = other;
+ return;
+ }
+ };
+ let Some(echo) = self.echo.take() else {
+ return;
+ };
+ let mut commands = Vec::new();
+ for id in touched {
+ let (Some(after), Some(before)) = (
+ echo.active().clip(&id),
+ self.session
+ .as_ref()
+ .and_then(|session| session.project().active().clip(&id)),
+ ) else {
+ continue;
+ };
+ if after.scale != before.scale
+ || after.offset_x != before.offset_x
+ || after.offset_y != before.offset_y
+ || after.rotation != before.rotation
+ {
+ commands.push(Command::SetClipTransform {
+ clip_id: id,
+ scale: Some(after.scale),
+ offset_x: Some(after.offset_x),
+ offset_y: Some(after.offset_y),
+ rotation: Some(after.rotation),
+ });
+ }
+ }
+ match commands.len() {
+ 0 => {
+ // A click that moved nothing: the echo is gone and the
+ // monitor goes back to the document.
+ self.request_preview();
+ }
+ 1 => {
+ self.apply(commands.remove(0));
+ }
+ _ => {
+ self.apply(Command::Batch { commands });
+ }
+ }
+ }
+
// ── edits from menus and the tray ──
/// Split at `at`: every selected clip the instant runs through, or every
@@ -2672,6 +3077,7 @@ impl Studio {
editor.set_preview_duration(self.duration());
editor.set_playing(self.playing);
editor.set_preview_frame(self.preview.clone());
+ sync(&models.stage, self.stage_items());
editor.set_drop(match &self.drop {
Some(plan) => DropData {
@@ -3382,3 +3788,67 @@ impl Studio {
}
}
}
+
+#[cfg(test)]
+mod tests {
+ use super::Footprint;
+
+ const FRAME: (u32, u32) = (1920, 1080);
+
+ /// A fitted 16:9 picture at rest covers the frame exactly.
+ #[test]
+ fn footprint_contains_an_unturned_box() {
+ let box_ = Footprint {
+ cx: 0.5,
+ cy: 0.5,
+ w: 0.5,
+ h: 0.5,
+ rotation: 0.0,
+ };
+ assert!(box_.contains(0.5, 0.5, FRAME));
+ assert!(box_.contains(0.26, 0.26, FRAME));
+ assert!(!box_.contains(0.24, 0.5, FRAME));
+ assert!(!box_.contains(0.5, 0.76, FRAME));
+ }
+
+ /// Turned a quarter, a wide box stands tall: a point that was inside
+ /// along the width is outside, and one above the old top edge is inside.
+ /// The test is in pixels, which is where the turn happens — a fraction
+ /// across is not the same distance as a fraction down.
+ #[test]
+ fn footprint_turns_in_pixels() {
+ let box_ = Footprint {
+ cx: 0.5,
+ cy: 0.5,
+ w: 0.5,
+ h: 0.2,
+ rotation: 90.0,
+ };
+ // Half the width is 480px, half the height 108px. After the turn
+ // the box reaches 480px up and down and 108px either side.
+ assert!(box_.contains(0.5, 0.5 + 400.0 / 1080.0, FRAME));
+ assert!(!box_.contains(0.5, 0.5 + 500.0 / 1080.0, FRAME));
+ assert!(box_.contains(0.5 + 100.0 / 1920.0, 0.5, FRAME));
+ assert!(!box_.contains(0.5 + 120.0 / 1920.0, 0.5, FRAME));
+ }
+
+ /// The turn is clockwise, as the compositor's is. The unturned top-right
+ /// corner sits at (480, -270) from the centre; turned thirty degrees
+ /// clockwise in y-down pixels it lands at about (551, +6) - it has swung
+ /// *down* past the centre line. A point just inside that corner is in
+ /// the box, and its mirror above the line is not; turned the other way
+ /// both answers would flip.
+ #[test]
+ fn footprint_turns_clockwise() {
+ let box_ = Footprint {
+ cx: 0.5,
+ cy: 0.5,
+ w: 0.5,
+ h: 0.5,
+ rotation: 30.0,
+ };
+ let x = 0.5 + 540.0 / 1920.0;
+ assert!(box_.contains(x, 0.5 + 6.0 / 1080.0, FRAME));
+ assert!(!box_.contains(x, 0.5 - 6.0 / 1080.0, FRAME));
+ }
+}
diff --git a/engine/crates/concat/ui/app.slint b/engine/crates/concat/ui/app.slint
index d03f92b7..92ac3de0 100644
--- a/engine/crates/concat/ui/app.slint
+++ b/engine/crates/concat/ui/app.slint
@@ -33,7 +33,8 @@ import { TooltipLayer } from "primitives/tooltip.slint";
import { Workspace } from "workspace/workspace.slint";
import {
ClipData, ClipField, ClipKind, ClipTextField, DropData, SelectedClipData,
- TextAlignment, TimelineTabData, TimelineTool, TrackData, TrackSize,
+ StageItemData, TextAlignment, TimelineTabData, TimelineTool, TrackData,
+ TrackSize,
} from "timeline/model.slint";
// Re-exported so main.rs can reach the globals and the struct.
@@ -42,8 +43,8 @@ export {
DockDivider, DockSide, PaneKind, SeatBox,
EffectData, MediaFilter, MediaItemData, MediaKind,
ClipData, ClipField, ClipKind, ClipTextField, DropData, SelectedClipData,
- TextAlignment, TimelineTabData, TimelineTool, TrackData, TrackSize,
- MenuItemData, MenuRow, ExportData, ExportPhase, ModelData, SettingsData,
+ StageItemData, TextAlignment, TimelineTabData, TimelineTool, TrackData,
+ TrackSize, MenuItemData, MenuRow, ExportData, ExportPhase, ModelData, SettingsData,
RecentProjectData, StartData, SystemFactData, ToastData,
}
diff --git a/engine/crates/concat/ui/editor.slint b/engine/crates/concat/ui/editor.slint
index 0557f3b2..1f02cf76 100644
--- a/engine/crates/concat/ui/editor.slint
+++ b/engine/crates/concat/ui/editor.slint
@@ -8,7 +8,7 @@ import { PaneKind } from "workspace/pane-switcher.slint";
import { MenuItemData } from "primitives/context-menu.slint";
import {
ClipData, ClipField, ClipTextField, DropData, SelectedClipData,
- TimelineTabData, TimelineTool, TrackData, TrackSize,
+ StageItemData, TimelineTabData, TimelineTool, TrackData, TrackSize,
} from "timeline/model.slint";
// Everything the four editor views read and everything they report, in one
@@ -121,6 +121,22 @@ export global Editor {
callback ratio-changed(index: int);
callback quality-changed(index: int);
+ /// Every picture under the playhead, placed as the compositor places it.
+ /// The stage outlines the selected ones and lets them be moved, scaled
+ /// and turned in place; see StageOverlay in the preview pane.
+ in-out property <[StageItemData]> stage-items;
+ /// A press on the stage itself, in fractions of the frame. Rust decides
+ /// what it landed on — a picture starts a move, empty stage clears the
+ /// selection — the way `clip-pressed` does for the lanes.
+ callback stage-pressed(x: float, y: float, additive: bool);
+ /// A press on one of a selected box's grips: 0..3 are its corners,
+ /// clockwise from top-left, and 4 is the rotation handle above it.
+ callback stage-grip-pressed(id: string, grip: int, x: float, y: float);
+ /// The pointer moved with a stage gesture live. `snap` is shift: an axis
+ /// for a move, steps for a scale, fifteen degrees for a turn.
+ callback stage-dragged(x: float, y: float, snap: bool);
+ callback stage-released();
+
// ── the timeline ──
in-out property <[TimelineTabData]> timeline-tabs;
in-out property <int> timeline-current-tab;
diff --git a/engine/crates/concat/ui/timeline/model.slint b/engine/crates/concat/ui/timeline/model.slint
index 8ba1cf34..5ede0574 100644
--- a/engine/crates/concat/ui/timeline/model.slint
+++ b/engine/crates/concat/ui/timeline/model.slint
@@ -213,3 +213,29 @@ export struct SelectedClipData {
line-height: float,
tracking: float,
}
+
+/// One picture under the playhead, as the monitor places it.
+///
+/// Everything is a fraction of the output frame rather than a pixel: the
+/// stage is drawn at whatever size the pane allows, and a box that is 40% of
+/// the frame wide is 40% of the stage wide at every size. Published for every
+/// picture and not only the selected ones, so a press on the stage has a
+/// list to test against — the hit-test itself is Rust's, because a rotated
+/// box is not something a TouchArea can be the shape of.
+export struct StageItemData {
+ id: string,
+ kind: ClipKind,
+ selected: bool,
+ /// The picture's centre, in fractions of the frame's width and height.
+ cx: float,
+ cy: float,
+ /// How much of the frame's width and height the picture covers, before
+ /// rotation. For a title this is an estimate: the engine does not report
+ /// where its glyphs landed.
+ w: float,
+ h: float,
+ /// Clockwise degrees, about the centre.
+ rotation: float,
+ /// The clip's scale, for the readout under the box.
+ scale: float,
+}
diff --git a/engine/crates/concat/ui/workspace/preview-pane.slint b/engine/crates/concat/ui/workspace/preview-pane.slint
index 2be84f98..66bbbf90 100644
--- a/engine/crates/concat/ui/workspace/preview-pane.slint
+++ b/engine/crates/concat/ui/workspace/preview-pane.slint
@@ -9,6 +9,7 @@ import { NumberField } from "../primitives/number-field.slint";
import { Select } from "../primitives/select.slint";
import { Pane, PaneHeader } from "pane.slint";
import { PaneKind, PaneSwitcher } from "pane-switcher.slint";
+import { ClipKind, StageItemData } from "../timeline/model.slint";
// The programme monitor: a header that says what the output is, a stage on a
// sunken viewport, and a transport tray under it in three parts — timecode on
@@ -200,6 +201,284 @@ component RatioPicker inherits Rectangle {
}
}
+// ── the stage's selection ────────────────────────────────────────────────────
+//
+// The selected pictures, outlined where the compositor put them, with a grip
+// at each corner to scale by and one above to turn by. The outline is the
+// accent — lime — because it is a selection, and a selection is the accent
+// everywhere else in the window.
+//
+// The geometry is fractions of the frame all the way from Rust, so the same
+// item draws correctly on a monitor of any size; only here does it meet
+// pixels. Rotation is drawn with `transform-rotation` and the grips are placed by
+// hand at the rotated corners, which is also why they are separate elements
+// and not children of the rotated box: a grip is a small square the pointer
+// has to find, and an unrotated square at a computed position is a thing a
+// TouchArea can be exactly the shape of. A rotated *body* is not, so a press
+// on the body goes to the floor beneath and Rust decides what it landed on.
+
+/// One grip. Sized in pixels, placed at a point the item computed.
+component Grip inherits Rectangle {
+ /// Where its centre is, in the overlay's pixels.
+ in property <length> at-x;
+ in property <length> at-y;
+ /// The overlay's size, to turn a pointer position back into fractions.
+ in property <length> stage-w;
+ in property <length> stage-h;
+ /// True for the rotation handle, which is round.
+ in property <bool> turn;
+ in property <MouseCursor> cursor;
+
+ callback pressed(x: float, y: float);
+ callback dragged(x: float, y: float, snap: bool);
+ callback released();
+
+ property <length> size: root.turn ? 12px : 9px;
+
+ x: root.at-x - self.width / 2;
+ y: root.at-y - self.height / 2;
+ width: root.size;
+ height: root.size;
+ border-radius: root.turn ? self.width / 2 : 1.5px;
+ background: touch.has-hover || touch.pressed ? Theme.accent-hover : Theme.accent;
+ // A dark ring, because the grip lands on footage that may be lime itself.
+ border-width: 1px;
+ border-color: Theme.stage;
+
+ touch := TouchArea {
+ // A hair wider than the drawn grip, so it is easier to find than it
+ // is to see.
+ x: -3px;
+ y: -3px;
+ width: parent.width + 6px;
+ height: parent.height + 6px;
+ mouse-cursor: root.cursor;
+
+ property <bool> live;
+ property <bool> snap;
+
+ // The pointer's position in the overlay: the grip's own place plus
+ // the offset within it. Absolute, not a delta from the press — the
+ // grip follows the echo as it is dragged, and a delta measured against
+ // a moving origin cancels itself out. Same reasoning as the lanes.
+ function px() -> float {
+ return (root.x + self.x + self.mouse-x) / root.stage-w;
+ }
+ function py() -> float {
+ return (root.y + self.y + self.mouse-y) / root.stage-h;
+ }
+
+ pointer-event(event) => {
+ self.snap = event.modifiers.shift;
+ if (event.kind == PointerEventKind.down
+ && event.button == PointerEventButton.left) {
+ self.live = true;
+ root.pressed(self.px(), self.py());
+ } else if (event.kind == PointerEventKind.up
+ || event.kind == PointerEventKind.cancel) {
+ if (self.live) {
+ self.live = false;
+ root.released();
+ }
+ }
+ }
+ moved => {
+ if (self.live) {
+ root.dragged(self.px(), self.py(), self.snap);
+ }
+ }
+ }
+}
+
+/// One selected picture: its outline, its grips and its readout.
+component StageItem inherits Rectangle {
+ in property <StageItemData> item;
+
+ callback grip-pressed(grip: int, x: float, y: float);
+ callback dragged(x: float, y: float, snap: bool);
+ callback released();
+
+ // Fractions to pixels, once.
+ property <length> cx: root.item.cx * root.width;
+ property <length> cy: root.item.cy * root.height;
+ property <length> bw: Math.max(2px, root.item.w * root.width);
+ property <length> bh: Math.max(2px, root.item.h * root.height);
+ property <angle> turn: root.item.rotation * 1deg;
+ property <float> c: Math.cos(root.turn);
+ property <float> s: Math.sin(root.turn);
+ /// How far the rotation handle stands off the top edge.
+ property <length> stem: 22px;
+ /// The half-height of the box's axis-aligned bounds: where a readout can
+ /// sit without the rotated box ever crossing it.
+ property <length> below: (root.bw * Math.abs(root.s) + root.bh * Math.abs(root.c)) / 2;
+
+ // A point in the box's own frame — `lx` across, `ly` down, both from the
+ // centre — turned clockwise and placed. The same forward map the GPU
+ // compositor applies to its quad, so a grip sits on the pixel the corner
+ // was drawn at.
+ pure function px(lx: length, ly: length) -> length {
+ return root.cx + lx * root.c - ly * root.s;
+ }
+ pure function py(lx: length, ly: length) -> length {
+ return root.cy + lx * root.s + ly * root.c;
+ }
+
+ background: transparent;
+
+ // The outline.
+ Rectangle {
+ x: root.cx - self.width / 2;
+ y: root.cy - self.height / 2;
+ width: root.bw;
+ height: root.bh;
+ transform-rotation: root.turn;
+ background: transparent;
+ border-width: 1.5px;
+ border-color: Theme.accent;
+ }
+
+ // The stem the rotation handle hangs off, from the top edge's midpoint.
+ Rectangle {
+ x: root.px(0px, -root.bh / 2 - root.stem / 2) - self.width / 2;
+ y: root.py(0px, -root.bh / 2 - root.stem / 2) - self.height / 2;
+ width: 1.5px;
+ height: root.stem;
+ transform-rotation: root.turn;
+ background: Theme.accent;
+ }
+
+ // The readout, clear of the box on whichever side is down.
+ Rectangle {
+ x: root.cx - self.width / 2;
+ y: root.cy + root.below + 8px;
+ width: readout.preferred-width + 12px;
+ height: 18px;
+ border-radius: Theme.r-sm;
+ background: Theme.accent;
+ readout := Text {
+ x: 6px;
+ width: parent.width - 12px;
+ height: parent.height;
+ text: "\{Math.round(root.item.scale * 100)}% · \{Math.round(root.item.rotation)}°";
+ color: Theme.on-accent;
+ font-family: Theme.font-technical;
+ font-size: Theme.fs-sm;
+ vertical-alignment: center;
+ horizontal-alignment: center;
+ }
+ }
+
+ // The corners, clockwise from top-left, as Rust numbers them.
+ Grip {
+ at-x: root.px(-root.bw / 2, -root.bh / 2);
+ at-y: root.py(-root.bw / 2, -root.bh / 2);
+ stage-w: root.width; stage-h: root.height;
+ cursor: MouseCursor.nwse-resize;
+ pressed(x, y) => { root.grip-pressed(0, x, y); }
+ dragged(x, y, snap) => { root.dragged(x, y, snap); }
+ released => { root.released(); }
+ }
+ Grip {
+ at-x: root.px(root.bw / 2, -root.bh / 2);
+ at-y: root.py(root.bw / 2, -root.bh / 2);
+ stage-w: root.width; stage-h: root.height;
+ cursor: MouseCursor.nesw-resize;
+ pressed(x, y) => { root.grip-pressed(1, x, y); }
+ dragged(x, y, snap) => { root.dragged(x, y, snap); }
+ released => { root.released(); }
+ }
+ Grip {
+ at-x: root.px(root.bw / 2, root.bh / 2);
+ at-y: root.py(root.bw / 2, root.bh / 2);
+ stage-w: root.width; stage-h: root.height;
+ cursor: MouseCursor.nwse-resize;
+ pressed(x, y) => { root.grip-pressed(2, x, y); }
+ dragged(x, y, snap) => { root.dragged(x, y, snap); }
+ released => { root.released(); }
+ }
+ Grip {
+ at-x: root.px(-root.bw / 2, root.bh / 2);
+ at-y: root.py(-root.bw / 2, root.bh / 2);
+ stage-w: root.width; stage-h: root.height;
+ cursor: MouseCursor.nesw-resize;
+ pressed(x, y) => { root.grip-pressed(3, x, y); }
+ dragged(x, y, snap) => { root.dragged(x, y, snap); }
+ released => { root.released(); }
+ }
+
+ // The rotation handle, above the top edge.
+ Grip {
+ turn: true;
+ at-x: root.px(0px, -root.bh / 2 - root.stem);
+ at-y: root.py(0px, -root.bh / 2 - root.stem);
+ stage-w: root.width; stage-h: root.height;
+ cursor: MouseCursor.grab;
+ pressed(x, y) => { root.grip-pressed(4, x, y); }
+ dragged(x, y, snap) => { root.dragged(x, y, snap); }
+ released => { root.released(); }
+ }
+}
+
+/// The layer over the stage: the floor that takes a press on a picture or on
+/// nothing, and one StageItem per selected picture above it.
+component StageOverlay inherits Rectangle {
+ in property <[StageItemData]> items;
+
+ callback pressed(x: float, y: float, additive: bool);
+ callback grip-pressed(id: string, grip: int, x: float, y: float);
+ callback dragged(x: float, y: float, snap: bool);
+ callback released();
+
+ background: transparent;
+
+ // The floor. Every press that no grip took lands here; Rust hit-tests
+ // it against the pictures, rotation and stacking included.
+ floor := TouchArea {
+ property <bool> live;
+ property <bool> snap;
+
+ pointer-event(event) => {
+ self.snap = event.modifiers.shift;
+ if (event.kind == PointerEventKind.down
+ && event.button == PointerEventButton.left) {
+ self.live = true;
+ root.pressed(self.mouse-x / root.width, self.mouse-y / root.height,
+ event.modifiers.shift || event.modifiers.control
+ || event.modifiers.meta);
+ } else if (event.kind == PointerEventKind.up
+ || event.kind == PointerEventKind.cancel) {
+ if (self.live) {
+ self.live = false;
+ root.released();
+ }
+ }
+ }
+ moved => {
+ if (self.live) {
+ root.dragged(self.mouse-x / root.width, self.mouse-y / root.height,
+ self.snap);
+ }
+ }
+ }
+
+ for entry in root.items: Rectangle {
+ x: 0;
+ y: 0;
+ width: root.width;
+ height: root.height;
+ if entry.selected: StageItem {
+ x: 0;
+ y: 0;
+ width: parent.width;
+ height: parent.height;
+ item: entry;
+ grip-pressed(grip, x, y) => { root.grip-pressed(entry.id, grip, x, y); }
+ dragged(x, y, snap) => { root.dragged(x, y, snap); }
+ released => { root.released(); }
+ }
+ }
+}
+
export component PreviewPane inherits Rectangle {
// ── what the output is ───────────────────────────────────────────────
in property <int> output-width: 1920;
@@ -219,6 +498,9 @@ export component PreviewPane inherits Rectangle {
in property <string> clip-name;
/// The decoded frame. Drawn fitted to the stage when there is one.
in property <image> frame;
+ /// Every picture under the playhead, for the selection drawn over the
+ /// frame. See StageOverlay.
+ in property <[StageItemData]> stage-items;
callback play-toggled();
/// Absolute, in seconds.
@@ -228,6 +510,12 @@ export component PreviewPane inherits Rectangle {
callback ratio-changed(index: int);
callback quality-changed(index: int);
+ // The stage's own gestures; see the Editor global for what each means.
+ callback stage-pressed(x: float, y: float, additive: bool);
+ callback stage-grip-pressed(id: string, grip: int, x: float, y: float);
+ callback stage-dragged(x: float, y: float, snap: bool);
+ callback stage-released();
+
/// The corner button: show something else in this pane's seat.
callback pane-picked(kind: PaneKind);
/// Which seat this pane is in. It travels no further than the corner
@@ -371,6 +659,21 @@ export component PreviewPane inherits Rectangle {
overflow: elide;
}
}
+
+ // The selection, over the stage and the same size as it. A
+ // sibling rather than a child because the stage clips, and a grip
+ // sits half outside the edge it belongs to.
+ StageOverlay {
+ x: stage.x;
+ y: stage.y;
+ width: stage.width;
+ height: stage.height;
+ items: root.stage-items;
+ pressed(x, y, additive) => { root.stage-pressed(x, y, additive); }
+ grip-pressed(id, grip, x, y) => { root.stage-grip-pressed(id, grip, x, y); }
+ dragged(x, y, snap) => { root.stage-dragged(x, y, snap); }
+ released => { root.stage-released(); }
+ }
}
// ── the transport ────────────────────────────────────────────────
diff --git a/engine/crates/concat/ui/workspace/seat.slint b/engine/crates/concat/ui/workspace/seat.slint
index f1b2c419..e61837e5 100644
--- a/engine/crates/concat/ui/workspace/seat.slint
+++ b/engine/crates/concat/ui/workspace/seat.slint
@@ -140,12 +140,19 @@ export component Seat inherits Rectangle {
has-picture: Editor.has-picture;
clip-name: Editor.preview-clip-name;
frame: Editor.preview-frame;
+ stage-items: Editor.stage-items;
play-toggled => { Editor.play-toggled(); }
seek(seconds) => { Editor.seek(seconds); }
step(frames) => { Editor.step-frames(frames); }
ratio-changed(index) => { Editor.ratio-changed(index); }
quality-changed(index) => { Editor.quality-changed(index); }
+ stage-pressed(x, y, additive) => { Editor.stage-pressed(x, y, additive); }
+ stage-grip-pressed(id, grip, x, y) => {
+ Editor.stage-grip-pressed(id, grip, x, y);
+ }
+ stage-dragged(x, y, snap) => { Editor.stage-dragged(x, y, snap); }
+ stage-released => { Editor.stage-released(); }
}
if root.kind == PaneKind.inspector: ConfigPane {