PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Option flips Dodge/Burn and Blur/Sharpen for a stroke (#1038)
jason4short1dd9a3418104
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex 19bfcbcbd..1f3c31961 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -2643,6 +2643,8 @@ pub fn tool_event(app: &mut PhotocraftApp, ev: ToolEvent, mods: egui::Modifiers)if let Some(p) = from {points.insert(0, [p[0], p[1], pressure as f64]);}+ // ⌥ flips Dodge/Burn and Blur/Sharpen for this stroke.+ let tool = crate::retouch_ui::alt_flipped(tool, mods.alt);app.drag = Some(Drag::new(tool, from.unwrap_or([x, y]), points, mods, erase));app.trail = None;app.stylus.begin_stroke();diff --git a/crates/ui-egui/src/retouch_ui.rs b/crates/ui-egui/src/retouch_ui.rsindex 4f22a09b1..1ab730de2 100644--- a/crates/ui-egui/src/retouch_ui.rs+++ b/crates/ui-egui/src/retouch_ui.rs@@ -10,6 +10,17 @@ use crate::canvas::ViewXform;use crate::state::Tool;use crate::theme::Tokens;+/// The tool a stroke uses with ⌥ held: Dodge and Burn swap, as do Blur and Sharpen.+pub(crate) fn alt_flipped(tool: Tool, alt: bool) -> Tool {+ match (tool, alt) {+ (Tool::Dodge, true) => Tool::Burn,+ (Tool::Burn, true) => Tool::Dodge,+ (Tool::Blur, true) => Tool::Sharpen,+ (Tool::Sharpen, true) => Tool::Blur,+ _ => tool,+ }+}+/// 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();@@ -338,6 +349,32 @@ mod tests {}}+ #[test]+ fn alt_flips_dodge_burn_and_blur_sharpen() {+ for (tool, flipped) in [(Tool::Dodge, Tool::Burn), (Tool::Burn, Tool::Dodge), (Tool::Blur, Tool::Sharpen), (Tool::Sharpen, Tool::Blur)] {+ assert_eq!(alt_flipped(tool, true), flipped);+ assert_eq!(alt_flipped(tool, false), tool);+ }+ for tool in [Tool::Sponge, Tool::Smudge, Tool::Brush] {+ assert_eq!(alt_flipped(tool, true), tool, "{tool:?} has no ⌥ counterpart");+ }+ }++ #[test]+ fn alt_stroke_runs_the_opposite_tool() {+ // ⌥ held as the stroke starts: Dodge burns, Burn dodges, Blur sharpens, Sharpen blurs.+ for (tool, cmd) in [(Tool::Dodge, "paint.burn"), (Tool::Burn, "paint.dodge"), (Tool::Blur, "paint.sharpen"), (Tool::Sharpen, "paint.blur")] {+ let mut app = app();+ app.ui.tool = tool;+ let m = egui::Modifiers::ALT;+ tool_event(&mut app, ToolEvent::Down { x: 10.0, y: 30.0, pressure: 1.0 }, m);+ tool_event(&mut app, ToolEvent::Move { x: 50.0, y: 30.0, pressure: 1.0 }, m);+ tool_event(&mut app, ToolEvent::Up { x: 50.0, y: 30.0 }, m);+ assert_eq!(app.session.journal.last().map(|(id, _)| id.as_str()), Some(cmd), "{tool:?} with ⌥");+ assert_eq!(app.ui.tool, tool, "the selected tool stays {tool:?}");+ }+ }+#[test]fn clone_without_a_source_names_the_platform_modifier() {// Option-click on the Mac, Alt-click elsewhere (#251).