G2: Fix effect input semantics and control activation
This commit is contained in:
@@ -33,6 +33,21 @@ type Actions = Vec<(String, serde_json::Value)>;
|
||||
const ROW: f32 = 24.0;
|
||||
const DIAL_ROW: f32 = 64.0;
|
||||
|
||||
/// Selecting any descendant activates its owning effect without replacing the property
|
||||
/// selection used by keyframe editing, copy and delete.
|
||||
fn effect_active(g: &PropGroup, layer: effectcraft_engine::project::LayerId, selected: &[(effectcraft_engine::project::LayerId, u64)]) -> bool {
|
||||
fn contains(g: &PropGroup, uid: u64, depth: usize) -> bool {
|
||||
if g.uid == uid {
|
||||
return true;
|
||||
}
|
||||
if depth >= 16 {
|
||||
return false;
|
||||
}
|
||||
g.children.iter().any(|n| n.uid() == uid || matches!(n, Node::Group(child) if contains(child, uid, depth + 1)))
|
||||
}
|
||||
selected.iter().any(|(l, uid)| *l == layer && contains(g, *uid, 0))
|
||||
}
|
||||
|
||||
fn selected_layer(app: &EffectcraftApp) -> Option<Layer> {
|
||||
let comp = app.session.active_comp()?;
|
||||
let id = app.session.state.selected_layers.first()?;
|
||||
@@ -159,6 +174,10 @@ fn prop_row(
|
||||
let t = app.tokens;
|
||||
let cy = r.center().y;
|
||||
let uid = prop.uid;
|
||||
if ui.input(|i| i.pointer.primary_pressed()) && ui.rect_contains_pointer(r) {
|
||||
let add = ui.input(|i| i.modifiers.shift || i.modifiers.command);
|
||||
actions.push(("prop.select".into(), json!({"layer": layer.id.0, "prop": uid, "add": add})));
|
||||
}
|
||||
let swr = Rect::from_center_size(pos2(r.min.x + indent, cy), vec2(14.0, 14.0));
|
||||
if !prop.static_only && !matches!(prop.ui, ParamUi::Hidden) {
|
||||
let resp = ui.interact(swr, egui::Id::new(("ec-sw", uid)), Sense::click());
|
||||
@@ -203,6 +222,8 @@ fn prop_row(
|
||||
let name_clip =
|
||||
Rect::from_min_max(pos2(swr.max.x + 6.0, r.min.y), pos2(((r.min.x + r.width() * 0.48).max(swr.max.x + 124.0) - 4.0).min(vx - 6.0), r.max.y));
|
||||
p.with_clip_rect(name_clip.intersect(p.clip_rect())).text(pos2(swr.max.x + 6.0, cy), Align2::LEFT_CENTER, &prop.name, Tokens::ui(12.0), t.text);
|
||||
ui.interact(name_clip, egui::Id::new(("ec-prop-name", uid)), Sense::click());
|
||||
app.auto.add(&format!("effectControls.prop.{uid}.name"), name_clip, &prop.name);
|
||||
let merge = format!("ec-{uid}");
|
||||
let set =
|
||||
|actions: &mut Actions, v: serde_json::Value| actions.push(("prop.set".into(), json!({"layer": layer.id.0, "prop": uid, "value": v, "merge": merge})));
|
||||
@@ -954,7 +975,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
// Clicking empty space deselects the effects.
|
||||
let bg = ui.interact(body, egui::Id::new("ec-bg"), Sense::click());
|
||||
if bg.clicked() {
|
||||
app.session.state.selected_props.retain(|(l, u)| !(*l == layer.id && fx.iter().any(|g| g.uid == *u)));
|
||||
app.session.state.selected_props.retain(|(l, u)| !(*l == layer.id && fx.iter().any(|g| effect_active(g, layer.id, &[(*l, *u)]))));
|
||||
}
|
||||
let has_clip = !app.session.state.effect_clipboard.is_empty();
|
||||
let drag_id = egui::Id::new("ec-drag-effect");
|
||||
@@ -968,7 +989,8 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
y += 26.0;
|
||||
let open = !app.ui.fx_closed.contains(&g.uid);
|
||||
let selected = app.session.state.selected_props.iter().any(|(l, u)| *l == layer.id && *u == g.uid);
|
||||
bp.rect_filled(r, 0.0, if selected { Color32::from_rgb(0x2f, 0x3a, 0x52) } else { Color32::from_rgb(0x2a, 0x2a, 0x2a) });
|
||||
let active = effect_active(g, layer.id, &app.session.state.selected_props);
|
||||
bp.rect_filled(r, 0.0, if active { Color32::from_rgb(0x2f, 0x3a, 0x52) } else { Color32::from_rgb(0x2a, 0x2a, 0x2a) });
|
||||
let fxr = Rect::from_center_size(pos2(r.min.x + 14.0, r.center().y), vec2(16.0, 16.0));
|
||||
if widgets::icon_toggle(ui, fxr, Icon::Fx, g.enabled, &t, egui::Id::new(("ec-fx", g.uid)), Sense::click()).clicked() {
|
||||
actions.push(("effect.toggle".into(), json!({"layer": layer.id.0, "effect": g.uid})));
|
||||
@@ -1009,6 +1031,7 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
egui::Id::new(("ec-hdr", g.uid)),
|
||||
Sense::click_and_drag(),
|
||||
);
|
||||
hresp.widget_info(|| egui::WidgetInfo::selected(egui::WidgetType::SelectableLabel, true, active, &g.name));
|
||||
app.auto.add(&format!("effectControls.effect.{}", g.uid), r, &g.name);
|
||||
if hresp.clicked() || hresp.drag_started() || hresp.secondary_clicked() {
|
||||
let add = ui.input(|i| i.modifiers.shift || i.modifiers.command);
|
||||
@@ -1049,6 +1072,11 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let er = Rect::from_min_size(pos2(body.min.x, y), vec2(body.width(), eh));
|
||||
y += eh;
|
||||
if er.max.y >= body.min.y && er.min.y <= body.max.y {
|
||||
// Curves, Levels and other custom editors do not use prop_row.
|
||||
// Clicking their controls must activate the owner as well.
|
||||
if ui.input(|i| i.pointer.primary_pressed()) && ui.rect_contains_pointer(er) {
|
||||
actions.push(("prop.select".into(), json!({"layer":layer.id.0,"prop":g.uid})));
|
||||
}
|
||||
match effect.as_str() {
|
||||
"ec.color.curves" => curves_editor(app, ui, &bp, &layer, g, &ectx, er, &mut actions),
|
||||
effectcraft_engine::effects::warp_stab::ID => warp_editor(app, ui, &bp, &layer, g, er, &mut actions),
|
||||
@@ -1125,11 +1153,29 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// 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)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Effect Controls' part of the Composition viewer, called by the viewer after its own
|
||||
/// interaction (so these controls sit on top):
|
||||
///
|
||||
/// - while a crosshair / eyedropper pick is armed, the next click in the viewer sets the point
|
||||
/// parameter (converted to the layer's space) or samples the frame's colour; Esc cancels;
|
||||
/// - 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).
|
||||
@@ -1144,6 +1190,7 @@ pub fn viewer_hook(
|
||||
let t = app.tokens;
|
||||
let ctx = ui.ctx().clone();
|
||||
let mut actions: Actions = vec![];
|
||||
let mut point_preview = None;
|
||||
if let Some(pick) = app.ui.fx_pick.clone() {
|
||||
let Some(layer) = ectx.comp.layer(effectcraft_engine::project::LayerId(pick.layer)).cloned() else {
|
||||
app.ui.fx_pick = None;
|
||||
@@ -1169,6 +1216,9 @@ pub fn viewer_hook(
|
||||
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
|
||||
@@ -1210,23 +1260,51 @@ pub fn viewer_hook(
|
||||
app.ui.fx_pick = None;
|
||||
app.ui.status.clear();
|
||||
}
|
||||
} else if app.ui.viewer.show_layer_controls {
|
||||
}
|
||||
let picking = app.ui.fx_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 sel = app.session.state.selected_props.clone();
|
||||
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) && l.is_active_at(ectx.time)) {
|
||||
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 = super::viewer::from_effect_space(ectx, layer, m);
|
||||
for g in fx.groups().filter(|g| g.enabled && sel.iter().any(|(l, u)| *l == layer.id && *u == g.uid)) {
|
||||
if matches!(&g.kind, GroupKind::Effect { effect } if effect == super::fx_editors::RESHAPE) {
|
||||
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 == super::fx_editors::RESHAPE) {
|
||||
super::fx_editors::reshape_overlay(app, ui, painter, map, ectx, layer, g, &m, &mut actions);
|
||||
}
|
||||
let pts: Vec<&Property> = g.props().filter(|p| matches!(p.ui, ParamUi::Point)).collect();
|
||||
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))
|
||||
})
|
||||
@@ -1238,11 +1316,13 @@ pub fn viewer_hook(
|
||||
for (pr, s) in pts.iter().zip(screen) {
|
||||
let hr = Rect::from_center_size(s, vec2(16.0, 16.0));
|
||||
let id = egui::Id::new(("viewer-fx-pt", pr.uid));
|
||||
let resp = ui.interact(hr, id, Sense::drag());
|
||||
let col = if resp.hovered() || resp.dragged() { t.accent } else { Color32::WHITE };
|
||||
// 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!("{}: {}", g.name, pr.name));
|
||||
|
||||
Reference in New Issue
Block a user