2022-01-26 19:43:03 -06:00
|
|
|
use shadeable::pixel_format::Rgba64;
|
|
|
|
|
|
|
|
use crate::SCREEN_BUFFER;
|
|
|
|
|
2022-01-18 06:15:51 -06:00
|
|
|
use {
|
2022-01-26 23:38:51 -06:00
|
|
|
ab_glyph::{Font, FontRef, Glyph},
|
|
|
|
vga::{
|
|
|
|
colors::Color16,
|
|
|
|
writers::{Graphics640x480x16, GraphicsWriter},
|
|
|
|
},
|
2022-01-13 08:54:33 -06:00
|
|
|
};
|
2022-01-07 10:31:47 -06:00
|
|
|
|
2022-01-16 14:55:58 -06:00
|
|
|
lazy_static::lazy_static! {
|
|
|
|
pub static ref VGAE: spin::Mutex<Graphics640x480x16> = {
|
|
|
|
let xyz = Graphics640x480x16::new();
|
|
|
|
xyz.set_mode();
|
|
|
|
spin::Mutex::new(xyz)
|
|
|
|
};
|
2022-01-18 06:15:51 -06:00
|
|
|
pub static ref VGAE_BUFF_OFFSET_X: spin::Mutex<u8> = spin::Mutex::new(0);
|
|
|
|
pub static ref VGAE_BUFF_OFFSET_Y: spin::Mutex<u8> = spin::Mutex::new(0);
|
2022-01-16 14:55:58 -06:00
|
|
|
}
|
2022-01-18 06:15:51 -06:00
|
|
|
|
2022-01-27 01:00:25 -06:00
|
|
|
const FONT_SCALE: f32 = 1.6;
|
|
|
|
|
2022-01-26 19:43:03 -06:00
|
|
|
/// Draw a glyph on the screen at the given position
|
|
|
|
///
|
|
|
|
/// # Arguments
|
|
|
|
/// * `x` - the x position of the glyph
|
|
|
|
/// * `y` - the y position of the glyph
|
|
|
|
/// * `glyph` - the glyph to draw
|
|
|
|
/// * `color` - the color of the glyph
|
|
|
|
pub fn draw_char(x: u8, y: u8, character: char, color: Rgba64) {
|
2022-01-26 23:38:51 -06:00
|
|
|
// let mode = *VGAE.lock();
|
|
|
|
let mut mode = SCREEN_BUFFER.lock();
|
2022-01-18 06:15:51 -06:00
|
|
|
|
2022-01-27 01:00:25 -06:00
|
|
|
let basic_multingual_plane = FontRef::try_from_slice(include_bytes!(
|
2022-01-26 23:38:51 -06:00
|
|
|
"../../ableos/assets/fonts/unifont-14.0.01.ttf"
|
|
|
|
))
|
|
|
|
.unwrap();
|
2022-01-18 06:15:51 -06:00
|
|
|
|
2022-01-27 01:00:25 -06:00
|
|
|
let supplementary_multilingual_plane = FontRef::try_from_slice(include_bytes!(
|
2022-01-26 23:38:51 -06:00
|
|
|
"../../ableos/assets/fonts/unifont_upper-14.0.01.ttf"
|
|
|
|
))
|
|
|
|
.unwrap();
|
2022-01-18 06:15:51 -06:00
|
|
|
|
2022-01-27 01:00:25 -06:00
|
|
|
// let mut has_char = false;
|
|
|
|
// for x in font.codepoint_ids() {
|
|
|
|
// if x.1 == character {
|
|
|
|
// has_char = true;
|
|
|
|
// break;
|
|
|
|
// }
|
|
|
|
// }
|
2022-01-18 06:15:51 -06:00
|
|
|
|
2022-01-27 01:00:25 -06:00
|
|
|
let is_in_basic_multilingual_plane = character as u32 <= 0xffff;
|
2022-01-18 08:30:09 -06:00
|
|
|
|
2022-01-27 01:00:25 -06:00
|
|
|
let plane = match is_in_basic_multilingual_plane {
|
|
|
|
true => basic_multingual_plane,
|
|
|
|
false => supplementary_multilingual_plane,
|
|
|
|
};
|
2022-01-18 08:30:09 -06:00
|
|
|
|
2022-01-26 23:38:51 -06:00
|
|
|
match character {
|
|
|
|
'\n' => {}
|
|
|
|
_ => {
|
2022-01-27 01:00:25 -06:00
|
|
|
let q_glyph: Glyph = plane.glyph_id(character).with_scale_and_position(
|
|
|
|
20.0 * FONT_SCALE,
|
|
|
|
ab_glyph::point(10.0 * FONT_SCALE, 18.0 * FONT_SCALE),
|
2022-01-26 23:38:51 -06:00
|
|
|
);
|
2022-01-18 06:15:51 -06:00
|
|
|
|
2022-01-27 01:00:25 -06:00
|
|
|
if let Some(q) = plane.outline_glyph(q_glyph) {
|
2022-01-26 23:38:51 -06:00
|
|
|
q.draw(|x, y, c| {
|
|
|
|
if c > 0.015 {
|
|
|
|
let corner = q.px_bounds().min;
|
|
|
|
mode.set_pixel(
|
|
|
|
x as usize + corner.x as usize,
|
|
|
|
y as usize + corner.y as usize,
|
|
|
|
color,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-01-16 09:23:19 -06:00
|
|
|
}
|
2022-01-27 01:00:25 -06:00
|
|
|
|
2022-01-26 22:06:04 -06:00
|
|
|
/// Converts a number to ... i forgor 💀
|
2022-01-18 08:30:09 -06:00
|
|
|
pub fn num_to_vga16(num: u8) -> Color16 {
|
2022-01-26 23:38:51 -06:00
|
|
|
use Color16::*;
|
|
|
|
match num {
|
|
|
|
0 => Black,
|
|
|
|
1 => Blue,
|
|
|
|
2 => Green,
|
|
|
|
3 => Cyan,
|
|
|
|
4 => Red,
|
|
|
|
5 => Magenta,
|
|
|
|
6 => Brown,
|
|
|
|
7 => LightGrey,
|
|
|
|
8 => DarkGrey,
|
|
|
|
9 => LightBlue,
|
|
|
|
10 => LightGreen,
|
|
|
|
11 => LightCyan,
|
|
|
|
12 => LightRed,
|
|
|
|
13 => Pink,
|
|
|
|
14 => Yellow,
|
|
|
|
15 => White,
|
|
|
|
// NOTE: Leasve the in
|
|
|
|
_ => Color16::Pink,
|
|
|
|
}
|
2022-01-18 08:30:09 -06:00
|
|
|
}
|