8
8
using System . Numerics ;
9
9
using System . Threading ;
10
10
using System . Threading . Tasks ;
11
- using Microsoft . Toolkit . Uwp . UI . Animations . Expressions ;
12
11
using Microsoft . Toolkit . Uwp . UI . Extensions ;
13
12
using Windows . Foundation ;
14
13
using Windows . UI . Composition ;
@@ -439,11 +438,12 @@ private async Task CreateModuloExpression(ScrollViewer scrollViewer = null)
439
438
/// <param name="scrollOrientation">The ScrollOrientation</param>
440
439
private void CreateModuloExpression ( ScrollViewer scrollViewer , double imageWidth , double imageHeight , ScrollOrientation scrollOrientation )
441
440
{
442
- const string offsetXParam = "offsetX" ;
443
- const string offsetYParam = "offsetY" ;
444
- const string imageWidthParam = "imageWidth" ;
445
- const string imageHeightParam = "imageHeight" ;
446
- const string speedParam = "speed" ;
441
+ const string pParam = "p" ;
442
+ const string offsetXParam = pParam + ".offsetX" ;
443
+ const string offsetYParam = pParam + ".offsetY" ;
444
+ const string imageWidthParam = pParam + ".imageWidth" ;
445
+ const string imageHeightParam = pParam + ".imageHeight" ;
446
+ const string speedParam = pParam + ".speed" ;
447
447
448
448
if ( _containerVisual == null )
449
449
{
@@ -453,90 +453,89 @@ private void CreateModuloExpression(ScrollViewer scrollViewer, double imageWidth
453
453
var compositor = _containerVisual . Compositor ;
454
454
455
455
// Setup the expression
456
- ExpressionNode expressionX = null ;
457
- ExpressionNode expressionY = null ;
458
- ExpressionNode expressionXVal ;
459
- ExpressionNode expressionYVal ;
456
+ var expressionX = compositor . CreateExpressionAnimation ( ) ;
457
+ var expressionY = compositor . CreateExpressionAnimation ( ) ;
460
458
461
459
var propertySetModulo = compositor . CreatePropertySet ( ) ;
462
- propertySetModulo . InsertScalar ( imageWidthParam , ( float ) imageWidth ) ;
463
- propertySetModulo . InsertScalar ( offsetXParam , ( float ) OffsetX ) ;
464
- propertySetModulo . InsertScalar ( imageHeightParam , ( float ) imageHeight ) ;
465
- propertySetModulo . InsertScalar ( offsetYParam , ( float ) OffsetY ) ;
466
- propertySetModulo . InsertScalar ( speedParam , ( float ) ParallaxSpeedRatio ) ;
460
+ propertySetModulo . InsertScalar ( "imageHeight" , ( float ) imageWidth ) ;
461
+ propertySetModulo . InsertScalar ( "offsetX" , ( float ) OffsetX ) ;
462
+ propertySetModulo . InsertScalar ( "imageWidth" , ( float ) imageHeight ) ;
463
+ propertySetModulo . InsertScalar ( "offsetY" , ( float ) OffsetY ) ;
464
+ propertySetModulo . InsertScalar ( "speed" , ( float ) ParallaxSpeedRatio ) ;
467
465
468
- var propertySetNodeModulo = propertySetModulo . GetReference ( ) ;
466
+ expressionX . SetReferenceParameter ( pParam , propertySetModulo ) ;
467
+ expressionY . SetReferenceParameter ( pParam , propertySetModulo ) ;
469
468
470
- var imageHeightNode = propertySetNodeModulo . GetScalarProperty ( imageHeightParam ) ;
471
- var imageWidthNode = propertySetNodeModulo . GetScalarProperty ( imageWidthParam ) ;
469
+ var imageHeightNode = imageHeightParam ;
470
+ var imageWidthNode = imageWidthParam ;
471
+
472
+ string expressionXVal ;
473
+ string expressionYVal ;
472
474
if ( scrollViewer == null )
473
475
{
474
- var offsetXNode = ExpressionFunctions . Ceil ( propertySetNodeModulo . GetScalarProperty ( offsetXParam ) ) ;
475
- var offsetYNode = ExpressionFunctions . Ceil ( propertySetNodeModulo . GetScalarProperty ( offsetYParam ) ) ;
476
+ var offsetXNode = " Ceil(" + offsetXParam + ")" ;
477
+ var offsetYNode = " Ceil(" + offsetYParam + ")" ;
476
478
477
479
// expressions are created to simulate a positive and negative modulo with the size of the image and the offset
478
- expressionXVal = ExpressionFunctions . Conditional (
479
- offsetXNode == 0 ,
480
- 0 ,
481
- ExpressionFunctions . Conditional (
482
- offsetXNode < 0 ,
483
- - ( ExpressionFunctions . Abs ( offsetXNode - ( ExpressionFunctions . Ceil ( offsetXNode / imageWidthNode ) * imageWidthNode ) ) % imageWidthNode ) ,
484
- - ( imageWidthNode - ( offsetXNode % imageWidthNode ) ) ) ) ;
485
-
486
- expressionYVal = ExpressionFunctions . Conditional (
487
- offsetYNode == 0 ,
488
- 0 ,
489
- ExpressionFunctions . Conditional (
490
- offsetYNode < 0 ,
491
- - ( ExpressionFunctions . Abs ( offsetYNode - ( ExpressionFunctions . Ceil ( offsetYNode / imageHeightNode ) * imageHeightNode ) ) % imageHeightNode ) ,
492
- - ( imageHeightNode - ( offsetYNode % imageHeightNode ) ) ) ) ;
480
+ expressionXVal =
481
+ $ "{ offsetXNode } == 0 " +
482
+ $ "? 0 " +
483
+ $ ": { offsetXNode } < 0 " +
484
+ $ "? -(Abs({ offsetXNode } - (Ceil({ offsetXNode } / { imageWidthNode } ) * { imageWidthNode } )) % { imageWidthNode } ) " +
485
+ $ ": -({ imageWidthNode } - ({ offsetXNode } % { imageWidthNode } ))";
486
+
487
+ expressionYVal =
488
+ $ "{ offsetYNode } == 0 " +
489
+ $ "? 0 " +
490
+ $ ": { offsetYNode } < 0 " +
491
+ $ "? -(Abs({ offsetYNode } - (Ceil({ offsetYNode } / { imageHeightNode } ) * { imageHeightNode } )) % { imageHeightNode } ) " +
492
+ $ ": -({ imageHeightNode } - ({ offsetYNode } % { imageHeightNode } ))";
493
493
}
494
494
else
495
495
{
496
496
// expressions are created to simulate a positive and negative modulo with the size of the image and the offset and the ScrollViewer offset (Translation)
497
497
var scrollProperties = ElementCompositionPreview . GetScrollViewerManipulationPropertySet ( scrollViewer ) ;
498
- var scrollPropSet = scrollProperties . GetSpecializedReference < ManipulationPropertySetReferenceNode > ( ) ;
499
-
500
- var speed = propertySetNodeModulo . GetScalarProperty ( speedParam ) ;
501
- var xCommon = ExpressionFunctions . Ceil ( ( scrollPropSet . Translation . X * speed ) + propertySetNodeModulo . GetScalarProperty ( offsetXParam ) ) ;
502
- expressionXVal = ExpressionFunctions . Conditional (
503
- xCommon == 0 ,
504
- 0 ,
505
- ExpressionFunctions . Conditional (
506
- xCommon < 0 ,
507
- - ( ExpressionFunctions . Abs ( xCommon - ( ExpressionFunctions . Ceil ( xCommon / imageWidthNode ) * imageWidthNode ) ) % imageWidthNode ) ,
508
- - ( imageWidthNode - ( xCommon % imageWidthNode ) ) ) ) ;
509
-
510
- var yCommon = ExpressionFunctions . Ceil ( ( scrollPropSet . Translation . Y * speed ) + propertySetNodeModulo . GetScalarProperty ( offsetYParam ) ) ;
511
- expressionYVal = ExpressionFunctions . Conditional (
512
- yCommon == 0 ,
513
- 0 ,
514
- ExpressionFunctions . Conditional (
515
- yCommon < 0 ,
516
- - ( ExpressionFunctions . Abs ( yCommon - ( ExpressionFunctions . Ceil ( yCommon / imageHeightNode ) * imageHeightNode ) ) % imageHeightNode ) ,
517
- - ( imageHeightNode - ( yCommon % imageHeightNode ) ) ) ) ;
498
+ expressionX . SetReferenceParameter ( "s" , scrollProperties ) ;
499
+ expressionY . SetReferenceParameter ( "s" , scrollProperties ) ;
500
+
501
+ var speed = speedParam ;
502
+ var xCommon = $ "Ceil((s.Translation.X * { speed } ) + { offsetXParam } )";
503
+ expressionXVal =
504
+ $ "{ xCommon } == 0 " +
505
+ "? 0 " +
506
+ $ ": { xCommon } < 0 " +
507
+ $ "? -(Abs({ xCommon } - (Ceil({ xCommon } / { imageWidthNode } ) * { imageWidthNode } )) % { imageWidthNode } ) " +
508
+ $ ": -({ imageWidthNode } - ({ xCommon } % { imageWidthNode } ))";
509
+
510
+ var yCommon = $ "Ceil((s.Translation.Y * { speed } ) + { offsetYParam } )";
511
+ expressionYVal =
512
+ $ "{ yCommon } == 0 " +
513
+ "? 0 " +
514
+ $ ": { yCommon } < 0 " +
515
+ $ "? -(Abs({ yCommon } - (Ceil({ yCommon } / { imageHeightNode } ) * { imageHeightNode } )) % { imageHeightNode } ) " +
516
+ $ ": -({ imageHeightNode } - ({ yCommon } % { imageHeightNode } ))";
518
517
}
519
518
520
519
if ( scrollOrientation == ScrollOrientation . Horizontal || scrollOrientation == ScrollOrientation . Both )
521
520
{
522
- expressionX = expressionXVal ;
521
+ expressionX . Expression = expressionXVal ;
523
522
524
523
if ( scrollOrientation == ScrollOrientation . Horizontal )
525
524
{
526
525
// In horizontal mode we never move the offset y
527
- expressionY = ( ScalarNode ) 0.0f ;
526
+ expressionY . Expression = "0" ;
528
527
_containerVisual . Offset = new Vector3 ( ( float ) OffsetY , 0 , 0 ) ;
529
528
}
530
529
}
531
530
532
531
if ( scrollOrientation == ScrollOrientation . Vertical || scrollOrientation == ScrollOrientation . Both )
533
532
{
534
- expressionY = expressionYVal ;
533
+ expressionY . Expression = expressionYVal ;
535
534
536
535
if ( scrollOrientation == ScrollOrientation . Vertical )
537
536
{
538
537
// In vertical mode we never move the offset x
539
- expressionX = ( ScalarNode ) 0.0f ;
538
+ expressionX . Expression = "0" ;
540
539
_containerVisual . Offset = new Vector3 ( 0 , ( float ) OffsetX , 0 ) ;
541
540
}
542
541
}
0 commit comments