Icon.h
1 /* Copyright (C) 2019 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_Forms_Icon_h
30 #define Pt_Forms_Icon_h
31 
32 #include <Pt/Forms/Api.h>
33 #include <Pt/Gfx/Size.h>
34 #include <Pt/Gfx/Image.h>
35 #include <Pt/System/Path.h>
36 
37 #include <vector>
38 
39 namespace Pt {
40 
41 namespace Forms {
42 
43 class IconImpl;
44 
58 class PT_FORMS_API IconProvider
59 {
60  friend class IconImpl;
61 
62  public:
66 
69  virtual ~IconProvider();
70 
73  virtual bool empty() const = 0;
74 
77  virtual void clear() = 0;
78 
81  virtual void addImage(const Gfx::SizeF& size, const Gfx::Image& image) = 0;
82 
87  virtual void addImage(const Gfx::SizeF& size, const System::Path& path) = 0;
88 
91  virtual Gfx::SizeF minimumSize() const = 0;
92 
95  virtual Gfx::SizeF maximumSize() const = 0;
96 
99  virtual const Gfx::Image& getImage(const Gfx::SizeF& area) = 0;
100 
101  private:
102  void attachIcon(IconImpl* parent);
103 
104  void detachIcon(IconImpl* parent);
105 
106  private:
107  std::vector<IconImpl*> _icons;
108 };
109 
110 
143 class PT_FORMS_API Icon
144 {
145  public:
148  Icon();
149 
152  Icon(const Icon& icon);
153 
156  Icon(IconProvider& provider);
157 
163  ~Icon();
164 
167  Icon& operator=(const Icon& icon);
168 
171  bool empty() const;
172 
177  void clear();
178 
183  void addImage(const Gfx::Image& image);
184 
190  void addImage(const Gfx::SizeF& size, const Gfx::Image& image);
191 
197  void addImage(const Gfx::SizeF& size, const System::Path& path);
198 
201  void addImage(double width, double height, const System::Path& path);
202 
207  const Gfx::Image& getImage(const Gfx::SizeF& area) const;
208 
212 
216 
217  private:
218  void detach();
219 
220  private:
221  mutable class IconImpl* _impl;
222 };
223 
224 } // namespace
225 
226 } // namespace
227 
228 #endif
Core module.
Definition: Allocator.h:33
Icon(IconProvider &provider)
Attaches provider. The icon does not own it.
Represents an image at one or more logical sizes.
Definition: Icon.h:144
Icon(const Icon &icon)
Shares images with icon until addImage() or clear().
virtual ~IconProvider()
Detaches remaining icons so they no longer use this provider.
void clear()
Removes all images from this icon.
Icon()
Creates an empty icon with a built-in provider.
~Icon()
Releases this copy.
Icon & operator=(const Icon &icon)
Shares images with icon until addImage() or clear().
Size with floating-point width and height.
Definition: Size.h:47
virtual bool empty() const =0
Returns true when no images are registered.
virtual void clear()=0
Removes all registered images.
IconProvider()
Creates an unused provider.
void addImage(double width, double height, const System::Path &path)
Registers a file path at width by height.
Provides images for Icon objects.
Definition: Icon.h:59
void addImage(const Gfx::SizeF &size, const System::Path &path)
Registers a file path at logical size size.
virtual void addImage(const Gfx::SizeF &size, const Gfx::Image &image)=0
Registers image at size.
virtual Gfx::SizeF minimumSize() const =0
Returns the smallest registered size, or an empty size.
void addImage(const Gfx::Image &image)
Registers image using its pixel size as the key.
Gfx::SizeF maximumSize() const
Returns the largest registered size, or an empty size.
Gfx::SizeF minimumSize() const
Returns the smallest registered size, or an empty size.
void addImage(const Gfx::SizeF &size, const Gfx::Image &image)
Registers image at logical size size.
Represents a path in the file-system.
Definition: Path.h:48
Basic image.
Definition: Image.h:52
virtual void addImage(const Gfx::SizeF &size, const System::Path &path)=0
Registers a file path at size.
virtual const Gfx::Image & getImage(const Gfx::SizeF &area)=0
Returns an image for the requested area.
const Gfx::Image & getImage(const Gfx::SizeF &area) const
Returns an image for the requested area.
bool empty() const
Returns true when no images are registered.
virtual Gfx::SizeF maximumSize() const =0
Returns the largest registered size, or an empty size.