alternate XOR pattern for busy-bar

this it to avoid abusing the primitive to create inverted text
(for secure UI elements only). It does degrade from the aesthetics
of a busy bar but it is a computationally efficient way to patch
around the concern.
This commit is contained in:
bunnie 2023-10-18 14:13:25 +08:00
parent 6a3e9f1584
commit 50ef03e319
3 changed files with 16 additions and 6 deletions

View file

@ -34,4 +34,4 @@ debugprint = []
braille = []
gfx-testing = []
ditherpunk = []
default = []
default = ["gfx-testing"]

View file

@ -275,7 +275,11 @@ pub fn rectangle(fb: &mut LcdFB, rect: Rectangle, clip: Option<Rectangle>, xor:
// This is to make it annoying for someone using an XOR rectangle to synthesize inverted
// text on an otherwise untrusted dialog box (I suspect it's not impossible, but introduces
// a likelihood of drawing artifacts especially across translations and font size selections).
xor_pixel(fb, pixel.0.x, pixel.0.y);
if pixel.0.y % 20 < 10 {
xor_pixel(fb, pixel.0.x, pixel.0.y);
} else {
// don't allow XOR on some pixels to avoid this being used as a primitive to synthesize secure boxes
}
} else {
log::warn!("invalid xor rect width");
put_pixel(fb, pixel.0.x, pixel.0.y, pixel.1);

View file

@ -62,10 +62,16 @@ pub fn tests() {
tv.insertion = None;
tv.draw_border = false;
tv.busy_animation_state = Some(0);
for _ in 0..4800 {
gfx.draw_textview(&mut tv).unwrap();
gfx.flush().unwrap();
ticktimer.sleep_ms(100).unwrap();
for y in 0..30 {
gfx.draw_rectangle(checkbound).unwrap();
tv.bounds_hint = TextBounds::BoundingBox(Rectangle::new_coords(
10, 10 + y, 240, 30 + y
));
for _ in 0..5 {
gfx.draw_textview(&mut tv).unwrap();
gfx.flush().unwrap();
ticktimer.sleep_ms(100).unwrap();
}
}
}
Some(TestType::BoundingBox) => {