Permalink
Browse files

Merged PR 162552: Bug 9132678:[SampleGallery][Mobile] Blur Playground…

… - Controls on left of

 - Bug 9132678:[SampleGallery][Mobile] Blur Playground - Controls on left of
  • Loading branch information...
krenner committed Jun 16, 2017
1 parent 3321e7a commit 743146035bef2623259df9168cb1beee23e0fd99
View
@@ -226,3 +226,4 @@ AI Files/
*.appxbundle
*.dll
*.exe
@@ -0,0 +1,167 @@
//*********************************************************
//
// Copyright (c) Microsoft. All rights reserved.
// This code is licensed under the MIT License (MIT).
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
//*********************************************************
using CompositionSampleGallery.Shared;
using Microsoft.Graphics.Canvas.Effects;
using SamplesCommon;
using System;
using System.Collections.Generic;
using System.Numerics;
using Windows.UI.Composition;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Hosting;
using Windows.UI.Xaml.Media.Imaging;
namespace CompositionSampleGallery
{
public sealed partial class BlurPlayground : SamplePage
{
private CompositionEffectBrush _brush;
private Compositor _compositor;
public BlurPlayground()
{
_compositor = ElementCompositionPreview.GetElementVisual(this).Compositor;
this.InitializeComponent();
}
public static string StaticSampleName { get { return "Blur Playground"; } }
public override string SampleName { get { return StaticSampleName; } }
public override string SampleDescription { get { return "This is a place to play around with different blur and blend recipes"; } }
private void Page_Loaded(object sender, RoutedEventArgs e)
{
// Populate the BlendEffectMode combobox
IList<ComboBoxItem> blendList = new List<ComboBoxItem>();
foreach (BlendEffectMode type in Enum.GetValues(typeof(BlendEffectMode)))
{
// Exclude unsupported types
if (type != BlendEffectMode.Dissolve &&
type != BlendEffectMode.Saturation &&
type != BlendEffectMode.Color &&
type != BlendEffectMode.Hue &&
type != BlendEffectMode.Luminosity
)
{
ComboBoxItem item = new ComboBoxItem();
item.Tag = type;
item.Content = type.ToString();
blendList.Add(item);
}
}
BlendSelection.ItemsSource = blendList;
BlendSelection.SelectedIndex = 0;
}
private void BlendSelection_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBoxItem item = BlendSelection.SelectedValue as ComboBoxItem;
BlendEffectMode blendmode = (BlendEffectMode)item.Tag;
// Create a chained effect graph using a BlendEffect, blending color and blur
var graphicsEffect = new BlendEffect
{
Mode = blendmode,
Background = new ColorSourceEffect()
{
Name = "Tint",
Color = Tint.Color,
},
Foreground = new GaussianBlurEffect()
{
Name = "Blur",
Source = new CompositionEffectSourceParameter("ImageSource"),
BlurAmount = (float)BlurAmount.Value,
BorderMode = EffectBorderMode.Hard,
}
};
var blurEffectFactory = _compositor.CreateEffectFactory(graphicsEffect,
new[] { "Blur.BlurAmount", "Tint.Color" });
// Create EffectBrush to be painted on CompositionImage Control’s SpriteVisual
_brush = blurEffectFactory.CreateBrush();
_brush.SetSourceParameter("ImageSource", CatImage.SurfaceBrush);
CatImage.Brush = _brush;
//If the animation is running, restart it on the new brush
if (AnimateToggle.IsOn)
{
StartBlurAnimation();
}
}
private void BlurAmount_ValueChanged(object sender, RangeBaseValueChangedEventArgs e)
{
// Get slider value
var blur_amount = (float)e.NewValue;
// Set new BlurAmount
_brush.Properties.InsertScalar("Blur.BlurAmount", blur_amount);
}
private void isEnabled (object sender, RangeBaseValueChangedEventArgs e)
{
_brush.StopAnimation("Blur.BlurAmount");
}
private void ColorChanged(object sender, ColorEventArgs e)
{
if (_brush != null)
{
// Get color value
_brush.Properties.InsertColor("Tint.Color", e.NewColor);
}
}
private void ToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
if (AnimateToggle.IsOn)
{
StartBlurAnimation();
BlurAmount.IsEnabled = false;
}
else
{
_brush.StopAnimation("Blur.BlurAmount");
BlurAmount.IsEnabled = true;
BlurAmount.Value = 0;
_brush.Properties.InsertScalar("Blur.BlurAmount", 0);
}
}
private void StartBlurAnimation()
{
ScalarKeyFrameAnimation blurAnimation = _compositor.CreateScalarKeyFrameAnimation();
blurAnimation.InsertKeyFrame(0.0f, 0.0f);
blurAnimation.InsertKeyFrame(0.5f, 100.0f);
blurAnimation.InsertKeyFrame(1.0f, 0.0f);
blurAnimation.Duration = TimeSpan.FromSeconds(4);
blurAnimation.IterationBehavior = AnimationIterationBehavior.Forever;
_brush.StartAnimation("Blur.BlurAmount", blurAnimation);
}
}
}
@@ -9,60 +9,101 @@
mc:Ignorable="d"
Loaded ="Page_Loaded">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid x:Name ="CatGrid" Background="DimGray">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<StackPanel Orientation="Vertical" HorizontalAlignment="Left" Margin="10">
<ScrollViewer x:Name ="Panel" Grid.Column="0" Grid.Row="0" VerticalScrollMode="Auto" VerticalScrollBarVisibility="Hidden">
<StackPanel>
<Slider
x:Name="BlurAmount"
<Slider x:Name="BlurAmount"
Header="Blur Amount"
ValueChanged="BlurAmount_ValueChanged"
Minimum="0"
Maximum="100"
IsEnabled="True"
Margin="10,10,0,10"/>
<ToggleSwitch x:Name="AnimateToggle"
Header="Animate Effects"
OffContent="Stop"
OnContent="Start"
Toggled="ToggleSwitch_Toggled"
IsEnabled="True"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Margin="10,0,0,10"/>
<ToggleSwitch x:Name="AnimateToggle"
Header="Animate Blur"
OffContent="Stop"
OnContent="Start"
Toggled="ToggleSwitch_Toggled"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Margin="10,0,0,10">
</ToggleSwitch>
<Border Height="Auto" Width="Auto">
<common:ColorMixer
<Border Height="Auto" Width="Auto">
<common:ColorMixer
x:Name="Tint"
ColorChanged="ColorChanged"
Color="{ThemeResource SystemAccentColor}"
Margin="10"/>
</Border>
</Border>
<ComboBox
<ComboBox
x:Name="BlendSelection"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
SelectionChanged="BlendSelection_SelectionChanged"
PlaceholderText="Blend Modes"
Margin="10,15,0,10"/>
Margin="10"/>
</StackPanel>
</ScrollViewer>
</StackPanel>
<Image x:Name="BackgroundImage"
<common:CompositionImage x:Name="CatImage"
Grid.Column="1"
SizeChanged="BackgroundImage_SizeChanged"
Margin="10"/>
Grid.Row="0"
Margin="10"
Source="ms-appx:///Assets/WindowsInsiders/Ninjacat-2.png"/>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup>
<VisualState x:Name="Wide">
<VisualState.StateTriggers>
<common:OrientationTrigger Orientation="Landscape" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="CatGrid.RowDefinitions[1].Height" Value="auto"/>
<Setter Target="CatGrid.RowDefinitions[0].Height" Value="*"/>
<Setter Target="CatGrid.ColumnDefinitions[1].Width" Value="*"/>
<Setter Target="Panel.(Grid.Row)" Value="0"/>
<Setter Target="Panel.(Grid.Column)" Value="0"/>
</VisualState.Setters>
</VisualState>
<VisualState x:Name="Narrow">
<VisualState.StateTriggers>
<common:OrientationTrigger Orientation="Portrait" />
</VisualState.StateTriggers>
<VisualState.Setters>
<Setter Target="CatGrid.RowDefinitions[0].Height" Value="*"/>
<Setter Target="CatGrid.RowDefinitions[1].Height" Value="*"/>
<Setter Target="CatGrid.ColumnDefinitions[1].Width" Value="*"/>
<Setter Target="Panel.(Grid.Row)" Value="1"/>
<Setter Target="Panel.(Grid.Column)" Value="1"/>
</VisualState.Setters>
</VisualState>
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
</local:SamplePage>

0 comments on commit 7431460

Please sign in to comment.