Skip to content

Commit

Permalink
add BlendEffectBox
Browse files Browse the repository at this point in the history
  • Loading branch information
NaBian committed Feb 24, 2020
1 parent f6da5e1 commit 6530a71
Show file tree
Hide file tree
Showing 17 changed files with 195 additions and 500 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -471,12 +471,6 @@
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\cloud.png">
<Link>Resources\Img\cloud.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\f.png">
<Link>Resources\Img\f.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\b.png">
<Link>Resources\Img\b.png</Link>
</Resource>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="..\..\Shared\HandyControlDemo_Shared\Properties\Langs\Lang.en.resx">
Expand Down
3 changes: 0 additions & 3 deletions src/Core_30/HandyControl_Core_30/HandyControl_Core_30.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@
<Resource Include="..\..\Shared\HandyControl_Shared\Resources\Effects\GrayScaleEffect.ps">
<Link>Resources\Effects\GrayScaleEffect.ps</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControl_Shared\Resources\Effects\MultiplyBlendEffect.ps">
<Link>Resources\Effects\MultiplyBlendEffect.ps</Link>
</Resource>
</ItemGroup>
<ItemGroup>
<Resource Include="..\..\Shared\HandyControl_Shared\Resources\Images\GlowWindow\bottom.png">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -547,12 +547,6 @@
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\cloud.png">
<Link>Resources\Img\cloud.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\f.png">
<Link>Resources\Img\f.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\b.png">
<Link>Resources\Img\b.png</Link>
</Resource>
</ItemGroup>
<ItemGroup>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Data\DemoInfo.json">
Expand Down
3 changes: 0 additions & 3 deletions src/Net_40/HandyControl_Net_40/HandyControl_Net_40.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -128,9 +128,6 @@
<Resource Include="..\..\Shared\HandyControl_Shared\Resources\Effects\GrayScaleEffect.ps">
<Link>Resources\Effects\GrayScaleEffect.ps</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControl_Shared\Resources\Effects\MultiplyBlendEffect.ps">
<Link>Resources\Effects\MultiplyBlendEffect.ps</Link>
</Resource>
</ItemGroup>
<ItemGroup>
<Resource Include="..\..\Shared\HandyControl_Shared\Resources\Images\GlowWindow\bottom.png">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -610,12 +610,6 @@
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\cloud.png">
<Link>Resources\Img\cloud.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\f.png">
<Link>Resources\Img\f.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\b.png">
<Link>Resources\Img\b.png</Link>
</Resource>
</ItemGroup>
<ItemGroup>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\fabric-icons.ttf">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,6 @@
<Resource Include="..\..\Shared\HandyControl_Shared\Resources\Effects\GrayScaleEffect.ps">
<Link>Resources\Effects\GrayScaleEffect.ps</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControl_Shared\Resources\Effects\MultiplyBlendEffect.ps">
<Link>Resources\Effects\MultiplyBlendEffect.ps</Link>
</Resource>
</ItemGroup>
<ItemGroup>
<Resource Include="..\..\Shared\HandyControl_Shared\Resources\Images\GlowWindow\bottom.png">
Expand Down
Binary file not shown.
Binary file not shown.
422 changes: 59 additions & 363 deletions src/Shared/HandyControlDemo_Shared/UserControl/Tools/EffectsDemoCtl.xaml

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions src/Shared/HandyControl_Shared/HandyControl_Shared.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Media\Animation\LinearGeometryKeyFrame.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Media\Animation\ResolvedKeyFrameEntry.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Media\Animation\SplineGeometryKeyFrame.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Media\Effects\BlendEffect.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Media\Effects\BlendEffectMode.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Media\Effects\BlendEffectBox.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Media\Effects\BrightnessEffect.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Media\Effects\ColorComplementEffect.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Media\Effects\ColorMatrixEffect.cs" />
Expand Down Expand Up @@ -404,6 +403,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\BlendEffectBox.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\Base\FrameBaseStyle.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
Expand Down
61 changes: 0 additions & 61 deletions src/Shared/HandyControl_Shared/Media/Effects/BlendEffect.cs

