not working

This commit is contained in:
2025-02-27 01:16:07 +00:00
parent ac0b47a45c
commit 3b6e272fd2
22 changed files with 448 additions and 50 deletions
+3 -3
View File
@@ -1,8 +1,8 @@
use crate::prelude::*;
mod frame;
mod render;
mod window;
pub mod frame;
pub mod render;
pub mod window;
pub trait Application {
type Output;
+26 -5
View File
@@ -1,19 +1,40 @@
use crate::{drivers::io::framebuffer::colour::Colour, std::maths::geometry::Vec2};
use super::{
render::{ColouredChar, RenderError},
window::Window,
window::{self, Window},
};
use alloc::vec::Vec;
use alloc::{vec, vec::Vec};
pub struct Frame<'f> {
data: Vec<Vec<ColouredChar>>,
data: Vec<Vec<Colour>>,
window: &'f Window,
}
impl Frame<'_> {
impl<'a> Frame<'a> {
pub fn new(window: &'a Window) -> Self {
Self {
data: vec![vec![Colour::Black; window.dimensions().x()]; window.dimensions().y()],
window,
}
}
pub fn render(&self) -> Result<(), RenderError> {
let data: Vec<&[ColouredChar]> = self.data.iter().map(|v| v.as_slice()).collect::<Vec<_>>();
let data: Vec<&[Colour]> = self.data.iter().map(|v| v.as_slice()).collect::<Vec<_>>();
self.window
.render(data.as_slice())
.map_err(|_| RenderError::Generic)
}
pub fn write_pixel(&mut self, x: usize, y: usize, color: Colour) -> Result<(), RenderError> {
if x >= self.window.dimensions().x() || y >= self.window.dimensions().y() {
return Err(RenderError::Generic);
}
self.data[y][x] = color;
Ok(())
}
pub const fn dimensions(&self) -> Vec2<usize> {
self.window.dimensions()
}
}
+14 -4
View File
@@ -1,6 +1,12 @@
use crate::{prelude::*, std::maths::geometry::Vec2};
use limine::framebuffer;
use super::render::{ColouredChar, RenderError};
use crate::{
drivers::io::framebuffer::{colour::Colour, display::FRAMEBUFFER_WRITER},
prelude::*,
std::maths::geometry::Vec2,
};
use super::render::RenderError;
pub struct Window {
dimensions: Vec2<usize>,
@@ -21,8 +27,12 @@ impl Window {
}
}
pub fn render(&self, _data: &[&[ColouredChar]]) -> Result<(), RenderError> {
todo!();
pub fn render(&self, _data: &[&[Colour]]) -> Result<(), RenderError> {
// TODO: error handling!! the kernel should return an error in some cases
if let Some(fb) = FRAMEBUFFER_WRITER.lock().as_mut() {
fb.render_frame(_data);
}
Ok(())
}
pub const fn is_bordered(&self) -> bool {
+59
View File
@@ -0,0 +1,59 @@
use alloc::vec::Vec;
use crate::{drivers::io::framebuffer::colour::Colour, resources::font::Font};
use super::{
application::{frame::Frame, render::RenderError},
maths::geometry::Vec2,
};
pub struct Writer<'a> {
font: &'a Font,
}
impl<'a> Writer<'a> {
pub const fn new(font: &'a Font) -> Self {
Self { font }
}
pub const fn set_font(&mut self, font: &'a Font) {
self.font = font;
}
pub const fn font_size(&self) -> Vec2<usize> {
Vec2::new(self.font.width(), self.font.height())
}
pub fn render_glyph(
&self,
frame: &mut Frame,
pos: Vec2<usize>,
c: u8,
scale: usize,
) -> Result<(), RenderError> {
// get a reference to the character glyph from the font.
let data: &[u8] = self.font.glyph_for(c as u16);
if pos.x() + self.font.width() * scale > frame.dimensions().x()
|| pos.y() + self.font.height() * scale > frame.dimensions().y()
{
return Err(RenderError::Generic);
}
for (row, line) in data.iter().enumerate().take(self.font.height()) {
for col in 0..self.font.width() {
let pixel_x: usize = pos.x() + col * scale;
let pixel_y: usize = pos.y() + row * scale;
if line & (0x80 >> col) != 0 {
for i in 0..scale {
for j in 0..scale {
frame.write_pixel(pixel_x + i, pixel_y + j, Colour::White)?;
}
}
}
}
}
Ok(())
}
}
+6
View File
@@ -71,3 +71,9 @@ impl<T: Coordinate> DivAssign<T> for Vec2<T> {
self.y /= rhs;
}
}
impl<T: Coordinate> From<Vec2<T>> for (T, T) {
fn from(value: Vec2<T>) -> Self {
(value.x, value.y)
}
}
+1
View File
@@ -1,3 +1,4 @@
pub mod application;
pub mod ascii;
pub mod io;
pub mod maths;