🔀 merge(B4): drags cast a shadow — a translucent ghost sits where the clip will land, red where it can't
Browse files at this commit1 changed file +329 -40
- crates/app/src/main.rs +329 -40
crates/app/src/main.rsmodified+329 -40
| @@ -40,6 +40,18 @@ const SELECTED: u32 = 0x2a4a6b; | |||
| 40 | /// the lane stays in the dark family the rest of the chrome lives in | 40 | /// the lane stays in the dark family the rest of the chrome lives in |
| 41 | /// (ledger:187), and the first source keeps `SURFACE` exactly. | 41 | /// (ledger:187), and the first source keeps `SURFACE` exactly. |
| 42 | const SOURCE_TINTS: [u32; 4] = [SURFACE, 0x3b3329, 0x293b33, 0x33293b]; | 42 | const SOURCE_TINTS: [u32; 4] = [SURFACE, 0x3b3329, 0x293b33, 0x33293b]; |
| 43 | +/// The mirror of `SELECTED`: a drop the lane will not take, tinting the shadow | ||
| 44 | +/// a drag draws ([`Ghost`]) so a refusal is seen before the release rather than | ||
| 45 | +/// read afterwards. Same brightness as the rest of the chrome -- a warning, not | ||
| 46 | +/// an alarm. | ||
| 47 | +const REFUSE: u32 = 0x6b2a2a; | ||
| 48 | +/// How solid that shadow is (`0xRRGGBBAA`): enough to read as a box, little | ||
| 49 | +/// enough that the clip it is drawn over is still legible through it. | ||
| 50 | +const GHOST_ALPHA: u32 = 0x66; | ||
| 51 | +/// ...and the narrowest it is drawn: a library row whose length the engine has | ||
| 52 | +/// not measured yet has a landing place but no width, and a head marker says | ||
| 53 | +/// where it goes where a zero-width box would say nothing. | ||
| 54 | +const GHOST_MIN: f32 = 2.; | ||
| 43 | /// One step lighter than whatever it sits on: the pointer's answer that this is | 55 | /// One step lighter than whatever it sits on: the pointer's answer that this is |
| 44 | /// clickable. Two of them, because buttons stand on `SURFACE` and the scrub | 56 | /// clickable. Two of them, because buttons stand on `SURFACE` and the scrub |
| 45 | /// strip stands on `CHROME`. | 57 | /// strip stands on `CHROME`. |
| @@ -297,6 +309,29 @@ struct ClipDrag { | |||
| 297 | clip: Clip, | 309 | clip: Clip, |
| 298 | } | 310 | } |
| 299 | 311 | ||
| 312 | +/// Where the drag in flight would leave what it is carrying: the lane the | ||
| 313 | +/// pointer is over, the snapped head the release will commit ([`landing`]), and | ||
| 314 | +/// how long the thing is. Drawn on that lane as a translucent box the size of | ||
| 315 | +/// the take, so a landing is *seen* before the release rather than discovered | ||
| 316 | +/// after it -- the line ([`Player::snap_cue`]) marks the frame, this shows the | ||
| 317 | +/// body. `refused` is a drop the lane cannot take -- a picture over an audio | ||
| 318 | +/// track, a sound over a video one -- tinted rather than silent, because the | ||
| 319 | +/// refusal is coming at the release either way ([`lane_refuses`], | ||
| 320 | +/// [`Project::move_clip`]). | ||
| 321 | +#[derive(Clone, Copy, PartialEq)] | ||
| 322 | +struct Ghost { | ||
| 323 | + lane: Lane, | ||
| 324 | + start: u32, | ||
| 325 | + /// Timeline frames, which a speed has already been counted into: the box is | ||
| 326 | + /// as wide as the clip is *long where it lands*. Zero for a library row of | ||
| 327 | + /// unknown length, drawn as a head marker. | ||
| 328 | + frames: u32, | ||
| 329 | + /// The swatch of the file being carried ([`Player::file_tint`]), so the | ||
| 330 | + /// ghost reads as the thing in the hand. | ||
| 331 | + tint: u32, | ||
| 332 | + refused: bool, | ||
| 333 | +} | ||
| 334 | + | ||
| 300 | /// A clip edge being dragged: which end of which clip, and the timeline frame | 335 | /// A clip edge being dragged: which end of which clip, and the timeline frame |
| 301 | /// the pointer has pulled it to. The box on screen is drawn from `to` while this | 336 | /// the pointer has pulled it to. The box on screen is drawn from `to` while this |
| 302 | /// is set and the engine hears about it once, at the release | 337 | /// is set and the engine hears about it once, at the release |
| @@ -944,6 +979,12 @@ struct Player { | |||
| 944 | /// happens rather than discovered after the release. Stale between gestures, | 979 | /// happens rather than discovered after the release. Stale between gestures, |
| 945 | /// which costs nothing -- it is drawn only while one is live. | 980 | /// which costs nothing -- it is drawn only while one is live. |
| 946 | snap_cue: Option<u32>, | 981 | snap_cue: Option<u32>, |
| 982 | + /// The box the same gesture is about to fill, or `None` while the pointer is | ||
| 983 | + /// over no lane: the shadow every proper editor draws under a drag. Set by | ||
| 984 | + /// the lane the pointer is actually over -- that is the one question the | ||
| 985 | + /// line above does not answer -- and drawn only while a drag is live, for | ||
| 986 | + /// [`Player::snap_cue`]'s reason. | ||
| 987 | + ghost: Option<Ghost>, | ||
| 947 | last_scrub: Instant, | 988 | last_scrub: Instant, |
| 948 | last_target: u32, | 989 | last_target: u32, |
| 949 | /// The running export. While it owns the UI the editor is read-only. | 990 | /// The running export. While it owns the UI the editor is read-only. |
| @@ -1244,6 +1285,10 @@ impl Player { | |||
| 1244 | // index would trim a clip nobody grabbed. Dropping it is the whole fix: | 1285 | // index would trim a clip nobody grabbed. Dropping it is the whole fix: |
| 1245 | // nothing has been written yet. | 1286 | // nothing has been written yet. |
| 1246 | self.trim = None; | 1287 | self.trim = None; |
| 1288 | + // ...and the shadow a drag is drawn under promises a landing on a lane | ||
| 1289 | + // this edit has just reshaped. The next move of the drag draws it | ||
| 1290 | + // again; until then it says nothing. | ||
| 1291 | + self.ghost = None; | ||
| 1247 | } | 1292 | } |
| 1248 | 1293 | ||
| 1249 | /// What an action does, wherever it was asked for -- a stroke, or the clip | 1294 | /// What an action does, wherever it was asked for -- a stroke, or the clip |
| @@ -1311,6 +1356,7 @@ impl Player { | |||
| 1311 | fn toggle_snap(&mut self, cx: &mut Context<Self>) { | 1356 | fn toggle_snap(&mut self, cx: &mut Context<Self>) { |
| 1312 | self.snap = !self.snap; | 1357 | self.snap = !self.snap; |
| 1313 | self.snap_cue = None; | 1358 | self.snap_cue = None; |
| 1359 | + self.ghost = None; | ||
| 1314 | self.notice = Some(match self.snap { | 1360 | self.notice = Some(match self.snap { |
| 1315 | true => "SNAP ON — drags land on clip edges, the playhead and the start".into(), | 1361 | true => "SNAP ON — drags land on clip edges, the playhead and the start".into(), |
| 1316 | false => "SNAP OFF — drags land exactly where the hand leaves them".into(), | 1362 | false => "SNAP OFF — drags land exactly where the hand leaves them".into(), |
| @@ -2817,9 +2863,32 @@ impl Player { | |||
| 2817 | /// leave a screen of empty bed after the end, the way every NLE does. | 2863 | /// leave a screen of empty bed after the end, the way every NLE does. |
| 2818 | fn drop_frame(&self, from: Lane, idx: usize, x: Pixels) -> Option<(u32, Option<u32>)> { | 2864 | fn drop_frame(&self, from: Lane, idx: usize, x: Pixels) -> Option<(u32, Option<u32>)> { |
| 2819 | let clip = self.session.as_ref()?.lane_clips(from).get(idx).copied()?; | 2865 | let clip = self.session.as_ref()?.lane_clips(from).get(idx).copied()?; |
| 2820 | - let raw = self.frame_under(x).saturating_sub(self.grab); | ||
| 2821 | let marks = self.snap_targets(Some((from, idx))); | 2866 | let marks = self.snap_targets(Some((from, idx))); |
| 2822 | - Some(self.snap_to(raw, clip.frames(), &marks)) | 2867 | + Some(landing( |
| 2868 | + self.frame_under(x), | ||
| 2869 | + self.grab, | ||
| 2870 | + clip.frames(), | ||
| 2871 | + self.snap, | ||
| 2872 | + self.snap_frames(), | ||
| 2873 | + &marks, | ||
| 2874 | + )) | ||
| 2875 | + } | ||
| 2876 | + | ||
| 2877 | + /// The same answer for a library row on its way down: nothing is in the hand | ||
| 2878 | + /// yet, so there is no grab offset to take off and no length to snap by -- | ||
| 2879 | + /// the file's own is not known until the engine has placed it -- and only | ||
| 2880 | + /// its head lands. Asked by the line, by the ghost and by the drop itself | ||
| 2881 | + /// ([`Player::insert_source`]), so all three name one frame. | ||
| 2882 | + fn place_frame(&self, x: Pixels) -> (u32, Option<u32>) { | ||
| 2883 | + let marks = self.snap_targets(None); | ||
| 2884 | + landing( | ||
| 2885 | + self.frame_under(x), | ||
| 2886 | + 0, | ||
| 2887 | + 0, | ||
| 2888 | + self.snap, | ||
| 2889 | + self.snap_frames(), | ||
| 2890 | + &marks, | ||
| 2891 | + ) | ||
| 2823 | } | 2892 | } |
| 2824 | 2893 | ||
| 2825 | /// Which index the clip in the hand is at *now*: [`live_idx`] against the | 2894 | /// Which index the clip in the hand is at *now*: [`live_idx`] against the |
| @@ -2842,15 +2911,91 @@ impl Player { | |||
| 2842 | } | 2911 | } |
| 2843 | 2912 | ||
| 2844 | /// The same line for a library row on its way to a lane: it goes down at | 2913 | /// The same line for a library row on its way to a lane: it goes down at |
| 2845 | - /// the frame it is let go on ([`Player::insert_source`]), so that frame is | 2914 | + /// the frame it is let go on ([`Player::place_frame`]), so that frame is |
| 2846 | - /// what snaps and what is drawn. No length to snap by -- the file's own is | 2915 | + /// what snaps and what is drawn. |
| 2847 | - /// not known until the engine has placed it -- so only its head lands. | ||
| 2848 | fn preview_place(&mut self, x: Pixels, cx: &mut Context<Self>) { | 2916 | fn preview_place(&mut self, x: Pixels, cx: &mut Context<Self>) { |
| 2849 | - let marks = self.snap_targets(None); | 2917 | + let cue = self.place_frame(x).1; |
| 2850 | - let cue = self.snap_to(self.frame_under(x), 0, &marks).1; | ||
| 2851 | self.set_cue(cue, x, cx); | 2918 | self.set_cue(cue, x, cx); |
| 2852 | } | 2919 | } |
| 2853 | 2920 | ||
| 2921 | + /// The shadow the clip in the hand would fill, on the lane the pointer is | ||
| 2922 | + /// over: its head where [`Player::drop_frame`] says the release will put it | ||
| 2923 | + /// -- the same call the drop makes, so the box drawn and the box committed | ||
| 2924 | + /// are one answer -- and its own length at this zoom. A lane of the other | ||
| 2925 | + /// kind refuses the drop ([`Project::move_clip`]), and the shadow says so | ||
| 2926 | + /// before the release does. | ||
| 2927 | + fn preview_ghost(&mut self, drag: &ClipDrag, to: Lane, x: Pixels, cx: &mut Context<Self>) { | ||
| 2928 | + let ghost = self | ||
| 2929 | + .dragged(drag) | ||
| 2930 | + .and_then(|idx| self.drop_frame(drag.lane, idx, x)) | ||
| 2931 | + .map(|(start, _)| Ghost { | ||
| 2932 | + lane: to, | ||
| 2933 | + start, | ||
| 2934 | + frames: drag.clip.frames(), | ||
| 2935 | + tint: self.clip_tint(drag.clip.source), | ||
| 2936 | + refused: drag.lane.kind != to.kind, | ||
| 2937 | + }); | ||
| 2938 | + self.set_ghost(ghost, cx); | ||
| 2939 | + } | ||
| 2940 | + | ||
| 2941 | + /// The same shadow for a library row: its head at [`Player::place_frame`], | ||
| 2942 | + /// which is where the drop inserts it, and the file's own length for its | ||
| 2943 | + /// width -- the length the library row already reports. A file this lane | ||
| 2944 | + /// cannot hold ([`lane_refuses`]) is tinted as refused, which is the answer | ||
| 2945 | + /// the release would give in words. | ||
| 2946 | + fn preview_ghost_asset(&mut self, path: &Path, to: Lane, x: Pixels, cx: &mut Context<Self>) { | ||
| 2947 | + let ghost = Ghost { | ||
| 2948 | + lane: to, | ||
| 2949 | + start: self.place_frame(x).0, | ||
| 2950 | + frames: self | ||
| 2951 | + .session | ||
| 2952 | + .as_ref() | ||
| 2953 | + .map_or(0, |session| session.file_frames(path)), | ||
| 2954 | + tint: self.file_tint(path), | ||
| 2955 | + refused: lane_refuses(path, to).is_some(), | ||
| 2956 | + }; | ||
| 2957 | + self.set_ghost(Some(ghost), cx); | ||
| 2958 | + } | ||
| 2959 | + | ||
| 2960 | + /// Sets the shadow, or takes it away, repainting only when it moved -- the | ||
| 2961 | + /// listeners below run it on every pointer sample of a drag. Cleared by the | ||
| 2962 | + /// root and set again by the lane under the pointer, in that order (gpui | ||
| 2963 | + /// runs the capture phase parent-first), so a pointer over no lane at all | ||
| 2964 | + /// leaves nothing drawn. | ||
| 2965 | + fn set_ghost(&mut self, ghost: Option<Ghost>, cx: &mut Context<Self>) { | ||
| 2966 | + if ghost != self.ghost { | ||
| 2967 | + self.ghost = ghost; | ||
| 2968 | + cx.notify(); | ||
| 2969 | + } | ||
| 2970 | + } | ||
| 2971 | + | ||
| 2972 | + /// The swatch a clip from source `n` wears: [`source_tint`] over the first | ||
| 2973 | + /// source entry naming that *file*, since two audio streams of one file are | ||
| 2974 | + /// two sources and one colour. Every box on a lane and every ghost a drag | ||
| 2975 | + /// draws asks this, so the shadow is recognisably the thing in the hand. | ||
| 2976 | + fn clip_tint(&self, source: usize) -> u32 { | ||
| 2977 | + match self.sources().get(source) { | ||
| 2978 | + Some(entry) => self.file_tint(&entry.path), | ||
| 2979 | + None => source_tint(source), | ||
| 2980 | + } | ||
| 2981 | + } | ||
| 2982 | + | ||
| 2983 | + /// The same swatch asked by path, which is what a library row is named by. | ||
| 2984 | + fn file_tint(&self, path: &Path) -> u32 { | ||
| 2985 | + source_tint( | ||
| 2986 | + self.sources() | ||
| 2987 | + .iter() | ||
| 2988 | + .position(|s| s.path == path) | ||
| 2989 | + .unwrap_or(0), | ||
| 2990 | + ) | ||
| 2991 | + } | ||
| 2992 | + | ||
| 2993 | + fn sources(&self) -> &[Source] { | ||
| 2994 | + self.session | ||
| 2995 | + .as_ref() | ||
| 2996 | + .map_or(&[][..], PlaybackSession::sources) | ||
| 2997 | + } | ||
| 2998 | + | ||
| 2854 | /// Sets the line, or takes it away, and repaints only when it moved: a | 2999 | /// Sets the line, or takes it away, and repaints only when it moved: a |
| 2855 | /// pointer dragged off the bed (up to the library, say) is not promising a | 3000 | /// pointer dragged off the bed (up to the library, say) is not promising a |
| 2856 | /// landing any more. | 3001 | /// landing any more. |
| @@ -3074,28 +3219,13 @@ impl Player { | |||
| 3074 | if self.exporting().is_some() { | 3219 | if self.exporting().is_some() { |
| 3075 | return; | 3220 | return; |
| 3076 | } | 3221 | } |
| 3077 | - // A file with no picture belongs on an audio lane and nowhere else: | 3222 | + // The lane the pointer named cannot hold this kind of file: refused by |
| 3078 | - // dropped on a video lane it is refused by name, and asked for by the | 3223 | + // name, in the same words the ghost was tinted by on the way down |
| 3079 | - // Add button (which names no lane) it goes to the audio one -- which is | 3224 | + // ([`lane_refuses`]). The Add button names no lane and so is never |
| 3080 | - // the engine's choice, in `place_stream_at`, not one made twice here. | 3225 | + // refused here -- where a file goes when nobody says is the engine's |
| 3081 | - if engine::is_audio(path) && onto.is_some_and(|lane| lane.kind == LaneKind::Video) { | 3226 | + // choice, in `place_stream_at`, not one made twice here. |
| 3082 | - let name = file_name(path); | 3227 | + if let Some(why) = onto.and_then(|lane| lane_refuses(path, lane)) { |
| 3083 | - let lane = onto.expect("checked above").label(); | 3228 | + self.notice = Some(why.into()); |
| 3084 | - self.notice = Some( | ||
| 3085 | - format!("NOT ON {lane} — {name} has no picture; drop it on an audio lane").into(), | ||
| 3086 | - ); | ||
| 3087 | - cx.notify(); | ||
| 3088 | - return; | ||
| 3089 | - } | ||
| 3090 | - // ...and the mirror of it: a still is silent, so an audio lane is the | ||
| 3091 | - // one place it cannot go. The engine puts it on `V1` regardless | ||
| 3092 | - // (`place_stream_at`); this is the word that says why it moved. | ||
| 3093 | - if engine::is_image(path) && onto.is_some_and(|lane| lane.kind == LaneKind::Audio) { | ||
| 3094 | - let name = file_name(path); | ||
| 3095 | - let lane = onto.expect("checked above").label(); | ||
| 3096 | - self.notice = Some( | ||
| 3097 | - format!("NOT ON {lane} — {name} is a still image; drop it on a video lane").into(), | ||
| 3098 | - ); | ||
| 3099 | cx.notify(); | 3229 | cx.notify(); |
| 3100 | return; | 3230 | return; |
| 3101 | } | 3231 | } |
| @@ -4282,10 +4412,18 @@ impl Render for Player { | |||
| 4282 | if let Some(idx) = this.dragged(&drag) { | 4412 | if let Some(idx) = this.dragged(&drag) { |
| 4283 | this.preview_drop(drag.lane, idx, event.event.position.x, cx); | 4413 | this.preview_drop(drag.lane, idx, event.event.position.x, cx); |
| 4284 | } | 4414 | } |
| 4415 | + // The shadow belongs to a *lane*, and which lane the pointer is | ||
| 4416 | + // over is the one thing this element cannot see. Cleared here | ||
| 4417 | + // and drawn again by the lane the pointer is actually inside | ||
| 4418 | + // (`lane_row`), which gpui runs straight after this one: the | ||
| 4419 | + // capture phase goes parent first, so a pointer over no lane at | ||
| 4420 | + // all -- up in the library, say -- promises nothing. | ||
| 4421 | + this.set_ghost(None, cx); | ||
| 4285 | })) | 4422 | })) |
| 4286 | .on_drag_move( | 4423 | .on_drag_move( |
| 4287 | cx.listener(|this, event: &DragMoveEvent<AssetDrag>, _, cx| { | 4424 | cx.listener(|this, event: &DragMoveEvent<AssetDrag>, _, cx| { |
| 4288 | this.preview_place(event.event.position.x, cx); | 4425 | this.preview_place(event.event.position.x, cx); |
| 4426 | + this.set_ghost(None, cx); | ||
| 4289 | }), | 4427 | }), |
| 4290 | ) | 4428 | ) |
| 4291 | // Scrubbing is tracked on the root because the pointer leaves the | 4429 | // Scrubbing is tracked on the root because the pointer leaves the |
| @@ -7602,6 +7740,11 @@ impl Player { | |||
| 7602 | .snap_cue | 7740 | .snap_cue |
| 7603 | .filter(|_| self.trim.is_some() || cx.has_active_drag()) | 7741 | .filter(|_| self.trim.is_some() || cx.has_active_drag()) |
| 7604 | .map(|frame| scale.px_at(f64::from(frame) / self.fps)); | 7742 | .map(|frame| scale.px_at(f64::from(frame) / self.fps)); |
| 7743 | + // The shadow, on the one lane the pointer is over -- and, like the line, | ||
| 7744 | + // only while the drag that asked for it is still in flight. | ||
| 7745 | + let ghost = self | ||
| 7746 | + .ghost | ||
| 7747 | + .filter(|g| g.lane == lane && cx.has_active_drag()); | ||
| 7605 | let clips = self | 7748 | let clips = self |
| 7606 | .session | 7749 | .session |
| 7607 | .as_ref() | 7750 | .as_ref() |
| @@ -7751,12 +7894,26 @@ impl Player { | |||
| 7751 | // Onto the edges near it, exactly as a clip carried by | 7894 | // Onto the edges near it, exactly as a clip carried by |
| 7752 | // hand lands: the line drawn while it was in flight is | 7895 | // hand lands: the line drawn while it was in flight is |
| 7753 | // the frame it goes down on. | 7896 | // the frame it goes down on. |
| 7754 | - let x = window.mouse_position().x; | 7897 | + let at = this.place_frame(window.mouse_position().x).0; |
| 7755 | - let marks = this.snap_targets(None); | ||
| 7756 | - let (at, _) = this.snap_to(this.frame_under(x), 0, &marks); | ||
| 7757 | this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) | 7898 | this.insert_source(&drag.0.clone(), drag.1, Some(lane), Some(at), cx) |
| 7758 | })) | 7899 | })) |
| 7759 | .drag_over::<AssetDrag>(|s, _, _, _| s.bg(rgb(HOVER_DIM))) | 7900 | .drag_over::<AssetDrag>(|s, _, _, _| s.bg(rgb(HOVER_DIM))) |
| 7901 | + // The shadow of the row in flight, drawn by the lane the | ||
| 7902 | + // pointer is inside: `on_drag_move` fires on every painted | ||
| 7903 | + // element while a drag of its type is live, wherever the | ||
| 7904 | + // pointer is, and hands each one its own box -- which is how | ||
| 7905 | + // a lane knows the pointer is over *it* (gpui div.rs:282). | ||
| 7906 | + // The root cleared it a moment ago, so exactly one lane | ||
| 7907 | + // draws one. | ||
| 7908 | + .on_drag_move(cx.listener( | ||
| 7909 | + move |this, event: &DragMoveEvent<AssetDrag>, _, cx| { | ||
| 7910 | + if !event.bounds.contains(&event.event.position) { | ||
| 7911 | + return; | ||
| 7912 | + } | ||
| 7913 | + let path = event.drag(cx).0.clone(); | ||
| 7914 | + this.preview_ghost_asset(&path, lane, event.event.position.x, cx); | ||
| 7915 | + }, | ||
| 7916 | + )) | ||
| 7760 | // ...and a clip let go over a lane lands the same way: on | 7917 | // ...and a clip let go over a lane lands the same way: on |
| 7761 | // the track it was dropped on, at the frame it was carried | 7918 | // the track it was dropped on, at the frame it was carried |
| 7762 | // to -- its own included, which is the drag that moves a | 7919 | // to -- its own included, which is the drag that moves a |
| @@ -7772,6 +7929,17 @@ impl Player { | |||
| 7772 | this.move_clip(drag.lane, idx, lane, window.mouse_position().x, cx) | 7929 | this.move_clip(drag.lane, idx, lane, window.mouse_position().x, cx) |
| 7773 | })) | 7930 | })) |
| 7774 | .drag_over::<ClipDrag>(|s, _, _, _| s.bg(rgb(HOVER_DIM))) | 7931 | .drag_over::<ClipDrag>(|s, _, _, _| s.bg(rgb(HOVER_DIM))) |
| 7932 | + // ...and the same shadow for the clip in the hand, seated on | ||
| 7933 | + // this lane when the pointer is inside it. | ||
| 7934 | + .on_drag_move(cx.listener( | ||
| 7935 | + move |this, event: &DragMoveEvent<ClipDrag>, _, cx| { | ||
| 7936 | + if !event.bounds.contains(&event.event.position) { | ||
| 7937 | + return; | ||
| 7938 | + } | ||
| 7939 | + let drag = *event.drag(cx); | ||
| 7940 | + this.preview_ghost(&drag, lane, event.event.position.x, cx); | ||
| 7941 | + }, | ||
| 7942 | + )) | ||
| 7775 | .children(clips.iter().enumerate().map(|(i, clip)| { | 7943 | .children(clips.iter().enumerate().map(|(i, clip)| { |
| 7776 | // The clip as the lane holds it, for the drag payload: | 7944 | // The clip as the lane holds it, for the drag payload: |
| 7777 | // what a drop looks itself up by has to be the placed | 7945 | // what a drop looks itself up by has to be the placed |
| @@ -7795,12 +7963,7 @@ impl Player { | |||
| 7795 | // Tinted by *file*, not by source entry: two audio | 7963 | // Tinted by *file*, not by source entry: two audio |
| 7796 | // streams of one file are two sources, and the library | 7964 | // streams of one file are two sources, and the library |
| 7797 | // gives them one swatch because they are one file. | 7965 | // gives them one swatch because they are one file. |
| 7798 | - let tint = source_tint( | 7966 | + let tint = self.clip_tint(clip.source); |
| 7799 | - sources | ||
| 7800 | - .get(clip.source) | ||
| 7801 | - .and_then(|s| sources.iter().position(|o| o.path == s.path)) | ||
| 7802 | - .unwrap_or(clip.source), | ||
| 7803 | - ); | ||
| 7804 | let width = scale.width_px(len); | 7967 | let width = scale.width_px(len); |
| 7805 | let left = scale.px_at(start); | 7968 | let left = scale.px_at(start); |
| 7806 | // The slice of this box that is on the bed: where its | 7969 | // The slice of this box that is on the bed: where its |
| @@ -8048,6 +8211,34 @@ impl Player { | |||
| 8048 | .bg(rgba(0x4a9effaa)) | 8211 | .bg(rgba(0x4a9effaa)) |
| 8049 | }), | 8212 | }), |
| 8050 | ) | 8213 | ) |
| 8214 | + // Where the thing in the hand would come to rest, at the size | ||
| 8215 | + // it would come to rest at: the shadow a proper editor draws | ||
| 8216 | + // under a drag. Over the clips (it is translucent, so what | ||
| 8217 | + // it would cover shows through) and under the line, which | ||
| 8218 | + // marks the frame this box merely fills. | ||
| 8219 | + .children(ghost.map(|g| { | ||
| 8220 | + div() | ||
| 8221 | + .absolute() | ||
| 8222 | + .top_0() | ||
| 8223 | + .h_full() | ||
| 8224 | + .left(px(scale.px_at(f64::from(g.start) / self.fps))) | ||
| 8225 | + // A row whose length the engine has not measured | ||
| 8226 | + // draws a head marker rather than nothing: where it | ||
| 8227 | + // lands is known, how long it is is not. | ||
| 8228 | + .w(px(scale | ||
| 8229 | + .width_px(f64::from(g.frames) / self.fps) | ||
| 8230 | + .max(GHOST_MIN))) | ||
| 8231 | + .rounded(px(3.)) | ||
| 8232 | + .border_1() | ||
| 8233 | + .border_color(rgb(if g.refused { REFUSE } else { INK })) | ||
| 8234 | + // The file's own swatch at a third of its weight, so | ||
| 8235 | + // the box beneath is still legible through it -- and | ||
| 8236 | + // the refusal red instead, for a lane that will not | ||
| 8237 | + // take this drop at all. | ||
| 8238 | + .bg(rgba( | ||
| 8239 | + ((if g.refused { REFUSE } else { g.tint }) << 8) | GHOST_ALPHA, | ||
| 8240 | + )) | ||
| 8241 | + })) | ||
| 8051 | // What the gesture in flight is about to land on, drawn on | 8242 | // What the gesture in flight is about to land on, drawn on |
| 8052 | // every lane so a clip lining up with a take one track over | 8243 | // every lane so a clip lining up with a take one track over |
| 8053 | // can be seen to line up with it. Under the playhead's line | 8244 | // can be seen to line up with it. Under the playhead's line |
| @@ -10081,6 +10272,44 @@ fn snap_cue(on: bool, raw: u32, len: u32, tol: u32, marks: &[u32]) -> (u32, Opti | |||
| 10081 | (start, mark) | 10272 | (start, mark) |
| 10082 | } | 10273 | } |
| 10083 | 10274 | ||
| 10275 | +/// Where a drag lands and the mark that pulled it there: the frame under the | ||
| 10276 | +/// pointer, less however far into the box the hand grabbed it (so a clip travels | ||
| 10277 | +/// with the pointer rather than jumping its head under it), snapped by | ||
| 10278 | +/// [`snap_cue`]. One answer, asked by the shadow drawn in flight | ||
| 10279 | +/// ([`Player::preview_ghost`]), by the line ([`Player::preview_drop`]) and by | ||
| 10280 | +/// the drop that commits ([`Player::move_clip`]) -- which is what makes the | ||
| 10281 | +/// promise and the landing the same frame. | ||
| 10282 | +fn landing( | ||
| 10283 | + under: u32, | ||
| 10284 | + grab: u32, | ||
| 10285 | + len: u32, | ||
| 10286 | + on: bool, | ||
| 10287 | + tol: u32, | ||
| 10288 | + marks: &[u32], | ||
| 10289 | +) -> (u32, Option<u32>) { | ||
| 10290 | + snap_cue(on, under.saturating_sub(grab), len, tol, marks) | ||
| 10291 | +} | ||
| 10292 | + | ||
| 10293 | +/// Why this file may not go on that lane, in the words the refusal is told in -- | ||
| 10294 | +/// `None` when it may. A file with no picture belongs on an audio lane and | ||
| 10295 | +/// nowhere else, and a still is silent, so an audio lane is the one place it | ||
| 10296 | +/// cannot go. Asked twice: by the ghost tinting itself as refused on the way | ||
| 10297 | +/// down, and by the insert that commits ([`Player::insert_source`]), so what is | ||
| 10298 | +/// shown as impossible is exactly what is refused. | ||
| 10299 | +fn lane_refuses(path: &Path, lane: Lane) -> Option<String> { | ||
| 10300 | + let name = file_name(path); | ||
| 10301 | + let label = lane.label(); | ||
| 10302 | + match lane.kind { | ||
| 10303 | + LaneKind::Video if engine::is_audio(path) => { | ||
| 10304 | + Some(format!("NOT ON {label} — {name} has no picture; drop it on an audio lane")) | ||
| 10305 | + } | ||
| 10306 | + LaneKind::Audio if engine::is_image(path) => { | ||
| 10307 | + Some(format!("NOT ON {label} — {name} is a still image; drop it on a video lane")) | ||
| 10308 | + } | ||
| 10309 | + _ => None, | ||
| 10310 | + } | ||
| 10311 | +} | ||
| 10312 | + | ||
| 10084 | /// Where down an element a pointer sits, 0..1 from the top: the vertical twin | 10313 | /// Where down an element a pointer sits, 0..1 from the top: the vertical twin |
| 10085 | /// of [`frac_along`], for the equalizer, whose gain axis is the y one. An | 10314 | /// of [`frac_along`], for the equalizer, whose gain axis is the y one. An |
| 10086 | /// element that was never painted reads as its middle -- flat, the one answer | 10315 | /// element that was never painted reads as its middle -- flat, the one answer |
| @@ -10458,8 +10687,9 @@ mod tests { | |||
| 10458 | use super::{ | 10687 | use super::{ |
| 10459 | Choice, Edge, FITS, LaneKind, PPS_DEFAULT, RESOLUTIONS, Repeat, Scale, View, | 10688 | Choice, Edge, FITS, LaneKind, PPS_DEFAULT, RESOLUTIONS, Repeat, Scale, View, |
| 10460 | ZOOM_MAX_SECONDS, ZOOM_MIN_FRAMES, ZOOM_STEP, file_name, file_uri, fit_choices, | 10689 | ZOOM_MAX_SECONDS, ZOOM_MIN_FRAMES, ZOOM_STEP, file_name, file_uri, fit_choices, |
| 10461 | - library_rows, live_idx, next_fit, next_resolution, px_along, repeats, resolution_choices, | 10690 | + landing, lane_refuses, library_rows, live_idx, next_fit, next_resolution, px_along, |
| 10462 | - resolution_ladder, span_label, trimmed_clip, unscannable, visible_slice, | 10691 | + repeats, resolution_choices, resolution_ladder, span_label, trimmed_clip, unscannable, |
| 10692 | + visible_slice, | ||
| 10463 | }; | 10693 | }; |
| 10464 | 10694 | ||
| 10465 | /// What the file manager is handed: the parts a path keeps as they are, and | 10695 | /// What the file manager is handed: the parts a path keeps as they are, and |
| @@ -11729,6 +11959,64 @@ mod tests { | |||
| 11729 | assert_eq!(snapped(2, 40, 4, &marks), 0); | 11959 | assert_eq!(snapped(2, 40, 4, &marks), 0); |
| 11730 | } | 11960 | } |
| 11731 | 11961 | ||
| 11962 | + /// The shadow a drag draws and the drop that commits are one answer: both | ||
| 11963 | + /// ask [`landing`], so the box seen in flight is the box the release leaves | ||
| 11964 | + /// behind. What this pins down is the composition around the snap -- the | ||
| 11965 | + /// grab offset comes off *before* the magnet, or a clip taken by its tail | ||
| 11966 | + /// would land a boxful late. | ||
| 11967 | + #[test] | ||
| 11968 | + fn a_ghost_and_a_drop_are_one_landing() { | ||
| 11969 | + // A neighbour covering [100, 160), the playhead at 300, and a 40 frame | ||
| 11970 | + // clip taken hold of 12 frames in. | ||
| 11971 | + let marks = [100, 160, 300, 0]; | ||
| 11972 | + let (len, grab, tol) = (40, 12, 4); | ||
| 11973 | + // Pointer at frame 170: the head is 12 frames behind it, at 158, which | ||
| 11974 | + // is a frame short of the neighbour's tail -- so both the ghost and the | ||
| 11975 | + // drop say 160, and the line stands on the mark that pulled it. | ||
| 11976 | + assert_eq!(landing(170, grab, len, true, tol, &marks), (160, Some(160))); | ||
| 11977 | + // Without the grab taken off first, the same pointer would land the | ||
| 11978 | + // box at 170 and no mark would be in reach: the offset is not cosmetic. | ||
| 11979 | + assert_eq!(landing(170, 0, len, true, tol, &marks), (170, None)); | ||
| 11980 | + // A library row carries no grab and no length the engine has measured, | ||
| 11981 | + // which is how `Player::place_frame` asks: only its head lands, on the | ||
| 11982 | + // playhead here. | ||
| 11983 | + assert_eq!(landing(298, 0, 0, true, tol, &marks), (300, Some(300))); | ||
| 11984 | + // The magnet off, ghost and drop agree on the raw frame and no line is | ||
| 11985 | + // drawn -- the frame-by-frame placement the switch is for. | ||
| 11986 | + assert_eq!(landing(170, grab, len, false, tol, &marks), (158, None)); | ||
| 11987 | + // A pointer nearer the bed's start than the hand is into the box cannot | ||
| 11988 | + // pull a head below zero. | ||
| 11989 | + assert_eq!(landing(3, grab, len, true, tol, &marks), (0, Some(0))); | ||
| 11990 | + } | ||
| 11991 | + | ||
| 11992 | + /// Which lanes tint that shadow as refused: the two kinds of file a lane | ||
| 11993 | + /// cannot hold, in the words the release would say them in -- one rule, so | ||
| 11994 | + /// what is shown as impossible is exactly what is refused. | ||
| 11995 | + #[test] | ||
| 11996 | + fn a_lane_refuses_the_files_it_cannot_hold_before_the_release_says_so() { | ||
| 11997 | + let (video, audio) = (Lane::V1, Lane::A1); | ||
| 11998 | + let sound = Path::new("/media/take.mp3"); | ||
| 11999 | + let still = Path::new("/media/card.png"); | ||
| 12000 | + let movie = Path::new("/media/take.mp4"); | ||
| 12001 | + assert_eq!( | ||
| 12002 | + lane_refuses(sound, video).as_deref(), | ||
| 12003 | + Some("NOT ON V1 — take.mp3 has no picture; drop it on an audio lane") | ||
| 12004 | + ); | ||
| 12005 | + assert_eq!( | ||
| 12006 | + lane_refuses(still, audio).as_deref(), | ||
| 12007 | + Some("NOT ON A1 — card.png is a still image; drop it on a video lane") | ||
| 12008 | + ); | ||
| 12009 | + // ...and every lane a file *can* go on says nothing at all, which is a | ||
| 12010 | + // ghost drawn in the file's own colour. | ||
| 12011 | + assert_eq!(lane_refuses(sound, audio), None); | ||
| 12012 | + assert_eq!(lane_refuses(still, video), None); | ||
| 12013 | + assert_eq!(lane_refuses(movie, video), None); | ||
| 12014 | + // A file with a picture is not refused by an audio lane here: the | ||
| 12015 | + // engine takes its sound onto one, and the words for a video-only file | ||
| 12016 | + // are its own. | ||
| 12017 | + assert_eq!(lane_refuses(movie, audio), None); | ||
| 12018 | + } | ||
| 12019 | + | ||
| 11732 | /// Where those edges come from: every lane, not the one being dropped on -- | 12020 | /// Where those edges come from: every lane, not the one being dropped on -- |
| 11733 | /// and never the clip in the hand or the half of it one track down. | 12021 | /// and never the clip in the hand or the half of it one track down. |
| 11734 | #[test] | 12022 | #[test] |
| @@ -14159,6 +14447,7 @@ fn main() { | |||
| 14159 | grab: 0, | 14447 | grab: 0, |
| 14160 | snap: true, | 14448 | snap: true, |
| 14161 | snap_cue: None, | 14449 | snap_cue: None, |
| 14450 | + ghost: None, | ||
| 14162 | last_scrub: Instant::now(), | 14451 | last_scrub: Instant::now(), |
| 14163 | last_target: 0, | 14452 | last_target: 0, |
| 14164 | export: None, | 14453 | export: None, |