Audacity  2.3.1
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Attributes | List of all members
ThemeBase Class Referenceabstract

Theme management - Image loading and saving. More...

#include <Theme.h>

Inheritance diagram for ThemeBase:
Theme

Public Member Functions

 ThemeBase (void)
 
virtual ~ThemeBase (void)
 
virtual void EnsureInitialised ()=0
 
virtual void ApplyUpdatedImages ()=0
 
void LoadTheme (teThemeType Theme)
 
void RegisterImage (int &iIndex, char const **pXpm, const wxString &Name)
 
void RegisterImage (int &iIndex, const wxImage &Image, const wxString &Name)
 
void RegisterColour (int &iIndex, const wxColour &Clr, const wxString &Name)
 
teThemeType GetFallbackThemeType ()
 
teThemeType ThemeTypeOfTypeName (const wxString &Name)
 
void CreateImageCache (bool bBinarySave=true)
 
bool ReadImageCache (teThemeType type=themeFromFile, bool bOkIfNotFound=false)
 
void LoadComponents (bool bOkIfNotFound=false)
 
void SaveComponents ()
 
void SaveThemeAsCode ()
 
void WriteImageDefs ()
 Writes a series of Macro definitions that can be used in the include file. More...
 
void WriteImageMap ()
 
bool IsUsingSystemTextColour ()
 
void RecolourBitmap (int iIndex, wxColour From, wxColour To)
 
void RecolourTheme ()
 
int ColourDistance (wxColour &From, wxColour &To)
 
wxColour & Colour (int iIndex)
 
wxBitmap & Bitmap (int iIndex)
 
wxImage & Image (int iIndex)
 
wxCursor & Cursor (int iIndex)
 
wxFont & Font (int iIndex)
 
wxSize ImageSize (int iIndex)
 
void ReplaceImage (int iIndex, wxImage *pImage)
 Replaces both the image and the bitmap. More...
 
void RotateImageInto (int iTo, int iFrom, bool bClockwise)
 
void SetBrushColour (wxBrush &Brush, int iIndex)
 
void SetPenColour (wxPen &Pen, int iIndex)
 
void SetFlags (int flags)
 
wxImage MaskedImage (char const **pXpm, char const **pMask)
 
wxImage MakeImageWithAlpha (wxBitmap &Bmp)
 

Static Public Member Functions

static bool LoadPreferredTheme ()
 

Public Attributes

bool bRecolourOnLoad
 
bool bIsUsingSystemTextColour
 

Protected Attributes

std::vector< wxImage > mImages
 
std::vector< wxBitmap > mBitmaps
 
wxArrayString mBitmapNames
 
std::vector< int > mBitmapFlags
 
std::vector< wxColour > mColours
 
wxArrayString mColourNames
 
FlowPacker mFlow
 

Detailed Description

Theme management - Image loading and saving.

Base for the Theme class. ThemeBase is a generic non-Audacity specific class.

See Also
Themability of Audacity

Definition at line 93 of file Theme.h.

Constructor & Destructor Documentation

ThemeBase::ThemeBase ( void  )

Definition at line 286 of file Theme.cpp.

References bIsUsingSystemTextColour, and bRecolourOnLoad.

287 {
288  bRecolourOnLoad = false;
289  bIsUsingSystemTextColour = false;
290 }
bool bRecolourOnLoad
Definition: Theme.h:129
bool bIsUsingSystemTextColour
Definition: Theme.h:130
ThemeBase::~ThemeBase ( void  )
virtual

Definition at line 292 of file Theme.cpp.

293 {
294 }

Member Function Documentation

virtual void ThemeBase::ApplyUpdatedImages ( )
pure virtual

Implemented in Theme.

wxBitmap & ThemeBase::Bitmap ( int  iIndex)
wxColour & ThemeBase::Colour ( int  iIndex)

Definition at line 1225 of file Theme.cpp.

References EnsureInitialised(), and mColours.

Referenced by AboutDialog::AboutDialog(), SelectionBar::AddTitle(), AudacityProject::ApplyUpdatedTheme(), ASlider::ASlider(), AudacityProject::AudacityProject(), auStaticText::auStaticText(), AColor::BevelTrackInfo(), TrackInfo::CloseTitleDrawFunction(), CursorColour(), AdornedRulerPanel::DoDrawMarks(), AdornedRulerPanel::DoDrawSelection(), TimeTrack::Draw(), LabelTrack::Draw(), Ruler::Label::Draw(), TrackInfo::DrawItems(), FreqWindow::DrawPlot(), LWSlider::DrawToBitmap(), TrackArtist::DrawTrack(), TrackArtist::DrawVRuler(), FreqWindow::FreqWindow(), Grabber::Grabber(), HtmlColourOfIndex(), AColor::Init(), NumericTextCtrl::Layout(), LoadTheme(), MixerBoard::MakeButtonBitmap(), TrackInfo::MinimizeSyncLockDrawFunction(), MixerBoard::MixerBoard(), ToolManager::OnIndicatorPaint(), ToolBarResizer::OnPaint(), EffectAutoDuckPanel::OnPaint(), MixerTrackCluster::OnPaint(), EffectCompressorPanel::OnPaint(), EffectScienFilterPanel::OnPaint(), ToolFrame::OnPaint(), MeterPanel::OnPaint(), ToolBar::OnPaint(), NumericTextCtrl::OnPaint(), EqualizationPanel::OnPaint(), ToolDock::OnPaint(), OverlayImage(), DeviceToolBar::Populate(), MixerToolBar::Populate(), SpectralSelectionBar::Populate(), MeterToolBar::Populate(), ScrubbingToolBar::Populate(), SelectionBar::Populate(), ToolsToolBar::Populate(), TranscriptionToolBar::Populate(), EditToolBar::Populate(), ControlToolBar::Populate(), AColor::PreComputeGradient(), RecolourTheme(), AdornedRulerPanel::ReCreateButtons(), SetBrushColour(), SetPenColour(), ToolDock::ToolDock(), MixerTrackCluster::UpdatePrefs(), MixerBoard::UpdatePrefs(), and AColor::UseThemeColour().

1226 {
1227  wxASSERT( iIndex >= 0 );
1229  return mColours[iIndex];
1230 }
std::vector< wxColour > mColours
Definition: Theme.h:151
virtual void EnsureInitialised()=0
int ThemeBase::ColourDistance ( wxColour &  From,
wxColour &  To 
)

Definition at line 366 of file Theme.cpp.

Referenced by CursorColour(), LoadTheme(), MeterPanel::OnPaint(), and RecolourTheme().

366  {
367  return
368  abs( From.Red() - To.Red() )
369  + abs( From.Green() - To.Green() )
370  + abs( From.Blue() - To.Blue() );
371 }
void ThemeBase::CreateImageCache ( bool  bBinarySave = true)

Definition at line 660 of file Theme.cpp.

