rename "BasicImage" to "GeneralBitmap"

this feels like a much, much, much better name to me. not sure what i
was thinking before!
This commit is contained in:
Gered 2023-03-09 11:57:07 -05:00
parent 2c2cf9dacd
commit 696ed0bfb3
4 changed files with 26 additions and 25 deletions

View file

@ -1,7 +1,8 @@
//! The purpose of this module is to provide "bit-depth-agnostic" Bitmap drawing capabilities. //! The purpose of this module is to provide "bit-depth-agnostic" Bitmap drawing capabilities. Basically access to
//! This isn't intended to be used all the time by applications, but is useful for certain functionality //! drawing operations that are common or shared across all different Bitmap implementations. This isn't intended to be
//! that we'd like to make generic across all available Bitmap types, where the drawing operations used //! used all the time by applications, but is useful for certain functionality that we'd like to make generic across
//! aren't actually specific to any specific pixel bit-depth. //! 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. //! 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; use crate::math::Rect;
// HACK: enum variant color arguments are sized to the max possible pixel type used across all supported bitmap variants // 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<PixelType: PrimInt + Unsigned>`) // right now. for some reason, making this enum generic (e.g. `GeneralBlitMethod<PixelType: PrimInt + Unsigned>`)
// resulted in some E0308 compile errors when trying to create enum variant values that contained args of the // 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. // 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, Solid,
Transparent(u32), 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 /// 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 /// 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. /// 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 PixelType: PrimInt + Unsigned;
type ErrorType: Error; type ErrorType: Error;
@ -82,20 +83,20 @@ pub trait BasicImage: Sized {
fn blit_region( fn blit_region(
&mut self, &mut self,
method: BasicBlitMethod, method: GeneralBlitMethod,
src: &Self, src: &Self,
src_region: &Rect, src_region: &Rect,
dest_x: i32, dest_x: i32,
dest_y: 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()); let src_region = Rect::new(0, 0, src.width(), src.height());
self.blit_region(method, src, &src_region, x, y); self.blit_region(method, src, &src_region, x, y);
} }
} }
impl BasicImage for indexed::Bitmap { impl GeneralBitmap for indexed::Bitmap {
type PixelType = u8; type PixelType = u8;
type ErrorType = indexed::BitmapError; type ErrorType = indexed::BitmapError;
@ -170,16 +171,16 @@ impl BasicImage for indexed::Bitmap {
fn blit_region( fn blit_region(
&mut self, &mut self,
method: BasicBlitMethod, method: GeneralBlitMethod,
src: &Self, src: &Self,
src_region: &Rect, src_region: &Rect,
dest_x: i32, dest_x: i32,
dest_y: 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 { let blit_method = match method {
BasicBlitMethod::Solid => indexed::BlitMethod::Solid, GeneralBlitMethod::Solid => indexed::BlitMethod::Solid,
BasicBlitMethod::Transparent(color) => indexed::BlitMethod::Transparent(color as u8), GeneralBlitMethod::Transparent(color) => indexed::BlitMethod::Transparent(color as u8),
}; };
self.blit_region(blit_method, src, src_region, dest_x, dest_y) self.blit_region(blit_method, src, src_region, dest_x, dest_y)
} }

View file

@ -14,7 +14,7 @@ pub enum BitmapAtlasError {
#[derive(Debug, Clone, Eq, PartialEq)] #[derive(Debug, Clone, Eq, PartialEq)]
pub struct BitmapAtlas<BitmapType> pub struct BitmapAtlas<BitmapType>
where where
BitmapType: BasicImage BitmapType: GeneralBitmap
{ {
bitmap: BitmapType, bitmap: BitmapType,
bounds: Rect, bounds: Rect,
@ -23,7 +23,7 @@ where
impl<BitmapType> BitmapAtlas<BitmapType> impl<BitmapType> BitmapAtlas<BitmapType>
where where
BitmapType: BasicImage BitmapType: GeneralBitmap
{ {
pub fn new(bitmap: BitmapType) -> Self { pub fn new(bitmap: BitmapType) -> Self {
let bounds = bitmap.full_bounds(); let bounds = bitmap.full_bounds();
@ -121,7 +121,7 @@ where
impl<BitmapType> Index<usize> for BitmapAtlas<BitmapType> impl<BitmapType> Index<usize> for BitmapAtlas<BitmapType>
where where
BitmapType: BasicImage { BitmapType: GeneralBitmap {
type Output = Rect; type Output = Rect;
#[inline] #[inline]

View file

@ -1,7 +1,7 @@
pub use self::basicimage::*; pub use self::bitmap::*;
pub use self::bitmapatlas::*; pub use self::bitmapatlas::*;
pub mod basicimage; pub mod bitmap;
pub mod bitmapatlas; pub mod bitmapatlas;
pub mod indexed; pub mod indexed;
pub mod rgb; pub mod rgb;

View file

@ -11,7 +11,7 @@ const DEFAULT_MOUSE_CURSOR_HEIGHT: usize = 16;
pub trait DefaultMouseCursorBitmaps<BitmapType> pub trait DefaultMouseCursorBitmaps<BitmapType>
where where
BitmapType: BasicImage BitmapType: GeneralBitmap
{ {
fn get_default() -> BitmapType; fn get_default() -> BitmapType;
} }
@ -21,7 +21,7 @@ where
#[derive(Debug)] #[derive(Debug)]
pub struct CustomMouseCursor<BitmapType> pub struct CustomMouseCursor<BitmapType>
where where
BitmapType: BasicImage BitmapType: GeneralBitmap
{ {
last_x: i32, last_x: i32,
last_y: i32, last_y: i32,
@ -35,7 +35,7 @@ where
impl<BitmapType> CustomMouseCursor<BitmapType> impl<BitmapType> CustomMouseCursor<BitmapType>
where where
Self: DefaultMouseCursorBitmaps<BitmapType>, Self: DefaultMouseCursorBitmaps<BitmapType>,
BitmapType: BasicImage BitmapType: GeneralBitmap
{ {
pub fn new() -> Self { pub fn new() -> Self {
let (cursor, cursor_background, cursor_hotspot_x, cursor_hotspot_y) = Self::get_default_mouse_cursor(); let (cursor, cursor_background, cursor_hotspot_x, cursor_hotspot_y) = Self::get_default_mouse_cursor();
@ -134,7 +134,7 @@ where
// preserve existing background first // preserve existing background first
self.cursor_background.blit_region( self.cursor_background.blit_region(
BasicBlitMethod::Solid, GeneralBlitMethod::Solid,
&dest, &dest,
&Rect::new(x, y, self.cursor.width(), self.cursor.height()), &Rect::new(x, y, self.cursor.width(), self.cursor.height()),
0, 0,
@ -142,7 +142,7 @@ where
); );
let color = 255; 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 /// 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(); 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 /// Updates current state from the given [`Mouse`] device's state, ensuring that subsequent calls to render