1.11
Classes | Public Types | Public Member Functions | Protected Attributes | List of all members
Painter Class Reference

Drawing interface for 2D graphics. More...

#include <painter.h>

Classes

struct  AutoGroup
 You are encouraged to use this instead of manually calling Painter::push_group() and Painter::pop_group(). More...
 
struct  AutoSaveRestore
 Scoped save() and restore() for a Painter. More...
 

Public Types

enum class  AntiAlias {
  system , none , gray , subpixel ,
  fast , good , best
}
 Supported types of anti-aliasing. More...
 
enum class  LineCap { butt , round , square }
 Supported line caps. More...
 
using SubordinateFilter = std::function< bool(const Widget &)>
 Return true if the subordinate widget is filtered out, hence should not be drawn by the painter.
 
enum class  TextDrawFlag : uint32_t { shadow = detail::bit(0) }
 
using TextDrawFlags = Flags< TextDrawFlag >
 

Public Member Functions

 Painter ()=delete
 
 Painter (Surface &surface) noexcept
 
 ~Painter ()
 
EGT_NODISCARD bool alpha_blending () const
 Get the alpha blending state, either enabled or disabled.
 
Painteralpha_blending (bool enabled)
 Set the alpha blending state either enabled or disabled.
 
EGT_NODISCARD Painter::AntiAlias antialias () const
 Get the current type of anti-aliasing.
 
Painterantialias (Painter::AntiAlias value)
 Set the type of anti-aliasing.
 
Painterarc (const ArcF &arc)
 
Painterclip ()
 
Color color_at (const Point &point) noexcept
 
void color_at (const Point &point, const Color &color) noexcept
 
EGT_NODISCARD const detail::InternalContext & context () const
 Get the current underlying context the painter is using.
 
template<class T >
Painterdraw (const ArcType< T > &arc)
 Create an arc.
 
Painterdraw (const Color &color, const RectF &rect={}, bool preserve=false)
 
Painterdraw (const Image &image)
 Draw an image surface at the specified point.
 
Painterdraw (const Image &image, const PointF &point, const RectF &rect={})
 
template<class T >
Painterdraw (const LineType< T > &line)
 Create a line.
 
Painterdraw (const Pattern &pattern, const RectF &rect={}, bool preserve=false)
 
template<class T >
Painterdraw (const PointType< T, detail::Compatible::normal > &point)
 Move to a point.
 
template<class T >
Painterdraw (const RectType< T > &rect)
 Create a rectangle.
 
Painterdraw (const std::string &str, const TextDrawFlags &flags={})
 Draw text inside the specified rectangle.
 
Painterdraw (const Surface &surface, const PointF &point, const RectF &rect={})
 
template<class T >
Painterdraw (const T &start, const T &end)
 Create a line from the start point to the end point.
 
EGT_NODISCARD Font::FontExtents extents () const
 Get the font extents based on the current context, hence taking into account transformations such as rotation or symmetry.
 
EGT_NODISCARD Font::TextExtents extents (const std::string &text) const
 Get the text extents based on the current context, hence taking into account transformations such as rotation or symmetry.
 
Painterfill ()
 
Painterfill_preserve ()
 
EGT_NODISCARD bool filter_subordinate (const Widget &subordinate) const
 Apply the current subordinate filter.
 
Painterflood (const Point &point, const Color &color)
 
void high_fidelity ()
 Configure high fidelity options.
 
template<class T >
Painterline (const PointType< T, detail::Compatible::normal > &point)
 
EGT_NODISCARD Painter::LineCap line_cap () const
 Get the current line cap.
 
Painterline_cap (Painter::LineCap value)
 Set the current line cap.
 
Painterline_to (const PointF &point)
 
Painterline_width (float width)
 Set the current line width.
 
void low_fidelity ()
 Configure low fidelity options.
 
Paintermask (const Image &image, const Point &point={})
 
Paintermask (const Surface &surface, const PointF &point={})
 Draw an image as a mask.
 
Paintermove_to (const PointF &point)
 
Painterpaint ()
 
Painterpaint (float alpha)
 
