Audacity 3.2.0
Theme.h
Go to the documentation of this file.
1/**********************************************************************
2
3 Audacity: A Digital Audio Editor
4
5 Theme.h
6
7 James Crook
8
9 Audacity is free software.
10 This file is licensed under the wxWidgets license, see License.txt
11
12**********************************************************************/
13
14#ifndef __AUDACITY_THEME__
15#define __AUDACITY_THEME__
16
17#include <map>
18#include <unordered_set>
19#include <vector>
20#include <optional>
21#include <wx/arrstr.h>
22#include <wx/defs.h>
23#include <wx/gdicmn.h>
25
26#include "Observer.h"
27#include "Prefs.h"
28
31
34{
35 Light,
36 Dark,
38};
39
40class wxArrayString;
41class wxBitmap;
42class wxColour;
43class wxImage;
44class wxPen;
45
46class ChoiceSetting;
47
48// JKC: will probably change name from 'teBmps' to 'tIndexBmp';
49using teBmps = int;
50
52{
56};
57
59{
64 resFlagInternal = 0x08, // For image manipulation. Don't save or load.
65 resFlagSkip = 0x10
66};
67
69class THEME_API FlowPacker
70{
71public:
72 explicit FlowPacker(int width);
74 void GetNextPosition( int xSize, int ySize );
75 void SetNewGroup( int iGroupSize );
76 void SetColourGroup( );
77 wxRect Rect();
78 wxRect RectInner();
79 void RectMid( int &x, int &y );
80
81 // These 4 should become private again...
82 int mFlags = resFlagPaired;
83 int mxPos = 0;
84 int myPos = 0;
85 int myHeight = 0;
86 int mBorderWidth = 1;
87
88private:
89 int iImageGroupSize = 1;
90 int iImageGroupIndex = -1;
91 int mOldFlags = resFlagPaired;
92 int myPosBase = 0;
93 int mxCacheWidth = 0;
94
95 int mComponentWidth = 0;
96 int mComponentHeight = 0;
97
98};
99
101{
102 // wxImage, wxBitmap copy cheaply using reference counting
103 std::vector<wxImage> mImages;
104 std::vector<wxBitmap> mBitmaps;
105 std::vector<wxColour> mColours;
106
107 bool bInitialised = false;
108 bool bRecolourOnLoad = false; // Request to recolour.
109};
110
112 std::optional<PreferredSystemAppearance> appearance;
115};
116
117class THEME_API ThemeBase /* not final */
118 : public Observer::Publisher<ThemeChangeMessage>
119{
120public:
121 ThemeBase(void);
122 ThemeBase ( const ThemeBase & ) = delete;
123 ThemeBase &operator =( const ThemeBase & ) = delete;
124public:
125 virtual ~ThemeBase(void);
126
127public:
128 virtual void EnsureInitialised() = 0;
129
130 // Get and set the root directory for saving and loading of files
131 FilePath GetFilePath();
132 void SetFilePath(const FilePath &path);
133
134 // Typically statically constructed:
135 struct THEME_API RegisteredTheme {
137 PreferredSystemAppearance preferredSystemAppearance,
138 const std::vector<unsigned char> &data
140 );
142
145 const std::vector<unsigned char>& data;
146 };
147
148 void SwitchTheme( teThemeType Theme );
149 void LoadTheme( teThemeType Theme );
150
151 // For checking uniqueness of names during registration
152 using NameSet = std::unordered_set<wxString>;
153
154 void RegisterImage( NameSet &allNames,
155 int &flags, int &iIndex,char const** pXpm, const wxString & Name);
156 void RegisterImage( NameSet &allNames,
157 int &flags, int &iIndex, const wxImage &Image, const wxString & Name );
158 void RegisterColour( NameSet &allNames,
159 int &iIndex, const wxColour &Clr, const wxString & Name );
160
161 teThemeType GetFallbackThemeType();
162 void CreateImageCache();
163 bool CreateOneImageCache(teThemeType id, bool bBinarySave);
164 bool ReadImageCache( teThemeType type = {}, bool bOkIfNotFound=false);
165 void LoadThemeComponents( bool bOkIfNotFound =false);
166 void LoadOneThemeComponents( teThemeType id, bool bOkIfNotFound = false);
170 void WriteImageDefs( );
171 void WriteImageMap( );
172 void WriteOneImageMap( teThemeType id );
173 static bool LoadPreferredTheme();
174 void RecolourBitmap( int iIndex, wxColour From, wxColour To );
175 void RecolourTheme();
176
177 int ColourDistance( wxColour & From, wxColour & To );
178 wxColour & Colour( int iIndex );
179 wxBitmap & Bitmap( int iIndex );
180 wxImage & Image( int iIndex );
181 wxSize ImageSize( int iIndex );
182
183 void ReplaceImage( int iIndex, wxImage * pImage );
184 void RotateImageInto( int iTo, int iFrom, bool bClockwise );
185
186 void SetBrushColour( wxBrush & Brush, int iIndex );
187 void SetPenColour( wxPen & Pen, int iIndex );
188
189 // Utility function that combines a bitmap and a mask, both in XPM format.
190 wxImage MaskedImage( char const ** pXpm, char const ** pMask );
191 // Utility function that takes a 32 bit bitmap and makes it into an image.
192 wxImage MakeImageWithAlpha( wxBitmap & Bmp );
193
194 // Reclaim resources after finished with theme editing
196
197protected:
199
200 wxArrayString mBitmapNames;
201 std::vector<int> mBitmapFlags;
202 wxArrayString mColourNames;
203
205
206 std::map<Identifier, ThemeSet> mSets;
207 ThemeSet *mpSet = nullptr;
208};
209
210class THEME_API Theme final : public ThemeBase
211{
212 friend class AColor; // So it can publish
213public:
214 Theme(void);
215public:
216 ~Theme(void);
217public:
218 void EnsureInitialised() override;
219 void RegisterImagesAndColours();
220};
221
222extern THEME_API Theme theTheme;
223
224extern THEME_API BoolSetting
226;
227
228extern THEME_API ChoiceSetting
230;
231
232#endif // __AUDACITY_THEME__
wxImage(22, 22)
int teBmps
wxString FilePath
Definition: Project.h:21
THEME_API BoolSetting GUIBlendThemes
THEME_API ChoiceSetting & GUITheme()
teResourceFlags
Definition: Theme.h:59
@ resFlagNewLine
Definition: Theme.h:63
@ resFlagSkip
Definition: Theme.h:65
@ resFlagNone
Definition: Theme.h:60
@ resFlagInternal
Definition: Theme.h:64
@ resFlagPaired
Definition: Theme.h:61
@ resFlagCursor
Definition: Theme.h:62
PreferredSystemAppearance
A system theme, that matches selected theme best (only works on macOS with builtin themes).
Definition: Theme.h:34
teResourceType
The index of a bitmap resource in Theme Resources.
Definition: Theme.h:52
@ resTypeColour
Definition: Theme.h:53
@ resTypeBitmap
Definition: Theme.h:54
@ resTypeImage
Definition: Theme.h:55
THEME_API Theme theTheme
Definition: Theme.cpp:82
AColor Manages color brushes and pens.
Definition: AColor.h:25
This specialization of Setting for bool adds a Toggle method to negate the saved value.
Definition: Prefs.h:344
ComponentInterfaceSymbol pairs a persistent string identifier used internally with an optional,...
A cursor for iterating the theme bitmap.
Definition: Theme.h:70
~FlowPacker()
Definition: Theme.h:73
An explicitly nonlocalized string, not meant for the user to see.
Definition: Identifier.h:22
An object that sends messages to an open-ended list of subscribed callbacks.
Definition: Observer.h:108
Theme management - Image loading and saving.
Definition: Theme.h:119
bool SaveOneThemeComponents(teThemeType id)
wxColour & Colour(int iIndex)
void SetBrushColour(wxBrush &Brush, int iIndex)
void DeleteUnusedThemes()
void SaveThemeAsCode()
wxImage MakeImageWithAlpha(wxBitmap &Bmp)
wxImage & Image(int iIndex)
wxBitmap & Bitmap(int iIndex)
void ReplaceImage(int iIndex, wxImage *pImage)
void RotateImageInto(int iTo, int iFrom, bool bClockwise)
FilePath mThemeDir
Definition: Theme.h:198
wxArrayString mBitmapNames
Definition: Theme.h:200
void SetPenColour(wxPen &Pen, int iIndex)
std::map< Identifier, ThemeSet > mSets
Definition: Theme.h:206
std::unordered_set< wxString > NameSet
Definition: Theme.h:152
wxArrayString mColourNames
Definition: Theme.h:202
std::vector< int > mBitmapFlags
Definition: Theme.h:201
virtual void EnsureInitialised()=0
wxSize ImageSize(int iIndex)
void SaveThemeComponents()
ThemeBase(const ThemeBase &)=delete
Based on ThemeBase, Theme manages image and icon resources.
Definition: Theme.h:211
const EnumValueSymbol symbol
Definition: Theme.h:143
const PreferredSystemAppearance preferredSystemAppearance
Definition: Theme.h:144
const std::vector< unsigned char > & data
Definition: Theme.h:145
std::optional< PreferredSystemAppearance > appearance
Definition: Theme.h:112
std::vector< wxImage > mImages
Definition: Theme.h:103
bool bRecolourOnLoad
Definition: Theme.h:108
std::vector< wxBitmap > mBitmaps
Definition: Theme.h:104
std::vector< wxColour > mColours
Definition: Theme.h:105
bool bInitialised
Definition: Theme.h:107