Fix rendering issue in fillRoundRect/strokeRoundRect #91
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There is a problem in AndroidCanvas.fillRoundRect() related to gradient fills.
Here's a test that fills some round rects using a linear gradient:
This is how it should look like:
This is how it looks like in Android:
The problem is that the origin for the gradient fill is reset to the origin of each shape (see the rectangle in the bottom right).
This seems to be due to the current implementation of AndroidCanvas.fillRoundRect, which translates the canvas, draws using a rect at (0, 0), and then translates it back. The translation is what is causing the issue with gradient fills.
The translate calls were introduced in this commit to fix a bug when the rect supplied to drawRoundRect had non-zero x or y. However, the problem was actually related to the coords passed to the rect (the two last parameters should be the right and bottom coords, not the width and height).
This PR fixes this issue by passing the right coords to the rect and removing the translate calls.
Another option would be to use the drawRoundRect method that takes (x, y, width, height) instead of a Rect, and avoid the creation of an intermediate Rect. However this was introduced in API level 21 which doesn't work if building PlayN using Maven (android.version is currently set to 4.1.1.4, which is the latest version available in Maven central).