The Composition viewer ignored drags from other panels. Now, as in After Effects: - A Project item dropped on the viewer becomes a layer centred where it lands (above the selected layer, like any new layer); while dragging, the viewer is outlined and the layer's frame follows the pointer. - Media Browser files do the same; files dropped from the OS file manager do too when the platform reports where the pointer is during the drag (otherwise they import as before). - An effect from Effects & Presets goes on the layer under the pointer, which is outlined while dragging. layer.addItem and layer.newModel take `position` ([x, y] comp px). file.import takes `addToComp` with `time`, `index` and `position`; mediaBrowser.import shares it (file::add_to_comp): layered files go in as their comps, the comp they were dropped in stays open, and items that can't be layers are reported in `errors`. viewer::layer_at is the hit test pick() and the drop share. Tests: ui_drag_drop.rs (project item and effect dropped on the viewer) and imported_files_go_into_the_comp_where_they_were_dropped (engine). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
78f49e09ab
commit
8ef1a28bc4
@@ -49,6 +49,7 @@ pub mod timeline;
|
||||
pub mod tracker;
|
||||
pub mod unsaved;
|
||||
pub mod viewer;
|
||||
pub mod viewer_drop;
|
||||
pub mod viewer_overlays;
|
||||
pub mod viewer_text;
|
||||
pub mod viewer_tools;
|
||||
|
||||
@@ -238,7 +238,7 @@ pub(crate) fn l2c(ctx: &EvalCtx, layer: &Layer) -> (Mat3, f64) {
|
||||
}
|
||||
|
||||
/// Layer → comp matrix and its bounds quad (in comp pixels).
|
||||
fn layer_quad(ctx: &EvalCtx, layer: &Layer) -> Option<(Mat3, [[f64; 2]; 4], [f64; 4])> {
|
||||
pub(crate) fn layer_quad(ctx: &EvalCtx, layer: &Layer) -> Option<(Mat3, [[f64; 2]; 4], [f64; 4])> {
|
||||
let b = effectcraft_engine::render::content_bounds(ctx, layer)?;
|
||||
let (m, _) = l2c(ctx, layer);
|
||||
let pts = [[b[0], b[1]], [b[2], b[1]], [b[2], b[3]], [b[0], b[3]]].map(|p| {
|
||||
@@ -881,6 +881,9 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
}
|
||||
|
||||
// Project items, files and effects dropped on the viewer.
|
||||
super::viewer_drop::show(app, ui, &painter, &map, &ectx);
|
||||
|
||||
// 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));
|
||||
@@ -1733,9 +1736,14 @@ pub(crate) fn selectable_layers(comp: &Comp, time: Tick) -> impl Iterator<Item =
|
||||
.filter(move |l| l.is_active_at(time) && l.switches.video && !l.switches.locked && !l.is_camera() && !l.is_light() && (!any_solo || l.switches.solo))
|
||||
}
|
||||
|
||||
/// Topmost selectable layer under a comp point.
|
||||
pub(crate) fn layer_at<'a>(ectx: &EvalCtx<'a>, cpt: [f64; 2]) -> Option<&'a Layer> {
|
||||
selectable_layers(ectx.comp, ectx.time).find(|l| layer_quad(ectx, l).is_some_and(|(_, q, _)| point_in_quad(cpt, &q)))
|
||||
}
|
||||
|
||||
/// Topmost layer under a comp point (selects it; shift toggles). Returns the hit layer.
|
||||
pub(crate) fn pick(app: &mut EffectcraftApp, ectx: &EvalCtx, cpt: [f64; 2], toggle: bool) -> Option<LayerId> {
|
||||
let hit = selectable_layers(ectx.comp, ectx.time).find(|l| layer_quad(ectx, l).is_some_and(|(_, q, _)| point_in_quad(cpt, &q))).map(|l| l.id)?;
|
||||
let hit = layer_at(ectx, cpt).map(|l| l.id)?;
|
||||
if toggle {
|
||||
let _ = app.session.execute("layer.select", json!({"layers": [hit.0], "toggle": true}));
|
||||
} else if !app.session.state.selected_layers.contains(&hit) {
|
||||
|
||||
@@ -0,0 +1,66 @@
|
||||
//! Dropping onto the Composition viewer, as in After Effects: footage, comps and solids from the
|
||||
//! Project panel and files from the Media Browser become layers centred where they are dropped
|
||||
//! (#85), and an effect from Effects & Presets goes on the layer under the pointer, outlined
|
||||
//! while it is dragged (#88). Agents do the same with `layer.addItem {position}`,
|
||||
//! `mediaBrowser.import {position}` and `effect.apply {layers}`.
|
||||
|
||||
use effectcraft_engine::project::{ItemId, ItemKind};
|
||||
use effectcraft_engine::render::EvalCtx;
|
||||
use egui::{Rect, Stroke, StrokeKind, vec2};
|
||||
use serde_json::{Value, json};
|
||||
|
||||
use super::DragPayload;
|
||||
use super::viewer::{ViewerMap, layer_at, layer_quad};
|
||||
use crate::EffectcraftApp;
|
||||
|
||||
/// While something is dragged over the viewer, show where it goes; drop it on release.
|
||||
pub(crate) fn show(app: &mut EffectcraftApp, ui: &egui::Ui, painter: &egui::Painter, map: &ViewerMap, ectx: &EvalCtx) {
|
||||
let ctx = ui.ctx().clone();
|
||||
let Some(payload) = egui::DragAndDrop::payload::<DragPayload>(&ctx) else { return };
|
||||
if matches!(*payload, DragPayload::Property { .. }) {
|
||||
return;
|
||||
}
|
||||
let Some(ptr) = ctx.input(|i| i.pointer.hover_pos()).filter(|_| ui.rect_contains_pointer(map.area)) else { return };
|
||||
let stroke = Stroke::new(2.0, app.tokens.accent);
|
||||
let at = map.to_comp(ptr);
|
||||
let action: Option<(&str, Value)> = match payload.as_ref() {
|
||||
DragPayload::Effect(effect) => layer_at(ectx, at).map(|l| {
|
||||
if let Some((_, q, _)) = layer_quad(ectx, l) {
|
||||
painter.add(egui::Shape::closed_line(q.iter().map(|c| map.to_screen(*c)).collect(), stroke));
|
||||
}
|
||||
("effect.apply", json!({"effect": effect, "layers": [l.id.0]}))
|
||||
}),
|
||||
DragPayload::Item(item) => {
|
||||
// The layer's frame, centred on the pointer.
|
||||
if let Some([w, h]) = app.session.project.item(ItemId(*item)).and_then(|it| frame_size(&it.kind, ectx.comp.pixel_aspect)) {
|
||||
painter.rect_stroke(Rect::from_center_size(ptr, vec2(w, h) * map.zoom), 0.0, Stroke::new(1.0, app.tokens.accent), StrokeKind::Middle);
|
||||
}
|
||||
Some(("layer.addItem", json!({"item": item, "position": at})))
|
||||
}
|
||||
DragPayload::Files(paths) => Some(("mediaBrowser.import", json!({"paths": paths, "addToComp": true, "position": at}))),
|
||||
DragPayload::Property { .. } => None,
|
||||
};
|
||||
if action.as_ref().is_some_and(|(id, _)| *id != "effect.apply") {
|
||||
painter.rect_stroke(map.area, 0.0, stroke, StrokeKind::Inside);
|
||||
}
|
||||
if ctx.input(|i| i.pointer.any_released()) {
|
||||
egui::DragAndDrop::clear_payload(&ctx);
|
||||
if let Some((id, params)) = action
|
||||
&& let Err(e) = crate::menus::invoke(app, &ctx, id, params)
|
||||
{
|
||||
app.ui.status = e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The size in comp pixels of a layer made from an item of `kind` (`None`: nothing to see).
|
||||
fn frame_size(kind: &ItemKind, comp_pixel_aspect: f64) -> Option<[f32; 2]> {
|
||||
let (w, h, pixel_aspect) = match kind {
|
||||
ItemKind::Comp(c) => (c.width, c.height, c.pixel_aspect),
|
||||
ItemKind::Footage(f) if f.has_video => (f.width, f.height, f.pixel_aspect),
|
||||
ItemKind::Solid(s) => (s.width, s.height, s.pixel_aspect),
|
||||
_ => return None,
|
||||
};
|
||||
let stretch = if comp_pixel_aspect > 0.0 && pixel_aspect > 0.0 { pixel_aspect / comp_pixel_aspect } else { 1.0 };
|
||||
(w > 0 && h > 0).then_some([(w as f64 * stretch) as f32, h as f32])
|
||||
}
|
||||
@@ -18,6 +18,8 @@ pub fn frame(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
}
|
||||
|
||||
/// Files dropped on the window are imported (layered files as Default Drag Import As says).
|
||||
/// Dropped on the Composition viewer, they also become layers centred there, as in After
|
||||
/// Effects (#85), when the platform reports where the pointer is during file drags.
|
||||
fn dropped_files(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
let paths: Vec<String> =
|
||||
ctx.input(|i| i.raw.dropped_files.iter().map(|f| f.path().to_string_lossy().to_string()).filter(|p| std::path::Path::new(p).is_absolute()).collect());
|
||||
@@ -34,7 +36,10 @@ fn dropped_files(app: &mut EffectcraftApp, ctx: &egui::Context) {
|
||||
app.ui.status = e;
|
||||
}
|
||||
if !rest.is_empty() {
|
||||
let params = json!({"paths": rest, "drag": true, "importAs": app.session.prefs.drag_import_as()});
|
||||
let viewer = app.auto.find("viewer.area").map(|e| Rect::from_min_size(egui::pos2(e.rect[0], e.rect[1]), egui::vec2(e.rect[2], e.rect[3])));
|
||||
let at =
|
||||
ctx.input(|i| i.pointer.hover_pos()).filter(|p| viewer.is_some_and(|v| v.contains(*p))).and_then(|p| crate::panels::viewer::screen_to_comp(ctx, p));
|
||||
let params = json!({"paths": rest, "drag": true, "importAs": app.session.prefs.drag_import_as(), "addToComp": at.is_some(), "position": at});
|
||||
if let Err(e) = crate::menus::invoke(app, ctx, "file.import", params) {
|
||||
app.ui.status = e;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user