Skip to content

FilmCraft: An open-source, nonlinear video editor written by scratch in pure Rust

program monitor: left button only, rotate anywhere outside the box, Premiere's anchor point (#639)

ReReddo42e04de087dd
diff --git a/crates/ui-egui/src/panels/effect_controls.rs b/crates/ui-egui/src/panels/effect_controls.rs
index fa5dd791e..8fe8f21d0 100644
--- a/crates/ui-egui/src/panels/effect_controls.rs
+++ b/crates/ui-egui/src/panels/effect_controls.rs
@@ -160,9 +160,9 @@ pub fn show(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
let selected = app.session.state.selected_effect.as_ref().is_some_and(|s| s.clip == clip && s.index(&it.effects) == Some(idx));
let (r, resp) = bui.allocate_exact_size(vec2(body.width(), ROW_H), Sense::click());
if selected {
- bui.painter().rect_filled(r, 0.0, t.row_selected);
+ bui.painter().rect_filled(crate::panels::effect_controls::row_fill(r), 0.0, t.row_selected);
} else if resp.hovered() {
- bui.painter().rect_filled(r, 0.0, t.hover);
+ bui.painter().rect_filled(crate::panels::effect_controls::row_fill(r), 0.0, t.hover);
}
row_line(bui, r, &lane, &t);
// only the arrow twirls the effect open or shut; the rest of the header selects it
@@ -982,6 +982,12 @@ pub fn properties_panel(app: &mut FilmcraftApp, ui: &mut egui::Ui, rect: Rect) {
run(app, ui.ctx(), actions);
}
+/// Where a row's highlight (hover, selection) is painted: the row less its first point, which is
+/// where the focused panel's outline runs, so the highlight doesn't cut through the outline.
+pub(crate) fn row_fill(r: Rect) -> Rect {
+ Rect::from_min_max(pos2(r.min.x + 1.0, r.min.y), r.max)
+}
+
/// Run the panel's actions (also the Lumetri Color panel's). Parameter changes made
/// while the mouse button is down (a drag) share one undo step, which the first change of each
/// press begins (#201); typed values and clicks stay separate steps. A drag value only changes once
diff --git a/crates/ui-egui/src/panels/graphics.rs b/crates/ui-egui/src/panels/graphics.rs
index ec813378f..c6522d193 100644
--- a/crates/ui-egui/src/panels/graphics.rs
+++ b/crates/ui-egui/src/panels/graphics.rs
@@ -620,8 +620,8 @@ pub fn monitor_overlay(app: &mut FilmcraftApp, ui: &mut egui::Ui, pic: Rect, fra
let editing = app.ui.gfx_edit.clone();
let edit_view = editing.as_ref().and_then(|e| views.iter().find(|v| v.clip.0 == e.clip && v.layer == e.layer));
- // ---- presses
- if graphics_tool && resp.drag_started() {
+ // ---- presses (the left button only: a middle or right drag leaves the layers alone)
+ if graphics_tool && resp.drag_started_by(egui::PointerButton::Primary) {
// where the button went down (a drag starts only after the pointer has moved a little)
let p = ui.input(|i| i.pointer.press_origin()).or(resp.interact_pointer_pos()).unwrap_or(pic.center());
let shift = ui.input(|i| i.modifiers.shift);
diff --git a/crates/ui-egui/src/panels/masks.rs b/crates/ui-egui/src/panels/masks.rs
index ca2b08fed..431465ea5 100644
--- a/crates/ui-egui/src/panels/masks.rs
+++ b/crates/ui-egui/src/panels/masks.rs
@@ -82,9 +82,9 @@ pub fn effect_rows(
let selected = app.session.state.selected_mask == Some(filmcraft_engine::masks::MaskSel { clip, effect: idx, mask: k });
let (r, resp) = ui.allocate_exact_size(vec2(body.width(), ROW_H), Sense::click());
if selected {
- ui.painter().rect_filled(r, 0.0, t.row_selected);
+ ui.painter().rect_filled(crate::panels::effect_controls::row_fill(r), 0.0, t.row_selected);
} else if resp.hovered() {
- ui.painter().rect_filled(r, 0.0, t.hover);
+ ui.painter().rect_filled(crate::panels::effect_controls::row_fill(r), 0.0, t.hover);
}
crate::panels::effect_controls::row_line(ui, r, lane, &t);
let tw = Rect::from_center_size(pos2(r.min.x + 26.0, r.center().y), vec2(10.0, 10.0));
@@ -172,6 +172,9 @@ pub fn effect_rows(
}
}
+/// Only the left button drags on the monitor; a middle or right drag leaves the mask alone.
+const LEFT: egui::PointerButton = egui::PointerButton::Primary;
+
/// Clip pixels → screen points for the clip's current Motion and the monitor picture rect.
fn clip_to_screen(app: &FilmcraftApp, it: &TrackItem, mt: Tick, pic: Rect, frame: (u32, u32)) -> Option<Affine> {
let seq = app.session.active_sequence()?;
@@ -293,11 +296,11 @@ pub fn monitor_overlay(app: &mut FilmcraftApp, ui: &mut egui::Ui, pic: Rect, fra
let body = ui.interact(bb, egui::Id::new("mask-body"), Sense::click_and_drag());
app.auto.add("program.mask.body", bb, &m.name);
let ptr_in = |p: Option<Pos2>| p.is_some_and(|p| inside(&flat, to_clip.apply(Vec2::new(p.x as f64, p.y as f64))));
- if body.drag_started() {
+ if body.drag_started_by(LEFT) {
let ok = ptr_in(body.interact_pointer_pos());
ui.data_mut(|d| d.insert_temp(gesture_id.with("body"), ok));
}
- if body.dragged() && ui.data(|d| d.get_temp::<bool>(gesture_id.with("body"))).unwrap_or(false) && body.drag_delta() != egui::Vec2::ZERO {
+ if body.dragged_by(LEFT) && ui.data(|d| d.get_temp::<bool>(gesture_id.with("body"))).unwrap_or(false) && body.drag_delta() != egui::Vec2::ZERO {
actions.push(("masks.translate".into(), with(json!({"delta": clip_delta(body.drag_delta()), "merge": format!("body-{gesture}")}))));
}
if body.clicked() && !ptr_in(body.interact_pointer_pos()) {
@@ -335,7 +338,7 @@ pub fn monitor_overlay(app: &mut FilmcraftApp, ui: &mut egui::Ui, pic: Rect, fra
}
let r = ui.interact(hr.expand(3.0), egui::Id::new(("mask-handle", which)), Sense::drag());
app.auto.add(&format!("program.mask.{which}"), hr, if which == "feather" { "Mask Feather" } else { "Mask Expansion" });
- if r.dragged() && r.drag_delta() != egui::Vec2::ZERO {
+ if r.dragged_by(LEFT) && r.drag_delta() != egui::Vec2::ZERO {
let d = clip_delta(r.drag_delta());
let along = d[0] * n.x + d[1] * n.y;
let (key, v) = if which == "feather" { ("feather", (feather + 2.0 * along).max(0.0)) } else { ("expansion", expansion + along) };
@@ -364,7 +367,7 @@ pub fn monitor_overlay(app: &mut FilmcraftApp, ui: &mut egui::Ui, pic: Rect, fra
let hr = Rect::from_center_size(h, vec2(8.0, 8.0));
let r = ui.interact(hr.expand(2.0), egui::Id::new(("mask-tan", which, i)), Sense::drag());
app.auto.add(&format!("program.mask.{which}.{i}"), hr, "Bezier handle");
- if r.dragged() && r.drag_delta() != egui::Vec2::ZERO {
+ if r.dragged_by(LEFT) && r.drag_delta() != egui::Vec2::ZERO {
actions.push((
"masks.moveVertex".into(),
with(json!({"vertex": i, "handle": which, "delta": clip_delta(r.drag_delta()), "breakHandles": alt, "merge": format!("tan-{gesture}")})),
@@ -384,10 +387,10 @@ pub fn monitor_overlay(app: &mut FilmcraftApp, ui: &mut egui::Ui, pic: Rect, fra
tl!("Drag: move · Alt-click: smooth/corner · Ctrl-click: delete")
});
app.auto.add(&format!("program.mask.vertex.{i}"), vr, "Mask vertex");
- if r.drag_started() {
+ if r.drag_started_by(LEFT) {
ui.data_mut(|d| d.insert_temp(sel_v_id, i));
}
- if r.dragged() && r.drag_delta() != egui::Vec2::ZERO {
+ if r.dragged_by(LEFT) && r.drag_delta() != egui::Vec2::ZERO {
actions.push(("masks.moveVertex".into(), with(json!({"vertex": i, "delta": clip_delta(r.drag_delta()), "merge": format!("vertex-{gesture}")}))));
}
if r.clicked() {
@@ -588,7 +591,7 @@ fn pen_overlay(app: &mut FilmcraftApp, ui: &mut egui::Ui, pic: Rect, frame: (u32
_ => p,
};
let mut commit = false;
- let pressed = resp.drag_started() || (resp.clicked() && !ui.data(|m| m.get_temp::<bool>(egui::Id::new("mask-pen-placed")).unwrap_or(false)));
+ let pressed = resp.drag_started_by(LEFT) || (resp.clicked() && !ui.data(|m| m.get_temp::<bool>(egui::Id::new("mask-pen-placed")).unwrap_or(false)));
if pressed && let Some(p) = resp.interact_pointer_pos() {
let near_first = d.points.first().is_some_and(|f| (sp(&to_screen, Vec2::new(f[0], f[1])) - p).length() < 8.0);
if d.points.len() >= 3 && near_first {
@@ -596,13 +599,13 @@ fn pen_overlay(app: &mut FilmcraftApp, ui: &mut egui::Ui, pic: Rect, frame: (u32
} else {
let c = to_c(snap(d.points.last(), p));
d.points.push([c.x, c.y, 0.0, 0.0]);
- ui.data_mut(|m| m.insert_temp(egui::Id::new("mask-pen-placed"), resp.drag_started()));
+ ui.data_mut(|m| m.insert_temp(egui::Id::new("mask-pen-placed"), resp.drag_started_by(LEFT)));
}
}
if resp.clicked() || resp.drag_stopped() {
ui.data_mut(|m| m.insert_temp(egui::Id::new("mask-pen-placed"), false));
}
- if resp.dragged()
+ if resp.dragged_by(LEFT)
&& !commit
&& let (Some(p), Some(last)) = (resp.interact_pointer_pos(), d.points.last_mut())
{
diff --git a/crates/ui-egui/src/panels/monitor_view.rs b/crates/ui-egui/src/panels/monitor_view.rs
index de721b94f..2ef5f030c 100644
--- a/crates/ui-egui/src/panels/monitor_view.rs
+++ b/crates/ui-egui/src/panels/monitor_view.rs
@@ -513,7 +513,8 @@ pub fn rulers(app: &mut FilmcraftApp, ui: &mut egui::Ui, w: Which, top: Rect, le
if resp.hovered() {
ui.ctx().set_cursor_icon(if vertical { egui::CursorIcon::ResizeHorizontal } else { egui::CursorIcon::ResizeVertical });
}
- if resp.drag_started() {
+ // the left button only, as for the other things dragged on the monitor
+ if resp.drag_started_by(egui::PointerButton::Primary) {
ui.data_mut(|d| d.insert_temp(drag_id, NewGuide { vertical }));
}
let Some(ng) = ui.data(|d| d.get_temp::<NewGuide>(drag_id)).filter(|g| g.vertical == vertical) else { continue };
@@ -563,12 +564,13 @@ pub fn guides(app: &mut FilmcraftApp, ui: &mut egui::Ui, w: Which, area: Rect, p
if resp.hovered() || resp.dragged() {
ui.ctx().set_cursor_icon(if g.vertical { egui::CursorIcon::ResizeHorizontal } else { egui::CursorIcon::ResizeVertical });
}
+ let left = egui::PointerButton::Primary;
// egui ends a drag on Escape: that stop puts the guide back where it was (#580)
let before_id = egui::Id::new((pfx, "guide-before-drag", i));
- if resp.drag_started() {
+ if resp.drag_started_by(left) {
ui.data_mut(|d| d.insert_temp(before_id, g.position));
}
- if resp.drag_stopped() {
+ if resp.drag_stopped_by(left) {
let before = ui.data_mut(|d| d.remove_temp::<f64>(before_id));
if ui.input(|i| i.key_pressed(egui::Key::Escape)) {
if let (Some(p0), Some(guide)) = (before, view_mut(app, w).guides.get_mut(i)) {
@@ -578,7 +580,7 @@ pub fn guides(app: &mut FilmcraftApp, ui: &mut egui::Ui, w: Which, area: Rect, p
}
}
if let Some(pos) = resp.interact_pointer_pos()
- && (resp.dragged() || resp.drag_stopped())
+ && (resp.dragged_by(left) || resp.drag_stopped_by(left))
{
if !area.contains(pos) {
// outside the picture area: dropping here removes the guide
diff --git a/crates/ui-egui/src/panels/transform_handles.rs b/crates/ui-egui/src/panels/transform_handles.rs
index 4d713aa93..6470544cf 100644
--- a/crates/ui-egui/src/panels/transform_handles.rs
+++ b/crates/ui-egui/src/panels/transform_handles.rs
@@ -5,7 +5,7 @@
//!
//! Dragging inside the box changes Position. A handle changes Scale about the anchor point; with
//! Uniform Scale off a side handle changes only the width and a top or bottom handle only the
-//! height. Dragging just outside a corner changes Rotation. The anchor point moves without moving
+//! height. Dragging just outside the box changes Rotation. The anchor point moves without moving
//! the picture: Position changes by the same amount. The values go through `effects.setParam` at
//! the playhead while the drag goes on, as dragging them in Effect Controls does, so a property
//! with its stopwatch on gets a keyframe there, and one drag is one undo step.
@@ -21,7 +21,6 @@ use filmcraft_time::Tick;
use serde_json::{Value, json};
use crate::FilmcraftApp;
-use crate::icons::{self, Icon};
use crate::panels::graphics::{frame_to_screen, handle_points, unscale};
use crate::state::Tool;
@@ -29,13 +28,18 @@ use crate::state::Tool;
/// beyond the drawn squares, so the small handles stay easy to take hold of.
const GRAB: f32 = 8.0;
/// The drawn handles, a little smaller than the graphic layers' (7 and 5 points) for precision:
-/// the side of a corner square and of an edge square, and the anchor point's circle radius and
-/// cross arm.
+/// the side of a corner square and of an edge square.
const CORNER: f32 = 5.0;
const EDGE: f32 = 4.0;
-const ANCHOR_RADIUS: f32 = 3.0;
-const ANCHOR_ARM: f32 = 5.0;
-/// How far from a corner, outside the box, the pointer rotates the picture.
+/// The anchor point, Premiere's ⊕: a circle of this radius with the cross inside it, in thin lines
+/// whose crossing marks the exact point; and how close the pointer must be to take hold of it.
+const ANCHOR_RADIUS: f32 = 7.0;
+const ANCHOR_ARM: f32 = ANCHOR_RADIUS;
+const ANCHOR_GRAB: f32 = 11.0;
+/// The small anchor point beside the pointer while it is over the anchor point.
+const BADGE_RADIUS: f32 = 3.0;
+const BADGE_ARM: f32 = 5.0;
+/// How far outside the box (from its edges and corners) the pointer rotates the picture.
const ROTATE_REACH: f32 = 24.0;
/// The `merge` key of a drag's changes: one undo step, whichever parameters the drag changes.
const MERGE: &str = "programTransform";
@@ -183,7 +187,7 @@ fn selected_placement(app: &FilmcraftApp, pic: Rect, frame: (u32, u32)) -> Optio
}
fn grab_at(pl: &Placement, p: Pos2) -> Option<Grab> {
- if (pl.anchor_at - p).length() <= GRAB {
+ if (pl.anchor_at - p).length() <= ANCHOR_GRAB {
return Some(Grab::Anchor);
}
if let Some(n) = handle_points(&pl.quad).iter().position(|h| (*h - p).length() <= GRAB) {
@@ -192,7 +196,18 @@ fn grab_at(pl: &Placement, p: Pos2) -> Option<Grab> {
if inside(&pl.quad, p) {
return Some(Grab::Move);
}
- pl.quad.iter().any(|c| (*c - p).length() <= ROTATE_REACH).then_some(Grab::Rotate)
+ // anywhere just outside the box rotates, beside an edge as beside a corner, as in Premiere
+ let n = pl.quad.len();
+ let near = (0..n).filter_map(|i| Some(seg_dist(p, *pl.quad.get(i)?, *pl.quad.get((i + 1) % n)?))).any(|d| d <= ROTATE_REACH);
+ near.then_some(Grab::Rotate)
+}
+
+/// The distance from `p` to the segment `a`–`b`.
+fn seg_dist(p: Pos2, a: Pos2, b: Pos2) -> f32 {
+ let ab = b - a;
+ let l2 = ab.length_sq();
+ let t = if l2 > 0.0 { ((p - a).dot(ab) / l2).clamp(0.0, 1.0) } else { 0.0 };
+ (p - (a + ab * t)).length()
}
/// The scale factors (width, height) dragging handle `n` from `start` to `cur` gives: the
@@ -292,26 +307,58 @@ fn draw(app: &mut FilmcraftApp, ui: &egui::Ui, pl: &Placement, pic: Rect, name:
painter.circle_stroke(a, ANCHOR_RADIUS, Stroke::new(1.0, accent));
painter.line_segment([a - vec2(ANCHOR_ARM, 0.0), a + vec2(ANCHOR_ARM, 0.0)], Stroke::new(1.0, accent));
painter.line_segment([a - vec2(0.0, ANCHOR_ARM), a + vec2(0.0, ANCHOR_ARM)], Stroke::new(1.0, accent));
- app.auto.add("program.transform.anchor", Rect::from_center_size(a, grab), "anchor point");
+ app.auto.add("program.transform.anchor", Rect::from_center_size(a, vec2(ANCHOR_GRAB, ANCHOR_GRAB) * std::f32::consts::SQRT_2), "anchor point");
}
/// The pointer for what it would take hold of at `at` (or has hold of). There is no system
/// cursor for rotating, so a code-drawn one replaces it there.
fn cursor(ui: &egui::Ui, pl: &Placement, grab: Grab, at: Pos2, pic: Rect) {
let icon = match grab {
- Grab::Move | Grab::Anchor => CursorIcon::Move,
+ Grab::Move => CursorIcon::Move,
+ // the plain arrow with a small anchor point beside it, as Premiere shows, so it's clear the
+ // anchor point is under the pointer and not the picture
+ Grab::Anchor => {
+ let painter = ui.painter().with_clip_rect(pic.expand(24.0));
+ let b = at + vec2(14.0, 16.0);
+ for (col, w) in [(Color32::BLACK, 3.0), (Color32::WHITE, 1.0)] {
+ painter.circle_stroke(b, BADGE_RADIUS, Stroke::new(w, col));
+ painter.line_segment([b - vec2(BADGE_ARM, 0.0), b + vec2(BADGE_ARM, 0.0)], Stroke::new(w, col));
+ painter.line_segment([b - vec2(0.0, BADGE_ARM), b + vec2(0.0, BADGE_ARM)], Stroke::new(w, col));
+ }
+ CursorIcon::Default
+ }
Grab::Handle(n) => handle_points(&pl.quad).get(n).map_or(CursorIcon::Move, |h| resize_cursor(*h - centre(&pl.quad))),
Grab::Rotate => {
- let painter = ui.painter().with_clip_rect(pic.expand(16.0));
- let r = Rect::from_center_size(at, vec2(16.0, 16.0));
- icons::paint(&painter, r.translate(vec2(1.0, 1.0)), Icon::Reset, Color32::BLACK);
- icons::paint(&painter, r, Icon::Reset, Color32::WHITE);
+ let out = (at - centre(&pl.quad)).normalized();
+ rotate_pointer(&ui.painter().with_clip_rect(pic.expand(ROTATE_REACH + 16.0)), at, if out.is_finite() { out } else { vec2(0.0, -1.0) });
CursorIcon::None
}
};
ui.ctx().set_cursor_icon(icon);
}
+/// Premiere's rotate pointer: a curved double arrow at `at`, bulging along `out` (away from the
+/// box), so it turns to face outward wherever the pointer is around the box.
+fn rotate_pointer(painter: &egui::Painter, at: Pos2, out: egui::Vec2) {
+ const R: f32 = 9.0;
+ const SWEEP: f32 = 1.6;
+ let c = at - out * R;
+ let base = out.y.atan2(out.x);
+ let on_arc = |a: f32| c + vec2(a.cos(), a.sin()) * R;
+ let arc: Vec<Pos2> = (0..=12).map(|i| on_arc(base + (i as f32 / 12.0 - 0.5) * SWEEP)).collect();
+ // an arrowhead at each end, pointing on along the arc
+ let head = |a: f32, dir: f32| {
+ let (tip, along, across) = (on_arc(a), vec2(-a.sin(), a.cos()) * dir, vec2(a.cos(), a.sin()));
+ vec![tip + along * 4.5, tip - across * 3.5, tip + across * 3.5]
+ };
+ let heads = [head(base + SWEEP / 2.0, 1.0), head(base - SWEEP / 2.0, -1.0)];
+ painter.add(egui::Shape::line(arc.clone(), Stroke::new(3.5, Color32::BLACK)));
+ painter.add(egui::Shape::line(arc, Stroke::new(1.5, Color32::WHITE)));
+ for h in heads {
+ painter.add(egui::Shape::convex_polygon(h, Color32::WHITE, Stroke::new(1.0, Color32::BLACK)));
+ }
+}
+
/// The top-most clip at the playhead whose picture is under `p`.
fn clip_under(app: &FilmcraftApp, pic: Rect, frame: (u32, u32), p: Pos2) -> Option<ClipId> {
let seq = app.session.active_sequence()?;
@@ -337,8 +384,11 @@ pub fn monitor_overlay(app: &mut FilmcraftApp, ui: &mut egui::Ui, pic: Rect, fra
let double = ui.input(|i| i.pointer.button_double_clicked(egui::PointerButton::Primary));
if let Some((sel, def, pl)) = selected_placement(app, pic, frame) {
draw(app, ui, &pl, pic, def.name);
- let resp = ui.interact(Rect::from_points(&pl.quad).expand(ROTATE_REACH), id, Sense::click_and_drag());
- if resp.drag_started() {
+ // (as far again beyond the rotate zone, where a click lets go of the box)
+ let resp = ui.interact(Rect::from_points(&pl.quad).expand(ROTATE_REACH * 2.0), id, Sense::click_and_drag());
+ // the left button only: a middle or right drag leaves the picture alone
+ let left = egui::PointerButton::Primary;
+ if resp.drag_started_by(left) {
// where the button went down (a drag starts only after the pointer has moved a little)
let p = ui.input(|i| i.pointer.press_origin()).or(resp.interact_pointer_pos()).unwrap_or(pl.anchor_at);
match grab_at(&pl, p) {
@@ -351,7 +401,7 @@ pub fn monitor_overlay(app: &mut FilmcraftApp, ui: &mut egui::Ui, pic: Rect, fra
}
let drag: Option<Drag> = ui.data(|d| d.get_temp(drag_id)).filter(|d: &Drag| d.sel == sel);
if let Some(mut d) = drag
- && resp.dragged()
+ && resp.dragged_by(left)
{
let cur = resp.interact_pointer_pos().unwrap_or(d.start);
let off = cur - d.from.anchor_at;
@@ -361,7 +411,7 @@ pub fn monitor_overlay(app: &mut FilmcraftApp, ui: &mut egui::Ui, pic: Rect, fra
d.angle = a;
ui.data_mut(|m| m.insert_temp(drag_id, d));
}
- if resp.drag_started() || resp.drag_delta() != egui::Vec2::ZERO {
+ if resp.drag_started_by(left) || resp.drag_delta() != egui::Vec2::ZERO {
for (param, value) in changes(&d, def.id, cur) {
actions.push(("effects.setParam".into(), json!({"clip": sel.0.0, "effect": sel.1, "param": param, "value": value, "merge": MERGE})));
}
diff --git a/crates/ui-egui/tests/transform_handles_ui.rs b/crates/ui-egui/tests/transform_handles_ui.rs
index a15cb8d97..c3c772a57 100644
--- a/crates/ui-egui/tests/transform_handles_ui.rs
+++ b/crates/ui-egui/tests/transform_handles_ui.rs
@@ -93,6 +93,19 @@ impl Driver {
let at = self.center(id);
self.drag_from(at, dx, dy);
}
+ /// A drag of 48 × 24 points with `button` (the control channel's `ui.drag` uses the left one).
+ fn drag_with(&mut self, (x, y): (f64, f64), button: egui::PointerButton) {
+ let from = egui::pos2(x as f32, y as f32);
+ let press = |pos, pressed| egui::Event::PointerButton { pos, button, pressed, modifiers: Default::default() };
+ let mut events = vec![egui::Event::PointerMoved(from), press(from, true)];
+ events.extend((1..=6).map(|k| egui::Event::PointerMoved(from + egui::vec2(8.0 * k as f32, 4.0 * k as f32))));
+ events.push(press(from + egui::vec2(48.0, 24.0), false));
+ for e in events {
+ self.harness.input_mut().events.push(e);
+ self.frames(1);
+ }
+ self.frames(3);
+ }
fn undo_len(&mut self) -> usize {
self.exec("history.list", json!({}))["undo"].as_array().unwrap().len()
}
@@ -235,9 +248,9 @@ fn motion_handles_move_scale_rotate_and_move_the_anchor() {
assert!(d.num(clip, "motion", "scale_width") > w + 3.0);
d.shot("transform-motion-non-uniform");
- // a click beside the box lets go of it
+ // a click beside the box, beyond its rotate zone, lets go of it
let b = d.rect("program.transform.box");
- d.ok("ui.click", json!({"x": b[0] - 20.0, "y": b[1] + b[3] / 2.0}));
+ d.ok("ui.click", json!({"x": b[0] - 40.0, "y": b[1] + b[3] / 2.0}));
d.frames(2);
assert_eq!(d.selected_effect(), Value::Null);
assert!(d.find("program.transform.box").is_none());
@@ -362,3 +375,82 @@ fn transform_effect_handles_and_double_click_selection() {
.unwrap();
assert_eq!(d.selected_effect(), json!({"clip": under, "effect": "motion", "instance": 0}));
}
+
+/// Only the left button takes hold of the box: a middle or right drag leaves the picture alone.
+#[test]
+fn only_the_left_button_drags_the_handles() {
+ let mut d = Driver::demo();
+ let (clip, _) = d.first_clip();
+ d.exec("effects.setParam", json!({"clip": clip, "effect": "motion", "param": "scale", "value": 50.0}));
+ d.click("effectControls.effect.motion");
+ let (p0, undo) = (d.point(clip, "motion", "position"), d.undo_len());
+ let b = d.rect("program.transform.box");
+ let from = (b[0] + b[2] * 0.3, b[1] + b[3] * 0.3);
+ for button in [egui::PointerButton::Middle, egui::PointerButton::Secondary] {
+ d.drag_with(from, button);
+ assert_eq!(d.point(clip, "motion", "position"), p0, "{button:?} drag moved the picture");
+ assert_eq!(d.undo_len(), undo, "{button:?} drag made an undo step");
+ }
+ d.drag_from(from, 40.0, 20.0);
+ assert_ne!(d.point(clip, "motion", "position"), p0, "the left button still moves it");
+}
+
+/// The other things dragged on the Program monitor take the left button only too: a guide, a
+/// mask's body and vertices, and a graphic layer stay put under a middle or right drag.
+#[test]
+fn guides_masks_and_graphics_take_the_left_button_only() {
+ let mut d = Driver::demo();
+ let (clip, _) = d.first_clip();
+ let others = [egui::PointerButton::Middle, egui::PointerButton::Secondary];
+ let project = |d: &Driver| d.harness.state().session.project.to_json();
+ // a guide
+ d.ok("ui.menu.invoke", json!({"id": "view.addGuide", "params": {"orientation": "vertical", "position": 700}}));
+ d.frames(2);
+ let g = d.rect("program.guide.0");
+ for b in others {
+ d.drag_with((g[0] + g[2] / 2.0, g[1] + g[3] * 0.2), b);
+ assert_eq!(d.rect("program.guide.0"), g, "a {b:?} drag moved the guide");
+ }
+ // a mask
+ d.exec("effects.apply", json!({"clips": [clip], "effect": "gaussian_blur"}));
+ let fx = {
+ let s = &d.harness.state().session;
+ s.active_sequence().unwrap().find_item(ClipId(clip)).unwrap().1.effects.iter().position(|e| e.effect == "gaussian_blur").unwrap()
+ };
+ d.exec("masks.add", json!({"clip": clip, "effect": fx, "shape": "ellipse"}));
+ d.exec("masks.select", json!({"clip": clip, "effect": fx, "mask": 0}));
+ d.frames(3);
+ let before = project(&d);
+ for id in ["program.mask.body", "program.mask.vertex.0"] {
+ for b in others {
+ let at = d.center(id);
+ d.drag_with(at, b);
+ assert_eq!(project(&d), before, "a {b:?} drag on {id} changed the mask");
+ }
+ }
+ // a graphic layer
+ d.exec("masks.select", json!({"none": true}));
+ let gclip = d.exec("graphics.newText", json!({"text": "Title", "position": [600, 500], "size": 120}))["clip"].as_u64().unwrap();
+ d.frames(3);
+ let before = project(&d);
+ let at = d.center(&format!("program.layer.{gclip}.0"));
+ for b in others {
+ d.drag_with(at, b);
+ assert_eq!(project(&d), before, "a {b:?} drag moved the layer");
+ }
+ d.drag_from(at, 40.0, 20.0);
+ assert_ne!(project(&d), before, "the left button still moves the layer");
+}
+/// Anywhere just outside the box rotates, beside the middle of an edge as beside a corner.
+#[test]
+fn rotating_from_beside_an_edge() {
+ let mut d = Driver::demo();
+ let (clip, _) = d.first_clip();
+ d.exec("effects.setParam", json!({"clip": clip, "effect": "motion", "param": "scale", "value": 50.0}));
+ d.click("effectControls.effect.motion");
+ let left = d.rect("program.transform.handle.7");
+ let (x, y) = (left[0] + left[2] / 2.0 - 14.0, left[1] + left[3] / 2.0);
+ d.drag_from((x, y), 0.0, -60.0);
+ let r = d.num(clip, "motion", "rotation");
+ assert!(r > 5.0, "up from beside the left edge turns clockwise: {r}");
+}