1
0
Fork 0
forked from koniifer/ableos
ableos-framebuffer/ableos/src/vga_e.rs

114 lines
3.1 KiB
Rust
Raw Normal View History

2022-01-18 06:15:51 -06:00
use {
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-07 10:31:47 -06:00
pub fn test_it_fucko() {
let mode = Graphics640x480x16::new();
mode.set_mode();
mode.clear_screen(Color16::Black);
mode.draw_line((80, 60), (80, 420), Color16::White);
mode.draw_line((80, 60), (540, 60), Color16::White);
{
let offset = 110;
mode.draw_character(offset - 15 - 4, 60 + 15 - 4, 'x', Color16::Red);
mode.draw_line(
(offset.try_into().unwrap(), 60),
(offset.try_into().unwrap(), 90),
Color16::White,
);
}
mode.draw_line((80, 420), (540, 420), Color16::White);
mode.draw_line((540, 420), (540, 60), Color16::White);
mode.draw_line((80, 90), (540, 90), Color16::White);
2022-01-07 10:31:47 -06:00
for (offset, character) in "ableOS".chars().enumerate() {
mode.draw_character(270 + offset * 8, 72, character, Color16::White)
}
}
pub trait GraphicsAPI {
2022-01-13 08:54:33 -06:00
fn add_shader() {}
2022-01-07 10:31:47 -06:00
}
2022-01-18 06:15:51 -06:00
pub fn draw_char(character: char, _offset: usize) {
2022-01-16 14:55:58 -06:00
let mode = *VGAE.lock();
2022-01-18 06:15:51 -06:00
let mut offset_x = VGAE_BUFF_OFFSET_X.lock();
let mut offset_y = VGAE_BUFF_OFFSET_Y.lock();
if *offset_x == 39 {
*offset_x = 0;
*offset_y += 1;
}
2022-01-16 19:42:11 -06:00
let font = FontRef::try_from_slice(include_bytes!(
2022-01-18 06:15:51 -06:00
"../../ableos/assets/fonts/unifont-14.0.01.ttf"
2022-01-16 19:42:11 -06:00
))
.unwrap();
2022-01-18 06:15:51 -06:00
let font2 = FontRef::try_from_slice(include_bytes!(
"../../ableos/assets/fonts/unifont_upper-14.0.01.ttf"
))
.unwrap();
let mut has_char = false;
for x in font.codepoint_ids() {
if x.1 == character {
has_char = true;
break;
}
}
let used_font;
match has_char {
true => used_font = font,
false => used_font = font2,
}
let font_scale = 1.6;
match character {
'\n' => {}
_ => {
let q_glyph: Glyph = used_font.glyph_id(character).with_scale_and_position(
20.0 * font_scale,
ab_glyph::point(
*offset_x as f32 * (10.0 * font_scale),
*offset_y as f32 + (18.0 * font_scale),
),
);
if let Some(q) = used_font.outline_glyph(q_glyph) {
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,
Color16::Green,
);
}
});
2022-01-16 14:55:58 -06:00
}
2022-01-18 06:15:51 -06:00
*offset_x += 1;
}
}
}