From: Jean-Philippe Bruyère Date: Mon, 2 Aug 2021 13:19:08 +0000 (+0200) Subject: reenable gradients, in vkvg also X-Git-Tag: v0.9.5-beta~4 X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=cee024384ea23e3bd965b8baad2705d607670c03;p=jp%2Fcrow.git reenable gradients, in vkvg also --- diff --git a/Crow/src/Fill/Gradient.cs b/Crow/src/Fill/Gradient.cs index d0b4b653..7fe3d4c1 100644 --- a/Crow/src/Fill/Gradient.cs +++ b/Crow/src/Fill/Gradient.cs @@ -60,7 +60,7 @@ namespace Crow public override void SetAsSource (Interface iFace, Context ctx, Rectangle bounds = default(Rectangle)) { - /*Cairo.Gradient grad = null; + Crow.Drawing.Gradient grad = null; switch (GradientType) { case Type.Vertical: grad = new LinearGradient (bounds.Left, bounds.Top, bounds.Left, bounds.Bottom); @@ -82,7 +82,7 @@ namespace Crow } ctx.SetSource (grad); - grad.Dispose ();*/ + grad.Dispose (); } #endregion diff --git a/Crow/src/GraphicBackends/Mono.Cairo/Gradient.cs b/Crow/src/GraphicBackends/Mono.Cairo/Gradient.cs index c7d2ea32..c9b8116c 100644 --- a/Crow/src/GraphicBackends/Mono.Cairo/Gradient.cs +++ b/Crow/src/GraphicBackends/Mono.Cairo/Gradient.cs @@ -37,11 +37,6 @@ namespace Crow.Drawing { { } - [Obsolete] - protected Gradient () - { - } - public int ColorStopCount { get { int cnt; diff --git a/Crow/src/GraphicBackends/vkvg/Gradient.cs b/Crow/src/GraphicBackends/vkvg/Gradient.cs new file mode 100644 index 00000000..9f6bed2d --- /dev/null +++ b/Crow/src/GraphicBackends/vkvg/Gradient.cs @@ -0,0 +1,29 @@ +// Copyright (c) 2018-2021 Jean-Philippe Bruyère +// +// This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) + +using System; +namespace Crow.Drawing +{ + public class Gradient : Pattern + { + protected Gradient(IntPtr handle) : base (handle) { } + public void AddColorStop (double offset, Crow.Color c) + => NativeMethods.vkvg_pattern_add_color_stop(handle, (float)offset, c.R / 255f, c.G / 255f, c.B / 255f, c.A / 255f); + public void AddColorStop(float offset, float r, float g, float b, float a = 1f) + => NativeMethods.vkvg_pattern_add_color_stop(handle, offset, r, g, b, a); + } + public class LinearGradient : Gradient { + public LinearGradient (float x0, float y0, float x1, float y1) + : base (NativeMethods.vkvg_pattern_create_linear(x0, y0, x1, y1)) { + + } + } + public class RadialGradient : Gradient { + public RadialGradient ( float cx0, float cy0, float radius0, + float cx1, float cy1, float radius1) + : base (NativeMethods.vkvg_pattern_create_radial(cx0, cy0, radius0, cx1, cy1, radius1)) { + + } + } +} \ No newline at end of file diff --git a/Crow/src/GraphicBackends/vkvg/Pattern.cs b/Crow/src/GraphicBackends/vkvg/Pattern.cs index 57401419..b25e26b2 100644 --- a/Crow/src/GraphicBackends/vkvg/Pattern.cs +++ b/Crow/src/GraphicBackends/vkvg/Pattern.cs @@ -1,92 +1,72 @@ -// Copyright (c) 2018-2020 Jean-Philippe Bruyère +// Copyright (c) 2018-2021 Jean-Philippe Bruyère // // This code is licensed under the MIT license (MIT) (http://opensource.org/licenses/MIT) using System; namespace Crow.Drawing { - public class Pattern : IDisposable - { + public class Pattern : IDisposable + { + protected IntPtr handle = IntPtr.Zero; - IntPtr handle = IntPtr.Zero; + #region CTORS & DTOR + protected Pattern(IntPtr handle) + { + this.handle = handle; + } + public Pattern(float r, float g, float b) + { + handle = NativeMethods.vkvg_pattern_create_rgb(r, g, b); + } + public Pattern(float r, float g, float b, float a) + { + handle = NativeMethods.vkvg_pattern_create_rgba(r, g, b, a); + } + public Pattern(Surface surf) + { + handle = NativeMethods.vkvg_pattern_create_for_surface(surf.Handle); + } - #region CTORS & DTOR - protected Pattern(IntPtr handle) - { - this.handle = handle; - } - public Pattern() - { - handle = NativeMethods.vkvg_pattern_create(); - } - public Pattern(float r, float g, float b) - { - handle = NativeMethods.vkvg_pattern_create_rgb(r, g, b); - } - public Pattern(float r, float g, float b, float a) - { - handle = NativeMethods.vkvg_pattern_create_rgba(r, g, b, a); - } - public Pattern(Surface surf) - { - handle = NativeMethods.vkvg_pattern_create_for_surface(surf.Handle); - } + ~Pattern() + { + Dispose(false); + } + #endregion - ~Pattern() - { - Dispose(false); - } - #endregion + public void AddReference() + { + NativeMethods.vkvg_pattern_reference(handle); + } + public uint References() => NativeMethods.vkvg_pattern_get_reference_count(handle); - public static Pattern CreateLinearGradient(float x0, float y0, float x1, float y1) - { - return new Pattern(NativeMethods.vkvg_pattern_create_linear(x0, y0, x1, y1)); - } - public static Pattern CreateRadialGradient(float cx0, float cy0, float radius0, - float cx1, float cy1, float radius1) - { - return new Pattern(NativeMethods.vkvg_pattern_create_radial(cx0, cy0, radius0, cx1, cy1, radius1)); - } + public IntPtr Handle => handle; - public void AddReference() - { - NativeMethods.vkvg_pattern_reference(handle); - } - public uint References() => NativeMethods.vkvg_pattern_get_reference_count(handle); + public Extend Extend + { + set { NativeMethods.vkvg_pattern_set_extend(handle, value); } + get { return NativeMethods.vkvg_pattern_get_extend(handle); } + } + public Filter Filter + { + set { NativeMethods.vkvg_pattern_set_filter(handle, value); } + get { return NativeMethods.vkvg_pattern_get_filter(handle); } + } - public IntPtr Handle { get { return handle; } } + #region IDisposable implementation + public void Dispose() + { + Dispose(true); + GC.SuppressFinalize(this); + } - public Extend Extend - { - set { NativeMethods.vkvg_pattern_set_extend(handle, value); } - get { return NativeMethods.vkvg_pattern_get_extend(handle); } - } - public Filter Filter - { - set { NativeMethods.vkvg_pattern_set_filter(handle, value); } - get { return NativeMethods.vkvg_pattern_get_filter(handle); } - } + protected virtual void Dispose(bool disposing) + { + if (!disposing || handle == IntPtr.Zero) + return; - public void AddColorStop(float offset, float r, float g, float b, float a = 1f) - { - NativeMethods.vkvg_pattern_add_color_stop(handle, offset, r, g, b, a); - } - - #region IDisposable implementation - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (!disposing || handle == IntPtr.Zero) - return; - - NativeMethods.vkvg_pattern_destroy(handle); - handle = IntPtr.Zero; - } - #endregion - } + NativeMethods.vkvg_pattern_destroy(handle); + handle = IntPtr.Zero; + } + #endregion + } } \ No newline at end of file