forked from koniifer/ableos
74 lines
1.7 KiB
Rust
74 lines
1.7 KiB
Rust
use alloc::{boxed::Box, vec, vec::Vec};
|
|
use shadeable::pixel_format::{new_rgba64, Rgba64};
|
|
use vga::{colors::Color16, writers::GraphicsWriter};
|
|
|
|
use crate::vga_e::VGAE;
|
|
|
|
#[derive(Debug)]
|
|
pub struct ScreenSize {
|
|
pub x: usize,
|
|
pub y: usize,
|
|
}
|
|
impl ScreenSize {
|
|
pub fn new(x: usize, y: usize) -> Self {
|
|
Self { x, y }
|
|
}
|
|
}
|
|
|
|
pub enum GraphicsReturn {
|
|
Ok,
|
|
ImproperScreenSize,
|
|
}
|
|
|
|
pub struct ScreenBuffer {
|
|
pub size: ScreenSize,
|
|
pub clear_color: Rgba64,
|
|
pub buff: Box<[Rgba64]>, // Vec<Rgba64>,
|
|
}
|
|
|
|
impl ScreenBuffer {
|
|
// Add optional size later
|
|
pub fn new(x: usize, y: usize) -> Self {
|
|
Self {
|
|
size: ScreenSize::new(x, y),
|
|
clear_color: 0,
|
|
buff: vec![0u64; x * y].into_boxed_slice(),
|
|
}
|
|
}
|
|
#[inline]
|
|
pub fn set_pixel(&mut self, x: usize, y: usize, color: Rgba64) {
|
|
self.buff[y * self.size.y + x] = color;
|
|
}
|
|
|
|
pub fn clear(&mut self) {
|
|
self.buff = vec![0u64; self.buff.len()].into_boxed_slice();
|
|
}
|
|
|
|
pub fn blit(&mut self, _width: usize, _height: usize) {}
|
|
}
|
|
pub trait VgaBuffer {
|
|
fn copy_to_buffer(&self) -> GraphicsReturn;
|
|
}
|
|
impl VgaBuffer for ScreenBuffer {
|
|
fn copy_to_buffer(&self) -> GraphicsReturn {
|
|
let mode = VGAE.lock();
|
|
|
|
/*
|
|
if self.size.y * 640 + self.size.x > 640 * 480 {
|
|
return GraphicsReturn::ImproperScreenSize;
|
|
}
|
|
|
|
*/
|
|
|
|
for y in 0..self.size.y {
|
|
for x in 0..self.size.x {
|
|
use shadeable::pixel_format::into_vga_16;
|
|
let vga_color = into_vga_16(self.buff[y * self.size.y + x]);
|
|
mode.set_pixel(x, y, vga_color);
|
|
}
|
|
}
|
|
|
|
GraphicsReturn::Ok
|
|
}
|
|
}
|