sptk2 logo
SPTK Home Page
CIcon.h
1/*
2╔══════════════════════════════════════════════════════════════════════════════╗
3║ SIMPLY POWERFUL TOOLKIT (SPTK) ║
4╟──────────────────────────────────────────────────────────────────────────────╢
5║ copyright © 1999-2022 Alexey Parshin. All rights reserved. ║
6║ email alexeyp@gmail.com ║
7╚══════════════════════════════════════════════════════════════════════════════╝
8┌──────────────────────────────────────────────────────────────────────────────┐
9│ This library is free software; you can redistribute it and/or modify it │
10│ under the terms of the GNU Library General Public License as published by │
11│ the Free Software Foundation; either version 2 of the License, or (at your │
12│ option) any later version. │
13│ │
14│ This library is distributed in the hope that it will be useful, but │
15│ WITHOUT ANY WARRANTY; without even the implied warranty of │
16│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library │
17│ General Public License for more details. │
18│ │
19│ You should have received a copy of the GNU Library General Public License │
20│ along with this library; if not, write to the Free Software Foundation, │
21│ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. │
22│ │
23│ Please report all bugs and problems to alexeyp@gmail.com. │
24└──────────────────────────────────────────────────────────────────────────────┘
25*/
26
27#pragma once
28
29#include <sptk5/CaseInsensitiveCompare.h>
30#include <sptk5/Tar.h>
31#include <sptk5/gui/CPngImage.h>
32#include <sptk5/xdoc/Node.h>
33
34namespace sptk {
35
44enum class CIconSize : uint8_t
45{
50
55
60
65
66};
67
71class CIcon
72{
76 CPngImage* m_image;
77
81 String m_name;
82
83public:
88
92 CIcon(const String& name = "", CPngImage* image = 0L, bool shared = true)
93 : m_image(image)
94 , m_name(name)
95 , m_shared(shared)
96 {
97 }
98
103 {
104 if (m_image && !m_shared)
105 {
106 delete m_image;
107 }
108 }
109
114 void load(const Buffer& imageData);
115
120 {
121 return m_image;
122 }
123
127 String name() const
128 {
129 return m_name;
130 }
131
137 void image(CPngImage* img, bool shared)
138 {
139 if (m_image && !m_shared)
140 {
141 delete m_image;
142 }
143 m_image = img;
144 m_shared = shared;
145 }
146};
147
151class SP_EXPORT CIconMap
152 : public std::map<String, CIcon*, CaseInsensitiveCompare>
153{
154 bool m_shared;
155
156public:
161 explicit CIconMap(bool shared = false)
162 : m_shared(shared)
163 {
164 }
165
170 {
171 clear();
172 }
173
177 void clear();
178
183 void insert(CIcon* icon);
184
192 void load(Tar& tar, const xdoc::SNode& node);
193};
194
198} // namespace sptk
Definition: Buffer.h:51
A map of theme icon names to theme icons.
Definition: CIcon.h:153
CIconMap(bool shared=false)
Default constructor.
Definition: CIcon.h:161
void clear()
Removes all the allocated images.
void load(Tar &tar, const xdoc::SNode &node)
Loads a collection of images using information from XML node.
void insert(CIcon *icon)
Inserts a new icon into icon map.
~CIconMap()
Destructor.
Definition: CIcon.h:169
Class CIcon provides a storage of PNG image.
Definition: CIcon.h:72
String name() const
Returns an icon symbolic name.
Definition: CIcon.h:127
void image(CPngImage *img, bool shared)
Sets the image pointer.
Definition: CIcon.h:137
CIcon(const String &name="", CPngImage *image=0L, bool shared=true)
Constructor.
Definition: CIcon.h:92
bool m_shared
Definition: CIcon.h:87
~CIcon()
Destructor.
Definition: CIcon.h:102
CPngImage * image()
Returns an icon image.
Definition: CIcon.h:119
void load(const Buffer &imageData)
Loads a PNG image from buffer.
PNG image that is initialized from the memory buffer.
Definition: CPngImage.h:53
Definition: String.h:49
Definition: Tar.h:44
CIconSize
Icon size variations.
Definition: CIcon.h:45

Fri Oct 14 2022 09:58:31: SPTK 5.4.1