From 51bdc82df9cb81dfca69970def70e814fbddca1a Mon Sep 17 00:00:00 2001 From: Ryan Kennedy Date: Sun, 22 Mar 2020 22:06:45 -0500 Subject: [PATCH] Screen trait --- src/writers/mod.rs | 14 +++++++++----- src/writers/text_40x25.rs | 10 ++++++++-- src/writers/text_40x50.rs | 10 ++++++++-- src/writers/text_80x25.rs | 10 ++++++++-- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/writers/mod.rs b/src/writers/mod.rs index 1154faa..5dc74af 100644 --- a/src/writers/mod.rs +++ b/src/writers/mod.rs @@ -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); diff --git a/src/writers/text_40x25.rs b/src/writers/text_40x25.rs index 29f9cd8..545a10a 100644 --- a/src/writers/text_40x25.rs +++ b/src/writers/text_40x25.rs @@ -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(); diff --git a/src/writers/text_40x50.rs b/src/writers/text_40x50.rs index e7a45c5..02766b9 100644 --- a/src/writers/text_40x50.rs +++ b/src/writers/text_40x50.rs @@ -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(); diff --git a/src/writers/text_80x25.rs b/src/writers/text_80x25.rs index 9929755..ed0d473 100644 --- a/src/writers/text_80x25.rs +++ b/src/writers/text_80x25.rs @@ -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);