-
Notifications
You must be signed in to change notification settings - Fork 132
Ported source code for CommunityToolkit.WinUI.Media #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
f5d45f8
Initial port of CommunityToolkit.WinUI.Media to 8.x
Arlodotexe 5644222
Unport Geometry
Arlodotexe 47c8133
Add missing file header
Arlodotexe b3fc0d2
Updated tooling submodule, suppress CS0067
Arlodotexe e44bb87
Removed RadialGradientBrush
Arlodotexe a58f504
Update submodule, testing hotfixes
Arlodotexe a1951df
Update tooling to latest main
Arlodotexe d6c2e59
Fixed null handling
Arlodotexe 2f0e269
Fixed version number
Arlodotexe 17144e0
Merge branch 'main' into port/media
Arlodotexe a57afe4
Use parameter validation for FontIconExtension
Arlodotexe c5674ac
Add ThrowIfNull polyfill to extensions
Arlodotexe 3f6e003
Move internal ArgumentNullExceptionExtensions from Animations to Exte…
Arlodotexe 9fa6b93
Merge branch 'main' into port/media
Arlodotexe f19bda7
Expose internals to CommunityToolkit.WinUI.Media
Arlodotexe File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
components/Extensions/src/ArgumentNullExceptionExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.Runtime.CompilerServices; | ||
|
|
||
| namespace System; | ||
|
|
||
| /// <summary> | ||
| /// Throw helper extensions for <see cref="ArgumentNullException"/>. | ||
| /// </summary> | ||
| internal static class ArgumentNullExceptionExtensions | ||
| { | ||
| /// <summary> | ||
| /// Throws an <see cref="ArgumentNullException"/> for a given parameter name. | ||
| /// </summary> | ||
| /// <param name="_">Dummy value to invoke the extension upon (always pass <see langword="null"/>.</param> | ||
| /// <param name="parameterName">The name of the parameter to report in the exception.</param> | ||
| /// <exception cref="ArgumentNullException">Thrown with <paramref name="parameterName"/>.</exception> | ||
| [DoesNotReturn] | ||
| public static void Throw(this ArgumentNullException? _, string? parameterName) | ||
| { | ||
| throw new ArgumentNullException(parameterName); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Throws an <see cref="ArgumentNullException"/> if <paramref name="argument"/> is <see langword="null"/>. | ||
| /// </summary> | ||
| /// <param name="_">Dummy value to invoke the extension upon (always pass <see langword="null"/>.</param> | ||
| /// <param name="argument">The reference type argument to validate as non-<see langword="null"/>.</param> | ||
| /// <param name="parameterName">The name of the parameter with which <paramref name="argument"/> corresponds.</param> | ||
| /// <exception cref="ArgumentNullException">Thrown if <paramref name="argument"/> is <see langword="null"/>.</exception> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static void ThrowIfNull(this ArgumentNullException? _, [NotNull] object? argument, [CallerArgumentExpression(nameof(argument))] string? parameterName = null) | ||
| { | ||
| if (argument is null) | ||
| { | ||
| Throw(parameterName); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Throws an <see cref="ArgumentNullException"/> if <paramref name="argument"/> is <see langword="null"/>. | ||
| /// </summary> | ||
| /// <param name="_">Dummy value to invoke the extension upon (always pass <see langword="null"/>.</param> | ||
| /// <param name="argument">The pointer argument to validate as non-<see langword="null"/>.</param> | ||
| /// <param name="parameterName">The name of the parameter with which <paramref name="argument"/> corresponds.</param> | ||
| /// <exception cref="ArgumentNullException">Thrown if <paramref name="argument"/> is <see langword="null"/>.</exception> | ||
| [MethodImpl(MethodImplOptions.AggressiveInlining)] | ||
| public static unsafe void ThrowIfNull(this ArgumentNullException? _, [NotNull] void* argument, [CallerArgumentExpression(nameof(argument))] string? parameterName = null) | ||
| { | ||
| if (argument is null) | ||
| { | ||
| Throw(parameterName); | ||
| } | ||
| } | ||
|
|
||
| /// <inheritdoc cref="Throw(ArgumentNullException?, string?)"/> | ||
| [DoesNotReturn] | ||
| private static void Throw(string? parameterName) | ||
| { | ||
| throw new ArgumentNullException(parameterName); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| @ECHO OFF | ||
|
|
||
| powershell ..\..\tooling\ProjectHeads\GenerateSingleSampleHeads.ps1 -componentPath %CD% %* |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| <!-- | ||
| WinUI 2 under UWP uses TargetFramework uap10.0.* | ||
| WinUI 3 under WinAppSdk uses TargetFramework net6.0-windows10.* | ||
| However, under Uno-powered platforms, both WinUI 2 and 3 can share the same TargetFramework. | ||
|
|
||
| MSBuild doesn't play nicely with this out of the box, so we've made it easy for you. | ||
|
|
||
| For .NET Standard packages, you can use the Nuget Package Manager in Visual Studio. | ||
| For UWP / WinAppSDK / Uno packages, place the package references here. | ||
| --> | ||
| <Project> | ||
| <!-- WinUI 2 / UWP --> | ||
| <ItemGroup Condition="'$(IsUwp)' == 'true'"> | ||
| <!-- <PackageReference Include="Microsoft.Toolkit.Uwp.UI.Controls.Primitives" Version="7.1.2"/> --> | ||
| </ItemGroup> | ||
|
|
||
| <!-- WinUI 2 / Uno --> | ||
| <ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '2'"> | ||
| <!-- <PackageReference Include="Uno.Microsoft.Toolkit.Uwp.UI.Controls.Primitives" Version="7.1.11"/> --> | ||
| </ItemGroup> | ||
|
|
||
| <!-- WinUI 3 / WinAppSdk --> | ||
| <ItemGroup Condition="'$(IsWinAppSdk)' == 'true'"> | ||
| <!-- <PackageReference Include="CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.2"/> --> | ||
| </ItemGroup> | ||
|
|
||
| <!-- WinUI 3 / Uno --> | ||
| <ItemGroup Condition="'$(IsUno)' == 'true' AND '$(WinUIMajorVersion)' == '3'"> | ||
| <!-- <PackageReference Include="Uno.CommunityToolkit.WinUI.UI.Controls.Primitives" Version="7.1.100-dev.15.g12261e2626"/> --> | ||
| </ItemGroup> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| <Project Sdk="MSBuild.Sdk.Extras/3.0.23"> | ||
| <PropertyGroup> | ||
| <ToolkitComponentName>Media</ToolkitComponentName> | ||
| </PropertyGroup> | ||
|
|
||
| <!-- Sets this up as a toolkit component's sample project --> | ||
| <Import Project="$(ToolingDirectory)\ToolkitComponent.SampleProject.props" /> | ||
| </Project> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using System.Runtime.CompilerServices; | ||
|
|
||
| // These `InternalsVisibleTo` calls are intended to make it easier for | ||
| // for any internal code to be testable in all the different test projects | ||
| // used with the Labs infrastructure. | ||
| [assembly: InternalsVisibleTo("Media.Tests.Uwp")] | ||
| [assembly: InternalsVisibleTo("Media.Tests.WinAppSdk")] | ||
| [assembly: InternalsVisibleTo("CommunityToolkit.Tests.Uwp")] | ||
| [assembly: InternalsVisibleTo("CommunityToolkit.Tests.WinAppSdk")] |
82 changes: 82 additions & 0 deletions
82
components/Media/src/Animations/Abstract/EffectAnimation{TEffect,TValue,TKeyFrame}.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using CommunityToolkit.WinUI.Media; | ||
| using static CommunityToolkit.WinUI.Animations.AnimationExtensions; | ||
|
|
||
| #if WINUI2 | ||
| using Windows.UI.Composition; | ||
| #elif WINUI3 | ||
| using Microsoft.UI.Composition; | ||
| #endif | ||
|
|
||
| namespace CommunityToolkit.WinUI.Animations; | ||
|
|
||
| /// <summary> | ||
| /// A custom animation targeting a property on an <see cref="IPipelineEffect"/> instance. | ||
| /// </summary> | ||
| /// <typeparam name="TEffect">The type of effect to animate.</typeparam> | ||
| /// <typeparam name="TValue"> | ||
| /// The type to use for the public <see cref="Animation{TValue,TKeyFrame}.To"/> and <see cref="Animation{TValue,TKeyFrame}.From"/> | ||
| /// properties. This can differ from <typeparamref name="TKeyFrame"/> to facilitate XAML parsing. | ||
| /// </typeparam> | ||
| /// <typeparam name="TKeyFrame">The actual type of keyframe values in use.</typeparam> | ||
| public abstract class EffectAnimation<TEffect, TValue, TKeyFrame> : Animation<TValue, TKeyFrame> | ||
| where TEffect : class, IPipelineEffect | ||
| where TKeyFrame : unmanaged | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the linked <typeparamref name="TEffect"/> instance to animate. | ||
| /// </summary> | ||
| public TEffect? Target | ||
| { | ||
| get => (TEffect?)GetValue(TargetProperty); | ||
| set => SetValue(TargetProperty, value); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Identifies the <seealso cref="Target"/> dependency property. | ||
| /// </summary> | ||
| public static readonly DependencyProperty TargetProperty = DependencyProperty.Register( | ||
| nameof(Target), | ||
| typeof(TEffect), | ||
| typeof(EffectAnimation<TEffect, TValue, TKeyFrame>), | ||
| new PropertyMetadata(null)); | ||
|
|
||
| /// <inheritdoc/> | ||
| public override AnimationBuilder AppendToBuilder(AnimationBuilder builder, TimeSpan? delayHint, TimeSpan? durationHint, EasingType? easingTypeHint, EasingMode? easingModeHint) | ||
| { | ||
| if (Target is not TEffect target) | ||
| { | ||
| static AnimationBuilder ThrowArgumentNullException() => throw new ArgumentNullException("The target effect is null, make sure to set the Target property"); | ||
|
|
||
| return ThrowArgumentNullException(); | ||
| } | ||
|
|
||
| if (ExplicitTarget is not string explicitTarget) | ||
| { | ||
| static AnimationBuilder ThrowArgumentNullException() | ||
| { | ||
| throw new ArgumentNullException( | ||
| "The target effect cannot be animated at this time. If you're targeting one of the " + | ||
| "built-in effects, make sure that the PipelineEffect.IsAnimatable property is set to true."); | ||
| } | ||
|
|
||
| return ThrowArgumentNullException(); | ||
| } | ||
|
|
||
| NormalizedKeyFrameAnimationBuilder<TKeyFrame>.Composition keyFrameBuilder = new( | ||
| explicitTarget, | ||
| Delay ?? delayHint ?? DefaultDelay, | ||
| Duration ?? durationHint ?? DefaultDuration, | ||
| Repeat, | ||
| DelayBehavior); | ||
|
|
||
| AppendToBuilder(keyFrameBuilder, easingTypeHint, easingModeHint); | ||
|
|
||
| CompositionAnimation animation = keyFrameBuilder.GetAnimation(target.Brush!, out _); | ||
|
|
||
| return builder.ExternalAnimation(target.Brush!, animation); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using CommunityToolkit.WinUI.Media; | ||
|
|
||
| namespace CommunityToolkit.WinUI.Animations; | ||
|
|
||
| /// <summary> | ||
| /// An effect animation that targets <see cref="BlurEffect.Amount"/>. | ||
| /// </summary> | ||
| public sealed class BlurEffectAnimation : EffectAnimation<BlurEffect, double?, double> | ||
| { | ||
| /// <inheritdoc/> | ||
| protected override string? ExplicitTarget => Target?.Id; | ||
|
|
||
| /// <inheritdoc/> | ||
| protected override (double?, double?) GetParsedValues() | ||
| { | ||
| return (To, From); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using CommunityToolkit.WinUI.Media; | ||
| using Windows.UI; | ||
|
|
||
| namespace CommunityToolkit.WinUI.Animations; | ||
|
|
||
| /// <summary> | ||
| /// An effect animation that targets <see cref="TintEffect.Color"/>. | ||
| /// </summary> | ||
| public sealed class ColorEffectAnimation : EffectAnimation<TintEffect, Color?, Color> | ||
| { | ||
| /// <inheritdoc/> | ||
| protected override string? ExplicitTarget => Target?.Id; | ||
|
|
||
| /// <inheritdoc/> | ||
| protected override (Color?, Color?) GetParsedValues() | ||
| { | ||
| return (To, From); | ||
| } | ||
| } |
22 changes: 22 additions & 0 deletions
22
components/Media/src/Animations/CrossFadeEffectAnimation.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| // Licensed to the .NET Foundation under one or more agreements. | ||
| // The .NET Foundation licenses this file to you under the MIT license. | ||
| // See the LICENSE file in the project root for more information. | ||
|
|
||
| using CommunityToolkit.WinUI.Media; | ||
|
|
||
| namespace CommunityToolkit.WinUI.Animations; | ||
|
|
||
| /// <summary> | ||
| /// An effect animation that targets <see cref="CrossFadeEffect.Factor"/>. | ||
| /// </summary> | ||
| public sealed class CrossFadeEffectAnimation : EffectAnimation<CrossFadeEffect, double?, double> | ||
| { | ||
| /// <inheritdoc/> | ||
| protected override string? ExplicitTarget => Target?.Id; | ||
|
|
||
| /// <inheritdoc/> | ||
| protected override (double?, double?) GetParsedValues() | ||
| { | ||
| return (To, From); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.