Skip to content

Commit

Permalink
Add WinAppSDK SceneGraph CompositionSamples into WinAppSDK directly (#…
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
jeffstall authored Apr 29, 2024
1 parent 76a4d19 commit 62316b1
Show file tree
Hide file tree
Showing 521 changed files with 43,765 additions and 0 deletions.
21 changes: 21 additions & 0 deletions Samples/SceneGraph/Demos/DepthDemo/DepthDemoApp/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<Application
x:Class="DepthDemo.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:DepthDemo">
<Application.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
<!-- Other merged dictionaries here -->
</ResourceDictionary.MergedDictionaries>
<!-- Other app resources here -->
<Style x:Key="ButtonStyle" TargetType="Button">
<Setter Property="Foreground" Value="#009999"/>
<Setter Property="Background" Value="White"/>
<Setter Property="BorderBrush" Value="#009999"/>
<Setter Property="BorderThickness" Value="2"/>
</Style>
</ResourceDictionary>
</Application.Resources>
</Application>
65 changes: 65 additions & 0 deletions Samples/SceneGraph/Demos/DepthDemo/DepthDemoApp/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
//*********************************************************
//
// 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 Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Controls.Primitives;
using Microsoft.UI.Xaml.Data;
using Microsoft.UI.Xaml.Input;
using Microsoft.UI.Xaml.Media;
using Microsoft.UI.Xaml.Navigation;
using Microsoft.UI.Xaml.Shapes;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.ApplicationModel;
using Windows.ApplicationModel.Activation;
using Windows.Foundation;
using Windows.Foundation.Collections;

// To learn more about WinUI, the WinUI project structure,
// and more about our project templates, see: http://aka.ms/winui-project-info.

namespace DepthDemo
{
/// <summary>
/// Provides application-specific behavior to supplement the default Application class.
/// </summary>
public partial class App : Application
{
/// <summary>
/// Initializes the singleton application object. This is the first line of authored code
/// executed, and as such is the logical equivalent of main() or WinMain().
/// </summary>
public App()
{
this.InitializeComponent();
}

/// <summary>
/// Invoked when the application is launched normally by the end user. Other entry points
/// will be used such as when the application is launched to open a specific file.
/// </summary>
/// <param name="args">Details about the launch request and process.</param>
protected override void OnLaunched(Microsoft.UI.Xaml.LaunchActivatedEventArgs args)
{
m_window = new MainWindow();
m_window.Activate();
}

private Window m_window;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows10.0.19041.0</TargetFramework>
<TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
<RootNamespace>DepthDemo</RootNamespace>
<ApplicationManifest>app.manifest</ApplicationManifest>
<Platforms>x86;x64;arm64</Platforms>
<RuntimeIdentifiers>win-x86;win-x64;win-arm64</RuntimeIdentifiers>
<UseWinUI>true</UseWinUI>
</PropertyGroup>

<ItemGroup>
<Manifest Include="$(ApplicationManifest)" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.WindowsAppSDK" Version="1.5.240404000" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\..\..\ExpressionBuilder\ExpressionBuilder\ExpressionBuilder.csproj" />
</ItemGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
//*********************************************************
//
// 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 Microsoft.UI;
using Microsoft.UI.Composition;
using System;
using System.Numerics;
using Windows.UI;

namespace DepthDemo
{
/// <summary>
/// Configuration for constant values that are consistent across all scenarios
/// </summary>
class ConfigurationConstants
{
public ConfigurationConstants() { }

public static int ZOffsetSpacingIncrement = 20;

public static Color ShadowColor = Colors.DarkSlateGray;

public static TimeSpan FocusAnimationDuration = TimeSpan.FromSeconds(0.5);
public static TimeSpan NavAnimationDuration = TimeSpan.FromSeconds(0.25);

public static float ShadowOpacity = 0.7f;

public static float BlurFocusFloat = 10.0f;
}


public class DepthTreatmentConfigurations
{
private Layer _associatedLayer;

public Vector3 ChildScale { get; set; }

public ShadowTreatment ShadowTreatment { get; set; }

// Focus treatment increase for top layer objects
private float _focusScaleIncreaseFactor;

public DepthTreatmentConfigurations(Layer associatedLayer, Vector3 childScale, float focusScaleIncreaseFactor, ShadowTreatment shadowTreatment = null)
{
_associatedLayer = associatedLayer;
_focusScaleIncreaseFactor = focusScaleIncreaseFactor;
ChildScale = childScale;
ShadowTreatment = shadowTreatment;
}

public CompositionAnimationGroup GetVisualFocusAnimations(Compositor compositor, Layer layer)
{
var oldscale = ChildScale;
var newScale = new Vector3(oldscale.X * _focusScaleIncreaseFactor, oldscale.Y * _focusScaleIncreaseFactor, oldscale.Z);

// Create AnimationGroup
CompositionAnimationGroup animationGroup = compositor.CreateAnimationGroup();

// Scale
Vector3KeyFrameAnimation scaleAnimation = compositor.CreateVector3KeyFrameAnimation();
scaleAnimation.InsertKeyFrame(0.0f, oldscale);
scaleAnimation.InsertKeyFrame(1.0f, newScale);
scaleAnimation.Duration = ConfigurationConstants.FocusAnimationDuration;
scaleAnimation.Target = "Scale";
animationGroup.Add(scaleAnimation);

return animationGroup;
}
}


public class ShadowTreatment
{
public Color ShadowColor { get { return ConfigurationConstants.ShadowColor; } }
public int BlurRadius { get; set; }
public Vector3 Offset { get; set; }

private int _focusShadowBlurRadiusIncreaseAmount;
private int _focusShadowOffsetIncreaseAmount;

public ShadowTreatment(int blurRadius, Vector3 offset, int focusShadowBlurRadiusIncrease,
int focusShadowOffsetIncrease)
{
BlurRadius = blurRadius;
Offset = offset;

_focusShadowBlurRadiusIncreaseAmount = focusShadowBlurRadiusIncrease;
_focusShadowOffsetIncreaseAmount = focusShadowOffsetIncrease;
}

public CompositionAnimationGroup GetShadowFocusAnimations(Compositor compositor, Layer layer)
{
var newShadowBlurRadius = BlurRadius + _focusShadowBlurRadiusIncreaseAmount;
var oldShadowOffset = Offset;
var additionalShadowOffsetAmount = _focusShadowOffsetIncreaseAmount;
var newShadowOffset = new Vector3(oldShadowOffset.X + additionalShadowOffsetAmount, oldShadowOffset.Y +
additionalShadowOffsetAmount, oldShadowOffset.Z + additionalShadowOffsetAmount);


// Create AnimationGroup
CompositionAnimationGroup animationGroup = compositor.CreateAnimationGroup();

// Blur Radius
ScalarKeyFrameAnimation shadowBlurAnimation = compositor.CreateScalarKeyFrameAnimation();
shadowBlurAnimation.InsertKeyFrame(0.0f, BlurRadius);
shadowBlurAnimation.InsertKeyFrame(1.0f, newShadowBlurRadius);
shadowBlurAnimation.Duration = ConfigurationConstants.FocusAnimationDuration;
shadowBlurAnimation.Target = "BlurRadius";
animationGroup.Add(shadowBlurAnimation);

// Offset
Vector3KeyFrameAnimation shadowOffsetAnimation = compositor.CreateVector3KeyFrameAnimation();
shadowOffsetAnimation.InsertKeyFrame(0.0f, Offset);
shadowOffsetAnimation.InsertKeyFrame(1.0f, newShadowOffset);
shadowOffsetAnimation.Duration = ConfigurationConstants.FocusAnimationDuration;
shadowOffsetAnimation.Target = "Offset";
animationGroup.Add(shadowOffsetAnimation);

return animationGroup;
}
}
}
Loading

0 comments on commit 62316b1

Please sign in to comment.