A transform card moves, scales, rotates and crops a clip (ctrl+k)
Browse files at this commit85d392819aa905ed8a1ce0c313c200b9c98e8a20Parent: a1cea17- feat
- a transform card moves, scales, rotates and crops a clip (ctrl+k)
5 changed files +41 -5
- crates/app/src/keymap.rs +22 -1
- crates/app/src/menus.rs +2 -1
- crates/app/src/oracle.rs +1 -1
- crates/app/src/transform_ui.rs +6 -2
- crates/app/src/ui/inspector.rs +10 -0
crates/app/src/keymap.rsmodified+22 -1
| @@ -527,7 +527,7 @@ fn preset_chord() -> String { | |||
| 527 | .join(" / ") | 527 | .join(" / ") |
| 528 | } | 528 | } |
| 529 | 529 | ||
| 530 | -pub static FIXED: std::sync::LazyLock<[Fixed; 32]> = std::sync::LazyLock::new(|| { | 530 | +pub static FIXED: std::sync::LazyLock<[Fixed; 35]> = std::sync::LazyLock::new(|| { |
| 531 | [ | 531 | [ |
| 532 | // Not a chord at all but a way of pressing one, and the only place the | 532 | // Not a chord at all but a way of pressing one, and the only place the |
| 533 | // editor can say so: holding a key that moves a *value* runs it, and | 533 | // editor can say so: holding a key that moves a *value* runs it, and |
| @@ -725,6 +725,27 @@ pub static FIXED: std::sync::LazyLock<[Fixed; 32]> = std::sync::LazyLock::new(|| | |||
| 725 | category: Category::Clips, | 725 | category: Category::Clips, |
| 726 | reach: Reach::Click("color-reset"), | 726 | reach: Reach::Click("color-reset"), |
| 727 | }, | 727 | }, |
| 728 | + // The transform card's own three, the same shape as the colour card's: | ||
| 729 | + // up/down pick a band (position, scale, rotate, crop), left/right move | ||
| 730 | + // it, and `r` resets to identity. | ||
| 731 | + Fixed { | ||
| 732 | + chord: "↑ / ↓".into(), | ||
| 733 | + label: "Pick a transform band", | ||
| 734 | + category: Category::Clips, | ||
| 735 | + reach: Reach::Click("transform-row"), | ||
| 736 | + }, | ||
| 737 | + Fixed { | ||
| 738 | + chord: "← / →".into(), | ||
| 739 | + label: "Move the picked transform band", | ||
| 740 | + category: Category::Clips, | ||
| 741 | + reach: Reach::Click("transform-bar"), | ||
| 742 | + }, | ||
| 743 | + Fixed { | ||
| 744 | + chord: "r".into(), | ||
| 745 | + label: "Take the transform off the clip", | ||
| 746 | + category: Category::Clips, | ||
| 747 | + reach: Reach::Click("transform-reset"), | ||
| 748 | + }, | ||
| 728 | // The silence card's two apply keys. Card-local like every stroke above -- | 749 | // The silence card's two apply keys. Card-local like every stroke above -- |
| 729 | // they mean nothing while it is closed -- but the card is the one place in | 750 | // they mean nothing while it is closed -- but the card is the one place in |
| 730 | // this editor where a key rewrites forty places at once, so both of them | 751 | // this editor where a key rewrites forty places at once, so both of them |
crates/app/src/menus.rsmodified+2 -1
| @@ -142,7 +142,7 @@ impl RowItem { | |||
| 142 | /// action a stroke already reaches -- the menu is a second way *to* the actions | 142 | /// action a stroke already reaches -- the menu is a second way *to* the actions |
| 143 | /// and never a second version of them -- so both the label and the hint come | 143 | /// and never a second version of them -- so both the label and the hint come |
| 144 | /// out of the keymap registry and the two can never disagree. | 144 | /// out of the keymap registry and the two can never disagree. |
| 145 | -pub(crate) const MENU_ITEMS: [ActionId; 15] = [ | 145 | +pub(crate) const MENU_ITEMS: [ActionId; 16] = [ |
| 146 | ActionId::Cut, | 146 | ActionId::Cut, |
| 147 | // The clipboard pair, which had no door but a chord: copy takes the clip the | 147 | // The clipboard pair, which had no door but a chord: copy takes the clip the |
| 148 | // menu names, and paste is the timeline's rather than this clip's -- the | 148 | // menu names, and paste is the timeline's rather than this clip's -- the |
| @@ -165,6 +165,7 @@ pub(crate) const MENU_ITEMS: [ActionId; 15] = [ | |||
| 165 | // whichever half was clicked. | 165 | // whichever half was clicked. |
| 166 | ActionId::Dissolve, | 166 | ActionId::Dissolve, |
| 167 | ActionId::Color, | 167 | ActionId::Color, |
| 168 | + ActionId::Transform, | ||
| 168 | ActionId::Fit, | 169 | ActionId::Fit, |
| 169 | ActionId::ToggleMute, | 170 | ActionId::ToggleMute, |
| 170 | ]; | 171 | ]; |
crates/app/src/oracle.rsmodified+1 -1
| @@ -187,7 +187,7 @@ pub(crate) fn enable(action: ActionId, ctx: Ctx) -> Enable { | |||
| 187 | }, | 187 | }, |
| 188 | // A grade is a picture setting and an audio clip has no picture. A fit | 188 | // A grade is a picture setting and an audio clip has no picture. A fit |
| 189 | // policy is a picture setting for the same reason. | 189 | // policy is a picture setting for the same reason. |
| 190 | - ActionId::Color | ActionId::Fit => match ctx.clip { | 190 | + ActionId::Color | ActionId::Fit | ActionId::Transform => match ctx.clip { |
| 191 | Some((_, lane)) if lane.kind != LaneKind::Video => Enable::Hidden("this clip is sound"), | 191 | Some((_, lane)) if lane.kind != LaneKind::Video => Enable::Hidden("this clip is sound"), |
| 192 | _ => Enable::Yes, | 192 | _ => Enable::Yes, |
| 193 | }, | 193 | }, |
crates/app/src/transform_ui.rsmodified+6 -2
| @@ -51,7 +51,10 @@ pub(crate) fn transform_snap(band: usize, value: f32) -> f32 { | |||
| 51 | if band == ROTATE_BAND { | 51 | if band == ROTATE_BAND { |
| 52 | let span = high - low + ROTATE_STEP; // one turn: 0..360 | 52 | let span = high - low + ROTATE_STEP; // one turn: 0..360 |
| 53 | let wrapped = (value - low).rem_euclid(span); | 53 | let wrapped = (value - low).rem_euclid(span); |
| 54 | - low + (wrapped / ROTATE_STEP).round() * ROTATE_STEP | 54 | + // The round can land exactly on `span` (315 rounds up to the 360 that |
| 55 | + // never appears in the range) which needs one more wrap back to 0, | ||
| 56 | + // not a clamp to a fourth stop past 270 -- `ROTATE_BAND`'s reason. | ||
| 57 | + low + ((wrapped / ROTATE_STEP).round() * ROTATE_STEP).rem_euclid(span) | ||
| 55 | } else { | 58 | } else { |
| 56 | ((value / TRANSFORM_STEP).round() * TRANSFORM_STEP).clamp(low, high) | 59 | ((value / TRANSFORM_STEP).round() * TRANSFORM_STEP).clamp(low, high) |
| 57 | } | 60 | } |
| @@ -91,8 +94,9 @@ mod tests { | |||
| 91 | assert_eq!(transform_snap(ROTATE_BAND, 46.0), 90.0); | 94 | assert_eq!(transform_snap(ROTATE_BAND, 46.0), 90.0); |
| 92 | assert_eq!(transform_snap(ROTATE_BAND, 270.0), 270.0); | 95 | assert_eq!(transform_snap(ROTATE_BAND, 270.0), 270.0); |
| 93 | // Past the last stop wraps back to the first, not clamps to the last. | 96 | // Past the last stop wraps back to the first, not clamps to the last. |
| 97 | + // -45 is the same angle as 315 mod 360, so it lands on the same stop. | ||
| 94 | assert_eq!(transform_snap(ROTATE_BAND, 315.0), 0.0); | 98 | assert_eq!(transform_snap(ROTATE_BAND, 315.0), 0.0); |
| 95 | - assert_eq!(transform_snap(ROTATE_BAND, -45.0), 270.0); | 99 | + assert_eq!(transform_snap(ROTATE_BAND, -45.0), 0.0); |
| 96 | } | 100 | } |
| 97 | 101 | ||
| 98 | #[test] | 102 | #[test] |
crates/app/src/ui/inspector.rsmodified+10 -0
| @@ -211,6 +211,16 @@ impl Player { | |||
| 211 | ActionId::Color, | 211 | ActionId::Color, |
| 212 | cx.listener(|this, _: &ClickEvent, _, cx| this.open_color(cx)), | 212 | cx.listener(|this, _: &ClickEvent, _, cx| this.open_color(cx)), |
| 213 | )) | 213 | )) |
| 214 | + .child(self.action_control( | ||
| 215 | + "inspect-transform", | ||
| 216 | + 0., | ||
| 217 | + BG_RAISED(), | ||
| 218 | + None, | ||
| 219 | + "Transform", | ||
| 220 | + "position, scale, rotation and crop for this clip", | ||
| 221 | + ActionId::Transform, | ||
| 222 | + cx.listener(|this, _: &ClickEvent, _, cx| this.open_transform(cx)), | ||
| 223 | + )) | ||
| 214 | .child(self.action_control( | 224 | .child(self.action_control( |
| 215 | "inspect-eq", | 225 | "inspect-eq", |
| 216 | 0., | 226 | 0., |