diff --git a/ggdt/src/graphics/basicimage.rs b/ggdt/src/graphics/basicimage.rs index 186ed07..4c2aa03 100644 --- a/ggdt/src/graphics/basicimage.rs +++ b/ggdt/src/graphics/basicimage.rs @@ -19,69 +19,76 @@ where PixelType: PrimInt + Unsigned { /// 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 -where PixelType: PrimInt + Unsigned { +pub trait BasicImage { + type PixelType: PrimInt + Unsigned; + /// Returns the width of the bitmap in pixels. fn width(&self) -> u32; /// Returns the height of the bitmap in pixels. fn height(&self) -> u32; + /// Returns a rect representing the full bitmap boundaries, ignoring the current clipping + /// region set on this bitmap. + fn full_bounds(&self) -> Rect; + /// Returns the bit-depth of this bitmap's pixels. fn bpp(&self) -> usize { - std::mem::size_of::() * 8 + std::mem::size_of::() * 8 } /// Fills the entire bitmap with the given color. - fn clear(&mut self, color: PixelType); + fn clear(&mut self, color: Self::PixelType); /// Sets the pixel at the given coordinates to the color specified. If the coordinates lie /// outside of the bitmaps clipping region, no pixels will be changed. - fn set_pixel(&mut self, x: i32, y: i32, color: PixelType); + fn set_pixel(&mut self, x: i32, y: i32, color: Self::PixelType); /// Gets the pixel at the given coordinates. If the coordinates lie outside of the bitmaps /// clipping region, None is returned. - fn get_pixel(&self, x: i32, y: i32) -> Option; + fn get_pixel(&self, x: i32, y: i32) -> Option; /// Draws a line from x1,y1 to x2,y2. - fn line(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: PixelType); + fn line(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: Self::PixelType); /// Draws a horizontal line from x1,y to x2,y. - fn horiz_line(&mut self, x1: i32, x2: i32, y: i32, color: PixelType); + fn horiz_line(&mut self, x1: i32, x2: i32, y: i32, color: Self::PixelType); /// Draws a vertical line from x,y1 to x,y2. - fn vert_line(&mut self, x: i32, y1: i32, y2: i32, color: PixelType); + fn vert_line(&mut self, x: i32, y1: i32, y2: i32, color: Self::PixelType); /// Draws an empty box (rectangle) using the points x1,y1 and x2,y2 to form the box to be /// drawn, assuming they are specifying the top-left and bottom-right corners respectively. - fn rect(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: PixelType); + fn rect(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: Self::PixelType); /// Draws a filled box (rectangle) using the points x1,y1 and x2,y2 to form the box to be /// drawn, assuming they are specifying the top-left and bottom-right corners respectively. - fn filled_rect(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: PixelType); + fn filled_rect(&mut self, x1: i32, y1: i32, x2: i32, y2: i32, color: Self::PixelType); /// Draws the outline of a circle formed by the center point and radius given. - fn circle(&mut self, center_x: i32, center_y: i32, radius: u32, color: PixelType); + fn circle(&mut self, center_x: i32, center_y: i32, radius: u32, color: Self::PixelType); /// 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: PixelType); + fn filled_circle(&mut self, center_x: i32, center_y: i32, radius: u32, color: Self::PixelType); fn blit_region( &mut self, - method: BasicBlitMethod, + method: BasicBlitMethod, 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: BasicBlitMethod, 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 BasicImage for indexed::Bitmap { + type PixelType = u8; + #[inline] fn width(&self) -> u32 { self.width()