This file was deleted.

116 changes: 116 additions & 0 deletions src/Shared/HandyControl_Shared/Media/Effects/BlendEffectBox.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Markup;
using System.Windows.Media.Effects;

namespace HandyControl.Media.Effects
{
[DefaultProperty("Content")]
[ContentProperty("Content")]
public class BlendEffectBox : Control
{
private readonly ContentPresenter _effectBottomPresenter;

private readonly ContentPresenter _effectTopPresenter;

private bool _isInternalAction;

public BlendEffectBox()
{
_effectTopPresenter = new ContentPresenter();
ActualContent = _effectTopPresenter;

_effectBottomPresenter = new ContentPresenter();
_effectBottomPresenter.SetBinding(ContentPresenter.ContentProperty, new Binding(ContentProperty.Name)
{
Source = this
});

var effects = new ObservableCollection<Effect>();
effects.CollectionChanged += OnEffectsChanged;
Effects = effects;
}

private void OnEffectsChanged(object sender, NotifyCollectionChangedEventArgs e)
{
if (Effects == null || Effects.Count == 0)
{
ClearEffect(_effectTopPresenter);
return;
}

if (_isInternalAction) return;

_isInternalAction = true;
AddEffect(_effectTopPresenter, Effects.Count);
_isInternalAction = false;
}

private void ClearEffect(ContentPresenter presenter)
{
if (presenter == null) return;

if (ReferenceEquals(_effectBottomPresenter, presenter))
{
_effectBottomPresenter.SetCurrentValue(EffectProperty, null);
return;
}

presenter.SetCurrentValue(EffectProperty, null);
ClearEffect(presenter.Content as ContentPresenter);
}

private void AddEffect(ContentPresenter presenter, int count)
{
var newCount = --count;

if (newCount >= 0)
{
presenter.Effect = Effects[newCount];

var nextCount = --count;
if (nextCount >= 1)
{
var content = new ContentPresenter();
presenter.Content = content;
AddEffect(content, newCount);
}
else if (nextCount >= 0)
{
_effectBottomPresenter.Effect = Effects[0];
presenter.Content = _effectBottomPresenter;
}
else
{
presenter.Content = _effectBottomPresenter;
}
}
}

[DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
[Bindable(true)]
public Collection<Effect> Effects { get; }

public static readonly DependencyProperty ContentProperty = DependencyProperty.Register(
"Content", typeof(FrameworkElement), typeof(BlendEffectBox), new PropertyMetadata(default(FrameworkElement)));

public FrameworkElement Content
{
get => (FrameworkElement)GetValue(ContentProperty);
set => SetValue(ContentProperty, value);
}

internal static readonly DependencyProperty ActualContentProperty = DependencyProperty.Register(
"ActualContent", typeof(FrameworkElement), typeof(BlendEffectBox), new PropertyMetadata(default(FrameworkElement)));

internal FrameworkElement ActualContent
{
get => (FrameworkElement) GetValue(ActualContentProperty);
set => SetValue(ActualContentProperty, value);
}
}
}
32 changes: 0 additions & 32 deletions src/Shared/HandyControl_Shared/Media/Effects/BlendEffectMode.cs

This file was deleted.

This file was deleted.

Binary file not shown.
14 changes: 14 additions & 0 deletions src/Shared/HandyControl_Shared/Themes/Styles/BlendEffectBox.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:effects="clr-namespace:HandyControl.Media.Effects">

<Style TargetType="effects:BlendEffectBox">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="effects:BlendEffectBox">
<ContentPresenter ContentSource="ActualContent"/>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>

</ResourceDictionary>
1 change: 1 addition & 0 deletions src/Shared/HandyControl_Shared/Themes/Styles/Style.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@
<ResourceDictionary Source="FlowDocument.xaml"/>
<ResourceDictionary Source="NavigationWindow.xaml"/>
<ResourceDictionary Source="Frame.xaml"/>
<ResourceDictionary Source="BlendEffectBox.xaml"/>
</ResourceDictionary.MergedDictionaries>

</ResourceDictionary>

0 comments on commit 6530a71

Please sign in to comment.