From f74e80cc294fd08e9343c0fed05220c3436eb385 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jean-Philippe=20Bruy=C3=A8re?= Date: Thu, 16 Nov 2017 03:28:40 +0100 Subject: [PATCH] adapt to embed cairo in mono --- Crow.csproj | 7 ++- Crow.dll.config | 3 +- src/CompilerServices/CompilerServices.cs | 6 ++- src/Configuration.cs | 2 +- src/GraphicObjects/Layoutable.cs | 55 ++++++++++++++++++++++++ src/GraphicObjects/NumericControl.cs | 2 + src/Instantiator.cs | 18 +++++++- src/Interface.cs | 32 ++++++++------ src/rsvg/Global.cs | 6 +-- src/rsvg/Handle.cs | 26 +++++------ 10 files changed, 119 insertions(+), 38 deletions(-) create mode 100644 src/GraphicObjects/Layoutable.cs diff --git a/Crow.csproj b/Crow.csproj index f6d78c1a..6e0b503c 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -1,5 +1,5 @@  - + Debug AnyCPU @@ -15,7 +15,6 @@ 4 False true - False OnBuildSuccess v4.5 C# Rapid Open Widget @@ -24,14 +23,14 @@ $(SolutionDir)build\obj\$(Configuration) crow.key 8.0.30703 - 2.0 0.5 + false true full true - DEBUG_UPDATE0;DEBUG_FOCUS0;DEBUG_LAYOUTING0;TRACE0;DEBUG;__linux__;MEASURE_TIME0;DEBUG_LOAD0;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE0 + DEBUG_UPDATE0;DEBUG_FOCUS0;DEBUG_LAYOUTING0;TRACE0;DEBUG0;__linux__;MEASURE_TIME0;DEBUG_LOAD0;DEBUG_BINDING0;DEBUG_CLIP_RECTANGLE0 false diff --git a/Crow.dll.config b/Crow.dll.config index ef7562ac..13de603c 100644 --- a/Crow.dll.config +++ b/Crow.dll.config @@ -5,7 +5,7 @@ - + @@ -17,3 +17,4 @@ + \ No newline at end of file diff --git a/src/CompilerServices/CompilerServices.cs b/src/CompilerServices/CompilerServices.cs index 827ee617..5edcc79e 100644 --- a/src/CompilerServices/CompilerServices.cs +++ b/src/CompilerServices/CompilerServices.cs @@ -386,8 +386,10 @@ namespace Crow /// Extention method name internal static MethodInfo SearchExtMethod(Type t, string methodName){ MethodInfo mi = null; - mi = GetExtensionMethods (Assembly.GetEntryAssembly(), t) - .Where (em => em.Name == methodName).FirstOrDefault (); + Assembly entryAss = Assembly.GetEntryAssembly (); + if (entryAss!=null) + mi = GetExtensionMethods (entryAss, t) + .Where (em => em.Name == methodName).FirstOrDefault (); if (mi != null) return mi; diff --git a/src/Configuration.cs b/src/Configuration.cs index 8f89dbfc..1f91e19c 100644 --- a/src/Configuration.cs +++ b/src/Configuration.cs @@ -68,7 +68,7 @@ namespace Crow static Dictionary items; static Configuration () - { + { items = new Dictionary (); string configRoot = Path.Combine( diff --git a/src/GraphicObjects/Layoutable.cs b/src/GraphicObjects/Layoutable.cs new file mode 100644 index 00000000..92aeb252 --- /dev/null +++ b/src/GraphicObjects/Layoutable.cs @@ -0,0 +1,55 @@ +// +// ILayoutable.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2013-2017 Jean-Philippe Bruyère +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in +// all copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +// THE SOFTWARE. + +using System; +using System.Collections.Generic; + +namespace Crow +{ + public class Layoutable + { + /// Parent in the graphic tree + Layoutable Parent { get; set; } + /// The logical parent (used mainly for bindings) as opposed + /// to the parent in the graphic tree + Layoutable LogicalParent { get; set; } + + Rectangle ClientRectangle { get; } + Rectangle getSlot(); + + bool ArrangeChildren { get; } + LayoutingType RegisteredLayoutings { get; set; } + void RegisterForLayouting(LayoutingType layoutType); + void RegisterClip(Rectangle clip); + bool UpdateLayout(LayoutingType layoutType); + + + Rectangle ContextCoordinates(Rectangle r); + Rectangle ScreenCoordinates (Rectangle r); + + } +} + diff --git a/src/GraphicObjects/NumericControl.cs b/src/GraphicObjects/NumericControl.cs index 8ab60edb..551668b9 100644 --- a/src/GraphicObjects/NumericControl.cs +++ b/src/GraphicObjects/NumericControl.cs @@ -30,6 +30,8 @@ using System.ComponentModel; namespace Crow { + //TODO: I'm waiting c#8 for default interface members implementation to set NumericControl and other widget base + //mecanics as interface to allow multiple inheritance. public abstract class NumericControl : TemplatedControl { #region CTOR diff --git a/src/Instantiator.cs b/src/Instantiator.cs index 4c236cd4..6cda11c3 100644 --- a/src/Instantiator.cs +++ b/src/Instantiator.cs @@ -336,15 +336,29 @@ namespace Crow ctx.il.Emit (OpCodes.Ldloc_0); ctx.il.Emit (OpCodes.Ldloc_0); + //TODO: optimize this Type t = Type.GetType ("Crow." + reader.Name); if (t == null) { - Assembly a = Assembly.GetEntryAssembly (); - foreach (Type expT in a.GetExportedTypes ()) { + Assembly ea = Assembly.GetEntryAssembly (); + foreach (Type expT in ea.GetExportedTypes ()) { if (expT.Name == reader.Name) { t = expT; break; } } + if (t == null) { + foreach (AssemblyName an in Assembly.GetEntryAssembly().GetReferencedAssemblies()) { + Assembly a = Assembly.Load (an); + foreach (Type expT in a.GetExportedTypes ()) { + if (expT.Name == reader.Name) { + t = expT; + break; + } + } + if (t != null) + break; + } + } } if (t == null) throw new Exception (reader.Name + " type not found"); diff --git a/src/Interface.cs b/src/Interface.cs index 53d90ea5..621f4a34 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -50,7 +50,7 @@ namespace Crow /// - the resulting bitmap of the interface /// public class Interface : ILayoutable - { + { #region CTOR static Interface(){ loadCursors (); @@ -64,6 +64,7 @@ namespace Crow FontRenderingOptions.SubpixelOrder = SubpixelOrder.Rgb; } public Interface(){ + Console.WriteLine ("Interface CTOR"); CurrentInterface = this; CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.InvariantCulture; } @@ -188,6 +189,8 @@ namespace Crow } /// Search for .style resources in assembly static void loadStylingFromAssembly (Assembly assembly) { + if (assembly == null) + return; foreach (string s in assembly .GetManifestResourceNames () .Where (r => r.EndsWith (".style", StringComparison.OrdinalIgnoreCase))) { @@ -197,15 +200,15 @@ namespace Crow } static void loadCursors(){ //Load cursors - XCursor.Cross = XCursorFile.Load("#Crow.Images.Icons.Cursors.cross").Cursors[0]; - XCursor.Default = XCursorFile.Load("#Crow.Images.Icons.Cursors.arrow").Cursors[0]; - XCursor.NW = XCursorFile.Load("#Crow.Images.Icons.Cursors.top_left_corner").Cursors[0]; - XCursor.NE = XCursorFile.Load("#Crow.Images.Icons.Cursors.top_right_corner").Cursors[0]; - XCursor.SW = XCursorFile.Load("#Crow.Images.Icons.Cursors.bottom_left_corner").Cursors[0]; - XCursor.SE = XCursorFile.Load("#Crow.Images.Icons.Cursors.bottom_right_corner").Cursors[0]; - XCursor.H = XCursorFile.Load("#Crow.Images.Icons.Cursors.sb_h_double_arrow").Cursors[0]; - XCursor.V = XCursorFile.Load("#Crow.Images.Icons.Cursors.sb_v_double_arrow").Cursors[0]; - XCursor.Text = XCursorFile.Load("#Crow.Images.Icons.Cursors.ibeam").Cursors[0]; + XCursor.Cross = XCursorFile.Load ("#Crow.Images.Icons.Cursors.cross").Cursors [0]; + XCursor.Default = XCursorFile.Load ("#Crow.Images.Icons.Cursors.arrow").Cursors [0]; + XCursor.NW = XCursorFile.Load ("#Crow.Images.Icons.Cursors.top_left_corner").Cursors [0]; + XCursor.NE = XCursorFile.Load ("#Crow.Images.Icons.Cursors.top_right_corner").Cursors [0]; + XCursor.SW = XCursorFile.Load ("#Crow.Images.Icons.Cursors.bottom_left_corner").Cursors [0]; + XCursor.SE = XCursorFile.Load ("#Crow.Images.Icons.Cursors.bottom_right_corner").Cursors [0]; + XCursor.H = XCursorFile.Load ("#Crow.Images.Icons.Cursors.sb_h_double_arrow").Cursors [0]; + XCursor.V = XCursorFile.Load ("#Crow.Images.Icons.Cursors.sb_v_double_arrow").Cursors [0]; + XCursor.Text = XCursorFile.Load ("#Crow.Images.Icons.Cursors.ibeam").Cursors [0]; } #endregion @@ -221,6 +224,8 @@ namespace Crow searchTemplatesIn (Assembly.GetExecutingAssembly ()); } static void searchTemplatesIn(Assembly assembly){ + if (assembly == null) + return; foreach (string resId in assembly .GetManifestResourceNames () .Where (r => r.EndsWith (".template", StringComparison.OrdinalIgnoreCase))) { @@ -240,12 +245,15 @@ namespace Crow public static Stream GetStreamFromPath (string path) { Stream stream = null; + Assembly ass = null; if (path.StartsWith ("#")) { string resId = path.Substring (1); //try/catch added to prevent nunit error try { - stream = System.Reflection.Assembly.GetEntryAssembly ().GetManifestResourceStream (resId); + ass = Assembly.GetEntryAssembly (); + if (ass != null) + stream = ass.GetManifestResourceStream (resId); } catch{} if (stream == null)//try to find ressource in Crow assembly stream = System.Reflection.Assembly.GetExecutingAssembly ().GetManifestResourceStream (resId); @@ -661,7 +669,7 @@ namespace Crow } #endregion - public void ProcessResize(Rectangle bounds){ + public void ProcessResize(Rectangle bounds){ lock (UpdateMutex) { clientRectangle = bounds; int stride = 4 * ClientRectangle.Width; diff --git a/src/rsvg/Global.cs b/src/rsvg/Global.cs index 65917012..b040ae63 100644 --- a/src/rsvg/Global.cs +++ b/src/rsvg/Global.cs @@ -9,14 +9,14 @@ namespace Rsvg { #region Autogenerated code public class Global { - [DllImport("rsvg-2")] + [DllImport(Handle.librsvg)] static extern void rsvg_set_default_dpi_x_y(double dpi_x, double dpi_y); public static void SetDefaultDpiXY(double dpi_x, double dpi_y) { rsvg_set_default_dpi_x_y(dpi_x, dpi_y); } - [DllImport("rsvg-2")] + [DllImport(Handle.librsvg)] static extern int rsvg_error_quark(); public static int ErrorQuark { @@ -27,7 +27,7 @@ namespace Rsvg { } } - [DllImport("rsvg-2")] + [DllImport(Handle.librsvg)] static extern void rsvg_set_default_dpi(double dpi); public static double DefaultDpi { diff --git a/src/rsvg/Handle.cs b/src/rsvg/Handle.cs index 039d3b6e..71528496 100644 --- a/src/rsvg/Handle.cs +++ b/src/rsvg/Handle.cs @@ -6,10 +6,10 @@ namespace Rsvg { using System.Runtime.InteropServices; public class Handle { - + public const string librsvg = "rsvg"; public IntPtr Raw; - [DllImport("rsvg-2")] + [DllImport(librsvg)] static extern IntPtr rsvg_handle_new(); public Handle () @@ -17,7 +17,7 @@ namespace Rsvg { Raw = rsvg_handle_new(); } - [DllImport("rsvg-2")] + [DllImport(librsvg)] static extern unsafe IntPtr rsvg_handle_new_from_data(byte[] data, UIntPtr n_data, out IntPtr error); public unsafe Handle (byte[] data) @@ -30,7 +30,7 @@ namespace Rsvg { if (error != IntPtr.Zero) throw new Exception (error.ToString()); } - [DllImport("rsvg-2")] + [DllImport(librsvg)] static extern unsafe IntPtr rsvg_handle_new_from_file(string file_name, out IntPtr error); public unsafe Handle (string file_name) @@ -40,10 +40,10 @@ namespace Rsvg { if (error != IntPtr.Zero) throw new Exception (error.ToString()); } - [DllImport("rsvg-2")] + [DllImport(librsvg)] static extern IntPtr rsvg_handle_get_base_uri(IntPtr raw); - [DllImport("rsvg-2")] + [DllImport(librsvg)] static extern void rsvg_handle_set_dpi(IntPtr raw, double dpi); public double Dpi { @@ -52,7 +52,7 @@ namespace Rsvg { } } - [DllImport("rsvg-2")] + [DllImport(librsvg)] static extern void rsvg_handle_render_cairo(IntPtr raw, IntPtr cr); public void RenderCairo(Cairo.Context cr) { @@ -61,14 +61,14 @@ namespace Rsvg { } } - [DllImport("rsvg-2")] + [DllImport(librsvg)] static extern void rsvg_handle_set_dpi_x_y(IntPtr raw, double dpi_x, double dpi_y); public void SetDpiXY(double dpi_x, double dpi_y) { rsvg_handle_set_dpi_x_y(Raw, dpi_x, dpi_y); } - [DllImport("rsvg-2")] + [DllImport(librsvg)] static extern void rsvg_handle_get_dimensions(IntPtr raw, IntPtr dimension_data); public Rsvg.DimensionData Dimensions { @@ -82,7 +82,7 @@ namespace Rsvg { } } - [DllImport("rsvg-2")] + [DllImport(librsvg)] static extern unsafe bool rsvg_handle_close(IntPtr raw, out IntPtr error); public unsafe bool Close() { @@ -92,7 +92,7 @@ namespace Rsvg { return raw_ret; } - [DllImport("rsvg-2")] + [DllImport(librsvg)] static extern IntPtr rsvg_handle_get_title(IntPtr raw); public string Title { @@ -102,14 +102,14 @@ namespace Rsvg { } } - [DllImport("rsvg-2")] + [DllImport(librsvg)] static extern void rsvg_handle_render_cairo_sub(IntPtr raw, IntPtr cr, string id); public void RenderCairoSub(Cairo.Context cr, string id) { rsvg_handle_render_cairo_sub(Raw, cr == null ? IntPtr.Zero : cr.Handle, id); } - [DllImport("rsvg-2")] + [DllImport(librsvg)] static extern IntPtr rsvg_handle_get_metadata(IntPtr raw); public string Metadata { -- 2.47.3