From 696ed0bfb3e16a802b1c28e57f2b2749a2e5cbbe Mon Sep 17 00:00:00 2001 From: gered Date: Thu, 9 Mar 2023 11:57:07 -0500 Subject: [PATCH] rename "BasicImage" to "GeneralBitmap" this feels like a much, much, much better name to me. not sure what i was thinking before! --- .../src/graphics/{basicimage.rs => bitmap.rs} | 29 ++++++++++--------- ggdt/src/graphics/bitmapatlas.rs | 6 ++-- ggdt/src/graphics/mod.rs | 4 +-- ggdt/src/system/input_devices/mouse/cursor.rs | 12 ++++---- 4 files changed, 26 insertions(+), 25 deletions(-) rename ggdt/src/graphics/{basicimage.rs => bitmap.rs} (85%) diff --git a/ggdt/src/graphics/basicimage.rs b/ggdt/src/graphics/bitmap.rs similarity index 85% rename from ggdt/src/graphics/basicimage.rs rename to ggdt/src/graphics/bitmap.rs index 6c9ecb9..6601b70 100644 --- a/ggdt/src/graphics/basicimage.rs +++ b/ggdt/src/graphics/bitmap.rs @@ -1,7 +1,8 @@ -//! The purpose of this module is to provide "bit-depth-agnostic" Bitmap drawing capabilities. -//! This isn't intended to be used all the time by applications, but is useful for certain functionality -//! that we'd like to make generic across all available Bitmap types, where the drawing operations used -//! aren't actually specific to any specific pixel bit-depth. +//! The purpose of this module is to provide "bit-depth-agnostic" Bitmap drawing capabilities. Basically access to +//! drawing operations that are common or shared across all different Bitmap implementations. This isn't intended to be +//! used all the time by applications, but is useful for certain functionality that we'd like to make generic across +//! all available Bitmap types, where the drawing operations used aren't actually specific to any specific pixel +//! bit-depth. //! //! Only a subset of the most common Bitmap drawing operations will be provided here. @@ -13,10 +14,10 @@ use crate::graphics::indexed; use crate::math::Rect; // HACK: enum variant color arguments are sized to the max possible pixel type used across all supported bitmap variants -// right now. for some reason, making this enum generic (e.g. `BasicBlitMethod`) +// right now. for some reason, making this enum generic (e.g. `GeneralBlitMethod`) // resulted in some E0308 compile errors when trying to create enum variant values that contained args of the // generic type. i could not find a solution to this. so i'll just do this hack approach for now. ugh. -pub enum BasicBlitMethod { +pub enum GeneralBlitMethod { Solid, Transparent(u32), } @@ -24,7 +25,7 @@ pub enum BasicBlitMethod { /// Trait that provides "bit-depth-agnostic" access to bitmap drawing operations. This is useful for implementing /// drawing functionality that is to be made generic across all supported bitmap types and is not specific to /// any one pixel-depth. Note that this does not provide cross-bit-depth drawing support. -pub trait BasicImage: Sized { +pub trait GeneralBitmap: Sized { type PixelType: PrimInt + Unsigned; type ErrorType: Error; @@ -82,20 +83,20 @@ pub trait BasicImage: Sized { fn blit_region( &mut self, - method: BasicBlitMethod, + method: GeneralBlitMethod, src: &Self, src_region: &Rect, dest_x: i32, dest_y: i32 ); - fn blit(&mut self, method: BasicBlitMethod, src: &Self, x: i32, y: i32) { + fn blit(&mut self, method: GeneralBlitMethod, src: &Self, x: i32, y: i32) { let src_region = Rect::new(0, 0, src.width(), src.height()); self.blit_region(method, src, &src_region, x, y); } } -impl BasicImage for indexed::Bitmap { +impl GeneralBitmap for indexed::Bitmap { type PixelType = u8; type ErrorType = indexed::BitmapError; @@ -170,16 +171,16 @@ impl BasicImage for indexed::Bitmap { fn blit_region( &mut self, - method: BasicBlitMethod, + method: GeneralBlitMethod, src: &Self, src_region: &Rect, dest_x: i32, dest_y: i32 ) { - // HACK: pixel/color value downcasting. see "HACK" comment above BasicBlitMethod type def + // HACK: pixel/color value downcasting. see "HACK" comment above GeneralBlitMethod type def let blit_method = match method { - BasicBlitMethod::Solid => indexed::BlitMethod::Solid, - BasicBlitMethod::Transparent(color) => indexed::BlitMethod::Transparent(color as u8), + GeneralBlitMethod::Solid => indexed::BlitMethod::Solid, + GeneralBlitMethod::Transparent(color) => indexed::BlitMethod::Transparent(color as u8), }; self.blit_region(blit_method, src, src_region, dest_x, dest_y) } diff --git a/ggdt/src/graphics/bitmapatlas.rs b/ggdt/src/graphics/bitmapatlas.rs index 754d497..976a65c 100644 --- a/ggdt/src/graphics/bitmapatlas.rs +++ b/ggdt/src/graphics/bitmapatlas.rs @@ -14,7 +14,7 @@ pub enum BitmapAtlasError { #[derive(Debug, Clone, Eq, PartialEq)] pub struct BitmapAtlas where - BitmapType: BasicImage + BitmapType: GeneralBitmap { bitmap: BitmapType, bounds: Rect, @@ -23,7 +23,7 @@ where impl BitmapAtlas where - BitmapType: BasicImage + BitmapType: GeneralBitmap { pub fn new(bitmap: BitmapType) -> Self { let bounds = bitmap.full_bounds(); @@ -121,7 +121,7 @@ where impl Index for BitmapAtlas where - BitmapType: BasicImage { + BitmapType: GeneralBitmap { type Output = Rect; #[inline] diff --git a/ggdt/src/graphics/mod.rs b/ggdt/src/graphics/mod.rs index 5003e3d..e3ef640 100644 --- a/ggdt/src/graphics/mod.rs +++ b/ggdt/src/graphics/mod.rs @@ -1,7 +1,7 @@ -pub use self::basicimage::*; +pub use self::bitmap::*; pub use self::bitmapatlas::*; -pub mod basicimage; +pub mod bitmap; pub mod bitmapatlas; pub mod indexed; pub mod rgb; diff --git a/ggdt/src/system/input_devices/mouse/cursor.rs b/ggdt/src/system/input_devices/mouse/cursor.rs index 8536b3a..97d0799 100644 --- a/ggdt/src/system/input_devices/mouse/cursor.rs +++ b/ggdt/src/system/input_devices/mouse/cursor.rs @@ -11,7 +11,7 @@ const DEFAULT_MOUSE_CURSOR_HEIGHT: usize = 16; pub trait DefaultMouseCursorBitmaps where - BitmapType: BasicImage + BitmapType: GeneralBitmap { fn get_default() -> BitmapType; } @@ -21,7 +21,7 @@ where #[derive(Debug)] pub struct CustomMouseCursor where - BitmapType: BasicImage + BitmapType: GeneralBitmap { last_x: i32, last_y: i32, @@ -35,7 +35,7 @@ where impl CustomMouseCursor where Self: DefaultMouseCursorBitmaps, - BitmapType: BasicImage + BitmapType: GeneralBitmap { pub fn new() -> Self { let (cursor, cursor_background, cursor_hotspot_x, cursor_hotspot_y) = Self::get_default_mouse_cursor(); @@ -134,7 +134,7 @@ where // preserve existing background first self.cursor_background.blit_region( - BasicBlitMethod::Solid, + GeneralBlitMethod::Solid, &dest, &Rect::new(x, y, self.cursor.width(), self.cursor.height()), 0, @@ -142,7 +142,7 @@ where ); let color = 255; - dest.blit(BasicBlitMethod::Transparent(color), &self.cursor, x, y); + dest.blit(GeneralBlitMethod::Transparent(color), &self.cursor, x, y); } /// Restores the original destination bitmap contents where the mouse cursor bitmap was @@ -162,7 +162,7 @@ where } let (x, y) = self.get_cursor_render_position(); - dest.blit(BasicBlitMethod::Solid, &self.cursor_background, x, y); + dest.blit(GeneralBlitMethod::Solid, &self.cursor_background, x, y); } /// Updates current state from the given [`Mouse`] device's state, ensuring that subsequent calls to render