Pixmap.h
1/* Copyright (C) 2015 Laurentiu-Gheorghe Crisan
2 Copyright (C) 2015-2024 Marc Boris Duerner
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_Forms_Pixmap_h
31#define Pt_Forms_Pixmap_h
32
33#include <Pt/Forms/Api.h>
34#include <Pt/Forms/PaintSurface.h>
35#include <Pt/Gfx/FontFace.h>
36#include <Pt/Gfx/Size.h>
37#include <Pt/Gfx/Rect.h>
38#include <Pt/Gfx/Image.h>
39#include <Pt/Gfx/Bitmap.h>
40#include <Pt/System/Path.h>
41
42namespace Pt {
43
44namespace Forms {
45
53class PT_FORMS_API IPixmapImpl
54{
55 public:
58 virtual ~IPixmapImpl() {}
59
62 virtual void reset(const Gfx::Image& image) = 0;
63
66 virtual void reset(const Gfx::SizeF& size) = 0;
67
70 virtual void reset() = 0;
71
74 virtual void getBitmap(Gfx::Bitmap& bitmap, const Gfx::RectF& rect) const = 0;
75
78 virtual void setScaleFactor(double scaleFactor) = 0;
79
85 virtual void drawPixmap(Gfx::Canvas& canvas, const Gfx::PointF& to,
86 const Pixmap& pm, const Gfx::RectF* rect) = 0;
87
90 virtual const Gfx::ImageFormat& format() const = 0;
91
94 virtual const Gfx::SizeF& size() const = 0;
95
98 virtual const Gfx::Scaling& scaling() const = 0;
99
102 virtual Gfx::Canvas* getCanvas(Gfx::Canvas* reuse) = 0;
103
107
110 virtual void releaseCanvas() = 0;
111
114 virtual void sync() = 0;
115
118 virtual void finish() = 0;
119};
120
121
129class PT_FORMS_API Pixmap : public PaintSurface
130{
131 public:
135
138 virtual ~Pixmap();
139
142 void reset();
143
146 void reset(const Gfx::Image& image);
147
150 void reset(const Gfx::SizeF& size);
151
154 bool empty() const;
155
158 void getBitmap(Gfx::Bitmap& image, const Gfx::RectF& rect);
159
162 void setScaleFactor(double v);
163
164 protected:
165 virtual void onDrawPixmap(Gfx::Canvas& canvas,
166 const Gfx::PointF& to,
167 const Pixmap& pixmap,
168 const Gfx::RectF* rect = 0) override;
169
170 protected:
171 virtual const Gfx::ImageFormat& onGetFormat() const override;
172
173 virtual const Gfx::SizeF& onGetSize() const override;
174
175 virtual const Gfx::Scaling& onGetScaling() const override;
176
177 virtual Gfx::Canvas* onGetCanvas(Gfx::Canvas* reuse) override;
178
179 virtual Gfx::Canvas* onCreateCanvas(Gfx::Canvas* reuse) override;
180
181 virtual void onReleaseCanvas() override;
182
183 virtual void onSync() override;
184
185 virtual void onFinish() override;
186
187 public:
193 {
194 return _impl;
195 }
196
201 const IPixmapImpl* impl() const
202 {
203 return _impl;
204 }
205
206 private:
207 IPixmapImpl* _impl;
208};
209
210} // namespace
211
212} // namespace
213
214#endif
Platform pixmap implementation.
Definition Pixmap.h:54
virtual void drawPixmap(Gfx::Canvas &canvas, const Gfx::PointF &to, const Pixmap &pm, const Gfx::RectF *rect)=0
Draws pm onto canvas at to.
virtual void reset()=0
Clears the pixmap.
virtual Gfx::Canvas * getCanvas(Gfx::Canvas *reuse)=0
Returns a canvas, reusing reuse when possible.
virtual void getBitmap(Gfx::Bitmap &bitmap, const Gfx::RectF &rect) const =0
Copies rect into bitmap.
virtual const Gfx::Scaling & scaling() const =0
Returns the scaling from logical to physical pixels.
virtual void sync()=0
Synchronizes pending drawing operations.
virtual void releaseCanvas()=0
Releases the current canvas.
virtual void setScaleFactor(double scaleFactor)=0
Sets the scale factor to scaleFactor.
virtual void finish()=0
Finishes painting on the pixmap.
virtual const Gfx::ImageFormat & format() const =0
Returns the image format.
virtual void reset(const Gfx::Image &image)=0
Resets the pixmap from image.
virtual const Gfx::SizeF & size() const =0
Returns the size in physical pixels.
virtual void reset(const Gfx::SizeF &size)=0
Resets the pixmap to size in physical pixels.
virtual Gfx::Canvas * createCanvas(Gfx::Canvas *reuse)=0
Creates a canvas, reusing reuse when possible.
virtual ~IPixmapImpl()
Destructor.
Definition Pixmap.h:58
PaintSurface()
Constructs an unbound paint surface.
Off-screen Forms paint surface.
Definition Pixmap.h:130
virtual void onReleaseCanvas() override
Releases the current Canvas.
void reset(const Gfx::Image &image)
Resets the pixmap from image.
virtual Gfx::Canvas * onCreateCanvas(Gfx::Canvas *reuse) override
Creates a Canvas.
virtual void onFinish() override
Finishes painting to the surface.
virtual void onDrawPixmap(Gfx::Canvas &canvas, const Gfx::PointF &to, const Pixmap &pixmap, const Gfx::RectF *rect=0) override
Draws pixmap onto canvas at to.
const IPixmapImpl * impl() const
Returns the platform pixmap implementation.
Definition Pixmap.h:201
IPixmapImpl * impl()
Returns the platform pixmap implementation.
Definition Pixmap.h:192
bool empty() const
Returns true when the pixmap has no size.
void setScaleFactor(double v)
Sets the scale factor to v.
virtual void onSync() override
Synchronizes pending operations to the surface.
virtual const Gfx::SizeF & onGetSize() const override
Returns the size in physical pixel.
virtual const Gfx::ImageFormat & onGetFormat() const override
Returns the image format.
void getBitmap(Gfx::Bitmap &image, const Gfx::RectF &rect)
Copies rect into image.
Pixmap()
Creates an empty pixmap.
void reset(const Gfx::SizeF &size)
Resets the pixmap to size in physical pixels.
virtual Gfx::Canvas * onGetCanvas(Gfx::Canvas *reuse) override
Returns a reusable canvas instance.
void reset()
Clears the pixmap.
virtual const Gfx::Scaling & onGetScaling() const override
Returns the scaling fro logical to physical pixels.
virtual ~Pixmap()
Destructor.
Off-screen image that can be painted.
Definition Bitmap.h:71
Backend that executes drawing commands.
Definition Canvas.h:66
Runtime pixel format.
Definition ImageFormat.h:72
const Gfx::SizeF & size() const
Returns the size in physical pixels.
Conversion between logical units and pixels.
Definition Scaling.h:52
Graphical user interfaces.
Definition ActivateEvent.h:40
Core module.
Definition Allocator.h:33