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 
42 namespace Pt {
43 
44 namespace Forms {
45 
48 class PT_FORMS_API IPixmapImpl
49 {
50  public:
51  virtual ~IPixmapImpl() {}
52 
53  virtual void reset(const Gfx::Image& image) = 0;
54  virtual void reset(const Gfx::SizeF& size) = 0;
55  virtual void reset() = 0;
56 
57  virtual void getBitmap(Gfx::Bitmap& bitmap, const Gfx::RectF& rect) const = 0;
58  virtual void setScaleFactor(double scaleFactor) = 0;
59  virtual void drawPixmap(Gfx::Canvas& canvas, const Gfx::PointF& to,
60  const Pixmap& pm, const Gfx::RectF* rect) = 0;
61 
62  virtual const Gfx::ImageFormat& format() const = 0;
63  virtual const Gfx::SizeF& size() const = 0;
64  virtual const Gfx::Scaling& scaling() const = 0;
65 
66  virtual Gfx::Canvas* getCanvas(Gfx::Canvas* reuse) = 0;
67  virtual Gfx::Canvas* createCanvas(Gfx::Canvas* reuse) = 0;
68  virtual void releaseCanvas() = 0;
69  virtual void sync() = 0;
70  virtual void finish() = 0;
71 };
72 
73 
76 class PT_FORMS_API Pixmap : public PaintSurface
77 {
78  public:
79  Pixmap();
80 
81  virtual ~Pixmap();
82 
83  void reset();
84 
87  void reset(const Gfx::Image& image);
88 
91  void reset(const Gfx::SizeF& size);
92 
93  bool empty() const;
94 
95  void getBitmap(Gfx::Bitmap& image, const Gfx::RectF& rect);
96 
97  void setScaleFactor(double v);
98 
99  protected:
100  virtual void onDrawPixmap(Gfx::Canvas& canvas,
101  const Gfx::PointF& to,
102  const Pixmap& pixmap,
103  const Gfx::RectF* rect = 0) override;
104 
105  protected:
106  virtual const Gfx::ImageFormat& onGetFormat() const override;
107 
108  virtual const Gfx::SizeF& onGetSize() const override;
109 
110  virtual const Gfx::Scaling& onGetScaling() const override;
111 
112  virtual Gfx::Canvas* onGetCanvas(Gfx::Canvas* reuse) override;
113 
114  virtual Gfx::Canvas* onCreateCanvas(Gfx::Canvas* reuse) override;
115 
116  virtual void onReleaseCanvas() override;
117 
118  virtual void onSync() override;
119 
120  virtual void onFinish() override;
121 
122  public:
123  IPixmapImpl* impl()
124  {
125  return _impl;
126  }
127 
128  const IPixmapImpl* impl() const
129  {
130  return _impl;
131  }
132 
133  private:
134  IPixmapImpl* _impl;
135 };
136 
137 typedef Pixmap PixmapSurface;
138 
139 } // namespace
140 
141 } // namespace
142 
143 #endif
Core module.
Definition: Allocator.h:33
Interface for the platform/backend-specific pixmap implementation.
Definition: Pixmap.h:49
void reset(const Gfx::SizeF &size)
Resizes to a size in physical pixels.
virtual Gfx::Canvas * onGetCanvas(Gfx::Canvas *reuse) override
Returns a reusable canvas instance.
Backend canvas for drawing commands.
Definition: Canvas.h:66
Paint surface.
Definition: PaintSurface.h:44
virtual Gfx::Canvas * onCreateCanvas(Gfx::Canvas *reuse) override
Creates a Canvas.
Logical-to-physical unit conversion.
Definition: Scaling.h:49
void reset(const Gfx::Image &image)
Resets to an image.
Size with floating-point width and height.
Definition: Size.h:47
virtual const Gfx::SizeF & onGetSize() const override
Returns the size in physical pixel.
Point with floating-point X and Y coordinates.
Definition: Point.h:47
Image format.
Definition: ImageFormat.h:53
virtual void onFinish() override
Finishes painting to the surface.
Basic image.
Definition: Image.h:52
virtual void onSync() override
Synchronizes pending operations to the surface.
virtual const Gfx::ImageFormat & onGetFormat() const override
Returns the image format.
Rect with floating-point coordinates.
Definition: Rect.h:47
Back buffer drawing surface.
Definition: Pixmap.h:77
virtual const Gfx::Scaling & onGetScaling() const override
Returns the scaling fro logical to physical pixels.
Off-screen drawing surface backed by an image.
Definition: Bitmap.h:60
virtual void onReleaseCanvas() override
Releases the current Canvas.