CoreComponents 3.0.0
A Modern C++ Toolkit
Loading...
Searching...
No Matches
Painter Class Reference

Drawing 2D vector graphics. More...

#include <cc/Painter>

Public Types

using GetColor = Function<Color(int)>
 Get color for a given byte offset.
 

Drawing

enum class  CurrentPath { Clear , Preserve }
 Tells if to delete the current path after a stroke or fill operation. More...
 
PaintersetPen (Color color)
 Set source color
 
PaintersetPen (const Pen &pen)
 Set source color and line style in one go
 
Painterfill (CurrentPath mode=CurrentPath::Clear)
 Fill the current path.
 
Painterstroke (CurrentPath mode=CurrentPath::Clear)
 Stroke the outline of the current path.
 

Painter State

 Painter (const Surface &surface)
 Create a new painter for surface.
 
 Painter (Surface::State *state)
 Create a new painter.
 
 ~Painter ()
 Finish painting.
 
Paintersave ()
 Save painter state to the top of the state stack.
 
Painterrestore ()
 Restore painter state from the top of the state stack.
 
PainternextPage (bool clear=true)
 Emit current page.
 

Path Creation

PainternewPath ()
 Start a new path.
 
PainternewSubPath ()
 Start a new sub-path without setting an initial current point.
 
PainterclosePath ()
 Close path with a line segment.
 
bool hasCurrentPoint () const
 Check if there is a current point.
 
Point currentPoint () const
 Get the current point.
 
PaintermoveTo (Point c)
 Start a new sub-path starting at c.
 
PainterlineTo (Point c)
 Add a line segment to the path from the current point to the new current point c.
 
PaintercurveTo (Point a, Point b, Point c)
 Add a cubic Bézier spline starting in the current point, spanning over control points a, b and ending in the new current point c.
 
PainterarcAround (Point b, double alpha)
 Add an arc that starts at the current point and circles around point b alpha radians (-2*pi to +2*pi)
 
Painterarc (Point m, double r, double alpha0=0, double alpha1=2 *M_PI)
 Add a circular arc of radius r centered at m starting at angle alpha0 and ending at angle alpha1 (in radians)
 
PainterarcNegative (Point m, double r, double alpha0, double alpha1)
 Add a circular arc with alpha1 < alpha0.
 
Painterrectangle (Point pos, Size size)
 Add a closed sub-path in form of a rectangle with top-left at pos and given dimensions size.
 
Rect pathExtents () const
 Get the current path's extents.
 
Rect fillExtents () const
 Get the current path's exact rasterization extents.
 
PainteraddPath (const Path &path)
 Add path.
 

Text Rendering

PaintershowGlyphRun (Point pos, const GlyphRun &run)
 Show glyph run.
 
PaintershowGlyphRun (Point pos, const GlyphRun &run, const GetColor &ink, const GetColor &paper=GetColor{})
 Show glyph run with additional colors.
 
PaintershowTextRun (Point pos, const TextRun &run)
 Show text run.
 
PaintershowTextRun (Point pos, const TextRun &run, const GetColor &ink, const GetColor &paper)
 Show text run with additional colors.
 

Coordinate System Transformations

Paintertranslate (Step step)
 Move coordinate system by step.
 
Painterscale (Scale ratio)
 Scale coordinate system by ratio
 
Painterrotate (double angle)
 Rotate coordinate system by angle (in radian)
 

Detailed Description

Drawing 2D vector graphics.

Exceptions
PainterError
Todo

make showGlyphRun() and showTextRun() use the currentPoint() as baseline start

remove arcNegative() (automatically select the proper method)

Member Typedef Documentation

◆ GetColor

using GetColor = Function<Color(int)>

Get color for a given byte offset.

Member Enumeration Documentation

◆ CurrentPath

enum class CurrentPath
strong

Tells if to delete the current path after a stroke or fill operation.

Enumerator
Clear 

Clear the current path from the painting context

Preserve 

Preserve the painting context's current path

Constructor & Destructor Documentation

