mirror of
https://github.com/Flow-Launcher/Flow.Launcher.git
synced 2026-03-11 08:54:32 +00:00
Add DropShadowEffect as a user option
This commit is contained in:
parent
3fddae7e96
commit
09308417a8
6 changed files with 97 additions and 14 deletions
|
|
@ -1,4 +1,4 @@
|
|||
using System;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
|
@ -8,6 +8,7 @@ using System.Windows.Controls;
|
|||
using System.Windows.Interop;
|
||||
using System.Windows.Markup;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Media.Effects;
|
||||
using Flow.Launcher.Infrastructure;
|
||||
using Flow.Launcher.Infrastructure.Logger;
|
||||
using Flow.Launcher.Infrastructure.UserSettings;
|
||||
|
|
@ -68,7 +69,7 @@ namespace Flow.Launcher.Core.Resource
|
|||
|
||||
public bool ChangeTheme(string theme)
|
||||
{
|
||||
const string defaultTheme = "Dark";
|
||||
const string defaultTheme = Constant.DefaultTheme;
|
||||
|
||||
string path = GetThemePath(theme);
|
||||
try
|
||||
|
|
@ -78,16 +79,15 @@ namespace Flow.Launcher.Core.Resource
|
|||
|
||||
Settings.Theme = theme;
|
||||
|
||||
var dicts = Application.Current.Resources.MergedDictionaries;
|
||||
//always allow re-loading default theme, in case of failure of switching to a new theme from default theme
|
||||
if (_oldTheme != theme || theme == defaultTheme)
|
||||
{
|
||||
dicts.Remove(_oldResource);
|
||||
var newResource = GetResourceDictionary();
|
||||
dicts.Add(newResource);
|
||||
_oldResource = newResource;
|
||||
UpdateResourceDictionary(GetResourceDictionary());
|
||||
_oldTheme = Path.GetFileNameWithoutExtension(_oldResource.Source.AbsolutePath);
|
||||
}
|
||||
|
||||
if (Settings.UseDropShadowEffect)
|
||||
AddDropShadowEffectToCurrentTheme();
|
||||
}
|
||||
catch (DirectoryNotFoundException e)
|
||||
{
|
||||
|
|
@ -112,7 +112,16 @@ namespace Flow.Launcher.Core.Resource
|
|||
return true;
|
||||
}
|
||||
|
||||
public ResourceDictionary GetResourceDictionary()
|
||||
private void UpdateResourceDictionary(ResourceDictionary dictionaryToUpdate)
|
||||
{
|
||||
var dicts = Application.Current.Resources.MergedDictionaries;
|
||||
|
||||
dicts.Remove(_oldResource);
|
||||
dicts.Add(dictionaryToUpdate);
|
||||
_oldResource = dictionaryToUpdate;
|
||||
}
|
||||
|
||||
private ResourceDictionary CurrentThemeResourceDictionary()
|
||||
{
|
||||
var uri = GetThemePath(Settings.Theme);
|
||||
var dict = new ResourceDictionary
|
||||
|
|
@ -120,6 +129,13 @@ namespace Flow.Launcher.Core.Resource
|
|||
Source = new Uri(uri, UriKind.Absolute)
|
||||
};
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
public ResourceDictionary GetResourceDictionary()
|
||||
{
|
||||
var dict = CurrentThemeResourceDictionary();
|
||||
|
||||
Style queryBoxStyle = dict["QueryBoxStyle"] as Style;
|
||||
if (queryBoxStyle != null)
|
||||
{
|
||||
|
|
@ -149,6 +165,7 @@ namespace Flow.Launcher.Core.Resource
|
|||
Setter[] setters = { fontFamily, fontStyle, fontWeight, fontStretch };
|
||||
Array.ForEach(new[] { resultItemStyle, resultSubItemStyle, resultItemSelectedStyle, resultSubItemSelectedStyle }, o => Array.ForEach(setters, p => o.Setters.Add(p)));
|
||||
}
|
||||
|
||||
return dict;
|
||||
}
|
||||
|
||||
|
|
@ -179,6 +196,36 @@ namespace Flow.Launcher.Core.Resource
|
|||
return string.Empty;
|
||||
}
|
||||
|
||||
public void AddDropShadowEffectToCurrentTheme()
|
||||
{
|
||||
var dict = CurrentThemeResourceDictionary();
|
||||
|
||||
var windowBorderStyle = dict["WindowBorderStyle"] as Style;
|
||||
|
||||
var effectSetter = new Setter();
|
||||
effectSetter.Property = Border.EffectProperty;
|
||||
effectSetter.Value = new DropShadowEffect
|
||||
{
|
||||
Opacity = 0.9,
|
||||
ShadowDepth = 2,
|
||||
BlurRadius = 15
|
||||
};
|
||||
|
||||
windowBorderStyle.Setters.Add(effectSetter);
|
||||
|
||||
UpdateResourceDictionary(dict);
|
||||
}
|
||||
|
||||
public void RemoveDropShadowEffectToCurrentTheme()
|
||||
{
|
||||
var dict = CurrentThemeResourceDictionary();
|
||||
var windowBorderStyle = dict["WindowBorderStyle"] as Style;
|
||||
|
||||
dict.Remove(Border.EffectProperty);
|
||||
|
||||
UpdateResourceDictionary(dict);
|
||||
}
|
||||
|
||||
#region Blur Handling
|
||||
/*
|
||||
Found on https://github.com/riverar/sample-win10-aeroglass
|
||||
|
|
|
|||
|
|
@ -29,5 +29,7 @@ namespace Flow.Launcher.Infrastructure
|
|||
public static string EverythingSDKPath;
|
||||
|
||||
public static readonly string QueryTextBoxIconImagePath = $"{ProgramDirectory}\\Images\\mainsearch.png";
|
||||
|
||||
public const string DefaultTheme = "Darker";
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,7 +11,8 @@ namespace Flow.Launcher.Infrastructure.UserSettings
|
|||
{
|
||||
public string Hotkey { get; set; } = "Alt + Space";
|
||||
public string Language { get; set; } = "en";
|
||||
public string Theme { get; set; } = "Dark";
|
||||
public string Theme { get; set; } = Constant.DefaultTheme;
|
||||
public bool UseDropShadowEffect { get; set; } = false;
|
||||
public string QueryBoxFont { get; set; } = FontFamily.GenericSansSerif.Name;
|
||||
public string QueryBoxFontStyle { get; set; }
|
||||
public string QueryBoxFontWeight { get; set; }
|
||||
|
|
|
|||
|
|
@ -61,9 +61,6 @@
|
|||
</Window.InputBindings>
|
||||
<Grid Width="750">
|
||||
<Border Style="{DynamicResource WindowBorderStyle}" MouseDown="OnMouseDown" CornerRadius="5" >
|
||||
<Border.Effect>
|
||||
<DropShadowEffect Opacity="0.9" ShadowDepth="2" BlurRadius="15" />
|
||||
</Border.Effect>
|
||||
<StackPanel Orientation="Vertical">
|
||||
<Grid>
|
||||
<TextBox x:Name="QueryTextSuggestionBox"
|
||||
|
|
|
|||
|
|
@ -216,10 +216,28 @@
|
|||
</DockPanel>
|
||||
<Grid Margin="0" Grid.Column="1">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="160"/>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="100" />
|
||||
</Grid.RowDefinitions>
|
||||
<StackPanel Background="{Binding PreviewBackground}" Grid.Row="0" Margin="0">
|
||||
<StackPanel Grid.Row="0">
|
||||
<Grid>
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition />
|
||||
<RowDefinition Height="20"/>
|
||||
<RowDefinition Height="30"/>
|
||||
</Grid.RowDefinitions>
|
||||
<TextBlock Grid.Row="0" Text="Query window shadow effect" Margin="20 20 0 0" FontSize="14" />
|
||||
<ui:ToggleSwitch Grid.Row="0" IsOn="{Binding DropShadowEffect}" Margin="250 15 0 0" Width="80"/>
|
||||
<TextBlock Grid.Row="1" Text="Shadow effect has a substantial usage of GPU."
|
||||
Width="280"
|
||||
Margin="20 0 0 0" FontSize="12" HorizontalAlignment="Left"/>
|
||||
<TextBlock Grid.Row="2" Text="Not recommended if you computer performance is limited"
|
||||
Width="320"
|
||||
Margin="20 0 0 0" FontSize="12" HorizontalAlignment="Left"/>
|
||||
</Grid>
|
||||
</StackPanel>
|
||||
<StackPanel Background="{Binding PreviewBackground}" Grid.Row="1" Margin="0">
|
||||
<StackPanel Orientation="Horizontal" Margin="10"
|
||||
HorizontalAlignment="Center" VerticalAlignment="Center">
|
||||
<Border Width="500" Style="{DynamicResource WindowBorderStyle}" CornerRadius="5">
|
||||
|
|
@ -240,7 +258,7 @@
|
|||
</StackPanel>
|
||||
</StackPanel>
|
||||
|
||||
<StackPanel Grid.Row="1" Margin="0 10 0 10" Orientation="Vertical">
|
||||
<StackPanel Grid.Row="2" Margin="0 10 0 10" Orientation="Vertical">
|
||||
<StackPanel Orientation="Horizontal" Margin="2">
|
||||
<TextBlock Text="{DynamicResource queryBoxFont}" FontSize="14" Margin="0 6 0 0" />
|
||||
<ComboBox ItemsSource="{Binding Source={StaticResource SortedFonts}}"
|
||||
|
|
|
|||
|
|
@ -268,6 +268,24 @@ namespace Flow.Launcher.ViewModel
|
|||
public List<string> Themes
|
||||
=> ThemeManager.Instance.LoadAvailableThemes().Select(Path.GetFileNameWithoutExtension).ToList();
|
||||
|
||||
public bool DropShadowEffect
|
||||
{
|
||||
get { return Settings.UseDropShadowEffect; }
|
||||
set
|
||||
{
|
||||
if (value)
|
||||
{
|
||||
ThemeManager.Instance.AddDropShadowEffectToCurrentTheme();
|
||||
}
|
||||
else
|
||||
{
|
||||
ThemeManager.Instance.RemoveDropShadowEffectToCurrentTheme();
|
||||
}
|
||||
|
||||
Settings.UseDropShadowEffect = value;
|
||||
}
|
||||
}
|
||||
|
||||
public Brush PreviewBackground
|
||||
{
|
||||
get
|
||||
|
|
|
|||
Loading…
Reference in a new issue