Interactiontracker sample updates (#308)

* Updating InteractionTracker Samples & adding SDK 17763

Making incremental updates to samples using InteractionTracker.
-Add mousewheel & pen functionality to PullToAnimate
-Add pen and mouse click functionality to Curtain
-Update Curtain to use NaturalMotion InertiaModifiers
-Add pen & mousewheel support to Interactions3D
-Fix bugs resulting from failed TryRedirect* calls
-Add runtime & compile-time checks for version-dependent features
This commit is contained in:
Lindsay Kubasik 2018-12-04 13:00:21 -08:00 коммит произвёл GitHub
Родитель e0692c8fbd
Коммит 7ec315f364
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
8 изменённых файлов: 92 добавлений и 37 удалений

Просмотреть файл

@ -322,7 +322,8 @@ namespace CompositionSampleGallery
_14393, // Anniversary Update (1607) _14393, // Anniversary Update (1607)
_15063, // Creators Update (1703) _15063, // Creators Update (1703)
_16299, // Fall Creators Update _16299, // Fall Creators Update
_17134 // Version 1803 _17134, // Version 1803
_17763 // Version 1810
}; };
public RuntimeSupportedSDKs() public RuntimeSupportedSDKs()

Просмотреть файл

@ -15,7 +15,7 @@
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids> <ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<PackageCertificateKeyFile>CompositionSampleGallery_TemporaryKey.pfx</PackageCertificateKeyFile> <PackageCertificateKeyFile>CompositionSampleGallery_TemporaryKey.pfx</PackageCertificateKeyFile>
<TargetPlatformVersion>10.0.17134.0</TargetPlatformVersion> <TargetPlatformVersion>10.0.17763.0</TargetPlatformVersion>
<TargetPlatformMinVersion>10.0.15063.0</TargetPlatformMinVersion> <TargetPlatformMinVersion>10.0.15063.0</TargetPlatformMinVersion>
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision> <AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
<AppxBundle>Always</AppxBundle> <AppxBundle>Always</AppxBundle>

Просмотреть файл

