-
Notifications
You must be signed in to change notification settings - Fork 742
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Added CompositionLinearGradientBrush implementation
- Loading branch information
1 parent
38db8d6
commit ab93de0
Showing
4 changed files
with
90 additions
and
16 deletions.
There are no files selected for viewing
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
30 changes: 30 additions & 0 deletions
30
src/Uno.UWP/UI/Composition/CompositionLinearGradientBrush.cs
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,30 @@ | ||
#nullable enable | ||
|
||
using System.Numerics; | ||
|
||
namespace Windows.UI.Composition | ||
{ | ||
public partial class CompositionLinearGradientBrush : CompositionGradientBrush | ||
{ | ||
private Vector2 _startPoint = Vector2.Zero; | ||
private Vector2 _endPoint = new Vector2(1, 0); | ||
|
||
internal CompositionLinearGradientBrush(Compositor compositor) | ||
: base(compositor) | ||
{ | ||
|
||
} | ||
|
||
public Vector2 StartPoint | ||
{ | ||
get => _startPoint; | ||
set => SetProperty(ref _startPoint, value); | ||
} | ||
|
||
public Vector2 EndPoint | ||
{ | ||
get => _endPoint; | ||
set => SetProperty(ref _endPoint, value); | ||
} | ||
} | ||
} |
50 changes: 50 additions & 0 deletions
50
src/Uno.UWP/UI/Composition/CompositionLinearGradientBrush.skia.cs
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,50 @@ | ||
#nullable enable | ||
|
||
using SkiaSharp; | ||
|
||
namespace Windows.UI.Composition | ||
{ | ||
public partial class CompositionLinearGradientBrush | ||
{ | ||
private protected override void UpdatePaintCore(SKPaint paint, SKRect bounds) | ||
{ | ||
var startPoint = StartPoint.ToSKPoint(); | ||
var endPoint = EndPoint.ToSKPoint(); | ||
var transform = CreateTransformMatrix(bounds); | ||
|
||
// Transform the points into absolute coordinates. | ||
if (MappingMode == CompositionMappingMode.Relative) | ||
{ | ||
// If mapping is relative to bounding box, multiply points by bounds. | ||
startPoint.X *= (float)bounds.Width; | ||
startPoint.Y *= (float)bounds.Height; | ||
|
||
endPoint.X *= (float)bounds.Width; | ||
endPoint.Y *= (float)bounds.Height; | ||
} | ||
|
||
// Translate gradient points by bounds offset. | ||
startPoint.X += bounds.Left; | ||
startPoint.Y += bounds.Top; | ||
|
||
endPoint.X += bounds.Left; | ||
endPoint.Y += bounds.Top; | ||
// | ||
|
||
// Create linear gradient shader. | ||
var shader = SKShader.CreateLinearGradient( | ||
startPoint, endPoint, | ||
Colors, ColorPositions, | ||
TileMode, transform); | ||
|
||
// Clean up old shader | ||
if (paint.Shader != null) | ||
{ | ||
paint.Shader.Dispose(); | ||
paint.Shader = null; | ||
} | ||
|
||
paint.Shader = shader; | ||
} | ||
} | ||
} |