M5.2–M5.5: keyframe clipboard, easy ease, velocity/interpolation dialogs, roving, time remap/stretch/reverse/freeze, graph editor, separate dimensions, pick-whip
Engine (all commands with undo/redo + tests in engine/src/tests_timeline.rs): - keys.copy/paste (Edit Copy/Cut/Paste route to keys when keys are selected; relative timing kept, paste at CTI, cross-property paste of same type), keys.selectAll (Cmd+Alt+A), keys.nudge* (Alt+Arrow, Alt+Shift+Arrow), keys.set / keys.setEase (graph editor drags), keys.info (dialog data), keys.timeReverse; keys.interpolation gains continuous/auto Bezier, spatial interpolation and roving; keys.velocity takes per-dimension values and Continuous. - Roving keys (keyframe::retime_roving): constant speed along the motion path. - Layer > Time: layer.timeStretch (percent|duration, hold in/current/out), layer.timeReverse (Cmd+Alt+R), layer.enableTimeRemap (Cmd+Alt+T), layer.freezeFrame, layer.freezeOnLastFrame; render uses Time Remap as the source time for precomp/footage layers. - prop.separateDimensions (X/Y/Z Position; prop.set on Position writes them). - layer.setParent compensates so the layer stays in place (compensate:false to opt out). - prop.pickWhip writes AE-style reference expressions (thisComp.layer(..), effect(..)(..), mask(..).maskFeather, temp=…;[temp,temp], …[0]). - prop.setExpression: syntax errors keep the text but disable the expression. - expr: arrays of properties returned by an expression are resolved. UI: Keyframe Velocity, Keyframe Interpolation and Time Stretch dialogs; Graph Editor (value + speed graphs, draggable keys and Bezier/influence handles, auto-zoom, fit, show selected, separate dimensions, hold/linear/ auto Bezier/Easy Ease buttons); key + layer context menus. Clears the workspace clippy -D warnings failures. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
dee16181fe
commit
951ed1fa3d
@@ -41,6 +41,9 @@ pub enum Dialog {
|
||||
CompSettings,
|
||||
SolidSettings,
|
||||
CommandPalette,
|
||||
KeyVelocity,
|
||||
KeyInterpolation,
|
||||
TimeStretch,
|
||||
}
|
||||
|
||||
/// Host hooks provided by the native app (file pickers etc.).
|
||||
|
||||
@@ -245,6 +245,9 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V
|
||||
"app.compSettings" | "comp.settings" if params.as_object().is_none_or(|m| m.is_empty()) => {
|
||||
crate::panels::dialogs::open_comp_settings(app)?;
|
||||
}
|
||||
"keys.velocity" if params.as_object().is_none_or(|m| m.is_empty()) => crate::panels::key_dialogs::open_velocity(app)?,
|
||||
"keys.interpolation" if params.as_object().is_none_or(|m| m.is_empty()) => crate::panels::key_dialogs::open_interpolation(app)?,
|
||||
"layer.timeStretch" if params.as_object().is_none_or(|m| m.is_empty()) => crate::panels::key_dialogs::open_time_stretch(app)?,
|
||||
"app.solidSettings" | "layer.newSolid" if params.as_object().is_none_or(|m| m.is_empty()) => {
|
||||
crate::panels::dialogs::open_new_solid(app)?;
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ use serde_json::json;
|
||||
|
||||
use crate::icons::{self, Icon};
|
||||
use crate::theme::Tokens;
|
||||
use crate::{Dialog, EffectcraftApp, widgets};
|
||||
use crate::{Dialog, EffectcraftApp};
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct CompDraft {
|
||||
@@ -34,6 +34,9 @@ pub struct DialogState {
|
||||
pub solid_size: [u32; 2],
|
||||
pub palette_query: String,
|
||||
pub palette_sel: usize,
|
||||
pub velocity: super::key_dialogs::VelocityDraft,
|
||||
pub interp: super::key_dialogs::InterpDraft,
|
||||
pub stretch: super::key_dialogs::StretchDraft,
|
||||
}
|
||||
|
||||
pub fn open_new_comp(app: &mut EffectcraftApp) {
|
||||
@@ -72,7 +75,7 @@ pub fn open_new_solid(app: &mut EffectcraftApp) -> Result<(), String> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn modal(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tokens, body: impl FnOnce(&mut egui::Ui)) {
|
||||
pub(crate) fn modal(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tokens, body: impl FnOnce(&mut egui::Ui)) {
|
||||
// Dim the app.
|
||||
let screen = ctx.content_rect();
|
||||
ctx.layer_painter(egui::LayerId::new(egui::Order::Middle, egui::Id::new("modal-dim"))).rect_filled(screen, 0.0, Color32::from_black_alpha(120));
|
||||
@@ -95,6 +98,9 @@ pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
Dialog::NewComp | Dialog::CompSettings => comp_settings(app, ctx, &t, d == Dialog::CompSettings),
|
||||
Dialog::SolidSettings => solid(app, ctx, &t),
|
||||
Dialog::CommandPalette => palette(app, ctx, &t),
|
||||
Dialog::KeyVelocity => super::key_dialogs::velocity(app, ctx, &t),
|
||||
Dialog::KeyInterpolation => super::key_dialogs::interpolation(app, ctx, &t),
|
||||
Dialog::TimeStretch => super::key_dialogs::time_stretch(app, ctx, &t),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,7 +268,7 @@ fn comp_settings(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens, exis
|
||||
}
|
||||
}
|
||||
|
||||
fn ui_enter(ctx: &egui::Context) -> bool {
|
||||
pub(crate) fn ui_enter(ctx: &egui::Context) -> bool {
|
||||
!ctx.egui_wants_keyboard_input() && ctx.input(|i| i.key_pressed(egui::Key::Enter))
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,452 @@
|
||||
//! The Graph Editor (Timeline ▸ Shift+F3): value graph and speed graph of the selected (or all
|
||||
//! animated) properties, keyframes you can drag in time and value, Bezier/influence handles on
|
||||
//! selected keys, auto-zoom / fit, and the bottom button bar (graph type, show selected,
|
||||
//! auto-zoom, fit, separate dimensions, hold/linear/auto Bezier, Easy Ease family).
|
||||
//!
|
||||
//! Every edit is an engine command (`keys.set`, `keys.setEase`, `keys.select`, `keys.*`).
|
||||
|
||||
use effectcraft_engine::KeyRef;
|
||||
use effectcraft_engine::keyframe::{Interp, Value, side_ease};
|
||||
use effectcraft_engine::project::{Comp, Layer, LayerId, Property};
|
||||
use effectcraft_engine::render::EvalCtx;
|
||||
use effectcraft_engine::time::Tick;
|
||||
use egui::{Align2, Color32, Pos2, Rect, Sense, Stroke, StrokeKind, pos2, vec2};
|
||||
use serde_json::json;
|
||||
|
||||
use super::timeline::TMap;
|
||||
use crate::EffectcraftApp;
|
||||
use crate::theme::Tokens;
|
||||
|
||||
type Actions = Vec<(String, serde_json::Value)>;
|
||||
|
||||
const DIM_COLORS: [Color32; 4] =
|
||||
[Color32::from_rgb(0xe0, 0x55, 0x55), Color32::from_rgb(0x5c, 0xc8, 0x5c), Color32::from_rgb(0x50, 0x8c, 0xf0), Color32::from_rgb(0xe8, 0xc8, 0x40)];
|
||||
const PROP_COLORS: [Color32; 6] = [
|
||||
Color32::from_rgb(0xe8, 0xc8, 0x40),
|
||||
Color32::from_rgb(0xd0, 0x70, 0xe0),
|
||||
Color32::from_rgb(0x40, 0xc8, 0xc8),
|
||||
Color32::from_rgb(0xf0, 0x90, 0x40),
|
||||
Color32::from_rgb(0x9c, 0xd8, 0x50),
|
||||
Color32::from_rgb(0xf0, 0x70, 0x90),
|
||||
];
|
||||
|
||||
struct Handle {
|
||||
out: bool,
|
||||
/// Comp seconds / graph value of the handle end.
|
||||
t: f64,
|
||||
v: f64,
|
||||
/// Original speed (sign is kept when dragging in the speed graph).
|
||||
speed: f64,
|
||||
/// Segment duration (layer seconds) the influence is relative to.
|
||||
dur: f64,
|
||||
}
|
||||
|
||||
struct KeyPt {
|
||||
idx: usize,
|
||||
time: Tick,
|
||||
/// Comp seconds.
|
||||
t: f64,
|
||||
v: f64,
|
||||
sel: bool,
|
||||
handles: Vec<Handle>,
|
||||
}
|
||||
|
||||
struct Curve<'a> {
|
||||
layer: &'a Layer,
|
||||
prop: &'a Property,
|
||||
dim: usize,
|
||||
color: Color32,
|
||||
pts: Vec<(f64, f64)>,
|
||||
keys: Vec<KeyPt>,
|
||||
/// Values editable in the value graph (not spatial / combined dimensions).
|
||||
editable: bool,
|
||||
}
|
||||
|
||||
/// Properties shown: the selected ones, or every animated property of the selected layers.
|
||||
fn shown_props(app: &EffectcraftApp, comp: &Comp) -> Vec<(LayerId, u64)> {
|
||||
let st = &app.session.state;
|
||||
let numeric = |pr: &Property| !pr.value.components().is_empty() && pr.value.interpolates();
|
||||
if app.ui.timeline.graph_show_selected && !st.selected_props.is_empty() {
|
||||
return st.selected_props.iter().filter(|(l, u)| comp.layer(*l).and_then(|l| l.props.find(*u)).is_some_and(numeric)).copied().collect();
|
||||
}
|
||||
let mut v = vec![];
|
||||
for l in comp.layers.iter().filter(|l| st.selected_layers.contains(&l.id)) {
|
||||
l.props.walk("", &mut |_, pr| {
|
||||
if (pr.is_animated() || pr.has_expression()) && numeric(pr) {
|
||||
v.push((l.id, pr.uid));
|
||||
}
|
||||
});
|
||||
}
|
||||
v
|
||||
}
|
||||
|
||||
fn shown_dims(l: &Layer, pr: &Property) -> usize {
|
||||
let n = pr.value.components().len();
|
||||
if pr.shown_dims > 0 && !l.is_3d() { (pr.shown_dims as usize).min(n) } else { n.min(4) }
|
||||
}
|
||||
|
||||
/// Build the curves for the visible time span.
|
||||
fn curves<'a>(app: &EffectcraftApp, comp: &'a Comp, ectx: &EvalCtx, tm: TMap, plot: Rect, speed: bool) -> Vec<Curve<'a>> {
|
||||
let sel = &app.session.state.selected_keys;
|
||||
let n = ((plot.width() / 2.0) as usize).max(2);
|
||||
let mut out = vec![];
|
||||
for (pi, (lid, uid)) in shown_props(app, comp).into_iter().enumerate() {
|
||||
let Some(l) = comp.layer(lid) else { continue };
|
||||
let Some(pr) = l.props.find(uid) else { continue };
|
||||
let spatial = pr.spatial && matches!(pr.value, Value::Vec2(_) | Value::Vec3(_));
|
||||
let dims = if speed && spatial { 1 } else { shown_dims(l, pr) };
|
||||
for d in 0..dims {
|
||||
let color = if dims > 1 { DIM_COLORS[d % 4] } else { PROP_COLORS[pi % PROP_COLORS.len()] };
|
||||
let mut pts = Vec::with_capacity(n);
|
||||
for i in 0..n {
|
||||
let x = plot.min.x + plot.width() * i as f32 / (n - 1) as f32;
|
||||
let ct = tm.t(x);
|
||||
let tt = Tick::from_seconds_f64(ct);
|
||||
let v = if speed {
|
||||
let lt = l.layer_time(tt);
|
||||
if spatial {
|
||||
effectcraft_engine::keyframe::speed(&pr.keys, lt, true)
|
||||
} else {
|
||||
effectcraft_engine::keyframe::velocity(&pr.keys, lt, false).get(d).copied().unwrap_or(0.0).abs()
|
||||
}
|
||||
} else {
|
||||
ectx.at(tt).value(l, pr).components().get(d).copied().unwrap_or(0.0)
|
||||
};
|
||||
pts.push((ct, v));
|
||||
}
|
||||
let mut keys = vec![];
|
||||
for (i, k) in pr.keys.iter().enumerate() {
|
||||
let ks = sel.contains(&KeyRef { layer: lid, prop: uid, time: k.time });
|
||||
let kt = l.comp_time(k.time).seconds();
|
||||
let ed = if spatial { 0 } else { d };
|
||||
let mut handles = vec![];
|
||||
let mut side_speeds = vec![];
|
||||
for out_side in [false, true] {
|
||||
let Some(e) = side_ease(&pr.keys, i, ed, pr.spatial, out_side) else { continue };
|
||||
let j = if out_side { i + 1 } else { i - 1 };
|
||||
let dur = (pr.keys[j].time.seconds() - k.time.seconds()).abs();
|
||||
side_speeds.push(e.speed.abs());
|
||||
let dt = e.influence * dur * if out_side { 1.0 } else { -1.0 };
|
||||
let (hv, show) = if speed { (e.speed.abs(), true) } else { (k.value.components().get(d).copied().unwrap_or(0.0) + e.speed * dt, !spatial) };
|
||||
let bezier = if out_side { k.out_interp == Interp::Bezier } else { k.in_interp == Interp::Bezier };
|
||||
if ks && show && (bezier || speed) {
|
||||
handles.push(Handle { out: out_side, t: kt + dt, v: hv, speed: e.speed, dur });
|
||||
}
|
||||
}
|
||||
let v = if speed {
|
||||
if side_speeds.is_empty() { 0.0 } else { side_speeds.iter().sum::<f64>() / side_speeds.len() as f64 }
|
||||
} else {
|
||||
k.value.components().get(d).copied().unwrap_or(0.0)
|
||||
};
|
||||
keys.push(KeyPt { idx: i, time: k.time, t: kt, v, sel: ks, handles });
|
||||
}
|
||||
out.push(Curve { layer: l, prop: pr, dim: d, color, pts, keys, editable: !spatial });
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
fn text_button(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter, x: &mut f32, y: f32, label: &str, on: bool, id: &str, tip: &str) -> bool {
|
||||
let t = app.tokens;
|
||||
let w = p.layout_no_wrap(label.to_string(), Tokens::ui(11.0), t.text).size().x + 14.0;
|
||||
let r = Rect::from_min_size(pos2(*x, y - 9.0), vec2(w, 18.0));
|
||||
let resp = ui.interact(r, egui::Id::new(("graph-btn", id)), Sense::click()).on_hover_text(tip);
|
||||
p.rect_filled(
|
||||
r,
|
||||
3.0,
|
||||
if on {
|
||||
t.accent.gamma_multiply(0.55)
|
||||
} else if resp.hovered() {
|
||||
t.hover
|
||||
} else {
|
||||
Color32::from_rgb(0x2c, 0x2c, 0x2c)
|
||||
},
|
||||
);
|
||||
p.text(r.center(), Align2::CENTER_CENTER, label, Tokens::ui(11.0), if on { Color32::WHITE } else { t.text });
|
||||
app.auto.add(&format!("timeline.graph.{id}"), r, tip);
|
||||
*x += w + 4.0;
|
||||
resp.clicked()
|
||||
}
|
||||
|
||||
/// Draw the Graph Editor into `area` (the right side of the Timeline) and queue edits.
|
||||
pub(crate) fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter, comp: &Comp, ectx: &EvalCtx, tm: TMap, area: Rect, actions: &mut Actions) {
|
||||
let t = app.tokens;
|
||||
let ctx = ui.ctx().clone();
|
||||
let footer_h = 28.0;
|
||||
let plot = Rect::from_min_max(area.min + vec2(0.0, 6.0), pos2(area.max.x, area.max.y - footer_h));
|
||||
let bar = Rect::from_min_max(pos2(area.min.x, area.max.y - footer_h), area.max);
|
||||
// Background first so keys and handles (added later) sit on top for hit-testing.
|
||||
let bg = ui.interact(plot, egui::Id::new("graph-bg"), Sense::click_and_drag());
|
||||
p.rect_filled(area, 0.0, Color32::from_rgb(0x1d, 0x1d, 0x1d));
|
||||
app.auto.add("timeline.graph", plot, &app.ui.timeline.graph_mode.clone());
|
||||
let speed = app.ui.timeline.graph_mode == "speed";
|
||||
let cs = curves(app, comp, ectx, tm, plot, speed);
|
||||
|
||||
// Vertical range: auto-zoom to the curves + handles, or the stored manual range.
|
||||
let (mut lo, mut hi) = (f64::INFINITY, f64::NEG_INFINITY);
|
||||
for c in &cs {
|
||||
for (_, v) in &c.pts {
|
||||
lo = lo.min(*v);
|
||||
hi = hi.max(*v);
|
||||
}
|
||||
for k in &c.keys {
|
||||
for v in std::iter::once(k.v).chain(k.handles.iter().map(|h| h.v)) {
|
||||
lo = lo.min(v);
|
||||
hi = hi.max(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
if !lo.is_finite() {
|
||||
(lo, hi) = (0.0, 100.0);
|
||||
}
|
||||
if speed {
|
||||
lo = lo.min(0.0);
|
||||
}
|
||||
if (hi - lo).abs() < 1e-9 {
|
||||
hi = lo + 1.0;
|
||||
}
|
||||
let pad = (hi - lo) * 0.08;
|
||||
let auto = (lo - pad, hi + pad);
|
||||
// While a key or handle is being dragged the scale stays put (no feedback loop).
|
||||
let drag_id = egui::Id::new("graph-dragging");
|
||||
let dragging = ctx.data(|d| d.get_temp::<bool>(drag_id)).unwrap_or(false) && ctx.input(|i| i.pointer.any_down());
|
||||
let (lo, hi) = if app.ui.timeline.graph_auto_zoom && !dragging { auto } else { app.ui.timeline.graph_range.unwrap_or(auto) };
|
||||
if app.ui.timeline.graph_auto_zoom && !dragging {
|
||||
app.ui.timeline.graph_range = Some((lo, hi));
|
||||
}
|
||||
let ymap = |v: f64| plot.max.y - ((v - lo) / (hi - lo)) as f32 * plot.height();
|
||||
let vmap = |y: f32| lo + (plot.max.y - y) as f64 / plot.height() as f64 * (hi - lo);
|
||||
|
||||
// Grid + value labels.
|
||||
let pc = p.with_clip_rect(plot);
|
||||
let step = nice_step((hi - lo) / 6.0);
|
||||
let mut gv = (lo / step).ceil() * step;
|
||||
while gv <= hi {
|
||||
let y = ymap(gv);
|
||||
pc.line_segment([pos2(plot.min.x, y), pos2(plot.max.x, y)], Stroke::new(1.0, Color32::from_white_alpha(12)));
|
||||
pc.text(pos2(plot.min.x + 4.0, y - 1.0), Align2::LEFT_BOTTOM, fmt(gv, step), Tokens::ui(10.0), t.text_faint);
|
||||
gv += step;
|
||||
}
|
||||
if cs.is_empty() {
|
||||
p.text(plot.center(), Align2::CENTER_CENTER, "Select animated properties to show them in the Graph Editor", Tokens::ui(12.0), t.text_faint);
|
||||
}
|
||||
|
||||
// Curves.
|
||||
for c in &cs {
|
||||
let pts: Vec<Pos2> = c.pts.iter().map(|(ct, v)| pos2(tm.x(*ct), ymap(*v))).collect();
|
||||
pc.add(egui::Shape::line(pts, Stroke::new(1.5, c.color)));
|
||||
}
|
||||
// Keys and handles.
|
||||
let mut key_screens: Vec<(serde_json::Value, Pos2)> = vec![];
|
||||
let fr = comp.frame_rate;
|
||||
for c in &cs {
|
||||
let (lid, uid, d) = (c.layer.id, c.prop.uid, c.dim);
|
||||
for k in &c.keys {
|
||||
let kp = pos2(tm.x(k.t), ymap(k.v));
|
||||
if !plot.expand(6.0).contains(kp) {
|
||||
continue;
|
||||
}
|
||||
let kjson = json!({"layer": lid.0, "prop": uid, "time": k.time.seconds()});
|
||||
key_screens.push((kjson.clone(), kp));
|
||||
// Handles (selected keys).
|
||||
for h in &k.handles {
|
||||
let hp = pos2(tm.x(h.t), ymap(h.v));
|
||||
pc.line_segment([kp, hp], Stroke::new(1.0, Color32::from_rgb(0xd8, 0xd8, 0x60)));
|
||||
pc.circle_filled(hp, 3.5, Color32::from_rgb(0xd8, 0xd8, 0x60));
|
||||
let side = if h.out { "out" } else { "in" };
|
||||
let hr = Rect::from_center_size(hp, vec2(10.0, 10.0));
|
||||
let hresp = ui.interact(hr, egui::Id::new(("ghandle", uid, d, k.idx, side)), Sense::drag());
|
||||
app.auto.add(&format!("timeline.graph.handle.{uid}.{d}.{}.{side}", k.idx), hr, "Bezier handle");
|
||||
if hresp.dragged()
|
||||
&& let Some(pt) = hresp.interact_pointer_pos()
|
||||
{
|
||||
ctx.data_mut(|dd| dd.insert_temp(drag_id, true));
|
||||
let mut dt = (tm.t(pt.x) - k.t) * if h.out { 1.0 } else { -1.0 };
|
||||
dt = dt.max(h.dur * 0.001);
|
||||
let influence = (dt / h.dur.max(1e-9) * 100.0).clamp(0.1, 100.0);
|
||||
let sp = if speed {
|
||||
let mag = vmap(pt.y).max(0.0);
|
||||
if h.speed < 0.0 { -mag } else { mag }
|
||||
} else {
|
||||
let dv = vmap(pt.y) - k.v;
|
||||
dv / dt * if h.out { 1.0 } else { -1.0 }
|
||||
};
|
||||
let mut params = json!({"layer": lid.0, "prop": uid, "time": k.time.seconds(), "side": side, "speed": sp, "influence": influence, "merge": format!("ghandle-{uid}-{}", k.idx)});
|
||||
if c.editable {
|
||||
params["dim"] = json!(d);
|
||||
}
|
||||
actions.push(("keys.setEase".into(), params));
|
||||
}
|
||||
if hresp.drag_stopped() {
|
||||
ctx.data_mut(|dd| dd.insert_temp(drag_id, false));
|
||||
actions.push(("__endMerge".into(), json!({})));
|
||||
}
|
||||
}
|
||||
// The key itself.
|
||||
let col = if k.sel { t.keyframe_selected } else { Color32::from_gray(0xe0) };
|
||||
pc.rect_filled(Rect::from_center_size(kp, vec2(7.0, 7.0)), 0.0, col);
|
||||
pc.rect_stroke(Rect::from_center_size(kp, vec2(7.0, 7.0)), 0.0, Stroke::new(1.0, c.color), StrokeKind::Outside);
|
||||
let kr = Rect::from_center_size(kp, vec2(11.0, 11.0));
|
||||
let kresp = ui.interact(kr, egui::Id::new(("gkey", uid, d, k.idx)), Sense::click_and_drag());
|
||||
app.auto.add(&format!("timeline.graph.key.{uid}.{d}.{}", k.idx), kr, &c.prop.name);
|
||||
let shift = ui.input(|i| i.modifiers.shift);
|
||||
if (kresp.clicked() || kresp.drag_started()) && (!k.sel || shift) {
|
||||
actions.push(("keys.select".into(), json!({"keys": [kjson.clone()], "add": shift})));
|
||||
}
|
||||
if kresp.dragged()
|
||||
&& let Some(pt) = kresp.interact_pointer_pos()
|
||||
{
|
||||
ctx.data_mut(|dd| dd.insert_temp(drag_id, true));
|
||||
let merge = format!("gkey-{uid}-{}", k.idx);
|
||||
let nt = c.layer.layer_time(fr.snap_nearest(Tick::from_seconds_f64(tm.t(pt.x).max(0.0))));
|
||||
let mut params = json!({"layer": lid.0, "prop": uid, "time": k.time.seconds(), "newTime": nt.seconds(), "merge": merge});
|
||||
if !speed && c.editable {
|
||||
let mut comps = c.prop.keys[k.idx].value.components();
|
||||
if d < comps.len() {
|
||||
comps[d] = vmap(pt.y);
|
||||
}
|
||||
params["value"] = if comps.len() == 1 { json!(comps[0]) } else { json!(comps) };
|
||||
}
|
||||
actions.push(("keys.set".into(), params));
|
||||
}
|
||||
if kresp.drag_stopped() {
|
||||
ctx.data_mut(|dd| dd.insert_temp(drag_id, false));
|
||||
actions.push(("__endMerge".into(), json!({})));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Background: click deselects keys, drag box-selects.
|
||||
if bg.clicked() {
|
||||
actions.push(("keys.select".into(), json!({"keys": []})));
|
||||
}
|
||||
if bg.dragged()
|
||||
&& let (Some(o), Some(cur)) = (ctx.input(|i| i.pointer.press_origin()), bg.interact_pointer_pos())
|
||||
{
|
||||
let br = Rect::from_two_pos(o, cur);
|
||||
pc.rect_filled(br, 0.0, t.accent.gamma_multiply(0.12));
|
||||
pc.rect_stroke(br, 0.0, Stroke::new(1.0, t.accent), StrokeKind::Middle);
|
||||
ctx.data_mut(|d| d.insert_temp(egui::Id::new("graph-box"), br));
|
||||
}
|
||||
if bg.drag_stopped()
|
||||
&& let Some(br) = ctx.data(|d| d.get_temp::<Rect>(egui::Id::new("graph-box")))
|
||||
{
|
||||
ctx.data_mut(|d| d.remove::<Rect>(egui::Id::new("graph-box")));
|
||||
let keys: Vec<serde_json::Value> = key_screens.iter().filter(|(_, sp)| br.contains(*sp)).map(|(k, _)| k.clone()).collect();
|
||||
actions.push(("keys.select".into(), json!({"keys": keys, "add": ui.input(|i| i.modifiers.shift)})));
|
||||
}
|
||||
// Wheel over the graph with Alt/Ctrl zooms the value axis (turns auto-zoom off).
|
||||
if ui.rect_contains_pointer(plot) {
|
||||
let (dy, zoom) = ui.input(|i| (i.smooth_scroll_delta.y, i.modifiers.ctrl || i.modifiers.command));
|
||||
if zoom && dy.abs() > 0.0 {
|
||||
let k = (-dy as f64 / 200.0).exp();
|
||||
let mid = (lo + hi) / 2.0;
|
||||
app.ui.timeline.graph_auto_zoom = false;
|
||||
app.ui.timeline.graph_range = Some((mid - (mid - lo) * k, mid + (hi - mid) * k));
|
||||
}
|
||||
}
|
||||
|
||||
// Button bar.
|
||||
p.rect_filled(bar, 0.0, t.panel_bg);
|
||||
p.line_segment([bar.left_top(), bar.right_top()], Stroke::new(1.0, t.separator));
|
||||
let y = bar.center().y;
|
||||
let mut x = bar.min.x + 8.0;
|
||||
let tl = &app.ui.timeline;
|
||||
let (is_value, show_sel, auto_on) = (tl.graph_mode != "speed", tl.graph_show_selected, tl.graph_auto_zoom);
|
||||
if text_button(app, ui, p, &mut x, y, "Value", is_value, "valueGraph", "Edit Value Graph") {
|
||||
app.ui.timeline.graph_mode = "value".into();
|
||||
}
|
||||
if text_button(app, ui, p, &mut x, y, "Speed", !is_value, "speedGraph", "Edit Speed Graph") {
|
||||
app.ui.timeline.graph_mode = "speed".into();
|
||||
}
|
||||
x += 6.0;
|
||||
if text_button(app, ui, p, &mut x, y, "Selected", show_sel, "showSelected", "Show Selected Properties (else all animated properties)") {
|
||||
app.ui.timeline.graph_show_selected = !show_sel;
|
||||
}
|
||||
if text_button(app, ui, p, &mut x, y, "Auto-zoom", auto_on, "autoZoom", "Auto-zoom graph height") {
|
||||
app.ui.timeline.graph_auto_zoom = !auto_on;
|
||||
}
|
||||
if text_button(app, ui, p, &mut x, y, "Fit", false, "fit", "Fit all graphs to view") {
|
||||
app.ui.timeline.graph_auto_zoom = true;
|
||||
app.ui.timeline.pps = None;
|
||||
}
|
||||
if text_button(app, ui, p, &mut x, y, "Fit Selection", false, "fitSelection", "Fit selection to view") {
|
||||
fit_selection(app, &cs, tm, plot);
|
||||
}
|
||||
x += 6.0;
|
||||
let pos_sel = app.session.state.selected_props.iter().find_map(|(l, u)| {
|
||||
let layer = comp.layer(*l)?;
|
||||
let tr = layer.transform()?;
|
||||
(tr.get("position").is_some_and(|p| p.uid == *u) || ["positionX", "positionY", "positionZ"].iter().any(|m| tr.get(m).is_some_and(|p| p.uid == *u)))
|
||||
.then_some(l.0)
|
||||
});
|
||||
if text_button(app, ui, p, &mut x, y, "Separate Dimensions", false, "separateDimensions", "Separate Dimensions (Position)")
|
||||
&& let Some(l) = pos_sel.or(app.session.state.selected_layers.first().map(|l| l.0))
|
||||
{
|
||||
actions.push(("prop.separateDimensions".into(), json!({"layer": l})));
|
||||
}
|
||||
x += 6.0;
|
||||
for (label, cmd, params, tip) in [
|
||||
("Hold", "keys.interpolation", json!({"interpolation": "hold"}), "Convert selected keyframes to Hold"),
|
||||
("Linear", "keys.interpolation", json!({"interpolation": "linear"}), "Convert selected keyframes to Linear"),
|
||||
("Auto Bezier", "keys.interpolation", json!({"interpolation": "autoBezier"}), "Convert selected keyframes to Auto Bezier"),
|
||||
("Easy Ease", "keys.easyEase", json!({}), "Easy Ease (F9)"),
|
||||
("Ease In", "keys.easyEaseIn", json!({}), "Easy Ease In (Shift+F9)"),
|
||||
("Ease Out", "keys.easyEaseOut", json!({}), "Easy Ease Out (Ctrl+Shift+F9)"),
|
||||
] {
|
||||
let id = cmd.trim_start_matches("keys.").to_string() + label.split_whitespace().next().unwrap_or("");
|
||||
if text_button(app, ui, p, &mut x, y, label, false, &id, tip) {
|
||||
actions.push((cmd.into(), params));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Zoom time and value to the selected keys (and their handles).
|
||||
fn fit_selection(app: &mut EffectcraftApp, cs: &[Curve], tm: TMap, plot: Rect) {
|
||||
let mut t0 = f64::INFINITY;
|
||||
let mut t1 = f64::NEG_INFINITY;
|
||||
let mut v0 = f64::INFINITY;
|
||||
let mut v1 = f64::NEG_INFINITY;
|
||||
for c in cs {
|
||||
for k in c.keys.iter().filter(|k| k.sel) {
|
||||
for (t, v) in std::iter::once((k.t, k.v)).chain(k.handles.iter().map(|h| (h.t, h.v))) {
|
||||
t0 = t0.min(t);
|
||||
t1 = t1.max(t);
|
||||
v0 = v0.min(v);
|
||||
v1 = v1.max(v);
|
||||
}
|
||||
}
|
||||
}
|
||||
if !t0.is_finite() {
|
||||
return;
|
||||
}
|
||||
let span = (t1 - t0).max(0.2);
|
||||
let pps = (plot.width() as f64 * 0.8 / span).clamp(5.0, 4000.0);
|
||||
app.ui.timeline.pps = Some(pps);
|
||||
app.ui.timeline.start = (t0 - span * 0.1).max(0.0);
|
||||
let pad = ((v1 - v0) * 0.15).max(1.0);
|
||||
app.ui.timeline.graph_auto_zoom = false;
|
||||
app.ui.timeline.graph_range = Some((v0 - pad, v1 + pad));
|
||||
let _ = tm;
|
||||
}
|
||||
|
||||
fn nice_step(raw: f64) -> f64 {
|
||||
let raw = raw.abs().max(1e-9);
|
||||
let mag = 10f64.powf(raw.log10().floor());
|
||||
let n = raw / mag;
|
||||
mag * if n < 1.5 {
|
||||
1.0
|
||||
} else if n < 3.5 {
|
||||
2.0
|
||||
} else if n < 7.5 {
|
||||
5.0
|
||||
} else {
|
||||
10.0
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt(v: f64, step: f64) -> String {
|
||||
let dec = if step >= 1.0 { 0 } else { (-step.log10()).ceil() as usize };
|
||||
let s = format!("{v:.dec$}");
|
||||
if s.trim_start_matches('-').chars().all(|c| c == '0' || c == '.') { s.trim_start_matches('-').to_string() } else { s }
|
||||
}
|
||||
@@ -0,0 +1,287 @@
|
||||
//! Animation dialogs: Keyframe Velocity, Keyframe Interpolation and Time Stretch. Each one is
|
||||
//! pre-filled from the engine (`keys.info`, the layer) and commits through one engine command.
|
||||
|
||||
use egui::{Color32, vec2};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use crate::theme::Tokens;
|
||||
use crate::{Dialog, EffectcraftApp};
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct VelocityDraft {
|
||||
pub dims: usize,
|
||||
pub units: String,
|
||||
pub name: String,
|
||||
pub in_speed: Vec<f64>,
|
||||
pub in_inf: Vec<f64>,
|
||||
pub out_speed: Vec<f64>,
|
||||
pub out_inf: Vec<f64>,
|
||||
/// Which sides exist (first key has no incoming side, last none outgoing).
|
||||
pub has_in: bool,
|
||||
pub has_out: bool,
|
||||
pub continuous: bool,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct InterpDraft {
|
||||
/// Index into TEMPORAL / SPATIAL / ROVING (0 = Current Settings).
|
||||
pub temporal: usize,
|
||||
pub spatial: usize,
|
||||
pub roving: usize,
|
||||
pub has_spatial: bool,
|
||||
pub count: usize,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, Default)]
|
||||
pub struct StretchDraft {
|
||||
pub percent: f64,
|
||||
pub duration: f64,
|
||||
/// 0 = Layer In-point, 1 = Current Frame, 2 = Layer Out-point.
|
||||
pub hold: usize,
|
||||
pub orig_duration: f64,
|
||||
pub orig_percent: f64,
|
||||
}
|
||||
|
||||
pub const TEMPORAL: [(&str, &str); 6] = [
|
||||
("Current Settings", ""),
|
||||
("Linear", "linear"),
|
||||
("Bezier", "bezier"),
|
||||
("Continuous Bezier", "continuousBezier"),
|
||||
("Auto Bezier", "autoBezier"),
|
||||
("Hold", "hold"),
|
||||
];
|
||||
pub const SPATIAL: [(&str, &str); 5] =
|
||||
[("Current Settings", ""), ("Linear", "linear"), ("Bezier", "bezier"), ("Continuous Bezier", "continuousBezier"), ("Auto Bezier", "autoBezier")];
|
||||
pub const ROVING: [&str; 3] = ["Current Settings", "Lock To Time", "Rove Across Time"];
|
||||
|
||||
fn num(v: &Value) -> f64 {
|
||||
v.as_f64().unwrap_or(0.0)
|
||||
}
|
||||
|
||||
/// Animation ▸ Keyframe Velocity… (⇧⌘K) with keys selected.
|
||||
pub fn open_velocity(app: &mut EffectcraftApp) -> Result<(), String> {
|
||||
let info = app.session.execute("keys.info", json!({})).map_err(|e| e.to_string())?;
|
||||
let first = info.as_array().and_then(|a| a.first()).ok_or("select keyframes first")?;
|
||||
let dims = first["dims"].as_u64().unwrap_or(1).max(1) as usize;
|
||||
let side = |k: &str| -> (Vec<f64>, Vec<f64>, bool) {
|
||||
let a = first[k].as_array().cloned().unwrap_or_default();
|
||||
let has = a.iter().any(|e| !e.is_null());
|
||||
let sp = (0..dims).map(|d| a.get(d).map(|e| num(&e["speed"])).unwrap_or(0.0)).collect();
|
||||
let inf = (0..dims).map(|d| a.get(d).map(|e| num(&e["influence"])).filter(|v| *v > 0.0).unwrap_or(33.33)).collect();
|
||||
(sp, inf, has)
|
||||
};
|
||||
let (in_speed, in_inf, has_in) = side("inEase");
|
||||
let (out_speed, out_inf, has_out) = side("outEase");
|
||||
app.dialog_state.velocity = VelocityDraft {
|
||||
dims,
|
||||
units: first["units"].as_str().unwrap_or("units/sec").into(),
|
||||
name: first["name"].as_str().unwrap_or("").into(),
|
||||
in_speed,
|
||||
in_inf,
|
||||
out_speed,
|
||||
out_inf,
|
||||
has_in,
|
||||
has_out,
|
||||
continuous: first["continuous"].as_bool().unwrap_or(false),
|
||||
};
|
||||
app.dialog = Some(Dialog::KeyVelocity);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Animation ▸ Keyframe Interpolation… (⌥⌘K).
|
||||
pub fn open_interpolation(app: &mut EffectcraftApp) -> Result<(), String> {
|
||||
let info = app.session.execute("keys.info", json!({})).map_err(|e| e.to_string())?;
|
||||
let a = info.as_array().cloned().unwrap_or_default();
|
||||
if a.is_empty() {
|
||||
return Err("select keyframes first".into());
|
||||
}
|
||||
app.dialog_state.interp = InterpDraft { has_spatial: a.iter().any(|k| !k["spatial"].is_null()), count: a.len(), ..Default::default() };
|
||||
app.dialog = Some(Dialog::KeyInterpolation);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// Layer ▸ Time ▸ Time Stretch…
|
||||
pub fn open_time_stretch(app: &mut EffectcraftApp) -> Result<(), String> {
|
||||
let lid = *app.session.state.selected_layers.first().ok_or("select a layer first")?;
|
||||
let l = app.session.active_comp().and_then(|c| c.layer(lid)).ok_or("no layer")?;
|
||||
let dur = (l.out_point - l.in_point).seconds();
|
||||
app.dialog_state.stretch = StretchDraft { percent: l.stretch, duration: dur, hold: 0, orig_duration: dur, orig_percent: l.stretch };
|
||||
app.dialog = Some(Dialog::TimeStretch);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn buttons(ui: &mut egui::Ui, app: &mut EffectcraftApp, t: &Tokens, prefix: &str) -> (bool, bool) {
|
||||
let (mut ok, mut cancel) = (false, false);
|
||||
ui.add_space(14.0);
|
||||
ui.with_layout(egui::Layout::right_to_left(egui::Align::Center), |ui| {
|
||||
let r = ui.add(egui::Button::new(egui::RichText::new(" OK ").color(Color32::WHITE)).fill(t.accent));
|
||||
app.auto.add(&format!("{prefix}.ok"), r.rect, "OK");
|
||||
ok = r.clicked();
|
||||
let r = ui.button("Cancel");
|
||||
app.auto.add(&format!("{prefix}.cancel"), r.rect, "Cancel");
|
||||
cancel = r.clicked();
|
||||
});
|
||||
(ok, cancel)
|
||||
}
|
||||
|
||||
fn drag(ui: &mut egui::Ui, app: &mut EffectcraftApp, id: &str, v: &mut f64, speed: f64, range: std::ops::RangeInclusive<f64>, suffix: &str, enabled: bool) {
|
||||
let r = ui.add_enabled(enabled, egui::DragValue::new(v).speed(speed).range(range).max_decimals(2).suffix(suffix));
|
||||
app.auto.add(id, r.rect, id);
|
||||
}
|
||||
|
||||
pub fn velocity(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
let mut d = app.dialog_state.velocity.clone();
|
||||
let (mut ok, mut cancel) = (false, false);
|
||||
let title = if d.name.is_empty() { "Keyframe Velocity".to_string() } else { format!("Keyframe Velocity: {}", d.name) };
|
||||
let h = 250.0 + 2.0 * 26.0 * d.dims as f32;
|
||||
super::dialogs::modal(ctx, &title, vec2(440.0, h), t, |ui| {
|
||||
for (label, out) in [("Incoming Velocity", false), ("Outgoing Velocity", true)] {
|
||||
ui.label(egui::RichText::new(label).font(Tokens::medium(12.5)));
|
||||
let enabled = if out { d.has_out } else { d.has_in };
|
||||
egui::Grid::new(("vel", out)).num_columns(3).spacing([12.0, 6.0]).show(ui, |ui| {
|
||||
for dim in 0..d.dims {
|
||||
let tag = if d.dims > 1 { format!("Dimension {}", ["X", "Y", "Z", "W"][dim.min(3)]) } else { String::new() };
|
||||
ui.label(egui::RichText::new(tag).color(t.text_dim));
|
||||
let side = if out { "out" } else { "in" };
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Speed:");
|
||||
let v = if out { &mut d.out_speed[dim] } else { &mut d.in_speed[dim] };
|
||||
drag(ui, app, &format!("dialog.velocity.{side}Speed.{dim}"), v, 1.0, -1e7..=1e7, "", enabled);
|
||||
ui.label(egui::RichText::new(&d.units).color(t.text_dim));
|
||||
});
|
||||
ui.horizontal(|ui| {
|
||||
ui.label("Influence:");
|
||||
let v = if out { &mut d.out_inf[dim] } else { &mut d.in_inf[dim] };
|
||||
drag(ui, app, &format!("dialog.velocity.{side}Influence.{dim}"), v, 0.2, 0.1..=100.0, " %", enabled);
|
||||
});
|
||||
ui.end_row();
|
||||
}
|
||||
});
|
||||
ui.add_space(8.0);
|
||||
}
|
||||
let r = ui.checkbox(&mut d.continuous, "Continuous (Lock Outgoing to Incoming)");
|
||||
app.auto.add("dialog.velocity.continuous", r.rect, "Continuous");
|
||||
if d.continuous {
|
||||
d.out_speed = d.in_speed.clone();
|
||||
}
|
||||
(ok, cancel) = buttons(ui, app, t, "dialog.velocity");
|
||||
});
|
||||
app.dialog_state.velocity = d.clone();
|
||||
if ok || super::dialogs::ui_enter(ctx) {
|
||||
let mut params = json!({"continuous": d.continuous});
|
||||
if d.has_in {
|
||||
params["inSpeed"] = json!(d.in_speed);
|
||||
params["inInfluence"] = json!(d.in_inf);
|
||||
}
|
||||
if d.has_out {
|
||||
params["outSpeed"] = json!(d.out_speed);
|
||||
params["outInfluence"] = json!(d.out_inf);
|
||||
}
|
||||
if let Err(e) = app.session.execute("keys.velocity", params) {
|
||||
app.ui.status = e.to_string();
|
||||
}
|
||||
cancel = true;
|
||||
}
|
||||
if cancel {
|
||||
app.dialog = None;
|
||||
}
|
||||
}
|
||||
|
||||
fn combo(ui: &mut egui::Ui, app: &mut EffectcraftApp, id: &str, sel: &mut usize, opts: &[&str], enabled: bool) {
|
||||
ui.add_enabled_ui(enabled, |ui| {
|
||||
let r = egui::ComboBox::from_id_salt(id).width(200.0).selected_text(opts[*sel]).show_ui(ui, |ui| {
|
||||
for (i, o) in opts.iter().enumerate() {
|
||||
ui.selectable_value(sel, i, *o);
|
||||
}
|
||||
});
|
||||
app.auto.add(id, r.response.rect, id);
|
||||
});
|
||||
}
|
||||
|
||||
pub fn interpolation(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
let mut d = app.dialog_state.interp.clone();
|
||||
let (mut ok, mut cancel) = (false, false);
|
||||
super::dialogs::modal(ctx, "Keyframe Interpolation", vec2(440.0, 250.0), t, |ui| {
|
||||
egui::Grid::new("interp-grid").num_columns(2).spacing([14.0, 10.0]).show(ui, |ui| {
|
||||
ui.label("Temporal Interpolation:");
|
||||
combo(ui, app, "dialog.interpolation.temporal", &mut d.temporal, &TEMPORAL.map(|x| x.0), true);
|
||||
ui.end_row();
|
||||
ui.label("Spatial Interpolation:");
|
||||
combo(ui, app, "dialog.interpolation.spatial", &mut d.spatial, &SPATIAL.map(|x| x.0), d.has_spatial);
|
||||
ui.end_row();
|
||||
ui.label("Roving:");
|
||||
combo(ui, app, "dialog.interpolation.roving", &mut d.roving, &ROVING, d.has_spatial);
|
||||
ui.end_row();
|
||||
});
|
||||
ui.add_space(6.0);
|
||||
ui.label(egui::RichText::new(format!("{} keyframe{} selected", d.count, if d.count == 1 { "" } else { "s" })).color(t.text_dim));
|
||||
(ok, cancel) = buttons(ui, app, t, "dialog.interpolation");
|
||||
});
|
||||
app.dialog_state.interp = d.clone();
|
||||
if ok || super::dialogs::ui_enter(ctx) {
|
||||
let mut params = json!({});
|
||||
if d.temporal > 0 {
|
||||
params["interpolation"] = json!(TEMPORAL[d.temporal].1);
|
||||
}
|
||||
if d.spatial > 0 && d.has_spatial {
|
||||
params["spatial"] = json!(SPATIAL[d.spatial].1);
|
||||
}
|
||||
if d.roving > 0 && d.has_spatial {
|
||||
params["roving"] = json!(d.roving == 2);
|
||||
}
|
||||
if params.as_object().is_some_and(|m| !m.is_empty())
|
||||
&& let Err(e) = app.session.execute("keys.interpolation", params)
|
||||
{
|
||||
app.ui.status = e.to_string();
|
||||
}
|
||||
cancel = true;
|
||||
}
|
||||
if cancel {
|
||||
app.dialog = None;
|
||||
}
|
||||
}
|
||||
|
||||
pub fn time_stretch(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
let mut d = app.dialog_state.stretch.clone();
|
||||
let (mut ok, mut cancel) = (false, false);
|
||||
super::dialogs::modal(ctx, "Time Stretch", vec2(420.0, 300.0), t, |ui| {
|
||||
ui.label(egui::RichText::new("Stretch").font(Tokens::medium(12.5)));
|
||||
egui::Grid::new("stretch-grid").num_columns(2).spacing([14.0, 8.0]).show(ui, |ui| {
|
||||
ui.label("Original Duration:");
|
||||
ui.label(format!("{:.2} s", d.orig_duration));
|
||||
ui.end_row();
|
||||
ui.label("Stretch Factor:");
|
||||
let before = d.percent;
|
||||
drag(ui, app, "dialog.timeStretch.percent", &mut d.percent, 0.5, -10000.0..=10000.0, " %", true);
|
||||
if (before - d.percent).abs() > 1e-9 && d.orig_percent.abs() > 1e-9 {
|
||||
d.duration = d.orig_duration * d.percent.abs() / d.orig_percent.abs();
|
||||
}
|
||||
ui.end_row();
|
||||
ui.label("New Duration:");
|
||||
let before = d.duration;
|
||||
drag(ui, app, "dialog.timeStretch.duration", &mut d.duration, 0.05, 0.01..=100000.0, " s", true);
|
||||
if (before - d.duration).abs() > 1e-9 && d.orig_duration > 1e-9 {
|
||||
d.percent = d.orig_percent.signum() * d.orig_percent.abs() * d.duration / d.orig_duration;
|
||||
}
|
||||
ui.end_row();
|
||||
});
|
||||
ui.add_space(10.0);
|
||||
ui.label(egui::RichText::new("Hold In Place").font(Tokens::medium(12.5)));
|
||||
for (i, l) in ["Layer In-point", "Current Frame", "Layer Out-point"].into_iter().enumerate() {
|
||||
let r = ui.radio_value(&mut d.hold, i, l);
|
||||
app.auto.add(&format!("dialog.timeStretch.hold.{i}"), r.rect, l);
|
||||
}
|
||||
(ok, cancel) = buttons(ui, app, t, "dialog.timeStretch");
|
||||
});
|
||||
app.dialog_state.stretch = d.clone();
|
||||
if ok || super::dialogs::ui_enter(ctx) {
|
||||
let hold = ["in", "current", "out"][d.hold.min(2)];
|
||||
if let Err(e) = app.session.execute("layer.timeStretch", json!({"percent": d.percent, "hold": hold})) {
|
||||
app.ui.status = e.to_string();
|
||||
}
|
||||
cancel = true;
|
||||
}
|
||||
if cancel {
|
||||
app.dialog = None;
|
||||
}
|
||||
}
|
||||
@@ -3,7 +3,9 @@
|
||||
pub mod dialogs;
|
||||
pub mod effect_controls;
|
||||
pub mod effects_presets;
|
||||
pub mod graph;
|
||||
pub mod info;
|
||||
pub mod key_dialogs;
|
||||
pub mod misc;
|
||||
pub mod project;
|
||||
pub mod text_panels;
|
||||
|
||||
@@ -167,10 +167,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if resp.double_clicked() {
|
||||
match &it.kind {
|
||||
ItemKind::Comp(_) => actions.push(("comp.open".into(), json!({"comp": id.0}))),
|
||||
ItemKind::Folder => {
|
||||
if !app.ui.project_open_folders.remove(&id.0) {
|
||||
app.ui.project_open_folders.insert(id.0);
|
||||
}
|
||||
ItemKind::Folder if !app.ui.project_open_folders.remove(&id.0) => {
|
||||
app.ui.project_open_folders.insert(id.0);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,6 @@ struct Cols {
|
||||
label: f32,
|
||||
num: f32,
|
||||
name: f32,
|
||||
name_w: f32,
|
||||
switches: f32,
|
||||
mode: f32,
|
||||
trkmat: f32,
|
||||
@@ -61,22 +60,22 @@ fn cols(x0: f32, width: f32, show_modes: bool) -> Cols {
|
||||
let mode = switches + SW * 8.0 + 6.0;
|
||||
let trkmat = mode + if show_modes { 92.0 } else { 0.0 };
|
||||
let parent = trkmat + if show_modes { 112.0 } else { 0.0 };
|
||||
Cols { av, label, num, name, name_w, switches, mode, trkmat, parent, end: parent + 116.0 }
|
||||
Cols { av, label, num, name, switches, mode, trkmat, parent, end: parent + 116.0 }
|
||||
}
|
||||
|
||||
/// Timeline horizontal mapping.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
struct TMap {
|
||||
x0: f32,
|
||||
start: f64,
|
||||
pps: f64,
|
||||
pub(crate) struct TMap {
|
||||
pub x0: f32,
|
||||
pub start: f64,
|
||||
pub pps: f64,
|
||||
}
|
||||
|
||||
impl TMap {
|
||||
fn x(&self, secs: f64) -> f32 {
|
||||
pub fn x(&self, secs: f64) -> f32 {
|
||||
self.x0 + ((secs - self.start) * self.pps) as f32
|
||||
}
|
||||
fn t(&self, x: f32) -> f64 {
|
||||
pub fn t(&self, x: f32) -> f64 {
|
||||
self.start + (x - self.x0) as f64 / self.pps
|
||||
}
|
||||
}
|
||||
@@ -141,6 +140,10 @@ fn prop_visible(p: &Property, layer: &Layer) -> bool {
|
||||
if p.two_d_only && layer.is_3d() {
|
||||
return false;
|
||||
}
|
||||
// Separate Dimensions: X/Y/Z Position replace Position.
|
||||
if p.match_id == "position" && layer.transform().is_some_and(|tr| tr.get("positionX").is_some() && tr.get("position").is_some_and(|q| q.uid == p.uid)) {
|
||||
return false;
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
@@ -168,7 +171,7 @@ fn build_rows(app: &EffectcraftApp, comp: &Comp) -> Vec<Row> {
|
||||
}
|
||||
if let Some(kind) = tl.reveal.first() {
|
||||
let (group, props): (&str, Vec<&str>) = match kind.as_str() {
|
||||
"position" => ("transform", vec!["position"]),
|
||||
"position" => ("transform", vec!["position", "positionX", "positionY", "positionZ"]),
|
||||
"scale" => ("transform", vec!["scale"]),
|
||||
"rotation" => ("transform", vec!["rotation", "rotationX", "rotationY", "orientation"]),
|
||||
"opacity" => ("transform", vec!["opacity"]),
|
||||
@@ -439,7 +442,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let fd = comp.frame_duration().seconds();
|
||||
let cy0 = ruler.min.y + 11.0;
|
||||
let mut run: Option<(i64, i64)> = None;
|
||||
let mut draw_run = |a: i64, b: i64| {
|
||||
let draw_run = |a: i64, b: i64| {
|
||||
let x0 = tm.x(a as f64 * fd);
|
||||
let x1 = tm.x((b + 1) as f64 * fd);
|
||||
p.rect_filled(Rect::from_min_max(pos2(x0, cy0), pos2(x1, cy0 + 2.5)), 0.0, t.cache_green);
|
||||
@@ -785,10 +788,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if lin.hovered() || lout.hovered() || lin.dragged() || lout.dragged() {
|
||||
ctx.set_cursor_icon(egui::CursorIcon::ResizeHorizontal);
|
||||
}
|
||||
if body.clicked() || body.drag_started() {
|
||||
if !is_sel {
|
||||
actions.push(("layer.select".into(), json!({"layers": [layer.id.0], "add": ui.input(|i| i.modifiers.shift)})));
|
||||
}
|
||||
if (body.clicked() || body.drag_started()) && !is_sel {
|
||||
actions.push(("layer.select".into(), json!({"layers": [layer.id.0], "add": ui.input(|i| i.modifiers.shift)})));
|
||||
}
|
||||
layer_context_menu(&body, layer, &mut actions);
|
||||
let drag_key = format!("bar-{}", layer.id.0);
|
||||
@@ -1001,15 +1002,32 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
kresp.context_menu(|ui| {
|
||||
for (lbl, cmd, params) in [
|
||||
("Copy", "keys.copy", json!({})),
|
||||
("Paste", "keys.paste", json!({})),
|
||||
("-", "", json!({})),
|
||||
("Keyframe Interpolation…", "keys.interpolation", json!({})),
|
||||
("Keyframe Velocity…", "keys.velocity", json!({})),
|
||||
("Toggle Hold Keyframe", "keys.toggleHold", json!({})),
|
||||
("Rove Across Time", "keys.interpolation", json!({"roving": !k.roving})),
|
||||
("-", "", json!({})),
|
||||
("Easy Ease", "keys.easyEase", json!({})),
|
||||
("Easy Ease In", "keys.easyEaseIn", json!({})),
|
||||
("Easy Ease Out", "keys.easyEaseOut", json!({})),
|
||||
("Toggle Hold Keyframe", "keys.toggleHold", json!({})),
|
||||
("Time-Reverse Keyframes", "keys.timeReverse", json!({})),
|
||||
("-", "", json!({})),
|
||||
("Linear", "keys.interpolation", json!({"interpolation": "linear"})),
|
||||
("Bezier", "keys.interpolation", json!({"interpolation": "bezier"})),
|
||||
("Auto Bezier", "keys.interpolation", json!({"autoBezier": true})),
|
||||
("Auto Bezier", "keys.interpolation", json!({"interpolation": "autoBezier"})),
|
||||
("Select All Keyframes", "keys.selectAll", json!({})),
|
||||
("Delete", "keys.delete", json!({})),
|
||||
] {
|
||||
if lbl == "-" {
|
||||
ui.separator();
|
||||
continue;
|
||||
}
|
||||
if lbl == "Rove Across Time" && !prop.spatial {
|
||||
continue;
|
||||
}
|
||||
if ui.button(lbl).clicked() {
|
||||
if !ks {
|
||||
actions.push(("keys.select".into(), json!({"keys": [{"layer": layer.id.0, "prop": uid, "time": k.time.seconds()}]})));
|
||||
@@ -1041,15 +1059,16 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
// Graph editor.
|
||||
if graph_on {
|
||||
graph_editor(app, ui, &gp, &comp, &ectx, tm, Rect::from_min_max(pos2(graph_x0, rows_rect.min.y), rows_rect.max));
|
||||
super::graph::show(app, ui, &gp, &comp, &ectx, tm, Rect::from_min_max(pos2(graph_x0, rows_rect.min.y), rows_rect.max), &mut actions);
|
||||
}
|
||||
// Empty-area click in the graph: deselect keys; drag: box-select keys.
|
||||
let empty = ui.interact(Rect::from_min_max(pos2(graph_x0, rows_rect.min.y), rows_rect.max), egui::Id::new("tl-graph-bg"), Sense::click_and_drag());
|
||||
let empty_rect = if graph_on { Rect::NOTHING } else { Rect::from_min_max(pos2(graph_x0, rows_rect.min.y), rows_rect.max) };
|
||||
let empty = ui.interact(empty_rect, egui::Id::new("tl-graph-bg"), Sense::click_and_drag());
|
||||
if empty.clicked() {
|
||||
actions.push(("keys.select".into(), json!({"keys": []})));
|
||||
}
|
||||
if let (true, Some(origin), Some(cur)) =
|
||||
(empty.dragged(), empty.interact_pointer_pos().map(|_| ctx.input(|i| i.pointer.press_origin())).flatten(), empty.interact_pointer_pos())
|
||||
(empty.dragged(), empty.interact_pointer_pos().and_then(|_| ctx.input(|i| i.pointer.press_origin())), empty.interact_pointer_pos())
|
||||
{
|
||||
let br = Rect::from_two_pos(origin, cur);
|
||||
gp.rect_filled(br, 0.0, t.accent.gamma_multiply(0.12));
|
||||
@@ -1188,6 +1207,10 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
}
|
||||
for (id, params) in actions {
|
||||
if id == "__endMerge" {
|
||||
app.session.history.merge_key = None;
|
||||
continue;
|
||||
}
|
||||
if let Err(e) = crate::menus::invoke(app, &ctx, &id, params) {
|
||||
app.ui.status = e;
|
||||
}
|
||||
@@ -1257,7 +1280,11 @@ fn layer_context_menu(resp: &egui::Response, layer: &Layer, actions: &mut Vec<(S
|
||||
item(ui, "Flip Vertical", "layer.transform", json!({"layers": [id], "op": "flipV"}));
|
||||
});
|
||||
ui.menu_button("Time", |ui| {
|
||||
item(ui, "Time-Reverse Layer", "layer.timeStretch", json!({"layers": [id], "op": "reverse"}));
|
||||
item(ui, "Enable Time Remapping", "layer.enableTimeRemap", json!({"layers": [id]}));
|
||||
item(ui, "Time-Reverse Layer", "layer.timeReverse", json!({"layers": [id]}));
|
||||
item(ui, "Time Stretch…", "layer.timeStretch", json!({}));
|
||||
item(ui, "Freeze Frame", "layer.freezeFrame", json!({"layers": [id]}));
|
||||
item(ui, "Freeze on Last Frame", "layer.freezeOnLastFrame", json!({"layers": [id]}));
|
||||
});
|
||||
ui.menu_button("Blending Mode", |ui| {
|
||||
for m in BlendMode::ALL {
|
||||
@@ -1412,86 +1439,3 @@ fn value_editor(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Value graph of the selected properties (numeric dimensions over time) with key markers.
|
||||
fn graph_editor(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter, comp: &Comp, ectx: &EvalCtx, tm: TMap, area: Rect) {
|
||||
let t = app.tokens;
|
||||
let props: Vec<(LayerId, u64)> = if app.session.state.selected_props.is_empty() {
|
||||
// Default: animated properties of selected layers.
|
||||
let mut v = vec![];
|
||||
for l in comp.layers.iter().filter(|l| app.session.state.selected_layers.contains(&l.id)) {
|
||||
l.props.walk("", &mut |_, pr| {
|
||||
if pr.is_animated() && !pr.value.components().is_empty() {
|
||||
v.push((l.id, pr.uid));
|
||||
}
|
||||
});
|
||||
}
|
||||
v
|
||||
} else {
|
||||
app.session.state.selected_props.clone()
|
||||
};
|
||||
p.rect_filled(area, 0.0, Color32::from_rgb(0x1e, 0x1e, 0x1e));
|
||||
// Grid.
|
||||
for i in 1..8 {
|
||||
let y = area.min.y + area.height() * i as f32 / 8.0;
|
||||
p.line_segment([pos2(area.min.x, y), pos2(area.max.x, y)], Stroke::new(1.0, Color32::from_white_alpha(10)));
|
||||
}
|
||||
if props.is_empty() {
|
||||
p.text(area.center(), Align2::CENTER_CENTER, "Select animated properties to show them in the Graph Editor", Tokens::ui(12.0), t.text_faint);
|
||||
return;
|
||||
}
|
||||
let colors =
|
||||
[Color32::from_rgb(0xe0, 0x50, 0x50), Color32::from_rgb(0x60, 0xd0, 0x60), Color32::from_rgb(0x50, 0x8c, 0xf0), Color32::from_rgb(0xe8, 0xc8, 0x40)];
|
||||
// Sample all curves over the visible span; normalise to a common range.
|
||||
let n = ((area.width() / 2.0) as usize).max(2);
|
||||
let mut curves: Vec<(Vec<Vec<f64>>, &Layer, &Property)> = vec![];
|
||||
let (mut lo, mut hi) = (f64::INFINITY, f64::NEG_INFINITY);
|
||||
for (lid, uid) in &props {
|
||||
let Some(l) = comp.layer(*lid) else { continue };
|
||||
let Some(pr) = l.props.find(*uid) else { continue };
|
||||
let mut dims: Vec<Vec<f64>> = vec![];
|
||||
for i in 0..n {
|
||||
let x = area.min.x + area.width() * i as f32 / (n - 1) as f32;
|
||||
let tt = Tick::from_seconds_f64(tm.t(x));
|
||||
let v = ectx.at(tt).value(l, pr).components();
|
||||
if dims.is_empty() {
|
||||
dims = vec![Vec::with_capacity(n); v.len().min(3)];
|
||||
}
|
||||
for (d, c) in v.iter().take(dims.len()).enumerate() {
|
||||
dims[d].push(*c);
|
||||
lo = lo.min(*c);
|
||||
hi = hi.max(*c);
|
||||
}
|
||||
}
|
||||
curves.push((dims, l, pr));
|
||||
}
|
||||
if !lo.is_finite() || !hi.is_finite() {
|
||||
return;
|
||||
}
|
||||
if (hi - lo).abs() < 1e-9 {
|
||||
hi = lo + 1.0;
|
||||
}
|
||||
let pad = (hi - lo) * 0.1;
|
||||
let (lo, hi) = (lo - pad, hi + pad);
|
||||
let ymap = |v: f64| area.max.y - ((v - lo) / (hi - lo)) as f32 * area.height();
|
||||
for (dims, l, pr) in &curves {
|
||||
for (d, vals) in dims.iter().enumerate() {
|
||||
let pts: Vec<Pos2> = vals.iter().enumerate().map(|(i, v)| pos2(area.min.x + area.width() * i as f32 / (n - 1) as f32, ymap(*v))).collect();
|
||||
p.add(egui::Shape::line(pts, Stroke::new(1.5, colors[d % colors.len()])));
|
||||
}
|
||||
for k in &pr.keys {
|
||||
let x = tm.x(l.comp_time(k.time).seconds());
|
||||
for (d, v) in k.value.components().iter().take(dims.len()).enumerate() {
|
||||
let c = pos2(x, ymap(*v));
|
||||
p.rect_filled(Rect::from_center_size(c, vec2(6.0, 6.0)), 0.0, Color32::WHITE);
|
||||
p.rect_stroke(Rect::from_center_size(c, vec2(6.0, 6.0)), 0.0, Stroke::new(1.0, colors[d % colors.len()]), StrokeKind::Outside);
|
||||
}
|
||||
}
|
||||
}
|
||||
// Value labels.
|
||||
for i in 0..=4 {
|
||||
let v = lo + (hi - lo) * i as f64 / 4.0;
|
||||
p.text(pos2(area.min.x + 4.0, ymap(v)), Align2::LEFT_BOTTOM, format!("{v:.1}"), Tokens::ui(10.0), t.text_faint);
|
||||
}
|
||||
let _ = ui;
|
||||
}
|
||||
|
||||
@@ -56,7 +56,7 @@ pub fn last_fit(ctx: &egui::Context) -> f32 {
|
||||
#[derive(Clone, Debug)]
|
||||
enum Gesture {
|
||||
Move { layers: Vec<(LayerId, [f64; 3], Mat3)>, start: [f64; 2] },
|
||||
Scale { layer: LayerId, anchor_screen: Pos2, start_scale: [f64; 3], start_local: [f64; 2], inv: Mat3, uniform: bool },
|
||||
Scale { layer: LayerId, start_scale: [f64; 3], start_local: [f64; 2], inv: Mat3 },
|
||||
Rotate { layer: LayerId, center: Pos2, start_angle: f64, start_rot: f64 },
|
||||
Anchor { layer: LayerId, start_anchor: [f64; 3], start_pos: [f64; 3], start: [f64; 2], inv: Mat3, l2p: Mat3 },
|
||||
Pan { start_pan: [f32; 2] },
|
||||
@@ -436,17 +436,9 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let (l2c, _) = ectx.layer_to_comp(&layer);
|
||||
let inv = l2c.inverse()?;
|
||||
let a = ectx.v3(&layer, tr, "anchor", [0.0; 3]);
|
||||
let ac = l2c.apply(gv2(a[0], a[1]));
|
||||
let lp = inv.apply(gv2(cpt[0], cpt[1]));
|
||||
let _ = hi;
|
||||
Some(Gesture::Scale {
|
||||
layer: lid,
|
||||
anchor_screen: map.to_screen([ac.x, ac.y]),
|
||||
start_scale: ectx.v3(&layer, tr, "scale", [100.0; 3]),
|
||||
start_local: [lp.x - a[0], lp.y - a[1]],
|
||||
inv,
|
||||
uniform: hi < 4,
|
||||
})
|
||||
Some(Gesture::Scale { layer: lid, start_scale: ectx.v3(&layer, tr, "scale", [100.0; 3]), start_local: [lp.x - a[0], lp.y - a[1]], inv })
|
||||
})
|
||||
} else if let Some(l) = pick(app, &ectx, cpt, mods.shift) {
|
||||
let layers: Vec<(LayerId, [f64; 3], Mat3)> = app
|
||||
@@ -491,14 +483,14 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let _ = app.session.execute("prop.set", json!({"layer": lid.0, "path": "transform/position", "value": v, "merge": merge}));
|
||||
}
|
||||
}
|
||||
Gesture::Scale { layer, start_scale, start_local, inv, uniform, .. } => {
|
||||
Gesture::Scale { layer, start_scale, start_local, inv, .. } => {
|
||||
let lp = inv.apply(gv2(cpt[0], cpt[1]));
|
||||
// Local point relative to the anchor in *unscaled* layer space.
|
||||
let a = comp.layer(layer).and_then(|l| l.transform().map(|tr| ectx.v3(l, tr, "anchor", [0.0; 3]))).unwrap_or([0.0; 3]);
|
||||
let cur = [lp.x - a[0], lp.y - a[1]];
|
||||
let fx = if start_local[0].abs() > 1e-6 { cur[0] / start_local[0] } else { 1.0 };
|
||||
let fy = if start_local[1].abs() > 1e-6 { cur[1] / start_local[1] } else { 1.0 };
|
||||
let (fx, fy) = if mods.shift || uniform && start_local[0].abs() > 1e-6 && start_local[1].abs() > 1e-6 && mods.shift {
|
||||
let (fx, fy) = if mods.shift {
|
||||
let f = (fx + fy) / 2.0;
|
||||
(f, f)
|
||||
} else {
|
||||
@@ -847,7 +839,7 @@ fn bottom_bar(app: &mut EffectcraftApp, ui: &mut egui::Ui, bar: Rect, zoom: f32,
|
||||
app.ui.viewer.res = Resolution::ALL[i];
|
||||
}
|
||||
x = r.max.x + 6.0;
|
||||
if tog(ui, &mut app.auto, &mut x, Icon::Region, false, "roi", "Region of Interest") {}
|
||||
let _ = tog(ui, &mut app.auto, &mut x, Icon::Region, false, "roi", "Region of Interest");
|
||||
if tog(ui, &mut app.auto, &mut x, Icon::Checker, app.ui.viewer.transparency_grid, "transparency", "Toggle Transparency Grid") {
|
||||
app.ui.viewer.transparency_grid = !app.ui.viewer.transparency_grid;
|
||||
}
|
||||
|
||||
@@ -249,6 +249,28 @@ pub struct TimelineState {
|
||||
pub open_groups: BTreeSet<u64>,
|
||||
/// "Reveal" filter: only show these property match ids (P/S/R/T/A…) — empty = normal.
|
||||
pub reveal: Vec<String>,
|
||||
/// Graph Editor: `value` or `speed` graph.
|
||||
#[serde(default = "value_graph")]
|
||||
pub graph_mode: String,
|
||||
/// Show only the selected properties (else every animated property of the selected layers).
|
||||
#[serde(default = "yes")]
|
||||
pub graph_show_selected: bool,
|
||||
/// Auto-zoom the graph height to the visible curves.
|
||||
#[serde(default = "yes")]
|
||||
pub graph_auto_zoom: bool,
|
||||
/// Manual graph value range (when auto-zoom is off).
|
||||
#[serde(default)]
|
||||
pub graph_range: Option<(f64, f64)>,
|
||||
/// Properties whose inline expression editor is collapsed.
|
||||
#[serde(default)]
|
||||
pub expr_closed: BTreeSet<u64>,
|
||||
}
|
||||
|
||||
fn value_graph() -> String {
|
||||
"value".into()
|
||||
}
|
||||
fn yes() -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
impl Default for TimelineState {
|
||||
@@ -264,6 +286,11 @@ impl Default for TimelineState {
|
||||
open_layers: BTreeSet::new(),
|
||||
open_groups: BTreeSet::new(),
|
||||
reveal: vec![],
|
||||
graph_mode: value_graph(),
|
||||
graph_show_selected: true,
|
||||
graph_auto_zoom: true,
|
||||
graph_range: None,
|
||||
expr_closed: BTreeSet::new(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user