mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
feat(ui-egui): change the operation of drawn path components; carry on open shape paths
Feedback on #7648 from testing a vector portrait workflow: - Path Selection selects path components: a click selects the one under the pointer, ⇧-click adds or removes one, a click off every component deselects, and a drag moves only the selected components (one `path.moveAnchors`). Their anchors show solid, as in Photoshop. - Path Selection gets the Path Operations menu. With components selected, the menu changes their operation through the new engine command `path.setOperation` (Work Path, saved path, shape layer or vector mask; one History step), and its icon shows their operation. - `+` (Combine Shapes) and `-` (Subtract Front Shape) pick the operation with the Pen tools and Path Selection, on the selected components and for the next path. `+` is ⇧= on a US layout, so with these tools it no longer steps the blend mode. - The Pen carries on an open path from its endpoint in Shape mode (the selected shape layer) and on a targeted vector mask, as it already did on the Work Path and saved paths. Closing the open path a stroked-only shape layer was made of gives it the options bar's fill and stroke, as if it had been drawn closed.
This commit is contained in:
1 parent
505503b93a
commit
754c61fd7f
10 files changed
+667
-29
No files matched your search
@@ -944,6 +944,7 @@ mod tests {
|
||||
| "path.addAnchor"
|
||||
| "path.deleteAnchor"
|
||||
| "path.mergeShapeComponents"
|
||||
| "path.setOperation"
|
||||
| "path.clippingPath.set"
|
||||
| "path.rename"
|
||||
| "path.stroke"
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
//! live shape) or a layer's vector mask. Knots are addressed by `subpath` and `knot` index, as
|
||||
//! listed by `path.info`, and the result is `{name, path}` in the compact JSON form.
|
||||
|
||||
use photocraft_doc::{LayerContent, Path};
|
||||
use photocraft_doc::{LayerContent, Path, PathOp};
|
||||
use photocraft_geom::Point;
|
||||
use photocraft_vector::edit::{self, Handle};
|
||||
use serde_json::{Value, json};
|
||||
@@ -178,6 +178,41 @@ fn merge_components(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
})
|
||||
}
|
||||
|
||||
/// The Path Operations menu (or + / −) with path components selected: the components holding
|
||||
/// `subpaths` take `op`, the way Photoshop changes the operation of the selected components. A
|
||||
/// component's operation lives on its first subpath; the subpaths joined to it keep theirs.
|
||||
fn set_operation(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
const CMD: &str = "path.setOperation";
|
||||
let op = p
|
||||
.get("op")
|
||||
.and_then(Value::as_str)
|
||||
.and_then(crate::vector_cmds::op_from)
|
||||
.filter(|op| *op != PathOp::Join)
|
||||
.ok_or_else(|| bad(CMD, "`op` must be \"combine\", \"subtract\", \"intersect\" or \"exclude\""))?;
|
||||
let subpaths: Vec<usize> = p
|
||||
.get("subpaths")
|
||||
.and_then(Value::as_array)
|
||||
.filter(|a| !a.is_empty())
|
||||
.ok_or_else(|| bad(CMD, "`subpaths` must list subpath indices"))?
|
||||
.iter()
|
||||
.map(|v| v.as_u64().and_then(|i| usize::try_from(i).ok()).ok_or_else(|| bad(CMD, "each subpath is an index")))
|
||||
.collect::<Result<_>>()?;
|
||||
edit_path(s, CMD, p, "Path Operation", |path| {
|
||||
let components = path.components();
|
||||
let mut heads = Vec::with_capacity(subpaths.len());
|
||||
for i in &subpaths {
|
||||
let c = components.iter().find(|c| c.contains(i)).ok_or_else(|| format!("no subpath {i} (the path has {})", path.subpaths.len()))?;
|
||||
heads.push(c.start);
|
||||
}
|
||||
for h in heads {
|
||||
if let Some(sp) = path.subpaths.get_mut(h) {
|
||||
sp.op = op;
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
})
|
||||
}
|
||||
|
||||
pub fn specs() -> Vec<CommandSpec> {
|
||||
const TARGET: &str = r#""name":str|"work"|"layer"="work","layer":id? (with "layer": a shape layer's path or a vector mask)"#;
|
||||
let spec = |id: &'static str, label: &'static str, params: String, run: fn(&mut Session, &Value) -> Result<Value>| CommandSpec {
|
||||
@@ -228,12 +263,18 @@ pub fn specs() -> Vec<CommandSpec> {
|
||||
r#""tolerance":px=0.1 (bakes the components' path operations into plain combined outlines, traced from the exact coverage)"#.into(),
|
||||
merge_components,
|
||||
),
|
||||
spec(
|
||||
"path.setOperation",
|
||||
"Path Operation",
|
||||
r#""subpaths":[i,…],"op":"combine|subtract|intersect|exclude" (the shape components holding these subpaths take the operation; the Path Operations menu with components selected)"#.into(),
|
||||
set_operation,
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use photocraft_doc::{LayerId, ShapeLayer};
|
||||
use photocraft_doc::{LayerId, PathOp, ShapeLayer};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::Session;
|
||||
@@ -500,6 +541,69 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// A hole cut with Combine by mistake becomes a hole: the component takes Subtract Front Shape,
|
||||
/// in one step, on the Work Path, a shape layer (re-rendered) and a vector mask alike.
|
||||
#[test]
|
||||
fn set_operation_changes_existing_components() {
|
||||
let mut s = session();
|
||||
let hole = json!({"subpaths": [{"closed": true, "knots": [[25, 25], [45, 25], [45, 45], [25, 45]]}]});
|
||||
s.execute("path.set", json!({"path": square()})).unwrap();
|
||||
s.execute("path.set", json!({"path": hole, "op": "combine"})).unwrap();
|
||||
assert_eq!(covered(&work(&s), 35, 35), 1.0);
|
||||
s.execute("path.setOperation", json!({"subpaths": [1], "op": "subtract"})).unwrap();
|
||||
assert_eq!(s.active().unwrap().history.undo_label(), Some("Path Operation"));
|
||||
assert_eq!(covered(&work(&s), 35, 35), 0.0);
|
||||
assert_eq!(work(&s).subpaths[1].op, PathOp::Subtract);
|
||||
assert!(s.undo());
|
||||
assert_eq!(work(&s).subpaths[1].op, PathOp::Combine);
|
||||
|
||||
let id = s.execute("shape.create", json!({"kind": "rect", "rect": [10, 10, 50, 50], "fill": "#ff0000"})).unwrap()["layer"].as_u64().unwrap();
|
||||
s.execute("shape.create", json!({"kind": "rect", "rect": [25, 25, 20, 20], "addTo": id, "op": "combine"})).unwrap();
|
||||
s.execute("path.setOperation", json!({"name": "layer", "layer": id, "subpaths": [1], "op": "subtract"})).unwrap();
|
||||
let st = s.active().unwrap();
|
||||
let photocraft_doc::LayerContent::Shape(ShapeLayer { path, cache, .. }) = &st.doc.layer(LayerId(id)).unwrap().content else { panic!("shape") };
|
||||
assert_eq!(covered(path, 35, 35), 0.0);
|
||||
assert!(cache.is_some());
|
||||
}
|
||||
|
||||
/// A component's operation is its first subpath's: naming a joined subpath changes the head,
|
||||
/// and the joined subpaths stay joined.
|
||||
#[test]
|
||||
fn set_operation_on_a_joined_subpath_changes_its_component() {
|
||||
let mut s = session();
|
||||
let mut p = square();
|
||||
let subs = p["subpaths"].as_array_mut().unwrap();
|
||||
subs.push(json!({"closed": true, "op": "combine", "knots": [[70, 10], [110, 10], [110, 50], [70, 50]]}));
|
||||
subs.push(json!({"closed": true, "op": "join", "knots": [[80, 20], [80, 40], [100, 40], [100, 20]]}));
|
||||
s.execute("path.set", json!({"path": p})).unwrap();
|
||||
s.execute("path.setOperation", json!({"subpaths": [2], "op": "exclude"})).unwrap();
|
||||
let ops: Vec<_> = work(&s).subpaths.iter().map(|sp| sp.op).collect();
|
||||
assert_eq!(ops, [PathOp::Combine, PathOp::Exclude, PathOp::Join]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bad_set_operation_params_change_nothing() {
|
||||
let mut s = session();
|
||||
s.execute("path.set", json!({"path": square()})).unwrap();
|
||||
let steps = s.active().unwrap().history.entries().len();
|
||||
for (p, msg) in [
|
||||
(json!({"subpaths": [0]}), "`op`"),
|
||||
(json!({"subpaths": [0], "op": "join"}), "`op`"),
|
||||
(json!({"subpaths": [0], "op": 3}), "`op`"),
|
||||
(json!({"op": "subtract"}), "`subpaths`"),
|
||||
(json!({"subpaths": [], "op": "subtract"}), "`subpaths`"),
|
||||
(json!({"subpaths": [-1], "op": "subtract"}), "index"),
|
||||
(json!({"subpaths": [7], "op": "subtract"}), "no subpath 7"),
|
||||
(json!({"subpaths": [0], "op": "subtract", "name": "Nope"}), ""),
|
||||
(json!({"subpaths": [0], "op": "subtract", "name": "layer", "layer": "x"}), "`layer`"),
|
||||
] {
|
||||
let e = s.execute("path.setOperation", p.clone()).unwrap_err().to_string();
|
||||
assert!(e.contains(msg), "{p}: {e}");
|
||||
}
|
||||
assert_eq!(s.active().unwrap().history.entries().len(), steps);
|
||||
assert_eq!(work(&s).subpaths[0].op, PathOp::Combine);
|
||||
}
|
||||
|
||||
/// Rejected merges name the problem and leave every path as it was, including the one a
|
||||
/// malformed target would otherwise have fallen back to (the Work Path, the active layer).
|
||||
#[test]
|
||||
|
||||
@@ -173,7 +173,7 @@ fn hex(c: &Color) -> String {
|
||||
if c.alpha < 1.0 { format!("#{:02x}{:02x}{:02x}{:02x}", q(r), q(g), q(b), q(c.alpha)) } else { format!("#{:02x}{:02x}{:02x}", q(r), q(g), q(b)) }
|
||||
}
|
||||
|
||||
fn op_from(s: &str) -> Option<PathOp> {
|
||||
pub(crate) fn op_from(s: &str) -> Option<PathOp> {
|
||||
Some(match s.to_ascii_lowercase().as_str() {
|
||||
"combine" | "add" | "union" => PathOp::Combine,
|
||||
"subtract" | "minus" => PathOp::Subtract,
|
||||
|
||||
@@ -6032,6 +6032,8 @@ pub fn tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers)
|
||||
{
|
||||
let _ = app.run("layer.select", json!({"layer": id.0}));
|
||||
}
|
||||
// The component pressed is selected, so the drag moves it (and the others selected).
|
||||
crate::path_components::press(app, [x, y], mods.shift);
|
||||
}
|
||||
Tool::Pen => {
|
||||
if !(mods.alt && crate::vector_ui::pen_grab_handle(app, x, y)) {
|
||||
|
||||
@@ -169,6 +169,7 @@ mod panel_docking;
|
||||
pub mod panels;
|
||||
pub mod parity;
|
||||
pub mod patch_preview;
|
||||
mod path_components;
|
||||
pub(crate) mod pattern_fill_ui;
|
||||
pub mod pattern_preview;
|
||||
pub mod perspective_crop_ui;
|
||||
|
||||
@@ -0,0 +1,193 @@
|
||||
//! Selected path components and their Path Operations, as in Photoshop. Path Selection (A) clicks a
|
||||
//! component to select it (⇧ adds or removes one, a click off every component deselects) and drags
|
||||
//! the selected components. With components selected, the Path Operations menu and its keys (`+`
|
||||
//! Combine Shapes, `-` Subtract Front Shape, with the Pen tools or Path Selection) change their
|
||||
//! operation through `path.setOperation`, one History step; with none selected they set how the
|
||||
//! next path is added. The selection is Direct Selection's: every anchor of a selected component.
|
||||
|
||||
use egui::{Event, Key};
|
||||
use photocraft_doc::{Path, PathOp};
|
||||
use photocraft_geom::Point;
|
||||
use serde_json::json;
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::direct_select::{DirectSelection, PathRef, active_paths};
|
||||
use crate::state::Tool;
|
||||
|
||||
/// The `pen_path_op` value of an operation (`Join` belongs to its component's first subpath).
|
||||
fn op_value(op: PathOp) -> &'static str {
|
||||
match op {
|
||||
PathOp::Combine | PathOp::Join => "combine",
|
||||
PathOp::Subtract => "subtract",
|
||||
PathOp::Intersect => "intersect",
|
||||
PathOp::Exclude => "exclude",
|
||||
}
|
||||
}
|
||||
|
||||
/// The path Path Selection selects in: the targeted vector mask or the active shape layer's
|
||||
/// path, else the Work Path (`active_paths`, front first).
|
||||
fn target(app: &PhotocraftApp) -> Option<(PathRef, Path)> {
|
||||
active_paths(app).into_iter().next()
|
||||
}
|
||||
|
||||
/// The selected components: their path and the first subpath of each, in order. `None` with
|
||||
/// nothing selected, or a selection on a path that is not an active one any more.
|
||||
pub(crate) fn selected(app: &PhotocraftApp) -> Option<(PathRef, Path, Vec<usize>)> {
|
||||
let sel = &app.ui.direct_selection;
|
||||
let r = sel.target.filter(|r| *r != PathRef::Pen)?;
|
||||
let (_, path) = active_paths(app).into_iter().find(|(p, _)| *p == r)?;
|
||||
let components = path.components();
|
||||
let mut heads: Vec<usize> = sel.anchors.iter().filter_map(|[s, _]| components.iter().find(|c| c.contains(s)).map(|c| c.start)).collect();
|
||||
heads.sort_unstable();
|
||||
heads.dedup();
|
||||
(!heads.is_empty()).then_some((r, path, heads))
|
||||
}
|
||||
|
||||
/// The operation every selected component has, for the menu's icon; `None` when they differ.
|
||||
pub(crate) fn selected_op(app: &PhotocraftApp) -> Option<&'static str> {
|
||||
let (_, path, heads) = selected(app)?;
|
||||
let mut ops = heads.iter().filter_map(|h| path.subpaths.get(*h)).map(|s| op_value(s.op));
|
||||
let first = ops.next()?;
|
||||
ops.all(|o| o == first).then_some(first)
|
||||
}
|
||||
|
||||
/// A Path Operations pick (menu or key): the selected components take `op`, and the tool keeps it
|
||||
/// for the next path. New Layer is not an operation a component can have: it only sets the tool.
|
||||
pub(crate) fn set_op(app: &mut PhotocraftApp, op: &str) -> Result<(), String> {
|
||||
app.ui.tool_options.pen_path_op = op.into();
|
||||
if op == "newLayer" {
|
||||
return Ok(());
|
||||
}
|
||||
let Some((r, path, heads)) = selected(app) else { return Ok(()) };
|
||||
if heads.iter().all(|h| path.subpaths.get(*h).is_some_and(|s| op_value(s.op) == op)) {
|
||||
return Ok(());
|
||||
}
|
||||
let mut params = r.params();
|
||||
params["subpaths"] = json!(heads);
|
||||
params["op"] = json!(op);
|
||||
app.run("path.setOperation", params).map(|_| ())
|
||||
}
|
||||
|
||||
/// The component of `path` under `at`: on its outline within `tol`, else inside it. The frontmost
|
||||
/// (last) component wins.
|
||||
fn component_at(path: &Path, at: [f64; 2], tol: f64) -> Option<std::ops::Range<usize>> {
|
||||
let components = path.components();
|
||||
if let Some(hit) = photocraft_vector::edit::hit(path, Point::new(at[0], at[1]), tol, &[]) {
|
||||
let s = match hit {
|
||||
photocraft_vector::edit::Hit::Anchor([s, _])
|
||||
| photocraft_vector::edit::Hit::Handle([s, _], _)
|
||||
| photocraft_vector::edit::Hit::Segment([s, _], _) => s,
|
||||
};
|
||||
return components.into_iter().find(|c| c.contains(&s));
|
||||
}
|
||||
components.into_iter().rev().find(|c| {
|
||||
// Even-odd over the component's flattened subpaths: a hole in it is not inside.
|
||||
let crossings: usize = path
|
||||
.subpaths
|
||||
.get(c.clone())
|
||||
.unwrap_or_default()
|
||||
.iter()
|
||||
.filter(|s| s.closed)
|
||||
.map(|s| crossings(&photocraft_vector::flatten::flatten_subpath(s, 0.25).pts, at))
|
||||
.sum();
|
||||
crossings % 2 == 1
|
||||
})
|
||||
}
|
||||
|
||||
/// How many edges of the closed polygon `pts` a ray from `at` to the right crosses.
|
||||
fn crossings(pts: &[(f64, f64)], at: [f64; 2]) -> usize {
|
||||
let n = pts.len();
|
||||
(0..n)
|
||||
.filter(|&i| {
|
||||
let (Some(&(xi, yi)), Some(&(xj, yj))) = (pts.get(i), pts.get((i + 1) % n)) else { return false };
|
||||
(yi > at[1]) != (yj > at[1]) && at[0] < (xj - xi) * (at[1] - yi) / (yj - yi) + xi
|
||||
})
|
||||
.count()
|
||||
}
|
||||
|
||||
/// Path Selection's press at `at`: selects the component there (⇧ adds or removes it). Pressing a
|
||||
/// selected component keeps the selection, so the drag moves all of it; pressing off every
|
||||
/// component deselects, unless ⇧ is held.
|
||||
pub(crate) fn press(app: &mut PhotocraftApp, at: [f64; 2], shift: bool) {
|
||||
let tol = 6.0 / f64::from(app.point_zoom().max(0.01));
|
||||
let Some((r, path)) = target(app) else {
|
||||
app.ui.direct_selection = DirectSelection::default();
|
||||
return;
|
||||
};
|
||||
let current = selected(app).filter(|(sr, ..)| *sr == r).map(|(.., heads)| heads).unwrap_or_default();
|
||||
let Some(hit) = component_at(&path, at, tol) else {
|
||||
if !shift {
|
||||
app.ui.direct_selection = DirectSelection::default();
|
||||
}
|
||||
return;
|
||||
};
|
||||
let was_selected = current.contains(&hit.start);
|
||||
let heads: Vec<usize> = match (shift, was_selected) {
|
||||
(true, true) => current.into_iter().filter(|h| *h != hit.start).collect(),
|
||||
(true, false) => current.into_iter().chain([hit.start]).collect(),
|
||||
(false, true) => current,
|
||||
(false, false) => vec![hit.start],
|
||||
};
|
||||
let components = path.components();
|
||||
let anchors = components
|
||||
.iter()
|
||||
.filter(|c| heads.contains(&c.start))
|
||||
.flat_map(|c| c.clone())
|
||||
.flat_map(|s| (0..path.subpaths.get(s).map_or(0, |sp| sp.knots.len())).map(move |k| [s, k]))
|
||||
.collect::<Vec<_>>();
|
||||
app.ui.direct_selection = if anchors.is_empty() { DirectSelection::default() } else { DirectSelection { target: Some(r), anchors, ..Default::default() } };
|
||||
}
|
||||
|
||||
/// Path Selection's drag by `d` with components selected on the path it edits: moves those
|
||||
/// components, one History step. `None` with none selected (the whole path moves instead).
|
||||
pub(crate) fn move_selected(app: &mut PhotocraftApp, d: [f64; 2]) -> Option<Result<(), String>> {
|
||||
let (r, ..) = selected(app)?;
|
||||
if target(app).map(|(t, _)| t) != Some(r) {
|
||||
return None;
|
||||
}
|
||||
let mut params = r.params();
|
||||
params["anchors"] = json!(app.ui.direct_selection.anchors);
|
||||
params["move"] = json!(d);
|
||||
Some(app.run("path.moveAnchors", params).map(|_| ()))
|
||||
}
|
||||
|
||||
/// Do `+` and `-` pick a Path Operation with `tool`? The tools whose options bar has the menu.
|
||||
fn has_keys(tool: Tool) -> bool {
|
||||
matches!(tool, Tool::Pen | Tool::FreeformPen | Tool::CurvaturePen | Tool::PathSelection)
|
||||
}
|
||||
|
||||
/// Consumes this frame's `+` (Combine Shapes) and `-` (Subtract Front Shape) presses while a tool
|
||||
/// with the Path Operations menu is active, as in Photoshop. `+` is ⇧= on many layouts and the
|
||||
/// keypad's key on all, so ⇧ is allowed; with these tools ⇧+ / ⇧− step no blend mode.
|
||||
pub fn handle_keys(app: &mut PhotocraftApp, ctx: &egui::Context) {
|
||||
if !has_keys(app.ui.tool) {
|
||||
return;
|
||||
}
|
||||
let ops: Vec<&str> = ctx.input_mut(|i| {
|
||||
let mut out = Vec::new();
|
||||
i.events.retain(|e| match e {
|
||||
Event::Key { key, pressed: true, modifiers, .. } if !modifiers.command && !modifiers.ctrl && !modifiers.alt => {
|
||||
let op = match key {
|
||||
Key::Plus => "combine",
|
||||
Key::Equals if modifiers.shift => "combine",
|
||||
Key::Minus => "subtract",
|
||||
_ => return true,
|
||||
};
|
||||
out.push(op);
|
||||
false
|
||||
}
|
||||
_ => true,
|
||||
});
|
||||
out
|
||||
});
|
||||
for op in ops {
|
||||
if let Err(e) = set_op(app, op) {
|
||||
app.ui.status = e;
|
||||
app.ui.status_error = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "path_components_tests.rs"]
|
||||
mod tests;
|
||||
@@ -0,0 +1,249 @@
|
||||
//! Path components after they are drawn (feedback on #7648): Path Selection selects them, the
|
||||
//! Path Operations menu and `+` / `-` change their operation, and the Pen carries on an open
|
||||
//! shape path from its endpoint.
|
||||
|
||||
use egui::Key;
|
||||
use photocraft_doc::vector::PathOp;
|
||||
use photocraft_doc::{LayerContent, LayerId, Path};
|
||||
use serde_json::json;
|
||||
|
||||
use crate::PhotocraftApp;
|
||||
use crate::direct_select::PathRef;
|
||||
use crate::state::Tool;
|
||||
use crate::vector_ui::{pen_commit, pen_down, pen_up};
|
||||
|
||||
fn app() -> PhotocraftApp {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 200, "height": 200})).unwrap();
|
||||
app.ui.tool = Tool::Pen;
|
||||
app.ui.tool_options.vector_mode = "shape".into();
|
||||
app
|
||||
}
|
||||
|
||||
fn click(app: &mut PhotocraftApp, x: f64, y: f64) {
|
||||
pen_down(app, x, y, false);
|
||||
pen_up(app);
|
||||
}
|
||||
|
||||
/// Clicks a closed square with the Pen, from `(x, y)` with side `side`.
|
||||
fn square(app: &mut PhotocraftApp, x: f64, y: f64, side: f64) {
|
||||
for (dx, dy) in [(0.0, 0.0), (side, 0.0), (side, side), (0.0, side), (0.5, 0.5)] {
|
||||
click(app, x + dx, y + dy);
|
||||
}
|
||||
}
|
||||
|
||||
fn shape(app: &PhotocraftApp) -> (LayerId, photocraft_doc::ShapeLayer) {
|
||||
let st = app.session.active().unwrap();
|
||||
let id = st.active_layer.unwrap();
|
||||
match &st.doc.layer(id).unwrap().content {
|
||||
LayerContent::Shape(sh) => (id, sh.clone()),
|
||||
_ => panic!("not a shape layer"),
|
||||
}
|
||||
}
|
||||
|
||||
fn ops(path: &Path) -> Vec<PathOp> {
|
||||
path.subpaths.iter().map(|s| s.op).collect()
|
||||
}
|
||||
|
||||
fn covered(path: &Path, x: i32, y: i32) -> f32 {
|
||||
photocraft_vector::fill_rasterizer(path, photocraft_vector::DEFAULT_TOLERANCE).render(photocraft_geom::Rect::from_xywh(x, y, 1, 1))[0]
|
||||
}
|
||||
|
||||
fn history(app: &PhotocraftApp) -> usize {
|
||||
app.session.active().unwrap().history.past_len()
|
||||
}
|
||||
|
||||
/// Feeds one key press through the app's shortcut handling.
|
||||
fn key(app: &mut PhotocraftApp, ctx: &egui::Context, key: Key, modifiers: egui::Modifiers) {
|
||||
let raw = egui::RawInput {
|
||||
events: vec![egui::Event::ModifiersChanged(modifiers), egui::Event::Key { key, physical_key: None, pressed: true, repeat: false, modifiers }],
|
||||
..Default::default()
|
||||
};
|
||||
ctx.begin_pass(raw);
|
||||
crate::shortcuts::handle(app, ctx);
|
||||
ctx.end_pass().textures_delta.clear();
|
||||
}
|
||||
|
||||
/// A body and an inner square drawn with Combine Shapes: the inner one is selected with Path
|
||||
/// Selection and turned into a hole with the menu's Subtract Front Shape, one History step.
|
||||
#[test]
|
||||
fn a_selected_component_takes_the_picked_operation() {
|
||||
let mut app = app();
|
||||
square(&mut app, 20.0, 20.0, 120.0);
|
||||
app.ui.tool_options.pen_path_op = "combine".into();
|
||||
square(&mut app, 60.0, 60.0, 40.0);
|
||||
let (id, sh) = shape(&app);
|
||||
assert_eq!(covered(&sh.path, 80, 80), 1.0);
|
||||
app.ui.tool = Tool::PathSelection;
|
||||
super::press(&mut app, [80.0, 80.0], false);
|
||||
let (r, _, heads) = super::selected(&app).expect("the inner square is selected");
|
||||
assert_eq!((r, heads), (PathRef::Layer(id.0), vec![1]));
|
||||
let steps = history(&app);
|
||||
super::set_op(&mut app, "subtract").unwrap();
|
||||
let (_, sh) = shape(&app);
|
||||
assert_eq!(ops(&sh.path), [PathOp::Combine, PathOp::Subtract]);
|
||||
assert_eq!((covered(&sh.path, 80, 80), covered(&sh.path, 30, 30)), (0.0, 1.0), "a hole");
|
||||
assert_eq!(history(&app), steps + 1);
|
||||
assert_eq!(super::selected_op(&app), Some("subtract"), "the menu shows the component's");
|
||||
// Picking what it already has adds no step; New Layer only sets the tool.
|
||||
super::set_op(&mut app, "subtract").unwrap();
|
||||
super::set_op(&mut app, "newLayer").unwrap();
|
||||
assert_eq!(history(&app), steps + 1);
|
||||
assert!(app.session.undo());
|
||||
assert_eq!(ops(&shape(&app).1.path), [PathOp::Combine, PathOp::Combine]);
|
||||
}
|
||||
|
||||
/// `+` and `-` with the Pen tools or Path Selection: Combine Shapes and Subtract Front Shape, on
|
||||
/// the selected components and for the next path. `+` arrives as ⇧= on a US keyboard, which
|
||||
/// otherwise steps the blend mode; with the Move tool it still does.
|
||||
#[test]
|
||||
fn plus_and_minus_pick_combine_and_subtract() {
|
||||
let ctx = egui::Context::default();
|
||||
let mut app = app();
|
||||
square(&mut app, 20.0, 20.0, 120.0);
|
||||
app.ui.tool_options.pen_path_op = "combine".into();
|
||||
square(&mut app, 60.0, 60.0, 40.0);
|
||||
app.ui.tool = Tool::PathSelection;
|
||||
super::press(&mut app, [80.0, 80.0], false);
|
||||
key(&mut app, &ctx, Key::Minus, egui::Modifiers::NONE);
|
||||
assert_eq!(ops(&shape(&app).1.path), [PathOp::Combine, PathOp::Subtract]);
|
||||
assert_eq!(app.ui.tool_options.pen_path_op, "subtract");
|
||||
key(&mut app, &ctx, Key::Equals, egui::Modifiers::SHIFT);
|
||||
assert_eq!(ops(&shape(&app).1.path), [PathOp::Combine, PathOp::Combine]);
|
||||
key(&mut app, &ctx, Key::Minus, egui::Modifiers::NONE);
|
||||
key(&mut app, &ctx, Key::Plus, egui::Modifiers::NONE);
|
||||
assert_eq!(ops(&shape(&app).1.path), [PathOp::Combine, PathOp::Combine], "the keypad's +");
|
||||
// With nothing selected the Pen's next path takes it.
|
||||
app.ui.direct_selection = Default::default();
|
||||
app.ui.tool = Tool::Pen;
|
||||
key(&mut app, &ctx, Key::Minus, egui::Modifiers::NONE);
|
||||
assert_eq!(app.ui.tool_options.pen_path_op, "subtract");
|
||||
// The blend mode is the Move tool's to step.
|
||||
let blend = |app: &PhotocraftApp| app.session.active().unwrap().doc.layer(shape(app).0).unwrap().blend;
|
||||
let before = blend(&app);
|
||||
key(&mut app, &ctx, Key::Equals, egui::Modifiers::SHIFT);
|
||||
assert_eq!(blend(&app), before, "the Pen picks Combine, not a blend mode");
|
||||
assert_eq!(app.ui.tool_options.pen_path_op, "combine");
|
||||
app.ui.tool = Tool::Move;
|
||||
key(&mut app, &ctx, Key::Equals, egui::Modifiers::SHIFT);
|
||||
assert_ne!(blend(&app), before);
|
||||
assert_eq!(app.ui.tool_options.pen_path_op, "combine");
|
||||
}
|
||||
|
||||
/// ⇧-click adds and removes components, a click off them deselects, and a drag moves only the
|
||||
/// selected ones.
|
||||
#[test]
|
||||
fn path_selection_selects_and_moves_components() {
|
||||
let mut app = app();
|
||||
square(&mut app, 10.0, 10.0, 40.0);
|
||||
app.ui.tool_options.pen_path_op = "combine".into();
|
||||
square(&mut app, 100.0, 10.0, 40.0);
|
||||
square(&mut app, 100.0, 100.0, 40.0);
|
||||
app.ui.tool = Tool::PathSelection;
|
||||
let heads = |app: &PhotocraftApp| super::selected(app).map(|(.., h)| h).unwrap_or_default();
|
||||
super::press(&mut app, [30.0, 30.0], false);
|
||||
super::press(&mut app, [120.0, 120.0], true);
|
||||
assert_eq!(heads(&app), [0, 2]);
|
||||
// Pressing a selected one keeps both, for the drag.
|
||||
super::press(&mut app, [120.0, 120.0], false);
|
||||
assert_eq!(heads(&app), [0, 2]);
|
||||
crate::vector_ui::path_selection_finish(&mut app, [120.0, 120.0], [125.0, 130.0]);
|
||||
let (_, sh) = shape(&app);
|
||||
let first = |s: usize| sh.path.subpaths[s].knots[0].anchor;
|
||||
assert_eq!((first(0).x, first(0).y), (15.0, 20.0));
|
||||
assert_eq!((first(1).x, first(1).y), (100.0, 10.0), "not selected: stays");
|
||||
assert_eq!((first(2).x, first(2).y), (105.0, 110.0));
|
||||
super::press(&mut app, [125.0, 130.0], true);
|
||||
assert_eq!(heads(&app), [0]);
|
||||
super::press(&mut app, [190.0, 190.0], false);
|
||||
assert!(super::selected(&app).is_none(), "a click off every component deselects");
|
||||
}
|
||||
|
||||
/// A selection left on a path that has fewer subpaths now (undone, edited elsewhere) selects
|
||||
/// nothing and changes nothing, never panics.
|
||||
#[test]
|
||||
fn a_stale_selection_changes_nothing() {
|
||||
let mut app = app();
|
||||
square(&mut app, 10.0, 10.0, 40.0);
|
||||
let (id, _) = shape(&app);
|
||||
app.ui.direct_selection = crate::direct_select::DirectSelection { target: Some(PathRef::Layer(id.0)), anchors: vec![[5, 0]], ..Default::default() };
|
||||
assert!(super::selected(&app).is_none());
|
||||
let steps = history(&app);
|
||||
super::set_op(&mut app, "subtract").unwrap();
|
||||
assert_eq!(history(&app), steps);
|
||||
assert_eq!(super::move_selected(&mut app, [3.0, 3.0]), None);
|
||||
}
|
||||
|
||||
/// A shape path left open (Enter before closing it) is carried on from its endpoint and closed on
|
||||
/// its first anchor: the same layer and subpath, one History step, and it takes the options bar's
|
||||
/// fill and stroke as if it had been drawn closed.
|
||||
#[test]
|
||||
fn the_pen_carries_on_an_open_shape_path() {
|
||||
let mut app = app();
|
||||
app.ui.tool_options.shape_fill = true;
|
||||
app.ui.tool_options.stroke_width = 0.0;
|
||||
for (x, y) in [(20.0, 20.0), (120.0, 20.0), (120.0, 120.0)] {
|
||||
click(&mut app, x, y);
|
||||
}
|
||||
assert!(pen_commit(&mut app, false));
|
||||
let (id, sh) = shape(&app);
|
||||
assert!(sh.fill.is_none() && sh.stroke.is_some(), "an open path is stroked");
|
||||
let count = app.session.active().unwrap().doc.layers.len();
|
||||
let steps = history(&app);
|
||||
click(&mut app, 120.0, 120.0); // its last anchor: carry on
|
||||
click(&mut app, 20.0, 120.0);
|
||||
click(&mut app, 20.5, 20.5); // its first anchor: close
|
||||
assert!(app.ui.pen.is_none(), "closing commits");
|
||||
let (same, sh) = shape(&app);
|
||||
assert_eq!((same, app.session.active().unwrap().doc.layers.len()), (id, count), "no new layer");
|
||||
assert_eq!(sh.path.subpaths.len(), 1);
|
||||
assert!(sh.path.subpaths[0].closed);
|
||||
assert_eq!(sh.path.subpaths[0].knots.len(), 4);
|
||||
assert!(sh.fill.is_some() && sh.stroke.is_none(), "filled like a path drawn closed");
|
||||
assert_eq!(history(&app), steps + 1);
|
||||
assert!(app.session.undo());
|
||||
assert!(!shape(&app).1.path.subpaths[0].closed);
|
||||
}
|
||||
|
||||
/// From the first anchor too, and a closed component's fill and stroke are the layer's own.
|
||||
#[test]
|
||||
fn an_open_component_of_a_filled_shape_keeps_its_paint() {
|
||||
let mut app = app();
|
||||
square(&mut app, 10.0, 10.0, 60.0);
|
||||
let (id, before) = shape(&app);
|
||||
// An open component added to the layer.
|
||||
app.ui.tool_options.pen_path_op = "combine".into();
|
||||
for (x, y) in [(100.0, 100.0), (150.0, 100.0)] {
|
||||
click(&mut app, x, y);
|
||||
}
|
||||
assert!(pen_commit(&mut app, false));
|
||||
app.ui.tool_options.shape_fill = false;
|
||||
click(&mut app, 100.0, 100.0); // its first anchor
|
||||
click(&mut app, 100.0, 150.0);
|
||||
assert!(pen_commit(&mut app, false));
|
||||
let (same, sh) = shape(&app);
|
||||
assert_eq!(same, id);
|
||||
assert_eq!(sh.path.subpaths.len(), 2);
|
||||
assert_eq!(sh.path.subpaths[1].knots.len(), 3);
|
||||
assert_eq!((sh.fill, sh.stroke), (before.fill, before.stroke));
|
||||
}
|
||||
|
||||
/// A targeted vector mask's open subpath is carried on in place too.
|
||||
#[test]
|
||||
fn the_pen_carries_on_a_vector_masks_open_subpath() {
|
||||
let mut app = app();
|
||||
app.ui.tool_options.vector_mode = "path".into();
|
||||
app.run("layer.new.layer", json!({})).unwrap();
|
||||
let id = app.session.active().unwrap().active_layer.unwrap().0;
|
||||
let open = json!({"subpaths": [{"closed": false, "knots": [[20, 20], [120, 20]]}]});
|
||||
app.run("layer.vectorMask.add", json!({"layer": id, "path": open})).unwrap();
|
||||
app.ui.vector_mask_target = true;
|
||||
click(&mut app, 120.0, 20.0);
|
||||
click(&mut app, 120.0, 120.0);
|
||||
assert!(pen_commit(&mut app, false));
|
||||
let st = app.session.active().unwrap();
|
||||
let mask = st.doc.layer(LayerId(id)).unwrap().vector_mask.clone().unwrap();
|
||||
assert_eq!(mask.path.subpaths.len(), 1);
|
||||
assert_eq!(mask.path.subpaths[0].knots.len(), 3);
|
||||
assert!(st.doc.work_path.is_none());
|
||||
}
|
||||
@@ -770,7 +770,9 @@ pub fn handle(app: &mut PhotocraftApp, ctx: &egui::Context) {
|
||||
}
|
||||
// 1–0 set opacity, ⇧1–0 flow or fill (`opacity_keys`).
|
||||
crate::opacity_keys::handle(app, ctx);
|
||||
// ⇧+ / ⇧− step the blend mode (`blend_keys`).
|
||||
// + / − pick a Path Operation with the Pen tools and Path Selection (`path_components`)…
|
||||
crate::path_components::handle_keys(app, ctx);
|
||||
// … and otherwise ⇧+ / ⇧− step the blend mode (`blend_keys`).
|
||||
crate::blend_keys::handle(app, ctx);
|
||||
}
|
||||
|
||||
|
||||
+108
-23
@@ -48,7 +48,11 @@ pub struct PenPath {
|
||||
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Resumed {
|
||||
pub doc: u64,
|
||||
/// A document path's name ("work" or a saved path's), or "layer" for `layer`'s.
|
||||
pub path: String,
|
||||
/// The shape layer (Shape mode) or targeted vector mask whose path it is.
|
||||
#[serde(default)]
|
||||
pub layer: Option<u64>,
|
||||
pub index: usize,
|
||||
pub was: photocraft_doc::vector::Subpath,
|
||||
}
|
||||
@@ -558,7 +562,9 @@ fn commit_path(app: &mut PhotocraftApp, pen: &PenPath, closed: bool) -> bool {
|
||||
let path = pen_to_json(pen, closed);
|
||||
let op = pen_path_op(&app.ui.tool_options);
|
||||
let into_shape = op.and_then(|_| selected_shape(&app.session)).map(|s| s.layer.0);
|
||||
let r = if let (Some(op), Some(layer), "shape") = (op, into_shape, app.ui.tool_options.vector_mode.as_str()) {
|
||||
let r = if let Some(r) = commit_resumed_on_layer(app, pen, &path, closed) {
|
||||
r
|
||||
} else if let (Some(op), Some(layer), "shape") = (op, into_shape, app.ui.tool_options.vector_mode.as_str()) {
|
||||
// The selected shape layer keeps its fill and stroke; the new component cuts, intersects…
|
||||
app.run("shape.create", json!({"kind": "path", "path": path, "addTo": layer, "op": op}))
|
||||
} else if app.ui.tool_options.vector_mode == "shape" {
|
||||
@@ -594,7 +600,8 @@ fn commit_path(app: &mut PhotocraftApp, pen: &PenPath, closed: bool) -> bool {
|
||||
// A resumed draft whose subpath changed meanwhile joins the path it came from, as a new
|
||||
// subpath, even with nothing selected in the Paths panel.
|
||||
let exists = |n: &String| app.session.active().is_some_and(|st| path_exists(&st.doc, n));
|
||||
let resumed_from = pen.resumes.as_ref().filter(|r| app.session.active().is_some_and(|st| st.doc.id.0 == r.doc)).map(|r| r.path.clone());
|
||||
let resumed_from =
|
||||
pen.resumes.as_ref().filter(|r| r.layer.is_none() && app.session.active().is_some_and(|st| st.doc.id.0 == r.doc)).map(|r| r.path.clone());
|
||||
let target = resumed_from.filter(exists).or_else(|| app.ui.selected_path.clone().filter(exists));
|
||||
let name = target.clone().unwrap_or_else(|| "work".into());
|
||||
let mut params = json!({"name": name, "path": path});
|
||||
@@ -621,19 +628,26 @@ fn doc_path<'a>(doc: &'a Document, name: &str) -> Option<&'a Path> {
|
||||
if name == "work" { doc.work_path.as_ref() } else { doc.paths.iter().find(|p| p.name == name).map(|p| &p.path) }
|
||||
}
|
||||
|
||||
/// The open subpath of the path a new Pen path would join (the one selected in the Paths panel,
|
||||
/// else the work path) that has its first or last anchor at `(x, y)`, as a Pen path to carry on
|
||||
/// drawing from there (#6593). Its knots run towards that anchor: reversed, handles swapped, when
|
||||
/// it is the first. Shape mode and a targeted vector mask take new paths, so they resume nothing.
|
||||
/// The open subpath that has its first or last anchor at `(x, y)`, as a Pen path to carry on
|
||||
/// drawing from there (#6593): of a targeted vector mask, else in Shape mode of the selected shape
|
||||
/// layer, else of the path a new Pen path would join (the one selected in the Paths panel, else
|
||||
/// the work path). Its knots run towards that anchor: reversed, handles swapped, when it is the
|
||||
/// first.
|
||||
fn resume_at(app: &PhotocraftApp, x: f64, y: f64, tol: f64) -> Option<PenPath> {
|
||||
if app.ui.tool_options.vector_mode == "shape" || targeted_vector_mask(app).is_some() {
|
||||
return None;
|
||||
}
|
||||
let st = app.session.active()?;
|
||||
let doc = st.doc.id.0;
|
||||
let name = app.ui.selected_path.clone().filter(|n| path_exists(&st.doc, n)).unwrap_or_else(|| "work".into());
|
||||
let (name, layer, path) = if let Some((id, p)) = targeted_vector_mask(app) {
|
||||
("layer".to_string(), Some(id), p)
|
||||
} else if app.ui.tool_options.vector_mode == "shape" {
|
||||
let (id, p) = active_shape_path(app)?;
|
||||
("layer".to_string(), Some(id), p)
|
||||
} else {
|
||||
let name = app.ui.selected_path.clone().filter(|n| path_exists(&st.doc, n)).unwrap_or_else(|| "work".into());
|
||||
let p = doc_path(&st.doc, &name)?.clone();
|
||||
(name, None, p)
|
||||
};
|
||||
let near = |k: &photocraft_doc::Knot| (k.anchor.x - x).hypot(k.anchor.y - y) < tol;
|
||||
doc_path(&st.doc, &name)?.subpaths.iter().enumerate().filter(|(_, s)| !s.closed).find_map(|(i, s)| {
|
||||
path.subpaths.iter().enumerate().filter(|(_, s)| !s.closed).find_map(|(i, s)| {
|
||||
let reversed = if s.knots.last().is_some_and(near) {
|
||||
false
|
||||
} else if s.knots.first().is_some_and(near) {
|
||||
@@ -649,7 +663,7 @@ fn resume_at(app: &PhotocraftApp, x: f64, y: f64, tol: f64) -> Option<PenPath> {
|
||||
}
|
||||
}
|
||||
let unlinked = knots.iter().enumerate().filter(|(_, (_, smooth))| !smooth).map(|(i, _)| i).collect();
|
||||
let resumes = Resumed { doc, path: name.clone(), index: i, was: s.clone() };
|
||||
let resumes = Resumed { doc, path: name.clone(), layer, index: i, was: s.clone() };
|
||||
Some(PenPath { knots: knots.into_iter().map(|(k, _)| k).collect(), unlinked, resumes: Some(resumes), ..Default::default() })
|
||||
})
|
||||
}
|
||||
@@ -658,7 +672,7 @@ fn resume_at(app: &PhotocraftApp, x: f64, y: f64, tol: f64) -> Option<PenPath> {
|
||||
/// anchors and closing, which keeps its other settings (its path operation). `None` when the
|
||||
/// subpath is no longer the one drawing resumed (another document, or the path changed).
|
||||
fn with_resumed_subpath(doc: &Document, r: &Resumed, drawn: &Value) -> Option<Value> {
|
||||
let path = doc_path(doc, &r.path).filter(|_| doc.id.0 == r.doc)?;
|
||||
let path = resumed_path(doc, r)?;
|
||||
if path.subpaths.get(r.index) != Some(&r.was) {
|
||||
return None;
|
||||
}
|
||||
@@ -671,6 +685,41 @@ fn with_resumed_subpath(doc: &Document, r: &Resumed, drawn: &Value) -> Option<Va
|
||||
Some(p)
|
||||
}
|
||||
|
||||
/// The path a resumed subpath belongs to, while `doc` is the document drawing resumed in: a shape
|
||||
/// layer's or a vector mask's, or a document path.
|
||||
fn resumed_path<'a>(doc: &'a Document, r: &Resumed) -> Option<&'a Path> {
|
||||
if doc.id.0 != r.doc {
|
||||
return None;
|
||||
}
|
||||
let Some(id) = r.layer else { return doc_path(doc, &r.path) };
|
||||
let l = doc.layer(photocraft_doc::LayerId(id))?;
|
||||
match &l.content {
|
||||
LayerContent::Shape(sh) => Some(&sh.path),
|
||||
_ => l.vector_mask.as_ref().map(|m| &m.path),
|
||||
}
|
||||
}
|
||||
|
||||
/// Commit a resumed Pen path (#6593) into a shape layer or vector mask: the carried-on subpath
|
||||
/// takes its old place, one step. Closing the open path a shape layer was made of gives it the
|
||||
/// options bar's fill and stroke, as drawing it closed would have. `None` when the draft resumes
|
||||
/// a document path, or its subpath changed meanwhile.
|
||||
fn commit_resumed_on_layer(app: &mut PhotocraftApp, pen: &PenPath, path: &Value, closed: bool) -> Option<Result<Value, String>> {
|
||||
let r = pen.resumes.as_ref()?;
|
||||
let id = r.layer?;
|
||||
let st = app.session.active()?;
|
||||
let p = with_resumed_subpath(&st.doc, r, path)?;
|
||||
let layer = st.doc.layer(photocraft_doc::LayerId(id))?;
|
||||
let LayerContent::Shape(sh) = &layer.content else {
|
||||
return Some(app.run("layer.vectorMask.edit", json!({"layer": id, "path": p})));
|
||||
};
|
||||
let mut params = json!({"layer": id, "path": p});
|
||||
if closed && sh.fill.is_none() && sh.path.subpaths.iter().all(|s| !s.closed) {
|
||||
params["fill"] = fill_param(app);
|
||||
params["stroke"] = stroke_param(app);
|
||||
}
|
||||
Some(app.run("shape.edit", params))
|
||||
}
|
||||
|
||||
/// The Pen's Path Operations (#1397), in Photoshop's menu order: the `pen_path_op` value, its
|
||||
/// label and its icon.
|
||||
pub(crate) const PATH_OPS: [(&str, &str, &str); 5] = [
|
||||
@@ -693,9 +742,14 @@ pub(crate) fn pen_path_op(o: &ToolOptions) -> Option<&'static str> {
|
||||
}
|
||||
|
||||
/// What the Path Operations menu's Merge Shape Components merges, as a command, its params and
|
||||
/// the number of shape components there: in Shape mode the selected shape layer; in Path mode
|
||||
/// the path the Pen draws into (a targeted vector mask, the selected path, else the Work Path).
|
||||
/// the number of shape components there: with Path Selection the path it selects in; in Shape
|
||||
/// mode the selected shape layer; in Path mode the path the Pen draws into (a targeted vector
|
||||
/// mask, the selected path, else the Work Path).
|
||||
fn merge_target(app: &PhotocraftApp) -> Option<(&'static str, Value, usize)> {
|
||||
if app.ui.tool == Tool::PathSelection {
|
||||
let (r, p) = crate::direct_select::active_paths(app).into_iter().next()?;
|
||||
return Some(("path.mergeShapeComponents", r.params(), p.components().len()));
|
||||
}
|
||||
let st = app.session.active()?;
|
||||
if app.ui.tool_options.vector_mode == "shape" {
|
||||
let id = st.active_layer?;
|
||||
@@ -710,23 +764,27 @@ fn merge_target(app: &PhotocraftApp) -> Option<(&'static str, Value, usize)> {
|
||||
Some(("path.mergeShapeComponents", json!({"name": name}), path.components().len()))
|
||||
}
|
||||
|
||||
/// The Path Operations button of the Pen, Freeform Pen and Curvature Pen (#1397), Photoshop's:
|
||||
/// how the next path combines with the shape or path it is drawn into, and Merge Shape Components.
|
||||
/// Its icon shows the current operation.
|
||||
/// The Path Operations button of the Pen, Freeform Pen, Curvature Pen and Path Selection (#1397),
|
||||
/// Photoshop's: the operation of the selected path components, or with none selected how the next
|
||||
/// path combines with the shape or path it is drawn into; and Merge Shape Components. Its icon
|
||||
/// shows the selected components' operation, else the tool's.
|
||||
fn path_operations_menu(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
let shape = app.ui.tool_options.vector_mode == "shape";
|
||||
let current = pen_path_op(&app.ui.tool_options).unwrap_or("newLayer");
|
||||
// New Layer makes a shape layer: Path mode and Path Selection have none.
|
||||
let shape = app.ui.tool_options.vector_mode == "shape" && app.ui.tool != Tool::PathSelection;
|
||||
let current = crate::path_components::selected_op(app)
|
||||
.or_else(|| pen_path_op(&app.ui.tool_options))
|
||||
.map_or("newLayer", |op| if op == "newLayer" && !shape { "combine" } else { op });
|
||||
let icon = PATH_OPS.iter().find(|(v, ..)| *v == current).map_or("path-op-combine", |(.., i)| *i);
|
||||
let resp = crate::icons::button_with_icon_size(ui, icon, 24.0, 16.0, false, tl!("Path operations"));
|
||||
let resp = crate::brush_picker::named(resp, "Path operations");
|
||||
let merge = merge_target(app).filter(|(.., n)| *n > 1);
|
||||
let mut run = None;
|
||||
let mut pick = None;
|
||||
egui::Popup::menu(&resp).show(|ui| {
|
||||
ui.set_min_width(240.0);
|
||||
for (value, label, glyph) in PATH_OPS {
|
||||
// New Layer makes a shape layer: Path mode has none.
|
||||
if ui.add_enabled_ui(shape || value != "newLayer", |ui| path_op_button(ui, glyph, tl!(label), value == current)).inner.clicked() {
|
||||
app.ui.tool_options.pen_path_op = value.into();
|
||||
pick = Some(value);
|
||||
ui.close();
|
||||
}
|
||||
}
|
||||
@@ -736,6 +794,12 @@ fn path_operations_menu(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|
||||
ui.close();
|
||||
}
|
||||
});
|
||||
if let Some(op) = pick
|
||||
&& let Err(e) = crate::path_components::set_op(app, op)
|
||||
{
|
||||
app.ui.status = e;
|
||||
app.ui.status_error = true;
|
||||
}
|
||||
if let Some((id, params, _)) = run
|
||||
&& let Err(e) = app.run(id, params)
|
||||
{
|
||||
@@ -1150,6 +1214,14 @@ pub fn path_selection_finish(app: &mut PhotocraftApp, start: [f64; 2], end: [f64
|
||||
let _ = app.run("layer.select", json!({"layer": id.0}));
|
||||
}
|
||||
}
|
||||
// Selected components move on their own (`path_components`); with none, the whole path.
|
||||
if let Some(r) = crate::path_components::move_selected(app, [dx.round(), dy.round()]) {
|
||||
if let Err(e) = r {
|
||||
app.ui.status = e;
|
||||
app.ui.status_error = true;
|
||||
}
|
||||
return;
|
||||
}
|
||||
let Some((target, path)) = target_path(app) else { return };
|
||||
let _ = match target {
|
||||
PathTarget::Shape(id) => app.run("shape.edit", json!({"layer": id, "move": [dx.round(), dy.round()]})),
|
||||
@@ -1326,6 +1398,15 @@ pub fn draw_overlay(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform
|
||||
if let Some((_, p)) = targeted_vector_mask(app) {
|
||||
draw_path(&p, anchors);
|
||||
}
|
||||
// Path Selection's selected components show solid anchors, as in Photoshop.
|
||||
if tool == Tool::PathSelection
|
||||
&& st.is_some_and(|s| s.doc.id == doc.id)
|
||||
&& let Some((_, path, _)) = crate::path_components::selected(app)
|
||||
{
|
||||
for k in app.ui.direct_selection.anchors.iter().filter_map(|[s, k]| path.subpaths.get(*s).and_then(|sp| sp.knots.get(*k))) {
|
||||
draw_anchor(painter, to_scr([k.anchor.x, k.anchor.y]), true, accent);
|
||||
}
|
||||
}
|
||||
crate::corner_radius::draw(app, painter, &to_scr, accent);
|
||||
}
|
||||
// Pen path in progress, with handles of the last knot and a rubber band to the pointer. While
|
||||
@@ -1415,8 +1496,12 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo
|
||||
let lbl = |ui: &mut egui::Ui, s: &str| {
|
||||
ui.label(egui::RichText::new(s).color(t.text_dim).size(12.0));
|
||||
};
|
||||
let o = &mut app.ui.tool_options;
|
||||
let target = selected_shape(&app.session);
|
||||
if tool == Tool::PathSelection && !crate::direct_select::active_paths(app).is_empty() {
|
||||
path_operations_menu(app, ui);
|
||||
crate::widgets::vline(ui, 22.0);
|
||||
}
|
||||
let o = &mut app.ui.tool_options;
|
||||
if tool == Tool::PathSelection && target.is_none() {
|
||||
lbl(ui, if app.ui.vector_mask_target { "Drag to move the targeted vector mask" } else { tl!("Drag to move the active shape's path or the Work Path") });
|
||||
return true;
|
||||
|
||||
+3
-2
@@ -1,6 +1,6 @@
|
||||
# UI parity: tools, handles, modifiers and feel
|
||||
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-21 · **Change:** minor (Pen, Freeform Pen and Curvature Pen Path Operations menu, #1397; View › Extras hides the Move transform controls, #6699; Hand tool ⌘ / ⌥ are Zoom In / Zoom Out while held, #6434; the wheel steps value fields, #5473; a dragged guide shows its X or Y beside the pointer, #7680; Type options bar "T" icon scrubs the font size, #6437; Move tool: dragged selected pixels take their own outline as the selection, #7538; artboard backgrounds remain below child Free Transform previews; ⌫/Delete removes the selected smart filter, #4751; Object Finder foreground/background discrimination (#6548); rounded triangle, polygon and star corners; shape Fill/Stroke popovers accept hex RGB values, #6176; a guide let go over either ruler is removed, #6286; Crop rows corrected: saved crop presets and Delete Cropped Pixels off are done, #6562; marching ants in device pixels, #7489; Animated Zoom: holding the Zoom tool zooms continuously, #6210; shape Density and Feather, TOOL-214-12, #5846; Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed; selection-modifier and ⌥-wheel rows match their tests) · **Target:** Adobe Photoshop 2026
|
||||
> **Last reviewed:** 2026-10-10 · **Last updated:** 2026-10-24 · **Change:** minor (Pen, Freeform Pen, Curvature Pen and Path Selection Path Operations menu, which changes selected components, `+` / `-` keys, #1397; the Pen carries on an open shape or vector mask path; View › Extras hides the Move transform controls, #6699; Hand tool ⌘ / ⌥ are Zoom In / Zoom Out while held, #6434; the wheel steps value fields, #5473; a dragged guide shows its X or Y beside the pointer, #7680; Type options bar "T" icon scrubs the font size, #6437; Move tool: dragged selected pixels take their own outline as the selection, #7538; artboard backgrounds remain below child Free Transform previews; ⌫/Delete removes the selected smart filter, #4751; Object Finder foreground/background discrimination (#6548); rounded triangle, polygon and star corners; shape Fill/Stroke popovers accept hex RGB values, #6176; a guide let go over either ruler is removed, #6286; Crop rows corrected: saved crop presets and Delete Cropped Pixels off are done, #6562; marching ants in device pixels, #7489; Animated Zoom: holding the Zoom tool zooms continuously, #6210; shape Density and Feather, TOOL-214-12, #5846; Pen Auto Add/Delete on the path being drawn, #6140; Show Transform Controls frames every selected layer; guide keys and clicks; menu bar from the keyboard, #4988; Crop tool Content-Aware Fill; on-canvas corner radius widgets, TOOL-214-12; Curvature Pen edits the active path; Clip Thumbnails to Layer Bounds; Pen ⇧ 45°; last selected tool restored at launch; Layers panel filter-type dropdown with Kind, Name and Mode, #5048; Free Transform box and marching ants follow the selection, #5297; History: the trash deletes the selected snapshot, rows drag onto the trash, #5324; smart filter reordering by drag; smart object perspective row corrected to done, #426; Free Transform H/V skew fields; toolbar tool shortcuts can be reassigned; ⇧-dragged guides land on ruler ticks; layer and selection keys; tool keys; spring-loaded tool letters; type formatting keys; Pen Auto Add/Delete, #4144; smart filter rows; stale missing-tool rows corrected: Color Replacement, Red Eye and the Add/Delete Anchor Point pair are live toolbar tools, Frame landed; no percentage changed; selection-modifier and ⌥-wheel rows match their tests) · **Target:** Adobe Photoshop 2026
|
||||
|
||||
How PhotoCraft's direct manipulation compares with Photoshop 2026 (27.11.0): the toolbox, the
|
||||
handles and modifier keys of each gesture, nudging, snapping, numeric precision, navigation,
|
||||
@@ -127,7 +127,7 @@ Triangle and Curvature Pen (minus legacy Rounded Rectangle and Targeted Adjustme
|
||||
| Handle on the last point, close-drag handle | partial | #1482 |
|
||||
| Pen Auto Add/Delete: click a segment of the active path, or of the path being drawn, to add, an anchor to delete; ⇧ suspends it | done | #4144, #6140 |
|
||||
| Curvature Pen edits the active path with no modifier: drag an anchor (the curve reflows), click a segment to add an anchor, double-click smooth ↔ corner; cursor badge + on segments, four arrows on anchors | done: `direct_select.rs` (`curvature_press`, `curvature_hover`), `path.moveAnchors`/`path.convertPoint` with `curvature`, `direct_select_tests.rs` | |
|
||||
| Path operations in the options bar (combine, subtract, intersect, exclude) | partial: the Pen, Freeform Pen and Curvature Pen have Photoshop's Path Operations menu (New Layer in Shape mode, Combine, Subtract Front Shape, Intersect, Exclude, Merge Shape Components) for the selected shape layer, a targeted vector mask, the selected path or the Work Path (`vector_ui.rs` `path_operations_menu`, `pen_path_ops_tests.rs`, `path.mergeShapeComponents`); the Shape tools and Path Selection don't have the menu yet | `layer.combineShapes.*`; #1397 |
|
||||
| Path operations in the options bar (combine, subtract, intersect, exclude) | partial: the Pen, Freeform Pen and Curvature Pen have Photoshop's Path Operations menu (New Layer in Shape mode, Combine, Subtract Front Shape, Intersect, Exclude, Merge Shape Components) for the selected shape layer, a targeted vector mask, the selected path or the Work Path (`vector_ui.rs` `path_operations_menu`, `pen_path_ops_tests.rs`, `path.mergeShapeComponents`). Path Selection has it too and selects components (click, ⇧-click, drag moves the selected ones); with components selected the menu, `+` (Combine) and `-` (Subtract Front Shape) change their operation (`path.setOperation`, `path_components.rs`, `path_components_tests.rs`). The Shape tools don't have the menu yet, and Intersect and Exclude have no key | `layer.combineShapes.*`; #1397 |
|
||||
| On-canvas corner-radius handles on live shapes | done: every selected live rectangle shows a widget at each arc centre with Path Selection, the Rectangle tool and Move with Show Transform Controls; a drag rounds every corner of every selected rectangle to the same radius, ⌥ that corner on each, with the corner radius cursor and an `R:` readout, previewed and committed as one history step (`corner_radius.rs`, `corner_radius_tests.rs`) | TOOL-214-12 |
|
||||
| Shape Density and Feather (Properties › Masks: a shape's path is its vector mask) | done: Density and Feather sliders for a selected shape layer, one undo step per drag, through `layer.vectorMask.edit`; the fill shows beyond the path at 100 − density %, a feather is the vector mask's Gaussian (Photoshop's 10 px ramp within 1 level); fill and stroke stay editable, the stroke stays crisp; PSD mask parameters and .pcraft round trip (#5846) | TOOL-214-12 |
|
||||
| On-canvas corner-radius handles on live shapes | done: every selected live rectangle, triangle, polygon and star shows a widget at each arc centre with Path Selection, the Rectangle, Triangle and Polygon tools and Move with Show Transform Controls; a drag rounds every corner of every selected shape to the same radius, ⌥ one corner of a rectangle (a triangle or polygon has one radius), with the corner radius cursor and an `R:` readout, previewed and committed as one history step (`corner_radius.rs`, `corner_radius_tests.rs`) | TOOL-214-12 |
|
||||
@@ -240,6 +240,7 @@ Paragraph; the rest open as in-app floating windows.
|
||||
|
||||
| Date | Change | Summary |
|
||||
|---|---|---|
|
||||
| 2026-10-24 | minor | Path Selection selects path components and has the Path Operations menu; the menu and `+` / `-` change the selected components' operation (`path.setOperation`); the Pen carries on an open shape layer or vector mask path from its endpoint (#1397 feedback); row stays partial until the Shape tools have the menu; no percentage changed |
|
||||
| 2026-10-19 | minor | Pen, Freeform Pen and Curvature Pen Path Operations menu (#1397): the operation a new path is added with, and Merge Shape Components for paths (`path.mergeShapeComponents`); row stays partial until the Shape tools and Path Selection have it; no percentage changed |
|
||||
| 2026-10-19 | minor | A guide being moved or dragged out of a ruler shows an `X:` / `Y:` position readout beside the pointer, from the zero point in the ruler unit (#7680) |
|
||||
| 2026-10-17 | minor | The wheel steps value fields: a focused field takes it wherever the pointer is (the canvas and panels don't scroll), an unfocused one only a gesture that starts over it (#5473, #4061); no percentage changed |
|
||||
|
||||
Reference in new issue
Block a user