From f508439a42f22d11c4156afdc8f8175f6d25c926 Mon Sep 17 00:00:00 2001 From: James Crook Date: Sat, 8 Apr 2017 14:49:10 +0100 Subject: [PATCH] Recolour Classic theme to wxSYS_COLOUR_3DFACE This is mainly for Linux which can have a much darker main bar in Classic theme. --- src/Theme.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/Theme.h | 3 +++ 2 files changed, 47 insertions(+) diff --git a/src/Theme.cpp b/src/Theme.cpp index fae9ed579..54c062a2a 100644 --- a/src/Theme.cpp +++ b/src/Theme.cpp @@ -73,6 +73,7 @@ and use it for toolbar and window layouts too. #include "FileNames.h" #include "Prefs.h" #include "AColor.h" +#include "ImageManipulation.h" #include @@ -276,6 +277,7 @@ void Theme::RegisterColours() ThemeBase::ThemeBase(void) { + bRecolourOnLoad = false; } ThemeBase::~ThemeBase(void) @@ -315,12 +317,52 @@ void ThemeBase::LoadTheme( teThemeType Theme ) CreateImageCache(); #endif } + if( bRecolourOnLoad ) + RecolourTheme(); + bRecolourOnLoad = false; // Next line is not required as we haven't yet built the GUI // when this function is (or should be) called. // ApplyUpdatedImages(); } +void ThemeBase::RecolourBitmap( int iIndex, wxColour From, wxColour To ) +{ + wxImage Image( Bitmap( iIndex ).ConvertToImage() ); + + std::unique_ptr pResult = ChangeImageColour( + &Image, From, To ); + ReplaceImage( iIndex, pResult.get() ); +} + +// This function coerces a theme to be more like the system colours. +void ThemeBase::RecolourTheme() +{ + wxColour From = Colour( clrMedium ); + wxColour To = wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE ); + // only recolour if recolouring is slight. + int d = + abs( From.Red() - To.Red() ) + + abs( From.Green() - To.Green() ) + + abs( From.Blue() - To.Blue() ); + + // Don't recolour if difference is too big, or no difference. + if( d > 120 ) + return; + if( d== 0 ) + return; + + Colour( clrMedium ) = To; + + RecolourBitmap( bmpUpButtonLarge, From, To ); + RecolourBitmap( bmpDownButtonLarge, From, To ); + RecolourBitmap( bmpHiliteButtonLarge, From, To ); + RecolourBitmap( bmpUpButtonSmall, From, To ); + RecolourBitmap( bmpDownButtonSmall, From, To ); + RecolourBitmap( bmpHiliteButtonSmall, From, To ); +// Colour( clrTrackInfo ) = To; +// RecolourBitmap( bmpUpButtonExpand, From, To ); +} wxImage ThemeBase::MaskedImage( char const ** pXpm, char const ** pMask ) { @@ -825,6 +867,7 @@ bool ThemeBase::ReadImageCache( teThemeType type, bool bOkIfNotFound) // ImageCache.InitAlpha(); // } + bRecolourOnLoad = false; if( type == themeFromFile ) { const wxString &FileName = FileNames::ThemeCachePng(); @@ -855,6 +898,7 @@ bool ThemeBase::ReadImageCache( teThemeType type, bool bOkIfNotFound) char * pImage = NULL; switch( type ){ case themeClassic : + bRecolourOnLoad = true; ImageSize = sizeof(ClassicImageCacheAsData); pImage = (char *)ClassicImageCacheAsData; break; diff --git a/src/Theme.h b/src/Theme.h index 307f05497..93c9fa682 100644 --- a/src/Theme.h +++ b/src/Theme.h @@ -116,6 +116,8 @@ public: void WriteImageDefs( ); void WriteImageMap( ); static bool LoadPreferredTheme(); + void RecolourBitmap( int iIndex, wxColour From, wxColour To ); + void RecolourTheme(); wxColour & Colour( int iIndex ); @@ -124,6 +126,7 @@ public: wxCursor & Cursor( int iIndex ); wxFont & Font( int iIndex ); wxSize ImageSize( int iIndex ); + bool bRecolourOnLoad; void ReplaceImage( int iIndex, wxImage * pImage );