Shapes and timeline: toolbar Fill / Stroke edit selected shape layers; Alt+Shift+P reveals; click below layers deselects (#205)
- With a shape layer selected, the toolbar shows its Fill, Stroke and Stroke Width (with any tool) and editing them changes the layer's fills and strokes, as in After Effects (new shape.fillStroke, one undo step per picker or drag). Shapes drawn without a stroke get one when a stroke colour or width is set, so changing the stroke now works. - Alt+Shift+P (A, S, R, T) reveals the property it keyed on each layer. - A click in the time graph below the last layer deselects the layers (it only deselected keyframes), so a shape tool draws a new shape layer instead of a mask on the selected image. Tests: toolbar_fill_and_stroke_paint_selected_shape_layers, toolbar_stroke_edits_the_selected_shape_layer, add_position_key_reveals_position, clicking_below_the_layers_deselects_them. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018gnTnH3Jmk5zr4tMq1Mc9f
This commit is contained in:
@@ -9,6 +9,7 @@ use crate::state::Tool;
|
||||
use crate::theme::Tokens;
|
||||
use crate::widgets;
|
||||
use crate::{Dialog, EffectcraftApp};
|
||||
use effectcraft_engine::project::{LayerId, LayerSource};
|
||||
|
||||
pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
let t = app.tokens;
|
||||
@@ -91,7 +92,40 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
|
||||
// Tool options.
|
||||
x += 10.0;
|
||||
if app.ui.tool.is_shape() || app.ui.tool == Tool::Pen {
|
||||
// Selected shape layers: the options show their paint and edit it (as in After Effects).
|
||||
let shape_layers: Vec<u64> = app
|
||||
.session
|
||||
.active_comp()
|
||||
.map(|c| {
|
||||
app.session.state.selected_layers.iter().filter(|id| c.layer(**id).is_some_and(|l| matches!(l.source, LayerSource::Shape))).map(|id| id.0).collect()
|
||||
})
|
||||
.unwrap_or_default();
|
||||
if let Some(l) = shape_layers.first().and_then(|id| app.session.active_comp()?.layer(LayerId(*id))) {
|
||||
let (fill, stroke, width) = effectcraft_engine::commands::shape_stroke::first_paint(l, l.layer_time(app.session.time()));
|
||||
let rgb = |c: [f64; 4]| [c[0] as f32, c[1] as f32, c[2] as f32];
|
||||
if let Some(c) = fill {
|
||||
app.ui.fill_color = rgb(c);
|
||||
}
|
||||
if let Some(c) = stroke {
|
||||
app.ui.stroke_color = rgb(c);
|
||||
}
|
||||
app.ui.stroke_width = width.unwrap_or(0.0) as f32;
|
||||
}
|
||||
// One undo step per picker session or width drag: end the merge once both are done.
|
||||
let picking = ["tool-fill-pop", "tool-stroke-pop"].iter().any(|k| ui.data(|d| d.get_temp::<bool>(egui::Id::new(*k).with("open")).unwrap_or(false)));
|
||||
if !picking && !ui.input(|i| i.pointer.any_down()) && app.session.history.merge_key.as_deref().is_some_and(|k| k.starts_with("tool-")) {
|
||||
app.session.history.merge_key = None;
|
||||
}
|
||||
if app.ui.tool.is_shape() || app.ui.tool == Tool::Pen || !shape_layers.is_empty() {
|
||||
let paint = |app: &mut EffectcraftApp, key: &str, v: serde_json::Value| {
|
||||
if shape_layers.is_empty() {
|
||||
return;
|
||||
}
|
||||
let merge = format!("tool-{key}");
|
||||
if let Err(e) = app.session.execute("shape.fillStroke", serde_json::json!({"layers": shape_layers, key: v, "merge": merge})) {
|
||||
app.ui.status = e.to_string();
|
||||
}
|
||||
};
|
||||
p.text(pos2(x, cy), Align2::LEFT_CENTER, "Fill:", Tokens::ui(12.0), t.text_dim);
|
||||
x += 28.0;
|
||||
let fr = Rect::from_center_size(pos2(x + 10.0, cy), vec2(20.0, 16.0));
|
||||
@@ -99,7 +133,11 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if widgets::swatch(ui, fr, [c[0], c[1], c[2], 1.0], egui::Id::new("tool-fill"), &t).clicked() {
|
||||
widgets::open_popup(ui, egui::Id::new("tool-fill-pop"));
|
||||
}
|
||||
color_popup(ui, egui::Id::new("tool-fill-pop"), fr.left_bottom(), &mut app.ui.fill_color);
|
||||
if color_popup(ui, egui::Id::new("tool-fill-pop"), fr.left_bottom(), &mut app.ui.fill_color) {
|
||||
let c = app.ui.fill_color;
|
||||
paint(app, "fill", serde_json::json!(c));
|
||||
}
|
||||
app.auto.add("header.fill", fr, "Fill Color");
|
||||
x += 32.0;
|
||||
p.text(pos2(x, cy), Align2::LEFT_CENTER, "Stroke:", Tokens::ui(12.0), t.text_dim);
|
||||
x += 44.0;
|
||||
@@ -108,13 +146,19 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if widgets::swatch(ui, sr, [c[0], c[1], c[2], 1.0], egui::Id::new("tool-stroke"), &t).clicked() {
|
||||
widgets::open_popup(ui, egui::Id::new("tool-stroke-pop"));
|
||||
}
|
||||
color_popup(ui, egui::Id::new("tool-stroke-pop"), sr.left_bottom(), &mut app.ui.stroke_color);
|
||||
if color_popup(ui, egui::Id::new("tool-stroke-pop"), sr.left_bottom(), &mut app.ui.stroke_color) {
|
||||
let c = app.ui.stroke_color;
|
||||
paint(app, "stroke", serde_json::json!(c));
|
||||
}
|
||||
app.auto.add("header.stroke", sr, "Stroke Color");
|
||||
x += 26.0;
|
||||
let (r, v, _) =
|
||||
widgets::hot_number_at(ui, pos2(x, cy - 9.0), egui::Id::new("tool-stroke-w"), app.ui.stroke_width as f64, 0.2, (0.0, 1000.0), 0, " px", &t);
|
||||
if let Some(v) = v {
|
||||
app.ui.stroke_width = v as f32;
|
||||
paint(app, "strokeWidth", serde_json::json!(v));
|
||||
}
|
||||
app.auto.add("header.strokeWidth", r, "Stroke Width");
|
||||
x = r.max.x + 14.0;
|
||||
}
|
||||
if app.ui.tool.puppet_kind().is_some() {
|
||||
|
||||
@@ -190,6 +190,35 @@ fn reveal_time_remap(app: &mut EffectcraftApp, params: &Value) {
|
||||
}
|
||||
}
|
||||
|
||||
/// After Alt+Shift+P (A, S, R, T) the Timeline shows the property on each layer it keyed, as in
|
||||
/// After Effects: added to what a reveal shortcut shows, else with the layer's Transform twirled
|
||||
/// open, else alone like P.
|
||||
fn reveal_keyed(app: &mut EffectcraftApp, keyed: &Value, kind: &str) {
|
||||
let layers: std::collections::BTreeSet<u64> = keyed.as_array().into_iter().flatten().filter_map(|k| k.get("layer").and_then(Value::as_u64)).collect();
|
||||
let Some(comp) = app.session.active_comp() else { return };
|
||||
let tl = &mut app.ui.timeline;
|
||||
for id in layers {
|
||||
let shown = tl.layer_reveal.get(&id).filter(|k| !k.is_empty()).cloned();
|
||||
match shown {
|
||||
Some(mut kinds) => {
|
||||
if !kinds.iter().any(|k| k == kind) {
|
||||
kinds.push(kind.to_string());
|
||||
tl.layer_reveal.insert(id, kinds);
|
||||
}
|
||||
}
|
||||
None if tl.open_layers.contains(&id) => {
|
||||
if let Some(tr) = comp.layer(effectcraft_engine::project::LayerId(id)).and_then(|l| l.transform()) {
|
||||
tl.open_groups.insert(tr.uid);
|
||||
}
|
||||
}
|
||||
None => {
|
||||
tl.open_layers.insert(id);
|
||||
tl.layer_reveal.insert(id, vec![kind.to_string()]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The layers a reveal shortcut acts on: the selected ones, else every layer of the active comp.
|
||||
fn reveal_targets(app: &EffectcraftApp) -> Vec<u64> {
|
||||
if app.session.state.selected_layers.is_empty() {
|
||||
@@ -314,7 +343,9 @@ pub fn invoke(app: &mut EffectcraftApp, ctx: &egui::Context, id: &str, params: V
|
||||
return Ok(Value::Null);
|
||||
}
|
||||
if let Some(k) = id.strip_prefix("timeline.keyAt.") {
|
||||
return run_engine(app, ctx, "keys.toggleTransform", json!({"prop": k}));
|
||||
let r = run_engine(app, ctx, "keys.toggleTransform", json!({"prop": k}))?;
|
||||
reveal_keyed(app, &r, k);
|
||||
return Ok(r);
|
||||
}
|
||||
if let Some(k) = id.strip_prefix("timeline.revealAdd.") {
|
||||
reveal(app, k, now, true);
|
||||
|
||||
@@ -2215,9 +2215,14 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
if graph_on {
|
||||
super::graph::show(app, ui, &gp, &comp, &ectx, tm, Rect::from_min_max(pos2(graph_x0, rows_rect.min.y), rows_rect.max), &mut actions);
|
||||
}
|
||||
// Empty-area click in the graph: deselect keys; drag: box-select keys.
|
||||
// Empty-area click in the graph: deselect keys (below the last row, the layers too, as in
|
||||
// After Effects); drag: box-select keys.
|
||||
if empty.clicked() {
|
||||
actions.push(("keys.select".into(), json!({"keys": []})));
|
||||
let below = empty.interact_pointer_pos().is_some_and(|p| hit_rows.iter().all(|(r, _)| p.y > r.max.y));
|
||||
if below && !ui.input(|i| i.modifiers.shift || i.modifiers.command) {
|
||||
actions.push(("layer.select".into(), json!({"layers": []})));
|
||||
}
|
||||
}
|
||||
if let (true, Some(origin), Some(cur)) =
|
||||
(empty.dragged(), empty.interact_pointer_pos().and_then(|_| ctx.input(|i| i.pointer.press_origin())), empty.interact_pointer_pos())
|
||||
|
||||
Reference in New Issue
Block a user