From cf8e7950a886e032733ccb82fd466a28991cca5c Mon Sep 17 00:00:00 2001 From: Jeremy Soller Date: Thu, 10 Nov 2016 10:35:43 -0700 Subject: [PATCH] Invert on cursor --- drivers/vesad/src/display.rs | 32 ++++++++++++++++++++++++++++++++ drivers/vesad/src/screen/text.rs | 6 ++---- 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/drivers/vesad/src/display.rs b/drivers/vesad/src/display.rs index a21be24..2d5f24e 100644 --- a/drivers/vesad/src/display.rs +++ b/drivers/vesad/src/display.rs @@ -103,6 +103,38 @@ impl Display { } } + /// Invert a rectangle + pub fn invert(&mut self, x: usize, y: usize, w: usize, h: usize) { + let start_y = cmp::min(self.height - 1, y); + let end_y = cmp::min(self.height, y + h); + + let start_x = cmp::min(self.width - 1, x); + let len = cmp::min(self.width, x + w) - start_x; + + let mut offscreen_ptr = self.offscreen.as_mut_ptr() as usize; + + let stride = self.width * 4; + + let offset = y * stride + start_x * 4; + offscreen_ptr += offset; + + let mut rows = end_y - start_y; + while rows > 0 { + let mut row_ptr = offscreen_ptr; + let mut cols = len; + while cols > 0 { + unsafe { + let color = *(row_ptr as *mut u32); + *(row_ptr as *mut u32) = !color; + } + row_ptr += 4; + cols -= 1; + } + offscreen_ptr += stride; + rows -= 1; + } + } + /// Draw a character #[cfg(not(feature="rusttype"))] pub fn char(&mut self, x: usize, y: usize, character: char, color: u32, _bold: bool, _italic: bool) { diff --git a/drivers/vesad/src/screen/text.rs b/drivers/vesad/src/screen/text.rs index 6d267d7..dbf7927 100644 --- a/drivers/vesad/src/screen/text.rs +++ b/drivers/vesad/src/screen/text.rs @@ -163,8 +163,7 @@ impl Screen for TextScreen { if self.console.cursor && self.console.x < self.console.w && self.console.y < self.console.h { let x = self.console.x; let y = self.console.y; - let color = self.console.background; - self.display.rect(x * 8, y * 16, 8, 16, color.data); + self.display.invert(x * 8, y * 16, 8, 16); self.changed.insert(y); } @@ -196,8 +195,7 @@ impl Screen for TextScreen { if self.console.cursor && self.console.x < self.console.w && self.console.y < self.console.h { let x = self.console.x; let y = self.console.y; - let color = self.console.foreground; - self.display.rect(x * 8, y * 16, 8, 16, color.data); + self.display.invert(x * 8, y * 16, 8, 16); self.changed.insert(y); }