void pop_group ()
 Pop a group off the stack and automatically make it the source.
 
void push_group ()
 Push a group onto the stack.
 
Painterrectangle (const RectF &rect)
 
void restore ()
 Restore the previous saved state of the current context.
 
void restore_subordinate_filter (SubordinateFilter &&subordinate_filter)
 Restore the subordinate filter from a previous value.
 
Painterrotate (float angle)
 
void save ()
 Save the state of the current context.
 
Painterscale (float sx, float sy)
 
Painterset (const Font &font)
 Set the active font.
 
Painterset (const Pattern &pattern)
 Set the current color.
 
Painterset_dash (const double *dashes, size_t num_dashes, double offset)
 Set the dash pattern to be used by stroke().
 
SubordinateFilter set_subordinate_filter (const SubordinateFilter &subordinate_filter)
 Set the subordinate filter (nullptr to remove the current filter).
 
Paintershow_text (const char *utf8)
 
Paintershow_text (const std::string &str)
 
Paintersource (const Color &color)
 Set the source pattern from a Color.
 
Paintersource (const Image &image, const PointF &point={})
 Set the source pattern from an Image.
 
Paintersource (const Pattern &pattern)
 Set the source pattern from a Pattern.
 
Paintersource (const Surface &surface, const PointF &point={})
 Set the source pattern from a Surface.
 
Painterstroke ()
 
void sync_for_cpu (bool skip_source=false) const
 Claim the painter for being used by the CPU.
 
EGT_NODISCARD Surfacetarget ()
 
EGT_NODISCARD const Surfacetarget () const
 Get the target surface the painter is using.
 
Size text_size (const std::string &text)
 
Paintertranslate (const Point &point)
 
Paintertranslate (const PointF &point)
 

Protected Attributes

std::unique_ptr< detail::InternalContext > m_cr
 Internal context.
 
SubordinateFilter m_subordinate_filter
 Internal state.
 
Surfacem_surface
 

Detailed Description

Drawing interface for 2D graphics.

This is the interface for 2D drawing primitives that makes working with and drawing EGT primitives easier.

Member Typedef Documentation

◆ SubordinateFilter

using SubordinateFilter = std::function<bool(const Widget&)>

Return true if the subordinate widget is filtered out, hence should not be drawn by the painter.

◆ TextDrawFlags

Member Enumeration Documentation

◆ AntiAlias

enum class AntiAlias
strong

Supported types of anti-aliasing.

Enumerator
system 
none 
gray 
subpixel 
fast 
good 
best 

◆ LineCap

enum class LineCap
strong

Supported line caps.

Enumerator
butt 
round 
square 

◆ TextDrawFlag

enum class TextDrawFlag : uint32_t
strong
Enumerator
shadow 

Constructor & Destructor Documentation

◆ Painter() [1/2]

Painter ( )
delete

◆ Painter() [2/2]

Painter ( Surface surface)
explicitnoexcept

◆ ~Painter()

~Painter ( )

Member Function Documentation

◆ alpha_blending() [1/2]

EGT_NODISCARD bool alpha_blending ( ) const

Get the alpha blending state, either enabled or disabled.

◆ alpha_blending() [2/2]

Painter & alpha_blending ( bool  enabled)

Set the alpha blending state either enabled or disabled.

Parameters
[in]enabledWhether the alpha blending is to be enabled.
Note
disabling the alpha blending is like forcing the destination alpha to zero.

◆ antialias() [1/2]

EGT_NODISCARD Painter::AntiAlias antialias ( ) const

Get the current type of anti-aliasing.

◆ antialias() [2/2]

Painter & antialias ( Painter::AntiAlias  value)

Set the type of anti-aliasing.

Parameters
[in]valueAnti-aliasing type.

◆ arc()

Painter & arc ( const ArcF arc)

◆ clip()

Painter & clip ( )

◆ color_at() [1/2]

Color color_at ( const Point point)
noexcept

◆ color_at() [2/2]

void color_at ( const Point point,
const Color color 
)
noexcept

◆ context()

