Screen trait

This commit is contained in:
Ryan Kennedy 2020-03-22 22:06:45 -05:00
parent c424b3134e
commit 51bdc82df9
4 changed files with 33 additions and 11 deletions

View file

@ -46,14 +46,18 @@ static BLANK_CHARACTER: ScreenCharacter = ScreenCharacter {
color: TextModeColor::new(Color16Bit::Yellow, Color16Bit::Black),
};
/// A helper trait used to interact with various vga text modes.
pub trait TextWriter {
/// Returns the width of the `TextWriter`.
/// A helper trait used to interact with various vga screens.
pub trait Screen {
/// Returns the width of the `Screen`.
fn get_width(&self) -> usize;
/// Returns the height of the `TextWriter`.
/// Returns the height of the `Screen`.
fn get_height(&self) -> usize;
/// Returns the size of the `Screen`.
fn get_size(&self) -> usize;
}
/// A helper trait used to interact with various vga text modes.
pub trait TextWriter: Screen {
/// Sets the graphics device to a video mode as determined by
/// the `TextWriter` implementation.
fn set_mode(&self);

View file

@ -1,4 +1,4 @@
use super::TextWriter;
use super::{Screen, TextWriter};
use crate::{
colors::DEFAULT_PALETTE,
fonts::TEXT_8X16_FONT,
@ -29,7 +29,7 @@ const HEIGHT: usize = 25;
#[derive(Default)]
pub struct Text40x25;
impl TextWriter for Text40x25 {
impl Screen for Text40x25 {
fn get_width(&self) -> usize {
WIDTH
}
@ -38,6 +38,12 @@ impl TextWriter for Text40x25 {
HEIGHT
}
fn get_size(&self) -> usize {
WIDTH * HEIGHT
}
}
impl TextWriter for Text40x25 {
/// Sets the graphics device to `VideoMode::Mode40x25`.
fn set_mode(&self) {
let mut vga = VGA.lock();

View file

@ -1,4 +1,4 @@
use super::TextWriter;
use super::{Screen, TextWriter};
use crate::{
colors::DEFAULT_PALETTE,
fonts::TEXT_8X8_FONT,
@ -29,7 +29,7 @@ const HEIGHT: usize = 50;
#[derive(Default)]
pub struct Text40x50;
impl TextWriter for Text40x50 {
impl Screen for Text40x50 {
fn get_width(&self) -> usize {
WIDTH
}
@ -38,6 +38,12 @@ impl TextWriter for Text40x50 {
HEIGHT
}
fn get_size(&self) -> usize {
WIDTH * HEIGHT
}
}
impl TextWriter for Text40x50 {
/// Sets the graphics device to `VideoMode::Mode40x50`.
fn set_mode(&self) {
let mut vga = VGA.lock();

View file

@ -1,4 +1,4 @@
use super::TextWriter;
use super::{Screen, TextWriter};
use crate::{
colors::DEFAULT_PALETTE,
fonts::TEXT_8X16_FONT,
@ -29,7 +29,7 @@ const HEIGHT: usize = 25;
#[derive(Default)]
pub struct Text80x25;
impl TextWriter for Text80x25 {
impl Screen for Text80x25 {
fn get_width(&self) -> usize {
WIDTH
}
@ -38,6 +38,12 @@ impl TextWriter for Text80x25 {
HEIGHT
}
fn get_size(&self) -> usize {
WIDTH * HEIGHT
}
}
impl TextWriter for Text80x25 {
fn set_mode(&self) {
let mut vga = VGA.lock();
vga.set_video_mode(VideoMode::Mode80x25);