Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Tools: Frame tool (#2914) (#2915)

Valentin Klein42e4af641634
diff --git a/ATTRIBUTION.md b/ATTRIBUTION.md
index 8f3803e76..004d05639 100644
--- a/ATTRIBUTION.md
+++ b/ATTRIBUTION.md
@@ -20,7 +20,7 @@ next to them.
| `crates/ui-egui/src/i18n/uk.tsv` | Ukrainian UI translations | PhotoCraft contributors | Original translations of PhotoCraft's English labels | MIT OR Apache-2.0, [`LICENSE-translations.txt`](crates/ui-egui/src/i18n/LICENSE-translations.txt) |
| `assets/fonts/Inter-Regular.ttf`, `Inter-Medium.ttf`, `Inter-SemiBold.ttf` | Inter 4.001 (UI font) | The Inter Project Authors (Rasmus Andersson) | <https://github.com/rsms/inter> | SIL OFL 1.1, [`assets/fonts/OFL-Inter.txt`](assets/fonts/OFL-Inter.txt) |
| `assets/fonts/JetBrainsMono-Regular.ttf` | JetBrains Mono 2.305 (numeric font) | The JetBrains Mono Project Authors | <https://github.com/JetBrains/JetBrainsMono> | SIL OFL 1.1, [`assets/fonts/OFL-JetBrainsMono.txt`](assets/fonts/OFL-JetBrainsMono.txt) |
-| `assets/icons/*.svg` except `slice-knife.svg`, `artboard.svg`, `perspective-crop.svg`, `type-mask.svg`, `type-mask-vertical.svg`, `clip-below.svg`, `clip-release.svg`, `layer-mask.svg`, `adjustment-layer.svg`, `brush-replace.svg`, `eraser-background.svg`, `eraser-magic.svg`, `lasso-magnetic.svg`, `direct-select.svg`, `pen-add-anchor.svg`, `pen-delete-anchor.svg`, `pen-freeform.svg`, `pen-curvature.svg`, `bandage-sparkle.svg`, `painting-symmetry.svg`, `symmetry-*.svg` and `marquee-{row,column}.svg` (112 files; `star-filled.svg` is `star.svg` with a solid fill) | Lucide icons | Lucide Icons and Contributors | <https://github.com/lucide-icons/lucide> (`icons/<name>.svg`; `align-*` are now named `text-align-*` upstream) | ISC, [`assets/icons/LICENSE-lucide.txt`](assets/icons/LICENSE-lucide.txt) |
+| `assets/icons/*.svg` except `slice-knife.svg`, `artboard.svg`, `perspective-crop.svg`, `frame-placeholder.svg`, `type-mask.svg`, `type-mask-vertical.svg`, `clip-below.svg`, `clip-release.svg`, `layer-mask.svg`, `adjustment-layer.svg`, `brush-replace.svg`, `eraser-background.svg`, `eraser-magic.svg`, `lasso-magnetic.svg`, `direct-select.svg`, `pen-add-anchor.svg`, `pen-delete-anchor.svg`, `pen-freeform.svg`, `pen-curvature.svg`, `bandage-sparkle.svg`, `painting-symmetry.svg`, `symmetry-*.svg` and `marquee-{row,column}.svg` (112 files; `star-filled.svg` is `star.svg` with a solid fill) | Lucide icons | Lucide Icons and Contributors | <https://github.com/lucide-icons/lucide> (`icons/<name>.svg`; `align-*` are now named `text-align-*` upstream) | ISC, [`assets/icons/LICENSE-lucide.txt`](assets/icons/LICENSE-lucide.txt) |
| `assets/icons/{check,chevron-down,chevron-right,chevron-up,chevrons-left,chevrons-right,circle,clock,compass,info,link,link-2,lock,minus,monitor,moon,move,navigation,plus,search,square,trash,triangle,type,x,zoom-in}.svg` | Lucide icons derived from Feather (subset of the row above) | Cole Bemis (Feather), Lucide Contributors | <https://github.com/feathericons/feather> via Lucide | MIT (Feather) and ISC (Lucide), [`assets/icons/LICENSE-lucide.txt`](assets/icons/LICENSE-lucide.txt) |
| `assets/icons/slice-knife.svg` | Slice tool glyph | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
| `assets/icons/artboard.svg` | Artboard tool glyph: a board with a tick at each end of its edges | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
@@ -29,6 +29,7 @@ next to them.
| `assets/icons/marquee-row.svg`, `assets/icons/marquee-column.svg` | Single Row and Single Column Marquee tool glyphs: a dashed row (column) between two edge bars, drawn on Lucide's 24 px grid and stroke | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
| `assets/icons/clip-below.svg`, `assets/icons/clip-release.svg` | Clipping-mask cursors (⌥ over the line between two layers): a hooked arrow onto the layer below; the same with a small "no" badge to release | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
| `assets/icons/layer-mask.svg`, `assets/icons/adjustment-layer.svg` | Layers panel footer glyphs: Add a mask (a frame around a solid disc) and New Fill or Adjustment Layer (a circle, one half solid), drawn on Lucide's 24 px grid and stroke | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
+| `assets/icons/frame-placeholder.svg` | Frame tool glyph: an empty placeholder frame, crossed corner to corner | PhotoCraft contributors | Original work | MIT OR Apache-2.0 |
| `assets/icons/eraser-background.svg`, `assets/icons/eraser-magic.svg` | Background Eraser and Magic Eraser tool glyphs: Lucide `eraser` plus added marks | Lucide Icons and Contributors; marks by PhotoCraft contributors | Derived from <https://github.com/lucide-icons/lucide> `icons/eraser.svg` | ISC, [`assets/icons/LICENSE-lucide.txt`](assets/icons/LICENSE-lucide.txt) |
| `assets/icons/brush-replace.svg` | Color Replacement tool glyph: Lucide `brush` plus two swap arrows | Lucide Icons and Contributors; arrows by PhotoCraft contributors | Derived from <https://github.com/lucide-icons/lucide> `icons/brush.svg` | ISC, [`assets/icons/LICENSE-lucide.txt`](assets/icons/LICENSE-lucide.txt) |
| `assets/icons/bandage-sparkle.svg` | Remove tool glyph: Lucide `bandage` moved down, plus a sparkle mark | Lucide Icons and Contributors; mark by PhotoCraft contributors | Derived from <https://github.com/lucide-icons/lucide> `icons/bandage.svg` | ISC, [`assets/icons/LICENSE-lucide.txt`](assets/icons/LICENSE-lucide.txt) |
diff --git a/README.md b/README.md
index a9a67182a..249d165cc 100644
--- a/README.md
+++ b/README.md
@@ -178,8 +178,8 @@ Every screenshot here is the real app at work on public-domain art, rendered off
<table>
<tr>
<td width="33%" valign="top">
- <h4>🧰 64 tools</h4>
- Move · Artboard · Rectangular and Elliptical Marquee · Single Row Marquee · Single Column Marquee · Lasso · Polygonal Lasso · Magnetic Lasso · Object Selection · Quick Selection · Magic Wand · Crop · Perspective Crop · Slice · Slice Select · Eyedropper · Ruler · Note · Count · Remove · Spot Healing Brush · Healing Brush · Patch · Content-Aware Move · Red Eye · Brush · Pencil · Mixer Brush · Color Replacement · Clone Stamp · Pattern Stamp · History Brush · Eraser · Background Eraser · Magic Eraser · Gradient · Paint Bucket · Blur · Sharpen · Smudge · Dodge · Burn · Sponge · Pen · Freeform Pen · Curvature Pen · Add Anchor Point · Delete Anchor Point · Horizontal and Vertical Type · Horizontal and Vertical Type Mask · Path Selection · Direct Selection · Rectangle · Ellipse · Triangle · Polygon · Line · Custom Shape · Hand · Rotate View · Zoom
+ <h4>🧰 65 tools</h4>
+ Move · Artboard · Rectangular and Elliptical Marquee · Single Row Marquee · Single Column Marquee · Lasso · Polygonal Lasso · Magnetic Lasso · Object Selection · Quick Selection · Magic Wand · Crop · Perspective Crop · Slice · Slice Select · Frame · Eyedropper · Ruler · Note · Count · Remove · Spot Healing Brush · Healing Brush · Patch · Content-Aware Move · Red Eye · Brush · Pencil · Mixer Brush · Color Replacement · Clone Stamp · Pattern Stamp · History Brush · Eraser · Background Eraser · Magic Eraser · Gradient · Paint Bucket · Blur · Sharpen · Smudge · Dodge · Burn · Sponge · Pen · Freeform Pen · Curvature Pen · Add Anchor Point · Delete Anchor Point · Horizontal and Vertical Type · Horizontal and Vertical Type Mask · Path Selection · Direct Selection · Rectangle · Ellipse · Triangle · Polygon · Line · Custom Shape · Hand · Rotate View · Zoom
</td>
<td width="33%" valign="top">
<h4>🖌️ A real brush engine</h4>
diff --git a/assets/icons/frame-placeholder.svg b/assets/icons/frame-placeholder.svg
new file mode 100644
index 000000000..d765639bf
--- /dev/null
+++ b/assets/icons/frame-placeholder.svg
@@ -0,0 +1,15 @@
+<svg
+ xmlns="http://www.w3.org/2000/svg"
+ width="24"
+ height="24"
+ viewBox="0 0 24 24"
+ fill="none"
+ stroke="currentColor"
+ stroke-width="2"
+ stroke-linecap="round"
+ stroke-linejoin="round"
+>
+ <!-- PhotoCraft's own Frame tool glyph (not from an icon set): an empty placeholder frame, crossed corner to corner. -->
+ <rect x="3" y="4" width="18" height="16" rx="1" />
+ <path d="M6.5 7.5l11 9M17.5 7.5l-11 9" />
+</svg>
diff --git a/crates/engine/src/frame_cmds.rs b/crates/engine/src/frame_cmds.rs
index 739715e57..75c24df7c 100644
--- a/crates/engine/src/frame_cmds.rs
+++ b/crates/engine/src/frame_cmds.rs
@@ -2,9 +2,11 @@
//! hold an image (or placeholder) that is cropped to the frame. We build it from existing
//! primitives: group the selected layers, then clip the group with a rectangular layer mask the
//! size of their bounds — the same visual result Photoshop's Frame tool produces for this command.
-//! Headless and scriptable like every other command.
+//! `layer.new.frame` is the Frame tool's (K) command: a rectangular or elliptical frame drawn on
+//! the canvas, empty or holding the pixel layer it was drawn over. Headless and scriptable like
+//! every other command.
-use photocraft_doc::{LayerId, LayerMask, PixelFormat};
+use photocraft_doc::{Layer, LayerContent, LayerId, LayerMask, PixelFormat};
use photocraft_geom::Rect;
use serde_json::{Value, json};
@@ -74,17 +76,106 @@ fn frame_group(s: &mut Session, grouped: &Value) -> Result<Value> {
Ok(json!({"layer": gid.0, "frame": [rect.x0, rect.y0, rect.width(), rect.height()]}))
}
+/// The largest frame side (px) `layer.new.frame` accepts, as Photoshop's canvas limit.
+const MAX_FRAME_SIDE: i32 = 300_000;
+
+/// A reveal mask that is on inside the ellipse inscribed in `rect` and off everywhere else, with
+/// 4x4-supersampled edges (as the Elliptical Marquee). Only pixels inside `area` are written.
+fn ellipse_mask(rect: Rect, area: Rect) -> LayerMask {
+ let mut mask = LayerMask::hide_all();
+ let (cx, cy) = ((f64::from(rect.x0) + f64::from(rect.x1)) / 2.0, (f64::from(rect.y0) + f64::from(rect.y1)) / 2.0);
+ let (rx, ry) = (f64::from(rect.width().max(1)) / 2.0, f64::from(rect.height().max(1)) / 2.0);
+ let inside = |x: f64, y: f64| {
+ let (dx, dy) = ((x - cx) / rx, (y - cy) / ry);
+ dx * dx + dy * dy <= 1.0
+ };
+ let cut = rect.intersect(&area);
+ for y in cut.y0..cut.y1 {
+ for x in cut.x0..cut.x1 {
+ let (fx, fy) = (f64::from(x), f64::from(y));
+ let n = (0..16).filter(|i| inside(fx + (f64::from(i % 4) + 0.5) / 4.0, fy + (f64::from(i / 4) + 0.5) / 4.0)).count();
+ if n > 0 {
+ mask.surface.write_pixel(x, y, &[n as f32 / 16.0]);
+ }
+ }
+ }
+ mask.surface.prune();
+ mask
+}
+
+/// Frame tool (K): a new frame — a group clipped to the drawn rectangle or ellipse — as one
+/// history step. With `layer` (a pixel layer, not the Background), that layer becomes the frame's
+/// content, as when a frame is drawn over a selected pixel layer in Photoshop; else it is empty.
+fn new_frame(s: &mut Session, p: &Value) -> Result<Value> {
+ const CMD: &str = "layer.new.frame";
+ let bad = |msg: String| EngineError::BadParams { cmd: CMD.into(), msg };
+ let get = |k: &str| crate::commands::int_i32(CMD, p, k)?.ok_or_else(|| bad(format!("missing `{k}`")));
+ let (x, y, w, h) = (get("x")?, get("y")?, get("width")?, get("height")?);
+ if !(1..=MAX_FRAME_SIDE).contains(&w) || !(1..=MAX_FRAME_SIDE).contains(&h) {
+ return Err(bad(format!("`width` and `height` must be 1..={MAX_FRAME_SIDE}")));
+ }
+ let (Some(x1), Some(y1)) = (x.checked_add(w), y.checked_add(h)) else {
+ return Err(bad("the frame is outside the 32-bit coordinate range".into()));
+ };
+ let rect = Rect::new(x, y, x1, y1);
+ let ellipse = match p.get("shape").map(|v| v.as_str()) {
+ None | Some(Some("rectangle")) => false,
+ Some(Some("ellipse")) => true,
+ Some(_) => return Err(bad("`shape` must be \"rectangle\" or \"ellipse\"".into())),
+ };
+ let content = match p.get("layer") {
+ None | Some(Value::Null) => None,
+ Some(v) => Some(LayerId(v.as_u64().ok_or_else(|| bad(format!("`layer` = {v} is not a layer id")))?)),
+ };
+ let name = p.get("name").and_then(Value::as_str).map(str::to_string);
+ let gid = s.edit("New Frame", |doc, active| {
+ let mask = if ellipse { ellipse_mask(rect, doc.bounds()) } else { clip_mask(rect.intersect(&doc.bounds())) };
+ let name = name.unwrap_or_else(|| doc.next_layer_name("Frame"));
+ let gid = match content {
+ Some(id) => {
+ let l = doc.layer(id).ok_or(EngineError::NoLayer(id))?;
+ if !matches!(l.content, LayerContent::Raster(_)) || crate::extra_cmds::is_background(l) {
+ return Err(bad("only a pixel layer (not the Background) can go in a frame".into()));
+ }
+ let gid = doc.insert_above(Some(id), Layer::group(name, vec![]));
+ let child = doc.remove(id).ok_or(EngineError::NoLayer(id))?;
+ doc.layer_mut(gid).and_then(Layer::children_mut).ok_or(EngineError::NoLayer(gid))?.push(child);
+ crate::layer_multi_cmds::check_group_depth(doc, "New Frame")?;
+ gid
+ }
+ None => doc.insert_above(*active, Layer::group(name, vec![])),
+ };
+ doc.layer_mut(gid).ok_or(EngineError::NoLayer(gid))?.mask = Some(mask);
+ *active = Some(gid);
+ Ok(gid)
+ })?;
+ crate::layer_multi_cmds::reselect(s, vec![gid], Some(gid));
+ Ok(json!({"layer": gid.0, "frame": [x, y, w, h], "shape": if ellipse { "ellipse" } else { "rectangle" }}))
+}
+
pub fn specs() -> Vec<CommandSpec> {
- vec![CommandSpec {
- id: "layer.new.frameFromLayers",
- label: "Frame from Layers",
- menu: &["Layer", "New"],
- shortcut: None,
- params: r#"{"name":str?} → {layer, frame:[x,y,w,h]}: groups the selected layers and clips them to a frame rect"#,
- enabled: has_layer,
- journal: true,
- run: |s, p| frame_from_layers(s, p),
- }]
+ vec![
+ CommandSpec {
+ id: "layer.new.frame",
+ label: "New Frame",
+ menu: &[],
+ shortcut: None,
+ params: r#"{"x":i32,"y":i32,"width":u32,"height":u32,"shape":"rectangle|ellipse"="rectangle","layer":id?,"name":str?} → {layer, frame:[x,y,w,h], shape}: Frame tool; a group clipped to the shape, holding pixel layer `layer` if given"#,
+ enabled: |s| s.active().map(|_| ()).ok_or_else(|| "no document open".into()),
+ journal: true,
+ run: new_frame,
+ },
+ CommandSpec {
+ id: "layer.new.frameFromLayers",
+ label: "Frame from Layers",
+ menu: &["Layer", "New"],
+ shortcut: None,
+ params: r#"{"name":str?} → {layer, frame:[x,y,w,h]}: groups the selected layers and clips them to a frame rect"#,
+ enabled: has_layer,
+ journal: true,
+ run: |s, p| frame_from_layers(s, p),
+ },
+ ]
}
#[cfg(test)]
@@ -151,6 +242,35 @@ mod tests {
assert!(s.active().unwrap().doc.layer(gid).is_some_and(|g| g.mask.is_some()), "redo brings back the framed group");
}
+ /// Frame tool: a rectangular frame is an empty group clipped to the drawn rect, undone in one
+ /// step; an elliptical one hides the corners; drawn over a pixel layer, it holds that layer.
+ #[test]
+ fn new_frame_clips_a_group_to_the_drawn_shape() {
+ let (mut s, a, _) = session();
+ let count = |s: &Session| s.active().unwrap().doc.layers.len();
+ let before = count(&s);
+ let r = s.execute("layer.new.frame", json!({"x": 10, "y": 10, "width": 40, "height": 30})).unwrap();
+ let gid = LayerId(r["layer"].as_u64().unwrap());
+ let st = s.active().unwrap();
+ let g = st.doc.layer(gid).unwrap();
+ assert!(matches!(&g.content, LayerContent::Group(c) if c.children.is_empty()), "an empty frame");
+ let m = g.mask.as_ref().unwrap();
+ assert_eq!((m.value(10, 10), m.value(49, 39), m.value(9, 10), m.value(50, 39)), (1.0, 1.0, 0.0, 0.0));
+ assert_eq!((g.name.as_str(), st.active_layer), ("Frame 1", Some(gid)));
+ assert!(s.undo());
+ assert_eq!(count(&s), before, "one undo removes the frame");
+
+ let r = s.execute("layer.new.frame", json!({"x": 10, "y": 10, "width": 40, "height": 30, "shape": "ellipse", "layer": a.0})).unwrap();
+ let gid = LayerId(r["layer"].as_u64().unwrap());
+ let g = s.active().unwrap().doc.layer(gid).unwrap();
+ assert!(matches!(&g.content, LayerContent::Group(c) if c.children.iter().map(|l| l.id).eq([a])), "the frame holds layer A");
+ let m = g.mask.as_ref().unwrap();
+ assert_eq!((m.value(30, 25), m.value(10, 10)), (1.0, 0.0), "centre shown, corner hidden");
+ for bad in [json!({"x": 0, "y": 0, "width": 0, "height": 5}), json!({"x": 0, "y": 0, "width": 5, "height": 5, "shape": "star"}), json!({"x": 0})] {
+ assert!(s.execute("layer.new.frame", bad).is_err());
+ }
+ }
+
#[test]
fn needs_a_selected_layer() {
let mut s = Session::new();
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index 7d5ac68c9..b99b8780e 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -3147,6 +3147,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
crate::analysis_ui::draw_overlay(app, &painter, &xf);
crate::gradient_ui::draw_overlay(app, &painter, &xf);
crate::slice_ui::draw_overlay(app, &painter, &xf);
+ crate::frame_tool::draw_overlay(app, &painter, &xf);
crate::artboard_tool::draw_overlay(app, &painter, &xf);
// Tool cursors (Photoshop-style).
let guide_hover = response.hover_pos().and_then(|p| {
@@ -4194,6 +4195,10 @@ pub fn tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers)
if crate::slice_ui::pointer(app, ev, mods) {
return;
}
+ // Frame tool: draw rectangular and elliptical frames.
+ if crate::frame_tool::pointer(app, ev, mods) {
+ return;
+ }
// Artboard tool: draw, select, move and resize boards.
if crate::artboard_tool::pointer(app, ev, mods) {
return;
diff --git a/crates/ui-egui/src/frame_tool.rs b/crates/ui-egui/src/frame_tool.rs
new file mode 100644
index 000000000..28eb55628
--- /dev/null
+++ b/crates/ui-egui/src/frame_tool.rs
@@ -0,0 +1,187 @@
+//! Frame tool (K): drag on the canvas to draw a rectangular or elliptical frame (the options bar
+//! picks the shape). ⇧ makes it a square or circle, ⌥ draws it from the centre. Drawn over the
+//! selected pixel layer's content, the frame takes that layer in, as in Photoshop; else it is an
+//! empty placeholder. Each frame is one engine command (`layer.new.frame`), so one undo step; this
+//! module only turns the drag into it.
+
+use egui::{Pos2, Stroke};
+use photocraft_doc::LayerContent;
+use serde::{Deserialize, Serialize};
+use serde_json::json;
+
+use crate::PhotocraftApp;
+use crate::canvas::{ToolEvent, ViewXform};
+use crate::state::Tool;
+use crate::theme::Tokens;
+
+/// A press that moves less than this (screen points) is a click, not a drawn frame.
+const CLICK_PX: f64 = 3.0;
+
+/// Frame tool state (serde: readable and settable through the control channel).
+#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
+#[serde(default)]
+pub struct FrameToolUi {
+ /// Options bar: draw elliptical frames (else rectangular).
+ pub ellipse: bool,
+ /// The drag in progress: press and current point (document pixels), ⇧ and ⌥ at the last event.
+ #[serde(skip)]
+ pub drag: Option<FrameDrag>,
+}
+
+#[derive(Clone, Copy, Debug, PartialEq)]
+pub struct FrameDrag {
+ pub start: [f64; 2],
+ pub cur: [f64; 2],
+ pub square: bool,
+ pub centred: bool,
+}
+
+/// The frame a drag leaves, `[x0, y0, x1, y1]` on whole pixels.
+fn drawn(d: &FrameDrag) -> [i64; 4] {
+ let (mut dx, mut dy) = (d.cur[0] - d.start[0], d.cur[1] - d.start[1]);
+ if d.square {
+ let side = dx.abs().max(dy.abs());
+ (dx, dy) = (side.copysign(dx), side.copysign(dy));
+ }
+ let (a, b) =
+ if d.centred { ([d.start[0] - dx, d.start[1] - dy], [d.start[0] + dx, d.start[1] + dy]) } else { (d.start, [d.start[0] + dx, d.start[1] + dy]) };
+ [a[0].min(b[0]), a[1].min(b[1]), a[0].max(b[0]), a[1].max(b[1])].map(|v| v.round() as i64)
+}
+
+/// The selected pixel layer the frame `r` takes in: one whose content it overlaps and that can
+/// move (not the Background or a position-locked layer).
+fn content_layer(app: &PhotocraftApp, r: [i64; 4]) -> Option<u64> {
+ let st = app.session.active()?;
+ let l = st.doc.layer(st.active_layer?)?;
+ if !matches!(l.content, LayerContent::Raster(_)) || l.locks.position || l.locks.all {
+ return None;
+ }
+ let b = l.surface()?.content_bounds();
+ let overlaps = i64::from(b.x0) < r[2] && r[0] < i64::from(b.x1) && i64::from(b.y0) < r[3] && r[1] < i64::from(b.y1);
+ (!b.is_empty() && overlaps).then_some(l.id.0)
+}
+
+/// Pointer input for the Frame tool. Returns true when the event was its own.
+pub fn pointer(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers) -> bool {
+ if app.ui.tool != Tool::Frame {
+ return false;
+ }
+ let (square, centred) = (mods.shift, mods.alt);
+ match ev {
+ ToolEvent::Down { x, y, .. } => {
+ if app.session.active().is_some() {
+ app.ui.frame_tool.drag = Some(FrameDrag { start: [x, y], cur: [x, y], square, centred });
+ }
+ }
+ ToolEvent::Move { x, y, .. } => {
+ if let Some(d) = &mut app.ui.frame_tool.drag {
+ *d = FrameDrag { cur: [x, y], square, centred, ..*d };
+ }
+ }
+ ToolEvent::Up { x, y } => {
+ let Some(mut d) = app.ui.frame_tool.drag.take() else { return true };
+ d.cur = [x, y];
+ let screen = (d.cur[0] - d.start[0]).hypot(d.cur[1] - d.start[1]) * f64::from(app.point_zoom());
+ let r = drawn(&d);
+ if screen < CLICK_PX || r[2] <= r[0] || r[3] <= r[1] {
+ return true;
+ }
+ let mut p = json!({
+ "x": r[0], "y": r[1], "width": r[2] - r[0], "height": r[3] - r[1],
+ "shape": if app.ui.frame_tool.ellipse { "ellipse" } else { "rectangle" },
+ });
+ if let Some(id) = content_layer(app, r) {
+ p["layer"] = json!(id);
+ }
+ if let Err(e) = app.run("layer.new.frame", p) {
+ app.ui.status = e;
+ app.ui.status_error = true;
+ }
+ }
+ }
+ true
+}
+
+/// The frame a drag in progress would leave.
+pub fn draw_overlay(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform) {
+ let Some(d) = app.ui.frame_tool.drag.filter(|_| app.ui.tool == Tool::Frame) else { return };
+ let t = Tokens::get(painter.ctx());
+ let r = drawn(&d).map(|v| v as f32);
+ let stroke = Stroke::new(1.5, t.accent);
+ let points: Vec<Pos2> = if app.ui.frame_tool.ellipse {
+ let (cx, cy, rx, ry) = ((r[0] + r[2]) / 2.0, (r[1] + r[3]) / 2.0, (r[2] - r[0]) / 2.0, (r[3] - r[1]) / 2.0);
+ (0..=64).map(|i| i as f32 * std::f32::consts::TAU / 64.0).map(|a| xf.to_screen(cx + rx * a.cos(), cy + ry * a.sin())).collect()
+ } else {
+ [(r[0], r[1]), (r[2], r[1]), (r[2], r[3]), (r[0], r[3]), (r[0], r[1])].into_iter().map(|(x, y)| xf.to_screen(x, y)).collect()
+ };
+ painter.add(egui::Shape::line(points, stroke));
+}
+
+/// The Frame tool's options bar: Create a new rectangular frame / elliptical frame.
+pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bool {
+ if tool != Tool::Frame {
+ return false;
+ }
+ let ellipse = app.ui.frame_tool.ellipse;
+ if crate::icons::button(ui, "square", 24.0, !ellipse, tl!("Create a new rectangular frame")).clicked() {
+ app.ui.frame_tool.ellipse = false;
+ }
+ if crate::icons::button(ui, "circle", 24.0, ellipse, tl!("Create a new elliptical frame")).clicked() {
+ app.ui.frame_tool.ellipse = true;
+ }
+ true
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+ use crate::canvas::tool_event;
+ use photocraft_doc::LayerId;
+
+ fn drag(app: &mut PhotocraftApp, from: [f64; 2], to: [f64; 2]) {
+ let m = egui::Modifiers::NONE;
+ tool_event(app, ToolEvent::Down { x: from[0], y: from[1], pressure: 1.0 }, m);
+ tool_event(app, ToolEvent::Move { x: to[0], y: to[1], pressure: 1.0 }, m);
+ tool_event(app, ToolEvent::Up { x: to[0], y: to[1] }, m);
+ }
+
+ /// K picks the Frame tool; a rectangular drag makes one frame (one undo step) clipped to the
+ /// drawn rect; with the elliptical button the frame's corners are hidden.
+ #[test]
+ fn frame_tool_draws_rectangular_and_elliptical_frames() {
+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
+ app.run("file.new", json!({"width": 400, "height": 300})).unwrap();
+ app.sync_views();
+ app.ui.extras.snap = false;
+ let ctx = egui::Context::default();
+ let raw = egui::RawInput {
+ events: vec![egui::Event::Key { key: egui::Key::K, physical_key: None, pressed: true, repeat: false, modifiers: egui::Modifiers::NONE }],
+ ..Default::default()
+ };
+ ctx.begin_pass(raw);
+ crate::shortcuts::handle(&mut app, &ctx);
+ ctx.end_pass().textures_delta.clear();
+ assert_eq!(app.ui.tool, Tool::Frame);
+
+ let frame = |app: &PhotocraftApp| {
+ let st = app.session.active().unwrap();
+ let l = st.doc.layer(st.active_layer.unwrap()).unwrap();
+ assert!(matches!(l.content, LayerContent::Group(_)) && l.name.starts_with("Frame"), "the new frame is selected");
+ (l.id, l.mask.clone().unwrap())
+ };
+ let layers = app.session.active().unwrap().doc.layers.len();
+ drag(&mut app, [20.0, 30.0], [120.0, 110.0]);
+ let (_, m) = frame(&app);
+ assert_eq!((m.value(20, 30), m.value(119, 109), m.value(19, 30), m.value(120, 109)), (1.0, 1.0, 0.0, 0.0));
+ app.run("edit.undo", json!({})).unwrap();
+ assert_eq!(app.session.active().unwrap().doc.layers.len(), layers, "one undo takes the frame back");
+
+ app.ui.frame_tool.ellipse = true;
+ drag(&mut app, [20.0, 30.0], [120.0, 110.0]);
+ let (id, m): (LayerId, _) = frame(&app);
+ assert_eq!((m.value(70, 70), m.value(20, 30)), (1.0, 0.0), "centre shown, corner hidden");
+ // A click draws nothing.
+ drag(&mut app, [300.0, 250.0], [300.0, 250.0]);
+ assert_eq!(frame(&app).0, id);
+ }
+}
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv
index ddb81bd48..02e36d68a 100644
--- a/crates/ui-egui/src/i18n/cs.tsv
+++ b/crates/ui-egui/src/i18n/cs.tsv
@@ -2496,6 +2496,9 @@ cameraData Lens Objektiv
Previous Document Předchozí dokument
W x H x Resolution Š x V x Rozlišení
Front Image Přední obraz
+ Frame Tool Nástroj rámeček
+ Create a new rectangular frame Vytvořit nový obdélníkový rámeček
+ Create a new elliptical frame Vytvořit nový eliptický rámeček
Include in playback Zahrnout do přehrávání
Perspective Crop Tool Nástroj perspektivní oříznutí
Show Grid Zobrazit mřížku
diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv
index 3f5e126f5..d5fe68f51 100644
--- a/crates/ui-egui/src/i18n/de.tsv
+++ b/crates/ui-egui/src/i18n/de.tsv
@@ -2529,6 +2529,9 @@ cameraData Lens Objektiv
Previous Document Vorheriges Dokument
W x H x Resolution B x H x Auflösung
Front Image Vorderes Bild
+ Frame Tool Rahmenwerkzeug
+ Create a new rectangular frame Neuen rechteckigen Rahmen erstellen
+ Create a new elliptical frame Neuen elliptischen Rahmen erstellen
Include in playback In Wiedergabe einbeziehen
Perspective Crop Tool Perspektivisches Freistellungswerkzeug
Show Grid Raster einblenden
diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv
index f9e9fbd62..3b0c12a11 100644
--- a/crates/ui-egui/src/i18n/el.tsv
+++ b/crates/ui-egui/src/i18n/el.tsv
@@ -3593,6 +3593,9 @@ cameraData Lens Φακός
Previous Document Προηγούμενο έγγραφο
W x H x Resolution Π x Υ x Ανάλυση
Front Image Μπροστινή εικόνα
+ Frame Tool Εργαλείο πλαισίου
+ Create a new rectangular frame Δημιουργία νέου ορθογώνιου πλαισίου
+ Create a new elliptical frame Δημιουργία νέου ελλειπτικού πλαισίου
Include in playback Συμπερίληψη στην αναπαραγωγή
Perspective Crop Tool Περικοπή προοπτικής (Perspective Crop Tool)
Drag a box or click four corners · drag the corners onto the edges of a skewed shape · {commit} commits · Esc cancels Σύρετε ένα πλαίσιο ή κάντε κλικ σε τέσσερις γωνίες · σύρετε τις γωνίες στις άκρες ενός λοξού σχήματος · {commit} για εφαρμογή · Esc για ακύρωση
diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv
index d03df2587..df6dfd2aa 100644
--- a/crates/ui-egui/src/i18n/es.tsv
+++ b/crates/ui-egui/src/i18n/es.tsv
@@ -2570,6 +2570,9 @@ cameraData Lens Objetivo
Previous Document Documento anterior
W x H x Resolution An. x Al. x Resolución
Front Image Imagen frontal
+ Frame Tool Herramienta Marco
+ Create a new rectangular frame Crear un marco rectangular nuevo
+ Create a new elliptical frame Crear un marco elíptico nuevo
Include in playback Incluir en la reproducción
Perspective Crop Tool Herramienta Recortar con perspectiva
Show Grid Mostrar cuadrícula
diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv
index b1180f6c4..3dbc15e6c 100644
--- a/crates/ui-egui/src/i18n/fr.tsv
+++ b/crates/ui-egui/src/i18n/fr.tsv
@@ -2907,6 +2907,9 @@ cameraData Lens Objectif
Previous Document Document précédent
W x H x Resolution L x H x Résolution
Front Image Image de premier plan
+ Frame Tool Outil Cadre
+ Create a new rectangular frame Créer un cadre rectangulaire
+ Create a new elliptical frame Créer un cadre elliptique
Include in playback Inclure dans la lecture
Perspective Crop Tool Outil Recadrage perspective
Show Grid Afficher la grille
diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv
index 2e0804bc0..6083c94dc 100644
--- a/crates/ui-egui/src/i18n/id.tsv
+++ b/crates/ui-egui/src/i18n/id.tsv
@@ -2894,6 +2894,9 @@ cameraData Lens Lensa
Previous Document Dokumen Sebelumnya
W x H x Resolution L x T x Resolusi
Front Image Gambar Depan
+ Frame Tool Alat Bingkai
+ Create a new rectangular frame Buat bingkai persegi panjang baru
+ Create a new elliptical frame Buat bingkai elips baru
Include in playback Sertakan dalam pemutaran
Perspective Crop Tool Alat Crop Perspektif
Show Grid Tampilkan Grid
diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv
index 3386fa0aa..4eeda8a3e 100644
--- a/crates/ui-egui/src/i18n/it.tsv
+++ b/crates/ui-egui/src/i18n/it.tsv
@@ -2560,6 +2560,9 @@ cameraData Lens Obiettivo
Previous Document Documento precedente
W x H x Resolution L x A x Risoluzione
Front Image Immagine in primo piano
+ Frame Tool Strumento Cornice
+ Create a new rectangular frame Crea una nuova cornice rettangolare
+ Create a new elliptical frame Crea una nuova cornice ellittica
Include in playback Includi nella riproduzione
Perspective Crop Tool Strumento Taglierina prospettica
Show Grid Mostra griglia
diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv
index e25db1cac..c7777e64a 100644
--- a/crates/ui-egui/src/i18n/ja.tsv
+++ b/crates/ui-egui/src/i18n/ja.tsv
@@ -3508,6 +3508,9 @@ cameraData Lens レンズ
Previous Document 前のドキュメント
W x H x Resolution 幅 x 高さ x 解像度
Front Image 前面の画像
+ Frame Tool フレームツール
+ Create a new rectangular frame 新しい長方形フレームを作成
+ Create a new elliptical frame 新しい楕円形フレームを作成
Include in playback 再生に含める
Perspective Crop Tool 遠近法の切り抜きツール
Show Grid グリッドを表示
diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv
index ce7b9ea86..f6b1bee14 100644
--- a/crates/ui-egui/src/i18n/ko.tsv
+++ b/crates/ui-egui/src/i18n/ko.tsv
@@ -3074,6 +3074,9 @@ cameraData Lens 렌즈
Previous Document 이전 문서
W x H x Resolution 폭 x 높이 x 해상도
Front Image 전면 이미지
+ Frame Tool 프레임 도구
+ Create a new rectangular frame 새 사각형 프레임 만들기
+ Create a new elliptical frame 새 타원형 프레임 만들기
Include in playback 재생에 포함
Perspective Crop Tool 원근 자르기 도구
Show Grid 격자 표시
diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv
index ef4e6759c..8d1e1f6c6 100644
--- a/crates/ui-egui/src/i18n/nl.tsv
+++ b/crates/ui-egui/src/i18n/nl.tsv
@@ -3681,4 +3681,7 @@ cameraData Lens Lens
Search settings… Instellingen zoeken…
No matching settings Geen overeenkomende instellingen
PhotoCraft — Screen Color Picker PhotoCraft — Schermkleurkiezer
+ Frame Tool Kadergereedschap
+ Create a new rectangular frame Nieuw rechthoekig kader maken
+ Create a new elliptical frame Nieuw ovaal kader maken
Include in playback Opnemen in afspelen
diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv
index 279baf77c..4e87d5b53 100644
--- a/crates/ui-egui/src/i18n/pl.tsv
+++ b/crates/ui-egui/src/i18n/pl.tsv
@@ -3509,6 +3509,9 @@ cameraData Lens Obiektyw
Previous Document Poprzedni dokument
W x H x Resolution Szer. x Wys. x Rozdzielczość
Front Image Obraz na wierzchu
+ Frame Tool Narzędzie Ramka
+ Create a new rectangular frame Utwórz nową ramkę prostokątną
+ Create a new elliptical frame Utwórz nową ramkę eliptyczną
Include in playback Uwzględnij w odtwarzaniu
Perspective Crop Tool Narzędzie Kadrowanie perspektywiczne
Show Grid Pokaż siatkę
diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv
index 36197a61d..587069bd5 100644
--- a/crates/ui-egui/src/i18n/pt-br.tsv
+++ b/crates/ui-egui/src/i18n/pt-br.tsv
@@ -2915,6 +2915,9 @@ cameraData Lens Lente
Previous Document Documento anterior
W x H x Resolution L x A x Resolução
Front Image Imagem frontal
+ Frame Tool Ferramenta Quadro
+ Create a new rectangular frame Criar um quadro retangular
+ Create a new elliptical frame Criar um quadro elíptico
Include in playback Incluir na reprodução
Perspective Crop Tool Ferramenta Corte demarcado em perspectiva
Show Grid Mostrar grade
diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv
index 71d865f09..0b950a69d 100644
--- a/crates/ui-egui/src/i18n/ru.tsv
+++ b/crates/ui-egui/src/i18n/ru.tsv
@@ -2834,6 +2834,9 @@ cameraData Lens Объектив
Previous Document Предыдущий документ
W x H x Resolution Ш x В x Разрешение
Front Image Изображение переднего плана
+ Frame Tool Рамка
+ Create a new rectangular frame Создать прямоугольную рамку
+ Create a new elliptical frame Создать эллиптическую рамку
Include in playback Включить в воспроизведение
Perspective Crop Tool Кадрирование перспективы
Show Grid Показать сетку
diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv
index b119ff19b..66ea4366c 100644
--- a/crates/ui-egui/src/i18n/uk.tsv
+++ b/crates/ui-egui/src/i18n/uk.tsv
@@ -3609,6 +3609,9 @@ cameraData Lens Об'єктив
Search settings… Пошук налаштувань…
No matching settings Немає відповідних налаштувань
PhotoCraft — Screen Color Picker PhotoCraft — Піпетка кольору екрана
+ Frame Tool Інструмент «Рамка»
+ Create a new rectangular frame Створити прямокутну рамку
+ Create a new elliptical frame Створити еліптичну рамку
Include in playback Включити у відтворення
New Crop Preset… Новий набір параметрів кадрування…
Delete Crop Preset… Видалити набір параметрів кадрування…
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index 409809c50..1c36a77ac 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -2503,6 +2503,9 @@ cameraData Lens 镜头
Previous Document 上一个文档
W x H x Resolution 宽 x 高 x 分辨率
Front Image 前面的图像
+ Frame Tool 图框工具
+ Create a new rectangular frame 新建矩形图框
+ Create a new elliptical frame 新建椭圆图框
Include in playback 包含在播放中
Perspective Crop Tool 透视裁剪工具
Show Grid 显示网格
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index acd9026ab..cba84fda3 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -2473,6 +2473,9 @@ cameraData Lens 鏡頭
Previous Document 上一個文件
W x H x Resolution 寬 x 高 x 解析度
Front Image 前面的影像
+ Frame Tool 影格工具
+ Create a new rectangular frame 建立新的矩形影格
+ Create a new elliptical frame 建立新的橢圓形影格
Include in playback 包含在播放中
Perspective Crop Tool 透視裁切工具
Show Grid 顯示格點
diff --git a/crates/ui-egui/src/icon_data.rs b/crates/ui-egui/src/icon_data.rs
index dc64bc5ad..ab280d585 100644
--- a/crates/ui-egui/src/icon_data.rs
+++ b/crates/ui-egui/src/icon_data.rs
@@ -49,6 +49,7 @@ pub static ICONS: &[(&str, &[u8])] = &[
("folder", include_bytes!("../../../assets/icons/folder.svg")),
("folder-open", include_bytes!("../../../assets/icons/folder-open.svg")),
("folder-plus", include_bytes!("../../../assets/icons/folder-plus.svg")),
+ ("frame-placeholder", include_bytes!("../../../assets/icons/frame-placeholder.svg")),
("gauge", include_bytes!("../../../assets/icons/gauge.svg")),
("grid-2x2", include_bytes!("../../../assets/icons/grid-2x2.svg")),
("grid-3x3", include_bytes!("../../../assets/icons/grid-3x3.svg")),
diff --git a/crates/ui-egui/src/icons.rs b/crates/ui-egui/src/icons.rs
index 5df343c8c..0675b2e64 100644
--- a/crates/ui-egui/src/icons.rs
+++ b/crates/ui-egui/src/icons.rs
@@ -109,6 +109,7 @@ pub fn tool_icon(t: Tool) -> &'static str {
Tool::PerspectiveCrop => "perspective-crop",
Tool::Slice => "slice-knife",
Tool::SliceSelect => "square-dashed-mouse-pointer",
+ Tool::Frame => "frame-placeholder",
Tool::Gradient => "blend",
Tool::PaintBucket => "paint-bucket",
Tool::Type | Tool::VerticalType => "type",
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 378b4d768..406b9b122 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -76,6 +76,7 @@ pub mod filter_dialog;
#[cfg(not(target_arch = "wasm32"))]
mod filter_preview_worker;
mod font_preview;
+pub mod frame_tool;
pub mod gallery_ui;
pub mod gpu_canvas;
pub mod gpu_status;
diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs
index 87a1d58e9..6fc11515f 100644
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@ -21,6 +21,7 @@ const TOOL_SECTIONS: &[&[&[Tool]]] = &[
&[Tool::Lasso, Tool::PolygonLasso, Tool::MagneticLasso],
&[Tool::ObjectSelection, Tool::QuickSelection, Tool::MagicWand],
&[Tool::Crop, Tool::PerspectiveCrop, Tool::Slice, Tool::SliceSelect],
+ &[Tool::Frame],
&[Tool::Eyedropper, Tool::Ruler, Tool::Note, Tool::Count],
],
&[
@@ -888,6 +889,7 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
|| crate::vector_ui::options_bar(app, ui, tool)
|| crate::analysis_ui::options_bar(app, ui, tool)
|| crate::slice_ui::options_bar(app, ui, tool)
+ || crate::frame_tool::options_bar(app, ui, tool)
|| crate::artboard_tool::options_bar(app, ui, tool)
{
return;
diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs
index d3a75d37e..9e3112419 100644
--- a/crates/ui-egui/src/state.rs
+++ b/crates/ui-egui/src/state.rs
@@ -130,10 +130,11 @@ pub enum Tool {
CustomShape,
Slice,
SliceSelect,
+ Frame,
}
impl Tool {
- pub const ALL: [Tool; 64] = [
+ pub const ALL: [Tool; 65] = [
Tool::Move,
Tool::Artboard,
Tool::RectMarquee,
@@ -198,6 +199,7 @@ impl Tool {
Tool::CustomShape,
Tool::Slice,
Tool::SliceSelect,
+ Tool::Frame,
];
pub fn label(self) -> &'static str {
@@ -227,6 +229,7 @@ impl Tool {
Tool::PerspectiveCrop => "Perspective Crop Tool",
Tool::Slice => "Slice Tool",
Tool::SliceSelect => "Slice Select Tool",
+ Tool::Frame => "Frame Tool",
Tool::Gradient => "Gradient Tool",
Tool::PaintBucket => "Paint Bucket Tool",
Tool::Type => "Horizontal Type Tool",
@@ -315,6 +318,7 @@ impl Tool {
Tool::Lasso | Tool::PolygonLasso | Tool::MagneticLasso => 'L',
Tool::MagicWand => 'W',
Tool::Crop | Tool::PerspectiveCrop | Tool::Slice | Tool::SliceSelect => 'C',
+ Tool::Frame => 'K',
Tool::Gradient | Tool::PaintBucket => 'G',
Tool::Type | Tool::VerticalType | Tool::HorizontalTypeMask | Tool::VerticalTypeMask => 'T',
Tool::Hand => 'H',
@@ -1051,8 +1055,10 @@ pub struct UiState {
/// Slice and Slice Select tools (see `slice_ui`).
#[serde(default)]
pub slices: crate::slice_ui::SliceUi,
- /// Artboard tool (see `artboard_tool`).
+ /// Frame tool (see `frame_tool`).
#[serde(default)]
+ pub frame_tool: crate::frame_tool::FrameToolUi,
+ /// Artboard tool (see `artboard_tool`).
pub artboard_tool: crate::artboard_tool::ArtboardToolUi,
/// Modifier Keys panel, custom pixel aspect ratios, workspace dialogs (see `workspace_ui`).
#[serde(default)]
@@ -1184,6 +1190,7 @@ impl Default for UiState {
analysis: Default::default(),
timeline: Default::default(),
slices: Default::default(),
+ frame_tool: Default::default(),
artboard_tool: Default::default(),
shell: Default::default(),
layer_filter: Vec::new(),
@@ -1293,7 +1300,7 @@ mod tests {
assert!(!Tool::RedEye.is_brushlike());
assert_eq!(Tool::from_name("patternStamp"), Some(Tool::PatternStamp));
assert_eq!(Tool::from_name("Pattern Stamp Tool"), Some(Tool::PatternStamp));
- assert_eq!(Tool::ALL.len(), 64);
+ assert_eq!(Tool::ALL.len(), 65);
assert_eq!(Tool::from_name("Vertical Type Mask Tool"), Some(Tool::VerticalTypeMask));
assert_eq!(Tool::from_name("addAnchorPoint"), Some(Tool::AddAnchorPoint));
assert_eq!(Tool::from_name("Delete Anchor Point Tool"), Some(Tool::DeleteAnchorPoint));
diff --git a/crates/ui-egui/src/tool_reset.rs b/crates/ui-egui/src/tool_reset.rs
index 89a1c0dc2..17bfdad1b 100644
--- a/crates/ui-egui/src/tool_reset.rs
+++ b/crates/ui-egui/src/tool_reset.rs
@@ -181,7 +181,8 @@ pub fn reset_options(o: &mut ToolOptions, tool: Tool) {
| Tool::SliceSelect
| Tool::AddAnchorPoint
| Tool::DeleteAnchorPoint
- | Tool::Artboard => {}
+ | Tool::Artboard
+ | Tool::Frame => {}
}
}
diff --git a/docs/gaps.md b/docs/gaps.md
index d0419643d..a2ec3dddc 100644
--- a/docs/gaps.md
+++ b/docs/gaps.md
@@ -54,10 +54,11 @@ what an agent can't finish alone.
scripted check there) is the only real oracle.
### G6. Missing tools
-- **Missing (7 of 68):** Frame, Color Sampler (#1046), Color Replacement (engine command exists),
- Art History Brush, Add Anchor Point, Delete Anchor Point, Convert Point (only as Pen + ⌥).
- Freeform Pen and Curvature Pen landed (#1054); Horizontal and Vertical Type Mask landed (#1055,
- `type.createSelection`); Perspective Crop landed (#1043, `image.perspectiveCrop`).
+- **Missing (6 of 68):** Color Sampler (#1046), Color Replacement (engine command exists), Art
+ History Brush, Add Anchor Point, Delete Anchor Point, Convert Point (only as Pen + ⌥). Freeform
+ Pen and Curvature Pen landed (#1054); Horizontal and Vertical Type Mask landed (#1055,
+ `type.createSelection`); Perspective Crop landed (#1043, `image.perspectiveCrop`); Frame landed
+ (#2914).
- **Evidence:** `Tool` enum (`crates/ui-egui/src/state.rs`) against the 67 `<tool>` entries of
Photoshop's `Default Keyboard Shortcuts.kys` plus Remove, Triangle and Curvature Pen.
- **Impact:** users look for them by name and shortcut; several are daily tools for designers.
diff --git a/docs/target-app-parity.md b/docs/target-app-parity.md
index ecf7f99f8..7a4f238cc 100644
--- a/docs/target-app-parity.md
+++ b/docs/target-app-parity.md
@@ -61,7 +61,7 @@ architecture and the PSD writer are the serial parts.
| Component | Weight | Ours / Photoshop | % | Kind |
|---|---:|---|---:|---|
| Menu commands | 30% | 628 / 628 catalog items dispatch a live command | 100% | measured (`cargo xtask parity`) |
-| Toolbox tools | 15% | 57 / 68 (Photoshop's 67 `.kys` tools plus Remove, Triangle, Curvature Pen; minus legacy Rounded Rectangle and Targeted Adjustment) | 84% | measured (`Tool` enum in `ui-egui/src/state.rs`, `TOOL_SECTIONS` in `panels.rs`) |
+| Toolbox tools | 15% | 58 / 68 (Photoshop's 67 `.kys` tools plus Remove, Triangle, Curvature Pen; minus legacy Rounded Rectangle and Targeted Adjustment) | 85% | measured (`Tool` enum in `ui-egui/src/state.rs`, `TOOL_SECTIONS` in `panels.rs`) |
| Panels | 10% | 30 / 35 Window-menu panels | 86% | measured (`view_cmds.rs`, panel modules) |
| Filters and adjustments | 10% | every Filter and Image › Adjustments item live; Filter Gallery 47 looks | 100% | measured (menu catalog) |
| File formats (usage-weighted) | 15% | 13 of 31 Photoshop formats supported in Photoshop's directions, 4 partial; the common ones (PSD/PSB, TIFF, JPEG, PNG, WebP) all present | ~80% (48% by count) | measured list, estimated weights ([file-format-parity.md](file-format-parity.md)) |
diff --git a/docs/ui-parity.md b/docs/ui-parity.md
index 38c3a58f2..df23d9f61 100644
--- a/docs/ui-parity.md
+++ b/docs/ui-parity.md
@@ -31,7 +31,7 @@ Triangle and Curvature Pen (minus legacy Rounded Rectangle and Targeted Adjustme
| Lasso | Lasso, Polygonal, Magnetic | |
| Selection | Object Selection, Quick Selection, Magic Wand | |
| Crop and slice | Crop, Perspective Crop, Slice, Slice Select | |
-| Frame | | Frame (`layer.new.frameFromLayers` exists) |
+| Frame | Frame (frames are groups clipped by a rectangular or elliptical mask) | |
| Eyedropper | Eyedropper, Ruler, Note, Count | Color Sampler (#1046) |
| Retouch | Remove, Spot Healing, Healing, Patch, Content-Aware Move, Red Eye | |
| Brush | Brush, Pencil, Mixer Brush | Color Replacement (`paint.colorReplacement` exists) |