]> O.S.I.I.S - jp/crow.git/commitdiff
reenable gradients, in vkvg also
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 2 Aug 2021 13:19:08 +0000 (15:19 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 2 Aug 2021 13:19:08 +0000 (15:19 +0200)
Crow/src/Fill/Gradient.cs
Crow/src/GraphicBackends/Mono.Cairo/Gradient.cs
Crow/src/GraphicBackends/vkvg/Gradient.cs [new file with mode: 0644]
Crow/src/GraphicBackends/vkvg/Pattern.cs

index d0b4b6537782efa2ddfe5cb51c95d2608750d2a0..7fe3d4c1ccb66c072b65e80712b9f3004901490c 100644 (file)
@@ -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
 
index c7d2ea32df4fda8e9df65cfa8559f9c4e891bd22..c9b8116cf20d1d491385d721c5e70ac9b5ff2888 100644 (file)
@@ -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 (file)
index 0000000..9f6bed2
--- /dev/null
@@ -0,0 +1,29 @@
+// Copyright (c) 2018-2021  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+//
+// 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
index 57401419206d48c697f27c129df82407ec60969e..b25e26b246bd5d639d94b8c5f5fb8197f41c29ed 100644 (file)
@@ -1,92 +1,72 @@
-// Copyright (c) 2018-2020  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
+// Copyright (c) 2018-2021  Jean-Philippe Bruyère <jp_bruyere@hotmail.com>
 //
 // 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