Bitmap

Struct 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>

Source

pub fn into_shared(self) -> Bitmap<Api, false>

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>

Source

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.

Calls sys::ffi::playdate_graphics::newBitmap.

Source

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.

Calls sys::ffi::playdate_graphics::newBitmap.

Source

pub fn load<P: AsRef<Path>>(path: P) -> Result<Self, ApiError>
where Api: Default,

Load a bitmap from a file.

Calls sys::ffi::playdate_graphics::loadBitmap.

Source

pub fn load_with<P: AsRef<Path>>(api: Api, path: P) -> Result<Self, ApiError>

Load a bitmap from a file, create new bitmap with given api.

Calls sys::ffi::playdate_graphics::loadBitmap.

Source§

impl<Api: Api, const FOD: bool> Bitmap<Api, FOD>

Source

pub fn load_into<P: AsRef<Path>>(&mut self, path: P) -> Result<(), ApiError>

Load a bitmap from a file into self.

Calls sys::ffi::playdate_graphics::loadIntoBitmap.

Source§

impl<Api: Api, const FOD: bool> Bitmap<Api, FOD>

Source

pub fn clear(&self, bg: Color<'_>)

Clears bitmap, filling with the given bg color.

Equivalent to sys::ffi::playdate_graphics::clearBitmap.

Source

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.

Calls sys::ffi::playdate_graphics::getBitmapData.

Source

pub fn bitmap_data<'bitmap>(&'bitmap mut self) -> BitmapData<'bitmap>

Returns mutable borrow of bitmap-data by this bitmap.

Calls sys::ffi::playdate_graphics::getBitmapData.

Source

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.

Calls sys::ffi::playdate_graphics::setBitmapMask.

Source

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.

Calls sys::ffi::playdate_graphics::getBitmapMask.

Source

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.

Calls sys::ffi::playdate_graphics::getBitmapMask.

Source

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.

Calls sys::ffi::playdate_graphics::rotatedBitmap.

Source

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.

Calls sys::ffi::playdate_graphics::rotatedBitmap.

Source

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.

Source

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.

Source

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_x and center_y are both 0.5 the center of the image is at (x,y),
  • if center_x and center_y are both 0 the top left corner of the image (before rotation) is at (x,y), etc.

Equivalent to sys::ffi::playdate_graphics::drawRotatedBitmap.

Source

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.

Source

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.

Source

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.

Uses sys::ffi::playdate_graphics::setColorToPattern.

Source

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.

Source

pub fn pixel_at(&self, x: c_int, y: c_int) -> LCDSolidColor

Gets the color of the pixel at (x,y) in this bitmap. If the coordinate is outside the bounds of the bitmap, or if the bitmap has a mask and the pixel is marked transparent, the function returns Clear; otherwise the return value is White or Black.

Calls sys::ffi::playdate_graphics::getBitmapPixel.

Trait Implementations§

Source§

impl<Api: Api, const FOD: bool> AsRaw for Bitmap<Api, FOD>

Source§

type Type = LCDBitmap

Source§

unsafe fn as_raw(&self) -> *mut LCDBitmap

This method ia actually safe. Unsafety is because so we’re removing owners lifetime that used by some API parts.
Source§

impl<Api: Api, const FOD: bool> BitmapApi for Bitmap<Api, FOD>

Source§

type Api = Api

Source§

fn api(&self) -> Api
where Self::Api: Copy,

Source§

fn api_ref(&self) -> &Self::Api

Source§

impl<Api: Api + Clone> Clone for Bitmap<Api, true>

Source§

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)

Performs copy-assignment from source. Read more
Source§

impl<Api: Debug + Api, const FREE_ON_DROP: bool> Debug for Bitmap<Api, FREE_ON_DROP>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Api: Api, const FOD: bool> Drop for Bitmap<Api, FOD>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<Api: Api + Default, const FOD: bool> From<*mut LCDBitmap> for Bitmap<Api, FOD>

Source§

fn from(ptr: *mut LCDBitmap) -> Self

Converts to this type from the input type.
Source§

impl<Api: Api, const FOD: bool> AnyBitmap for Bitmap<Api, FOD>

Auto Trait Implementations§

§

impl<Api, const FREE_ON_DROP: bool> Freeze for Bitmap<Api, FREE_ON_DROP>
where Api: Freeze,

§

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 T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of [From]<T> for U chooses to do.

§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.

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.