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
@@ -1,9 +1,14 @@
|
||||
//! Dragging Project items into the Timeline (egui_kittest, real pointer drags): they land where
|
||||
//! they are dropped, between layers and, over the time graph, starting there (#89).
|
||||
//! Drag and drop between panels (egui_kittest, real pointer drags), as in After Effects: Project
|
||||
//! items land in the Timeline where they are dropped, between layers and, over the time graph,
|
||||
//! starting there (#89); dropped on the Composition viewer they are centred where they land
|
||||
//! (#85); an effect dropped on the viewer goes on the layer under the pointer (#88).
|
||||
|
||||
use effectcraft_engine::Session;
|
||||
use effectcraft_engine::keyframe::Value as KV;
|
||||
use effectcraft_engine::time::Tick;
|
||||
use effectcraft_ui_egui::EffectcraftApp;
|
||||
use effectcraft_ui_egui::dock::PanelKind;
|
||||
use effectcraft_ui_egui::panels::viewer::{comp_to_screen, last_fit};
|
||||
use egui::{Event, Modifiers, Pos2, Rect, pos2, vec2};
|
||||
use egui_kittest::Harness;
|
||||
use serde_json::json;
|
||||
@@ -97,3 +102,37 @@ fn project_items_land_where_they_are_dropped_in_the_timeline() {
|
||||
assert_eq!(stack(&h), ["Top", "Middle", "Bottom", "Clip"]);
|
||||
assert!((in_point(&h, 3) - 1.0).abs() < 1e-9, "Shift starts it at the current time");
|
||||
}
|
||||
|
||||
/// #85: a Project item dropped on the Composition viewer becomes a layer centred where it was
|
||||
/// dropped (above the selected layer, like any new layer).
|
||||
#[test]
|
||||
fn project_items_dropped_on_the_viewer_land_under_the_pointer() {
|
||||
let (mut h, clip) = harness();
|
||||
let item = rect(&h, &format!("project.item.{clip}.name")).center();
|
||||
let to = comp_to_screen(&h.ctx, [80.0, 45.0]).unwrap();
|
||||
drag(&mut h, item, to, Modifiers::NONE);
|
||||
assert_eq!(stack(&h), ["Clip", "Top", "Middle", "Bottom"]);
|
||||
let comp = h.state().session.active_comp().unwrap();
|
||||
let Some(KV::Vec3(p)) = comp.layers[0].props.prop("transform/position").map(|p| p.value.clone()) else { panic!("no position") };
|
||||
// One screen point is up to 1/zoom comp pixels.
|
||||
let tol = 1.0 / last_fit(&h.ctx) as f64 + 1e-6;
|
||||
assert!((p[0] - 80.0).abs() <= tol && (p[1] - 45.0).abs() <= tol, "{p:?}");
|
||||
}
|
||||
|
||||
/// #88: an effect dragged from Effects & Presets onto the viewer goes on the layer under the
|
||||
/// pointer, not the selected one.
|
||||
#[test]
|
||||
fn effects_dropped_on_the_viewer_go_on_the_layer_under_the_pointer() {
|
||||
let (mut h, _) = harness();
|
||||
let (top, middle) = (layer_id(&h, "Top"), layer_id(&h, "Middle"));
|
||||
h.state_mut().session.execute("layer.select", json!({"layers": [middle]})).unwrap();
|
||||
h.state_mut().show_panel(PanelKind::EffectsPresets);
|
||||
h.state_mut().ui.effects_search = "Gaussian Blur".into();
|
||||
h.run_steps(3);
|
||||
let fx = rect(&h, "effects.item.ec.blur.gaussian").center();
|
||||
let to = comp_to_screen(&h.ctx, [160.0, 90.0]).unwrap();
|
||||
drag(&mut h, fx, to, Modifiers::NONE);
|
||||
let comp = h.state().session.active_comp().unwrap();
|
||||
let effects = |id: u64| comp.layer(effectcraft_engine::project::LayerId(id)).unwrap().effects().map_or(0, |fx| fx.groups().count());
|
||||
assert_eq!((effects(top), effects(middle)), (1, 0), "on Top, which is under the pointer");
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user