References _(), AudacityMessageBox(), EnsureInitialised(), FlowPacker::GetNextPosition(), ImageCacheHeight, ImageCacheWidth, FlowPacker::Init(), mBitmapFlags, mBitmapNames, FlowPacker::mBorderWidth, mColourNames, mColours, FlowPacker::mFlags, mFlow, mImages, FlowPacker::mxPos, FlowPacker::myPos, SourceOutputStream::OpenFile(), PasteSubImage(), FlowPacker::Rect(), FlowPacker::RectInner(), resFlagInternal, resFlagSkip, FlowPacker::SetColourGroup(), FileNames::ThemeCacheAsCee(), and FileNames::ThemeCachePng().

Referenced by LoadTheme(), ThemePrefs::OnSaveThemeCache(), and SaveThemeAsCode().

661 {
663  wxBusyCursor busy;
664 
665  wxImage ImageCache( ImageCacheWidth, ImageCacheHeight );
666  ImageCache.SetRGB( wxRect( 0,0,ImageCacheWidth, ImageCacheHeight), 1,1,1);//Not-quite black.
667 
668  // Ensure we have an alpha channel...
669  if( !ImageCache.HasAlpha() )
670  {
671  ImageCache.InitAlpha();
672  }
673 
674  int i;
675 
677  mFlow.mBorderWidth =1;
678 
679 //#define IMAGE_MAP
680 #ifdef IMAGE_MAP
681  wxLogDebug( wxT("<img src=\"ImageCache.png\" usemap=\"#map1\">" ));
682  wxLogDebug( wxT("<map name=\"map1\">") );
683 #endif
684 
685  // Save the bitmaps
686  for(i = 0;i < (int)mImages.size();i++)
687  {
688  wxImage &SrcImage = mImages[i];
690  if( (mBitmapFlags[i] & resFlagInternal)==0)
691  {
692  mFlow.GetNextPosition( SrcImage.GetWidth(), SrcImage.GetHeight());
693  ImageCache.SetRGB( mFlow.Rect(), 0xf2, 0xb0, 0x27 );
694  if( (mFlow.mFlags & resFlagSkip) == 0 )
695  PasteSubImage( &ImageCache, &SrcImage,
698  else
699  ImageCache.SetRGB( mFlow.RectInner(), 1,1,1);
700 #ifdef IMAGE_MAP
701  // No href in html. Uses title not alt.
702  wxRect R( mFlow.Rect() );
703  wxLogDebug( wxT("<area title=\"Bitmap:%s\" shape=rect coords=\"%i,%i,%i,%i\">"),
704  mBitmapNames[i],
705  R.GetLeft(), R.GetTop(), R.GetRight(), R.GetBottom() );
706 #endif
707  }
708  }
709 
710  // Now save the colours.
711  int x,y;
712 
714  const int iColSize = 10;
715  for(i = 0; i < (int)mColours.size(); i++)
716  {
717  mFlow.GetNextPosition( iColSize, iColSize );
718  wxColour c = mColours[i];
719  ImageCache.SetRGB( mFlow.Rect() , 0xf2, 0xb0, 0x27 );
720  ImageCache.SetRGB( mFlow.RectInner() , c.Red(), c.Green(), c.Blue() );
721 
722  // YUCK! No function in wxWidgets to set a rectangle of alpha...
723  for(x=0;x<iColSize;x++)
724  {
725  for(y=0;y<iColSize;y++)
726  {
727  ImageCache.SetAlpha( mFlow.mxPos + x, mFlow.myPos+y, 255);
728  }
729  }
730 #ifdef IMAGE_MAP
731  // No href in html. Uses title not alt.
732  wxRect R( mFlow.Rect() );
733  wxLogDebug( wxT("<area title=\"Colour:%s\" shape=rect coords=\"%i,%i,%i,%i\">"),
734  mColourNames[i],
735  R.GetLeft(), R.GetTop(), R.GetRight(), R.GetBottom() );
736 #endif
737  }
738 #if TEST_CARD
739  int j;
740  for(i=0;i<ImageCacheWidth;i++)
741  for(j=0;j<ImageCacheHeight;j++){
742  int r = j &0xff;
743  int g = i &0xff;
744  int b = (j >> 8) | ((i>>4)&0xf0);
745  wxRect R( i,j, 1, 1);
746  ImageCache.SetRGB( R, r, g, b );
747  ImageCache.SetAlpha( i,j, 255);
748  }
749 #endif
750 
751 #ifdef IMAGE_MAP
752  wxLogDebug( "</map>" );
753 #endif
754 
755  // IF bBinarySave, THEN saving to a normal PNG file.
756  if( bBinarySave )
757  {
758  const wxString &FileName = FileNames::ThemeCachePng();
759 
760  // Perhaps we should prompt the user if they are overwriting
761  // an existing theme cache?
762 #if 0
763  if( wxFileExist( FileName ))
764  {
766  wxString::Format(
767 // _("Theme cache file:\n %s\nalready exists.\nAre you sure you want to replace it?"),
768  FileName )
769  );
770  return;
771  }
772 #endif
773 #if 0
774  // Deliberate policy to use the fast/cheap blocky pixel-multiplication
775  // algorithm, as this introduces no artifacts on repeated scale up/down.
776  ImageCache.Rescale(
777  ImageCache.GetWidth()*4,
778  ImageCache.GetHeight()*4,
779  wxIMAGE_QUALITY_NEAREST );
780 #endif
781  if( !ImageCache.SaveFile( FileName, wxBITMAP_TYPE_PNG ))
782  {
784  wxString::Format(
785  _("Audacity could not write file:\n %s."),
786  FileName ));
787  return;
788  }
790  wxString::Format(
791 /* i18n-hint: A theme is a consistent visual style across an application's
792  graphical user interface, including choices of colors, and similarity of images
793  such as those on button controls. Audacity can load and save alternative
794  themes. */
795  _("Theme written to:\n %s."),
796  FileName ));
797  }
798  // ELSE saving to a C code textual version.
799  else
800  {
801  SourceOutputStream OutStream;
802  const wxString &FileName = FileNames::ThemeCacheAsCee( );
803  if( !OutStream.OpenFile( FileName ))
804  {
806  wxString::Format(
807  _("Audacity could not open file:\n %s\nfor writing."),
808  FileName ));
809  return;
810  }
811  if( !ImageCache.SaveFile(OutStream, wxBITMAP_TYPE_PNG ) )
812  {
814  wxString::Format(
815  _("Audacity could not write images to file:\n %s."),
816  FileName ));
817  return;
818  }
820  wxString::Format(
821  /* i18n-hint "Cee" means the C computer programming language */
822  _("Theme as Cee code written to:\n %s."),
823  FileName ));
824  }
825 }
wxRect Rect()
Definition: Theme.cpp:570
const int ImageCacheWidth
Definition: Theme.cpp:656
int mxPos
Definition: Theme.h:75
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
static wxString ThemeCacheAsCee()
Definition: FileNames.cpp:301
int myPos
Definition: Theme.h:76
void GetNextPosition(int xSize, int ySize)
Definition: Theme.cpp:538
Helper class based on wxOutputStream used to get a png file in text format.
Definition: Theme.cpp:592
wxArrayString mColourNames
Definition: Theme.h:152
std::vector< wxColour > mColours
Definition: Theme.h:151
int mBorderWidth
Definition: Theme.h:78
wxArrayString mBitmapNames
Definition: Theme.h:148
int OpenFile(const wxString &Filename)
Opens the file and also adds a standard comment at the start of it.
Definition: Theme.cpp:606
int mFlags
Definition: Theme.h:74
void PasteSubImage(wxImage *background, wxImage *foreground, int xoff, int yoff)
wxRect RectInner()
Definition: Theme.cpp:575
virtual void EnsureInitialised()=0
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void Init(int width)
Definition: Theme.cpp:503
static wxString ThemeCachePng()
Definition: FileNames.cpp:286
FlowPacker mFlow
Definition: Theme.h:153
std::vector< int > mBitmapFlags
Definition: Theme.h:149
const int ImageCacheHeight
Definition: Theme.cpp:658
void SetColourGroup()
Definition: Theme.cpp:527
std::vector< wxImage > mImages
Definition: Theme.h:146
wxCursor& ThemeBase::Cursor ( int  iIndex)
virtual void ThemeBase::EnsureInitialised ( )
pure virtual
wxFont& ThemeBase::Font ( int  iIndex)
teThemeType ThemeBase::GetFallbackThemeType ( )

