Struct playdate_graphics::bitmap::Bitmap
source · pub struct Bitmap<Api: Api = Default, const FREE_ON_DROP: bool = true>(/* private fields */);Implementations§
source§impl<Api: Api + Copy> Bitmap<Api, true>
impl<Api: Api + Copy> Bitmap<Api, true>
Convert this bitmap into the same bitmap that will not be freed on drop. That means that only C-part of the bitmap will not be freed.
Safety is guaranteed by the caller.
source§impl<Api: Api> Bitmap<Api, true>
impl<Api: Api> Bitmap<Api, true>
sourcepub fn new(width: c_int, height: c_int, bg: Color<'_>) -> Result<Self, Error>where
Api: Default,
pub fn new(width: c_int, height: c_int, bg: Color<'_>) -> Result<Self, Error>where Api: Default,
Allocates and returns a new width by height Bitmap filled with bg color.
sourcepub fn new_with(
api: Api,
width: c_int,
height: c_int,
bg: Color<'_>
) -> Result<Self, Error>
pub fn new_with( api: Api, width: c_int, height: c_int, bg: Color<'_> ) -> Result<Self, Error>
Allocates and returns a new width by height Bitmap filled with bg color,
using the given api.
sourcepub fn load<P: AsRef<Path>>(path: P) -> Result<Self, ApiError>where
Api: Default,
pub fn load<P: AsRef<Path>>(path: P) -> Result<Self, ApiError>where Api: Default,
Load a bitmap from a file.
source§impl<Api: Api, const FOD: bool> Bitmap<Api, FOD>
impl<Api: Api, const FOD: bool> Bitmap<Api, FOD>
source§impl<Api: Api, const FOD: bool> Bitmap<Api, FOD>
impl<Api: Api, const FOD: bool> Bitmap<Api, FOD>
sourcepub fn clear(&self, bg: Color<'_>)
pub fn clear(&self, bg: Color<'_>)
Clears bitmap, filling with the given bg color.
Equivalent to sys::ffi::playdate_graphics::clearBitmap.
sourcepub fn size(&self) -> (c_int, c_int)
pub fn size(&self) -> (c_int, c_int)
Returns (width, height) of the bitmap.
Can return error if there is no bitmap-data or any internal error occurred.
sourcepub fn bitmap_data<'bitmap>(&'bitmap mut self) -> BitmapData<'bitmap>
pub fn bitmap_data<'bitmap>(&'bitmap mut self) -> BitmapData<'bitmap>
Returns mutable borrow of bitmap-data by this bitmap.
sourcepub fn set_mask<Api2: Api, const FREE: bool>(
&self,
mask: &mut Bitmap<Api2, FREE>
) -> Result<(), Error>
pub fn set_mask<Api2: Api, const FREE: bool>( &self, mask: &mut Bitmap<Api2, FREE> ) -> Result<(), Error>
Sets a mask image for the bitmap.
The set mask must be the same size as the self bitmap.
sourcepub fn mask(&self) -> Option<Bitmap<Api, false>>where
Api: Clone,
pub fn mask(&self) -> Option<Bitmap<Api, false>>where Api: Clone,
Gets a mask image for the given bitmap. If the image doesn’t have a mask, returns None.
Clones inner api-access.
sourcepub fn mask_with<NewApi: Api>(
&self,
api: NewApi
) -> Option<Bitmap<NewApi, false>>
pub fn mask_with<NewApi: Api>( &self, api: NewApi ) -> Option<Bitmap<NewApi, false>>
Gets a mask image for the given bitmap. If the image doesn’t have a mask, returns None.
Produced Bitmap uses passed api api-access.
sourcepub fn rotated_clone(
&self,
rotation: c_float,
x_scale: c_float,
y_scale: c_float
) -> Result<Bitmap<Api, true>, Error>where
Api: Clone,
pub fn rotated_clone( &self, rotation: c_float, x_scale: c_float, y_scale: c_float ) -> Result<Bitmap<Api, true>, Error>where Api: Clone,
Returns a new, rotated and scaled Bitmap based on the bitmap.
sourcepub fn rotated_clone_with<NewApi: Api>(
&self,
api: NewApi,
rotation: c_float,
x_scale: c_float,
y_scale: c_float
) -> Result<Bitmap<NewApi, true>, Error>where
Api: Clone,
pub fn rotated_clone_with<NewApi: Api>( &self, api: NewApi, rotation: c_float, x_scale: c_float, y_scale: c_float ) -> Result<Bitmap<NewApi, true>, Error>where Api: Clone,
Returns a new, rotated and scaled Bitmap based on the bitmap using given api.
sourcepub fn draw(&self, x: c_int, y: c_int, flip: BitmapFlip)
pub fn draw(&self, x: c_int, y: c_int, flip: BitmapFlip)
Draws self with its upper-left corner at location x, y,
using the given flip orientation.
Equivalent to sys::ffi::playdate_graphics::drawBitmap.
sourcepub fn draw_tiled(
&self,
x: c_int,
y: c_int,
width: c_int,
height: c_int,
flip: BitmapFlip
)
pub fn draw_tiled( &self, x: c_int, y: c_int, width: c_int, height: c_int, flip: BitmapFlip )
Draws self with its upper-left corner at location x, y
tiled inside a width by height rectangle.
Equivalent to sys::ffi::playdate_graphics::tileBitmap.
sourcepub fn draw_rotated(
&self,
x: c_int,
y: c_int,
degrees: c_float,
center_x: c_float,
center_y: c_float,
x_scale: c_float,
y_scale: c_float
)
pub fn draw_rotated( &self, x: c_int, y: c_int, degrees: c_float, center_x: c_float, center_y: c_float, x_scale: c_float, y_scale: c_float )
Draws the bitmap scaled to x_scale and y_scale
then rotated by degrees with its center as given by proportions center_x and center_y at x, y;
that is:
- if
center_xandcenter_yare both 0.5 the center of the image is at (x,y), - if
center_xandcenter_yare both 0 the top left corner of the image (before rotation) is at (x,y), etc.
Equivalent to sys::ffi::playdate_graphics::drawRotatedBitmap.
sourcepub fn draw_scaled(
&self,
x: c_int,
y: c_int,
x_scale: c_float,
y_scale: c_float
)
pub fn draw_scaled( &self, x: c_int, y: c_int, x_scale: c_float, y_scale: c_float )
Draws this bitmap scaled to x_scale and y_scale with its upper-left corner at location x, y.
Note that flip is not available when drawing scaled bitmaps but negative scale values will achieve the same effect.
Equivalent to sys::ffi::playdate_graphics::drawScaledBitmap.
sourcepub fn check_mask_collision<OApi: Api, const OFOD: bool>(
&self,
x: c_int,
y: c_int,
flip: BitmapFlip,
other: Bitmap<OApi, OFOD>,
x_other: c_int,
y_other: c_int,
flip_other: BitmapFlip,
rect: LCDRect
) -> bool
pub fn check_mask_collision<OApi: Api, const OFOD: bool>( &self, x: c_int, y: c_int, flip: BitmapFlip, other: Bitmap<OApi, OFOD>, x_other: c_int, y_other: c_int, flip_other: BitmapFlip, rect: LCDRect ) -> bool
Returns true if any of the opaque pixels in this bitmap when positioned at x, y with flip
overlap any of the opaque pixels in other bitmap at x_other, y_other with flip_other
within the non-empty rect,
or false if no pixels overlap or if one or both fall completely outside of rect.
Equivalent to sys::ffi::playdate_graphics::checkMaskCollision.
sourcepub fn pattern_at(&self, x: c_int, y: c_int) -> LCDPattern
pub fn pattern_at(&self, x: c_int, y: c_int) -> LCDPattern
Returns pattern 8 x 8 from this bitmap.
x, y indicates the top left corner of the 8 x 8 pattern in bitmap’s coordinates.
Returned pattern is owned by rust and can be dropped freely.
sourcepub fn set_color_to_pattern(&self, color: &mut LCDColor, x: c_int, y: c_int)
pub fn set_color_to_pattern(&self, color: &mut LCDColor, x: c_int, y: c_int)
Sets color to an 8 x 8 pattern using this bitmap.
x, y indicates the top left corner of the 8 x 8 pattern.
After this operation inner pointer is owned by the system.
To get owned pattern use Bitmap::pattern_at.
Equivalent to sys::ffi::playdate_graphics::setColorToPattern.
Trait Implementations§
source§impl<Api: Api + Clone> Clone for Bitmap<Api, true>
impl<Api: Api + Clone> Clone for Bitmap<Api, true>
source§fn clone(&self) -> Self
fn clone(&self) -> Self
Allocates and returns a new Bitmap that is an exact copy of self,
not a reference.
Equivalent to sys::ffi::playdate_graphics::copyBitmap.
1.0.0§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<Api: Api, const FOD: bool> AnyBitmap for Bitmap<Api, FOD>
Auto Trait Implementations§
impl<Api, const FREE_ON_DROP: bool> RefUnwindSafe for Bitmap<Api, FREE_ON_DROP>where Api: RefUnwindSafe,
impl<Api = Default, const FREE_ON_DROP: bool = true> !Send for Bitmap<Api, FREE_ON_DROP>
impl<Api = Default, const FREE_ON_DROP: bool = true> !Sync for Bitmap<Api, FREE_ON_DROP>
impl<Api, const FREE_ON_DROP: bool> Unpin for Bitmap<Api, FREE_ON_DROP>where Api: Unpin,
impl<Api, const FREE_ON_DROP: bool> UnwindSafe for Bitmap<Api, FREE_ON_DROP>where Api: UnwindSafe,
Blanket Implementations§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T, U> Into<U> for Twhere
U: From<T>,
impl<T, U> Into<U> for Twhere U: From<T>,
§impl<T> ToOwned for Twhere
T: Clone,
impl<T> ToOwned for Twhere T: Clone,
§impl<T, U> TryFrom<U> for Twhere
U: Into<T>,
impl<T, U> TryFrom<U> for Twhere U: Into<T>,
Layout§
Note: Unable to compute type layout, possibly due to this type having generic parameters. Layout can only be computed for concrete, fully-instantiated types.