Trait flo_canvas::GraphicsContext
source · pub trait GraphicsContext {
Show 59 methods
// Provided methods
fn start_frame(&mut self) { ... }
fn show_frame(&mut self) { ... }
fn reset_frame(&mut self) { ... }
fn new_path(&mut self) { ... }
fn move_to(&mut self, x: f32, y: f32) { ... }
fn line_to(&mut self, x: f32, y: f32) { ... }
fn bezier_curve_to(
&mut self,
x: f32,
y: f32,
cp1_x: f32,
cp1_y: f32,
cp2_x: f32,
cp2_y: f32
) { ... }
fn close_path(&mut self) { ... }
fn fill(&mut self) { ... }
fn stroke(&mut self) { ... }
fn line_width(&mut self, width: f32) { ... }
fn line_width_pixels(&mut self, width: f32) { ... }
fn line_join(&mut self, join: LineJoin) { ... }
fn line_cap(&mut self, cap: LineCap) { ... }
fn winding_rule(&mut self, winding_rule: WindingRule) { ... }
fn new_dash_pattern(&mut self) { ... }
fn dash_length(&mut self, length: f32) { ... }
fn dash_offset(&mut self, offset: f32) { ... }
fn fill_color(&mut self, col: Color) { ... }
fn fill_texture(
&mut self,
texture_id: TextureId,
x1: f32,
y1: f32,
x2: f32,
y2: f32
) { ... }
fn fill_gradient(
&mut self,
gradient_id: GradientId,
x1: f32,
y1: f32,
x2: f32,
y2: f32
) { ... }
fn fill_transform(&mut self, transform: Transform2D) { ... }
fn stroke_color(&mut self, col: Color) { ... }
fn blend_mode(&mut self, mode: BlendMode) { ... }
fn identity_transform(&mut self) { ... }
fn canvas_height(&mut self, height: f32) { ... }
fn center_region(&mut self, minx: f32, miny: f32, maxx: f32, maxy: f32) { ... }
fn transform(&mut self, transform: Transform2D) { ... }
fn unclip(&mut self) { ... }
fn clip(&mut self) { ... }
fn store(&mut self) { ... }
fn restore(&mut self) { ... }
fn free_stored_buffer(&mut self) { ... }
fn push_state(&mut self) { ... }
fn pop_state(&mut self) { ... }
fn clear_canvas(&mut self, color: Color) { ... }
fn layer(&mut self, layer_id: LayerId) { ... }
fn layer_blend(&mut self, layer_id: LayerId, blend_mode: BlendMode) { ... }
fn clear_layer(&mut self) { ... }
fn clear_all_layers(&mut self) { ... }
fn swap_layers(&mut self, layer1: LayerId, layer2: LayerId) { ... }
fn sprite(&mut self, sprite_id: SpriteId) { ... }
fn clear_sprite(&mut self) { ... }
fn sprite_transform(&mut self, transform: SpriteTransform) { ... }
fn draw_sprite(&mut self, sprite_id: SpriteId) { ... }
fn define_font_data(
&mut self,
font_id: FontId,
font_data: Arc<CanvasFontFace>
) { ... }
fn set_font_size(&mut self, font_id: FontId, size: f32) { ... }
fn draw_text(
&mut self,
font_id: FontId,
text: String,
baseline_x: f32,
baseline_y: f32
) { ... }
fn draw_glyphs(&mut self, font_id: FontId, glyphs: Vec<GlyphPosition>) { ... }
fn begin_line_layout(&mut self, x: f32, y: f32, align: TextAlignment) { ... }
fn layout_text(&mut self, font_id: FontId, text: String) { ... }
fn draw_text_layout(&mut self) { ... }
fn create_texture(
&mut self,
texture_id: TextureId,
width: u32,
height: u32,
format: TextureFormat
) { ... }
fn free_texture(&mut self, texture_id: TextureId) { ... }
fn set_texture_bytes(
&mut self,
texture_id: TextureId,
x: u32,
y: u32,
width: u32,
height: u32,
bytes: Arc<Vec<u8>>
) { ... }
fn set_texture_fill_alpha(&mut self, texture_id: TextureId, alpha: f32) { ... }
fn create_gradient(&mut self, gradient_id: GradientId, initial_color: Color) { ... }
fn gradient_stop(&mut self, gradient_id: GradientId, pos: f32, color: Color) { ... }
fn draw(&mut self, d: Draw) { ... }
}
Expand description
A graphics context provides the basic set of graphics actions that can be performed
This trait contains default implementations for all of the operations that call draw()
as well as an implementation of draw()
that calls the default implementations. Inheritors should either implement ‘draw’ or implement all of the operations.
Provided Methods§
sourcefn start_frame(&mut self)
fn start_frame(&mut self)
Suspends rendering to the display until the next ‘ShowFrame’
The renderer may perform tessellation or rendering in the background after ‘StartFrame’ but won’t commit anything to the visible frame buffer until ‘ShowFrame’ is hit. If ‘StartFrame’ is nested, then the frame won’t be displayed until ‘ShowFrame’ has been requested at least that many times.
The frame state persists across a ‘ClearCanvas’
sourcefn show_frame(&mut self)
fn show_frame(&mut self)
Displays any requested queued after ‘StartFrame’
sourcefn reset_frame(&mut self)
fn reset_frame(&mut self)
Resets the frame count back to 0 (for when regenerating the state of a canvas)
sourcefn move_to(&mut self, x: f32, y: f32)
fn move_to(&mut self, x: f32, y: f32)
Move to a new point in the current path (paths should always begin with a move instruction, and moves can define subpaths)
sourcefn bezier_curve_to(
&mut self,
x: f32,
y: f32,
cp1_x: f32,
cp1_y: f32,
cp2_x: f32,
cp2_y: f32
)
fn bezier_curve_to( &mut self, x: f32, y: f32, cp1_x: f32, cp1_y: f32, cp2_x: f32, cp2_y: f32 )
Adds a bezier curve to the current path
sourcefn close_path(&mut self)
fn close_path(&mut self)
Closes the current path (adds a line to the last move point)
sourcefn line_width(&mut self, width: f32)
fn line_width(&mut self, width: f32)
Sets the line width for the next stroke() operation
sourcefn line_width_pixels(&mut self, width: f32)
fn line_width_pixels(&mut self, width: f32)
Sets the line width for the next stroke() operation in device pixels
sourcefn line_join(&mut self, join: LineJoin)
fn line_join(&mut self, join: LineJoin)
Sets the line join style for the next stroke() operation
sourcefn line_cap(&mut self, cap: LineCap)
fn line_cap(&mut self, cap: LineCap)
Sets the style of the start and end cap of the next line drawn by the stroke() operation
sourcefn winding_rule(&mut self, winding_rule: WindingRule)
fn winding_rule(&mut self, winding_rule: WindingRule)
Sets the winding rule used to determine if an internal subpath should be filled or empty
sourcefn new_dash_pattern(&mut self)
fn new_dash_pattern(&mut self)
Starts defining a new dash pattern
sourcefn dash_length(&mut self, length: f32)
fn dash_length(&mut self, length: f32)
Adds a dash of the specified length to the dash pattern (alternating between drawing and gap lengths)
sourcefn dash_offset(&mut self, offset: f32)
fn dash_offset(&mut self, offset: f32)
Sets the offset for where the dash pattern starts at the next stroke
sourcefn fill_color(&mut self, col: Color)
fn fill_color(&mut self, col: Color)
Sets the colour of the next fill() operation
sourcefn fill_texture(&mut self, texture_id: TextureId, x1: f32, y1: f32, x2: f32, y2: f32)
fn fill_texture(&mut self, texture_id: TextureId, x1: f32, y1: f32, x2: f32, y2: f32)
Sets the texture to use for the next fill() operation
sourcefn fill_gradient(
&mut self,
gradient_id: GradientId,
x1: f32,
y1: f32,
x2: f32,
y2: f32
)
fn fill_gradient( &mut self, gradient_id: GradientId, x1: f32, y1: f32, x2: f32, y2: f32 )
Sets the gradient to use for the next fill() operation
sourcefn fill_transform(&mut self, transform: Transform2D)
fn fill_transform(&mut self, transform: Transform2D)
Applies a transformation to the fill texture or gradient
sourcefn stroke_color(&mut self, col: Color)
fn stroke_color(&mut self, col: Color)
Sets the colour to use for the next stroke() operation
sourcefn blend_mode(&mut self, mode: BlendMode)
fn blend_mode(&mut self, mode: BlendMode)
Sets the blend mode of the next fill or stroke operation
sourcefn identity_transform(&mut self)
fn identity_transform(&mut self)
Reset the canvas transformation to the identity transformation (so that the y axis goes from -1 to 1)
sourcefn canvas_height(&mut self, height: f32)
fn canvas_height(&mut self, height: f32)
Sets a transformation such that: (0,0) is the center point of the canvas (0,height/2) is the top of the canvas Pixels are square
sourcefn center_region(&mut self, minx: f32, miny: f32, maxx: f32, maxy: f32)
fn center_region(&mut self, minx: f32, miny: f32, maxx: f32, maxy: f32)
Moves a particular region to the center of the canvas (coordinates are minx, miny, maxx, maxy)
sourcefn transform(&mut self, transform: Transform2D)
fn transform(&mut self, transform: Transform2D)
Multiply a 2D transform by the current transformation
sourcefn free_stored_buffer(&mut self)
fn free_stored_buffer(&mut self)
Releases the memory allocated by the last store() operation
sourcefn push_state(&mut self)
fn push_state(&mut self)
Stores the current state of the canvas (line width, fill colour, etc)
sourcefn pop_state(&mut self)
fn pop_state(&mut self)
Restore a state previously pushed
This will restore the line width (and the other stroke settings), stroke colour, current path, fill colour, winding rule, sprite settings and blend settings.
The currently selected layer is not affected by this operation.
sourcefn clear_canvas(&mut self, color: Color)
fn clear_canvas(&mut self, color: Color)
Clears the canvas entirely to a background colour, and removes any stored resources (layers, sprites, fonts, textures)
sourcefn layer(&mut self, layer_id: LayerId)
fn layer(&mut self, layer_id: LayerId)
Selects a particular layer for drawing Layer 0 is selected initially. Layers are drawn in order starting from 0. Layer IDs don’t have to be sequential.
sourcefn layer_blend(&mut self, layer_id: LayerId, blend_mode: BlendMode)
fn layer_blend(&mut self, layer_id: LayerId, blend_mode: BlendMode)
Sets how a particular layer is blended with the underlying layer
sourcefn clear_layer(&mut self)
fn clear_layer(&mut self)
Clears the current layer
sourcefn clear_all_layers(&mut self)
fn clear_all_layers(&mut self)
Clears all of the layers (without resetting any other resources, as clear_canvas does)
sourcefn swap_layers(&mut self, layer1: LayerId, layer2: LayerId)
fn swap_layers(&mut self, layer1: LayerId, layer2: LayerId)
Exchanges the contents of two layers in the drawing
sourcefn sprite(&mut self, sprite_id: SpriteId)
fn sprite(&mut self, sprite_id: SpriteId)
Selects a particular sprite for drawing
Future drawing actions are sent to this sprite: use something like Layer(0)
to start drawing
to a layer again.
Sprites can be repeatedly re-rendered with a single command and their appearance may be cached for efficiency. Actions that affect the whole canvas or layers are not permitted in sprites.
sourcefn clear_sprite(&mut self)
fn clear_sprite(&mut self)
Releases the resources used by the current sprite
sourcefn sprite_transform(&mut self, transform: SpriteTransform)
fn sprite_transform(&mut self, transform: SpriteTransform)
Adds a sprite transform to the next sprite drawing operation
sourcefn draw_sprite(&mut self, sprite_id: SpriteId)
fn draw_sprite(&mut self, sprite_id: SpriteId)
Renders a sprite with a set of transformations
sourcefn define_font_data(&mut self, font_id: FontId, font_data: Arc<CanvasFontFace>)
fn define_font_data(&mut self, font_id: FontId, font_data: Arc<CanvasFontFace>)
Loads font data into the canvas for a particular font ID
sourcefn set_font_size(&mut self, font_id: FontId, size: f32)
fn set_font_size(&mut self, font_id: FontId, size: f32)
Sets the size that text in the specified font will be rendered at
sourcefn draw_text(
&mut self,
font_id: FontId,
text: String,
baseline_x: f32,
baseline_y: f32
)
fn draw_text( &mut self, font_id: FontId, text: String, baseline_x: f32, baseline_y: f32 )
Draws a text string using a font
sourcefn draw_glyphs(&mut self, font_id: FontId, glyphs: Vec<GlyphPosition>)
fn draw_glyphs(&mut self, font_id: FontId, glyphs: Vec<GlyphPosition>)
Draws specific glyphs from a font
sourcefn begin_line_layout(&mut self, x: f32, y: f32, align: TextAlignment)
fn begin_line_layout(&mut self, x: f32, y: f32, align: TextAlignment)
Starts laying out a line of text
sourcefn layout_text(&mut self, font_id: FontId, text: String)
fn layout_text(&mut self, font_id: FontId, text: String)
Adds text to the current line layout
sourcefn draw_text_layout(&mut self)
fn draw_text_layout(&mut self)
Finishes laying out text and renders the result
sourcefn create_texture(
&mut self,
texture_id: TextureId,
width: u32,
height: u32,
format: TextureFormat
)
fn create_texture( &mut self, texture_id: TextureId, width: u32, height: u32, format: TextureFormat )
Creates a new texture that can be used with fill_texture of the specified width and height
sourcefn free_texture(&mut self, texture_id: TextureId)
fn free_texture(&mut self, texture_id: TextureId)
Releases the memory allocated to a particular texture
sourcefn set_texture_bytes(
&mut self,
texture_id: TextureId,
x: u32,
y: u32,
width: u32,
height: u32,
bytes: Arc<Vec<u8>>
)
fn set_texture_bytes( &mut self, texture_id: TextureId, x: u32, y: u32, width: u32, height: u32, bytes: Arc<Vec<u8>> )
Sets the bitmap data for a texture, in the format specified by the call to create_texture()
sourcefn set_texture_fill_alpha(&mut self, texture_id: TextureId, alpha: f32)
fn set_texture_fill_alpha(&mut self, texture_id: TextureId, alpha: f32)
Applies an alpha value to a texture
sourcefn create_gradient(&mut self, gradient_id: GradientId, initial_color: Color)
fn create_gradient(&mut self, gradient_id: GradientId, initial_color: Color)
Defines a new gradient with a colour at stop position 0.0. Gradients can be used via fill_gradient()
sourcefn gradient_stop(&mut self, gradient_id: GradientId, pos: f32, color: Color)
fn gradient_stop(&mut self, gradient_id: GradientId, pos: f32, color: Color)
Adds a new colour stop to a texture
Trait Implementations§
source§impl<'a> GraphicsPrimitives for dyn GraphicsContext + 'a
impl<'a> GraphicsPrimitives for dyn GraphicsContext + 'a
The dynamic graphics context object also implements the graphics primitives
source§fn rect(&mut self, x1: f32, y1: f32, x2: f32, y2: f32)
fn rect(&mut self, x1: f32, y1: f32, x2: f32, y2: f32)
source§fn circle(&mut self, center_x: f32, center_y: f32, radius: f32)
fn circle(&mut self, center_x: f32, center_y: f32, radius: f32)
source§fn bezier_path<TPath: BezierPath>(&mut self, path: &TPath)where
TPath::Point: Coordinate2D,
fn bezier_path<TPath: BezierPath>(&mut self, path: &TPath)where TPath::Point: Coordinate2D,
source§fn bezier_curve<TCurve: BezierCurve>(&mut self, curve: &TCurve)where
TCurve::Point: Coordinate2D,
fn bezier_curve<TCurve: BezierCurve>(&mut self, curve: &TCurve)where TCurve::Point: Coordinate2D,
source§fn draw_list<'a, DrawIter: 'a + IntoIterator<Item = Draw>>(
&'a mut self,
drawing: DrawIter
)
fn draw_list<'a, DrawIter: 'a + IntoIterator<Item = Draw>>( &'a mut self, drawing: DrawIter )
Implementations on Foreign Types§
source§impl GraphicsContext for Vec<Draw>
impl GraphicsContext for Vec<Draw>
A Vec