diff --git a/crates/imaging/src/ui/live_preview/key.rs b/crates/imaging/src/ui/live_preview/key.rs index 4179f72d4..31e48f582 100644 --- a/crates/imaging/src/ui/live_preview/key.rs +++ b/crates/imaging/src/ui/live_preview/key.rs @@ -21,6 +21,9 @@ pub enum PreviewLane { Dialog, /// A Properties-panel drag on an adjustment layer: tag `1 << 58`, session 18 bits (40..58). Properties, + /// A canvas tool's preview while dragged or held (Content-Aware Move, Patch): tag `1 << 57`, session 17 bits + /// (40..57). + Tool, } impl PreviewLane { @@ -32,6 +35,7 @@ impl PreviewLane { match self { PreviewLane::Dialog => (59, 19), PreviewLane::Properties => (58, 18), + PreviewLane::Tool => (57, 17), } } } @@ -47,6 +51,13 @@ impl PreviewLane { pub struct PreviewKey(u64); impl PreviewKey { + /// The display key of progressive stage `n` (1..=7) of a result of the same settings: bit 0 cleared and `n` in bits + /// 1..=3, so it never equals a settings key. + #[must_use] + pub fn stage(self, n: u8) -> PreviewKey { + PreviewKey((self.0 & !0xF) | (u64::from(n & 7) << 1)) + } + /// The bits from 40 up: the lane's tag and the session's low bits. Equal for the keys of one /// session and lane. pub(super) const SESSION_SHIFT: u32 = 40; diff --git a/crates/imaging/src/ui/scopes/panel/frame.rs b/crates/imaging/src/ui/scopes/panel/frame.rs index 72377dfca..7598fb32f 100644 --- a/crates/imaging/src/ui/scopes/panel/frame.rs +++ b/crates/imaging/src/ui/scopes/panel/frame.rs @@ -51,6 +51,7 @@ pub struct HistogramSet<'a> { pub(crate) colors: Option, pub(crate) stale: bool, pub(crate) cache_level: u32, + pub(crate) pixels: Option, } impl<'a> ScopeChannel<'a> { @@ -73,7 +74,14 @@ impl<'a> HistogramSet<'a> { /// Luminosity; Lightness, a, b, Luminosity; Gray). // pc: crates/ui-egui/src/panels/histogram_panel.rs:123 `channel_options`. pub fn new(channels: &'a [ScopeChannel<'a>]) -> Self { - Self { channels, original: None, colors: None, stale: false, cache_level: 1 } + Self { channels, original: None, colors: None, stale: false, cache_level: 1, pixels: None } + } + + /// The Pixels row shows the host's `total` (transparent pixels included); the other statistics stay on the bins. + #[must_use] + pub fn pixels(mut self, total: u64) -> Self { + self.pixels = Some(total); + self } /// The histograms before the adjustment that previews now: each channel's original is outlined diff --git a/crates/imaging/src/ui/select/drag.rs b/crates/imaging/src/ui/select/drag.rs index b3b7a2c56..13e36ed3b 100644 --- a/crates/imaging/src/ui/select/drag.rs +++ b/crates/imaging/src/ui/select/drag.rs @@ -99,7 +99,16 @@ pub struct InsideDrag { impl InsideDrag { /// Starts a `kind` drag named `id` at `at` (document units): the gesture and the `Begin` event, which names the /// undo step `label`. - pub fn begin(style: &ConstrainStyle, kind: DragKind, at: Point, mods: Mods, id: GestureId, label: Arc) -> (InsideDrag, SelectEvent) { + pub fn begin( + style: &ConstrainStyle, + kind: DragKind, + at: Point, + mods: Mods, + id: GestureId, + label: Arc, + bounds: Option, + ) -> (InsideDrag, SelectEvent) { + let _ = bounds; // P3(canvas-widgets-w10): cw.C20 let gesture = MoveGesture::press(style, at, mods, Directions::Eight); let event = SelectEvent::DragSelection(EditEvent::begin(id, Mixed::Same(SelectionDrag { kind, delta: [0, 0] }), label, None)); (InsideDrag { kind, id, gesture, last: [0, 0] }, event) @@ -113,7 +122,8 @@ impl InsideDrag { /// The pointer moved to `at` at `zoom` screen points per document unit: an `Update` when the whole-pixel delta /// changed. The delta is the gesture's offset rounded per axis and clamped to 10^7; the gesture's own Alt copy is /// ignored (the copy is latched in `kind`). - pub fn drag(&mut self, at: Point, mods: Mods, zoom: f64) -> Option { + pub fn drag(&mut self, at: Point, mods: Mods, zoom: f64, snap: &mut dyn FnMut(kurbo::Rect) -> Vec2) -> Option { + let _ = snap; // P3(canvas-widgets-w10): cw.C20 let delta = whole_pixels(self.gesture.follow(at, mods, zoom)?.delta); if delta == self.last { return None; @@ -123,7 +133,8 @@ impl InsideDrag { } /// The release: the `Commit`. A delta of 0 means nothing moved. - pub fn end(self, at: Point, mods: Mods, zoom: f64) -> SelectEvent { + pub fn end(self, at: Point, mods: Mods, zoom: f64, snap: &mut dyn FnMut(kurbo::Rect) -> Vec2) -> SelectEvent { + let _ = snap; // P3(canvas-widgets-w10): cw.C20 let after = SelectionDrag { kind: self.kind, delta: whole_pixels(self.gesture.release(at, mods, zoom).delta) }; let before = SelectionDrag { kind: self.kind, delta: [0, 0] }; SelectEvent::DragSelection(EditEvent::commit(self.id, Mixed::Same(before), after)) diff --git a/crates/imaging/src/ui/select/lasso.rs b/crates/imaging/src/ui/select/lasso.rs index f272ab06c..16f5fda33 100644 --- a/crates/imaging/src/ui/select/lasso.rs +++ b/crates/imaging/src/ui/select/lasso.rs @@ -75,7 +75,7 @@ pub(super) fn cursor(shown: &LassoCursor<'_>, probe: &dyn SelectionProbe, cx: &T } /// The outline as marching ants and, between straight segments, the rubber band. -pub(super) fn paint_outline(draft: &OutlineDraft, draw: &Draw<'_>, cx: &ToolContext<'_>) { +pub fn paint_outline(draft: &OutlineDraft, draw: &Draw<'_>, cx: &ToolContext<'_>) { let Some(place) = Place::of(cx) else { return }; let points: Vec = draft.points().iter().map(|&at| place.screen(at)).collect(); if points.len() >= 2 { @@ -112,7 +112,7 @@ pub(super) fn begin_inside( let id = report.gesture(); let label = cx.words::().move_selection.as_str().into(); let style = ConstrainStyle::new(f64::from(cx.slop), f64::from(cx.slop)); - let (drag, event) = InsideDrag::begin(&style, kind, place.doc(pointer.pos), pointer.mods, id, label); + let (drag, event) = InsideDrag::begin(&style, kind, place.doc(pointer.pos), pointer.mods, id, label, None); *inside = Some(drag); report.push(event); } @@ -311,7 +311,7 @@ impl CanvasTool for SelectToolPass<'_, LassoTool> { let (tool, probe) = (&mut *self.tool, self.probe); let Some(place) = Place::of(cx) else { return }; if let Some(inside) = tool.inside.as_mut() { - if let Some(event) = inside.drag(place.doc(pointer.pos), pointer.mods, place.zoom()) { + if let Some(event) = inside.drag(place.doc(pointer.pos), pointer.mods, place.zoom(), &mut |_| kurbo::Vec2::ZERO) { tool.report.push(event); } return; @@ -326,7 +326,7 @@ impl CanvasTool for SelectToolPass<'_, LassoTool> { let (tool, probe) = (&mut *self.tool, self.probe); let Some(place) = Place::of(cx) else { return }; if let Some(inside) = tool.inside.take() { - tool.report.push(inside.end(place.doc(pointer.pos), pointer.mods, place.zoom())); + tool.report.push(inside.end(place.doc(pointer.pos), pointer.mods, place.zoom(), &mut |_| kurbo::Vec2::ZERO)); return; } let event = tool.draft.release(sample(pointer, &place)); diff --git a/crates/imaging/src/ui/select/marquee.rs b/crates/imaging/src/ui/select/marquee.rs index 66de2ba3d..d9385c1a5 100644 --- a/crates/imaging/src/ui/select/marquee.rs +++ b/crates/imaging/src/ui/select/marquee.rs @@ -255,7 +255,7 @@ impl CanvasTool for SelectToolPass<'_, MarqueeTool> { { let id = tool.report.gesture(); let label = cx.words::().move_selection.as_str().into(); - let (drag, event) = InsideDrag::begin(&ConstrainStyle::new(f64::from(cx.slop), f64::from(cx.slop)), kind, at, pointer.mods, id, label); + let (drag, event) = InsideDrag::begin(&ConstrainStyle::new(f64::from(cx.slop), f64::from(cx.slop)), kind, at, pointer.mods, id, label, None); tool.inside = Some(drag); tool.report.push(event); return ToolAction::Claimed; @@ -287,7 +287,7 @@ impl CanvasTool for SelectToolPass<'_, MarqueeTool> { let tool = &mut *self.tool; let Some(place) = Place::of(cx) else { return }; if let Some(inside) = tool.inside.as_mut() { - if let Some(event) = inside.drag(cx.snap(place.doc(pointer.pos)), pointer.mods, place.zoom()) { + if let Some(event) = inside.drag(cx.snap(place.doc(pointer.pos)), pointer.mods, place.zoom(), &mut |_| kurbo::Vec2::ZERO) { tool.report.push(event); } return; @@ -307,7 +307,7 @@ impl CanvasTool for SelectToolPass<'_, MarqueeTool> { let Some(place) = Place::of(cx) else { return }; let at = cx.snap(place.doc(pointer.pos)); if let Some(inside) = tool.inside.take() { - tool.report.push(inside.end(at, pointer.mods, place.zoom())); + tool.report.push(inside.end(at, pointer.mods, place.zoom(), &mut |_| kurbo::Vec2::ZERO)); return; } tool.follow(pointer, at, cx.held(Key::Space)); diff --git a/crates/imaging/src/ui/select/mod.rs b/crates/imaging/src/ui/select/mod.rs index 4a0b0d541..4336a5e97 100644 --- a/crates/imaging/src/ui/select/mod.rs +++ b/crates/imaging/src/ui/select/mod.rs @@ -52,8 +52,9 @@ mod polygon; #[cfg(feature = "screen-testing")] pub(crate) mod stories; +pub mod operations; pub use drag::{InsideDrag, PressRule, cursor_over, drag_kind}; -pub use lasso::LassoTool; +pub use lasso::{LassoTool, paint_outline}; pub use magnetic::{EdgeSearch, EdgeTracer, MagneticLassoTool, MagneticSettings}; pub use marquee::{MarqueeKind, MarqueeTool}; pub use polygon::PolygonLassoTool; @@ -210,6 +211,12 @@ pub trait SelectionProbe { /// Whether document point `at` is inside the selection (coverage above 0). fn inside_selection(&self, at: Point) -> bool; + /// The selection's content bounds in document units, for snapping a dragged selection's box; the default leaves a + /// drag unsnapped. + fn bounds(&self) -> Option { + None + } + /// Whether a floating piece (pixels lifted by a selection drag, not yet dropped) is on the canvas. Default: none. fn floating(&self) -> bool { false diff --git a/crates/imaging/src/ui/select/operations.rs b/crates/imaging/src/ui/select/operations.rs new file mode 100644 index 000000000..5f8697f3c --- /dev/null +++ b/crates/imaging/src/ui/select/operations.rs @@ -0,0 +1,20 @@ +//! The four selection operations as entries for a `Segmented`: New, Add, Subtract and Intersect. + +use craft_behavior::geometry::selection_op::SelectionOperation; +use craft_ui::contract::Entry; + +craft_ui::words! { + /// The selection operations' words, English by default (Photoshop's names). + pub struct SelectionOpWords { + new_selection: "selectionOp.newSelection" = "New selection"; + add_to_selection: "selectionOp.addToSelection" = "Add to selection"; + subtract_from_selection: "selectionOp.subtractFromSelection" = "Subtract from selection"; + intersect_with_selection: "selectionOp.intersectWithSelection" = "Intersect with selection"; + } +} + +/// The four entries (icons `square`, `plus`, `minus`, `squares_subtract`) for a `Segmented`. +pub fn selection_operations(words: &SelectionOpWords) -> [Entry; 4] { + let _ = words; + todo!("pn.C19") +} diff --git a/crates/imaging/src/ui/select/polygon.rs b/crates/imaging/src/ui/select/polygon.rs index 2a702cca1..babb1f4ba 100644 --- a/crates/imaging/src/ui/select/polygon.rs +++ b/crates/imaging/src/ui/select/polygon.rs @@ -161,7 +161,7 @@ impl CanvasTool for SelectToolPass<'_, PolygonLassoTool> { let (tool, probe) = (&mut *self.tool, self.probe); let Some(place) = Place::of(cx) else { return }; if let Some(inside) = tool.inside.as_mut() { - if let Some(event) = inside.drag(place.doc(pointer.pos), pointer.mods, place.zoom()) { + if let Some(event) = inside.drag(place.doc(pointer.pos), pointer.mods, place.zoom(), &mut |_| kurbo::Vec2::ZERO) { tool.report.push(event); } return; @@ -175,7 +175,7 @@ impl CanvasTool for SelectToolPass<'_, PolygonLassoTool> { let (tool, probe) = (&mut *self.tool, self.probe); let Some(place) = Place::of(cx) else { return }; if let Some(inside) = tool.inside.take() { - tool.report.push(inside.end(place.doc(pointer.pos), pointer.mods, place.zoom())); + tool.report.push(inside.end(place.doc(pointer.pos), pointer.mods, place.zoom(), &mut |_| kurbo::Vec2::ZERO)); return; } let event = tool.draft.release(sample(pointer, &place));