Definition at line 922 of file Theme.cpp.

References themeDark, and themeLight.

Referenced by LoadTheme(), ThemePrefs::OnReadThemeInternal(), and ThemeTypeOfTypeName().

922  {
923 // Fallback must be an internally supported type,
924 // to guarantee it is found.
925 #ifdef EXPERIMENTAL_DA
926  return themeDark;
927 #else
928  return themeLight;
929 #endif
930 }
wxImage & ThemeBase::Image ( int  iIndex)
wxSize ThemeBase::ImageSize ( int  iIndex)

Definition at line 1257 of file Theme.cpp.

References EnsureInitialised(), Image(), and mImages.

Referenced by ScrubbingToolBar::AddButton(), EditToolBar::AddButton(), TranscriptionToolBar::AddButton(), TranscriptionToolBar::MakeAlternateImages(), ControlToolBar::MakeAlternateImages(), ControlToolBar::MakeButton(), ToolsToolBar::MakeTool(), ReadImageCache(), and AdornedRulerPanel::ReCreateButtons().

1258 {
1259  wxASSERT( iIndex >= 0 );
1261  wxImage & Image = mImages[iIndex];
1262  return wxSize( Image.GetWidth(), Image.GetHeight());
1263 }
wxImage & Image(int iIndex)
Definition: Theme.cpp:1251
virtual void EnsureInitialised()=0
std::vector< wxImage > mImages
Definition: Theme.h:146
bool ThemeBase::IsUsingSystemTextColour ( )
inline

Definition at line 118 of file Theme.h.

118 { return bIsUsingSystemTextColour;};
bool bIsUsingSystemTextColour
Definition: Theme.h:130
void ThemeBase::LoadComponents ( bool  bOkIfNotFound = false)

JKC:

Bug:
(wxWidgets) A png may have been saved with alpha, but when you load it, it comes back with a mask instead! (well I guess it is more efficient). Anyway, we want alpha and not a mask, so we call InitAlpha, and that transfers the mask into the alpha channel, and we're done.

Definition at line 1085 of file Theme.cpp.

References _(), AudacityMessageBox(), mBitmapFlags, mBitmapNames, mBitmaps, mImages, resFlagInternal, FileNames::ThemeComponent(), and FileNames::ThemeComponentsDir().

Referenced by LoadTheme(), and ThemePrefs::OnLoadThemeComponents().

