Skip to content

Commit 83e0941

Browse files
committed
Added the rest of the sweep gradient shader arguments
- Closes #656
1 parent 1f6f568 commit 83e0941

File tree

5 files changed

+66
-12
lines changed

5 files changed

+66
-12
lines changed

binding/Binding/SKShader.cs

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,28 +112,38 @@ public static SKShader CreateRadialGradient (SKPoint center, float radius, SKCol
112112
}
113113

114114
public static SKShader CreateSweepGradient (SKPoint center, SKColor [] colors, float [] colorPos)
115+
{
116+
return CreateSweepGradient (center, colors, colorPos, SKShaderTileMode.Clamp, 0, 360);
117+
}
118+
119+
public static SKShader CreateSweepGradient (SKPoint center, SKColor [] colors, float [] colorPos, SKMatrix localMatrix)
120+
{
121+
return CreateSweepGradient (center, colors, colorPos, SKShaderTileMode.Clamp, 0, 360, localMatrix);
122+
}
123+
124+
public static SKShader CreateSweepGradient (SKPoint center, SKColor [] colors, float [] colorPos, SKShaderTileMode tileMode, float startAngle, float endAngle)
115125
{
116126
if (colors == null)
117127
throw new ArgumentNullException (nameof (colors));
118128
if (colorPos == null) {
119-
return GetObject<SKShader> (SkiaApi.sk_shader_new_sweep_gradient (ref center, colors, IntPtr.Zero, colors.Length, IntPtr.Zero));
129+
return GetObject<SKShader> (SkiaApi.sk_shader_new_sweep_gradient (ref center, colors, IntPtr.Zero, colors.Length, tileMode, startAngle, endAngle, IntPtr.Zero));
120130
} else {
121131
if (colors.Length != colorPos.Length)
122132
throw new ArgumentException ("The number of colors must match the number of color positions.");
123-
return GetObject<SKShader> (SkiaApi.sk_shader_new_sweep_gradient (ref center, colors, colorPos, colors.Length, IntPtr.Zero));
133+
return GetObject<SKShader> (SkiaApi.sk_shader_new_sweep_gradient (ref center, colors, colorPos, colors.Length, tileMode, startAngle, endAngle, IntPtr.Zero));
124134
}
125135
}
126136

127-
public static SKShader CreateSweepGradient (SKPoint center, SKColor [] colors, float [] colorPos, SKMatrix localMatrix)
137+
public static SKShader CreateSweepGradient (SKPoint center, SKColor [] colors, float [] colorPos, SKShaderTileMode tileMode, float startAngle, float endAngle, SKMatrix localMatrix)
128138
{
129139
if (colors == null)
130140
throw new ArgumentNullException (nameof (colors));
131141
if (colorPos == null) {
132-
return GetObject<SKShader> (SkiaApi.sk_shader_new_sweep_gradient (ref center, colors, IntPtr.Zero, colors.Length, ref localMatrix));
142+
return GetObject<SKShader> (SkiaApi.sk_shader_new_sweep_gradient (ref center, colors, IntPtr.Zero, colors.Length, tileMode, startAngle, endAngle, ref localMatrix));
133143
} else {
134144
if (colors.Length != colorPos.Length)
135145
throw new ArgumentException ("The number of colors must match the number of color positions.");
136-
return GetObject<SKShader> (SkiaApi.sk_shader_new_sweep_gradient (ref center, colors, colorPos, colors.Length, ref localMatrix));
146+
return GetObject<SKShader> (SkiaApi.sk_shader_new_sweep_gradient (ref center, colors, colorPos, colors.Length, tileMode, startAngle, endAngle, ref localMatrix));
137147
}
138148
}
139149

