mirror of
https://github.com/storytold/AniCraft.git
synced 2026-11-24 03:21:54 +01:00
feat(shell): Attach to Path by picking a shape on the stage, path rows in Properties, the path shown on selection; soft mask and path text screenshots (M4)
This commit is contained in:
1 parent
bdb7515e3c
commit
16a871e7ed
6 files changed
+112
-6
No files matched your search
@@ -1,6 +1,6 @@
|
||||
# Command reference
|
||||
|
||||
Everything you can do in AniCraft is a command: the menus, the shortcuts, the command palette (**Ctrl+K**, macOS **⌘K**), `anicraft-cli` and AI assistants over MCP all run the same 258 commands, listed here by menu. The id is what scripts and [working headless](../working-headless.md) use; the parameters are what a command takes as JSON. Commands that change the document are one undo step each. Your own shortcuts (**F1**) replace the defaults shown here; see the [shortcut reference](shortcuts.md).
|
||||
Everything you can do in AniCraft is a command: the menus, the shortcuts, the command palette (**Ctrl+K**, macOS **⌘K**), `anicraft-cli` and AI assistants over MCP all run the same 262 commands, listed here by menu. The id is what scripts and [working headless](../working-headless.md) use; the parameters are what a command takes as JSON. Commands that change the document are one undo step each. Your own shortcuts (**F1**) replace the defaults shown here; see the [shortcut reference](shortcuts.md).
|
||||
|
||||
This page is generated from the command registry, so it always matches the version of AniCraft it came with.
|
||||
|
||||
@@ -137,7 +137,7 @@ This page is generated from the command registry, so it always matches the versi
|
||||
- **Mask** `layer.toggle_mask` · Modify › Timeline · changes the document
|
||||
Parameters: `{layer?}`
|
||||
- **Layer Properties** `layer.set_properties` · Modify › Timeline · changes the document
|
||||
Parameters: `{layer?, name?, type?: normal|mask|masked|guide|guided, color?, outline?: bool (view as outlines), height?: 100|200|300, visible?, locked?, onion?} sets several at once, as one undo step; answers with the layer's properties`
|
||||
Parameters: `{layer?, name?, type?: normal|mask|masked|guide|guided, mask?: coverage|alpha|luminance (a mask layer's mask type), color?, outline?: bool (view as outlines), height?: 100|200|300, visible?, locked?, onion?} sets several at once, as one undo step; answers with the layer's properties`
|
||||
- **Remove Camera** `camera.remove` · Modify › Timeline · changes the document
|
||||
Parameters: `{} (removes the camera layer and its moves; asks first when the camera is animated)`
|
||||
- **Add Shape Hint** `tween.add_hint` · Modify › Shape · **Ctrl+Shift+H** (macOS **⇧⌘H**) · changes the document
|
||||
@@ -192,6 +192,10 @@ This page is generated from the command registry, so it always matches the versi
|
||||
Parameters: `{}`
|
||||
- **Distribute Vertical Centers** `align.distribute_v` · Modify › Align · changes the document
|
||||
Parameters: `{}`
|
||||
- **Attach Text to Path** `text.attach_path` · Modify › Text · changes the document
|
||||
Parameters: `{path?: element id of a shape (default: the other selected element, a shape), x?, y? (pick the shape at this stage point instead), offset? (px along the path; default by the text's alignment: its start, middle or end), flip?: bool} sets the selected static text along a copy of the shape's outline (its first contour); the shape stays as it is (ADR 0070)`
|
||||
- **Release Text from Path** `text.release_path` · Modify › Text · changes the document
|
||||
Parameters: `{} the selected text on a path goes back to lines of text (ADR 0070)`
|
||||
|
||||
## Commands
|
||||
|
||||
@@ -277,8 +281,10 @@ These commands have no menu item: the panels, the stage and the timeline use the
|
||||
Parameters: `{color: "#rrggbb", layer?} the layer's colour: its outlines in outline mode and its bar on the timeline`
|
||||
- **Layer Height** `layer.set_height` · changes the document
|
||||
Parameters: `{height: 100 | 200 | 300 (percent of a normal row), layer?} the layer's row height on the timeline`
|
||||
- **Mask Type** `layer.set_mask` · changes the document
|
||||
Parameters: `{mask: coverage|alpha|luminance, layer?} how a mask layer reveals the layers it masks: coverage (its fills' area, as in Animate), alpha (its artwork's opacity: gradients and faded shapes make soft edges) or luminance (its brightness: white shows, black hides; SVG's mask) (ADR 0070)`
|
||||
- **Get Layer Properties** `layer.properties`
|
||||
Parameters: `{layer?} the layer's name, type, colour, outline, height (percent), visible, locked and onion`
|
||||
Parameters: `{layer?} the layer's name, type, mask type (mask layers), colour, outline, height (percent), visible, locked and onion`
|
||||
- **Camera** `camera.set` · changes the document
|
||||
Parameters: `{x?, y? (camera centre, stage px), dx?, dy? (pan by), zoom? (%, 5–2000), zoom_by? (factor), rotation? (°), rotate_by? (°), tint? (#rrggbb), tint_amount? (%), reset?: bool, frame?}`
|
||||
- **Camera Info** `camera.info`
|
||||
@@ -497,6 +503,8 @@ These commands have no menu item: the panels, the stage and the timeline use the
|
||||
Parameters: `{text?, font?, size? (px), bold?, italic?, color?, align?: left|center|right, letter_spacing?, line_spacing?, width? (px, wraps; null: one line per paragraph)} on the selected text`
|
||||
- **Fonts** `text.fonts`
|
||||
Parameters: `{}`
|
||||
- **Text on Path** `text.path` · changes the document
|
||||
Parameters: `{offset? (px along the path), flip?: bool (along the path backwards, on its other side), release?: bool (back to lines of text where it starts)} on the selected text on a path (ADR 0070)`
|
||||
- **Text Type** `text.field` · changes the document
|
||||
Parameters: `{type?: static|dynamic|input, lines?: single|multiline|multiline_no_wrap|password (input only), width?, height? (the field's box, px), selectable?, border?, background?, border_color?, background_color?, max_chars? (input; 0: no limit), variable? (kept, not run)} on the selected text; dynamic and input fields are named with instance.set_name and scripted in Test Movie and the HTML export (ADR 0066)`
|
||||
- **Width Profile** `stroke.set_profile` · changes the document
|
||||
|
||||
+1
-1
@@ -374,7 +374,7 @@ mod tests {
|
||||
for tool in [Tool::Bone, Tool::Rect, Tool::Star, Tool::Text, Tool::Pencil, Tool::Brush, Tool::PaintBrush, Tool::Eraser, Tool::PaintBucket, Tool::InkBottle, Tool::Eyedropper, Tool::Pen] {
|
||||
found.extend(check(&format!("{tool:?} tool"), |a, _| a.tool = tool));
|
||||
}
|
||||
for panel in ["select", "motion", "motionspan", "motionpath", "motionpoints", "motionedit", "motionpins", "motionpinsspan", "rawsub", "camera", "cameraview", "bones", "sound", "envelope", "prefs", "shortcuts", "palette", "about", "files", "licenses", "confirm", "recovery", "frames", "actions", "script", "scriptproblems", "testscript", "onion", "onionmenu", "editmultiple", "library", "librarymenu", "edittransform", "onionsymbol", "layerprops", "frameview", "layercolour", "timelinepolish", "convert", "mixed", "bitmap", "nineslice", "nineslicedit", "find", "explorer", "publish", "publishreport", "publishanim", "start", "drop", "droplibrary", "testmovie", "testmovieinside", "templates", "savetemplate", "droptimeline", "textfields", "testtext", "brushlibrary", "brushcurve", "paintbrush"] {
|
||||
for panel in ["select", "motion", "motionspan", "motionpath", "motionpoints", "motionedit", "motionpins", "motionpinsspan", "rawsub", "camera", "cameraview", "bones", "sound", "envelope", "prefs", "shortcuts", "palette", "about", "files", "licenses", "confirm", "recovery", "frames", "actions", "script", "scriptproblems", "testscript", "onion", "onionmenu", "editmultiple", "library", "librarymenu", "edittransform", "onionsymbol", "layerprops", "frameview", "layercolour", "timelinepolish", "convert", "mixed", "bitmap", "nineslice", "nineslicedit", "find", "explorer", "publish", "publishreport", "publishanim", "start", "drop", "droplibrary", "testmovie", "testmovieinside", "templates", "savetemplate", "droptimeline", "textfields", "testtext", "softmask", "pathtext", "brushlibrary", "brushcurve", "paintbrush"] {
|
||||
found.extend(check(panel, |a, _| a.open_panel(Some(panel))));
|
||||
}
|
||||
// Test Movie in a window of its own (ADR 0062): its controls, named in that window.
|
||||
|
||||
+37
@@ -337,6 +337,8 @@ pub struct App {
|
||||
pub library: crate::library::LibraryView,
|
||||
/// Text being typed on the stage.
|
||||
pub text_edit: Option<TextEditing>,
|
||||
/// Attach to Path is waiting for a click on a shape (ADR 0070): the text to set along it.
|
||||
pub path_pick: Option<anicraft_engine::doc::ElementId>,
|
||||
/// Font families on this computer, listed once on first need.
|
||||
pub font_families: Option<Vec<String>>,
|
||||
pub star_points: u32,
|
||||
@@ -584,6 +586,7 @@ impl App {
|
||||
library_sel,
|
||||
library: Default::default(),
|
||||
text_edit: None,
|
||||
path_pick: None,
|
||||
font_families: None,
|
||||
star_points: 5,
|
||||
rect_radius: 0.0,
|
||||
@@ -1309,6 +1312,40 @@ impl App {
|
||||
crate::test_movie::demo_pointer(self);
|
||||
}
|
||||
}
|
||||
Some(which @ ("softmask" | "pathtext")) => {
|
||||
// Soft masks and text on a path (ADR 0070): colour bands seen through a radial
|
||||
// gradient on an alpha mask layer, and a line of text along an oval. `softmask`
|
||||
// opens the mask layer's Layer Properties; `pathtext` selects the text.
|
||||
self.perform("file.new", json!({"width": 640, "height": 400}));
|
||||
self.run("draw.rect", json!({"x": 0, "y": 0, "w": 640, "h": 400, "fill": "#1d3557", "stroke": null}));
|
||||
self.run("layer.new", json!({"name": "Bands"}));
|
||||
for (i, c) in ["#e76f51", "#f4a261", "#e9c46a", "#2a9d8f", "#8ab17d"].iter().enumerate() {
|
||||
self.run("draw.rect", json!({"x": 120 + 80 * i, "y": 40, "w": 80, "h": 320, "fill": c, "stroke": null}));
|
||||
}
|
||||
let mask = self.run("layer.new", json!({"name": "Soft mask"})).and_then(|v| v["layer"].as_u64());
|
||||
let stops = vec![anicraft_engine::doc::GradientStop { offset: 0.0, color: anicraft_engine::doc::Rgba::WHITE }, anicraft_engine::doc::GradientStop { offset: 1.0, color: anicraft_engine::doc::Rgba::WHITE.with_alpha(0.0) }];
|
||||
let swatch = std::mem::replace(&mut self.s.style.fill_paint, Some(anicraft_engine::doc::Paint::Radial { center: anicraft_engine::geom::Vec2::new(320.0, 200.0), radius: 190.0, stops }));
|
||||
self.run("draw.ellipse", json!({"x": 130, "y": 10, "w": 380, "h": 380, "stroke": null}));
|
||||
self.s.style.fill_paint = swatch;
|
||||
self.run("layer.toggle_mask", json!({}));
|
||||
self.run("layer.set_mask", json!({"mask": "alpha"}));
|
||||
self.run("layer.new", json!({"name": "Title"}));
|
||||
// i18n-exempt: document content
|
||||
let text = self.run("text.create", json!({"text": "Soft masks · text on a path", "x": 40, "y": 40, "size": 26, "color": "#f1faee", "align": "center"})).and_then(|v| v["element"].as_u64());
|
||||
let oval = self.run("draw.ellipse", json!({"x": 70, "y": 25, "w": 500, "h": 350, "fill": null, "stroke": "#f1faee", "stroke_width": 1})).and_then(|v| v["element"].as_u64());
|
||||
if let (Some(t), Some(o)) = (text, oval) {
|
||||
self.run("element.select", json!({"ids": [t]}));
|
||||
self.run("text.attach_path", json!({"path": o, "offset": 1080}));
|
||||
self.run("element.select", json!({"ids": [o]}));
|
||||
self.run("edit.delete", json!({}));
|
||||
self.run("element.select", json!({"ids": [t]}));
|
||||
}
|
||||
if which == "softmask"
|
||||
&& let Some(m) = mask
|
||||
{
|
||||
crate::layer_props::open(self, Some(anicraft_engine::doc::LayerId(m)));
|
||||
}
|
||||
}
|
||||
Some(which @ ("textfields" | "testtext")) => {
|
||||
// Dynamic and input text fields (ADR 0066): a score a script sets, a name field
|
||||
// and a multiline notes field. `textfields` selects the name field for its
|
||||
|
||||
+1
-1
@@ -226,7 +226,7 @@ fn parse_args(args: impl IntoIterator<Item = String>) -> Result<Args, String> {
|
||||
/// `--help` (the console's text, in English).
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
// i18n-exempt: the --help console text
|
||||
const HELP: &str = "anicraft [file.anicraft|file.fla|file.xfl] [--version] [--screenshot out.png [--shot-width <px>]] [--renderer wgpu|gl] [--theme graphite|high-contrast] [--scale <percent>] [--lang <code>|auto|pseudo] [--open palette|shortcuts|lastscene|start|drop|droplibrary|select|about|files|confirm|transform|points|merge|rawparts|rawedit|rawsub|rawpoints|rawsnap|symboledit|nineslice|nineslicedit|brush|brushing|brushlibrary|brushcurve|paintbrush|eraser|erasing|eyedropper|pen|frames|span|bucket|tlzoom|tlwide|motion|motionspan|motionpath|motionpoints|motionedit|motionpins|motionpinsspan|hints|hintsend|camera|cameraview|filters|strokes|prefs|licenses|zoom|recovery|plugins|actions|script|scriptproblems|testmovie|testmovieinside|testscript|textfields|testtext|button|testhits|exporthtml|publish|publishreport|publishanim|sound|envelope|library|librarymenu|colour|layerprops|frameview|layercolour|timelinepolish]\n\
|
||||
const HELP: &str = "anicraft [file.anicraft|file.fla|file.xfl] [--version] [--screenshot out.png [--shot-width <px>]] [--renderer wgpu|gl] [--theme graphite|high-contrast] [--scale <percent>] [--lang <code>|auto|pseudo] [--open palette|shortcuts|lastscene|start|drop|droplibrary|select|about|files|confirm|transform|points|merge|rawparts|rawedit|rawsub|rawpoints|rawsnap|symboledit|nineslice|nineslicedit|brush|brushing|brushlibrary|brushcurve|paintbrush|eraser|erasing|eyedropper|pen|frames|span|bucket|tlzoom|tlwide|motion|motionspan|motionpath|motionpoints|motionedit|motionpins|motionpinsspan|hints|hintsend|camera|cameraview|filters|strokes|prefs|licenses|zoom|recovery|plugins|actions|script|scriptproblems|testmovie|testmovieinside|testscript|textfields|testtext|softmask|pathtext|button|testhits|exporthtml|publish|publishreport|publishanim|sound|envelope|library|librarymenu|colour|layerprops|frameview|layercolour|timelinepolish]\n\
|
||||
--renderer force the GPU backend (also ANICRAFT_RENDERER); default wgpu, falling back to OpenGL\n\
|
||||
--open shows a panel at start (handy with --screenshot for visual checks)\n\
|
||||
--shot-width scales the screenshot down to this width (the user guide's pictures)\n\
|
||||
|
||||
+40
-1
@@ -3,7 +3,7 @@
|
||||
use crate::app::{App, Tool};
|
||||
use crate::icons::{self, Icon};
|
||||
use crate::theme::{Section, T, TARGET, TOOL_BUTTON, TOOL_ICON, Type, color, section, text, to_color32, with_type};
|
||||
use anicraft_engine::doc::{ColorEffect, ColorStyle, ElementKind, LibraryItem, LineType, Paint, Rgba, SymbolKind, TextKind, evaluate_layer_elements};
|
||||
use anicraft_engine::doc::{ColorEffect, ColorStyle, ElementKind, LibraryItem, LineType, MAX_PATH_OFFSET, Paint, Rgba, SymbolKind, TextKind, evaluate_layer_elements};
|
||||
use crate::a11y::{self, Named};
|
||||
use egui::{Color32, Pos2, Rect, Sense, Stroke, StrokeKind, WidgetType, pos2, vec2};
|
||||
use serde_json::{Value, json};
|
||||
@@ -795,6 +795,7 @@ fn selection_props(app: &mut App, ui: &mut egui::Ui, e: &anicraft_engine::doc::E
|
||||
app.text_edit = Some(crate::app::TextEditing { at: pos2(at.x, at.y), element: Some(e.id), text: t.text.clone(), original: t.text.clone(), focus: true });
|
||||
}
|
||||
});
|
||||
text_path_rows(app, ui, e, t);
|
||||
}
|
||||
if let ElementKind::Shape(sh) = &e.kind {
|
||||
ui.add_space(4.0);
|
||||
@@ -882,6 +883,44 @@ fn bitmap_row(app: &mut App, ui: &mut egui::Ui, current: anicraft_engine::doc::B
|
||||
});
|
||||
}
|
||||
|
||||
/// Text on a path (ADR 0070): Attach to Path (then a click on a shape) for static text; for text
|
||||
/// on a path, where it sits along it, its side, and Release.
|
||||
fn text_path_rows(app: &mut App, ui: &mut egui::Ui, e: &anicraft_engine::doc::Element, t: &anicraft_engine::doc::TextBlock) {
|
||||
if t.field.is_some() {
|
||||
return;
|
||||
}
|
||||
let Some(on) = &t.on_path else {
|
||||
row_prose(ui, tr!("Path"), |ui| {
|
||||
let waiting = app.path_pick == Some(e.id);
|
||||
let label = if waiting { tr!("Click a shape…") } else { tr!("Attach to Path") };
|
||||
if ui.selectable_label(waiting, label).on_hover_text(tr!("Then click a shape on the stage: the text follows its outline (Esc cancels)")).clicked() {
|
||||
if waiting {
|
||||
app.path_pick = None;
|
||||
} else {
|
||||
app.path_pick = Some(e.id);
|
||||
app.status_ok(tr!("Click a shape to set the text along its outline. Esc cancels."));
|
||||
}
|
||||
}
|
||||
});
|
||||
return;
|
||||
};
|
||||
let mut offset = on.offset;
|
||||
row(ui, tr!("Path"), |ui| {
|
||||
if ui.add(egui::DragValue::new(&mut offset).prefix(format!("{} ", tr!("Offset"))).suffix(" px").speed(0.5).range(-MAX_PATH_OFFSET..=MAX_PATH_OFFSET).max_decimals(1)).named(tr!("Offset along the path")).on_hover_text(tr!("Where the text sits along the path: its alignment decides whether it starts, is centred or ends there")).changed() {
|
||||
live(app, tr_noop!("Text on Path"), "text.path", json!({"offset": offset}));
|
||||
}
|
||||
});
|
||||
row_prose(ui, tr!("Side"), |ui| {
|
||||
let mut flip = on.flip;
|
||||
if crate::theme::checkbox(ui, &mut flip, tr!("Flip")).on_hover_text(tr!("Run the text along the path the other way, on its other side")).changed() {
|
||||
app.run("text.path", json!({"flip": flip}));
|
||||
}
|
||||
if ui.button(tr!("Release")).on_hover_text(tr!("Back to lines of text, where the text starts")).clicked() {
|
||||
app.run("text.release_path", json!({}));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// A text type's name, as the Properties panel shows it.
|
||||
pub(crate) fn text_kind_label(kind: TextKind) -> &'static str {
|
||||
match kind {
|
||||
|
||||
@@ -633,11 +633,22 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) {
|
||||
app.snap_ring = None;
|
||||
}
|
||||
|
||||
// Attach to Path (ADR 0070) waits for a click on a shape; Escape gives up.
|
||||
if app.path_pick.is_some() && ui.input(|i| i.key_pressed(egui::Key::Escape)) {
|
||||
app.path_pick = None;
|
||||
app.status_ok(tr!("Attach to Path cancelled."));
|
||||
}
|
||||
if resp.clicked()
|
||||
&& !paused
|
||||
&& let Some(p) = resp.interact_pointer_pos() {
|
||||
let sp = to_stage(p);
|
||||
match app.tool {
|
||||
_ if !panning && let Some(text) = app.path_pick.take() => {
|
||||
app.s.selection = anicraft_engine::Selection::only(app.s.layer, [text]);
|
||||
if app.run("text.attach_path", json!({"x": sp.x, "y": sp.y})).is_some() {
|
||||
app.status_ok(tr!("The text follows the shape's outline. {undo} to undo.", undo = app.undo_key()));
|
||||
}
|
||||
}
|
||||
Tool::Subselect if !panning => {
|
||||
if !crate::motion_path::click(app, p, xf, shift) {
|
||||
crate::pathtools::subselect_click(app, p, shift, xf);
|
||||
@@ -1017,6 +1028,17 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) {
|
||||
continue;
|
||||
}
|
||||
painter.rect_stroke(r, 0.0, sel_stroke, StrokeKind::Middle);
|
||||
// Text on a path shows the path it follows (ADR 0070).
|
||||
if let anicraft_engine::doc::ElementKind::Text(t) = &e.kind
|
||||
&& let Some(on) = &t.on_path
|
||||
&& let Some(item) = app.s.display_list().items.iter().find(|i| i.element == id)
|
||||
{
|
||||
let to_px = Affine::translate(origin.x, origin.y).mul(&Affine::scale(zoom, zoom)).mul(&item.transform);
|
||||
for pl in on.path.flatten(&to_px, 0.5) {
|
||||
let pts: Vec<Pos2> = pl.points.iter().map(|p| pos2(p.x, p.y)).collect();
|
||||
painter.add(if pl.closed { egui::Shape::closed_line(pts, sel_stroke) } else { egui::Shape::line(pts, sel_stroke) });
|
||||
}
|
||||
}
|
||||
for c in [r.left_top(), r.right_top(), r.left_bottom(), r.right_bottom(), r.center_top(), r.center_bottom(), r.left_center(), r.right_center()] {
|
||||
let h = Rect::from_center_size(c, vec2(6.0, 6.0));
|
||||
painter.rect_filled(h, 0.0, Color32::WHITE);
|
||||
|
||||
Reference in new issue
Block a user