1086 {
1087  // IF directory doesn't exist THEN return early.
1088  if( !wxDirExists( FileNames::ThemeComponentsDir() ))
1089  return;
1090 
1091  wxBusyCursor busy;
1092  int i;
1093  int n=0;
1094  wxString FileName;
1095  for(i = 0; i < (int)mImages.size(); i++)
1096  {
1097 
1098  if( (mBitmapFlags[i] & resFlagInternal)==0)
1099  {
1100  FileName = FileNames::ThemeComponent( mBitmapNames[i] );
1101  if( wxFileExists( FileName ))
1102  {
1103  if( !mImages[i].LoadFile( FileName, wxBITMAP_TYPE_PNG ))
1104  {
1105  /* i18n-hint: Do not translate png. It is the name of a file format.*/
1107  wxString::Format(
1108  _("Audacity could not load file:\n %s.\nBad png format perhaps?"),
1109  FileName ));
1110  return;
1111  }
1116  if( ! mImages[i].HasAlpha() )
1117  {
1118  // wxLogDebug( wxT("File %s lacked alpha"), mBitmapNames[i] );
1119  mImages[i].InitAlpha();
1120  }
1121  mBitmaps[i] = wxBitmap( mImages[i] );
1122  n++;
1123  }
1124  }
1125  }
1126  if( n==0 )
1127  {
1128  if( bOkIfNotFound )
1129  return;
1130  AudacityMessageBox(wxString::Format(_("None of the expected theme component files\n were found in:\n %s."),
1132  }
1133 }
std::vector< wxBitmap > mBitmaps
Definition: Theme.h:147
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
static wxString ThemeComponent(const wxString &Str)
Definition: FileNames.cpp:311
wxArrayString mBitmapNames
Definition: Theme.h:148
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
static wxString ThemeComponentsDir()
Definition: FileNames.cpp:281
std::vector< int > mBitmapFlags
Definition: Theme.h:149
std::vector< wxImage > mImages
Definition: Theme.h:146
bool ThemeBase::LoadPreferredTheme ( )
static

Definition at line 237 of file Theme.cpp.

References gPrefs, LoadTheme(), ThemeTypeOfTypeName(), and theTheme.

Referenced by Theme::EnsureInitialised(), and PrefsDialog::OnOK().

238 {
239 // DA: Default themes differ.
240 #ifdef EXPERIMENTAL_DA
241  wxString theme = gPrefs->Read(wxT("/GUI/Theme"), wxT("dark"));
242 #else
243  wxString theme = gPrefs->Read(wxT("/GUI/Theme"), wxT("light"));
244 #endif
245 
247  return true;
248 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
teThemeType ThemeTypeOfTypeName(const wxString &Name)
Definition: Theme.cpp:932
void LoadTheme(teThemeType Theme)
Definition: Theme.cpp:298
void ThemeBase::LoadTheme ( teThemeType  Theme)

This function is called to load the initial Theme images. It does not though cause the GUI to refresh.

Definition at line 298 of file Theme.cpp.

References bIsUsingSystemTextColour, bRecolourOnLoad, Colour(), ColourDistance(), CreateImageCache(), EnsureInitialised(), GetFallbackThemeType(), LoadComponents(), ReadImageCache(), RecolourTheme(), RotateImageInto(), and theTheme.

Referenced by LoadPreferredTheme().

299 {
301  const bool cbOkIfNotFound = true;
302 
303  if( !ReadImageCache( Theme, cbOkIfNotFound ) )
304  {
305  // THEN get the default set.
306  ReadImageCache( GetFallbackThemeType(), !cbOkIfNotFound );
307 
308  // JKC: Now we could go on and load the individual images
309  // on top of the default images using the commented out
310  // code that follows...
311  //
312  // However, I think it is better to get the user to
313  // build a NEW image cache, which they can do easily
314  // from the Theme preferences tab.
315 #if 0
316  // and now add any available component images.
317  LoadComponents( cbOkIfNotFound );
318 
319  // JKC: I'm usure about doing this next step automatically.
320  // Suppose the disk is write protected?
321  // Is having the image cache created automatically
322  // going to confuse users? Do we need version specific names?
323  // and now save the combined image as a cache for later use.
324  // We should load the images a little faster in future as a result.
326 #endif
327  }
328 
329  RotateImageInto( bmpRecordBeside, bmpRecordBelow, false );
330  RotateImageInto( bmpRecordBesideDisabled, bmpRecordBelowDisabled, false );
331 
332  if( bRecolourOnLoad )
333  RecolourTheme();
334 
335  wxColor Back = theTheme.Colour( clrTrackInfo );
336  wxColor CurrentText = theTheme.Colour( clrTrackPanelText );
337  wxColor DesiredText = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
338 
339  int TextColourDifference = ColourDistance( CurrentText, DesiredText );
340 
341  bIsUsingSystemTextColour = ( TextColourDifference == 0 );
342  // Theming is very accepting of alternative text colours. They just need to
343  // have decent contrast to the background colour, if we're blending themes.
345  int ContrastLevel = ColourDistance( Back, DesiredText );
346  bIsUsingSystemTextColour = bRecolourOnLoad && (ContrastLevel > 250);
348  Colour( clrTrackPanelText ) = DesiredText;
349  }
350  bRecolourOnLoad = false;
351 
352  // Next line is not required as we haven't yet built the GUI
353  // when this function is (or should be) called.
354  // ApplyUpdatedImages();
355 }
void RotateImageInto(int iTo, int iFrom, bool bClockwise)
Definition: Theme.cpp:1293
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
int ColourDistance(wxColour &From, wxColour &To)
Definition: Theme.cpp:366
bool bRecolourOnLoad
Definition: Theme.h:129
Based on ThemeBase, Theme manages image and icon resources.
Definition: Theme.h:157
void CreateImageCache(bool bBinarySave=true)
Definition: Theme.cpp:660
void LoadComponents(bool bOkIfNotFound=false)
Definition: Theme.cpp:1085
teThemeType GetFallbackThemeType()
Definition: Theme.cpp:922
void RecolourTheme()
Definition: Theme.cpp:376
virtual void EnsureInitialised()=0
bool ReadImageCache(teThemeType type=themeFromFile, bool bOkIfNotFound=false)
Definition: Theme.cpp:953
bool bIsUsingSystemTextColour
Definition: Theme.h:130
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
wxImage ThemeBase::MakeImageWithAlpha ( wxBitmap &  Bmp)

Definition at line 1218 of file Theme.cpp.

1219 {
1220  // BUG in wxWidgets. Conversion from BMP to image does not preserve alpha.
1221  wxImage image( Bmp.ConvertToImage() );
1222  return image;
1223 }
wxImage ThemeBase::MaskedImage ( char const **  pXpm,
char const **  pMask 
)

Definition at line 409 of file Theme.cpp.

410 {
411  wxBitmap Bmp1( pXpm );
412  wxBitmap Bmp2( pMask );
413 
414 // wxLogDebug( wxT("Image 1: %i Image 2: %i"),
415 // Bmp1.GetDepth(), Bmp2.GetDepth() );
416 
417  // We want a 24-bit-depth bitmap if all is working, but on some
418  // platforms it might just return -1 (which means best available
419  // or not relevant).
420  // JKC: \todo check that we're not relying on 24 bit elsewhere.
421  wxASSERT( Bmp1.GetDepth()==-1 || Bmp1.GetDepth()==24);
422  wxASSERT( Bmp1.GetDepth()==-1 || Bmp2.GetDepth()==24);
423 
424  int i,nBytes;
425  nBytes = Bmp1.GetWidth() * Bmp1.GetHeight();
426  wxImage Img1( Bmp1.ConvertToImage());
427  wxImage Img2( Bmp2.ConvertToImage());
428 
429 // unsigned char *src = Img1.GetData();
430  unsigned char *mk = Img2.GetData();
431  //wxImage::setAlpha requires memory allocated with malloc, not NEW
433  static_cast<unsigned char*>(malloc( nBytes )) };
434 
435  // Extract alpha channel from second XPM.
436  for(i=0;i<nBytes;i++)
437  {
438  alpha[i] = mk[0];
439  mk+=3;
440  }
441 
442  Img1.SetAlpha( alpha.release() );
443 
444  //dmazzoni: the top line does not work on wxGTK
445  //wxBitmap Result( Img1, 32 );
446  //wxBitmap Result( Img1 );
447 
448  return Img1;
449 }
std::unique_ptr< Character[], freer > MallocString
Definition: MemoryX.h:336
bool ThemeBase::ReadImageCache ( teThemeType  type = themeFromFile,
bool  bOkIfNotFound = false 
)

Reads an image cache including images, cursors and colours.

Parameters
bBinaryReadif true means read from an external binary file. otherwise the data is taken from a compiled in block of memory.
bOkIfNotFoundif true means do not report absent file.
Returns
true iff we loaded the images.
Todo:
revisit this hack which makes adding NEW colours easier but which prevents a colour of (1,1,1) from being added. find an alternative way to make adding NEW colours easier. e.g. initialise the background to translucent, perhaps.

Definition at line 953 of file Theme.cpp.

References _(), AudacityMessageBox(), bRecolourOnLoad, ClassicImageCacheAsData, DarkImageCacheAsData, EnsureInitialised(), FlowPacker::GetNextPosition(), GetSubImageWithAlpha(), gPrefs, HiContrastImageCacheAsData, Image(), ImageCacheWidth, ImageSize(), FlowPacker::Init(), LightImageCacheAsData, mBitmapFlags, mBitmaps, FlowPacker::mBorderWidth, mColours, FlowPacker::mFlags, mFlow, mImages, FlowPacker::RectInner(), FlowPacker::RectMid(), resFlagInternal, FlowPacker::SetColourGroup(), FileNames::ThemeCachePng(), themeClassic, themeDark, themeFromFile, themeHiContrast, and themeLight.

