-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(gradient): Added Radial Gradient for Android
- Loading branch information
1 parent
92aa150
commit 171f9e4
Showing
8 changed files
with
292 additions
and
216 deletions.
There are no files selected for viewing
370 changes: 186 additions & 184 deletions
370
src/SamplesApp/UITests.Shared/Windows_UI_Xaml_Media/GradientBrushTests/GradientsPage.xaml
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
using System.Linq; | ||
using Android.Graphics; | ||
using Uno.Extensions; | ||
using Uno.UI; | ||
using Point = Windows.Foundation.Point; | ||
|
||
namespace Windows.UI.Xaml.Media | ||
{ | ||
partial class RadialGradientBrush | ||
{ | ||
protected override Paint GetPaintInner(Windows.Foundation.Rect destinationRect) | ||
{ | ||
var paint = new Paint(); | ||
|
||
var center = Center; | ||
var radiusX = RadiusX; | ||
var radiusY = RadiusY; | ||
|
||
float radius; | ||
|
||
if (MappingMode == BrushMappingMode.RelativeToBoundingBox) | ||
{ | ||
var size = destinationRect.Size; | ||
|
||
center = new Point(center.X * size.Width, Center.Y * size.Height); | ||
radius = (float)(radiusX * size.Width + radiusY * size.Height) / 4.0f; // We take the avg | ||
} | ||
else | ||
{ | ||
center = center.LogicalToPhysicalPixels(); | ||
radius = ViewHelper.LogicalToPhysicalPixels((radiusX + radiusY) / 2.0d); // We take the avg | ||
} | ||
|
||
|
||
// Android RadialGradient requires two ore more stop points. | ||
if (GradientStops.Count >= 2) | ||
{ | ||
var colors = GradientStops.SelectToArray(s => ((Android.Graphics.Color)s.Color).ToArgb()); | ||
var locations = GradientStops.SelectToArray(s => (float)s.Offset); | ||
|
||
var width = destinationRect.Width; | ||
var height = destinationRect.Height; | ||
|
||
var transform = RelativeTransform?.ToNative(size: new Windows.Foundation.Size(width, height), isBrush: true); | ||
|
||
var shader = new RadialGradient( | ||
(float)center.X, | ||
(float)center.Y, | ||
radius, | ||
colors, | ||
locations, | ||
Shader.TileMode.Clamp); | ||
|
||
paint.SetShader(shader); | ||
} | ||
|
||
return paint; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters