Reapply theme coloring

Upstream got rid of theme recoloring, but I thought ours worked pretty
good, so I decided to reapply it. This commit also reapplies commit
ee370f0e13.

Actually, upstream's new dark theme blends pretty well with Breeze Dark
under KDE on Arch Linux. Still, our themes will be reintroduced (and set
as default).

Co-authored-by: akleja <storspov@gmail.com>
Signed-off-by: Avery King <avery98@pm.me>
This commit is contained in:
Avery King
2025-01-02 08:54:39 -08:00
parent cb1b65f3a0
commit 4798fca515
5 changed files with 86 additions and 0 deletions

View File

@@ -77,6 +77,9 @@ bool App::OnInit()
// Leave no persistent side-effect on preferences
SettingScope scope;
// Don't blend colors
GUIBlendThemes.Write(false);
// So that the program can interpret PNG
wxInitAllImageHandlers();

View File

@@ -262,6 +262,27 @@ void ThemeBase::LoadTheme( teThemeType Theme )
RotateImageInto( bmpRecordBeside, bmpRecordBelow, false );
RotateImageInto( bmpRecordBesideDisabled, bmpRecordBelowDisabled, false );
// Other modifications of images happening only when the setting
// GUIBlendThemes is true
if ( mpSet->bRecolourOnLoad ) {
RecolourTheme();
wxColor Back = theTheme.Colour( clrTrackInfo );
wxColor CurrentText = theTheme.Colour( clrTrackPanelText );
wxColor DesiredText = wxSystemSettings::GetColour( wxSYS_COLOUR_WINDOWTEXT );
int TextColourDifference = ColourDistance( CurrentText, DesiredText );
// Theming is very accepting of alternative text colours. They just need to
// have decent contrast to the background colour, if we're blending themes.
if ( TextColourDifference != 0 ) {
int ContrastLevel = ColourDistance( Back, DesiredText );
if ( ContrastLevel > 250 )
Colour( clrTrackPanelText ) = DesiredText;
}
mpSet->bRecolourOnLoad = false;
}
// Next line is not required as we haven't yet built the GUI
// when this function is (or should be) called.
// AColor::ApplyUpdatedImages();
@@ -289,6 +310,35 @@ int ThemeBase::ColourDistance( wxColour & From, wxColour & To ){
+ abs( From.Blue() - To.Blue() );
}
// This function coerces a theme to be more like the system colours.
// Only used for built in themes. For custom themes a user
// will choose a better theme for them and just not use a mismatching one.
void ThemeBase::RecolourTheme()
{
wxColour From = Colour( clrMedium );
#if defined( __WXGTK__ )
wxColour To = wxSystemSettings::GetColour( wxSYS_COLOUR_BACKGROUND );
#else
wxColour To = wxSystemSettings::GetColour( wxSYS_COLOUR_3DFACE );
#endif
// Don't recolour if difference is too big.
int d = ColourDistance( From, To );
if( d > 120 )
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 )
{
wxBitmap Bmp1( pXpm );
@@ -851,6 +901,8 @@ bool ThemeBase::ReadImageCache( teThemeType type, bool bOkIfNotFound)
// ImageCache.InitAlpha();
// }
mpSet->bRecolourOnLoad = GUIBlendThemes.Read();
using namespace BasicUI;
if( type.empty() || type == "custom" )
@@ -1317,3 +1369,5 @@ ChoiceSetting &GUITheme()
return setting;
}
BoolSetting GUIBlendThemes{ wxT("/GUI/BlendThemes"), true };

View File

@@ -105,6 +105,7 @@ struct ThemeSet
std::vector<wxColour> mColours;
bool bInitialised = false;
bool bRecolourOnLoad = false; // Request to recolour
};
struct ThemeChangeMessage {
@@ -171,6 +172,7 @@ public:
void WriteOneImageMap( teThemeType id );
static bool LoadPreferredTheme();
void RecolourBitmap( int iIndex, wxColour From, wxColour To );
void RecolourTheme();
int ColourDistance( wxColour & From, wxColour & To );
wxColour & Colour( int iIndex );
@@ -219,6 +221,10 @@ public:
extern THEME_API Theme theTheme;
extern THEME_API BoolSetting
GUIBlendThemes
;
extern THEME_API ChoiceSetting
&GUITheme()
;

View File

@@ -142,6 +142,8 @@ void GUIPrefs::PopulateOrExchange(ShuttleGui & S)
S.TieCheckBox(XXO("Re&tain labels if selection snaps to a label"),
{wxT("/GUI/RetainLabels"),
false});
S.TieCheckBox(XXO("B&lend system and Tenacity theme"),
GUIBlendThemes);
#ifndef __WXMAC__
/* i18n-hint: RTL stands for 'Right to Left' */
S.TieCheckBox(XXO("Use mostly Left-to-Right layouts in RTL languages"),

View File

@@ -57,6 +57,21 @@ BEGIN_EVENT_TABLE(ThemePrefs, PrefsPanel)
EVT_BUTTON(idSaveThemeAsCode, ThemePrefs::OnSaveThemeAsCode)
END_EVENT_TABLE()
static bool ConfirmSave()
{
if (!GUIBlendThemes.Read())
return true;
using namespace BasicUI;
const auto message = Verbatim(
"\"Blend system and TEnacity theme\" in Interface Preferences was on.\n"
"This may cause images to to be re-saved with slight changes of color."
);
return MessageBoxResult::Cancel != ShowMessageBox(message,
MessageBoxOptions{}.CancelButton().IconStyle(Icon::Warning));
}
ThemePrefs::ThemePrefs(wxWindow * parent, wxWindowID winid)
/* i18n-hint: A theme is a consistent visual style across an application's
graphical user interface, including choices of colors, and similarity of images
@@ -181,6 +196,8 @@ void ThemePrefs::OnLoadThemeComponents(wxCommandEvent & WXUNUSED(event))
/// Save Theme to multiple png files.
void ThemePrefs::OnSaveThemeComponents(wxCommandEvent & WXUNUSED(event))
{
if (!ConfirmSave()) return;
wxBusyCursor busy;
theTheme.SaveThemeComponents();
}
@@ -196,6 +213,8 @@ void ThemePrefs::OnLoadThemeCache(wxCommandEvent & WXUNUSED(event))
/// Save Themes, each to a single png file.
void ThemePrefs::OnSaveThemeCache(wxCommandEvent & WXUNUSED(event))
{
if (!ConfirmSave()) return;
wxBusyCursor busy;
theTheme.CreateImageCache();
theTheme.WriteImageMap();// bonus - give them the html version.
@@ -212,6 +231,8 @@ void ThemePrefs::OnReadThemeInternal(wxCommandEvent & WXUNUSED(event))
/// Save Theme as C source code.
void ThemePrefs::OnSaveThemeAsCode(wxCommandEvent & WXUNUSED(event))
{
if (!ConfirmSave()) return;
wxBusyCursor busy;
theTheme.SaveThemeAsCode();
theTheme.WriteImageDefs();// bonus - give them the Defs too.