Referenced by LoadTheme(), ThemePrefs::OnLoadThemeCache(), and ThemePrefs::OnReadThemeInternal().

954 {
956  wxImage ImageCache;
957  wxBusyCursor busy;
958 
959  // Ensure we have an alpha channel...
960 // if( !ImageCache.HasAlpha() )
961 // {
962 // ImageCache.InitAlpha();
963 // }
964 
965  gPrefs->Read(wxT("/GUI/BlendThemes"), &bRecolourOnLoad, true);
966 
967  if( type == themeFromFile )
968  {
969  const wxString &FileName = FileNames::ThemeCachePng();
970  if( !wxFileExists( FileName ))
971  {
972  if( bOkIfNotFound )
973  return false; // did not load the images, so return false.
975  wxString::Format(
976  _("Audacity could not find file:\n %s.\nTheme not loaded."),
977  FileName ));
978  return false;
979  }
980  if( !ImageCache.LoadFile( FileName, wxBITMAP_TYPE_PNG ))
981  {
982  /* i18n-hint: Do not translate png. It is the name of a file format.*/
984  wxString::Format(
985  _("Audacity could not load file:\n %s.\nBad png format perhaps?"),
986  FileName ));
987  return false;
988  }
989  }
990  // ELSE we are reading from internal storage.
991  else
992  {
993  size_t ImageSize = 0;
994  const unsigned char * pImage = nullptr;
995  switch( type ){
996  default:
997  case themeClassic :
998  ImageSize = sizeof(ClassicImageCacheAsData);
999  pImage = ClassicImageCacheAsData;
1000  break;
1001  case themeLight :
1002  ImageSize = sizeof(LightImageCacheAsData);
1003  pImage = LightImageCacheAsData;
1004  break;
1005  case themeDark :
1006  ImageSize = sizeof(DarkImageCacheAsData);
1007  pImage = DarkImageCacheAsData;
1008  break;
1009  case themeHiContrast :
1010  ImageSize = sizeof(HiContrastImageCacheAsData);
1011  pImage = HiContrastImageCacheAsData;
1012  break;
1013  }
1014  //wxLogDebug("Reading ImageCache %p size %i", pImage, ImageSize );
1015  wxMemoryInputStream InternalStream( pImage, ImageSize );
1016 
1017  if( !ImageCache.LoadFile( InternalStream, wxBITMAP_TYPE_PNG ))
1018  {
1019  // If we get this message, it means that the data in file
1020  // was not a valid png image.
1021  // Most likely someone edited it by mistake,
1022  // Or some experiment is being tried with NEW formats for it.
1023  AudacityMessageBox(_("Audacity could not read its default theme.\nPlease report the problem."));
1024  return false;
1025  }
1026  //wxLogDebug("Read %i by %i", ImageCache.GetWidth(), ImageCache.GetHeight() );
1027  }
1028 
1029  // Resize a large image down.
1030  if( ImageCache.GetWidth() > ImageCacheWidth ){
1031  int h = ImageCache.GetHeight() * ((1.0*ImageCacheWidth)/ImageCache.GetWidth());
1032  ImageCache.Rescale( ImageCacheWidth, h );
1033  }
1034  int i;
1036  mFlow.mBorderWidth = 1;
1037  // Load the bitmaps
1038  for(i = 0; i < (int)mImages.size(); i++)
1039  {
1040  wxImage &Image = mImages[i];
1041  mFlow.mFlags = mBitmapFlags[i];
1042  if( (mBitmapFlags[i] & resFlagInternal)==0)
1043  {
1044  mFlow.GetNextPosition( Image.GetWidth(),Image.GetHeight() );
1045  wxRect R = mFlow.RectInner();
1046  //wxLogDebug( "[%i, %i, %i, %i, \"%s\"], ", R.x, R.y, R.width, R.height, mBitmapNames[i].c_str() );
1047  Image = GetSubImageWithAlpha( ImageCache, mFlow.RectInner() );
1048  mBitmaps[i] = wxBitmap(Image);
1049  }
1050  }
1051  if( !ImageCache.HasAlpha() )
1052  ImageCache.InitAlpha();
1053 
1054 // return true; //To not load colours..
1055  // Now load the colours.
1056  int x,y;
1058  wxColour TempColour;
1059  const int iColSize=10;
1060  for(i = 0; i < (int)mColours.size(); i++)
1061  {
1062  mFlow.GetNextPosition( iColSize, iColSize );
1063  mFlow.RectMid( x, y );
1064  wxRect R = mFlow.RectInner();
1065  //wxLogDebug( "[%i, %i, %i, %i, \"%s\"], ", R.x, R.y, R.width, R.height, mColourNames[i].c_str() );
1066  // Only change the colour if the alpha is opaque.
1067  // This allows us to add NEW colours more easily.
1068  if( ImageCache.GetAlpha(x,y ) > 128 )
1069  {
1070  TempColour = wxColour(
1071  ImageCache.GetRed( x,y),
1072  ImageCache.GetGreen( x,y),
1073  ImageCache.GetBlue(x,y));
1078  if( TempColour != wxColour(1,1,1) )
1079  mColours[i] = TempColour;
1080  }
1081  }
1082  return true;
1083 }
AudacityPrefs * gPrefs
Definition: Prefs.cpp:73
void RectMid(int &x, int &y)
Definition: Theme.cpp:580
static const unsigned char HiContrastImageCacheAsData[]
Definition: Theme.cpp:204
bool bRecolourOnLoad
Definition: Theme.h:129
std::vector< wxBitmap > mBitmaps
Definition: Theme.h:147
const int ImageCacheWidth
Definition: Theme.cpp:656
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
wxSize ImageSize(int iIndex)
Definition: Theme.cpp:1257
void GetNextPosition(int xSize, int ySize)
Definition: Theme.cpp:538
std::vector< wxColour > mColours
Definition: Theme.h:151
int mBorderWidth
Definition: Theme.h:78
int mFlags
Definition: Theme.h:74
wxImage & Image(int iIndex)
Definition: Theme.cpp:1251
static const unsigned char DarkImageCacheAsData[]
Definition: Theme.cpp:195
wxRect RectInner()
Definition: Theme.cpp:575
virtual void EnsureInitialised()=0
static const unsigned char ClassicImageCacheAsData[]
Definition: Theme.cpp:201
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
void Init(int width)
Definition: Theme.cpp:503
static wxString ThemeCachePng()
Definition: FileNames.cpp:286
static const unsigned char LightImageCacheAsData[]
Definition: Theme.cpp:198
wxImage GetSubImageWithAlpha(const wxImage &Src, const wxRect &rect)
FlowPacker mFlow
Definition: Theme.h:153
std::vector< int > mBitmapFlags
Definition: Theme.h:149
void SetColourGroup()
Definition: Theme.cpp:527
std::vector< wxImage > mImages
Definition: Theme.h:146
void ThemeBase::RecolourBitmap ( int  iIndex,
wxColour  From,
wxColour  To 
)

