diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs index ccff0fdcd..8feb8c8c5 100644 --- a/crates/ui-egui/src/panels.rs +++ b/crates/ui-egui/src/panels.rs @@ -9,6 +9,7 @@ pub mod crypto_pick; pub mod delete_items; pub mod dialogs; pub mod dialogs_3d; +pub(crate) mod drag_preview; pub mod effect_controls; pub mod effects_presets; pub mod essential; diff --git a/crates/ui-egui/src/panels/drag_preview.rs b/crates/ui-egui/src/panels/drag_preview.rs new file mode 100644 index 000000000..9d0d42f7b --- /dev/null +++ b/crates/ui-egui/src/panels/drag_preview.rs @@ -0,0 +1,47 @@ +//! Fast Previews ▸ Adaptive Resolution for drags outside the viewer: as in After Effects, a drag +//! that changes the frame on screen (scrubbing the time, moving or trimming layers, slipping, +//! dragging keys, scrubbing values) draws a draft until the button is released. + +use std::sync::Arc; + +use effectcraft_engine::project::{Comp, ItemId}; + +use crate::EffectcraftApp; + +/// The frame on screen when a panel starts its pass: the active comp and its current frame. +/// [`DragWatch::end`] compares it with the frame after the panel ran its gestures, so every drag +/// the panel handles is covered without a flag per gesture. +pub(crate) struct DragWatch { + before: Option<(ItemId, Arc, i64)>, +} + +impl DragWatch { + pub(crate) fn begin(app: &EffectcraftApp) -> Self { + let before = app.session.active_comp_id().and_then(|id| { + let comp = app.session.project.comp_arc(id)?; + let frame = comp.frame_rate.frame_at(app.session.time()); + Some((id, comp, frame)) + }); + Self { before } + } + + /// While the primary button drags (moved past a click), a change of the current frame or of + /// the active comp's pixels since [`Self::begin`] sets `property_interacting`, which stays + /// set until the button is up (`App::frame`). A click, a held button, or a drag that draws + /// the same pixels (scrolling, zooming, the work area, selecting) keeps Full. + pub(crate) fn end(self, app: &mut EffectcraftApp, ctx: &egui::Context) { + let Some((id, comp, frame)) = self.before else { return }; + if app.ui.viewer.property_interacting || !ctx.input(|i| i.pointer.primary_down() && i.pointer.is_decidedly_dragging()) { + return; + } + if app.session.active_comp_id() != Some(id) { + return; + } + let Some(now) = app.session.project.comp_arc(id) else { return }; + let moved = comp.frame_rate.frame_at(app.session.time()) != frame; + if moved || (!Arc::ptr_eq(&comp, &now) && !now.same_pixels(&comp)) { + app.ui.viewer.property_interacting = true; + ctx.request_repaint(); + } + } +} diff --git a/crates/ui-egui/src/panels/properties.rs b/crates/ui-egui/src/panels/properties.rs index 4edcbb31a..74ae4daec 100644 --- a/crates/ui-egui/src/panels/properties.rs +++ b/crates/ui-egui/src/panels/properties.rs @@ -67,6 +67,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { p.text(rect.center(), Align2::CENTER_CENTER, crate::i18n::tr("Select a layer to see its properties"), Tokens::ui(12.0), t.text_faint); return; }; + let watch = super::drag_preview::DragWatch::begin(app); let project = app.session.project.clone(); let expr = app.session.expr.clone(); let now = app.session.time(); @@ -190,6 +191,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { app.ui.status = e; } } + watch.end(app, &ctx); } fn section_header(app: &mut EffectcraftApp, p: &egui::Painter, x0: f32, w: f32, y: f32, title: &str, auto: &str) { diff --git a/crates/ui-egui/src/panels/timeline.rs b/crates/ui-egui/src/panels/timeline.rs index 4de3233e8..4d35de005 100644 --- a/crates/ui-egui/src/panels/timeline.rs +++ b/crates/ui-egui/src/panels/timeline.rs @@ -1963,6 +1963,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { return; }; let Some(comp) = app.session.project.comp_arc(cid) else { return }; + let watch = super::drag_preview::DragWatch::begin(app); let mut tl = layout(app, ui, rect, cid, &comp); let g = &mut tl; if !ui.input(|i| i.pointer.primary_down()) { @@ -2022,7 +2023,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) { drop_targets(app, ui, g); let Rw { tl, ui_actions, .. } = rw; apply_ui_acts(app, &tl.comp, ui_actions); - apply_actions(app, ui, &tl.ctx, tl.actions); + apply_actions(app, &tl.ctx, tl.actions); + watch.end(app, &tl.ctx); } /// Applies the UI-only changes the frame collected (twirls, time, ending an undo merge). @@ -2081,11 +2083,7 @@ fn apply_ui_acts(app: &mut EffectcraftApp, comp: &Comp, ui_actions: Vec) } /// Runs the commands the frame collected through [`crate::menus::invoke`]. -fn apply_actions(app: &mut EffectcraftApp, ui: &mut egui::Ui, ctx: &egui::Context, actions: Vec<(String, serde_json::Value)>) { - if ui.input(|i| i.pointer.primary_down()) && actions.iter().any(|(id, _)| id == "prop.set") { - app.ui.viewer.property_interacting = true; - ctx.request_repaint(); - } +fn apply_actions(app: &mut EffectcraftApp, ctx: &egui::Context, actions: Vec<(String, serde_json::Value)>) { for (id, params) in actions { if id == "__endMerge" { app.session.history.merge_key = None; diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs index ee415e36c..d71114b4d 100644 --- a/crates/ui-egui/src/state.rs +++ b/crates/ui-egui/src/state.rs @@ -265,7 +265,9 @@ pub struct ViewerState { /// The pointer is dragging in the viewer this frame (Adaptive Resolution). #[serde(skip)] pub interacting: bool, - /// A property scrub (Effect Controls, Timeline) or a Timeline drag of the playhead, keys or layer bars is in progress (Adaptive Resolution); cleared once the primary button is up. + /// A drag outside the viewer changed the frame on screen: a property scrub in Effect Controls, + /// or any Timeline or Properties drag ([`crate::panels::drag_preview`]). Adaptive Resolution + /// draws a draft until the primary button is up, which clears it. #[serde(skip)] pub property_interacting: bool, /// Extended Viewer: the comp-space region the viewer renders this frame (comp frame plus