From a1cea17257cf6a702444e7b932b7a4a6ae09e4d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Kaan=20G=C3=BCm=C3=BC=C5=9F?= Date: Thu, 20 Aug 2026 03:41:04 +0300 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20wip(app):=20the=20transform=20ca?= =?UTF-8?q?rd=20compiles?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/app/src/keymap.rs | 13 ++- crates/app/src/main.rs | 25 +++++ crates/app/src/player/actions.rs | 2 + crates/app/src/player/cards.rs | 128 +++++++++++++++++++++++ crates/app/src/player/library.rs | 6 ++ crates/app/src/player/timeline_edit.rs | 15 +++ crates/app/src/render.rs | 23 ++++ crates/app/src/transform_ui.rs | 108 +++++++++++++++++++ crates/app/src/ui/cards.rs | 139 +++++++++++++++++++++++++ crates/app/src/ui/inspector.rs | 1 + crates/engine/src/playback.rs | 30 ++++++ 11 files changed, 489 insertions(+), 1 deletion(-) create mode 100644 crates/app/src/transform_ui.rs diff --git a/crates/app/src/keymap.rs b/crates/app/src/keymap.rs index 5020786..71b200b 100644 --- a/crates/app/src/keymap.rs +++ b/crates/app/src/keymap.rs @@ -106,6 +106,10 @@ actions! { Delete, Lift, Color, + /// Where a clip sits, how big and which way up + /// ([`crate::transform_ui::TRANSFORM_BANDS`]) -- the geometry twin of + /// [`ActionId::Color`], filed right beside it. + Transform, Fit, Resolution, ZoomIn, @@ -209,6 +213,7 @@ impl ActionId { ActionId::Delete => "Delete", ActionId::Lift => "Lift (leave a gap)", ActionId::Color => "Colour…", + ActionId::Transform => "Transform — position, scale, rotation, crop", ActionId::Fit => "Fit policy: fit → fill → stretch → centre", ActionId::Resolution => "Project resolution: source → 2160p → 1080p → 720p → 480p", ActionId::ZoomIn => "Zoom in on the timeline (around the playhead)", @@ -277,6 +282,7 @@ impl ActionId { ActionId::Delete => "delete", ActionId::Lift => "lift", ActionId::Color => "color", + ActionId::Transform => "transform", ActionId::Fit => "fit", ActionId::Resolution => "resolution", ActionId::ZoomIn => "zoom-in", @@ -344,6 +350,7 @@ impl ActionId { | ActionId::Delete | ActionId::Lift | ActionId::Color + | ActionId::Transform | ActionId::Fit // A rate is the clip's, not the sound's: it re-times the picture // and the sound together, and the card opens on whichever half was @@ -903,6 +910,10 @@ impl Keymap { // k: free, next to nothing that edits, and one press like the // rest of the clip keys. b(ActionId::Color, "k", false), + // The placement card takes the ctrl chord of the grade's own + // key: the two sit beside each other on a clip and neither + // steals a bare letter that already means something else. + b(ActionId::Transform, "k", true), // The fit policy is a clip key like the grade beside it: "p" for // policy, free, and one press like the rest of them. The project // resolution is not a clip key and takes a ctrl chord, next to @@ -1290,7 +1301,7 @@ mod tests { #[test] fn every_default_stroke_reaches_its_action() { let k = Keymap::defaults(); - assert_eq!(k.entries().len(), 63); + assert_eq!(k.entries().len(), 64); assert_eq!(k.lookup("f11", false), Some(ActionId::Fullscreen)); assert_eq!(k.lookup("w", false), Some(ActionId::Screenshot)); assert_eq!(k.lookup("y", false), Some(ActionId::SubtitleStyle)); diff --git a/crates/app/src/main.rs b/crates/app/src/main.rs index 4f6d7b3..fd986fa 100644 --- a/crates/app/src/main.rs +++ b/crates/app/src/main.rs @@ -17,6 +17,7 @@ mod oracle; mod render; mod subs; mod timeline_math; +mod transform_ui; mod transport; mod viewport; @@ -37,6 +38,7 @@ pub(crate) use notices::*; pub(crate) use oracle::*; pub(crate) use subs::*; pub(crate) use timeline_math::*; +pub(crate) use transform_ui::*; pub(crate) use transport::*; pub(crate) use viewport::*; @@ -62,6 +64,7 @@ use engine::limiter::Limiter; use engine::project::{Edge, Lane, LaneKind, Source, Speed, SubClip}; use engine::scale::FitPolicy; use engine::tonemap::Preset; +use engine::transform::TransformParams; use engine::{Clip, Codec, ExportHandle, Frame, MediaBitrate, PlaybackSession}; use gpui::{ AnyElement, App, Application, Bounds, ClickEvent, Context, CursorStyle, Div, DragMoveEvent, @@ -663,6 +666,23 @@ struct Player { /// stands, and never lost -- the frame that lands writes it, and so does the /// release. pending_color: Option, + /// The transform card is up on this clip -- the lane it is on and its + /// index there, exactly as the colour card's handle is. `None` when it is + /// closed: the placement itself is the project's. + transform_open: Option<(Lane, usize)>, + /// Which of the card's eight sliders the arrow keys and a drag move. The + /// card's own focus, since nothing in it takes gpui's (ledger:182). + transform_band: usize, + /// A slider is being dragged. Tracked on the root like the colour card's, + /// for the same reason: a 4 px bar is left by the pointer on the first + /// move and its own listeners then stop firing. + transform_dragging: bool, + /// Each slider's box, recorded at prepaint -- [`Self::color_bars`]' own + /// reason, one per band. + transform_bars: [Rc>>; TRANSFORM_BANDS.len()], + /// The placement the hand is on, held back because the worker still owes a + /// frame -- [`Self::pending_color`]'s own reason. + pending_transform: Option, /// The frame on screen counted into `HIST_BINS` bins per channel -- the /// *graded* frame, because the grade is applied in the decode worker and /// what arrives here is already through it. Refilled by every pumped frame, @@ -910,6 +930,11 @@ fn main() { color_dragging: false, color_bars: std::array::from_fn(|_| Rc::default()), pending_color: None, + transform_open: None, + transform_band: 0, + transform_dragging: false, + transform_bars: std::array::from_fn(|_| Rc::default()), + pending_transform: None, // Empty until the first frame is pumped, which draws as a // flat line rather than as a shape nothing measured. histogram: [[0; HIST_BINS]; 3], diff --git a/crates/app/src/player/actions.rs b/crates/app/src/player/actions.rs index 59d0753..d0d3364 100644 --- a/crates/app/src/player/actions.rs +++ b/crates/app/src/player/actions.rs @@ -101,6 +101,7 @@ impl Player { ActionId::Delete => self.delete_selected(cx), ActionId::Lift => self.lift_selected(cx), ActionId::Color => self.open_color(cx), + ActionId::Transform => self.open_transform(cx), ActionId::Fit => self.cycle_fit(cx), ActionId::Resolution => self.cycle_resolution(cx), // The playhead is what a key zoom is aimed at: it is the one place @@ -377,6 +378,7 @@ impl Player { Repeat::Nothing } else if self.eq_open.is_some() || self.color_open.is_some() + || self.transform_open.is_some() || self.speed_open.is_some() || self.silence_open.is_some() || self.mix_open diff --git a/crates/app/src/player/cards.rs b/crates/app/src/player/cards.rs index 167d598..8c1896d 100644 --- a/crates/app/src/player/cards.rs +++ b/crates/app/src/player/cards.rs @@ -383,6 +383,132 @@ impl Player { } } + /// Opens the transform card on the clip a placement would go on -- + /// [`open_color`](Self::open_color)'s own rule, since it targets the same + /// clip a grade would. + pub(crate) fn open_transform(&mut self, cx: &mut Context) { + if self.exporting().is_some() { + return; + } + let Some(session) = &self.session else { + self.notify_user("no timeline to place — open a file first".into()); + cx.notify(); + return; + }; + let target = match self.selected.anchor() { + Some((lane, idx)) if lane.kind == LaneKind::Subtitle => { + match caption_media_half(session, (lane, idx), LaneKind::Video) { + Some(half) => Some(half), + None => { + self.notify_user( + "NOTHING TO PLACE — a caption has no picture; group it with a clip \ + first (ctrl-click both, then Group)" + .into(), + ); + cx.notify(); + return; + } + } + } + Some((lane, _)) if lane.kind == LaneKind::Audio => session.video_clip_at(session.now()), + other => other.or_else(|| session.video_clip_at(session.now())), + }; + match target { + Some(clip) => { + self.transform_open = Some(clip); + self.transform_band = 0; + self.transform_dragging = false; + self.pending_transform = None; + self.keys_open = false; + self.export_open = false; + self.context_menu = None; + } + None => self.notify_user("no clip under the playhead to place".into()), + } + cx.notify(); + } + + /// What the card's clip is placed by right now -- [`color_params`](Self::color_params)'s + /// own rule. + pub(crate) fn transform_params(&self) -> TransformParams { + if let Some(params) = self.pending_transform { + return params; + } + self.transform_open + .zip(self.session.as_ref()) + .and_then(|((lane, idx), session)| session.transform_of(lane, idx).copied()) + .unwrap_or_default() + } + + /// Puts `params` on the card's clip, or takes the placement off when they + /// are the identity -- [`set_color`](Self::set_color)'s own rule. + pub(crate) fn set_transform(&mut self, params: TransformParams, cx: &mut Context) { + self.write_transform(params, false, cx); + } + + /// Both writes: `live` is the one that takes no undo step, which is what + /// every sample *inside* a drag goes through -- + /// [`write_color`](Self::write_color)'s own rule. + pub(crate) fn write_transform(&mut self, params: TransformParams, live: bool, cx: &mut Context) { + self.pending_transform = None; + let Some((lane, idx)) = self.transform_open else { + return; + }; + let Some(session) = &mut self.session else { + return; + }; + let placement = Some(params).filter(|p| !p.is_identity()); + let took = match live { + true => session.set_transform_live(lane, idx, placement), + false => session.set_transform(lane, idx, placement), + }; + if took { + self.mark_dirty(); + self.reset_after_reseek(); + } + cx.notify(); + } + + /// Moves the picked slider by `steps` -- [`nudge_color`](Self::nudge_color)'s + /// own rule, except rotation wraps into its range on + /// [`transform_snap`] instead of clamping. + pub(crate) fn nudge_transform(&mut self, steps: f32, cx: &mut Context) { + let mut params = self.transform_params(); + let (_, low, high) = TRANSFORM_BANDS[self.transform_band]; + let step = if self.transform_band == ROTATE_BAND { + ROTATE_STEP + } else { + TRANSFORM_STEP + }; + let value = transform_band_mut(&mut params, self.transform_band); + let raw = *value + steps * step; + *value = if self.transform_band == ROTATE_BAND { + transform_snap(self.transform_band, raw) + } else { + raw.clamp(low, high) + }; + self.set_transform(params, cx); + } + + /// Where the pointer sits along a slider, as that band's value -- + /// [`drag_color`](Self::drag_color)'s own rule. + pub(crate) fn drag_transform(&mut self, x: Pixels, first: bool, cx: &mut Context) { + let (_, low, high) = TRANSFORM_BANDS[self.transform_band]; + let along = frac_along(x, self.transform_bars[self.transform_band].get()); + let value = transform_snap(self.transform_band, low + along * (high - low)); + let mut params = self.transform_params(); + let at = transform_band_mut(&mut params, self.transform_band); + if *at == value && !first { + return; + } + *at = value; + let busy = self.seek_since.is_some(); + match stash_or_write(&mut self.pending_transform, params, first, busy) { + Some(params) => self.write_transform(params, !first, cx), + None => cx.notify(), + } + } + /// Opens the speed card on the clip whose rate is to change: the selected /// one, or -- with nothing selected -- the clip the picture is coming from, /// which is what a person means by "this shot". Either half of a take will @@ -1132,6 +1258,7 @@ impl Player { || self.export_open || self.eq_open.is_some() || self.color_open.is_some() + || self.transform_open.is_some() || self.speed_open.is_some() || self.silence_open.is_some() || self.mix_open @@ -1159,6 +1286,7 @@ impl Player { self.eq_open = None; self.eq_dragging = false; self.color_open = None; + self.transform_open = None; self.speed_open = None; // Marks and a running scan go with this one, which is why it is a call // and not an assignment ([`Player::close_silence`]). diff --git a/crates/app/src/player/library.rs b/crates/app/src/player/library.rs index 23434ac..4cd54d0 100644 --- a/crates/app/src/player/library.rs +++ b/crates/app/src/player/library.rs @@ -168,6 +168,7 @@ impl Player { self.library_menu = None; self.eq_open = None; self.color_open = None; + self.transform_open = None; self.speed_open = None; self.close_silence(); self.waves.clear(); @@ -196,6 +197,8 @@ impl Player { self.speed_dragging = false; self.color_dragging = false; self.pending_color = None; + self.transform_dragging = false; + self.pending_transform = None; self.pending_speed = None; self.displayed = 0; self.dropped = 0; @@ -1279,6 +1282,7 @@ impl Player { self.context_menu = None; self.eq_open = None; self.color_open = None; + self.transform_open = None; // Marks are timeline frames of the timeline that was. self.close_silence(); // A different set of sources: the row that was picked is not @@ -1541,6 +1545,7 @@ impl Player { self.context_menu = None; self.eq_open = None; self.color_open = None; + self.transform_open = None; self.speed_open = None; self.close_silence(); // The shown lane with them: a `Lane` is a position among @@ -1599,6 +1604,7 @@ impl Player { self.context_menu = None; self.eq_open = None; self.color_open = None; + self.transform_open = None; self.speed_open = None; self.close_silence(); // The shown lane with them: a `Lane` is a position among its diff --git a/crates/app/src/player/timeline_edit.rs b/crates/app/src/player/timeline_edit.rs index 6191576..2faeb70 100644 --- a/crates/app/src/player/timeline_edit.rs +++ b/crates/app/src/player/timeline_edit.rs @@ -1554,6 +1554,16 @@ impl Player { } return; } + // The transform card's sliders, [`Self::color_dragging`]'s own reason. + if self.transform_dragging { + if event.pressed_button == Some(MouseButton::Left) { + self.drag_transform(event.position.x, false, cx); + } else { + self.transform_dragging = false; + self.flush_drag(cx); + } + return; + } // The speed bar, the same 4 px and the same live writes: the // press took the undo step and every sample since is live. if self.speed_dragging { @@ -1652,6 +1662,11 @@ impl Player { self.flush_drag(cx); return; } + if std::mem::take(&mut self.transform_dragging) { + self.drag_transform(event.position.x, false, cx); + self.flush_drag(cx); + return; + } if std::mem::take(&mut self.speed_dragging) { self.drag_speed(event.position.x, false, cx); self.flush_drag(cx); diff --git a/crates/app/src/render.rs b/crates/app/src/render.rs index 3ac6491..38c5154 100644 --- a/crates/app/src/render.rs +++ b/crates/app/src/render.rs @@ -476,6 +476,29 @@ impl Render for Player { cx.notify(); return; } + // The transform card, the same way again: the arrows pick a + // slider and move it, and `r` puts the placement back to + // identity. Card-local, [`ActionId::Color`]'s own reason (see + // `FIXED`, where the keys menu still lists them). + if this.transform_open.is_some() { + let n = TRANSFORM_BANDS.len(); + if key == ESCAPE { + this.transform_open = None; + this.transform_dragging = false; + } else if key == "down" { + this.transform_band = (this.transform_band + 1) % n; + } else if key == "up" { + this.transform_band = (this.transform_band + n - 1) % n; + } else if key == "right" { + this.nudge_transform(1., cx); + } else if key == "left" { + this.nudge_transform(-1., cx); + } else if key == "r" { + this.set_transform(TransformParams::default(), cx); + } + cx.notify(); + return; + } // The speed card, the same way again: its arrows move the rate // and `r` puts it back to real time, and neither means anything // outside the card -- so neither is a binding (see `FIXED`, diff --git a/crates/app/src/transform_ui.rs b/crates/app/src/transform_ui.rs new file mode 100644 index 0000000..60dddaf --- /dev/null +++ b/crates/app/src/transform_ui.rs @@ -0,0 +1,108 @@ +//! The transform card's numbers -- [`crate::color_ui`]'s twin for where a +//! clip sits instead of what it looks like. + +use crate::*; + +/// The transform card's eight controls, in the order it lists them: what each +/// is called and the range it moves in. The order is `TransformParams`' own, +/// which is what [`transform_band_mut`] indexes. Rotation's range is one turn +/// short (`0..270`) because 360 is the same picture as 0 and a slider with two +/// ends that read the same is not a range, it is a cycle +/// ([`ROTATE_BAND`]/[`rotate_key`]). +pub(crate) const TRANSFORM_BANDS: [(&str, f32, f32); 8] = [ + ("Position X", -1., 1.), + ("Position Y", -1., 1.), + ("Scale", 0.1, 4.), + ("Rotation", 0., 270.), + ("Crop left", 0., 0.45), + ("Crop right", 0., 0.45), + ("Crop top", 0., 0.45), + ("Crop bottom", 0., 0.45), +]; + +/// Which band is rotation: the one control on the card that wraps at its ends +/// instead of clamping, and steps by [`ROTATE_STEP`] rather than +/// [`TRANSFORM_STEP`] -- the engine only ever renders a 90-degree turn +/// ([`crate::transform::TransformParams::rotate`]), so a finer grid on this +/// one row would be numbers nothing on screen answers to. +pub(crate) const ROTATE_BAND: usize = 3; + +/// A press of a nudge key on every band but rotation: a fortieth-ish of a +/// band's range, [`crate::color_ui::COLOR_STEP`]'s own reason. A drag lands on +/// the same grid ([`Player::drag_transform`]). +pub(crate) const TRANSFORM_STEP: f32 = 0.05; + +/// Rotation's own step: one 90-degree turn, [`ROTATE_BAND`]'s reason. +pub(crate) const ROTATE_STEP: f32 = 90.; + +/// The card's width, [`crate::color_ui::COLOR_W`]'s own measure against this +/// card's longest label ("Position X" is short, but the value column is wider +/// here for the crop rows' extra digit). +pub(crate) const TRANSFORM_W: f32 = 460.; +/// How much of a slider row the bar itself gets, [`crate::color_ui::COLOR_BAR_W`]. +pub(crate) const TRANSFORM_BAR_W: f32 = 240.; + +/// A slider value on the band's own grid: [`ROTATE_BAND`] snaps to +/// [`ROTATE_STEP`] and wraps into its range, every other band snaps to +/// [`TRANSFORM_STEP`] and clamps into its own -- what a drag rounds to, so the +/// pointer stops where the arrow keys do. +pub(crate) fn transform_snap(band: usize, value: f32) -> f32 { + let (_, low, high) = TRANSFORM_BANDS[band]; + if band == ROTATE_BAND { + let span = high - low + ROTATE_STEP; // one turn: 0..360 + let wrapped = (value - low).rem_euclid(span); + low + (wrapped / ROTATE_STEP).round() * ROTATE_STEP + } else { + ((value / TRANSFORM_STEP).round() * TRANSFORM_STEP).clamp(low, high) + } +} + +/// The band'th control of a placement, to read or to write. The order is +/// [`TRANSFORM_BANDS`]', which is the order the card lists them in -- +/// [`crate::export_ui::band_mut`]'s own twin. +pub(crate) fn transform_band_mut(params: &mut TransformParams, band: usize) -> &mut f32 { + match band { + 0 => &mut params.pos_x, + 1 => &mut params.pos_y, + 2 => &mut params.scale, + 3 => &mut params.rotate, + 4 => &mut params.crop_l, + 5 => &mut params.crop_r, + 6 => &mut params.crop_t, + _ => &mut params.crop_b, + } +} + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn ordinary_bands_snap_to_the_step_and_clamp() { + assert_eq!(transform_snap(0, 0.024), 0.0); + assert_eq!(transform_snap(0, 0.026), 0.05); + assert_eq!(transform_snap(0, 5.0), 1.0); // clamped to Position X's high + assert_eq!(transform_snap(0, -5.0), -1.0); + } + + #[test] + fn rotation_snaps_to_ninety_and_wraps() { + assert_eq!(transform_snap(ROTATE_BAND, 44.0), 0.0); + assert_eq!(transform_snap(ROTATE_BAND, 46.0), 90.0); + assert_eq!(transform_snap(ROTATE_BAND, 270.0), 270.0); + // Past the last stop wraps back to the first, not clamps to the last. + assert_eq!(transform_snap(ROTATE_BAND, 315.0), 0.0); + assert_eq!(transform_snap(ROTATE_BAND, -45.0), 270.0); + } + + #[test] + fn transform_band_mut_indexes_in_bands_order() { + let mut p = TransformParams::default(); + *transform_band_mut(&mut p, 0) = 0.1; + *transform_band_mut(&mut p, 3) = 90.; + *transform_band_mut(&mut p, 7) = 0.2; + assert_eq!(p.pos_x, 0.1); + assert_eq!(p.rotate, 90.); + assert_eq!(p.crop_b, 0.2); + } +} diff --git a/crates/app/src/ui/cards.rs b/crates/app/src/ui/cards.rs index 0547183..a979b32 100644 --- a/crates/app/src/ui/cards.rs +++ b/crates/app/src/ui/cards.rs @@ -1523,6 +1523,145 @@ impl Player { ) } + /// The transform card: [`color_card`](Self::color_card)'s own shape, one + /// row per [`TRANSFORM_BANDS`] entry instead of four, and no histogram -- + /// there is nothing here a graded frame would tilt. + pub(crate) fn transform_card(&self, cx: &mut Context) -> Option { + let (lane, idx) = self.transform_open?; + let params = self.transform_params(); + let rows: Vec<_> = TRANSFORM_BANDS + .iter() + .enumerate() + .map(|(i, &(label, low, high))| { + let mut read = params; + let value = *transform_band_mut(&mut read, i); + let frac = ((value - low) / (high - low)).clamp(0., 1.); + let picked = i == self.transform_band; + div() + .id(("transform-row", i)) + .flex() + .min_h(px(KEYS_ROW_H)) + .items_center() + .gap(px(8.)) + .px(px(6.)) + .rounded(px(3.)) + .cursor_pointer() + .when(picked, |d| d.bg(rgb(BG_SELECTED()))) + .hover(|s| s.bg(rgb(BG_HOVER()))) + .on_click(cx.listener(move |this, _: &ClickEvent, _, cx| { + this.transform_band = i; + cx.notify(); + })) + .child(div().flex_1().min_w(px(0.)).truncate().child(label)) + .child( + div() + .id(("transform-bar", i)) + .relative() + .flex_1() + .min_w(px(0.)) + .max_w(px(TRANSFORM_BAR_W)) + .h(px(KEYS_ROW_H)) + .flex() + .items_center() + .on_mouse_down( + MouseButton::Left, + cx.listener(move |this, event: &MouseDownEvent, _, cx| { + this.transform_band = i; + this.transform_dragging = true; + this.drag_transform(event.position.x, true, cx); + }), + ) + .child(bounds_probe(self.transform_bars[i].clone())) + .child( + div() + .w_full() + .h(px(4.)) + .rounded(px(2.)) + .bg(rgb(BG_PANEL())) + .child( + div() + .h_full() + .w(relative(frac)) + .rounded(px(2.)) + .bg(rgb(ACCENT_PRIMARY())), + ), + ), + ) + .child( + div() + .w(px(44.)) + .text_size(px(11.)) + .text_color(rgb(FG_SECONDARY())) + .child(match i == ROTATE_BAND { + true => format!("{value:.0}°"), + false => format!("{value:.2}"), + }), + ) + }) + .collect(); + Some( + drag_scrim(cx) + .flex() + .justify_center() + .items_center() + .bg(rgba(SCRIM())) + .on_mouse_down( + MouseButton::Left, + cx.listener(|this, _: &MouseDownEvent, _, cx| { + this.close_card(); + cx.notify(); + cx.stop_propagation(); + }), + ) + .child( + div() + .w_full() + .max_w(px(TRANSFORM_W)) + .on_mouse_down(MouseButton::Left, swallow) + .flex() + .flex_col() + .gap(px(2.)) + .p(px(12.)) + .rounded(px(6.)) + .bg(rgb(BG_RAISED())) + .child(div().flex_none().px(px(6.)).child(format!( + "Transform — {} clip {}", + lane.label(), + idx + 1 + ))) + .child( + div() + .flex_none() + .px(px(6.)) + .text_size(px(11.)) + .text_color(rgb(FG_SECONDARY())) + .child( + "drag a bar, or ↑↓ picks one and ←→ moves it (rotation steps \ + by 90°), r resets — a click away or esc closes", + ), + ) + .children(rows) + .child( + div() + .id("transform-reset") + .mt(px(4.)) + .flex() + .h(px(CONTROL_H)) + .items_center() + .justify_center() + .rounded(px(3.)) + .bg(rgb(BG_SELECTED())) + .cursor_pointer() + .hover(|s| s.bg(rgb(BG_HOVER()))) + .on_click(cx.listener(|this, _: &ClickEvent, _, cx| { + this.set_transform(TransformParams::default(), cx); + })) + .child("Reset"), + ), + ), + ) + } + /// The speed card: one bar from a quarter speed to four times it, the rates /// people name as buttons under it, and the clip's new length in frames -- /// which is the number a person is actually choosing. Built like the colour diff --git a/crates/app/src/ui/inspector.rs b/crates/app/src/ui/inspector.rs index f31866b..2717ef1 100644 --- a/crates/app/src/ui/inspector.rs +++ b/crates/app/src/ui/inspector.rs @@ -81,6 +81,7 @@ impl Player { }) .children(self.eq_card(room, cx)) .children(self.color_card(cx)) + .children(self.transform_card(cx)) .children(self.speed_card(cx)) .children(self.silence_card(cx)) .children(self.mix_card(cx)) diff --git a/crates/engine/src/playback.rs b/crates/engine/src/playback.rs index bff510a..0a6b1b8 100644 --- a/crates/engine/src/playback.rs +++ b/crates/engine/src/playback.rs @@ -2603,6 +2603,36 @@ impl PlaybackSession { self.edit(Dirty::Picture, |p| p.set_color_live(lane, idx, params)) } + /// Where the clip at `idx` of `lane` is placed -- [`color_of`](Self::color_of)'s + /// twin for geometry instead of grade. + pub fn transform_of(&self, lane: Lane, idx: usize) -> Option<&TransformParams> { + self.project.transform_of(lane, idx) + } + + /// Moves/scales/rotates/crops that clip, or takes the placement off with + /// `None` -- [`set_color`](Self::set_color)'s twin, one undo step and one + /// reseek. + pub fn set_transform( + &mut self, + lane: Lane, + idx: usize, + params: Option, + ) -> bool { + self.edit(Dirty::Picture, |p| p.set_transform(lane, idx, params)) + } + + /// The same placement and the same reseek without the undo step + /// ([`Project::set_transform_live`]) -- [`set_color_live`](Self::set_color_live)'s + /// twin for a slider drag. + pub fn set_transform_live( + &mut self, + lane: Lane, + idx: usize, + params: Option, + ) -> bool { + self.edit(Dirty::Picture, |p| p.set_transform_live(lane, idx, params)) + } + /// The project's resolution: what every clip is composed onto, what the /// window is sized to and what an export writes -- *not* any one file's. /// It starts as source 0's picture, which is what a project meant before it