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 
55 namespace Pt {
56 
57 namespace Gfx {
58 
59 class Canvas;
60 class Bitmap;
61 class PaintSurface;
62 class PaintContext;
63 
72 class PT_GFX_API PainterBase : private NonCopyable
73 {
74  friend class PaintSurface;
75  friend class PaintContext;
76 
77  protected:
81 
82  public:
85  virtual ~PainterBase();
86 
89  void finish();
90 
93  const ImageFormat& format() const;
94 
97  const Scaling& scaling() const;
98 
99  public:
103 
107 
110  const Pen& pen() const;
111 
114  void setPen(const Pen& pen);
115 
118  const Brush& brush() const;
119 
122  void setBrush(const Brush& brush);
123 
126  const Font& font() const;
127 
130  void setFont(const Font& font);
131 
134  const Transform& transform() const;
135 
138  void setTransform(const Transform& tx);
139 
143 
146  const RectF* clip() const;
147 
150  void setClip(const RectF& clip);
151 
154  void resetClip();
155 
156  public:
159  void drawLine(const PointF& from, const PointF& to);
160 
163  void drawPolyline(const PointF* points, const size_t pointCount);
164 
167  void fillPolygon(const PointF* points, const size_t pointCount);
168 
171  void drawRect(const RectF& rect);
172 
175  void fillRect(const RectF& rect);
176 
179  void drawCircle(const PointF& topLeft, double diameter);
180 
183  void fillCircle(const PointF& topLeft, double diameter);
184 
187  void drawEllipse(const PointF& topLeft, const SizeF& size);
188 
191  void fillEllipse(const PointF& topLeft, const SizeF& size);
192 
195  void drawArc(const PointF& topLeft, const SizeF& size,
196  float degBegin, float degEnd);
197 
200  void fillChord(const PointF& topLeft, const SizeF& size,
201  float degBegin, float degEnd);
202 
205  void fillPie(const PointF& topLeft, const SizeF& size,
206  float degBegin, float degEnd);
207 
208  public:
211  const Gfx::Path& path() const;
212 
215  void setPath(const Path& path);
216 
219  void drawPath();
220 
223  void fillPath();
224 
227  void drawPath(const Path& path);
228 
231  void fillPath(const Path& path);
232 
233  public:
236  const FontMetrics& fontMetrics() const;
237 
240  TextMetrics textMetrics(const Pt::String& text) const;
241 
244  void drawText(const PointF& to, const Pt::String& text);
245 
248  void drawText(const PointF& to, const Pt::String& text, const Transform& t);
249 
250  public:
253  void drawImage(const PointF& to, const Image& im);
254 
257  void drawImage(const PointF& to, const Image& im, const RectF& rect);
258 
259  public:
262  void drawBitmap(const PointF& to, const Bitmap& bm);
263 
266  void drawBitmap(const PointF& to, const Bitmap& bm, const RectF& rect);
267 
268  protected:
271  void beginPaint(PaintSurface& surface);
272 
275  void beginPaint(PaintContext& context);
276 
279  const Paint& paint() const;
280 
283  Canvas* canvas() const;
284 
287  virtual void onDetachSurface(PaintSurface& surface);
288 
291  virtual void onDetachContext(PaintContext& context);
292 
293  private:
294  void onBeginPaint(Canvas& canvas);
295 
296  private:
297  PaintSurface* _surface;
298  PaintContext* _context;
299  Canvas* _canvas;
300  Paint _paint;
301  Scaling _scaling;
302  Transform _transform;
303  RectF _clip;
304  bool _hasClip;
305  Path _path;
306 };
307 
308 } // namespace
309 
310 } // namespace
311 
312 #endif
virtual ~PainterBase()
Destructor.
Core module.
Definition: Allocator.h:33
void setBrush(const Brush &brush)
Sets the brush used to fill areas.
void drawPolyline(const PointF *points, const size_t pointCount)
Draws a connected sequence of line segments.
void setClip(const RectF &clip)
Sets the clipping rect.
Paint state used by drawing operations.
Definition: Paint.h:50
void setTransform(const Transform &tx)
Sets the user transform.
void drawRect(const RectF &rect)
Draws the outline of a rectangle.
Attributes for the drawing of outlines.
Definition: Pen.h:54
virtual void onDetachContext(PaintContext &context)
Called when the context is detached.
void drawCircle(const PointF &topLeft, double diameter)
Draws the outline of a circle.
void drawText(const PointF &to, const Pt::String &text)
Draws a line of text at the given position.
void fillCircle(const PointF &topLeft, double diameter)
Fills a circular area.
Backend canvas for drawing commands.
Definition: Canvas.h:66
void resetTransform()
Resets the user transform to identity.
Metrics that describe a font face at a given size.
Definition: FontMetrics.h:46
const CompositionMode & compositionMode() const
Returns the current composition mode.
void fillChord(const PointF &topLeft, const SizeF &size, float degBegin, float degEnd)
Fills a chord on an ellipse.
void fillRect(const RectF &rect)
Fills a rectangular area.
void finish()
Ends the current painting operation.
void drawLine(const PointF &from, const PointF &to)
Draws a line between two points.
const Scaling & scaling() const
Returns the logical-to-physical scaling of the target.
const Brush & brush() const
Returns the current brush.
void setCompositionMode(const CompositionMode &mode)
Sets the composition mode.
void fillPolygon(const PointF *points, const size_t pointCount)
Fills a polygon defined by the given points.
Active painting session for a surface.
Definition: PaintContext.h:52
Blend mode used for drawing operations.
Definition: CompositionMode.h:47
void drawImage(const PointF &to, const Image &im)
Draws an image.
const Paint & paint() const
Returns the current paint state.
void setPen(const Pen &pen)
Sets the pen used to stroke lines.
Base class for drawing commands and paint state.
Definition: PainterBase.h:73
void drawBitmap(const PointF &to, const Bitmap &bm, const RectF &rect)
Draws a rectangular part of a bitmap.
Logical-to-physical unit conversion.
Definition: Scaling.h:49
const RectF * clip() const
Returns the current clip rectangle or null if clipping is disabled.
Size with floating-point width and height.
Definition: Size.h:45
void fillPie(const PointF &topLeft, const SizeF &size, float degBegin, float degEnd)
Fills a pie segment on an ellipse.
const Transform & transform() const
Returns the user transform.
Point with floating-point X and Y coordinates.
Definition: Point.h:45
Image format.
Definition: ImageFormat.h:53
const ImageFormat & format() const
Returns the pixel format of the current target.
void beginPaint(PaintContext &context)
Begins painting to a paint context.
Metrics for a measured line of text.
Definition: TextMetrics.h:46
const Font & font() const
Returns the current font.
Affine transform for drawing coordinates.
Definition: Transform.h:49
void setFont(const Font &font)
Sets the font used to draw text.
Abstract target for drawing operations.
Definition: PaintSurface.h:55
const Pen & pen() const
Returns the current pen.
Vector path for drawing outlines and filled shapes.
Definition: Path.h:61
void beginPaint(PaintSurface &surface)
Begins painting to a paint surface.
void setPath(const Path &path)
Sets the current path.
Canvas * canvas() const
Returns the current canvas or null.
void drawText(const PointF &to, const Pt::String &text, const Transform &t)
Draws a line of text using an additional text transform.
void resetClip()
Resets the clipping rect.
void drawArc(const PointF &topLeft, const SizeF &size, float degBegin, float degEnd)
Draws an arc on an ellipse.
Font request used for text drawing and measurement.
Definition: Font.h:56
void drawPath(const Path &path)
Draws the given path.
Basic image.
Definition: Image.h:52
void fillEllipse(const PointF &topLeft, const SizeF &size)
Fills an elliptical area.
void fillPath(const Path &path)
Fills the given path.
void drawPath()
Draws the current path.
TextMetrics textMetrics(const Pt::String &text) const
Measures a line of text using the current font.
void drawImage(const PointF &to, const Image &im, const RectF &rect)
Draws a rectangular part of an image.
Unicode capable basic_string.
Definition: Api-String.h:44
Protects derived classes from being copied.
Definition: NonCopyable.h:54
void fillPath()
Fills the current path.
void drawEllipse(const PointF &topLeft, const SizeF &size)
Draws the outline of an ellipse.
Fill description for shapes and text.
Definition: Brush.h:145
Rect with floating-point coordinates.
Definition: Rect.h:45
Off-screen drawing surface backed by an image.
Definition: Bitmap.h:60
PainterBase()
Default constructor.
const Gfx::Path & path() const
Returns the current path.
void drawBitmap(const PointF &to, const Bitmap &bm)
Draws a bitmap.
const FontMetrics & fontMetrics() const
Returns the font metrics of the current font.
virtual void onDetachSurface(PaintSurface &surface)
Called when the surface is detached.