diff --git a/ableos/src/arch/uefi_86/mod.rs b/ableos/src/arch/uefi_86/mod.rs index 554f57d..ecf919e 100644 --- a/ableos/src/arch/uefi_86/mod.rs +++ b/ableos/src/arch/uefi_86/mod.rs @@ -176,8 +176,17 @@ impl<'b: 'c, 'c> FrameBuffWrap<'c> { unsafe fn write_pixel_bgr(&mut self, pixel_base: usize, rgb: [u8; 3]) { self.inner.write_value(pixel_base, [rgb[2], rgb[1], rgb[0]]); } +} - pub fn draw_pixel(&mut self, x: usize, y: usize, color: [u8; 3]) { +unsafe impl Sync for FrameBuffWrap<'_> {} +unsafe impl Send for FrameBuffWrap<'_> {} + +pub trait GraphicsAPI { + fn draw_pixel(&mut self, x: usize, y: usize, color: [u8; 3]); +} + +impl GraphicsAPI for FrameBuffWrap<'_> { + fn draw_pixel(&mut self, x: usize, y: usize, color: [u8; 3]) { let pixel_base = (y * self.mode_info.stride()) + x; match self.mode_info.pixel_format() { @@ -194,6 +203,3 @@ impl<'b: 'c, 'c> FrameBuffWrap<'c> { } } } - -unsafe impl Sync for FrameBuffWrap<'_> {} -unsafe impl Send for FrameBuffWrap<'_> {} diff --git a/ableos/src/graphics/mod.rs b/ableos/src/graphics/mod.rs index 0b978c9..0334fb0 100644 --- a/ableos/src/graphics/mod.rs +++ b/ableos/src/graphics/mod.rs @@ -139,10 +139,6 @@ impl ScreenBuffer { /// * `glyph` - the glyph to draw /// * `color` - the color of the glyph pub fn draw_char(&mut self, mut x: u32, mut y: u32, character: char, color: Rgba64) { - // trace!["Judy Hopps is thicc af"]; - // let mode = *VGAE.lock(); - // trace!["She got them bouncy bunny buns"]; - let basic_multingual_plane = FontRef::try_from_slice(include_bytes!( "../../../ableos/assets/fonts/unifont-14.0.01.ttf" )) diff --git a/ableos/src/graphics_api/inputs.rs b/ableos/src/graphics_api/inputs.rs new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/ableos/src/graphics_api/inputs.rs @@ -0,0 +1 @@ + diff --git a/ableos/src/graphics_api/mod.rs b/ableos/src/graphics_api/mod.rs new file mode 100644 index 0000000..8360676 --- /dev/null +++ b/ableos/src/graphics_api/mod.rs @@ -0,0 +1,9 @@ +pub mod inputs; +pub mod pixel_format; +pub mod positions; +pub mod text; +pub mod window; + +pub trait API { + fn init(); +} diff --git a/ableos/src/graphics_api/pixel_format.rs b/ableos/src/graphics_api/pixel_format.rs new file mode 100644 index 0000000..70075f7 --- /dev/null +++ b/ableos/src/graphics_api/pixel_format.rs @@ -0,0 +1,45 @@ +use core::ops::{BitAnd, BitOr, Shr}; + +pub type Rgba = u32; + +pub fn get_r(rgba: Rgba) -> u8 { + rgba.bitand(0xff_00_00_00).shr(0o30) as u8 +} +pub fn get_g(rgba: Rgba) -> u8 { + rgba.bitand(0xff_00_00).shr(0o20) as u8 +} + +pub fn get_b(rgba: Rgba) -> u8 { + rgba.bitand(0xff_00).shr(0o10) as u8 +} + +pub fn get_a(rgba: Rgba) -> u8 { + (rgba & 0xff) as u8 +} + +pub fn set_r(rgba: Rgba, r: u8) -> Rgba { + rgba.bitand(0x_00_ff_ff_ff).bitor((r as Rgba).shr(0o30)) +} + +pub fn set_g(rgba: Rgba, g: u8) -> Rgba { + rgba.bitand(0xff_00_ff_ff).bitor((g as Rgba).shr(0o20)) +} + +pub fn set_b(rgba: Rgba, b: u8) -> Rgba { + rgba.bitand(0xff_ff_00_ff).bitor((b as Rgba).shr(0o10)) +} + +pub fn set_a(rgba: Rgba, a: u8) -> Rgba { + rgba.bitand(0xff_ff_ff_00).bitor(a as Rgba) +} + +pub fn rgba_div(a: Rgba, b: Rgba) -> Rgba { + set_r(0, get_r(a) / get_r(b)) + | set_g(0, get_g(a) / get_g(b)) + | set_g(0, get_b(a) / get_b(b)) + | set_g(0, get_a(a) / get_a(b)) +} + +pub fn new_rgba(r: u8, g: u8, b: u8, a: u8) -> Rgba { + set_r(0, r) | set_g(0, g) | set_b(0, b) | set_a(0, a) +} diff --git a/ableos/src/graphics_api/positions.rs b/ableos/src/graphics_api/positions.rs new file mode 100644 index 0000000..ade4b18 --- /dev/null +++ b/ableos/src/graphics_api/positions.rs @@ -0,0 +1,23 @@ +#[derive(Debug, Clone, Copy, PartialEq, Eq)] +pub struct Position2D { + pub x: isize, + pub y: isize, +} + +impl Position2D { + pub fn new(x: isize, y: isize) -> Self { + Self { x, y } + } +} + +pub struct Position3D { + pub x: isize, + pub y: isize, + pub z: isize, +} + +impl Position3D { + pub fn new(x: isize, y: isize, z: isize) -> Self { + Self { x, y, z } + } +} diff --git a/ableos/src/graphics_api/window.rs b/ableos/src/graphics_api/window.rs new file mode 100644 index 0000000..4cd6a37 --- /dev/null +++ b/ableos/src/graphics_api/window.rs @@ -0,0 +1,38 @@ +use super::positions::Position2D; +use alloc::string::{String, ToString}; + +/// NOTE: If this is a zero then no framebuffer has been created for this window. +pub type FrameBufferID = u16; + +pub struct Window { + pub title: String, + pub resolution: Resolution, + pub position: Position2D, + pub is_fullscreen: bool, + pub framebuffer_id: FrameBufferID, + + pub cursor_position: Position2D, +} + +impl Window { + pub fn set_title(&mut self, title: &str) { + self.title = title.to_string(); + } + pub fn get_cursor_position(&self) -> Position2D { + self.cursor_position + } +} + +pub struct Resolution { + pub width: usize, + pub height: usize, +} + +pub enum CursorType { + Arrow, + IBeam, + Crosshair, + Hand, + HResize, + VResize, +} diff --git a/ableos/src/lib.rs b/ableos/src/lib.rs index 7fe6992..83458ad 100644 --- a/ableos/src/lib.rs +++ b/ableos/src/lib.rs @@ -37,6 +37,7 @@ pub mod arch; #[macro_use] pub mod print; +pub mod graphics_api; #[macro_use] pub extern crate log;