M13.14: puppet pin editing — click / Shift-click selects pins (puppet.selectPins), a drag from empty canvas or Alt-drag marquee-selects them, Select All with a pin selected takes every pin of that kind, Delete removes the selected pins instead of their layer; Advanced and Bend pins rotate by their ring and scale by its square (Shift: 15° / 5 % steps, one undo step per drag); ⌘/Ctrl-dragging one of several selected pins records them all; pins in their kind's colour, larger under the pointer; pushpin icons for the five pin tools
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
//! Puppet tools in the Composition viewer: the deformed mesh and pins of the selected layers'
|
||||
//! Puppet effect, click to add a pin (`puppet.addPin`), drag a pin to move it
|
||||
//! (`puppet.movePin`, merged into one undo step per drag).
|
||||
//! Puppet effect, click to add a pin (`puppet.addPin`), click / Shift-click a pin to select it
|
||||
//! (`puppet.selectPins`), drag a pin to move it (`puppet.movePin`), and drag an Advanced or Bend
|
||||
//! pin's ring to rotate it or its square to scale it (`puppet.setPin`); each drag is one undo step.
|
||||
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -17,6 +18,9 @@ use crate::EffectcraftApp;
|
||||
/// Deformed meshes of a layer's Puppet effect: (mesh uid, mesh, deformed vertices, pins).
|
||||
pub type Overlay = Arc<Vec<(u64, Arc<Mesh>, Vec<[f64; 2]>, Vec<Pin>)>>;
|
||||
|
||||
/// Rotation ring radius (screen points) of Advanced and Bend pins.
|
||||
pub const RING: f32 = 9.0;
|
||||
|
||||
/// A pin drawn this frame.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct PinHit {
|
||||
@@ -24,6 +28,36 @@ pub struct PinHit {
|
||||
pub pin: u64,
|
||||
pub kind: PinKind,
|
||||
pub pos: Pos2,
|
||||
/// Rotation (°) and scale (1 = 100 %) now, for Advanced and Bend pins.
|
||||
pub rotation: f64,
|
||||
pub scale: f64,
|
||||
/// The scale handle on the ring (Advanced and Bend pins).
|
||||
pub handle: Option<Pos2>,
|
||||
}
|
||||
|
||||
/// The part of a pin under the pointer.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
pub enum PinPart {
|
||||
/// The pin itself (drag moves Position, Advanced, Starch and Overlap pins).
|
||||
Center,
|
||||
/// The rotation ring of an Advanced or Bend pin.
|
||||
Ring,
|
||||
/// The scale handle on that ring.
|
||||
Scale,
|
||||
}
|
||||
|
||||
/// The pin part under `p`, topmost pin first.
|
||||
pub fn hit(hits: &[PinHit], p: Pos2) -> Option<(PinHit, PinPart)> {
|
||||
hits.iter().rev().find_map(|h| {
|
||||
let d = h.pos.distance(p);
|
||||
match h.handle {
|
||||
Some(s) if s.distance(p) < 5.0 => Some((*h, PinPart::Scale)),
|
||||
Some(_) if d < 6.0 => Some((*h, PinPart::Center)),
|
||||
Some(_) if (d - RING).abs() < 4.0 => Some((*h, PinPart::Ring)),
|
||||
None if d < 8.0 => Some((*h, PinPart::Center)),
|
||||
_ => None,
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
@@ -65,8 +99,31 @@ pub fn pin_position(mesh: &Mesh, def: &[[f64; 2]], p: &Pin) -> [f64; 2] {
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw the mesh (when `show_mesh`) and pins of `layer`; returns pin hit targets.
|
||||
pub fn draw(painter: &egui::Painter, map: &ViewerMap, ectx: &EvalCtx, layer: &Layer, ov: &Overlay, show_mesh: bool, selected: &[u64]) -> Vec<PinHit> {
|
||||
/// Pin colours by kind: Position yellow, Starch red, Overlap blue, Advanced blue-green, Bend
|
||||
/// orange-brown.
|
||||
pub fn pin_color(kind: PinKind) -> Color32 {
|
||||
match kind {
|
||||
PinKind::Position => Color32::from_rgb(0xf0, 0xd0, 0x40),
|
||||
PinKind::Starch => Color32::from_rgb(0xe0, 0x50, 0x50),
|
||||
PinKind::Overlap => Color32::from_rgb(0x40, 0x90, 0xf0),
|
||||
PinKind::Advanced => Color32::from_rgb(0x30, 0xc8, 0xb4),
|
||||
PinKind::Bend => Color32::from_rgb(0xc8, 0x82, 0x3c),
|
||||
}
|
||||
}
|
||||
|
||||
/// Draw the mesh (when `show_mesh`) and pins of `layer` (the pin under `hover` is drawn larger);
|
||||
/// returns pin hit targets.
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn draw(
|
||||
painter: &egui::Painter,
|
||||
map: &ViewerMap,
|
||||
ectx: &EvalCtx,
|
||||
layer: &Layer,
|
||||
ov: &Overlay,
|
||||
show_mesh: bool,
|
||||
selected: &[u64],
|
||||
hover: Option<Pos2>,
|
||||
) -> Vec<PinHit> {
|
||||
let (m, _) = l2c(ectx, layer);
|
||||
let scr = |q: [f64; 2]| {
|
||||
let c = m.apply(gv2(q[0], q[1]));
|
||||
@@ -84,25 +141,39 @@ pub fn draw(painter: &egui::Painter, map: &ViewerMap, ectx: &EvalCtx, layer: &La
|
||||
}
|
||||
}
|
||||
for pn in pins {
|
||||
let pos = scr(pin_position(mesh, def, pn));
|
||||
let at = pin_position(mesh, def, pn);
|
||||
let pos = scr(at);
|
||||
let sel = selected.contains(&pn.uid);
|
||||
let col = match pn.kind {
|
||||
PinKind::Starch => Color32::from_rgb(0xe0, 0x50, 0x50),
|
||||
PinKind::Overlap => Color32::from_rgb(0x40, 0x90, 0xf0),
|
||||
PinKind::Bend => Color32::from_rgb(0xf0, 0x90, 0x30),
|
||||
_ => Color32::from_rgb(0xf0, 0xd0, 0x40),
|
||||
};
|
||||
let col = pin_color(pn.kind);
|
||||
if matches!(pn.kind, PinKind::Starch | PinKind::Overlap) {
|
||||
// Extent ring (layer pixels → screen).
|
||||
let r = (scr([pn.rest[0] + pn.extent, pn.rest[1]]) - scr(pn.rest)).length();
|
||||
painter.circle_stroke(pos, r.max(2.0), Stroke::new(1.0, col.gamma_multiply(0.6)));
|
||||
}
|
||||
// Advanced and Bend pins: the rotation ring with a square scale handle at the pin's
|
||||
// rotation (the layer's own orientation on screen).
|
||||
let mut handle = None;
|
||||
if matches!(pn.kind, PinKind::Bend | PinKind::Advanced) {
|
||||
painter.circle_stroke(pos, 9.0, Stroke::new(1.5, col));
|
||||
painter.circle_stroke(pos, RING, Stroke::new(1.5, col));
|
||||
let (s, c) = pn.rotation.to_radians().sin_cos();
|
||||
let dir = (scr([at[0] + c, at[1] + s]) - pos).normalized();
|
||||
if dir.x.is_finite() && dir.y.is_finite() {
|
||||
let hp = pos + dir * RING;
|
||||
painter.rect_filled(egui::Rect::from_center_size(hp, egui::vec2(5.0, 5.0)), 0.0, col);
|
||||
painter.rect_stroke(
|
||||
egui::Rect::from_center_size(hp, egui::vec2(5.0, 5.0)),
|
||||
0.0,
|
||||
Stroke::new(1.0, Color32::BLACK),
|
||||
egui::StrokeKind::Outside,
|
||||
);
|
||||
handle = Some(hp);
|
||||
}
|
||||
}
|
||||
painter.circle_filled(pos, if sel { 5.5 } else { 4.5 }, if sel { col } else { col.gamma_multiply(0.85) });
|
||||
painter.circle_stroke(pos, if sel { 5.5 } else { 4.5 }, Stroke::new(1.0, Color32::BLACK));
|
||||
hits.push(PinHit { layer: layer.id, pin: pn.uid, kind: pn.kind, pos });
|
||||
// Pins grow under the pointer.
|
||||
let r = if sel { 5.5 } else { 4.5 } + if hover.is_some_and(|h| h.distance(pos) < 8.0) { 1.5 } else { 0.0 };
|
||||
painter.circle_filled(pos, r, if sel { col } else { col.gamma_multiply(0.85) });
|
||||
painter.circle_stroke(pos, r, Stroke::new(1.0, Color32::BLACK));
|
||||
hits.push(PinHit { layer: layer.id, pin: pn.uid, kind: pn.kind, pos, rotation: pn.rotation, scale: pn.scale, handle });
|
||||
}
|
||||
}
|
||||
hits
|
||||
|
||||
Reference in New Issue
Block a user