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

82 lines
2.1 KiB
Rust
Raw Normal View History

2022-01-16 14:55:58 -06:00
use ab_glyph::{Font, FontRef, Glyph};
2022-01-07 10:31:47 -06:00
use alloc::string::String;
2022-01-13 08:54:33 -06:00
use vga::{
colors::Color16,
writers::{Graphics640x480x16, GraphicsWriter},
};
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-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
}
pub struct Buffer {
2022-01-16 19:42:11 -06:00
pub label: String,
pub resolution: (u64, u64),
2022-01-07 10:31:47 -06:00
}
2022-01-16 14:55:58 -06:00
// #[deprecated(note = "Deprecated because you should use the damn graphics api")]
pub fn draw_char(character: char, offset: usize) {
let mode = *VGAE.lock();
2022-01-16 19:42:11 -06:00
let font = FontRef::try_from_slice(include_bytes!(
"../../ableos/assets/fonts/MesloLGS NF Regular.ttf"
))
.unwrap();
// Get a glyph for 'q' with a scale & position.
2022-01-16 19:42:11 -06:00
let q_glyph: Glyph = font.glyph_id(character).with_scale(20.0);
2022-01-16 19:42:11 -06:00
// Draw it.
if let Some(q) = font.outline_glyph(q_glyph) {
2022-01-16 19:42:11 -06:00
let scale = q.glyph().scale;
2022-01-16 14:55:58 -06:00
q.draw(|x, y, c| {
if c > 0.2 {
mode.set_pixel(
2022-01-16 19:42:11 -06:00
x as usize + (offset * scale.y as usize / 2),
2022-01-16 14:55:58 -06:00
//
y as usize,
2022-01-16 19:42:11 -06:00
Color16::LightGreen,
2022-01-16 14:55:58 -06:00
);
}
});
}
}