PainterBase.h
1/* Copyright (C) 2006-2015 Laurentiu-Gheorghe Crisan
2 Copyright (C) 2006-2015 Marc Boris Duerner
3 Copyright (C) 2010-2017 Aloysius Indrayanto
4
5 This library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
9
10 As a special exception, you may use this file as part of a free
11 software library without restriction. Specifically, if other files
12 instantiate templates or use macros or inline functions from this
13 file, or you compile this file and link it with other files to
14 produce an executable, this file does not by itself cause the
15 resulting executable to be covered by the GNU General Public
16 License. This exception does not however invalidate any other
17 reasons why the executable file might be covered by the GNU Library
18 General Public License.
19
20 This library is distributed in the hope that it will be useful,
21 but WITHOUT ANY WARRANTY; without even the implied warranty of
22 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
23 Lesser General Public License for more details.
24
25 You should have received a copy of the GNU Lesser General Public
26 License along with this library; if not, write to the Free Software
27 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
28 MA 02110-1301 USA
29*/
30
31#ifndef PT_GFX_PAINTERBASE_H
32#define PT_GFX_PAINTERBASE_H
33
34#include <Pt/Gfx/Api.h>
35#include <Pt/Gfx/Size.h>
36#include <Pt/Gfx/Point.h>
37#include <Pt/Gfx/Rect.h>
38#include <Pt/Gfx/Font.h>
39#include <Pt/Gfx/FontMetrics.h>
40#include <Pt/Gfx/TextMetrics.h>
41#include <Pt/Gfx/Pen.h>
42#include <Pt/Gfx/Brush.h>
43#include <Pt/Gfx/Scaling.h>
44#include <Pt/Gfx/Transform.h>
45#include <Pt/Gfx/Path.h>
46#include <Pt/Gfx/CompositionMode.h>
47#include <Pt/Gfx/Paint.h>
48
49#include <Pt/NonCopyable.h>
50#include <Pt/String.h>
51#include <Pt/Types.h>
52
53#include <cstddef>
54
55namespace Pt {
56
57namespace Gfx {
58
59class Canvas;
60class Bitmap;
61class PaintSurface;
62class PaintContext;
63
84class PT_GFX_API PainterBase : private NonCopyable
85{
86 friend class PaintSurface;
87 friend class PaintContext;
88
89 protected:
93
94 public:
97 virtual ~PainterBase();
98
101 void finish();
102
105 const ImageFormat& format() const;
106
109 const Scaling& scaling() const;
110
111 public:
115
119
122 const Pen& pen() const;
123
126 void setPen(const Pen& pen);
127
130 const Brush& brush() const;
131
134 void setBrush(const Brush& brush);
135
138 const Font& font() const;
139
142 void setFont(const Font& font);
143
146 const Transform& transform() const;
147
150 void setTransform(const Transform& tx);
151
155
158 const RectF* clip() const;
159
162 void setClip(const RectF& clip);
163
166 void resetClip();
167
168 public:
171 void drawLine(const PointF& from, const PointF& to);
172
175 void drawPolyline(const PointF* points, const size_t pointCount);
176
179 void fillPolygon(const PointF* points, const size_t pointCount);
180
183 void drawRect(const RectF& rect);
184
187 void fillRect(const RectF& rect);
188
191 void drawCircle(const PointF& topLeft, double diameter);
192
195 void fillCircle(const PointF& topLeft, double diameter);
196
199 void drawEllipse(const PointF& topLeft, const SizeF& size);
200
203 void fillEllipse(const PointF& topLeft, const SizeF& size);
204
207 void drawArc(const PointF& topLeft, const SizeF& size,
208 float degBegin, float degEnd);
209
212 void fillChord(const PointF& topLeft, const SizeF& size,
213 float degBegin, float degEnd);
214
217 void fillPie(const PointF& topLeft, const SizeF& size,
218 float degBegin, float degEnd);
219
220 public:
223 const Gfx::Path& path() const;
224
227 void setPath(const Path& path);
228
231 void drawPath();
232
235 void fillPath();
236
239 void drawPath(const Path& path);
240
243 void fillPath(const Path& path);
244
245 public:
248 const FontMetrics& fontMetrics() const;
249
253
256 void drawText(const PointF& to, const Pt::String& text);
257
260 void drawText(const PointF& to, const Pt::String& text, const Transform& t);
261
262 public:
265 void drawImage(const PointF& to, const Image& im);
266
269 void drawImage(const PointF& to, const Image& im, const RectF& rect);
270
271 public:
274 void drawBitmap(const PointF& to, const Bitmap& bm);
275
278 void drawBitmap(const PointF& to, const Bitmap& bm, const RectF& rect);
279
280 protected:
283 void beginPaint(PaintSurface& surface);
284
287 void beginPaint(PaintContext& context);
288
291 const Paint& paint() const;
292
295 Canvas* canvas() const;
296
299 virtual void onDetachSurface(PaintSurface& surface);
300
303 virtual void onDetachContext(PaintContext& context);
304
305 private:
306 void onBeginPaint(Canvas& canvas);
307
308 void onSetContextClip(const RectF* clip);
309
310 void updateClip(const RectF* painterClip, const RectF* contextClip);
311
312 private:
313 PaintSurface* _surface;
314 PaintContext* _context;
315 Canvas* _canvas;
316 Paint _paint;
317 Scaling _scaling;
318 Transform _transform;
319 RectF _clip;
320 bool _hasClip;
321 Path _path;
322};
323
324} // namespace
325
326} // namespace
327
328#endif
Off-screen image that can be painted.
Definition Bitmap.h:71
Fill color, gradient or texture.
Definition Brush.h:151
Backend that executes drawing commands.
Definition Canvas.h:66
How new pixels combine with existing pixels.
Definition CompositionMode.h:49
Ascent, descent and line height of a font.
Definition FontMetrics.h:50
Font family, size and style.
Definition Font.h:63
Runtime pixel format.
Definition ImageFormat.h:72
Active painting session on a surface.
Definition PaintContext.h:61
Target for drawing operations.
Definition PaintSurface.h:66
Pen, brush, font and composition mode.
Definition Paint.h:53
const Paint & paint() const
Returns the current paint state.
void beginPaint(PaintSurface &surface)
Begins painting to a paint surface.
const Brush & brush() const
Returns the current brush.
void drawText(const PointF &to, const Pt::String &text)
Draws a line of text at the given position.
void setClip(const RectF &clip)
Sets the clipping rect.
const Transform & transform() const
Returns the user transform.
void drawPath(const Path &path)
Draws the given path.
const Pen & pen() const
Returns the current pen.
virtual void onDetachContext(PaintContext &context)
Called when the context is detached.
void setPath(const Path &path)
Sets the current path.
void drawBitmap(const PointF &to, const Bitmap &bm)
Draws a bitmap.
void drawEllipse(const PointF &topLeft, const SizeF &size)
Draws the outline of an ellipse.
const Font & font() const
Returns the current font.
void resetTransform()
Resets the user transform to identity.
const RectF * clip() const
Returns the current clip rectangle or null if clipping is disabled.
void drawBitmap(const PointF &to, const Bitmap &bm, const RectF &rect)
Draws a rectangular part of a bitmap.
void finish()
Ends the current painting operation.
PainterBase()
Default constructor.
const ImageFormat & format() const
Returns the pixel format of the current target.
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 setBrush(const Brush &brush)
Sets the brush used to fill areas.
void fillPie(const PointF &topLeft, const SizeF &size, float degBegin, float degEnd)
Fills a pie segment on an ellipse.
void drawImage(const PointF &to, const Image &im, const RectF &rect)
Draws a rectangular part of an image.
void fillChord(const PointF &topLeft, const SizeF &size, float degBegin, float degEnd)
Fills a chord on an ellipse.
void drawRect(const RectF &rect)
Draws the outline of a rectangle.
void setCompositionMode(const CompositionMode &mode)
Sets the composition mode.
void fillEllipse(const PointF &topLeft, const SizeF &size)
Fills an elliptical area.
const FontMetrics & fontMetrics() const
Returns the font metrics of the current font.
const Scaling & scaling() const
Returns the logical-to-physical scaling of the target.
void resetClip()
Resets the clipping rect.
const CompositionMode & compositionMode() const
Returns the current composition mode.
virtual void onDetachSurface(PaintSurface &surface)
Called when the surface is detached.
void fillPolygon(const PointF *points, const size_t pointCount)
Fills a polygon defined by the given points.
void drawImage(const PointF &to, const Image &im)
Draws an image.
void drawCircle(const PointF &topLeft, double diameter)
Draws the outline of a circle.
const Gfx::Path & path() const
Returns the current path.
void fillPath(const Path &path)
Fills the given path.
void drawText(const PointF &to, const Pt::String &text, const Transform &t)
Draws a line of text using an additional text transform.
Canvas * canvas() const
Returns the current canvas or null.
void setPen(const Pen &pen)
Sets the pen used to stroke lines.
void setTransform(const Transform &tx)
Sets the user transform.
void fillCircle(const PointF &topLeft, double diameter)
Fills a circular area.
void setFont(const Font &font)
Sets the font used to draw text.
void drawPath()
Draws the current path.
void beginPaint(PaintContext &context)
Begins painting to a paint context.
void drawArc(const PointF &topLeft, const SizeF &size, float degBegin, float degEnd)
Draws an arc on an ellipse.
TextMetrics textMetrics(const Pt::String &text) const
Measures a line of text using the current font.
virtual ~PainterBase()
Destructor.
void fillRect(const RectF &rect)
Fills a rectangular area.
void fillPath()
Fills the current path.
Sequence of lines and curves.
Definition Path.h:81
Outline color, width and style.
Definition Pen.h:59
Conversion between logical units and pixels.
Definition Scaling.h:52
Width and bounds of a text run.
Definition TextMetrics.h:49
2D affine transform.
Definition Transform.h:54
NonCopyable()
Default constructor.
Definition NonCopyable.h:63
Unicode capable basic_string.
Definition Api-String.h:67
Graphics and imaging services.
Definition Api-Argb32Image.h:12
Core module.
Definition Allocator.h:33