Skip to content

Commit

Permalink
Apply ThemedImageEffect to Window
Browse files Browse the repository at this point in the history
  • Loading branch information
diluculo committed May 23, 2018
1 parent 0c38470 commit 01e1066
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 4 deletions.
44 changes: 44 additions & 0 deletions src/Gemini/Framework/ShaderEffects/Converters/IsNullConverter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;

namespace Gemini.Framework.ShaderEffects.Converters
{
// From https://github.com/MahApps/MahApps.Metro/blob/9c331aa20b2b3fd6a9426e0687cfc535511bf134/MahApps.Metro/Converters/IsNullConverter.cs

/// <summary>
/// Converts the value from true to false and false to true.
/// </summary>
public sealed class IsNullConverter : IValueConverter
{
private static IsNullConverter _instance;

// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static IsNullConverter()
{
}

private IsNullConverter()
{
}

public static IsNullConverter Instance
{
get { return _instance ?? (_instance = new IsNullConverter()); }
}

public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return null == value;
}

public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
{
return Binding.DoNothing;
}
}
}
6 changes: 3 additions & 3 deletions src/Gemini/Gemini.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
Expand Down Expand Up @@ -149,6 +149,7 @@
<Compile Include="Framework\Services\IMainWindow.cs" />
<Compile Include="Framework\Services\SettingsPropertyChangedEventManager.cs" />
<Compile Include="Framework\ShaderEffects\Converters\BindingProxy.cs" />
<Compile Include="Framework\ShaderEffects\Converters\IsNullConverter.cs" />
<Compile Include="Framework\ShaderEffects\Converters\SolidColorBrushToColorConverter.cs" />
<Compile Include="Framework\ShaderEffects\GrayscaleEffect.cs" />
<Compile Include="Framework\ShaderEffects\ShaderEffectBase.cs" />
Expand Down Expand Up @@ -472,7 +473,6 @@
<ItemGroup>
<Resource Include="Resources\Icons\FullScreen.png" />
</ItemGroup>
<ItemGroup />
<ItemGroup>
<None Include="Framework\ShaderEffects\Scripts\ThemedImage.fx" />
</ItemGroup>
Expand All @@ -484,4 +484,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>
24 changes: 23 additions & 1 deletion src/Gemini/Themes/VS2013/Controls/Window.xaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:shaderEffects="clr-namespace:Gemini.Framework.ShaderEffects"
xmlns:converters="clr-namespace:Gemini.Framework.ShaderEffects.Converters"
xmlns:controls="http://metro.mahapps.com/winfx/xaml/controls">

<converters:BindingProxy x:Key="DefaultBackground" Data="{DynamicResource MainWindowCaptionActiveBackground}"/>
<converters:SolidColorBrushToColorConverter x:Key="SolidColorBrushToColorConverter"/>

<Style x:Key="MainWindowStyle"
TargetType="controls:MetroWindow"
BasedOn="{StaticResource {x:Type controls:MetroWindow}}">
Expand All @@ -17,6 +21,24 @@
<Trigger Property="IsActive" Value="False">
<Setter Property="TitleForeground" Value="{DynamicResource MainWindowCaptionInactiveText}" />
</Trigger>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=Icon, Mode=OneWay, Converter={x:Static converters:IsNullConverter.Instance}}" Value="False">
<Setter Property="IconTemplate">
<Setter.Value>
<DataTemplate>
<controls:MultiFrameImage Width="{TemplateBinding Width}"
Height="{TemplateBinding Height}"
RenderOptions.BitmapScalingMode="{Binding IconBitmapScalingMode, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type controls:MetroWindow}}}"
RenderOptions.EdgeMode="{Binding IconEdgeMode, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type controls:MetroWindow}}}"
Source="{TemplateBinding Content}" >
<controls:MultiFrameImage.Effect>
<shaderEffects:ThemedImageEffect Background="{Binding Converter={StaticResource SolidColorBrushToColorConverter}, Mode=OneWay,
Source={StaticResource DefaultBackground}, Path=Data}"/>
</controls:MultiFrameImage.Effect>
</controls:MultiFrameImage>
</DataTemplate>
</Setter.Value>
</Setter>
</DataTrigger>
</Style.Triggers>
</Style>

Expand Down

0 comments on commit 01e1066

Please sign in to comment.