]> O.S.I.I.S - jp/crow.git/commitdiff
wip vkvg2
authorJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 19 Jul 2021 15:00:22 +0000 (17:00 +0200)
committerJean-Philippe Bruyère <jp_bruyere@hotmail.com>
Mon, 19 Jul 2021 15:00:22 +0000 (17:00 +0200)
36 files changed:
Crow/Default.style
Crow/src/Cairo/CairoHelpers.cs
Crow/src/DebugUtils/DbgEvtType.cs
Crow/src/DebugUtils/DebugLogger.cs
Crow/src/DebugUtils/PerformanceMeasure.cs
Crow/src/Fill/BmpPicture.cs
Crow/src/Fill/Picture.cs
Crow/src/Fill/SvgPicture.cs
Crow/src/GraphicBackends/Mono.Cairo/Region.cs
Crow/src/GraphicBackends/Mono.Cairo/rsvg/DimensionData.cs [new file with mode: 0644]
Crow/src/GraphicBackends/Mono.Cairo/rsvg/SvgHandle.cs [new file with mode: 0644]
Crow/src/GraphicBackends/vkvg/Context.cs
Crow/src/GraphicBackends/vkvg/NativeMethods.cs
Crow/src/GraphicBackends/vkvg/Surface.cs
Crow/src/GraphicBackends/vkvg/SvgHandle.cs [new file with mode: 0644]
Crow/src/GraphicBackends/vkvg/VulkanContext.cs
Crow/src/GraphicBackends/vkvg/tmp/Region.cs
Crow/src/Interface.cs
Crow/src/Widgets/Border.cs
Crow/src/Widgets/Expandable.cs
Crow/src/Widgets/GroupBase.cs
Crow/src/Widgets/Image.cs
Crow/src/Widgets/Label.cs
Crow/src/Widgets/PrivateContainer.cs
Crow/src/Widgets/Scroller.cs
Crow/src/Widgets/Shape.cs
Crow/src/Widgets/TemplatedControl.cs
Crow/src/Widgets/Widget.cs
Crow/src/rsvg/DimensionData.cs [deleted file]
Crow/src/rsvg/Handle.cs [deleted file]
Samples/BasicTests/BasicTests.cs
Samples/HelloWorld/main.cs
Samples/common/samples.style
Samples/common/ui/Interfaces/Divers/welcome.crow
Samples/common/ui/Interfaces/Stack/StretchedInFit4.crow
Samples/common/ui/Interfaces/TemplatedControl/testEnumSelector.crow

index 46de42c963951b9a6360bd9f2779cf7d4b611b88..428939a03f5c88a0e5e30f770ad61dc9c0bbca3a 100644 (file)
@@ -319,7 +319,7 @@ TableHeaderLabel {
 }
 
 Button, CheckBox, RadioButton, ComboBox, Expandable,
-MessageBox, Popper, Slider, Spinner, TextBox, NumericControl {
+MessageBox, Popper, Slider, Spinner, TextBox, NumericControl, EnumSelector {
        //Focusable = "true";
        Foreground="${ControlForeground}";
        Height = "Fit";
@@ -328,6 +328,9 @@ MessageBox, Popper, Slider, Spinner, TextBox, NumericControl {
        Margin="0";
        BubbleMouseEvent="MouseWheel|Keyboard";
 }
-//TemplatedControl, GenericStack {
-//     CacheEnabled="true";
-//}
\ No newline at end of file
+TemplatedGroup {
+       UseLoadingThread = "false";
+}
+TemplatedControl, GenericStack {
+       CacheEnabled="true";
+}
\ No newline at end of file
index 129879a14b47b570f53cf603c643929ddcc9321e..2903b73c1cf4f005e24f81b4572b5011df984c67 100644 (file)
@@ -64,7 +64,7 @@ namespace Crow
         }
         public static void DrawRoundedRectangle(Context gr, double x, double y, double width, double height, double radius)
         {
-            gr.Save();
+            //gr.Save();
 
             if ((radius > height / 2) || (radius > width / 2))
                 radius = min(height / 2, width / 2);
@@ -78,11 +78,11 @@ namespace Crow
             gr.LineTo(x + radius, y + height);
             gr.Arc(x + radius, y + height - radius, radius, Math.PI / 2, Math.PI);
             gr.ClosePath();
-            gr.Restore();
+            //gr.Restore();
         }
         public static void StrokeRaisedRectangle(Context gr, Rectangle r, double width = 1)
         {
-            gr.Save();
+            //gr.Save();
             r.Inflate((int)-width / 2, (int)-width / 2);
             gr.LineWidth = width;
                        gr.SetSource(Colors.White);
@@ -97,11 +97,11 @@ namespace Crow
             gr.LineTo(r.BottomLeft);
             gr.Stroke();
 
-            gr.Restore();
+            //gr.Restore();
         }
         public static void StrokeLoweredRectangle(Context gr, Rectangle r, double width = 1)
         {
-            gr.Save();
+            //gr.Save();
             r.Inflate((int)-width / 2, (int)-width / 2);
             gr.LineWidth = width;
                        gr.SetSource(Colors.DarkGrey);
@@ -115,7 +115,7 @@ namespace Crow
             gr.LineTo(r.BottomLeft);
             gr.Stroke();
 
-            gr.Restore();
+            //gr.Restore();
         }
     }
 }
index be7f66dd5ae17cfae904e6d944001ffba17888a1..1b56d77ab27e9d35baffd71e82b25480e444f70a 100644 (file)
@@ -75,6 +75,8 @@ namespace Crow
                GOUpdateCache                                   = Widget | Drawing | 0x03,
                GOPaintCache                                    = Widget | Drawing | 0x04,              
                GOPaint                                                 = Widget | Drawing | 0x05,
+               GOCreateSurface                                 = Widget | Drawing | 0x06,
+               GOCreateContext                                 = Widget | Drawing | 0x07,
 
                GOLockUpdate                                    = Widget | Lock | 0x01,
                GOLockClipping                                  = Widget | Lock | 0x02,
