diff --git a/crates/engine/src/cmds_draw.rs b/crates/engine/src/cmds_draw.rs index db1cf314..9880fa9e 100644 --- a/crates/engine/src/cmds_draw.rs +++ b/crates/engine/src/cmds_draw.rs @@ -50,7 +50,7 @@ pub fn specs() -> Vec { c("arrange.send_backward", "Send Backward", "Modify/Arrange", Some("Ctrl+Down"), "{} (within each layer)", true, |s, _| s.each_layer(true, |s| arrange_step(s, false))), c("arrange.send_to_back", "Send to Back", "Modify/Arrange", Some("Ctrl+Shift+Down"), "{} (within each layer)", true, |s, _| s.each_layer(true, |s| arrange(s, false))), c("modify.convert_to_symbol", "Convert to Symbol…", "Modify", Some("F8"), "{name? (default: the next free “Symbol n”; a name the folder holds gets a number), kind?: graphic|movie_clip|button (default: graphic), folder?: Library folder id (default: the top level)} → {symbol, instance, name, layer, folder} (a selection on several layers becomes one symbol with those layers inside; the instance lands on the topmost)", true, convert_to_symbol), - c("modify.break_apart", "Break Apart", "Modify", Some("Ctrl+B"), "{}", true, |s, p| s.each_layer(false, |s| break_apart(s, p))), + c("modify.break_apart", "Break Apart", "Modify", Some("Ctrl+B"), "{} the selected symbol instances become their contents, text becomes shapes, and drawing objects become raw shapes that merge with the raw shapes they touch", true, |s, p| s.each_layer(false, |s| break_apart(s, p))), c("library.place", "Place on Stage", "", None, "{symbol | bitmap | sound: id, x?, y?} or {items: [{symbol | bitmap | sound: id}, ..], x?, y?} → {element, elements, sound?}: symbols and bitmaps centred on x, y (default: the stage centre; inside an open symbol, in its space) in the active layer's keyframe at the playhead, selected; a sound goes onto that keyframe, its span grown to fit (one sound per keyframe). One undo step", true, place), ] } @@ -873,7 +873,21 @@ fn break_apart(s: &mut Session, _: &Value) -> Result { let mut fresh_ids = Vec::new(); let kf_elements: Vec> = s.editable_keyframe()?.elements.clone(); let mut out = Vec::new(); + // Drawing objects (Object Drawing) break apart into raw shapes, which then merge with the + // raw shapes they touch, as in Animate (#253). + let mut objects = Vec::new(); for e in kf_elements { + if let ElementKind::Shape(sh) = &e.kind + && !sh.merge + && sel.contains(&e.id) + { + let mut c = (*e).clone(); + if let ElementKind::Shape(sh) = &mut c.kind { + sh.merge = true; + } + objects.push(c); + continue; + } // Text breaks apart into a shape with the same outlines. if let ElementKind::Text(t) = &e.kind && sel.contains(&e.id) @@ -908,10 +922,13 @@ fn break_apart(s: &mut Session, _: &Value) -> Result { } } } - if fresh_ids.is_empty() { - return Err(EngineError::State("the selection has no symbol instances or text to break apart".into())); + if fresh_ids.is_empty() && objects.is_empty() { + return Err(EngineError::State("the selection has no symbol instances, text or drawing objects to break apart".into())); } s.editable_keyframe()?.elements = out; + if !objects.is_empty() { + fresh_ids.extend(crate::merge::merge_in(s, objects)?); + } s.select_only(fresh_ids.iter().copied()); Ok(json!({"created": fresh_ids.len()})) } diff --git a/crates/engine/src/selection_tests.rs b/crates/engine/src/selection_tests.rs index f701857c..5ace4650 100644 --- a/crates/engine/src/selection_tests.rs +++ b/crates/engine/src/selection_tests.rs @@ -375,6 +375,41 @@ fn break_apart_works_on_each_layer() { assert_eq!(s.selected_layers(), vec![top, bottom]); } +/// #253: a drawing object (Object Drawing) breaks apart into raw shapes that merge with the raw +/// drawing they touch, so it can be edited as a merged shape again; one undo step brings the +/// object back. +#[test] +fn break_apart_turns_a_drawing_object_into_raw_shapes() { + let mut s = Session::default(); + s.style.object_drawing = false; + run(&mut s, "draw.rect", json!({"x": 0, "y": 0, "w": 100, "h": 100, "fill": "#00ff00", "stroke": null})); + let raw = s.visible_elements().len(); + let obj = el_id(&run(&mut s, "draw.rect", json!({"x": 50, "y": 50, "w": 100, "h": 100, "fill": "#ff0000", "stroke": null, "object": true}))); + let squiggle = el_id(&run(&mut s, "draw.freehand", json!({"points": [[300, 0], [320, 30], [340, 0], [360, 30]], "object": true}))); + let shapes = |s: &Session| -> Vec<(ElementId, bool)> { + s.visible_elements().iter().filter_map(|e| match &e.kind { + ElementKind::Shape(sh) => Some((e.id, sh.merge)), + _ => None, + }).collect() + }; + assert!(shapes(&s).iter().filter(|(id, _)| [obj, squiggle].contains(id)).all(|(_, m)| !m), "drawn as objects"); + let before = s.doc.clone(); + let steps = s.history_len(); + run(&mut s, "element.select", json!({"ids": [obj.0, squiggle.0]})); + let v = run(&mut s, "modify.break_apart", json!({})); + assert!(v["created"].as_u64().unwrap() >= 2, "{v}"); + assert!(shapes(&s).iter().all(|(_, m)| *m), "every shape is raw now: {:?}", shapes(&s)); + assert!(!shapes(&s).iter().any(|(id, _)| *id == obj), "the object merged into the drawing"); + assert!(s.visible_elements().len() > raw + 1, "the red square cut the green one"); + assert!(!s.selection.is_empty(), "what came out of it is selected"); + assert_eq!(s.history_len(), steps + 1); + s.undo().unwrap(); + assert!(s.doc == before, "one undo brings the objects back"); + // Nothing to break apart: an error, not a no-op step. + run(&mut s, "edit.deselect", json!({})); + assert!(s.execute("modify.break_apart", &json!({})).is_err()); +} + // ----- the marquee across layers with raw parts (ADR 0041) ------------------------------------ /// Raw squares on two layers: Top's 0..100, Bottom's 200..300 (both 0..100 high). diff --git a/src/panels.rs b/src/panels.rs index 612e2395..bc8bce86 100644 --- a/src/panels.rs +++ b/src/panels.rs @@ -1840,6 +1840,12 @@ fn sound_rows(app: &mut App, ui: &mut egui::Ui, current: Option bool { + matches!(tool, Tool::InkBottle | Tool::PaintBrush | Tool::Pencil | Tool::Line) +} + fn tool_props(app: &mut App, ui: &mut egui::Ui) { if app.tool == Tool::Eraser { eraser_props(app, ui); @@ -1854,10 +1860,10 @@ fn tool_props(app: &mut App, ui: &mut egui::Ui) { return; } let mut st = app.s.style.clone(); - // Each tool shows only what it uses: the bucket and the brush always fill, the ink bottle - // always strokes. + // Each tool shows only what it uses: the bucket and the brush always fill; the ink bottle, + // the Pencil and the Line tool always stroke and never fill (#252). // The Paint Brush (ADR 0068) draws in the stroke colour at its own size and profile. - let (fills, ink) = (matches!(app.tool, Tool::PaintBucket | Tool::Brush), matches!(app.tool, Tool::InkBottle | Tool::PaintBrush)); + let (fills, ink) = (matches!(app.tool, Tool::PaintBucket | Tool::Brush), stroke_only(app.tool)); let brush_line = app.tool == Tool::PaintBrush; if !ink { row(ui, tr!("Fill"), |ui| { @@ -2247,3 +2253,27 @@ fn library(app: &mut App, ui: &mut egui::Ui) { let r = ui.scope(|ui| crate::library::panel(app, ui)).response.rect; app.library.drop_zone.panel = Some(r); } + +#[cfg(test)] +mod tests { + use super::*; + + /// #252: the Pencil and the Line tool never fill, whatever the fill swatch says, so their + /// Properties show no Fill row; the Pen and the shape tools still fill. + #[test] + fn stroke_only_tools_never_fill() { + let mut s = anicraft_engine::Session::default(); + s.style.use_fill = true; + let pts: Vec<[f32; 2]> = (0..20).map(|i| [i as f32 * 5.0, (i % 4) as f32 * 6.0]).collect(); + // A loop back to where it began, too. + let loop_pts: Vec<[f32; 2]> = (0..=24).map(|i| { let a = i as f32 / 24.0 * std::f32::consts::TAU; [200.0 + 40.0 * a.cos(), 200.0 + 40.0 * a.sin()] }).collect(); + for (id, p) in [("draw.freehand", json!({"points": pts})), ("draw.freehand", json!({"points": loop_pts})), ("draw.line", json!({"x0": 0, "y0": 0, "x1": 90, "y1": 40}))] { + s.execute(id, &p).expect("drawn"); + } + assert!(s.visible_elements().iter().all(|e| matches!(&e.kind, ElementKind::Shape(sh) if sh.fill.is_none() && sh.stroke.is_some()))); + assert!(stroke_only(Tool::Pencil) && stroke_only(Tool::Line) && stroke_only(Tool::InkBottle) && stroke_only(Tool::PaintBrush)); + for t in [Tool::Pen, Tool::Rect, Tool::Oval, Tool::Star, Tool::Brush, Tool::PaintBucket] { + assert!(!stroke_only(t), "{t:?} fills"); + } + } +}