1.1-rc3
Classes | Public Types | Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
Painter Class Reference

Drawing interface for 2D graphics. More...

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  TextDrawFlag : uint32_t { shadow = detail::bit(0) }
 
using TextDrawFlags = Flags< TextDrawFlag >
 

Public Member Functions

 Painter ()=delete
 
 Painter (shared_cairo_t cr) noexcept
 Construct a Painter with an existing context. More...
 
Painterclip ()
 
Color color_at (const Point &point) noexcept
 
void color_at (const Point &point, const Color &color) noexcept
 
EGT_NODISCARD shared_cairo_t context () const
 Get the current underlying context the painter is using. More...
 
template<class T >
Painterdraw (const ArcType< T > &arc)
 Create an arc. More...
 
template<class T >
Painterdraw (const CircleType< T > &arc)
 Create a circle. More...
 
Painterdraw (const Image &image)
 Draw an image surface at the specified point. More...
 
template<class T >
Painterdraw (const LineType< T > &line)
 Create a line. More...
 
template<class T >
Painterdraw (const PointType< T, detail::Compatible::normal > &point)
 Move to a point. More...
 
Painterdraw (const Rect &rect, const Image &image)
 
template<class T >
Painterdraw (const RectType< T > &rect)
 Create a rectangle. More...
 
Painterdraw (const std::string &str, const TextDrawFlags &flags={})
 Draw text inside the specified rectangle. More...
 
template<class T >
Painterdraw (const T &start, const T &end)
 Create a line from the start point to the end point. More...
 
Painterfill ()
 
Painterflood (const Point &point, const Color &color)
 
Size font_size (const std::string &text)
 
template<class T >
Painterline (const PointType< T, detail::Compatible::normal > &point)
 
Painterline_width (float width)
 Set the current line width. More...
 
Paintermask (const Image &image, const Point &point={})
 Draw an image as a mask. More...
 
Painterpaint ()
 
Painterpaint (float alpha)
 
void pop_group ()
 Pop a group off the stack and automatically make it the source. More...
 
void push_group ()
 Push a group onto the stack. More...
 
void restore ()
 Restore the previous saved state of the current context. More...
 
void save ()
 Save the state of the current context. More...
 
Painterset (const Font &font)
 Set the active font. More...
 
Painterset (const Pattern &pattern)
 Set the current color. More...
 
Painterstroke ()
 
Size text_size (const std::string &text)
 

Static Public Member Functions

static Color color_at (cairo_surface_t *image, const Point &point) noexcept
 
static void color_at (cairo_surface_t *image, const Point &point, const Color &color) noexcept
 
static void flood (cairo_surface_t *image, const Point &point, const Color &color)
 
static Size surface_to_size (cairo_surface_t *surface)
 Get a Size from a surface. More...
 
static Size surface_to_size (const shared_cairo_surface_t &surface)
 Get a Size from a surface. More...
 

Protected Attributes

shared_cairo_t m_cr
 Cairo context. More...
 

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

◆ TextDrawFlags

Member Enumeration Documentation

◆ TextDrawFlag

enum TextDrawFlag : uint32_t
strong
Enumerator
shadow 

Constructor & Destructor Documentation

◆ Painter() [1/2]

Painter ( )
delete

◆ Painter() [2/2]

Painter ( shared_cairo_t  cr)
explicitnoexcept

Construct a Painter with an existing context.

Todo:
Painter needs to come from the Screen. This constructor should be hidden and you should have to get a custom version of it from the Screen for drawing. A default software/GPU painter can be created, otherwise for something like X11 we should be using X11 to paint.

Member Function Documentation

◆ clip()

Painter& clip ( )

◆ color_at() [1/4]

static Color color_at ( cairo_surface_t *  image,
const Point point 
)
staticnoexcept

◆ color_at() [2/4]

static void color_at ( cairo_surface_t *  image,
const Point point,
const Color color 
)
staticnoexcept

◆ color_at() [3/4]

Color color_at ( const Point point)
noexcept

◆ color_at() [4/4]

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

◆ context()

EGT_NODISCARD shared_cairo_t context ( ) const
inline

Get the current underlying context the painter is using.

◆ draw() [1/9]

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

Create an arc.

Parameters
[in]arcThe arc.

◆ draw() [2/9]

Painter& draw ( const CircleType< T > &  arc)
inline

Create a circle.

Parameters
[in]arcThe circle.

◆ draw() [3/9]

Painter& draw ( const Image image)

Draw an image surface at the specified point.

◆ draw() [4/9]

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

Create a line.

Parameters
[in]lineThe line.

◆ draw() [5/9]

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

Move to a point.

Parameters
[in]pointThe point.

◆ draw() [6/9]

Painter& draw ( const Rect rect,
const Image image 
)
Parameters
[in]rectThe source rect to copy.
[in]imageThe image surface to draw.

◆ draw() [7/9]

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

Create a rectangle.

Parameters
[in]rectThe rectangle.

◆ draw() [8/9]

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

Draw text inside the specified rectangle.

◆ draw() [9/9]

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.

◆ fill()

Painter& fill ( )

◆ flood() [1/2]

static void flood ( cairo_surface_t *  image,
const Point point,
const Color color 
)
static

◆ flood() [2/2]

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

◆ font_size()

Size font_size ( const std::string &  text)

◆ line()

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

◆ line_width()

Painter& line_width ( float  width)

Set the current line width.

Parameters
[in]widthLine width.

◆ mask()

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

Draw an image as a mask.

◆ 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

◆ restore()

void restore ( )

Restore the previous saved state of the current context.

See also
AutoSaveRestore

◆ save()

void save ( )

Save the state of the current context.

See also
AutoSaveRestore

◆ set() [1/2]

Painter& set ( const Font font)

Set the active font.

◆ set() [2/2]

Painter& set ( const Pattern pattern)

Set the current color.

◆ stroke()

Painter& stroke ( )

◆ surface_to_size() [1/2]

static Size surface_to_size ( cairo_surface_t *  surface)
inlinestatic

Get a Size from a surface.

◆ surface_to_size() [2/2]

static Size surface_to_size ( const shared_cairo_surface_t surface)
inlinestatic

Get a Size from a surface.

◆ text_size()

Size text_size ( const std::string &  text)

Member Data Documentation

◆ m_cr

shared_cairo_t m_cr
protected

Cairo context.