Skip to content

Commit

Permalink
Merge branch 'main' into zt/133-parse-out-markdown
Browse files Browse the repository at this point in the history
  • Loading branch information
nmetulev authored Feb 6, 2025
2 parents 7f6280f + 91fd85c commit 0f3c3e2
Show file tree
Hide file tree
Showing 10 changed files with 156 additions and 22 deletions.
1 change: 0 additions & 1 deletion AIDevGallery/AIDevGallery.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
<PackageReference Include="System.Drawing.Common" />
<PackageReference Include="NAudio.WinMM" />
<PackageReference Include="System.Numerics.Tensors" />
<PackageReference Include="WinUICommunity.Components" />
<PackageReference Include="WinUIEx" />
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>
Expand Down
3 changes: 2 additions & 1 deletion AIDevGallery/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@
<ResourceDictionary Source="/Styles/Card.xaml" />
<ResourceDictionary Source="/Styles/NavigationView.xaml" />
<ResourceDictionary Source="/Styles/SelectorBar.xaml" />
<ResourceDictionary Source="/Controls/CopyButton/CopyButton.xaml" />
<ResourceDictionary Source="/Controls/CopyButton.xaml" />
<ResourceDictionary Source="/Controls/OpacityMask.xaml" />
<ResourceDictionary Source="/Controls/HomePage/Header/HeaderTile/HeaderTile.xaml" />
<ResourceDictionary Source="/Samples/SharedCode/SemanticComboBox.xaml" />
<ResourceDictionary Source="/Samples/SharedCode/SmartPasteForm.xaml" />
Expand Down
File renamed without changes.
File renamed without changes.
33 changes: 15 additions & 18 deletions AIDevGallery/Controls/HomePage/Header/HeaderCarousel.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
xmlns:local="using:AIDevGallery.Controls"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:media="using:CommunityToolkit.WinUI.Media"
xmlns:wuc="using:WinUICommunity"
Loaded="UserControl_Loaded"
Unloaded="UserControl_Unloaded"
mc:Ignorable="d">
Expand Down Expand Up @@ -61,23 +60,21 @@
</ResourceDictionary>
</UserControl.Resources>
<Grid x:Name="RootGrid" CornerRadius="8,0,0,0">
<wuc:OpacityMaskView
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
OpacityMask="{ThemeResource OverlayRadialGradient}">
<Grid>
<local:AnimatedImage
x:Name="BackDropImage"
ImageUrl="ms-appx:///Assets/TileImages/BackgroundBlur.png"
Visibility="Visible">
<media:UIElementExtensions.VisualFactory>
<media:PipelineVisualFactory>
<media:BlurEffect Amount="100.0" />
</media:PipelineVisualFactory>
</media:UIElementExtensions.VisualFactory>
</local:AnimatedImage>
</Grid>
</wuc:OpacityMaskView>
<local:OpacityMaskView HorizontalAlignment="Stretch">
<local:OpacityMaskView.OpacityMask>
<Rectangle Fill="{ThemeResource OverlayRadialGradient}" />
</local:OpacityMaskView.OpacityMask>
<local:AnimatedImage
x:Name="BackDropImage"
ImageUrl="ms-appx:///Assets/TileImages/BackgroundBlur.png"
Visibility="Visible">
<media:UIElementExtensions.VisualFactory>
<media:PipelineVisualFactory>
<media:BlurEffect Amount="100.0" />
</media:PipelineVisualFactory>
</media:UIElementExtensions.VisualFactory>
</local:AnimatedImage>
</local:OpacityMaskView>
<StackPanel
Padding="24"
HorizontalAlignment="Center"
Expand Down
32 changes: 32 additions & 0 deletions AIDevGallery/Controls/OpacityMask.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AIDevGallery.Controls">

<Style BasedOn="{StaticResource DefaultOpacityMaskViewStyle}" TargetType="local:OpacityMaskView" />

<Style x:Key="DefaultOpacityMaskViewStyle" TargetType="local:OpacityMaskView">
<Setter Property="IsTabStop" Value="False" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Top" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="local:OpacityMaskView">
<Grid
x:Name="PART_RootGrid"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Border
x:Name="PART_MaskContainer"
Child="{TemplateBinding OpacityMask}"
IsHitTestVisible="False" />
<ContentPresenter
x:Name="PART_ContentPresenter"
Content="{TemplateBinding Content}"
ContentTemplate="{TemplateBinding ContentTemplate}" />
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
105 changes: 105 additions & 0 deletions AIDevGallery/Controls/OpacityMask.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.

using Microsoft.UI.Composition;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Hosting;
using Microsoft.UI.Xaml.Media;
using System.Numerics;

namespace AIDevGallery.Controls;

