Skip to content

EffectCraft: An open-source motion graphics and compositing tool written by scratch in pure Rust

Merge main into fix/712-eyedroppers-everywhere

Claudeeee8fa786c20
diff --cc crates/ui-egui/src/app/frame.rs
index 000000000,d41e0a9d0..f519bcdde
mode 000000,100644..100644
--- a/crates/ui-egui/src/app/frame.rs
+++ b/crates/ui-egui/src/app/frame.rs
@@@ -1,0 -1,553 +1,556 @@@
+ use super::clipboard::copy_image;
+ use super::window::fit_window;
+ use super::*;
+
+ impl EffectcraftApp {
+ /// Completed, non-discarded UI passes since launch.
+ pub fn ui_passes(&self) -> u64 {
+ self.ui_pass_seq
+ }
+
+ // ---------------------------------------------------------------- control channel
+
+ pub(crate) fn raise_for_control(&mut self, ctx: &egui::Context) {
+ ctx.request_repaint();
+ }
+
+ /// Handle the control channel for this tick: drain queued requests plus previously deferred ones, run each
+ /// through `control::handle`, answer `Done` immediately, retry `Retry` until its three-second deadline, hold
+ /// input/job/screenshot replies until their event happens and finish job waiters. Retry timeouts and refused
+ /// screenshots are answered as `{"ok": false, "error": ...}`; the receiver is kept for the next tick.
+ fn drain_control(&mut self, ctx: &egui::Context, now: f64) {
+ let Some(rx) = self.control_rx.take() else { return };
+ let mut reqs: Vec<(ControlRequest, f64)> = std::mem::take(&mut self.deferred);
+ while let Ok(req) = rx.try_recv() {
+ reqs.push((req, now + 3.0));
+ }
+ for (req, deadline) in reqs {
+ let reply = req.reply.clone();
+ match control::handle(self, ctx, &req, now) {
+ control::Outcome::Done(v) => {
+ let _ = reply.send(v);
+ }
+ control::Outcome::Retry(msg) => {
+ if now < deadline {
+ self.deferred.push((req, deadline));
+ ctx.request_repaint();
+ } else {
+ let _ = reply.send(json!({"ok": false, "error": msg}));
+ }
+ }
+ control::Outcome::AfterInput => {
+ self.input_waiters.push(reply);
+ // The reply waits for a real UI pass: a hidden window must run one.
+ self.want_paint = true;
+ }
+ control::Outcome::AwaitJobs(w) => {
+ self.job_waiters.push((w, reply));
+ ctx.request_repaint();
+ }
+ control::Outcome::Screenshot { path, target } => {
+ // A covered or minimized window presents no frames (macOS skips its redraws), so
+ // a screenshot would never arrive and nothing would tick its timeout. The
+ // hidden-window capture path (a pending screenshot forces a pass in 0.37) needs
+ // a native platform run before this gate is removed; the web build never paints
+ // a hidden tab.
+ if ctx.input(|i| i.viewport().occluded == Some(true) || i.viewport().minimized == Some(true)) {
+ let _ = reply.send(json!({"ok": false, "error": "window is covered or minimized: call ui.focus first (render.frame renders comp pixels without the window)"}));
+ continue;
+ }
+ self.admit_screenshot(ctx, path, target, reply);
+ }
+ }
+ }
+ self.control_rx = Some(rx);
+ self.finish_job_waiters(ctx);
+ }
+
+ /// Reply to the control requests whose offloaded jobs ended.
+ fn finish_job_waiters(&mut self, ctx: &egui::Context) {
+ if self.job_waiters.is_empty() {
+ return;
+ }
+ self.session.poll_render();
+ self.session.poll_offload();
+ let waiters = std::mem::take(&mut self.job_waiters);
+ for (w, reply) in waiters {
+ if w.pending(self) {
+ self.job_waiters.push((w, reply));
+ } else {
+ let v = w.finish(self);
+ let _ = reply.send(v);
+ }
+ }
+ if !self.job_waiters.is_empty() {
+ ctx.request_repaint_after(std::time::Duration::from_millis(50));
+ }
+ }
+
+ // ---------------------------------------------------------------- frame
+
+ /// Apply the engine events drained this tick: open a comp, show a toast, open a URL, run a frontend command,
+ /// purge frame caches or copy an image; command and clipboard failures go to `app.ui.status`.
+ pub(super) fn handle_events(&mut self, ctx: &egui::Context) {
+ for ev in self.session.drain_events() {
+ match ev {
+ effectcraft_engine::Event::OpenComp(c) => {
+ panels::viewers::on_open_comp(self, c);
+ self.ui.timeline.pps = None;
+ }
+ effectcraft_engine::Event::Toast { message, .. } => self.toast = Some((message, self.now)),
+ effectcraft_engine::Event::OpenUrl(url) => ctx.open_url(egui::OpenUrl::new_tab(url)),
+ // Frames are keyed by content: an edit keeps those of comps it doesn't touch.
+ effectcraft_engine::Event::ProjectChanged { .. } => {}
+ effectcraft_engine::Event::Frontend { command, params } => {
+ if let Err(e) = crate::menus::frontend(self, ctx, &command, params) {
+ self.ui.status = e;
+ }
+ }
+ effectcraft_engine::Event::PurgeCaches => self.frames.clear(),
+ effectcraft_engine::Event::CopyImage { width, height, rgba } => {
+ if let Err(e) = copy_image(ctx, width, height, &rgba) {
+ self.ui.status = e;
+ }
+ }
+ }
+ }
+ }
+
+ /// The app's only non-paint entry: one tick of background work.
+ ///
+ /// This runs for every eframe logic callback, including the logic-only ticks of a hidden
+ /// window (which never reach [`Self::draw`]). It must therefore do no input handling, no
+ /// layout and no presentation: engine/job queues, autosave, playback, audio, the control
+ /// channel, screenshots and the close guard. Everything here is idempotent for a pass that
+ /// `Context::request_discard` replays.
+ pub fn tick(&mut self, ctx: &egui::Context, frame: &eframe::Frame) {
+ self.now = self.clock.now();
+ // The compositor exists before the first paint and while hidden (device-loss handling
+ // must run there too).
+ self.init_gpu(frame);
+ self.apply_gpu_failure(ctx);
+ if self.gpu_failure_applied == Some(true) {
+ self.close_after_device_loss(ctx);
+ return;
+ }
+ // Focus comes from the fresh viewport copy; a full pass's `InputState::focused` is only a
+ // fallback (a logic-only tick leaves it at the previous pass's value).
+ let focused = ctx.input(|i| i.viewport().focused.or(Some(i.focused)));
+ self.focused = focused.unwrap_or(self.focused);
+ // The interface language's fallback fonts are installed in `draw` (fonts need a pass), but
+ // commands handled here use the right catalog already.
+ let language = crate::i18n::language(self);
+ crate::i18n::set_current(language);
+ if self.styled_language != language {
+ self.want_paint = true;
+ }
+ // Frames and worker completions wake the app even while it is hidden.
+ self.frames.set_context(ctx);
+ updates_ui::tick(self, ctx);
+ if self.session.render_job.is_some() {
+ self.session.poll_render();
+ ctx.request_repaint_after(std::time::Duration::from_millis(100));
+ }
+ if self.session.track_job.is_some() {
+ self.session.poll_track();
+ ctx.request_repaint_after(std::time::Duration::from_millis(50));
+ }
+ if self.session.mask_job.is_some() {
+ self.session.poll_mask_track();
+ ctx.request_repaint_after(std::time::Duration::from_millis(50));
+ }
+ // Background tasks (Content-Aware Fill, Scene Edit Detection, imports).
+ if !self.session.tasks.is_empty() {
+ self.session.poll_jobs();
+ ctx.request_repaint_after(std::time::Duration::from_millis(100));
+ }
+ // Analyses running in a worker (the web app).
+ if !self.session.offloaded.is_empty() {
+ self.session.poll_offload();
+ ctx.request_repaint_after(std::time::Duration::from_millis(100));
+ }
+ // Warp Stabilizer: finish analyses and start queued (re-)analyses in the background.
+ if self.session.warp_job.is_some() || !self.session.warp_pending.is_empty() {
+ self.session.poll_warp(true);
+ self.session.poll_roto(true);
+ ctx.request_repaint_after(std::time::Duration::from_millis(100));
+ }
+ // Roto Brush propagation and Object Matte tracking / Freeze: finish jobs (a Freeze writes
+ // its mattes) and start queued ones in the background.
+ if self.session.roto_job.is_some() || !self.session.roto_pending.is_empty() {
+ self.session.poll_roto(true);
+ ctx.request_repaint_after(std::time::Duration::from_millis(100));
+ }
+ // 3D Camera Tracker: likewise (tracking, then solving).
+ if self.session.camera_job.is_some() || !self.session.camera_pending.is_empty() {
+ self.session.poll_camera(true);
+ ctx.request_repaint_after(std::time::Duration::from_millis(100));
+ }
+ self.run_script_tasks(ctx);
+ self.run_dialog_answers();
+ self.handle_events(ctx);
+ if let Some(rx) = self.command_inbox.take() {
+ while let Ok(id) = rx.try_recv() {
+ if let Err(e) = menus::invoke(self, ctx, &id, json!({})) {
+ self.ui.status = e;
+ }
+ }
+ self.command_inbox = Some(rx);
+ }
+ // A close request (the window's button, Quit, `app.quit`) must be answered while hidden.
+ // An answered file dialog can change the project, so the answers above run first. The host
+ // calls `panels::unsaved::quit_on_close` last in its `logic`.
+ panels::unsaved::on_close_requested(self, ctx);
+ let title = panels::unsaved::window_title(self);
+ if title != self.window_title {
+ ctx.send_viewport_cmd(egui::ViewportCommand::Title(title.clone()));
+ self.window_title = title;
+ }
+ self.tick_autosave(ctx);
+ self.tick_workspace_autosave(ctx);
+ let now = self.now;
+ prefs_live::tick(self, ctx, now);
+ // Playback advances without a paint (its frames and the audio clock are background work).
+ // Idle prefetch keeps its old condition: it only runs once a viewer has drawn.
+ if (self.playback.playing || self.last_viewer_scale.is_some())
+ && let Some(cid) = self.session.active_comp_id()
+ {
+ let (scale, active) = (self.last_viewer_scale.unwrap_or(1.0), self.input_active);
+ self.advance_playback(ctx, scale, now, active, cid);
+ }
+ self.drain_control(ctx, now);
+ // Screenshot completion, deadlines and issuance are app-side work: the callback only
+ // stores pixels and wakes this viewport.
+ self.tick_screenshots(ctx);
+ // Time-based FPS readout over UI passes (a hidden logic-only tick is not a frame).
+ let dt = (now - self.last_time) as f32;
+ if dt > 0.0 && dt < 2.0 {
+ self.fps = self.fps * 0.9 + (1.0 / dt).min(480.0) * 0.1;
+ }
+ self.last_time = now;
+ // A hidden window paints when work needs a UI pass: queued input and waits, a settled
+ // screenshot, or playback into a child viewport.
+ let focused = self.focused;
+ let child_viewports = !self.ui.dock.layout.floating.is_empty() || prefs_live::video_preview_active(self, focused);
+ let paint = self.want_paint
+ || !self.synthetic.is_empty()
+ || !self.input_waiters.is_empty()
+ || self.pending_screenshots.iter().any(|s| s.slot.is_none())
+ || (self.playback.playing && child_viewports);
+ if paint {
+ self.request_hidden_paint(ctx);
+ }
+ }
+
+ /// Ask the host for a UI pass even when the window is minimized or occluded.
+ ///
+ /// Native eframe honours `RequestPaintWhileHidden`; the shared web backend does not carry it
+ /// yet (a browser does not paint a hidden tab), so the web build only requests a normal
+ /// repaint and hidden web screenshots/input remain unqualified.
+ fn request_hidden_paint(&mut self, ctx: &egui::Context) {
+ self.want_paint = false;
+ #[cfg(not(target_arch = "wasm32"))]
+ ctx.send_viewport_cmd(egui::ViewportCommand::RequestPaintWhileHidden);
+ ctx.request_repaint();
+ }
+
+ /// Install the theme and fonts for the current language. Fonts need a real pass: the pass
+ /// that installs them draws nothing, and the next pass draws with them (the two-pass warm-up
+ /// the app has always had). Never call this from a logic-only tick.
+ fn ui_setup(&mut self, ctx: &egui::Context) {
+ panels::viewer_text::install_hooks(ctx);
+ let language = crate::i18n::language(self);
+ crate::i18n::set_current(language);
+ if (!self.styled || self.styled_language != language) && self.synthetic_in_flight {
+ // The install needs a pass that draws nothing, but this pass has already applied a
+ // synthetic batch: defer the theme/font install by one pass instead of dropping the
+ // input (feeds are only put into a pass that can draw).
+ ctx.request_repaint();
+ return;
+ }
+ if !self.styled || self.styled_language != language {
+ theme::install(ctx, &self.tokens, language);
+ self.styled_language = language;
+ if !self.styled {
+ fit_window(ctx);
+ self.styled = true;
+ }
+ self.fonts_ready = false;
+ ctx.request_repaint();
+ } else if !self.fonts_ready {
+ // The pass after the install draws: egui has the new font definitions by now.
+ self.fonts_ready = true;
+ ctx.request_repaint();
+ }
+ }
+
+ /// One UI pass: setup, input-driven shortcuts, layout and painting. Called from
+ /// `eframe::App::ui` and by tests with the root `Ui`.
+ pub fn draw(&mut self, ui: &mut egui::Ui, frame: &eframe::Frame) {
+ panels::viewer_text::begin_ui(ui.ctx());
+ self.draw_inner(ui, frame);
+ // All exits, including fonts/device loss, observe this pass's real custom availability.
+ panels::viewer_text::finish_ime(self, ui);
+ }
+
+ /// Context creators install these hooks before the first full pass.
+ pub fn install_ime_reset_hooks(ctx: &egui::Context) {
+ panels::viewer_text::install_hooks(ctx);
+ }
+
+ /// Host wrappers call this after their last logic mutation, without replaying UI events.
+ pub fn finish_ime_logic(&self, ctx: &egui::Context) {
+ panels::viewer_text::finish_logic(self, ctx);
+ }
+
+ /// One UI pass after the IME begin hook: close on an applied GPU failure, run `ui_setup`, skip drawing until
+ /// fonts are ready, draw the frame, finish pointer wrapping, pump queued wasm frames, record input activity,
+ /// publish the completed pass's geometry and pass sequence, acknowledge applied synthetic input and answer
+ /// `AfterInput` replies only after a non-discarded pass. Requests repaints while frames are in flight.
+ fn draw_inner(&mut self, ui: &mut egui::Ui, frame: &eframe::Frame) {
+ let ctx = ui.ctx().clone();
+ if self.gpu_failure_applied == Some(true) {
+ self.close_after_device_loss(&ctx);
+ return;
+ }
+ self.ui_setup(&ctx);
+ if !self.fonts_ready {
+ // A pass that installs fonts draws nothing. No synthetic batch is in flight here (the
+ // hook feeds input only to a ready app), and events egui already applied are never
+ // fed again: that would double the pointer/key state of one click.
+ ctx.request_repaint();
+ return;
+ }
+ self.frame(ui);
+ #[cfg(not(target_arch = "wasm32"))]
+ pointer_wrap::finish_native(&ctx, frame);
+ // wasm32: no frame threads; render queued frames now, between UI frames.
+ if cfg!(target_arch = "wasm32") && self.frames.pump(std::time::Duration::from_millis(if self.playback.playing { 24 } else { 40 })) {
+ ctx.request_repaint();
+ }
+ // Input belongs to this known UI phase: record it for the next tick.
+ let active = ctx.input(|i| !i.events.is_empty() || i.pointer.any_down() || i.pointer.is_moving());
+ self.input_active = active;
+ self.last_pointer_down = ctx.input(|i| i.pointer.any_down());
+ // Geometry of a completed pass (a discarded pass is laid out again; only the final one
+ // describes the surface the next capture will see). Window position is irrelevant.
+ if !ctx.will_discard() {
+ let rect = ctx.content_rect();
+ let ppp = ctx.pixels_per_point();
+ let changed = self.draw_geom.is_none_or(|g| g.rect.size() != rect.size() || g.ppp != ppp);
+ if changed {
+ self.geometry_epoch = self.geometry_epoch.wrapping_add(1);
+ }
+ self.draw_geom = Some(DrawGeometry { rect, ppp, epoch: self.geometry_epoch });
+ self.ui_pass_seq = self.ui_pass_seq.saturating_add(1);
+ }
+ // A batch is acknowledged once a UI pass applied it, even if layout was later discarded.
+ self.mark_synthetic_applied();
+ // `AfterInput` replies wait for the final (non-discarded) pass that applied the last
+ // synthetic event: a hidden request is answered only after its forced pass, and a pass
+ // egui throws away cannot produce an early success reply.
+ if !ctx.will_discard() && self.synthetic.is_empty() {
+ for w in self.input_waiters.drain(..) {
+ let _ = w.send(json!({"ok": true, "result": null}));
+ }
+ } else if !self.input_waiters.is_empty() {
+ self.want_paint = true;
+ ctx.request_repaint();
+ }
+ if self.frames.inflight() > 0 {
+ ctx.request_repaint_after(std::time::Duration::from_millis(30));
+ }
+ }
+
+ /// The panels, menus, dialogs and overlays of one pass.
+ fn frame(&mut self, ui: &mut egui::Ui) {
+ let ctx = ui.ctx().clone();
+ // Only a viewer that draws in *this* pass records a scale: a closed viewer, the Home
+ // screen or another comp must stop idle prefetch at a stale scale.
+ self.last_viewer_scale = None;
+ self.apply_prefs(&ctx);
+ // Video Preview is a second viewport: only a real pass can update it.
+ prefs_live::frame(self, &ctx);
+ self.auto.begin_frame();
++ if let Some(rect) = crate::color_picker::take_automation(&ctx) {
++ self.auto.add("colorPicker.eyedropper", rect, "Eyedropper");
++ }
+ let tab_had_widget_focus = ctx.egui_wants_keyboard_input();
+ 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 {
+ let mb = egui::Rect::from_min_size(full.min, egui::vec2(full.width(), 24.0));
+ let mut child = ui.new_child(egui::UiBuilder::new().max_rect(mb));
+ child.painter().rect_filled(mb, 0.0, t.header_bg);
+ menus::menu_bar(self, &mut child);
+ top = mb.max.y;
+ }
+ let header_h = 40.0;
+ let header = egui::Rect::from_min_size(egui::pos2(full.min.x, top), egui::vec2(full.width(), header_h));
+ header::show(self, ui, header);
+ let body = egui::Rect::from_min_max(egui::pos2(full.min.x + 4.0, header.max.y + 2.0), egui::pos2(full.max.x - 4.0, full.max.y - 4.0));
+ self.dock_area(ui, body);
+ #[cfg(not(target_arch = "wasm32"))]
+ prefs_live::dropped_files(self, ui, full);
+ if !tab_had_widget_focus {
+ menus::handle_tab_shortcut(self, &ctx);
+ }
+ panels::precomp::mini_flowchart(self, &ctx);
+ panels::home::capture_thumbnail(self);
+ panels::dialogs::show(self, &ctx);
+ updates_ui::show(self, &ctx);
+ panels::scriptui_view::sync_panels(self);
+ panels::scriptui_view::show_windows(self, &ctx);
+ panels::learn::coach(self, &ctx);
+ let lift = panels::media_panels::import_card(self, ui, full);
+ self.draw_toast(ui, full, lift);
+ }
+
+ /// Workspace-layout auto-save: a background write that also runs while hidden, once the
+ /// pointer has lifted.
+ fn tick_workspace_autosave(&mut self, ctx: &egui::Context) {
+ if self.session.config.is_none() || !self.workspace_store.has_changes(&self.ui) || self.last_pointer_down {
+ return;
+ }
+ if self.workspace_store.due(self.now) {
+ self.save_workspace_state();
+ }
+ if self.workspace_store.has_changes(&self.ui) {
+ ctx.request_repaint_after(std::time::Duration::from_secs(1));
+ }
+ }
+
+ pub(super) fn save_workspace_state(&mut self) {
+ if let Err(error) = self.workspace_store.save(self.session.config.as_deref(), &self.ui) {
+ if self.workspace_store.error.as_ref() != Some(&error) {
+ log::warn!("{error}");
+ self.ui.status = error.clone();
+ }
+ self.workspace_store.error = Some(error);
+ }
+ }
+
+ /// The status message or the latest toast, bottom left (`lift` points higher while the
+ /// Importing card is there).
+ fn draw_toast(&mut self, ui: &mut egui::Ui, full: egui::Rect, lift: f32) {
+ let now = self.now;
+ let msg = if !self.ui.status.is_empty() {
+ Some(self.ui.status.clone())
+ } else {
+ self.toast.as_ref().filter(|(_, at)| now - at < 4.0).map(|(m, _)| m.clone())
+ };
+ if let Some(m) = msg {
+ let t = &self.tokens;
+ let galley = ui.painter().layout_no_wrap(m.clone(), 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 - lift), galley.size() + egui::vec2(24.0, 14.0));
+ 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);
+ self.auto.add("toast", r, &m);
+ let resp = ui.interact(r, egui::Id::unique("toast"), egui::Sense::click());
+ if resp.clicked() {
+ self.ui.status.clear();
+ self.toast = None;
+ }
+ ui.ctx().request_repaint_after(std::time::Duration::from_millis(500));
+ if !self.ui.status.is_empty() {
+ let since: f64 = ui.data(|d| d.get_temp(egui::Id::unique("status-since")).unwrap_or(now));
+ ui.data_mut(|d| d.insert_temp(egui::Id::unique("status-since"), since));
+ if now - since > 5.0 {
+ self.ui.status.clear();
+ ui.data_mut(|d| d.remove::<f64>(egui::Id::unique("status-since")));
+ }
+ }
+ }
+ }
+ }
+
+ impl EffectcraftApp {
+ /// Scripts' `app.scheduleTask` tasks that are due (repeating ones keep a ScriptUI panel
+ /// fresh): errors as a toast, the last line printed in the status bar, and a repaint when
+ /// the next one is due.
+ fn run_script_tasks(&mut self, ctx: &egui::Context) {
+ if self.session.script_ui.task_hosts.is_empty() {
+ return;
+ }
+ let previous_comp = self.session.active_comp_id();
+ let Some(r) = effectcraft_engine::scriptui::ScriptUi::run_tasks(&mut self.session) else { return };
+ if self.session.active_comp_id().is_some() && self.session.active_comp_id() != previous_comp {
+ self.ui.start_screen = false;
+ }
+ if let Some(msg) = r["errors"].as_array().and_then(|e| e.first()).and_then(|e| e["message"].as_str()) {
+ self.toast = Some((format!("Scheduled script task: {msg}"), self.now));
+ } else if let Some(line) = r["output"].as_array().and_then(|o| o.last()).and_then(|l| l.as_str()) {
+ self.ui.status = line.to_string();
+ }
+ if let Some(next) = r["next"].as_u64() {
+ ctx.request_repaint_after(std::time::Duration::from_millis(next));
+ }
+ }
+
+ /// Auto-save a dirty project when the interval has passed (Settings ▸ Project ▸ Auto-Save).
+ fn tick_autosave(&mut self, ctx: &egui::Context) {
+ // Monotonic app time: a wall-clock jump must not skip or repeat an auto-save.
+ let now = self.now;
+ if let Some(Err(e)) = self.session.autosave_tick(now) {
+ self.ui.status = e.to_string();
+ }
+ if self.session.prefs.auto_save.enabled {
+ ctx.request_repaint_after(std::time::Duration::from_secs(30));
+ }
+ // File ▸ Watch Folder: look for new projects every 10 seconds.
+ if self.session.state.watch_folder.is_some() {
+ let key = egui::Id::unique("watchFolder.lastPoll");
+ let last: f64 = ctx.data(|d| d.get_temp(key)).unwrap_or(0.0);
+ if now - last >= 10.0 {
+ ctx.data_mut(|d| d.insert_temp(key, now));
+ match self.session.execute("file.watchFolder.poll", serde_json::json!({})) {
+ Ok(r) => {
+ if let Some(n) = r["rendered"].as_array().map(Vec::len).filter(|n| *n > 0) {
+ self.ui.status = format!("Watch Folder: rendered {n} project(s)");
+ }
+ }
+ Err(e) => self.ui.status = e.to_string(),
+ }
+ }
+ ctx.request_repaint_after(std::time::Duration::from_secs(10));
+ }
+ self.tick_footage_reload(ctx, now);
+ }
+
+ /// Settings ▸ Import ▸ Reload Footage Changed on Disk: every two seconds, and as soon as the
+ /// window comes back to the front (after saving in another app), stamp the footage files on a
+ /// worker thread and reload the ones that changed.
+ fn tick_footage_reload(&mut self, ctx: &egui::Context, now: f64) {
+ use effectcraft_engine::footage_reload;
+ if let Some(Err(e)) = footage_reload::poll_scan(&mut self.session) {
+ self.ui.status = e.to_string();
+ }
+ let (last_key, focus_key) = (egui::Id::unique("footageReload.lastScan"), egui::Id::unique("footageReload.focused"));
+ let focused = self.focused;
+ let was_focused: bool = ctx.data(|d| d.get_temp(focus_key)).unwrap_or(focused);
+ ctx.data_mut(|d| d.insert_temp(focus_key, focused));
+ if self.session.prefs.import.auto_reload_footage == "off" || self.session.project.items.is_empty() {
+ return;
+ }
+ let last: f64 = ctx.data(|d| d.get_temp(last_key)).unwrap_or(0.0);
+ if now - last >= 2.0 || (focused && !was_focused) {
+ ctx.data_mut(|d| d.insert_temp(last_key, now));
+ footage_reload::start_scan(&mut self.session);
+ }
+ if self.session.footage_scan.is_some() {
+ ctx.request_repaint_after(std::time::Duration::from_millis(100));
+ } else {
+ ctx.request_repaint_after(std::time::Duration::from_secs(2));
+ }
+ }
+ }
diff --cc crates/ui-egui/src/color_picker.rs
index a692d78db,acc01cc65..b4fd70544
--- a/crates/ui-egui/src/color_picker.rs
+++ b/crates/ui-egui/src/color_picker.rs
@@@ -53,21 -41,19 +53,27 @@@ pub fn color_popup(ui: &mut Ui, id: egu
let area = egui::Area::new(id.with("area")).order(egui::Order::Foreground).fixed_pos(pos + vec2(0.0, 4.0)).show(ui.ctx(), |ui| {
egui::Frame::popup(ui.style()).show(ui, |ui| out = color_picker(ui, id, c, original));
});
- // Escape is the picker's: consume it, so nothing later this pass takes it too.
+ // Escape is the picker's: consume it, so nothing later this pass takes it too. While the
+ // eyedropper is armed, Escape cancels it and the picker stays open.
if ui.input_mut(|i| i.consume_key(egui::Modifiers::NONE, egui::Key::Escape)) {
- out.close = Some(false);
+ if armed {
+ disarm(ui.ctx(), id);
+ } else {
+ out.close = Some(false);
+ }
}
+ // A press outside closes the picker, unless it is the armed eyedropper's press on the viewer.
+ let on_viewer = armed && eyedropper_point(ui.ctx()).is_some();
- if pressed_outside(ui.ctx(), &area.response) && !on_viewer {
+ // A press in the pass that first draws the picker must not close it: an Area's rect is only
+ // at its requested position from its second pass on (the first pass reports it at the
+ // origin), so the click that just opened the picker would be read as a press outside it and
+ // the picker would flash and close in that one frame (#1476).
+ let pass_id = id.with("open-pass");
+ let drawn_before = ui.data(|d| d.get_temp::<u64>(pass_id)).is_some_and(|p| p < ui.ctx().cumulative_pass_nr());
- if drawn_before && pressed_outside(ui.ctx(), &area.response) {
++ if drawn_before && pressed_outside(ui.ctx(), &area.response) && !on_viewer {
out.close.get_or_insert(true);
}
+ note_overlay(ui.ctx(), area.response.rect);
if let Some(keep) = out.close {
if !keep && *c != original {
*c = original;
@@@ -81,16 -67,20 +88,21 @@@
d.remove::<u64>(open_pass_id());
});
} else {
+ refresh_armed(ui.ctx(), id);
// Still open after this pass: dialogs leave Escape to the picker (see `open_recently`).
let pass = ui.ctx().cumulative_pass_nr();
- ui.data_mut(|d| d.insert_temp(open_pass_id(), pass));
+ ui.data_mut(|d| {
+ d.insert_temp(pass_id, pass);
+ d.insert_temp(open_pass_id(), pass);
+ });
}
- out.changed
+ out.changed || sampled
}
+ /// The `egui::Id` of the pass number in which a colour picker last stayed open, which
+ /// [`open_recently`] uses to keep Escape for the picker rather than the dialog under it.
fn open_pass_id() -> egui::Id {
- egui::Id::new("color-picker-open-pass")
+ egui::Id::unique("color-picker-open-pass")
}
/// A colour picker is open: it was drawn, and stayed open, in this pass or the last one (so one
@@@ -102,177 -92,6 +114,177 @@@ pub fn open_recently(ctx: &egui::Contex
pass.is_some_and(|p| p.saturating_add(1) >= ctx.cumulative_pass_nr())
}
+/// The armed eyedropper of a picker: the picker's popup id, the pass it was last drawn in, and the
+/// colour the viewer sampled for it, if one is waiting for the picker's next draw. It lives in the
+/// egui context, since the viewer that samples has no picker in hand.
+#[derive(Clone, Copy)]
+struct Armed {
+ popup: egui::Id,
+ pass: u64,
+ sample: Option<[f32; 3]>,
+}
+
+fn armed_key() -> egui::Id {
- egui::Id::new("color-picker-eyedropper")
++ egui::Id::unique("color-picker-eyedropper")
+}
+
+/// The armed eyedropper, if its picker was drawn in this pass or the last: one whose picker stops
+/// being drawn (its dialog gone) lapses.
+fn armed_record(ctx: &egui::Context) -> Option<Armed> {
+ let armed: Option<Armed> = ctx.data(|d| d.get_temp(armed_key()));
+ let pass = ctx.cumulative_pass_nr();
+ armed.filter(|a| a.pass.saturating_add(1) >= pass)
+}
+
+fn armed_for(ctx: &egui::Context, popup: egui::Id) -> bool {
+ armed_record(ctx).is_some_and(|a| a.popup == popup)
+}
+
+/// Some picker's eyedropper is armed: a press on the Composition viewer samples the frame for it.
+pub fn eyedropper_armed(ctx: &egui::Context) -> bool {
+ armed_record(ctx).is_some()
+}
+
+fn arm(ctx: &egui::Context, popup: egui::Id) {
+ let pass = ctx.cumulative_pass_nr();
+ ctx.data_mut(|d| d.insert_temp(armed_key(), Armed { popup, pass, sample: None }));
+}
+
+fn disarm(ctx: &egui::Context, popup: egui::Id) {
+ let armed: Option<Armed> = ctx.data(|d| d.get_temp(armed_key()));
+ if armed.is_some_and(|a| a.popup == popup) {
+ ctx.data_mut(|d| d.remove::<Armed>(armed_key()));
+ }
+}
+
+/// Keeps `popup`'s eyedropper armed while its picker is drawn.
+fn refresh_armed(ctx: &egui::Context, popup: egui::Id) {
+ if let Some(armed) = armed_record(ctx).filter(|a| a.popup == popup) {
+ let pass = ctx.cumulative_pass_nr();
+ ctx.data_mut(|d| d.insert_temp(armed_key(), Armed { pass, ..armed }));
+ }
+}
+
+/// The colour the viewer sampled for `popup`, once: taking it disarms the eyedropper.
+fn take_sample(ctx: &egui::Context, popup: egui::Id) -> Option<[f32; 3]> {
+ let armed = armed_record(ctx).filter(|a| a.popup == popup)?;
+ let sample = armed.sample?;
+ disarm(ctx, popup);
+ Some(sample)
+}
+
+/// The viewer sampled `rgb` for the armed picker, which takes it on its next draw.
+pub fn deliver_sample(ctx: &egui::Context, rgb: [f32; 3]) {
+ if let Some(armed) = armed_record(ctx) {
+ ctx.data_mut(|d| d.insert_temp(armed_key(), Armed { sample: Some(rgb), ..armed }));
+ ctx.request_repaint();
+ }
+}
+
+fn viewer_key() -> egui::Id {
- egui::Id::new("color-picker-viewer")
++ egui::Id::unique("color-picker-viewer")
+}
+
+/// The Composition viewer's rect as it was drawn this pass: where an armed eyedropper samples.
+pub fn note_viewer(ctx: &egui::Context, rect: Rect) {
+ let pass = ctx.cumulative_pass_nr();
+ ctx.data_mut(|d| d.insert_temp(viewer_key(), (pass, rect)));
+}
+
+fn overlay_key() -> egui::Id {
- egui::Id::new("color-picker-overlays")
++ egui::Id::unique("color-picker-overlays")
+}
+
+/// A popup or dialog drawn over the viewer: a press inside `rect` is not a sample.
+pub fn note_overlay(ctx: &egui::Context, rect: Rect) {
+ let pass = ctx.cumulative_pass_nr();
+ ctx.data_mut(|d| {
+ // This pass's and the last's: the viewer may be drawn before an overlay in a pass.
+ let mut rects = d.get_temp::<Vec<(u64, Rect)>>(overlay_key()).unwrap_or_default();
+ rects.retain(|(p, _)| p.saturating_add(1) >= pass);
+ rects.push((pass, rect));
+ d.insert_temp(overlay_key(), rects);
+ });
+}
+
+/// Whether `pos` is over a popup or dialog drawn this pass or the last.
+fn overlaid(ctx: &egui::Context, pos: egui::Pos2) -> bool {
+ let pass = ctx.cumulative_pass_nr();
+ let rects: Option<Vec<(u64, Rect)>> = ctx.data(|d| d.get_temp(overlay_key()));
+ rects.unwrap_or_default().iter().any(|(p, r)| p.saturating_add(1) >= pass && r.contains(pos))
+}
+
+/// Where an armed eyedropper samples: the pointer, if it is over the viewer and not over a popup or
+/// dialog. The pointer is read rather than the viewer's responses, since a modal dialog over the
+/// viewer takes its clicks.
+pub fn eyedropper_point(ctx: &egui::Context) -> Option<egui::Pos2> {
+ let viewer: Option<(u64, Rect)> = ctx.data(|d| d.get_temp(viewer_key()));
+ let viewer = viewer.filter(|(p, _)| p.saturating_add(1) >= ctx.cumulative_pass_nr())?.1;
+ let pos = ctx.input(|i| i.pointer.interact_pos())?;
+ (viewer.contains(pos) && !overlaid(ctx, pos)).then_some(pos)
+}
+
+/// The press that samples for an armed eyedropper this frame, if there is one.
+pub fn sample_press(ctx: &egui::Context) -> Option<egui::Pos2> {
+ if ctx.input(|i| i.pointer.primary_pressed()) { eyedropper_point(ctx) } else { None }
+}
+
+fn automation_key() -> egui::Id {
- egui::Id::new("color-picker-eyedropper-rect")
++ egui::Id::unique("color-picker-eyedropper-rect")
+}
+
+/// The eyedropper's rect, for the automation registry; [`take_automation`] hands it over.
+fn note_automation(ctx: &egui::Context, rect: Rect) {
+ ctx.data_mut(|d| d.insert_temp(automation_key(), rect));
+}
+
+/// The eyedropper rect the last picker drawing noted, once. Pickers have no registry in hand, so the
+/// app registers it each frame.
+pub fn take_automation(ctx: &egui::Context) -> Option<Rect> {
+ ctx.data_mut(|d| {
+ let rect = d.get_temp::<Rect>(automation_key());
+ d.remove::<Rect>(automation_key());
+ rect
+ })
+}
+
+/// The eyedropper of the hex row. A press arms it, or disarms it while armed; the next press on the
+/// Composition viewer then samples the colour under the pointer into this picker.
+fn eyedropper(ui: &mut Ui, popup: egui::Id) {
+ let armed = armed_for(ui.ctx(), popup);
+ let (rect, resp) = ui.allocate_exact_size(vec2(18.0, 18.0), Sense::click());
+ let resp = resp.on_hover_text(tr("Eyedropper: click, then click in the Composition panel"));
- resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, ui.is_enabled(), "Eyedropper"));
++ resp.widget_info(|| egui::WidgetInfo::labeled(egui::Role::Button, resp.enabled(), "Eyedropper"));
+ let fill = if armed {
+ ui.visuals().selection.bg_fill
+ } else if resp.hovered() {
+ ui.visuals().widgets.hovered.bg_fill
+ } else {
+ Color32::TRANSPARENT
+ };
+ ui.painter().rect_filled(rect, 2.0, fill);
+ let col = if armed { ui.visuals().selection.stroke.color } else { ui.visuals().strong_text_color() };
+ draw_pipette(ui.painter(), rect, col);
+ if resp.clicked() {
+ if armed {
+ disarm(ui.ctx(), popup);
+ } else {
+ arm(ui.ctx(), popup);
+ }
+ }
+ note_automation(ui.ctx(), rect);
+}
+
+/// A pipette: a diagonal glass tube with a bulb at the top right and a tip at the bottom left, drawn
+/// within `rect`.
+pub fn draw_pipette(p: &egui::Painter, rect: Rect, col: Color32) {
+ let r = rect.shrink(rect.width() * 0.2);
+ let at = |x: f32, y: f32| pos2(r.min.x + x * r.width(), r.min.y + y * r.height());
+ p.line_segment([at(0.08, 0.92), at(0.62, 0.38)], Stroke::new(2.2, col));
+ p.circle_filled(at(0.76, 0.24), r.width() * 0.2, col);
+ p.line_segment([at(0.5, 0.3), at(0.7, 0.5)], Stroke::new(1.4, col));
+}
+
/// What the picker did this frame.
#[derive(Default)]
struct Outcome {
@@@ -623,30 -447,3 +641,30 @@@ pub fn hsv_to_rgb([h, s, v]: [f32; 3])
};
[f(5.0), f(3.0), f(1.0)]
}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn armed_eyedropper_takes_one_sample_then_disarms() {
+ let ctx = egui::Context::default();
- let popup = egui::Id::new("test-picker");
++ let popup = egui::Id::unique("test-picker");
+ arm(&ctx, popup);
+ assert!(eyedropper_armed(&ctx));
+ assert_eq!(take_sample(&ctx, popup), None);
+ deliver_sample(&ctx, [0.1, 0.2, 0.3]);
+ assert_eq!(take_sample(&ctx, popup), Some([0.1, 0.2, 0.3]));
+ assert!(!eyedropper_armed(&ctx));
+ assert_eq!(take_sample(&ctx, popup), None);
+ }
+
+ #[test]
+ fn points_over_a_dialog_are_not_samples() {
+ let ctx = egui::Context::default();
+ let dialog = Rect::from_min_size(pos2(100.0, 100.0), vec2(120.0, 80.0));
+ note_overlay(&ctx, dialog);
+ assert!(overlaid(&ctx, pos2(150.0, 150.0)));
+ assert!(!overlaid(&ctx, pos2(20.0, 20.0)));
+ }
+}
diff --cc crates/ui-egui/src/panels/effect_controls/viewer.rs
index 000000000,b11b63a35..5f471953c
mode 000000,100644..100644
--- a/crates/ui-egui/src/panels/effect_controls/viewer.rs
+++ b/crates/ui-egui/src/panels/effect_controls/viewer.rs
@@@ -1,0 -1,295 +1,328 @@@
+ use std::ops::ControlFlow;
+
+ use super::common::{Actions, effect_active, gesture_key};
+ use super::rows::FxScope;
+ use super::{
+ Align2, Color32, EffectcraftApp, EvalCtx, GroupKind, Layer, Mat3, Node, ParamUi, PropGroup, Property, Rect, Sense, Stroke, Tokens, fw, json, vec2,
+ };
+
+ // ---------------------------------------------------------------------------------------------
+ // Viewer hook
+
+ /// Collect point controls through visible parameter groups. Hidden optional slots do not
+ /// leave stray viewport handles. The depth cap also bounds malformed project trees.
+ fn visible_points<'a>(g: &'a PropGroup, scope: &FxScope<'_>, layer: &Layer, ectx: &EvalCtx, depth: usize, out: &mut Vec<&'a Property>) {
+ if depth > 16 {
+ return;
+ }
+ for node in &g.children {
+ match node {
+ Node::Prop(p) if matches!(p.ui, ParamUi::Point) && scope.shown(layer, ectx, &p.match_id) => out.push(p),
+ Node::Group(child) if child.enabled && scope.shown(layer, ectx, &child.match_id) => {
+ visible_points(child, &scope.sub(&child.match_id), layer, ectx, depth + 1, out)
+ }
+ _ => {}
+ }
+ }
+ }
+
+ /// An armed crosshair / eyedropper pick: the hint chip, the cursor preview, and the click that
+ /// sets or samples. `Break` when the picked layer is gone; `Continue` carries the point preview.
+ fn fx_pick_session(
+ app: &mut EffectcraftApp,
+ ui: &mut egui::Ui,
+ painter: &egui::Painter,
+ map: &crate::panels::viewer::ViewerMap,
+ ectx: &EvalCtx,
+ l2c: &dyn Fn(&EvalCtx, &Layer) -> Mat3,
+ actions: &mut Actions,
+ ) -> ControlFlow<(), Option<egui::Pos2>> {
+ let t = app.tokens;
+ let ctx = ui.ctx().clone();
+ let mut point_preview = None;
+ let Some(pick) = app.ui.fx_pick.clone() else {
+ return ControlFlow::Continue(None);
+ };
+ let Some(layer) = ectx.comp.layer(effectcraft_engine::project::LayerId(pick.layer)).cloned() else {
+ app.ui.fx_pick = None;
+ return ControlFlow::Break(());
+ };
+ // Keyers pick from their input (the shown frame is already keyed): `effect.pickColor`.
+ let keyer = (pick.kind == "color")
+ .then(|| layer.effects()?.groups().find(|g| g.find(pick.prop).is_some()))
+ .flatten()
+ .filter(|g| effectcraft_engine::effects::find(&g.match_id).is_some_and(|s| s.category == "Keying"))
+ .map(|g| g.uid);
+ if pick.kind == "color" && keyer.is_none() {
+ // GPU frames: read the shown frame back for sampling.
+ app.viewer_pixels();
+ }
+ let resp = ui.interact(map.area, egui::Id::unique("viewer-fx-pick"), Sense::click());
+ app.auto.add("viewer.fxPick", map.area, &pick.name);
+ let hint = if pick.kind == "point" { format!("Click to set {}", pick.name) } else { format!("Click to sample {}", pick.name) };
+ let chip = Rect::from_min_size(map.area.min + vec2(10.0, 10.0), vec2(220.0, 22.0));
+ painter.rect_filled(chip, 11.0, Color32::from_black_alpha(180));
+ painter.text(chip.center(), Align2::CENTER_CENTER, hint, Tokens::ui(11.5), t.text);
+ if let Some(hp) = resp.hover_pos() {
+ ctx.set_cursor_icon(egui::CursorIcon::Crosshair);
+ let c = map.to_comp(hp);
+ app.pointer_comp = Some([c[0] as f32, c[1] as f32]);
+ if pick.kind == "point" && fw::comp_to_layer(&l2c(ectx, &layer), c).is_some() {
+ point_preview = Some(hp);
+ }
+ if pick.kind == "color"
+ && keyer.is_none()
+ && let Some(img) = &app.viewer_image
+ && let Some(s) = fw::sample_frame(img, crate::panels::viewer_tools::shown_region(&ctx, map.comp), c)
+ {
+ let sw = Rect::from_min_size(hp + vec2(14.0, 14.0), vec2(26.0, 18.0));
+ painter.rect_filled(sw, 2.0, Color32::from_rgb((s[0] * 255.0) as u8, (s[1] * 255.0) as u8, (s[2] * 255.0) as u8));
+ painter.rect_stroke(sw, 2.0, Stroke::new(1.0, Color32::WHITE), egui::StrokeKind::Outside);
+ }
+ }
+ // No frame to sample yet (it is still rendering, or its readback is pending): the click
+ // leaves the eyedropper armed instead of using it up without a colour.
+ let unsampled = pick.kind == "color" && keyer.is_none() && app.viewer_image.is_none();
+ if resp.clicked()
+ && !unsampled
+ && let Some(pos) = resp.interact_pointer_pos()
+ {
+ let c = map.to_comp(pos);
+ // Effect points and the keyer's input are in effect space.
+ let m = crate::panels::viewer::from_effect_space(ectx, &layer, l2c(ectx, &layer));
+ if pick.kind == "point" {
+ if let Some(lp) = fw::comp_to_layer(&m, c) {
+ actions.push(("prop.set".into(), json!({"layer": pick.layer, "prop": pick.prop, "value": [lp[0], lp[1]]})));
+ }
+ } else if let Some(fx) = keyer {
+ // Ctrl/Cmd+click averages the 5 × 5 pixels around the point.
+ if let Some(lp) = fw::comp_to_layer(&m, c) {
+ let average = ui.input(|i| i.modifiers.command);
+ actions.push((
+ "effect.pickColor".into(),
+ json!({"layer": pick.layer, "effect": fx, "prop": pick.prop, "x": lp[0], "y": lp[1], "average": average}),
+ ));
+ }
+ } else if let Some(img) = &app.viewer_image
+ && let Some(s) = fw::sample_frame(img, crate::panels::viewer_tools::shown_region(&ctx, map.comp), c)
+ {
+ actions.push(("prop.set".into(), json!({"layer": pick.layer, "prop": pick.prop, "value": [s[0], s[1], s[2], 1.0]})));
+ }
+ app.ui.fx_pick = None;
+ app.ui.status.clear();
+ }
+ if ui.input(|i| i.key_pressed(egui::Key::Escape)) {
+ app.ui.fx_pick = None;
+ app.ui.status.clear();
+ }
+
+ ControlFlow::Continue(point_preview)
+ }
+
+ /// An armed text-colour pick: sample the shown frame on click, Esc cancels.
+ fn text_color_pick(
+ app: &mut EffectcraftApp,
+ ui: &mut egui::Ui,
+ painter: &egui::Painter,
+ map: &crate::panels::viewer::ViewerMap,
+ ectx: &EvalCtx,
+ actions: &mut Actions,
+ ) {
+ let t = app.tokens;
+ let ctx = ui.ctx().clone();
+ let Some(pick) = app.ui.text_color_pick.clone() else {
+ return;
+ };
+ if ectx.comp.layer(effectcraft_engine::project::LayerId(pick.layer)).is_none() {
+ app.ui.text_color_pick = None;
+ app.ui.status.clear();
+ } else {
+ app.viewer_pixels();
+ let resp = ui.interact(map.area, egui::Id::unique("viewer-text-color-pick"), Sense::click());
+ app.auto.add("viewer.textColorPick", map.area, &pick.field);
+ let chip = Rect::from_min_size(map.area.min + vec2(10.0, 10.0), vec2(220.0, 22.0));
+ painter.rect_filled(chip, 11.0, Color32::from_black_alpha(180));
+ painter.text(chip.center(), Align2::CENTER_CENTER, crate::i18n::tr_args("Click to sample text {}", &[&pick.field]), Tokens::ui(11.5), t.text);
+ if let Some(pos) = resp.hover_pos() {
+ ctx.set_cursor_icon(egui::CursorIcon::Crosshair);
+ let c = map.to_comp(pos);
+ app.pointer_comp = Some([c[0] as f32, c[1] as f32]);
+ if let Some(img) = &app.viewer_image
+ && let Some(s) = fw::sample_frame(img, crate::panels::viewer_tools::shown_region(&ctx, map.comp), c)
+ {
+ let sw = Rect::from_min_size(pos + vec2(14.0, 14.0), vec2(26.0, 18.0));
+ painter.rect_filled(sw, 2.0, Color32::from_rgb((s[0] * 255.0) as u8, (s[1] * 255.0) as u8, (s[2] * 255.0) as u8));
+ painter.rect_stroke(sw, 2.0, Stroke::new(1.0, Color32::WHITE), egui::StrokeKind::Outside);
+ }
+ }
+ if resp.clicked()
+ && let Some(pos) = resp.interact_pointer_pos()
+ && let Some(img) = &app.viewer_image
+ && let Some(s) = fw::sample_frame(img, crate::panels::viewer_tools::shown_region(&ctx, map.comp), map.to_comp(pos))
+ {
+ let mut params = json!({"layer": pick.layer});
+ params[&pick.field] = json!([s[0], s[1], s[2]]);
+ if let Some(range) = pick.range {
+ params["range"] = json!(range);
+ }
+ actions.push(("layer.setText".into(), params));
+ app.ui.text_color_pick = None;
+ app.ui.status.clear();
+ }
+ if ui.input(|i| i.key_pressed(egui::Key::Escape)) {
+ app.ui.text_color_pick = None;
+ app.ui.status.clear();
+ }
+ }
+ }
+
++/// A colour picker's eyedropper is armed (its popup stays open): the viewer shows the colour under
++/// the pointer, and the next press on it samples the frame into the picker. The press is read from
++/// the pointer, since a modal dialog over the viewer takes its clicks.
++fn popup_eyedropper(app: &mut EffectcraftApp, ui: &mut egui::Ui, painter: &egui::Painter, map: &crate::panels::viewer::ViewerMap) {
++ let t = app.tokens;
++ let ctx = ui.ctx().clone();
++ if !crate::color_picker::eyedropper_armed(&ctx) {
++ return;
++ }
++ let _ = ui.interact(map.area, egui::Id::unique("viewer-popup-eyedropper"), Sense::click());
++ ctx.set_cursor_icon(egui::CursorIcon::Crosshair);
++ app.viewer_pixels();
++ let chip = Rect::from_min_size(map.area.min + vec2(10.0, 10.0), vec2(220.0, 22.0));
++ painter.rect_filled(chip, 11.0, Color32::from_black_alpha(180));
++ painter.text(chip.center(), Align2::CENTER_CENTER, "Click to sample color", Tokens::ui(11.5), t.text);
++ if let Some(hp) = crate::color_picker::eyedropper_point(&ctx)
++ && let Some(img) = &app.viewer_image
++ && let Some(s) = fw::sample_frame(img, crate::panels::viewer_tools::shown_region(&ctx, map.comp), map.to_comp(hp))
++ {
++ let sw = Rect::from_min_size(hp + vec2(14.0, 14.0), vec2(26.0, 18.0));
++ painter.rect_filled(sw, 2.0, Color32::from_rgb((s[0] * 255.0) as u8, (s[1] * 255.0) as u8, (s[2] * 255.0) as u8));
++ painter.rect_stroke(sw, 2.0, Stroke::new(1.0, Color32::WHITE), egui::StrokeKind::Outside);
++ }
++ if let Some(pos) = crate::color_picker::sample_press(&ctx)
++ && let Some(img) = &app.viewer_image
++ && let Some(s) = fw::sample_frame(img, crate::panels::viewer_tools::shown_region(&ctx, map.comp), map.to_comp(pos))
++ {
++ crate::color_picker::deliver_sample(&ctx, [s[0], s[1], s[2]]);
++ }
++}
++
+ /// Effect Controls' part of the Composition viewer, called by the viewer after its own
+ /// interaction (so these controls sit on top):
+ ///
+ /// - while a crosshair pick is armed, its handle previews the cursor position without editing
+ /// the property; the next click sets the point in layer space, and Esc cancels;
+ /// - an eyedropper pick samples the frame's colour on click;
+ /// - otherwise, the point parameters of the selected effects are drawn as draggable ⊕ controls.
+ ///
+ /// `l2c` is the viewer's layer→comp matrix (it knows the 3D view).
+ pub fn viewer_hook(
+ app: &mut EffectcraftApp,
+ ui: &mut egui::Ui,
+ painter: &egui::Painter,
+ map: &crate::panels::viewer::ViewerMap,
+ ectx: &EvalCtx,
+ l2c: &dyn Fn(&EvalCtx, &Layer) -> Mat3,
+ ) {
+ let t = app.tokens;
+ let ctx = ui.ctx().clone();
++ crate::color_picker::note_viewer(&ctx, map.area);
+ let mut actions: Actions = vec![];
+ let point_preview = match fx_pick_session(app, ui, painter, map, ectx, l2c, &mut actions) {
+ ControlFlow::Break(()) => return,
+ ControlFlow::Continue(p) => p,
+ };
+ text_color_pick(app, ui, painter, map, ectx, &mut actions);
++ popup_eyedropper(app, ui, painter, map);
+ let picking = app.ui.fx_pick.is_some() || app.ui.text_color_pick.is_some();
+ let point_pick = app.ui.fx_pick.clone().filter(|p| p.kind == "point");
+ if app.ui.viewer.show_layer_controls || point_pick.is_some() {
+ // ⊕ controls for the point parameters of the selected effects.
+ let mut sel = app.session.state.selected_props.clone();
+ if let Some(pick) = &point_pick {
+ sel.push((effectcraft_engine::project::LayerId(pick.layer), pick.prop));
+ }
+ let selected = app.session.state.selected_layers.clone();
+ for layer in ectx
+ .comp
+ .layers
+ .iter()
+ .filter(|l| (selected.contains(&l.id) || point_pick.as_ref().is_some_and(|p| p.layer == l.id.0)) && l.is_active_at(ectx.time))
+ {
+ let Some(fx) = layer.effects() else { continue };
+ let m = l2c(ectx, layer);
+ // Masks are in layer space, effect points in effect space.
+ let fm = crate::panels::viewer::from_effect_space(ectx, layer, m);
+ let picked_prop = point_pick.as_ref().filter(|p| p.layer == layer.id.0).map(|p| p.prop);
+ for g in fx.groups().filter(|g| g.enabled && effect_active(g, layer.id, &sel)) {
+ // Puppet owns its pin handles and hit testing. Generic crosshairs would
+ // overlap the pins and steal their selection/rotation/scale gestures.
+ if matches!(&g.kind, GroupKind::Effect { effect } if effect == effectcraft_engine::effects::puppet::ID) {
+ continue;
+ }
+ if !picking
+ && app.ui.viewer.show_layer_controls
+ && matches!(&g.kind, GroupKind::Effect { effect } if effect == crate::panels::fx_editors::RESHAPE)
+ {
+ crate::panels::fx_editors::reshape_overlay(app, ui, painter, map, ectx, layer, g, &m, &mut actions);
+ }
+ if !picking
+ && app.ui.viewer.show_layer_controls
+ && matches!(&g.kind, GroupKind::Effect { effect } if effect == crate::panels::fx_editors::MESH_WARP)
+ {
+ crate::panels::fx_editors::mesh_warp_overlay(app, ui, painter, map, ectx, layer, g, &fm, &mut actions);
+ }
+ let scope = FxScope { effect: &g.match_id, root: g, path: String::new() };
+ let mut pts = Vec::new();
+ visible_points(g, &scope, layer, ectx, 0, &mut pts);
+ // An explicit pick stays visible even when View > Show Layer Controls is off.
+ if !app.ui.viewer.show_layer_controls {
+ pts.retain(|pr| picked_prop == Some(pr.uid));
+ }
+ let screen: Vec<egui::Pos2> = pts
+ .iter()
+ .map(|pr| {
+ if picked_prop == Some(pr.uid)
+ && let Some(pos) = point_preview
+ {
+ return pos;
+ }
+ let v = ectx.value(layer, pr).as_vec2();
+ map.to_screen(fw::layer_to_comp(&fm, v))
+ })
+ .collect();
+ // Gradient Ramp and friends: a guide between start and end points.
+ if screen.len() == 2 && matches!(&g.kind, GroupKind::Effect { effect } if effect.contains("gradient") || effect.contains("ramp")) {
+ painter.line_segment([screen[0], screen[1]], Stroke::new(1.0, Color32::from_white_alpha(110)));
+ }
+ for (pr, s) in pts.iter().zip(screen) {
+ let hr = Rect::from_center_size(s, vec2(16.0, 16.0));
+ let id = egui::Id::unique(("viewer-fx-pt", pr.uid));
+ // The picker owns the click. Preview handles must not steal it or start a drag.
+ let resp = (!picking).then(|| ui.interact(hr, id, Sense::drag()));
+ let col = if picked_prop == Some(pr.uid) || resp.as_ref().is_some_and(|r| r.hovered() || r.dragged()) { t.accent } else { Color32::WHITE };
+ fw::draw_crosshair(painter, s + vec2(1.0, 1.0), 5.0, Color32::from_black_alpha(160));
+ fw::draw_crosshair(painter, s, 5.0, col);
+ app.auto.add(&format!("viewer.effectPoint.{}", pr.uid), hr, &pr.name);
+ let Some(resp) = resp else { continue };
+ if resp.hovered() {
+ ctx.set_cursor_icon(egui::CursorIcon::Move);
+ resp.clone().on_hover_text(format!("{}: {}", crate::i18n::effects::group(&g.match_id, &g.name), pr.name));
+ }
+ if resp.dragged()
+ && let Some(pos) = resp.interact_pointer_pos()
+ && let Some(lp) = fw::comp_to_layer(&fm, map.to_comp(pos))
+ {
+ let key = gesture_key(ui, id, resp.drag_started());
+ actions.push(("prop.set".into(), json!({"layer": layer.id.0, "prop": pr.uid, "value": [lp[0], lp[1]], "merge": key})));
+ }
+ }
+ }
+ }
+ }
+ for (id, params) in actions {
+ if let Err(e) = crate::menus::invoke(app, &ctx, &id, params) {
+ app.ui.status = e;
+ }
+ }
+ }
diff --cc crates/ui-egui/src/panels/text_panels.rs
index ed5c531cb,8a8e604e2..0082abf80
--- a/crates/ui-egui/src/panels/text_panels.rs
+++ b/crates/ui-egui/src/panels/text_panels.rs
@@@ -204,8 -245,7 +245,8 @@@ pub fn character(app: &mut EffectcraftA
}
let er = Rect::from_min_size(pos2(fs.max.x + 4.0, y + 1.0), vec2(18.0, 18.0));
let active = app.ui.text_color_pick.as_ref().is_some_and(|pick| pick.layer == target.as_ref().map_or(0, |tt| tt.layer) && pick.field == key);
- let eye = super::fx_widgets::eyedropper_button(ui, er, active, egui::Id::new(("char-eye", key)), &t)
- let eye = super::fx_widgets::eyedropper_button(ui, er, active, egui::Id::unique(("char-eye", key)), &t);
++ let eye = super::fx_widgets::eyedropper_button(ui, er, active, egui::Id::unique(("char-eye", key)), &t)
+ .on_hover_text(tr("Eyedropper: click, then click in the Composition panel"));
app.auto.add(&format!("character.{key}.eyedropper"), er, &format!("{label} eyedropper"));
if eye.clicked() {
if active {