PaintSurface.h
1 /* Copyright (C) 2015 Marc Boris Duerner
2  Copyright (C) 2015 Laurentiu-Gheorghe Crisan
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Lesser General Public
6  License as published by the Free Software Foundation; either
7  version 2.1 of the License, or (at your option) any later version.
8 
9  As a special exception, you may use this file as part of a free
10  software library without restriction. Specifically, if other files
11  instantiate templates or use macros or inline functions from this
12  file, or you compile this file and link it with other files to
13  produce an executable, this file does not by itself cause the
14  resulting executable to be covered by the GNU General Public
15  License. This exception does not however invalidate any other
16  reasons why the executable file might be covered by the GNU Library
17  General Public License.
18 
19  This library is distributed in the hope that it will be useful,
20  but WITHOUT ANY WARRANTY; without even the implied warranty of
21  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  Lesser General Public License for more details.
23 
24  You should have received a copy of the GNU Lesser General Public
25  License along with this library; if not, write to the Free Software
26  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
27  MA 02110-1301 USA
28 */
29 
30 #ifndef Pt_Gfx_PaintSurface_h
31 #define Pt_Gfx_PaintSurface_h
32 
33 #include <Pt/Gfx/Api.h>
34 #include <Pt/Gfx/ImageFormat.h>
35 #include <Pt/Gfx/Scaling.h>
36 #include <Pt/NonCopyable.h>
37 #include <Pt/System/Path.h>
38 
39 #include <vector>
40 
41 namespace Pt {
42 
43 namespace Gfx {
44 
45 class PaintContext;
46 
54 class PT_GFX_API PaintSurface : private NonCopyable
55 {
56  friend class PainterBase;
57  friend class PaintContext;
58  friend class Canvas;
59 
60  protected:
64 
65  public:
68  virtual ~PaintSurface();
69 
72  const Gfx::ImageFormat& format() const;
73 
76  const Gfx::SizeF& size() const;
77 
80  const Scaling& scaling() const;
81 
84  Canvas* getCanvas(Canvas* canvas);
85 
88  void sync();
89 
92  void finish();
93 
94  protected:
97  void invalidate();
98 
99  protected:
102  virtual const Gfx::ImageFormat& onGetFormat() const = 0;
103 
106  virtual const Gfx::SizeF& onGetSize() const = 0;
107 
110  virtual const Scaling& onGetScaling() const = 0;
111 
112  protected:
116 
119  virtual Gfx::Canvas* onCreateCanvas(Gfx::Canvas* reuse) = 0;
120 
123  virtual void onReleaseCanvas() = 0;
124 
127  virtual void onSync() = 0;
128 
131  virtual void onFinish() = 0;
132 
133  private:
136  void attachPainter(PainterBase& painter);
137 
140  void detachPainter(PainterBase& painter);
141 
144  void attachContext(PaintContext& context);
145 
148  void detachContext(PaintContext& context);
149 
150  private:
153  void onDetachCanvas(Canvas& canvas);
154 
155  private:
156  Canvas* _canvas;
157  PainterBase* _painter;
158  PaintContext* _context;
159  void* _reserved;
160 };
161 
162 } // namespace
163 
164 } // namespace
165 
166 #endif
Core module.
Definition: Allocator.h:33
void invalidate()
Invalidates the currently active paint canvas.
virtual void onReleaseCanvas()=0
Releases the current Canvas.
Backend canvas for drawing commands.
Definition: Canvas.h:66
virtual void onFinish()=0
Finishes painting to the surface.
const Gfx::SizeF & size() const
Returns the size in physical pixels.
virtual const Gfx::SizeF & onGetSize() const =0
Returns the size in physical pixel.
Active painting session for a surface.
Definition: PaintContext.h:52
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:45
Image format.
Definition: ImageFormat.h:53
virtual Gfx::Canvas * onCreateCanvas(Gfx::Canvas *reuse)=0
Creates a Canvas.
virtual const Gfx::ImageFormat & onGetFormat() const =0
Returns the image format.
void sync()
Synchronizes pending operations to the surface.
Abstract target for drawing operations.
Definition: PaintSurface.h:55
const Gfx::ImageFormat & format() const
Returns the image format.
void finish()
Finishes painting to the surface.
virtual ~PaintSurface()
Destructor.
const Scaling & scaling() const
Returns the scaling from logical to physical pixels.
virtual const Scaling & onGetScaling() const =0
Returns the scaling fro logical to physical pixels.
virtual void onSync()=0
Synchronizes pending operations to the surface.
virtual Gfx::Canvas * onGetCanvas(Gfx::Canvas *reuse)
Returns a reusable canvas instance.
Protects derived classes from being copied.
Definition: NonCopyable.h:54
Canvas * getCanvas(Canvas *canvas)
Returns a canvas for backend drawing.
PaintSurface()
Default constructor.