@@ -168,7 +168,7 @@ static void TranslateAndApplyLinearGradientStroke(
168168 ApplyCommonStrokeProperties (
169169 context ,
170170 shapeStroke ,
171- TranslateLinearGradient ( context , shapeStroke , contextOpacity ) ,
171+ TranslateLinearGradient ( context , shapeStroke , contextOpacity , null ) ,
172172 sprite ) ;
173173 }
174174
@@ -181,7 +181,7 @@ static void TranslateAndApplyRadialGradientStroke(
181181 ApplyCommonStrokeProperties (
182182 context ,
183183 shapeStroke ,
184- TranslateRadialGradient ( context , shapeStroke , contextOpacity ) ,
184+ TranslateRadialGradient ( context , shapeStroke , contextOpacity , null ) ,
185185 sprite ) ;
186186 }
187187
@@ -254,7 +254,11 @@ static void ApplyCommonStrokeProperties(
254254 sprite . StrokeBrush = brush ;
255255 }
256256
257- public static CompositionBrush ? TranslateShapeFill ( LayerContext context , ShapeFill ? shapeFill , CompositeOpacity opacity )
257+ public static CompositionBrush ? TranslateShapeFill (
258+ LayerContext context ,
259+ ShapeFill ? shapeFill ,
260+ CompositeOpacity opacity ,
261+ Rectangles . InternalOffset ? internalOffset )
258262 {
259263 if ( shapeFill is null )
260264 {
@@ -264,8 +268,8 @@ static void ApplyCommonStrokeProperties(
264268 return shapeFill . FillKind switch
265269 {
266270 ShapeFill . ShapeFillKind . SolidColor => TranslateSolidColorFill ( context , ( SolidColorFill ) shapeFill , opacity ) ,
267- ShapeFill . ShapeFillKind . LinearGradient => TranslateLinearGradient ( context , ( LinearGradientFill ) shapeFill , opacity ) ,
268- ShapeFill . ShapeFillKind . RadialGradient => TranslateRadialGradient ( context , ( RadialGradientFill ) shapeFill , opacity ) ,
271+ ShapeFill . ShapeFillKind . LinearGradient => TranslateLinearGradient ( context , ( LinearGradientFill ) shapeFill , opacity , internalOffset ) ,
272+ ShapeFill . ShapeFillKind . RadialGradient => TranslateRadialGradient ( context , ( RadialGradientFill ) shapeFill , opacity , internalOffset ) ,
269273 _ => throw new InvalidOperationException ( ) ,
270274 } ;
271275 }
@@ -406,10 +410,40 @@ static CompositionColorBrush TranslateBoundSolidColor(
406410 return result ;
407411 }
408412
413+ static void TranslateVector2AnimatableWithInternalOffset (
414+ LayerContext context ,
415+ CompositionObject obj ,
416+ string propertyName ,
417+ TrimmedAnimatable < Vector2 > value ,
418+ Rectangles . InternalOffset offset )
419+ {
420+ // anomate source property first
421+ string sourcePropertyName = propertyName + "Source" ;
422+ obj . Properties . InsertVector2 ( sourcePropertyName , ConvertTo . Vector2 ( value . InitialValue ) ) ;
423+ Animate . Vector2 ( context , value , obj , sourcePropertyName ) ;
424+
425+ // create expression that offsets source property by internal offset
426+ WinCompData . Expressions . Vector2 expression = offset . IsAnimated ?
427+ ExpressionFactory . InternalOffsetExressionAdded ( sourcePropertyName , offset . OffsetExpression ! ) :
428+ ExpressionFactory . InternalOffsetValueAdded ( sourcePropertyName , ( Sn . Vector2 ) offset . OffsetValue ! ) ;
429+
430+ var expressionAnimation = context . ObjectFactory . CreateExpressionAnimation ( expression ) ;
431+ expressionAnimation . SetReferenceParameter ( "my" , obj ) ;
432+ if ( offset . IsAnimated )
433+ {
434+ // expression can use geometry
435+ expressionAnimation . SetReferenceParameter ( "geometry" , offset . Geometry ) ;
436+ }
437+
438+ // animate original property with expression that applies internal offset to it
439+ Animate . WithExpression ( obj , expressionAnimation , propertyName ) ;
440+ }
441+
409442 static CompositionLinearGradientBrush ? TranslateLinearGradient (
410443 LayerContext context ,
411444 IGradient linearGradient ,
412- CompositeOpacity opacity )
445+ CompositeOpacity opacity ,
446+ Rectangles . InternalOffset ? internalOffset )
413447 {
414448 var result = context . ObjectFactory . CreateLinearGradientBrush ( ) ;
415449
@@ -419,7 +453,11 @@ static CompositionColorBrush TranslateBoundSolidColor(
419453 var startPoint = Optimizer . TrimAnimatable ( context , linearGradient . StartPoint ) ;
420454 var endPoint = Optimizer . TrimAnimatable ( context , linearGradient . EndPoint ) ;
421455
422- if ( startPoint . IsAnimated )
456+ if ( internalOffset is not null )
457+ {
458+ TranslateVector2AnimatableWithInternalOffset ( context , result , nameof ( result . StartPoint ) , startPoint , internalOffset ) ;
459+ }
460+ else if ( startPoint . IsAnimated )
423461 {
424462 Animate . Vector2 ( context , startPoint , result , nameof ( result . StartPoint ) ) ;
425463 }
@@ -428,7 +466,11 @@ static CompositionColorBrush TranslateBoundSolidColor(
428466 result . StartPoint = ConvertTo . Vector2 ( startPoint . InitialValue ) ;
429467 }
430468
431- if ( endPoint . IsAnimated )
469+ if ( internalOffset is not null )
470+ {
471+ TranslateVector2AnimatableWithInternalOffset ( context , result , nameof ( result . EndPoint ) , endPoint , internalOffset ) ;
472+ }
473+ else if ( endPoint . IsAnimated )
432474 {
433475 Animate . Vector2 ( context , endPoint , result , nameof ( result . EndPoint ) ) ;
434476 }
@@ -453,13 +495,14 @@ static CompositionColorBrush TranslateBoundSolidColor(
453495 static CompositionGradientBrush ? TranslateRadialGradient (
454496 LayerContext context ,
455497 IRadialGradient gradient ,
456- CompositeOpacity opacity )
498+ CompositeOpacity opacity ,
499+ Rectangles . InternalOffset ? internalOffset )
457500 {
458501 if ( ! context . ObjectFactory . IsUapApiAvailable ( nameof ( CompositionRadialGradientBrush ) , versionDependentFeatureDescription : "Radial gradient fill" ) )
459502 {
460503 // CompositionRadialGradientBrush didn't exist until UAP v8. If the target OS doesn't support
461504 // UAP v8 then fall back to linear gradients as a compromise.
462- return TranslateLinearGradient ( context , gradient , opacity ) ;
505+ return TranslateLinearGradient ( context , gradient , opacity , internalOffset ) ;
463506 }
464507
465508 var result = context . ObjectFactory . CreateRadialGradientBrush ( ) ;
@@ -470,7 +513,11 @@ static CompositionColorBrush TranslateBoundSolidColor(
470513 var startPoint = Optimizer . TrimAnimatable ( context , gradient . StartPoint ) ;
471514 var endPoint = Optimizer . TrimAnimatable ( context , gradient . EndPoint ) ;
472515
473- if ( startPoint . IsAnimated )
516+ if ( internalOffset is not null )
517+ {
518+ TranslateVector2AnimatableWithInternalOffset ( context , result , nameof ( result . EllipseCenter ) , startPoint , internalOffset ) ;
519+ }
520+ else if ( startPoint . IsAnimated )
474521 {
475522 Animate . Vector2 ( context , startPoint , result , nameof ( result . EllipseCenter ) ) ;
476523 }
0 commit comments