Trait piet_common::RenderContext [−][src]
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: Clone + IntoBrush<Self>
[src]
The type of a “brush”.
Represents solid colors and gradients.
type Text: Text
[src]
An associated factory for creating text layouts and related resources.
type TextLayout: TextLayout
[src]
The type use to represent text layout objects.
type Image: Image
[src]
The associated type of an image.
Required methods
pub fn status(&mut self) -> Result<(), Error>
[src]
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.
pub fn solid_brush(&mut self, color: Color) -> Self::Brush
[src]
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 responsibility? 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.
pub fn gradient(
&mut self,
gradient: impl Into<FixedGradient>
) -> Result<Self::Brush, Error>
[src]
&mut self,
gradient: impl Into<FixedGradient>
) -> Result<Self::Brush, Error>
Create a new gradient brush.
pub fn clear(&mut self, region: impl Into<Option<Rect>>, color: Color)
[src]
Replace a region of the canvas with the provided Color
.
The region can be omitted, in which case it will apply to the entire canvas.
This operation ignores any existing clipping and transforations.
Note:
You probably don’t want to call this. It is essentially a specialized
fill method that can be used in GUI contexts for things like clearing
damage regions. It does not have a good cross-platform implementation,
and eventually should be deprecated when support is added for blend
modes, at which point it will be easier to just use fill
for
everything.
pub fn stroke(
&mut self,
shape: impl Shape,
brush: &impl IntoBrush<Self>,
width: f64
)
[src]
&mut self,
shape: impl Shape,
brush: &impl IntoBrush<Self>,
width: f64
)
Stroke a shape.
pub fn stroke_styled(
&mut self,
shape: impl Shape,
brush: &impl IntoBrush<Self>,
width: f64,
style: &StrokeStyle
)
[src]
&mut self,
shape: impl Shape,
brush: &impl IntoBrush<Self>,
width: f64,
style: &StrokeStyle
)
Stroke a shape, with styled strokes.
pub fn fill(&mut self, shape: impl Shape, brush: &impl IntoBrush<Self>)
[src]
Fill a shape, using non-zero fill rule.
pub fn fill_even_odd(&mut self, shape: impl Shape, brush: &impl IntoBrush<Self>)
[src]
Fill a shape, using even-odd fill rule
pub fn clip(&mut self, shape: impl Shape)
[src]
Clip to a shape.
All subsequent drawing operations up to the next restore
are clipped by the shape.
pub fn text(&mut self) -> &mut Self::Text
[src]
Returns a reference to a shared Text
object.
This provides access to the text API.
pub fn draw_text(&mut self, layout: &Self::TextLayout, pos: impl Into<Point>)
[src]
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.
pub fn save(&mut self) -> Result<(), Error>
[src]
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.
pub fn restore(&mut self) -> Result<(), Error>
[src]
Restore the context state.
Pop a context state that was pushed by save
. See
that method for details.
pub fn finish(&mut self) -> Result<(), Error>
[src]
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.
pub fn transform(&mut self, transform: Affine)
[src]
Apply a transform.
Apply an affine transformation. The transformation remains in effect
until a restore
operation.
pub fn make_image(
&mut self,
width: usize,
height: usize,
buf: &[u8],
format: ImageFormat
) -> Result<Self::Image, Error>
[src]
&mut self,
width: usize,
height: usize,
buf: &[u8],
format: ImageFormat
) -> Result<Self::Image, Error>
Create a new image from a pixel buffer.
pub fn draw_image(
&mut self,
image: &Self::Image,
dst_rect: impl Into<Rect>,
interp: InterpolationMode
)
[src]
&mut self,
image: &Self::Image,
dst_rect: impl Into<Rect>,
interp: InterpolationMode
)
Draw an image.
The image
is scaled to the provided dst_rect
.
It will be squashed if the aspect ratios don’t match.
pub fn draw_image_area(
&mut self,
image: &Self::Image,
src_rect: impl Into<Rect>,
dst_rect: impl Into<Rect>,
interp: InterpolationMode
)
[src]
&mut self,
image: &Self::Image,
src_rect: impl Into<Rect>,
dst_rect: impl Into<Rect>,
interp: InterpolationMode
)
Draw a specified area of an image.
The src_rect
area of image
is scaled to the provided dst_rect
.
It will be squashed if the aspect ratios don’t match.
pub fn capture_image_area(
&mut self,
src_rect: impl Into<Rect>
) -> Result<Self::Image, Error>
[src]
&mut self,
src_rect: impl Into<Rect>
) -> Result<Self::Image, Error>
Create an Image
of the specified region of the context.
The src_rect
area of the current render context will be captured
as a copy and returned.
This can be used for things like caching expensive drawing operations.
pub fn blurred_rect(
&mut self,
rect: Rect,
blur_radius: f64,
brush: &impl IntoBrush<Self>
)
[src]
&mut self,
rect: Rect,
blur_radius: f64,
brush: &impl IntoBrush<Self>
)
Draw a rectangle with Gaussian blur.
The blur radius is sometimes referred to as the “standard deviation” of the blur.
pub fn current_transform(&self) -> Affine
[src]
Returns the transformations currently applied to the context.
Provided methods
pub fn with_save(
&mut self,
f: impl FnOnce(&mut Self) -> Result<(), Error>
) -> Result<(), Error>
[src]
&mut self,
f: impl FnOnce(&mut Self) -> Result<(), Error>
) -> Result<(), Error>
Implementations on Foreign Types
impl<'a> RenderContext for CairoRenderContext<'a>
[src]
type Brush = Brush
type Text = CairoText
type TextLayout = CairoTextLayout
type Image = CairoImage
pub fn status(&mut self) -> Result<(), Error>
[src]
pub fn clear(&mut self, region: impl Into<Option<Rect>>, color: Color)
[src]
pub fn solid_brush(&mut self, color: Color) -> Brush
[src]
pub fn gradient(
&mut self,
gradient: impl Into<FixedGradient>
) -> Result<Brush, Error>
[src]
&mut self,
gradient: impl Into<FixedGradient>
) -> Result<Brush, Error>
pub fn fill(
&mut self,
shape: impl Shape,
brush: &impl IntoBrush<CairoRenderContext<'a>>
)
[src]
&mut self,
shape: impl Shape,
brush: &impl IntoBrush<CairoRenderContext<'a>>
)
pub fn fill_even_odd(
&mut self,
shape: impl Shape,
brush: &impl IntoBrush<CairoRenderContext<'a>>
)
[src]
&mut self,
shape: impl Shape,
brush: &impl IntoBrush<CairoRenderContext<'a>>
)
pub fn clip(&mut self, shape: impl Shape)
[src]
pub fn stroke(
&mut self,
shape: impl Shape,
brush: &impl IntoBrush<CairoRenderContext<'a>>,
width: f64
)
[src]
&mut self,
shape: impl Shape,
brush: &impl IntoBrush<CairoRenderContext<'a>>,
width: f64
)
pub fn stroke_styled(
&mut self,
shape: impl Shape,
brush: &impl IntoBrush<CairoRenderContext<'a>>,
width: f64,
style: &StrokeStyle
)
[src]
&mut self,
shape: impl Shape,
brush: &impl IntoBrush<CairoRenderContext<'a>>,
width: f64,
style: &StrokeStyle
)
pub fn text(&mut self) -> &mut <CairoRenderContext<'a> as RenderContext>::Text
[src]
pub fn draw_text(
&mut self,
layout: &<CairoRenderContext<'a> as RenderContext>::TextLayout,
pos: impl Into<Point>
)
[src]
&mut self,
layout: &<CairoRenderContext<'a> as RenderContext>::TextLayout,
pos: impl Into<Point>
)
pub fn save(&mut self) -> Result<(), Error>
[src]
pub fn restore(&mut self) -> Result<(), Error>
[src]
pub fn finish(&mut self) -> Result<(), Error>
[src]
pub fn transform(&mut self, transform: Affine)
[src]
pub fn current_transform(&self) -> Affine
[src]
pub fn make_image(
&mut self,
width: usize,
height: usize,
buf: &[u8],
format: ImageFormat
) -> Result<<CairoRenderContext<'a> as RenderContext>::Image, Error>
[src]
&mut self,
width: usize,
height: usize,
buf: &[u8],
format: ImageFormat
) -> Result<<CairoRenderContext<'a> as RenderContext>::Image, Error>
pub fn draw_image(
&mut self,
image: &<CairoRenderContext<'a> as RenderContext>::Image,
dst_rect: impl Into<Rect>,
interp: InterpolationMode
)
[src]
&mut self,
image: &<CairoRenderContext<'a> as RenderContext>::Image,
dst_rect: impl Into<Rect>,
interp: InterpolationMode
)
pub fn draw_image_area(
&mut self,
image: &<CairoRenderContext<'a> as RenderContext>::Image,
src_rect: impl Into<Rect>,
dst_rect: impl Into<Rect>,
interp: InterpolationMode
)
[src]
&mut self,
image: &<CairoRenderContext<'a> as RenderContext>::Image,
src_rect: impl Into<Rect>,
dst_rect: impl Into<Rect>,
interp: InterpolationMode
)
pub fn capture_image_area(
&mut self,
_src_rect: impl Into<Rect>
) -> Result<<CairoRenderContext<'a> as RenderContext>::Image, Error>
[src]
&mut self,
_src_rect: impl Into<Rect>
) -> Result<<CairoRenderContext<'a> as RenderContext>::Image, Error>
pub fn blurred_rect(
&mut self,
rect: Rect,
blur_radius: f64,
brush: &impl IntoBrush<CairoRenderContext<'a>>
)
[src]
&mut self,
rect: Rect,
blur_radius: f64,
brush: &impl IntoBrush<CairoRenderContext<'a>>
)