PaintContext.h
1 /* Copyright (C) 2015 Marc Boris Duerner
2 
3  This library is free software; you can redistribute it and/or
4  modify it under the terms of the GNU Lesser General Public
5  License as published by the Free Software Foundation; either
6  version 2.1 of the License, or (at your option) any later version.
7 
8  As a special exception, you may use this file as part of a free
9  software library without restriction. Specifically, if other files
10  instantiate templates or use macros or inline functions from this
11  file, or you compile this file and link it with other files to
12  produce an executable, this file does not by itself cause the
13  resulting executable to be covered by the GNU General Public
14  License. This exception does not however invalidate any other
15  reasons why the executable file might be covered by the GNU Library
16  General Public License.
17 
18  This library is distributed in the hope that it will be useful,
19  but WITHOUT ANY WARRANTY; without even the implied warranty of
20  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
21  Lesser General Public License for more details.
22 
23  You should have received a copy of the GNU Lesser General Public
24  License along with this library; if not, write to the Free Software
25  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
26  MA 02110-1301 USA
27 */
28 
29 #ifndef Pt_Gfx_PaintContext_h
30 #define Pt_Gfx_PaintContext_h
31 
32 #include <Pt/Gfx/Api.h>
33 #include <Pt/Gfx/ImageFormat.h>
34 #include <Pt/Gfx/Rect.h>
35 #include <Pt/Gfx/Scaling.h>
36 #include <Pt/NonCopyable.h>
37 
38 namespace Pt {
39 
40 namespace Gfx {
41 
42 class PainterBase;
43 class PaintSurface;
44 
52 class PT_GFX_API PaintContext : private NonCopyable
53 {
54  friend class PainterBase;
55  friend class PaintSurface;
56 
57  public:
60  explicit PaintContext(PaintSurface& surface);
61 
64  PaintContext(PaintSurface& surface, const RectF& clip);
65 
68  virtual ~PaintContext();
69 
72  const Gfx::ImageFormat& format() const;
73 
76  const Gfx::SizeF& size() const;
77 
80  const Scaling& scaling() const;
81 
84  const RectF* clip() const;
85 
88  void setClip(const RectF& clip);
89 
92  void resetClip();
93 
96  Canvas* getCanvas(Canvas* canvas);
97 
100  void sync();
101 
104  void finish();
105 
106  protected:
109  virtual void onDetachSurface(PaintSurface& surface);
110 
111  private:
112  PaintSurface* surface();
113 
114  void attachPainter(PainterBase& painter);
115 
116  void detachPainter(PainterBase& painter);
117 
118  private:
119  PaintSurface* _surface;
120  PainterBase* _painter;
121  RectF _clip;
122  bool _hasClip;
123 };
124 
125 } // namespace
126 
127 } // namespace
128 
129 #endif
Core module.
Definition: Allocator.h:33
const Scaling & scaling() const
Returns the scaling from logical to physical pixels.
void resetClip()
Resets the default clip rect.
Canvas * getCanvas(Canvas *canvas)
Returns a canvas for backend drawing.
const RectF * clip() const
Returns the default clip rect or null if clipping is disabled.
PaintContext(PaintSurface &surface, const RectF &clip)
Constructs a context using the paint surface and an initial clip rect.
Backend canvas for drawing commands.
Definition: Canvas.h:66
Active painting session for a surface.
Definition: PaintContext.h:53
Base class for drawing commands and paint state.
Definition: PainterBase.h:73
Logical-to-physical unit conversion.
Definition: Scaling.h:49
Size with floating-point width and height.
Definition: Size.h:47
virtual void onDetachSurface(PaintSurface &surface)
Handles detachment from the surface.
Image format.
Definition: ImageFormat.h:53
virtual ~PaintContext()
Destructor.
const Gfx::ImageFormat & format() const
Returns the image format.
Abstract target for drawing operations.
Definition: PaintSurface.h:55
const Gfx::SizeF & size() const
Returns the size in physical pixels.
void sync()
Synchronizes pending drawing operations.
void setClip(const RectF &clip)
Sets the default clip rect for painters on this context.
Protects derived classes from being copied.
Definition: NonCopyable.h:54
Rect with floating-point coordinates.
Definition: Rect.h:47
void finish()
Finishes painting on the surface.
PaintContext(PaintSurface &surface)
Constructs a context using the paint surface.