sptk2 logo
SPTK Home Page
CThemes.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 <map>
31#include <sptk5/gui/CFont.h>
32#include <sptk5/gui/CFrame.h>
33#include <sptk5/gui/CIcon.h>
34#include <sptk5/gui/CRect.h>
35#include <sptk5/gui/CTabImage.h>
36#include <sptk5/gui/CThemeColorCollection.h>
37#include <sptk5/gui/CThemeImageCollection.h>
38#include <sptk5/gui/CThemeScrollBar.h>
39#include <sptk5/xdoc/Node.h>
40
41namespace sptk {
42
48#define MAX_BACKGROUND_IMAGES 7
49
54{
55 THM_BUTTON_COMBO,
56 THM_BUTTON_CHECK,
57 THM_BUTTON_RADIO,
58 THM_BUTTON_NORMAL
59};
60
67class SP_EXPORT CThemes
68 : public CThemeScrollBar
69{
70 friend class CBaseButton;
71
75 static std::string m_name;
76
77
81 static Fl_Box_Draw_F* m_flatBox;
82
86 static Fl_Box_Draw_F* m_thinUpBox;
87
91 static Fl_Box_Draw_F* m_upBox;
92
96 static Fl_Box_Draw_F* m_thinDownBox;
97
101 static Fl_Box_Draw_F* m_downBox;
102
103
107 static Fl_Box_Draw_F* m_thinUpFrame;
108
112 static Fl_Box_Draw_F* m_upFrame;
113
117 static Fl_Box_Draw_F* m_thinDownFrame;
118
122 static Fl_Box_Draw_F* m_downFrame;
123
124
128 static CFontsMap m_fonts;
129
133 static CFrames m_frames;
134
138 static std::string m_themeFolder;
139
140
145 static CPngImage* m_background[MAX_BACKGROUND_IMAGES];
146
150 static CThemeImageCollection m_normalButtons;
151
155 static CThemeImageCollection m_comboButtons;
156
160 static CThemeImageCollection m_checkButtons;
161
165 static CThemeImageCollection m_radioButtons;
166
174 static CThemeImageCollection m_progressBar[2];
175
181 static CThemeColorCollection m_colors;
182
188 static CTabImages m_tabImages;
189
193 static bool m_flatButtons;
194
198 static bool m_gtkTheme;
199
203 static xdoc::Document* m_registry;
204
208 static void reset();
209
214 static CThemeImageCollection& sizeToButtonImages(CThemeButtonType sz);
215
221 static void replaceImage(CPngImage** images, int ndx, const std::string& fileName);
222
231 static void paintBackground(int xx, int yy, int ww, int hh, CPngImage* image);
232
242 static void drawThemeBox(int x, int y, int w, int h, Fl_Color color, Fl_Boxtype frameType = FL_NO_BOX);
243
252 static void drawThemeFrame(int x, int y, int w, int h, Fl_Boxtype frameType);
253
258 static CPngImage* imageForColor(Fl_Color clr);
259
264 static bool m_desaturateInactiveButtons;
265
269 static int m_buttonFocusRadius;
270
281 static bool drawCheckOrRadioButton(CThemeImageCollection& buttonImages, int x, int y, bool checked, bool highlited);
282
283protected:
287 static CIconMap m_icons[4];
288
294 static void loadGtkButton(const xdoc::SNode& imageNode, std::map<CThemeImageState, std::string>& buttonFileNames);
295
303 static void loadGtkButtonFileNames(xdoc::Document& xml, std::string XPath,
304 std::map<CThemeImageState, std::string>& fileNames,
305 std::string orientation = "");
306
314 static void loadGtkButtons(xdoc::Document& xml, const String& styleName, CThemeImageCollection& buttons,
315 const String& function);
316
323 static void loadGtkTheme(const String& gtkThemeName);
324
325public:
330
335
339 static void set(std::string themeName);
340
347 static CIcon* getIcon(const String& iconName, CIconSize iconSize);
348
355 static CPngImage* getIconImage(const String& iconName, CIconSize iconSize);
356
362 static void registerIcon(CIcon* icon, CIconSize iconSize);
363
367 static void drawFlatBox(int x, int y, int w, int h, Fl_Color clr);
368
372 static void drawThinUpBox(int x, int y, int w, int h, Fl_Color clr);
373
377 static void drawUpBox(int x, int y, int w, int h, Fl_Color clr);
378
382 static void drawThinDownBox(int x, int y, int w, int h, Fl_Color clr);
383
387 static void drawDownBox(int x, int y, int w, int h, Fl_Color clr);
388
392 static void drawThinUpFrame(int x, int y, int w, int h, Fl_Color clr);
393
397 static void drawUpFrame(int x, int y, int w, int h, Fl_Color clr);
398
402 static void drawThinDownFrame(int x, int y, int w, int h, Fl_Color clr);
403
407 static void drawDownFrame(int x, int y, int w, int h, Fl_Color clr);
408
420 static bool drawButton(CThemeButtonType sz, int x, int y, int& w, int& h, bool highlited, bool pressed,
421 bool defaultButton);
422
430 static bool sizeButton(CThemeButtonType sz, int& w, int& h);
431
438 static bool sizeProgressBar(int& w, int& h);
439
443 static int buttonFocusRadius();
444
453 static bool drawCheckButton(int x, int y, bool checked, bool highlited);
454
463 static bool drawRadioButton(int x, int y, bool checked, bool highlited);
464
476 static bool drawProgressBar(int x, int y, int w, float percent);
477
487 static bool drawTab(int x, int y, int w, int h, bool active);
488
499 static bool drawTabFrame(int x, int y, int w, int h);
500
505
513 static const Strings& searchDirectories();
514
519
523 static std::string name();
524
528 static std::string themeFolder();
529
533 static Tar m_tar;
534};
535
539} // namespace sptk
Definition: CButton.h:96
CFontsMap is a map font names to fonts.
Definition: CFont.h:157
CFontsVector is a map font names to fonts.
Definition: CFont.h:184
Frame images collection.
Definition: CFrame.h:157
A map of theme icon names to theme icons.
Definition: CIcon.h:153
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
Definition: CTabImage.h:128
Definition: CThemeColorCollection.h:115
A collection of theme images.
Definition: CThemeImageCollection.h:46
Definition: CThemeScrollBar.h:116
Widget themes.
Definition: CThemes.h:69
static void drawThinDownFrame(int x, int y, int w, int h, Fl_Color clr)
static int buttonFocusRadius()
static CIcon * getIcon(const String &iconName, CIconSize iconSize)
Returns a button icon by symbolic name.
static void set(std::string themeName)
static const Strings & searchDirectories()
Themes root directories.
static void drawThinUpFrame(int x, int y, int w, int h, Fl_Color clr)
static bool drawButton(CThemeButtonType sz, int x, int y, int &w, int &h, bool highlited, bool pressed, bool defaultButton)
static CFontsVector screenFonts
All the available screen fonts.
Definition: CThemes.h:518
static bool drawRadioButton(int x, int y, bool checked, bool highlited)
static void loadGtkButtonFileNames(xdoc::Document &xml, std::string XPath, std::map< CThemeImageState, std::string > &fileNames, std::string orientation="")
Loads GTK theme button file names from XPath.
static void registerIcon(CIcon *icon, CIconSize iconSize)
Registers a new button icon.
static CPngImage * getIconImage(const String &iconName, CIconSize iconSize)
Returns a button icon image by symbolic name.
static void drawDownFrame(int x, int y, int w, int h, Fl_Color clr)
static void drawThinUpBox(int x, int y, int w, int h, Fl_Color clr)
static void loadGtkButtons(xdoc::Document &xml, const String &styleName, CThemeImageCollection &buttons, const String &function)
Loads GTK theme button images from 'style' node.
static bool sizeButton(CThemeButtonType sz, int &w, int &h)
static bool drawTabFrame(int x, int y, int w, int h)
Draws a tab frame.
static void drawFlatBox(int x, int y, int w, int h, Fl_Color clr)
static bool sizeProgressBar(int &w, int &h)
static void drawThinDownBox(int x, int y, int w, int h, Fl_Color clr)
static void drawUpBox(int x, int y, int w, int h, Fl_Color clr)
static void loadGtkTheme(const String &gtkThemeName)
Loads current Gnome GTK theme.
static void loadGtkButton(const xdoc::SNode &imageNode, std::map< CThemeImageState, std::string > &buttonFileNames)
Loads GTK theme button file name from 'image' node, and stores it into the map.
static Strings availableThemes()
static bool drawProgressBar(int x, int y, int w, float percent)
static void drawUpFrame(int x, int y, int w, int h, Fl_Color clr)
static std::string themeFolder()
Returns path to the theme folder.
static void drawDownBox(int x, int y, int w, int h, Fl_Color clr)
static Tar m_tar
Theme tar archive. Contains all the theme data.
Definition: CThemes.h:533
static bool drawTab(int x, int y, int w, int h, bool active)
Draws a tab.
static bool drawCheckButton(int x, int y, bool checked, bool highlited)
static std::string name()
Returns theme name.
Definition: String.h:49
Definition: Strings.h:52
Definition: Tar.h:44
Definition: Document.h:34
CThemeButtonType
Theme button size - defines the button size and look to select the correct pixmap.
Definition: CThemes.h:54
CIconSize
Icon size variations.
Definition: CIcon.h:45

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