/// <summary>
/// A control that applies an opacity mask to its content.
/// </summary>
[TemplatePart(Name = RootGridTemplateName, Type = typeof(Grid))]
[TemplatePart(Name = MaskContainerTemplateName, Type = typeof(Border))]
[TemplatePart(Name = ContentPresenterTemplateName, Type = typeof(ContentPresenter))]
public partial class OpacityMaskView : ContentControl
{
// This is from Windows Community Toolkit Labs: https://github.com/CommunityToolkit/Labs-Windows/pull/491

/// <summary>
/// Identifies the <see cref="OpacityMask"/> property.
/// </summary>
public static readonly DependencyProperty OpacityMaskProperty =
DependencyProperty.Register(nameof(OpacityMask), typeof(UIElement), typeof(OpacityMaskView), new PropertyMetadata(null, OnOpacityMaskChanged));

private const string ContentPresenterTemplateName = "PART_ContentPresenter";
private const string MaskContainerTemplateName = "PART_MaskContainer";
private const string RootGridTemplateName = "PART_RootGrid";

private readonly Compositor _compositor = CompositionTarget.GetCompositorForCurrentThread();
private CompositionBrush? _mask;
private CompositionMaskBrush? _maskBrush;

/// <summary>
/// Initializes a new instance of the <see cref="OpacityMaskView"/> class.
/// Creates a new instance of the <see cref="OpacityMaskView"/> class.
/// </summary>
public OpacityMaskView()
{
DefaultStyleKey = typeof(OpacityMaskView);
}

/// <summary>
/// Gets or sets a <see cref="UIElement"/> as the opacity mask that is applied to alpha-channel masking for the rendered content of the content.
/// </summary>
public UIElement? OpacityMask
{
get => (UIElement?)GetValue(OpacityMaskProperty);
set => SetValue(OpacityMaskProperty, value);
}

/// <inheritdoc />
protected override void OnApplyTemplate()
{
base.OnApplyTemplate();

Grid rootGrid = (Grid)GetTemplateChild(RootGridTemplateName);
ContentPresenter contentPresenter = (ContentPresenter)GetTemplateChild(ContentPresenterTemplateName);
Border maskContainer = (Border)GetTemplateChild(MaskContainerTemplateName);

_maskBrush = _compositor.CreateMaskBrush();
_maskBrush.Source = GetVisualBrush(contentPresenter);
_mask = GetVisualBrush(maskContainer);
_maskBrush.Mask = OpacityMask is null ? null : _mask;

SpriteVisual redirectVisual = _compositor.CreateSpriteVisual();
redirectVisual.RelativeSizeAdjustment = Vector2.One;
redirectVisual.Brush = _maskBrush;
ElementCompositionPreview.SetElementChildVisual(rootGrid, redirectVisual);
}

private static CompositionBrush GetVisualBrush(UIElement element)
{
Visual visual = ElementCompositionPreview.GetElementVisual(element);

Compositor compositor = visual.Compositor;

CompositionVisualSurface visualSurface = compositor.CreateVisualSurface();
visualSurface.SourceVisual = visual;
ExpressionAnimation sourceSizeAnimation = compositor.CreateExpressionAnimation($"{nameof(visual)}.Size");
sourceSizeAnimation.SetReferenceParameter(nameof(visual), visual);
visualSurface.StartAnimation(nameof(visualSurface.SourceSize), sourceSizeAnimation);

CompositionSurfaceBrush brush = compositor.CreateSurfaceBrush(visualSurface);

visual.Opacity = 0;

return brush;
}

private static void OnOpacityMaskChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
OpacityMaskView self = (OpacityMaskView)d;
if (self._maskBrush is not { } maskBrush)
{
return;
}

UIElement? opacityMask = (UIElement?)e.NewValue;
maskBrush.Mask = opacityMask is null ? null : self._mask;
}
}
2 changes: 1 addition & 1 deletion AIDevGallery/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
<TextBlock Style="{StaticResource SettingsSectionHeaderTextBlockStyle}" Text="About" />
<toolkit:SettingsExpander
AutomationProperties.AccessibilityView="Raw"
Description="© 2024. All rights reserved."
Description="© 2025. All rights reserved."
Header="AI Dev Gallery"
HeaderIcon="{ui:BitmapIcon Source=ms-appx:///Assets/AppIcon/Icon.ico}"
IsExpanded="True">
Expand Down
1 change: 1 addition & 0 deletions AIDevGallery/Themes/Generic.xaml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" />
1 change: 0 additions & 1 deletion Directory.Packages.props
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
<PackageVersion Include="Microsoft.Windows.SDK.BuildTools" Version="10.0.26100.1742" />
<PackageVersion Include="Microsoft.Windows.CsWin32" Version="0.3.162" />
<PackageVersion Include="System.Drawing.Common" Version="9.0.1" />
<PackageVersion Include="WinUICommunity.Components" Version="7.1.0" />
<PackageVersion Include="NAudio.WinMM" Version="2.2.1" />
<PackageVersion Include="System.Numerics.Tensors" Version="9.0.1" />
<PackageVersion Include="WinUIEx" Version="2.5.1" />
Expand Down

0 comments on commit 0f3c3e2

Please sign in to comment.