index b773b99074627f339c244676efbf66401279443c..07313382173bb07c958976e09c8ccce49dc25ff3 100644 (file)
@@ -265,7 +265,7 @@ lock (logMutex) {
                public static void Save(Interface iface, string dbgLogFilePath = "debug.log") {
 #if DEBUG_LOG
                        using (Stream stream = new FileStream (dbgLogFilePath, FileMode.Create, FileAccess.Write))
-                               Save (iface, stream);
+                               Save (iface, stream, 0);
                        Console.WriteLine ($"Crow Debug Log saved to: {System.IO.Path.GetFullPath(dbgLogFilePath)}");
 #endif
                }
index f4cf76a8d7f5a9b0f504dbcc3a82048298d09841..8cd72d97281307a13260b3f98b7f926eb4a36d26 100644 (file)
@@ -29,7 +29,7 @@ namespace Crow
                public static void InitMeasures () {
                        Measures = new PerformanceMeasure[4];
                        Measures[(int)Kind.Update] = new PerformanceMeasure (Kind.Update, 1);
-                       Measures[(int)Kind.Clipping] = new PerformanceMeasure (Kind.Clipping, 1);
+                       Measures[(int)Kind.Clipping] = new PerformanceMeasure (Kind.Clipping, 0);
                        Measures[(int)Kind.Layouting] = new PerformanceMeasure (Kind.Layouting, 1);
                        Measures[(int)Kind.Drawing] = new PerformanceMeasure (Kind.Drawing, 1);
                }
index 8284e3a15e84836be84030113661cd7780016df3..4a6291057223bd789a341524360151e9a7a76eb3 100644 (file)
@@ -34,7 +34,7 @@ namespace Crow
                /// <summary>
                /// load the image for rendering from the path given as argument
                /// </summary>
-               void load (Interface iFace) {
+               public override void load (Interface iFace) {
                        if (iFace.sharedPictures.ContainsKey (Path)) {
                                sharedPicture sp = iFace.sharedPictures[Path];
                                image = (byte[])sp.Data;
@@ -51,6 +51,9 @@ namespace Crow
 #if STB_SHARP
                        StbImageSharp.ImageResult stbi = StbImageSharp.ImageResult.FromStream (stream, StbImageSharp.ColorComponents.RedGreenBlueAlpha);
                        image = new byte[stbi.Data.Length];
+       #if VKVG
+                       Array.Copy (stbi.Data, image, stbi.Data.Length);
+       #else
                        //rgba to argb for cairo.
                        for (int i = 0; i < stbi.Data.Length; i += 4) {
                                image[i] = stbi.Data[i + 2];
@@ -58,17 +61,22 @@ namespace Crow
                                image[i + 2] = stbi.Data[i];
                                image[i + 3] = stbi.Data[i + 3];
                        }
+       #endif
                        Dimensions = new Size (stbi.Width, stbi.Height);
 #else
                                using (StbImage stbi = new StbImage (stream)) {
                                        image = new byte [stbi.Size];
-                                       //rgba to argb for cairo.
+       #if VKVG
+                                       Marshal.Copy (stbi.Handle, image, 0, stbi.Size);
+       #else
                                        for (int i = 0; i < stbi.Size; i+=4) {
+                                               //rgba to argb for cairo. ???? looks like bgra to me.
                                                image [i] = Marshal.ReadByte (stbi.Handle, i + 2);
                                                image [i + 1] = Marshal.ReadByte (stbi.Handle, i + 1);
                                                image [i + 2] = Marshal.ReadByte (stbi.Handle, i);
                                                image [i + 3] = Marshal.ReadByte (stbi.Handle, i + 3);
                                        }
+       #endif
                                        Dimensions = new Size (stbi.Width, stbi.Height);
                                }
 #endif
@@ -102,7 +110,7 @@ namespace Crow
                }*/
 
                #region implemented abstract members of Fill
-
+               public override bool IsLoaded => image != null;
                public override void SetAsSource (Interface iFace, Context ctx, Rectangle bounds = default(Rectangle))
                {
                        if (image == null)
@@ -133,7 +141,7 @@ namespace Crow
                                        gr.Scale (widthRatio, heightRatio);
                                        gr.Translate ((bounds.Width/widthRatio - Dimensions.Width)/2, (bounds.Height/heightRatio - Dimensions.Height)/2);
 #if VKVG
-                                       using (Surface imgSurf = new Surface (iFace.vkvgDevice, ref image, Dimensions.Width, Dimensions.Height)) 
+                                       using (Surface imgSurf = new Surface (iFace.vkvgDevice, image, Dimensions.Width, Dimensions.Height)) 
 #else
                                        using (Surface imgSurf = new ImageSurface (image, Format.Argb32, Dimensions.Width, Dimensions.Height, 4 * Dimensions.Width)) 
 #endif
@@ -174,22 +182,26 @@ namespace Crow
                                        widthRatio = heightRatio;
                        }
 
-                       gr.Save ();
+                       //gr.Save ();
+
+                       Matrix m = gr.Matrix;
 
                        gr.Translate (rect.Left,rect.Top);
                        gr.Scale (widthRatio, heightRatio);
                        gr.Translate ((rect.Width/widthRatio - Dimensions.Width)/2, (rect.Height/heightRatio - Dimensions.Height)/2);
 
 #if VKVG
-                       using (Surface imgSurf = new Surface (iFace.vkvgDevice, ref image, Dimensions.Width, Dimensions.Height)) 
+                       using (Surface imgSurf = new Surface (iFace.vkvgDevice, image, Dimensions.Width, Dimensions.Height)) 
 #else
                        using (Surface imgSurf = new ImageSurface (image, Format.Argb32, Dimensions.Width, Dimensions.Height, 4 * Dimensions.Width)) 
 #endif                 
-                       {
+                       {                               
                                gr.SetSource (imgSurf, 0,0);
                                gr.Paint ();
                        }
-                       gr.Restore ();
+
+                       gr.Matrix = m;
+                       //gr.Restore ();
                }
        }
 }
index 8c885bc87f37203e2d08239eb90cf8608bc1e8d0..07da3fb4a490dd71d7e570b4479aabc8c3450081 100644 (file)
@@ -62,7 +62,7 @@ namespace Crow
                /// <summary>
                /// unscaled dimensions fetched on loading
                /// </summary>
-               public Size Dimensions;
+               public Size Dimensions { get; protected set; }
                /// <summary>
                /// if true and image has to be scalled, it will be scaled in both direction
                /// equaly
@@ -98,7 +98,8 @@ namespace Crow
                /// <param name="rect">bounds of the target surface to paint</param>
                /// <param name="subPart">used for svg only</param>
                public abstract void Paint(Interface iFace, Context ctx, Rectangle rect, string subPart = "");
-
+               public abstract bool IsLoaded { get; }
+               public abstract void load (Interface iface);
                #region Operators
                public static implicit operator Picture(string path) => Parse (path) as Picture;
                public static implicit operator string(Picture _pic) => _pic == null ? null : _pic.Path;
index 1f1bb12e31f39c90b15bbd76dd00f7fe182a7b16..0c7e8d62cc9caf1aa920537884c53fbc6f966822 100644 (file)
@@ -17,7 +17,7 @@ namespace Crow
        /// </summary>
        public class SvgPicture : Picture
        {
-               Rsvg.Handle hSVG;
+               SvgHandle hSVG;
 
                #region CTOR
                /// <summary>
@@ -31,45 +31,49 @@ namespace Crow
                public SvgPicture (string path) : base(path) {}
                #endregion
 
-               bool load (Interface iFace)
+               public override void load (Interface iFace)
                {
-                       if (string.IsNullOrEmpty(Path))
-                               return false;
                        if (iFace.sharedPictures.ContainsKey (Path)) {
                                sharedPicture sp = iFace.sharedPictures [Path];
-                               hSVG = (Rsvg.Handle)sp.Data;
+                               hSVG = (SvgHandle)sp.Data;
                                Dimensions = sp.Dims;
-                               return true;
+                               return;
                        }
                        using (Stream stream = iFace.GetStreamFromPath (Path))
-                               load (stream);
+                               load (iFace, stream);
                        iFace.sharedPictures [Path] = new sharedPicture (hSVG, Dimensions);
-                       return true;
                }
-               void load (Stream stream) {
+               void load (Interface iface, Stream stream) {
                        using (BinaryReader sr = new BinaryReader (stream)) {
-                               hSVG = new Rsvg.Handle (sr.ReadBytes ((int)stream.Length));
-                               Dimensions = new Size (hSVG.Dimensions.Width, hSVG.Dimensions.Height);
+#if VKVG
+                               hSVG = new SvgHandle (iface.vkvgDevice, sr.ReadBytes ((int)stream.Length));
+#else
+                               hSVG = new SvgHandle (sr.ReadBytes ((int)stream.Length));
+#endif
+                               Dimensions = hSVG.Dimensions;
                        }
                }
-               internal static sharedPicture CreateSharedPicture (Stream stream) {
+               internal static sharedPicture CreateSharedPicture (Interface iface, Stream stream) {
                        SvgPicture pic = new SvgPicture ();
-                       pic.load (stream);
+                       pic.load (iface, stream);
                        return new sharedPicture (pic.hSVG, pic.Dimensions);
                }
 
-               public void LoadSvgFragment (string fragment) {                 
-                       hSVG = new Rsvg.Handle (System.Text.Encoding.Unicode.GetBytes(fragment));
+               public void LoadSvgFragment (Interface iface, string fragment) {                        
+#if VKVG
+                       hSVG = new SvgHandle (iface.vkvgDevice, System.Text.Encoding.Unicode.GetBytes(fragment));
+#else
+                       hSVG = new SvgHandle (System.Text.Encoding.Unicode.GetBytes(fragment));
+#endif
                        Dimensions = new Size (hSVG.Dimensions.Width, hSVG.Dimensions.Height);
                }
 
                #region implemented abstract members of Fill
-
+               public override bool IsLoaded => hSVG != null;
                public override void SetAsSource (Interface iFace, Context ctx, Rectangle bounds = default(Rectangle))
                {
                        if (hSVG == null)
-                               if (!load (iFace))
-                                       return;
+                               load (iFace);
 
                        float widthRatio = 1f;
                        float heightRatio = 1f;
@@ -86,16 +90,20 @@ namespace Crow
                                        widthRatio = heightRatio;
                        }
 
-                       /*using (Surface tmp = new ImageSurface (Format.Argb32, bounds.Width, bounds.Height)) {
+#if VKVG
+                       using (Surface tmp = new Surface (iFace.vkvgDevice, bounds.Width, bounds.Height)) {
+#else
+                       using (Surface tmp = new ImageSurface (Format.Argb32, bounds.Width, bounds.Height)) {
+#endif
                                using (Context gr = new Context (tmp)) {
                                        gr.Translate (bounds.Left, bounds.Top);
                                        gr.Scale (widthRatio, heightRatio);
                                        gr.Translate ((bounds.Width/widthRatio - Dimensions.Width)/2, (bounds.Height/heightRatio - Dimensions.Height)/2);
 
-                                       hSVG.RenderCairo (gr);
+                                       hSVG.Render (gr);
                                }
                                ctx.SetSource (tmp);
-                       }*/     
+                       }
                }
                #endregion
 
@@ -109,8 +117,7 @@ namespace Crow
                public override void Paint (Interface iFace, Context gr, Rectangle rect, string subPart = "")
                {
                        if (hSVG == null)
-                               if (!load (iFace))
-                                       return;
+                               load (iFace);
 
                        float widthRatio = 1f;
                        float heightRatio = 1f;
@@ -126,21 +133,21 @@ namespace Crow
                                        widthRatio = heightRatio;
                        }
                                
-                       /*gr.Save ();
+                       gr.Save ();
 
                        gr.Translate (rect.Left,rect.Top);
                        gr.Scale (widthRatio, heightRatio);
                        gr.Translate (((float)rect.Width/widthRatio - Dimensions.Width)/2f, ((float)rect.Height/heightRatio - Dimensions.Height)/2f);
 
                        if (string.IsNullOrEmpty (subPart))
-                               hSVG.RenderCairo (gr);
+                               hSVG.Render (gr);
                        else {
                                string[] parts = subPart.Split (new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);
                 foreach (string p in parts)                
-                                       hSVG.RenderCairoSub (gr, "#" + subPart);
+                                       hSVG.Render (gr, "#" + subPart);
                        }
                        
-                       gr.Restore ();  */              
+                       gr.Restore ();
                }
        }
 }