Definition at line 357 of file Theme.cpp.

References Bitmap(), ChangeImageColour(), Image(), and ReplaceImage().

Referenced by RecolourTheme().

358 {
359  wxImage Image( Bitmap( iIndex ).ConvertToImage() );
360 
361  std::unique_ptr<wxImage> pResult = ChangeImageColour(
362  &Image, From, To );
363  ReplaceImage( iIndex, pResult.get() );
364 }
void ReplaceImage(int iIndex, wxImage *pImage)
Replaces both the image and the bitmap.
Definition: Theme.cpp:1287
wxBitmap & Bitmap(int iIndex)
Definition: Theme.cpp:1244
wxImage & Image(int iIndex)
Definition: Theme.cpp:1251
std::unique_ptr< wxImage > ChangeImageColour(wxImage *srcImage, wxColour &dstColour)
void ThemeBase::RecolourTheme ( )

Definition at line 376 of file Theme.cpp.

References Colour(), ColourDistance(), and RecolourBitmap().

Referenced by LoadTheme().

377 {
378  wxColour From = Colour( clrMedium );
379 #if defined( __WXGTK__ )
380  wxColour To = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND );
381 #else
382  wxColour To = wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE );
383 #endif
384  // only recolour if recolouring is slight.
385  int d = ColourDistance( From, To );
386 
387  // Don't recolour if difference is too big.
388  if( d > 120 )
389  return;
390 
391  // A minor tint difference from standard does not need
392  // to be recouloured either. Includes case of d==0 which is nothing
393  // needs to be done.
394  if( d < 40 )
395  return;
396 
397  Colour( clrMedium ) = To;
398  RecolourBitmap( bmpUpButtonLarge, From, To );
399  RecolourBitmap( bmpDownButtonLarge, From, To );
400  RecolourBitmap( bmpHiliteButtonLarge, From, To );
401  RecolourBitmap( bmpUpButtonSmall, From, To );
402  RecolourBitmap( bmpDownButtonSmall, From, To );
403  RecolourBitmap( bmpHiliteButtonSmall, From, To );
404 
405  Colour( clrTrackInfo ) = To;
406  RecolourBitmap( bmpUpButtonExpand, From, To );
407 }
int ColourDistance(wxColour &From, wxColour &To)
Definition: Theme.cpp:366
void RecolourBitmap(int iIndex, wxColour From, wxColour To)
Definition: Theme.cpp:357
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
void ThemeBase::RegisterColour ( int &  iIndex,
const wxColour &  Clr,
const wxString &  Name 
)

Definition at line 495 of file Theme.cpp.

References mColourNames, and mColours.

496 {
497  wxASSERT( iIndex == -1 ); // Don't initialise same colour twice!
498  mColours.push_back( Clr );
499  mColourNames.Add( Name );
500  iIndex = mColours.size() - 1;
501 }
wxArrayString mColourNames
Definition: Theme.h:152
std::vector< wxColour > mColours
Definition: Theme.h:151
void ThemeBase::RegisterImage ( int &  iIndex,
char const **  pXpm,
const wxString &  Name 
)

Definition at line 455 of file Theme.cpp.

456 {
457  wxASSERT( iIndex == -1 ); // Don't initialise same bitmap twice!
458  wxBitmap Bmp( pXpm );
459  wxImage Img( Bmp.ConvertToImage() );
460  // The next line recommended by http://forum.audacityteam.org/viewtopic.php?f=50&t=96765
461  Img.SetMaskColour(0xDE, 0xDE, 0xDE);
462  Img.InitAlpha();
463 
464  //dmazzoni: the top line does not work on wxGTK
465  //wxBitmap Bmp2( Img, 32 );
466  //wxBitmap Bmp2( Img );
467 
468  RegisterImage( iIndex, Img, Name );
469 }
void RegisterImage(int &iIndex, char const **pXpm, const wxString &Name)
Definition: Theme.cpp:455
void ThemeBase::RegisterImage ( int &  iIndex,
const wxImage &  Image,
const wxString &  Name 
)

Definition at line 471 of file Theme.cpp.

References mBitmapFlags, mBitmapNames, mBitmaps, FlowPacker::mFlags, mFlow, mImages, and resFlagSkip.

472 {
473  wxASSERT( iIndex == -1 ); // Don't initialise same bitmap twice!
474  mImages.push_back( Image );
475 
476 #ifdef __APPLE__
477  // On Mac, bitmaps with alpha don't work.
478  // So we convert to a mask and use that.
479  // It isn't quite as good, as alpha gives smoother edges.
480  //[Does not affect the large control buttons, as for those we do
481  // the blending ourselves anyway.]
482  wxImage TempImage( Image );
483  TempImage.ConvertAlphaToMask();
484  mBitmaps.push_back( wxBitmap( TempImage ) );
485 #else
486  mBitmaps.push_back( wxBitmap( Image ) );
487 #endif
488 
489  mBitmapNames.Add( Name );
490  mBitmapFlags.push_back( mFlow.mFlags );
492  iIndex = mBitmaps.size() - 1;
493 }
std::vector< wxBitmap > mBitmaps
Definition: Theme.h:147
wxArrayString mBitmapNames
Definition: Theme.h:148
int mFlags
Definition: Theme.h:74
wxImage & Image(int iIndex)
Definition: Theme.cpp:1251
FlowPacker mFlow
Definition: Theme.h:153
std::vector< int > mBitmapFlags
Definition: Theme.h:149
std::vector< wxImage > mImages
Definition: Theme.h:146
void ThemeBase::ReplaceImage ( int  iIndex,
wxImage *  pImage 
)

Replaces both the image and the bitmap.

Definition at line 1287 of file Theme.cpp.

References Bitmap(), and Image().

Referenced by ToolBar::MakeMacRecoloredImage(), RecolourBitmap(), and RotateImageInto().

1288 {
1289  Image( iIndex ) = *pImage;
1290  Bitmap( iIndex ) = wxBitmap( *pImage );
1291 }
wxBitmap & Bitmap(int iIndex)
Definition: Theme.cpp:1244
wxImage & Image(int iIndex)
Definition: Theme.cpp:1251
void ThemeBase::RotateImageInto ( int  iTo,
int  iFrom,
bool  bClockwise 
)

Definition at line 1293 of file Theme.cpp.

References Bitmap(), ReplaceImage(), and theTheme.

Referenced by LoadTheme().

1294 {
1295  wxImage img(theTheme.Bitmap( iFrom ).ConvertToImage() );
1296  wxImage img2 = img.Rotate90( bClockwise );
1297  ReplaceImage( iTo, &img2 );
1298 }
AUDACITY_DLL_API Theme theTheme
Definition: Theme.cpp:209
void ReplaceImage(int iIndex, wxImage *pImage)
Replaces both the image and the bitmap.
Definition: Theme.cpp:1287
wxBitmap & Bitmap(int iIndex)
Definition: Theme.cpp:1244
void ThemeBase::SaveComponents ( )
Bug:
1 in wxWidgets documentation; wxMkDir returns false if directory didn't exist, even if it successfully creates it. so we create and then test if it exists instead.
Bug:
2 in wxWidgets documentation; wxMkDir has only one argument under MSW

