graphics api
This commit is contained in:
parent
7f8a7e92a5
commit
b7c9feff26
|
@ -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<'_> {}
|
||||
|
|
|
@ -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"
|
||||
))
|
||||
|
|
1
ableos/src/graphics_api/inputs.rs
Normal file
1
ableos/src/graphics_api/inputs.rs
Normal file
|
@ -0,0 +1 @@
|
|||
|
9
ableos/src/graphics_api/mod.rs
Normal file
9
ableos/src/graphics_api/mod.rs
Normal file
|
@ -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();
|
||||
}
|
45
ableos/src/graphics_api/pixel_format.rs
Normal file
45
ableos/src/graphics_api/pixel_format.rs
Normal file
|
@ -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)
|
||||
}
|
23
ableos/src/graphics_api/positions.rs
Normal file
23
ableos/src/graphics_api/positions.rs
Normal file
|
@ -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 }
|
||||
}
|
||||
}
|
38
ableos/src/graphics_api/window.rs
Normal file
38
ableos/src/graphics_api/window.rs
Normal file
|
@ -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,
|
||||
}
|
|
@ -37,6 +37,7 @@ pub mod arch;
|
|||
|
||||
#[macro_use]
|
||||
pub mod print;
|
||||
pub mod graphics_api;
|
||||
|
||||
#[macro_use]
|
||||
pub extern crate log;
|
||||
|
|
Loading…
Reference in a new issue