![]() |
1.11 |
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. | |
Painter & | alpha_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. | |
Painter & | antialias (Painter::AntiAlias value) |
Set the type of anti-aliasing. | |
Painter & | arc (const ArcF &arc) |
Painter & | clip () |
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 > | |
Painter & | draw (const ArcType< T > &arc) |
Create an arc. | |
Painter & | draw (const Color &color, const RectF &rect={}, bool preserve=false) |
Painter & | draw (const Image &image) |
Draw an image surface at the specified point. | |
Painter & | draw (const Image &image, const PointF &point, const RectF &rect={}) |
template<class T > | |
Painter & | draw (const LineType< T > &line) |
Create a line. | |
Painter & | draw (const Pattern &pattern, const RectF &rect={}, bool preserve=false) |
template<class T > | |
Painter & | draw (const PointType< T, detail::Compatible::normal > &point) |
Move to a point. | |
template<class T > | |
Painter & | draw (const RectType< T > &rect) |
Create a rectangle. | |
Painter & | draw (const std::string &str, const TextDrawFlags &flags={}) |
Draw text inside the specified rectangle. | |
Painter & | draw (const Surface &surface, const PointF &point, const RectF &rect={}) |
template<class T > | |
Painter & | draw (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. | |
Painter & | fill () |
Painter & | fill_preserve () |
EGT_NODISCARD bool | filter_subordinate (const Widget &subordinate) const |
Apply the current subordinate filter. | |
Painter & | flood (const Point &point, const Color &color) |
void | high_fidelity () |
Configure high fidelity options. | |
template<class T > | |
Painter & | line (const PointType< T, detail::Compatible::normal > &point) |
EGT_NODISCARD Painter::LineCap | line_cap () const |
Get the current line cap. | |
Painter & | line_cap (Painter::LineCap value) |
Set the current line cap. | |
Painter & | line_to (const PointF &point) |
Painter & | line_width (float width) |
Set the current line width. | |
void | low_fidelity () |
Configure low fidelity options. | |
Painter & | mask (const Image &image, const Point &point={}) |
Painter & | mask (const Surface &surface, const PointF &point={}) |
Draw an image as a mask. | |
Painter & | move_to (const PointF &point) |
Painter & | paint () |
Painter & | paint (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. | |
Painter & | rectangle (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. | |
Painter & | rotate (float angle) |
void | save () |
Save the state of the current context. | |
Painter & | scale (float sx, float sy) |
Painter & | set (const Font &font) |
Set the active font. | |
Painter & | set (const Pattern &pattern) |
Set the current color. | |
Painter & | set_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). | |
Painter & | show_text (const char *utf8) |
Painter & | show_text (const std::string &str) |
Painter & | source (const Color &color) |
Set the source pattern from a Color. | |
Painter & | source (const Image &image, const PointF &point={}) |
Set the source pattern from an Image. | |
Painter & | source (const Pattern &pattern) |
Set the source pattern from a Pattern. | |
Painter & | source (const Surface &surface, const PointF &point={}) |
Set the source pattern from a Surface. | |
Painter & | stroke () |
void | sync_for_cpu (bool skip_source=false) const |
Claim the painter for being used by the CPU. | |
EGT_NODISCARD Surface & | target () |
EGT_NODISCARD const Surface & | target () const |
Get the target surface the painter is using. | |
Size | text_size (const std::string &text) |
Painter & | translate (const Point &point) |
Painter & | translate (const PointF &point) |
Protected Attributes | |
std::unique_ptr< detail::InternalContext > | m_cr |
Internal context. | |
SubordinateFilter | m_subordinate_filter |
Internal state. | |
Surface & | m_surface |
Drawing interface for 2D graphics.
This is the interface for 2D drawing primitives that makes working with and drawing EGT primitives easier.
using SubordinateFilter = std::function<bool(const Widget&)> |
Return true if the subordinate widget is filtered out, hence should not be drawn by the painter.
using TextDrawFlags = Flags<TextDrawFlag> |
|
strong |
|
strong |
|
strong |
|
delete |
~Painter | ( | ) |
EGT_NODISCARD bool alpha_blending | ( | ) | const |
Get the alpha blending state, either enabled or disabled.
Painter & alpha_blending | ( | bool | enabled | ) |
Set the alpha blending state either enabled or disabled.
[in] | enabled | Whether the alpha blending is to be enabled. |
EGT_NODISCARD Painter::AntiAlias antialias | ( | ) | const |
Get the current type of anti-aliasing.
Painter & antialias | ( | Painter::AntiAlias | value | ) |
Set the type of anti-aliasing.
[in] | value | Anti-aliasing type. |
Painter & clip | ( | ) |
|
inline |
Get the current underlying context the painter is using.
Create an arc.
[in] | arc | The arc. |
[in] | color | The source color to fill the @rect rectangle with. |
[in] | rect | The rectangle to draw, if any, the whole clip region otherwise. |
[in] | preserve | If true and @rect is not empty, reset the path to @rect. |
[in] | image | The image source to draw. |
[in] | point | The position of the surface origin. |
[in] | rect | The rectangle to draw, if any, the whole image otherwise. |
Create a line.
[in] | line | The line. |
[i] | pattern The source pattern to fill the @rect rectangle with. | |
[in] | rect | The rectangle to draw, if any, the whole clip region otherwise. |
[in] | preserve | If true and @rect is not empty, reset the path to @rect. |
|
inline |
Move to a point.
[in] | point | The point. |
Create a rectangle.
[in] | rect | The rectangle. |
Painter & draw | ( | const std::string & | str, |
const TextDrawFlags & | flags = {} |
||
) |
Draw text inside the specified rectangle.
[in] | surface | The surface source to draw. |
[in] | point | The position of the surface origin. |
[in] | rect | The rectangle to draw, if any, the whole surface otherwise. |
|
inline |
Create a line from the start point to the end point.
[in] | start | The point. |
[in] | end | The 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.
[in] | text | The UTF8 encoded text. |
Painter & fill | ( | ) |
Painter & fill_preserve | ( | ) |
EGT_NODISCARD bool filter_subordinate | ( | const Widget & | subordinate | ) | const |
Apply the current subordinate filter.
[in] | subordinate | The widget to be tested. |
void high_fidelity | ( | ) |
Configure high fidelity options.
This configures settings related to font hinting, font aliasing, and shape aliasing.
|
inline |
EGT_NODISCARD Painter::LineCap line_cap | ( | ) | const |
Get the current line cap.
Painter & line_cap | ( | Painter::LineCap | value | ) |
Set the current line cap.
[in] | value | Line cap. |
Painter & line_width | ( | float | width | ) |
Set the current line width.
[in] | width | Line width. |
void low_fidelity | ( | ) |
Configure low fidelity options.
This configures settings related to font hinting, font aliasing, and shape aliasing.
Painter & paint | ( | ) |
Painter & paint | ( | 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.
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.
[in] | subordinate_filter | The saved subordinate filter to restore. |
Painter & rotate | ( | float | angle | ) |
void save | ( | ) |
Save the state of the current context.
Painter & scale | ( | float | sx, |
float | sy | ||
) |
Painter & set_dash | ( | const double * | dashes, |
size_t | num_dashes, | ||
double | offset | ||
) |
Set the dash pattern to be used by stroke().
[in] | dashes | An array specifying alternate lengths of on and off stroke portions. |
[in] | num_dashes | The length of the dashes array. |
[in] | offset | An offset into the dash pattern at which the stroke should start. |
SubordinateFilter set_subordinate_filter | ( | const SubordinateFilter & | subordinate_filter | ) |
Set the subordinate filter (nullptr to remove the current filter).
[in] | subordinate_filter | The new subordinate filter. |
Painter & show_text | ( | const char * | utf8 | ) |
|
inline |
Set the source pattern from an Image.
Set the source pattern from a Surface.
Painter & stroke | ( | ) |
void sync_for_cpu | ( | bool | skip_source = false | ) | const |
Claim the painter for being used by the CPU.
[in] | skip_source | The 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.
|
inline |
|
inline |
Get the target surface the painter is using.
Size text_size | ( | const std::string & | text | ) |
|
protected |
Internal context.
|
protected |
Internal state.
|
protected |