Audacity  3.0.3
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 
18 
19 #include <vector>
20 #include <wx/defs.h>
21 #include <wx/window.h> // to inherit
22 
23 class wxArrayString;
24 class wxBitmap;
25 class wxColour;
26 class wxFont;
27 class wxImage;
28 class wxPen;
29 
30 class ChoiceSetting;
31 
32 // JKC: will probably change name from 'teBmps' to 'tIndexBmp';
33 using teBmps = int;
34 
36 {
42 };
43 
45 {
46  resFlagNone =0x00,
50  resFlagInternal = 0x08, // For image manipulation. Don't save or load.
51  resFlagSkip = 0x10
52 };
53 
55 {
61 };
62 
63 
64 
65 class AUDACITY_DLL_API FlowPacker
66 {
67 public:
68  FlowPacker(){;};
70  void Init(int width);
71  void GetNextPosition( int xSize, int ySize );
72  void SetNewGroup( int iGroupSize );
73  void SetColourGroup( );
74  wxRect Rect();
75  wxRect RectInner();
76  void RectMid( int &x, int &y );
77 
78  // These 4 should become private again...
79  int mFlags;
80  int mxPos;
81  int myPos;
82  int myHeight;
84 
85 private:
88  int mOldFlags;
89  int myPosBase;
90  int mxWidth;
92 
95 
96 };
97 
98 class AUDACITY_DLL_API ThemeBase /* not final */
99 {
100 public:
101  ThemeBase(void);
102  ThemeBase ( const ThemeBase & ) = delete;
103  ThemeBase &operator =( const ThemeBase & ) = delete;
104 public:
105  virtual ~ThemeBase(void);
106 
107 public:
108  virtual void EnsureInitialised()=0;
109  void LoadTheme( teThemeType Theme );
110  void RegisterImage( int &iIndex,char const** pXpm, const wxString & Name);
111  void RegisterImage( int &iIndex, const wxImage &Image, const wxString & Name );
112  void RegisterColour( int &iIndex, const wxColour &Clr, const wxString & Name );
113 
114  teThemeType GetFallbackThemeType();
115  teThemeType ThemeTypeOfTypeName( const wxString & Name );
116  void CreateImageCache(bool bBinarySave = true);
117  bool ReadImageCache( teThemeType type = themeFromFile, bool bOkIfNotFound=false);
118  void LoadComponents( bool bOkIfNotFound =false);
119  void SaveComponents();
120  void SaveThemeAsCode();
121  void WriteImageDefs( );
122  void WriteImageMap( );
123  static bool LoadPreferredTheme();
124  bool IsUsingSystemTextColour(){ return bIsUsingSystemTextColour;};
125  void RecolourBitmap( int iIndex, wxColour From, wxColour To );
126  void RecolourTheme();
127 
128  int ColourDistance( wxColour & From, wxColour & To );
129  wxColour & Colour( int iIndex );
130  wxBitmap & Bitmap( int iIndex );
131  wxImage & Image( int iIndex );
132  wxCursor & Cursor( int iIndex );
133  wxFont & Font( int iIndex );
134  wxSize ImageSize( int iIndex );
135  bool bRecolourOnLoad; // Request to recolour.
137 
138  void ReplaceImage( int iIndex, wxImage * pImage );
139  void RotateImageInto( int iTo, int iFrom, bool bClockwise );
140 
141  void SetBrushColour( wxBrush & Brush, int iIndex );
142  void SetPenColour( wxPen & Pen, int iIndex );
143  void SetFlags( int flags ){ mFlow.mFlags = flags;};
144 
145  // Utility function that combines a bitmap and a mask, both in XPM format.
146  wxImage MaskedImage( char const ** pXpm, char const ** pMask );
147  // Utility function that takes a 32 bit bitmap and makes it into an image.
148  wxImage MakeImageWithAlpha( wxBitmap & Bmp );
149 
150 protected:
151  // wxImage, wxBitmap copy cheaply using reference counting
152  std::vector<wxImage> mImages;
153  std::vector<wxBitmap> mBitmaps;
154  wxArrayString mBitmapNames;
155  std::vector<int> mBitmapFlags;
156 
157  std::vector<wxColour> mColours;
158  wxArrayString mColourNames;
160 };
161 
162 
163 class AUDACITY_DLL_API Theme final : public ThemeBase
164 {
165 public:
166  Theme(void);
167 public:
168  ~Theme(void);
169 public:
170  void EnsureInitialised() override;
171  void RegisterImages();
172  void RegisterColours();
174 };
175 
176 // A bit cheeky - putting a themable wxStaticText control into
177 // theme, rather than in a new file. Saves sorting out makefiles (for now).
178 class wxWindow;
179 class wxString;
180 class wxPaintEvent;
181 
182 class AUDACITY_DLL_API auStaticText : public wxWindow
183 {
184 public:
185  auStaticText(wxWindow* parent, wxString text);
186  void OnPaint(wxPaintEvent & evt);
187  bool AcceptsFocus() const override { return false; }
188  void OnErase(wxEraseEvent& event) {
189  static_cast<void>(event);
190  };
192 };
193 
194 extern AUDACITY_DLL_API Theme theTheme;
195 
196 extern AUDACITY_DLL_API ChoiceSetting
197  GUITheme
198 ;
199 
200 #endif // __AUDACITY_THEME__
Init
Definition: ModuleManager.h:152
FlowPacker::mxCacheWidth
int mxCacheWidth
Definition: Theme.h:91
FlowPacker::mxPos
int mxPos
Definition: Theme.h:80
teBmps
int teBmps
Definition: ImageManipulation.h:48
FlowPacker::iImageGroupIndex
int iImageGroupIndex
Definition: Theme.h:87
ThemeBase::mImages
std::vector< wxImage > mImages
Definition: Theme.h:152
FlowPacker::mComponentWidth
int mComponentWidth
Definition: Theme.h:93
resFlagPaired
@ resFlagPaired
Definition: Theme.h:47
teResourceFlags
teResourceFlags
Definition: Theme.h:45
ThemeBase::bRecolourOnLoad
bool bRecolourOnLoad
Definition: Theme.h:135
theTheme
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:203
auStaticText::AcceptsFocus
bool AcceptsFocus() const override
Definition: Theme.h:187
Theme
Based on ThemeBase, Theme manages image and icon resources.
Definition: Theme.h:164
ThemeBase::mBitmaps
std::vector< wxBitmap > mBitmaps
Definition: Theme.h:153
resTypeFont
@ resTypeFont
Definition: Theme.h:41
resFlagSkip
@ resFlagSkip
Definition: Theme.h:51
FlowPacker::mBorderWidth
int mBorderWidth
Definition: Theme.h:83
resTypeBitmap
@ resTypeBitmap
Definition: Theme.h:38
resTypeCursor
@ resTypeCursor
Definition: Theme.h:40
FlowPacker::iImageGroupSize
int iImageGroupSize
Definition: Theme.h:86
themeHiContrast
@ themeHiContrast
Definition: Theme.h:59
FlowPacker::mFlags
int mFlags
Definition: Theme.h:79
ThemeBase::Cursor
wxCursor & Cursor(int iIndex)
resFlagInternal
@ resFlagInternal
Definition: Theme.h:50
ThemeBase::mColours
std::vector< wxColour > mColours
Definition: Theme.h:157
resFlagNone
@ resFlagNone
Definition: Theme.h:46
themeFromFile
@ themeFromFile
Definition: Theme.h:60
FlowPacker::mxWidth
int mxWidth
Definition: Theme.h:90
GUITheme
AUDACITY_DLL_API ChoiceSetting GUITheme
Definition: Theme.cpp:1314
ChoiceSetting
Definition: Prefs.h:267
ThemeBase::mBitmapNames
wxArrayString mBitmapNames
Definition: Theme.h:154
auStaticText::OnErase
void OnErase(wxEraseEvent &event)
Definition: Theme.h:188
FlowPacker::FlowPacker
FlowPacker()
Definition: Theme.h:68
ThemeBase::mColourNames
wxArrayString mColourNames
Definition: Theme.h:158
resTypeColour
@ resTypeColour
Definition: Theme.h:37
ThemeBase
Theme management - Image loading and saving.
Definition: Theme.h:99
FlowPacker::mOldFlags
int mOldFlags
Definition: Theme.h:88
FlowPacker::~FlowPacker
~FlowPacker()
Definition: Theme.h:69
FlowPacker::myHeight
int myHeight
Definition: Theme.h:82
FlowPacker::myPosBase
int myPosBase
Definition: Theme.h:89
themeDark
@ themeDark
Definition: Theme.h:57
ThemeBase::SetFlags
void SetFlags(int flags)
Definition: Theme.h:143
FlowPacker
Packs rectangular boxes into a rectangle, using simple first fit.
Definition: Theme.h:66
ThemeBase::EnsureInitialised
virtual void EnsureInitialised()=0
auStaticText::DECLARE_EVENT_TABLE
DECLARE_EVENT_TABLE()
ThemeBase::IsUsingSystemTextColour
bool IsUsingSystemTextColour()
Definition: Theme.h:124
ThemeBase::ThemeBase
ThemeBase(const ThemeBase &)=delete
ThemeBase::bIsUsingSystemTextColour
bool bIsUsingSystemTextColour
Definition: Theme.h:136
themeClassic
@ themeClassic
Definition: Theme.h:56
auStaticText
is like wxStaticText, except it can be themed. wxStaticText can't be.
Definition: Theme.h:183
FlowPacker::myPos
int myPos
Definition: Theme.h:81
FlowPacker::mComponentHeight
int mComponentHeight
Definition: Theme.h:94
ThemeBase::mFlow
FlowPacker mFlow
Definition: Theme.h:159
teThemeType
teThemeType
Definition: Theme.h:55
resTypeImage
@ resTypeImage
Definition: Theme.h:39
ThemeBase::mBitmapFlags
std::vector< int > mBitmapFlags
Definition: Theme.h:155
themeLight
@ themeLight
Definition: Theme.h:58
resFlagCursor
@ resFlagCursor
Definition: Theme.h:48
resFlagNewLine
@ resFlagNewLine
Definition: Theme.h:49
Theme::mbInitialised
bool mbInitialised
Definition: Theme.h:173
teResourceType
teResourceType
The index of a bitmap resource in Theme Resources.
Definition: Theme.h:36
ThemeBase::Font
wxFont & Font(int iIndex)