Skip to content

Commit

Permalink
chore: move the transparency theme flag to a setting
Browse files Browse the repository at this point in the history
it no longer requires a specific theme
  • Loading branch information
misha-gilbert committed Jan 21, 2024
1 parent 4dd41a7 commit 50aa705
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 59 deletions.
11 changes: 8 additions & 3 deletions FoxTunes.UI.Windows.LibraryBrowser/LibraryBrowserBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.IO;
using System.IO.Packaging;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
Expand All @@ -17,8 +18,6 @@ namespace FoxTunes
{
public abstract class LibraryBrowserBase : ConfigurableUIComponentBase
{
public static readonly ThemeLoader ThemeLoader = ComponentRegistry.Instance.GetComponent<ThemeLoader>();

protected override void CreateMenu()
{
var menu = new Menu()
Expand All @@ -35,6 +34,8 @@ protected override void CreateMenu()

public SelectionConfigurationElement ImageMode { get; private set; }

public BooleanConfigurationElement Transparency { get; private set; }

protected override void OnConfigurationChanged()
{
if (this.Configuration != null)
Expand All @@ -47,6 +48,10 @@ protected override void OnConfigurationChanged()
LibraryBrowserBaseConfiguration.SECTION,
LibraryBrowserBaseConfiguration.TILE_IMAGE
);
this.Transparency = this.Configuration.GetElement<BooleanConfigurationElement>(
WindowsUserInterfaceConfiguration.SECTION,
WindowsUserInterfaceConfiguration.TRANSPARENCY
);
this.TileSize.ValueChanged += this.OnValueChanged;
this.ImageMode.ValueChanged += this.OnValueChanged;
}
Expand Down Expand Up @@ -185,7 +190,7 @@ protected virtual void ApplyBlur()
var activeListBox = this.GetActiveListBox();
var inactiveListBox = this.GetInactiveListBox();
activeListBox.Effect = null;
if (ThemeLoader.Theme.Flags.HasFlag(ThemeFlags.RequiresTransparency))
if (this.Transparency.Value)
{
if (inactiveListBox != null)
{
Expand Down
9 changes: 0 additions & 9 deletions FoxTunes.UI.Windows.Themes/Properties/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions FoxTunes.UI.Windows.Themes/Properties/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,4 @@
<data name="TransparentThemeConfiguration.Opacity" xml:space="preserve">
<value>Opacity</value>
</data>
<data name="TransparentThemeConfiguration.AccentColor" xml:space="preserve">
<value>Accent Color</value>
</data>
</root>
8 changes: 0 additions & 8 deletions FoxTunes.UI.Windows.Themes/TransparentTheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,6 @@ public override int CornerRadius
}
}

public override ThemeFlags Flags
{
get
{
return ThemeFlags.RequiresTransparency;
}
}

public IntegerConfigurationElement Opacity { get; private set; }

public override void InitializeComponent(ICore core)
Expand Down
4 changes: 0 additions & 4 deletions FoxTunes.UI.Windows.Themes/TransparentThemeConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,12 @@ internal class TransparentThemeConfiguration

public const int MAX_OPACITY = 100;

public const string ACCENT_COLOR = WindowsUserInterfaceConfiguration.ACCENT_COLOR;

public static IEnumerable<ConfigurationSection> GetConfigurationSections()
{
yield return new ConfigurationSection(SECTION)
.WithElement(new IntegerConfigurationElement(OPACITY, Strings.TransparentThemeConfiguration_Opacity)
.WithValue(DEFAULT_OPACITY)
.WithValidationRule(new IntegerValidationRule(MIN_OPACITY, MAX_OPACITY))
.DependsOn(WindowsUserInterfaceConfiguration.SECTION, WindowsUserInterfaceConfiguration.THEME_ELEMENT, TransparentTheme.ID))
.WithElement(new TextConfigurationElement(ACCENT_COLOR, Strings.TransparentThemeConfiguration_AccentColor)
.DependsOn(WindowsUserInterfaceConfiguration.SECTION, WindowsUserInterfaceConfiguration.THEME_ELEMENT, TransparentTheme.ID));
}
}
Expand Down
48 changes: 20 additions & 28 deletions FoxTunes.UI.Windows/Extensions/Window_AllowsTransparency.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using FoxTunes.Interfaces;
using FoxDb;
using FoxTunes.Interfaces;
using System;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Interop;
using System.Windows.Media;
using System.Windows.Media.Animation;

namespace FoxTunes
{
Expand Down Expand Up @@ -56,7 +58,6 @@ private class AllowsTransparencyBehaviour : UIBehaviour

private AllowsTransparencyBehaviour()
{
this.ThemeLoader = ComponentRegistry.Instance.GetComponent<ThemeLoader>();
this.UserInterface = ComponentRegistry.Instance.GetComponent<IUserInterface>();
this.Configuration = ComponentRegistry.Instance.GetComponent<IConfiguration>();
}
Expand All @@ -65,13 +66,19 @@ public AllowsTransparencyBehaviour(Window window) : this()
{
this.Window = window;
this.Window.Loaded += this.OnLoaded;
if (this.ThemeLoader != null)
{
this.ThemeLoader.ThemeChanged += this.OnThemeChanged;
this.Refresh();
}
if (this.Configuration != null)
{
this.Configuration.GetElement<BooleanConfigurationElement>(
WindowsUserInterfaceConfiguration.SECTION,
WindowsUserInterfaceConfiguration.TRANSPARENCY
).ConnectValue(value =>
{
this.Enabled = value;
if (this.Window != null)
{
this.EnableTransparency(value);
}
});
this.Configuration.GetElement<TextConfigurationElement>(
WindowsUserInterfaceConfiguration.SECTION,
WindowsUserInterfaceConfiguration.ACCENT_COLOR
Expand All @@ -85,20 +92,20 @@ public AllowsTransparencyBehaviour(Window window) : this()
{
this.AccentColor = value.ToColor();
}
if (this.Window != null)
if (this.Window != null && this.Enabled)
{
this.EnableBlur();
}
});
}
}

public ThemeLoader ThemeLoader { get; private set; }

public IUserInterface UserInterface { get; private set; }

public IConfiguration Configuration { get; private set; }

public bool Enabled { get; private set; }

public Color AccentColor { get; private set; }

public Window Window { get; private set; }
Expand All @@ -112,15 +119,9 @@ protected virtual void OnLoaded(object sender, RoutedEventArgs e)
this.EnableBlur();
}