EGT_NODISCARD const detail::InternalContext & context ( ) const
inline

Get the current underlying context the painter is using.

◆ draw() [1/11]

template<class T >
Painter & draw ( const ArcType< T > &  arc)
inline

Create an arc.

Parameters
[in]arcThe arc.

◆ draw() [2/11]

Painter & draw ( const Color color,
const RectF rect = {},
bool  preserve = false 
)
Parameters
[in]colorThe source color to fill the @rect rectangle with.
[in]rectThe rectangle to draw, if any, the whole clip region otherwise.
[in]preserveIf true and @rect is not empty, reset the path to @rect.

◆ draw() [3/11]

Painter & draw ( const Image image)

Draw an image surface at the specified point.

◆ draw() [4/11]

Painter & draw ( const Image image,
const PointF point,
const RectF rect = {} 
)
Parameters
[in]imageThe image source to draw.
[in]pointThe position of the surface origin.
[in]rectThe rectangle to draw, if any, the whole image otherwise.

◆ draw() [5/11]

template<class T >
Painter & draw ( const LineType< T > &  line)
inline

Create a line.

Parameters
[in]lineThe line.

◆ draw() [6/11]

Painter & draw ( const Pattern pattern,
const RectF rect = {},
bool  preserve = false 
)
Parameters
[i]pattern The source pattern to fill the @rect rectangle with.
[in]rectThe rectangle to draw, if any, the whole clip region otherwise.
[in]preserveIf true and @rect is not empty, reset the path to @rect.

◆ draw() [7/11]

template<class T >
Painter & draw ( const PointType< T, detail::Compatible::normal > &  point)
inline

Move to a point.

Parameters
[in]pointThe point.

◆ draw() [8/11]

template<class T >
Painter & draw ( const RectType< T > &  rect)
inline

Create a rectangle.

Parameters
[in]rectThe rectangle.

◆ draw() [9/11]

Painter & draw ( const std::string &  str,
const TextDrawFlags flags = {} 
)

Draw text inside the specified rectangle.

◆ draw() [10/11]

Painter & draw ( const Surface surface,
const PointF point,
const RectF rect = {} 
)
Parameters
[in]surfaceThe surface source to draw.
[in]pointThe position of the surface origin.
[in]rectThe rectangle to draw, if any, the whole surface otherwise.

◆ draw() [11/11]

template<class T >
Painter & draw ( const T &  start,
const T &  end 
)
inline

Create a line from the start point to the end point.

Parameters
[in]startThe point.
[in]endThe point.

◆ extents() [1/2]

EGT_NODISCARD Font::FontExtents extents ( ) const

Get the font extents based on the current context, hence taking into account transformations such as rotation or symmetry.

◆ extents() [2/2]

EGT_NODISCARD Font::TextExtents extents ( const std::string &  text) const

Get the text extents based on the current context, hence taking into account transformations such as rotation or symmetry.

Parameters
[in]textThe UTF8 encoded text.

◆ fill()

Painter & fill ( )

◆ fill_preserve()

Painter & fill_preserve ( )

◆ filter_subordinate()

EGT_NODISCARD bool filter_subordinate ( const Widget subordinate) const

Apply the current subordinate filter.

Parameters
[in]subordinateThe widget to be tested.
Returns
true if the subordinate widget is filtered out, hence should not be drawn by the painter.

◆ flood()

Painter & flood ( const Point point,
const Color color 
)

◆ high_fidelity()

void high_fidelity ( )

Configure high fidelity options.

This configures settings related to font hinting, font aliasing, and shape aliasing.

◆ line()

template<class T >
Painter & line ( const PointType< T, detail::Compatible::normal > &  point)
inline

◆ line_cap() [1/2]

EGT_NODISCARD Painter::LineCap line_cap ( ) const

Get the current line cap.

◆ line_cap() [2/2]

Painter & line_cap ( Painter::LineCap  value)

Set the current line cap.

Parameters
[in]valueLine cap.

◆ line_to()

Painter & line_to ( const PointF point)

◆ line_width()

Painter & line_width ( float  width)

Set the current line width.

