Skip to content

Gradient fill for rectangle(rounded rectangle) shape fixed - #450

Merged
aborziak-ms merged 7 commits into
masterfrom
user/aborziak-ms/rectangles-gradient-fill-fix
Jun 14, 2021
Merged

aborziak-ms merged 7 commits into
masterfrom
user/aborziak-ms/rectangles-gradient-fill-fix

Conversation

@aborziak-ms

Copy link
Copy Markdown
Collaborator

Because of the difference in how gradient fill for rectangles works in WinComp API and Lottie, previously it was displayed incorrectly.

WinComp API uses top left corner of rectangle as point [0, 0] while Lottie uses middle-middle instead. To account for this difference we need to add (Rectangle.Size/2) to Start and End points of gradients. We can't add a constant value since Rectangle.Size can also be animated, and if it is animated, we need to use expression animation.

In this change, I added InternalOffset class for rectangle shapes, which propagates information about offset to the gradients and then this offset is applied to Start and End points.

Examples below show how it works now:

Lottie-windows old

Lottie web viewer (https://lottiefiles.com/preview)

Lottie-windows with this PR

@aborziak-ms
aborziak-ms requested a review from a team as a code owner June 10, 2021 23:45
@aborziak-ms
aborziak-ms requested a review from eliezerpMS June 10, 2021 23:46
Comment thread source/LottieToWinComp/Brushes.cs Resolved
Comment thread source/LottieToWinComp/Brushes.cs Resolved
Comment thread source/LottieToWinComp/Rectangles.cs Resolved
Comment thread source/LottieToWinComp/Brushes.cs Resolved
Comment thread source/LottieToWinComp/Brushes.cs Resolved
Comment thread source/LottieToWinComp/Brushes.cs Resolved
Comment thread source/LottieToWinComp/Brushes.cs Resolved
Comment thread source/LottieToWinComp/Brushes.cs Resolved
Comment thread source/LottieToWinComp/Brushes.cs Resolved
Comment thread source/LottieToWinComp/Rectangles.cs Resolved
Comment thread source/LottieToWinComp/Rectangles.cs Resolved
Comment thread source/LottieToWinComp/Rectangles.cs Resolved
Comment thread source/LottieToWinComp/Shapes.cs Resolved
Comment thread source/LottieToWinComp/Rectangles.cs Resolved

@eliezerpMS eliezerpMS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

πŸ•

Comment thread source/LottieToWinComp/Brushes.cs Resolved
@aborziak-ms

aborziak-ms commented Jun 14, 2021 •

Copy link
Copy Markdown
Collaborator Author

Ok, so I moved OriginOffset to ShapeLayerContainer, now it looks kind of better in Brushes.cs, Shapes.cs. But now we have this weird line (Rectangles.cs:333) context.LayerContext.OriginOffset = null; because we need to cleanup the offset before exiting this scope.


In reply to: 860911730

Comment thread source/LottieToWinComp/Brushes.cs Resolved
@eliezerpMS

Copy link
Copy Markdown
Contributor

In TranslateAndApplyShapeContextWithTrimOffset in Shapes.cs before you call "Brushes.TranslateAndApplyStroke(context, context.Stroke, shape, context.Opacity);" Do you need to call do the clearing out of OriginOffset here instead? It looks like TranslateAndApplyStroke can hit the linear gradient code but I assume it does not need the offset stuff factored in. If you do put the clearing here then also put a comment about how the offset is only needed for shape fills.


In reply to: 860911730

@aborziak-ms

aborziak-ms commented Jun 14, 2021 •

Copy link
Copy Markdown
Collaborator Author

In TranslateAndApplyShapeContextWithTrimOffset in Shapes.cs before you call "Brushes.TranslateAndApplyStroke(context, context.Stroke, shape, context.Opacity);" Do you need to call do the clearing out of OriginOffset here instead? It looks like TranslateAndApplyStroke can hit the linear gradient code but I assume it does not need the offset stuff factored in. If you do put the clearing here then also put a comment about how the offset is only needed for shape fills.

Agree, done


In reply to: 860968161

@eliezerpMS eliezerpMS left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:shipit:

@aborziak-ms
aborziak-ms merged commit d87f131 into master Jun 14, 2021
@delete-merged-branch
delete-merged-branch Bot deleted the user/aborziak-ms/rectangles-gradient-fill-fix branch June 14, 2021 23:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants