sptk2 logo
SPTK Home Page
CPngImage.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 <FL/Fl.H>
30#include <FL/Fl_Image.H>
31#include <sptk5/Buffer.h>
32
33namespace sptk {
34
38enum class CBorderIndex : uint8_t
39{
40 BORDER_LEFT,
41 BORDER_RIGHT,
42 BORDER_TOP,
43 BORDER_BOTTOM
44};
45
51class SP_EXPORT CPngImage
52 : public Fl_RGB_Image
53{
54
55 friend class CIcon;
56
57 using resized_draw_function = void (*)(CPngImage* image, int srcX, int srcY, int srcW, int srcH, int destX,
58 int destY, int destW, int destH);
59
60protected:
65 void load(const Buffer& buffer);
66
79 static void cutTileDraw(CPngImage* image, int srcX, int srcY, int srcW, int srcH, int destX, int destY, int destW,
80 int destH);
81
94 static void cutStretchDraw(CPngImage* image, int srcX, int srcY, int srcW, int srcH, int destX, int destY,
95 int destW, int destH);
96
97public:
104 enum class CPatternDrawMode : uint8_t
105 {
109 PDM_UNDEFINED,
110
114 PDM_TILE,
115
119 PDM_STRETCH
120
121 };
122
134 void cutTileDraw(int srcX, int srcY, int srcW, int srcH, int destX, int destY, int destW, int destH)
135 {
136 cutTileDraw(this, srcX, srcY, srcW, srcH, destX, destY, destW, destH);
137 }
138
150 void cutStretchDraw(int srcX, int srcY, int srcW, int srcH, int destX, int destY, int destW, int destH)
151 {
152 cutStretchDraw(this, srcX, srcY, srcW, srcH, destX, destY, destW, destH);
153 }
154
161 explicit CPngImage(const Buffer& imagedata);
162
169 explicit CPngImage(const Fl_RGB_Image* image);
170
177 explicit CPngImage(const String& fileName);
178
190 void drawResized(int x, int y, int w, int h, int cornerZone, CPatternDrawMode drawMode, bool drawBackground);
191
203 void drawResized(int x, int y, int w, int h, int border[], CPatternDrawMode drawMode, bool drawBackground);
204};
205
206} // namespace sptk
Definition: Buffer.h:51
Class CIcon provides a storage of PNG image.
Definition: CIcon.h:72
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.
CPngImage(const String &fileName)
Constructor.
void cutTileDraw(int srcX, int srcY, int srcW, int srcH, int destX, int destY, int destW, int destH)
Draws a part of the image by cutting a corresponding source and tiling it in required area.
Definition: CPngImage.h:134
void drawResized(int x, int y, int w, int h, int border[], CPatternDrawMode drawMode, bool drawBackground)
Draws resized image.
CPngImage(const Fl_RGB_Image *image)
Constructor.
CPngImage(const Buffer &imagedata)
Constructor.
CPatternDrawMode
The way how the resized parts of image are drawn.
Definition: CPngImage.h:105
static void cutTileDraw(CPngImage *image, int srcX, int srcY, int srcW, int srcH, int destX, int destY, int destW, int destH)
Draws a part of the image by cutting a corresponding source and tiling it in required area.
void load(const Buffer &buffer)
Internal loader from PNG image buffer.
void cutStretchDraw(int srcX, int srcY, int srcW, int srcH, int destX, int destY, int destW, int destH)
Draws a part of the image by cutting a corresponding source and stretching it in required area.
Definition: CPngImage.h:150
static void cutStretchDraw(CPngImage *image, int srcX, int srcY, int srcW, int srcH, int destX, int destY, int destW, int destH)
Draws a part of the image by cutting a corresponding source and stretching it in required area.
Definition: String.h:49

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