Merge pull request #744 from vangel76/fix-732-toolbar-fill-type
#732: toolbar Fill/Stroke Options change the selected shape layers' kind
This commit is contained in:
@@ -133,13 +133,15 @@ 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();
|
||||
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 layer_paint = shape_layers.first().and_then(|id| app.session.active_comp()?.layer(LayerId(*id))).map(|l| {
|
||||
let lt = l.layer_time(app.session.time());
|
||||
(effectcraft_engine::commands::shape_stroke::first_paint(l, lt), effectcraft_engine::commands::shape_stroke::first_paint_kinds(l, lt))
|
||||
});
|
||||
if let Some(((fill, stroke, width), (fill_kind, stroke_kind))) = 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;
|
||||
tool.fill.kind = fill_kind;
|
||||
tool.stroke.kind = stroke_kind;
|
||||
if let Some(c) = fill {
|
||||
tool.fill.color = rgb(c);
|
||||
}
|
||||
@@ -363,8 +365,7 @@ fn fill_stroke_options(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Pa
|
||||
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()}));
|
||||
paint_kind(app, shape_layers, key, next);
|
||||
} else if tp.kind == PaintKind::Solid {
|
||||
widgets::open_popup(ui, picker_id(key));
|
||||
} else {
|
||||
@@ -376,7 +377,7 @@ fn fill_stroke_options(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Pa
|
||||
tool_options(app, json!({key: c}));
|
||||
paint(app, key, json!(c));
|
||||
}
|
||||
paint_options_popup(app, ui, key, &options, wr.left_bottom());
|
||||
paint_options_popup(app, ui, shape_layers, key, &options, wr.left_bottom());
|
||||
x = sr.max.x + 12.0;
|
||||
}
|
||||
let width = app.session.state.shape_tool.stroke_width;
|
||||
@@ -389,9 +390,28 @@ fn fill_stroke_options(app: &mut EffectcraftApp, ui: &mut egui::Ui, p: &egui::Pa
|
||||
r.max.x + 14.0
|
||||
}
|
||||
|
||||
/// A Fill or Stroke kind: for new shapes, and (as in After Effects) for the selected shape
|
||||
/// layers' fills or strokes, which None switches off (#732).
|
||||
fn paint_kind(app: &mut EffectcraftApp, shape_layers: &[u64], key: &str, kind: PaintKind) {
|
||||
let k_type = format!("{key}Type");
|
||||
tool_options(app, json!({&k_type: kind.id()}));
|
||||
if shape_layers.is_empty() {
|
||||
return;
|
||||
}
|
||||
let mut v = json!({"layers": shape_layers, k_type: kind.id()});
|
||||
// A Solid Color takes the swatch's colour.
|
||||
let color = if key == "fill" { app.session.state.shape_tool.fill.color } else { app.session.state.shape_tool.stroke.color };
|
||||
if let (PaintKind::Solid, Some(o)) = (kind, v.as_object_mut()) {
|
||||
o.insert(key.to_string(), json!(color));
|
||||
}
|
||||
if let Err(e) = app.session.execute("shape.fillStroke", v) {
|
||||
app.ui.status = e.to_string();
|
||||
}
|
||||
}
|
||||
|
||||
/// 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) {
|
||||
fn paint_options_popup(app: &mut EffectcraftApp, ui: &mut egui::Ui, shape_layers: &[u64], key: &str, title: &str, pos: egui::Pos2) {
|
||||
let id = egui::Id::new(("tool-paint-options", key));
|
||||
if !widgets::popup_is_open(ui, id) {
|
||||
return;
|
||||
@@ -400,6 +420,7 @@ fn paint_options_popup(app: &mut EffectcraftApp, ui: &mut egui::Ui, key: &str, t
|
||||
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 kind = 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| {
|
||||
@@ -416,8 +437,7 @@ fn paint_options_popup(app: &mut EffectcraftApp, ui: &mut egui::Ui, key: &str, t
|
||||
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()}));
|
||||
kind = Some(k);
|
||||
}
|
||||
}
|
||||
p.text(row(33.0) + vec2(134.0, 0.0), Align2::LEFT_CENTER, tp.kind.label(), Tokens::ui(11.5), t.text_dim);
|
||||
@@ -451,6 +471,9 @@ fn paint_options_popup(app: &mut EffectcraftApp, ui: &mut egui::Ui, key: &str, t
|
||||
if let Some(v) = set {
|
||||
tool_options(app, v);
|
||||
}
|
||||
if let Some(k) = kind {
|
||||
paint_kind(app, shape_layers, key, k);
|
||||
}
|
||||
}
|
||||
|
||||
/// A Fill or Stroke swatch: its colour, a gradient (white to black), or None's red slash.
|
||||
|
||||
Reference in New Issue
Block a user