From 469325b52ac233e5dfc1a6c0f9d1c611767e4e96 Mon Sep 17 00:00:00 2001 From: Able Date: Mon, 5 Dec 2022 05:18:32 -0600 Subject: [PATCH] update the graphics lib --- Cargo.lock | 2 +- libraries/able_graphics_library/Cargo.toml | 2 +- .../able_graphics_library/src/display.rs | 33 +++++++++++++++++++ .../able_graphics_library/src/framebuffer.rs | 2 ++ libraries/able_graphics_library/src/lib.rs | 7 +++- libraries/able_graphics_library/src/vertex.rs | 2 ++ 6 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 libraries/able_graphics_library/src/display.rs diff --git a/Cargo.lock b/Cargo.lock index c7224f1..5560b55 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -4,7 +4,7 @@ version = 3 [[package]] name = "able_graphics_library" -version = "0.1.0" +version = "0.1.1" dependencies = [ "versioning", ] diff --git a/libraries/able_graphics_library/Cargo.toml b/libraries/able_graphics_library/Cargo.toml index 3859e06..860311b 100644 --- a/libraries/able_graphics_library/Cargo.toml +++ b/libraries/able_graphics_library/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "able_graphics_library" -version = "0.1.0" +version = "0.1.1" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/libraries/able_graphics_library/src/display.rs b/libraries/able_graphics_library/src/display.rs new file mode 100644 index 0000000..1dbd744 --- /dev/null +++ b/libraries/able_graphics_library/src/display.rs @@ -0,0 +1,33 @@ +pub enum DisplayError { + InvalidFormat, + InvalidWidth, + InvalidHeight, + InvalidBPP, + InvalidFPS, +} + +pub fn parse_display_string(s: &str) -> Result<(u32, u32, u32, u32), DisplayError> { + let parts: Vec<&str> = s.split('x').collect(); + if parts.len() != 3 { + return Err(DisplayError::InvalidFormat); + } + + let width = parts[0] + .parse::() + .map_err(|_| DisplayError::InvalidWidth)?; + let height = parts[1] + .parse::() + .map_err(|_| DisplayError::InvalidHeight)?; + let bits = parts[2].split('@').collect(); + if bits.len() != 2 { + return Err(DisplayError::InvalidFormat); + } + + let bpp = bits[0] + .parse::() + .map_err(|_| DisplayError::InvalidBPP)?; + let fps = bits[1] + .parse::() + .map_err(|_| DisplayError::InvalidFPS)?; + Ok((width, height, bpp, fps)) +} diff --git a/libraries/able_graphics_library/src/framebuffer.rs b/libraries/able_graphics_library/src/framebuffer.rs index 241ecd6..aa3d6ed 100644 --- a/libraries/able_graphics_library/src/framebuffer.rs +++ b/libraries/able_graphics_library/src/framebuffer.rs @@ -1,5 +1,7 @@ use core::ptr; +use alloc::vec::Vec; + use crate::color::Color3; /// NOTE: Assumes the layout of RGBA pub struct FrameBuffer { diff --git a/libraries/able_graphics_library/src/lib.rs b/libraries/able_graphics_library/src/lib.rs index 8ddbcf4..77c2b09 100644 --- a/libraries/able_graphics_library/src/lib.rs +++ b/libraries/able_graphics_library/src/lib.rs @@ -1,3 +1,8 @@ +#![no_std] + +#[macro_use] +extern crate alloc; + pub mod buffer; pub mod color; pub mod commands; @@ -8,5 +13,5 @@ pub mod vertex; pub const VERSION: versioning::Version = versioning::Version { major: 0, minor: 1, - patch: 0, + patch: 1, }; diff --git a/libraries/able_graphics_library/src/vertex.rs b/libraries/able_graphics_library/src/vertex.rs index 873fd80..9148ef9 100644 --- a/libraries/able_graphics_library/src/vertex.rs +++ b/libraries/able_graphics_library/src/vertex.rs @@ -1,3 +1,5 @@ +use alloc::vec::Vec; + use crate::{ color::Color3, types::{Float2Array, Float3Array, Position3},