Skip to content

Commit 62316b1

Browse files
authored
Add WinAppSDK SceneGraph CompositionSamples into WinAppSDK directly (#335)
* Port WindowsCompositionSamples into WinAppSDK Moving Microsoft/WindowsCompositionSamples into WindowsAppSDK-Samples * Remove differentiating Platform SDKs The WinAppSDK Scene Graph runs consistently down-level to RS5 (1809) / Server 2019. It does not need to differentiate platform versions. * Fix arm64 build Fix VS config for arm64.
1 parent 76a4d19 commit 62316b1

File tree

521 files changed

+43765
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

521 files changed

+43765
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<Application
2+
x:Class="DepthDemo.App"
3+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
4+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
5+
xmlns:local="using:DepthDemo">
6+
<Application.Resources>
7+
<ResourceDictionary>
8+
<ResourceDictionary.MergedDictionaries>
9+
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
10+
<!-- Other merged dictionaries here -->
11+
</ResourceDictionary.MergedDictionaries>
12+
<!-- Other app resources here -->
13+
<Style x:Key="ButtonStyle" TargetType="Button">
14+
<Setter Property="Foreground" Value="#009999"/>
15+
<Setter Property="Background" Value="White"/>
16+
<Setter Property="BorderBrush" Value="#009999"/>
17+
<Setter Property="BorderThickness" Value="2"/>
18+
</Style>
19+
</ResourceDictionary>
20+
</Application.Resources>
21+
</Application>
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//*********************************************************
2+
//
3+
// Copyright (c) Microsoft. All rights reserved.
4+
// This code is licensed under the MIT License (MIT).
5+
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
6+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
8+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
9+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10+
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
11+
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
//
13+
//*********************************************************
14+
15+
using Microsoft.UI.Xaml;
16+
using Microsoft.UI.Xaml.Controls;
17+
using Microsoft.UI.Xaml.Controls.Primitives;
18+
using Microsoft.UI.Xaml.Data;
19+
using Microsoft.UI.Xaml.Input;
20+
using Microsoft.UI.Xaml.Media;
21+
using Microsoft.UI.Xaml.Navigation;
22+
using Microsoft.UI.Xaml.Shapes;
23+
using System;
24+
using System.Collections.Generic;
25+
using System.IO;
26+
using System.Linq;
27+
using System.Runtime.InteropServices.WindowsRuntime;
28+
using Windows.ApplicationModel;
29+
using Windows.ApplicationModel.Activation;
30+
using Windows.Foundation;
31+
using Windows.Foundation.Collections;
32+
33+
// To learn more about WinUI, the WinUI project structure,
34+
// and more about our project templates, see: http://aka.ms/winui-project-info.
35+
36+
namespace DepthDemo
37+
{
38+
/// <summary>
39+
/// Provides application-specific behavior to supplement the default Application class.
40+
/// </summary>
41+
public partial class App : Application
42+
{
43+
/// <summary>
44+
/// Initializes the singleton application object. This is the first line of authored code
45+
/// executed, and as such is the logical equivalent of main() or WinMain().
46+
/// </summary>
47+
public App()
48+
{
49+
this.InitializeComponent();
50+
}
51+
52+
/// <summary>
53+
/// Invoked when the application is launched normally by the end user. Other entry points
54+
/// will be used such as when the application is launched to open a specific file.
55+
/// </summary>
56+
/// <param name="args">Details about the launch request and process.</param>
57+
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
58+
{
59+
m_window = new MainWindow();
60+
m_window.Activate();
61+
}
62+
63+
private Window m_window;
64+
}
65+
}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<PropertyGroup>
3+
<OutputType>WinExe</OutputType>
4+
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
5+
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
6+
<RootNamespace>DepthDemo</RootNamespace>
7+
<ApplicationManifest>app.manifest</ApplicationManifest>
8+
<Platforms>x86;x64;arm64</Platforms>
9+
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
10+
<UseWinUI>true</UseWinUI>
11+
</PropertyGroup>
12+
13+
<ItemGroup>
14+
<Manifest Include="$(ApplicationManifest)" />
15+
</ItemGroup>
16+
17+
<ItemGroup>
18+
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240404000" />
19+
</ItemGroup>
20+
21+
<ItemGroup>
22+
<ProjectReference Include="..\..\..\ExpressionBuilder\ExpressionBuilder\ExpressionBuilder.csproj" />
23+
</ItemGroup>
24+
</Project>
Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
1+
//*********************************************************
2+
//
3+
// Copyright (c) Microsoft. All rights reserved.
4+
// This code is licensed under the MIT License (MIT).
5+
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
6+
// INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
8+
// IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
9+
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
10+
// TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH
11+
// THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
12+
//
13+
//*********************************************************
14+
15+
using Microsoft.UI;
16+
using Microsoft.UI.Composition;
17+
using System;
18+
using System.Numerics;
19+
using Windows.UI;
20+
21+
namespace DepthDemo
22+
{
23+
/// <summary>
24+
/// Configuration for constant values that are consistent across all scenarios
25+
/// </summary>
26+
class ConfigurationConstants
27+
{
28+
public ConfigurationConstants() { }
29+
30+
public static int ZOffsetSpacingIncrement = 20;
31+
32+
public static Color ShadowColor = Colors.DarkSlateGray;
33+
34+
public static TimeSpan FocusAnimationDuration = TimeSpan.FromSeconds(0.5);
35+
public static TimeSpan NavAnimationDuration = TimeSpan.FromSeconds(0.25);
36+
37+
public static float ShadowOpacity = 0.7f;
38+
39+
public static float BlurFocusFloat = 10.0f;
40+
}
41+
42+
43+
public class DepthTreatmentConfigurations
44+
{
45+
private Layer _associatedLayer;
46+
47+
public Vector3 ChildScale { get; set; }
48+
49+
public ShadowTreatment ShadowTreatment { get; set; }
50+
51+
// Focus treatment increase for top layer objects
52+
private float _focusScaleIncreaseFactor;
53+
54+
public DepthTreatmentConfigurations(Layer associatedLayer, Vector3 childScale, float focusScaleIncreaseFactor, ShadowTreatment shadowTreatment = null)
55+
{
56+
_associatedLayer = associatedLayer;
57+
_focusScaleIncreaseFactor = focusScaleIncreaseFactor;
58+
ChildScale = childScale;
59+
ShadowTreatment = shadowTreatment;
60+
}
61+
62+
public CompositionAnimationGroup GetVisualFocusAnimations(Compositor compositor, Layer layer)
63+
{
64+
var oldscale = ChildScale;
65+
var newScale = new Vector3(oldscale.X * _focusScaleIncreaseFactor, oldscale.Y * _focusScaleIncreaseFactor, oldscale.Z);
66+
67+
// Create AnimationGroup
68+
CompositionAnimationGroup animationGroup = compositor.CreateAnimationGroup();
69+
70+
// Scale
71+
Vector3KeyFrameAnimation scaleAnimation = compositor.CreateVector3KeyFrameAnimation();
72+
scaleAnimation.InsertKeyFrame(0.0f, oldscale);
73+
scaleAnimation.InsertKeyFrame(1.0f, newScale);
74+
scaleAnimation.Duration = ConfigurationConstants.FocusAnimationDuration;
75+
scaleAnimation.Target = "Scale";
76+
animationGroup.Add(scaleAnimation);
77+
78+
return animationGroup;
79+
}
80+
}
81+
82+
83+
public class ShadowTreatment
84+
{
85+
public Color ShadowColor { get { return ConfigurationConstants.ShadowColor; } }
86+
public int BlurRadius { get; set; }
87+
public Vector3 Offset { get; set; }
88+
89+
private int _focusShadowBlurRadiusIncreaseAmount;
90+
private int _focusShadowOffsetIncreaseAmount;
91+
92+
public ShadowTreatment(int blurRadius, Vector3 offset, int focusShadowBlurRadiusIncrease,
93+
int focusShadowOffsetIncrease)
94+
{
95+
BlurRadius = blurRadius;
96+
Offset = offset;
97+
98+
_focusShadowBlurRadiusIncreaseAmount = focusShadowBlurRadiusIncrease;
99+
_focusShadowOffsetIncreaseAmount = focusShadowOffsetIncrease;
100+
}
101+
102+
public CompositionAnimationGroup GetShadowFocusAnimations(Compositor compositor, Layer layer)
103+
{
104+
var newShadowBlurRadius = BlurRadius + _focusShadowBlurRadiusIncreaseAmount;
105+
var oldShadowOffset = Offset;
106+
var additionalShadowOffsetAmount = _focusShadowOffsetIncreaseAmount;
107+
var newShadowOffset = new Vector3(oldShadowOffset.X + additionalShadowOffsetAmount, oldShadowOffset.Y +
108+
additionalShadowOffsetAmount, oldShadowOffset.Z + additionalShadowOffsetAmount);
109+
110+
111+
// Create AnimationGroup
112+
CompositionAnimationGroup animationGroup = compositor.CreateAnimationGroup();
113+
114+
// Blur Radius
115+
ScalarKeyFrameAnimation shadowBlurAnimation = compositor.CreateScalarKeyFrameAnimation();
116+
shadowBlurAnimation.InsertKeyFrame(0.0f, BlurRadius);
117+
shadowBlurAnimation.InsertKeyFrame(1.0f, newShadowBlurRadius);
118+
shadowBlurAnimation.Duration = ConfigurationConstants.FocusAnimationDuration;
119+
shadowBlurAnimation.Target = "BlurRadius";
120+
animationGroup.Add(shadowBlurAnimation);
121+
122+
// Offset
123+
Vector3KeyFrameAnimation shadowOffsetAnimation = compositor.CreateVector3KeyFrameAnimation();
124+
shadowOffsetAnimation.InsertKeyFrame(0.0f, Offset);
125+
shadowOffsetAnimation.InsertKeyFrame(1.0f, newShadowOffset);
126+
shadowOffsetAnimation.Duration = ConfigurationConstants.FocusAnimationDuration;
127+
shadowOffsetAnimation.Target = "Offset";
128+
animationGroup.Add(shadowOffsetAnimation);
129+
130+
return animationGroup;
131+
}
132+
}
133+
}

0 commit comments

Comments
 (0)