binding/Binding/SkiaApi.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -939,9 +939,9 @@ internal static class SkiaApi
939939
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
940940
public extern static sk_shader_t sk_shader_new_radial_gradient(ref SKPoint center, float radius, [In] SKColor[] colors, float[] colorPos, int count, SKShaderTileMode mode, IntPtr matrixZero);
941941
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
942-
public extern static sk_shader_t sk_shader_new_sweep_gradient(ref SKPoint center, [In] SKColor[] colors, float[] colorPos, int count, IntPtr matrixZero);
942+
public extern static sk_shader_t sk_shader_new_sweep_gradient(ref SKPoint center, [In] SKColor[] colors, float[] colorPos, int count, SKShaderTileMode mode, float startAngle, float endAngle, IntPtr matrixZero);
943943
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
944-
public extern static sk_shader_t sk_shader_new_sweep_gradient(ref SKPoint center, [In] SKColor[] colors, float[] colorPos, int count, ref SKMatrix matrixZero);
944+
public extern static sk_shader_t sk_shader_new_sweep_gradient(ref SKPoint center, [In] SKColor[] colors, float[] colorPos, int count, SKShaderTileMode mode, float startAngle, float endAngle, ref SKMatrix matrixZero);
945945
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
946946
public extern static sk_shader_t sk_shader_new_two_point_conical_gradient(ref SKPoint start, float startRadius, ref SKPoint end, float endRadius, [In] SKColor[] colors, float[] colorPos, int count, SKShaderTileMode mode, ref SKMatrix matrix);
947947
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
@@ -955,9 +955,9 @@ internal static class SkiaApi
955955
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
956956
public extern static sk_shader_t sk_shader_new_radial_gradient(ref SKPoint center, float radius, [In] SKColor[] colors, IntPtr colorPosZero, int count, SKShaderTileMode mode, IntPtr matrixZero);
957957
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
958-
public extern static sk_shader_t sk_shader_new_sweep_gradient(ref SKPoint center, [In] SKColor[] colors, IntPtr colorPosZero, int count, IntPtr matrixZero);
958+
public extern static sk_shader_t sk_shader_new_sweep_gradient(ref SKPoint center, [In] SKColor[] colors, IntPtr colorPosZero, int count, SKShaderTileMode mode, float startAngle, float endAngle, IntPtr matrixZero);
959959
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
960-
public extern static sk_shader_t sk_shader_new_sweep_gradient(ref SKPoint center, [In] SKColor[] colors, IntPtr colorPosZero, int count, ref SKMatrix matrixZero);
960+
public extern static sk_shader_t sk_shader_new_sweep_gradient(ref SKPoint center, [In] SKColor[] colors, IntPtr colorPosZero, int count, SKShaderTileMode mode, float startAngle, float endAngle, ref SKMatrix matrixZero);
961961
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]
962962
public extern static sk_shader_t sk_shader_new_two_point_conical_gradient(ref SKPoint start, float startRadius, ref SKPoint end, float endRadius, [In] SKColor[] colors, IntPtr colorPosZero, int count, SKShaderTileMode mode, ref SKMatrix matrix);
963963
[DllImport(SKIA, CallingConvention = CallingConvention.Cdecl)]

tests/Tests/SKBitmapTest.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -252,8 +252,6 @@ public void TestExtractAlpha()
252252
Assert.True(bitmap.ExtractAlpha(alpha, paint, out offset));
253253

254254
Assert.Equal(new SKPointI(-12, -12), offset);
255-
256-
SaveBitmap(alpha);
257255
}
258256

259257
[SkippableFact]

tests/Tests/SKShaderTest.cs

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
using Xunit;
2+
3+
namespace SkiaSharp.Tests
4+
{
5+
public class SKShaderTest : SKTest
6+
{
7+
[SkippableFact]
8+
public void CanDrawWithCreateSweepGradientShader()
9+
{
10+
var size = 160;
11+
var colors = new[] { SKColors.Blue, SKColors.Yellow, SKColors.Green };
12+
var pos = new[] { 0.0f, 0.25f, 0.50f };
13+
var modes = new[] { SKShaderTileMode.Clamp, SKShaderTileMode.Repeat, SKShaderTileMode.Mirror };
14+
15+
var angles = new[] {
16+
(start: -330, end: -270),
17+
(start: 30, end: 90),
18+
(start: 390, end: 450),
19+
(start: -30, end: 800),
20+
};
21+
22+
using (var bitmap = new SKBitmap(new SKImageInfo(690, 512)))
23+
using (var canvas = new SKCanvas(bitmap))
24+
using (var p = new SKPaint())
25+
{
26+
var r = SKRect.Create(size, size);
27+
28+
foreach (var mode in modes)
29+
{
30+
using (new SKAutoCanvasRestore(canvas, true))
31+
{
32+
foreach (var angle in angles)
33+
{
34+
p.Shader = SKShader.CreateSweepGradient(new SKPoint(size / 2f, size / 2f), colors, pos, mode, angle.start, angle.end);
35+
36+
canvas.DrawRect(r, p);
37+
canvas.Translate(size * 1.1f, 0);
38+
}
39+
}
40+
41+
canvas.Translate(0, size * 1.1f);
42+
}
43+
}
44+
}
45+
}
46+
}

0 commit comments

Comments
 (0)