Color Replacement: not-allowed cursor over a Lock All layer (#17761)

paint_cursor_blocked now covers the Color Replacement tool, so its
cursor over a fully locked pixel layer is the not-allowed sign, as the
Brush's and the Eraser's already are. Partial locks, hidden layers and
type layers keep today's tip cursor (not measured).
This commit is contained in:
qvest-ssels committed 2026-11-29 18:47:48 +01:00
1 parent db731507eb
commit c33bda2b9e
2 files changed
+104 -2

No files matched your search

@@ -0,0 +1,97 @@
//! #17761: the Color Replacement tool shows the not-allowed cursor over a Lock All layer, as the
//! Brush and Eraser do; its size and hardness keys and the Alt+right-drag still change the tool.
//! Driven through real egui input on the real canvas.
use craft::behavior::{Cursor, CursorIcon, PaintedCursor};
use craft::ui::runtime::windows::WindowHost;
use egui::{Key, Modifiers, PointerButton, vec2};
use egui_kittest::Harness;
use serde_json::json;
use crate::PhotocraftApp;
use crate::guide_cursor_tests::{harness, hover, screen};
use crate::state::Tool;
const BLOCKED: Option<Cursor> = Some(Cursor::System(CursorIcon::NotAllowed));
fn pixel_layer() -> Harness<'static, Box<PhotocraftApp>> {
let mut h = harness(Tool::ColorReplacement);
h.state_mut().run("layer.new.layer", json!({})).unwrap();
h.state_mut().run("edit.fill", json!({"color": "#ff0000"})).unwrap();
h
}
fn cursor(h: &mut Harness<'static, Box<PhotocraftApp>>, x: f32) -> Option<Cursor> {
hover(h, x, 150.0, Modifiers::NONE);
h.state().canvas_tools.last_response.as_ref().and_then(|response| response.cursor.clone())
}
fn lock_all(h: &mut Harness<'static, Box<PhotocraftApp>>, on: bool) {
h.state_mut().run("layer.lockLayers", json!({"all": on})).unwrap();
}
#[test]
fn lock_all_gives_the_not_allowed_cursor_on_the_image_and_pasteboard() {
let mut h = pixel_layer();
let tip = cursor(&mut h, 100.0);
assert!(matches!(tip, Some(Cursor::Painted(PaintedCursor::Circle { .. } | PaintedCursor::Outline { .. }))), "unlocked: the tip outline, got {tip:?}");
lock_all(&mut h, true);
for x in [100.0, -40.0] {
assert_eq!(cursor(&mut h, x), BLOCKED, "x={x}");
assert_eq!(h.output().platform_output.cursor_icon, egui::CursorIcon::NotAllowed, "x={x}");
}
lock_all(&mut h, false);
assert_eq!(cursor(&mut h, 100.0), tip, "unlocked again: the tip outline");
}
#[test]
fn caps_lock_still_gives_the_precise_crosshair_on_an_unlocked_layer() {
let mut h = pixel_layer();
WindowHost::of(&h.ctx).set_caps_lock(Some(true));
assert_eq!(cursor(&mut h, 100.0), Some(Cursor::Painted(PaintedCursor::Crosshair)));
}
#[test]
fn partial_locks_and_a_hidden_locked_layer_keep_the_tip() {
let mut h = pixel_layer();
let tip = cursor(&mut h, 100.0);
for lock in ["pixels", "transparency", "position"] {
h.state_mut().run("layer.lockLayers", json!({ (lock): true })).unwrap();
assert_eq!(cursor(&mut h, 100.0), tip, "{lock}");
h.state_mut().run("layer.lockLayers", json!({ (lock): false })).unwrap();
}
lock_all(&mut h, true);
h.state_mut().run("layer.setProps", json!({"visible": false})).unwrap();
assert_eq!(cursor(&mut h, 100.0), tip, "hidden Lock All layer");
}
#[test]
fn size_and_hardness_keys_and_the_resize_drag_work_on_a_locked_layer() {
let mut h = pixel_layer();
lock_all(&mut h, true);
cursor(&mut h, 100.0);
let size = h.state().session.tools.brush.size;
h.key_press(Key::CloseBracket);
h.run_steps(2);
let bigger = h.state().session.tools.brush.size;
assert!(bigger > size, "] grows the tip: {size} -> {bigger}");
h.state_mut().run("tools.setBrush", json!({"hardness": 0.0})).unwrap();
h.key_press_modifiers(Modifiers::SHIFT, Key::CloseBracket);
h.run_steps(2);
assert!(h.state().session.tools.brush.hardness > 0.0, "Shift+] hardens the tip");
let from = screen(&h, 100.0, 150.0);
let alt = Modifiers::ALT;
h.event(egui::Event::ModifiersChanged(alt));
h.event(egui::Event::PointerMoved(from));
h.run_steps(1);
h.event(egui::Event::PointerButton { pos: from, button: PointerButton::Secondary, pressed: true, modifiers: alt });
h.run_steps(1);
for i in 1..=6 {
h.event(egui::Event::PointerMoved(from + vec2(i as f32 * 8.0, 0.0)));
h.run_steps(1);
}
h.event(egui::Event::PointerButton { pos: from + vec2(48.0, 0.0), button: PointerButton::Secondary, pressed: false, modifiers: alt });
h.run_steps(2);
assert_ne!(h.state().session.tools.brush.size, bigger, "Alt+right-drag resizes the tip");
}
+7 -2
View File
@@ -123,12 +123,13 @@ pub(crate) fn alt_loads_mixer(tool: Tool, mods: craft::keymap::Mods) -> bool {
mods.alt && !mods.ctrl && tool == Tool::MixerBrush
}
/// Whether the painting tool shows the not-allowed cursor for its current target.
/// Whether the painting tool shows the not-allowed cursor for its current target. The Color
/// Replacement tool shows it on a Lock All pixel layer (#17761).
pub(super) fn paint_cursor_blocked(app: &PhotocraftApp) -> bool {
use photocraft_doc::LayerContent;
let tool = app.ui.tool;
if !matches!(tool, Tool::Brush | Tool::Eraser | Tool::PaintBucket | Tool::MixerBrush) {
if !matches!(tool, Tool::Brush | Tool::Eraser | Tool::PaintBucket | Tool::MixerBrush | Tool::ColorReplacement) {
return false;
}
let Some(state) = app.session.active() else { return false };
@@ -217,3 +218,7 @@ mod magic_eraser_cursor_tests;
#[cfg(test)]
#[path = "locked_layer_cursor_tests.rs"]
mod locked_layer_cursor_tests;
#[cfg(test)]
#[path = "color_replacement_locked_cursor_tests.rs"]
mod color_replacement_locked_cursor_tests;