G2: improve editing reliability and Windows rendering fidelity
This commit is contained in:
@@ -396,6 +396,15 @@ pub fn to_color_image(img: &effectcraft_engine::render::Image) -> egui::ColorIma
|
||||
}
|
||||
|
||||
impl Frames {
|
||||
/// Actual native frame-worker capacity, including the OS fallback pool.
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
pub fn parallelism(&self) -> usize {
|
||||
self.pool.as_ref().map_or_else(rayon::current_num_threads, rayon::ThreadPool::current_num_threads)
|
||||
}
|
||||
#[cfg(target_arch = "wasm32")]
|
||||
pub fn parallelism(&self) -> usize {
|
||||
self.remote_slots().max(1)
|
||||
}
|
||||
pub fn set_context(&mut self, ctx: &egui::Context) {
|
||||
if self.ctx.is_none() {
|
||||
self.ctx = Some(ctx.clone());
|
||||
@@ -736,18 +745,21 @@ impl Worker {
|
||||
let t0 = web_time::Instant::now();
|
||||
let disk = job.src.disk.as_ref().map(|dc| (dc.clone(), frame_disk_key(content_keys, &job.src.project, &job.key, opts_hash(&job.opts))));
|
||||
let from_disk = disk.as_ref().and_then(|(dc, k)| dc.get_frame(*k));
|
||||
let disk_hit = from_disk.is_some();
|
||||
let ci = match from_disk {
|
||||
Some(f) => FrameImage::Cpu(Arc::new(egui::ColorImage::from_rgba_premultiplied([f.width as usize, f.height as usize], &f.rgba))),
|
||||
None => {
|
||||
let ci = self.render_job(&job);
|
||||
if let (Some((dc, k)), FrameImage::Cpu(img)) = (&disk, &ci) {
|
||||
let rgba: Vec<u8> = img.pixels.iter().flat_map(|c| c.to_array()).collect();
|
||||
dc.put_frame(*k, img.size[0] as u32, img.size[1] as u32, &rgba);
|
||||
}
|
||||
ci
|
||||
}
|
||||
None => self.render_job(&job),
|
||||
};
|
||||
self.finish(&job, ci, t0);
|
||||
// Publish the shared frame and wake the viewer before optional RGBA conversion
|
||||
// and compression. Persistence still runs on this worker, using the same snapshot.
|
||||
self.finish(&job, ci.clone(), t0);
|
||||
if !disk_hit && let (Some((dc, k)), FrameImage::Cpu(img)) = (&disk, &ci) {
|
||||
let rgba: Vec<u8> = img.pixels.iter().flat_map(|c| c.to_array()).collect();
|
||||
dc.put_frame(*k, img.size[0] as u32, img.size[1] as u32, &rgba);
|
||||
if let Some(ctx) = &self.ctx {
|
||||
ctx.request_repaint();
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
|
||||
@@ -433,14 +433,21 @@ impl EffectcraftApp {
|
||||
}
|
||||
self.gpu_checked = true;
|
||||
let Some(rs) = frame.wgpu_render_state() else { return };
|
||||
match effectcraft_gpu::Gpu::new(&rs.adapter, rs.device.clone(), rs.queue.clone()) {
|
||||
Ok(g) => {
|
||||
// Backend validation can panic on shader compilation even when device creation
|
||||
// succeeded. Keep the document and the egui renderer, and use CPU compositing.
|
||||
let gpu = std::panic::catch_unwind(std::panic::AssertUnwindSafe(|| effectcraft_gpu::Gpu::new(&rs.adapter, rs.device.clone(), rs.queue.clone())));
|
||||
match gpu {
|
||||
Ok(Ok(g)) => {
|
||||
log::info!("GPU compositor: {}", effectcraft_engine::render::Accelerator::name(&g));
|
||||
self.session.accel = Some(Arc::new(g.clone()));
|
||||
self.gpu = Some(g);
|
||||
self.wgpu = Some(rs.clone());
|
||||
}
|
||||
Err(e) => log::info!("GPU compositor unavailable: {e}"),
|
||||
Ok(Err(e)) => log::info!("GPU compositor unavailable: {e}"),
|
||||
Err(e) => {
|
||||
let reason = e.downcast_ref::<String>().map(String::as_str).or_else(|| e.downcast_ref::<&str>().copied()).unwrap_or("backend panicked");
|
||||
log::warn!("GPU compositor setup failed; using CPU compositing: {reason}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -461,7 +468,7 @@ impl EffectcraftApp {
|
||||
/// and returns `None`; a later call (the next frame) has the pixels.
|
||||
pub fn viewer_pixels(&mut self) -> Option<Arc<egui::ColorImage>> {
|
||||
let to_image = |bytes: Vec<u8>, w: u32, h: u32| {
|
||||
let px = bytes.chunks_exact(4).map(|c| egui::Color32::from_rgba_premultiplied(c[0], c[1], c[2], c[3])).collect();
|
||||
let px = bytes.as_chunks::<4>().0.iter().map(|c| egui::Color32::from_rgba_premultiplied(c[0], c[1], c[2], c[3])).collect();
|
||||
Arc::new(egui::ColorImage::new([w as usize, h as usize], px))
|
||||
};
|
||||
if self.viewer_image.is_none()
|
||||
@@ -511,7 +518,7 @@ impl EffectcraftApp {
|
||||
// play back, and frames cached by a preview stay on screen when it stops.
|
||||
let full = self.ui.viewer.res.scale(zoom, ppp);
|
||||
// Fast Previews ▸ Adaptive Resolution / Fast Draft: lower resolution while dragging.
|
||||
let (_, k) = self.session.state.viewer.fast_previews.render(self.ui.viewer.interacting);
|
||||
let (_, k) = self.session.state.viewer.fast_previews.render(self.ui.viewer.interacting || self.ui.viewer.property_interacting);
|
||||
if k < 1.0 && self.ui.viewer.res == state::Resolution::Auto {
|
||||
return full.min((full * 0.5).max(self.session.prefs.adaptive_limit()));
|
||||
}
|
||||
@@ -585,7 +592,7 @@ impl EffectcraftApp {
|
||||
|
||||
/// Render options of viewer frames of `comp` at `scale`.
|
||||
pub fn frame_opts(&self, comp: ItemId, scale: f64) -> RenderOpts {
|
||||
let (draft, _) = self.session.state.viewer.fast_previews.render(self.ui.viewer.interacting);
|
||||
let (draft, _) = self.session.state.viewer.fast_previews.render(self.ui.viewer.interacting || self.ui.viewer.property_interacting);
|
||||
let roi = self.viewer_region(comp);
|
||||
RenderOpts {
|
||||
scale,
|
||||
@@ -814,7 +821,9 @@ impl EffectcraftApp {
|
||||
ctx.request_repaint_after(std::time::Duration::from_secs_f64(wait));
|
||||
0
|
||||
} else {
|
||||
(self.frames_parallelism() / 2).max(2) as i64
|
||||
// Keep workers available for a newly edited viewer frame. Running obsolete
|
||||
// background renders cannot be preempted by the priority queue.
|
||||
self.frames_parallelism().saturating_sub(1).min(2) as i64
|
||||
};
|
||||
let mut queued = self.frames.inflight();
|
||||
let series = self.frame_series(cid, scale);
|
||||
@@ -1042,7 +1051,7 @@ impl EffectcraftApp {
|
||||
// on the UI thread (`Frames::pump`)
|
||||
return self.frames.remote_slots().max(1);
|
||||
}
|
||||
std::thread::available_parallelism().map(|n| n.get()).unwrap_or(4)
|
||||
self.frames.parallelism()
|
||||
}
|
||||
|
||||
// ---------------------------------------------------------------- control channel
|
||||
@@ -1252,8 +1261,14 @@ impl EffectcraftApp {
|
||||
self.command_inbox = Some(rx);
|
||||
}
|
||||
menus::handle_shortcuts(self, &ctx);
|
||||
if !ctx.input(|i| i.pointer.primary_down()) {
|
||||
self.ui.viewer.property_interacting = false;
|
||||
}
|
||||
let t = self.tokens;
|
||||
let full = ui.max_rect();
|
||||
if self.dialog.is_some() {
|
||||
ui.disable();
|
||||
}
|
||||
ui.painter().rect_filled(full, 0.0, t.app_bg);
|
||||
let mut top = full.min.y;
|
||||
if self.ui.show_menu_bar {
|
||||
@@ -1288,7 +1303,7 @@ impl EffectcraftApp {
|
||||
let t = &self.tokens;
|
||||
let galley = ui.painter().layout_no_wrap(m, Tokens::ui(12.0), t.text);
|
||||
let r = egui::Rect::from_min_size(egui::pos2(full.min.x + 16.0, full.max.y - 44.0), galley.size() + egui::vec2(24.0, 14.0));
|
||||
ui.painter().rect_filled(r, 6.0, egui::Color32::from_rgba_premultiplied(30, 30, 30, 235));
|
||||
ui.painter().rect_filled(r, 6.0, t.panel_bg);
|
||||
ui.painter().rect_stroke(r, 6.0, egui::Stroke::new(1.0, t.field_border), egui::StrokeKind::Inside);
|
||||
ui.painter().galley(r.min + egui::vec2(12.0, 7.0), galley, t.text);
|
||||
let resp = ui.interact(r, egui::Id::new("toast"), egui::Sense::click());
|
||||
|
||||
@@ -191,6 +191,35 @@ fn no_params(p: &Value) -> bool {
|
||||
|
||||
/// Execute a UI or engine command by id.
|
||||
pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: Value) -> Result<Value, String> {
|
||||
if no_params(¶ms) && app.ui.focused == PanelKind::Project {
|
||||
match id {
|
||||
"edit.duplicate" => return run_engine(app, ctx, "project.duplicate", json!({})),
|
||||
"edit.selectAll" => {
|
||||
let items: Vec<u64> = crate::panels::project::visible_rows(app)
|
||||
.into_iter()
|
||||
.filter(|(id, _)| app.ui.project_search.is_empty() || app.session.project.item(*id).is_some_and(|it| !it.is_folder()))
|
||||
.map(|(id, _)| id.0)
|
||||
.collect();
|
||||
return run_engine(app, ctx, "project.select", json!({"items":items}));
|
||||
}
|
||||
"edit.deselectAll" => return run_engine(app, ctx, "project.select", json!({"items":[]})),
|
||||
"edit.cut" | "edit.copy" | "edit.paste" | "edit.copyWithPropertyLinks" | "edit.copyWithRelativePropertyLinks" | "edit.copyExpressionOnly" => {
|
||||
return Err("Project clipboard actions are not supported yet".into());
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
// Clear follows panel focus, including the Edit menu and keyboard shortcut.
|
||||
if id == "edit.clear" && params.as_object().is_some_and(|p| p.is_empty()) && app.ui.focused == PanelKind::Project {
|
||||
return run_engine(app, ctx, "project.delete", json!({}));
|
||||
}
|
||||
if id == "edit.clear" && params.as_object().is_some_and(|p| p.is_empty()) && app.ui.focused == PanelKind::RenderQueue {
|
||||
let selected = ctx.data(|d| d.get_temp::<(Vec<u64>, Option<u64>)>(egui::Id::new("rq-ui"))).and_then(|(_, id)| id);
|
||||
return match selected {
|
||||
Some(item) => run_engine(app, ctx, "renderQueue.remove", json!({"item": item})),
|
||||
None => Err("select a Render Queue item first".into()),
|
||||
};
|
||||
}
|
||||
let now = ctx.input(|i| i.time);
|
||||
// Closing a modified project asks to save it first; the command runs once answered.
|
||||
if crate::panels::unsaved::guard(app, id, ¶ms) {
|
||||
@@ -1117,6 +1146,26 @@ pub(crate) fn entry_checked(app: &EffectcraftApp, e: &MenuEntry) -> Option<bool>
|
||||
}
|
||||
|
||||
pub(crate) fn entry_enabled(app: &EffectcraftApp, e: &MenuEntry) -> bool {
|
||||
if app.ui.focused == PanelKind::Project {
|
||||
match e.command.as_str() {
|
||||
"edit.duplicate" => {
|
||||
return !app.session.state.project_selection.is_empty()
|
||||
&& app.session.state.project_selection.iter().all(|id| app.session.project.item(*id).is_some_and(|i| !i.is_folder()));
|
||||
}
|
||||
"edit.selectAll" => return !app.session.project.items.is_empty(),
|
||||
"edit.deselectAll" => return !app.session.state.project_selection.is_empty(),
|
||||
"edit.cut" | "edit.copy" | "edit.paste" | "edit.copyWithPropertyLinks" | "edit.copyWithRelativePropertyLinks" | "edit.copyExpressionOnly" => {
|
||||
return false;
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
if e.command == "edit.clear" && app.ui.focused == PanelKind::Project {
|
||||
return app.session.is_enabled("project.delete");
|
||||
}
|
||||
if e.command == "edit.clear" && app.ui.focused == PanelKind::RenderQueue {
|
||||
return !app.session.is_rendering() && !app.session.project.render_queue.is_empty();
|
||||
}
|
||||
if e.command == "window.panel" {
|
||||
return true;
|
||||
}
|
||||
@@ -1254,6 +1303,28 @@ fn mods_match(want: egui::Modifiers, got: egui::Modifiers) -> bool {
|
||||
|
||||
/// Dispatch keyboard shortcuts (skipped while typing in a text field).
|
||||
pub fn handle_shortcuts(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
// Dialog cancellation owns Escape even when a text field has keyboard focus.
|
||||
if app.dialog.is_some() && ctx.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
if crate::panels::shortcut_editor::recording(app) || egui::Popup::is_any_open(ctx) {
|
||||
return;
|
||||
}
|
||||
ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape));
|
||||
if app.dialog == Some(crate::Dialog::LayerStyles) {
|
||||
crate::panels::layer_styles_dialog::finish(app, false);
|
||||
} else {
|
||||
if app.dialog == Some(crate::Dialog::Settings)
|
||||
&& let Some(p) = app.dialog_state.prefs_snapshot.take()
|
||||
{
|
||||
app.session.prefs = p;
|
||||
app.session.prefs_changed();
|
||||
}
|
||||
if app.dialog == Some(crate::Dialog::UnsavedChanges) {
|
||||
app.dialog_state.unsaved.command = None;
|
||||
}
|
||||
app.dialog = None;
|
||||
}
|
||||
return;
|
||||
}
|
||||
if ctx.egui_wants_keyboard_input() {
|
||||
return;
|
||||
}
|
||||
@@ -1310,17 +1381,18 @@ pub fn handle_shortcuts(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
// The Project panel has its own selection; a previously selected Timeline layer
|
||||
// must not be deleted while the Project panel has focus.
|
||||
if matches!(key, egui::Key::Delete | egui::Key::Backspace) && !mods.any() {
|
||||
let command = if app.ui.focused == PanelKind::Project {
|
||||
if app.session.state.project_selection.is_empty() {
|
||||
continue;
|
||||
if matches!(app.ui.focused, PanelKind::Composition | PanelKind::Viewer(_)) && !app.session.state.camera_points.is_empty() {
|
||||
if let Err(e) = run_engine(app, ctx, "camera.deletePoints", json!({})) {
|
||||
app.ui.status = e;
|
||||
}
|
||||
"project.delete"
|
||||
} else {
|
||||
"edit.clear"
|
||||
};
|
||||
if let Err(e) = invoke(app, ctx, command, json!({})) {
|
||||
app.ui.status = e;
|
||||
ctx.input_mut(|i| i.consume_key(egui::Modifiers::NONE, key));
|
||||
continue;
|
||||
}
|
||||
// The queue panel consumes the event after its selection state is drawn.
|
||||
if app.ui.focused == PanelKind::RenderQueue {
|
||||
continue;
|
||||
}
|
||||
let _ = invoke(app, ctx, "edit.clear", json!({}));
|
||||
continue;
|
||||
}
|
||||
if let Some((_, _, id, params)) = binds.iter().find(|(m, k, ..)| *k == key && mods_match(*m, mods)) {
|
||||
|
||||
@@ -329,6 +329,7 @@ pub fn viewer_hook(
|
||||
}
|
||||
});
|
||||
if resp.hovered()
|
||||
&& app.dialog.is_none()
|
||||
&& !selected.is_empty()
|
||||
&& ui.input(|i| i.key_pressed(egui::Key::Delete) || i.key_pressed(egui::Key::Backspace))
|
||||
&& !ctx.egui_wants_keyboard_input()
|
||||
|
||||
@@ -147,18 +147,18 @@ pub fn route_layer_settings(app: &mut EffectcraftApp, id: &str, params: &Value)
|
||||
}
|
||||
|
||||
pub(crate) fn modal(ctx: &egui::Context, title: &str, size: egui::Vec2, t: &Tokens, body: impl FnOnce(&mut egui::Ui)) {
|
||||
// Dim the app.
|
||||
let screen = ctx.content_rect();
|
||||
ctx.layer_painter(egui::LayerId::new(egui::Order::Middle, egui::Id::new("modal-dim"))).rect_filled(screen, 0.0, Color32::from_black_alpha(120));
|
||||
egui::Area::new(egui::Id::new(("modal", title))).order(egui::Order::Foreground).fixed_pos(screen.center() - size / 2.0).show(ctx, |ui| {
|
||||
egui::Frame::window(ui.style()).fill(t.panel_bg).inner_margin(egui::Margin::same(18)).show(ui, |ui| {
|
||||
let available = (ctx.content_rect().size() - vec2(48.0, 48.0)).max(vec2(120.0, 80.0));
|
||||
let size = size.min(available);
|
||||
egui::Modal::new(egui::Id::new(("modal", title)))
|
||||
.backdrop_color(Color32::from_black_alpha(120))
|
||||
.frame(egui::Frame::window(&ctx.style_of(ctx.theme())).fill(t.panel_bg).inner_margin(egui::Margin::same(18)))
|
||||
.show(ctx, |ui| {
|
||||
ui.set_width(size.x - 36.0);
|
||||
ui.set_min_height(size.y - 36.0);
|
||||
ui.label(egui::RichText::new(title).font(Tokens::semibold(15.0)).color(t.tab_text_active));
|
||||
ui.add_space(10.0);
|
||||
body(ui);
|
||||
egui::ScrollArea::both().max_height((available.y - 84.0).max(40.0)).auto_shrink([false, true]).show(ui, body);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
@@ -228,11 +228,12 @@ fn about(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
} else if resp.hovered() {
|
||||
t.hover
|
||||
} else {
|
||||
Color32::from_rgb(0x2b, 0x2b, 0x2b)
|
||||
t.field_bg
|
||||
},
|
||||
);
|
||||
icons::paint(p, Rect::from_center_size(pos2(r.min.x + 18.0, r.center().y), vec2(15.0, 15.0)), icon, Color32::WHITE);
|
||||
p.text(pos2(r.min.x + 36.0, r.center().y), Align2::LEFT_CENTER, label, Tokens::medium(12.5), Color32::WHITE);
|
||||
let foreground = if discord { Color32::WHITE } else { t.text };
|
||||
icons::paint(p, Rect::from_center_size(pos2(r.min.x + 18.0, r.center().y), vec2(15.0, 15.0)), icon, foreground);
|
||||
p.text(pos2(r.min.x + 36.0, r.center().y), Align2::LEFT_CENTER, label, Tokens::medium(12.5), foreground);
|
||||
p.text(
|
||||
pos2(r.max.x - 12.0, r.center().y),
|
||||
Align2::RIGHT_CENTER,
|
||||
|
||||
@@ -1064,6 +1064,10 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
egui::DragAndDrop::clear_payload(&ctx);
|
||||
}
|
||||
}
|
||||
if ui.input(|i| i.pointer.primary_down()) && actions.iter().any(|(id, _)| id == "prop.set") {
|
||||
app.ui.viewer.property_interacting = true;
|
||||
ctx.request_repaint();
|
||||
}
|
||||
for (id, params) in actions {
|
||||
if let Err(e) = crate::menus::invoke(app, &ctx, &id, params) {
|
||||
app.ui.status = e;
|
||||
|
||||
@@ -320,8 +320,8 @@ fn name_label(app: &mut EffectcraftApp, ui: &mut egui::Ui, cid: ItemId, c: &EgCo
|
||||
fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Option<ControlType>, p: &Property, v: &KV) -> Option<Value> {
|
||||
let ty = ty?;
|
||||
let mut out = None;
|
||||
let rect;
|
||||
match ty {
|
||||
|
||||
let rect = match ty {
|
||||
ControlType::Text => {
|
||||
let cur = match v {
|
||||
KV::Text(d) => d.text.clone(),
|
||||
@@ -339,7 +339,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
}
|
||||
ui.ctx().data_mut(|d| d.remove::<String>(id));
|
||||
}
|
||||
rect = r.rect;
|
||||
r.rect
|
||||
}
|
||||
ControlType::Color => {
|
||||
let c = v.as_color();
|
||||
@@ -349,7 +349,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
let u = rgba.to_rgba_unmultiplied();
|
||||
out = Some(json!([u[0], u[1], u[2], u[3]]));
|
||||
}
|
||||
rect = r.rect;
|
||||
r.rect
|
||||
}
|
||||
ControlType::Checkbox => {
|
||||
let mut on = v.as_bool();
|
||||
@@ -357,7 +357,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
if r.changed() {
|
||||
out = Some(json!(on));
|
||||
}
|
||||
rect = r.rect;
|
||||
r.rect
|
||||
}
|
||||
ControlType::Dropdown => {
|
||||
let opts = match &p.ui {
|
||||
@@ -372,7 +372,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
}
|
||||
}
|
||||
});
|
||||
rect = r.response.rect;
|
||||
r.response.rect
|
||||
}
|
||||
ControlType::Point => {
|
||||
let mut a = v.as_vec2();
|
||||
@@ -381,7 +381,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
if r1.changed() || r2.changed() {
|
||||
out = Some(json!(a));
|
||||
}
|
||||
rect = r1.rect.union(r2.rect);
|
||||
r1.rect.union(r2.rect)
|
||||
}
|
||||
ControlType::Angle => {
|
||||
let mut a = v.as_f64();
|
||||
@@ -389,7 +389,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
if r.changed() {
|
||||
out = Some(json!(a));
|
||||
}
|
||||
rect = r.rect;
|
||||
r.rect
|
||||
}
|
||||
ControlType::Font => {
|
||||
// Family (from the installed fonts), style and size; the text stays as it is.
|
||||
@@ -421,7 +421,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
if changed || r3.changed() {
|
||||
out = serde_json::to_value(&d).ok();
|
||||
}
|
||||
rect = r1.response.rect.union(r3.rect);
|
||||
r1.response.rect.union(r3.rect)
|
||||
}
|
||||
ControlType::Scale => {
|
||||
// One percentage for every axis.
|
||||
@@ -431,7 +431,7 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
if r.changed() {
|
||||
out = Some(json!(vec![x; comps.len().max(1)]));
|
||||
}
|
||||
rect = r.rect;
|
||||
r.rect
|
||||
}
|
||||
ControlType::Slider | ControlType::Media => {
|
||||
let mut x = v.as_f64();
|
||||
@@ -442,9 +442,9 @@ fn value_widget(app: &mut EffectcraftApp, ui: &mut egui::Ui, auto: &str, ty: Opt
|
||||
if r.changed() {
|
||||
out = Some(json!(x));
|
||||
}
|
||||
rect = r.rect;
|
||||
r.rect
|
||||
}
|
||||
}
|
||||
};
|
||||
app.auto.add(auto, rect, &p.name);
|
||||
out
|
||||
}
|
||||
|
||||
@@ -159,7 +159,7 @@ pub fn decode_thumb(text: &str) -> Option<egui::ColorImage> {
|
||||
return None;
|
||||
}
|
||||
let b: Vec<u8> = (0..t.len()).step_by(2).map(|i| u8::from_str_radix(&t[i..i + 2], 16)).collect::<Result<_, _>>().ok()?;
|
||||
let px = b.chunks_exact(3).map(|c| Color32::from_rgb(c[0], c[1], c[2])).collect();
|
||||
let px = b.as_chunks::<3>().0.iter().map(|c| Color32::from_rgb(c[0], c[1], c[2])).collect();
|
||||
Some(egui::ColorImage::new([THUMB_W, THUMB_H], px))
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,24 @@ pub struct LayerStyleState {
|
||||
pub layer: u64,
|
||||
pub selected: String,
|
||||
pub undo_mark: usize,
|
||||
checkpoint: Option<Checkpoint>,
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
struct Checkpoint {
|
||||
project: std::sync::Arc<effectcraft_engine::project::Project>,
|
||||
history: effectcraft_engine::history::History,
|
||||
}
|
||||
|
||||
impl std::fmt::Debug for Checkpoint {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
f.debug_struct("Checkpoint").field("undo_steps", &self.history.undo.len()).finish_non_exhaustive()
|
||||
}
|
||||
}
|
||||
|
||||
fn checkpoint(app: &mut EffectcraftApp) -> Checkpoint {
|
||||
app.session.history.merge_key = None;
|
||||
Checkpoint { project: app.session.project.clone(), history: app.session.history.clone() }
|
||||
}
|
||||
|
||||
/// Open the dialog on the first selected (or given) layer, showing `style` (a style id;
|
||||
@@ -35,7 +53,8 @@ pub fn open(app: &mut EffectcraftApp, params: &Value) -> Result<(), String> {
|
||||
if style != BLENDING && !STYLES.iter().any(|s| s.0 == style) {
|
||||
return Err(format!("unknown layer style `{style}`"));
|
||||
}
|
||||
app.dialog_state.layer_style = LayerStyleState { layer, selected: style, undo_mark: app.session.history.undo.len() };
|
||||
let checkpoint = checkpoint(app);
|
||||
app.dialog_state.layer_style = LayerStyleState { layer, selected: style, undo_mark: app.session.history.undo.len(), checkpoint: Some(checkpoint) };
|
||||
app.dialog = Some(Dialog::LayerStyles);
|
||||
Ok(())
|
||||
}
|
||||
@@ -48,10 +67,12 @@ pub fn route(app: &mut EffectcraftApp, id: &str, params: &Value) -> Result<bool,
|
||||
return Ok(false);
|
||||
}
|
||||
let mark = app.session.history.undo.len();
|
||||
let checkpoint = checkpoint(app);
|
||||
app.session.execute(id, json!({})).map_err(|e| e.to_string())?;
|
||||
open(app, &json!({"style": style}))?;
|
||||
// Cancel also removes the style just added.
|
||||
app.dialog_state.layer_style.undo_mark = mark;
|
||||
app.dialog_state.layer_style.checkpoint = Some(checkpoint);
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
@@ -214,13 +235,17 @@ pub fn select(app: &mut EffectcraftApp, style: &str) {
|
||||
|
||||
/// Close the dialog: OK keeps the edits, Cancel undoes everything done since it opened.
|
||||
pub fn finish(app: &mut EffectcraftApp, ok: bool) {
|
||||
if !ok {
|
||||
let mark = app.dialog_state.layer_style.undo_mark;
|
||||
while app.session.history.undo.len() > mark {
|
||||
if !app.session.undo() {
|
||||
break;
|
||||
}
|
||||
if let Some(checkpoint) = app.dialog_state.layer_style.checkpoint.take()
|
||||
&& !ok
|
||||
{
|
||||
let changed = !std::sync::Arc::ptr_eq(&app.session.project, &checkpoint.project);
|
||||
app.session.project = checkpoint.project;
|
||||
app.session.history = checkpoint.history;
|
||||
app.session.sanitize_state();
|
||||
if changed {
|
||||
app.session.bump();
|
||||
}
|
||||
}
|
||||
app.session.history.merge_key = None;
|
||||
app.dialog = None;
|
||||
}
|
||||
|
||||
@@ -189,6 +189,25 @@ pub fn begin_rename(app: &EffectcraftApp, ctx: &egui::Context) {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn visible_rows(app: &EffectcraftApp) -> Vec<(ItemId, usize)> {
|
||||
fn walk(app: &EffectcraftApp, folder: Option<ItemId>, depth: usize, q: &str, out: &mut Vec<(ItemId, usize)>) {
|
||||
let mut kids = app.session.project.children(folder);
|
||||
sort_items(&mut kids, &app.ui.project_sort, app.ui.project_sort_desc);
|
||||
for it in kids {
|
||||
if !q.is_empty() && !it.is_folder() && !it.name.to_lowercase().contains(q) {
|
||||
continue;
|
||||
}
|
||||
out.push((it.id, depth));
|
||||
if it.is_folder() && (app.ui.project_open_folders.contains(&it.id.0) || !q.is_empty()) {
|
||||
walk(app, Some(it.id), depth + 1, q, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut rows = vec![];
|
||||
walk(app, None, 0, &app.ui.project_search.to_lowercase(), &mut rows);
|
||||
rows
|
||||
}
|
||||
|
||||
pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let t = app.tokens;
|
||||
let p = ui.painter().clone();
|
||||
@@ -330,22 +349,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
app.ui.project_hscroll = (hscroll + sresp.drag_delta().x * overflow / (track.width() - tw).max(1.0)).clamp(0.0, overflow);
|
||||
}
|
||||
}
|
||||
let query = app.ui.project_search.to_lowercase();
|
||||
let mut rows: Vec<(ItemId, usize)> = vec![];
|
||||
fn walk(app: &EffectcraftApp, folder: Option<ItemId>, depth: usize, q: &str, out: &mut Vec<(ItemId, usize)>) {
|
||||
let mut kids = app.session.project.children(folder);
|
||||
sort_items(&mut kids, &app.ui.project_sort, app.ui.project_sort_desc);
|
||||
for it in kids {
|
||||
if !q.is_empty() && !it.is_folder() && !it.name.to_lowercase().contains(q) {
|
||||
continue;
|
||||
}
|
||||
out.push((it.id, depth));
|
||||
if it.is_folder() && (app.ui.project_open_folders.contains(&it.id.0) || !q.is_empty()) {
|
||||
walk(app, Some(it.id), depth + 1, q, out);
|
||||
}
|
||||
}
|
||||
}
|
||||
walk(app, None, 0, &query, &mut rows);
|
||||
let rows = visible_rows(app);
|
||||
// Enter renames the selected item (Project panel focused, not typing).
|
||||
if app.ui.focused == crate::dock::PanelKind::Project
|
||||
&& app.dialog.is_none()
|
||||
@@ -547,13 +551,24 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
app.auto.add(&format!("project.item.{}.name", id.0), name_clip, &it.name);
|
||||
let resp = resp.union(nresp);
|
||||
if resp.clicked() {
|
||||
let add = ui.input(|i| i.modifiers.command || i.modifiers.shift);
|
||||
if add {
|
||||
if !app.session.state.project_selection.contains(id) {
|
||||
let m = ui.input(|i| i.modifiers);
|
||||
let anchor_key = egui::Id::new("project-selection-anchor");
|
||||
let anchor = ctx.data(|d| d.get_temp::<ItemId>(anchor_key)).or_else(|| app.session.state.project_selection.first().copied());
|
||||
if m.shift
|
||||
&& let Some(a) = anchor.and_then(|a| rows.iter().position(|(i, _)| *i == a))
|
||||
{
|
||||
let b = rows.iter().position(|(i, _)| i == id).unwrap_or(a);
|
||||
app.session.state.project_selection = rows.get(a.min(b)..=a.max(b)).unwrap_or_default().iter().map(|(i, _)| *i).collect();
|
||||
} else if m.command {
|
||||
if app.session.state.project_selection.contains(id) {
|
||||
app.session.state.project_selection.retain(|i| i != id);
|
||||
} else {
|
||||
app.session.state.project_selection.push(*id);
|
||||
}
|
||||
ctx.data_mut(|d| d.insert_temp(anchor_key, *id));
|
||||
} else {
|
||||
app.session.state.project_selection = vec![*id];
|
||||
ctx.data_mut(|d| d.insert_temp(anchor_key, *id));
|
||||
}
|
||||
}
|
||||
// Double-click opens the item, as in After Effects (a comp gets its own Timeline tab and
|
||||
@@ -576,6 +591,11 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
egui::DragAndDrop::set_payload(&ctx, DragPayload::Item(id.0));
|
||||
}
|
||||
resp.context_menu(|ui| {
|
||||
if ui.button("Delete").clicked() {
|
||||
let items: Vec<u64> = if selected { app.session.state.project_selection.iter().map(|i| i.0).collect() } else { vec![id.0] };
|
||||
actions.push(("project.delete".into(), json!({"items": items})));
|
||||
ui.close();
|
||||
}
|
||||
if matches!(it.kind, ItemKind::Comp(_)) && ui.button("Open Composition").clicked() {
|
||||
actions.push(("comp.open".into(), json!({"comp": id.0})));
|
||||
ui.close();
|
||||
|
||||
@@ -406,6 +406,26 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let rendering = app.session.is_rendering();
|
||||
let available = app.session.exporter.as_ref().map(|e| e.formats()).unwrap_or_default();
|
||||
let mut actions: Vec<(&'static str, Value)> = Vec::new();
|
||||
app.auto.add("renderQueue.drop", rect, "Drop compositions to queue");
|
||||
if !rendering
|
||||
&& let Some(crate::panels::DragPayload::Item(id)) = egui::DragAndDrop::payload::<crate::panels::DragPayload>(ui.ctx()).as_deref()
|
||||
&& app.session.project.comp(effectcraft_engine::project::ItemId(*id)).is_some()
|
||||
&& ui.input(|i| i.pointer.hover_pos()).is_some_and(|pos| rect.contains(pos))
|
||||
{
|
||||
let ids: Vec<u64> = if app.session.state.project_selection.contains(&effectcraft_engine::project::ItemId(*id)) {
|
||||
app.session.state.project_selection.iter().filter(|i| app.session.project.comp(**i).is_some()).map(|i| i.0).collect()
|
||||
} else {
|
||||
vec![*id]
|
||||
};
|
||||
if ui.input(|i| i.pointer.any_released()) {
|
||||
for comp in ids {
|
||||
actions.push(("renderQueue.add", json!({"comp": comp})));
|
||||
}
|
||||
egui::DragAndDrop::clear_payload(ui.ctx());
|
||||
} else {
|
||||
p.rect_stroke(rect.shrink(2.0), 0.0, Stroke::new(2.0, t.accent), StrokeKind::Inside);
|
||||
}
|
||||
}
|
||||
let mut forms: Vec<(RenderQueueItem, String)> = Vec::new();
|
||||
let state_id = egui::Id::new("rq-ui");
|
||||
let (mut open, mut selected): (Vec<u64>, Option<u64>) = ui.data(|d| d.get_temp(state_id).unwrap_or_default());
|
||||
@@ -723,6 +743,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
&& editing.is_none()
|
||||
&& !rendering
|
||||
&& let Some(id) = selected
|
||||
&& app.dialog.is_none()
|
||||
&& ui.input(|i| i.key_pressed(egui::Key::Delete) || i.key_pressed(egui::Key::Backspace))
|
||||
&& !ui.ctx().egui_wants_keyboard_input()
|
||||
{
|
||||
|
||||
@@ -428,32 +428,34 @@ pub fn show(app: &mut EffectcraftApp, ctx: &egui::Context, t: &Tokens) {
|
||||
let mut acts: Vec<Act> = vec![];
|
||||
let (mut ok, mut cancel) = (false, false);
|
||||
super::dialogs::modal(ctx, "Settings", vec2(820.0, 600.0), t, |ui| {
|
||||
let body_h = 470.0;
|
||||
let body_h = (ctx.content_rect().height() - 170.0).clamp(120.0, 470.0);
|
||||
ui.allocate_ui_with_layout(vec2(ui.available_width(), body_h), egui::Layout::left_to_right(egui::Align::Min), |ui| {
|
||||
ui.set_height(body_h);
|
||||
// Page list (left, like After Effects).
|
||||
ui.vertical(|ui| {
|
||||
ui.set_width(180.0);
|
||||
for p in &all {
|
||||
let (r, resp) = ui.allocate_exact_size(vec2(176.0, 24.0), egui::Sense::click());
|
||||
let sel = page == p.id;
|
||||
if sel {
|
||||
ui.painter().rect_filled(r, 3.0, t.accent);
|
||||
} else if resp.hovered() {
|
||||
ui.painter().rect_filled(r, 3.0, t.hover);
|
||||
egui::ScrollArea::vertical().id_salt("settings-pages").max_height(body_h).auto_shrink([false, false]).show(ui, |ui| {
|
||||
for p in &all {
|
||||
let (r, resp) = ui.allocate_exact_size(vec2(176.0, 24.0), egui::Sense::click());
|
||||
let sel = page == p.id;
|
||||
if sel {
|
||||
ui.painter().rect_filled(r, 3.0, t.accent);
|
||||
} else if resp.hovered() {
|
||||
ui.painter().rect_filled(r, 3.0, t.hover);
|
||||
}
|
||||
ui.painter().text(
|
||||
r.left_center() + vec2(10.0, 0.0),
|
||||
egui::Align2::LEFT_CENTER,
|
||||
p.title,
|
||||
Tokens::ui(12.5),
|
||||
if sel { Color32::WHITE } else { t.text },
|
||||
);
|
||||
app.auto.add(&format!("settings.page.{}", p.id), r, p.title);
|
||||
if resp.clicked() {
|
||||
page = p.id.to_string();
|
||||
}
|
||||
}
|
||||
ui.painter().text(
|
||||
r.left_center() + vec2(10.0, 0.0),
|
||||
egui::Align2::LEFT_CENTER,
|
||||
p.title,
|
||||
Tokens::ui(12.5),
|
||||
if sel { Color32::WHITE } else { t.text },
|
||||
);
|
||||
app.auto.add(&format!("settings.page.{}", p.id), r, p.title);
|
||||
if resp.clicked() {
|
||||
page = p.id.to_string();
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
ui.separator();
|
||||
ui.vertical(|ui| {
|
||||
|
||||
@@ -37,7 +37,7 @@ fn thumb(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, budget: &mut b
|
||||
}
|
||||
*budget = false;
|
||||
let tex = templates::thumbnail(&app.session, id).ok().and_then(|t| templates::decode_thumb(&t)).map(|rgb| {
|
||||
let px = rgb.chunks_exact(3).map(|c| Color32::from_rgb(c[0], c[1], c[2])).collect();
|
||||
let px = rgb.as_chunks::<3>().0.iter().map(|c| Color32::from_rgb(c[0], c[1], c[2])).collect();
|
||||
ctx.load_texture(format!("template-thumb-{id}"), egui::ColorImage::new([THUMB_W, THUMB_H], px), egui::TextureOptions::LINEAR)
|
||||
});
|
||||
app.template_thumbs.insert(id.to_string(), tex.clone());
|
||||
|
||||
@@ -1205,6 +1205,9 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
// Registered before the rows so keys, bars and editors on top of it get the pointer first.
|
||||
let empty_rect = if graph_on { Rect::NOTHING } else { Rect::from_min_max(pos2(graph_x0, rows_rect.min.y), rows_rect.max) };
|
||||
let empty = ui.interact(empty_rect, egui::Id::new("tl-graph-bg"), Sense::click_and_drag());
|
||||
let outline_rect = Rect::from_min_max(rows_rect.min, pos2(graph_x0 - 1.0, rows_rect.max.y));
|
||||
let outline_empty = ui.interact(outline_rect, egui::Id::new("tl-layer-bg"), Sense::click_and_drag());
|
||||
app.auto.add("timeline.layerMarquee", outline_rect, "Drag empty outline to select layers");
|
||||
let mut hit_rows: Vec<(Rect, Row)> = vec![];
|
||||
for (ri, row) in rows.iter().enumerate() {
|
||||
// Outline widgets never spill into the time graph (narrow timelines).
|
||||
@@ -1336,7 +1339,28 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
app.auto.add(&format!("timeline.layer.{}.row", layer.id.0), left, &layer.name);
|
||||
if row_resp.clicked() && !locked {
|
||||
let m = ui.input(|i| i.modifiers);
|
||||
actions.push(("layer.select".into(), json!({"layers": [layer.id.0], "toggle": m.command, "add": m.shift})));
|
||||
let anchor_key = egui::Id::new(("timeline-selection-anchor", cid.0));
|
||||
let anchor = ctx.data(|d| d.get_temp::<LayerId>(anchor_key)).or_else(|| selected.first().copied());
|
||||
let range = if m.shift {
|
||||
anchor.and_then(|a| comp.layers.iter().position(|l| l.id == a)).map(|a| {
|
||||
let b = comp.layers.iter().position(|l| l.id == layer.id).unwrap_or(a);
|
||||
comp.layers
|
||||
.get(a.min(b)..=a.max(b))
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.filter(|l| !l.switches.locked && rows.iter().any(|r| r.layer == l.id))
|
||||
.map(|l| l.id.0)
|
||||
.collect::<Vec<_>>()
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
if let Some(layers) = range {
|
||||
actions.push(("layer.select".into(), json!({"layers": layers})));
|
||||
} else {
|
||||
actions.push(("layer.select".into(), json!({"layers": [layer.id.0], "toggle": m.command})));
|
||||
ctx.data_mut(|d| d.insert_temp(anchor_key, layer.id));
|
||||
}
|
||||
}
|
||||
if row_resp.double_clicked() {
|
||||
match &layer.source {
|
||||
@@ -2015,6 +2039,29 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
}
|
||||
ui.set_clip_rect(full_clip);
|
||||
if outline_empty.clicked() && !ui.input(|i| i.modifiers.shift || i.modifiers.command) {
|
||||
actions.push(("layer.select".into(), json!({"layers": []})));
|
||||
}
|
||||
if let (Some(start), Some(end)) = (ctx.input(|i| i.pointer.press_origin()), outline_empty.interact_pointer_pos())
|
||||
&& outline_empty.dragged()
|
||||
{
|
||||
let box_rect = Rect::from_two_pos(start, end).intersect(outline_rect);
|
||||
lp.rect_filled(box_rect, 0.0, t.accent.gamma_multiply(0.12));
|
||||
lp.rect_stroke(box_rect, 0.0, Stroke::new(1.0, t.accent), StrokeKind::Inside);
|
||||
ctx.data_mut(|d| d.insert_temp(egui::Id::new("tl-layer-box"), box_rect));
|
||||
}
|
||||
if outline_empty.drag_stopped()
|
||||
&& let Some(box_rect) = ctx.data(|d| d.get_temp::<Rect>(egui::Id::new("tl-layer-box")))
|
||||
{
|
||||
ctx.data_mut(|d| d.remove::<Rect>(egui::Id::new("tl-layer-box")));
|
||||
let layers: Vec<u64> = hit_rows
|
||||
.iter()
|
||||
.filter(|(r, row)| matches!(row.kind, RowKind::Layer) && r.intersects(box_rect))
|
||||
.filter(|(_, row)| comp.layer(row.layer).is_some_and(|l| !l.switches.locked))
|
||||
.map(|(_, row)| row.layer.0)
|
||||
.collect();
|
||||
actions.push(("layer.select".into(), json!({"layers": layers, "add": ui.input(|i| i.modifiers.shift || i.modifiers.command)})));
|
||||
}
|
||||
// Pick whips: a line follows the pointer; releasing over a row links to it.
|
||||
if let Some((kind, src_layer, src_prop, start)) = ctx.data(|d| d.get_temp::<PickWhip>(pick_whip_id())) {
|
||||
let ptr = ctx.input(|i| i.pointer.latest_pos()).unwrap_or(start);
|
||||
@@ -2287,6 +2334,10 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
UiAct::EndMerge => app.session.history.merge_key = None,
|
||||
}
|
||||
}
|
||||
if ui.input(|i| i.pointer.primary_down()) && actions.iter().any(|(id, _)| id == "prop.set") {
|
||||
app.ui.viewer.property_interacting = true;
|
||||
ctx.request_repaint();
|
||||
}
|
||||
for (id, params) in actions {
|
||||
if id == "__endMerge" {
|
||||
app.session.history.merge_key = None;
|
||||
@@ -2540,63 +2591,66 @@ fn zoom_at(app: &mut EffectcraftApp, comp: &Comp, tm: TMap, k: f64, at_x: f32) {
|
||||
}
|
||||
|
||||
fn layer_context_menu(resp: &egui::Response, layer: &Layer, actions: &mut Vec<(String, serde_json::Value)>) {
|
||||
resp.context_menu(|ui| {
|
||||
let id = layer.id.0;
|
||||
let mut item = |ui: &mut egui::Ui, label: &str, cmd: &str, params: serde_json::Value| {
|
||||
if ui.button(label).clicked() {
|
||||
actions.push(("layer.select".into(), json!({"layers": [id]})));
|
||||
actions.push((cmd.into(), params));
|
||||
ui.close();
|
||||
}
|
||||
};
|
||||
ui.menu_button("New", |ui| {
|
||||
item(ui, "Text", "layer.newText", json!({"text": "Text"}));
|
||||
item(ui, "Solid…", "app.solidSettings", json!({}));
|
||||
item(ui, "Light…", "layer.newLight", json!({}));
|
||||
item(ui, "Camera…", "layer.newCamera", json!({}));
|
||||
item(ui, "Null Object", "layer.newNull", json!({}));
|
||||
item(ui, "Shape Layer", "layer.newShape", json!({"kind": "none"}));
|
||||
item(ui, "Adjustment Layer", "layer.newAdjustment", json!({}));
|
||||
});
|
||||
item(ui, "Layer Settings…", "layer.settings", json!({}));
|
||||
ui.separator();
|
||||
ui.menu_button("Masks", |ui| {
|
||||
item(ui, "New Mask", "layer.addMask", json!({"layer": id}));
|
||||
});
|
||||
ui.menu_button("Transform", |ui| {
|
||||
item(ui, "Reset", "layer.transform", json!({"layers": [id], "op": "reset"}));
|
||||
item(ui, "Center In View", "layer.transform", json!({"layers": [id], "op": "center"}));
|
||||
item(ui, "Fit to Comp", "layer.transform", json!({"layers": [id], "op": "fit"}));
|
||||
item(ui, "Flip Horizontal", "layer.transform", json!({"layers": [id], "op": "flipH"}));
|
||||
item(ui, "Flip Vertical", "layer.transform", json!({"layers": [id], "op": "flipV"}));
|
||||
});
|
||||
ui.menu_button("Time", |ui| {
|
||||
item(ui, "Enable Time Remapping", "layer.enableTimeRemap", json!({"layers": [id]}));
|
||||
item(ui, "Time-Reverse Layer", "layer.timeReverse", json!({"layers": [id]}));
|
||||
item(ui, "Time Stretch…", "layer.timeStretch", json!({}));
|
||||
item(ui, "Freeze Frame", "layer.freezeFrame", json!({"layers": [id]}));
|
||||
item(ui, "Freeze on Last Frame", "layer.freezeOnLastFrame", json!({"layers": [id]}));
|
||||
});
|
||||
ui.menu_button("Blending Mode", |ui| {
|
||||
for m in BlendMode::ALL {
|
||||
item(ui, m.label(), "layer.setBlendMode", json!({"layers": [id], "mode": m.label()}));
|
||||
if m.ends_group() {
|
||||
ui.separator();
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.menu_button("Arrange", |ui| {
|
||||
item(ui, "Bring Layer to Front", "layer.arrange", json!({"layers": [id], "to": "front"}));
|
||||
item(ui, "Bring Layer Forward", "layer.arrange", json!({"layers": [id], "to": "forward"}));
|
||||
item(ui, "Send Layer Backward", "layer.arrange", json!({"layers": [id], "to": "backward"}));
|
||||
item(ui, "Send Layer to Back", "layer.arrange", json!({"layers": [id], "to": "back"}));
|
||||
});
|
||||
ui.separator();
|
||||
item(ui, "Pre-compose…", "layer.precompose", json!({"layers": [id]}));
|
||||
item(ui, "Duplicate", "edit.duplicate", json!({"layers": [id]}));
|
||||
item(ui, "Split Layer", "edit.splitLayer", json!({"layers": [id]}));
|
||||
item(ui, "Delete", "edit.clear", json!({"layers": [id]}));
|
||||
resp.context_menu(|ui| layer_menu(ui, &[layer.id.0], actions));
|
||||
}
|
||||
|
||||
/// Shared layer actions for Timeline rows and Composition context menus.
|
||||
pub(crate) fn layer_menu(ui: &mut egui::Ui, layers: &[u64], actions: &mut Vec<(String, serde_json::Value)>) {
|
||||
let Some(&id) = layers.first() else { return };
|
||||
let mut item = |ui: &mut egui::Ui, label: &str, cmd: &str, params: serde_json::Value| {
|
||||
if ui.button(label).clicked() {
|
||||
actions.push(("layer.select".into(), json!({"layers": layers})));
|
||||
actions.push((cmd.into(), params));
|
||||
ui.close();
|
||||
}
|
||||
};
|
||||
ui.menu_button("New", |ui| {
|
||||
item(ui, "Text", "layer.newText", json!({"text": "Text"}));
|
||||
item(ui, "Solid…", "app.solidSettings", json!({}));
|
||||
item(ui, "Light…", "layer.newLight", json!({}));
|
||||
item(ui, "Camera…", "layer.newCamera", json!({}));
|
||||
item(ui, "Null Object", "layer.newNull", json!({}));
|
||||
item(ui, "Shape Layer", "layer.newShape", json!({"kind": "none"}));
|
||||
item(ui, "Adjustment Layer", "layer.newAdjustment", json!({}));
|
||||
});
|
||||
item(ui, "Layer Settings…", "layer.settings", json!({}));
|
||||
ui.separator();
|
||||
ui.menu_button("Masks", |ui| {
|
||||
item(ui, "New Mask", "layer.addMask", json!({"layer": id}));
|
||||
});
|
||||
ui.menu_button("Transform", |ui| {
|
||||
item(ui, "Reset", "layer.transform", json!({"layers": layers, "op": "reset"}));
|
||||
item(ui, "Center In View", "layer.transform", json!({"layers": layers, "op": "center"}));
|
||||
item(ui, "Fit to Comp", "layer.transform", json!({"layers": layers, "op": "fit"}));
|
||||
item(ui, "Flip Horizontal", "layer.transform", json!({"layers": layers, "op": "flipH"}));
|
||||
item(ui, "Flip Vertical", "layer.transform", json!({"layers": layers, "op": "flipV"}));
|
||||
});
|
||||
ui.menu_button("Time", |ui| {
|
||||
item(ui, "Enable Time Remapping", "layer.enableTimeRemap", json!({"layers": layers}));
|
||||
item(ui, "Time-Reverse Layer", "layer.timeReverse", json!({"layers": layers}));
|
||||
item(ui, "Time Stretch…", "layer.timeStretch", json!({}));
|
||||
item(ui, "Freeze Frame", "layer.freezeFrame", json!({"layers": layers}));
|
||||
item(ui, "Freeze on Last Frame", "layer.freezeOnLastFrame", json!({"layers": layers}));
|
||||
});
|
||||
ui.menu_button("Blending Mode", |ui| {
|
||||
for m in BlendMode::ALL {
|
||||
item(ui, m.label(), "layer.setBlendMode", json!({"layers": layers, "mode": m.label()}));
|
||||
if m.ends_group() {
|
||||
ui.separator();
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.menu_button("Arrange", |ui| {
|
||||
item(ui, "Bring Layer to Front", "layer.arrange", json!({"layers": layers, "to": "front"}));
|
||||
item(ui, "Bring Layer Forward", "layer.arrange", json!({"layers": layers, "to": "forward"}));
|
||||
item(ui, "Send Layer Backward", "layer.arrange", json!({"layers": layers, "to": "backward"}));
|
||||
item(ui, "Send Layer to Back", "layer.arrange", json!({"layers": layers, "to": "back"}));
|
||||
});
|
||||
ui.separator();
|
||||
item(ui, "Pre-compose…", "layer.precompose", json!({"layers": layers}));
|
||||
item(ui, "Duplicate", "edit.duplicate", json!({"layers": layers}));
|
||||
item(ui, "Split Layer", "edit.splitLayer", json!({"layers": layers}));
|
||||
item(ui, "Delete", "edit.clear", json!({"layers": layers}));
|
||||
}
|
||||
|
||||
fn fmt_num(v: f64, d: usize) -> String {
|
||||
|
||||
@@ -292,6 +292,29 @@ fn point_in_quad(p: [f64; 2], q: &[[f64; 2]; 4]) -> bool {
|
||||
true
|
||||
}
|
||||
|
||||
/// Separating-axis test: a marquee may cross a layer without containing any corner.
|
||||
fn quad_intersects_box(q: &[[f64; 2]; 4], a: [f64; 2], b: [f64; 2]) -> bool {
|
||||
if q.iter().flatten().chain(a.iter()).chain(b.iter()).any(|v| !v.is_finite()) {
|
||||
return false;
|
||||
}
|
||||
let lo = [a[0].min(b[0]), a[1].min(b[1])];
|
||||
let hi = [a[0].max(b[0]), a[1].max(b[1])];
|
||||
let rect = [lo, [hi[0], lo[1]], hi, [lo[0], hi[1]]];
|
||||
let axes = [[1.0, 0.0], [0.0, 1.0]].into_iter().chain((0..4).map(|i| {
|
||||
let j = (i + 1) % 4;
|
||||
[q[j][1] - q[i][1], q[i][0] - q[j][0]]
|
||||
}));
|
||||
for axis in axes {
|
||||
let project = |p: &[f64; 2]| p[0] * axis[0] + p[1] * axis[1];
|
||||
let (qmin, qmax) = q.iter().map(project).fold((f64::INFINITY, f64::NEG_INFINITY), |(lo, hi), v| (lo.min(v), hi.max(v)));
|
||||
let (rmin, rmax) = rect.iter().map(project).fold((f64::INFINITY, f64::NEG_INFINITY), |(lo, hi), v| (lo.min(v), hi.max(v)));
|
||||
if qmax < rmin || rmax < qmin {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
/// Parent-space linear inverse (to convert a comp-space drag delta into a position delta).
|
||||
fn parent_inverse(ctx: &EvalCtx, layer: &Layer) -> Mat3 {
|
||||
match layer.parent.and_then(|p| ctx.comp.layer(p)) {
|
||||
@@ -860,6 +883,47 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
|
||||
// Interaction.
|
||||
let resp = ui.interact(area, egui::Id::new("viewer-interact"), Sense::click_and_drag());
|
||||
let menu_hits_id = egui::Id::new(("viewer-menu-hits", cid.0));
|
||||
if resp.secondary_clicked()
|
||||
&& let Some(pos) = resp.interact_pointer_pos()
|
||||
{
|
||||
// Picking an already selected layer preserves the group; an unselected hit
|
||||
// becomes the target, using the same visible/unlocked hit test as left-click.
|
||||
pick(app, &ectx, map.to_comp(pos), false);
|
||||
let point = map.to_comp(pos);
|
||||
let hits: Vec<(u64, String)> = selectable_layers(&comp, time)
|
||||
.filter(|l| layer_quad(&ectx, l).is_some_and(|(_, q, _)| point_in_quad(point, &q)))
|
||||
.map(|l| (l.id.0, l.name.clone()))
|
||||
.collect();
|
||||
ui.data_mut(|d| d.insert_temp(menu_hits_id, hits));
|
||||
}
|
||||
let context_layers: Vec<u64> =
|
||||
app.session.state.selected_layers.iter().filter(|id| comp.layer(**id).is_some_and(|l| !l.switches.locked)).map(|id| id.0).collect();
|
||||
let mut context_actions = Vec::new();
|
||||
resp.context_menu(|ui| {
|
||||
let hits = ui.data(|d| d.get_temp::<Vec<(u64, String)>>(menu_hits_id)).unwrap_or_default();
|
||||
if !hits.is_empty() {
|
||||
ui.menu_button("Select", |ui| {
|
||||
for (id, name) in &hits {
|
||||
if ui.button(name).clicked() {
|
||||
context_actions.push(("layer.select".to_owned(), serde_json::json!({"layers":[id]})));
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
});
|
||||
ui.separator();
|
||||
}
|
||||
if context_layers.is_empty() {
|
||||
ui.label("No unlocked layer selected");
|
||||
} else {
|
||||
super::timeline::layer_menu(ui, &context_layers, &mut context_actions);
|
||||
}
|
||||
});
|
||||
for (id, params) in context_actions {
|
||||
if let Err(e) = crate::menus::invoke(app, &ctx, &id, params) {
|
||||
app.ui.status = e;
|
||||
}
|
||||
}
|
||||
let gid = egui::Id::new("viewer-gesture");
|
||||
if let Some(hp) = resp.hover_pos() {
|
||||
app.pointer_comp = Some({
|
||||
@@ -1106,7 +1170,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
} else {
|
||||
// With path vertices on screen the marquee selects vertices (layers stay
|
||||
// selected); otherwise it starts from a clean selection.
|
||||
if !vertex_hits.iter().any(|h| h.tangent.is_none()) {
|
||||
if !mods.shift && !vertex_hits.iter().any(|h| h.tangent.is_none()) {
|
||||
let _ = app.session.execute("edit.deselectAll", json!({}));
|
||||
}
|
||||
Some(Gesture::Marquee { start: press })
|
||||
@@ -1353,13 +1417,11 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
Gesture::Marquee { start } => {
|
||||
let a = map.to_comp(start);
|
||||
let b = map.to_comp(pos);
|
||||
let (x0, x1) = (a[0].min(b[0]), a[0].max(b[0]));
|
||||
let (y0, y1) = (a[1].min(b[1]), a[1].max(b[1]));
|
||||
let hits: Vec<u64> = selectable_layers(&comp, time)
|
||||
.filter(|l| layer_quad(&ectx, l).is_some_and(|(_, q, _)| q.iter().any(|p| p[0] >= x0 && p[0] <= x1 && p[1] >= y0 && p[1] <= y1)))
|
||||
.filter(|l| layer_quad(&ectx, l).is_some_and(|(_, q, _)| quad_intersects_box(&q, a, b)))
|
||||
.map(|l| l.id.0)
|
||||
.collect();
|
||||
let _ = app.session.execute("layer.select", json!({"layers": hits}));
|
||||
let _ = app.session.execute("layer.select", json!({"layers": hits, "toggle": mods.shift}));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
|
||||
@@ -320,7 +320,7 @@ pub fn hook(
|
||||
}
|
||||
|
||||
// ---- keyboard
|
||||
if app.session.state.text_edit.is_some() {
|
||||
if app.session.state.text_edit.is_some() && app.dialog.is_none() && ui.is_enabled() {
|
||||
ui.memory_mut(|m| {
|
||||
m.set_focus_lock_filter(focus_id(), egui::EventFilter { tab: true, horizontal_arrows: true, vertical_arrows: true, escape: true });
|
||||
});
|
||||
|
||||
@@ -711,7 +711,9 @@ pub(crate) fn bottom_bar(app: &mut EffectcraftApp, ui: &mut egui::Ui, bar: Rect,
|
||||
app.auto.add("viewer.timecode", tr, "Current time");
|
||||
// Right: render time.
|
||||
let ms = app.frames.last_ms.lock().map(|v| *v).unwrap_or(0.0);
|
||||
p.text(pos2(bar.max.x - 10.0, cy), Align2::RIGHT_CENTER, format!("{ms:.0} ms"), Tokens::ui(11.0), t.text_faint);
|
||||
if tr.max.x + 50.0 < bar.max.x {
|
||||
p.text(pos2(bar.max.x - 10.0, cy), Align2::RIGHT_CENTER, format!("{ms:.0} ms"), Tokens::ui(11.0), t.text_faint);
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -303,6 +303,8 @@ pub struct ViewerState {
|
||||
/// The pointer is dragging in the viewer this frame (Adaptive Resolution).
|
||||
#[serde(skip)]
|
||||
pub interacting: bool,
|
||||
#[serde(skip)]
|
||||
pub property_interacting: bool,
|
||||
/// Extended Viewer: the comp-space region the viewer renders this frame (comp frame plus
|
||||
/// the visible pasteboard), set while a 3D view shows past the frame.
|
||||
#[serde(skip)]
|
||||
@@ -334,6 +336,7 @@ impl Default for ViewerState {
|
||||
ruler_origin: [0.0, 0.0],
|
||||
roi_draw: false,
|
||||
interacting: false,
|
||||
property_interacting: false,
|
||||
extended: None,
|
||||
pasteboard: None,
|
||||
custom_pasteboard: [0x80, 0x80, 0x80],
|
||||
|
||||
@@ -114,7 +114,7 @@ impl Tokens {
|
||||
accent_hover: Color32::from_rgb(0x4a, 0xa0, 0xf5),
|
||||
text: Color32::from_rgb(0xc8, 0xc8, 0xc8),
|
||||
text_dim: Color32::from_rgb(0x9a, 0x9a, 0x9a),
|
||||
text_faint: Color32::from_rgb(0x66, 0x66, 0x66),
|
||||
text_faint: Color32::from_rgb(0x8c, 0x8c, 0x8c),
|
||||
icon: Color32::from_rgb(0xb4, 0xb4, 0xb4),
|
||||
icon_active: Color32::from_rgb(0xf0, 0xf0, 0xf0),
|
||||
hover: Color32::from_rgb(0x30, 0x30, 0x30),
|
||||
@@ -170,7 +170,9 @@ impl Tokens {
|
||||
tab_text_active: Color32::from_rgb(0x14, 0x14, 0x14),
|
||||
text: Color32::from_rgb(0x22, 0x22, 0x22),
|
||||
text_dim: Color32::from_rgb(0x5a, 0x5a, 0x5a),
|
||||
text_faint: Color32::from_rgb(0x8c, 0x8c, 0x8c),
|
||||
text_faint: Color32::from_rgb(0x68, 0x68, 0x68),
|
||||
hot_text: Color32::from_rgb(0x00, 0x5a, 0x9c),
|
||||
timecode: Color32::from_rgb(0x00, 0x5a, 0x9c),
|
||||
icon: Color32::from_rgb(0x3c, 0x3c, 0x3c),
|
||||
icon_active: Color32::from_rgb(0x10, 0x10, 0x10),
|
||||
hover: Color32::from_rgb(0xd0, 0xd0, 0xd0),
|
||||
@@ -307,11 +309,11 @@ pub fn apply_visuals(ctx: &egui::Context, t: &Tokens) {
|
||||
v.widgets.noninteractive.bg_stroke = Stroke::new(1.0, t.separator);
|
||||
v.widgets.noninteractive.fg_stroke = Stroke::new(1.0, t.text);
|
||||
v.widgets.inactive.bg_fill = t.field_bg;
|
||||
v.widgets.inactive.weak_bg_fill = Color32::from_rgb(0x2e, 0x2e, 0x2e);
|
||||
v.widgets.inactive.weak_bg_fill = t.field_bg;
|
||||
v.widgets.inactive.bg_stroke = Stroke::new(1.0, t.field_border);
|
||||
v.widgets.inactive.fg_stroke = Stroke::new(1.0, t.text);
|
||||
v.widgets.hovered.bg_fill = t.hover;
|
||||
v.widgets.hovered.weak_bg_fill = Color32::from_rgb(0x3a, 0x3a, 0x3a);
|
||||
v.widgets.hovered.weak_bg_fill = t.hover;
|
||||
v.widgets.hovered.bg_stroke = Stroke::new(1.0, t.field_border);
|
||||
v.widgets.hovered.fg_stroke = Stroke::new(1.0, t.tab_text_active);
|
||||
v.widgets.active.bg_fill = t.pressed;
|
||||
|
||||
@@ -209,7 +209,7 @@ pub fn text_button(ui: &mut Ui, rect: Rect, text: &str, primary: bool, t: &Token
|
||||
} else if resp.hovered() {
|
||||
t.pressed
|
||||
} else {
|
||||
Color32::from_rgb(0x33, 0x33, 0x33)
|
||||
t.hover
|
||||
};
|
||||
ui.painter().rect_filled(rect, rect.height() / 2.0, bg);
|
||||
ui.painter().text(rect.center(), Align2::CENTER_CENTER, text, Tokens::medium(12.0), if primary { Color32::WHITE } else { t.text });
|
||||
|
||||
Reference in New Issue
Block a user