From a3778ac07ef66760ff2f14b69b66c3b089567d93 Mon Sep 17 00:00:00 2001 From: Bill Holmes Date: Sat, 21 Nov 2015 08:33:19 -0500 Subject: [PATCH] Adding a gradient sample to the Forms app - Removing an unused count argument from CreateTwoPointConicalGradient - Bump the skia submodule to pick up the missing SK_API fix --- binding/Binding/SKShader.cs | 4 +-- binding/SkiaSharp.Portable/SkiaPortable.cs | 4 +-- samples/Skia.Forms.Demo/DrawHelpers.cs | 40 ++++++++++++++++++++++ samples/Skia.Forms.Demo/Skia.Forms.Demo.cs | 4 ++- skia | 2 +- 5 files changed, 48 insertions(+), 6 deletions(-) diff --git a/binding/Binding/SKShader.cs b/binding/Binding/SKShader.cs index c2420d804..27f1bf82c 100644 --- a/binding/Binding/SKShader.cs +++ b/binding/Binding/SKShader.cs @@ -69,12 +69,12 @@ namespace SkiaSharp return new SKShader (SkiaApi.sk_shader_new_sweep_gradient (ref center, colors, colorPos, colors.Length, ref localMatrix)); } - public static SKShader CreateTwoPointConicalGradient (SKPoint start, float startRadius, SKPoint end, float endRadius, SKColor [] colors, float [] colorPos, int count, SKShaderTileMode mode) + public static SKShader CreateTwoPointConicalGradient (SKPoint start, float startRadius, SKPoint end, float endRadius, SKColor [] colors, float [] colorPos, SKShaderTileMode mode) { return new SKShader (SkiaApi.sk_shader_new_two_point_conical_gradient (ref start, startRadius, ref end, endRadius, colors, colorPos, colors.Length, mode, IntPtr.Zero)); } - public static SKShader CreateTwoPointConicalGradient (SKPoint start, float startRadius, SKPoint end, float endRadius, SKColor [] colors, float [] colorPos, int count, SKShaderTileMode mode, SKMatrix localMatrix) + public static SKShader CreateTwoPointConicalGradient (SKPoint start, float startRadius, SKPoint end, float endRadius, SKColor [] colors, float [] colorPos, SKShaderTileMode mode, SKMatrix localMatrix) { return new SKShader (SkiaApi.sk_shader_new_two_point_conical_gradient (ref start, startRadius, ref end, endRadius, colors, colorPos, colors.Length, mode, ref localMatrix)); } diff --git a/binding/SkiaSharp.Portable/SkiaPortable.cs b/binding/SkiaSharp.Portable/SkiaPortable.cs index 7d156db69..6969ab481 100644 --- a/binding/SkiaSharp.Portable/SkiaPortable.cs +++ b/binding/SkiaSharp.Portable/SkiaPortable.cs @@ -373,8 +373,8 @@ public static SkiaSharp.SKShader CreateRadialGradient(SkiaSharp.SKPoint center, float radius, SkiaSharp.SKColor[] colors, System.Single[] colorPos, SkiaSharp.SKShaderTileMode mode, SkiaSharp.SKMatrix localMatrix) { return default(SkiaSharp.SKShader); } public static SkiaSharp.SKShader CreateSweepGradient(SkiaSharp.SKPoint center, SkiaSharp.SKColor[] colors, System.Single[] colorPos) { return default(SkiaSharp.SKShader); } public static SkiaSharp.SKShader CreateSweepGradient(SkiaSharp.SKPoint center, SkiaSharp.SKColor[] colors, System.Single[] colorPos, SkiaSharp.SKMatrix localMatrix) { return default(SkiaSharp.SKShader); } - public static SkiaSharp.SKShader CreateTwoPointConicalGradient(SkiaSharp.SKPoint start, float startRadius, SkiaSharp.SKPoint end, float endRadius, SkiaSharp.SKColor[] colors, System.Single[] colorPos, int count, SkiaSharp.SKShaderTileMode mode) { return default(SkiaSharp.SKShader); } - public static SkiaSharp.SKShader CreateTwoPointConicalGradient(SkiaSharp.SKPoint start, float startRadius, SkiaSharp.SKPoint end, float endRadius, SkiaSharp.SKColor[] colors, System.Single[] colorPos, int count, SkiaSharp.SKShaderTileMode mode, SkiaSharp.SKMatrix localMatrix) { return default(SkiaSharp.SKShader); } + public static SkiaSharp.SKShader CreateTwoPointConicalGradient(SkiaSharp.SKPoint start, float startRadius, SkiaSharp.SKPoint end, float endRadius, SkiaSharp.SKColor[] colors, System.Single[] colorPos, SkiaSharp.SKShaderTileMode mode) { return default(SkiaSharp.SKShader); } + public static SkiaSharp.SKShader CreateTwoPointConicalGradient(SkiaSharp.SKPoint start, float startRadius, SkiaSharp.SKPoint end, float endRadius, SkiaSharp.SKColor[] colors, System.Single[] colorPos, SkiaSharp.SKShaderTileMode mode, SkiaSharp.SKMatrix localMatrix) { return default(SkiaSharp.SKShader); } public void Dispose() { } protected virtual void Dispose(bool disposing) { } ~SKShader() { } diff --git a/samples/Skia.Forms.Demo/DrawHelpers.cs b/samples/Skia.Forms.Demo/DrawHelpers.cs index 0a658dcc2..1cd3c8824 100644 --- a/samples/Skia.Forms.Demo/DrawHelpers.cs +++ b/samples/Skia.Forms.Demo/DrawHelpers.cs @@ -129,7 +129,47 @@ namespace Skia.Forms.Demo canvas.DrawText ("Skia", 20.0f, 224.0f, paint); } + } + public static void DrawGradient (SKCanvas canvas, int width, int height) + { + var ltColor = SKColors.White; + var dkColor = SKColors.Black; + + using (var paint = new SKPaint ()) { + using (var shader = SKShader.CreateLinearGradient ( + new SKPoint (0, 0), + new SKPoint (0, height), + new [] {ltColor, dkColor}, + null, + SKShaderTileMode.Clamp)) { + + paint.Shader = shader; + canvas.DrawPaint (paint); + } + } + + // Center and Scale the Surface + var scale = (width < height ? width : height) / (240f); + canvas.Translate (width/2f, height/2f); + canvas.Scale (scale, scale); + canvas.Translate (-128, -128); + + using (var paint = new SKPaint ()) { + using (var shader = SKShader.CreateTwoPointConicalGradient ( + new SKPoint (115.2f, 102.4f), + 25.6f, + new SKPoint (102.4f, 102.4f), + 128.0f, + new [] {ltColor, dkColor}, + null, + SKShaderTileMode.Clamp + )) { + paint.Shader = shader; + + canvas.DrawOval (new SKRect (51.2f, 51.2f, 204.8f, 204.8f), paint); + } + } } } } diff --git a/samples/Skia.Forms.Demo/Skia.Forms.Demo.cs b/samples/Skia.Forms.Demo/Skia.Forms.Demo.cs index e243c81c8..fa98c7e31 100644 --- a/samples/Skia.Forms.Demo/Skia.Forms.Demo.cs +++ b/samples/Skia.Forms.Demo/Skia.Forms.Demo.cs @@ -21,7 +21,7 @@ namespace Skia.Forms.Demo BarTextColor = Xamarin.Forms.Color.White, }; - listView.ItemsSource = new [] {"Xamagon", "Text Sample"}; + listView.ItemsSource = new [] {"Xamagon", "Text Sample", "Gradient Sample"}; listView.ItemSelected += (sender, e) => { if (e.SelectedItem == null) return; @@ -41,6 +41,8 @@ namespace Skia.Forms.Demo return DrawHelpers.DrawXamagon; case "Text Sample": return DrawHelpers.TextSample; + case "Gradient Sample": + return DrawHelpers.DrawGradient; } throw new NotImplementedException (); diff --git a/skia b/skia index 2e74eb03d..fd370f013 160000 --- a/skia +++ b/skia @@ -1 +1 @@ -Subproject commit 2e74eb03db87ed53376401071c32315f92d8e3b3 +Subproject commit fd370f0131e526963a77eb528819101cdc8eb871