Skip to content

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

Clone Stamp: live stroke, strokes start on the press, source preview under the brush (#1026)

jason4short7892365f9382
diff --git a/crates/engine/src/presets/clone_source.rs b/crates/engine/src/presets/clone_source.rs
index 0f0e1f141..e2a4a8485 100644
--- a/crates/engine/src/presets/clone_source.rs
+++ b/crates/engine/src/presets/clone_source.rs
@@ -156,6 +156,16 @@ fn pt(p: &Value, k: &str) -> Option<(f64, f64)> {
/// stroke's first point. With `"aligned"` strokes the slot remembers the anchor so later
/// strokes keep sampling relative to the original pairing.
pub fn mapping(s: &mut Session, p: &Value, first: (f64, f64), cmd: &str) -> Result<Mapping> {
+ let (m, anchor) = resolve(s, p, first, cmd)?;
+ if let Some(a) = anchor {
+ s.presets.clone.active_mut().anchor = Some(a);
+ }
+ Ok(m)
+}
+
+/// [`mapping`] without remembering anything: the mapping, and the anchor an aligned stroke from
+/// the slot stores (a live preview resolves the same mapping the commit will).
+pub fn resolve(s: &Session, p: &Value, first: (f64, f64), cmd: &str) -> Result<(Mapping, Option<[f64; 2]>)> {
let aligned = p.get("aligned").and_then(Value::as_bool).unwrap_or(true);
let slot = s.presets.clone.active().clone();
let explicit_tf = ["scale", "rotation", "flipH", "flipV"].iter().any(|k| p.get(*k).is_some());
@@ -172,10 +182,10 @@ pub fn mapping(s: &mut Session, p: &Value, first: (f64, f64), cmd: &str) -> Resu
let anchor_param = pt(p, "anchor");
if let Some(off) = pt(p, "offset") {
let a = anchor_param.unwrap_or(first);
- return Ok(Mapping { source: (a.0 + off.0, a.1 + off.1), anchor: a, m });
+ return Ok((Mapping { source: (a.0 + off.0, a.1 + off.1), anchor: a, m }, None));
}
if let Some(src) = pt(p, "source") {
- return Ok(Mapping { source: src, anchor: anchor_param.unwrap_or(first), m });
+ return Ok((Mapping { source: src, anchor: anchor_param.unwrap_or(first), m }, None));
}
let Some(src) = slot.source else { return Err(bad(cmd, "missing `source` ([x,y]) or `offset` ([dx,dy]); or set one with cloneSource.set")) };
let src = (src[0], src[1]);
@@ -183,10 +193,7 @@ pub fn mapping(s: &mut Session, p: &Value, first: (f64, f64), cmd: &str) -> Resu
(true, Some(a)) => (a[0], a[1]),
_ => first,
};
- if aligned {
- s.presets.clone.active_mut().anchor = Some([anchor.0, anchor.1]);
- }
- Ok(Mapping { source: src, anchor, m })
+ Ok((Mapping { source: src, anchor, m }, aligned.then_some([anchor.0, anchor.1])))
}
/// Bilinear resample of `src` (covering [`Mapping::source_rect`]) onto `dst`, interpolating
diff --git a/crates/engine/src/retouch_cmds.rs b/crates/engine/src/retouch_cmds.rs
index e306bce07..43f76c3b3 100644
--- a/crates/engine/src/retouch_cmds.rs
+++ b/crates/engine/src/retouch_cmds.rs
@@ -303,6 +303,97 @@ fn clone_stamp(s: &mut Session, p: &Value) -> Result<Value> {
Ok(clone_result(dmg, off, aligned, p, &stroke))
}
+/// A Clone Stamp stroke shown while it is drawn: the dabs so far composited from the clone source
+/// onto a copy of the active document, as `paint.cloneStamp` with the same params commits them
+/// (the same coverage, sampling and blend; a smoothing catch-up appears on release).
+pub struct LiveClone {
+ /// The active document with the stroke so far.
+ pub doc: std::sync::Arc<Document>,
+ renderer: photocraft_paint::StrokeRenderer,
+ pre: std::sync::Arc<Document>,
+ pre_surf: Surface,
+ id: Option<LayerId>,
+ params: Value,
+ which: SampleLayers,
+ map: crate::presets::clone_source::Mapping,
+ mode: BlendMode,
+ opacity: f32,
+ sel: Option<Surface>,
+ lock: bool,
+ /// Where the doc shows what finishing the stroke now would add (a lone first dab, the
+ /// smoothing catch-up), redrawn on every step as the Brush's live stroke does.
+ tail: Rect,
+}
+
+impl LiveClone {
+ /// Start from `paint.cloneStamp` params; their `points` are rendered.
+ pub fn begin(s: &Session, p: &Value) -> Result<Self> {
+ const CMD: &str = "paint.cloneStamp";
+ has_pixel_layer(s).map_err(EngineError::Other)?;
+ let (stroke, id) = parse_brush(s, p, CMD)?;
+ let which = sample_layers(p, CMD)?;
+ let mode = blend_param(p, CMD)?;
+ let f = *stroke.points.first().ok_or_else(|| bad(CMD, "`points` is empty"))?;
+ let (map, _) = crate::presets::clone_source::resolve(s, p, (f.x, f.y), CMD)?;
+ let pre = s.active().ok_or(EngineError::NoDocument)?.doc.clone();
+ let mut doc = (*pre).clone();
+ let sel = doc.selection.clone();
+ let (surf, lock) = crate::channel_cmds::target_surface(&mut doc, id, p)?;
+ let pre_surf = surf.clone();
+ // As `stroke_coverage`, which the commit uses.
+ let renderer = photocraft_paint::StrokeRenderer::new(&stroke.brush, None, 1.0);
+ let opacity = stroke.brush.opacity;
+ let mut live =
+ Self { doc: std::sync::Arc::new(doc), renderer, pre, pre_surf, id, params: p.clone(), which, map, mode, opacity, sel, lock, tail: Rect::EMPTY };
+ live.push(&stroke.points)?;
+ Ok(live)
+ }
+
+ /// Everything the stroke has touched so far.
+ pub fn bounds(&self) -> Rect {
+ self.renderer.bounds().union(&self.tail)
+ }
+
+ /// Render more points; returns the rectangle that changed. Each changed area is redrawn from
+ /// the pre-stroke pixels with the stroke's coverage so far, so overlapping dabs build up as in
+ /// the commit, and pixels painted earlier in the stroke are never re-cloned. What finishing
+ /// the stroke now would add is drawn too (a lone first dab shows on the press), and redrawn on
+ /// every step.
+ pub fn push(&mut self, pts: &[StrokePoint]) -> Result<Rect> {
+ self.renderer.push(pts);
+ let old = std::mem::replace(&mut self.tail, Rect::EMPTY);
+ let mut dmg = Rect::EMPTY;
+ if !old.is_empty() {
+ // Back to the stroke without the previous tail.
+ let (surf, _) = crate::channel_cmds::target_surface(std::sync::Arc::make_mut(&mut self.doc), self.id, &self.params)?;
+ surf.write_region(old, &self.pre_surf.read_region(old));
+ self.renderer.mark_dirty(old);
+ dmg = old;
+ }
+ let r = self.renderer.take_dirty_rect();
+ let cov = self.renderer.coverage_in(r);
+ dmg = dmg.union(&self.composite(r, &cov)?);
+ if let Some(mut tail) = self.renderer.tail_preview() {
+ let r = tail.take_dirty_rect();
+ let cov = tail.coverage_in(r);
+ self.tail = self.composite(r, &cov)?;
+ dmg = dmg.union(&self.tail);
+ }
+ Ok(dmg)
+ }
+
+ /// Redraw `r` from the pre-stroke pixels with the clone source through coverage `cov`.
+ fn composite(&mut self, r: Rect, cov: &[f32]) -> Result<Rect> {
+ if r.is_empty() {
+ return Ok(r);
+ }
+ let paint = clone_sample(&self.pre, self.id, &self.pre_surf, self.which, r, &self.map, "paint.cloneStamp")?;
+ let (surf, _) = crate::channel_cmds::target_surface(std::sync::Arc::make_mut(&mut self.doc), self.id, &self.params)?;
+ surf.write_region(r, &self.pre_surf.read_region(r));
+ Ok(apply_coverage(surf, r, cov, self.opacity, self.sel.as_ref(), self.lock, &paint, self.mode).union(&r))
+ }
+}
+
/// Grow a stroke's coverage map by `m` pixels of zero coverage (a Dirichlet boundary for the solve).
fn pad_coverage(bounds: Rect, cov: &[f32], m: i32) -> (Rect, Vec<f32>) {
let g = bounds.inflate(m);
diff --git a/crates/engine/src/retouch_cmds/tests.rs b/crates/engine/src/retouch_cmds/tests.rs
index fd30b0099..058722ffe 100644
--- a/crates/engine/src/retouch_cmds/tests.rs
+++ b/crates/engine/src/retouch_cmds/tests.rs
@@ -1090,3 +1090,28 @@ fn pattern_stamp_rejects_hostile_input() {
s.execute("layer.setProps", json!({"locks": {"pixels": true}})).unwrap();
assert!(stamp(&mut s, json!({"points": [[16, 16]]})).is_err());
}
+
+/// The live Clone Stamp shows what the commit paints: the same pixels, fed in pieces or at once,
+/// with soft overlapping dabs (built-up coverage) and opacity.
+#[test]
+fn live_clone_matches_the_commit() {
+ let mut s = session(96, 64, 8, "rgb");
+ paint_layer(&mut s, texture);
+ let p = json!({"points": [[50, 30], [60, 34], [70, 30], [80, 36]], "source": [20, 20], "size": 14, "hardness": 40, "opacity": 70});
+ let pts = |v: &[[f64; 2]]| v.iter().map(|q| StrokePoint::new(q[0], q[1], 1.0)).collect::<Vec<_>>();
+ let mut live = LiveClone::begin(&s, &json!({"points": [[50, 30]], "source": [20, 20], "size": 14, "hardness": 40, "opacity": 70})).unwrap();
+ live.push(&pts(&[[60.0, 34.0], [70.0, 30.0]])).unwrap();
+ live.push(&pts(&[[80.0, 36.0]])).unwrap();
+ let shown = live.doc.clone();
+ s.execute("paint.cloneStamp", p).unwrap();
+ let id = s.active().unwrap().active_layer.unwrap();
+ let (a, b) = (shown.layer(id).unwrap().surface().unwrap(), s.active().unwrap().doc.layer(id).unwrap().surface().unwrap());
+ for y in 20..46 {
+ for x in 40..92 {
+ let (got, want) = (a.rgba(x, y), b.rgba(x, y));
+ for c in 0..4 {
+ assert!((got[c] - want[c]).abs() <= tol(8), "({x}, {y}): live {got:?} vs commit {want:?}");
+ }
+ }
+ }
+}
diff --git a/crates/paint/src/render.rs b/crates/paint/src/render.rs
index f84bca494..d0d0ff68d 100644
--- a/crates/paint/src/render.rs
+++ b/crates/paint/src/render.rs
@@ -574,6 +574,27 @@ impl StrokeRenderer {
}
}
+ /// The coverage tiles touched since the last call (or `composite`), as one rectangle clipped to
+ /// the stroke bounds, and forget them: what a live preview that composites its own paint has
+ /// to redraw.
+ pub fn take_dirty_rect(&mut self) -> Rect {
+ let r = self
+ .cov
+ .take_dirty()
+ .into_iter()
+ .fold(Rect::EMPTY, |acc, (tx, ty)| acc.union(&Rect::new(tx * COV_TILE, ty * COV_TILE, (tx + 1) * COV_TILE, (ty + 1) * COV_TILE)));
+ if let Some(d) = self.dual.as_mut() {
+ d.dirty.clear();
+ }
+ r.intersect(&self.bounds())
+ }
+
+ /// Final coverage over `r`, one value per pixel in rows (as [`dense_coverage`](Self::dense_coverage)
+ /// over its bounds).
+ pub fn coverage_in(&self, r: Rect) -> Vec<f32> {
+ (r.y0..r.y1).flat_map(|y| (r.x0..r.x1).map(move |x| (x, y))).map(|(x, y)| self.coverage_at(x, y)).collect()
+ }
+
/// Final stroke coverage at a pixel (stroke-level masks applied, before opacity/selection).
pub fn coverage_at(&self, x: i32, y: i32) -> f32 {
let c = self.cov.get(x, y);
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index 508aef84f..de3aa0dc1 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -237,10 +237,45 @@ pub(crate) fn draw_readout(ctx: &egui::Context, id: &str, cursor: Pos2, labels:
});
}
-/// A Brush/Eraser stroke shown while it is drawn: the engine renders the real dabs onto a copy of
-/// the document, and the canvas redraws only what each step changed.
+/// The engine's live stroke of a tool: the Brush, Pencil and Eraser paint dabs, the Clone Stamp
+/// composites its source.
+enum EngineStroke {
+ Brush(Box<photocraft_engine::brush_cmds::LiveStroke>),
+ Clone(Box<photocraft_engine::retouch_cmds::LiveClone>),
+}
+
+impl EngineStroke {
+ fn doc(&self) -> &std::sync::Arc<photocraft_doc::Document> {
+ match self {
+ Self::Brush(s) => &s.doc,
+ Self::Clone(s) => &s.doc,
+ }
+ }
+ fn bounds(&self) -> DRect {
+ match self {
+ Self::Brush(s) => s.bounds(),
+ Self::Clone(s) => s.bounds(),
+ }
+ }
+ fn push(&mut self, pts: &[photocraft_engine::paint::StrokePoint]) -> photocraft_engine::Result<DRect> {
+ match self {
+ Self::Brush(s) => s.push(pts),
+ Self::Clone(s) => s.push(pts),
+ }
+ }
+ /// The jitter seed the commit must reuse (the Clone Stamp's comes from the session brush).
+ fn seed(&self) -> Option<u64> {
+ match self {
+ Self::Brush(s) => Some(s.seed),
+ Self::Clone(_) => None,
+ }
+ }
+}
+
+/// A stroke shown while it is drawn: the engine renders the real result onto a copy of the
+/// document, and the canvas redraws only what each step changed.
pub(crate) struct LiveStroke {
- stroke: photocraft_engine::brush_cmds::LiveStroke,
+ stroke: EngineStroke,
doc: photocraft_doc::DocId,
revision: u64,
/// Preview key of the stroke; step `n` displays as `key + n`.
@@ -281,7 +316,7 @@ fn stroke_params(app: &PhotocraftApp, tool: Tool, erase: bool, points: &[Vec<f64
/// Tools whose strokes the engine renders while they are drawn (`LiveStroke`).
pub(crate) fn strokes_live(tool: Tool) -> bool {
- matches!(tool, Tool::Brush | Tool::Pencil | Tool::Eraser)
+ matches!(tool, Tool::Brush | Tool::Pencil | Tool::Eraser | Tool::CloneStamp)
}
/// The command a live-stroking tool commits: the Pencil's `paint.pencil`, else `paint.stroke`.
@@ -381,8 +416,16 @@ fn begin_live_stroke(app: &PhotocraftApp) -> Option<LiveStroke> {
static STROKES: std::sync::atomic::AtomicU64 = std::sync::atomic::AtomicU64::new(0);
let st = app.session.active()?;
let d = app.drag.as_ref()?;
- let p = stroke_params(app, d.tool, d.erase, &app.stylus.stroke_points(&d.points));
- let stroke = photocraft_engine::brush_cmds::LiveStroke::begin_with(&app.session, stroke_command(d.tool), &p).ok()?;
+ let stroke = if d.tool == Tool::CloneStamp {
+ // The params `retouch_ui::finish_stroke` commits.
+ let mut p = crate::retouch_ui::clone_params(app)?;
+ p["points"] = json!(d.points);
+ p["target"] = paint_target(app);
+ EngineStroke::Clone(Box::new(photocraft_engine::retouch_cmds::LiveClone::begin(&app.session, &p).ok()?))
+ } else {
+ let p = stroke_params(app, d.tool, d.erase, &app.stylus.stroke_points(&d.points));
+ EngineStroke::Brush(Box::new(photocraft_engine::brush_cmds::LiveStroke::begin_with(&app.session, stroke_command(d.tool), &p).ok()?))
+ };
let n = STROKES.fetch_add(1, std::sync::atomic::Ordering::Relaxed) & 0xff_ffff;
let damage = vec![stroke.bounds()];
Some(LiveStroke { stroke, doc: st.doc.id, revision: st.revision, key: (1 << 44) | (n << 20), damage, fed: d.points.len() })
@@ -637,7 +680,7 @@ fn display_doc(app: &mut PhotocraftApp, idx: usize) -> (std::sync::Arc<Document>
}
let st = &app.session.documents()[idx];
if let Some(l) = live_stroke(app, idx) {
- return (l.stroke.doc.clone(), l.display_key());
+ return (l.stroke.doc().clone(), l.display_key());
}
if let (Some(t), Some(pv)) = (&app.ui.transform, &app.transform_preview)
&& app.session.active_index() == Some(idx)
@@ -852,7 +895,7 @@ fn damage_since(app: &PhotocraftApp, idx: usize, seen: (u64, u64), now: (u64, u6
}
let l = live_stroke(app, idx).filter(|l| seen.0 == now.0 && l.display_key() == now.1)?;
let r = l.since(seen.1 ^ display_key)?;
- Some(if r.is_empty() { r } else { r.inflate(effect_reach(&l.stroke.doc.layers)) })
+ Some(if r.is_empty() { r } else { r.inflate(effect_reach(&l.stroke.doc().layers)) })
}
/// Document `doc`'s canvas caches showed a preview that the edit just committed reproduces
@@ -2165,6 +2208,25 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
// A drag is only recognised once the pointer has moved past egui's click distance: the
// gesture starts where the button went down, not where it is now (#123).
let gesture_active_before = app.drag.is_some();
+ // Live painting tools start on the press, not once the pointer passes egui's click
+ // distance: the first dab shows at once. The drag recognised later continues that stroke,
+ // and a click (or a long press that never moved) just ends it.
+ if strokes_live(tool)
+ && app.drag.is_none()
+ && response.is_pointer_button_down_on()
+ && ui.input(|i| i.pointer.primary_pressed())
+ && let Some(p) = ui.input(|i| i.pointer.press_origin()).filter(|p| rect.contains(*p))
+ {
+ let d = xf.to_doc(p);
+ // The press's own modifiers: a ⇧ that arrives with the click still connects the line.
+ let press_mods = ui.input(|i| pointer_button_modifiers(&i.events, PointerButton::Primary)).unwrap_or(mods);
+ tool_event(app, ToolEvent::Down { x: d[0], y: d[1], pressure: app.stylus.pressure() }, press_mods);
+ app.press_stroke = app.drag.is_some();
+ }
+ let press_stroke = app.press_stroke;
+ if press_stroke {
+ buttons.started = false;
+ }
if buttons.started
&& let Some(p) = ui.input(|i| i.pointer.press_origin()).filter(|p| rect.contains(*p)).or(response.interact_pointer_pos())
{
@@ -2226,6 +2288,20 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
tool_event(app, ToolEvent::Up { x: d[0], y: d[1] }, mods);
}
}
+ // A stroke started on the press ends with the release, whether egui saw a drag, a click,
+ // or neither (a long press that never moved).
+ if press_stroke && !buttons.stopped && ui.input(|i| i.pointer.primary_released()) {
+ buttons.clicked = false;
+ let p = response.interact_pointer_pos().map(|p| xf.to_doc(p)).or_else(|| app.drag.as_ref().and_then(|d| d.points.last().map(|q| [q[0], q[1]])));
+ if let Some(d) = p
+ && app.drag.is_some()
+ {
+ tool_event(app, ToolEvent::Up { x: d[0], y: d[1] }, mods);
+ }
+ }
+ if press_stroke && (app.drag.is_none() || !ui.input(|i| i.pointer.primary_down())) {
+ app.press_stroke = false;
+ }
if buttons.clicked
&& let Some(p) = response.interact_pointer_pos()
{
@@ -2658,7 +2734,7 @@ fn draw_drag_preview(app: &mut PhotocraftApp, painter: &egui::Painter, xf: &View
}
match d.tool {
// The canvas shows the live stroke itself (`LiveStroke`).
- Tool::Brush | Tool::Pencil | Tool::Eraser => {}
+ t if strokes_live(t) => {}
t if t.is_brushlike() || t == Tool::QuickSelection => {
// Retouching strokes preview as a translucent trail of the brush footprint: a mask,
// not a brush-wide egui polyline (which zoomed in tessellates into wedges, #189).
@@ -3201,6 +3277,10 @@ pub(crate) fn finish_gesture(app: &mut PhotocraftApp, d: Drag) {
{
app.last_stroke_end = Some((st.doc.id, [end[0], end[1]]));
}
+ // A live Clone Stamp preview ends here; the commit below replaces it.
+ if d.tool == Tool::CloneStamp {
+ app.live_stroke = None;
+ }
if crate::eraser_ui::finish_stroke(app, d.tool, &d.points) || crate::retouch_ui::finish_stroke(app, d.tool, &d.points, d.modifiers) {
return;
}
@@ -3212,8 +3292,8 @@ pub(crate) fn finish_gesture(app: &mut PhotocraftApp, d: Drag) {
Tool::Brush | Tool::Pencil | Tool::Eraser => {
let live = app.live_stroke.take();
let mut p = stroke_params(app, d.tool, d.erase, &app.stylus.stroke_points(&d.points));
- if let Some(l) = &live {
- p["seed"] = json!(l.stroke.seed);
+ if let Some(seed) = live.as_ref().and_then(|l| l.stroke.seed()) {
+ p["seed"] = json!(seed);
}
// The canvas already shows the stroke: let the commit's damage rect refresh it rather
// than recompositing the whole document.
diff --git a/crates/ui-egui/src/lib.rs b/crates/ui-egui/src/lib.rs
index 2871855dc..8978f95d4 100644
--- a/crates/ui-egui/src/lib.rs
+++ b/crates/ui-egui/src/lib.rs
@@ -322,6 +322,9 @@ pub struct PhotocraftApp {
/// While a batch of recovered pointer samples is replayed, defer the live-stroke update to one
/// call for the whole frame (see `canvas::canvas_view`).
defer_live_stroke: bool,
+ /// A live painting stroke started on the press (`canvas_view`): the drag egui recognises later,
+ /// or the click, continues or ends it rather than starting another.
+ press_stroke: bool,
/// End of the last painting stroke: ⇧-click draws a straight line from it (#178).
last_stroke_end: Option<(DocId, [f64; 2])>,
/// Control+Alt-drag brush resize in progress (`brush_resize`, #231).
@@ -487,6 +490,7 @@ impl PhotocraftApp {
magnetic: Default::default(),
secondary_erase: false,
defer_live_stroke: false,
+ press_stroke: false,
last_stroke_end: None,
brush_resize: None,
quick_pick: false,
diff --git a/crates/ui-egui/src/retouch_ui.rs b/crates/ui-egui/src/retouch_ui.rs
index 7460c3f52..f0e8775b9 100644
--- a/crates/ui-egui/src/retouch_ui.rs
+++ b/crates/ui-egui/src/retouch_ui.rs
@@ -21,6 +21,24 @@ pub(crate) fn alt_flipped(tool: Tool, alt: bool) -> Tool {
}
}
+/// Clone Stamp / Healing Brush params for the options bar and the clone source (without
+/// `points` and `target`): shared by the live preview and the commit. `None` when no source
+/// point is set yet.
+pub(crate) fn clone_params(app: &PhotocraftApp) -> Option<Value> {
+ let o = &app.ui.tool_options;
+ let mut p = json!({"aligned": o.clone_aligned, "sampleLayer": o.clone_sample});
+ // The Clone Source panel's active slot (set by ⌥-click) drives the stroke: the engine keeps
+ // the aligned pairing and applies the slot's scale/rotation/flip.
+ let slot = app.session.presets.clone.active().source.is_some();
+ match (app.ui.clone_offset.filter(|_| o.clone_aligned && !slot), app.ui.clone_source.filter(|_| !slot)) {
+ _ if slot => {}
+ (Some(off), _) => p["offset"] = json!(off),
+ (None, Some(src)) => p["source"] = json!(src),
+ (None, None) => return None,
+ }
+ Some(p)
+}
+
/// Finish a stroke with a retouching tool. Returns false if `tool` isn't one.
pub fn finish_stroke(app: &mut PhotocraftApp, tool: Tool, points: &[[f64; 3]], mods: egui::Modifiers) -> bool {
let o = app.ui.tool_options.clone();
@@ -46,26 +64,17 @@ pub fn finish_stroke(app: &mut PhotocraftApp, tool: Tool, points: &[[f64; 3]], m
("paint.patternStamp", p)
}
Tool::Healing | Tool::CloneStamp => {
- let mut p = json!({"aligned": o.clone_aligned, "sampleLayer": o.clone_sample});
- // The Clone Source panel's active slot (set by ⌥-click) drives the stroke: the engine
- // keeps the aligned pairing and applies the slot's scale/rotation/flip.
- let slot = app.session.presets.clone.active().source.is_some();
- match (app.ui.clone_offset.filter(|_| o.clone_aligned && !slot), app.ui.clone_source.filter(|_| !slot)) {
- _ if slot => {}
- (Some(off), _) => p["offset"] = json!(off),
- (None, Some(src)) => p["source"] = json!(src),
- (None, None) => {
- // Photoshop says Option-click on the Mac and Alt-click on Windows.
- app.ui.status = if cfg!(target_os = "macos") {
- tl!("Option-click to define a source point to clone from")
- } else {
- tl!("Alt-click to define a source point to clone from")
- }
- .into();
- app.ui.status_error = true;
- return true;
+ let Some(p) = clone_params(app) else {
+ // Option-click on the Mac, Alt-click on Windows.
+ app.ui.status = if cfg!(target_os = "macos") {
+ tl!("Option-click to define a source point to clone from")
+ } else {
+ tl!("Alt-click to define a source point to clone from")
}
- }
+ .into();
+ app.ui.status_error = true;
+ return true;
+ };
(if tool == Tool::Healing { "paint.healingBrush" } else { "paint.cloneStamp" }, p)
}
Tool::HistoryBrush => ("paint.historyBrush", json!({})),