Struct lapix::Canvas

source ·
pub struct Canvas<IMG> { /* private fields */ }
Expand description

The canvas is the area where drawing can take place. Each layer has a canvas, and the canvas in turn holds an image internally to represent the drawing on it.

Implementations§

source§

impl<IMG: Bitmap> Canvas<IMG>

source

pub fn new(size: Size<i32>) -> Self

Create a new blank canvas with a specified size

source

pub fn inner(&self) -> &IMG

Get the inner image held by this canvas

source

pub fn size(&self) -> Size<i32>

Get the size of the canvas in pixels. This is the amount of pixels of the underlying image, not the real screen-size that the canvas takes up when displayed.

source

pub fn width(&self) -> i32

Get the width of the canvas in pixels (width of the underlying image, not real screen-size)

source

pub fn height(&self) -> i32

Get the height of the canvas in pixels (height of the underlying image)

source

pub fn rect(&self) -> Rect<i32>

Get the rectangle representing the canvas dimensions, starting from the origin at (0, 0).

source

pub fn bytes(&self) -> &[u8]

Get a representation of the inner image as a slice of bytes

source

pub fn is_in_bounds(&self, p: Point<i32>) -> bool

Check whether a point is inside the canvas

source

pub fn set_img(&mut self, img: IMG)

Set the image of the canvas with a predefined one

source

pub fn take_inner(&mut self) -> IMG

Take the inner image replacing it with a dummy empty one.

source

pub fn clear(&mut self) -> IMG

Set all pixels of the canvas to transparent

source

pub fn resize(&mut self, size: Size<i32>) -> IMG

Resize the canvas, keeping the content that is in bounds and in case of an increase in one of the dimensions, set new pixels to transparent.

source

pub fn pixel(&self, p: Point<i32>) -> Color

Get the color of a pixel in a certain position in the canvas

source

pub fn set_pixel( &mut self, p: Point<i32>, color: Color ) -> Option<(Point<i32>, Color)>

Set the color of a pixel in a certain position in the canvas. If there was an actual change, return the data needed for a reversal, that is, which point needs to be set to which color to reverse the action.

source

pub fn line( &mut self, p1: Point<i32>, p2: Point<i32>, color: Color ) -> Vec<(Point<i32>, Color)>

Draw a line between two points in the canvas with a certain color. Returns a set of reversals (points and the colors they need to be set to in order to reverse the action).

source

pub fn rectangle( &mut self, p1: Point<i32>, p2: Point<i32>, color: Color ) -> Vec<(Point<i32>, Color)>

Draw a rectangle (outline) between two points in the canvas with a certain color. Returns a set of reversals (points and the colors they need to be set to in order to reverse the action).

source

pub fn set_area( &mut self, area: Rect<i32>, color: Color ) -> Vec<(Point<i32>, Color)>

Set an area of the canvas (determined by a rectangle) to a certain color. Returns a set of reversals (points and colors they need to be set to in order to reverse the action).

source

pub fn paste_obj(&mut self, obj: &FreeImage<IMG>) -> Vec<(Point<i32>, Color)>

Paste a free image into the canvas, overriding the contents that existed below that area. Returns a set of reversals (points and colors they need to be set to in order to reverse the action).

source

pub fn bucket( &mut self, p: Point<i32>, color: Color ) -> Vec<(Point<i32>, Color)>

Paint an enclosed area with a certain color. Returns a set of reversals (points and colors they need to be set to in order to reverse the action).

source

pub fn img_from_area(&self, area: Rect<i32>) -> IMG

Get an image from a certain area of the canvas (determined by a rectangle).

Trait Implementations§

source§

impl<IMG: Debug> Debug for Canvas<IMG>

source§

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

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

impl<'de, IMG> Deserialize<'de> for Canvas<IMG>where IMG: Deserialize<'de>,

source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
source§

impl<IMG> Serialize for Canvas<IMG>where IMG: Serialize,

source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

§

impl<IMG> RefUnwindSafe for Canvas<IMG>where IMG: RefUnwindSafe,

§

impl<IMG> Send for Canvas<IMG>where IMG: Send,

§

impl<IMG> Sync for Canvas<IMG>where IMG: Sync,

§

impl<IMG> Unpin for Canvas<IMG>where IMG: Unpin,

§

impl<IMG> UnwindSafe for Canvas<IMG>where IMG: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · source§

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> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

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

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

impl<T> DeserializeOwned for Twhere T: for<'de> Deserialize<'de>,