mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
Merge approved PhotoCraft PR #8986: Path tools: edit the saved path selected in the Paths panel (#8478)
Port behavior and regression coverage into current modules; preserve current upstream behavior. Combined selected saved paths with current Type Path and targeted-mask editing; retained hidden Work Path exclusion independently of saved-path targeting, registered saved-path regressions and current modular overlay routing.
This commit is contained in:
commit
eab48af082
7 files changed
+242
-15
No files matched your search
@@ -852,3 +852,6 @@ mod browse_field_tests;
|
||||
mod options_hit_area_tests;
|
||||
#[cfg(test)]
|
||||
mod select_and_mask_button_tests;
|
||||
|
||||
#[cfg(test)]
|
||||
mod saved_path_edit_tests;
|
||||
@@ -0,0 +1,192 @@
|
||||
//! #8478: the saved path selected in the Paths panel is Photoshop's target path, and Path
|
||||
//! Selection, Direct Selection and the anchor tools edit it, as they edit the work path. It was
|
||||
//! drawn (#6550) but none of the tools picked it, so a path that arrived in a PSD ("Path 1") could
|
||||
//! not be selected or changed.
|
||||
|
||||
use egui::Modifiers;
|
||||
use photocraft_doc::vector::Path;
|
||||
use photocraft_geom::Point;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::canvas::{ToolEvent, tool_event};
|
||||
use crate::direct_select::PathRef;
|
||||
use crate::state::Tool;
|
||||
|
||||
const NAME: &str = "Path 1";
|
||||
|
||||
fn app(tool: Tool) -> PhotocraftApp {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.session.execute("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app.sync_views();
|
||||
app.ui.tool = tool;
|
||||
app
|
||||
}
|
||||
|
||||
fn square(x: f64, y: f64, w: f64) -> serde_json::Value {
|
||||
json!({"subpaths": [{"closed": true, "knots": [[x, y], [x + w, y], [x + w, y + w], [x, y + w]]}]})
|
||||
}
|
||||
|
||||
/// A saved path, a square from (40, 40) to (120, 120), selected in the Paths panel.
|
||||
fn with_saved_path(app: &mut PhotocraftApp) {
|
||||
app.run("path.set", json!({"name": NAME, "path": square(40.0, 40.0, 80.0)})).unwrap();
|
||||
app.ui.selected_path = Some(NAME.into());
|
||||
}
|
||||
|
||||
fn saved(app: &PhotocraftApp) -> Path {
|
||||
app.session.active().unwrap().doc.paths.iter().find(|p| p.name == NAME).unwrap().path.clone()
|
||||
}
|
||||
|
||||
fn anchors(p: &Path) -> Vec<Point> {
|
||||
p.subpaths.iter().flat_map(|s| s.knots.iter().map(|k| k.anchor)).collect()
|
||||
}
|
||||
|
||||
fn steps(app: &PhotocraftApp) -> usize {
|
||||
app.session.active().unwrap().history.entries().len()
|
||||
}
|
||||
|
||||
fn drag(app: &mut PhotocraftApp, from: [f64; 2], to: [f64; 2], mods: Modifiers) {
|
||||
tool_event(app, ToolEvent::Down { x: from[0], y: from[1], pressure: 1.0 }, mods);
|
||||
let mid = [(from[0] + to[0]) / 2.0, (from[1] + to[1]) / 2.0];
|
||||
tool_event(app, ToolEvent::Move { x: mid[0], y: mid[1], pressure: 1.0 }, mods);
|
||||
tool_event(app, ToolEvent::Move { x: to[0], y: to[1], pressure: 1.0 }, mods);
|
||||
tool_event(app, ToolEvent::Up { x: to[0], y: to[1] }, mods);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn direct_selection_drags_an_anchor_of_the_selected_saved_path() {
|
||||
let mut app = app(Tool::DirectSelection);
|
||||
with_saved_path(&mut app);
|
||||
let (before, n) = (saved(&app), steps(&app));
|
||||
drag(&mut app, [120.5, 120.5], [130.5, 135.5], Modifiers::NONE);
|
||||
let after = saved(&app);
|
||||
assert_eq!(after.subpaths[0].knots[2].anchor, Point::new(130.0, 135.0), "the dragged anchor moved");
|
||||
assert_eq!(after.subpaths[0].knots[0].anchor, Point::new(40.0, 40.0), "the others stay");
|
||||
assert_eq!(steps(&app), n + 1, "one history step");
|
||||
assert_eq!((app.ui.direct_selection.target, app.ui.direct_selection.anchors.clone()), (Some(PathRef::Saved(0)), vec![[0, 2]]));
|
||||
assert!(app.session.active().unwrap().doc.work_path.is_none(), "no work path was made");
|
||||
assert!(app.session.undo());
|
||||
assert_eq!(saved(&app), before);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn direct_selection_marquee_selects_and_arrow_params_name_the_saved_path() {
|
||||
let mut app = app(Tool::DirectSelection);
|
||||
with_saved_path(&mut app);
|
||||
drag(&mut app, [30.0, 30.0], [50.0, 50.0], Modifiers::NONE);
|
||||
assert_eq!((app.ui.direct_selection.target, app.ui.direct_selection.anchors.clone()), (Some(PathRef::Saved(0)), vec![[0, 0]]));
|
||||
assert_eq!(PathRef::Saved(0).params(&app), json!({"name": NAME}));
|
||||
// A path that is gone gets no name, which the engine refuses instead of editing another one.
|
||||
assert_eq!(PathRef::Saved(7).params(&app), json!({"name": ""}));
|
||||
assert!(app.run("path.moveAnchors", json!({"name": "", "anchors": [[0, 0]], "move": [1, 1]})).is_err());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_saved_path_is_only_edited_while_the_paths_panel_selects_it() {
|
||||
let mut app = app(Tool::DirectSelection);
|
||||
with_saved_path(&mut app);
|
||||
app.ui.selected_path = None;
|
||||
let before = saved(&app);
|
||||
drag(&mut app, [120.5, 120.5], [130.5, 135.5], Modifiers::NONE);
|
||||
assert_eq!(saved(&app), before, "an unselected saved path is not the target path");
|
||||
assert!(!crate::direct_select::active_paths(&app).iter().any(|(r, _)| matches!(r, PathRef::Saved(_))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_selected_saved_path_comes_before_the_work_path() {
|
||||
let mut app = app(Tool::DirectSelection);
|
||||
with_saved_path(&mut app);
|
||||
// A work path on top of the same square: the saved path the panel selects wins.
|
||||
app.run("path.set", json!({"name": "work", "path": square(40.0, 40.0, 80.0)})).unwrap();
|
||||
let work = app.session.active().unwrap().doc.work_path.clone().unwrap();
|
||||
let refs: Vec<PathRef> = crate::direct_select::active_paths(&app).into_iter().map(|(r, _)| r).collect();
|
||||
assert_eq!(refs, vec![PathRef::Saved(0), PathRef::Work]);
|
||||
drag(&mut app, [40.5, 40.5], [20.5, 30.5], Modifiers::NONE);
|
||||
assert_eq!(saved(&app).subpaths[0].knots[0].anchor, Point::new(20.0, 30.0));
|
||||
assert_eq!(app.session.active().unwrap().doc.work_path.clone().unwrap(), work, "the work path is untouched");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn path_selection_moves_the_selected_saved_path() {
|
||||
let mut app = app(Tool::PathSelection);
|
||||
with_saved_path(&mut app);
|
||||
let n = steps(&app);
|
||||
drag(&mut app, [80.0, 40.0], [90.0, 55.0], Modifiers::NONE);
|
||||
assert_eq!(
|
||||
anchors(&saved(&app)),
|
||||
vec![Point::new(50.0, 55.0), Point::new(130.0, 55.0), Point::new(130.0, 135.0), Point::new(50.0, 135.0)],
|
||||
"the whole path moved by (10, 15)"
|
||||
);
|
||||
assert_eq!(steps(&app), n + 1);
|
||||
assert!(app.session.active().unwrap().doc.work_path.is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn free_transform_path_names_the_selected_saved_path() {
|
||||
let mut app = app(Tool::PathSelection);
|
||||
with_saved_path(&mut app);
|
||||
let (params, path) = crate::vector_ui::free_transform_path(&app).expect("the saved path is transformable");
|
||||
assert_eq!(params, json!({"name": NAME}));
|
||||
assert_eq!(path, saved(&app));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn add_and_delete_anchor_point_edit_the_selected_saved_path() {
|
||||
let mut app = app(Tool::AddAnchorPoint);
|
||||
with_saved_path(&mut app);
|
||||
tool_event(&mut app, ToolEvent::Down { x: 80.0, y: 40.0, pressure: 1.0 }, Modifiers::NONE);
|
||||
tool_event(&mut app, ToolEvent::Up { x: 80.0, y: 40.0 }, Modifiers::NONE);
|
||||
assert_eq!(anchors(&saved(&app)).len(), 5, "an anchor was added on the top segment");
|
||||
app.ui.tool = Tool::DeleteAnchorPoint;
|
||||
tool_event(&mut app, ToolEvent::Down { x: 120.0, y: 120.0, pressure: 1.0 }, Modifiers::NONE);
|
||||
tool_event(&mut app, ToolEvent::Up { x: 120.0, y: 120.0 }, Modifiers::NONE);
|
||||
assert!(!anchors(&saved(&app)).contains(&Point::new(120.0, 120.0)), "the corner anchor was deleted");
|
||||
}
|
||||
|
||||
/// The report's file: a PSD whose saved path "Path 1" is picked in the Paths panel. A synthetic
|
||||
/// one, written and read back through the PSD codec.
|
||||
#[test]
|
||||
fn a_saved_path_read_from_a_psd_is_editable() {
|
||||
let mut src = app(Tool::DirectSelection);
|
||||
with_saved_path(&mut src);
|
||||
let doc = src.session.active().unwrap().doc.clone();
|
||||
let bytes = photocraft_io::export(&doc, "psd", &Default::default()).unwrap().bytes;
|
||||
let mut app = app(Tool::DirectSelection);
|
||||
photocraft_engine::file_cmds::open_bytes_as(&mut app.session, "paths.psd", &bytes, None, None).unwrap();
|
||||
app.sync_views();
|
||||
assert!(app.session.active().unwrap().doc.paths.iter().any(|p| p.name == NAME), "the PSD keeps its saved path");
|
||||
app.ui.selected_path = Some(NAME.into());
|
||||
let n = steps(&app);
|
||||
drag(&mut app, [120.5, 120.5], [130.5, 135.5], Modifiers::NONE);
|
||||
// PSD stores path points as 8.24 fixed-point fractions of the canvas: compare loosely.
|
||||
let a = saved(&app).subpaths[0].knots[2].anchor;
|
||||
assert!((a.x - 130.0).abs() < 1e-3 && (a.y - 135.0).abs() < 1e-3, "the anchor moved to (130, 135): {a:?}");
|
||||
assert_eq!(steps(&app), n + 1);
|
||||
}
|
||||
|
||||
/// Anchors selected on one saved path are dropped once the Paths panel picks another: the arrow
|
||||
/// keys must not nudge a path that is no longer the target path.
|
||||
#[test]
|
||||
fn arrows_leave_a_saved_path_the_paths_panel_no_longer_selects() {
|
||||
let mut app = app(Tool::DirectSelection);
|
||||
with_saved_path(&mut app);
|
||||
app.run("path.set", json!({"name": "Path 2", "path": square(10.0, 10.0, 20.0)})).unwrap();
|
||||
drag(&mut app, [30.0, 30.0], [50.0, 50.0], Modifiers::NONE);
|
||||
assert_eq!((app.ui.direct_selection.target, app.ui.direct_selection.anchors.clone()), (Some(PathRef::Saved(0)), vec![[0, 0]]));
|
||||
// One → press through the canvas arrow keys, as egui delivers it.
|
||||
let arrow = |app: &mut PhotocraftApp| {
|
||||
let ctx = egui::Context::default();
|
||||
ctx.input_mut(|i| {
|
||||
i.events.push(egui::Event::Key { key: egui::Key::ArrowRight, physical_key: None, pressed: true, repeat: false, modifiers: Modifiers::NONE })
|
||||
});
|
||||
crate::direct_select::arrow_keys(app, &ctx)
|
||||
};
|
||||
assert!(arrow(&mut app), "the selected path's anchor is nudged");
|
||||
assert_eq!(saved(&app).subpaths[0].knots[0].anchor, Point::new(41.0, 40.0));
|
||||
app.ui.selected_path = Some("Path 2".into());
|
||||
let (one, two) = (saved(&app), app.session.active().unwrap().doc.paths[1].path.clone());
|
||||
assert!(!arrow(&mut app), "no key is used for a path that is not the target");
|
||||
assert_eq!(saved(&app), one, "Path 1 stays");
|
||||
assert_eq!(app.session.active().unwrap().doc.paths[1].path, two, "Path 2 stays");
|
||||
assert_eq!(app.ui.direct_selection.target, None, "the stale anchor selection is dropped");
|
||||
}
|
||||
@@ -135,7 +135,7 @@ fn apply(app: &mut PhotocraftApp, r: PathRef, hit: Hit) {
|
||||
Hit::Handle(..) => return,
|
||||
};
|
||||
// A hit right at a segment's end is an anchor (anchors win the hit test), so `t` is inside.
|
||||
if let (Some(o), Some(t)) = (params.as_object_mut(), r.params().as_object()) {
|
||||
if let (Some(o), Some(t)) = (params.as_object_mut(), r.params(app).as_object()) {
|
||||
o.extend(t.clone());
|
||||
}
|
||||
match app.run(id, params) {
|
||||
|
||||
@@ -41,17 +41,24 @@ pub enum PathRef {
|
||||
Layer(u64),
|
||||
/// A type layer's Type Path (#9114), apart from a vector mask the layer may have.
|
||||
TypePath(u64),
|
||||
/// A saved path, by its index in the document's `paths`: the one selected in the Paths panel.
|
||||
Saved(usize),
|
||||
/// The Pen path being drawn (`ui.pen`): edited in place, not through the engine.
|
||||
Pen,
|
||||
}
|
||||
|
||||
impl PathRef {
|
||||
/// The engine's target params for this path.
|
||||
pub(crate) fn params(self) -> Value {
|
||||
/// The engine's target params for this path. A saved path goes by its name; one that is gone
|
||||
/// gets an empty name, which the engine refuses.
|
||||
pub(crate) fn params(self, app: &PhotocraftApp) -> Value {
|
||||
match self {
|
||||
PathRef::Work => json!({"name": "work"}),
|
||||
PathRef::Layer(id) => json!({"name": "layer", "layer": id}),
|
||||
PathRef::TypePath(id) => json!({"name": "layer", "layer": id, "typePath": true}),
|
||||
PathRef::Saved(i) => {
|
||||
let name = app.session.active().and_then(|st| st.doc.paths.get(i)).map(|p| p.name.clone()).unwrap_or_default();
|
||||
json!({"name": name})
|
||||
}
|
||||
// Never sent: edits to the Pen path being drawn don't go through the engine.
|
||||
PathRef::Pen => json!({}),
|
||||
}
|
||||
@@ -175,7 +182,8 @@ pub(crate) fn active_paths(app: &PhotocraftApp) -> Vec<(PathRef, Path)> {
|
||||
.map(|(id, p)| (PathRef::Layer(id), p))
|
||||
.or_else(|| crate::vector_ui::active_type_path(app).map(|(id, p)| (PathRef::TypePath(id), p)));
|
||||
let work = app.session.active().and_then(|st| st.doc.work_path.clone()).filter(|_| crate::vector_ui::work_path_shown(app));
|
||||
layer.into_iter().chain(work.map(|p| (PathRef::Work, p))).collect()
|
||||
let saved = crate::vector_ui::selected_saved_path_index(app);
|
||||
layer.into_iter().chain(saved.map(|(i, p)| (PathRef::Saved(i), p))).chain(work.map(|p| (PathRef::Work, p))).collect()
|
||||
}
|
||||
|
||||
/// The paths Direct Selection edits, front first: the Pen path being drawn, the active paths, then
|
||||
@@ -396,7 +404,7 @@ pub fn curvature_hover(app: &PhotocraftApp, p: [f64; 2], mods: Modifiers) -> Opt
|
||||
pub(crate) fn curvature_toggle_active(app: &mut PhotocraftApp, p: [f64; 2]) {
|
||||
let Some((target, _, Hit::Anchor([s, k]))) = curvature_target(app, p) else { return };
|
||||
let mut params = json!({"subpath": s, "knot": k, "curvature": true});
|
||||
if let (Some(o), Some(tp)) = (params.as_object_mut(), target.params().as_object()) {
|
||||
if let (Some(o), Some(tp)) = (params.as_object_mut(), target.params(app).as_object()) {
|
||||
o.extend(tp.clone());
|
||||
}
|
||||
if let Err(e) = app.run("path.convertPoint", params) {
|
||||
@@ -419,7 +427,7 @@ fn curvature_press(app: &mut PhotocraftApp, p: [f64; 2]) -> bool {
|
||||
Hit::Segment([s, k], t) => {
|
||||
let key = format!("curvature-add-{}", app.ui.alloc_id());
|
||||
let mut params = json!({"subpath": s, "knot": k, "t": t.clamp(0.01, 0.99), "coalesce": key});
|
||||
if let (Some(o), Some(tp)) = (params.as_object_mut(), target.params().as_object()) {
|
||||
if let (Some(o), Some(tp)) = (params.as_object_mut(), target.params(app).as_object()) {
|
||||
o.extend(tp.clone());
|
||||
}
|
||||
let added = match app.run("path.addAnchor", params) {
|
||||
@@ -468,7 +476,7 @@ fn release(app: &mut PhotocraftApp, target: PathRef, base: &Path, edit: &Edit, s
|
||||
_ if !moved => return,
|
||||
e => e.command(start, end),
|
||||
};
|
||||
if let (Some(p), Some(t)) = (params.as_object_mut(), target.params().as_object()) {
|
||||
if let (Some(p), Some(t)) = (params.as_object_mut(), target.params(app).as_object()) {
|
||||
p.extend(t.clone());
|
||||
}
|
||||
if let (Some(p), Some(key)) = (params.as_object_mut(), app.ui.direct_selection.coalesce.take()) {
|
||||
@@ -512,7 +520,14 @@ pub fn arrow_keys(app: &mut PhotocraftApp, ctx: &egui::Context) -> bool {
|
||||
let Some(target) = ds.target.filter(|_| app.ui.tool == Tool::DirectSelection && !ds.anchors.is_empty() && ds.drag.is_none()) else {
|
||||
return false;
|
||||
};
|
||||
let anchors = ds.anchors.clone();
|
||||
// The anchors belong to a path the canvas no longer offers (another saved path picked in the
|
||||
// Paths panel, the path deleted): drop them rather than nudge that path, or another one that
|
||||
// took its index.
|
||||
if !candidates(app).iter().any(|(r, _)| *r == target) {
|
||||
app.ui.direct_selection = DirectSelection::default();
|
||||
return false;
|
||||
}
|
||||
let anchors = app.ui.direct_selection.anchors.clone();
|
||||
use egui::Key;
|
||||
let keys = [(Key::ArrowLeft, -1.0, 0.0), (Key::ArrowRight, 1.0, 0.0), (Key::ArrowUp, 0.0, -1.0), (Key::ArrowDown, 0.0, 1.0)];
|
||||
for (key, ux, uy) in keys {
|
||||
@@ -521,7 +536,7 @@ pub fn arrow_keys(app: &mut PhotocraftApp, ctx: &egui::Context) -> bool {
|
||||
if ctx.input_mut(|i| i.consume_key(mods, key)) {
|
||||
let k = if mods.shift { 10.0 } else { 1.0 };
|
||||
let mut params = json!({"anchors": anchors, "move": [ux * k, uy * k]});
|
||||
if let (Some(p), Some(t)) = (params.as_object_mut(), target.params().as_object()) {
|
||||
if let (Some(p), Some(t)) = (params.as_object_mut(), target.params(app).as_object()) {
|
||||
p.extend(t.clone());
|
||||
}
|
||||
if let Err(e) = app.run("path.moveAnchors", params) {
|
||||
|
||||
@@ -33,6 +33,7 @@ use options::{corner_radii_patch, solid_paint};
|
||||
pub(crate) use options::{enabled_stroke_width, paint_gesture};
|
||||
pub use options::{options_bar, shape_properties};
|
||||
pub use overlay::draw_overlay;
|
||||
pub(crate) use overlay::selected_saved_path_index;
|
||||
#[cfg(test)]
|
||||
use overlay::{MAX_CURVE_PIECES, bezier};
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -120,6 +120,13 @@ pub(crate) fn selected_saved_path(app: &PhotocraftApp) -> Option<&Path> {
|
||||
app.session.active()?.doc.paths.iter().find(|p| p.name == sel).map(|p| &p.path)
|
||||
}
|
||||
|
||||
/// [`selected_saved_path`] with its index in the document's `paths`: the saved path Path
|
||||
/// Selection and Direct Selection edit (#8478).
|
||||
pub(crate) fn selected_saved_path_index(app: &PhotocraftApp) -> Option<(usize, Path)> {
|
||||
let sel = app.ui.selected_path.as_deref().filter(|s| !matches!(*s, "work" | "layer"))?;
|
||||
app.session.active()?.doc.paths.iter().enumerate().find(|(_, p)| p.name == sel).map(|(i, p)| (i, p.path.clone()))
|
||||
}
|
||||
|
||||
/// Work path / active shape path / selected saved path outlines, anchors, and the pen path in
|
||||
/// progress.
|
||||
pub fn draw_overlay(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform, doc: &Document) {
|
||||
@@ -141,10 +148,6 @@ pub fn draw_overlay(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform
|
||||
// Direct Selection (or the Pen with ⌘/Ctrl held) draws the paths it edits (#790).
|
||||
crate::direct_select::draw_overlay(app, painter, &to_scr, accent, paths);
|
||||
if paths {
|
||||
// The selected saved path shows too, though Direct Selection doesn't edit it yet.
|
||||
if let Some(p) = selected_saved_path(app) {
|
||||
draw_path(p, true);
|
||||
}
|
||||
crate::anchor_tools::draw_hover(app, painter, &to_scr, accent, painter.ctx().input(|i| i.modifiers));
|
||||
}
|
||||
} else if paths {
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
use super::overlay::selected_saved_path_index;
|
||||
use super::paths_panel::{PathEntry, PathRow, path_rows};
|
||||
use super::pen::pen_commit;
|
||||
use super::{Affine, Document, LayerContent, Path, PhotocraftApp, Tool, Value, json};
|
||||
@@ -117,6 +118,8 @@ pub(super) enum PathTarget {
|
||||
Shape(u64),
|
||||
/// The active layer's vector mask, when its Layers thumbnail is targeted (#196).
|
||||
VectorMask(u64),
|
||||
/// The saved path selected in the Paths panel, by name (#8478).
|
||||
Saved(String),
|
||||
Work,
|
||||
}
|
||||
|
||||
@@ -162,8 +165,8 @@ pub(crate) fn delete_key_deletes_work_path(app: &PhotocraftApp) -> bool {
|
||||
&& matches!(target_path(app), Some((PathTarget::Work, _)))
|
||||
}
|
||||
|
||||
/// The path Path Selection edits: the targeted vector mask, the active shape layer's path, else
|
||||
/// the work path.
|
||||
/// The path Path Selection edits: the targeted vector mask, the active shape layer's path, the
|
||||
/// saved path selected in the Paths panel (#8478), else the work path.
|
||||
pub(super) fn target_path(app: &PhotocraftApp) -> Option<(PathTarget, Path)> {
|
||||
if let Some((id, p)) = targeted_vector_mask(app) {
|
||||
return Some((PathTarget::VectorMask(id), p));
|
||||
@@ -171,6 +174,11 @@ pub(super) fn target_path(app: &PhotocraftApp) -> Option<(PathTarget, Path)> {
|
||||
if let Some((id, p)) = active_shape_path(app) {
|
||||
return Some((PathTarget::Shape(id), p));
|
||||
}
|
||||
if let Some(name) = app.ui.selected_path.as_deref()
|
||||
&& let Some((_, p)) = selected_saved_path_index(app)
|
||||
{
|
||||
return Some((PathTarget::Saved(name.to_string()), p));
|
||||
}
|
||||
if !work_path_shown(app) {
|
||||
return None;
|
||||
}
|
||||
@@ -187,6 +195,7 @@ pub(crate) fn free_transform_path(app: &PhotocraftApp) -> Option<(Value, Path)>
|
||||
path.control_bounds()?;
|
||||
let params = match target {
|
||||
PathTarget::Shape(id) | PathTarget::VectorMask(id) => json!({"name": "layer", "layer": id}),
|
||||
PathTarget::Saved(name) => json!({"name": name}),
|
||||
PathTarget::Work => json!({"name": "work"}),
|
||||
};
|
||||
Some((params, path))
|
||||
@@ -299,6 +308,10 @@ pub fn path_selection_finish(app: &mut PhotocraftApp, start: [f64; 2], end: [f64
|
||||
let moved = path.transform(&Affine::translate(dx.round(), dy.round()));
|
||||
app.run("layer.vectorMask.edit", json!({"layer": id, "path": photocraft_engine::vector_cmds::path_json(&moved)}))
|
||||
}
|
||||
PathTarget::Saved(name) => {
|
||||
let moved = path.transform(&Affine::translate(dx.round(), dy.round()));
|
||||
app.run("path.set", json!({"name": name, "path": photocraft_engine::vector_cmds::path_json(&moved)}))
|
||||
}
|
||||
PathTarget::Work => {
|
||||
let moved = path.transform(&Affine::translate(dx.round(), dy.round()));
|
||||
app.run("path.set", json!({"name": "work", "path": photocraft_engine::vector_cmds::path_json(&moved)}))
|
||||
|
||||
Reference in new issue
Block a user