Skip to content

Commit a20e824

Browse files
author
msftbot[bot]
authored
Orbitview remove animation expressions (#3627)
<!-- 🚨 Please Do Not skip any instructions and information mentioned below as they are all required and essential to evaluate and test the PR. By fulfilling all the required information you will be able to reduce the volume of questions and most likely help merge the PR faster 🚨 --> <!-- 📝 It is preferred if you keep the "☑️ Allow edits by maintainers" checked in the Pull Request Template as it increases collaboration with the Toolkit maintainers by permitting commits to your PR branch (only) created from your fork. This can let us quickly make fixes for minor typos or forgotten StyleCop issues during review without needing to wait on you doing extra work. Let us help you help us! 🎉 --> <!-- Add a brief overview here of the feature/bug & fix. --> Sept towards #3578. ## PR Type What kind of change does this PR introduce? <!-- Please uncomment one or more that apply to this PR. --> <!-- - Bugfix --> <!-- - Feature --> <!-- - Code style update (formatting) --> - Refactoring (no functional changes, no api changes) <!-- - Build or CI related changes --> <!-- - Documentation content changes --> <!-- - Sample app changes --> <!-- - Other... Please describe: --> ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> OrbitView uses the Toolkit Animation.Expressions API. ## What is the new behavior? <!-- Describe how was this issue resolved or changed? --> OrbitView uses [ExpressionAnimation](https://docs.microsoft.com/en-us/uwp/api/windows.ui.composition.expressionanimation) ## PR Checklist Please check if your PR fulfills the following requirements: - [ ] Tested code with current [supported SDKs](../readme.md#supported) - [ ] Pull Request has been submitted to the documentation repository [instructions](..\contributing.md#docs). Link: <!-- docs PR link --> - [ ] Sample in sample app has been added / updated (for bug fixes / features) - [ ] Icon has been created (if new sample) following the [Thumbnail Style Guide and templates](https://github.com/windows-toolkit/WindowsCommunityToolkit-design-assets) - [ ] Tests for the changes have been added (for bug fixes / features) (if applicable) - [ ] Header has been added to all new source files (run *build/UpdateHeaders.bat*) - [ ] Contains **NO** breaking changes <!-- If this PR contains a breaking change, please describe the impact and migration path for existing applications below. Please note that breaking changes are likely to be rejected within minor release cycles or held until major versions. --> ## Other information
2 parents 3790024 + 0d79906 commit a20e824

File tree

1 file changed

+22
-16
lines changed

1 file changed

+22
-16
lines changed

Microsoft.Toolkit.Uwp.UI.Controls/OrbitView/OrbitView.cs

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
using System.Collections.Generic;
77
using System.Linq;
88
using System.Numerics;
9-
using Microsoft.Toolkit.Uwp.UI.Animations.Expressions;
109
using Windows.UI;
1110
using Windows.UI.Composition;
1211
using Windows.UI.Xaml;
@@ -631,41 +630,48 @@ private Line CreateAnchor(UIElement element, double x, double y)
631630
var anchorVisual = ElementCompositionPreview.GetElementVisual(anchor);
632631
var elementVisual = ElementCompositionPreview.GetElementVisual(element);
633632
var centerVisual = ElementCompositionPreview.GetElementVisual(_centerContent);
634-
var elementNode = elementVisual.GetReference();
635-
var centerNode = centerVisual.GetReference();
636633

637-
ScalarNode expression;
638-
var elementY = elementNode.Offset.Y + (elementNode.Size.Y / 2);
639-
var centerY = centerNode.Offset.Y + (centerNode.Size.Y / 2);
640-
var elementX = elementNode.Offset.X + (elementNode.Size.X / 2);
641-
var centerX = centerNode.Offset.X + (centerNode.Size.X / 2);
634+
string expression = string.Empty;
635+
var elementY = "(elementVisual.Offset.Y + elementVisual.Size.Y / 2)";
636+
var centerY = "(centerVisual.Offset.Y + centerVisual.Size.Y / 2)";
637+
var elementX = "(elementVisual.Offset.X + elementVisual.Size.X / 2)";
638+
var centerX = "(centerVisual.Offset.X + centerVisual.Size.X / 2)";
642639

643640
var startingAngle = Math.Atan2(y, x);
644641

645642
if (startingAngle > Math.PI / 4 && startingAngle < 3 * Math.PI / 4)
646643
{
647-
expression = ExpressionFunctions.ATan((-1 * (elementX - centerX)) / (elementY - centerY)) - ((float)Math.PI / 2.0f);
644+
expression = $"Atan((-1 * ({elementX} - {centerX})) / ( {elementY} - {centerY})) - PI / 2";
648645
}
649646
else if (startingAngle >= 3 * Math.PI / 4 || startingAngle < -3 * Math.PI / 4)
650647
{
651-
expression = ExpressionFunctions.ATan((elementY - centerY) / (elementX - centerX)) + (float)Math.PI;
648+
expression = $"Atan(({elementY} - {centerY}) / ({elementX} - {centerX})) + PI";
652649
}
653650
else if (startingAngle >= -3 * Math.PI / 4 && startingAngle < Math.PI / -4)
654651
{
655-
expression = ExpressionFunctions.ATan((elementX - centerX) / (-1 * (elementY - centerY))) + ((float)Math.PI / 2.0f);
652+
expression = $"Atan(({elementX} - {centerX}) / (-1 * ({elementY} - {centerY}))) + PI / 2";
656653
}
657654
else
658655
{
659-
expression = ExpressionFunctions.ATan((elementY - centerY) / (elementX - centerX));
656+
expression = $"Atan(({elementY} - {centerY}) / ({elementX} - {centerX}))";
660657
}
661658

662659
anchorVisual.CenterPoint = new Vector3(0);
663-
anchorVisual.StartAnimation(nameof(anchorVisual.RotationAngle), expression);
664-
665-
var offsetExpression = ExpressionFunctions.Vector3(centerNode.Offset.X + (centerNode.Size.X / 2), centerNode.Offset.Y + (centerNode.Size.Y / 2), 0);
660+
var rotationExpression = _compositor.CreateExpressionAnimation();
661+
rotationExpression.Expression = expression;
662+
rotationExpression.SetReferenceParameter("centerVisual", centerVisual);
663+
rotationExpression.SetReferenceParameter("elementVisual", elementVisual);
664+
anchorVisual.StartAnimation(nameof(anchorVisual.RotationAngle), rotationExpression);
665+
666+
var offsetExpression = _compositor.CreateExpressionAnimation();
667+
offsetExpression.Expression = "Vector3(centerVisual.Offset.X + centerVisual.Size.X / 2, centerVisual.Offset.Y + centerVisual.Size.Y / 2, 0)";
668+
offsetExpression.SetReferenceParameter("centerVisual", centerVisual);
666669
anchorVisual.StartAnimation(nameof(anchorVisual.Offset), offsetExpression);
667670

668-
var scaleExpression = ExpressionFunctions.Vector3(ExpressionFunctions.Pow(ExpressionFunctions.Pow(elementX - centerX, 2) + ExpressionFunctions.Pow(elementY - centerY, 2), 0.5f) / 80, 1, 1);
671+
var scaleExpression = _compositor.CreateExpressionAnimation();
672+
scaleExpression.Expression = $"Vector3(Pow(Pow({elementX} - {centerX}, 2) + Pow({elementY} - {centerY}, 2), 0.5)/80, 1, 1)";
673+
scaleExpression.SetReferenceParameter("centerVisual", centerVisual);
674+
scaleExpression.SetReferenceParameter("elementVisual", elementVisual);
669675
anchorVisual.StartAnimation(nameof(anchorVisual.Scale), scaleExpression);
670676

671677
return anchor;

0 commit comments

Comments
 (0)