From babb70cf30c6778e88d674af519eee35a4b7b858 Mon Sep 17 00:00:00 2001 From: gered Date: Fri, 14 Apr 2023 12:19:28 -0400 Subject: [PATCH] add more useful methods to GeneralBitmap trait and impls --- ggdt/src/graphics/bitmap/general.rs | 45 +++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/ggdt/src/graphics/bitmap/general.rs b/ggdt/src/graphics/bitmap/general.rs index ff257cb..181794c 100644 --- a/ggdt/src/graphics/bitmap/general.rs +++ b/ggdt/src/graphics/bitmap/general.rs @@ -11,6 +11,7 @@ use crate::graphics::bitmap::indexed::IndexedBitmap; use crate::graphics::bitmap::rgb::blit::RgbaBlitMethod; use crate::graphics::bitmap::rgb::RgbaBitmap; use crate::graphics::bitmap::BitmapError; +use crate::graphics::font::{Font, FontRenderOpts}; use crate::graphics::Pixel; use crate::math::rect::Rect; @@ -35,6 +36,12 @@ pub trait GeneralBitmap: Sized + Clone { /// Returns the height of the bitmap in pixels. fn height(&self) -> u32; + /// Returns the right x coordinate of the bitmap. + fn right(&self) -> u32; + + /// Returns the bottom x coordinate of the bitmap. + fn bottom(&self) -> u32; + /// Returns the current clipping region set on this bitmap. fn clip_region(&self) -> &Rect; @@ -81,6 +88,12 @@ pub trait GeneralBitmap: Sized + Clone { /// Draws a filled circle formed by the center point and radius given. fn filled_circle(&mut self, center_x: i32, center_y: i32, radius: u32, color: Self::PixelType); + /// Renders a single character using the font given. + fn print_char(&mut self, ch: char, x: i32, y: i32, opts: FontRenderOpts, font: &T); + + /// Renders the string of text using the font given. + fn print_string(&mut self, text: &str, x: i32, y: i32, opts: FontRenderOpts, font: &T); + fn blit_region( &mut self, method: GeneralBlitMethod, @@ -111,6 +124,14 @@ impl GeneralBitmap for IndexedBitmap { self.height() } + fn right(&self) -> u32 { + self.right() + } + + fn bottom(&self) -> u32 { + self.bottom() + } + fn clip_region(&self) -> &Rect { self.clip_region() } @@ -159,6 +180,14 @@ impl GeneralBitmap for IndexedBitmap { self.filled_circle(center_x, center_y, radius, color) } + fn print_char(&mut self, ch: char, x: i32, y: i32, opts: FontRenderOpts, font: &T) { + self.print_char(ch, x, y, opts, font); + } + + fn print_string(&mut self, text: &str, x: i32, y: i32, opts: FontRenderOpts, font: &T) { + self.print_string(text, x, y, opts, font); + } + fn blit_region( &mut self, method: GeneralBlitMethod, @@ -190,6 +219,14 @@ impl GeneralBitmap for RgbaBitmap { self.height() } + fn right(&self) -> u32 { + self.right() + } + + fn bottom(&self) -> u32 { + self.bottom() + } + fn clip_region(&self) -> &Rect { self.clip_region() } @@ -238,6 +275,14 @@ impl GeneralBitmap for RgbaBitmap { self.filled_circle(center_x, center_y, radius, color) } + fn print_char(&mut self, ch: char, x: i32, y: i32, opts: FontRenderOpts, font: &T) { + self.print_char(ch, x, y, opts, font); + } + + fn print_string(&mut self, text: &str, x: i32, y: i32, opts: FontRenderOpts, font: &T) { + self.print_string(text, x, y, opts, font); + } + fn blit_region( &mut self, method: GeneralBlitMethod,