Merge main into M13.6
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
+230
-41
@@ -110,6 +110,20 @@ pub struct Playback {
|
||||
pub shown: u64,
|
||||
pub waiting: bool,
|
||||
pub fps: f64,
|
||||
/// The Preview panel shortcut that started this preview and what it plays.
|
||||
pub shortcut: effectcraft_engine::preview::PreviewShortcut,
|
||||
pub plan: Option<effectcraft_engine::preview::PreviewPlan>,
|
||||
/// Cache Before Playback: rendering the range before the clock starts.
|
||||
pub caching: bool,
|
||||
/// Resolution override while playing (pixel step), `None` = the viewer's.
|
||||
pub res: Option<u32>,
|
||||
/// Include Overlays / Include Layer Controls.
|
||||
pub overlays: bool,
|
||||
pub layer_controls: bool,
|
||||
/// Full Screen: the maximized panel to restore when the preview stops.
|
||||
pub restore_max: Option<Option<PanelKind>>,
|
||||
/// Audio-only previews: the frame under the audible sample (the current time stays put).
|
||||
pub audio_frame: Option<i64>,
|
||||
}
|
||||
|
||||
pub struct EffectcraftApp {
|
||||
@@ -419,6 +433,19 @@ impl EffectcraftApp {
|
||||
|
||||
/// The render scale used by the viewer right now.
|
||||
pub fn viewer_scale(&self, zoom: f32, ppp: f32) -> f64 {
|
||||
// The preview's Resolution (when not Auto) while it plays.
|
||||
if self.playback.playing
|
||||
&& let Some(f) = self.playback.res
|
||||
{
|
||||
let r = match f {
|
||||
1 => state::Resolution::Full,
|
||||
2 => state::Resolution::Half,
|
||||
3 => state::Resolution::Third,
|
||||
4 => state::Resolution::Quarter,
|
||||
n => state::Resolution::Custom(n.min(40) as u8),
|
||||
};
|
||||
return r.scale(zoom, ppp);
|
||||
}
|
||||
if self.playback.playing && self.ui.viewer.res == state::Resolution::Auto {
|
||||
// Keep previews snappy: half the displayed size, but no lower than Settings ▸
|
||||
// Previews ▸ Adaptive Resolution Limit.
|
||||
@@ -510,64 +537,163 @@ impl EffectcraftApp {
|
||||
// ---------------------------------------------------------------- playback
|
||||
|
||||
pub fn play(&mut self, now: f64) {
|
||||
let sc = self.session.prefs.preview.current;
|
||||
self.play_with(now, sc);
|
||||
}
|
||||
|
||||
/// Start the preview of a Preview panel shortcut (its range, play-from, rate, skip,
|
||||
/// resolution, loop, caching, full screen and include options).
|
||||
pub fn play_with(&mut self, now: f64, sc: effectcraft_engine::preview::PreviewShortcut) {
|
||||
let Some(c) = self.session.active_comp().cloned() else { return };
|
||||
let mut t = self.session.time();
|
||||
let (wa, wb) = c.work_area;
|
||||
if t >= wb - c.frame_duration() || t < wa {
|
||||
t = wa;
|
||||
let preset = self.session.prefs.preview.get(sc).clone();
|
||||
let plan = effectcraft_engine::preview::plan(&preset, &c, self.session.time());
|
||||
let fr = c.frame_rate;
|
||||
if plan.video {
|
||||
self.session.set_time(fr.tick_of(plan.first));
|
||||
}
|
||||
let restore_max = preset.full_screen.then_some(self.ui.maximized);
|
||||
if preset.full_screen && self.ui.dock.contains(PanelKind::Composition) {
|
||||
self.ui.maximized = Some(PanelKind::Composition);
|
||||
}
|
||||
self.session.set_time(t);
|
||||
self.playback = Playback {
|
||||
playing: true,
|
||||
start_wall: now,
|
||||
start_time: t,
|
||||
start_frame: c.frame_rate.frame_at(t),
|
||||
start_time: fr.tick_of(plan.first),
|
||||
start_frame: plan.first,
|
||||
shown: 0,
|
||||
waiting: false,
|
||||
fps: c.frame_rate.as_f64(),
|
||||
fps: plan.fps,
|
||||
shortcut: sc,
|
||||
plan: Some(plan),
|
||||
caching: plan.cache_first && plan.video,
|
||||
res: preset.resolution.factor(preset.custom_resolution),
|
||||
overlays: preset.include_overlays,
|
||||
layer_controls: preset.include_layer_controls,
|
||||
restore_max,
|
||||
audio_frame: (!plan.video).then_some(plan.first),
|
||||
};
|
||||
self.start_audio(t);
|
||||
if !self.playback.caching {
|
||||
self.start_audio(fr.tick_of(plan.first));
|
||||
}
|
||||
}
|
||||
|
||||
/// Start audio preview from comp time `t` when the Preview panel includes audio, the comp
|
||||
/// has something audible and an output device opens.
|
||||
/// Start audio preview from comp time `t` when the preview includes audio at the comp's
|
||||
/// frame rate, the comp has something audible and an output device opens.
|
||||
fn start_audio(&mut self, t: Tick) {
|
||||
self.audio = None;
|
||||
self.meter.clipped = [false; 2];
|
||||
if !self.ui.preview_audio {
|
||||
let Some(pl) = self.playback.plan else { return };
|
||||
if !pl.audio {
|
||||
return;
|
||||
}
|
||||
let Some(cid) = self.session.active_comp_id() else { return };
|
||||
let Some(c) = self.session.project.comp(cid).cloned() else { return };
|
||||
// A preview at another frame rate plays slower or faster than real time: silent.
|
||||
if (pl.fps - c.frame_rate.as_f64()).abs() > 0.01 {
|
||||
return;
|
||||
}
|
||||
if !effectcraft_engine::render::audio::comp_has_audio(&self.session.project, cid) {
|
||||
return;
|
||||
}
|
||||
let out = audio::AudioOutput::from_prefs(&self.session.prefs);
|
||||
let Some(dev) = self.hooks.audio_device.as_ref().and_then(|f| f(&out)) else { return };
|
||||
let mix = self.session.prefs.audio.preview_sample_rate;
|
||||
match audio::AudioPlayback::start(dev, self.render_source(), cid, t, c.work_area.0, c.work_area.1, self.ui.preview_loop, mix) {
|
||||
let fr = c.frame_rate;
|
||||
match audio::AudioPlayback::start(dev, self.render_source(), cid, t, fr.tick_of(pl.start), fr.tick_of(pl.end + 1), pl.looping, mix) {
|
||||
Ok(a) => self.audio = Some(a),
|
||||
Err(e) => log::warn!("audio preview: {e}"),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn stop(&mut self) {
|
||||
self.playback.playing = false;
|
||||
let was = std::mem::replace(&mut self.playback.playing, false);
|
||||
self.audio = None;
|
||||
self.playback.caching = false;
|
||||
if !was {
|
||||
return;
|
||||
}
|
||||
if let Some(m) = self.playback.restore_max.take() {
|
||||
self.ui.maximized = m;
|
||||
}
|
||||
let Some(pl) = self.playback.plan else { return };
|
||||
let move_time = self.session.prefs.preview.get(self.playback.shortcut).move_time_to_preview_time;
|
||||
if !move_time {
|
||||
self.session.set_time(pl.origin);
|
||||
} else if let Some(f) = self.playback.audio_frame
|
||||
&& let Some(c) = self.session.active_comp()
|
||||
{
|
||||
let t = c.frame_rate.tick_of(f);
|
||||
self.session.set_time(t);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn toggle_play(&mut self, now: f64) {
|
||||
if self.playback.playing { self.stop() } else { self.play(now) }
|
||||
let sc = self.session.prefs.preview.current;
|
||||
self.toggle_play_with(now, sc);
|
||||
}
|
||||
|
||||
/// RAM preview: advance at the comp frame rate when frames are cached; otherwise hold and
|
||||
/// keep rendering ahead (the green cache bar fills, then playback runs in real time).
|
||||
/// A preview shortcut pressed: start its preview, or stop the running one. While Cache
|
||||
/// Before Playback is still rendering, "If caching, play cached frames" plays what is
|
||||
/// cached so far instead of stopping.
|
||||
pub fn toggle_play_with(&mut self, now: f64, sc: effectcraft_engine::preview::PreviewShortcut) {
|
||||
if !self.playback.playing {
|
||||
self.play_with(now, sc);
|
||||
return;
|
||||
}
|
||||
if self.playback.caching && self.session.prefs.preview.get(self.playback.shortcut).play_cached_frames && self.play_cached(now) {
|
||||
return;
|
||||
}
|
||||
self.stop();
|
||||
}
|
||||
|
||||
/// Cut the caching preview down to the frames cached from its first frame on and play them.
|
||||
fn play_cached(&mut self, now: f64) -> bool {
|
||||
let (Some(mut pl), Some(cid)) = (self.playback.plan, self.session.active_comp_id()) else { return false };
|
||||
let scale = self.viewer_shown.as_ref().map(|(_, k)| k.scale as f64 / 1000.0).unwrap_or(1.0);
|
||||
let mut last = None;
|
||||
let mut f = pl.first;
|
||||
while f <= pl.end && self.frames.is_cached(&self.frame_key(cid, f, scale)) {
|
||||
last = Some(f);
|
||||
f += pl.step;
|
||||
}
|
||||
let Some(last) = last else { return false };
|
||||
pl.end = last;
|
||||
pl.start = pl.first;
|
||||
self.playback.plan = Some(pl);
|
||||
self.playback.caching = false;
|
||||
self.playback.start_wall = now;
|
||||
self.playback.start_frame = pl.first;
|
||||
let t = self.session.active_comp().map(|c| c.frame_rate.tick_of(pl.first)).unwrap_or_default();
|
||||
self.start_audio(t);
|
||||
true
|
||||
}
|
||||
|
||||
/// The viewer shows grids, guides and safe margins (hidden while a preview without
|
||||
/// Include Overlays plays).
|
||||
pub fn overlays_visible(&self) -> bool {
|
||||
!self.playback.playing || self.playback.overlays
|
||||
}
|
||||
|
||||
/// The viewer shows layer handles and paths (View ▸ Show Layer Controls, and Include Layer
|
||||
/// Controls while a preview plays).
|
||||
pub fn layer_controls_visible(&self) -> bool {
|
||||
self.ui.viewer.show_layer_controls && (!self.playback.playing || self.playback.layer_controls)
|
||||
}
|
||||
|
||||
/// RAM preview: advance at the preview's frame rate when frames are cached; otherwise hold
|
||||
/// and keep rendering ahead (the green cache bar fills, then playback runs in real time).
|
||||
fn advance_playback(&mut self, ctx: &egui::Context, scale: f64) {
|
||||
let Some(cid) = self.session.active_comp_id() else { return };
|
||||
let Some(c) = self.session.project.comp(cid).cloned() else { return };
|
||||
let now = ctx.input(|i| i.time);
|
||||
let fr = c.frame_rate;
|
||||
let (wa, wb) = (fr.frame_at(c.work_area.0), fr.frame_at(c.work_area.1 - c.frame_duration()));
|
||||
let plan = self.playback.plan.filter(|_| self.playback.playing);
|
||||
let (wa, wb) = match plan {
|
||||
Some(p) => (p.start, p.end),
|
||||
None => (fr.frame_at(c.work_area.0), fr.frame_at(c.work_area.1 - c.frame_duration())),
|
||||
};
|
||||
let looping = plan.is_none_or(|p| p.looping);
|
||||
let video = plan.is_none_or(|p| p.video);
|
||||
// Prefetch ahead.
|
||||
let cur = fr.frame_at(self.session.time());
|
||||
// While paused (scrubbing, editing) the viewer's frame comes first: prefetch only a few
|
||||
@@ -580,17 +706,53 @@ impl EffectcraftApp {
|
||||
(self.frames_parallelism() / 2).max(2) as i64
|
||||
};
|
||||
let mut queued = self.frames.inflight();
|
||||
if self.playback.caching
|
||||
&& let Some(p) = plan
|
||||
{
|
||||
// Cache Before Playback: the whole range in play order, then start the clock.
|
||||
let mut all = true;
|
||||
let n = (p.end - p.start) / p.step + 1;
|
||||
let order: Vec<i64> = (0..n).filter_map(|k| p.frame_after(p.first, k)).collect();
|
||||
for f in order {
|
||||
let key = self.frame_key(cid, f, scale);
|
||||
if self.frames.is_cached(&key) {
|
||||
continue;
|
||||
}
|
||||
all = false;
|
||||
if queued < ahead as usize {
|
||||
self.request_frame(cid, f, scale);
|
||||
queued += 1;
|
||||
}
|
||||
}
|
||||
self.playback.waiting = !all;
|
||||
if all {
|
||||
self.playback.caching = false;
|
||||
self.playback.start_wall = now;
|
||||
self.playback.start_frame = p.first;
|
||||
self.session.set_time(fr.tick_of(p.first));
|
||||
self.start_audio(fr.tick_of(p.first));
|
||||
}
|
||||
ctx.request_repaint();
|
||||
return;
|
||||
}
|
||||
let step = plan.map_or(1, |p| p.step);
|
||||
for k in 0..ahead * 3 {
|
||||
if queued >= ahead as usize {
|
||||
if queued >= ahead as usize || !video {
|
||||
break;
|
||||
}
|
||||
let mut f = cur + k;
|
||||
if f > wb {
|
||||
if !self.ui.preview_loop {
|
||||
break;
|
||||
let f = match plan {
|
||||
Some(p) => match p.frame_after(cur, k) {
|
||||
Some(f) => f,
|
||||
None => break,
|
||||
},
|
||||
None => {
|
||||
let mut f = cur + k;
|
||||
if f > wb {
|
||||
f = wa + (f - wb - 1).rem_euclid((wb - wa + 1).max(1));
|
||||
}
|
||||
f
|
||||
}
|
||||
f = wa + (f - wb - 1).rem_euclid((wb - wa + 1).max(1));
|
||||
}
|
||||
};
|
||||
let key = self.frame_key(cid, f, scale);
|
||||
if !self.frames.is_cached(&key) {
|
||||
self.request_frame(cid, f, scale);
|
||||
@@ -607,33 +769,61 @@ impl EffectcraftApp {
|
||||
if !self.playback.playing {
|
||||
return;
|
||||
}
|
||||
let snap = |f: i64| wa + (f - wa).div_euclid(step) * step;
|
||||
// Audio clock drives playback: show the frame under the audible sample (frames that
|
||||
// are not rendered yet are dropped, never delayed).
|
||||
if let Some(a) = &self.audio {
|
||||
if a.finished() {
|
||||
self.session.set_time(fr.tick_of(wb));
|
||||
if video {
|
||||
self.session.set_time(fr.tick_of(wb));
|
||||
} else {
|
||||
self.playback.audio_frame = Some(wb);
|
||||
}
|
||||
self.stop();
|
||||
return;
|
||||
}
|
||||
let target = audio::frame_of_sample(a.clock(), a.rate, fr).clamp(wa, wb);
|
||||
self.playback.waiting = !self.frames.is_cached(&self.frame_key(cid, target, scale));
|
||||
if target != cur {
|
||||
self.session.set_time(fr.tick_of(target));
|
||||
self.playback.shown += 1;
|
||||
let target = snap(audio::frame_of_sample(a.clock(), a.rate, fr).clamp(wa, wb));
|
||||
if !video {
|
||||
self.playback.audio_frame = Some(target);
|
||||
} else {
|
||||
self.playback.waiting = !self.frames.is_cached(&self.frame_key(cid, target, scale));
|
||||
if target != cur {
|
||||
self.session.set_time(fr.tick_of(target));
|
||||
self.playback.shown += 1;
|
||||
}
|
||||
}
|
||||
ctx.request_repaint();
|
||||
return;
|
||||
}
|
||||
let elapsed = now - self.playback.start_wall;
|
||||
let mut target = self.playback.start_frame + (elapsed * fr.as_f64()).floor() as i64;
|
||||
if target > wb {
|
||||
if self.ui.preview_loop {
|
||||
target = wa + (target - wa).rem_euclid((wb - wa + 1).max(1));
|
||||
} else {
|
||||
self.session.set_time(fr.tick_of(wb));
|
||||
self.stop();
|
||||
return;
|
||||
let n = ((elapsed * self.playback.fps) / step as f64).floor() as i64;
|
||||
let target = match plan {
|
||||
Some(p) => p.frame_after(self.playback.start_frame, n),
|
||||
None => {
|
||||
let t = self.playback.start_frame + n;
|
||||
if t <= wb {
|
||||
Some(t)
|
||||
} else if looping {
|
||||
Some(wa + (t - wa).rem_euclid((wb - wa + 1).max(1)))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
}
|
||||
};
|
||||
let Some(target) = target else {
|
||||
if video {
|
||||
self.session.set_time(fr.tick_of(wb));
|
||||
} else {
|
||||
self.playback.audio_frame = Some(wb);
|
||||
}
|
||||
self.stop();
|
||||
return;
|
||||
};
|
||||
if !video {
|
||||
// Audio-only preview without an audio device: the clock runs, the time stays.
|
||||
self.playback.audio_frame = Some(target);
|
||||
ctx.request_repaint();
|
||||
return;
|
||||
}
|
||||
let key = self.frame_key(cid, target, scale);
|
||||
if self.frames.is_cached(&key) {
|
||||
@@ -645,8 +835,7 @@ impl EffectcraftApp {
|
||||
} else {
|
||||
// Not cached yet: hold the clock at the current frame (cache first, then play).
|
||||
self.playback.waiting = true;
|
||||
let next = cur + 1;
|
||||
let next = if next > wb { wa } else { next };
|
||||
let next = plan.and_then(|p| p.frame_after(cur, 1)).unwrap_or(if cur + 1 > wb { wa } else { cur + 1 });
|
||||
if self.frames.is_cached(&self.frame_key(cid, next, scale)) {
|
||||
self.session.set_time(fr.tick_of(next));
|
||||
}
|
||||
|
||||
@@ -27,7 +27,10 @@ macro_rules! uic {
|
||||
|
||||
/// UI-only commands (not in the AE menus; shortcuts and the command palette).
|
||||
pub const UI_COMMANDS: &[UiCommand] = &[
|
||||
uic!("playback.ramPreview", "Play Current Preview", [], Some("Num0")),
|
||||
uic!("playback.ramPreview", "Preview (Numpad 0)", [], Some("Num0")),
|
||||
uic!("playback.preview.shiftSpacebar", "Preview (Shift+Spacebar)", [], Some("Shift+Space")),
|
||||
uic!("playback.preview.shiftNumpad0", "Preview (Shift+Numpad 0)", [], Some("Shift+Num0")),
|
||||
uic!("playback.preview.altNumpad0", "Preview (Alt+Numpad 0)", [], Some("Alt+Num0")),
|
||||
uic!("playback.stop", "Stop", [], None),
|
||||
uic!("view.fit", "Fit", [], Some("Shift+/")),
|
||||
uic!("view.actualSize", "100%", [], Some("/")),
|
||||
@@ -290,7 +293,12 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V
|
||||
let timing = |app: &mut EffectcraftApp, op: &str| app.session.execute("layer.timing", json!({"op": op})).map_err(|e| e.to_string());
|
||||
match id {
|
||||
"playback.ramPreview" => {
|
||||
app.toggle_play(now);
|
||||
app.toggle_play_with(now, effectcraft_engine::preview::PreviewShortcut::Numpad0);
|
||||
return Ok(json!({"playing": app.playback.playing}));
|
||||
}
|
||||
"playback.preview.shiftSpacebar" | "playback.preview.shiftNumpad0" | "playback.preview.altNumpad0" => {
|
||||
let sc = effectcraft_engine::preview::PreviewShortcut::parse(id.trim_start_matches("playback.preview.")).ok_or("unknown preview shortcut")?;
|
||||
app.toggle_play_with(now, sc);
|
||||
return Ok(json!({"playing": app.playback.playing}));
|
||||
}
|
||||
"playback.stop" => {
|
||||
@@ -534,8 +542,14 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu
|
||||
Value::Null
|
||||
}
|
||||
"playback.toggle" => {
|
||||
app.toggle_play(now);
|
||||
json!({"playing": app.playback.playing})
|
||||
// The play button and Spacebar: `{shortcut?}` picks which Preview panel shortcut's
|
||||
// options to play with (default Spacebar).
|
||||
let sc = match p.get("shortcut").and_then(Value::as_str) {
|
||||
Some(k) => effectcraft_engine::preview::PreviewShortcut::parse(k).ok_or_else(|| format!("unknown preview shortcut `{k}`"))?,
|
||||
None => effectcraft_engine::preview::PreviewShortcut::Spacebar,
|
||||
};
|
||||
app.toggle_play_with(now, sc);
|
||||
json!({"playing": app.playback.playing, "shortcut": sc.id()})
|
||||
}
|
||||
"playback.cacheWhenIdle" => {
|
||||
let r = toggle(&mut app.ui.cache_when_idle, &p);
|
||||
@@ -543,8 +557,11 @@ pub fn frontend(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, p: Valu
|
||||
r
|
||||
}
|
||||
"playback.audio" => {
|
||||
let r = toggle(&mut app.ui.preview_audio, &p);
|
||||
if !app.ui.preview_audio {
|
||||
// Include Audio of the shortcut shown in the Preview panel.
|
||||
let mut on = app.session.prefs.preview.active().include_audio;
|
||||
let r = toggle(&mut on, &p);
|
||||
app.session.execute("playback.settings.set", json!({"includeAudio": on})).map_err(|e| e.to_string())?;
|
||||
if !on {
|
||||
app.audio = None;
|
||||
}
|
||||
r
|
||||
@@ -955,7 +972,7 @@ pub(crate) fn entry_checked(app: &EffectcraftApp, e: &MenuEntry) -> Option<bool>
|
||||
"view.snapToGrid" => Some(v.snap_grid),
|
||||
"view.layerControls" => Some(v.show_layer_controls),
|
||||
"playback.cacheWhenIdle" => Some(app.ui.cache_when_idle),
|
||||
"playback.audio" => Some(app.ui.preview_audio),
|
||||
"playback.audio" => Some(app.session.prefs.preview.active().include_audio),
|
||||
"view.res.full" | "view.res.half" | "view.res.third" | "view.res.quarter" => {
|
||||
Some(v.res.label().eq_ignore_ascii_case(e.command.trim_start_matches("view.res.")))
|
||||
}
|
||||
|
||||
@@ -294,7 +294,7 @@ pub fn state_key(app: &EffectcraftApp) -> u64 {
|
||||
let v = &app.ui.viewer;
|
||||
(v.rulers, v.guides, v.snap_guides, v.lock_guides, v.grid, v.snap_grid, v.show_layer_controls, v.pasteboard).hash(&mut h);
|
||||
v.res.label().hash(&mut h);
|
||||
(app.ui.cache_when_idle, app.ui.preview_audio, &app.ui.workspace, app.dialog.is_some()).hash(&mut h);
|
||||
(app.ui.cache_when_idle, app.session.prefs.preview.active().include_audio, &app.ui.workspace, app.dialog.is_some()).hash(&mut h);
|
||||
h.finish()
|
||||
}
|
||||
|
||||
|
||||
@@ -13,8 +13,11 @@ pub fn placeholder(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect, p: P
|
||||
ui.painter().text(rect.center(), Align2::CENTER_CENTER, format!("{} — coming soon", p.title()), Tokens::ui(12.0), t.text_faint);
|
||||
}
|
||||
|
||||
/// Preview panel: transport controls and RAM preview options.
|
||||
/// Preview panel: transport controls, the shortcut whose options are shown, and that
|
||||
/// shortcut's options (each Preview shortcut keeps its own; see `effectcraft_engine::preview`).
|
||||
/// Every change runs `playback.settings.set`.
|
||||
pub fn preview(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
use effectcraft_engine::preview::{PlayFrom, PreviewRange, PreviewResolution, PreviewShortcut};
|
||||
let t = app.tokens;
|
||||
let ctx = ui.ctx().clone();
|
||||
let p = ui.painter().with_clip_rect(rect);
|
||||
@@ -29,57 +32,248 @@ pub fn preview(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
(Icon::StepFwd, "time.nextFrame", "Next Frame"),
|
||||
(Icon::Last, "time.end", "Last Frame"),
|
||||
];
|
||||
let current = app.session.prefs.preview.current;
|
||||
for (icon, cmd, tip) in buttons {
|
||||
let r = Rect::from_min_size(pos2(x, y), vec2(bw, 28.0));
|
||||
let icon = if cmd == "playback.toggle" && app.playback.playing { Icon::Pause } else { icon };
|
||||
if widgets::icon_button(ui, r, icon, cmd == "playback.toggle" && app.playback.playing, &t, egui::Id::new(("pv", cmd))).on_hover_text(tip).clicked() {
|
||||
let _ = crate::menus::invoke(app, &ctx, cmd, json!({}));
|
||||
// The play button plays with the options of the shortcut shown below.
|
||||
let params = if cmd == "playback.toggle" { json!({"shortcut": current.id()}) } else { json!({}) };
|
||||
let _ = crate::menus::invoke(app, &ctx, cmd, params);
|
||||
}
|
||||
app.auto.add(&format!("preview.{}", tip.replace([' ', '/'], "")), r, tip);
|
||||
x += bw + 4.0;
|
||||
}
|
||||
let mut yy = y + 44.0;
|
||||
let row = |p: &egui::Painter, yy: f32, k: &str, v: &str| {
|
||||
p.text(pos2(rect.min.x + 12.0, yy), Align2::LEFT_CENTER, k, Tokens::ui(12.0), t.text_dim);
|
||||
p.text(pos2(rect.min.x + 130.0, yy), Align2::LEFT_CENTER, v, Tokens::ui(12.0), t.text);
|
||||
let o = app.session.prefs.preview.get(current).clone();
|
||||
let mut changes: Vec<serde_json::Value> = vec![];
|
||||
let x0 = rect.min.x + 12.0;
|
||||
let xv = rect.min.x + 92.0;
|
||||
let wv = (rect.max.x - xv - 12.0).clamp(80.0, 240.0);
|
||||
let label = |yy: f32, k: &str| {
|
||||
p.text(pos2(x0, yy), Align2::LEFT_CENTER, k, Tokens::ui(12.0), t.text_dim);
|
||||
};
|
||||
row(&p, yy, "Shortcut", "Spacebar");
|
||||
yy += 22.0;
|
||||
let lr = Rect::from_min_size(pos2(rect.min.x + 10.0, yy - 8.0), vec2(16.0, 16.0));
|
||||
if widgets::checkbox(ui, lr, app.ui.preview_loop, &t, egui::Id::new("pv-loop")).clicked() {
|
||||
app.ui.preview_loop = !app.ui.preview_loop;
|
||||
let mut yy = y + 46.0;
|
||||
|
||||
// Shortcut.
|
||||
label(yy, "Shortcut");
|
||||
let names: Vec<String> = PreviewShortcut::ALL.iter().map(|s| s.label().to_string()).collect();
|
||||
if let Some(i) = dropdown_row(
|
||||
app,
|
||||
ui,
|
||||
Rect::from_min_size(pos2(xv, yy - 10.0), vec2(wv, 20.0)),
|
||||
"shortcut",
|
||||
current.label(),
|
||||
&names,
|
||||
PreviewShortcut::ALL.iter().position(|s| *s == current),
|
||||
) {
|
||||
let s = PreviewShortcut::ALL[i];
|
||||
changes.push(json!({"shortcut": s.id(), "current": s.id()}));
|
||||
}
|
||||
app.auto.add("preview.loop", lr, "Loop");
|
||||
p.text(pos2(lr.max.x + 6.0, yy), Align2::LEFT_CENTER, "Loop", Tokens::ui(12.0), t.text);
|
||||
let ar = Rect::from_min_size(pos2(rect.min.x + 90.0, yy - 8.0), vec2(16.0, 16.0));
|
||||
if widgets::checkbox(ui, ar, app.ui.preview_audio, &t, egui::Id::new("pv-audio")).clicked() {
|
||||
let _ = crate::menus::invoke(app, &ctx, "playback.audio", json!({}));
|
||||
}
|
||||
app.auto.add("preview.audio", ar, "Include Audio");
|
||||
p.text(pos2(ar.max.x + 6.0, yy), Align2::LEFT_CENTER, "Include Audio", Tokens::ui(12.0), t.text);
|
||||
yy += 24.0;
|
||||
row(&p, yy, "Range", "Work Area Extended By Current Time");
|
||||
yy += 22.0;
|
||||
row(&p, yy, "Play From", "Current Time");
|
||||
yy += 22.0;
|
||||
let comp = app.session.active_comp().cloned();
|
||||
row(&p, yy, "Frame Rate", &comp.as_ref().map(|c| format!("({:.2})", c.frame_rate.as_f64())).unwrap_or_default());
|
||||
yy += 22.0;
|
||||
row(&p, yy, "Resolution", app.ui.viewer.res.label());
|
||||
yy += 26.0;
|
||||
if let Some(c) = comp {
|
||||
|
||||
// Include Video / Audio / Overlays / Layer Controls, Loop, Cache Before Playback.
|
||||
let checks: [(&str, &str, bool); 6] = [
|
||||
("includeVideo", "Video", o.include_video),
|
||||
("includeAudio", "Audio", o.include_audio),
|
||||
("includeOverlays", "Overlays", o.include_overlays),
|
||||
("includeLayerControls", "Layer Controls", o.include_layer_controls),
|
||||
("loop", "Loop", o.loop_),
|
||||
("cacheBeforePlayback", "Cache Before Playback", o.cache_before_playback),
|
||||
];
|
||||
for (i, (key, text, on)) in checks.into_iter().enumerate() {
|
||||
let col = if i < 4 { i % 2 } else { 0 };
|
||||
let row = if i < 4 { i / 2 } else { i - 2 };
|
||||
let cx = x0 + col as f32 * 110.0 - 2.0;
|
||||
let cy = yy + row as f32 * 22.0;
|
||||
if check_row(app, ui, &p, pos2(cx, cy), key, text, on) {
|
||||
changes.push(json!({"shortcut": current.id(), key: !on}));
|
||||
}
|
||||
}
|
||||
yy += 4.0 * 22.0 + 6.0;
|
||||
|
||||
// Range (and the pre/post-roll of Play Around Current Time).
|
||||
label(yy, "Range");
|
||||
let ranges: Vec<String> = PreviewRange::ALL.iter().map(|r| r.label().to_string()).collect();
|
||||
let range_ids = ["workArea", "workAreaExtended", "entireDuration", "aroundCurrentTime"];
|
||||
if let Some(i) = dropdown_row(
|
||||
app,
|
||||
ui,
|
||||
Rect::from_min_size(pos2(xv, yy - 10.0), vec2(wv, 20.0)),
|
||||
"range",
|
||||
o.range.label(),
|
||||
&ranges,
|
||||
PreviewRange::ALL.iter().position(|r| *r == o.range),
|
||||
) {
|
||||
changes.push(json!({"shortcut": current.id(), "range": range_ids[i]}));
|
||||
}
|
||||
yy += 24.0;
|
||||
if o.range == PreviewRange::AroundCurrentTime {
|
||||
for (k, (key, text, v)) in [("preRoll", "Pre-roll", o.pre_roll), ("postRoll", "Post-roll", o.post_roll)].into_iter().enumerate() {
|
||||
let lx = xv + k as f32 * 100.0;
|
||||
p.text(pos2(lx, yy), Align2::LEFT_CENTER, text, Tokens::ui(11.5), t.text_dim);
|
||||
let (r, nv, _) = widgets::hot_number_at(ui, pos2(lx + 52.0, yy - 9.0), egui::Id::new(("pv-roll", key)), v, 0.05, (0.0, 600.0), 1, "s", &t);
|
||||
app.auto.add(&format!("preview.{key}"), r, text);
|
||||
if let Some(nv) = nv {
|
||||
changes.push(json!({"shortcut": current.id(), key: nv}));
|
||||
}
|
||||
}
|
||||
yy += 22.0;
|
||||
}
|
||||
|
||||
// Play From.
|
||||
label(yy, "Play From");
|
||||
let froms: Vec<String> = PlayFrom::ALL.iter().map(|f| f.label().to_string()).collect();
|
||||
if let Some(i) = dropdown_row(
|
||||
app,
|
||||
ui,
|
||||
Rect::from_min_size(pos2(xv, yy - 10.0), vec2(wv, 20.0)),
|
||||
"playFrom",
|
||||
o.play_from.label(),
|
||||
&froms,
|
||||
PlayFrom::ALL.iter().position(|f| *f == o.play_from),
|
||||
) {
|
||||
changes.push(json!({"shortcut": current.id(), "playFrom": (["rangeStart", "currentTime"][i])}));
|
||||
}
|
||||
yy += 26.0;
|
||||
|
||||
// Frame Rate, Skip, Resolution.
|
||||
let comp_fps = app.session.active_comp().map(|c| c.frame_rate.as_f64());
|
||||
label(yy, "Frame Rate");
|
||||
const RATES: [f64; 12] = [8.0, 10.0, 12.0, 12.5, 15.0, 23.976, 24.0, 25.0, 29.97, 30.0, 50.0, 60.0];
|
||||
let auto = format!("({:.2}) Auto", comp_fps.unwrap_or(0.0));
|
||||
let mut rates = vec![auto.clone()];
|
||||
rates.extend(RATES.iter().map(|r| fmt_rate(*r)));
|
||||
let rate_text = o.frame_rate.map(fmt_rate).unwrap_or(auto);
|
||||
let rate_cur = match o.frame_rate {
|
||||
None => Some(0),
|
||||
Some(r) => RATES.iter().position(|x| (x - r).abs() < 1e-3).map(|i| i + 1),
|
||||
};
|
||||
if let Some(i) = dropdown_row(app, ui, Rect::from_min_size(pos2(xv, yy - 10.0), vec2(96.0, 20.0)), "frameRate", &rate_text, &rates, rate_cur) {
|
||||
let v = if i == 0 { json!("auto") } else { json!(RATES[i - 1]) };
|
||||
changes.push(json!({"shortcut": current.id(), "frameRate": v}));
|
||||
}
|
||||
let sx = xv + 106.0;
|
||||
p.text(pos2(sx, yy), Align2::LEFT_CENTER, "Skip", Tokens::ui(12.0), t.text_dim);
|
||||
let (r, nv, _) = widgets::hot_number_at(ui, pos2(sx + 30.0, yy - 9.0), egui::Id::new("pv-skip"), o.skip as f64, 0.1, (0.0, 99.0), 0, "", &t);
|
||||
app.auto.add("preview.skip", r, "Skip");
|
||||
if let Some(nv) = nv {
|
||||
changes.push(json!({"shortcut": current.id(), "skip": nv.round() as u32}));
|
||||
}
|
||||
yy += 24.0;
|
||||
label(yy, "Resolution");
|
||||
let ress: Vec<String> = PreviewResolution::ALL.iter().map(|r| r.label().to_string()).collect();
|
||||
let res_ids = ["auto", "full", "half", "third", "quarter", "custom"];
|
||||
if let Some(i) = dropdown_row(
|
||||
app,
|
||||
ui,
|
||||
Rect::from_min_size(pos2(xv, yy - 10.0), vec2(96.0, 20.0)),
|
||||
"resolution",
|
||||
o.resolution.label(),
|
||||
&ress,
|
||||
PreviewResolution::ALL.iter().position(|r| *r == o.resolution),
|
||||
) {
|
||||
changes.push(json!({"shortcut": current.id(), "resolution": res_ids[i]}));
|
||||
}
|
||||
if o.resolution == PreviewResolution::Custom {
|
||||
let (r, nv, _) =
|
||||
widgets::hot_number_at(ui, pos2(xv + 106.0, yy - 9.0), egui::Id::new("pv-custom-res"), o.custom_resolution as f64, 0.1, (1.0, 40.0), 0, "", &t);
|
||||
app.auto.add("preview.customResolution", r, "Custom Resolution");
|
||||
if let Some(nv) = nv {
|
||||
changes.push(json!({"shortcut": current.id(), "customResolution": nv.round() as u32}));
|
||||
}
|
||||
}
|
||||
yy += 24.0;
|
||||
if check_row(app, ui, &p, pos2(x0 - 2.0, yy), "fullScreen", "Full Screen", o.full_screen) {
|
||||
changes.push(json!({"shortcut": current.id(), "fullScreen": !o.full_screen}));
|
||||
}
|
||||
yy += 24.0;
|
||||
|
||||
// What stopping does.
|
||||
p.text(pos2(x0, yy), Align2::LEFT_CENTER, format!("On ({}) stop:", current.label()), Tokens::ui(11.5), t.text_dim);
|
||||
yy += 20.0;
|
||||
if check_row(app, ui, &p, pos2(x0 - 2.0, yy), "playCachedFrames", "If caching, play cached frames", o.play_cached_frames) {
|
||||
changes.push(json!({"shortcut": current.id(), "playCachedFrames": !o.play_cached_frames}));
|
||||
}
|
||||
yy += 22.0;
|
||||
if check_row(app, ui, &p, pos2(x0 - 2.0, yy), "moveTimeToPreviewTime", "Move time to preview time", o.move_time_to_preview_time) {
|
||||
changes.push(json!({"shortcut": current.id(), "moveTimeToPreviewTime": !o.move_time_to_preview_time}));
|
||||
}
|
||||
yy += 24.0;
|
||||
for c in changes {
|
||||
if let Err(e) = app.session.execute("playback.settings.set", c) {
|
||||
app.ui.status = e.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
// Cache bar over the preview range.
|
||||
if let Some(c) = app.session.active_comp().cloned() {
|
||||
let cid = app.session.active_comp_id().map(|i| i.0).unwrap_or(0);
|
||||
let scale = app.viewer_shown.as_ref().map(|(_, k)| k.scale).unwrap_or(1000);
|
||||
let cached = app.frames.cached_frames(app.session.revision, cid, scale).len();
|
||||
let total = c.frame_rate.frame_at(c.work_area.1) - c.frame_rate.frame_at(c.work_area.0);
|
||||
let pl = match app.playback.plan.filter(|_| app.playback.playing) {
|
||||
Some(pl) => pl,
|
||||
None => effectcraft_engine::preview::plan(&o, &c, app.session.time()),
|
||||
};
|
||||
let cached_set = app.frames.cached_frames(app.session.revision, cid, scale);
|
||||
let total = pl.frames().count();
|
||||
let cached = pl.frames().filter(|f| cached_set.binary_search(f).is_ok()).count();
|
||||
let bar = Rect::from_min_size(pos2(rect.min.x + 12.0, yy), vec2(rect.width() - 24.0, 6.0));
|
||||
p.rect_filled(bar, 3.0, t.field_bg);
|
||||
let f = (cached as f32 / total.max(1) as f32).min(1.0);
|
||||
p.rect_filled(Rect::from_min_size(bar.min, vec2(bar.width() * f, bar.height())), 3.0, t.cache_green);
|
||||
p.text(pos2(bar.min.x, bar.max.y + 12.0), Align2::LEFT_CENTER, format!("{cached} / {total} frames cached"), Tokens::ui(11.0), t.text_faint);
|
||||
let status = if app.playback.playing && app.playback.caching { " — caching before playback" } else { "" };
|
||||
p.text(pos2(bar.min.x, bar.max.y + 12.0), Align2::LEFT_CENTER, format!("{cached} / {total} frames cached{status}"), Tokens::ui(11.0), t.text_faint);
|
||||
}
|
||||
}
|
||||
|
||||
fn fmt_rate(r: f64) -> String {
|
||||
if (r - r.round()).abs() < 1e-6 { format!("{r:.0}") } else { format!("{r}") }
|
||||
}
|
||||
|
||||
/// A checkbox with its label; returns true when clicked.
|
||||
fn check_row(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter, at: egui::Pos2, key: &str, text: &str, on: bool) -> bool {
|
||||
let t = app.tokens;
|
||||
let r = Rect::from_min_size(pos2(at.x, at.y - 8.0), vec2(16.0, 16.0));
|
||||
let clicked = widgets::checkbox(ui, r, on, &t, egui::Id::new(("pv-check", key))).clicked();
|
||||
p.text(pos2(r.max.x + 5.0, at.y), Align2::LEFT_CENTER, text, Tokens::ui(12.0), t.text);
|
||||
app.auto.add(&format!("preview.{key}"), r, text);
|
||||
clicked
|
||||
}
|
||||
|
||||
/// A dropdown with its popup list (automation ids `preview.<key>` and `preview.<key>.<i>`);
|
||||
/// returns the chosen index.
|
||||
fn dropdown_row(app: &mut EffectcraftApp, ui: &mut egui::Ui, r: Rect, key: &str, text: &str, items: &[String], current: Option<usize>) -> Option<usize> {
|
||||
let t = app.tokens;
|
||||
let pid = egui::Id::new(("pv-pop", key));
|
||||
if widgets::dropdown(ui, r, text, &t, pid.with("btn")).clicked() {
|
||||
let open: bool = ui.data(|d| d.get_temp(pid.with("open")).unwrap_or(false));
|
||||
ui.data_mut(|d| d.insert_temp(pid.with("open"), !open));
|
||||
}
|
||||
app.auto.add(&format!("preview.{key}"), r, text);
|
||||
let open: bool = ui.data(|d| d.get_temp(pid.with("open")).unwrap_or(false));
|
||||
if !open {
|
||||
return None;
|
||||
}
|
||||
let mut chosen = None;
|
||||
let area = egui::Area::new(pid.with("area")).order(egui::Order::Foreground).fixed_pos(r.left_bottom() + vec2(0.0, 2.0)).show(ui.ctx(), |ui| {
|
||||
egui::Frame::popup(ui.style()).show(ui, |ui| {
|
||||
ui.set_min_width(r.width().max(140.0));
|
||||
for (i, label) in items.iter().enumerate() {
|
||||
let resp = ui.selectable_label(current == Some(i), label.as_str());
|
||||
app.auto.add(&format!("preview.{key}.{i}"), resp.rect, label);
|
||||
if resp.clicked() {
|
||||
chosen = Some(i);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
let outside =
|
||||
ui.input(|i| i.pointer.any_pressed()) && !area.response.contains_pointer() && !r.contains(ui.input(|i| i.pointer.interact_pos()).unwrap_or_default());
|
||||
if chosen.is_some() || outside || ui.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
ui.data_mut(|d| d.insert_temp(pid.with("open"), false));
|
||||
}
|
||||
chosen
|
||||
}
|
||||
|
||||
/// Audio panel: L/R VU meters (dBFS, 0 to -48) with peak hold and clip indicators, fed by the
|
||||
/// audio preview; the selected layer's Audio Levels on the right.
|
||||
pub fn audio(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
|
||||
@@ -7,7 +7,6 @@ use effectcraft_engine::render::EvalCtx;
|
||||
use egui::{Align2, Rect, Sense, pos2, vec2};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::icons::{self, Icon};
|
||||
use crate::theme::Tokens;
|
||||
use crate::{EffectcraftApp, widgets};
|
||||
|
||||
@@ -591,90 +590,131 @@ fn font_popup(app: &EffectcraftApp, ui: &mut egui::Ui, id: egui::Id, pos: egui::
|
||||
chosen
|
||||
}
|
||||
|
||||
/// Align panel: align selected layers to the composition (or to the selection).
|
||||
/// Align panel: Align Layers to Selection / Composition, the six align buttons and the six
|
||||
/// Distribute Layers buttons. Buttons run `layer.align {edge, to}` and `layer.distribute
|
||||
/// {mode}` on the selected layers.
|
||||
pub fn align(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let t = app.tokens;
|
||||
let p = ui.painter().with_clip_rect(rect);
|
||||
let x0 = rect.min.x + 10.0;
|
||||
let y = rect.min.y + 10.0;
|
||||
p.text(pos2(x0, y + 8.0), Align2::LEFT_CENTER, "Align Layers to: Composition", Tokens::ui(11.5), t.text_dim);
|
||||
let mut y = rect.min.y + 10.0;
|
||||
p.text(pos2(x0, y + 10.0), Align2::LEFT_CENTER, "Align Layers to:", Tokens::ui(11.5), t.text_dim);
|
||||
let dr = Rect::from_min_size(pos2(x0 + 100.0, y), vec2(110.0, 20.0));
|
||||
let to_sel = app.ui.align_to_selection;
|
||||
let pid = egui::Id::new("align-to-pop");
|
||||
if widgets::dropdown(ui, dr, if to_sel { "Selection" } else { "Composition" }, &t, pid.with("btn")).clicked() {
|
||||
widgets::open_popup(ui, pid);
|
||||
}
|
||||
app.auto.add("align.to", dr, if to_sel { "Selection" } else { "Composition" });
|
||||
if let Some(i) =
|
||||
widgets::popup_menu(ui, pid, dr.left_bottom() + vec2(0.0, 2.0), &["Selection".to_string(), "Composition".to_string()], Some(if to_sel { 0 } else { 1 }))
|
||||
{
|
||||
app.ui.align_to_selection = i == 0;
|
||||
}
|
||||
y += 28.0;
|
||||
let ops = ["left", "hcenter", "right", "top", "vcenter", "bottom"];
|
||||
for (i, op) in ops.iter().enumerate() {
|
||||
let r = Rect::from_min_size(pos2(x0 + i as f32 * 34.0 + if i >= 3 { 12.0 } else { 0.0 }, y + 24.0), vec2(30.0, 28.0));
|
||||
let resp = ui.interact(r, egui::Id::new(("align", *op)), Sense::click());
|
||||
p.rect_filled(r, 3.0, if resp.hovered() { t.hover } else { t.field_bg });
|
||||
// Glyph: a bar (alignment edge) and two boxes.
|
||||
let c = r.center();
|
||||
let st = egui::Stroke::new(1.3, t.text);
|
||||
match *op {
|
||||
"left" | "hcenter" | "right" => {
|
||||
let ex = match *op {
|
||||
"left" => r.min.x + 7.0,
|
||||
"right" => r.max.x - 7.0,
|
||||
_ => c.x,
|
||||
};
|
||||
p.line_segment([pos2(ex, r.min.y + 5.0), pos2(ex, r.max.y - 5.0)], st);
|
||||
let off = |w: f32| match *op {
|
||||
"left" => ex,
|
||||
"right" => ex - w,
|
||||
_ => ex - w / 2.0,
|
||||
};
|
||||
p.rect_filled(Rect::from_min_size(pos2(off(14.0), c.y - 7.0), vec2(14.0, 5.0)), 1.0, t.text_dim);
|
||||
p.rect_filled(Rect::from_min_size(pos2(off(9.0), c.y + 2.0), vec2(9.0, 5.0)), 1.0, t.text_dim);
|
||||
}
|
||||
_ => {
|
||||
let ey = match *op {
|
||||
"top" => r.min.y + 6.0,
|
||||
"bottom" => r.max.y - 6.0,
|
||||
_ => c.y,
|
||||
};
|
||||
p.line_segment([pos2(r.min.x + 5.0, ey), pos2(r.max.x - 5.0, ey)], st);
|
||||
let off = |h: f32| match *op {
|
||||
"top" => ey,
|
||||
"bottom" => ey - h,
|
||||
_ => ey - h / 2.0,
|
||||
};
|
||||
p.rect_filled(Rect::from_min_size(pos2(c.x - 8.0, off(14.0)), vec2(5.0, 14.0)), 1.0, t.text_dim);
|
||||
p.rect_filled(Rect::from_min_size(pos2(c.x + 3.0, off(9.0)), vec2(5.0, 9.0)), 1.0, t.text_dim);
|
||||
let mut run: Option<(&str, &str)> = None;
|
||||
for (row, kind) in ["align", "distribute"].into_iter().enumerate() {
|
||||
if row == 1 {
|
||||
p.text(pos2(x0, y + 8.0), Align2::LEFT_CENTER, "Distribute Layers:", Tokens::ui(11.5), t.text_dim);
|
||||
y += 20.0;
|
||||
}
|
||||
for (i, op) in ops.iter().enumerate() {
|
||||
let r = Rect::from_min_size(pos2(x0 + i as f32 * 34.0 + if i >= 3 { 12.0 } else { 0.0 }, y), vec2(30.0, 28.0));
|
||||
let resp = ui.interact(r, egui::Id::new((kind, *op)), Sense::click());
|
||||
p.rect_filled(r, 3.0, if resp.hovered() { t.hover } else { t.field_bg });
|
||||
align_glyph(&p, r, op, row == 1, &t);
|
||||
let tip = align_tip(kind, op);
|
||||
app.auto.add(&format!("{kind}.{op}"), r, &tip);
|
||||
if resp.on_hover_text(tip).clicked() {
|
||||
run = Some((kind, op));
|
||||
}
|
||||
}
|
||||
app.auto.add(&format!("align.{op}"), r, op);
|
||||
if resp.clicked() {
|
||||
align_layers(app, op);
|
||||
y += 34.0;
|
||||
}
|
||||
if let Some((kind, op)) = run {
|
||||
let r = if kind == "align" {
|
||||
let to = if app.ui.align_to_selection { "selection" } else { "composition" };
|
||||
app.session.execute("layer.align", json!({"edge": op, "to": to}))
|
||||
} else {
|
||||
app.session.execute("layer.distribute", json!({"mode": op}))
|
||||
};
|
||||
if let Err(e) = r {
|
||||
app.ui.status = e.to_string();
|
||||
}
|
||||
}
|
||||
let _ = icons::paint;
|
||||
let _ = Icon::Grid;
|
||||
}
|
||||
|
||||
/// Move selected layers so their content bounds align to the comp.
|
||||
pub fn align_layers(app: &mut EffectcraftApp, op: &str) {
|
||||
let Some(cid) = app.session.active_comp_id() else { return };
|
||||
let Some(comp) = app.session.project.comp(cid).cloned() else { return };
|
||||
let time = app.session.time();
|
||||
let mut moves = vec![];
|
||||
{
|
||||
let ectx = EvalCtx { project: &app.session.project, comp_id: cid, comp: &comp, time, expr: app.session.expr.as_deref(), footage: None };
|
||||
for l in comp.layers.iter().filter(|l| app.session.state.selected_layers.contains(&l.id)) {
|
||||
let Some(b) = effectcraft_engine::render::content_bounds(&ectx, l) else { continue };
|
||||
let (m, _) = ectx.layer_to_comp(l);
|
||||
let pts = [[b[0], b[1]], [b[2], b[1]], [b[2], b[3]], [b[0], b[3]]].map(|p| m.apply(effectcraft_engine::geom::vec2(p[0], p[1])));
|
||||
let (x0, x1) = (pts.iter().map(|p| p.x).fold(f64::INFINITY, f64::min), pts.iter().map(|p| p.x).fold(f64::NEG_INFINITY, f64::max));
|
||||
let (y0, y1) = (pts.iter().map(|p| p.y).fold(f64::INFINITY, f64::min), pts.iter().map(|p| p.y).fold(f64::NEG_INFINITY, f64::max));
|
||||
let (cw, ch) = (comp.width as f64, comp.height as f64);
|
||||
let (dx, dy) = match op {
|
||||
"left" => (-x0, 0.0),
|
||||
"right" => (cw - x1, 0.0),
|
||||
"hcenter" => (cw / 2.0 - (x0 + x1) / 2.0, 0.0),
|
||||
"top" => (0.0, -y0),
|
||||
"bottom" => (0.0, ch - y1),
|
||||
_ => (0.0, ch / 2.0 - (y0 + y1) / 2.0),
|
||||
};
|
||||
let pos = l.transform().map(|tr| ectx.v3(l, tr, "position", [0.0; 3])).unwrap_or([0.0; 3]);
|
||||
moves.push((l.id.0, [pos[0] + dx, pos[1] + dy, pos[2]]));
|
||||
fn align_tip(kind: &str, op: &str) -> String {
|
||||
let what = match op {
|
||||
"left" => "Left",
|
||||
"hcenter" => "Horizontal Center",
|
||||
"right" => "Right",
|
||||
"top" => "Top",
|
||||
"vcenter" => "Vertical Center",
|
||||
_ => "Bottom",
|
||||
};
|
||||
if kind == "align" { format!("Align {what}") } else { format!("Distribute {what}") }
|
||||
}
|
||||
|
||||
/// Button glyph: the alignment edge as a line and two boxes (distribute: three boxes spread,
|
||||
/// the line through each).
|
||||
fn align_glyph(p: &egui::Painter, r: Rect, op: &str, distribute: bool, t: &Tokens) {
|
||||
let c = r.center();
|
||||
let st = egui::Stroke::new(1.3, t.text);
|
||||
let horizontal = matches!(op, "left" | "hcenter" | "right");
|
||||
if distribute {
|
||||
for k in 0..3 {
|
||||
let f = (k as f32 - 1.0) * 7.0;
|
||||
if horizontal {
|
||||
let bx = c.x + f;
|
||||
let ex = match op {
|
||||
"left" => bx - 2.5,
|
||||
"right" => bx + 2.5,
|
||||
_ => bx,
|
||||
};
|
||||
p.rect_filled(Rect::from_center_size(pos2(bx, c.y), vec2(5.0, 10.0 + k as f32 * 2.0)), 1.0, t.text_dim);
|
||||
p.line_segment([pos2(ex, r.min.y + 5.0), pos2(ex, r.max.y - 5.0)], st);
|
||||
} else {
|
||||
let by = c.y + f;
|
||||
let ey = match op {
|
||||
"top" => by - 2.5,
|
||||
"bottom" => by + 2.5,
|
||||
_ => by,
|
||||
};
|
||||
p.rect_filled(Rect::from_center_size(pos2(c.x, by), vec2(10.0 + k as f32 * 2.0, 5.0)), 1.0, t.text_dim);
|
||||
p.line_segment([pos2(r.min.x + 5.0, ey), pos2(r.max.x - 5.0, ey)], st);
|
||||
}
|
||||
}
|
||||
return;
|
||||
}
|
||||
for (id, v) in moves {
|
||||
let _ = app.session.execute("prop.set", json!({"layer": id, "path": "transform/position", "value": v}));
|
||||
if horizontal {
|
||||
let ex = match op {
|
||||
"left" => r.min.x + 7.0,
|
||||
"right" => r.max.x - 7.0,
|
||||
_ => c.x,
|
||||
};
|
||||
p.line_segment([pos2(ex, r.min.y + 5.0), pos2(ex, r.max.y - 5.0)], st);
|
||||
let off = |w: f32| match op {
|
||||
"left" => ex,
|
||||
"right" => ex - w,
|
||||
_ => ex - w / 2.0,
|
||||
};
|
||||
p.rect_filled(Rect::from_min_size(pos2(off(14.0), c.y - 7.0), vec2(14.0, 5.0)), 1.0, t.text_dim);
|
||||
p.rect_filled(Rect::from_min_size(pos2(off(9.0), c.y + 2.0), vec2(9.0, 5.0)), 1.0, t.text_dim);
|
||||
} else {
|
||||
let ey = match op {
|
||||
"top" => r.min.y + 6.0,
|
||||
"bottom" => r.max.y - 6.0,
|
||||
_ => c.y,
|
||||
};
|
||||
p.line_segment([pos2(r.min.x + 5.0, ey), pos2(r.max.x - 5.0, ey)], st);
|
||||
let off = |h: f32| match op {
|
||||
"top" => ey,
|
||||
"bottom" => ey - h,
|
||||
_ => ey - h / 2.0,
|
||||
};
|
||||
p.rect_filled(Rect::from_min_size(pos2(c.x - 8.0, off(14.0)), vec2(5.0, 14.0)), 1.0, t.text_dim);
|
||||
p.rect_filled(Rect::from_min_size(pos2(c.x + 3.0, off(9.0)), vec2(5.0, 9.0)), 1.0, t.text_dim);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,7 +519,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
app.auto.add("viewer.area", area, "Composition viewer");
|
||||
|
||||
// Guides.
|
||||
if app.ui.viewer.safe_margins {
|
||||
let overlays = app.overlays_visible();
|
||||
if overlays && app.ui.viewer.safe_margins {
|
||||
let g = &app.session.prefs.grids;
|
||||
let (act, title) = (1.0 - g.action_safe as f32 / 100.0, 1.0 - g.title_safe as f32 / 100.0);
|
||||
for (k, a) in [(act, 120u8), (title, 160)] {
|
||||
@@ -530,7 +531,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
painter.line_segment([c - vec2(10.0, 0.0), c + vec2(10.0, 0.0)], Stroke::new(1.0, Color32::from_white_alpha(140)));
|
||||
painter.line_segment([c - vec2(0.0, 10.0), c + vec2(0.0, 10.0)], Stroke::new(1.0, Color32::from_white_alpha(140)));
|
||||
}
|
||||
if app.ui.viewer.grid {
|
||||
if overlays && app.ui.viewer.grid {
|
||||
// Settings ▸ Grids & Guides: gridline spacing, subdivisions and colour.
|
||||
let g = &app.session.prefs.grids;
|
||||
let [r, gg, b] = hex_rgb(&g.grid_color).unwrap_or([120, 160, 255]);
|
||||
@@ -567,7 +568,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
vt::proportional_grid(app, &painter, comp_rect);
|
||||
|
||||
// Comp guides (View ▸ Show Guides) and the region of interest.
|
||||
if app.ui.viewer.guides {
|
||||
if overlays && app.ui.viewer.guides {
|
||||
let [r, gg, b] = hex_rgb(&app.session.prefs.grids.guide_color).unwrap_or([0x3c, 0xc8, 0xf0]);
|
||||
let stroke = Stroke::new(1.0, Color32::from_rgb(r, gg, b));
|
||||
// Settings ▸ Grids & Guides ▸ Guide Style.
|
||||
@@ -625,7 +626,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if finish || app.ui.tool != Tool::Selection {
|
||||
ov::end_free_transform(&ctx);
|
||||
}
|
||||
if app.ui.viewer.show_layer_controls {
|
||||
if app.layer_controls_visible() {
|
||||
// Settings ▸ General ▸ Path Point and Handle Size; Appearance ▸ Use Label Color for
|
||||
// Layer Handles and Paths.
|
||||
let hs = app.session.prefs.general.path_point_size as f32 + 2.0;
|
||||
@@ -748,7 +749,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
// Track points of the current track (Tracker panel) on its layer, while that layer is selected.
|
||||
let mut track_hits = vec![];
|
||||
let track_cur = super::tracker::viewer_track(app);
|
||||
if app.ui.viewer.show_layer_controls
|
||||
if app.layer_controls_visible()
|
||||
&& let Some((tl, tu)) = track_cur
|
||||
&& selected.contains(&tl)
|
||||
&& let Some(layer) = comp.layer(tl)
|
||||
|
||||
@@ -590,16 +590,13 @@ pub struct UiState {
|
||||
pub snapping: bool,
|
||||
/// Tool creates shape (true) or mask (false) when a layer is selected.
|
||||
pub tool_creates_shape: bool,
|
||||
/// Preview panel options.
|
||||
pub preview_loop: bool,
|
||||
pub preview_cache_first: bool,
|
||||
/// Preview panel "Include Audio" (Mute Audio off).
|
||||
#[serde(default = "yes")]
|
||||
pub preview_audio: bool,
|
||||
pub start_screen: bool,
|
||||
/// The Home screen shows its Learn tab (tutorials) instead of the recent projects.
|
||||
#[serde(default)]
|
||||
pub home_learn: bool,
|
||||
/// Align panel: Align Layers to Selection (off: to the composition).
|
||||
#[serde(default)]
|
||||
pub align_to_selection: bool,
|
||||
/// Composition ▸ Preview ▸ Cache Frames When Idle.
|
||||
pub cache_when_idle: bool,
|
||||
/// Tracker panel ▸ Motion Source chosen without a tracker yet (layer id).
|
||||
@@ -665,11 +662,9 @@ impl Default for UiState {
|
||||
stroke_width: 0.0,
|
||||
snapping: true,
|
||||
tool_creates_shape: true,
|
||||
preview_loop: true,
|
||||
preview_cache_first: false,
|
||||
preview_audio: true,
|
||||
start_screen: false,
|
||||
home_learn: false,
|
||||
align_to_selection: false,
|
||||
cache_when_idle: false,
|
||||
tracker_source: None,
|
||||
layer_panel: None,
|
||||
|
||||
Reference in New Issue
Block a user