[−][src]Trait piet_common::RenderContext
The main trait for rendering graphics.
This trait provides an API for drawing 2D graphics. In basic usage, it wraps a surface of some kind, so that drawing commands paint onto the surface. It can also be a recording context, creating a display list for playback later.
The intent of the design is to be general so that any number of back-ends can implement this trait.
Code that draws graphics will in general take &mut impl RenderContext
.
Associated Types
type Brush
The type of a "brush".
Initially just a solid RGBA color, but will probably expand to gradients.
type Text: Text
An associated factory for creating text layouts and related resources.
type TextLayout: TextLayout
type Image
The associated type of an image.
Required methods
fn status(&mut self) -> Result<(), Error>
Report an internal error.
Drawing operations may cause internal errors, which may also occur asynchronously after the drawing command was issued. This method reports any such error that has been detected.
fn solid_brush(&mut self, color: Color) -> Self::Brush
Create a new brush resource.
TODO: figure out how to document lifetime and rebuilding requirements. Should that be the responsibility of the client, or should the back-end take responsiblity? We could have a cache that is flushed when the Direct2D render target is rebuilt. Solid brushes are super lightweight, but other potentially retained objects will be heavier.
fn gradient(&mut self, gradient: Gradient) -> Result<Self::Brush, Error>
Create a new gradient brush.
fn clear(&mut self, color: Color)
Clear the canvas with the given color.
Note: only opaque colors are meaningful.
fn stroke<impl Shape>(
&mut self,
shape: impl Shape,
brush: &Self::Brush,
width: f64,
style: Option<&StrokeStyle>
) where
impl Shape: Shape,
&mut self,
shape: impl Shape,
brush: &Self::Brush,
width: f64,
style: Option<&StrokeStyle>
) where
impl Shape: Shape,
Stroke a shape.
fn fill<impl Shape>(
&mut self,
shape: impl Shape,
brush: &Self::Brush,
fill_rule: FillRule
) where
impl Shape: Shape,
&mut self,
shape: impl Shape,
brush: &Self::Brush,
fill_rule: FillRule
) where
impl Shape: Shape,
Fill a shape.
fn clip<impl Shape>(&mut self, shape: impl Shape, fill_rule: FillRule) where
impl Shape: Shape,
impl Shape: Shape,
Clip to a shape.
All subsequent drawing operations up to the next restore
are clipped by the shape.
fn text(&mut self) -> &mut Self::Text
fn draw_text<impl Into>(
&mut self,
layout: &Self::TextLayout,
pos: impl Into,
brush: &Self::Brush
) where
impl Into: Into<Point>,
&mut self,
layout: &Self::TextLayout,
pos: impl Into
brush: &Self::Brush
) where
impl Into
Draw a text layout.
The pos
parameter specifies the baseline of the left starting place of
the text. Note: this is true even if the text is right-to-left.
fn save(&mut self) -> Result<(), Error>
Save the context state.
Pushes the current context state onto a stack, to be popped by
restore
.
Prefer with_save
if possible, as that statically
enforces balance of save/restore pairs.
The context state currently consists of a clip region and an affine transform, but is expected to grow in the near future.
fn restore(&mut self) -> Result<(), Error>
Restore the context state.
Pop a context state that was pushed by save
. See
that method for details.
fn finish(&mut self) -> Result<(), Error>
Finish any pending operations.
This will generally be called by a shell after all user drawing operations but before presenting. Not all back-ends will handle this the same way.
fn transform(&mut self, transform: Affine)
Apply a transform.
Apply an affine transformation. The transformation remains in effect
until a restore
operation.
fn make_image(
&mut self,
width: usize,
height: usize,
buf: &[u8],
format: ImageFormat
) -> Result<Self::Image, Error>
&mut self,
width: usize,
height: usize,
buf: &[u8],
format: ImageFormat
) -> Result<Self::Image, Error>
Create a new image from a pixel buffer.
fn draw_image<impl Into>(
&mut self,
image: &Self::Image,
rect: impl Into,
interp: InterpolationMode
) where
impl Into: Into<Rect>,
&mut self,
image: &Self::Image,
rect: impl Into
interp: InterpolationMode
) where
impl Into
Draw an image.
The image is scaled to the provided rect
. It will be squashed if
aspect ratios don't match.
Provided methods
fn with_save<impl FnOnce(&mut Self) -> Result<(), Error>>(
&mut self,
f: impl FnOnce(&mut Self) -> Result<(), Error>
) -> Result<(), Error> where
impl FnOnce(&mut Self) -> Result<(), Error>: FnOnce(&mut Self) -> Result<(), Error>,
&mut self,
f: impl FnOnce(&mut Self) -> Result<(), Error>
) -> Result<(), Error> where
impl FnOnce(&mut Self) -> Result<(), Error>: FnOnce(&mut Self) -> Result<(), Error>,
Implementations on Foreign Types
impl<'a> RenderContext for D2DRenderContext<'a>
[src]
type Brush = GenericBrush
type Text = D2DText<'a>
type TextLayout = D2DTextLayout
type Image = Bitmap
fn status(&mut self) -> Result<(), Error>
[src]
fn clear(&mut self, color: Color)
[src]
fn solid_brush(&mut self, color: Color) -> GenericBrush
[src]
fn gradient(&mut self, gradient: Gradient) -> Result<GenericBrush, Error>
[src]
fn fill<impl Shape>(
&mut self,
shape: impl Shape,
brush: &<D2DRenderContext<'a> as RenderContext>::Brush,
fill_rule: FillRule
) where
impl Shape: Shape,
[src]
&mut self,
shape: impl Shape,
brush: &<D2DRenderContext<'a> as RenderContext>::Brush,
fill_rule: FillRule
) where
impl Shape: Shape,
fn stroke<impl Shape>(
&mut self,
shape: impl Shape,
brush: &<D2DRenderContext<'a> as RenderContext>::Brush,
width: f64,
style: Option<&StrokeStyle>
) where
impl Shape: Shape,
[src]
&mut self,
shape: impl Shape,
brush: &<D2DRenderContext<'a> as RenderContext>::Brush,
width: f64,
style: Option<&StrokeStyle>
) where
impl Shape: Shape,
fn clip<impl Shape>(&mut self, shape: impl Shape, fill_rule: FillRule) where
impl Shape: Shape,
[src]
impl Shape: Shape,
fn text(&mut self) -> &mut <D2DRenderContext<'a> as RenderContext>::Text
[src]
fn draw_text<impl Into>(
&mut self,
layout: &<D2DRenderContext<'a> as RenderContext>::TextLayout,
pos: impl Into,
brush: &<D2DRenderContext<'a> as RenderContext>::Brush
) where
impl Into: Into<Point>,
[src]
&mut self,
layout: &<D2DRenderContext<'a> as RenderContext>::TextLayout,
pos: impl Into
brush: &<D2DRenderContext<'a> as RenderContext>::Brush
) where
impl Into
fn save(&mut self) -> Result<(), Error>
[src]
fn restore(&mut self) -> Result<(), Error>
[src]
fn finish(&mut self) -> Result<(), Error>
[src]
fn transform(&mut self, transform: Affine)
[src]
fn make_image(
&mut self,
width: usize,
height: usize,
buf: &[u8],
format: ImageFormat
) -> Result<<D2DRenderContext<'a> as RenderContext>::Image, Error>
[src]
&mut self,
width: usize,
height: usize,
buf: &[u8],
format: ImageFormat
) -> Result<<D2DRenderContext<'a> as RenderContext>::Image, Error>
fn draw_image<impl Into>(
&mut self,
image: &<D2DRenderContext<'a> as RenderContext>::Image,
rect: impl Into,
interp: InterpolationMode
) where
impl Into: Into<Rect>,
[src]
&mut self,
image: &<D2DRenderContext<'a> as RenderContext>::Image,
rect: impl Into
interp: InterpolationMode
) where
impl Into