◆ Painter() [1/2]

Painter ( const Surface & surface)
explicit

Create a new painter for surface.

◆ Painter() [2/2]

Painter ( Surface::State * state)
explicit

Create a new painter.

◆ ~Painter()

~Painter ( )

Finish painting.

Member Function Documentation

◆ save()

Painter & save ( )

Save painter state to the top of the state stack.

◆ restore()

Painter & restore ( )

Restore painter state from the top of the state stack.

◆ nextPage()

Painter & nextPage ( bool clear = true)

Emit current page.

Parameters
clearStart with clean page

◆ newPath()

Painter & newPath ( )

Start a new path.

◆ newSubPath()

Painter & newSubPath ( )

Start a new sub-path without setting an initial current point.

◆ closePath()

Painter & closePath ( )

Close path with a line segment.

◆ hasCurrentPoint()

bool hasCurrentPoint ( ) const

Check if there is a current point.

◆ currentPoint()

Point currentPoint ( ) const

Get the current point.

◆ moveTo()

Painter & moveTo ( Point c)

Start a new sub-path starting at c.

◆ lineTo()

Painter & lineTo ( Point c)

Add a line segment to the path from the current point to the new current point c.

◆ curveTo()

Painter & curveTo ( Point a,
Point b,
Point c )

Add a cubic Bézier spline starting in the current point, spanning over control points a, b and ending in the new current point c.

◆ arcAround()

Painter & arcAround ( Point b,
double alpha )

Add an arc that starts at the current point and circles around point b alpha radians (-2*pi to +2*pi)

◆ arc()

Painter & arc ( Point m,
double r,
double alpha0 = 0,
double alpha1 = 2 * M_PI )

Add a circular arc of radius r centered at m starting at angle alpha0 and ending at angle alpha1 (in radians)

◆ arcNegative()

Painter & arcNegative ( Point m,
double r,
double alpha0,
double alpha1 )

Add a circular arc with alpha1 < alpha0.

◆ rectangle()

Painter & rectangle ( Point pos,
Size size )

Add a closed sub-path in form of a rectangle with top-left at pos and given dimensions size.

◆ pathExtents()

Rect pathExtents ( ) const

Get the current path's extents.

◆ fillExtents()

Rect fillExtents ( ) const

Get the current path's exact rasterization extents.

◆ addPath()

Painter & addPath ( const Path & path)

Add path.

◆ showGlyphRun() [1/2]

Painter & showGlyphRun ( Point pos,
const GlyphRun & run )

Show glyph run.

Parameters
posBaseline position
runGlyph run

◆ showGlyphRun() [2/2]

Painter & showGlyphRun ( Point pos,
const GlyphRun & run,
const GetColor & ink,
const GetColor & paper = GetColor{} )

Show glyph run with additional colors.

Parameters
posBaseline position
runGlyph run
inkForeground colors
paperBackground colors

◆ showTextRun() [1/2]

Painter & showTextRun ( Point pos,
const TextRun & run )

Show text run.

Parameters
posBaseline position
runText run

◆ showTextRun() [2/2]

Painter & showTextRun ( Point pos,
const TextRun & run,
const GetColor & ink,
const GetColor & paper )

Show text run with additional colors.

Parameters
posBaseline position
runText run
inkForeground colors
paperBackground colors

◆ translate()

Painter & translate ( Step step)

Move coordinate system by step.

◆ scale()

Painter & scale ( Scale ratio)

Scale coordinate system by ratio

◆ rotate()

Painter & rotate ( double angle)

Rotate coordinate system by angle (in radian)

◆ setPen() [1/2]

Painter & setPen ( Color color)

Set source color

◆ setPen() [2/2]

Painter & setPen ( const Pen & pen)

Set source color and line style in one go

◆ fill()

Fill the current path.

Parameters
modeTells if to delete the current path after a stroke or fill operation.

◆ stroke()

Stroke the outline of the current path.

Parameters
modeTells if to delete the current path after a stroke or fill operation.