Parameters
[in]widthLine width.

◆ low_fidelity()

void low_fidelity ( )

Configure low fidelity options.

This configures settings related to font hinting, font aliasing, and shape aliasing.

◆ mask() [1/2]

Painter & mask ( const Image image,
const Point point = {} 
)

◆ mask() [2/2]

Painter & mask ( const Surface surface,
const PointF point = {} 
)

Draw an image as a mask.

◆ move_to()

Painter & move_to ( const PointF point)

◆ paint() [1/2]

Painter & paint ( )

◆ paint() [2/2]

Painter & paint ( float  alpha)

◆ pop_group()

void pop_group ( )

Pop a group off the stack and automatically make it the source.

See also
AutoGroup

◆ push_group()

void push_group ( )

Push a group onto the stack.

See also
AutoGroup

◆ rectangle()

Painter & rectangle ( const RectF rect)

◆ restore()

void restore ( )

Restore the previous saved state of the current context.

See also
AutoSaveRestore

◆ restore_subordinate_filter()

void restore_subordinate_filter ( SubordinateFilter &&  subordinate_filter)

Restore the subordinate filter from a previous value.

Parameters
[in]subordinate_filterThe saved subordinate filter to restore.

◆ rotate()

Painter & rotate ( float  angle)

◆ save()

void save ( )

Save the state of the current context.

See also
AutoSaveRestore

◆ scale()

Painter & scale ( float  sx,
float  sy 
)

◆ set() [1/2]

Painter & set ( const Font font)

Set the active font.

◆ set() [2/2]

Painter & set ( const Pattern pattern)

Set the current color.

◆ set_dash()

Painter & set_dash ( const double *  dashes,
size_t  num_dashes,
double  offset 
)

Set the dash pattern to be used by stroke().

Parameters
[in]dashesAn array specifying alternate lengths of on and off stroke portions.
[in]num_dashesThe length of the dashes array.
[in]offsetAn offset into the dash pattern at which the stroke should start.

◆ set_subordinate_filter()

SubordinateFilter set_subordinate_filter ( const SubordinateFilter subordinate_filter)

Set the subordinate filter (nullptr to remove the current filter).

Parameters
[in]subordinate_filterThe new subordinate filter.
Returns
a copy of the previous subordinate filter.

◆ show_text() [1/2]

Painter & show_text ( const char *  utf8)

◆ show_text() [2/2]

Painter & show_text ( const std::string &  str)
inline

◆ source() [1/4]

Painter & source ( const Color color)

Set the source pattern from a Color.

◆ source() [2/4]

Painter & source ( const Image image,
const PointF point = {} 
)

Set the source pattern from an Image.

◆ source() [3/4]

Painter & source ( const Pattern pattern)

Set the source pattern from a Pattern.

◆ source() [4/4]

Painter & source ( const Surface surface,
const PointF point = {} 
)

Set the source pattern from a Surface.

◆ stroke()

Painter & stroke ( )

◆ sync_for_cpu()

void sync_for_cpu ( bool  skip_source = false) const

Claim the painter for being used by the CPU.

Parameters
[in]skip_sourceThe boolean telling whether the source surface should be ignored.

Wait for all GPU operations, if any, to complete. Synchronize the target surface of the Painter instance. Also synchronize the source surface, if any, unless @skip_source is 'true'. Indeed, the source should be skipped if the rendering operations to come won't use it because a new source is about to be set.

◆ target() [1/2]

EGT_NODISCARD Surface & target ( )
inline

◆ target() [2/2]

EGT_NODISCARD const Surface & target ( ) const
inline

Get the target surface the painter is using.

◆ text_size()

Size text_size ( const std::string &  text)

◆ translate() [1/2]

Painter & translate ( const Point point)

◆ translate() [2/2]

Painter & translate ( const PointF point)

Member Data Documentation

◆ m_cr

std::unique_ptr<detail::InternalContext> m_cr
protected

Internal context.

◆ m_subordinate_filter

SubordinateFilter m_subordinate_filter
protected

Internal state.

◆ m_surface

Surface& m_surface
protected