From 62cb357fc3440638053f2df8fb90feeafa27fb0b Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Tue, 15 Dec 2020 17:08:20 -0500 Subject: [PATCH 01/11] Remove animation.expressions --- .../TileControl/TileControl.cs | 117 +++++++++--------- 1 file changed, 58 insertions(+), 59 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs index dea441e074f..c7cad436962 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs @@ -8,7 +8,6 @@ using System.Numerics; using System.Threading; using System.Threading.Tasks; -using Microsoft.Toolkit.Uwp.UI.Animations.Expressions; using Microsoft.Toolkit.Uwp.UI.Extensions; using Windows.Foundation; using Windows.UI.Composition; @@ -439,11 +438,12 @@ private async Task CreateModuloExpression(ScrollViewer scrollViewer = null) /// The ScrollOrientation private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth, double imageHeight, ScrollOrientation scrollOrientation) { - const string offsetXParam = "offsetX"; - const string offsetYParam = "offsetY"; - const string imageWidthParam = "imageWidth"; - const string imageHeightParam = "imageHeight"; - const string speedParam = "speed"; + const string pParam = "p"; + const string offsetXParam = pParam + ".offsetX"; + const string offsetYParam = pParam + ".offsetY"; + const string imageWidthParam = pParam + ".imageWidth"; + const string imageHeightParam = pParam + ".imageHeight"; + const string speedParam = pParam + ".speed"; if (_containerVisual == null) { @@ -453,90 +453,89 @@ private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth var compositor = _containerVisual.Compositor; // Setup the expression - ExpressionNode expressionX = null; - ExpressionNode expressionY = null; - ExpressionNode expressionXVal; - ExpressionNode expressionYVal; + var expressionX = compositor.CreateExpressionAnimation(); + var expressionY = compositor.CreateExpressionAnimation(); var propertySetModulo = compositor.CreatePropertySet(); - propertySetModulo.InsertScalar(imageWidthParam, (float)imageWidth); - propertySetModulo.InsertScalar(offsetXParam, (float)OffsetX); - propertySetModulo.InsertScalar(imageHeightParam, (float)imageHeight); - propertySetModulo.InsertScalar(offsetYParam, (float)OffsetY); - propertySetModulo.InsertScalar(speedParam, (float)ParallaxSpeedRatio); + propertySetModulo.InsertScalar("imageHeight", (float)imageWidth); + propertySetModulo.InsertScalar("offsetX", (float)OffsetX); + propertySetModulo.InsertScalar("imageWidth", (float)imageHeight); + propertySetModulo.InsertScalar("offsetY", (float)OffsetY); + propertySetModulo.InsertScalar("speed", (float)ParallaxSpeedRatio); - var propertySetNodeModulo = propertySetModulo.GetReference(); + expressionX.SetReferenceParameter(pParam, propertySetModulo); + expressionY.SetReferenceParameter(pParam, propertySetModulo); - var imageHeightNode = propertySetNodeModulo.GetScalarProperty(imageHeightParam); - var imageWidthNode = propertySetNodeModulo.GetScalarProperty(imageWidthParam); + var imageHeightNode = imageHeightParam; + var imageWidthNode = imageWidthParam; + + string expressionXVal; + string expressionYVal; if (scrollViewer == null) { - var offsetXNode = ExpressionFunctions.Ceil(propertySetNodeModulo.GetScalarProperty(offsetXParam)); - var offsetYNode = ExpressionFunctions.Ceil(propertySetNodeModulo.GetScalarProperty(offsetYParam)); + var offsetXNode = "Ceil(" + offsetXParam + ")"; + var offsetYNode = "Ceil(" + offsetYParam + ")"; // expressions are created to simulate a positive and negative modulo with the size of the image and the offset - expressionXVal = ExpressionFunctions.Conditional( - offsetXNode == 0, - 0, - ExpressionFunctions.Conditional( - offsetXNode < 0, - -(ExpressionFunctions.Abs(offsetXNode - (ExpressionFunctions.Ceil(offsetXNode / imageWidthNode) * imageWidthNode)) % imageWidthNode), - -(imageWidthNode - (offsetXNode % imageWidthNode)))); - - expressionYVal = ExpressionFunctions.Conditional( - offsetYNode == 0, - 0, - ExpressionFunctions.Conditional( - offsetYNode < 0, - -(ExpressionFunctions.Abs(offsetYNode - (ExpressionFunctions.Ceil(offsetYNode / imageHeightNode) * imageHeightNode)) % imageHeightNode), - -(imageHeightNode - (offsetYNode % imageHeightNode)))); + expressionXVal = + $"{offsetXNode} == 0 " + + $"? 0 " + + $": {offsetXNode} < 0 " + + $"? -(Abs({offsetXNode} - (Ceil({offsetXNode} / {imageWidthNode}) * {imageWidthNode})) % {imageWidthNode}) " + + $": -({imageWidthNode} - ({offsetXNode} % {imageWidthNode}))"; + + expressionYVal = + $"{offsetYNode} == 0 " + + $"? 0 " + + $": {offsetYNode} < 0 " + + $"? -(Abs({offsetYNode} - (Ceil({offsetYNode} / {imageHeightNode}) * {imageHeightNode})) % {imageHeightNode}) " + + $": -({imageHeightNode} - ({offsetYNode} % {imageHeightNode}))"; } else { // expressions are created to simulate a positive and negative modulo with the size of the image and the offset and the ScrollViewer offset (Translation) var scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer); - var scrollPropSet = scrollProperties.GetSpecializedReference(); - - var speed = propertySetNodeModulo.GetScalarProperty(speedParam); - var xCommon = ExpressionFunctions.Ceil((scrollPropSet.Translation.X * speed) + propertySetNodeModulo.GetScalarProperty(offsetXParam)); - expressionXVal = ExpressionFunctions.Conditional( - xCommon == 0, - 0, - ExpressionFunctions.Conditional( - xCommon < 0, - -(ExpressionFunctions.Abs(xCommon - (ExpressionFunctions.Ceil(xCommon / imageWidthNode) * imageWidthNode)) % imageWidthNode), - -(imageWidthNode - (xCommon % imageWidthNode)))); - - var yCommon = ExpressionFunctions.Ceil((scrollPropSet.Translation.Y * speed) + propertySetNodeModulo.GetScalarProperty(offsetYParam)); - expressionYVal = ExpressionFunctions.Conditional( - yCommon == 0, - 0, - ExpressionFunctions.Conditional( - yCommon < 0, - -(ExpressionFunctions.Abs(yCommon - (ExpressionFunctions.Ceil(yCommon / imageHeightNode) * imageHeightNode)) % imageHeightNode), - -(imageHeightNode - (yCommon % imageHeightNode)))); + expressionX.SetReferenceParameter("s", scrollProperties); + expressionY.SetReferenceParameter("s", scrollProperties); + + var speed = speedParam; + var xCommon = $"Ceil((s.Translation.X * {speed}) + {offsetXParam})"; + expressionXVal = + $"{xCommon} == 0 " + + "? 0 " + + $": {xCommon} < 0 " + + $"? -(Abs({xCommon} - (Ceil({xCommon} / {imageWidthNode}) * {imageWidthNode})) % {imageWidthNode}) " + + $": -({imageWidthNode} - ({xCommon} % {imageWidthNode}))"; + + var yCommon = $"Ceil((s.Translation.Y * {speed}) + {offsetYParam})"; + expressionYVal = + $"{yCommon} == 0 " + + "? 0 " + + $": {yCommon} < 0 " + + $"? -(Abs({yCommon} - (Ceil({yCommon} / {imageHeightNode}) * {imageHeightNode})) % {imageHeightNode}) " + + $": -({imageHeightNode} - ({yCommon} % {imageHeightNode}))"; } if (scrollOrientation == ScrollOrientation.Horizontal || scrollOrientation == ScrollOrientation.Both) { - expressionX = expressionXVal; + expressionX.Expression = expressionXVal; if (scrollOrientation == ScrollOrientation.Horizontal) { // In horizontal mode we never move the offset y - expressionY = (ScalarNode)0.0f; + expressionY.Expression = "0"; _containerVisual.Offset = new Vector3((float)OffsetY, 0, 0); } } if (scrollOrientation == ScrollOrientation.Vertical || scrollOrientation == ScrollOrientation.Both) { - expressionY = expressionYVal; + expressionY.Expression = expressionYVal; if (scrollOrientation == ScrollOrientation.Vertical) { // In vertical mode we never move the offset x - expressionX = (ScalarNode)0.0f; + expressionX.Expression = "0"; _containerVisual.Offset = new Vector3(0, (float)OffsetX, 0); } } From 1b79903d0bd0e54484cb0e3ef8bf591f42709e4d Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Wed, 16 Dec 2020 09:54:47 -0500 Subject: [PATCH 02/11] change node names out --- .../TileControl/TileControl.cs | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs index c7cad436962..513bdf597c0 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs @@ -466,30 +466,27 @@ private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth expressionX.SetReferenceParameter(pParam, propertySetModulo); expressionY.SetReferenceParameter(pParam, propertySetModulo); - var imageHeightNode = imageHeightParam; - var imageWidthNode = imageWidthParam; - string expressionXVal; string expressionYVal; if (scrollViewer == null) { - var offsetXNode = "Ceil(" + offsetXParam + ")"; - var offsetYNode = "Ceil(" + offsetYParam + ")"; + var xCommon = "Ceil(" + offsetXParam + ")"; + var yCommon = "Ceil(" + offsetYParam + ")"; // expressions are created to simulate a positive and negative modulo with the size of the image and the offset expressionXVal = - $"{offsetXNode} == 0 " + + $"{xCommon} == 0 " + $"? 0 " + - $": {offsetXNode} < 0 " + - $"? -(Abs({offsetXNode} - (Ceil({offsetXNode} / {imageWidthNode}) * {imageWidthNode})) % {imageWidthNode}) " + - $": -({imageWidthNode} - ({offsetXNode} % {imageWidthNode}))"; + $": {xCommon} < 0 " + + $"? -(Abs({xCommon} - (Ceil({xCommon} / {imageWidthParam}) * {imageWidthParam})) % {imageWidthParam}) " + + $": -({imageWidthParam} - ({xCommon} % {imageWidthParam}))"; expressionYVal = - $"{offsetYNode} == 0 " + + $"{yCommon} == 0 " + $"? 0 " + - $": {offsetYNode} < 0 " + - $"? -(Abs({offsetYNode} - (Ceil({offsetYNode} / {imageHeightNode}) * {imageHeightNode})) % {imageHeightNode}) " + - $": -({imageHeightNode} - ({offsetYNode} % {imageHeightNode}))"; + $": {yCommon} < 0 " + + $"? -(Abs({yCommon} - (Ceil({yCommon} / {imageHeightParam}) * {imageHeightParam})) % {imageHeightParam}) " + + $": -({imageHeightParam} - ({yCommon} % {imageHeightParam}))"; } else { @@ -498,22 +495,21 @@ private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth expressionX.SetReferenceParameter("s", scrollProperties); expressionY.SetReferenceParameter("s", scrollProperties); - var speed = speedParam; - var xCommon = $"Ceil((s.Translation.X * {speed}) + {offsetXParam})"; + var xCommon = $"Ceil((s.Translation.X * {speedParam}) + {offsetXParam})"; expressionXVal = $"{xCommon} == 0 " + "? 0 " + $": {xCommon} < 0 " + - $"? -(Abs({xCommon} - (Ceil({xCommon} / {imageWidthNode}) * {imageWidthNode})) % {imageWidthNode}) " + - $": -({imageWidthNode} - ({xCommon} % {imageWidthNode}))"; + $"? -(Abs({xCommon} - (Ceil({xCommon} / {imageWidthParam}) * {imageWidthParam})) % {imageWidthParam}) " + + $": -({imageWidthParam} - ({xCommon} % {imageWidthParam}))"; - var yCommon = $"Ceil((s.Translation.Y * {speed}) + {offsetYParam})"; + var yCommon = $"Ceil((s.Translation.Y * {speedParam}) + {offsetYParam})"; expressionYVal = $"{yCommon} == 0 " + "? 0 " + $": {yCommon} < 0 " + - $"? -(Abs({yCommon} - (Ceil({yCommon} / {imageHeightNode}) * {imageHeightNode})) % {imageHeightNode}) " + - $": -({imageHeightNode} - ({yCommon} % {imageHeightNode}))"; + $"? -(Abs({yCommon} - (Ceil({yCommon} / {imageHeightParam}) * {imageHeightParam})) % {imageHeightParam}) " + + $": -({imageHeightParam} - ({yCommon} % {imageHeightParam}))"; } if (scrollOrientation == ScrollOrientation.Horizontal || scrollOrientation == ScrollOrientation.Both) From 687137d206fa2d148d33f78e2d8b42aa82b1b4c8 Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Wed, 16 Dec 2020 10:48:09 -0500 Subject: [PATCH 03/11] Factor out common string format. --- .../TileControl/TileControl.cs | 48 +++++++------------ 1 file changed, 18 insertions(+), 30 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs index 513bdf597c0..623cdf40735 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs @@ -466,27 +466,24 @@ private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth expressionX.SetReferenceParameter(pParam, propertySetModulo); expressionY.SetReferenceParameter(pParam, propertySetModulo); + string Thing(string common, string diemtion) + => string.Format( + "{0} == 0 " + + "? 0 " + + ": {0} < 0 " + + "? -(Abs({0} - (Ceil({0} / {1}) * {1})) % {1}) " + + ": -({1} - ({0} % {1}))", + common, + diemtion); + string expressionXVal; string expressionYVal; if (scrollViewer == null) { - var xCommon = "Ceil(" + offsetXParam + ")"; - var yCommon = "Ceil(" + offsetYParam + ")"; - // expressions are created to simulate a positive and negative modulo with the size of the image and the offset - expressionXVal = - $"{xCommon} == 0 " + - $"? 0 " + - $": {xCommon} < 0 " + - $"? -(Abs({xCommon} - (Ceil({xCommon} / {imageWidthParam}) * {imageWidthParam})) % {imageWidthParam}) " + - $": -({imageWidthParam} - ({xCommon} % {imageWidthParam}))"; - - expressionYVal = - $"{yCommon} == 0 " + - $"? 0 " + - $": {yCommon} < 0 " + - $"? -(Abs({yCommon} - (Ceil({yCommon} / {imageHeightParam}) * {imageHeightParam})) % {imageHeightParam}) " + - $": -({imageHeightParam} - ({yCommon} % {imageHeightParam}))"; + expressionXVal = Thing("Ceil(" + offsetXParam + ")", imageHeightParam); + + expressionYVal = Thing("Ceil(" + offsetYParam + ")", imageWidthParam); } else { @@ -495,21 +492,12 @@ private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth expressionX.SetReferenceParameter("s", scrollProperties); expressionY.SetReferenceParameter("s", scrollProperties); - var xCommon = $"Ceil((s.Translation.X * {speedParam}) + {offsetXParam})"; - expressionXVal = - $"{xCommon} == 0 " + - "? 0 " + - $": {xCommon} < 0 " + - $"? -(Abs({xCommon} - (Ceil({xCommon} / {imageWidthParam}) * {imageWidthParam})) % {imageWidthParam}) " + - $": -({imageWidthParam} - ({xCommon} % {imageWidthParam}))"; + string LocalThing(string scroll, string speed, string offset, string dimention) + => Thing(string.Format("Ceil(({0} * {1}) + {2})", scroll, speed, offset), dimention); - var yCommon = $"Ceil((s.Translation.Y * {speedParam}) + {offsetYParam})"; - expressionYVal = - $"{yCommon} == 0 " + - "? 0 " + - $": {yCommon} < 0 " + - $"? -(Abs({yCommon} - (Ceil({yCommon} / {imageHeightParam}) * {imageHeightParam})) % {imageHeightParam}) " + - $": -({imageHeightParam} - ({yCommon} % {imageHeightParam}))"; + expressionXVal = LocalThing("s.Translation.X", speedParam, offsetXParam, imageWidthParam); + + expressionYVal = LocalThing("s.Translation.Y", speedParam, offsetYParam, imageHeightParam); } if (scrollOrientation == ScrollOrientation.Horizontal || scrollOrientation == ScrollOrientation.Both) From c9b46c0612bce441751d83e6bcd5beb08aa11dbc Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Wed, 16 Dec 2020 12:13:06 -0500 Subject: [PATCH 04/11] simplified constants --- .../TileControl/TileControl.cs | 39 ++++++++++--------- 1 file changed, 20 insertions(+), 19 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs index 623cdf40735..44f8cd1a3f9 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs @@ -438,12 +438,12 @@ private async Task CreateModuloExpression(ScrollViewer scrollViewer = null) /// The ScrollOrientation private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth, double imageHeight, ScrollOrientation scrollOrientation) { - const string pParam = "p"; - const string offsetXParam = pParam + ".offsetX"; - const string offsetYParam = pParam + ".offsetY"; - const string imageWidthParam = pParam + ".imageWidth"; - const string imageHeightParam = pParam + ".imageHeight"; - const string speedParam = pParam + ".speed"; + const string propSetParam = "p"; + const string offsetXParam = "offsetX"; + const string offsetYParam = "offsetY"; + const string imageWidthParam = "imageWidth"; + const string imageHeightParam = "imageHeight"; + const string speedParam = "speed"; if (_containerVisual == null) { @@ -457,14 +457,14 @@ private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth var expressionY = compositor.CreateExpressionAnimation(); var propertySetModulo = compositor.CreatePropertySet(); - propertySetModulo.InsertScalar("imageHeight", (float)imageWidth); - propertySetModulo.InsertScalar("offsetX", (float)OffsetX); - propertySetModulo.InsertScalar("imageWidth", (float)imageHeight); - propertySetModulo.InsertScalar("offsetY", (float)OffsetY); - propertySetModulo.InsertScalar("speed", (float)ParallaxSpeedRatio); + propertySetModulo.InsertScalar(imageHeightParam, (float)imageWidth); + propertySetModulo.InsertScalar(offsetXParam, (float)OffsetX); + propertySetModulo.InsertScalar(imageWidthParam, (float)imageHeight); + propertySetModulo.InsertScalar(offsetYParam, (float)OffsetY); + propertySetModulo.InsertScalar(speedParam, (float)ParallaxSpeedRatio); - expressionX.SetReferenceParameter(pParam, propertySetModulo); - expressionY.SetReferenceParameter(pParam, propertySetModulo); + expressionX.SetReferenceParameter(propSetParam, propertySetModulo); + expressionY.SetReferenceParameter(propSetParam, propertySetModulo); string Thing(string common, string diemtion) => string.Format( @@ -481,23 +481,24 @@ string Thing(string common, string diemtion) if (scrollViewer == null) { // expressions are created to simulate a positive and negative modulo with the size of the image and the offset - expressionXVal = Thing("Ceil(" + offsetXParam + ")", imageHeightParam); + expressionXVal = Thing("Ceil(" + propSetParam + "." + offsetXParam + ")", propSetParam + "." + imageHeightParam); - expressionYVal = Thing("Ceil(" + offsetYParam + ")", imageWidthParam); + expressionYVal = Thing("Ceil(" + propSetParam + "." + offsetYParam + ")", propSetParam + "." + imageWidthParam); } else { // expressions are created to simulate a positive and negative modulo with the size of the image and the offset and the ScrollViewer offset (Translation) var scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer); - expressionX.SetReferenceParameter("s", scrollProperties); - expressionY.SetReferenceParameter("s", scrollProperties); + const string scrollParam = "s"; + expressionX.SetReferenceParameter(scrollParam, scrollProperties); + expressionY.SetReferenceParameter(scrollParam, scrollProperties); string LocalThing(string scroll, string speed, string offset, string dimention) => Thing(string.Format("Ceil(({0} * {1}) + {2})", scroll, speed, offset), dimention); - expressionXVal = LocalThing("s.Translation.X", speedParam, offsetXParam, imageWidthParam); + expressionXVal = LocalThing(scrollParam + ".Translation.X", propSetParam + "." + speedParam, propSetParam + "." + offsetXParam, propSetParam + "." + imageWidthParam); - expressionYVal = LocalThing("s.Translation.Y", speedParam, offsetYParam, imageHeightParam); + expressionYVal = LocalThing(scrollParam + ".Translation.Y", propSetParam + "." + speedParam, propSetParam + "." + offsetYParam, propSetParam + "." + imageHeightParam); } if (scrollOrientation == ScrollOrientation.Horizontal || scrollOrientation == ScrollOrientation.Both) From 1ce7a8740f68a6ad4f2f488f258a6f1b118adaf4 Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Wed, 16 Dec 2020 12:40:38 -0500 Subject: [PATCH 05/11] Normailize qulified names --- .../TileControl/TileControl.cs | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs index 44f8cd1a3f9..87b8a18aa25 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs @@ -440,9 +440,13 @@ private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth { const string propSetParam = "p"; const string offsetXParam = "offsetX"; + const string qualifiedOffsetXParam = propSetParam + "." + offsetXParam; const string offsetYParam = "offsetY"; + const string qualifiedOffsetYParam = propSetParam + "." + offsetYParam; const string imageWidthParam = "imageWidth"; + const string qualifiedImageWidthParam = propSetParam + "." + imageWidthParam; const string imageHeightParam = "imageHeight"; + const string qualifiedImageHeightParam = propSetParam + "." + imageHeightParam; const string speedParam = "speed"; if (_containerVisual == null) @@ -481,24 +485,26 @@ string Thing(string common, string diemtion) if (scrollViewer == null) { // expressions are created to simulate a positive and negative modulo with the size of the image and the offset - expressionXVal = Thing("Ceil(" + propSetParam + "." + offsetXParam + ")", propSetParam + "." + imageHeightParam); + expressionXVal = Thing("Ceil(" + qualifiedOffsetXParam + ")", qualifiedImageHeightParam); - expressionYVal = Thing("Ceil(" + propSetParam + "." + offsetYParam + ")", propSetParam + "." + imageWidthParam); + expressionYVal = Thing("Ceil(" + qualifiedOffsetYParam + ")", qualifiedImageWidthParam); } else { // expressions are created to simulate a positive and negative modulo with the size of the image and the offset and the ScrollViewer offset (Translation) var scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer); const string scrollParam = "s"; + const string qualifiedSpeedParam = propSetParam + "." + speedParam; + expressionX.SetReferenceParameter(scrollParam, scrollProperties); expressionY.SetReferenceParameter(scrollParam, scrollProperties); string LocalThing(string scroll, string speed, string offset, string dimention) => Thing(string.Format("Ceil(({0} * {1}) + {2})", scroll, speed, offset), dimention); - expressionXVal = LocalThing(scrollParam + ".Translation.X", propSetParam + "." + speedParam, propSetParam + "." + offsetXParam, propSetParam + "." + imageWidthParam); + expressionXVal = LocalThing(scrollParam + ".Translation.X", qualifiedSpeedParam, qualifiedOffsetXParam, qualifiedImageWidthParam); - expressionYVal = LocalThing(scrollParam + ".Translation.Y", propSetParam + "." + speedParam, propSetParam + "." + offsetYParam, propSetParam + "." + imageHeightParam); + expressionYVal = LocalThing(scrollParam + ".Translation.Y", qualifiedSpeedParam, qualifiedOffsetYParam, qualifiedImageHeightParam); } if (scrollOrientation == ScrollOrientation.Horizontal || scrollOrientation == ScrollOrientation.Both) From 5269fdde77c8ce86c7f628fa988d69e7b565cae5 Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Wed, 16 Dec 2020 12:57:47 -0500 Subject: [PATCH 06/11] Fix spelling of dimension --- .../TileControl/TileControl.cs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs index 87b8a18aa25..884b70e196b 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs @@ -470,7 +470,7 @@ private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth expressionX.SetReferenceParameter(propSetParam, propertySetModulo); expressionY.SetReferenceParameter(propSetParam, propertySetModulo); - string Thing(string common, string diemtion) + string Thing(string common, string dimension) => string.Format( "{0} == 0 " + "? 0 " + @@ -478,7 +478,7 @@ string Thing(string common, string diemtion) "? -(Abs({0} - (Ceil({0} / {1}) * {1})) % {1}) " + ": -({1} - ({0} % {1}))", common, - diemtion); + dimension); string expressionXVal; string expressionYVal; @@ -499,8 +499,8 @@ string Thing(string common, string diemtion) expressionX.SetReferenceParameter(scrollParam, scrollProperties); expressionY.SetReferenceParameter(scrollParam, scrollProperties); - string LocalThing(string scroll, string speed, string offset, string dimention) - => Thing(string.Format("Ceil(({0} * {1}) + {2})", scroll, speed, offset), dimention); + string LocalThing(string scroll, string speed, string offset, string dimension) + => Thing(string.Format("Ceil(({0} * {1}) + {2})", scroll, speed, offset), dimension); expressionXVal = LocalThing(scrollParam + ".Translation.X", qualifiedSpeedParam, qualifiedOffsetXParam, qualifiedImageWidthParam); From dd8d11d9953fd0d90852c85154b759c01b68e624 Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Wed, 16 Dec 2020 13:33:41 -0500 Subject: [PATCH 07/11] Use nameof to pull out some strings --- .../TileControl/TileControl.cs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs index 884b70e196b..fba89c27489 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs @@ -439,15 +439,15 @@ private async Task CreateModuloExpression(ScrollViewer scrollViewer = null) private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth, double imageHeight, ScrollOrientation scrollOrientation) { const string propSetParam = "p"; - const string offsetXParam = "offsetX"; + const string offsetXParam = nameof(OffsetX); const string qualifiedOffsetXParam = propSetParam + "." + offsetXParam; - const string offsetYParam = "offsetY"; + const string offsetYParam = nameof(OffsetY); const string qualifiedOffsetYParam = propSetParam + "." + offsetYParam; - const string imageWidthParam = "imageWidth"; + const string imageWidthParam = nameof(imageWidth); const string qualifiedImageWidthParam = propSetParam + "." + imageWidthParam; - const string imageHeightParam = "imageHeight"; + const string imageHeightParam = nameof(imageHeight); const string qualifiedImageHeightParam = propSetParam + "." + imageHeightParam; - const string speedParam = "speed"; + const string speedParam = nameof(ParallaxSpeedRatio); if (_containerVisual == null) { @@ -494,6 +494,7 @@ string Thing(string common, string dimension) // expressions are created to simulate a positive and negative modulo with the size of the image and the offset and the ScrollViewer offset (Translation) var scrollProperties = ElementCompositionPreview.GetScrollViewerManipulationPropertySet(scrollViewer); const string scrollParam = "s"; + const string translationParam = scrollParam + "." + nameof(scrollViewer.Translation); const string qualifiedSpeedParam = propSetParam + "." + speedParam; expressionX.SetReferenceParameter(scrollParam, scrollProperties); @@ -502,9 +503,9 @@ string Thing(string common, string dimension) string LocalThing(string scroll, string speed, string offset, string dimension) => Thing(string.Format("Ceil(({0} * {1}) + {2})", scroll, speed, offset), dimension); - expressionXVal = LocalThing(scrollParam + ".Translation.X", qualifiedSpeedParam, qualifiedOffsetXParam, qualifiedImageWidthParam); + expressionXVal = LocalThing(translationParam + "." + nameof(scrollViewer.Translation.X), qualifiedSpeedParam, qualifiedOffsetXParam, qualifiedImageWidthParam); - expressionYVal = LocalThing(scrollParam + ".Translation.Y", qualifiedSpeedParam, qualifiedOffsetYParam, qualifiedImageHeightParam); + expressionYVal = LocalThing(translationParam + "." + nameof(scrollViewer.Translation.Y), qualifiedSpeedParam, qualifiedOffsetYParam, qualifiedImageHeightParam); } if (scrollOrientation == ScrollOrientation.Horizontal || scrollOrientation == ScrollOrientation.Both) From 354a7bf69b5a62c5939f0fb0b9c13b853c464444 Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Wed, 16 Dec 2020 13:58:26 -0500 Subject: [PATCH 08/11] More precise param name --- Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs index fba89c27489..25607bfe358 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs @@ -500,8 +500,8 @@ string Thing(string common, string dimension) expressionX.SetReferenceParameter(scrollParam, scrollProperties); expressionY.SetReferenceParameter(scrollParam, scrollProperties); - string LocalThing(string scroll, string speed, string offset, string dimension) - => Thing(string.Format("Ceil(({0} * {1}) + {2})", scroll, speed, offset), dimension); + string LocalThing(string scrollTranslation, string speed, string offset, string dimension) + => Thing(string.Format("Ceil(({0} * {1}) + {2})", scrollTranslation, speed, offset), dimension); expressionXVal = LocalThing(translationParam + "." + nameof(scrollViewer.Translation.X), qualifiedSpeedParam, qualifiedOffsetXParam, qualifiedImageWidthParam); From 2ceaf28a7d1a768cca922ab7e34601b9301ec545 Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Wed, 16 Dec 2020 14:01:14 -0500 Subject: [PATCH 09/11] Use GenrateForumla name for fn --- .../TileControl/TileControl.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs index 25607bfe358..86a7f4466d2 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs @@ -470,7 +470,7 @@ private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth expressionX.SetReferenceParameter(propSetParam, propertySetModulo); expressionY.SetReferenceParameter(propSetParam, propertySetModulo); - string Thing(string common, string dimension) + string GenerateFormula(string common, string dimension) => string.Format( "{0} == 0 " + "? 0 " + @@ -485,9 +485,9 @@ string Thing(string common, string dimension) if (scrollViewer == null) { // expressions are created to simulate a positive and negative modulo with the size of the image and the offset - expressionXVal = Thing("Ceil(" + qualifiedOffsetXParam + ")", qualifiedImageHeightParam); + expressionXVal = GenerateFormula("Ceil(" + qualifiedOffsetXParam + ")", qualifiedImageHeightParam); - expressionYVal = Thing("Ceil(" + qualifiedOffsetYParam + ")", qualifiedImageWidthParam); + expressionYVal = GenerateFormula("Ceil(" + qualifiedOffsetYParam + ")", qualifiedImageWidthParam); } else { @@ -500,12 +500,12 @@ string Thing(string common, string dimension) expressionX.SetReferenceParameter(scrollParam, scrollProperties); expressionY.SetReferenceParameter(scrollParam, scrollProperties); - string LocalThing(string scrollTranslation, string speed, string offset, string dimension) - => Thing(string.Format("Ceil(({0} * {1}) + {2})", scrollTranslation, speed, offset), dimension); + string GenerateParalaxFormula(string scrollTranslation, string speed, string offset, string dimension) + => GenerateFormula(string.Format("Ceil(({0} * {1}) + {2})", scrollTranslation, speed, offset), dimension); - expressionXVal = LocalThing(translationParam + "." + nameof(scrollViewer.Translation.X), qualifiedSpeedParam, qualifiedOffsetXParam, qualifiedImageWidthParam); + expressionXVal = GenerateParalaxFormula(translationParam + "." + nameof(scrollViewer.Translation.X), qualifiedSpeedParam, qualifiedOffsetXParam, qualifiedImageWidthParam); - expressionYVal = LocalThing(translationParam + "." + nameof(scrollViewer.Translation.Y), qualifiedSpeedParam, qualifiedOffsetYParam, qualifiedImageHeightParam); + expressionYVal = GenerateParalaxFormula(translationParam + "." + nameof(scrollViewer.Translation.Y), qualifiedSpeedParam, qualifiedOffsetYParam, qualifiedImageHeightParam); } if (scrollOrientation == ScrollOrientation.Horizontal || scrollOrientation == ScrollOrientation.Both) From b305088ee52f50f0ca44bc05bd522839423dfb41 Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Wed, 16 Dec 2020 15:10:26 -0500 Subject: [PATCH 10/11] Update Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs Co-authored-by: Michael Hawker MSFT (XAML Llama) <24302614+michael-hawker@users.noreply.github.com> --- .../TileControl/TileControl.cs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs index 86a7f4466d2..93fb1d01b55 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs @@ -500,12 +500,12 @@ string GenerateFormula(string common, string dimension) expressionX.SetReferenceParameter(scrollParam, scrollProperties); expressionY.SetReferenceParameter(scrollParam, scrollProperties); - string GenerateParalaxFormula(string scrollTranslation, string speed, string offset, string dimension) + string GenerateParallaxFormula(string scrollTranslation, string speed, string offset, string dimension) => GenerateFormula(string.Format("Ceil(({0} * {1}) + {2})", scrollTranslation, speed, offset), dimension); - expressionXVal = GenerateParalaxFormula(translationParam + "." + nameof(scrollViewer.Translation.X), qualifiedSpeedParam, qualifiedOffsetXParam, qualifiedImageWidthParam); + expressionXVal = GenerateParallaxFormula(translationParam + "." + nameof(scrollViewer.Translation.X), qualifiedSpeedParam, qualifiedOffsetXParam, qualifiedImageWidthParam); - expressionYVal = GenerateParalaxFormula(translationParam + "." + nameof(scrollViewer.Translation.Y), qualifiedSpeedParam, qualifiedOffsetYParam, qualifiedImageHeightParam); + expressionYVal = GenerateParallaxFormula(translationParam + "." + nameof(scrollViewer.Translation.Y), qualifiedSpeedParam, qualifiedOffsetYParam, qualifiedImageHeightParam); } if (scrollOrientation == ScrollOrientation.Horizontal || scrollOrientation == ScrollOrientation.Both) From fcd9a3be64f3ee97233ea085740ce6de33a4b959 Mon Sep 17 00:00:00 2001 From: Rosario Pulella Date: Wed, 16 Dec 2020 15:22:50 -0500 Subject: [PATCH 11/11] Fixed fliped width and height --- Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs index 93fb1d01b55..b537ffebf6c 100644 --- a/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs +++ b/Microsoft.Toolkit.Uwp.UI.Controls/TileControl/TileControl.cs @@ -461,9 +461,9 @@ private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth var expressionY = compositor.CreateExpressionAnimation(); var propertySetModulo = compositor.CreatePropertySet(); - propertySetModulo.InsertScalar(imageHeightParam, (float)imageWidth); + propertySetModulo.InsertScalar(imageWidthParam, (float)imageWidth); propertySetModulo.InsertScalar(offsetXParam, (float)OffsetX); - propertySetModulo.InsertScalar(imageWidthParam, (float)imageHeight); + propertySetModulo.InsertScalar(imageHeightParam, (float)imageHeight); propertySetModulo.InsertScalar(offsetYParam, (float)OffsetY); propertySetModulo.InsertScalar(speedParam, (float)ParallaxSpeedRatio);