Skip to content

PhotoCraft: An open-source, photo editor written by scratch in pure Rust

Eraser: Block mode (#2770) (#2778)

Valentin Kleind0127f92943b
diff --git a/crates/engine/src/brush_cmds.rs b/crates/engine/src/brush_cmds.rs
index 27eeefd68..a0a217c30 100644
--- a/crates/engine/src/brush_cmds.rs
+++ b/crates/engine/src/brush_cmds.rs
@@ -312,6 +312,9 @@ fn apply_auto_erase(brush: &mut BrushSettings, surf: &Surface, start: Option<&St
/// dabs on the pixel grid), hard and at full flow, with the options-bar mode.
fn pencil_brush(s: &Session, p: &Value) -> Result<BrushSettings> {
let mut brush = with_blend_mode(resolve_brush(s, p, "paint.pencil")?, p);
+ if flag(p, "block", false) {
+ return block_brush(brush, p);
+ }
brush.aliased = true;
if num(p, "hardness").is_none() {
brush.hardness = 1.0;
@@ -322,6 +325,42 @@ fn pencil_brush(s: &Session, p: &Value) -> Result<BrushSettings> {
Ok(brush)
}
+/// Edge of the Eraser's Block in screen pixels (Photoshop): constant on screen, so it covers
+/// `BLOCK_SCREEN_PX / zoom` document pixels.
+pub const BLOCK_SCREEN_PX: f64 = 16.0;
+
+/// The Eraser's Block edge in document pixels at view `zoom`: `16 / zoom`, rounded to whole
+/// pixels (a zoom that is not a positive number counts as 100 %).
+pub fn block_size(zoom: f64) -> f32 {
+ let zoom = if zoom.is_finite() && zoom > 0.0 { zoom } else { 1.0 };
+ (BLOCK_SCREEN_PX / zoom).round().clamp(1.0, f64::from(photocraft_paint::brush::MAX_BRUSH_SIZE)) as f32
+}
+
+/// The Eraser's Block mode (`"block": true`): a hard, aliased square of
+/// [`BLOCK_SCREEN_PX`] screen pixels at the stroke's `"zoom"`, i.e. `16 / zoom` document
+/// pixels rounded to whole pixels. Size, opacity, flow, hardness and the brush's dynamics don't
+/// apply (Photoshop); colour, erase, smoothing and the seed are the resolved brush's.
+fn block_brush(b: BrushSettings, p: &Value) -> Result<BrushSettings> {
+ let zoom = match p.get("zoom") {
+ None => 1.0,
+ Some(v) => v.as_f64().filter(|z| z.is_finite() && *z > 0.0).ok_or_else(|| bad("paint.pencil", "`zoom` must be a positive number"))?,
+ };
+ Ok(BrushSettings {
+ size: block_size(zoom),
+ aliased: true,
+ square: true,
+ pressure_size: false,
+ pressure_opacity: false,
+ spacing: 0.25,
+ color: b.color,
+ background: b.background,
+ erase: b.erase,
+ smoothing: b.smoothing,
+ seed: b.seed,
+ ..BrushSettings::default()
+ })
+}
+
/// Applies the options-bar blend `mode` to a brush. `"mode"` accepts any blend-mode name
/// (normal|multiply|screen|…). The Eraser has no blend mode in Photoshop, so it is forced to Normal.
fn with_blend_mode(mut b: BrushSettings, p: &Value) -> BrushSettings {
@@ -882,7 +921,7 @@ pub fn specs() -> Vec<CommandSpec> {
spec!(
"paint.pencil",
"Pencil",
- r##"{"points":[[x,y,pressure?,tiltX?,tiltY?,rotation?,timeMs?,wheel?],…],"brush":{…}?,"preset":name?,"size":0.5..5000 px?,"opacity":0..1?,"color":"#rrggbb"?=foreground,"mode":"normal|multiply|screen|…"="normal","erase":bool?,"autoErase":bool=false,"seed":u64?,"target":"pixels"|"mask"|"quickMask"|{"channel":i}=Channels panel target}"##,
+ r##"{"points":[[x,y,pressure?,tiltX?,tiltY?,rotation?,timeMs?,wheel?],…],"brush":{…}?,"preset":name?,"size":0.5..5000 px?,"opacity":0..1?,"color":"#rrggbb"?=foreground,"mode":"normal|multiply|screen|…"="normal","erase":bool?,"block":bool=false (a hard 16×16 screen-px square, 16/zoom doc px; size, opacity, flow, hardness and dynamics ignored: the Eraser's Block mode),"zoom":view zoom=1,"autoErase":bool=false,"seed":u64?,"target":"pixels"|"mask"|"quickMask"|{"channel":i}=Channels panel target}"##,
has_paintable,
pencil,
true
diff --git a/crates/paint/src/brush.rs b/crates/paint/src/brush.rs
index 7e19d36df..25ebea5ef 100644
--- a/crates/paint/src/brush.rs
+++ b/crates/paint/src/brush.rs
@@ -485,6 +485,10 @@ pub struct BrushSettings {
pub flip_y: bool,
/// Pencil: no anti-aliasing (coverage is 0 or 1).
pub aliased: bool,
+ /// With `aliased`, a square tip: every pixel of the dab's whole-pixel square
+ /// ([`crate::grid_square`]), whatever its angle or roundness. The Eraser's Block mode.
+ #[serde(skip_serializing_if = "std::ops::Not::not")]
+ pub square: bool,
// --- dynamics sections ---
pub shape_dynamics: ShapeDynamics,
pub scattering: Scattering,
@@ -533,6 +537,7 @@ impl Default for BrushSettings {
flip_x: false,
flip_y: false,
aliased: false,
+ square: false,
shape_dynamics: ShapeDynamics::default(),
scattering: Scattering::default(),
texture: Texture::default(),
diff --git a/crates/paint/src/render.rs b/crates/paint/src/render.rs
index 386c5c0a8..09098293d 100644
--- a/crates/paint/src/render.rs
+++ b/crates/paint/src/render.rs
@@ -219,6 +219,13 @@ impl BrushContext {
let dx = x as f32 + 0.5 - cx;
let (u, v) = to_tip(dx, dy);
let (mut val, rn) = match mips {
+ // Block: the whole-pixel square, hard (the Eraser's Block mode).
+ _ if aliased && b.square => {
+ if dx.abs() >= r || dy.abs() >= r {
+ continue;
+ }
+ (1.0, 0.0)
+ }
None if small => {
let d2 = (u * ro).powi(2) + v * v;
if d2 >= small_reach2 {
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rs
index 06af2a85e..07038ad3d 100644
--- a/crates/ui-egui/src/canvas.rs
+++ b/crates/ui-egui/src/canvas.rs
@@ -342,6 +342,10 @@ fn stroke_params(app: &PhotocraftApp, tool: Tool, erase: bool, points: &[Vec<f64
if tool == Tool::Pencil {
p["autoErase"] = json!(app.ui.tool_options.pencil_auto_erase);
}
+ // Block mode: the engine sizes the square from the stroke's zoom (16 / zoom px, #2770).
+ if crate::eraser_ui::block_mode(app, tool) {
+ p["block"] = json!(true);
+ }
p
}
@@ -362,10 +366,10 @@ fn live_retouch_command(tool: Tool) -> Option<&'static str> {
}
}
-/// The command a live-stroking tool commits: the Pencil's (and the Pencil-mode Eraser's)
-/// `paint.pencil`, else `paint.stroke`.
+/// The command a live-stroking tool commits: the Pencil's (and the Pencil- or Block-mode
+/// Eraser's) `paint.pencil`, else `paint.stroke`.
pub(crate) fn stroke_command(app: &PhotocraftApp, tool: Tool) -> &'static str {
- if tool == Tool::Pencil || crate::eraser_ui::pencil_mode(app, tool) { "paint.pencil" } else { "paint.stroke" }
+ if tool == Tool::Pencil || crate::eraser_ui::pencil_mode(app, tool) || crate::eraser_ui::block_mode(app, tool) { "paint.pencil" } else { "paint.stroke" }
}
/// Windows' crosshair cursor inverts the pixels under it, so over mid-grey (the pasteboard, many
@@ -3037,13 +3041,16 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:
_ if painting && cur.show_only_crosshair_while_painting => crate::tool_cursor::crosshair(&painter, p, 5.0, 0.0),
// The Pencil (and the Eraser in Pencil mode): the outline of the
// whole pixels its dab fills, on the pixel grid. A round tip is a
- // disc, a tiny one the whole square (#2662).
- _ if tool == Tool::Pencil || crate::eraser_ui::pencil_mode(app, tool) => {
+ // disc, a tiny one the whole square (#2662). The Block-mode Eraser:
+ // its square, 16 screen pixels at any zoom (#2770).
+ _ 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), brush.size, ppp);
+ 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 pencil_tip_is_round(brush.size) {
+ 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);
diff --git a/crates/ui-egui/src/eraser_ui.rs b/crates/ui-egui/src/eraser_ui.rs
index fa62347e2..59fc4d492 100644
--- a/crates/ui-egui/src/eraser_ui.rs
+++ b/crates/ui-egui/src/eraser_ui.rs
@@ -59,10 +59,22 @@ pub fn pencil_mode(app: &PhotocraftApp, tool: Tool) -> bool {
tool == Tool::Eraser && app.ui.tool_options.eraser_mode == "pencil"
}
-/// The Eraser's Mode dropdown (Brush / Pencil). Returns whether it changed.
+/// Whether `tool` is the Eraser in Block mode: it erases a hard square of 16 screen pixels
+/// (`16 / zoom` document pixels) through `paint.pencil` (`"block": true`); Size, Hardness,
+/// Opacity and Flow don't apply (#2770).
+pub fn block_mode(app: &PhotocraftApp, tool: Tool) -> bool {
+ tool == Tool::Eraser && app.ui.tool_options.eraser_mode == "block"
+}
+
+/// The Block's edge in document pixels at the current zoom (what the engine erases).
+pub fn block_size(app: &PhotocraftApp) -> f32 {
+ photocraft_engine::brush_cmds::block_size(f64::from(app.point_zoom()))
+}
+
+/// The Eraser's Mode dropdown (Brush / Pencil / Block). Returns whether it changed.
pub fn mode_dropdown(ui: &mut egui::Ui, mode: &mut String) -> bool {
opt(ui, tl!("Mode:"));
- let modes = [("brush".to_string(), tl!("Brush")), ("pencil".to_string(), tl!("Pencil"))];
+ let modes = [("brush".to_string(), tl!("Brush")), ("pencil".to_string(), tl!("Pencil")), ("block".to_string(), tl!("Block"))];
widgets::dropdown(ui, "eraser-mode", mode, &modes, 96.0)
}
diff --git a/crates/ui-egui/src/i18n/cs.tsv b/crates/ui-egui/src/i18n/cs.tsv
index 5234ff971..80b7a8975 100644
--- a/crates/ui-egui/src/i18n/cs.tsv
+++ b/crates/ui-egui/src/i18n/cs.tsv
@@ -1550,6 +1550,7 @@
Bold Tučné
Brush Štětec
Pencil Tužka
+ Block Blok
Brush Pose Poloha štětce
Brush Tip Shape Tvar hrotu štětce
Brush Tool Nástroj štětec
diff --git a/crates/ui-egui/src/i18n/de.tsv b/crates/ui-egui/src/i18n/de.tsv
index 7e2d14f08..0ac393103 100644
--- a/crates/ui-egui/src/i18n/de.tsv
+++ b/crates/ui-egui/src/i18n/de.tsv
@@ -1525,6 +1525,7 @@
Blur Tool Weichzeichner-Werkzeug
Bold Fett
Brush Pinsel
+ Block Block
Brush Pose Pinselhaltung
Brush Tip Shape Pinselspitzenform
Brush Tool Pinsel-Werkzeug
diff --git a/crates/ui-egui/src/i18n/el.tsv b/crates/ui-egui/src/i18n/el.tsv
index 907fd8f83..4c71091ae 100644
--- a/crates/ui-egui/src/i18n/el.tsv
+++ b/crates/ui-egui/src/i18n/el.tsv
@@ -3361,6 +3361,7 @@ cameraRaw Yellow Κίτρινο
Black Matte Μαύρο ματ
Brush Πινέλο
Pencil Μολύβι
+ Block Μπλοκ
Color… Χρώμα…
Cone (Inverted) Κώνος (αντεστραμμένος)
Could not open Δεν ήταν δυνατό το άνοιγμα
diff --git a/crates/ui-egui/src/i18n/es.tsv b/crates/ui-egui/src/i18n/es.tsv
index 6bffff35f..b8466f507 100644
--- a/crates/ui-egui/src/i18n/es.tsv
+++ b/crates/ui-egui/src/i18n/es.tsv
@@ -1532,6 +1532,7 @@
Blur Tool Herramienta Desenfocar
Bold Negrita
Brush Pincel
+ Block Bloque
Brush Pose Postura del pincel
Brush Tip Shape Forma de la punta del pincel
Brush Tool Herramienta Pincel
diff --git a/crates/ui-egui/src/i18n/fr.tsv b/crates/ui-egui/src/i18n/fr.tsv
index ed8dc39fe..34e0a3eb9 100644
--- a/crates/ui-egui/src/i18n/fr.tsv
+++ b/crates/ui-egui/src/i18n/fr.tsv
@@ -1512,6 +1512,7 @@
Blur Tool Outil Flou
Bold Gras
Brush Pinceau
+ Block Carré
Brush Pose Position du pinceau
Brush Tip Shape Forme de la pointe
Brush Tool Outil Pinceau
diff --git a/crates/ui-egui/src/i18n/id.tsv b/crates/ui-egui/src/i18n/id.tsv
index 8b658a098..28199e299 100644
--- a/crates/ui-egui/src/i18n/id.tsv
+++ b/crates/ui-egui/src/i18n/id.tsv
@@ -1506,6 +1506,7 @@
Blur Tool Alat Blur
Bold Tebal
Brush Kuas
+ Block Blok
Brush Pose Pose Kuas
Brush Tip Shape Bentuk Ujung Kuas
Brush Tool Alat Kuas
diff --git a/crates/ui-egui/src/i18n/it.tsv b/crates/ui-egui/src/i18n/it.tsv
index 36bae98f8..10a483984 100644
--- a/crates/ui-egui/src/i18n/it.tsv
+++ b/crates/ui-egui/src/i18n/it.tsv
@@ -1531,6 +1531,7 @@
Blur Tool Strumento Sfoca
Bold Grassetto
Brush Pennello
+ Block Blocco
Brush Pose Posa pennello
Brush Tip Shape Forma punta pennello
Brush Tool Strumento Pennello
diff --git a/crates/ui-egui/src/i18n/ja.tsv b/crates/ui-egui/src/i18n/ja.tsv
index e807a56e8..3e7318741 100644
--- a/crates/ui-egui/src/i18n/ja.tsv
+++ b/crates/ui-egui/src/i18n/ja.tsv
@@ -1536,6 +1536,7 @@
Blur Tool ぼかしツール
Bold ボールド
Brush ブラシ
+ Block ブロック
Brush Pose ブラシの姿勢
Brush Tip Shape ブラシ先端のシェイプ
Brush Tool ブラシツール
diff --git a/crates/ui-egui/src/i18n/ko.tsv b/crates/ui-egui/src/i18n/ko.tsv
index 792485fae..5d45ef534 100644
--- a/crates/ui-egui/src/i18n/ko.tsv
+++ b/crates/ui-egui/src/i18n/ko.tsv
@@ -1504,6 +1504,7 @@
Bold 굵게
Brush 브러시
Pencil 연필
+ Block 블록
Brush Pose 브러시 자세
Brush Tip Shape 브러시 끝 모양
Brush Tool 브러시 도구
diff --git a/crates/ui-egui/src/i18n/nl.tsv b/crates/ui-egui/src/i18n/nl.tsv
index 304a81e17..aef8f7451 100644
--- a/crates/ui-egui/src/i18n/nl.tsv
+++ b/crates/ui-egui/src/i18n/nl.tsv
@@ -1516,6 +1516,7 @@
Blur Tool Vervagingsgereedschap
Bold Vet
Brush Penseel
+ Block Blok
Brush Pose Penseelhouding
Brush Tip Shape Vorm penseelpunt
Brush Tool Penseelgereedschap
diff --git a/crates/ui-egui/src/i18n/pl.tsv b/crates/ui-egui/src/i18n/pl.tsv
index dd596cf24..a40977248 100644
--- a/crates/ui-egui/src/i18n/pl.tsv
+++ b/crates/ui-egui/src/i18n/pl.tsv
@@ -1529,6 +1529,7 @@
Blur Tool Narzędzie Rozmycie
Bold Pogrubiona
Brush Pędzel
+ Block Blok
Brush Pose Pozycja pędzla
Brush Tip Shape Kształt końcówki pędzla
Brush Tool Narzędzie Pędzel
diff --git a/crates/ui-egui/src/i18n/pt-br.tsv b/crates/ui-egui/src/i18n/pt-br.tsv
index ed19dd0a4..8beedbbdd 100644
--- a/crates/ui-egui/src/i18n/pt-br.tsv
+++ b/crates/ui-egui/src/i18n/pt-br.tsv
@@ -1511,6 +1511,7 @@
Blur Tool Ferramenta Desfoque
Bold Negrito
Brush Pincel
+ Block Bloco
Brush Pose Pose do pincel
Brush Tip Shape Forma da ponta do pincel
Brush Tool Ferramenta Pincel
diff --git a/crates/ui-egui/src/i18n/ru.tsv b/crates/ui-egui/src/i18n/ru.tsv
index c43e70dec..e1e26696c 100644
--- a/crates/ui-egui/src/i18n/ru.tsv
+++ b/crates/ui-egui/src/i18n/ru.tsv
@@ -492,6 +492,7 @@
Wand Волшебная палочка
Eyedropper Пипетка
Brush Кисть
+ Block Квадрат
Pencil Карандаш
Eraser Ластик
Clone Stamp Штамп
diff --git a/crates/ui-egui/src/i18n/uk.tsv b/crates/ui-egui/src/i18n/uk.tsv
index 4011b55c8..175dd7b3a 100644
--- a/crates/ui-egui/src/i18n/uk.tsv
+++ b/crates/ui-egui/src/i18n/uk.tsv
@@ -472,6 +472,7 @@
Wand Чарівна паличка
Eyedropper Піпетка
Brush Пензель
+ Block Блок
Pencil Олівець
Eraser Гумка
Clone Stamp Клонувальний штамп
diff --git a/crates/ui-egui/src/i18n/zh-hans.tsv b/crates/ui-egui/src/i18n/zh-hans.tsv
index f1a0d52a6..3d5bd4f2b 100644
--- a/crates/ui-egui/src/i18n/zh-hans.tsv
+++ b/crates/ui-egui/src/i18n/zh-hans.tsv
@@ -1545,6 +1545,7 @@
Bold 粗体
Brush 画笔
Pencil 铅笔
+ Block 块
Brush Pose 画笔姿态
Brush Tip Shape 画笔笔尖形状
Brush Tool 画笔工具
diff --git a/crates/ui-egui/src/i18n/zh-hant.tsv b/crates/ui-egui/src/i18n/zh-hant.tsv
index b20e71ca3..274a06ea1 100644
--- a/crates/ui-egui/src/i18n/zh-hant.tsv
+++ b/crates/ui-egui/src/i18n/zh-hant.tsv
@@ -1539,6 +1539,7 @@
Bold 粗體
Brush 筆刷
Pencil 鉛筆
+ Block 區塊
Brush Pose 筆刷姿勢
Brush Tip Shape 筆尖形狀
Brush Tool 筆刷工具
diff --git a/crates/ui-egui/src/panels.rs b/crates/ui-egui/src/panels.rs
index ff7c31553..debd56730 100644
--- a/crates/ui-egui/src/panels.rs
+++ b/crates/ui-egui/src/panels.rs
@@ -834,10 +834,14 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
let b = &mut brush;
match app.ui.tool {
Tool::Brush | Tool::Eraser if t.pro => {
- brush_preset_chip(ui, b, &mut app.ui);
- crate::brush_picker::settings_toggle(app, ui);
+ // A Block-mode Eraser has a fixed size, opacity and flow (Photoshop, #2770).
+ let block = crate::eraser_ui::block_mode(app, app.ui.tool);
+ ui.add_enabled_ui(!block, |ui| {
+ brush_preset_chip(ui, b, &mut app.ui);
+ crate::brush_picker::settings_toggle(app, ui);
+ });
widgets::vline(ui, 22.0);
- // The Eraser has no blend mode: its Mode is Brush or Pencil (#2662).
+ // The Eraser has no blend mode: its Mode is Brush, Pencil or Block (#2662).
if app.ui.tool == Tool::Eraser {
crate::eraser_ui::mode_dropdown(ui, &mut app.ui.tool_options.eraser_mode);
} else {
@@ -848,12 +852,14 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
b.mode = mode;
}
}
- percent_field(ui, tl!("Opacity"), &mut b.opacity, 0.0..=100.0, 62.0);
- if icons::button(ui, "circle-dot", 24.0, b.pressure_opacity, tl!("Always use pressure for opacity")).clicked() {
- b.pressure_opacity = !b.pressure_opacity;
- }
- // A Pencil-mode Eraser is always full flow, without build-up (Photoshop).
- ui.add_enabled_ui(!crate::eraser_ui::pencil_mode(app, app.ui.tool), |ui| {
+ ui.add_enabled_ui(!block, |ui| {
+ percent_field(ui, tl!("Opacity"), &mut b.opacity, 0.0..=100.0, 62.0);
+ if icons::button(ui, "circle-dot", 24.0, b.pressure_opacity, tl!("Always use pressure for opacity")).clicked() {
+ b.pressure_opacity = !b.pressure_opacity;
+ }
+ });
+ // A Pencil- or Block-mode Eraser is always full flow, without build-up (Photoshop).
+ ui.add_enabled_ui(!block && !crate::eraser_ui::pencil_mode(app, app.ui.tool), |ui| {
percent_field(ui, tl!("Flow"), &mut b.flow, 1.0..=100.0, 62.0);
let airbrush = icons::button(ui, "sparkles", 24.0, b.build_up, tl!("Enable airbrush-style build-up effects"));
if crate::brush_picker::named(airbrush, tl!("Enable airbrush-style build-up effects")).clicked() {
@@ -894,17 +900,21 @@ pub fn options_bar(app: &mut PhotocraftApp, ui: &mut egui::Ui) {
brush_preset_chip(ui, b, &mut app.ui);
crate::brush_picker::settings_toggle(app, ui);
widgets::vline(ui, 22.0);
- opt_label(ui, tl!("Size"));
- widgets::value_field(ui, &mut b.size, 1.0..=2500.0, "px", 76.0);
+ // A Block-mode Eraser has a fixed size, opacity and flow (Photoshop, #2770).
+ let block = crate::eraser_ui::block_mode(app, app.ui.tool);
+ ui.add_enabled_ui(!block, |ui| {
+ opt_label(ui, tl!("Size"));
+ widgets::value_field(ui, &mut b.size, 1.0..=2500.0, "px", 76.0);
+ });
widgets::vline(ui, 22.0);
if app.ui.tool == Tool::Eraser {
crate::eraser_ui::mode_dropdown(ui, &mut app.ui.tool_options.eraser_mode);
}
// A Pencil-mode Eraser is always hard and at full flow (Photoshop).
- let pencil = crate::eraser_ui::pencil_mode(app, app.ui.tool);
- ui.add_enabled_ui(!pencil, |ui| percent_field(ui, tl!("Hardness"), &mut b.hardness, 0.0..=100.0, 66.0));
- percent_field(ui, tl!("Opacity"), &mut b.opacity, 0.0..=100.0, 66.0);
- ui.add_enabled_ui(!pencil, |ui| percent_field(ui, tl!("Flow"), &mut b.flow, 1.0..=100.0, 66.0));
+ let fixed = block || crate::eraser_ui::pencil_mode(app, app.ui.tool);
+ ui.add_enabled_ui(!fixed, |ui| percent_field(ui, tl!("Hardness"), &mut b.hardness, 0.0..=100.0, 66.0));
+ ui.add_enabled_ui(!block, |ui| percent_field(ui, tl!("Opacity"), &mut b.opacity, 0.0..=100.0, 66.0));
+ ui.add_enabled_ui(!fixed, |ui| percent_field(ui, tl!("Flow"), &mut b.flow, 1.0..=100.0, 66.0));
opt_label(ui, tl!("Smoothing"));
smoothing_field(ui, b, 66.0);
widgets::vline(ui, 22.0);
diff --git a/crates/ui-egui/src/pencil_tests.rs b/crates/ui-egui/src/pencil_tests.rs
index fc33581bd..c57df1d70 100644
--- a/crates/ui-egui/src/pencil_tests.rs
+++ b/crates/ui-egui/src/pencil_tests.rs
@@ -176,6 +176,37 @@ fn the_eraser_in_pencil_mode_erases_aliased_pixels() {
assert!(erased > 500, "{erased}");
}
+#[test]
+fn the_eraser_in_block_mode_erases_a_16_screen_px_square() {
+ // #2770: a soft, small, half-opacity Eraser in Block mode still clears a hard square of
+ // 16 screen pixels: 16 document pixels at 100 %, 8 at 200 %.
+ for (zoom, n) in [(1.0, 16usize), (2.0, 8)] {
+ let mut app = app();
+ app.run("paint.pencil", json!({"points": [[60.0, 40.0]], "size": 400})).unwrap();
+ app.ui.tool = Tool::Eraser;
+ crate::paint_mouse::sync_tool_brush(&mut app);
+ app.run("tools.setBrush", json!({"brush": {"size": 5, "hardness": 0.0, "opacity": 0.5, "flow": 0.3, "smoothing": {"amount": 0.0}}})).unwrap();
+ app.ui.tool_options.eraser_mode = "block".into();
+ app.ui.views[0].zoom = zoom;
+ drag(&mut app, &[(60.3, 40.6)], Modifiers::NONE);
+ let (id, p) = last(&app);
+ assert_eq!((id.as_str(), &p["block"]), ("paint.pencil", &json!(true)));
+ let s = layer(&app).surface().unwrap().clone();
+ let (mut erased, mut x0, mut y0, mut x1, mut y1) = (0, i32::MAX, i32::MAX, 0, 0);
+ for y in 0..80 {
+ for x in 0..120 {
+ let a = s.rgba(x, y)[3];
+ assert!(a == 0.0 || a == 1.0, "partial alpha {a} at ({x},{y}), zoom {zoom}");
+ if a == 0.0 {
+ erased += 1;
+ (x0, y0, x1, y1) = (x0.min(x), y0.min(y), x1.max(x), y1.max(y));
+ }
+ }
+ }
+ assert_eq!((erased, x1 - x0 + 1, y1 - y0 + 1), (n * n, n as i32, n as i32), "zoom {zoom}");
+ }
+}
+
#[test]
fn b_cycles_brush_pencil_and_mixer_brush() {
let mut h = Harness::builder().with_size(vec2(1280.0, 800.0)).with_max_steps(64).build_eframe(|cc| {