sptk2 logo
SPTK Home Page
CFrame.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/Tar.h>
30#include <sptk5/gui/CPngImage.h>
31#include <sptk5/xdoc/Node.h>
32
33namespace sptk {
34
46class SP_EXPORT CFrame
47 : public CPngImage
48{
49public:
54 enum class CFrameKind : uint8_t
55 {
59 FLTK_STANDARD,
60
64 USER_EXTENDED
65 };
66
67protected:
71 uint32_t m_frameWidth;
72
76 uint32_t m_cornerZone;
77
82
87
88public:
98 CFrame(const Buffer& imageData, uint32_t frameWidth, uint32_t cornerZone,
100 CFrameKind kind = CFrameKind::USER_EXTENDED)
101 : CPngImage(imageData)
102 , m_frameWidth(frameWidth)
103 , m_cornerZone(cornerZone)
104 , m_drawMode(drawMode)
105 , m_kind(kind)
106 {
107 }
108
119 void drawResized(int x, int y, int w, int h, bool drawBackground)
120 {
121 CPngImage::drawResized(x, y, w, h, (int) m_cornerZone, m_drawMode, drawBackground);
122 }
123
128 uint32_t frameWidth() const
129 {
130 return m_frameWidth;
131 }
132
137 uint32_t cornerZone() const
138 {
139 return m_cornerZone;
140 }
141
147 {
148 return m_kind;
149 }
150};
151
156class SP_EXPORT CFrames
157{
161 using CFrameMap = std::map<std::string, CFrame*>;
162
166 using CFltkFrameMap = std::map<Fl_Boxtype, CFrame*>;
167
168
172 CFrameMap m_frames;
173
177 CFltkFrameMap m_fltkFrames;
178
179
180 static const Strings frameTypeNames;
181 static const std::array<Fl_Boxtype, 4> frameTypes;
182
183public:
188 CFrames() = default;
189
195 {
196 clear();
197 }
198
204 void clear();
205
211 void load(Tar& tar, const xdoc::SNode& frameNode);
212
219 void registerFrame(std::string frameName, CFrame* frame, Fl_Boxtype frameType = FL_NO_BOX);
220
225 CFrame* find(Fl_Boxtype frameType) const;
226
231 CFrame* find(std::string frameName) const;
232};
236} // namespace sptk
Definition: Buffer.h:51
Frame information class.
Definition: CFrame.h:48
uint32_t m_cornerZone
Definition: CFrame.h:76
uint32_t cornerZone() const
Returns corner zone width to draw the frame corners without changes.
Definition: CFrame.h:137
uint32_t frameWidth() const
Returns frame width, to keep widgets inside the frame w/o overlaping.
Definition: CFrame.h:128
void drawResized(int x, int y, int w, int h, bool drawBackground)
Draws resized image.
Definition: CFrame.h:119
CPatternDrawMode m_drawMode
Definition: CFrame.h:81
CFrame(const Buffer &imageData, uint32_t frameWidth, uint32_t cornerZone, CPatternDrawMode drawMode=CPngImage::CPatternDrawMode::PDM_STRETCH, CFrameKind kind=CFrameKind::USER_EXTENDED)
Constructor.
Definition: CFrame.h:98
uint32_t m_frameWidth
Definition: CFrame.h:71
CFrameKind
An expected usage of the frame.
Definition: CFrame.h:55
CFrameKind m_kind
Definition: CFrame.h:86
CFrameKind kind() const
Returns an expected usage of the frame.
Definition: CFrame.h:146
Frame images collection.
Definition: CFrame.h:157
void load(Tar &tar, const xdoc::SNode &frameNode)
Loads the frames from the tar archive by the XML description.
void clear()
Clears the frame collection.
void registerFrame(std::string frameName, CFrame *frame, Fl_Boxtype frameType=FL_NO_BOX)
Registers a single frame image in the collection.
CFrames()=default
Constructor.
~CFrames()
Destructor.
Definition: CFrame.h:194
CFrame * find(std::string frameName) const
Returns a frame image, or NULL if not defined in the collection.
CFrame * find(Fl_Boxtype frameType) const
Returns a standard FLTK frame image, or NULL if not defined in the collection.
PNG image that is initialized from the memory buffer.
Definition: CPngImage.h:53
void drawResized(int x, int y, int w, int h, int cornerZone, CPatternDrawMode drawMode, bool drawBackground)
Draws resized image.
CPatternDrawMode
The way how the resized parts of image are drawn.
Definition: CPngImage.h:105
Definition: Strings.h:52
Definition: Tar.h:44

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