PhotoCraft: An open-source, photo editor written by scratch in pure Rust
test: optionally capture actual pen cursor bitmaps
jonathnwxh79e827ce7a83
diff --git a/crates/ui-egui/src/tool_cursor/tests.rs b/crates/ui-egui/src/tool_cursor/tests.rsindex 91a922477..a28d54940 100644--- a/crates/ui-egui/src/tool_cursor/tests.rs+++ b/crates/ui-egui/src/tool_cursor/tests.rs@@ -400,6 +400,8 @@ fn brush_cursor_follows_pen_orientation_6350() {h.state_mut().stylus.feed.set(Some(crate::stylus::PenSample { tilt_y: -45.0, rotation: 90.0, ..Default::default() }));h.run_steps(3);let turned = h.output().platform_output.cursor_image.clone().expect("turned brush cursor");+ save_pen_cursor_image(&format!("{control}-initial"), &initial);+ save_pen_cursor_image(&format!("{control}-turned"), &turned);let pen = h.state().stylus.sample().expect("simulated pen reaches the canvas");assert_eq!((pen.tilt_y, pen.rotation), (-45.0, 90.0));let point = photocraft_paint::StrokePoint { tilt_y: pen.tilt_y, rotation: pen.rotation, ..Default::default() };@@ -432,12 +434,26 @@ fn round_cursor_shows_brush_projection_6350() {h.state_mut().stylus.feed.set(Some(crate::stylus::PenSample { tilt_x: 60.0, ..Default::default() }));h.run_steps(3);let tilted = h.output().platform_output.cursor_image.clone().unwrap();+ save_pen_cursor_image("projection-upright", &upright);+ save_pen_cursor_image("projection-tilted", &tilted);assert_ne!(upright.rgba, tilted.rgba, "a projected round brush must not keep a circular cursor");h.state_mut().stylus.feed.set(None);h.run_steps(3);assert_eq!(upright.rgba, h.output().platform_output.cursor_image.clone().unwrap().rgba, "mouse restores the unprojected tip");}+#[cfg(not(target_arch = "wasm32"))]+fn save_pen_cursor_image(name: &str, cursor: &egui::CustomCursorImage) {+ let Some(dir) = std::env::var_os("PHOTOCRAFT_CURSOR_OUTPUT") else { return };+ let dir = std::path::PathBuf::from(dir);+ std::fs::create_dir_all(&dir).unwrap();+ let image =+ photocraft_codecs::Image::from_u8(u32::from(cursor.size[0]), u32::from(cursor.size[1]), photocraft_codecs::ChannelLayout::Rgba, cursor.rgba.to_vec())+ .unwrap();+ let png = photocraft_codecs::encode(&image, photocraft_codecs::Format::Png, &Default::default()).unwrap();+ std::fs::write(dir.join(format!("{name}.png")), png).unwrap();+}+#[test]#[cfg(not(target_arch = "wasm32"))]fn brush_hover_uses_an_os_bitmap_that_survives_motion_but_not_tool_or_panel_changes() {