Definition at line 1135 of file Theme.cpp.

References _(), AudacityMessageBox(), AudacityMessageBoxCaptionStr(), mBitmapFlags, mBitmapNames, mImages, resFlagInternal, FileNames::ThemeComponent(), and FileNames::ThemeComponentsDir().

Referenced by ThemePrefs::OnSaveThemeComponents().

1136 {
1137  // IF directory doesn't exist THEN create it
1138  if( !wxDirExists( FileNames::ThemeComponentsDir() ))
1139  {
1145 #ifdef __WXMSW__
1146  wxMkDir( FileNames::ThemeComponentsDir().fn_str() );
1147 #else
1148  wxMkDir( FileNames::ThemeComponentsDir().fn_str(), 0700 );
1149 #endif
1150  if( !wxDirExists( FileNames::ThemeComponentsDir() ))
1151  {
1153  wxString::Format(
1154  _("Could not create directory:\n %s"),
1156  return;
1157  }
1158  }
1159 
1160  wxBusyCursor busy;
1161  int i;
1162  int n=0;
1163  wxString FileName;
1164  for(i = 0; i < (int)mImages.size(); i++)
1165  {
1166  if( (mBitmapFlags[i] & resFlagInternal)==0)
1167  {
1168  FileName = FileNames::ThemeComponent( mBitmapNames[i] );
1169  if( wxFileExists( FileName ))
1170  {
1171  ++n;
1172  break;
1173  }
1174  }
1175  }
1176 
1177  if (n > 0)
1178  {
1179  auto result =
1181  wxString::Format(
1182  _("Some required files in:\n %s\nwere already present. Overwrite?"),
1185  wxYES_NO | wxNO_DEFAULT);
1186  if(result == wxNO)
1187  return;
1188  }
1189 
1190  for(i = 0; i < (int)mImages.size(); i++)
1191  {
1192  if( (mBitmapFlags[i] & resFlagInternal)==0)
1193  {
1194  FileName = FileNames::ThemeComponent( mBitmapNames[i] );
1195  if( !mImages[i].SaveFile( FileName, wxBITMAP_TYPE_PNG ))
1196  {
1198  wxString::Format(
1199  _("Audacity could not save file:\n %s"),
1200  FileName ));
1201  return;
1202  }
1203  }
1204  }
1206  wxString::Format(
1207  _("Theme written to:\n %s."),
1209 }
wxString AudacityMessageBoxCaptionStr()
int AudacityMessageBox(const wxString &message, const wxString &caption=AudacityMessageBoxCaptionStr(), long style=wxOK|wxCENTRE, wxWindow *parent=NULL, int x=wxDefaultCoord, int y=wxDefaultCoord)
Definition: ErrorDialog.h:92
static wxString ThemeComponent(const wxString &Str)
Definition: FileNames.cpp:311
wxArrayString mBitmapNames
Definition: Theme.h:148
_("Move Track &Down")+wxT("\t")+(GetActiveProject() -> GetCommandManager() ->GetKeyFromName(wxT("TrackMoveDown")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveTopID, _("Move Track to &Top")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveTop")).Raw()), OnMoveTrack) POPUP_MENU_ITEM(OnMoveBottomID, _("Move Track to &Bottom")+wxT("\t")+(GetActiveProject() ->GetCommandManager() ->GetKeyFromName(wxT("TrackMoveBottom")).Raw()), OnMoveTrack)#define SET_TRACK_NAME_PLUGIN_SYMBOLclass SetTrackNameCommand:public AudacityCommand
static wxString ThemeComponentsDir()
Definition: FileNames.cpp:281
std::vector< int > mBitmapFlags
Definition: Theme.h:149
std::vector< wxImage > mImages
Definition: Theme.h:146
void ThemeBase::SaveThemeAsCode ( )

Definition at line 1212 of file Theme.cpp.

References CreateImageCache().

Referenced by ThemePrefs::OnSaveThemeAsCode().

1213 {
1214  // false indicates not using standard binary method.
1215  CreateImageCache( false );
1216 }
void CreateImageCache(bool bBinarySave=true)
Definition: Theme.cpp:660
void ThemeBase::SetBrushColour ( wxBrush &  Brush,
int  iIndex 
)

Definition at line 1232 of file Theme.cpp.

References Colour().

Referenced by AColor::Init(), NumericTextCtrl::Layout(), NumericTextCtrl::OnPaint(), and TrackArtist::SetColours().

1233 {
1234  wxASSERT( iIndex >= 0 );
1235  Brush.SetColour( Colour( iIndex ));
1236 }
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
void ThemeBase::SetFlags ( int  flags)
inline

Definition at line 137 of file Theme.h.

137 { mFlow.mFlags = flags;};
int mFlags
Definition: Theme.h:74
FlowPacker mFlow
Definition: Theme.h:153
void ThemeBase::SetPenColour ( wxPen &  Pen,
int  iIndex 
)

Definition at line 1238 of file Theme.cpp.

References Colour().

Referenced by AColor::Init(), NumericTextCtrl::OnPaint(), and TrackArtist::SetColours().

1239 {
1240  wxASSERT( iIndex >= 0 );
1241  Pen.SetColour( Colour( iIndex ));
1242 }
wxColour & Colour(int iIndex)
Definition: Theme.cpp:1225
teThemeType ThemeBase::ThemeTypeOfTypeName ( const wxString &  Name)

Definition at line 932 of file Theme.cpp.

References GetFallbackThemeType().

Referenced by LoadPreferredTheme().

933 {
934  wxArrayString aThemes;
935  aThemes.Add( "classic" );
936  aThemes.Add( "dark" );
937  aThemes.Add( "light" );
938  aThemes.Add( "high-contrast" );
939  aThemes.Add( "custom" );
940  int themeIx = aThemes.Index( Name );
941  if( themeIx < 0 )
942  return GetFallbackThemeType();
943  return (teThemeType)themeIx;
944 }
teThemeType
Definition: Theme.h:49
teThemeType GetFallbackThemeType()
Definition: Theme.cpp:922
void ThemeBase::WriteImageDefs ( )

Writes a series of Macro definitions that can be used in the include file.

Definition at line 882 of file Theme.cpp.

References EnsureInitialised(), mBitmapFlags, mBitmapNames, mImages, resFlagCursor, resFlagInternal, resFlagNewLine, resFlagPaired, and FileNames::ThemeImageDefsAsCee().

Referenced by ThemePrefs::OnSaveThemeAsCode().

883 {
885  wxBusyCursor busy;
886 
887  int i;
888  wxFFile File( FileNames::ThemeImageDefsAsCee(), wxT("wb") );
889  if( !File.IsOpened() )
890  return;
891  teResourceFlags PrevFlags = (teResourceFlags)-1;
892  for(i = 0; i < (int)mImages.size(); i++)
893  {
894  wxImage &SrcImage = mImages[i];
895  // No href in html. Uses title not alt.
896  if( PrevFlags != mBitmapFlags[i] )
897  {
898  PrevFlags = (teResourceFlags)mBitmapFlags[i];
899  int t = (int)PrevFlags;
900  wxString Temp;
901  if( t==0 ) Temp = wxT(" resFlagNone ");
902  if( t & resFlagPaired ) Temp += wxT(" resFlagPaired ");
903  if( t & resFlagCursor ) Temp += wxT(" resFlagCursor ");
904  if( t & resFlagNewLine ) Temp += wxT(" resFlagNewLine ");
905  if( t & resFlagInternal ) Temp += wxT(" resFlagInternal ");
906  Temp.Replace( wxT(" "), wxT(" | ") );
907 
908  File.Write( wxString::Format( wxT("\r\n SET_THEME_FLAGS( %s );\r\n"),
909  Temp ));
910  }
911  File.Write( wxString::Format(
912  wxT(" DEFINE_IMAGE( bmp%s, wxImage( %i, %i ), wxT(\"%s\"));\r\n"),
913  mBitmapNames[i],
914  SrcImage.GetWidth(),
915  SrcImage.GetHeight(),
916  mBitmapNames[i]
917  ));
918  }
919 }
teResourceFlags
Definition: Theme.h:39
static wxString ThemeImageDefsAsCee()
Definition: FileNames.cpp:296
wxArrayString mBitmapNames
Definition: Theme.h:148
virtual void EnsureInitialised()=0
std::vector< int > mBitmapFlags
Definition: Theme.h:149
std::vector< wxImage > mImages
Definition: Theme.h:146
void ThemeBase::WriteImageMap ( )

Writes an html file with an image map of the ImageCache Very handy for seeing what each part is for.

Definition at line 829 of file Theme.cpp.

References EnsureInitialised(), FlowPacker::GetNextPosition(), FlowPacker::Init(), mBitmapFlags, mBitmapNames, FlowPacker::mBorderWidth, mColourNames, mColours, FlowPacker::mFlags, mFlow, mImages, FlowPacker::RectInner(), resFlagInternal, FlowPacker::SetColourGroup(), and FileNames::ThemeCacheHtm().

Referenced by ThemePrefs::OnSaveThemeCache().

830 {
832  wxBusyCursor busy;
833 
834  int i;
836  mFlow.mBorderWidth = 1;
837 
838  wxFFile File( FileNames::ThemeCacheHtm(), wxT("wb") );// I'll put in NEW lines explicitly.
839  if( !File.IsOpened() )
840  return;
841 
842  File.Write( wxT("<html>\r\n"));
843  File.Write( wxT("<body bgcolor=\"303030\">\r\n"));
844  wxString Temp = wxString::Format( wxT("<img src=\"ImageCache.png\" width=\"%i\" usemap=\"#map1\">\r\n" ), ImageCacheWidth );
845  File.Write( Temp );
846  File.Write( wxT("<map name=\"map1\">\r\n") );
847 
848  for(i = 0; i < (int)mImages.size(); i++)
849  {
850  wxImage &SrcImage = mImages[i];
852  if( (mBitmapFlags[i] & resFlagInternal)==0)
853  {
854  mFlow.GetNextPosition( SrcImage.GetWidth(), SrcImage.GetHeight());
855  // No href in html. Uses title not alt.
856  wxRect R( mFlow.RectInner() );
857  File.Write( wxString::Format(
858  wxT("<area title=\"Bitmap:%s\" shape=rect coords=\"%i,%i,%i,%i\">\r\n"),
859  mBitmapNames[i],
860  R.GetLeft(), R.GetTop(), R.GetRight(), R.GetBottom()) );
861  }
862  }
863  // Now save the colours.
865  const int iColSize = 10;
866  for(i = 0; i < (int)mColours.size(); i++)
867  {
868  mFlow.GetNextPosition( iColSize, iColSize );
869  // No href in html. Uses title not alt.
870  wxRect R( mFlow.RectInner() );
871  File.Write( wxString::Format( wxT("<area title=\"Colour:%s\" shape=rect coords=\"%i,%i,%i,%i\">\r\n"),
872  mColourNames[i],
873  R.GetLeft(), R.GetTop(), R.GetRight(), R.GetBottom()) );
874  }
875  File.Write( wxT("</map>\r\n") );
876  File.Write( wxT("</body>\r\n"));
877  File.Write( wxT("</html>\r\n"));
878  // File will be closed automatically.
879 }
const int ImageCacheWidth
Definition: Theme.cpp:656
void GetNextPosition(int xSize, int ySize)
Definition: Theme.cpp:538
static wxString ThemeCacheHtm()
Definition: FileNames.cpp:291
wxArrayString mColourNames
Definition: Theme.h:152
std::vector< wxColour > mColours
Definition: Theme.h:151
int mBorderWidth
Definition: Theme.h:78
wxArrayString mBitmapNames
Definition: Theme.h:148
int mFlags
Definition: Theme.h:74
wxRect RectInner()
Definition: Theme.cpp:575
virtual void EnsureInitialised()=0
void Init(int width)
Definition: Theme.cpp:503
FlowPacker mFlow
Definition: Theme.h:153
std::vector< int > mBitmapFlags
Definition: Theme.h:149
void SetColourGroup()
Definition: Theme.cpp:527
std::vector< wxImage > mImages
Definition: Theme.h:146

Member Data Documentation

bool ThemeBase::bIsUsingSystemTextColour

Definition at line 130 of file Theme.h.

Referenced by LoadTheme(), and ThemeBase().

bool ThemeBase::bRecolourOnLoad

Definition at line 129 of file Theme.h.

Referenced by LoadTheme(), ReadImageCache(), and ThemeBase().

std::vector<int> ThemeBase::mBitmapFlags
protected
wxArrayString ThemeBase::mBitmapNames
protected
std::vector<wxBitmap> ThemeBase::mBitmaps
protected

Definition at line 147 of file Theme.h.

Referenced by Bitmap(), LoadComponents(), ReadImageCache(), and RegisterImage().

wxArrayString ThemeBase::mColourNames
protected

Definition at line 152 of file Theme.h.

Referenced by CreateImageCache(), RegisterColour(), and WriteImageMap().

std::vector<wxColour> ThemeBase::mColours
protected

Definition at line 151 of file Theme.h.

Referenced by Colour(), CreateImageCache(), ReadImageCache(), RegisterColour(), and WriteImageMap().

FlowPacker ThemeBase::mFlow
protected

Definition at line 153 of file Theme.h.

Referenced by CreateImageCache(), ReadImageCache(), RegisterImage(), and WriteImageMap().

std::vector<wxImage> ThemeBase::mImages
protected

The documentation for this class was generated from the following files: