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:
co-authored by
Claude Opus 5.5
parent
0048569682
commit
89e075d1b1
+221
-53
@@ -1,7 +1,7 @@
|
||||
//! The Tools bar: home, the tool slots, tool options, snapping, workspaces and the community
|
||||
//! buttons (Discord is always one click away).
|
||||
|
||||
use egui::{Align2, Color32, Rect, Sense, Stroke, pos2, vec2};
|
||||
use egui::{Align2, Color32, Rect, Sense, Stroke, StrokeKind, pos2, vec2};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::icons::{self, Icon};
|
||||
@@ -9,6 +9,8 @@ use crate::state::Tool;
|
||||
use crate::theme::Tokens;
|
||||
use crate::widgets;
|
||||
use crate::{Dialog, EffectcraftApp};
|
||||
use effectcraft_color::BlendMode;
|
||||
use effectcraft_engine::commands::shape_tool::{PaintKind, ToolPaint};
|
||||
use effectcraft_engine::project::{LayerId, LayerSource};
|
||||
|
||||
pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
@@ -100,66 +102,35 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
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 layer_paint = shape_layers
|
||||
.first()
|
||||
.and_then(|id| app.session.active_comp()?.layer(LayerId(*id)))
|
||||
.map(|l| effectcraft_engine::commands::shape_stroke::first_paint(l, l.layer_time(app.session.time())));
|
||||
if let Some((fill, stroke, width)) = layer_paint {
|
||||
let rgb = |c: [f64; 4]| [c[0] as f32, c[1] as f32, c[2] as f32];
|
||||
let tool = &mut app.session.state.shape_tool;
|
||||
if let Some(c) = fill {
|
||||
app.ui.fill_color = rgb(c);
|
||||
tool.fill.color = rgb(c);
|
||||
}
|
||||
if let Some(c) = stroke {
|
||||
app.ui.stroke_color = rgb(c);
|
||||
tool.stroke.color = rgb(c);
|
||||
}
|
||||
app.ui.stroke_width = width.unwrap_or(0.0) as f32;
|
||||
tool.stroke_width = width.unwrap_or(0.0);
|
||||
}
|
||||
// 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)));
|
||||
let picking = ["fill", "stroke"].iter().any(|k| widgets::popup_is_open(ui, picker_id(k)));
|
||||
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));
|
||||
let c = app.ui.fill_color;
|
||||
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"));
|
||||
}
|
||||
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;
|
||||
let sr = Rect::from_center_size(pos2(x + 10.0, cy), vec2(20.0, 16.0));
|
||||
let c = app.ui.stroke_color;
|
||||
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"));
|
||||
}
|
||||
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;
|
||||
let drawing = app.ui.tool.is_shape() || app.ui.tool == Tool::Pen;
|
||||
// Tool Creates Shape / Tool Creates Mask, with a shape layer selected (as in After Effects).
|
||||
if drawing && !shape_layers.is_empty() {
|
||||
x = creates_buttons(app, ui, x, cy);
|
||||
}
|
||||
// Fill and Stroke, hidden while the tools draw masks.
|
||||
let masking = drawing && !shape_layers.is_empty() && app.session.state.shape_tool.creates_mask;
|
||||
if (drawing || !shape_layers.is_empty()) && !masking {
|
||||
x = fill_stroke_options(app, ui, &p, &shape_layers, x, cy);
|
||||
}
|
||||
if app.ui.tool.puppet_kind().is_some() {
|
||||
x = puppet_options(app, ui, &p, x, cy);
|
||||
@@ -251,6 +222,204 @@ pub fn show(app: &mut EffectcraftApp, ui: &mut egui::Ui, rect: Rect) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Set the shape tools' options (`shape.toolOptions`).
|
||||
fn tool_options(app: &mut EffectcraftApp, v: serde_json::Value) {
|
||||
if let Err(e) = app.session.execute("shape.toolOptions", v) {
|
||||
app.ui.status = e.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
/// The colour picker of the Fill or Stroke swatch.
|
||||
fn picker_id(key: &str) -> egui::Id {
|
||||
egui::Id::new(("tool-pick", key))
|
||||
}
|
||||
|
||||
/// Tool Creates Shape / Tool Creates Mask: with a shape layer selected, whether the shape tools
|
||||
/// and the Pen draw shapes into it or masks on it. Returns the next x.
|
||||
fn creates_buttons(app: &mut EffectcraftApp, ui: &mut egui::Ui, mut x: f32, cy: f32) -> f32 {
|
||||
let t = app.tokens;
|
||||
for (mask, icon, tip, key) in [(false, Icon::ShapeLayer, "Tool Creates Shape", "createsShape"), (true, Icon::MaskVis, "Tool Creates Mask", "createsMask")] {
|
||||
let r = Rect::from_min_size(pos2(x, cy - 13.0), vec2(26.0, 26.0));
|
||||
let on = app.session.state.shape_tool.creates_mask == mask;
|
||||
if widgets::icon_button(ui, r, icon, on, &t, egui::Id::new(("tool-creates", key))).on_hover_text(tip).clicked() {
|
||||
tool_options(app, json!({"createsMask": mask}));
|
||||
}
|
||||
app.auto.add(&format!("header.{key}"), r, tip);
|
||||
x += 28.0;
|
||||
}
|
||||
x + 10.0
|
||||
}
|
||||
|
||||
/// Fill and Stroke (the words open Fill Options / Stroke Options), their swatches and the
|
||||
/// Stroke Width: for new shapes, and for the selected shape layers. Returns the next x.
|
||||
fn fill_stroke_options(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter, shape_layers: &[u64], mut x: f32, cy: f32) -> f32 {
|
||||
let t = app.tokens;
|
||||
// The selected shape layers take the colours and the width too, one undo step per picker
|
||||
// session or drag.
|
||||
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", json!({"layers": shape_layers, key: v, "merge": merge})) {
|
||||
app.ui.status = e.to_string();
|
||||
}
|
||||
};
|
||||
for (key, title) in [("fill", "Fill"), ("stroke", "Stroke")] {
|
||||
let tp = if key == "fill" { &app.session.state.shape_tool.fill } else { &app.session.state.shape_tool.stroke }.clone();
|
||||
let options = format!("{title} Options");
|
||||
let g = p.layout_no_wrap(format!("{title}:"), Tokens::ui(12.0), t.text_dim);
|
||||
let wr = Rect::from_min_size(pos2(x, cy - g.size().y / 2.0), g.size());
|
||||
let wresp = ui.interact(wr, egui::Id::new(("tool-paint-word", key)), Sense::click()).on_hover_text(&options);
|
||||
let col = if wresp.hovered() { t.text } else { t.text_dim };
|
||||
if wresp.hovered() {
|
||||
p.line_segment([pos2(wr.min.x, wr.max.y), pos2(wr.max.x - 3.0, wr.max.y)], Stroke::new(1.0, col));
|
||||
}
|
||||
p.galley_with_override_text_color(wr.min, g, col);
|
||||
app.auto.add(&format!("header.{key}Options"), wr, &options);
|
||||
let opts = egui::Id::new(("tool-paint-options", key));
|
||||
if wresp.clicked() {
|
||||
widgets::open_popup(ui, opts);
|
||||
}
|
||||
// The swatch picks a Solid Color's colour and opens the options for the other kinds;
|
||||
// Alt-click steps through the kinds (as in After Effects).
|
||||
let sr = Rect::from_min_size(pos2(wr.max.x + 6.0, cy - 8.0), vec2(20.0, 16.0));
|
||||
let sresp = ui.interact(sr, egui::Id::new(("tool-paint-swatch", key)), Sense::click()).on_hover_text(format!("{title}: {}", tp.kind.label()));
|
||||
paint_swatch(p, sr, &tp, sresp.hovered(), &t);
|
||||
app.auto.add(&format!("header.{key}"), sr, &format!("{title} Color"));
|
||||
if sresp.clicked() {
|
||||
if ui.input(|i| i.modifiers.alt) {
|
||||
let at = PaintKind::ALL.iter().position(|k| *k == tp.kind).unwrap_or(0);
|
||||
let next = PaintKind::ALL.get((at + 1) % PaintKind::ALL.len()).copied().unwrap_or_default();
|
||||
let k = format!("{key}Type");
|
||||
tool_options(app, json!({k: next.id()}));
|
||||
} else if tp.kind == PaintKind::Solid {
|
||||
widgets::open_popup(ui, picker_id(key));
|
||||
} else {
|
||||
widgets::open_popup(ui, opts);
|
||||
}
|
||||
}
|
||||
let mut c = tp.color;
|
||||
if color_popup(ui, picker_id(key), sr.left_bottom(), &mut c) {
|
||||
tool_options(app, json!({key: c}));
|
||||
paint(app, key, json!(c));
|
||||
}
|
||||
paint_options_popup(app, ui, key, &options, wr.left_bottom());
|
||||
x = sr.max.x + 12.0;
|
||||
}
|
||||
let width = app.session.state.shape_tool.stroke_width;
|
||||
let (r, v, _) = widgets::hot_number_at(ui, pos2(x - 6.0, cy - 9.0), egui::Id::new("tool-stroke-w"), width, 0.2, (0.0, 1000.0), 0, " px", &t);
|
||||
if let Some(v) = v {
|
||||
tool_options(app, json!({"strokeWidth": v}));
|
||||
paint(app, "strokeWidth", json!(v));
|
||||
}
|
||||
app.auto.add("header.strokeWidth", r, "Stroke Width");
|
||||
r.max.x + 14.0
|
||||
}
|
||||
|
||||
/// Fill Options / Stroke Options: None, Solid Color, Linear Gradient or Radial Gradient, and the
|
||||
/// blend mode and opacity new shapes get (After Effects' dialogs, applied as they change).
|
||||
fn paint_options_popup(app: &mut EffectcraftApp, ui: &mut egui::Ui, key: &str, title: &str, pos: egui::Pos2) {
|
||||
let id = egui::Id::new(("tool-paint-options", key));
|
||||
if !widgets::popup_is_open(ui, id) {
|
||||
return;
|
||||
}
|
||||
let t = app.tokens;
|
||||
let tp = if key == "fill" { &app.session.state.shape_tool.fill } else { &app.session.state.shape_tool.stroke }.clone();
|
||||
let blend_pop = id.with("blend");
|
||||
let mut set = None;
|
||||
let mut blend_rect = Rect::NOTHING;
|
||||
let area = egui::Area::new(id.with("area")).order(egui::Order::Foreground).fixed_pos(pos + vec2(0.0, 4.0)).show(ui.ctx(), |ui| {
|
||||
egui::Frame::popup(ui.style()).show(ui, |ui| {
|
||||
let (rect, _) = ui.allocate_exact_size(vec2(236.0, 112.0), Sense::hover());
|
||||
let p = ui.painter().clone();
|
||||
let row = |y: f32| rect.min + vec2(0.0, y);
|
||||
p.text(row(8.0), Align2::LEFT_CENTER, title, Tokens::semibold(12.0), t.text);
|
||||
for (i, k) in PaintKind::ALL.into_iter().enumerate() {
|
||||
let r = Rect::from_min_size(row(22.0) + vec2(i as f32 * 32.0, 0.0), vec2(28.0, 22.0));
|
||||
let resp = ui.interact(r, id.with(k.id()), Sense::click()).on_hover_text(k.label());
|
||||
if k == tp.kind {
|
||||
p.rect_stroke(r, 3.0, Stroke::new(1.5, t.accent), StrokeKind::Outside);
|
||||
}
|
||||
paint_swatch(&p, r.shrink(3.0), &ToolPaint { kind: k, ..tp.clone() }, resp.hovered(), &t);
|
||||
app.auto.add(&format!("header.{key}Options.{}", k.id()), r, k.label());
|
||||
if resp.clicked() {
|
||||
let k_type = format!("{key}Type");
|
||||
set = Some(json!({k_type: k.id()}));
|
||||
}
|
||||
}
|
||||
p.text(row(33.0) + vec2(134.0, 0.0), Align2::LEFT_CENTER, tp.kind.label(), Tokens::ui(11.5), t.text_dim);
|
||||
p.text(row(66.0), Align2::LEFT_CENTER, "Blend Mode:", Tokens::ui(12.0), t.text_dim);
|
||||
blend_rect = Rect::from_min_size(row(56.0) + vec2(84.0, 0.0), vec2(150.0, 20.0));
|
||||
if widgets::dropdown(ui, blend_rect, tp.blend.label(), &t, id.with("blend-dd")).clicked() {
|
||||
widgets::open_popup(ui, blend_pop);
|
||||
}
|
||||
app.auto.add(&format!("header.{key}Options.blend"), blend_rect, "Blend Mode");
|
||||
p.text(row(98.0), Align2::LEFT_CENTER, "Opacity:", Tokens::ui(12.0), t.text_dim);
|
||||
let (or, v, _) = widgets::hot_number_at(ui, row(89.0) + vec2(84.0, 0.0), id.with("opacity"), tp.opacity, 0.5, (0.0, 100.0), 0, "%", &t);
|
||||
app.auto.add(&format!("header.{key}Options.opacity"), or, "Opacity");
|
||||
if let Some(v) = v {
|
||||
let k_opacity = format!("{key}Opacity");
|
||||
set = Some(json!({k_opacity: v}));
|
||||
}
|
||||
});
|
||||
});
|
||||
// The blend modes in the Layer ▸ Blending Mode menu's groups, over the options.
|
||||
let modes: Vec<String> =
|
||||
BlendMode::ALL.iter().flat_map(|m| std::iter::once(m.label().to_string()).chain(m.ends_group().then(|| "-".to_string()))).collect();
|
||||
let current = modes.iter().position(|m| m == tp.blend.label());
|
||||
if let Some(m) = widgets::popup_menu(ui, blend_pop, blend_rect.left_bottom(), &modes, current).and_then(|i| modes.get(i)) {
|
||||
let k_blend = format!("{key}Blend");
|
||||
set = Some(json!({k_blend: m}));
|
||||
}
|
||||
// Closes on a press outside or Escape, but stays open while its blend mode menu is.
|
||||
if !widgets::popup_is_open(ui, blend_pop) && (widgets::pressed_outside(ui.ctx(), &area.response) || ui.input(|i| i.key_pressed(egui::Key::Escape))) {
|
||||
ui.data_mut(|d| d.insert_temp(id.with("open"), false));
|
||||
}
|
||||
if let Some(v) = set {
|
||||
tool_options(app, v);
|
||||
}
|
||||
}
|
||||
|
||||
/// sRGB components (0–1) as a colour.
|
||||
fn srgb32(c: [f32; 3]) -> Color32 {
|
||||
let b = |v: f32| (v.clamp(0.0, 1.0) * 255.0).round() as u8;
|
||||
Color32::from_rgb(b(c[0]), b(c[1]), b(c[2]))
|
||||
}
|
||||
|
||||
/// A Fill or Stroke swatch: its colour, a gradient (white to black), or None's red slash.
|
||||
fn paint_swatch(p: &egui::Painter, r: Rect, paint: &ToolPaint, hovered: bool, t: &Tokens) {
|
||||
let clip = p.with_clip_rect(r);
|
||||
match paint.kind {
|
||||
PaintKind::None => {
|
||||
clip.rect_filled(r, 2.0, Color32::WHITE);
|
||||
clip.line_segment([r.left_bottom(), r.right_top()], Stroke::new(1.5, Color32::from_rgb(0xe0, 0x30, 0x30)));
|
||||
}
|
||||
PaintKind::Solid => {
|
||||
clip.rect_filled(r, 2.0, srgb32(paint.color));
|
||||
}
|
||||
PaintKind::Linear => {
|
||||
let mut m = egui::Mesh::default();
|
||||
for (q, c) in
|
||||
[(r.left_top(), Color32::WHITE), (r.right_top(), Color32::BLACK), (r.right_bottom(), Color32::BLACK), (r.left_bottom(), Color32::WHITE)]
|
||||
{
|
||||
m.colored_vertex(q, c);
|
||||
}
|
||||
m.add_triangle(0, 1, 2);
|
||||
m.add_triangle(0, 2, 3);
|
||||
clip.add(m);
|
||||
}
|
||||
PaintKind::Radial => {
|
||||
let rad = r.size().length() / 2.0;
|
||||
for i in 0..8 {
|
||||
let f = 1.0 - i as f32 / 8.0;
|
||||
clip.circle_filled(r.center(), rad * f, Color32::from_gray((255.0 * (1.0 - f)) as u8));
|
||||
}
|
||||
}
|
||||
}
|
||||
p.rect_stroke(r, 2.0, Stroke::new(1.0, if hovered { t.text } else { t.field_border }), StrokeKind::Inside);
|
||||
}
|
||||
|
||||
/// Puppet tool options: Mesh: Show, Expansion, Density (for new meshes and the selected
|
||||
/// layer's meshes). Returns the next x.
|
||||
fn puppet_options(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Painter, mut x: f32, cy: f32) -> f32 {
|
||||
@@ -331,8 +500,7 @@ pub fn color_popup(ui: &mut egui::Ui, id: egui::Id, pos: egui::Pos2, c: &mut [f3
|
||||
let mut changed = false;
|
||||
let area = egui::Area::new(id.with("area")).order(egui::Order::Foreground).fixed_pos(pos + vec2(0.0, 4.0)).show(ui.ctx(), |ui| {
|
||||
egui::Frame::popup(ui.style()).show(ui, |ui| {
|
||||
let mut col =
|
||||
egui::Color32::from_rgb((c[0].clamp(0.0, 1.0) * 255.0) as u8, (c[1].clamp(0.0, 1.0) * 255.0) as u8, (c[2].clamp(0.0, 1.0) * 255.0) as u8);
|
||||
let mut col = srgb32(*c);
|
||||
if egui::color_picker::color_picker_color32(ui, &mut col, egui::color_picker::Alpha::Opaque) {
|
||||
*c = [col.r() as f32 / 255.0, col.g() as f32 / 255.0, col.b() as f32 / 255.0];
|
||||
changed = true;
|
||||
|
||||
@@ -1654,8 +1654,9 @@ fn draw_rigs(app: &mut EffectcraftApp, painter: &egui::Painter, map: &ViewerMap,
|
||||
|
||||
/// Pen tool press at `pos`: continue the path in progress (pressing its first vertex closes it),
|
||||
/// add a vertex on a visible path's segment, or start a new path: a mask on the selected
|
||||
/// footage/solid layer, a shape path (Shape n group with Fill and Stroke) on the selected shape
|
||||
/// layer, or a new shape layer when nothing is selected. The placed point snaps.
|
||||
/// footage/solid layer (or shape layer, with Tool Creates Mask), a shape path (Shape n group with
|
||||
/// the Tools bar's Fill and Stroke) on the selected shape layer, or a new shape layer when
|
||||
/// nothing is selected. The placed point snaps.
|
||||
fn pen_press(app: &mut EffectcraftApp, ui: &mut egui::Ui, ectx: &EvalCtx, map: &ViewerMap, paths: &[ov::PathInfo], pos: Pos2, mods: egui::Modifiers) {
|
||||
use effectcraft_engine::project::LayerSource;
|
||||
let gid = egui::Id::new("viewer-gesture");
|
||||
@@ -1702,7 +1703,7 @@ fn pen_press(app: &mut EffectcraftApp, ui: &mut egui::Ui, ectx: &EvalCtx, map: &
|
||||
.find(|id| ectx.comp.layer(*id).is_some_and(|l| !l.switches.locked && (l.masks().is_some() || matches!(l.source, LayerSource::Shape))));
|
||||
let layer = target.and_then(|id| ectx.comp.layer(id));
|
||||
let (lid, uid, inv) = match layer {
|
||||
Some(l) if !matches!(l.source, LayerSource::Shape) => {
|
||||
Some(l) if !matches!(l.source, LayerSource::Shape) || app.session.state.shape_tool.creates_mask => {
|
||||
let Some(inv) = l2c(ectx, l).0.inverse() else { return };
|
||||
let lp = inv.apply(gv2(c[0], c[1]));
|
||||
let Ok(v) = app.session.execute("mask.new", json!({"layer": l.id.0, "vertices": [[lp.x, lp.y]]})) else { return };
|
||||
@@ -1712,23 +1713,13 @@ fn pen_press(app: &mut EffectcraftApp, ui: &mut egui::Ui, ectx: &EvalCtx, map: &
|
||||
Some(l) => {
|
||||
let Some(inv) = l2c(ectx, l).0.inverse() else { return };
|
||||
let lp = inv.apply(gv2(c[0], c[1]));
|
||||
let fill = app.ui.fill_color;
|
||||
let stroke = app.ui.stroke_color;
|
||||
let r = app.session.execute(
|
||||
"shape.newPath",
|
||||
json!({"layer": l.id.0, "vertices": [[lp.x, lp.y]], "space": "layer", "fill": [fill[0], fill[1], fill[2]], "stroke": [stroke[0], stroke[1], stroke[2]], "strokeWidth": app.ui.stroke_width}),
|
||||
);
|
||||
let r = app.session.execute("shape.newPath", json!({"layer": l.id.0, "vertices": [[lp.x, lp.y]], "space": "layer"}));
|
||||
let Some(path) = r.ok().and_then(|v| v["path"].as_u64()) else { return };
|
||||
(l.id, path, inv)
|
||||
}
|
||||
None => {
|
||||
// A new shape layer at the comp centre (unrotated: comp → layer is a translation).
|
||||
let fill = app.ui.fill_color;
|
||||
let stroke = app.ui.stroke_color;
|
||||
let r = app.session.execute(
|
||||
"shape.newPath",
|
||||
json!({"vertices": [c], "space": "comp", "fill": [fill[0], fill[1], fill[2]], "stroke": [stroke[0], stroke[1], stroke[2]], "strokeWidth": app.ui.stroke_width}),
|
||||
);
|
||||
let r = app.session.execute("shape.newPath", json!({"vertices": [c], "space": "comp"}));
|
||||
let Some(v) = r.ok() else { return };
|
||||
let (Some(l), Some(path)) = (v["layer"].as_u64(), v["path"].as_u64()) else { return };
|
||||
let inv = Mat3::translate(gv2(-(ectx.comp.width as f64) / 2.0, -(ectx.comp.height as f64) / 2.0));
|
||||
@@ -1799,13 +1790,14 @@ fn create_shape(app: &mut EffectcraftApp, tool: Tool, a: [f64; 2], b: [f64; 2],
|
||||
Tool::Polygon => "polygon",
|
||||
_ => "star",
|
||||
};
|
||||
// A non-shape layer selected and "creates mask": add a mask instead.
|
||||
// A footage, solid or other non-shape layer selected, or a shape layer with Tool Creates
|
||||
// Mask: a mask on it instead.
|
||||
let creates_mask = app.session.state.shape_tool.creates_mask;
|
||||
let sel = app.session.state.selected_layers.first().copied();
|
||||
let sel_layer = sel.and_then(|id| app.session.active_comp().and_then(|c| c.layer(id)).cloned());
|
||||
if let Some(l) = sel_layer
|
||||
&& !matches!(l.source, effectcraft_engine::project::LayerSource::Shape)
|
||||
&& l.source.is_av()
|
||||
&& matches!(kind, "rect" | "ellipse")
|
||||
&& (creates_mask || !matches!(l.source, effectcraft_engine::project::LayerSource::Shape))
|
||||
{
|
||||
// Mask in layer space: invert the layer transform.
|
||||
let comp = app.session.active_comp_arc();
|
||||
@@ -1821,21 +1813,16 @@ fn create_shape(app: &mut EffectcraftApp, tool: Tool, a: [f64; 2], b: [f64; 2],
|
||||
let inv = l2c(&ectx, &l).0.inverse().unwrap_or(Mat3::IDENTITY);
|
||||
let p0 = inv.apply(gv2(cx - w / 2.0, cy - h / 2.0));
|
||||
let p1 = inv.apply(gv2(cx + w / 2.0, cy + h / 2.0));
|
||||
let _ = app.session.execute(
|
||||
"layer.addMask",
|
||||
json!({"layer": l.id.0, "shape": if kind == "ellipse" { "ellipse" } else { "rect" }, "rect": [p0.x.min(p1.x), p0.y.min(p1.y), (p1.x - p0.x).abs(), (p1.y - p0.y).abs()]}),
|
||||
);
|
||||
let rect = [p0.x.min(p1.x), p0.y.min(p1.y), (p1.x - p0.x).abs(), (p1.y - p0.y).abs()];
|
||||
if let Err(e) = app.session.execute("layer.addMask", json!({"layer": l.id.0, "shape": kind, "rect": rect})) {
|
||||
app.ui.status = e.to_string();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
// Into the selected shape layer's Contents as a new group (as in After Effects), else a new
|
||||
// shape layer.
|
||||
let fill = app.ui.fill_color;
|
||||
let stroke = app.ui.stroke_color;
|
||||
if let Err(e) = app.session.execute(
|
||||
"shape.newShape",
|
||||
json!({"kind": kind, "size": [w, h], "position": [cx, cy], "fill": [fill[0], fill[1], fill[2]], "stroke": [stroke[0], stroke[1], stroke[2]], "strokeWidth": app.ui.stroke_width}),
|
||||
) {
|
||||
// shape layer; painted with the Tools bar's Fill and Stroke.
|
||||
if let Err(e) = app.session.execute("shape.newShape", json!({"kind": kind, "size": [w, h], "position": [cx, cy]})) {
|
||||
app.ui.status = e.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -633,13 +633,7 @@ pub struct UiState {
|
||||
/// Effects & Presets contents-menu view options.
|
||||
#[serde(default)]
|
||||
pub effects_view: EffectsView,
|
||||
/// Shape tool options.
|
||||
pub fill_color: [f32; 3],
|
||||
pub stroke_color: [f32; 3],
|
||||
pub stroke_width: f32,
|
||||
pub snapping: bool,
|
||||
/// Tool creates shape (true) or mask (false) when a layer is selected.
|
||||
pub tool_creates_shape: bool,
|
||||
pub start_screen: bool,
|
||||
/// The Home screen shows its Learn tab (tutorials) instead of the recent projects.
|
||||
#[serde(default)]
|
||||
@@ -714,11 +708,7 @@ impl Default for UiState {
|
||||
effects_favorites: BTreeSet::new(),
|
||||
effects_recent: Vec::new(),
|
||||
effects_view: EffectsView::default(),
|
||||
fill_color: [0.24, 0.55, 0.96],
|
||||
stroke_color: [1.0, 1.0, 1.0],
|
||||
stroke_width: 0.0,
|
||||
snapping: true,
|
||||
tool_creates_shape: true,
|
||||
start_screen: false,
|
||||
home_learn: false,
|
||||
home_templates: false,
|
||||
|
||||
Reference in New Issue
Block a user