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

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

Public Member Functions

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

Protected Attributes

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

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());
...
Canvas(const Size &size, PixelFormat format=PixelFormat::argb8888) noexcept
Construct a canvas with the specified format and size.
SizeType< DefaultDim, detail::Compatible::normal > Size
Helper type alias.
Definition: geometry.h:566

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.