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
38namespace Pt {
39
40namespace Gfx {
41
42class PainterBase;
43class PaintSurface;
44
60class PT_GFX_API PaintContext : private NonCopyable
61{
62 friend class PainterBase;
63 friend class PaintSurface;
64
65 public:
68 explicit PaintContext(PaintSurface& surface);
69
72 PaintContext(PaintSurface& surface, const RectF& clip);
73
76 virtual ~PaintContext();
77
80 const Gfx::ImageFormat& format() const;
81
84 const Gfx::SizeF& size() const;
85
88 const Scaling& scaling() const;
89
92 const RectF* clip() const;
93
96 void setClip(const RectF& clip);
97
100 void resetClip();
101
105
108 void sync();
109
112 void finish();
113
114 protected:
117 virtual void onDetachSurface(PaintSurface& surface);
118
119 private:
120 PaintSurface* surface();
121
122 void attachPainter(PainterBase& painter);
123
124 void detachPainter(PainterBase& painter);
125
126 private:
127 PaintSurface* _surface;
128 PainterBase* _painter;
129 RectF _clip;
130 bool _hasClip;
131};
132
133} // namespace
134
135} // namespace
136
137#endif
Backend that executes drawing commands.
Definition Canvas.h:66
Runtime pixel format.
Definition ImageFormat.h:72
Canvas * getCanvas(Canvas *canvas)
Returns a canvas for backend drawing.
PaintContext(PaintSurface &surface)
Constructs a context using the paint surface.
void setClip(const RectF &clip)
Sets the default clip rect for painters on this context.
PaintContext(PaintSurface &surface, const RectF &clip)
Constructs a context using the paint surface and an initial clip rect.
const RectF * clip() const
Returns the default clip rect or null if clipping is disabled.
void finish()
Finishes painting on the surface.
virtual ~PaintContext()
Destructor.
const Gfx::ImageFormat & format() const
Returns the image format.
const Scaling & scaling() const
Returns the scaling from logical to physical pixels.
void resetClip()
Resets the default clip rect.
const Gfx::SizeF & size() const
Returns the size in physical pixels.
virtual void onDetachSurface(PaintSurface &surface)
Handles detachment from the surface.
void sync()
Synchronizes pending drawing operations.
Target for drawing operations.
Definition PaintSurface.h:66
Drawing commands and paint state.
Definition PainterBase.h:85
Conversion between logical units and pixels.
Definition Scaling.h:52
NonCopyable()
Default constructor.
Definition NonCopyable.h:63
Graphics and imaging services.
Definition Api-Argb32Image.h:12
Core module.
Definition Allocator.h:33