#include <Pt/Gfx/Painter.h>

Painter for a surface or a paint context. More...

Inherits PainterBase.

Public Member Functions

 Painter ()
 Constructs an inactive painter.
 Painter (PaintSurface &surface)
 Constructs and begins painting on a surface.
 Painter (PaintContext &context)
 Constructs and begins painting on a context.
virtual ~Painter ()
 Destructor.
void begin (PaintSurface &surface)
 Begins painting on a surface.
void begin (PaintContext &context)
 Begins painting on a context.
void finish ()
 Ends the current painting operation.
const ImageFormatformat () const
 Returns the pixel format of the current target.
const Scalingscaling () const
 Returns the logical-to-physical scaling of the target.
const CompositionModecompositionMode () const
 Returns the current composition mode.
void setCompositionMode (const CompositionMode &mode)
 Sets the composition mode.
const Penpen () const
 Returns the current pen.
void setPen (const Pen &pen)
 Sets the pen used to stroke lines.
const Brushbrush () const
 Returns the current brush.
void setBrush (const Brush &brush)
 Sets the brush used to fill areas.
const Fontfont () const
 Returns the current font.
void setFont (const Font &font)
 Sets the font used to draw text.
const Transformtransform () const
 Returns the user transform.
void setTransform (const Transform &tx)
 Sets the user transform.
void resetTransform ()
 Resets the user transform to identity.
const RectF * clip () const
 Returns the current clip rectangle or null if clipping is disabled.
void setClip (const RectF &clip)
 Sets the clipping rect.
void resetClip ()
 Resets the clipping rect.
void drawLine (const PointF &from, const PointF &to)
 Draws a line between two points.
void drawPolyline (const PointF *points, const size_t pointCount)
 Draws a connected sequence of line segments.
void fillPolygon (const PointF *points, const size_t pointCount)
 Fills a polygon defined by the given points.
void drawRect (const RectF &rect)
 Draws the outline of a rectangle.
void fillRect (const RectF &rect)
 Fills a rectangular area.
void drawCircle (const PointF &topLeft, double diameter)
 Draws the outline of a circle.
void fillCircle (const PointF &topLeft, double diameter)
 Fills a circular area.
void drawEllipse (const PointF &topLeft, const SizeF &size)
 Draws the outline of an ellipse.
void fillEllipse (const PointF &topLeft, const SizeF &size)
 Fills an elliptical area.
void drawArc (const PointF &topLeft, const SizeF &size, float degBegin, float degEnd)
 Draws an arc on an ellipse.
void fillChord (const PointF &topLeft, const SizeF &size, float degBegin, float degEnd)
 Fills a chord on an ellipse.
void fillPie (const PointF &topLeft, const SizeF &size, float degBegin, float degEnd)
 Fills a pie segment on an ellipse.
const Gfx::Pathpath () const
 Returns the current path.
void setPath (const Path &path)
 Sets the current path.
void drawPath ()
 Draws the current path.
void drawPath (const Path &path)
 Draws the given path.
void fillPath ()
 Fills the current path.
void fillPath (const Path &path)
 Fills the given path.
const FontMetricsfontMetrics () const
 Returns the font metrics of the current font.
TextMetrics textMetrics (const Pt::String &text) const
 Measures a line of text using the current font.
void drawText (const PointF &to, const Pt::String &text)
 Draws a line of text at the given position.
void drawText (const PointF &to, const Pt::String &text, const Transform &t)
 Draws a line of text using an additional text transform.
void drawImage (const PointF &to, const Image &im)
 Draws an image.
void drawImage (const PointF &to, const Image &im, const RectF &rect)
 Draws a rectangular part of an image.
void drawBitmap (const PointF &to, const Bitmap &bm)
 Draws a bitmap.
void drawBitmap (const PointF &to, const Bitmap &bm, const RectF &rect)
 Draws a rectangular part of a bitmap.

Protected Member Functions

void beginPaint (PaintSurface &surface)
 Begins painting to a paint surface.
void beginPaint (PaintContext &context)
 Begins painting to a paint context.
const Paintpaint () const
 Returns the current paint state.
Canvascanvas () const
 Returns the current canvas or null.
virtual void onDetachSurface (PaintSurface &surface)
 Called when the surface is detached.
virtual void onDetachContext (PaintContext &context)
 Called when the context is detached.

Detailed Description

Painter is the type a caller constructs to draw. It begins a session on a PaintSurface or on an existing PaintContext, through a constructor or begin(). Drawing commands live on PainterBase. This type does not own the surface or the context. One painter is bound to at most one target at a time. finish() ends the session.

The example begins painting on a bitmap and fills it.

Pt::Gfx::Bitmap bitmap(Pt::Gfx::SizeF(64, 64));
Pt::Gfx::Painter painter(bitmap);
painter.setBrush(Pt::Gfx::Brush(Pt::Gfx::Color(255, 255, 255)));
painter.fillRect(Pt::Gfx::RectF(Pt::Gfx::SizeF(64, 64)));
painter.finish();
Off-screen image that can be painted.
Definition Bitmap.h:71
Fill color, gradient or texture.
Definition Brush.h:151
8-bit ARGB color.
Definition Color.h:65
Painter for a surface or a paint context.
Definition Painter.h:62