Cleaner blending of fonts. Do not draw cursor when disabled

This commit is contained in:
Jeremy Soller 2016-09-28 12:19:30 -06:00
parent 3cce378c59
commit 6911093696
2 changed files with 17 additions and 8 deletions

View file

@ -94,14 +94,23 @@ impl Display {
let off_y = y + (off_y as i32 + bb.min.y) as usize;
// There's still a possibility that the glyph clips the boundaries of the bitmap
if off_x < width && off_y < height {
let v_u = (v * 255.0) as u32;
if v_u > 0 {
let r = (((color >> 16) & 0xFF) * v_u)/255;
let g = (((color >> 8) & 0xFF) * v_u)/255;
let b = ((color & 0xFF) * v_u)/255;
let c = (r << 16) | (g << 8) | b;
if v > 0.0 {
let f_a = (v * 255.0) as u32;
let f_r = (((color >> 16) & 0xFF) * f_a)/255;
let f_g = (((color >> 8) & 0xFF) * f_a)/255;
let f_b = ((color & 0xFF) * f_a)/255;
let index = (off_y * width + off_x) as isize;
let bg = unsafe { *offscreen.offset(index) };
let b_a = 255 - f_a;
let b_r = (((bg >> 16) & 0xFF) * b_a)/255;
let b_g = (((bg >> 8) & 0xFF) * b_a)/255;
let b_b = ((bg & 0xFF) * b_a)/255;
let c = ((f_r + b_r) << 16) | ((f_g + b_g) << 8) | (f_b + b_b);
unsafe { *offscreen.offset(index) = c; }
unsafe { *onscreen.offset(index) = c; }
}

View file

@ -73,7 +73,7 @@ impl Scheme for DisplayScheme {
} else {
let mut display = self.display.borrow_mut();
let mut console = self.console.borrow_mut();
if console.x < console.w && console.y < console.h {
if console.cursor && console.x < console.w && console.y < console.h {
display.rect(console.x * 8, console.y * 16, 8, 16, 0);
}
console.write(buf, |event| {
@ -83,7 +83,7 @@ impl Scheme for DisplayScheme {
Event::Scroll { rows, color } => display.scroll(rows * 16, color.data)
}
});
if console.x < console.w && console.y < console.h {
if console.cursor && console.x < console.w && console.y < console.h {
display.rect(console.x * 8, console.y * 16, 8, 16, 0xFFFFFF);
}
Ok(buf.len())