mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-16 07:02:42 +00:00
Refactor UI canvas for strict Clippy checks
This commit is contained in:
1 parent
ef065ee66e
commit
9366cd58ec
24 files changed
+1608
-1298
No files matched your search
+1457
-1164
File diff suppressed because it is too large.
Load diff
@@ -1,6 +1,6 @@
|
||||
use super::tool_input::ToolEvent;
|
||||
use super::view_xform::ViewXform;
|
||||
use super::*;
|
||||
use super::{Color32, PhotocraftApp, Pos2, Rect, Stroke, Tool, json, pos2, vec2};
|
||||
|
||||
/// Windows' crosshair cursor inverts the pixels under it, so over mid-grey (the pasteboard, many
|
||||
/// photos) it vanishes (#737), and the Linux themes' and macOS's differ. Use the same black-and-white
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::strokes::live_stroke;
|
||||
use super::*;
|
||||
use super::{Color32, Document, LayerContent, PhotocraftApp, TextureOptions};
|
||||
|
||||
pub(super) fn checker(app: &mut PhotocraftApp, ctx: &egui::Context) -> egui::TextureId {
|
||||
// Preferences › Transparency & Gamut colours (the texture is rebuilt when they change).
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::view_xform::ViewXform;
|
||||
use super::*;
|
||||
use super::{PhotocraftApp, Pos2, Rect, Stroke, Tool, vec2};
|
||||
|
||||
/// An in-progress pointer gesture on the canvas.
|
||||
#[derive(Clone, Debug)]
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::display::canvas_display;
|
||||
use super::textures::texture_buffer;
|
||||
use super::*;
|
||||
use super::{Document, LayerContent, PhotocraftApp};
|
||||
|
||||
/// The proxy factor of a live preview of filter `cmd` with `params` on `doc`, the active document:
|
||||
/// reduced on a large document (Preferences › Performance › Low Resolution Previews), except for
|
||||
@@ -125,7 +125,7 @@ pub(crate) fn ensure_filter_preview(app: &mut PhotocraftApp, idx: usize, ctx: &e
|
||||
let buffer = photocraft_compose::flatten(&doc);
|
||||
(std::sync::Arc::new(doc), buffer)
|
||||
});
|
||||
crate::filter_preview_worker::Computed { result, ms: crate::gpu_canvas::now_ms() - t0 }
|
||||
crate::dialogs::filter_preview_worker::Computed { result, ms: crate::gpu_canvas::now_ms() - t0 }
|
||||
}) {
|
||||
app.filter_preview = Some(crate::filter_dialog::FilterPreview { key: request.clone(), result: None, committing: false });
|
||||
crate::notices::error(app, error);
|
||||
|
||||
@@ -4,7 +4,7 @@ use super::strokes::{
|
||||
EngineStroke, commit_brush_stroke, feed_live_stroke, live_retouch_command, offer_live_retouch, paint_target, snap_aliased_tip, stroke_params,
|
||||
};
|
||||
use super::textures::shown_as_document;
|
||||
use super::*;
|
||||
use super::{PhotocraftApp, Tool, json};
|
||||
|
||||
pub(crate) fn finish_gesture(app: &mut PhotocraftApp, d: Drag) {
|
||||
// Control can select a different tool and release before the next frame cancels the drag.
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::doc_textures::mip_count;
|
||||
use super::*;
|
||||
use super::wgpu;
|
||||
|
||||
/// Floor of the compositor's memory budget: enough for a viewport's pages of a dozen layers.
|
||||
pub const MIN_GPU_BUDGET: u64 = 512 << 20;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::resources::{CanvasStyle, Resources, ViewGpu, f32_bytes};
|
||||
use super::*;
|
||||
use super::{CallbackResources, CallbackTrait, ScreenDescriptor, VIEW_FLOATS, VIEW_UNIFORM_SIZE, ViewParams, wgpu};
|
||||
|
||||
// ---------------------------------------------------------------------------------------------
|
||||
// Per-frame callback
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::budget::canvas_texture_bytes;
|
||||
use super::resources::{DocTextures, Resources, Tile, f32_bytes};
|
||||
use super::texels::texel_bytes;
|
||||
use super::*;
|
||||
use super::{Ordering, WHOLE_MIP_SIDE, wgpu};
|
||||
|
||||
pub(super) fn mip_count(w: u32, h: u32) -> u32 {
|
||||
32 - w.max(h).max(1).leading_zeros()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::budget::video_memory;
|
||||
use super::setup::Refresh;
|
||||
use super::texels::LayerFit;
|
||||
use super::*;
|
||||
use super::wgpu;
|
||||
|
||||
/// Milliseconds since the process (or page) started, from a monotonic clock.
|
||||
///
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::budget::{canvas_budget, physical_memory};
|
||||
use super::doc_textures::init_buffer;
|
||||
use super::shaders::{CANVAS_WGSL, ENCODE_WGSL, MIP_WGSL};
|
||||
use super::texels::LayerFit;
|
||||
use super::*;
|
||||
use super::{FORMAT, FORMAT_HIGH, HashMap, NonZeroU64, TILE_UNIFORM_SIZE, VIEW_FLOATS, VIEW_UNIFORM_SIZE, wgpu};
|
||||
|
||||
pub(super) struct Resources {
|
||||
pub(super) view_bgl: wgpu::BindGroupLayout,
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::texels::texels;
|
||||
use super::*;
|
||||
use super::{egui_wgpu, wgpu};
|
||||
|
||||
/// A CPU composite as the canvas texture stores it (`display`'s encoding; as is without one).
|
||||
pub(super) fn texture_buffer<'a>(
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::*;
|
||||
use super::{FORMAT, FORMAT_HIGH, wgpu};
|
||||
|
||||
/// Straight-alpha f32 RGBA (sRGB-encoded) → premultiplied RGBA8, split across threads on native.
|
||||
pub fn premultiply_rgba8(px: &[[f32; 4]]) -> Vec<u8> {
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
use super::display::{canvas_display, display_doc, display_image};
|
||||
use super::strokes::live_stroke;
|
||||
use super::textures::{effect_reach, ensure_texture};
|
||||
use super::*;
|
||||
use super::{Document, PhotocraftApp, Rect, TextureOptions};
|
||||
|
||||
/// Longest side of the Navigator panel's image (about twice the panel's width, for HiDPI).
|
||||
pub const NAVIGATOR_SIDE: u32 = 512;
|
||||
|
||||
@@ -6,7 +6,7 @@ use super::gesture::constrained_polygon_point;
|
||||
use super::strokes::{EngineStroke, SPOT_HEALING_TRAIL, draw_smoothing_string, strokes_live};
|
||||
use super::textures::texture_side;
|
||||
use super::view_xform::ViewXform;
|
||||
use super::*;
|
||||
use super::{Color32, DRect, Document, Mesh, PhotocraftApp, Pos2, Rect, Stroke, TextureOptions, Tool, json, pos2, vec2};
|
||||
|
||||
/// A texture mapped over the `size` document area starting at `origin` (follows a rotated view).
|
||||
pub(super) fn paint_mapped_image_at(painter: &egui::Painter, xf: &ViewXform, tex: egui::TextureId, uv: Rect, origin: [f32; 2], size: [f32; 2], tint: Color32) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::tool_input::selection_drag_kind;
|
||||
use super::*;
|
||||
use super::{PhotocraftApp, Tool, json};
|
||||
|
||||
/// Photoshop's cursor over a selection: what a press (or the drag under way) would do.
|
||||
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
use super::tabs::{open_on_double_click, paint_dots};
|
||||
use super::*;
|
||||
use super::{PhotocraftApp, Rect, Sense};
|
||||
|
||||
/// The Home screen's card is this wide when the canvas has room, and as wide as the canvas when it doesn't.
|
||||
const HOME_CARD_WIDTH: f32 = 460.0;
|
||||
|
||||
@@ -2,7 +2,7 @@ use super::display::{canvas_display, display_image};
|
||||
use super::drag::Drag;
|
||||
use super::textures::{canvas_texture_options, shown_as_document};
|
||||
use super::view_xform::ViewXform;
|
||||
use super::*;
|
||||
use super::{Color32, DRect, PhotocraftApp, Pos2, Stroke, Tool, json, pos2};
|
||||
|
||||
pub(crate) struct ClonePreviewCache {
|
||||
pub(super) key: String,
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::start_screen::start_screen;
|
||||
use super::textures::retain_gpu_documents;
|
||||
use super::*;
|
||||
use super::{Color32, PhotocraftApp, Pos2, Rect, Sense, Stroke, TextureOptions, canvas_view, fmt_zoom, json, mode_label, pos2};
|
||||
|
||||
/// Tabs + canvas for the active document, or the start screen; then drops layers dragged onto
|
||||
/// another document (`layer_transfer`).
|
||||
|
||||
@@ -285,7 +285,7 @@ fn every_filter_previews_off_the_ui_thread_and_a_newer_value_cancels_the_old() {
|
||||
std::thread::sleep(std::time::Duration::from_millis(1));
|
||||
}
|
||||
let _ = told.send(job.cancelled());
|
||||
crate::filter_preview_worker::Computed { result: None, ms: 0.0 }
|
||||
crate::dialogs::filter_preview_worker::Computed { result: None, ms: 0.0 }
|
||||
})
|
||||
.unwrap();
|
||||
// The slider moves on and stops: once the value settles, the stale preview is cancelled
|
||||
@@ -352,7 +352,7 @@ fn gated_blur_preview(app: &mut PhotocraftApp, ctx: &egui::Context) -> (std::syn
|
||||
let buffer = photocraft_compose::flatten(&d);
|
||||
(std::sync::Arc::new(d), buffer)
|
||||
});
|
||||
crate::filter_preview_worker::Computed { result, ms: 0.0 }
|
||||
crate::dialogs::filter_preview_worker::Computed { result, ms: 0.0 }
|
||||
})
|
||||
.expect("the worker starts");
|
||||
(release, radius)
|
||||
@@ -482,7 +482,7 @@ fn a_mid_drag_empty_result_leaves_the_preview_alone() {
|
||||
app.filter_preview_worker
|
||||
.start(key, ctx.clone(), move |_| {
|
||||
wait.recv_timeout(std::time::Duration::from_secs(60)).expect("released");
|
||||
crate::filter_preview_worker::Computed { result: None, ms: 0.0 }
|
||||
crate::dialogs::filter_preview_worker::Computed { result: None, ms: 0.0 }
|
||||
})
|
||||
.expect("the worker starts");
|
||||
app.ui.dialogs[0].fields.insert("radius".into(), json!(moved + 4.0));
|
||||
|
||||
@@ -3,7 +3,7 @@ use super::filter_preview::filter_channel_preview;
|
||||
use super::navigator::navigator_waits_for_drag;
|
||||
use super::strokes::live_stroke;
|
||||
use super::view_xform::ViewXform;
|
||||
use super::*;
|
||||
use super::{CanvasCache, CpuTextures, DRect, DetailTexture, Document, InView, LayerContent, PhotocraftApp, TextureOptions, pos2};
|
||||
|
||||
/// Largest texture side we upload; bigger documents are uploaded downsampled, with the part in
|
||||
/// view added at the screen's resolution when zoomed in (`detail_plan`).
|
||||
|
||||
@@ -3,7 +3,7 @@ use super::drag::Drag;
|
||||
use super::gesture::{finish_gesture, polygon_click, selection_mode};
|
||||
use super::selection::finish_selection_drag;
|
||||
use super::strokes::{HOLD_REPEAT_MS, begin_live_stroke, feed_live_stroke, paint_target, snap_aliased_tip, stroke_params, strokes_live};
|
||||
use super::*;
|
||||
use super::{PhotocraftApp, Tool, json};
|
||||
|
||||
/// Abstract tool event, produced by the mouse or by automation (`ui.pointer`).
|
||||
#[derive(Clone, Copy, Debug, PartialEq)]
|
||||
@@ -52,8 +52,7 @@ fn tool_move(app: &mut PhotocraftApp, x: f64, y: f64, pressure: f32, mods: egui:
|
||||
}
|
||||
}
|
||||
|
||||
/// Tool state machine. Shared by mouse input and automation.
|
||||
pub fn tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers) {
|
||||
fn preflight_tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers) -> Option<(bool, egui::Modifiers)> {
|
||||
// A press anywhere but on a guide deselects the selected guide (`guide_select`).
|
||||
if let ToolEvent::Down { x, y, .. } = ev
|
||||
&& app.ui.selected_guide.is_some()
|
||||
@@ -62,7 +61,7 @@ pub fn tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers)
|
||||
crate::guide_select::clear(app);
|
||||
}
|
||||
if crate::symmetry_ui::pointer(app, ev, crate::workspace_ui::sticky_mods(app, mods)) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// An Alt+right-drag armed for this press (`paint_mouse`): taken before anything else can
|
||||
// consume the event, so it never outlives the press it was armed for (#297).
|
||||
@@ -70,11 +69,11 @@ pub fn tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers)
|
||||
crate::transform_tool::end_if_left(app);
|
||||
let mods = crate::workspace_ui::sticky_mods(app, mods);
|
||||
if app.ui.transform.is_none() && crate::type_transform::pointer(app, ev, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// Content-Aware Move's Transform On Drop box takes every press until ↩ or Esc.
|
||||
if crate::cam_transform::pointer(app, ev, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// A Mixer Brush press that loaded paint stays a sample press until it is released, with ⌥
|
||||
// let go or not (`mixer_sampling`; `canvas_view` holds back egui's later drag start too).
|
||||
@@ -82,9 +81,9 @@ pub fn tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers)
|
||||
ToolEvent::Down { .. } => app.mixer_sampling = false,
|
||||
ToolEvent::Up { .. } if app.mixer_sampling => {
|
||||
app.mixer_sampling = false;
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
_ if app.mixer_sampling => return,
|
||||
_ if app.mixer_sampling => return None,
|
||||
_ => {}
|
||||
}
|
||||
// The tool in use, so a held temporary tool (⌘ = Move) with ⌥ doesn't load paint.
|
||||
@@ -98,13 +97,17 @@ pub fn tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers)
|
||||
app.ui.status_error = true;
|
||||
}
|
||||
}
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
Some((armed, mods))
|
||||
}
|
||||
|
||||
fn filter_event_before_tool(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers, armed: bool) -> Option<(ToolEvent, ToolEvent, egui::Modifiers)> {
|
||||
// View › Snap / Snap To and smart guides (snap_ui.rs).
|
||||
let raw = ev;
|
||||
// The Move tool's marquee selecting layers takes its moves and release unsnapped (move_box.rs).
|
||||
if crate::move_box::pointer(app, raw) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// A press anywhere but on the floating piece (or with ⇧ / ⌥, to draw) drops it first; the
|
||||
// Move tool (⌘ with a painting tool too, `event_tool`) drags it from anywhere.
|
||||
@@ -120,29 +123,29 @@ pub fn tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers)
|
||||
// can land outside the corner's grab area and turn a corner drag into a move of the whole box.
|
||||
let transform_ev = if matches!(raw, ToolEvent::Down { .. }) { raw } else { ev };
|
||||
if crate::transform_tool::pointer(app, transform_ev, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
if crate::distort_ui::pointer(app, ev, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
if crate::perspective_crop_ui::pointer(app, ev) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// Window › Modifier Keys: sticky Shift/⌘/⌥ act as held keys.
|
||||
let mods = crate::workspace_ui::sticky_mods(app, mods);
|
||||
// ⌘⌥⌃-click with any tool selects the topmost layer with pixels there (quick_pick.rs); it
|
||||
// must run before the ⌃⌥ brush resize below, which the same keys would trigger.
|
||||
if crate::quick_pick::pointer(app, ev, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// Control+Alt-drag or Alt+right-drag with a painting tool resizes the brush instead of
|
||||
// painting (#231, #297).
|
||||
if crate::brush_resize::pointer(app, ev, mods, armed) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// ⌥ (Alt) with a painting tool is the Eyedropper for that press.
|
||||
if alt_eyedropper(app, ev, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// Move tool: ⇧ locks the axis, ⌥ duplicates (move_mods.rs).
|
||||
let ev = crate::move_mods::filter_event(app, ev, mods);
|
||||
@@ -150,39 +153,39 @@ pub fn tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers)
|
||||
// transform controls). Unsnapped, as Free Transform's handles: snapping would pull the press
|
||||
// off a widget onto a nearby vertex or guide, and the shape tool would draw a new shape.
|
||||
if crate::corner_radius::pointer(app, raw, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// Direct Selection, and the Pen's ⌘ (Direct Selection) and ⌥ (Convert Point) modes (#790).
|
||||
if crate::direct_select::pointer(app, ev, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// Add / Delete Anchor Point tools (#1044).
|
||||
if crate::anchor_tools::pointer(app, ev, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// Ruler, Count and Note tools.
|
||||
if crate::analysis_ui::pointer(app, ev, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// Slice and Slice Select tools.
|
||||
if crate::slice_ui::pointer(app, ev, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// Frame tool: draw rectangular and elliptical frames.
|
||||
if crate::frame_tool::pointer(app, ev, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// Artboard tool: draw, select, move and resize boards.
|
||||
if crate::artboard_tool::pointer(app, ev, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// Crop tool: draw, move and resize the frame.
|
||||
if crate::crop_ui::pointer(app, ev, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// Gradient tool, live mode: draw and edit Gradient Fill layers.
|
||||
if crate::gradient_ui::pointer(app, ev, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// ⌘ over a guide takes the guide (#2690, #6288); the guide drag below moves it.
|
||||
if let ToolEvent::Down { x, y, .. } = raw
|
||||
@@ -190,15 +193,107 @@ pub fn tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers)
|
||||
{
|
||||
app.guide_drag = Some(crate::rulers::GuideDrag::existing(vertical, i, [x, y]));
|
||||
crate::snap_ui::begin_guide(app, [x, y]);
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
if crate::lasso_ui::pointer(app, ev, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
// Magnetic Lasso: fastening points and the border following the pointer.
|
||||
if crate::magnetic_lasso_ui::pointer(app, ev, mods) {
|
||||
return;
|
||||
return None;
|
||||
}
|
||||
Some((raw, ev, mods))
|
||||
}
|
||||
|
||||
fn handle_move_pointer(app: &mut PhotocraftApp, ev: ToolEvent, tool: Tool, mods: egui::Modifiers) -> bool {
|
||||
match ev {
|
||||
ToolEvent::Down { x, y, pressure } if tool == Tool::Move => {
|
||||
if let Some((vertical, i)) = crate::rulers::guide_at(app, x, y) {
|
||||
// ⌥-click turns the guide, through the point clicked, as in Photoshop.
|
||||
if mods.alt && !mods.shift && !mods.command {
|
||||
crate::guide_select::flip(app, vertical, i, [x, y]);
|
||||
return true;
|
||||
}
|
||||
app.guide_drag = Some(crate::rulers::GuideDrag::existing(vertical, i, [x, y]));
|
||||
return true;
|
||||
}
|
||||
// Auto-Select (or ⌘-click while it is off) picks the layer under the pointer first
|
||||
// (not when the selected pixels move: those are the active layer's).
|
||||
if !crate::move_ui::moves_selected_pixels_with(app, tool) && app.ui.tool_options.move_auto_select != mods.command {
|
||||
let target = app.ui.tool_options.move_target.clone();
|
||||
let mode = if mods.shift { "add" } else { "replace" };
|
||||
let before = app.session.active().map(|st| st.selected_layers());
|
||||
// A locked layer under the pointer (the Background) can't move. Photoshop draws
|
||||
// the layer marquee instead of reporting the lock (#4058). Probe without
|
||||
// selecting so a locked hit doesn't become the selection first.
|
||||
let probe = app.run("layer.pickAt", json!({"x": x, "y": y, "target": target, "select": false}));
|
||||
let locked_hit = probe.as_ref().ok().and_then(|v| v["layer"].as_u64()).is_some_and(|id| {
|
||||
app.session.active().is_some_and(|st| {
|
||||
let id = photocraft_doc::LayerId(id);
|
||||
let locks = st.doc.effective_locks(id);
|
||||
locks.position || locks.all || st.doc.is_background(id)
|
||||
})
|
||||
});
|
||||
if locked_hit || (probe.as_ref().is_ok_and(|v| v["layer"].is_null()) && crate::move_box::empty_at(app, [x, y])) {
|
||||
if locked_hit {
|
||||
// A click still selects the locked layer, as in Photoshop; a drag's
|
||||
// marquee then replaces that selection on release.
|
||||
let _ = app.run("layer.pickAt", json!({"x": x, "y": y, "target": target, "mode": mode}));
|
||||
}
|
||||
crate::move_box::begin(app, [x, y], mods.shift);
|
||||
return true;
|
||||
}
|
||||
let picked = app.run("layer.pickAt", json!({"x": x, "y": y, "target": target, "mode": mode}));
|
||||
// No pixels there at all (an empty spot, or off the canvas): drag a marquee that
|
||||
// selects the layers it touches instead (move_box.rs).
|
||||
if picked.is_ok_and(|v| v["layer"].is_null()) && crate::move_box::empty_at(app, [x, y]) {
|
||||
crate::move_box::begin(app, [x, y], mods.shift);
|
||||
return true;
|
||||
}
|
||||
// Snapping (and the drag's box) started before the pick: point it at what moves.
|
||||
if app.session.active().map(|st| st.selected_layers()) != before {
|
||||
crate::snap_ui::retarget_move(app, [x, y], mods);
|
||||
}
|
||||
}
|
||||
// A locked layer: no drag, and Photoshop's message once the pointer moves (`move_lock`).
|
||||
if crate::move_lock::blocked(app, tool, [x, y], mods) {
|
||||
app.move_blocked = true;
|
||||
return true;
|
||||
}
|
||||
// With a selection: cut the selected pixels (⌥ copies them) and drag them as a floating
|
||||
// piece, from anywhere, as a marquee ⌘-drag does.
|
||||
if crate::move_ui::moves_selected_pixels_with(app, tool) {
|
||||
if crate::move_ui::float_selected(app, mods.alt, 0.0, 0.0) {
|
||||
let mut d = Drag::new(tool, [x, y], vec![[x, y, pressure as f64]], mods, false);
|
||||
d.sel_move = Some(true);
|
||||
app.drag = Some(d);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
ToolEvent::Move { x, y, .. } => {
|
||||
if let Some(d) = app.guide_drag.as_mut().filter(|d| d.index.is_some()) {
|
||||
d.pos = if d.vertical { x } else { y };
|
||||
return true;
|
||||
}
|
||||
}
|
||||
ToolEvent::Up { x, y } => {
|
||||
if let Some(mut d) = app.guide_drag.filter(|d| d.index.is_some()) {
|
||||
app.guide_drag = None;
|
||||
d.pos = if d.vertical { x } else { y };
|
||||
crate::rulers::finish_drag(app, d);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
false
|
||||
}
|
||||
|
||||
/// Tool state machine. Shared by mouse input and automation.
|
||||
pub fn tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers) {
|
||||
let Some((armed, mods)) = preflight_tool_event(app, ev, mods) else { return };
|
||||
let Some((raw, ev, mods)) = filter_event_before_tool(app, ev, mods, armed) else { return };
|
||||
let tool = event_tool(app, mods);
|
||||
if tool == Tool::Eyedropper {
|
||||
match ev {
|
||||
@@ -228,88 +323,10 @@ pub fn tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers)
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
// Move tool over a guide drags the guide (off the canvas deletes it).
|
||||
match ev {
|
||||
ToolEvent::Down { x, y, pressure } if tool == Tool::Move => {
|
||||
if let Some((vertical, i)) = crate::rulers::guide_at(app, x, y) {
|
||||
// ⌥-click turns the guide, through the point clicked, as in Photoshop.
|
||||
if mods.alt && !mods.shift && !mods.command {
|
||||
crate::guide_select::flip(app, vertical, i, [x, y]);
|
||||
return;
|
||||
}
|
||||
app.guide_drag = Some(crate::rulers::GuideDrag::existing(vertical, i, [x, y]));
|
||||
return;
|
||||
}
|
||||
// Auto-Select (or ⌘-click while it is off) picks the layer under the pointer first
|
||||
// (not when the selected pixels move: those are the active layer's).
|
||||
if !crate::move_ui::moves_selected_pixels_with(app, tool) && app.ui.tool_options.move_auto_select != mods.command {
|
||||
let target = app.ui.tool_options.move_target.clone();
|
||||
let mode = if mods.shift { "add" } else { "replace" };
|
||||
let before = app.session.active().map(|st| st.selected_layers());
|
||||
// A locked layer under the pointer (the Background) can't move. Photoshop draws
|
||||
// the layer marquee instead of reporting the lock (#4058). Probe without
|
||||
// selecting so a locked hit doesn't become the selection first.
|
||||
let probe = app.run("layer.pickAt", json!({"x": x, "y": y, "target": target, "select": false}));
|
||||
let locked_hit = probe.as_ref().ok().and_then(|v| v["layer"].as_u64()).is_some_and(|id| {
|
||||
app.session.active().is_some_and(|st| {
|
||||
let id = photocraft_doc::LayerId(id);
|
||||
let locks = st.doc.effective_locks(id);
|
||||
locks.position || locks.all || st.doc.is_background(id)
|
||||
})
|
||||
});
|
||||
if locked_hit || (probe.as_ref().is_ok_and(|v| v["layer"].is_null()) && crate::move_box::empty_at(app, [x, y])) {
|
||||
if locked_hit {
|
||||
// A click still selects the locked layer, as in Photoshop; a drag's
|
||||
// marquee then replaces that selection on release.
|
||||
let _ = app.run("layer.pickAt", json!({"x": x, "y": y, "target": target, "mode": mode}));
|
||||
}
|
||||
crate::move_box::begin(app, [x, y], mods.shift);
|
||||
return;
|
||||
}
|
||||
let picked = app.run("layer.pickAt", json!({"x": x, "y": y, "target": target, "mode": mode}));
|
||||
// No pixels there at all (an empty spot, or off the canvas): drag a marquee that
|
||||
// selects the layers it touches instead (move_box.rs).
|
||||
if picked.is_ok_and(|v| v["layer"].is_null()) && crate::move_box::empty_at(app, [x, y]) {
|
||||
crate::move_box::begin(app, [x, y], mods.shift);
|
||||
return;
|
||||
}
|
||||
// Snapping (and the drag's box) started before the pick: point it at what moves.
|
||||
if app.session.active().map(|st| st.selected_layers()) != before {
|
||||
crate::snap_ui::retarget_move(app, [x, y], mods);
|
||||
}
|
||||
}
|
||||
// A locked layer: no drag, and Photoshop's message once the pointer moves (`move_lock`).
|
||||
if crate::move_lock::blocked(app, tool, [x, y], mods) {
|
||||
app.move_blocked = true;
|
||||
return;
|
||||
}
|
||||
// With a selection: cut the selected pixels (⌥ copies them) and drag them as a floating
|
||||
// piece, from anywhere, as a marquee ⌘-drag does.
|
||||
if crate::move_ui::moves_selected_pixels_with(app, tool) {
|
||||
if crate::move_ui::float_selected(app, mods.alt, 0.0, 0.0) {
|
||||
let mut d = Drag::new(tool, [x, y], vec![[x, y, pressure as f64]], mods, false);
|
||||
d.sel_move = Some(true);
|
||||
app.drag = Some(d);
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
ToolEvent::Move { x, y, .. } => {
|
||||
if let Some(d) = app.guide_drag.as_mut().filter(|d| d.index.is_some()) {
|
||||
d.pos = if d.vertical { x } else { y };
|
||||
return;
|
||||
}
|
||||
}
|
||||
ToolEvent::Up { x, y } => {
|
||||
if let Some(mut d) = app.guide_drag.filter(|d| d.index.is_some()) {
|
||||
app.guide_drag = None;
|
||||
d.pos = if d.vertical { x } else { y };
|
||||
crate::rulers::finish_drag(app, d);
|
||||
return;
|
||||
}
|
||||
}
|
||||
_ => {}
|
||||
if handle_move_pointer(app, ev, tool, mods) {
|
||||
return;
|
||||
}
|
||||
|
||||
match ev {
|
||||
ToolEvent::Down { x, y, pressure } => {
|
||||
// Painting a type, shape, Smart Object or fill layer asks to rasterize it first
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
use super::selection::floating_outline;
|
||||
use super::view_xform::ViewXform;
|
||||
use super::*;
|
||||
use super::{Color32, LayerContent, PhotocraftApp, Pos2, Rect, Stroke, Tool, Vec2, pos2, vec2};
|
||||
|
||||
/// View › Show › Layer Edges: the colour of the active layer's outline.
|
||||
pub(crate) const LAYER_EDGES: Color32 = Color32::from_rgb(0x2d, 0x8c, 0xeb);
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
use super::*;
|
||||
use super::{DRect, Document, PhotocraftApp, Pos2, Rect, Vec2, View, pos2, vec2};
|
||||
|
||||
/// Document ↔ screen mapping for a canvas rect and a view.
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
|
||||
Reference in new issue
Block a user