Shapes: Tools bar Tool Creates Shape / Mask and Fill / Stroke Options (#227)

The Tools bar had Fill and Stroke swatches and a Stroke Width, kept in
the interface only, so agents couldn't set them and new shapes could
only be a solid fill with a solid stroke. As in After Effects:

- With a shape layer selected and a shape tool or the Pen active, Tool
  Creates Shape / Tool Creates Mask choose whether drawing adds shapes
  to the layer or masks on it (Fill and Stroke hide while drawing
  masks).
- Clicking the word "Fill" or "Stroke" opens Fill Options / Stroke
  Options: None, Solid Color, Linear Gradient or Radial Gradient, the
  blend mode and the opacity. The swatches show the kind; Alt-click
  steps through the kinds.
- New shapes and Pen paths are painted with them: a Gradient Fill or
  Gradient Stroke across the shape for the gradient kinds.

The options are engine state (EditorState.shape_tool) set with the new
shape.toolOptions command; shape.newShape and shape.newPath use them
unless given paint parameters (which now include fillType, fillBlend,
fillOpacity and their stroke twins; layer.newShape takes them too). A
Pen path without paint parameters now takes the Tools bar's stroke
(none by default) instead of a fixed 2 px white one. layer.addMask also
draws rounded rectangle, polygon and star masks, so every shape tool
makes a mask on a selected footage or solid layer (rounded rectangles,
polygons and stars made a new shape layer).

Test: shape_tool_options_paint_new_shapes,
masks_of_every_shape_tool_kind,
tool_creates_mask_draws_a_mask_on_the_selected_shape_layer,
fill_options_paint_the_next_shape.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
bflatastic
2026-10-08 13:03:38 +07:00
co-authored by Claude Opus 5.5
parent 0048569682
commit 89e075d1b1
11 changed files with 636 additions and 168 deletions
+1 -1
View File
@@ -195,5 +195,5 @@ fn toolbar_stroke_edits_the_selected_shape_layer() {
let layer = h.state().session.active_comp().unwrap().layer(LayerId(l)).unwrap().clone();
let width = layer.props.prop("contents/group/contents/stroke/width").map(|p| p.value.as_f64());
assert_eq!(width, Some(4.0), "a stroke was added with the toolbar's width");
assert_eq!(h.state().ui.stroke_width, 4.0);
assert_eq!(h.state().session.state.shape_tool.stroke_width, 4.0);
}
+68
View File
@@ -3,11 +3,13 @@
//! (egui_kittest, UI logic only).
use effectcraft_engine::Session;
use effectcraft_engine::commands::shape_tool::PaintKind;
use effectcraft_engine::project::LayerId;
use effectcraft_ui_egui::EffectcraftApp;
use effectcraft_ui_egui::state::Tool;
use egui::{Event, Pos2, Rect, pos2, vec2};
use egui_kittest::Harness;
use egui_kittest::kittest::Queryable;
use serde_json::json;
fn app() -> EffectcraftApp {
@@ -280,6 +282,72 @@ fn shape_tool_draws_into_the_selected_shape_layer() {
assert_ne!(comp.layers[0].id, LayerId(l));
}
/// With a shape layer selected and a shape tool active, the Tools bar's Tool Creates Mask makes
/// the tool draw a mask on the layer (and hides Fill and Stroke); Tool Creates Shape draws
/// shapes again (#227).
#[test]
fn tool_creates_mask_draws_a_mask_on_the_selected_shape_layer() {
let mut h = harness();
let l = h.state_mut().session.execute("layer.newShape", json!({"kind": "rect", "size": [100, 100], "position": [320, 180]})).unwrap()["layer"]
.as_u64()
.unwrap();
h.state_mut().ui.tool = Tool::Star;
h.run_steps(2);
assert!(h.state().auto.find("header.fill").is_some());
let at = rect(&h, "header.createsMask").center();
click(&mut h, at);
assert!(h.state().session.state.shape_tool.creates_mask);
assert!(h.state().auto.find("header.fill").is_none(), "no Fill or Stroke for masks");
let (a, b) = (screen(&h, [100.0, 100.0]), screen(&h, [200.0, 200.0]));
drag(&mut h, a, b);
let layer = h.state().session.active_comp().unwrap().layer(LayerId(l)).unwrap().clone();
let masks = layer.props.sub("masks").unwrap();
assert_eq!(masks.groups().count(), 1, "a mask");
assert_eq!(masks.groups().next().unwrap().get("path").unwrap().value.as_path().unwrap().vertices.len(), 10, "a star");
assert_eq!(layer.props.sub("contents").unwrap().groups().count(), 1, "no new shape");
let at = rect(&h, "header.createsShape").center();
click(&mut h, at);
assert!(!h.state().session.state.shape_tool.creates_mask);
}
/// Clicking the word "Fill" opens Fill Options: a radial gradient in Multiply at 40% paints the
/// next shape drawn (#227).
#[test]
fn fill_options_paint_the_next_shape() {
let mut h = harness();
h.state_mut().ui.tool = Tool::Ellipse;
h.run_steps(2);
let at = rect(&h, "header.fillOptions").center();
click(&mut h, at);
let at = rect(&h, "header.fillOptions.radial").center();
click(&mut h, at);
let at = rect(&h, "header.fillOptions.blend").center();
click(&mut h, at);
let at = h.get_by_label("Multiply").rect().center();
click(&mut h, at);
let at = rect(&h, "header.fillOptions.opacity").center();
click(&mut h, at);
h.input_mut().events.push(Event::Text("40".into()));
h.step();
h.input_mut().events.push(Event::Key { key: egui::Key::Enter, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() });
h.run_steps(2);
let fill = h.state().session.state.shape_tool.fill.clone();
assert_eq!((fill.kind, fill.blend, fill.opacity), (PaintKind::Radial, effectcraft_engine::color::BlendMode::Multiply, 40.0));
h.input_mut().events.push(Event::Key { key: egui::Key::Escape, physical_key: None, pressed: true, repeat: false, modifiers: Default::default() });
h.run_steps(3);
assert!(h.state().auto.find("header.fillOptions.radial").is_none(), "closed");
let (a, b) = (screen(&h, [100.0, 100.0]), screen(&h, [220.0, 160.0]));
drag(&mut h, a, b);
let layer = h.state().session.active_comp().unwrap().layers[0].clone();
let g = layer.props.sub("contents").unwrap().groups().next().unwrap().sub("contents").unwrap().clone();
assert_eq!(g.groups().map(|x| x.match_id.as_str()).collect::<Vec<_>>(), ["ellipse", "gfill"]);
let gfill = g.groups().find(|x| x.match_id == "gfill").unwrap();
let multiply = effectcraft_engine::color::BlendMode::ALL.iter().position(|m| *m == effectcraft_engine::color::BlendMode::Multiply).unwrap() as u32;
assert_eq!(gfill.get("type").unwrap().value, effectcraft_keyframe::Value::Enum(1));
assert_eq!(gfill.get("blend").unwrap().value, effectcraft_keyframe::Value::Enum(multiply));
assert_eq!(gfill.get("opacity").unwrap().value.as_f64(), 40.0);
}
#[test]
fn shape_pen_draws_a_closed_shape_layer() {
let mut h = harness();