mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-12 21:23:02 +00:00
Fix main: split the Pencil outline out of draw_default_tool_cursor
main fails the gate at clippy since #12214 landed: its Count arm took draw_default_tool_cursor to a cognitive complexity of 31 (limit 30). The Pencil / Block eraser outline moves into pencil_outline_cursor; behaviour is unchanged. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This commit is contained in:
1 parent
e99e07c04a
commit
47d3dcde33
1 file changed
+24
-17
@@ -1797,6 +1797,29 @@ fn draw_canvas_tool_cursor(app: &mut PhotocraftApp, ui: &mut egui::Ui, input: &C
|
||||
}
|
||||
}
|
||||
|
||||
/// The Pencil's cursor (and the Eraser's in Pencil or Block mode): the outline of the whole pixels
|
||||
/// its dab fills, on the pixel grid. A round tip is a disc, a square or Block one its square. The
|
||||
/// hotspot is drawn as well when `crosshair` asks for it or the outline is too small to see.
|
||||
fn pencil_outline_cursor(painter: &egui::Painter, xf: &ViewXform, p: Pos2, size: f32, block: bool, crosshair: bool) -> egui::CursorIcon {
|
||||
let ppp = painter.ctx().pixels_per_point();
|
||||
let sq = pencil_cursor_rect(xf, xf.to_doc(p), size, ppp);
|
||||
let px = 1.0 / ppp;
|
||||
let (dark, light) = (Stroke::new(px, Color32::from_black_alpha(160)), Stroke::new(px, Color32::from_white_alpha(230)));
|
||||
if !block && pencil_tip_is_round(size) {
|
||||
let r = sq.width() / 2.0;
|
||||
painter.circle_stroke(sq.center(), r + px / 2.0, dark);
|
||||
painter.circle_stroke(sq.center(), (r - px / 2.0).max(0.0), light);
|
||||
} else {
|
||||
painter.rect_stroke(sq, 0.0, dark, egui::StrokeKind::Outside);
|
||||
painter.rect_stroke(sq, 0.0, light, egui::StrokeKind::Inside);
|
||||
}
|
||||
// Too small to see where it is: the hotspot as well.
|
||||
if crosshair || sq.width() < 6.0 {
|
||||
crate::tool_cursor::crosshair(painter, p, 4.0, 0.0);
|
||||
}
|
||||
egui::CursorIcon::None
|
||||
}
|
||||
|
||||
fn draw_default_tool_cursor(app: &mut PhotocraftApp, ui: &mut egui::Ui, input: &CanvasOverlayInput<'_>, resizing: bool, p: Pos2) {
|
||||
let painter = input.painter;
|
||||
let xf = input.xf;
|
||||
@@ -1861,23 +1884,7 @@ fn draw_default_tool_cursor(app: &mut PhotocraftApp, ui: &mut egui::Ui, input: &
|
||||
_ if tool == Tool::Pencil || crate::eraser_ui::pencil_mode(app, tool) || crate::eraser_ui::block_mode(app, tool) => {
|
||||
let block = crate::eraser_ui::block_mode(app, tool);
|
||||
let size = if block { crate::eraser_ui::block_size(app) } else { brush.size };
|
||||
let ppp = painter.ctx().pixels_per_point();
|
||||
let sq = pencil_cursor_rect(xf, xf.to_doc(p), size, ppp);
|
||||
let px = 1.0 / ppp;
|
||||
let (dark, light) = (Stroke::new(px, Color32::from_black_alpha(160)), Stroke::new(px, Color32::from_white_alpha(230)));
|
||||
if !block && pencil_tip_is_round(size) {
|
||||
let r = sq.width() / 2.0;
|
||||
painter.circle_stroke(sq.center(), r + px / 2.0, dark);
|
||||
painter.circle_stroke(sq.center(), (r - px / 2.0).max(0.0), light);
|
||||
} else {
|
||||
painter.rect_stroke(sq, 0.0, dark, egui::StrokeKind::Outside);
|
||||
painter.rect_stroke(sq, 0.0, light, egui::StrokeKind::Inside);
|
||||
}
|
||||
// Too small to see where it is: the hotspot as well.
|
||||
if cur.show_crosshair_in_brush_tip || sq.width() < 6.0 {
|
||||
crate::tool_cursor::crosshair(painter, p, 4.0, 0.0);
|
||||
}
|
||||
egui::CursorIcon::None
|
||||
pencil_outline_cursor(painter, xf, p, size, block, cur.show_crosshair_in_brush_tip)
|
||||
}
|
||||
// A shaped tip (sampled bitmap, or a rotated/flattened round tip)
|
||||
// traces its outline, turned and flipped with the view; a plain round
|
||||
|
||||
Reference in new issue
Block a user