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:
Родитель
e0692c8fbd
Коммит
7ec315f364
|
@ -322,7 +322,8 @@ namespace CompositionSampleGallery
|
|||
_14393, // Anniversary Update (1607)
|
||||
_15063, // Creators Update (1703)
|
||||
_16299, // Fall Creators Update
|
||||
_17134 // Version 1803
|
||||
_17134, // Version 1803
|
||||
_17763 // Version 1810
|
||||
};
|
||||
|
||||
public RuntimeSupportedSDKs()
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
<FileAlignment>512</FileAlignment>
|
||||
<ProjectTypeGuids>{A5A43C5B-DE2A-4C0C-9213-0A381AF9435A};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
|
||||
<PackageCertificateKeyFile>CompositionSampleGallery_TemporaryKey.pfx</PackageCertificateKeyFile>
|
||||
<TargetPlatformVersion>10.0.17134.0</TargetPlatformVersion>
|
||||
<TargetPlatformVersion>10.0.17763.0</TargetPlatformVersion>
|
||||
<TargetPlatformMinVersion>10.0.15063.0</TargetPlatformMinVersion>
|
||||
<AppxAutoIncrementPackageRevision>True</AppxAutoIncrementPackageRevision>
|
||||
<AppxBundle>Always</AppxBundle>
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
//*********************************************************
|
||||
|
||||
using ExpressionBuilder;
|
||||
using System;
|
||||
using System.Numerics;
|
||||
using Windows.Foundation;
|
||||
using Windows.UI.Composition;
|
||||
|
@ -59,9 +60,9 @@ namespace CompositionSampleGallery
|
|||
|
||||
_interactionSource = VisualInteractionSource.Create(_root);
|
||||
_interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;
|
||||
_interactionSource.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadOnly;
|
||||
_tracker.InteractionSources.Add(_interactionSource);
|
||||
_tracker.MaxPosition = new Vector3(0, (float)Root.ActualHeight, 0);
|
||||
SetDefaultInertia();
|
||||
|
||||
//
|
||||
// Use the Tacker's Position (negated) to apply to the Offset of the Image.
|
||||
|
@ -72,19 +73,41 @@ namespace CompositionSampleGallery
|
|||
|
||||
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.SetCondition((BooleanNode)true);
|
||||
modifier.Condition = _compositor.CreateExpressionAnimation("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.
|
||||
var target = ExpressionValues.Target.CreateInteractionTrackerTarget();
|
||||
modifier.SetMotion((-target.Position.Y * springConstant) - (dampingConstant * target.PositionVelocityInPixelsPerSecond.Y));
|
||||
// Set the condition to true (always)
|
||||
modifier.SetCondition((BooleanNode)true);
|
||||
|
||||
_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)
|
||||
{
|
||||
|
@ -156,17 +179,33 @@ namespace CompositionSampleGallery
|
|||
_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)
|
||||
{
|
||||
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).
|
||||
_interactionSource.TryRedirectForManipulation(e.GetCurrentPoint(Root));
|
||||
_tracker.TryUpdatePositionWithAdditionalVelocity(new Vector3(0.0f, 1000.0f, 0.0f));
|
||||
}
|
||||
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)
|
||||
{
|
||||
case 0:
|
||||
ClearInertiaModifiers();
|
||||
SetDefaultInertia();
|
||||
break;
|
||||
|
||||
case 1:
|
||||
|
|
|
@ -241,6 +241,13 @@ namespace CompositionSampleGallery
|
|||
|
||||
_interactionSource = VisualInteractionSource.Create(_backgroundVisual);
|
||||
_interactionSource.PositionYSourceMode = InteractionSourceMode.EnabledWithInertia;
|
||||
|
||||
#if SDKVERSION_17763
|
||||
if (MainPage.RuntimeCapabilities.IsSdkVersionRuntimeSupported(RuntimeSupportedSDKs.SDKVERSION._17763))
|
||||
{
|
||||
_interactionSource.ManipulationRedirectionMode = VisualInteractionSourceRedirectionMode.CapableTouchpadAndPointerWheel;
|
||||
}
|
||||
#endif
|
||||
_tracker.InteractionSources.Add(_interactionSource);
|
||||
|
||||
var trackerNode = _tracker.GetReference();
|
||||
|
@ -372,12 +379,16 @@ namespace CompositionSampleGallery
|
|||
|
||||
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));
|
||||
}
|
||||
|
||||
catch (Exception)
|
||||
{
|
||||
//
|
||||
// Catch to avoid app crash based on unauthorized input.
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
private Compositor _compositor;
|
||||
|
|
|
@ -115,7 +115,7 @@ namespace CompositionSampleGallery.Samples.SDK_14393.SwipeScroller.Behaviors
|
|||
{
|
||||
interactionSource.TryRedirectForManipulation(a.GetCurrentPoint(s as UIElement));
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
catch (Exception)
|
||||
{
|
||||
// Ignoring the failed redirect to prevent app crashing
|
||||
}
|
||||
|
|
|
@ -89,7 +89,12 @@ namespace CompositionSampleGallery
|
|||
_interactionSource = VisualInteractionSource.Create(_rootContainer);
|
||||
_interactionSource.ScaleSourceMode = 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.MinScale = 0.6f;
|
||||
_tracker.MaxScale = 5.0f;
|
||||
|
@ -661,14 +666,15 @@ namespace CompositionSampleGallery
|
|||
}
|
||||
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));
|
||||
|
||||
// Stop ambient animations
|
||||
_tracker.TryUpdatePositionBy(Vector3.Zero);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public void CustomAnimationStateEntered(InteractionTracker sender, InteractionTrackerCustomAnimationStateEnteredArgs args)
|
||||
|
|
|
@ -113,17 +113,14 @@ namespace CompositionSampleGallery
|
|||
|
||||
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));
|
||||
}
|
||||
catch (UnauthorizedAccessException)
|
||||
{
|
||||
// Ignoring the failed redirect to prevent app crashing
|
||||
}
|
||||
// Tell the system to use the gestures from this pointer point (if it can).
|
||||
_interactionSource.TryRedirectForManipulation(e.GetCurrentPoint(null));
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
// Ignoring the failed redirect to prevent app crashing
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,7 @@
|
|||
<DefineConstants Condition="$(TargetPlatformBuild) >=15063">$(DefineConstants);SDKVERSION_15063</DefineConstants>
|
||||
<DefineConstants Condition="$(TargetPlatformBuild) >=16299">$(DefineConstants);SDKVERSION_16299</DefineConstants>
|
||||
<DefineConstants Condition="$(TargetPlatformBuild) >=17134">$(DefineConstants);SDKVERSION_17134</DefineConstants>
|
||||
<DefineConstants Condition="$(TargetPlatformBuild) >=17763">$(DefineConstants);SDKVERSION_17763</DefineConstants>
|
||||
|
||||
</PropertyGroup>
|
||||
</Project>
|
||||
|
|
Загрузка…
Ссылка в новой задаче