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>
impl<IMG: Bitmap> Canvas<IMG>
sourcepub fn size(&self) -> Size<i32>
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.
sourcepub fn width(&self) -> i32
pub fn width(&self) -> i32
Get the width of the canvas in pixels (width of the underlying image, not real screen-size)
sourcepub fn height(&self) -> i32
pub fn height(&self) -> i32
Get the height of the canvas in pixels (height of the underlying image)
sourcepub fn rect(&self) -> Rect<i32>
pub fn rect(&self) -> Rect<i32>
Get the rectangle representing the canvas dimensions, starting from the origin at (0, 0).
sourcepub fn is_in_bounds(&self, p: Point<i32>) -> bool
pub fn is_in_bounds(&self, p: Point<i32>) -> bool
Check whether a point is inside the canvas
sourcepub fn take_inner(&mut self) -> IMG
pub fn take_inner(&mut self) -> IMG
Take the inner image replacing it with a dummy empty one.
sourcepub fn resize(&mut self, size: Size<i32>) -> IMG
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.
sourcepub fn pixel(&self, p: Point<i32>) -> Color
pub fn pixel(&self, p: Point<i32>) -> Color
Get the color of a pixel in a certain position in the canvas
sourcepub fn set_pixel(
&mut self,
p: Point<i32>,
color: Color
) -> Option<(Point<i32>, Color)>
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.
sourcepub fn line(
&mut self,
p1: Point<i32>,
p2: Point<i32>,
color: Color
) -> Vec<(Point<i32>, Color)>
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).
sourcepub fn rectangle(
&mut self,
p1: Point<i32>,
p2: Point<i32>,
color: Color
) -> Vec<(Point<i32>, Color)>
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).
sourcepub fn set_area(
&mut self,
area: Rect<i32>,
color: Color
) -> Vec<(Point<i32>, Color)>
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).
sourcepub fn paste_obj(&mut self, obj: &FreeImage<IMG>) -> Vec<(Point<i32>, Color)>
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).
sourcepub fn bucket(
&mut self,
p: Point<i32>,
color: Color
) -> Vec<(Point<i32>, Color)>
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).
sourcepub fn img_from_area(&self, area: Rect<i32>) -> IMG
pub fn img_from_area(&self, area: Rect<i32>) -> IMG
Get an image from a certain area of the canvas (determined by a rectangle).