Screen trait
This commit is contained in:
parent
c424b3134e
commit
51bdc82df9
|
@ -46,14 +46,18 @@ static BLANK_CHARACTER: ScreenCharacter = ScreenCharacter {
|
||||||
color: TextModeColor::new(Color16Bit::Yellow, Color16Bit::Black),
|
color: TextModeColor::new(Color16Bit::Yellow, Color16Bit::Black),
|
||||||
};
|
};
|
||||||
|
|
||||||
/// A helper trait used to interact with various vga text modes.
|
/// A helper trait used to interact with various vga screens.
|
||||||
pub trait TextWriter {
|
pub trait Screen {
|
||||||
/// Returns the width of the `TextWriter`.
|
/// Returns the width of the `Screen`.
|
||||||
fn get_width(&self) -> usize;
|
fn get_width(&self) -> usize;
|
||||||
|
/// Returns the height of the `Screen`.
|
||||||
/// Returns the height of the `TextWriter`.
|
|
||||||
fn get_height(&self) -> usize;
|
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
|
/// Sets the graphics device to a video mode as determined by
|
||||||
/// the `TextWriter` implementation.
|
/// the `TextWriter` implementation.
|
||||||
fn set_mode(&self);
|
fn set_mode(&self);
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use super::TextWriter;
|
use super::{Screen, TextWriter};
|
||||||
use crate::{
|
use crate::{
|
||||||
colors::DEFAULT_PALETTE,
|
colors::DEFAULT_PALETTE,
|
||||||
fonts::TEXT_8X16_FONT,
|
fonts::TEXT_8X16_FONT,
|
||||||
|
@ -29,7 +29,7 @@ const HEIGHT: usize = 25;
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Text40x25;
|
pub struct Text40x25;
|
||||||
|
|
||||||
impl TextWriter for Text40x25 {
|
impl Screen for Text40x25 {
|
||||||
fn get_width(&self) -> usize {
|
fn get_width(&self) -> usize {
|
||||||
WIDTH
|
WIDTH
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,12 @@ impl TextWriter for Text40x25 {
|
||||||
HEIGHT
|
HEIGHT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_size(&self) -> usize {
|
||||||
|
WIDTH * HEIGHT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TextWriter for Text40x25 {
|
||||||
/// Sets the graphics device to `VideoMode::Mode40x25`.
|
/// Sets the graphics device to `VideoMode::Mode40x25`.
|
||||||
fn set_mode(&self) {
|
fn set_mode(&self) {
|
||||||
let mut vga = VGA.lock();
|
let mut vga = VGA.lock();
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use super::TextWriter;
|
use super::{Screen, TextWriter};
|
||||||
use crate::{
|
use crate::{
|
||||||
colors::DEFAULT_PALETTE,
|
colors::DEFAULT_PALETTE,
|
||||||
fonts::TEXT_8X8_FONT,
|
fonts::TEXT_8X8_FONT,
|
||||||
|
@ -29,7 +29,7 @@ const HEIGHT: usize = 50;
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Text40x50;
|
pub struct Text40x50;
|
||||||
|
|
||||||
impl TextWriter for Text40x50 {
|
impl Screen for Text40x50 {
|
||||||
fn get_width(&self) -> usize {
|
fn get_width(&self) -> usize {
|
||||||
WIDTH
|
WIDTH
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,12 @@ impl TextWriter for Text40x50 {
|
||||||
HEIGHT
|
HEIGHT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_size(&self) -> usize {
|
||||||
|
WIDTH * HEIGHT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TextWriter for Text40x50 {
|
||||||
/// Sets the graphics device to `VideoMode::Mode40x50`.
|
/// Sets the graphics device to `VideoMode::Mode40x50`.
|
||||||
fn set_mode(&self) {
|
fn set_mode(&self) {
|
||||||
let mut vga = VGA.lock();
|
let mut vga = VGA.lock();
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use super::TextWriter;
|
use super::{Screen, TextWriter};
|
||||||
use crate::{
|
use crate::{
|
||||||
colors::DEFAULT_PALETTE,
|
colors::DEFAULT_PALETTE,
|
||||||
fonts::TEXT_8X16_FONT,
|
fonts::TEXT_8X16_FONT,
|
||||||
|
@ -29,7 +29,7 @@ const HEIGHT: usize = 25;
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
pub struct Text80x25;
|
pub struct Text80x25;
|
||||||
|
|
||||||
impl TextWriter for Text80x25 {
|
impl Screen for Text80x25 {
|
||||||
fn get_width(&self) -> usize {
|
fn get_width(&self) -> usize {
|
||||||
WIDTH
|
WIDTH
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,12 @@ impl TextWriter for Text80x25 {
|
||||||
HEIGHT
|
HEIGHT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn get_size(&self) -> usize {
|
||||||
|
WIDTH * HEIGHT
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TextWriter for Text80x25 {
|
||||||
fn set_mode(&self) {
|
fn set_mode(&self) {
|
||||||
let mut vga = VGA.lock();
|
let mut vga = VGA.lock();
|
||||||
vga.set_video_mode(VideoMode::Mode80x25);
|
vga.set_video_mode(VideoMode::Mode80x25);
|
||||||
|
|
Loading…
Reference in a new issue