protected virtual void OnThemeChanged(object sender, EventArgs e)
{
this.Refresh();
}

public void Refresh()
public virtual void EnableTransparency(bool enable)
{
var allowsTransparency = this.ThemeLoader.Theme.Flags.HasFlag(ThemeFlags.RequiresTransparency);
if (this.Window.AllowsTransparency != allowsTransparency)
if (this.Window.AllowsTransparency != enable)
{
if (new WindowInteropHelper(this.Window).Handle != IntPtr.Zero)
{
Expand All @@ -131,7 +132,7 @@ public void Refresh()
}
return;
}
this.Window.AllowsTransparency = allowsTransparency;
this.Window.AllowsTransparency = enable;
}
}

Expand All @@ -147,15 +148,6 @@ protected virtual void EnableBlur()
WindowExtensions.EnableBlur(windowHelper.Handle);
}
}

protected override void OnDisposing()
{
if (this.ThemeLoader != null)
{
this.ThemeLoader.ThemeChanged -= this.OnThemeChanged;
}
base.OnDisposing();
}
}

public static bool SupportsAcrylicBlur
Expand Down
18 changes: 18 additions & 0 deletions FoxTunes.UI.Windows/Properties/Strings.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions FoxTunes.UI.Windows/Properties/Strings.resx
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,9 @@
<data name="WindowExtensions.TransparencyWarning" xml:space="preserve">
<value>Restart required to enable/disable transparency.</value>
</data>
<data name="WindowsUserInterfaceConfiguration.AccentColor" xml:space="preserve">
<value>Accent Color</value>
</data>
<data name="WindowsUserInterfaceConfiguration.Counters" xml:space="preserve">
<value>Show Counters</value>
</data>
Expand All @@ -627,4 +630,7 @@
<data name="WindowsUserInterfaceConfiguration.TimerFrequency" xml:space="preserve">
<value>Global Timer Interval</value>
</data>
<data name="WindowsUserInterfaceConfiguration.Transparency" xml:space="preserve">
<value>Transparency</value>
</data>
</root>
3 changes: 1 addition & 2 deletions FoxTunes.UI.Windows/Theme/ITheme.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ public interface ITheme : IStandardComponent
[Flags]
public enum ThemeFlags : byte
{
None = 0,
RequiresTransparency = 1
None = 0
}
}
10 changes: 8 additions & 2 deletions FoxTunes.UI.Windows/WindowsUserInterfaceConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ public static class WindowsUserInterfaceConfiguration

public const int MAX_TIMER_FREQUENCY = 1000;

public const string ACCENT_COLOR = "2A835DBB-8ACE-4FFC-B975-9131D4D82947";
public const string TRANSPARENCY = "NNNN0D57-6E03-4718-ACA3-AD8199F5AC75";

public const string ACCENT_COLOR = "OOOO5DBB-8ACE-4FFC-B975-9131D4D82947";

public static IEnumerable<ConfigurationSection> GetConfigurationSections()
{
Expand All @@ -44,7 +46,11 @@ public static IEnumerable<ConfigurationSection> GetConfigurationSections()
.WithElement(
new BooleanConfigurationElement(SHOW_CURSOR_ADORNERS_ELEMENT, Strings.WindowsUserInterfaceConfiguration_Cursors, path: Strings.General_Advanced).WithValue(Publication.ReleaseType == ReleaseType.Default))
.WithElement(
new IntegerConfigurationElement(TIMER_FREQUENCY, Strings.WindowsUserInterfaceConfiguration_TimerFrequency, path: Strings.General_Advanced).WithValue(DEFAULT_TIMER_FREQUENCY).WithValidationRule(new IntegerValidationRule(MIN_TIMER_FREQUENCY, MAX_TIMER_FREQUENCY))
new IntegerConfigurationElement(TIMER_FREQUENCY, Strings.WindowsUserInterfaceConfiguration_TimerFrequency, path: Strings.General_Advanced).WithValue(DEFAULT_TIMER_FREQUENCY).WithValidationRule(new IntegerValidationRule(MIN_TIMER_FREQUENCY, MAX_TIMER_FREQUENCY)))
.WithElement(
new BooleanConfigurationElement(TRANSPARENCY, Strings.WindowsUserInterfaceConfiguration_Transparency))
.WithElement(
new TextConfigurationElement(ACCENT_COLOR, Strings.WindowsUserInterfaceConfiguration_AccentColor).DependsOn(SECTION, TRANSPARENCY)
);
}

Expand Down

0 comments on commit 50aa705

Please sign in to comment.