video: Add a Color enum to make it easier to work with colors
This commit is contained in:
parent
ab4d34ecdb
commit
9902506264
@ -1,27 +1,51 @@
|
||||
#![allow(dead_code)]
|
||||
|
||||
use crate::bootboot::{BOOTBOOT, BOOTBOOT_FB};
|
||||
use crate::util::get_bootboot;
|
||||
|
||||
use BOOTBOOT_FB as FB;
|
||||
|
||||
pub fn put_pixel(x: u32, y: u32, color: u32) -> () {
|
||||
let boot: BOOTBOOT = get_bootboot();
|
||||
let ptr: u64 = FB + (boot.fb_scanline * y) as u64 + (x * 4) as u64;
|
||||
unsafe { *(ptr as *mut u32) = color };
|
||||
#[allow(dead_code)]
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
#[repr(u32)]
|
||||
pub enum Color {
|
||||
Black = 0x00000000,
|
||||
Blue = 0xff0000ff,
|
||||
Green = 0xff00ff00,
|
||||
Cyan = 0xff00ffff,
|
||||
Red = 0xffff0000,
|
||||
Magenta = 0xffff00ff,
|
||||
Brown = 0xff231709,
|
||||
LightGray = 0xffb9b8b5,
|
||||
DarkGray = 0xff808080,
|
||||
LightBlue = 0xff317ecc,
|
||||
LightGreen = 0xff6aab8e,
|
||||
LightCyan = 0xffe0ffff,
|
||||
LightRed = 0xffff7377,
|
||||
Pink = 0xffffc0cb,
|
||||
Yellow = 0xffffff00,
|
||||
White = 0xffffffff,
|
||||
}
|
||||
|
||||
pub fn draw_rect(x: u32, y: u32, width: u32, height: u32, color: u32) -> () {
|
||||
pub fn put_pixel(x: u32, y: u32, color: Color) -> () {
|
||||
let boot: BOOTBOOT = get_bootboot();
|
||||
let ptr: u64 = FB + (boot.fb_scanline * y) as u64 + (x * 4) as u64;
|
||||
unsafe { *(ptr as *mut u32) = color as u32 };
|
||||
}
|
||||
|
||||
pub fn draw_rect(x: u32, y: u32, width: u32, height: u32, color: Color) -> () {
|
||||
let boot: BOOTBOOT = get_bootboot();
|
||||
for i in y..(y + height)
|
||||
{
|
||||
let addr: u64 = FB + (boot.fb_scanline * i) as u64 + (x * 4) as u64;
|
||||
for ptr in (addr..(addr + (width*4) as u64)).step_by(4)
|
||||
{
|
||||
unsafe { *(ptr as *mut u32) = color };
|
||||
unsafe { *(ptr as *mut u32) = color as u32 };
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn clear(color: u32) -> () {
|
||||
pub fn clear(color: Color) -> () {
|
||||
let boot: BOOTBOOT = get_bootboot();
|
||||
draw_rect(0, 0, boot.fb_width, boot.fb_height, color)
|
||||
}
|
Loading…
Reference in New Issue
Block a user