mirror of
https://github.com/storytold/AniCraft.git
synced 2026-11-21 18:12:28 +01:00
fix(stage): drawing tools leave nothing selected, and the selection box has no dead handles (M1)
This commit is contained in:
1 parent
df49c9d1c7
commit
e1f6d12db6
4 files changed
+53
-13
No files matched your search
@@ -713,6 +713,15 @@ impl App {
|
||||
}
|
||||
}
|
||||
|
||||
/// Runs a drawing tool's command and leaves nothing selected, as Animate's drawing tools
|
||||
/// do: the next stroke goes on without a box around the last one (#205, #243). The command
|
||||
/// itself selects what it drew, for scripts that style it next.
|
||||
pub fn draw(&mut self, id: &str, params: Value) -> Option<Value> {
|
||||
let v = self.run(id, params)?;
|
||||
let _ = self.s.execute("edit.deselect", &json!({}));
|
||||
Some(v)
|
||||
}
|
||||
|
||||
pub fn run(&mut self, id: &str, params: Value) -> Option<Value> {
|
||||
let result = self.s.execute(id, ¶ms);
|
||||
if platform::WEB && id.starts_with("file.") {
|
||||
|
||||
+2
-2
@@ -256,14 +256,14 @@ pub fn commit(app: &mut App, xf: Xf) {
|
||||
params["unit"] = json!(xf.unit());
|
||||
params["as_stroke"] = json!(as_stroke);
|
||||
if as_stroke {
|
||||
if let Some(v) = app.run("draw.brush", params)
|
||||
if let Some(v) = app.draw("draw.brush", params)
|
||||
&& v["width_points"].as_u64().is_some_and(|n| n > 1)
|
||||
{
|
||||
app.status_ok(tr!("A line whose width you can shape with the Width tool."));
|
||||
}
|
||||
return;
|
||||
}
|
||||
if let Some(v) = app.run("draw.brush", params)
|
||||
if let Some(v) = app.draw("draw.brush", params)
|
||||
&& v["elements"].as_array().is_some_and(Vec::is_empty)
|
||||
{
|
||||
app.status_ok(tr!("Nothing to paint behind there: Paint Behind only paints empty areas."));
|
||||
|
||||
+2
-2
@@ -141,7 +141,7 @@ pub fn commit_pen(app: &mut App, closed: bool) {
|
||||
if pen.knots.len() < 2 {
|
||||
return;
|
||||
}
|
||||
app.run("draw.path", json!({"d": pen.to_svg(closed)}));
|
||||
app.draw("draw.path", json!({"d": pen.to_svg(closed)}));
|
||||
}
|
||||
|
||||
// ----- Pencil ------------------------------------------------------------------------------
|
||||
@@ -195,7 +195,7 @@ pub fn commit_pencil(app: &mut App, xf: Xf) {
|
||||
return;
|
||||
}
|
||||
let points: Vec<[f32; 2]> = pts.iter().map(|p| [p.x, p.y]).collect();
|
||||
app.run("draw.freehand", json!({"points": points, "mode": app.pencil_mode.id(), "tolerance": 1.5 * xf.unit()}));
|
||||
app.draw("draw.freehand", json!({"points": points, "mode": app.pencil_mode.id(), "tolerance": 1.5 * xf.unit()}));
|
||||
}
|
||||
|
||||
// ----- Subselection --------------------------------------------------------------------------
|
||||
|
||||
+40
-9
@@ -1020,12 +1020,9 @@ pub fn show(app: &mut App, ui: &mut egui::Ui) {
|
||||
painter.rect_stroke(r, 0.0, Stroke::new(1.0, T.selection.gamma_multiply(0.45)), StrokeKind::Middle);
|
||||
continue;
|
||||
}
|
||||
// A plain box, as Animate's Selection tool shows: handles are Free Transform's (Q),
|
||||
// where they work. Handles drawn here could not be dragged (#205).
|
||||
painter.rect_stroke(r, 0.0, sel_stroke, StrokeKind::Middle);
|
||||
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);
|
||||
painter.rect_stroke(h, 0.0, sel_stroke, StrokeKind::Middle);
|
||||
}
|
||||
// registration point
|
||||
let o = to_screen(e.transform.translation());
|
||||
painter.circle(o, 3.5, Color32::WHITE, Stroke::new(1.0, Color32::BLACK));
|
||||
@@ -1509,17 +1506,17 @@ fn create_shape(app: &mut App, start: Pos2, cur: Pos2) {
|
||||
}
|
||||
match app.tool {
|
||||
Tool::Rect => {
|
||||
app.run("draw.rect", json!({"x": start.x, "y": start.y, "w": d.x, "h": d.y, "radius": app.rect_radius}));
|
||||
app.draw("draw.rect", json!({"x": start.x, "y": start.y, "w": d.x, "h": d.y, "radius": app.rect_radius}));
|
||||
}
|
||||
Tool::Oval => {
|
||||
app.run("draw.ellipse", json!({"x": start.x, "y": start.y, "w": d.x, "h": d.y}));
|
||||
app.draw("draw.ellipse", json!({"x": start.x, "y": start.y, "w": d.x, "h": d.y}));
|
||||
}
|
||||
Tool::Star => {
|
||||
let r = d.length();
|
||||
app.run("draw.star", json!({"cx": start.x, "cy": start.y, "outer": r, "inner": r * 0.45, "points": app.star_points}));
|
||||
app.draw("draw.star", json!({"cx": start.x, "cy": start.y, "outer": r, "inner": r * 0.45, "points": app.star_points}));
|
||||
}
|
||||
Tool::Line => {
|
||||
app.run("draw.line", json!({"x0": start.x, "y0": start.y, "x1": cur.x, "y1": cur.y}));
|
||||
app.draw("draw.line", json!({"x0": start.x, "y0": start.y, "x1": cur.x, "y1": cur.y}));
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
@@ -1565,6 +1562,40 @@ fn draw_preview(app: &App, painter: &egui::Painter, a: Pos2, b: Pos2, zoom: f32)
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod draw_tests {
|
||||
use super::*;
|
||||
|
||||
fn app() -> App {
|
||||
let ctx = egui::Context::default();
|
||||
App::with_context(&ctx, anicraft_engine::Session::new(anicraft_engine::doc::Document::default()), Some(std::path::PathBuf::from("unused.png")))
|
||||
}
|
||||
|
||||
/// #205, #243: a shape or a line drawn with a tool leaves nothing selected (no box around
|
||||
/// the last stroke), in merge drawing and in Object Drawing, and the previous selection
|
||||
/// goes too, as in Animate. Undo still takes the shape away in one step.
|
||||
#[test]
|
||||
fn drawing_tools_leave_nothing_selected() {
|
||||
for object in [false, true] {
|
||||
let mut app = app();
|
||||
app.s.style.object_drawing = object;
|
||||
for tool in [Tool::Line, Tool::Rect, Tool::Oval, Tool::Star] {
|
||||
app.tool = tool;
|
||||
let before = app.s.history_len();
|
||||
create_shape(&mut app, pos2(10.0, 10.0), pos2(80.0, 60.0));
|
||||
assert_eq!(app.s.history_len(), before + 1, "{tool:?} drew");
|
||||
assert!(app.s.selection.is_empty(), "{tool:?}, object {object}: nothing selected");
|
||||
}
|
||||
app.pencil = (0..20).map(|i| Vec2::new(100.0 + i as f32 * 4.0, 100.0 + (i % 3) as f32)).collect();
|
||||
crate::pathtools::commit_pencil(&mut app, crate::pathtools::Xf { origin: Pos2::ZERO, zoom: 1.0 });
|
||||
assert!(app.s.selection.is_empty(), "Pencil, object {object}");
|
||||
let n = app.s.visible_elements().len();
|
||||
app.s.undo().expect("undo");
|
||||
assert!(app.s.visible_elements().len() < n, "one undo takes the stroke away");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod xf_tests {
|
||||
use super::*;
|
||||
|
||||
Reference in new issue
Block a user