mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-03 06:31:42 +01:00
commit
548eeafcee
3 files changed
+66
-8
No files matched your search
@@ -4011,7 +4011,11 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
|
||||
}
|
||||
let xf = if crop_camera { ViewXform { center: view.center, rotation: view.rotation, ..xf } } else { xf };
|
||||
let (img_rect, beyond, layer_edges) = painted.unwrap_or_else(|| paint_canvas(app, ui, &view, xf));
|
||||
if primary && !(hand_pan && response.dragged()) {
|
||||
// A Hand drag (the tool, Space or the middle button) keeps every overlay on screen, as in
|
||||
// Photoshop: the Pen path being drawn, paths, guides, grid, transform box (#6592). Only the
|
||||
// tool cursors below give way to the fist.
|
||||
let panning = hand_pan && response.dragged();
|
||||
if primary {
|
||||
// The transform preview is image content: it goes under the grid and guides, which
|
||||
// stay visible across a layer being transformed (#5086); the box is drawn later.
|
||||
crate::transform_tool::draw_content(app, &painter, &xf);
|
||||
@@ -4075,7 +4079,9 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
|
||||
}
|
||||
command_guide_at(app, tool, d, crate::workspace_ui::sticky_mods(app, ui.input(|i| i.modifiers)))
|
||||
});
|
||||
if let Some((vertical, _)) = guide_hover {
|
||||
if panning {
|
||||
// The fist set with the pan above stays (#2196).
|
||||
} else if let Some((vertical, _)) = guide_hover {
|
||||
ui.ctx().set_cursor_icon(crate::rulers::guide_cursor(&xf, vertical));
|
||||
} else if let Some(p) = response.hover_pos()
|
||||
&& let Some(c) = crate::transform_tool::cursor(app, &xf, xf.to_doc(p), ui.input(|i| i.modifiers.alt || i.modifiers.command))
|
||||
@@ -4310,12 +4316,6 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
|
||||
crate::stroke_constraint::draw_line_preview(app, &painter, &xf, p, tool, held.shift);
|
||||
}
|
||||
}
|
||||
if primary && hand_pan && response.dragged() {
|
||||
crate::transform_tool::draw_content(app, &painter, &xf);
|
||||
crate::transform_tool::draw_overlay(app, &painter, &xf);
|
||||
// The Pen's path in progress survives a Space pan, and stays on screen through it (#6592).
|
||||
crate::vector_ui::draw_overlay(app, &painter, &xf, &doc);
|
||||
}
|
||||
app.tool_override = None;
|
||||
if let Some(b) = layer_edges_rect(app, idx) {
|
||||
painter.set(layer_edges, egui::Shape::rect_stroke(xf.doc_rect(b), 0, Stroke::new(1.0, LAYER_EDGES), egui::StrokeKind::Outside));
|
||||
|
||||
@@ -180,6 +180,58 @@ fn space_is_a_temporary_hand_and_gives_the_tool_back() {
|
||||
assert!(!st.session.active().unwrap().history.can_undo(), "nothing was painted");
|
||||
}
|
||||
|
||||
/// The open paths the last frame painted, as their screen points.
|
||||
fn painted_paths(h: &Harness<'static, PhotocraftApp>) -> Vec<Vec<Pos2>> {
|
||||
fn walk(s: &egui::Shape, out: &mut Vec<Vec<Pos2>>) {
|
||||
match s {
|
||||
egui::Shape::Path(p) if !p.closed => out.push(p.points.clone()),
|
||||
egui::Shape::Vec(v) => v.iter().for_each(|s| walk(s, out)),
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let mut out = Vec::new();
|
||||
for c in &h.output().shapes {
|
||||
walk(&c.shape, &mut out);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn the_pen_path_being_drawn_stays_visible_while_space_pans() {
|
||||
// #6592: the path vanished for as long as the Hand dragged.
|
||||
let mut h = harness(Tool::Pen);
|
||||
click(&mut h, 100.0, 100.0, Modifiers::NONE);
|
||||
click(&mut h, 200.0, 100.0, Modifiers::NONE);
|
||||
assert_eq!(h.state().ui.pen.as_ref().map(|p| p.knots.len()), Some(2));
|
||||
key(&mut h, Key::Space, true, Modifiers::NONE);
|
||||
let before = h.state().ui.views[0].center;
|
||||
press_at(&mut h, 150.0, 200.0);
|
||||
move_to(&mut h, 190.0, 230.0);
|
||||
assert_ne!(h.state().ui.views[0].center, before, "the view is panning");
|
||||
// Mid-drag: the segment is painted where its anchors now are on screen.
|
||||
let (a, b) = (screen(&h, 100.0, 100.0), screen(&h, 200.0, 100.0));
|
||||
let near = |p: &Pos2, q: Pos2| p.distance(q) < 1.0;
|
||||
assert!(
|
||||
painted_paths(&h).iter().any(|pts| pts.first().is_some_and(|p| near(p, a)) && pts.last().is_some_and(|p| near(p, b))),
|
||||
"the Pen path from {a:?} to {b:?} is drawn while panning"
|
||||
);
|
||||
// The fist (#2196): the OS's own on macOS and Linux; on Windows our bitmap, over the
|
||||
// `Crosshair` fallback `CursorLifecycle` leaves under it.
|
||||
let out = &h.output().platform_output;
|
||||
let fist = if cfg!(target_os = "windows") {
|
||||
(egui::CursorIcon::Crosshair, crate::tool_cursor::hand_bitmap(&h.ctx, true).map(|i| i.rgba))
|
||||
} else {
|
||||
(egui::CursorIcon::Grabbing, None)
|
||||
};
|
||||
assert_eq!((out.cursor_icon, out.cursor_image.as_ref().map(|i| i.rgba.clone())), fist, "the fist while panning (#2196)");
|
||||
release(&mut h, 190.0, 230.0, Modifiers::NONE);
|
||||
key(&mut h, Key::Space, false, Modifiers::NONE);
|
||||
h.run_steps(2);
|
||||
let st = h.state();
|
||||
assert_eq!(st.ui.pen.as_ref().map(|p| p.knots.len()), Some(2), "the path is still being drawn");
|
||||
assert_eq!(st.ui.tool, Tool::Pen);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn space_while_editing_type_is_not_the_hand_tool() {
|
||||
let mut h = harness(Tool::Type);
|
||||
|
||||
@@ -152,6 +152,12 @@ fn hand_with(ctx: &egui::Context, closed: bool, bitmap: bool) -> CursorIcon {
|
||||
if closed { CursorIcon::Grabbing } else { CursorIcon::Grab }
|
||||
}
|
||||
|
||||
/// The bitmap [`hand`] hands Windows, for tests that check the Hand's pointer on every platform.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn hand_bitmap(ctx: &egui::Context, closed: bool) -> Option<CustomCursorImage> {
|
||||
rasterize(&Shape::Hand { closed }, native_scale(ctx))
|
||||
}
|
||||
|
||||
/// The Zoom tool's pointer: a magnifier with a plus, or a minus when it zooms `out`. winit maps
|
||||
/// `ZoomIn` and `ZoomOut` to the plain arrow on Windows (#3735), so there it is a bitmap; macOS and
|
||||
/// the Linux themes already draw magnifiers.
|
||||
|
||||
Reference in new issue
Block a user