1.10
Public Member Functions | Protected Attributes | List of all members
Canvas Class Reference

Manages a unique drawing surface and context. More...

#include <canvas.h>

Public Member Functions

 Canvas (const shared_cairo_surface_t &surface) noexcept
 Construct a canvas with an already existing surface.
 
 Canvas (const shared_cairo_surface_t &surface, PixelFormat format) noexcept
 Construct a canvas with an already existing surface, and specify the format of the surface the canvas create a copy to.
 
 Canvas (const Size &size, PixelFormat format=PixelFormat::argb8888) noexcept
 Construct a canvas with the specified format and size.
 
 Canvas (const SizeF &size, PixelFormat format=PixelFormat::argb8888) noexcept
 Construct a canvas with the specified format and size.
 
EGT_NODISCARD shared_cairo_t context () const
 Get the context for the Canvas.
 
void copy (const shared_cairo_surface_t &surface)
 Create a copy of a surface.
 
void copy (const shared_cairo_surface_t &surface, const RectF &rect)
 
EGT_NODISCARD PixelFormat format () const
 Get the format of the surface.
 
void reallocate (const Size &size, PixelFormat format=PixelFormat::argb8888)
 Reallocate the canvas to a different size.
 
void reallocate (const SizeF &size, PixelFormat format=PixelFormat::argb8888)
 Reallocate the canvas to a different size.
 
EGT_NODISCARD Size size () const
 Get the size of the surface.
 
EGT_NODISCARD shared_cairo_surface_t surface () const
 Get the surface for the Canvas.
 
void zero ()
 Fill the surface with zero (including for transparency channel if applicable).
 

Protected Attributes

shared_cairo_t m_cr
 The context of the canvas.
 
shared_cairo_surface_t m_surface
 The surface of the canvas.
 

Detailed Description

Manages a unique drawing surface and context.

This can be created and directly drawn to with Painter.

This is useful, for example, if you need a temporary or intermediate buffer for drawing to.

Example

Canvas canvas(Size(100,100));
Painter painter(canvas.context());
...
Manages a unique drawing surface and context.
Definition canvas.h:41
Drawing interface for 2D graphics.
Definition painter.h:45
SizeType< DefaultDim, detail::Compatible::normal > Size
Helper type alias.
Definition geometry.h:573

Constructor & Destructor Documentation

◆ Canvas() [1/4]

Canvas ( const Size size,
PixelFormat  format = PixelFormat::argb8888 
)
explicitnoexcept

Construct a canvas with the specified format and size.

Parameters
[in]sizeThe size of the canvas.
[in]formatThe pixel format for the canvas.
Note
The canvas contents are undefined. zero() can be used to initialize it.

◆ Canvas() [2/4]

Canvas ( const SizeF size,
PixelFormat  format = PixelFormat::argb8888 
)
explicitnoexcept

Construct a canvas with the specified format and size.

Parameters
[in]sizeThe size of the canvas.
[in]formatThe pixel format for the canvas.
Note
The canvas contents are undefined. zero() can be used to initialize it.

◆ Canvas() [3/4]

Canvas ( const shared_cairo_surface_t surface)
explicitnoexcept

Construct a canvas with an already existing surface.

The canvas will create a copy of the supplied surface.

Parameters
[in]surfaceThe surface to copy from. A copy will be made.

◆ Canvas() [4/4]

Canvas ( const shared_cairo_surface_t surface,
PixelFormat  format 
)
noexcept

Construct a canvas with an already existing surface, and specify the format of the surface the canvas create a copy to.

The canvas will create a copy of the supplied surface.

Parameters
[in]surfaceThe surface to copy from. A copy will be made.
[in]formatThe pixel format for the canvas.

Member Function Documentation

◆ context()

EGT_NODISCARD shared_cairo_t context ( ) const
inline

Get the context for the Canvas.

◆ copy() [1/2]

void copy ( const shared_cairo_surface_t surface)

Create a copy of a surface.

◆ copy() [2/2]

void copy ( const shared_cairo_surface_t surface,
const RectF rect 
)

◆ format()

EGT_NODISCARD PixelFormat format ( ) const

Get the format of the surface.

◆ reallocate() [1/2]

void reallocate ( const Size size,
PixelFormat  format = PixelFormat::argb8888 
)

Reallocate the canvas to a different size.

Parameters
[in]sizeThe size of the canvas.
[in]formatThe pixel format for the canvas.

◆ reallocate() [2/2]

void reallocate ( const SizeF size,
PixelFormat  format = PixelFormat::argb8888 
)

Reallocate the canvas to a different size.

Parameters
[in]sizeThe size of the canvas.
[in]formatThe pixel format for the canvas.

◆ size()

EGT_NODISCARD Size size ( ) const

Get the size of the surface.

◆ surface()

EGT_NODISCARD shared_cairo_surface_t surface ( ) const
inline

Get the surface for the Canvas.

◆ zero()

void zero ( )

Fill the surface with zero (including for transparency channel if applicable).

Note
This is not done by default when creating a canvas.

Member Data Documentation

◆ m_cr

shared_cairo_t m_cr
protected

The context of the canvas.

◆ m_surface

shared_cairo_surface_t m_surface
protected

The surface of the canvas.