G2: merge main and preserve blank panel menus and selection
This commit is contained in:
@@ -425,6 +425,55 @@ pub fn to_color_image(img: &effectcraft_engine::render::Image) -> egui::ColorIma
|
||||
egui::ColorImage::new([img.width as usize, img.height as usize], px)
|
||||
}
|
||||
|
||||
/// The size `size` is shown at in a texture whose sides can't exceed `max_side`: divided by the
|
||||
/// smallest whole factor that fits (frames of comps wider than the GPU's texture limit, #201).
|
||||
pub fn fitted_size(size: [usize; 2], max_side: usize) -> [usize; 2] {
|
||||
let k = size[0].max(size[1]).div_ceil(max_side.max(1)).max(1);
|
||||
[size[0].div_ceil(k), size[1].div_ceil(k)]
|
||||
}
|
||||
|
||||
/// `img` as a texture the renderer accepts: unchanged when it fits in `max_side`, else averaged
|
||||
/// down by a whole factor (premultiplied pixels average correctly). The viewer draws it over the
|
||||
/// same area, so only detail beyond the GPU's texture limit is lost, instead of the upload
|
||||
/// failing (#201).
|
||||
pub fn fit_texture(img: egui::ColorImage, max_side: usize) -> egui::ColorImage {
|
||||
let [w, h] = img.size;
|
||||
let [fw, fh] = fitted_size(img.size, max_side);
|
||||
if [fw, fh] == [w, h] {
|
||||
return img;
|
||||
}
|
||||
let k = w.max(h).div_ceil(max_side.max(1)).max(1);
|
||||
let px: Vec<egui::Color32> = (0..fw * fh)
|
||||
.into_par_iter()
|
||||
.map(|i| {
|
||||
let (x0, y0) = ((i % fw) * k, (i / fw) * k);
|
||||
let (mut sum, mut n) = ([0u32; 4], 0u32);
|
||||
for y in y0..(y0 + k).min(h) {
|
||||
for c in img.pixels.get(y * w + x0..y * w + (x0 + k).min(w)).unwrap_or_default() {
|
||||
for (s, v) in sum.iter_mut().zip(c.to_array()) {
|
||||
*s += v as u32;
|
||||
}
|
||||
n += 1;
|
||||
}
|
||||
}
|
||||
let n = n.max(1);
|
||||
let [r, g, b, a] = sum.map(|s| ((s + n / 2) / n) as u8);
|
||||
egui::Color32::from_rgba_premultiplied(r, g, b, a)
|
||||
})
|
||||
.collect();
|
||||
egui::ColorImage::new([fw, fh], px)
|
||||
}
|
||||
|
||||
/// The largest texture side the renderer accepts.
|
||||
pub fn max_texture_side(ctx: &egui::Context) -> usize {
|
||||
ctx.input(|i| i.max_texture_side)
|
||||
}
|
||||
|
||||
/// `ctx.load_texture` for frame-sized images: fitted to the renderer's texture limit first.
|
||||
pub fn load_fitted(ctx: &egui::Context, name: impl Into<String>, img: egui::ColorImage, opts: egui::TextureOptions) -> egui::TextureHandle {
|
||||
ctx.load_texture(name, fit_texture(img, max_texture_side(ctx)), opts)
|
||||
}
|
||||
|
||||
impl Frames {
|
||||
/// Retire only GPU preview state; documents, CPU frames and running job leases survive.
|
||||
/// Publication checks the same latch while holding the cache lock, so a late GPU frame
|
||||
@@ -1015,6 +1064,26 @@ impl Queue {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// Frames larger than the texture limit are averaged down by a whole factor (#201: an
|
||||
/// 11000×2200 comp at Full resolution against an 8192 limit).
|
||||
#[test]
|
||||
fn frames_over_the_texture_limit_are_averaged_down() {
|
||||
assert_eq!(fitted_size([11000, 2200], 8192), [5500, 1100]);
|
||||
assert_eq!(fitted_size([8192, 100], 8192), [8192, 100]);
|
||||
assert_eq!(fitted_size([30000, 30000], 16384), [15000, 15000]);
|
||||
assert_eq!(fitted_size([0, 0], 0), [0, 0]);
|
||||
// 5×2 (three columns of white, then black) into 2 px: 3×2 blocks (the last one 2×2).
|
||||
let w = egui::Color32::WHITE;
|
||||
let b = egui::Color32::from_rgba_premultiplied(0, 0, 0, 255);
|
||||
let img = egui::ColorImage::new([5, 2], vec![w, w, w, b, b, w, w, w, b, b]);
|
||||
let out = fit_texture(img.clone(), 2);
|
||||
assert_eq!(out.size, [2, 1]);
|
||||
assert_eq!(out.pixels, vec![w, b]);
|
||||
assert_eq!(fit_texture(img.clone(), 5).pixels, img.pixels);
|
||||
let mixed = fit_texture(egui::ColorImage::new([2, 1], vec![w, b]), 1);
|
||||
assert_eq!(mixed.pixels, vec![egui::Color32::from_rgba_premultiplied(128, 128, 128, 255)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn retirement_reaches_existing_workers_and_keeps_cpu_frames_and_completion_live() {
|
||||
let frames = Frames::default();
|
||||
|
||||
@@ -9,6 +9,7 @@ use crate::state::Tool;
|
||||
use crate::theme::Tokens;
|
||||
use crate::widgets;
|
||||
use crate::{Dialog, EffectcraftApp};
|
||||
use effectcraft_engine::project::{LayerId, LayerSource};
|
||||
|
||||
pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let t = app.tokens;
|
||||
@@ -91,7 +92,40 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
|
||||
// Tool options.
|
||||
x += 10.0;
|
||||
if app.ui.tool.is_shape() || app.ui.tool == Tool::Pen {
|
||||
// Selected shape layers: the options show their paint and edit it (as in After Effects).
|
||||
let shape_layers: Vec<u64> = app
|
||||
.session
|
||||
.active_comp()
|
||||
.map(|c| {
|
||||
app.session.state.selected_layers.iter().filter(|id| c.layer(**id).is_some_and(|l| matches!(l.source, LayerSource::Shape))).map(|id| id.0).collect()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
if let Some(l) = shape_layers.first().and_then(|id| app.session.active_comp()?.layer(LayerId(*id))) {
|
||||
let (fill, stroke, width) = effectcraft_engine::commands::shape_stroke::first_paint(l, l.layer_time(app.session.time()));
|
||||
let rgb = |c: [f64; 4]| [c[0] as f32, c[1] as f32, c[2] as f32];
|
||||
if let Some(c) = fill {
|
||||
app.ui.fill_color = rgb(c);
|
||||
}
|
||||
if let Some(c) = stroke {
|
||||
app.ui.stroke_color = rgb(c);
|
||||
}
|
||||
app.ui.stroke_width = width.unwrap_or(0.0) as f32;
|
||||
}
|
||||
// One undo step per picker session or width drag: end the merge once both are done.
|
||||
let picking = ["tool-fill-pop", "tool-stroke-pop"].iter().any(|k| ui.data(|d| d.get_temp::<bool>(egui::Id::new(*k).with("open")).unwrap_or(false)));
|
||||
if !picking && !ui.input(|i| i.pointer.any_down()) && app.session.history.merge_key.as_deref().is_some_and(|k| k.starts_with("tool-")) {
|
||||
app.session.history.merge_key = None;
|
||||
}
|
||||
if app.ui.tool.is_shape() || app.ui.tool == Tool::Pen || !shape_layers.is_empty() {
|
||||
let paint = |app: &mut EffectcraftApp, key: &str, v: serde_json::Value| {
|
||||
if shape_layers.is_empty() {
|
||||
return;
|
||||
}
|
||||
let merge = format!("tool-{key}");
|
||||
if let Err(e) = app.session.execute("shape.fillStroke", serde_json::json!({"layers": shape_layers, key: v, "merge": merge})) {
|
||||
app.ui.status = e.to_string();
|
||||
}
|
||||
};
|
||||
p.text(pos2(x, cy), Align2::LEFT_CENTER, "Fill:", Tokens::ui(12.0), t.text_dim);
|
||||
x += 28.0;
|
||||
let fr = Rect::from_center_size(pos2(x + 10.0, cy), vec2(20.0, 16.0));
|
||||
@@ -99,7 +133,11 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if widgets::swatch(ui, fr, [c[0], c[1], c[2], 1.0], egui::Id::new("tool-fill"), &t).clicked() {
|
||||
widgets::open_popup(ui, egui::Id::new("tool-fill-pop"));
|
||||
}
|
||||
color_popup(ui, egui::Id::new("tool-fill-pop"), fr.left_bottom(), &mut app.ui.fill_color);
|
||||
if color_popup(ui, egui::Id::new("tool-fill-pop"), fr.left_bottom(), &mut app.ui.fill_color) {
|
||||
let c = app.ui.fill_color;
|
||||
paint(app, "fill", serde_json::json!(c));
|
||||
}
|
||||
app.auto.add("header.fill", fr, "Fill Color");
|
||||
x += 32.0;
|
||||
p.text(pos2(x, cy), Align2::LEFT_CENTER, "Stroke:", Tokens::ui(12.0), t.text_dim);
|
||||
x += 44.0;
|
||||
@@ -108,13 +146,19 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if widgets::swatch(ui, sr, [c[0], c[1], c[2], 1.0], egui::Id::new("tool-stroke"), &t).clicked() {
|
||||
widgets::open_popup(ui, egui::Id::new("tool-stroke-pop"));
|
||||
}
|
||||
color_popup(ui, egui::Id::new("tool-stroke-pop"), sr.left_bottom(), &mut app.ui.stroke_color);
|
||||
if color_popup(ui, egui::Id::new("tool-stroke-pop"), sr.left_bottom(), &mut app.ui.stroke_color) {
|
||||
let c = app.ui.stroke_color;
|
||||
paint(app, "stroke", serde_json::json!(c));
|
||||
}
|
||||
app.auto.add("header.stroke", sr, "Stroke Color");
|
||||
x += 26.0;
|
||||
let (r, v, _) =
|
||||
widgets::hot_number_at(ui, pos2(x, cy - 9.0), egui::Id::new("tool-stroke-w"), app.ui.stroke_width as f64, 0.2, (0.0, 1000.0), 0, " px", &t);
|
||||
if let Some(v) = v {
|
||||
app.ui.stroke_width = v as f32;
|
||||
paint(app, "strokeWidth", serde_json::json!(v));
|
||||
}
|
||||
app.auto.add("header.strokeWidth", r, "Stroke Width");
|
||||
x = r.max.x + 14.0;
|
||||
}
|
||||
if app.ui.tool.puppet_kind().is_some() {
|
||||
|
||||
@@ -139,7 +139,8 @@ pub struct Playback {
|
||||
pub audio_frame: Option<i64>,
|
||||
/// The preview's sound waits for frames: while the frames ahead aren't cached, every frame
|
||||
/// shows as it renders, silently; the sound starts once the rest of the preview (or what
|
||||
/// fits in the RAM preview) is cached, so it never plays over skipped frames (#103).
|
||||
/// fits in the RAM preview) is cached, so it never plays over skipped frames (#103), or
|
||||
/// sooner once the silent preview keeps real time with the frames ahead cached (#208).
|
||||
pub audio_held: bool,
|
||||
/// When the last frames were shown (seconds, the last second's worth): the achieved rate.
|
||||
pub shown_at: std::collections::VecDeque<f64>,
|
||||
@@ -168,6 +169,15 @@ impl Playback {
|
||||
let step = self.plan.map_or(1, |p| p.step).max(1) as f64;
|
||||
self.achieved_fps().map(|f| f * step >= self.fps * 0.95)
|
||||
}
|
||||
|
||||
/// The preview has kept real time for the last quarter second (at least two frames) up to
|
||||
/// `now`: rendering keeps up, so sound can start without waiting for the whole preview.
|
||||
pub fn keeps_up(&self, now: f64) -> bool {
|
||||
let step = self.plan.map_or(1, |p| p.step).max(1) as f64;
|
||||
let frame = step / self.fps.max(1.0);
|
||||
let (Some(a), Some(b)) = (self.shown_at.front(), self.shown_at.back()) else { return false };
|
||||
self.shown_at.len() >= 3 && b - a >= (2.0 * frame).max(0.25) && now - b <= 2.0 * frame && self.real_time() == Some(true)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct EffectcraftApp {
|
||||
@@ -566,6 +576,11 @@ impl EffectcraftApp {
|
||||
self.gpu.as_ref().map(effectcraft_engine::render::Accelerator::name)
|
||||
}
|
||||
|
||||
/// The size of the viewer frame's texture (CPU frames; fitted to the GPU's texture limit).
|
||||
pub fn viewer_texture_size(&self) -> Option<[usize; 2]> {
|
||||
self.viewer_tex.as_ref().map(|(t, _)| t.size())
|
||||
}
|
||||
|
||||
/// The viewer's current pixels as 8-bit premultiplied RGBA, reading a GPU frame back the
|
||||
/// first time something asks for it.
|
||||
///
|
||||
@@ -1016,10 +1031,12 @@ impl EffectcraftApp {
|
||||
return;
|
||||
}
|
||||
let snap = |f: i64| wa + (f - wa).div_euclid(step) * step;
|
||||
// Held sound starts once the frames ahead are cached (see `Playback::audio_held`).
|
||||
// Held sound starts once the frames ahead are cached (see `Playback::audio_held`): the
|
||||
// prefetch window when the silent preview keeps real time, else the rest of the preview.
|
||||
let fit = self.frames_that_fit(&c, scale);
|
||||
if self.playback.audio_held
|
||||
&& let Some(p) = plan
|
||||
&& self.cached_ahead(&p, &series, cur, self.frames_that_fit(&c, scale))
|
||||
&& ((self.playback.keeps_up(now) && self.cached_ahead(&p, &series, cur, ahead.min(fit))) || self.cached_ahead(&p, &series, cur, fit))
|
||||
{
|
||||
self.playback.audio_held = false;
|
||||
self.playback.start_wall = now;
|
||||
@@ -1052,6 +1069,8 @@ impl EffectcraftApp {
|
||||
self.audio = None;
|
||||
self.playback.audio_held = true;
|
||||
self.playback.waiting = true;
|
||||
// The rate measured before the stall no longer says it keeps up.
|
||||
self.playback.shown_at.clear();
|
||||
self.playback.start_wall = now;
|
||||
self.playback.start_frame = cur;
|
||||
}
|
||||
|
||||
@@ -190,6 +190,35 @@ fn reveal_time_remap(app: &mut EffectcraftApp, params: &Value) {
|
||||
}
|
||||
}
|
||||
|
||||
/// After Alt+Shift+P (A, S, R, T) the Timeline shows the property on each layer it keyed, as in
|
||||
/// After Effects: added to what a reveal shortcut shows, else with the layer's Transform twirled
|
||||
/// open, else alone like P.
|
||||
fn reveal_keyed(app: &mut EffectcraftApp, keyed: &Value, kind: &str) {
|
||||
let layers: std::collections::BTreeSet<u64> = keyed.as_array().into_iter().flatten().filter_map(|k| k.get("layer").and_then(Value::as_u64)).collect();
|
||||
let Some(comp) = app.session.active_comp() else { return };
|
||||
let tl = &mut app.ui.timeline;
|
||||
for id in layers {
|
||||
let shown = tl.layer_reveal.get(&id).filter(|k| !k.is_empty()).cloned();
|
||||
match shown {
|
||||
Some(mut kinds) => {
|
||||
if !kinds.iter().any(|k| k == kind) {
|
||||
kinds.push(kind.to_string());
|
||||
tl.layer_reveal.insert(id, kinds);
|
||||
}
|
||||
}
|
||||
None if tl.open_layers.contains(&id) => {
|
||||
if let Some(tr) = comp.layer(effectcraft_engine::project::LayerId(id)).and_then(|l| l.transform()) {
|
||||
tl.open_groups.insert(tr.uid);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
tl.open_layers.insert(id);
|
||||
tl.layer_reveal.insert(id, vec![kind.to_string()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The layers a reveal shortcut acts on: the selected ones, else every layer of the active comp.
|
||||
fn reveal_targets(app: &EffectcraftApp) -> Vec<u64> {
|
||||
if app.session.state.selected_layers.is_empty() {
|
||||
@@ -314,7 +343,9 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V
|
||||
return Ok(Value::Null);
|
||||
}
|
||||
if let Some(k) = id.strip_prefix("timeline.keyAt.") {
|
||||
return run_engine(app, ctx, "keys.toggleTransform", json!({"prop": k}));
|
||||
let r = run_engine(app, ctx, "keys.toggleTransform", json!({"prop": k}))?;
|
||||
reveal_keyed(app, &r, k);
|
||||
return Ok(r);
|
||||
}
|
||||
if let Some(k) = id.strip_prefix("timeline.revealAdd.") {
|
||||
reveal(app, k, now, true);
|
||||
|
||||
@@ -58,7 +58,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
Some((k, tex, size)) if k == key => Some((tex, size)),
|
||||
_ => app.session.footage.frame(view.item, f, view.time).map(|img| {
|
||||
let ci = egui::ColorImage::from_rgba_unmultiplied([img.width as usize, img.height as usize], &img.to_rgba8());
|
||||
let tex = ctx.load_texture("footage-panel", ci, egui::TextureOptions::LINEAR);
|
||||
let tex = crate::frames::load_fitted(&ctx, "footage-panel", ci, egui::TextureOptions::LINEAR);
|
||||
ctx.data_mut(|d| d.insert_temp(tid, (key, tex.clone(), [img.width, img.height])));
|
||||
(tex, [img.width, img.height])
|
||||
}),
|
||||
|
||||
@@ -147,7 +147,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let x0 = -buf.offset[0] / buf.scale;
|
||||
let y0 = -buf.offset[1] / buf.scale;
|
||||
let rect = [x0, y0, x0 + buf.img.width as f64 / buf.scale, y0 + buf.img.height as f64 / buf.scale];
|
||||
let tex = ctx.load_texture("layer-panel", img, egui::TextureOptions::LINEAR);
|
||||
let tex = crate::frames::load_fitted(&ctx, "layer-panel", img, egui::TextureOptions::LINEAR);
|
||||
let c = Tex { key, tex, rect };
|
||||
ctx.data_mut(|d| d.insert_temp(tex_id(), c.clone()));
|
||||
c
|
||||
|
||||
@@ -323,9 +323,10 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let list = Rect::from_min_max(pos2(rect.min.x, hdr.max.y), pos2(rect.max.x, rect.max.y - footer_h));
|
||||
let lp = p.with_clip_rect(list);
|
||||
// The list's empty area (under the rows and the scroll bar, which take their own clicks):
|
||||
// a double-click imports, as in After Effects (File ▸ Import ▸ File...).
|
||||
let empty = ui.interact(list, egui::Id::new("proj-empty"), Sense::click());
|
||||
app.auto.add("project.empty", list, "Double-click to import files; right-click for project actions");
|
||||
// a click deselects, a drag draws a selection box, a double-click imports, as in After
|
||||
// Effects (File ▸ Import ▸ File...).
|
||||
let empty = ui.interact(list, egui::Id::new("proj-empty"), Sense::click_and_drag());
|
||||
app.auto.add("project.empty", list, "Double-click to import files; drag to select items; right-click for project actions");
|
||||
if overflow > 0.0 && ui.rect_contains_pointer(list) {
|
||||
let (dx, dy, shift) = ui.input(|i| (i.smooth_scroll_delta.x, i.smooth_scroll_delta.y, i.modifiers.shift));
|
||||
let d = if dx.abs() > 0.0 {
|
||||
@@ -730,6 +731,41 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
}
|
||||
});
|
||||
// Selection box over the rows it touches (#203); Shift or Cmd/Ctrl adds to the selection.
|
||||
let adding = ui.input(|i| i.modifiers.shift || i.modifiers.command);
|
||||
if empty.clicked() && !adding {
|
||||
app.session.state.project_selection.clear();
|
||||
}
|
||||
let box_id = egui::Id::new("proj-marquee");
|
||||
if let (Some(start), Some(end)) = (ctx.input(|i| i.pointer.press_origin()), empty.interact_pointer_pos())
|
||||
&& empty.dragged()
|
||||
{
|
||||
let b = Rect::from_two_pos(start, end).intersect(list);
|
||||
lp.rect_filled(b, 0.0, t.accent.gamma_multiply(0.12));
|
||||
lp.rect_stroke(b, 0.0, Stroke::new(1.0, t.accent), egui::StrokeKind::Inside);
|
||||
ctx.data_mut(|d| d.insert_temp(box_id, b));
|
||||
}
|
||||
if empty.drag_stopped()
|
||||
&& let Some(b) = ctx.data(|d| d.get_temp::<Rect>(box_id))
|
||||
{
|
||||
ctx.data_mut(|d| d.remove::<Rect>(box_id));
|
||||
// Rows sit at fixed heights from the top of the scrolled list.
|
||||
let top = list.min.y - app.ui.project_scroll;
|
||||
let picked = rows.iter().enumerate().filter(|(i, _)| {
|
||||
let y = top + *i as f32 * ROW_H;
|
||||
y < b.max.y && y + ROW_H > b.min.y
|
||||
});
|
||||
let picked: Vec<ItemId> = picked.map(|(_, (id, _))| *id).collect();
|
||||
let sel = &mut app.session.state.project_selection;
|
||||
if !adding {
|
||||
sel.clear();
|
||||
}
|
||||
for id in picked {
|
||||
if !sel.contains(&id) {
|
||||
sel.push(id);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (id, params) in actions {
|
||||
if let Err(e) = crate::menus::invoke(app, &ctx, &id, params) {
|
||||
app.ui.status = e;
|
||||
|
||||
@@ -122,7 +122,7 @@ pub fn draw_overlay(
|
||||
let x0 = -inp.offset[0] / inp.scale;
|
||||
let y0 = -inp.offset[1] / inp.scale;
|
||||
let rect = [x0, y0, x0 + w as f64 / inp.scale, y0 + h as f64 / inp.scale];
|
||||
let tex = ctx.load_texture("roto-overlay", img, egui::TextureOptions::NEAREST);
|
||||
let tex = crate::frames::load_fitted(ctx, "roto-overlay", img, egui::TextureOptions::NEAREST);
|
||||
let c = Overlay { key, tex, rect };
|
||||
ctx.data_mut(|d| d.insert_temp(id, c.clone()));
|
||||
Some(c)
|
||||
|
||||
@@ -47,6 +47,16 @@ enum RowKind {
|
||||
/// Synthetic group uid for a layer's Audio > Waveform twirl (never a real property uid).
|
||||
const WAVE_BIT: u64 = 1 << 60;
|
||||
|
||||
/// Synthetic group uid for the Geometry Options row of a 3D text or shape layer in a Classic 3D
|
||||
/// comp, which only offers "Change Renderer…" (never a real property uid).
|
||||
const GEOM_BIT: u64 = 1 << 59;
|
||||
|
||||
/// Classic 3D comps don't extrude: a 3D text or shape layer's Geometry Options row offers to
|
||||
/// change the renderer instead, as in After Effects.
|
||||
fn classic_geometry_row(comp: &Comp, l: &Layer) -> bool {
|
||||
comp.renderer == effectcraft_engine::project::Renderer::Classic3D && l.is_3d() && matches!(l.source, LayerSource::Text | LayerSource::Shape)
|
||||
}
|
||||
|
||||
/// Time navigator's visible-span bar and the work area bar.
|
||||
const NAV_BAR: Color32 = Color32::from_rgb(0x55, 0x55, 0x55);
|
||||
const WORK_AREA_BAR: Color32 = Color32::from_rgb(0x5c, 0x5c, 0x5c);
|
||||
@@ -597,8 +607,11 @@ fn build_rows(app: &EffectcraftApp, comp: &Comp) -> Vec<Row> {
|
||||
reveal_rows(app, l, kinds, &mut rows);
|
||||
continue;
|
||||
}
|
||||
let classic_geometry = classic_geometry_row(comp, l);
|
||||
for c in &l.props.children {
|
||||
match c {
|
||||
// The Change Renderer row (after Transform) stands in for the extrusion options.
|
||||
Node::Group(g) if classic_geometry && g.match_id == "geometryOptions" => {}
|
||||
Node::Group(g) if group_visible(g, l) => {
|
||||
let open = tl.open_groups.contains(&g.uid);
|
||||
rows.push(Row {
|
||||
@@ -631,6 +644,20 @@ fn build_rows(app: &EffectcraftApp, comp: &Comp) -> Vec<Row> {
|
||||
}
|
||||
}
|
||||
}
|
||||
if classic_geometry && g.match_id == "transform" {
|
||||
rows.push(Row {
|
||||
layer: l.id,
|
||||
depth: 1,
|
||||
kind: RowKind::Group {
|
||||
uid: GEOM_BIT | l.id.0,
|
||||
name: "Geometry Options".into(),
|
||||
open: false,
|
||||
has_children: false,
|
||||
fx: None,
|
||||
eye: None,
|
||||
},
|
||||
});
|
||||
}
|
||||
}
|
||||
Node::Prop(p) if prop_visible(p, l) => rows.push(Row { layer: l.id, depth: 1, kind: RowKind::Prop { uid: p.uid } }),
|
||||
_ => {}
|
||||
@@ -1704,6 +1731,19 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
lp.text(pos2(indent + 10.0, cy), Align2::LEFT_CENTER, name, Tokens::ui(12.0), t.text);
|
||||
text_anim_popups(app, ui, &lp, layer, *uid, cw.switches, cy, &mut actions);
|
||||
shape_add_popup(app, ui, &lp, layer, *uid, cw.switches, cy, &mut actions);
|
||||
if *uid == GEOM_BIT | layer.id.0 {
|
||||
let lr = lp.text(pos2(cw.switches + 6.0, cy), Align2::LEFT_CENTER, "Change Renderer…", Tokens::ui(11.5), t.accent);
|
||||
let resp =
|
||||
ui.interact(lr, egui::Id::new(("tl-change-renderer", layer.id.0)), Sense::click()).on_hover_text("Composition Settings ▸ 3D Renderer");
|
||||
if resp.hovered() {
|
||||
ctx.set_cursor_icon(egui::CursorIcon::PointingHand);
|
||||
}
|
||||
app.auto.add(&format!("timeline.layer.{}.changeRenderer", layer.id.0), lr, "Change Renderer…");
|
||||
if resp.clicked() {
|
||||
ui_actions.push(UiAct::ChangeRenderer);
|
||||
}
|
||||
}
|
||||
dash_buttons(app, ui, &lp, layer, *uid, cw.switches, cy, &mut actions);
|
||||
// Mask mode + inverted inline.
|
||||
if let Some(g) = layer.props.find_group(*uid)
|
||||
@@ -1727,7 +1767,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let gr_rect = Rect::from_min_max(pos2(indent + 8.0, r.min.y), pos2(cw.switches, r.max.y));
|
||||
let gr = ui.interact(gr_rect, egui::Id::new(("grow", uid)), Sense::click());
|
||||
app.auto.add(&format!("timeline.group.{uid}.name"), gr_rect, name);
|
||||
if gr.clicked() && uid & WAVE_BIT == 0 {
|
||||
if gr.clicked() && uid & (WAVE_BIT | GEOM_BIT) == 0 {
|
||||
actions.push(("prop.select".into(), json!({"layer": layer.id.0, "prop": uid, "selectKeys": false})));
|
||||
}
|
||||
if gr.double_clicked() {
|
||||
@@ -2208,9 +2248,14 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if graph_on {
|
||||
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.
|
||||
// Empty-area click in the graph: deselect keys (below the last row, the layers too, as in
|
||||
// After Effects); drag: box-select keys.
|
||||
if empty.clicked() {
|
||||
actions.push(("keys.select".into(), json!({"keys": []})));
|
||||
let below = empty.interact_pointer_pos().is_some_and(|p| hit_rows.iter().all(|(r, _)| p.y > r.max.y));
|
||||
if below && !ui.input(|i| i.modifiers.shift || i.modifiers.command) {
|
||||
actions.push(("layer.select".into(), json!({"layers": []})));
|
||||
}
|
||||
}
|
||||
if let (true, Some(origin), Some(cur)) =
|
||||
(empty.dragged(), empty.interact_pointer_pos().and_then(|_| ctx.input(|i| i.pointer.press_origin())), empty.interact_pointer_pos())
|
||||
@@ -2477,6 +2522,11 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
UiAct::SetTime(tt) => app.session.set_time(tt),
|
||||
UiAct::EndMerge => app.session.history.merge_key = None,
|
||||
UiAct::ChangeRenderer => {
|
||||
if super::dialogs::open_comp_settings(app).is_ok() {
|
||||
app.dialog_state.comp.tab = super::comp_settings::Tab::Renderer;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ui.input(|i| i.pointer.primary_down()) && actions.iter().any(|(id, _)| id == "prop.set") {
|
||||
@@ -2594,6 +2644,8 @@ enum UiAct {
|
||||
ToggleGroup(u64),
|
||||
SetTime(Tick),
|
||||
EndMerge,
|
||||
/// Composition Settings on its 3D Renderer tab.
|
||||
ChangeRenderer,
|
||||
}
|
||||
|
||||
fn walk_groups(g: &PropGroup, out: &mut Vec<u64>) {
|
||||
@@ -2634,6 +2686,75 @@ fn dash_buttons(
|
||||
}
|
||||
}
|
||||
|
||||
/// The shape items the Contents row's "Add:" menu offers, as `layer.addShapeItem` kinds ("-" is
|
||||
/// a separator), in After Effects' order.
|
||||
const SHAPE_ADD_ITEMS: &[(&str, &str)] = &[
|
||||
("group", "Group (empty)"),
|
||||
("-", ""),
|
||||
("rect", "Rectangle"),
|
||||
("ellipse", "Ellipse"),
|
||||
("star", "Polystar"),
|
||||
("path", "Path"),
|
||||
("-", ""),
|
||||
("fill", "Fill"),
|
||||
("stroke", "Stroke"),
|
||||
("gfill", "Gradient Fill"),
|
||||
("gstroke", "Gradient Stroke"),
|
||||
("-", ""),
|
||||
("merge", "Merge Paths"),
|
||||
("offset", "Offset Paths"),
|
||||
("pucker", "Pucker & Bloat"),
|
||||
("repeater", "Repeater"),
|
||||
("round", "Round Corners"),
|
||||
("trim", "Trim Paths"),
|
||||
("twist", "Twist"),
|
||||
("wiggle", "Wiggle Paths"),
|
||||
("zigzag", "Zig Zag"),
|
||||
];
|
||||
|
||||
/// A shape layer's Contents "Add:" pop-up menu: adds a shape, paint or path operation to the
|
||||
/// selected shape group, else to the layer's contents.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn shape_add_popup(
|
||||
app: &mut EffectcraftApp,
|
||||
ui: &mut egui::Ui,
|
||||
p: &egui::Painter,
|
||||
layer: &Layer,
|
||||
uid: u64,
|
||||
x: f32,
|
||||
cy: f32,
|
||||
actions: &mut Vec<(String, serde_json::Value)>,
|
||||
) {
|
||||
if !matches!(layer.source, LayerSource::Shape) || layer.props.sub("contents").is_none_or(|c| c.uid != uid) {
|
||||
return;
|
||||
}
|
||||
let t = app.tokens;
|
||||
p.text(pos2(x + 6.0, cy), Align2::LEFT_CENTER, "Add:", Tokens::ui(11.5), t.text_dim);
|
||||
let br = Rect::from_center_size(pos2(x + 40.0, cy), vec2(16.0, 16.0));
|
||||
let resp = ui.interact(br, egui::Id::new(("tl-shapeadd", uid)), Sense::click()).on_hover_text("Add a shape, fill, stroke or path operation");
|
||||
icons::paint(p, br.shrink(3.0), Icon::ChevronRight, if resp.hovered() { t.text } else { t.text_dim });
|
||||
app.auto.add(&format!("timeline.group.{uid}.add"), br, "Add:");
|
||||
let pop = egui::Id::new(("tl-shapeadd-pop", uid));
|
||||
if resp.clicked() {
|
||||
widgets::open_popup(ui, pop);
|
||||
}
|
||||
let opts: Vec<String> = SHAPE_ADD_ITEMS.iter().map(|(k, l)| if *k == "-" { "-".to_string() } else { l.to_string() }).collect();
|
||||
if let Some(i) = widgets::popup_menu(ui, pop, br.left_bottom(), &opts, None)
|
||||
&& let Some((kind, _)) = SHAPE_ADD_ITEMS.get(i).filter(|(k, _)| *k != "-")
|
||||
{
|
||||
let mut params = json!({"layer": layer.id.0, "kind": kind});
|
||||
// Into the selected shape group, as After Effects does.
|
||||
let group = app.session.state.selected_props.iter().filter(|(l, _)| *l == layer.id).find_map(|(_, u)| {
|
||||
let g = layer.props.find_group(*u)?;
|
||||
(g.match_id == "group" && g.sub("contents").is_some()).then_some(g.uid)
|
||||
});
|
||||
if let Some(g) = group {
|
||||
params["group"] = json!(g);
|
||||
}
|
||||
actions.push(("layer.addShapeItem".into(), params));
|
||||
}
|
||||
}
|
||||
|
||||
/// The Text group's "Animate:" and an animator's "Add:" pop-up menus (AE's twirl-down menus).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn text_anim_popups(
|
||||
@@ -2794,6 +2915,26 @@ fn fmt_num(v: f64, d: usize) -> String {
|
||||
format!("{v:.d$}")
|
||||
}
|
||||
|
||||
/// Linked values after component `d` of `c` became `v`: the others scale by the same ratio
|
||||
/// (Constrain Proportions); from 0 the others that are 0 too follow the value.
|
||||
fn constrained(c: &[f64], d: usize, v: f64) -> Vec<f64> {
|
||||
let Some(&old) = c.get(d) else { return c.to_vec() };
|
||||
c.iter()
|
||||
.enumerate()
|
||||
.map(|(e, &x)| {
|
||||
if e == d {
|
||||
v
|
||||
} else if old.abs() > 1e-9 {
|
||||
x * v / old
|
||||
} else if x.abs() <= 1e-9 {
|
||||
v
|
||||
} else {
|
||||
x
|
||||
}
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Inline value editor for a property row; pushes `prop.set` actions.
|
||||
fn value_editor(
|
||||
app: &mut EffectcraftApp,
|
||||
@@ -2841,21 +2982,35 @@ fn value_editor(
|
||||
let c = value.components();
|
||||
let n = if prop.shown_dims > 0 && !(is_3d && c.len() == 3) { prop.shown_dims as usize } else { c.len() };
|
||||
let pct = matches!(prop.ui, ParamUi::Percent);
|
||||
// Mask Feather: two linked values, never negative (as in After Effects, #203).
|
||||
let feather = prop.match_id == "feather" && layer.props.parent_of(uid).is_some_and(|g| matches!(g.kind, GroupKind::Mask { .. }));
|
||||
let range = if feather { (0.0, 1e9) } else { (-1e9, 1e9) };
|
||||
// Scale and Mask Feather: the chain link (Constrain Proportions, on by default).
|
||||
let linkable = feather || (pct && prop.match_id == "scale");
|
||||
let linked = linkable && !app.ui.timeline.unlinked.contains(&uid);
|
||||
if linkable {
|
||||
let lr = Rect::from_center_size(pos2(x + 7.0, at.y), vec2(14.0, 14.0));
|
||||
let resp = ui.interact(lr, egui::Id::new(("tl-link", uid)), Sense::click()).on_hover_text("Constrain Proportions");
|
||||
icons::paint(p, lr, Icon::Link, if linked { t.accent } else { t.text_faint });
|
||||
app.auto.add(&format!("timeline.prop.{uid}.link"), lr, "Constrain Proportions");
|
||||
if resp.clicked() && !app.ui.timeline.unlinked.remove(&uid) {
|
||||
app.ui.timeline.unlinked.insert(uid);
|
||||
}
|
||||
x += 18.0;
|
||||
}
|
||||
for d in 0..n.min(c.len()) {
|
||||
let suffix = if pct && d + 1 == n { "%" } else { "" };
|
||||
let (r, nv, _) =
|
||||
widgets::hot_number_at(ui, pos2(x, y), egui::Id::new(("v", uid, d)), c[d], if pct { 0.5 } else { 1.0 }, (-1e9, 1e9), 1, suffix, &t);
|
||||
let (r, nv, _) = widgets::hot_number_at(ui, pos2(x, y), egui::Id::new(("v", uid, d)), c[d], if pct { 0.5 } else { 1.0 }, range, 1, suffix, &t);
|
||||
app.auto.add(&format!("timeline.prop.{uid}.value.{d}"), r, &prop.name);
|
||||
if let Some(nv) = nv {
|
||||
let mut nc = c.clone();
|
||||
if pct && prop.match_id == "scale" && !ui.input(|i| i.modifiers.alt) {
|
||||
// Constrain proportions (AE's chain link, on by default).
|
||||
let k = if c[d].abs() > 1e-9 { nv / c[d] } else { 1.0 };
|
||||
for e in 0..n {
|
||||
nc[e] = if e == d { nv } else { c[e] * k };
|
||||
// Alt edits one value of a linked pair.
|
||||
let shown = if linked && !ui.input(|i| i.modifiers.alt) { n.min(c.len()) } else { 1 };
|
||||
let from = if shown == 1 { d } else { 0 };
|
||||
for (e, v) in constrained(c.get(from..from + shown).unwrap_or_default(), d - from, nv).into_iter().enumerate() {
|
||||
if let Some(slot) = nc.get_mut(from + e) {
|
||||
*slot = v;
|
||||
}
|
||||
} else {
|
||||
nc[d] = nv;
|
||||
}
|
||||
set(actions, json!(nc));
|
||||
}
|
||||
|
||||
@@ -397,7 +397,7 @@ fn aux_views(
|
||||
_ => {
|
||||
let opts = effectcraft_engine::render::RenderOpts { scale, view: comp.has_3d().then_some(cam), draft: true, ..Default::default() };
|
||||
let img = app.session.render(cid, t, opts);
|
||||
let tex = ctx.load_texture(format!("viewer-aux-{i}"), crate::frames::to_color_image(&img), egui::TextureOptions::LINEAR);
|
||||
let tex = crate::frames::load_fitted(&ctx, format!("viewer-aux-{i}"), crate::frames::to_color_image(&img), egui::TextureOptions::LINEAR);
|
||||
ctx.data_mut(|d| d.insert_temp(id, (key, tex.clone())));
|
||||
tex
|
||||
}
|
||||
@@ -459,7 +459,7 @@ fn locked_pane(app: &mut EffectcraftApp, ui: &mut egui::Ui, full: Rect, bg: Colo
|
||||
dc.apply(&mut px);
|
||||
ci = egui::ColorImage::new(ci.size, px.into_iter().map(|a| Color32::from_rgba_premultiplied(a[0], a[1], a[2], a[3])).collect());
|
||||
}
|
||||
let tex = ctx.load_texture("viewer-locked", ci, egui::TextureOptions::LINEAR);
|
||||
let tex = crate::frames::load_fitted(&ctx, "viewer-locked", ci, egui::TextureOptions::LINEAR);
|
||||
ctx.data_mut(|d| d.insert_temp(id, (key, tex.clone())));
|
||||
tex
|
||||
}
|
||||
@@ -1912,12 +1912,15 @@ fn show_frame(app: &mut EffectcraftApp, ctx: &egui::Context, key: crate::frames:
|
||||
let opts = zoom_texture_options(smooth);
|
||||
match img {
|
||||
FrameImage::Cpu(img) => {
|
||||
// Frames wider or taller than the GPU's texture limit go up averaged down (#201).
|
||||
let max = crate::frames::max_texture_side(ctx);
|
||||
let fitted = crate::frames::fit_texture((*img).clone(), max);
|
||||
match &mut app.viewer_tex {
|
||||
Some((tex, k)) if tex.size() == img.size => {
|
||||
tex.set((*img).clone(), opts);
|
||||
Some((tex, k)) if tex.size() == fitted.size => {
|
||||
tex.set(fitted, opts);
|
||||
*k = key;
|
||||
}
|
||||
_ => app.viewer_tex = Some((ctx.load_texture("viewer-frame", (*img).clone(), opts), key)),
|
||||
_ => app.viewer_tex = Some((ctx.load_texture("viewer-frame", fitted, opts), key)),
|
||||
}
|
||||
app.viewer_shown = app.viewer_tex.as_ref().map(|(t, k)| (t.id(), *k));
|
||||
app.viewer_image = Some(img);
|
||||
|
||||
@@ -382,7 +382,7 @@ pub(crate) fn draw_frame(app: &mut EffectcraftApp, ctx: &egui::Context, painter:
|
||||
_ => {
|
||||
let img = crate::frames::to_color_image(&s.image);
|
||||
let img = if plain { img } else { transformed(&img, opts.channel, opts.colorized, opts.exposure, dc) };
|
||||
let tex = ctx.load_texture("viewer-snapshot", img, egui::TextureOptions::LINEAR);
|
||||
let tex = crate::frames::load_fitted(ctx, "viewer-snapshot", img, egui::TextureOptions::LINEAR);
|
||||
ctx.data_mut(|d| d.insert_temp(id, (key, tex.clone())));
|
||||
tex
|
||||
}
|
||||
@@ -432,7 +432,7 @@ pub(crate) fn draw_frame(app: &mut EffectcraftApp, ctx: &egui::Context, painter:
|
||||
let tex = match ctx.data(|d| d.get_temp::<(u64, egui::TextureHandle)>(id)) {
|
||||
Some((k, tex)) if k == key => tex,
|
||||
_ => {
|
||||
let tex = ctx.load_texture("viewer-display", transformed(&src, opts.channel, opts.colorized, opts.exposure, dc), zoom_opts);
|
||||
let tex = crate::frames::load_fitted(ctx, "viewer-display", transformed(&src, opts.channel, opts.colorized, opts.exposure, dc), zoom_opts);
|
||||
ctx.data_mut(|d| d.insert_temp(id, (key, tex.clone())));
|
||||
tex
|
||||
}
|
||||
|
||||
@@ -131,13 +131,15 @@ fn set_texture(app: &mut EffectcraftApp, ctx: &egui::Context, id: u32, key: Fram
|
||||
}
|
||||
let opts = super::viewer::zoom_texture_options(app.session.prefs.viewer_zoom_smooth());
|
||||
let tex = match (img, app.passive_tex.remove(&id)) {
|
||||
(FrameImage::Cpu(img), Some((_, PassiveTexture::Cpu(mut h)))) if h.size() == img.size => {
|
||||
h.set((*img).clone(), opts);
|
||||
(FrameImage::Cpu(img), Some((_, PassiveTexture::Cpu(mut h))))
|
||||
if h.size() == crate::frames::fitted_size(img.size, crate::frames::max_texture_side(ctx)) =>
|
||||
{
|
||||
h.set(crate::frames::fit_texture((*img).clone(), crate::frames::max_texture_side(ctx)), opts);
|
||||
PassiveTexture::Cpu(h)
|
||||
}
|
||||
(FrameImage::Cpu(img), old) => {
|
||||
free(app, old.map(|(_, t)| t));
|
||||
PassiveTexture::Cpu(ctx.load_texture(format!("viewer-{id}"), (*img).clone(), opts))
|
||||
PassiveTexture::Cpu(crate::frames::load_fitted(ctx, format!("viewer-{id}"), (*img).clone(), opts))
|
||||
}
|
||||
(FrameImage::Gpu(f), old) => {
|
||||
let Some(rs) = &app.wgpu else { return };
|
||||
|
||||
@@ -108,10 +108,10 @@ fn video_preview(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
let opts = crate::panels::viewer::zoom_texture_options(app.session.prefs.viewer_zoom_smooth());
|
||||
let t = match prev {
|
||||
Some((_, mut t)) => {
|
||||
t.set((*img).clone(), opts);
|
||||
t.set(crate::frames::fit_texture((*img).clone(), crate::frames::max_texture_side(ctx)), opts);
|
||||
t
|
||||
}
|
||||
None => ctx.load_texture("video-preview", (*img).clone(), opts),
|
||||
None => crate::frames::load_fitted(ctx, "video-preview", (*img).clone(), opts),
|
||||
};
|
||||
ctx.data_mut(|d| d.insert_temp(tex_id, (k, t.clone())));
|
||||
Some(t)
|
||||
|
||||
@@ -413,6 +413,10 @@ pub struct TimelineState {
|
||||
/// Properties whose inline expression editor is collapsed.
|
||||
#[serde(default)]
|
||||
pub expr_closed: BTreeSet<u64>,
|
||||
/// Scale and Mask Feather properties whose chain link (Constrain Proportions, on by default)
|
||||
/// was turned off.
|
||||
#[serde(default)]
|
||||
pub unlinked: BTreeSet<u64>,
|
||||
/// Visible optional columns (column header right-click ▸ Columns): `av`, `keys`, `label`,
|
||||
/// `num`, `comment`, `switches`, `parent`, `in`, `out`, `duration`, `stretch`. The name
|
||||
/// column is always shown; Modes follows `show_modes` (F4).
|
||||
@@ -458,6 +462,7 @@ impl Default for TimelineState {
|
||||
graph_reference: false,
|
||||
graph_transform_box: true,
|
||||
expr_closed: BTreeSet::new(),
|
||||
unlinked: BTreeSet::new(),
|
||||
columns: default_tl_columns(),
|
||||
source_name: false,
|
||||
}
|
||||
|
||||
@@ -283,10 +283,20 @@ pub fn popup_menu(ui: &mut Ui, id: egui::Id, pos: egui::Pos2, options: &[String]
|
||||
if !open {
|
||||
return None;
|
||||
}
|
||||
// As tall as the window allows (a shape layer's Add menu has 20 entries), scrolling beyond,
|
||||
// and moved up when it would run past the bottom of the window (the Timeline's menus).
|
||||
let screen = ui.ctx().content_rect();
|
||||
let max_h = (screen.height() - 24.0).max(120.0);
|
||||
let sp = ui.spacing();
|
||||
let seps = options.iter().filter(|o| *o == "-").count() as f32;
|
||||
let rows = options.len() as f32 - seps;
|
||||
let est = (rows * (sp.interact_size.y + sp.item_spacing.y + 4.0) + seps * (2.0 * sp.item_spacing.y + 2.0) + 16.0).min(max_h + 12.0);
|
||||
let pos = egui::pos2(pos.x, pos.y.min(screen.bottom() - est).max(screen.top()));
|
||||
let area = egui::Area::new(id.with("area")).order(egui::Order::Foreground).fixed_pos(pos).show(ui.ctx(), |ui| {
|
||||
egui::Frame::popup(ui.style()).show(ui, |ui| {
|
||||
ui.set_min_width(160.0);
|
||||
egui::ScrollArea::vertical().max_height(420.0).show(ui, |ui| {
|
||||
// (An area's content is laid out in last frame's size: ask for the estimate.)
|
||||
egui::ScrollArea::vertical().max_height(max_h).min_scrolled_height((est - 16.0).min(max_h)).show(ui, |ui| {
|
||||
for (i, o) in options.iter().enumerate() {
|
||||
if o == "-" {
|
||||
ui.separator();
|
||||
|
||||
@@ -30,10 +30,15 @@ impl AudioDevice for Fake {
|
||||
}
|
||||
}
|
||||
|
||||
/// A 30 fps comp whose solid sounds a tone (Audio switch on).
|
||||
/// A 2 s, 30 fps comp whose solid sounds a tone (Audio switch on).
|
||||
fn setup(audible: bool, fake: &Fake) -> (EffectcraftApp, ItemId) {
|
||||
setup_long(audible, fake, 2.0)
|
||||
}
|
||||
|
||||
/// A `duration`-second, 30 fps comp whose solid sounds a tone (Audio switch on).
|
||||
fn setup_long(audible: bool, fake: &Fake, duration: f64) -> (EffectcraftApp, ItemId) {
|
||||
let mut s = Session::default();
|
||||
s.execute("comp.new", json!({"name": "A", "width": 64, "height": 36, "frameRate": 30, "duration": 2})).unwrap();
|
||||
s.execute("comp.new", json!({"name": "A", "width": 64, "height": 36, "frameRate": 30, "duration": duration})).unwrap();
|
||||
let cid = s.active_comp_id().unwrap();
|
||||
let l = s.execute("layer.newSolid", json!({"color": "#808080"})).unwrap()["layer"].as_u64().unwrap();
|
||||
if audible {
|
||||
@@ -140,8 +145,41 @@ fn preview_with_audio_shows_every_frame_and_sounds_once_cached() {
|
||||
}
|
||||
assert!(h.state().audio.is_some() && fake.0.lock().unwrap().0.is_some(), "the sound started once the frames ahead were cached");
|
||||
assert!(shown > 0, "frames played silently first");
|
||||
// A frame that isn't cached stops the sound rather than being skipped.
|
||||
// A frame that isn't cached stops the sound rather than being skipped. (Frames render fast
|
||||
// enough here to be cached again before the check: keep them out of the cache.)
|
||||
h.state().frames.set_budget(0);
|
||||
h.state().frames.clear();
|
||||
h.step();
|
||||
assert!(h.state().audio.is_none() && h.state().playback.audio_held && h.state().playback.playing);
|
||||
}
|
||||
|
||||
/// A preview whose frames render in real time sounds without waiting for the whole work area to
|
||||
/// be cached (#208): once the silent preview has kept up for a moment with the frames ahead
|
||||
/// cached, the sound starts, still without skipping a frame before it.
|
||||
#[test]
|
||||
fn preview_with_audio_sounds_once_rendering_keeps_up() {
|
||||
let fake = Fake::default();
|
||||
let (app, cid) = setup_long(true, &fake, 30.0);
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1400.0, 900.0)).with_step_dt(1.0 / 30.0).build_eframe(|_| app);
|
||||
h.run_steps(2);
|
||||
let frame = |h: &Harness<'_, EffectcraftApp>| {
|
||||
let app = h.state();
|
||||
app.session.project.comp(cid).unwrap().frame_rate.frame_at(app.session.time())
|
||||
};
|
||||
let now = h.ctx.input(|i| i.time);
|
||||
h.state_mut().play(now);
|
||||
assert!(h.state().playback.audio_held && h.state().audio.is_none(), "nothing is cached: no sound yet");
|
||||
let mut last = frame(&h);
|
||||
// Two seconds of playback, each step giving the frame workers time to keep up.
|
||||
for _ in 0..60 {
|
||||
h.step();
|
||||
if h.state().audio.is_some() {
|
||||
break;
|
||||
}
|
||||
let f = frame(&h);
|
||||
assert!(f == last || f == last + 1, "{last} → {f}: a frame was skipped");
|
||||
last = f;
|
||||
std::thread::sleep(std::time::Duration::from_millis(20));
|
||||
}
|
||||
assert!(h.state().audio.is_some() && fake.0.lock().unwrap().0.is_some(), "the sound started within 2 s, at frame {last} of 900");
|
||||
}
|
||||
|
||||
@@ -95,3 +95,27 @@ fn label_swatch_opens_the_label_menu() {
|
||||
assert_eq!(h.state().session.history.undo.len(), undo + 1);
|
||||
assert!(h.query_by_label(&green).is_none(), "the menu closed after the choice");
|
||||
}
|
||||
|
||||
/// Dragging from the Project panel's empty area draws a selection box that selects the rows it
|
||||
/// touches; a click there deselects (#203).
|
||||
#[test]
|
||||
fn dragging_in_the_empty_area_box_selects_items() {
|
||||
let (mut h, folder, _, solid) = harness();
|
||||
let list = h.state().auto.find("project.empty").unwrap().rect;
|
||||
let from = pos2(list[0] + 40.0, list[1] + list[3] - 6.0);
|
||||
let to = center(&h, &format!("project.item.{}.name", folder.0));
|
||||
h.input_mut().events.push(Event::PointerMoved(from));
|
||||
h.step();
|
||||
button(&mut h, from, true);
|
||||
h.step();
|
||||
for k in 1..=6 {
|
||||
h.input_mut().events.push(Event::PointerMoved(from + (to - from) * (k as f32 / 6.0)));
|
||||
h.step();
|
||||
}
|
||||
button(&mut h, to, false);
|
||||
h.run_steps(2);
|
||||
let sel = h.state().session.state.project_selection.clone();
|
||||
assert!(sel.contains(&folder) && sel.contains(&solid), "{sel:?}");
|
||||
click_at(&mut h, from);
|
||||
assert!(h.state().session.state.project_selection.is_empty());
|
||||
}
|
||||
|
||||
@@ -0,0 +1,154 @@
|
||||
//! Timeline rows for shape layers, masks and keyframing: the Contents "Add:" menu and the Classic
|
||||
//! 3D "Change Renderer…" row (#206), Alt+Shift+P revealing the key it adds and clicks below the
|
||||
//! layers deselecting them (#205), and Mask Feather's linked values (#203).
|
||||
|
||||
use effectcraft_engine::Session;
|
||||
use effectcraft_engine::project::LayerId;
|
||||
use effectcraft_ui_egui::{Dialog, EffectcraftApp};
|
||||
use egui::{Event, Key, Modifiers, PointerButton, Pos2, pos2};
|
||||
use egui_kittest::Harness;
|
||||
use egui_kittest::kittest::Queryable;
|
||||
use serde_json::json;
|
||||
|
||||
fn harness(s: Session) -> Harness<'static, EffectcraftApp> {
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
h.run_steps(3);
|
||||
h
|
||||
}
|
||||
|
||||
fn session() -> Session {
|
||||
let mut s = Session::default();
|
||||
s.execute("comp.new", json!({"name": "Main", "width": 320, "height": 180, "duration": 4})).unwrap();
|
||||
s
|
||||
}
|
||||
|
||||
fn center(h: &Harness<'_, EffectcraftApp>, id: &str) -> Pos2 {
|
||||
let e = h.state().auto.find(id).unwrap_or_else(|| panic!("no {id}"));
|
||||
pos2(e.rect[0] + e.rect[2] / 2.0, e.rect[1] + e.rect[3] / 2.0)
|
||||
}
|
||||
|
||||
fn click_at(h: &mut Harness<'_, EffectcraftApp>, p: Pos2) {
|
||||
h.input_mut().events.push(Event::PointerMoved(p));
|
||||
h.step();
|
||||
h.input_mut().events.push(Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: true, modifiers: Modifiers::NONE });
|
||||
h.step();
|
||||
h.input_mut().events.push(Event::PointerButton { pos: p, button: PointerButton::Primary, pressed: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(3);
|
||||
}
|
||||
|
||||
fn click(h: &mut Harness<'_, EffectcraftApp>, id: &str) {
|
||||
let p = center(h, id);
|
||||
click_at(h, p);
|
||||
}
|
||||
|
||||
fn open_layer(h: &mut Harness<'_, EffectcraftApp>, id: u64) {
|
||||
h.state_mut().ui.timeline.open_layers.insert(id);
|
||||
h.run_steps(2);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn shape_contents_add_menu_adds_path_operations() {
|
||||
let mut s = session();
|
||||
let l = s.execute("layer.newShape", json!({"kind": "ellipse"})).unwrap()["layer"].as_u64().unwrap();
|
||||
let contents = s.active_comp().unwrap().layer(LayerId(l)).unwrap().props.sub("contents").unwrap().uid;
|
||||
let mut h = harness(s);
|
||||
open_layer(&mut h, l);
|
||||
click(&mut h, &format!("timeline.group.{contents}.add"));
|
||||
let entry = h.get_by_label("Trim Paths").rect();
|
||||
assert!(entry.max.y <= 1000.0, "the whole menu fits in the window: {entry:?}");
|
||||
click_at(&mut h, entry.center());
|
||||
let layer = h.state().session.active_comp().unwrap().layer(LayerId(l)).unwrap().clone();
|
||||
let items: Vec<&str> = layer.props.sub("contents").unwrap().groups().map(|g| g.match_id.as_str()).collect();
|
||||
assert_eq!(items, ["group", "trim"]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn classic_3d_shape_layers_offer_change_renderer() {
|
||||
let mut s = session();
|
||||
let l = s.execute("layer.newShape", json!({"kind": "rect"})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("layer.setSwitch", json!({"layers": [l], "switch": "threeD", "value": true})).unwrap();
|
||||
let mut h = harness(s);
|
||||
open_layer(&mut h, l);
|
||||
click(&mut h, &format!("timeline.layer.{l}.changeRenderer"));
|
||||
assert_eq!(h.state().dialog, Some(Dialog::CompSettings));
|
||||
assert!(h.state().auto.find("dialog.comp.renderer").is_some(), "on the 3D Renderer tab");
|
||||
// Advanced 3D shows the extrusion options instead.
|
||||
h.state_mut().dialog = None;
|
||||
h.state_mut().session.execute("comp.renderer", json!({"renderer": "advanced3d"})).unwrap();
|
||||
h.run_steps(3);
|
||||
assert!(h.state().auto.find(&format!("timeline.layer.{l}.changeRenderer")).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_position_key_reveals_position() {
|
||||
let mut s = session();
|
||||
let l = s.execute("layer.newSolid", json!({"color": "#808080"})).unwrap()["layer"].as_u64().unwrap();
|
||||
let mut h = harness(s);
|
||||
let ctx = h.ctx.clone();
|
||||
effectcraft_ui_egui::menus::invoke(h.state_mut(), &ctx, "timeline.keyAt.position", json!({})).unwrap();
|
||||
h.run_steps(2);
|
||||
let app = h.state();
|
||||
let position = app.session.active_comp().unwrap().layer(LayerId(l)).unwrap().props.prop("transform/position").unwrap().clone();
|
||||
assert_eq!(position.keys.len(), 1);
|
||||
assert_eq!(app.ui.timeline.layer_reveal.get(&l), Some(&vec!["position".to_string()]));
|
||||
assert!(app.auto.find(&format!("timeline.prop.{}.value.0", position.uid)).is_some(), "the Position row shows");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn clicking_below_the_layers_deselects_them() {
|
||||
let mut s = session();
|
||||
let l = s.execute("layer.newSolid", json!({"color": "#808080"})).unwrap()["layer"].as_u64().unwrap();
|
||||
let mut h = harness(s);
|
||||
assert_eq!(h.state().session.state.selected_layers, vec![LayerId(l)]);
|
||||
// In the time graph, below the only layer.
|
||||
let bar = center(&h, &format!("timeline.layer.{l}.bar"));
|
||||
click_at(&mut h, bar + egui::vec2(0.0, 80.0));
|
||||
assert!(h.state().session.state.selected_layers.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn mask_feather_values_are_linked_and_not_negative() {
|
||||
let mut s = session();
|
||||
let l = s.execute("layer.newSolid", json!({"color": "#808080"})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("layer.addMask", json!({"layer": l, "shape": "rect"})).unwrap();
|
||||
let feather = |h: &Harness<'_, EffectcraftApp>| {
|
||||
let p = h.state().session.active_comp().unwrap().layer(LayerId(l)).unwrap().props.prop("masks/#1/feather").unwrap().clone();
|
||||
(p.uid, p.value.components())
|
||||
};
|
||||
let mut h = harness(s);
|
||||
h.state_mut().ui.timeline.open_layers.insert(l);
|
||||
h.state_mut().ui.timeline.layer_reveal.insert(l, vec!["feather".into()]);
|
||||
h.run_steps(2);
|
||||
let (uid, _) = feather(&h);
|
||||
let type_value = |h: &mut Harness<'_, EffectcraftApp>, d: usize, v: &str| {
|
||||
click(h, &format!("timeline.prop.{uid}.value.{d}"));
|
||||
h.input_mut().events.push(Event::Text(v.into()));
|
||||
h.step();
|
||||
h.input_mut().events.push(Event::Key { key: Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(3);
|
||||
};
|
||||
type_value(&mut h, 0, "12");
|
||||
assert_eq!(feather(&h).1, vec![12.0, 12.0], "linked by default");
|
||||
type_value(&mut h, 1, "-5");
|
||||
assert_eq!(feather(&h).1, vec![0.0, 0.0], "never negative");
|
||||
click(&mut h, &format!("timeline.prop.{uid}.link"));
|
||||
type_value(&mut h, 1, "7");
|
||||
assert_eq!(feather(&h).1, vec![0.0, 7.0], "unlinked");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn toolbar_stroke_edits_the_selected_shape_layer() {
|
||||
let mut s = session();
|
||||
let l = s.execute("layer.newShape", json!({"kind": "rect", "fill": "#ff0000"})).unwrap()["layer"].as_u64().unwrap();
|
||||
let mut h = harness(s);
|
||||
// The Selection tool is active: the options show for the selected shape layer.
|
||||
click(&mut h, "header.strokeWidth");
|
||||
h.input_mut().events.push(Event::Text("4".into()));
|
||||
h.step();
|
||||
h.input_mut().events.push(Event::Key { key: Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE });
|
||||
h.run_steps(3);
|
||||
let layer = h.state().session.active_comp().unwrap().layer(LayerId(l)).unwrap().clone();
|
||||
let width = layer.props.prop("contents/group/contents/stroke/width").map(|p| p.value.as_f64());
|
||||
assert_eq!(width, Some(4.0), "a stroke was added with the toolbar's width");
|
||||
assert_eq!(h.state().ui.stroke_width, 4.0);
|
||||
}
|
||||
@@ -1019,3 +1019,26 @@ fn handle_drags_scale_about_the_anchor_and_follow_the_pointer() {
|
||||
drag_path(&mut h, &path, egui::Modifiers::SHIFT);
|
||||
assert!(close(scale(&h), [162.5, 162.5]), "{:?}", scale(&h));
|
||||
}
|
||||
|
||||
/// A comp wider than the GPU's texture limit at Full resolution shows its frame (averaged down
|
||||
/// into a texture the renderer accepts) instead of failing the upload (#201: 11000×2200).
|
||||
#[test]
|
||||
fn full_resolution_frames_wider_than_the_texture_limit_fit() {
|
||||
let mut s = Session::default();
|
||||
s.execute("comp.new", json!({"name": "Wide", "width": 2400, "height": 400, "duration": 1})).unwrap();
|
||||
s.execute("layer.newSolid", json!({"name": "Plate", "color": "#406080"})).unwrap();
|
||||
let mut h = Harness::builder().with_size(egui::vec2(1600.0, 1000.0)).build_eframe(|_| EffectcraftApp::new(s));
|
||||
// (egui's font atlas needs 1024.)
|
||||
h.input_mut().max_texture_side = Some(1024);
|
||||
h.state_mut().ui.viewer.res = effectcraft_ui_egui::state::Resolution::Full;
|
||||
let full = |h: &mut Harness<'_, EffectcraftApp>| h.state_mut().viewer_pixels().is_some_and(|px| px.size == [2400, 400]);
|
||||
for _ in 0..400 {
|
||||
h.step();
|
||||
if full(&mut h) {
|
||||
break;
|
||||
}
|
||||
std::thread::sleep(std::time::Duration::from_millis(5));
|
||||
}
|
||||
assert!(full(&mut h), "the full-size frame is shown (and stays readable): {:?}", h.state().ui.viewer.res);
|
||||
assert_eq!(h.state().viewer_texture_size(), Some([800, 134]), "2400×400 averaged by 3");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user