Skip to content

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

Masks: Alt-click to view mask, Cmd-click vector mask to select, vector-mask target brackets (#196) (#256) (#256)

Brandon Thomas02c07eb02127
diff --git a/crates/engine/src/channel_cmds.rs b/crates/engine/src/channel_cmds.rs
index 47360103c..ed55926da 100644
--- a/crates/engine/src/channel_cmds.rs
+++ b/crates/engine/src/channel_cmds.rs
@@ -52,6 +52,8 @@ pub struct ChannelView {
/// Visible alpha channels (missing entries are hidden).
pub alpha_visible: Vec<bool>,
pub quick_mask_hidden: bool,
+ /// ⌥-click view of the active layer's mask (#196); see [`crate::mask_view_cmds`].
+ pub layer_mask: Option<crate::mask_view_cmds::LayerMaskView>,
}
impl ChannelView {
@@ -80,7 +82,15 @@ impl ChannelView {
/// True when the canvas shows just the normal composite (nothing extra to draw).
pub fn is_plain(&self, doc: &Document) -> bool {
let colors = color_count(doc);
- self.visible_colors(colors) == colors && !(0..doc.channels.len()).any(|i| self.alpha_shown(i)) && (doc.quick_mask.is_none() || self.quick_mask_hidden)
+ self.visible_colors(colors) == colors
+ && !(0..doc.channels.len()).any(|i| self.alpha_shown(i))
+ && (doc.quick_mask.is_none() || self.quick_mask_hidden)
+ && self.shown_layer_mask(doc).is_none()
+ }
+ /// The layer mask shown on the canvas (#196) and how, if its layer still has a mask.
+ pub fn shown_layer_mask<'a>(&self, doc: &'a Document) -> Option<(&'a photocraft_doc::LayerMask, crate::mask_view_cmds::MaskViewMode)> {
+ let v = self.layer_mask?;
+ Some((doc.layer(v.layer)?.mask.as_ref()?, v.mode))
}
}
@@ -115,6 +125,7 @@ pub(crate) fn fix_view(st: &mut DocState) {
if v.visible_colors(colors) == 0 && !(0..n).any(|i| v.alpha_shown(i)) {
v.color_hidden.clear();
}
+ crate::mask_view_cmds::fix(st);
}
/// Bump the revision for a view-only change without dirtying a clean document.
@@ -212,6 +223,8 @@ pub enum ChanRef {
Selection,
Transparency,
LayerMask,
+ /// The layer's vector mask, rasterized (⌘-click its thumbnail, #196).
+ VectorMask,
}
pub fn parse_ref(v: &Value, doc: &Document) -> Option<ChanRef> {
@@ -233,6 +246,7 @@ pub fn parse_ref(v: &Value, doc: &Document) -> Option<ChanRef> {
"selection" => return Some(ChanRef::Selection),
"transparency" => return Some(ChanRef::Transparency),
"mask" | "layermask" => return Some(ChanRef::LayerMask),
+ "vectormask" | "vector mask" => return Some(ChanRef::VectorMask),
_ => {}
}
if l == composite_name(mode).to_ascii_lowercase() {
@@ -335,6 +349,14 @@ fn ref_planes(doc: &Document, layer: Option<LayerId>, active: Option<LayerId>, r
let m = l.mask.as_ref().ok_or_else(|| EngineError::Other(format!("layer \"{}\" has no mask", l.name)))?;
vec![read_plane(&m.surface, area)]
}
+ ChanRef::VectorMask => {
+ let id = layer.or(active).ok_or_else(|| EngineError::Other("vector mask needs a layer".into()))?;
+ let l = doc.layer(id).ok_or(EngineError::NoLayer(id))?;
+ let m = l.vector_mask.as_ref().ok_or_else(|| EngineError::Other(format!("layer \"{}\" has no vector mask", l.name)))?;
+ // The path's shape, whether or not the mask is enabled (as Photoshop loads it).
+ let shape = photocraft_doc::VectorMask { enabled: true, density: 1.0, feather: 0.0, ..m.clone() };
+ vec![photocraft_vector::vector_mask_values(&shape, area)]
+ }
})
}
@@ -541,6 +563,8 @@ pub(crate) fn inject_target(s: &Session, id: &str, params: Value) -> Value {
let t = match st.channel_view.target {
ChannelTarget::Alpha(i) if i < st.doc.channels.len() => json!({ "channel": i }),
ChannelTarget::Composite if st.doc.quick_mask.is_some() => json!("quickMask"),
+ // Viewing the active layer's mask (⌥-click): pixel commands edit the mask.
+ ChannelTarget::Composite if crate::mask_view_cmds::current(st).is_some() => json!("mask"),
_ => return params,
};
match params {
@@ -1429,6 +1453,7 @@ pub fn channels_json(st: &DocState) -> Value {
"quickMask": doc.quick_mask.as_ref().map(|q| json!({ "visible": !v.quick_mask_hidden, "color": q.color.to_rgb(), "opacity": q.opacity, "indicates": q.indicates })),
"target": v.target,
"compositeVisible": v.visible_colors(colors) == colors,
+ "layerMaskView": crate::mask_view_cmds::view_json(st),
})
}
@@ -1461,7 +1486,7 @@ pub fn specs() -> Vec<CommandSpec> {
"Load Selection…",
["Select"],
None,
- r##"{"channel":index|name|"composite"|"red|green|blue|…"|"transparency"|"mask"|"quickMask"|"selection","layer":id?,"document":index?,"invert":bool=false,"operation":"new|add|subtract|intersect"="new"}"##,
+ r##"{"channel":index|name|"composite"|"red|green|blue|…"|"transparency"|"mask"|"vectorMask"|"quickMask"|"selection","layer":id?,"document":index?,"invert":bool=false,"operation":"new|add|subtract|intersect"="new"}"##,
has_doc,
load_selection
),
diff --git a/crates/engine/src/commands.rs b/crates/engine/src/commands.rs
index 2338be5ae..5c6f06304 100644
--- a/crates/engine/src/commands.rs
+++ b/crates/engine/src/commands.rs
@@ -998,6 +998,7 @@ fn build() -> Vec<CommandSpec> {
v.extend(crate::plugin_cmds::specs());
v.extend(crate::group_view_cmds::specs());
v.extend(crate::fx_view_cmds::specs());
+ v.extend(crate::mask_view_cmds::specs());
v
}
diff --git a/crates/engine/src/inspect.rs b/crates/engine/src/inspect.rs
index bbd4e1c16..9ff5df29c 100644
--- a/crates/engine/src/inspect.rs
+++ b/crates/engine/src/inspect.rs
@@ -44,6 +44,7 @@ pub fn document(d: &DocState) -> Value {
"revision": d.revision,
"channels": crate::channel_cmds::channels_json(d),
"quickMask": doc.quick_mask.is_some(),
+ "layerMaskView": crate::mask_view_cmds::view_json(d),
"layerComps": doc.layer_comps.iter().map(|c| json!({"id": c.id, "name": c.name})).collect::<Vec<_>>(),
"lastAppliedComp": doc.last_applied_comp,
"measurement": {"scale": doc.measurement.scale.describe(), "ruler": doc.measurement.ruler.map(|r| json!({"start": r.start, "end": r.end, "protractor": r.protractor})), "count": doc.measurement.count_total(), "countGroups": doc.measurement.count_groups.len()},
diff --git a/crates/engine/src/lib.rs b/crates/engine/src/lib.rs
index 6210d713e..7a1d93fb2 100644
--- a/crates/engine/src/lib.rs
+++ b/crates/engine/src/lib.rs
@@ -41,6 +41,7 @@ pub mod layer_menu_cmds;
pub mod layer_multi_cmds;
pub mod layer_style;
pub mod lens_cmds;
+pub mod mask_view_cmds;
mod migrate_cmds;
pub mod mode_cmds;
pub mod multichannel_cmds;
@@ -339,6 +340,10 @@ impl Session {
self.coalesce_request = None;
self.color_restrict = None;
let r = r?;
+ // A layer-mask view ends when another layer becomes active (#196).
+ if let Some(st) = self.active_mut() {
+ mask_view_cmds::fix(st);
+ }
edit_menu_cmds::after_command(self, id);
automate_cmds::after_command(self, id);
self.sync_preset_store();
diff --git a/crates/engine/src/mask_view_cmds.rs b/crates/engine/src/mask_view_cmds.rs
new file mode 100644
index 000000000..104bcf235
--- /dev/null
+++ b/crates/engine/src/mask_view_cmds.rs
@@ -0,0 +1,138 @@
+//! View › layer mask (#196): ⌥-click a layer-mask thumbnail shows the mask as a grayscale image
+//! instead of the composite; ⇧⌥-click (or the eye on the Channels panel's temporary mask row)
+//! shows it as a rubylith overlay over the composite.
+//!
+//! This is view state on [`crate::channel_cmds::ChannelView::layer_mask`], like the Channels
+//! panel's eyes: no history step, a clean document stays clean, and it never changes a pixel.
+//! While a mask is shown, pixel commands without an explicit `target` edit that mask
+//! ([`crate::channel_cmds`]'s target injection), so painting in mask view paints the mask.
+//! The view ends when its layer stops being the active layer or loses its mask ([`fix`]).
+
+use photocraft_doc::LayerId;
+use serde::Serialize;
+use serde_json::{Value, json};
+
+use crate::commands::CommandSpec;
+use crate::{DocState, EngineError, Result, Session};
+
+pub const ID: &str = "view.layerMask";
+
+/// How a shown layer mask is drawn.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
+#[serde(rename_all = "camelCase")]
+pub enum MaskViewMode {
+ /// The mask alone, as a grayscale image (⌥-click).
+ Gray,
+ /// The composite with the mask as a red overlay over hidden areas (⇧⌥-click, `\`).
+ Overlay,
+}
+
+/// Which layer's mask is shown, and how.
+#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize)]
+pub struct LayerMaskView {
+ pub layer: LayerId,
+ pub mode: MaskViewMode,
+}
+
+fn bad(msg: impl Into<String>) -> EngineError {
+ EngineError::BadParams { cmd: ID.into(), msg: msg.into() }
+}
+
+fn has_doc(s: &Session) -> std::result::Result<(), String> {
+ s.active().map(|_| ()).ok_or_else(|| "no document open".into())
+}
+
+/// The mask view of `st` when it is live: its layer is the active layer and still has a mask.
+pub fn current(st: &DocState) -> Option<LayerMaskView> {
+ let v = st.channel_view.layer_mask?;
+ let live = st.active_layer == Some(v.layer) && st.doc.layer(v.layer).is_some_and(|l| l.mask.is_some());
+ live.then_some(v)
+}
+
+/// Drop a mask view that no longer applies (another layer became active, the layer or its mask
+/// was deleted, undo).
+pub(crate) fn fix(st: &mut DocState) {
+ if st.channel_view.layer_mask.is_some() && current(st).is_none() {
+ st.channel_view.layer_mask = None;
+ }
+}
+
+fn mode_name(v: Option<LayerMaskView>) -> &'static str {
+ match v.map(|v| v.mode) {
+ None => "off",
+ Some(MaskViewMode::Gray) => "gray",
+ Some(MaskViewMode::Overlay) => "overlay",
+ }
+}
+
+/// The view as JSON (`{"layer","mode"}`, or `null` when off); part of `document.inspect`.
+pub fn view_json(st: &DocState) -> Value {
+ match current(st) {
+ Some(v) => json!({"layer": v.layer.0, "mode": mode_name(Some(v))}),
+ None => Value::Null,
+ }
+}
+
+/// `{"layer":id?,"mode":"off"|"gray"|"overlay"|"toggleGray"|"toggleOverlay"="toggleGray"}`.
+fn set_view(s: &mut Session, p: &Value) -> Result<Value> {
+ let mode = match p.get("mode") {
+ None | Some(Value::Null) => "toggleGray",
+ Some(v) => v.as_str().ok_or_else(|| bad("`mode` must be a string"))?,
+ };
+ let st = s.active().ok_or(EngineError::NoDocument)?;
+ let layer = match p.get("layer") {
+ None | Some(Value::Null) => st.active_layer.ok_or_else(|| bad("no layer given and no active layer"))?,
+ Some(v) => LayerId(v.as_u64().ok_or_else(|| bad("`layer` must be a layer id"))?),
+ };
+ let l = st.doc.layer(layer).ok_or(EngineError::NoLayer(layer))?;
+ let has_mask = l.mask.is_some();
+ let name = l.name.clone();
+ let shown = current(st).filter(|v| v.layer == layer).map(|v| v.mode);
+ let want = match mode {
+ "off" => None,
+ "gray" => Some(MaskViewMode::Gray),
+ "overlay" => Some(MaskViewMode::Overlay),
+ "toggleGray" => (shown != Some(MaskViewMode::Gray)).then_some(MaskViewMode::Gray),
+ "toggleOverlay" => (shown != Some(MaskViewMode::Overlay)).then_some(MaskViewMode::Overlay),
+ other => return Err(bad(format!("unknown mode `{other}` (off|gray|overlay|toggleGray|toggleOverlay)"))),
+ };
+ if want.is_some() && !has_mask {
+ return Err(bad(format!("layer \"{name}\" has no layer mask")));
+ }
+ // ⌥-clicking another layer's mask selects that layer, as in Photoshop.
+ if want.is_some() && s.active().and_then(|st| st.active_layer) != Some(layer) {
+ s.select_layer(layer)?;
+ }
+ let st = s.active_mut().ok_or(EngineError::NoDocument)?;
+ let next = want.map(|mode| LayerMaskView { layer, mode });
+ // "off" for a layer whose mask isn't the one shown leaves the other view alone.
+ let applies = next.is_some() || st.channel_view.layer_mask.is_some_and(|v| v.layer == layer);
+ if applies && st.channel_view.layer_mask != next {
+ st.channel_view.layer_mask = next;
+ // A view change: redraw without recompositing, and keep a clean document clean.
+ let clean = st.saved_revision == st.revision;
+ st.revision += 1;
+ if clean {
+ st.saved_revision = st.revision;
+ }
+ st.last_damage = Some(photocraft_geom::Rect::EMPTY);
+ }
+ let v = current(st);
+ Ok(json!({"layer": layer.0, "mode": mode_name(v.filter(|v| v.layer == layer))}))
+}
+
+pub fn specs() -> Vec<CommandSpec> {
+ vec![CommandSpec {
+ id: ID,
+ label: "View Layer Mask",
+ menu: &[],
+ shortcut: None,
+ params: r##"{"layer":id?,"mode":"off"|"gray"|"overlay"|"toggleGray"|"toggleOverlay"="toggleGray"} (gray: the mask alone, ⌥-click its thumbnail; overlay: red rubylith over the composite, ⇧⌥-click; view state, not an undo step; painting while shown paints the mask)"##,
+ enabled: has_doc,
+ run: set_view,
+ journal: false,
+ }]
+}
+
+#[cfg(test)]
+mod tests;
diff --git a/crates/engine/src/mask_view_cmds/tests.rs b/crates/engine/src/mask_view_cmds/tests.rs
new file mode 100644
index 000000000..c9e47ec6f
--- /dev/null
+++ b/crates/engine/src/mask_view_cmds/tests.rs
@@ -0,0 +1,137 @@
+use super::*;
+use photocraft_geom::Rect;
+
+/// 40×20 document: Background, then "Masked" (red, mask hiding the left half) on top.
+fn session() -> (Session, u64, u64) {
+ let mut s = Session::new();
+ s.execute("file.new", json!({"width": 40, "height": 20})).unwrap();
+ let bg = s.active().unwrap().doc.layers[0].id.0;
+ let masked = s.execute("layer.new.layer", json!({"name": "Masked"})).unwrap()["layer"].as_u64().unwrap();
+ s.execute("edit.fill", json!({"contents": "color", "color": "#ff0000"})).unwrap();
+ s.execute("select.rect", json!({"x": 20, "y": 0, "width": 20, "height": 20})).unwrap();
+ s.execute("layer.layerMask.revealSelection", json!({})).unwrap();
+ s.execute("select.deselect", json!({})).unwrap();
+ let st = s.active_mut().unwrap();
+ st.saved_revision = st.revision;
+ (s, masked, bg)
+}
+
+/// The view as `document.inspect` reports it.
+fn view(s: &Session) -> Value {
+ crate::inspect::document(s.active().unwrap())["layerMaskView"].clone()
+}
+
+#[test]
+fn modes_toggle_and_show_in_inspect_without_history() {
+ let (mut s, masked, _) = session();
+ let steps = s.active().unwrap().history.entries().len();
+ assert_eq!(view(&s), Value::Null);
+ assert_eq!(s.execute(ID, json!({})).unwrap()["mode"], "gray", "no mode: toggle the grayscale view");
+ assert_eq!(view(&s), json!({"layer": masked, "mode": "gray"}));
+ assert_eq!(s.execute(ID, json!({"mode": "toggleGray"})).unwrap()["mode"], "off", "⌥-click again returns");
+ assert_eq!(s.execute(ID, json!({"layer": masked, "mode": "overlay"})).unwrap()["mode"], "overlay");
+ assert_eq!(s.active().unwrap().channel_view.layer_mask.unwrap().mode, MaskViewMode::Overlay);
+ let ch = crate::channel_cmds::channels_json(s.active().unwrap());
+ assert_eq!(ch["layerMaskView"]["mode"], "overlay", "the Channels state carries it too");
+ assert_eq!(s.execute(ID, json!({"mode": "toggleGray"})).unwrap()["mode"], "gray", "overlay → gray");
+ assert_eq!(s.execute(ID, json!({"mode": "off"})).unwrap()["mode"], "off");
+ let st = s.active().unwrap();
+ assert_eq!(st.history.entries().len(), steps, "view changes are not history steps");
+ assert!(!st.is_dirty(), "a clean document stays clean");
+ assert_eq!(st.last_damage, Some(Rect::EMPTY), "no recomposite");
+}
+
+#[test]
+fn a_mask_view_never_alters_pixels() {
+ let (mut s, masked, _) = session();
+ let before = s.active().unwrap().doc.clone();
+ let px = |s: &Session| photocraft_compose::render(&s.active().unwrap().doc, Rect::new(0, 0, 40, 20)).px;
+ let composite = px(&s);
+ for mode in ["gray", "overlay", "toggleOverlay", "toggleGray", "off"] {
+ s.execute(ID, json!({"layer": masked, "mode": mode})).unwrap();
+ assert!(std::sync::Arc::ptr_eq(&before, &s.active().unwrap().doc), "{mode}: the document is untouched");
+ assert_eq!(px(&s), composite, "{mode}: same composite");
+ }
+}
+
+#[test]
+fn painting_in_mask_view_paints_the_mask() {
+ let (mut s, masked, _) = session();
+ s.execute(ID, json!({"mode": "gray"})).unwrap();
+ let id = photocraft_doc::LayerId(masked);
+ let pixels_before = s.active().unwrap().doc.layer(id).unwrap().surface().unwrap().clone();
+ s.execute("paint.stroke", json!({"points": [[30, 10]], "size": 6, "hardness": 1.0, "color": "#000000"})).unwrap();
+ let l = s.active().unwrap().doc.layer(id).unwrap().clone();
+ assert!(l.mask.as_ref().unwrap().value(30, 10) < 0.01, "the stroke went into the mask");
+ let mut a = Vec::new();
+ let mut b = Vec::new();
+ pixels_before.read_region_into(Rect::new(0, 0, 40, 20), &mut a);
+ l.surface().unwrap().read_region_into(Rect::new(0, 0, 40, 20), &mut b);
+ assert_eq!(a, b, "the layer's pixels are untouched");
+ // An explicit target still wins.
+ s.execute("paint.stroke", json!({"points": [[5, 5]], "size": 4, "color": "#00ff00", "target": "pixels"})).unwrap();
+ let l = s.active().unwrap().doc.layer(id).unwrap();
+ assert!(l.surface().unwrap().sample_channel(5, 5, 1) > 0.9);
+}
+
+#[test]
+fn the_view_ends_with_its_layer_or_mask() {
+ let (mut s, masked, bg) = session();
+ s.execute(ID, json!({"mode": "gray"})).unwrap();
+ s.execute("layer.select", json!({"layer": bg})).unwrap();
+ assert_eq!(view(&s), Value::Null, "selecting another layer leaves mask view");
+ assert!(s.active().unwrap().channel_view.layer_mask.is_none());
+ // ⌥-clicking a mask of an unselected layer selects it.
+ s.execute(ID, json!({"layer": masked, "mode": "overlay"})).unwrap();
+ assert_eq!(s.active().unwrap().active_layer, Some(photocraft_doc::LayerId(masked)));
+ s.execute("layer.layerMask.delete", json!({})).unwrap();
+ assert!(s.active().unwrap().channel_view.layer_mask.is_none(), "deleting the mask ends the view");
+ s.undo();
+ assert!(s.active().unwrap().channel_view.layer_mask.is_none(), "undo doesn't bring a stale view back");
+}
+
+#[test]
+fn bad_params_and_no_mask_fail_gracefully() {
+ let (mut s, masked, bg) = session();
+ for p in [
+ json!({"layer": bg, "mode": "gray"}),
+ json!({"layer": bg}),
+ json!({"layer": 999_999, "mode": "gray"}),
+ json!({"layer": "x"}),
+ json!({"layer": -1}),
+ json!({"mode": 3}),
+ json!({"mode": "sideways"}),
+ json!({"layer": masked, "mode": ["gray"]}),
+ ] {
+ assert!(s.execute(ID, p.clone()).is_err(), "{p} should fail");
+ }
+ assert_eq!(view(&s), Value::Null, "failures change nothing");
+ // "off" is always fine, even for a layer without a mask, and leaves another view alone.
+ s.execute(ID, json!({"layer": masked, "mode": "gray"})).unwrap();
+ assert_eq!(s.execute(ID, json!({"layer": bg, "mode": "off"})).unwrap()["mode"], "off");
+ assert_eq!(view(&s)["mode"], "gray");
+ // No document.
+ let mut empty = Session::new();
+ assert!(empty.execute(ID, json!({"mode": "gray"})).is_err());
+}
+
+#[test]
+fn load_selection_from_a_vector_mask() {
+ let (mut s, masked, _) = session();
+ let path = json!({"subpaths": [{"knots": [[4, 4], [16, 4], [16, 16], [4, 16]]}]});
+ s.execute("layer.vectorMask.add", json!({"layer": masked, "path": path})).unwrap();
+ s.execute("layer.vectorMask.enabled", json!({"enabled": false})).unwrap();
+ s.execute("select.loadSelection", json!({"channel": "vectorMask", "layer": masked})).unwrap();
+ let b = s.active().unwrap().doc.selection.as_ref().unwrap().content_bounds();
+ assert_eq!((b.x0, b.y0, b.width(), b.height()), (4, 4, 12, 12), "the path's shape, even when disabled");
+ // ⌘⌥: subtract, ⌘⇧⌥: intersect.
+ s.execute("select.all", json!({})).unwrap();
+ s.execute("select.loadSelection", json!({"channel": "vectorMask", "operation": "subtract"})).unwrap();
+ let sel = s.active().unwrap().doc.selection.clone().unwrap();
+ assert!(sel.sample_channel(10, 10, 0) < 0.01 && sel.sample_channel(30, 10, 0) > 0.99);
+ s.execute("select.loadSelection", json!({"channel": "vectorMask", "operation": "intersect"})).unwrap();
+ assert!(s.active().unwrap().doc.selection.is_none(), "nothing left");
+ // No vector mask: an error, not a crash.
+ s.execute("layer.vectorMask.delete", json!({})).unwrap();
+ assert!(s.execute("select.loadSelection", json!({"channel": "vectorMask"})).is_err());
+}
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index 71c551329..4f485901d 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -2068,7 +2068,7 @@ pub fn commit_crop(app: &mut PhotocraftApp) {
}
}
-/// "mask" when the Layers panel targets the active layer's mask, else "pixels".
+/// "mask" when the Layers panel targets (or the canvas shows) the active layer's mask, else "pixels".
pub fn paint_target(app: &PhotocraftApp) -> serde_json::Value {
use photocraft_engine::channel_cmds::ChannelTarget;
let Some(st) = app.session.active() else { return json!("pixels") };
@@ -2079,7 +2079,9 @@ pub fn paint_target(app: &PhotocraftApp) -> serde_json::Value {
_ => {}
}
let has_mask = st.active_layer.and_then(|id| st.doc.layer(id)).is_some_and(|l| l.mask.is_some());
- json!(if app.ui.mask_target && has_mask { "mask" } else { "pixels" })
+ // Viewing the mask (⌥-click its thumbnail, #196) paints the mask.
+ let viewing = photocraft_engine::mask_view_cmds::current(st).is_some();
+ json!(if (app.ui.mask_target || viewing) && has_mask { "mask" } else { "pixels" })
}
/// `#rrggbb` for an sRGB colour (the engine's colour parameter notation).
diff --git a/crates/ui-egui/src/channel_view.rs b/crates/ui-egui/src/channel_view.rs
index 9fd16e671..b89bfc050 100644
--- a/crates/ui-egui/src/channel_view.rs
+++ b/crates/ui-egui/src/channel_view.rs
@@ -10,6 +10,7 @@
use egui::{Color32, TextureOptions};
use photocraft_doc::{AlphaChannel, ColorMode, Document};
use photocraft_engine::channel_cmds::{ChannelView, color_count};
+use photocraft_engine::mask_view_cmds::MaskViewMode;
use photocraft_geom::Rect;
use photocraft_raster::{Surface, from_rgba, to_rgba};
@@ -22,6 +23,9 @@ pub struct Cache {
revision: u64,
key: u64,
factor: u32,
+ /// False while the plain composite shows: the texture is kept (so toggling a view back on
+ /// reuses its allocation) but its pixels are stale.
+ valid: bool,
tex: egui::TextureHandle,
}
@@ -65,6 +69,22 @@ pub fn render(doc: &Document, v: &ChannelView, r: Rect, factor: u32, in_color: b
if v.is_plain(doc) || r.is_empty() {
return None;
}
+ let layer_mask = v.shown_layer_mask(doc);
+ // ⌥-click mask view (#196): the layer mask alone, in grayscale (white reveals); ⇧⌥ with
+ // nothing else shown: just the rubylith. Both straight from the mask, in parallel rows, so
+ // switching the view on a 24 MP document takes one frame.
+ let only_mask = ChannelView { layer_mask: None, ..v.clone() }.is_plain(doc);
+ match layer_mask {
+ Some((m, MaskViewMode::Gray)) => return Some(mask_px(&m.surface, r, factor, |g| Color32::from_gray(q(g)))),
+ Some((m, MaskViewMode::Overlay)) if only_mask => {
+ let c = AlphaChannel::DEFAULT_COLOR.to_rgb();
+ return Some(mask_px(&m.surface, r, factor, |g| {
+ let a = 0.5 * (1.0 - g.clamp(0.0, 1.0));
+ Color32::from_rgba_premultiplied(q(c[0] * a), q(c[1] * a), q(c[2] * a), q(a))
+ }));
+ }
+ _ => {}
+ }
let colors = color_count(doc);
let vis = v.visible_colors(colors);
let (w, h) = (r.width().div_ceil(factor), r.height().div_ceil(factor));
@@ -102,6 +122,17 @@ pub fn render(doc: &Document, v: &ChannelView, r: Rect, factor: u32, in_color: b
} else {
vec![[0.0; 4]; n]
};
+ // Rubylith: `color` at `opacity` × coverage over the accumulated pixels.
+ let mut tint = |values: Vec<f32>, color: photocraft_color::Color, opacity: f32, coverage: &dyn Fn(f32) -> f32| {
+ let c = color.to_rgb();
+ for (o, val) in out.iter_mut().zip(values) {
+ let a = (coverage(val.clamp(0.0, 1.0)) * opacity).clamp(0.0, 1.0);
+ for j in 0..3 {
+ o[j] = c[j] * a + o[j] * (1.0 - a);
+ }
+ o[3] = a + o[3] * (1.0 - a);
+ }
+ };
let quick = doc.quick_mask.as_ref().filter(|_| !v.quick_mask_hidden);
for ch in overlays.into_iter().chain(quick) {
let (color, opacity) = match ch.spot {
@@ -109,19 +140,48 @@ pub fn render(doc: &Document, v: &ChannelView, r: Rect, factor: u32, in_color: b
Some((ink, solidity)) => (ink, 0.5 + 0.5 * solidity),
None => (ch.color, ch.opacity),
};
- let c = color.to_rgb();
- for (o, val) in out.iter_mut().zip(sample(&ch.surface, r, factor)) {
- let a = (ch.overlay_coverage(val.clamp(0.0, 1.0)) * opacity).clamp(0.0, 1.0);
- for j in 0..3 {
- o[j] = c[j] * a + o[j] * (1.0 - a);
- }
- o[3] = a + o[3] * (1.0 - a);
- }
+ tint(sample(&ch.surface, r, factor), color, opacity, &|x| ch.overlay_coverage(x));
+ }
+ // ⇧⌥-click mask view (#196): the layer mask as Quick Mask's red over the hidden areas
+ // (Photoshop's Layer Mask Display Options default).
+ if let Some((m, MaskViewMode::Overlay)) = layer_mask {
+ tint(sample(&m.surface, r, factor), AlphaChannel::DEFAULT_COLOR, 0.5, &|x| 1.0 - x);
}
- let q = |x: f32| (x.clamp(0.0, 1.0) * 255.0 + 0.5) as u8;
Some(out.into_iter().map(|p| Color32::from_rgba_premultiplied(q(p[0]), q(p[1]), q(p[2]), q(p[3]))).collect())
}
+/// `r` of a one-channel surface sampled every `factor` px, mapped to colours row by row (in
+/// parallel off the web).
+fn mask_px(s: &Surface, r: Rect, factor: u32, color: impl Fn(f32) -> Color32 + Sync) -> Vec<Color32> {
+ let (w, h) = (r.width().div_ceil(factor) as usize, r.height().div_ceil(factor) as usize);
+ let mut px = vec![Color32::TRANSPARENT; w * h];
+ let row = |y: usize, out: &mut [Color32]| {
+ let mut vals = vec![0.0f32; out.len()];
+ s.sample_row_strided(r.y0 + (y as u32 * factor) as i32, r.x0, factor as i32, 0, &mut vals);
+ for (o, v) in out.iter_mut().zip(vals) {
+ *o = color(v);
+ }
+ };
+ if w == 0 {
+ return px;
+ }
+ #[cfg(not(target_arch = "wasm32"))]
+ {
+ use rayon::prelude::*;
+ px.par_chunks_mut(w).enumerate().for_each(|(y, out)| row(y, out));
+ }
+ #[cfg(target_arch = "wasm32")]
+ for (y, out) in px.chunks_mut(w).enumerate() {
+ row(y, out);
+ }
+ px
+}
+
+/// A float in 0..=1 as an 8-bit channel value.
+fn q(x: f32) -> u8 {
+ (x.clamp(0.0, 1.0) * 255.0 + 0.5) as u8
+}
+
fn view_key(v: &ChannelView, in_color: bool) -> u64 {
let s = serde_json::to_string(v).unwrap_or_default();
s.bytes().fold(in_color as u64 + 1, |h, b| h.wrapping_mul(1_099_511_628_211).wrapping_add(b as u64))
@@ -135,7 +195,9 @@ pub fn ensure(app: &mut PhotocraftApp, ctx: &egui::Context, idx: usize) -> Optio
let (revision, damage) = (st.revision, st.last_damage);
let id = doc.id.0;
if view.is_plain(&doc) {
- app.channel_views.remove(&id);
+ if let Some(c) = app.channel_views.get_mut(&id) {
+ c.valid = false;
+ }
return None;
}
let in_color = false;
@@ -146,20 +208,24 @@ pub fn ensure(app: &mut PhotocraftApp, ctx: &egui::Context, idx: usize) -> Optio
if let Some(c) = app.channel_views.get_mut(&id)
&& c.key == key
&& c.factor == factor
+ && c.valid
{
if c.revision == revision {
return Some(c.tex.id());
}
if c.revision + 1 == revision
- && factor == 1
&& let Some(d) = damage
{
- let r = d.intersect(&doc.bounds());
+ // Re-render just the damage, snapped to the sampling grid so a downsampled texture
+ // (big documents) updates in place too.
+ let f = factor as i32;
+ let d = d.intersect(&doc.bounds());
+ let r = Rect::new(d.x0.div_euclid(f) * f, d.y0.div_euclid(f) * f, d.x1, d.y1).intersect(&doc.bounds());
if !r.is_empty()
- && let Some(px) = render(&doc, &view, r, 1, in_color)
+ && let Some(px) = render(&doc, &view, r, factor, in_color)
{
- let img = egui::ColorImage::new([r.width() as usize, r.height() as usize], px);
- c.tex.set_partial([r.x0 as usize, r.y0 as usize], img, TextureOptions::LINEAR);
+ let img = egui::ColorImage::new([r.width().div_ceil(factor) as usize, r.height().div_ceil(factor) as usize], px);
+ c.tex.set_partial([(r.x0 / f) as usize, (r.y0 / f) as usize], img, TextureOptions::LINEAR);
}
c.revision = revision;
return Some(c.tex.id());
@@ -175,10 +241,11 @@ pub fn ensure(app: &mut PhotocraftApp, ctx: &egui::Context, idx: usize) -> Optio
c.revision = revision;
c.key = key;
c.factor = factor;
+ c.valid = true;
}
_ => {
let tex = ctx.load_texture(format!("channel-view-{id}"), img, TextureOptions::LINEAR);
- app.channel_views.insert(id, Cache { revision, key, factor, tex });
+ app.channel_views.insert(id, Cache { revision, key, factor, valid: true, tex });
}
}
app.channel_views.get(&id).map(|c| c.tex.id())
@@ -215,6 +282,63 @@ mod tests {
assert_eq!(px[6], Color32::from_rgba_premultiplied(128, 0, 0, 128), "masked: 50% red");
}
+ #[test]
+ fn layer_mask_views_and_damage_on_the_downsampled_grid() {
+ let mut s = Session::new();
+ s.execute("file.new", json!({"width": 37, "height": 21})).unwrap();
+ s.execute("layer.new.layer", json!({})).unwrap();
+ s.execute("edit.fill", json!({"color": "#0000ff"})).unwrap();
+ s.execute("layer.layerMask.revealAll", json!({})).unwrap();
+ s.execute("paint.gradient", json!({"from": [0, 0], "to": [37, 0], "colors": ["#000000", "#ffffff"], "target": "mask"})).unwrap();
+ s.execute("view.layerMask", json!({"mode": "gray"})).unwrap();
+ let st = s.active().unwrap();
+ let b = st.doc.bounds();
+ let full = render(&st.doc, &st.channel_view, b, 1, false).unwrap();
+ assert!(full[0].r() < 10 && full[36].r() > 245 && full[0].a() == 255, "opaque grayscale ramp");
+ // A sub-rect starting on the factor grid matches the same pixels of the full render.
+ for f in [1u32, 2, 3] {
+ let all = render(&st.doc, &st.channel_view, b, f, false).unwrap();
+ let w = b.width().div_ceil(f) as usize;
+ let r = Rect::new(3 * f as i32, 2 * f as i32, 30, 19);
+ let part = render(&st.doc, &st.channel_view, r, f, false).unwrap();
+ let pw = r.width().div_ceil(f) as usize;
+ for (i, p) in part.iter().enumerate() {
+ assert_eq!(*p, all[(i / pw + 2) * w + i % pw + 3], "factor {f}, pixel {i}");
+ }
+ }
+ s.execute("view.layerMask", json!({"mode": "overlay"})).unwrap();
+ let st = s.active().unwrap();
+ let px = render(&st.doc, &st.channel_view, b, 1, false).unwrap();
+ assert!(px[0].r() >= 124 && px[0].g() == 0 && px[0].a() >= 124, "about 50% red over the hidden end: {:?}", px[0]);
+ assert!(px[36].a() <= 4, "next to nothing over the revealed end: {:?}", px[36]);
+ }
+
+ /// `cargo test --release -p photocraft-ui-egui --lib mask_view_switch_24mp -- --ignored --nocapture`
+ #[test]
+ #[ignore = "benchmark"]
+ fn mask_view_switch_24mp() {
+ let mut s = Session::new();
+ s.execute("file.new", json!({"width": 6000, "height": 4000})).unwrap();
+ s.execute("layer.new.layer", json!({})).unwrap();
+ s.execute("edit.fill", json!({"color": "#d0402b"})).unwrap();
+ s.execute("layer.layerMask.revealAll", json!({})).unwrap();
+ s.execute("paint.gradient", json!({"from": [0, 0], "to": [6000, 0], "colors": ["#000000", "#ffffff"], "target": "mask"})).unwrap();
+ let factor = 6000u32.div_ceil(MAX_SIDE);
+ for mode in ["gray", "overlay"] {
+ s.execute("view.layerMask", json!({"mode": mode})).unwrap();
+ let st = s.active().unwrap();
+ let mut best = f64::MAX;
+ for _ in 0..8 {
+ let t = std::time::Instant::now();
+ let px = render(&st.doc, &st.channel_view, st.doc.bounds(), factor, false).unwrap();
+ let img = egui::ColorImage::new([3000, 2000], px);
+ std::hint::black_box(img);
+ best = best.min(t.elapsed().as_secs_f64() * 1000.0);
+ }
+ println!("24 MP mask view {mode}: {best:.1} ms (render at 1/{factor})");
+ }
+ }
+
#[test]
fn solo_alpha_is_grayscale_and_colour_channels_split() {
let mut s = session();
diff --git a/crates/ui-egui/src/channels_panel.rs b/crates/ui-egui/src/channels_panel.rs
index 32129a878..2dde85582 100644
--- a/crates/ui-egui/src/channels_panel.rs
+++ b/crates/ui-egui/src/channels_panel.rs
@@ -53,6 +53,9 @@ pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
};
let doc = st.doc.clone();
let view = st.channel_view.clone();
+ // ⌥-click mask view (#196): gray shows the mask alone (colour eyes off), overlay over the composite.
+ let mask_view = photocraft_engine::mask_view_cmds::current(st).map(|v| v.mode);
+ let gray_view = mask_view == Some(photocraft_engine::mask_view_cmds::MaskViewMode::Gray);
let active_layer = st.active_layer;
let mode = doc.pixel_format().mode;
let colors = mode.color_channels();
@@ -91,14 +94,14 @@ pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
channel_cmds::composite_name(mode).to_string(),
0,
Some(2),
- view.visible_colors(colors) == colors,
+ view.visible_colors(colors) == colors && !gray_view,
view.target == ChannelTarget::Composite && !quick && !mask_targeted,
),
Row::Color(k) => (
channel_cmds::color_names(mode)[k].to_string(),
1 + k,
Some(3 + k),
- view.color_visible(k),
+ view.color_visible(k) && !gray_view,
(view.target == ChannelTarget::Composite && !quick && !mask_targeted) || view.target == ChannelTarget::Color(k),
),
Row::Alpha(i) => (
@@ -111,7 +114,9 @@ pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
Row::QuickMask => {
("Quick Mask".to_string(), 1 + shown_colors + doc.channels.len(), None, !view.quick_mask_hidden, view.target == ChannelTarget::Composite)
}
- Row::LayerMask => (masked.as_ref().map(|l| format!("{} Mask", l.name)).unwrap_or_default(), usize::MAX, None, false, mask_targeted),
+ Row::LayerMask => {
+ (masked.as_ref().map(|l| format!("{} Mask", l.name)).unwrap_or_default(), usize::MAX, None, mask_view.is_some(), mask_targeted)
+ }
};
let row_h = if t.pro { 36.0 } else { 40.0 };
let (rect, resp) = ui.allocate_exact_size(vec2(ui.available_width(), row_h), Sense::click());
@@ -127,12 +132,22 @@ pub fn show(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
}
let eye = Rect::from_min_size(pos2(rect.left() + 6.0, rect.center().y - 11.0), vec2(22.0, 22.0));
let eye_resp = ui.interact(eye, ui.id().with(("chan-eye", format!("{:?}", row.reference()))), Sense::click());
- // The layer mask's eye slot stays empty: its overlay view isn't supported yet.
- if row != Row::LayerMask {
+ // Like Photoshop, the temporary mask row's eye is empty until the mask is shown.
+ if row != Row::LayerMask || visible || eye_resp.hovered() {
icons::paint(ui, eye, if visible { "eye" } else { "eye-off" }, 14.0, if visible { t.icon } else { t.text_faint });
}
- if eye_resp.clicked() && row != Row::LayerMask {
- actions.push(("channel.setVisible".into(), json!({ "channel": row.reference(), "visible": !visible })));
+ let eye_resp = eye_resp.on_hover_text(if row == Row::LayerMask { "Show the layer mask as an overlay" } else { "Toggle visibility" });
+ eye_resp.widget_info(|| egui::WidgetInfo::labeled(egui::WidgetType::Button, true, format!("Visibility {name}")));
+ let layer_id = masked.as_ref().map(|l| l.id.0);
+ if eye_resp.clicked() {
+ let view_cmd = photocraft_engine::mask_view_cmds::ID.to_string();
+ match row {
+ // The mask's eye: the overlay on, or the mask view off.
+ Row::LayerMask => actions.push((view_cmd, json!({ "layer": layer_id, "mode": if visible { "off" } else { "overlay" } }))),
+ // Showing the composite again over a gray mask view keeps the mask as an overlay.
+ Row::Composite if gray_view => actions.push((view_cmd, json!({ "layer": layer_id, "mode": "overlay" }))),
+ _ => actions.push(("channel.setVisible".into(), json!({ "channel": row.reference(), "visible": !visible }))),
+ }
}
let ts = if t.pro { 28.0 } else { 30.0 };
let cell = Rect::from_min_size(pos2(rect.left() + 36.0, rect.center().y - ts / 2.0), vec2(ts, ts));
diff --git a/crates/ui-egui/src/control.rs b/crates/ui-egui/src/control.rs
index 7dacfb9d9..fe79ece30 100644
--- a/crates/ui-egui/src/control.rs
+++ b/crates/ui-egui/src/control.rs
@@ -125,6 +125,11 @@ pub fn handle(app: &mut PhotocraftApp, ctx: &egui::Context, req: &ControlRequest
}
if let Some(m) = p.get("maskTarget").and_then(Value::as_bool) {
app.ui.mask_target = m;
+ app.ui.vector_mask_target &= !m;
+ }
+ if let Some(m) = p.get("vectorMaskTarget").and_then(Value::as_bool) {
+ app.ui.vector_mask_target = m;
+ app.ui.mask_target &= !m;
}
// Selection tools' options-bar mode: 0 New, 1 Add, 2 Subtract, 3 Intersect.
if let Some(m) = p.get("selectionMode").and_then(Value::as_u64) {
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 616c6f6e5..bf76befaa 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -495,6 +495,12 @@ impl PhotocraftApp {
self.ui.views.resize_with(n, Default::default);
self.ui.windows.retain(|w| w.document < n);
self.prune_thumbs();
+ self.sync_mask_targets();
+ // Channel-view textures outlive a hidden view (cheap re-show), not their document.
+ if !self.channel_views.is_empty() {
+ let docs = self.session.documents();
+ self.channel_views.retain(|id, _| docs.iter().any(|d| d.doc.id.0 == *id));
+ }
// Commands may close and reopen a preserved-ID document before the next repaint.
canvas::retain_gpu_documents(self);
}
@@ -876,6 +882,19 @@ fn read_dropped(_f: &dyn egui::DroppedFile) -> Result<Vec<u8>, String> {
}
impl PhotocraftApp {
+ /// Viewing a layer mask (#196) targets it; a vector-mask target needs a vector mask on the
+ /// active layer (a shape layer's path is its content, not a mask).
+ fn sync_mask_targets(&mut self) {
+ let Some(st) = self.session.active() else { return };
+ if photocraft_engine::mask_view_cmds::current(st).is_some() {
+ self.ui.mask_target = true;
+ self.ui.vector_mask_target = false;
+ }
+ if self.ui.vector_mask_target && !mask_thumbs_ui::has_vector_mask(st) {
+ self.ui.vector_mask_target = false;
+ }
+ }
+
fn prune_thumbs(&mut self) {
let documents = self.session.documents();
if self.thumb_documents.len() == documents.len()
diff --git a/crates/ui-egui/src/mask_thumbs_ui.rs b/crates/ui-egui/src/mask_thumbs_ui.rs
index cdca7f544..e97bf05a7 100644
--- a/crates/ui-egui/src/mask_thumbs_ui.rs
+++ b/crates/ui-egui/src/mask_thumbs_ui.rs
@@ -5,6 +5,9 @@
//! (`layer.layerMask.linked` / `layer.vectorMask.linked`); a disabled mask is crossed out with
//! a red X and ⇧-clicking a mask thumbnail toggles it (`…enabled`). Vector masks render as a
//! white (revealed) / grey (hidden) thumbnail, cached like the other row thumbnails.
+//!
+//! #196: ⌥-click a layer-mask thumbnail to view the mask (⇧⌥: as an overlay), ⌘-click either
+//! mask to load it as a selection, and click the vector mask to target it (brackets).
use egui::{Color32, Painter, Pos2, Rect, Sense, Stroke, StrokeKind, pos2, vec2};
use photocraft_doc::{Document, Layer, LayerId, VectorMask};
@@ -174,15 +177,59 @@ fn paint_chain(painter: &Painter, c: Pos2, color: Color32) {
}
/// The command a click on mask thumbnail `kind` issues with modifiers `m`, if it is one that
-/// replaces the normal click (⇧: toggle the mask on/off, like Photoshop).
+/// replaces the normal click: ⇧ toggles the mask on/off; ⌥ views a layer mask alone in
+/// grayscale and ⇧⌥ as a rubylith overlay (again: back to the composite), like Photoshop.
pub fn click_command(l: &Layer, kind: MaskKind, m: egui::Modifiers) -> Option<(String, Value)> {
- if !m.shift || m.command {
+ if m.command {
+ return None;
+ }
+ if m.alt {
+ let mode = if m.shift { "toggleOverlay" } else { "toggleGray" };
+ return (kind == MaskKind::Pixel && l.mask.is_some()).then(|| (photocraft_engine::mask_view_cmds::ID.into(), json!({"layer": l.id.0, "mode": mode})));
+ }
+ if !m.shift {
return None;
}
let enabled = masks(l).into_iter().find(|(k, _, _)| *k == kind)?.1;
Some((format!("{}.enabled", kind.command()), json!({"layer": l.id.0, "enabled": !enabled})))
}
+/// The `select.loadSelection` params for a ⌘-click on mask thumbnail `kind` (⌘⇧ add, ⌘⌥
+/// subtract, ⌘⇧⌥ intersect).
+pub fn load_params(l: &Layer, kind: MaskKind, m: egui::Modifiers) -> Value {
+ let channel = match kind {
+ MaskKind::Pixel => "mask",
+ MaskKind::Vector => "vectorMask",
+ };
+ json!({"channel": channel, "layer": l.id.0, "operation": crate::channels_panel::load_operation(m)})
+}
+
+/// The active layer of `st` has a vector mask (shape layers' paths are content, not masks).
+pub fn has_vector_mask(st: &photocraft_engine::DocState) -> bool {
+ st.active_layer.and_then(|id| st.doc.layer(id)).is_some_and(|l| l.vector_mask.is_some() && !matches!(l.content, photocraft_doc::LayerContent::Shape(_)))
+}
+
+/// Photoshop's target brackets: corner marks just outside thumbnail `r`.
+pub fn paint_brackets(painter: &Painter, r: Rect, color: Color32) {
+ let r = r.expand(3.0);
+ let k = 6.0;
+ let st = Stroke::new(1.5, color);
+ for (c, dx, dy) in [(r.left_top(), 1.0, 1.0), (r.right_top(), -1.0, 1.0), (r.right_bottom(), -1.0, -1.0), (r.left_bottom(), 1.0, -1.0)] {
+ painter.line_segment([c, c + vec2(k * dx, 0.0)], st);
+ painter.line_segment([c, c + vec2(0.0, k * dy)], st);
+ }
+ painter.ctx().data_mut(|d| d.insert_temp(bracket_id(), r));
+}
+
+fn bracket_id() -> egui::Id {
+ egui::Id::new("layer-target-brackets")
+}
+
+/// Where the target brackets were last drawn (for tests and automation).
+pub fn brackets(ctx: &egui::Context) -> Option<Rect> {
+ ctx.data(|d| d.get_temp(bracket_id()))
+}
+
/// Cheap identity of a vector mask's geometry and state.
pub fn vector_fingerprint(m: &VectorMask) -> u64 {
let mut h: u64 = 0xcbf2_9ce4_8422_2325;
diff --git a/crates/ui-egui/src/mask_thumbs_ui/tests.rs b/crates/ui-egui/src/mask_thumbs_ui/tests.rs
index 9726dba1f..6aba8c6b5 100644
--- a/crates/ui-egui/src/mask_thumbs_ui/tests.rs
+++ b/crates/ui-egui/src/mask_thumbs_ui/tests.rs
@@ -202,3 +202,185 @@ fn panels_never_panic_on_odd_documents() {
let (r, uv) = crate::channels_panel::fit_thumb(Rect::from_min_size(pos2(0.0, 0.0), vec2(28.0, 28.0)), 0, 0);
assert!(r.is_finite() && uv.is_finite() && r.width() > 0.0);
}
+
+// ---------------------------------------------------------------------------------------------
+// #196: ⌥-click mask view, ⌘-click vector mask to select, vector-mask target brackets.
+
+/// The session above with a black dot painted into the layer mask at (50, 50).
+fn dotted() -> (photocraft_engine::Session, u64, u64) {
+ let (mut s, masked, shape) = session();
+ s.execute("paint.stroke", json!({"points": [[50, 50]], "size": 20, "hardness": 1.0, "color": "#000000", "target": "mask"})).unwrap();
+ (s, masked, shape)
+}
+
+fn mask_rect(h: &Harness<'_, PhotocraftApp>, id: u64, kind: MaskKind) -> Rect {
+ recorded(&h.ctx, id).unwrap().0.into_iter().find(|(k, _)| *k == kind).unwrap().1
+}
+
+/// The layer thumbnail sits left of the first chain (see `paint`).
+fn layer_thumb_center(h: &Harness<'_, PhotocraftApp>, id: u64) -> Pos2 {
+ let first = recorded(&h.ctx, id).unwrap().0[0].1;
+ pos2(first.left() - 4.0 - super::CHAIN_W - first.width() / 2.0, first.center().y)
+}
+
+fn mask_view(h: &Harness<'_, PhotocraftApp>) -> serde_json::Value {
+ photocraft_engine::inspect::document(h.state().session.active().unwrap())["layerMaskView"].clone()
+}
+
+fn canvas_px(h: &Harness<'_, PhotocraftApp>) -> Option<Vec<egui::Color32>> {
+ let st = h.state().session.active().unwrap();
+ crate::channel_view::render(&st.doc, &st.channel_view, photocraft_geom::Rect::new(0, 0, 200, 100), 1, false)
+}
+
+fn near(a: Rect, b: Rect) -> bool {
+ (a.min - b.min).length() < 0.6 && (a.max - b.max).length() < 0.6
+}
+
+#[test]
+fn alt_click_views_the_mask_in_gray_and_the_layer_thumbnail_returns() {
+ for ppp in [1.0, 2.0] {
+ let (s, masked, _) = dotted();
+ let mut h = harness(s, 0, ppp, 290.0);
+ let doc = h.state().session.active().unwrap().doc.clone();
+ let r = mask_rect(&h, masked, MaskKind::Pixel);
+ click_with(&mut h, r.center(), Modifiers::ALT);
+ assert_eq!(mask_view(&h), json!({"layer": masked, "mode": "gray"}), "@{ppp}x");
+ assert!(h.state().ui.mask_target, "viewing the mask targets it");
+ assert_eq!(crate::canvas::paint_target(h.state()), json!("mask"), "painting paints the mask");
+ let px = canvas_px(&h).expect("the canvas shows the mask");
+ assert_eq!(px[50 * 200 + 50], egui::Color32::BLACK, "hidden reads black");
+ assert_eq!(px[10 * 200 + 150], egui::Color32::WHITE, "revealed reads white");
+ assert!(near(super::brackets(&h.ctx).unwrap(), r.expand(3.0)), "brackets on the mask");
+ // ⌥-click again: back to the composite.
+ click_with(&mut h, r.center(), Modifiers::ALT);
+ assert_eq!(mask_view(&h), serde_json::Value::Null);
+ assert!(canvas_px(&h).is_none());
+ // Into mask view again, then out by clicking the layer thumbnail.
+ click_with(&mut h, r.center(), Modifiers::ALT);
+ assert_eq!(mask_view(&h)["mode"], "gray");
+ let p = layer_thumb_center(&h, masked);
+ click_with(&mut h, p, Modifiers::NONE);
+ assert_eq!(mask_view(&h), serde_json::Value::Null, "@{ppp}x the layer thumbnail returns");
+ assert!(!h.state().ui.mask_target, "and targets the pixels");
+ assert!(std::sync::Arc::ptr_eq(&doc, &h.state().session.active().unwrap().doc), "viewing never touched the document");
+ }
+}
+
+#[test]
+fn shift_alt_click_shows_a_rubylith_and_the_channels_eye_toggles_it() {
+ let (s, masked, _) = dotted();
+ let mut h = harness(s, 0, 1.0, 290.0);
+ let r = mask_rect(&h, masked, MaskKind::Pixel);
+ click_with(&mut h, r.center(), Modifiers::SHIFT | Modifiers::ALT);
+ assert_eq!(mask_view(&h), json!({"layer": masked, "mode": "overlay"}));
+ let px = canvas_px(&h).unwrap();
+ assert_eq!(px[50 * 200 + 50], egui::Color32::from_rgba_premultiplied(128, 0, 0, 128), "50% red over hidden areas");
+ assert_eq!(px[10 * 200 + 150], egui::Color32::TRANSPARENT, "the composite shows through elsewhere");
+ assert!(layer(&h, masked).mask.unwrap().enabled, "⇧⌥ doesn't disable the mask");
+ // Channels: the mask row's eye shows and hides the overlay.
+ let ctx = h.ctx.clone();
+ let (req, _rx) = crate::control::ControlRequest::new("ui.set", json!({"dockTabs": {"layers": 1}}));
+ crate::control::handle(h.state_mut(), &ctx, &req);
+ h.run_steps(4);
+ let p = h.get_by_label("Visibility Masked Mask").rect().center();
+ click_with(&mut h, p, Modifiers::NONE);
+ assert_eq!(mask_view(&h), serde_json::Value::Null, "the eye hides the overlay");
+ let p = h.get_by_label("Visibility Masked Mask").rect().center();
+ click_with(&mut h, p, Modifiers::NONE);
+ assert_eq!(mask_view(&h)["mode"], "overlay", "and shows it again");
+ // In gray view the composite's eye brings the composite back under the overlay.
+ h.state_mut().run("view.layerMask", json!({"mode": "gray"})).unwrap();
+ h.run_steps(3);
+ let p = h.get_by_label("Visibility RGB").rect().center();
+ click_with(&mut h, p, Modifiers::NONE);
+ assert_eq!(mask_view(&h)["mode"], "overlay");
+}
+
+#[test]
+fn command_click_a_vector_mask_loads_its_path_as_a_selection() {
+ let (s, masked, _) = session();
+ let mut h = harness(s, 0, 1.0, 290.0);
+ let r = mask_rect(&h, masked, MaskKind::Vector);
+ let sel = |h: &Harness<'_, PhotocraftApp>| h.state().session.active().unwrap().doc.selection.clone();
+ click_with(&mut h, r.center(), Modifiers::COMMAND);
+ let b = sel(&h).expect("⌘-click selects the path").content_bounds();
+ assert_eq!((b.x0, b.y0, b.width(), b.height()), (20, 10, 100, 80));
+ assert!(!h.state().ui.vector_mask_target, "⌘-click doesn't retarget");
+ // ⌘⇧ add a 4×4 square, ⌘⌥ subtract, ⌘⇧⌥ intersect.
+ h.state_mut().run("select.rect", json!({"x": 150, "y": 50, "width": 4, "height": 4})).unwrap();
+ click_with(&mut h, r.center(), Modifiers::COMMAND | Modifiers::SHIFT);
+ let s1 = sel(&h).unwrap();
+ assert!(s1.sample_channel(60, 50, 0) > 0.99 && s1.sample_channel(151, 51, 0) > 0.99, "added");
+ h.state_mut().run("select.all", json!({})).unwrap();
+ click_with(&mut h, r.center(), Modifiers::COMMAND | Modifiers::ALT);
+ let s2 = sel(&h).unwrap();
+ assert!(s2.sample_channel(60, 50, 0) < 0.01 && s2.sample_channel(150, 50, 0) > 0.99, "subtracted");
+ h.state_mut().run("select.rect", json!({"x": 100, "y": 0, "width": 100, "height": 100})).unwrap();
+ click_with(&mut h, r.center(), Modifiers::COMMAND | Modifiers::SHIFT | Modifiers::ALT);
+ let b = sel(&h).unwrap().content_bounds();
+ assert_eq!((b.x0, b.y0, b.width(), b.height()), (100, 10, 20, 80), "intersected");
+}
+
+#[test]
+fn clicking_the_vector_mask_targets_it_for_the_path_tools() {
+ let (s, masked, _) = session();
+ let mut h = harness(s, 0, 1.0, 290.0);
+ let r = mask_rect(&h, masked, MaskKind::Vector);
+ click_with(&mut h, r.center(), Modifiers::NONE);
+ assert!(h.state().ui.vector_mask_target && !h.state().ui.mask_target);
+ assert_eq!(h.state().ui.selected_path.as_deref(), Some("layer"), "the Paths panel selects its path");
+ assert!(near(super::brackets(&h.ctx).unwrap(), r.expand(3.0)), "brackets on the vector mask");
+ assert_eq!(crate::canvas::paint_target(h.state()), json!("pixels"));
+ // Path Selection moves the vector mask.
+ crate::vector_ui::path_selection_finish(h.state_mut(), [30.0, 30.0], [35.0, 32.0]);
+ let k = layer(&h, masked).vector_mask.unwrap().path.subpaths[0].knots[0].anchor;
+ assert_eq!((k.x, k.y), (25.0, 12.0));
+ // The Pen adds a subpath to it.
+ h.state_mut().ui.pen = Some(crate::vector_ui::PenPath { knots: vec![[[150.0, 10.0]; 3], [[190.0, 10.0]; 3], [[190.0, 40.0]; 3]], dragging: false });
+ crate::vector_ui::pen_commit(h.state_mut(), true);
+ assert_eq!(layer(&h, masked).vector_mask.unwrap().path.subpaths.len(), 2);
+ assert!(h.state().session.active().unwrap().doc.work_path.is_none(), "not a work path");
+ h.run_steps(2);
+ // The pixel mask and the layer thumbnail take the brackets back.
+ let m = mask_rect(&h, masked, MaskKind::Pixel);
+ click_with(&mut h, m.center(), Modifiers::NONE);
+ assert!(h.state().ui.mask_target && !h.state().ui.vector_mask_target);
+ assert!(near(super::brackets(&h.ctx).unwrap(), m.expand(3.0)));
+ click_with(&mut h, r.center(), Modifiers::NONE);
+ let p = layer_thumb_center(&h, masked);
+ click_with(&mut h, p, Modifiers::NONE);
+ assert!(!h.state().ui.mask_target && !h.state().ui.vector_mask_target);
+ // Deleting the vector mask drops the target.
+ click_with(&mut h, r.center(), Modifiers::NONE);
+ assert!(h.state().ui.vector_mask_target);
+ h.state_mut().run("layer.vectorMask.delete", json!({"layer": masked})).unwrap();
+ h.run_steps(2);
+ assert!(!h.state().ui.vector_mask_target);
+}
+
+#[test]
+fn mask_view_gestures_fail_gracefully_without_a_mask() {
+ let (s, masked, shape) = session();
+ let mut h = harness(s, 0, 1.0, 290.0);
+ // ⌥-click on a vector mask is not a mask view.
+ let p = mask_rect(&h, masked, MaskKind::Vector).center();
+ click_with(&mut h, p, Modifiers::ALT);
+ assert_eq!(mask_view(&h), serde_json::Value::Null);
+ // A layer without a layer mask: the command fails, nothing changes.
+ assert!(h.state_mut().run("view.layerMask", json!({"layer": shape, "mode": "gray"})).is_err());
+ assert_eq!(mask_view(&h), serde_json::Value::Null);
+ h.run_steps(2);
+ // A stale view (layer gone) draws nothing instead of panicking.
+ h.state_mut().session.active_mut().unwrap().channel_view.layer_mask = Some(photocraft_engine::mask_view_cmds::LayerMaskView {
+ layer: photocraft_doc::LayerId(987_654),
+ mode: photocraft_engine::mask_view_cmds::MaskViewMode::Gray,
+ });
+ assert!(canvas_px(&h).is_none());
+ h.run_steps(2);
+ // The mask goes while it is shown: the view ends.
+ h.state_mut().run("view.layerMask", json!({"layer": masked, "mode": "gray"})).unwrap();
+ h.state_mut().run("layer.layerMask.delete", json!({"layer": masked})).unwrap();
+ h.run_steps(2);
+ assert_eq!(mask_view(&h), serde_json::Value::Null);
+ assert_eq!(crate::canvas::paint_target(h.state()), json!("pixels"));
+}
diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs
index ba84d0e9f..02433854f 100644
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@ -1348,6 +1348,12 @@ fn layers(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
for (id, p) in actions {
if id == "ui.maskTarget" {
app.ui.mask_target = p.as_bool().unwrap_or(false);
+ app.ui.vector_mask_target = false;
+ continue;
+ }
+ if id == "ui.vectorMaskTarget" {
+ app.ui.vector_mask_target = p.as_bool().unwrap_or(false);
+ app.ui.mask_target = false;
continue;
}
if p.is_null() {
@@ -1471,17 +1477,19 @@ fn layer_row(
// Link chains and pixel / vector mask thumbnails (#153).
let masks = crate::mask_thumbs_ui::paint(app, ctx, ui, &painter, doc, l, &mut x, rect.center().y, ts, actions);
let mask_rect = masks.thumb(crate::mask_thumbs_ui::MaskKind::Pixel);
- // Photoshop frames the targeted thumbnail (pixels or mask) of the active layer with corner brackets.
+ let vector_rect = masks.thumb(crate::mask_thumbs_ui::MaskKind::Vector);
+ // Photoshop frames the targeted thumbnail (pixels, mask or vector mask) of the active layer
+ // with corner brackets.
if row.primary {
- let target = if app.ui.mask_target { mask_rect } else { Some(thumb) };
- if let Some(r) = target.filter(|_| l.mask.is_some() || !app.ui.mask_target) {
- let r = r.expand(3.0);
- let k = 6.0;
- let st = Stroke::new(1.5, t.text);
- for (c, dx, dy) in [(r.left_top(), 1.0, 1.0), (r.right_top(), -1.0, 1.0), (r.right_bottom(), -1.0, -1.0), (r.left_bottom(), 1.0, -1.0)] {
- painter.line_segment([c, c + vec2(k * dx, 0.0)], st);
- painter.line_segment([c, c + vec2(0.0, k * dy)], st);
- }
+ let target = if app.ui.vector_mask_target && vector_rect.is_some() {
+ vector_rect
+ } else if app.ui.mask_target {
+ mask_rect.or(Some(thumb))
+ } else {
+ Some(thumb)
+ };
+ if let Some(r) = target {
+ crate::mask_thumbs_ui::paint_brackets(&painter, r, t.text);
}
}
// Right-hand indicators first; the name gets what is left and ends in "…" (#144).
@@ -1508,15 +1516,16 @@ fn layer_row(
crate::layer_row_ui::label(&painter, x, rect.center().y + 8.0, name_right, &sub, egui::FontId::proportional(11.0), t.text_faint);
}
crate::layer_row_ui::record(ctx, crate::layer_row_ui::RowRects { layer: l.id.0, row: rect, name: name_rect, indicators });
- // ⌘-click a layer or mask thumbnail loads its transparency / mask as a selection (⇧ add,
- // ⌥ subtract, ⇧⌥ intersect) instead of changing the layer selection.
+ // ⌘-click a layer, mask or vector-mask thumbnail loads its transparency / mask / path as a
+ // selection (⇧ add, ⌥ subtract, ⇧⌥ intersect) instead of changing the layer selection.
let thumb_load = resp.clicked().then(|| (ui.input(|i| i.modifiers), resp.interact_pointer_pos())).and_then(|(m, pos)| {
let p = pos.filter(|_| m.command)?;
- let on_mask = mask_rect.is_some_and(|r| r.expand(2.0).contains(p));
- (on_mask || thumb.expand(2.0).contains(p))
- .then(|| json!({"channel": if on_mask { "mask" } else { "transparency" }, "layer": l.id.0, "operation": crate::channels_panel::load_operation(m)}))
+ if let Some(kind) = masks.hit(p) {
+ return Some(crate::mask_thumbs_ui::load_params(l, kind, m));
+ }
+ thumb.expand(2.0).contains(p).then(|| json!({"channel": "transparency", "layer": l.id.0, "operation": crate::channels_panel::load_operation(m)}))
});
- // ⇧-click a mask thumbnail: disable / enable that mask.
+ // ⇧-click a mask thumbnail: disable / enable that mask; ⌥-click a layer mask: view it.
let mask_toggle = resp.clicked().then(|| (ui.input(|i| i.modifiers), resp.interact_pointer_pos())).and_then(|(m, pos)| {
let kind = masks.hit(pos?)?;
crate::mask_thumbs_ui::click_command(l, kind, m)
@@ -1532,12 +1541,19 @@ fn layer_row(
let pos = resp.interact_pointer_pos();
let on_mask = mask_rect.zip(pos).is_some_and(|(r, p)| r.expand(2.0).contains(p));
let on_thumb = pos.is_some_and(|p| thumb.expand(2.0).contains(p));
- // The vector mask thumbnail picks the layer's path in the Paths panel.
- if pos.and_then(|p| masks.hit(p)) == Some(crate::mask_thumbs_ui::MaskKind::Vector) {
- app.ui.selected_path = Some("layer".into());
+ let on_vector = pos.and_then(|p| masks.hit(p)) == Some(crate::mask_thumbs_ui::MaskKind::Vector);
+ // Clicking the layer thumbnail leaves mask view (#196).
+ let viewing = app.session.active().and_then(photocraft_engine::mask_view_cmds::current).is_some_and(|v| v.layer == l.id);
+ if on_thumb && viewing {
+ actions.push((photocraft_engine::mask_view_cmds::ID.into(), json!({"layer": l.id.0, "mode": "off"})));
}
let content_less = matches!(l.content, LayerContent::Adjustment(_) | LayerContent::Fill(_));
- if on_mask || (content_less && l.mask.is_some()) {
+ if on_vector {
+ // The vector mask thumbnail targets the vector mask: the path tools edit it and the
+ // Paths panel selects the layer's path.
+ app.ui.selected_path = Some("layer".into());
+ actions.push(("ui.vectorMaskTarget".into(), json!(true)));
+ } else if on_mask || (content_less && l.mask.is_some()) {
actions.push(("ui.maskTarget".into(), json!(true)));
} else if on_thumb || !row.primary {
actions.push(("ui.maskTarget".into(), json!(false)));
diff --git a/crates/ui-egui/src/state.rs b/crates/ui-egui/src/state.rs
index c43e11efe..79951a47c 100644
--- a/crates/ui-egui/src/state.rs
+++ b/crates/ui-egui/src/state.rs
@@ -550,6 +550,10 @@ pub struct UiState {
/// Painting targets the active layer's mask instead of its pixels.
#[serde(default)]
pub mask_target: bool,
+ /// The active layer's vector mask is targeted (its Layers thumbnail is bracketed): the path
+ /// tools edit it (#196). Never set together with `mask_target`.
+ #[serde(default)]
+ pub vector_mask_target: bool,
/// Brush Preset picker opened by a right-click on the canvas: its screen position (points).
#[serde(default)]
pub brush_picker: Option<[f32; 2]>,
@@ -649,6 +653,7 @@ impl Default for UiState {
text_edit: None,
transform: None,
mask_target: false,
+ vector_mask_target: false,
brush_picker: None,
smoothing_tool: None,
tool_smoothing: Vec::new(),
diff --git a/crates/ui-egui/src/vector_ui.rs b/crates/ui-egui/src/vector_ui.rs
index cbe8d254f..6b1c34287 100644
--- a/crates/ui-egui/src/vector_ui.rs
+++ b/crates/ui-egui/src/vector_ui.rs
@@ -166,6 +166,13 @@ pub fn pen_commit(app: &mut PhotocraftApp, closed: bool) {
let stroke =
if closed { stroke_param(app) } else { json!({"width": app.ui.tool_options.stroke_width.max(1.0), "color": hex(app.session.tools.foreground)}) };
app.run("shape.create", json!({"kind": "path", "path": path, "fill": fill, "stroke": stroke}))
+ } else if let Some((id, existing)) = targeted_vector_mask(app) {
+ // A targeted vector mask takes the new subpath (#196), as in Photoshop.
+ let mut p = photocraft_engine::vector_cmds::path_json(&existing);
+ if let (Some(subs), Some(new)) = (p.get_mut("subpaths").and_then(Value::as_array_mut), path.get("subpaths").and_then(Value::as_array)) {
+ subs.extend(new.iter().cloned());
+ }
+ app.run("layer.vectorMask.edit", json!({"layer": id, "path": p}))
} else {
app.run("path.set", json!({"name": "work", "path": path}))
};
@@ -178,15 +185,35 @@ pub fn pen_commit(app: &mut PhotocraftApp, closed: bool) {
// ---------------------------------------------------------------------------------------------
// Path Selection
-/// The path Path Selection edits: the active shape layer's, else the work path.
-fn target_path(app: &PhotocraftApp) -> Option<(Option<u64>, Path)> {
+/// What Path Selection edits.
+enum PathTarget {
+ Shape(u64),
+ /// The active layer's vector mask, when its Layers thumbnail is targeted (#196).
+ VectorMask(u64),
+ Work,
+}
+
+/// The targeted vector mask of the active layer, if the Layers panel targets it.
+fn targeted_vector_mask(app: &PhotocraftApp) -> Option<(u64, Path)> {
+ let st = app.session.active()?;
+ let l = st.active_layer.and_then(|id| st.doc.layer(id))?;
+ (app.ui.vector_mask_target && !matches!(l.content, LayerContent::Shape(_))).then_some(())?;
+ l.vector_mask.as_ref().map(|m| (l.id.0, m.path.clone()))
+}
+
+/// The path Path Selection edits: the targeted vector mask, the active shape layer's path, else
+/// the work path.
+fn target_path(app: &PhotocraftApp) -> Option<(PathTarget, Path)> {
+ if let Some((id, p)) = targeted_vector_mask(app) {
+ return Some((PathTarget::VectorMask(id), p));
+ }
let st = app.session.active()?;
if let Some(l) = st.active_layer.and_then(|id| st.doc.layer(id))
&& let LayerContent::Shape(sh) = &l.content
{
- return Some((Some(l.id.0), sh.path.clone()));
+ return Some((PathTarget::Shape(l.id.0), sh.path.clone()));
}
- st.doc.work_path.clone().map(|p| (None, p))
+ st.doc.work_path.clone().map(|p| (PathTarget::Work, p))
}
pub fn path_selection_finish(app: &mut PhotocraftApp, start: [f64; 2], end: [f64; 2]) {
@@ -194,10 +221,14 @@ pub fn path_selection_finish(app: &mut PhotocraftApp, start: [f64; 2], end: [f64
if dx.abs() + dy.abs() < 0.5 {
return;
}
- let Some((layer, path)) = target_path(app) else { return };
- let _ = match layer {
- Some(id) => app.run("shape.edit", json!({"layer": id, "move": [dx.round(), dy.round()]})),
- None => {
+ 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()]})),
+ PathTarget::VectorMask(id) => {
+ let moved = path.transform(&Affine::translate(dx.round(), dy.round()));
+ app.run("layer.vectorMask.edit", json!({"layer": id, "path": photocraft_engine::vector_cmds::path_json(&moved)}))
+ }
+ PathTarget::Work => {
let moved = path.transform(&Affine::translate(dx.round(), dy.round()));
app.run("path.set", json!({"name": "work", "path": photocraft_engine::vector_cmds::path_json(&moved)}))
}
@@ -274,6 +305,10 @@ pub fn draw_overlay(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform
draw_path(&sh.path, tool == Tool::PathSelection);
}
}
+ // A targeted vector mask shows its path with any tool (#196).
+ if let Some((_, p)) = targeted_vector_mask(app) {
+ draw_path(&p, tool == Tool::PathSelection);
+ }
// Pen path in progress, with handles of the last knot and a rubber band to the pointer.
if let Some(pen) = &app.ui.pen {
let mut pts = Vec::new();
@@ -318,7 +353,7 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui, tool: Tool) -> bo
};
let o = &mut app.ui.tool_options;
if tool == Tool::PathSelection {
- lbl(ui, "Drag to move the active shape's path or the Work Path");
+ lbl(ui, if app.ui.vector_mask_target { "Drag to move the targeted vector mask" } else { "Drag to move the active shape's path or the Work Path" });
return true;
}
if tool == Tool::Pen {