pub struct Canvas<T: Renderer> { /* private fields */ }
Expand description
Main 2D drawing context.
Implementations
pub fn new_with_text_context(
renderer: T,
text_context: TextContext
) -> Result<Self, ErrorKind>
pub fn new_with_text_context(
renderer: T,
text_context: TextContext
) -> Result<Self, ErrorKind>
Creates a new canvas with the specified renderer and using the fonts registered with the
provided TextContext
. Note that the context is explicitly shared, so that any fonts
registered with a clone of this context will also be visible to this canvas.
Sets the size of the default framebuffer (screen size)
Clears the rectangle area defined by left upper corner (x,y), width and height with the provided color.
Tells the renderer to execute all drawing commands and clears the current internal state
Call this at the end of each frame.
Pushes and saves the current render state into a state stack.
A matching restore() must be used to restore the state.
Restores the previous render state
Restoring the initial/first state will just reset it to the defaults
Resets current state to default values. Does not affect the state stack.
Saves the current state before calling the callback and restores it afterwards
This is less error prone than remembering to match save() -> restore() calls
Sets the transparency applied to all rendered shapes.
Already transparent paths will get proportionally more transparent as well.
Sets the composite operation.
pub fn global_composite_blend_func(
&mut self,
src_factor: BlendFactor,
dst_factor: BlendFactor
)
pub fn global_composite_blend_func(
&mut self,
src_factor: BlendFactor,
dst_factor: BlendFactor
)
Sets the composite operation with custom pixel arithmetic.
pub fn global_composite_blend_func_separate(
&mut self,
src_rgb: BlendFactor,
dst_rgb: BlendFactor,
src_alpha: BlendFactor,
dst_alpha: BlendFactor
)
pub fn global_composite_blend_func_separate(
&mut self,
src_rgb: BlendFactor,
dst_rgb: BlendFactor,
src_alpha: BlendFactor,
dst_alpha: BlendFactor
)
Sets the composite operation with custom pixel arithmetic for RGB and alpha components separately.
Sets a new render target. All drawing operations after this call will happen on the provided render target
pub fn create_image_empty(
&mut self,
width: usize,
height: usize,
format: PixelFormat,
flags: ImageFlags
) -> Result<ImageId, ErrorKind>
pub fn create_image_empty(
&mut self,
width: usize,
height: usize,
format: PixelFormat,
flags: ImageFlags
) -> Result<ImageId, ErrorKind>
Allocates an empty image with the provided domensions and format.
pub fn create_image<'a, S: Into<ImageSource<'a>>>(
&mut self,
src: S,
flags: ImageFlags
) -> Result<ImageId, ErrorKind>
pub fn create_image<'a, S: Into<ImageSource<'a>>>(
&mut self,
src: S,
flags: ImageFlags
) -> Result<ImageId, ErrorKind>
Creates image from specified image data.
pub fn realloc_image(
&mut self,
id: ImageId,
width: usize,
height: usize,
format: PixelFormat,
flags: ImageFlags
) -> Result<(), ErrorKind>
pub fn realloc_image(
&mut self,
id: ImageId,
width: usize,
height: usize,
format: PixelFormat,
flags: ImageFlags
) -> Result<(), ErrorKind>
Resizes an image to the new provided dimensions.
pub fn load_image_file<P: AsRef<FilePath>>(
&mut self,
filename: P,
flags: ImageFlags
) -> Result<ImageId, ErrorKind>
pub fn load_image_file<P: AsRef<FilePath>>(
&mut self,
filename: P,
flags: ImageFlags
) -> Result<ImageId, ErrorKind>
Decode an image from file
pub fn load_image_mem(
&mut self,
data: &[u8],
flags: ImageFlags
) -> Result<ImageId, ErrorKind>
pub fn load_image_mem(
&mut self,
data: &[u8],
flags: ImageFlags
) -> Result<ImageId, ErrorKind>
Decode an image from memory
pub fn update_image<'a, S: Into<ImageSource<'a>>>(
&mut self,
id: ImageId,
src: S,
x: usize,
y: usize
) -> Result<(), ErrorKind>
pub fn update_image<'a, S: Into<ImageSource<'a>>>(
&mut self,
id: ImageId,
src: S,
x: usize,
y: usize
) -> Result<(), ErrorKind>
Updates image data specified by image handle.
Deletes created image.
Returns the size in pixels of the image for the specified id.
pub fn filter_image(
&mut self,
target_image: ImageId,
filter: ImageFilter,
source_image: ImageId
)
pub fn filter_image(
&mut self,
target_image: ImageId,
filter: ImageFilter,
source_image: ImageId
)
Renders the given source_image into target_image while applying a filter effect.
The target image must have the same size as the source image. The filtering is recorded
as a drawing command and run by the renderer when Self::flush()
is called.
The filtering does not take any transformation set on the Canvas into account nor does it change the current rendering target.
Resets current transform to a identity matrix.
Premultiplies current coordinate system by specified matrix.
The parameters are interpreted as matrix as follows: [a c e] [b d f] [0 0 1]
Rotates the current coordinate system. Angle is specified in radians.
Skews the current coordinate system along X axis. Angle is specified in radians.
Skews the current coordinate system along Y axis. Angle is specified in radians.
Returns the current transformation matrix
TODO: It’s not ok that this method returns Transform2D while set_transform accepts 6 floats - make it consistant
Sets the current scissor rectangle.
The scissor rectangle is transformed by the current transform.
Intersects current scissor rectangle with the specified rectangle.
The scissor rectangle is transformed by the current transform. Note: in case the rotation of previous scissor rect differs from the current one, the intersection will be done between the specified rectangle and the previous scissor rectangle transformed in the current transform space. The resulting shape is always rectangle.
Reset and disables scissoring.
Returns true if the specified point (x,y) is in the provided path, and false otherwise.
Fills the provided Path with the specified Paint.
Strokes the provided Path with the specified Paint.
Adds a font file to the canvas
Adds a font to the canvas by reading it from the specified chunk of memory.
Adds all .ttf files from a directory
pub fn measure_text<S: AsRef<str>>(
&mut self,
x: f32,
y: f32,
text: S,
paint: Paint
) -> Result<TextMetrics, ErrorKind>
pub fn measure_text<S: AsRef<str>>(
&mut self,
x: f32,
y: f32,
text: S,
paint: Paint
) -> Result<TextMetrics, ErrorKind>
Returns information on how the provided text will be drawn with the specified paint.
Returns font metrics for a particular Paint.
Returns the maximum index-th byte of text that will fit inside max_width.
The retuned index will always lie at the start and/or end of a UTF-8 code point sequence or at the start or end of the text
Returnes a list of ranges representing each line of text that will fit inside max_width
Fills the provided string with the specified Paint.
pub fn stroke_text<S: AsRef<str>>(
&mut self,
x: f32,
y: f32,
text: S,
paint: Paint
) -> Result<TextMetrics, ErrorKind>
pub fn stroke_text<S: AsRef<str>>(
&mut self,
x: f32,
y: f32,
text: S,
paint: Paint
) -> Result<TextMetrics, ErrorKind>
Strokes the provided string with the specified Paint.