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 
46 class PixmapImpl;
47 
50 class PT_FORMS_API Pixmap : public PaintSurface
51 {
52  public:
53  Pixmap();
54 
55  virtual ~Pixmap();
56 
57  void reset();
58 
61  void reset(const Gfx::Image& image);
62 
65  void reset(const Gfx::SizeF& size);
66 
67  bool empty() const;
68 
69  void getBitmap(Gfx::Bitmap& image, const Gfx::RectF& rect);
70 
71  void setScaleFactor(double v);
72 
73  protected:
74  virtual void onDrawPixmap(Gfx::Canvas& canvas,
75  const Gfx::PointF& to,
76  const Pixmap& pixmap,
77  const Gfx::RectF* rect = 0) override;
78 
79  protected:
80  virtual const Gfx::ImageFormat& onGetFormat() const override;
81 
82  virtual const Gfx::SizeF& onGetSize() const override;
83 
84  virtual const Gfx::Scaling& onGetScaling() const override;
85 
86  virtual Gfx::Canvas* onGetCanvas(Gfx::Canvas* reuse) override;
87 
88  virtual Gfx::Canvas* onCreateCanvas(Gfx::Canvas* reuse) override;
89 
90  virtual void onReleaseCanvas() override;
91 
92  virtual void onSync() override;
93 
94  virtual void onFinish() override;
95 
96  public:
97  static std::string defaultFont();
98 
99  static void setDefaultFont(const std::string& family);
100 
101  static std::vector<std::string> fontFamilies();
102 
103  static std::vector<Gfx::FontFace> fontFaces(const std::string& family);
104 
105  public:
106  PixmapImpl* impl()
107  {
108  return _impl;
109  }
110 
111  const PixmapImpl* impl() const
112  {
113  return _impl;
114  }
115 
116  private:
117  PixmapImpl* _impl;
118 };
119 
120 typedef Pixmap PixmapSurface;
121 
122 } // namespace
123 
124 } // namespace
125 
126 #endif
Core module.
Definition: Allocator.h:33
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:45
virtual const Gfx::SizeF & onGetSize() const override
Returns the size in physical pixel.
Point with floating-point X and Y coordinates.
Definition: Point.h:45
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:45
Back buffer drawing surface.
Definition: Pixmap.h:51
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.