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};
109
111 std::optional<PreferredSystemAppearance> appearance;
114};
115
116class THEME_API ThemeBase /* not final */
117 : public Observer::Publisher<ThemeChangeMessage>
118{
119public:
120 ThemeBase(void);
121 ThemeBase ( const ThemeBase & ) = delete;
122 ThemeBase &operator =( const ThemeBase & ) = delete;
123public:
124 virtual ~ThemeBase(void);
125
126public:
127 virtual void EnsureInitialised() = 0;
128
129 // Get and set the root directory for saving and loading of files
130 FilePath GetFilePath();
131 void SetFilePath(const FilePath &path);
132
133 // Typically statically constructed:
134 struct THEME_API RegisteredTheme {
136 PreferredSystemAppearance preferredSystemAppearance,
137 const std::vector<unsigned char> &data
139 );
141
144 const std::vector<unsigned char>& data;
145 };
146
147 void SwitchTheme( teThemeType Theme );
148 void LoadTheme( teThemeType Theme );
149
150 // For checking uniqueness of names during registration
151 using NameSet = std::unordered_set<wxString>;
152
153 void RegisterImage( NameSet &allNames,
154 int &flags, int &iIndex,char const** pXpm, const wxString & Name);
155 void RegisterImage( NameSet &allNames,
156 int &flags, int &iIndex, const wxImage &Image, const wxString & Name );
157 void RegisterColour( NameSet &allNames,
158 int &iIndex, const wxColour &Clr, const wxString & Name );
159
160 teThemeType GetFallbackThemeType();
161 void CreateImageCache();
162 bool CreateOneImageCache(teThemeType id, bool bBinarySave);
163 bool ReadImageCache( teThemeType type = {}, bool bOkIfNotFound=false);
164 void LoadThemeComponents( bool bOkIfNotFound =false);
165 void LoadOneThemeComponents( teThemeType id, bool bOkIfNotFound = false);
169 void WriteImageDefs( );
170 void WriteImageMap( );
171 void WriteOneImageMap( teThemeType id );
172 static bool LoadPreferredTheme();
173 void RecolourBitmap( int iIndex, wxColour From, wxColour To );
174
175 int ColourDistance( wxColour & From, wxColour & To );
176 wxColour & Colour( int iIndex );
177 wxBitmap & Bitmap( int iIndex );
178 wxImage & Image( int iIndex );
179 wxSize ImageSize( int iIndex );
180
181 void ReplaceImage( int iIndex, wxImage * pImage );
182 void RotateImageInto( int iTo, int iFrom, bool bClockwise );
183
184 void SetBrushColour( wxBrush & Brush, int iIndex );
185 void SetPenColour( wxPen & Pen, int iIndex );
186
187 // Utility function that combines a bitmap and a mask, both in XPM format.
188 wxImage MaskedImage( char const ** pXpm, char const ** pMask );
189 // Utility function that takes a 32 bit bitmap and makes it into an image.
190 wxImage MakeImageWithAlpha( wxBitmap & Bmp );
191
192 // Reclaim resources after finished with theme editing
194
195protected:
197
198 wxArrayString mBitmapNames;
199 std::vector<int> mBitmapFlags;
200 wxArrayString mColourNames;
201
203
204 std::map<Identifier, ThemeSet> mSets;
205 ThemeSet *mpSet = nullptr;
206};
207
208class THEME_API Theme final : public ThemeBase
209{
210 friend class AColor; // So it can publish
211public:
212 Theme(void);
213public:
214 ~Theme(void);
215public:
216 void EnsureInitialised() override;
217 void RegisterImagesAndColours();
218};
219
220extern THEME_API Theme theTheme;
221
222extern THEME_API ChoiceSetting
224;
225
226#endif // __AUDACITY_THEME__
wxImage(22, 22)
int teBmps
wxString FilePath
Definition: Project.h:21
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
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:118
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:196
wxArrayString mBitmapNames
Definition: Theme.h:198
void SetPenColour(wxPen &Pen, int iIndex)
std::map< Identifier, ThemeSet > mSets
Definition: Theme.h:204
std::unordered_set< wxString > NameSet
Definition: Theme.h:151
wxArrayString mColourNames
Definition: Theme.h:200
std::vector< int > mBitmapFlags
Definition: Theme.h:199
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:209
RectType< float > Rect
Alias for rectangle with float data type.
Definition: Rect.h:66
const EnumValueSymbol symbol
Definition: Theme.h:142
const PreferredSystemAppearance preferredSystemAppearance
Definition: Theme.h:143
const std::vector< unsigned char > & data
Definition: Theme.h:144
std::optional< PreferredSystemAppearance > appearance
Definition: Theme.h:111
std::vector< wxImage > mImages
Definition: Theme.h:103
std::vector< wxBitmap > mBitmaps
Definition: Theme.h:104
std::vector< wxColour > mColours
Definition: Theme.h:105
bool bInitialised
Definition: Theme.h:107