index e1540089a4faa978e8d9ae1f52f4a6fa5c394d56..3488c528f301050d9fe08fe27a5cc3fa63f9ce77 100644 (file)
@@ -198,6 +198,6 @@ namespace Crow.Cairo
                        NativeMethods.cairo_region_destroy (Handle);
                        handle = NativeMethods.cairo_region_create ();                  
                }
-               public bool DoesNotContains (Crow.Rectangle rectangle) => Contains (p.Slot) == RegionOverlap.Out;
+               public bool OverlapOut (Crow.Rectangle rectangle) => Contains (p.Slot) == RegionOverlap.Out;
        }
 }
diff --git a/Crow/src/GraphicBackends/Mono.Cairo/rsvg/DimensionData.cs b/Crow/src/GraphicBackends/Mono.Cairo/rsvg/DimensionData.cs
new file mode 100644 (file)
index 0000000..66aab91
--- /dev/null
@@ -0,0 +1,24 @@
+//Copyright GPL2
+namespace Rsvg {
+
+       using System;
+       using System.Collections;
+       using System.Runtime.InteropServices;
+
+       [StructLayout(LayoutKind.Sequential)]
+       public struct DimensionData {
+
+               public int Width;
+               public int Height;
+               public double Em;
+               public double Ex;
+
+               public static Rsvg.DimensionData Zero = new Rsvg.DimensionData ();
+
+               public static Rsvg.DimensionData New(IntPtr raw) {
+                       if (raw == IntPtr.Zero)
+                               return Rsvg.DimensionData.Zero;
+                       return (Rsvg.DimensionData) Marshal.PtrToStructure (raw, typeof (Rsvg.DimensionData));
+               }
+       }
+}
diff --git a/Crow/src/GraphicBackends/Mono.Cairo/rsvg/SvgHandle.cs b/Crow/src/GraphicBackends/Mono.Cairo/rsvg/SvgHandle.cs
new file mode 100644 (file)
index 0000000..a5c8a8f
--- /dev/null
@@ -0,0 +1,82 @@
+//Copyright GPL2
+using System;
+using System.Runtime.InteropServices;
+
+namespace Crow.Cairo {
+
+
+       public sealed class SvgHandle : IDisposable {
+               const string lib = "rsvg-2.40";
+
+               public IntPtr Raw;
+
+               [DllImport (lib)]
+               static extern IntPtr rsvg_handle_new();
+               [DllImport (lib)]
+               static extern IntPtr rsvg_handle_new_from_data (byte[] data, UIntPtr n_data, out IntPtr error);
+               [DllImport (lib)]
+               static extern IntPtr rsvg_handle_new_from_file (string file_name, out IntPtr error);
+               [DllImport (lib)]
+               static extern IntPtr rsvg_handle_get_base_uri (IntPtr raw);
+               [DllImport (lib)]
+               static extern void rsvg_handle_set_dpi (IntPtr raw, double dpi);
+               [DllImport (lib)]
+               static extern void rsvg_handle_set_dpi_x_y (IntPtr raw, double dpi_x, double dpi_y);
+
+               [DllImport (lib)]
+               static extern void rsvg_handle_render_cairo (IntPtr raw, IntPtr cr);
+               [DllImport (lib)]
+               static extern void rsvg_handle_render_cairo_sub (IntPtr raw, IntPtr cr, string id);
+
+               [DllImport (lib)]
+               static extern void rsvg_handle_get_dimensions (IntPtr raw, IntPtr dimension_data);
+               [DllImport (lib)]
+               static extern bool rsvg_handle_close (IntPtr raw, out IntPtr error);
+               [DllImport (lib)]
+               static extern IntPtr rsvg_handle_get_title (IntPtr raw);
+               [DllImport (lib)]
+               static extern IntPtr rsvg_handle_get_metadata (IntPtr raw);
+
+               public SvgHandle ()
+               {
+                       Raw = rsvg_handle_new();
+               }
+               public  SvgHandle (byte[] data)
+               {                       
+                       Raw = rsvg_handle_new_from_data(data, new UIntPtr ((ulong) (data == null ? 0 : data.Length)), out IntPtr error);
+                       if (error != IntPtr.Zero) throw new Exception (error.ToString());
+               }
+               public SvgHandle (string file_name)
+               {                       
+                       Raw = rsvg_handle_new_from_file(file_name, out IntPtr error);
+                       if (error != IntPtr.Zero) throw new Exception (error.ToString());
+               }
+
+
+               public double Dpi { set => rsvg_handle_set_dpi (Raw, value); }
+               public void SetDpiXY (double dpi_x, double dpi_y) => rsvg_handle_set_dpi_x_y (Raw, dpi_x, dpi_y);
+
+
+               public void Render(Context cr) =>
+                       rsvg_handle_render_cairo (Raw, cr == null ? IntPtr.Zero : cr.Handle);
+               
+               public void Render (Context cr, string id) =>
+                       rsvg_handle_render_cairo_sub (Raw, cr == null ? IntPtr.Zero : cr.Handle, id);
+               
+               public Size Dimensions {
+                       get {
+                               DimensionData dimension_data;
+                               IntPtr native_dimension_data = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (DimensionData)));
+                               rsvg_handle_get_dimensions(Raw, native_dimension_data);
+                               dimension_data = DimensionData.New (native_dimension_data);
+                               Marshal.FreeHGlobal (native_dimension_data);
+                               return new Size (dimension_data.Width, dimension_data.Height);
+                       }
+               }
+
+               public void Dispose() {                 
+                       bool raw_ret = rsvg_handle_close(Raw, out IntPtr error);
+                       if (error != IntPtr.Zero) throw new Exception (error.ToString());                       
+               }
+       }
+}
index 870573bad534f51a21c35a4fd12eff27d88f1977..27db38b4a2fbfd84e950b1a796b34c90f18c730c 100644 (file)
@@ -16,6 +16,7 @@ namespace vkvg
                public Context(Surface surf)
                {
                        handle = NativeMethods.vkvg_create(surf.Handle);
+                       this.FillRule = FillRule.NonZero;
                }
                ~Context()
                {
index 1a6335211910d151f7d2038ef45ba7768e1133c2..2e345643aa49c4be0c85513624a49da83edcc68d 100644 (file)
@@ -239,7 +239,7 @@ namespace vkvg
         [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
         internal static extern IntPtr vkvg_surface_create_from_svg_fragment(IntPtr dev, byte[] filePath);
         [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr vkvg_surface_create_from_bitmap(IntPtr dev, ref byte[] data, uint width, uint height);
+        internal static extern IntPtr vkvg_surface_create_from_bitmap(IntPtr dev, ref byte data, uint width, uint height);
         [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
         internal static extern void vkvg_surface_destroy(IntPtr surf);
         [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
@@ -262,7 +262,7 @@ namespace vkvg
         [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
         internal static extern IntPtr nsvg_load_file(IntPtr dev, string filePath);
         [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
-        internal static extern IntPtr nsvg_load(IntPtr dev, byte[] fragment);
+        internal static extern IntPtr nsvg_load(IntPtr dev, ref byte fragment);
         [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
         internal static extern void nsvg_destroy(IntPtr nsvgImage);
         [DllImport(libvkvg, CallingConvention = CallingConvention.Cdecl)]
index de7682cfd628424b16672455afbf57c4dced4561..d942b5c5caf48d25635845eb5686560b9f73f5d5 100644 (file)
@@ -11,15 +11,18 @@ namespace vkvg
                IntPtr handle = IntPtr.Zero;
                Device vkvgDev;
 
-               public Surface (Device device, int width, int heigth)
+               public Surface (Device device, int width, int height)
                {
                        vkvgDev = device;
-                       handle = NativeMethods.vkvg_surface_create (device.Handle, (uint)width, (uint)heigth);
+                       if (width <= 0 || height <= 0)                          
+                               handle = NativeMethods.vkvg_surface_create (device.Handle, 1, 1);
+                       else
+                               handle = NativeMethods.vkvg_surface_create (device.Handle, (uint)width, (uint)height);
                }
-               public Surface (Device device, ref byte[] data, int width, int heigth)
+               public Surface (Device device, Span<byte> data, int width, int heigth)
                {
                        vkvgDev = device;
-                       handle = NativeMethods.vkvg_surface_create (device.Handle, (uint)width, (uint)heigth);
+                       handle = NativeMethods.vkvg_surface_create_from_bitmap (device.Handle, ref data.GetPinnableReference(), (uint)width, (uint)heigth);
                }
                public Surface (Device device, string imgPath) {
                        vkvgDev = device;
diff --git a/Crow/src/GraphicBackends/vkvg/SvgHandle.cs b/Crow/src/GraphicBackends/vkvg/SvgHandle.cs
new file mode 100644 (file)
index 0000000..fb55f74
--- /dev/null
@@ -0,0 +1,44 @@
+//Copyright GPL2
+using System;
+using System.Runtime.InteropServices;
+using Crow;
+
+namespace vkvg {
+
+
+       public sealed class SvgHandle : IDisposable {
+
+               public IntPtr Raw;
+               
+               public  SvgHandle (vkvg.Device dev, Span<byte> bytes)           
+               {
+                       /*int size = svgFragment.Length * 4 + 1;
+                       Span<byte> bytes = size > 512 ? new byte[size] : stackalloc byte[size];
+                       int encodedBytes = Crow.Text.Encoding.ToUtf8 (svgFragment, bytes);
+                       bytes[encodedBytes] = 0;*/
+                       Raw = NativeMethods.nsvg_load (dev.Handle, ref bytes.GetPinnableReference());
+               }
+               public SvgHandle (vkvg.Device dev, string file_name)
+               {                       
+                       Raw = NativeMethods.nsvg_load_file (dev.Handle, file_name);
+               }
+
+               public void Render(Context cr) =>
+                       cr.RenderSvg (Raw);
+               
+               public void Render (Context cr, string id) =>
+                       cr.RenderSvg (Raw, id);
+               
+               public Size Dimensions {
+                       get {
+                               NativeMethods.nsvg_get_size (Raw, out int w, out int h);
+                               return new Size (w, h);
+                       }
+               }
+
+               public void Dispose() {                 
+                       NativeMethods.nsvg_destroy (Raw);
+               }
+
+       }
+}
index 8ca1eb6d0b72e8176478e61f330d426deba79002..4488fb8fdce44034cb152f3e93ed461eddb08acb 100644 (file)
@@ -45,7 +45,7 @@ namespace vkvg {
                uint frameCount;
                Stopwatch frameChrono;
 
-               string[] EnabledInstanceExtensions => null;
+               string[] EnabledInstanceExtensions => new string[] { Ext.I.VK_EXT_debug_utils };
 
                string[] EnabledDeviceExtensions => new string[] { Ext.D.VK_KHR_swapchain };
 
@@ -53,10 +53,11 @@ namespace vkvg {
                public void WaitIdle() => dev.WaitIdle ();
                public VulkanContext (IntPtr hWin, uint _width, uint _height, bool vsync = false) {
                        this.hWin = hWin;
-                       Instance.VALIDATION = true;
-                       /*Instance.RENDER_DOC_CAPTURE = true;*/
+                       //Instance.VALIDATION = true;
+                       //Instance.RENDER_DOC_CAPTURE = true;
 
                        SwapChain.IMAGES_USAGE = VkImageUsageFlags.ColorAttachment | VkImageUsageFlags.TransferDst;
+                       SwapChain.PREFERED_FORMAT = VkFormat.B8g8r8a8Unorm;
 
                        List<string> instExts = new List<string> (Glfw3.GetRequiredInstanceExtensions ());
                        if (EnabledInstanceExtensions != null)
@@ -99,11 +100,12 @@ namespace vkvg {
                }
 
                public vkvg.Device CreateVkvgDevice () => 
-                       new vkvg.Device (instance.Handle, phy.Handle, dev.VkDev.Handle, presentQueue.qFamIndex);
+                       new vkvg.Device (instance.Handle, phy.Handle, dev.VkDev.Handle, presentQueue.qFamIndex, SampleCount.Sample_8);
 
                internal vke.Image blitSource;
                
                public void BuildBlitCommand (vkvg.Surface surf) {
+                       //Console.WriteLine ($"build blit w:{width} h:{height}");
                        cmdPool.Reset();
                        
                        blitSource = new vke.Image (dev, new VkImage((ulong)surf.VkImage.ToInt64()), Vulkan.VkFormat.B8g8r8a8Unorm,
@@ -144,20 +146,26 @@ namespace vkvg {
                /// Main render method called each frame. get next swapchain image, process resize if needed, submit and present to the presentQueue.
                /// Wait QueueIdle after presenting.
                /// </summary>
-               public void render () {
+               public bool render () {
+                       WaitIdle();
+
                        int idx = swapChain.GetNextImage ();
                        if (idx < 0) {
                                width = swapChain.Width;
                                height = swapChain.Height;
-                               return;
+                               //Console.WriteLine ($"get next image failed w:{width} h:{height}");
+                               return false;
                        }
 
                        if (cmds[idx] == null)
-                               return;
+                               return false;
                        WaitAndResetDrawFence();
 
                        presentQueue.Submit (cmds[idx], swapChain.presentComplete, drawComplete[idx], drawFence);
-                       presentQueue.Present (swapChain, drawComplete[idx]);                    
+                       presentQueue.Present (swapChain, drawComplete[idx]);
+
+                       WaitIdle();
+                       return true;
                }
 
                #region IDisposable Support
index 2d061e64eb423c570e3883f7272c2b5b39fb4020..c07aa065fbe5c075cd7d807687bd6f6fd162115a 100644 (file)
@@ -13,41 +13,49 @@ namespace Crow {
                Part,
        }       
        public class Region : IDisposable
-    {
-        public List<Rectangle> list = new List<Rectangle>();
-        public int count => list.Count;
+       {
+               public List<Rectangle> list = new List<Rectangle>();
+               public int count => list.Count;
                public int NumRectangles => list.Count;
                public bool IsEmpty => list.Count == 0;
                public Rectangle GetRectangle(int i) => list[i];
 
-        public void AddRectangle(Rectangle r)
-        {
+               public void AddRectangle(Rectangle r)
+               {
+                       if (r == default)
+                               return;
                        if (DoesNotContains (r)) {
                                list.Add (r);
                                boundsUpToDate = false;
                        }
-        }
-        public void Reset()
-        {
-            list = new List<Rectangle>();
+               }
+               public void Reset()
+               {
+                       list = new List<Rectangle>();
                        _bounds = default;
                        boundsUpToDate = true;
-        }
-        public bool DoesNotContains(Rectangle r)
-        {
-            foreach (Rectangle rInList in list)
-                if (rInList.ContainsOrIsEqual(r))
-                    return false;
-            return true;
-        }              
+               }
+               public bool DoesNotContains(Rectangle r)
+               {
+                       foreach (Rectangle rInList in list)
+                               if (rInList.ContainsOrIsEqual(r))
+                                       return false;
+                       return true;
+               }
+               public bool OverlapOut (Rectangle r) {
+                       foreach (Rectangle rInList in list)
+                               if (rInList.Intersect(r))
+                                       return false;
+                       return true;
+               }
 
-        public bool intersect(Rectangle r)
-        {
-            foreach (Rectangle rInList in list)
-                if (rInList.Intersect(r))
-                    return true;
-            return false;
-        }
+               public bool intersect(Rectangle r)
+               {
+                       foreach (Rectangle rInList in list)
+                               if (rInList.Intersect(r))
+                                       return true;
+                       return false;
+               }
                public void stroke(Context ctx, Color c)
                {
                        foreach (Rectangle r in list)
@@ -58,27 +66,29 @@ namespace Crow {
                        ctx.LineWidth = 2;
                        ctx.Stroke ();
                }
-        public void clearAndClip(Context ctx)
-        {
+               public void clearAndClip(Context ctx)
+               {
                        if (list.Count == 0)
                                return;
-            foreach (Rectangle r in list)
-                ctx.Rectangle(r);
+                       foreach (Rectangle r in list)
+                               ctx.Rectangle(r);
 
                        ctx.ClipPreserve();
                        ctx.Operator = Operator.Clear;
-            ctx.Fill();
-            ctx.Operator = Operator.Over;
-        }
+                       ctx.Fill();
+                       ctx.Operator = Operator.Over;
+               }
 
-        public void clip(Context ctx)
-        {
-            foreach (Rectangle r in list)
-               ctx.Rectangle(r);
+               public void clip(Context ctx)
+               {
+                       foreach (Rectangle r in list)
+                               ctx.Rectangle(r);
 
-            ctx.Clip();
-        }
+                       ctx.Clip();
+               }
                public void UnionRectangle (Rectangle r) {
+                       /*if (r == default)
+                               System.Diagnostics.Debugger.Break ();*/
                        AddRectangle (r);
                }
                Rectangle _bounds;
@@ -99,13 +109,13 @@ namespace Crow {
                        }
                }
                public void clear(Context ctx)
-        {
-            foreach (Rectangle r in list)
-                ctx.Rectangle(r);
-            ctx.Operator = Operator.Clear;
-            ctx.Fill();
-            ctx.Operator = Operator.Over;
-        }
+               {
+                       foreach (Rectangle r in list)
+                               ctx.Rectangle(r);
+                       ctx.Operator = Operator.Clear;
+                       ctx.Fill();
+                       ctx.Operator = Operator.Over;
+               }
                public override string ToString ()
                {
                        string tmp = "";
index 5825661a9c5e0c63f4bf72665b065dc88d2f3337..367ed25e8efb7eda7eaf5d384d6ec741d3e000e3 100644 (file)
@@ -150,12 +150,12 @@ namespace Crow
 
                        PerformanceMeasure.InitMeasures ();
 
-                       if (startUIThread) {
+                       /*if (startUIThread) {
                                Thread t = new Thread (InterfaceThread) {
                                        IsBackground = true
                                };
                                t.Start ();
-                       }                       
+                       }*/                     
                }
                #endregion
 
@@ -206,7 +206,7 @@ namespace Crow
 #if VKVG
                        vkCtx = new VulkanContext (hWin, (uint)clientRectangle.Width, (uint)clientRectangle.Height);
                        vkvgDevice = vkCtx.CreateVkvgDevice ();
-                       surf = new Surface (vkvgDevice, clientRectangle.Width, clientRectangle.Height);
+                       surf = new Surface (vkvgDevice, clientRectangle.Width, clientRectangle.Height);                 
                        vkCtx.BuildBlitCommand (surf);
 #else
                        switch (Environment.OSVersion.Platform) {
@@ -259,8 +259,8 @@ namespace Crow
                                                image [i + 2] = Marshal.ReadByte (stbi.Handle, i);
                                                image [i + 3] = Marshal.ReadByte (stbi.Handle, i + 3);
                                        }
-                                       Glfw.Image icon = new Glfw.Image (stbi.Width, stbi.Height, image);
-                                       Glfw3.setWindowIcon (hWin, 1, ref icon);
+                                       Glfw.Image icon = new Glfw.Image ((uint)stbi.Width, (uint)stbi.Height, image);
+                                       Glfw3.SetWindowIcon (hWin, 1, ref icon);
                                        icon.Dispose();
                                }
 #endif
@@ -382,7 +382,10 @@ namespace Crow
                        Terminate ();
                }
                public virtual void Terminate () {}
-               public virtual void UpdateFrame () { Thread.Sleep (1); }
+               public virtual void UpdateFrame () { 
+                       Update ();
+                       Thread.Sleep (UPDATE_INTERVAL);
+               }
 
                public virtual void Quit () => Glfw3.SetWindowShouldClose (hWin, 1);
 
@@ -707,7 +710,7 @@ namespace Crow
                                                        string resId = $"#{pic.Substring (path.Length + 1).Replace (Path.DirectorySeparatorChar, '.')}";
                                                        using (Stream s = new FileStream (pic, FileMode.Open, FileAccess.Read)) {
                                                                if (resId.EndsWith (".svg", StringComparison.OrdinalIgnoreCase))
-                                                                       sharedPictures[resId] = SvgPicture.CreateSharedPicture (s);
+                                                                       sharedPictures[resId] = SvgPicture.CreateSharedPicture (this, s);
                                                                else
                                                                        sharedPictures[resId] = BmpPicture.CreateSharedPicture (s);
                                                        }
@@ -1039,18 +1042,24 @@ namespace Crow
 
                                clippingRegistration ();
 
-                               if (ctx == null) {
-                                       using (ctx = new Context (surf)) 
+
+                               if (!clipping.IsEmpty) {
+                                       if (ctx == null) {
+                                               using (ctx = new Context (surf)) 
+                                                       processDrawing (ctx);
+                                       }else
                                                processDrawing (ctx);
-                               }else
-                                       processDrawing (ctx);
+                               }
 
 #if VKVG
                                if (IsDirty) {
-                                       IsDirty = false;
-                                       vkCtx.render ();
+                                       if (vkCtx.render ())
+                                               IsDirty = false;
+                                       else {
+                                               resizeVulkanContext();
+                                       }
                                }
-#endif
+#endif                 
                                
                        } finally {
 
@@ -1062,6 +1071,19 @@ namespace Crow
 
                        PerformanceMeasure.Notify ();
                }
+               void resizeVulkanContext () {
+                       vkCtx.WaitIdle();
+                       vkCtx.blitSource?.Dispose ();
+                       surf?.Dispose ();
+                       surf = new Surface (vkvgDevice, clientRectangle.Width, clientRectangle.Height);                         
+                       vkCtx.BuildBlitCommand (surf);
+                       vkCtx.WaitIdle();
+                       foreach (Widget g in GraphicTree)
+                               g.RegisterForLayouting (LayoutingType.All);
+
+                       registerRefreshClientRectangle ();
+
+               }
                /// <summary>Layouting loop, this is the first step of the udpate and process registered
                /// Layouting queue items. Failing LQI's are requeued in this cycle until MaxTry is reached which
                /// trigger an enqueue for the next Update Cycle</summary>
@@ -1118,7 +1140,7 @@ namespace Crow
 
                        ctx.ClipPreserve ();
                        ctx.Operator = Operator.Clear;
-                       ctx.Fill ();
+                       ctx.Fill ();                    
                        ctx.Operator = Operator.Over;                   
                }
         bool solidBackground = false;
@@ -1148,7 +1170,7 @@ namespace Crow
                        if (DragImage != null)
                                clipping.UnionRectangle(DragImageBounds);
 
-                       if (!clipping.IsEmpty) {
+                       
                                PerformanceMeasure.Begin (PerformanceMeasure.Kind.Drawing);                             
 
 #if VKVG                               
@@ -1158,13 +1180,14 @@ namespace Crow
 
                                if (SolidBackground)
                                        clear (ctx);
+                               ctx.Flush();
 #endif
                                
                                for (int i = GraphicTree.Count -1; i >= 0 ; i--){
                                        Widget p = GraphicTree[i];
                                        if (!p.IsVisible)
                                                continue;
-                                       if (clipping.DoesNotContains (p.Slot))
+                                       if (clipping.OverlapOut (p.Slot))
                                                continue;
 
                                        //ctx.Save ();
@@ -1191,15 +1214,17 @@ namespace Crow
 
 #if DEBUG_CLIP_RECTANGLE
                                ctx.LineWidth = 1;
-                               ctx.SetSource(1,0,0,0.5);
+                               ctx.SetSource(1,1,0,0.5);
                                for (int i = 0; i < clipping.NumRectangles; i++)
                                        ctx.Rectangle(clipping.GetRectangle(i));
                                ctx.Stroke ();
+                               
 #endif
 
 #if VKVG
+                               ctx.Flush();
                                //vkCtx.render ();
-                               vkCtx.WaitIdle();
+                               //vkCtx.WaitIdle();
 #else
                                ctx.PopGroupToSource ();
 
@@ -1215,9 +1240,9 @@ namespace Crow
 
                                PerformanceMeasure.End (PerformanceMeasure.Kind.Drawing);
                                IsDirty = true;
-                       }
+                       
 
-                       drawTextCursor (ctx);
+                       //drawTextCursor (ctx);
 
                        debugHighlightFocus (ctx);
                        
@@ -1398,11 +1423,7 @@ namespace Crow
                                clientRectangle = bounds;
 
 #if VKVG
-                               vkCtx.WaitIdle();
-                               vkCtx.blitSource?.Dispose ();
-                               surf?.Dispose ();
-                               surf = new Surface (vkvgDevice, clientRectangle.Width, clientRectangle.Height);                         
-                               vkCtx.BuildBlitCommand (surf);                          
+
 #else
                                switch (Environment.OSVersion.Platform) {
                                case PlatformID.MacOSX:
@@ -1425,11 +1446,11 @@ namespace Crow
                                case PlatformID.WinCE:
                                        throw new PlatformNotSupportedException ("Unable to create cairo surface.");
                                }
-#endif
                                foreach (Widget g in GraphicTree)
                                        g.RegisterForLayouting (LayoutingType.All);
 
                                registerRefreshClientRectangle ();
+#endif
                        }
                }
 
index 0dc156f2baf59d8d3b5d6af192d2a622ad9d9d5f..8fe9800324820d8f02a9923bb52da637f265728a 100644 (file)
@@ -108,15 +108,15 @@ namespace Crow
                {
                        drawborder2 (gr);
 
-                       gr.Save ();
+                       /*gr.Save ();
                        if (ClipToClientRect) {
                                CairoHelpers.CairoRectangle (gr, ClientRectangle, Math.Max (0.0, CornerRadius - Margin));
                                gr.Clip ();
-                       }
+                       }*/
+
+                       child?.Paint (gr);
 
-                       if (child != null)
-                               child.Paint (gr);
-                       gr.Restore ();
+                       //gr.Restore ();
                }
                void drawborder2(Context gr){
                        Rectangle rBack = new Rectangle (Slot.Size);
index d63249bb2ba1c762859f49bfe8dcb6a814b4ab85..1e334c2e77f6687b18f1deca54642d21e7895457 100644 (file)
@@ -49,7 +49,7 @@ namespace Crow
                public override void OnDataSourceChanged(object sender, DataSourceChangeEventArgs e)
                {
                        base.OnDataSourceChanged(sender, e);
-                       NotifyValueChanged ("IsExpandable", IsExpandable);
+                       //NotifyValueChanged ("IsExpandable", IsExpandable);
 
                }
                /// <summary>
index 6387048fc303e515b984a7607ad06088dbac59e3..7a30f34eb985cea233d85b70888bd8655922ab0f 100644 (file)
@@ -259,7 +259,7 @@ namespace Crow
                                                gr.Rectangle(Clipping.GetRectangle(i));
                                        gr.ClipPreserve();
                                        gr.Operator = Operator.Clear;
-                                       gr.Fill();
+                                       gr.Fill();                                      
                                        gr.Operator = Operator.Over;
 
                                        base.onDraw (gr);
@@ -274,7 +274,7 @@ namespace Crow
                                                foreach (Widget c in Children) {
                                                        if (!c.IsVisible)
                                                                continue;
-                                                       if (Clipping.DoesNotContains (c.Slot + ClientRectangle.Position))
+                                                       if (Clipping.OverlapOut (c.Slot + ClientRectangle.Position))
                                                                continue;
                                                        c.Paint (gr);
                                                }
index 001931b3075ed94d422482b719d3c61934a23a29..c460c598fa81278af283f8024d8d42aadbea8104 100644 (file)
@@ -165,6 +165,8 @@ namespace Crow
                {
                        if (_pic == null)
                                return 2 * Margin;
+                       if (!_pic.IsLoaded)
+                               _pic.load (IFace);
                                //_pic = "#Crow.Images.Icons.IconAlerte.svg";
                        //TODO:take scalling in account
                        if (lt == LayoutingType.Width)
index f11066e2e4c36020be61223fab986877a9bbd808..de48518401daf479dd309dd9201d6b0b6c3a7791 100644 (file)
@@ -641,6 +641,8 @@ namespace Crow
                
                protected override void onDraw (Context gr)
                {
+                       DbgLogger.StartEvent(DbgEvtType.GODraw, this);
+
                        base.onDraw (gr);
 
                        setFontForContext (gr);
@@ -661,6 +663,8 @@ namespace Crow
                        
                        if (ClipToClientRect)
                                gr.Restore ();
+
+                       DbgLogger.EndEvent (DbgEvtType.GODraw);
                }
                #endregion
 
index 65a9335737f0f0e0fe552b07b58f553f2f6b23c2..af7367e48eba285dc09488787494da1bc45f1383 100644 (file)
@@ -224,7 +224,7 @@ namespace Crow
                                                gr.Rectangle(Clipping.GetRectangle(i));
                                        gr.ClipPreserve();
                                        gr.Operator = Operator.Clear;
-                                       gr.Fill();
+                                       gr.Fill();                                      
                                        gr.Operator = Operator.Over;
 
                                        onDraw (gr);
index 8a8f640d80a55c018512361ed0c0736b948a69c7..1d56b56b1da5d26b4d83b3bc975f006ea848932a 100644 (file)
@@ -191,8 +191,9 @@ namespace Crow
                        Background.SetAsSource (IFace, gr, rBack);
                        CairoHelpers.CairoRectangle(gr,rBack, CornerRadius);
                        gr.Fill ();
-
+               
                        gr.Save ();
+
                        if (ClipToClientRect) {
                                //clip to scrolled client zone
                                CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
@@ -200,8 +201,12 @@ namespace Crow
                        }
 
                        gr.Translate (-ScrollX, -ScrollY);
+
                        if (child != null)
                                child.Paint (gr);
+                       
+                       //gr.Translate (ScrollX, ScrollY);
+
                        gr.Restore ();
                }
 
index da00ae3789210581603e5bc612ed1b8af25e4107..20cbeb6cce4434f45603c240ad030a68d89f0c50 100644 (file)
@@ -223,7 +223,8 @@ namespace Crow
                                        widthRatio = heightRatio;
                        }
 
-                       gr.Save ();
+                       Matrix m = gr.Matrix;
+                       //gr.Save ();
 
                        gr.Translate (cr.Left, cr.Top);
                        gr.Scale (widthRatio, heightRatio);
@@ -235,7 +236,8 @@ namespace Crow
                        using (PathParser parser = new PathParser (path))
                                parser.Draw (gr);
 
-                       gr.Restore ();
+                       //gr.Restore ();
+                       gr.Matrix = m;
                }
 
 
index aaf5a962b32512b8ef9005e8d8561af9296bdb91..0ee818bb6f1a72a22225e0b46b0f744cad453190 100644 (file)
@@ -86,26 +86,26 @@ namespace Crow
                //public override T FindByType<T> () => this is TemplatedControl tg ? tg : default (T);
                public Widget FindByNameInTemplate (string nameToFind) => child?.FindByName (nameToFind);
                /// <summary>
-               ///onDraw is overrided to prevent default drawing of background, template top container
+               ///onDraw is overriden to prevent default drawing of background, template top container
                ///may have a binding to root background or a fixed one.
                ///this allow applying root background to random template's component
                /// </summary>
                /// <param name="gr">Backend context</param>
                protected override void onDraw (Context gr)
                {
-                       DbgLogger.StartEvent (DbgEvtType.GODraw, this);
-
-                       gr.Save ();
+                       DbgLogger.StartEvent (DbgEvtType.GODraw, this);                 
 
                        if (ClipToClientRect) {
                                //clip to client zone
+                               gr.Save ();
                                CairoHelpers.CairoRectangle (gr, ClientRectangle, CornerRadius);
                                gr.Clip ();
                        }
                        
                        child?.Paint (gr);
 
-                       gr.Restore ();
+                       if (ClipToClientRect)
+                               gr.Restore ();
 
                        DbgLogger.EndEvent (DbgEvtType.GODraw);
                }
index 8c3b82a224617dc151fe3ad64e6ce0ae24f03cfd..601c6033c61dfbb31bfd303522cc3dacc8430877 100644 (file)
@@ -1934,13 +1934,18 @@ namespace Crow
                                bmp.SetSize (Slot.Width, Slot.Height);*/
                        bmp?.Dispose ();
 #if (VKVG)
+                       DbgLogger.StartEvent (DbgEvtType.GOCreateSurface, this);
                        bmp = new Surface (IFace.vkvgDevice, Slot.Width, Slot.Height);
+                       DbgLogger.EndEvent (DbgEvtType.GOCreateSurface);
+                       //bmp.Clear();
 #else
                        bmp = IFace.surf.CreateSimilar (Content.ColorAlpha, Slot.Width, Slot.Height);
 #endif
                        //bmp = new ImageSurface(Format.Argb32, Slot.Width, Slot.Height);
 
+                       DbgLogger.StartEvent (DbgEvtType.GOCreateContext, this);
                        using (Context gr = new Context (bmp)) {
+                               DbgLogger.EndEvent (DbgEvtType.GOCreateContext);
                                gr.Antialias = Interface.Antialias;
                                onDraw (gr);
                        }
@@ -1958,8 +1963,9 @@ namespace Crow
                                ctx.Operator = Operator.Over;
                        }
 
-                       ctx.SetSource (bmp, rb.X, rb.Y);
+                       ctx.SetSource (bmp, rb.X, rb.Y);                        
                        ctx.Paint ();
+                       ctx.Flush ();
                        DbgLogger.EndEvent(DbgEvtType.GOPaintCache);    
                }
                protected virtual void UpdateCache(Context ctx){
@@ -2009,13 +2015,15 @@ namespace Crow
                                                paintDisabled (ctx, Slot + Parent.ClientRectangle.Position);                                    
                                } else {
                                        Rectangle rb = Slot + Parent.ClientRectangle.Position;
-                                       ctx.Save ();
+                                       //ctx.Save ();
 
                                        ctx.Translate (rb.X, rb.Y);
 
                                        onDraw (ctx);
 
-                                       ctx.Restore ();
+                                       ctx.Translate (-rb.X, -rb.Y);
+
+                                       //ctx.Restore ();
 
                                        if (!IsEnabled)
                                                paintDisabled (ctx, rb);
diff --git a/Crow/src/rsvg/DimensionData.cs b/Crow/src/rsvg/DimensionData.cs
deleted file mode 100644 (file)
index 66aab91..0000000
+++ /dev/null
@@ -1,24 +0,0 @@
-//Copyright GPL2
-namespace Rsvg {
-
-       using System;
-       using System.Collections;
-       using System.Runtime.InteropServices;
-
-       [StructLayout(LayoutKind.Sequential)]
-       public struct DimensionData {
-
-               public int Width;
-               public int Height;
-               public double Em;
-               public double Ex;
-
-               public static Rsvg.DimensionData Zero = new Rsvg.DimensionData ();
-
-               public static Rsvg.DimensionData New(IntPtr raw) {
-                       if (raw == IntPtr.Zero)
-                               return Rsvg.DimensionData.Zero;
-                       return (Rsvg.DimensionData) Marshal.PtrToStructure (raw, typeof (Rsvg.DimensionData));
-               }
-       }
-}
diff --git a/Crow/src/rsvg/Handle.cs b/Crow/src/rsvg/Handle.cs
deleted file mode 100644 (file)
index bd0e725..0000000
+++ /dev/null
@@ -1,93 +0,0 @@
-//Copyright GPL2
-#if VKVG
-using vkvg;
-#else
-using Crow.Cairo;
-#endif
-
-
-namespace Rsvg {
-
-       using System;
-       using System.Collections;
-       using System.Runtime.InteropServices;
-
-       public sealed class Handle {
-               const string lib = "rsvg-2.40";
-
-               public IntPtr Raw;
-
-               [DllImport (lib)]
-               static extern IntPtr rsvg_handle_new();
-               [DllImport (lib)]
-               static extern IntPtr rsvg_handle_new_from_data (byte[] data, UIntPtr n_data, out IntPtr error);
-               [DllImport (lib)]
-               static extern IntPtr rsvg_handle_new_from_file (string file_name, out IntPtr error);
-               [DllImport (lib)]
-               static extern IntPtr rsvg_handle_get_base_uri (IntPtr raw);
-               [DllImport (lib)]
-               static extern void rsvg_handle_set_dpi (IntPtr raw, double dpi);
-               [DllImport (lib)]
-               static extern void rsvg_handle_set_dpi_x_y (IntPtr raw, double dpi_x, double dpi_y);
-
-               [DllImport (lib)]
-               static extern void rsvg_handle_render_cairo (IntPtr raw, IntPtr cr);
-               [DllImport (lib)]
-               static extern void rsvg_handle_render_cairo_sub (IntPtr raw, IntPtr cr, string id);
-
-               [DllImport (lib)]
-               static extern void rsvg_handle_get_dimensions (IntPtr raw, IntPtr dimension_data);
-               [DllImport (lib)]
-               static extern bool rsvg_handle_close (IntPtr raw, out IntPtr error);
-               [DllImport (lib)]
-               static extern IntPtr rsvg_handle_get_title (IntPtr raw);
-               [DllImport (lib)]
-               static extern IntPtr rsvg_handle_get_metadata (IntPtr raw);
-
-               public Handle ()
-               {
-                       Raw = rsvg_handle_new();
-               }
-               public  Handle (byte[] data)
-               {                       
-                       Raw = rsvg_handle_new_from_data(data, new UIntPtr ((ulong) (data == null ? 0 : data.Length)), out IntPtr error);
-                       if (error != IntPtr.Zero) throw new Exception (error.ToString());
-               }
-               public Handle (string file_name)
-               {                       
-                       Raw = rsvg_handle_new_from_file(file_name, out IntPtr error);
-                       if (error != IntPtr.Zero) throw new Exception (error.ToString());
-               }
-
-
-               public double Dpi { set => rsvg_handle_set_dpi (Raw, value); }
-               public void SetDpiXY (double dpi_x, double dpi_y) => rsvg_handle_set_dpi_x_y (Raw, dpi_x, dpi_y);
-
-
-               public void RenderCairo(Context cr) =>
-                       rsvg_handle_render_cairo (Raw, cr == null ? IntPtr.Zero : cr.Handle);
-               
-               public void RenderCairoSub (Context cr, string id) =>
-                       rsvg_handle_render_cairo_sub (Raw, cr == null ? IntPtr.Zero : cr.Handle, id);
-               
-               public DimensionData Dimensions {
-                       get {
-                               DimensionData dimension_data;
-                               IntPtr native_dimension_data = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (DimensionData)));
-                               rsvg_handle_get_dimensions(Raw, native_dimension_data);
-                               dimension_data = DimensionData.New (native_dimension_data);
-                               Marshal.FreeHGlobal (native_dimension_data);
-                               return dimension_data;
-                       }
-               }
-
-               public bool Close() {                   
-                       bool raw_ret = rsvg_handle_close(Raw, out IntPtr error);
-                       if (error != IntPtr.Zero) throw new Exception (error.ToString());
-                       return raw_ret;
-               }
-
-               public string Title => throw new NotSupportedException ();
-               public string Metadata => throw new NotSupportedException ();
-       }
-}
index 11eed07e1f0956eeacd0e4365ace1a5a5746b21a..9de4e4c12eb8dadb61d7c3483857e59e5879d42e 100644 (file)
@@ -11,6 +11,10 @@ namespace Samples
        {
                static void Main ()
                {
+                       DbgLogger.IncludeEvents = DbgEvtType.Widget;
+                       DbgLogger.DiscardEvents = DbgEvtType.None;
+                       Crow.DbgLogger.ConsoleOutput = false;
+
                        using (BasicTests app = new BasicTests ()) {
                                app.SolidBackground = false;
                                app.Run ();
@@ -42,12 +46,12 @@ namespace Samples
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Container", "*.crow")).ToArray ();
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Group", "*.crow")).ToArray ();
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Stack", "*.crow")).ToArray ();
-                       /*testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/TemplatedControl", "*.crow")).ToArray ();
+                       testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/TemplatedControl", "*.crow")).ToArray ();
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/TemplatedContainer", "*.crow")).ToArray ();
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/TemplatedGroup", "*.crow")).ToArray ();
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Wrapper", "*.crow")).ToArray ();
                        testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Divers", "*.crow")).ToArray ();
-                       testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/DragAndDrop", "*.crow")).ToArray ();*/
+                       testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/DragAndDrop", "*.crow")).ToArray ();
                        //testFiles = testFiles.Concat (Directory.GetFiles (@"Interfaces/Experimental", "*.crow")).ToArray ();
 
                        Load (testFiles [idx]).DataSource = this;
index e2be248e57a250a9f824148e0f10e4a4d7b2d623..cb5b413bb37f8bf93248690ef68527a6ca47f196 100644 (file)
@@ -7,7 +7,25 @@ namespace HelloWorld
        class Program : SampleBase {
                static void Main (string[] args) {
                        using (Interface app = new Program ()) {
-                               app.Initialized += (sender, e) => (sender as Interface).Load ("#HelloWorld.helloworld.crow").DataSource = sender;
+                               //app.Initialized += (sender, e) => (sender as Interface).Load ("#HelloWorld.helloworld.crow").DataSource = sender;
+                               /*app.Initialized += (sender, e) => (sender as Interface).LoadIMLFragment (@"
+<Border Background='Red' Margin='100' Fit='true' BorderWidth='10'>
+<Image Path='/mnt/devel/CrowIDE/Crow/Images/screenshot3.png' Width='100' Height='100' />
+</Border>
+").DataSource = sender;*/
+app.Initialized += (sender, e) => (sender as Interface).LoadIMLFragment (@"
+<Container Background='Jet' Margin='10'                                        CacheEnabled='false'>
+       <CheckBox Background='Blue'                                                     CacheEnabled='false'>
+               <Template>
+                       <Border Background='{./Background}' Margin='5'  CacheEnabled='false'>
+                               <HorizontalStack Margin='30'                            CacheEnabled='true'>
+                                       <Label Background='Pink' Fit='true'     CacheEnabled='false'/>
+                               </HorizontalStack>
+                       </Border>
+               </Template>
+       </CheckBox>
+</Container>
+").DataSource = sender;
                                app.Run ();
                        }
                }
index 6f78b149aadce9b7576c28b0cc9291961631e82a..ee5a541ad790213f83104cd79acd6127397a53ac 100644 (file)
@@ -4,14 +4,14 @@ FpsLabel {
        Width = "30";
        Font = "droid, 10";
        Margin = "0";
-       TextAlignment = "Center";
+       //TextAlignment = "Center";
 }
 FpsDisp {
        Font = "droid bold, 10";
        Width = "60";
        Margin = "0";
-       CornerRadius = "3";
-       TextAlignment = "Center";
+       //CornerRadius = "3";
+       //TextAlignment = "Center";
        Background = "MediumSeaGreen";
 }
 HStackMeasure {
index 9c7e942c11af502d23408f1bb6116eeba4977cce..cddf8bffaed78f47a72a38d07199389c8c8adc94 100644 (file)
@@ -1,19 +1,33 @@
 <?xml version="1.0"?>
-<Border BorderStyle="Sunken" Fit="true" Background="0.8,0.8,0.9,0.5" CornerRadius="30">
-       <VerticalStack Margin="20" Spacing="10">
-               <Image Path="#Crow.Icons.crow.svg" Width="64" Height="64" Background="WhiteSmoke" CornerRadius="5" Margin="5"/>
-<!--           <Label Font="Times bold, 60" Text="C.R.O.W"/>-->
-               <HorizontalStack Fit="true" DataSource="{CrowVersion}" Spacing="0" Background="Grey" Margin="10" CornerRadius="15">
-                       <Label Foreground="Jet" Font="mono, 12" Text="version: "/>              
-                       <Label Foreground="Black" Font="mono, 16" Text="{Major}"/>              
-                       <Label Foreground="Black" Font="mono, 12" Text="."/>
-                       <Label Foreground="Black" Font="mono, 16" Text="{Minor}"/>
-                       <Label Foreground="Black" Font="mono, 12" Text="."/>
-                       <Label Foreground="DarkBlue" Font="mono, 14" Text="{Build}" VerticalAlignment="Bottom"/>
+<VerticalStack>
+<ListBox Data="{PerfMeasures}" Height="Fit">
+       <Template>
+               <VerticalStack Name="ItemsContainer" Width="90%" Spacing="2"/>
+       </Template>
+       <ItemTemplate>
+               <HorizontalStack Style="HStackMeasure" Width="Stretched">
+                       <Label Text="{Name}" Style="FpsLabel" Width="Stretched"/>
+                       <Label Text="{current}" Style="FpsDisp" Width="25%" TextAlignment="Right" Margin="2"/>
+                       <Label Text="{minimum}" Style="FpsDisp" Width="25%" TextAlignment="Right" Margin="2"/>
+                       <Label Text="{maximum}" Style="FpsDisp" Width="25%" TextAlignment="Right" Margin="2"/>
+                       <Button Width="Fit" Caption="reset" MouseClick="onResetClick"/>
                </HorizontalStack>
-               <Label Font="20" Text="Press &lt;F2&gt; and &lt;F3&gt; to cycle into the examples"/>
-               <Label Font="20" Text="Those are basic tests used to validate changes,"/>
-               <Label Foreground="Onyx" Font="20" Text="&lt;F5&gt; => File dialog example"/>
-               <Label Foreground="Onyx" Font="20" Text="&lt;F6&gt; => Window example"/>
-       </VerticalStack>
-</Border>
\ No newline at end of file
+       </ItemTemplate>
+</ListBox>
+<ListBox Data="{PerfMeasures}" Height="Fit">
+       <Template>
+               
+                       <VerticalStack Name="ItemsContainer" Width="90%" Spacing="2"/>
+               
+       </Template>
+       <ItemTemplate>
+               <HorizontalStack Style="HStackMeasure" Width="Stretched">
+                       <Label Text="{Name}" Style="FpsLabel" Width="Stretched"/>
+                       <Label Text="{current}" Style="FpsDisp" Width="25%" TextAlignment="Right" Margin="2"/>
+                       <Label Text="{minimum}" Style="FpsDisp" Width="25%" TextAlignment="Right" Margin="2"/>
+                       <Label Text="{maximum}" Style="FpsDisp" Width="25%" TextAlignment="Right" Margin="2"/>
+                       <Button Width="Fit" Caption="reset" MouseClick="onResetClick"/>
+               </HorizontalStack>
+       </ItemTemplate>
+</ListBox>
+</VerticalStack>
index 2c0b77213a58735398f04ed1f0a34637e30429aa..7dc7be90b4071a0c15ab0f5d291d0d2e67abe366 100644 (file)
@@ -1,10 +1,12 @@
 <?xml version="1.0"?>
 <Container Background="DimGrey" Margin="10" Width="Fit" Height="Fit" >
-       <Popper Width="Stretched" Margin="10" Background="RoyalBlue">
-               <Container Width="Fit" Height="Fit" Margin="10" Background="Blue">
+       <Popper Width="Stretched" Margin="0" Background="Red"
+               MouseEnter="{Background=Yellow}"
+               MouseLeave="{Background=Red}">
+               <Container Width="Fit" Height="Fit" Margin="10" Background="{./Background}">
                        <Container  Margin="10" Background="Yellow">
                                <Container Margin="10" Background="FireBrick">
-                                       <CheckBox/> 
+                                       
                                </Container>
                        </Container>
                </Container>
index 63590efdea111cce1fbc617794d7c1b44957cbcd..1e6e03fab62aeb71789341452b757076e1f4b616 100644 (file)
@@ -1,6 +1,6 @@
 <?xml version="1.0"?>
 <VerticalStack Spacing="5" Margin="5">
-       <EnumSelector Caption="Vertical Alignemnt" EnumValue="{²CurrentVAlign}" Width="200">
+       <EnumSelector Caption="Vertical Alignemnt" EnumValue="{²CurrentVAlign}" Width="200" Background="Onyx">
                <Template>
                        <Popper Caption="{./Caption}" CornerRadius="{./CornerRadius}" Foreground="{./Foreground}" Background="{./Background}">
                                <Template>