@ -13,6 +13,7 @@
//********************************************************* //*********************************************************
using ExpressionBuilder; using ExpressionBuilder;
using System;
using System.Numerics; using System.Numerics;
using Windows.Foundation; using Windows.Foundation;
using Windows.UI.Composition; using Windows.UI.Composition;
@ -59,9 +60,9 @@ namespace CompositionSampleGallery
_interactionSource = VisualInteractionSource.Create(_root); _interactionSource = VisualInteractionSource.Create(_root);
_interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; _interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;
_interactionSource.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadOnly;
_tracker.InteractionSources.Add(_interactionSource); _tracker.InteractionSources.Add(_interactionSource);
_tracker.MaxPosition = new Vector3(0, (float)Root.ActualHeight, 0); _tracker.MaxPosition = new Vector3(0, (float)Root.ActualHeight, 0);
SetDefaultInertia();
// //
// Use the Tacker's Position (negated) to apply to the Offset of the Image. // Use the Tacker's Position (negated) to apply to the Offset of the Image.
@ -72,19 +73,41 @@ namespace CompositionSampleGallery
private void ActivateSpringForce() private void ActivateSpringForce()
{ {
var dampingConstant = 5;
var springConstant = 20;
var modifier = InteractionTrackerInertiaMotion.Create(_compositor); #if SDKVERSION_15063
//
// On newer builds, use the Spring NaturalMotion
//
if (MainPage.RuntimeCapabilities.IsSdkVersionRuntimeSupported(RuntimeSupportedSDKs.SDKVERSION._15063))
{
var modifier = InteractionTrackerInertiaNaturalMotion.Create(_compositor);
var springAnimation = _compositor.CreateSpringScalarAnimation();
springAnimation.Period = TimeSpan.FromSeconds(.15);
springAnimation.DampingRatio = .4f;
springAnimation.FinalValue = 0.0f;
// Set the condition to true (always) modifier.Condition = _compositor.CreateExpressionAnimation("true");
modifier.SetCondition((BooleanNode)true); modifier.NaturalMotion = springAnimation;
_tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { modifier });
}
//
// On older builds, use a custom force that behaves like a spring
//
else
#endif
{
var dampingConstant = 5;
var springConstant = 20;
var modifier = InteractionTrackerInertiaMotion.Create(_compositor);
// Define a spring-like force, anchored at position 0. // Set the condition to true (always)
var target = ExpressionValues.Target.CreateInteractionTrackerTarget(); modifier.SetCondition((BooleanNode)true);
modifier.SetMotion((-target.Position.Y * springConstant) - (dampingConstant * target.PositionVelocityInPixelsPerSecond.Y));
_tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { modifier }); // Define a spring-like force, anchored at position 0.
var target = ExpressionValues.Target.CreateInteractionTrackerTarget();
modifier.SetMotion((-target.Position.Y * springConstant) - (dampingConstant * target.PositionVelocityInPixelsPerSecond.Y));
_tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { modifier });
}
} }
private void Grid_SizeChanged(object sender, SizeChangedEventArgs e) private void Grid_SizeChanged(object sender, SizeChangedEventArgs e)
{ {
@ -156,17 +179,33 @@ namespace CompositionSampleGallery
_tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { modifier }); _tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { modifier });
} }
private void ClearInertiaModifiers() //
// Create a snap point in the "down" position using default inertia
//
private void SetDefaultInertia()
{ {
_tracker.ConfigurePositionYInertiaModifiers(null); var modifier = InteractionTrackerInertiaRestingValue.Create(_compositor);
modifier.RestingValue = _compositor.CreateExpressionAnimation("0");
modifier.Condition = _compositor.CreateExpressionAnimation("true");
_tracker.ConfigurePositionYInertiaModifiers(new InteractionTrackerInertiaModifier[] { modifier });
} }
private void Root_PointerPressed(object sender, PointerRoutedEventArgs e) private void Root_PointerPressed(object sender, PointerRoutedEventArgs e)
{ {
if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch) if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Mouse)
{ {
// Tell the system to use the gestures from this pointer point (if it can). _tracker.TryUpdatePositionWithAdditionalVelocity(new Vector3(0.0f, 1000.0f, 0.0f));
_interactionSource.TryRedirectForManipulation(e.GetCurrentPoint(Root)); }
else
{
try
{
_interactionSource.TryRedirectForManipulation(e.GetCurrentPoint(Root));
}
catch (Exception)
{
//catch to avoid app crash based on unauthorized input
}
} }
} }
@ -177,7 +216,7 @@ namespace CompositionSampleGallery
switch (((ListBox)sender).SelectedIndex) switch (((ListBox)sender).SelectedIndex)
{ {
case 0: case 0:
ClearInertiaModifiers(); SetDefaultInertia();
break; break;
case 1: case 1:

Просмотреть файл

@ -241,6 +241,13 @@ namespace CompositionSampleGallery
_interactionSource = VisualInteractionSource.Create(_backgroundVisual); _interactionSource = VisualInteractionSource.Create(_backgroundVisual);
_interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia; _interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;
#if SDKVERSION_17763
if (MainPage.RuntimeCapabilities.IsSdkVersionRuntimeSupported(RuntimeSupportedSDKs.SDKVERSION._17763))
{
_interactionSource.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadAndPointerWheel;
}
#endif
_tracker.InteractionSources.Add(_interactionSource); _tracker.InteractionSources.Add(_interactionSource);
var trackerNode = _tracker.GetReference(); var trackerNode = _tracker.GetReference();
@ -372,12 +379,16 @@ namespace CompositionSampleGallery
private void Pointer_Pressed(object sender, PointerRoutedEventArgs e) private void Pointer_Pressed(object sender, PointerRoutedEventArgs e)
{ {
if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch) try
{ {
//Capture pointer to system for gestures
_interactionSource.TryRedirectForManipulation(e.GetCurrentPoint(Root)); _interactionSource.TryRedirectForManipulation(e.GetCurrentPoint(Root));
} }
catch (Exception)
{
//
// Catch to avoid app crash based on unauthorized input.
//
}
} }
private Compositor _compositor; private Compositor _compositor;

Просмотреть файл

@ -115,7 +115,7 @@ namespace CompositionSampleGallery.Samples.SDK_14393.SwipeScroller.Behaviors
{ {
interactionSource.TryRedirectForManipulation(a.GetCurrentPoint(s as UIElement)); interactionSource.TryRedirectForManipulation(a.GetCurrentPoint(s as UIElement));
} }
catch (UnauthorizedAccessException) catch (Exception)
{ {
// Ignoring the failed redirect to prevent app crashing // Ignoring the failed redirect to prevent app crashing
} }

Просмотреть файл

@ -89,7 +89,12 @@ namespace CompositionSampleGallery
_interactionSource = VisualInteractionSource.Create(_rootContainer); _interactionSource = VisualInteractionSource.Create(_rootContainer);
_interactionSource.ScaleSourceMode = InteractionSourceMode.EnabledWithInertia; _interactionSource.ScaleSourceMode = InteractionSourceMode.EnabledWithInertia;
_interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia; _interactionSource.PositionXSourceMode = InteractionSourceMode.EnabledWithInertia;
#if SDKVERSION_17763
if (MainPage.RuntimeCapabilities.IsSdkVersionRuntimeSupported(RuntimeSupportedSDKs.SDKVERSION._17763))
{
_interactionSource.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadAndPointerWheel;
}
#endif
_tracker = InteractionTracker.CreateWithOwner(_compositor, this); _tracker = InteractionTracker.CreateWithOwner(_compositor, this);
_tracker.MinScale = 0.6f; _tracker.MinScale = 0.6f;
_tracker.MaxScale = 5.0f; _tracker.MaxScale = 5.0f;
@ -661,14 +666,15 @@ namespace CompositionSampleGallery
} }
private void Root_PointerPressed(object sender, PointerRoutedEventArgs e) private void Root_PointerPressed(object sender, PointerRoutedEventArgs e)
{ {
if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch) try
{ {
// Tell the system to use the gestures from this pointer point (if it can).
_interactionSource.TryRedirectForManipulation(e.GetCurrentPoint(Root)); _interactionSource.TryRedirectForManipulation(e.GetCurrentPoint(Root));
// Stop ambient animations
_tracker.TryUpdatePositionBy(Vector3.Zero); _tracker.TryUpdatePositionBy(Vector3.Zero);
} }
catch (Exception)
{
return;
}
} }
public void CustomAnimationStateEntered(InteractionTracker sender, InteractionTrackerCustomAnimationStateEnteredArgs args) public void CustomAnimationStateEntered(InteractionTracker sender, InteractionTrackerCustomAnimationStateEnteredArgs args)

Просмотреть файл

@ -113,17 +113,14 @@ namespace CompositionSampleGallery
private void Window_PointerPressed(object sender, PointerRoutedEventArgs e) private void Window_PointerPressed(object sender, PointerRoutedEventArgs e)
{ {
if (e.Pointer.PointerDeviceType == Windows.Devices.Input.PointerDeviceType.Touch) try
{ {
try // Tell the system to use the gestures from this pointer point (if it can).
{ _interactionSource.TryRedirectForManipulation(e.GetCurrentPoint(null));
// Tell the system to use the gestures from this pointer point (if it can). }
_interactionSource.TryRedirectForManipulation(e.GetCurrentPoint(null)); catch (Exception)
} {
catch (UnauthorizedAccessException) // Ignoring the failed redirect to prevent app crashing
{
// Ignoring the failed redirect to prevent app crashing
}
} }
} }

Просмотреть файл

@ -13,6 +13,7 @@
<DefineConstants Condition="$(TargetPlatformBuild) &gt;=15063">$(DefineConstants);SDKVERSION_15063</DefineConstants> <DefineConstants Condition="$(TargetPlatformBuild) &gt;=15063">$(DefineConstants);SDKVERSION_15063</DefineConstants>
<DefineConstants Condition="$(TargetPlatformBuild) &gt;=16299">$(DefineConstants);SDKVERSION_16299</DefineConstants> <DefineConstants Condition="$(TargetPlatformBuild) &gt;=16299">$(DefineConstants);SDKVERSION_16299</DefineConstants>
<DefineConstants Condition="$(TargetPlatformBuild) &gt;=17134">$(DefineConstants);SDKVERSION_17134</DefineConstants> <DefineConstants Condition="$(TargetPlatformBuild) &gt;=17134">$(DefineConstants);SDKVERSION_17134</DefineConstants>
<DefineConstants Condition="$(TargetPlatformBuild) &gt;=17763">$(DefineConstants);SDKVERSION_17763</DefineConstants>
</PropertyGroup> </PropertyGroup>
</Project> </Project>