From: Jean-Philippe Bruyère Date: Mon, 7 May 2018 06:12:56 +0000 (+0200) Subject: first tests with vkvg as backend X-Git-Url: https://git.osiis.dedyn.io/?a=commitdiff_plain;h=6b02331dfe7c6d8290c136ce20b4a7c655b47aae;p=jp%2Fcrow.git first tests with vkvg as backend --- diff --git a/Crow.Test/Crow.Test.csproj b/Crow.Test/Crow.Test.csproj index cf7b10a0..12c612c8 100644 --- a/Crow.Test/Crow.Test.csproj +++ b/Crow.Test/Crow.Test.csproj @@ -10,7 +10,7 @@ Crow.Test Crow.Test v4.6.1 - 0.7 + 0.5 true diff --git a/Crow.csproj b/Crow.csproj index 1b5b3406..2580dfce 100644 --- a/Crow.csproj +++ b/Crow.csproj @@ -88,7 +88,6 @@ - @@ -222,6 +221,20 @@ + + + + + + + + + + + + + + @@ -251,6 +264,9 @@ + + + @@ -395,5 +411,6 @@ + diff --git a/Crow.sln b/Crow.sln index 4d3e4799..fdcd2fd3 100644 --- a/Crow.sln +++ b/Crow.sln @@ -9,6 +9,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Crow.Test", "Crow.Test\Crow EndProject Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CrowIDE", "CrowIDE\CrowIDE.csproj", "{B6D911CD-1D09-42FC-B300-9187190F2AE1}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "vkglfw.net", "..\..\vulkan\vkglfw.net\vkglfw.net.csproj", "{FE2D5F0D-F9F4-4F88-9D32-C33D8A4A42C9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -29,27 +31,39 @@ Global {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Debug|Any CPU.Build.0 = Debug|Any CPU {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Release|Any CPU.ActiveCfg = Release|Any CPU {C2980F9B-4798-4C05-99E2-E174810F7C7B}.Release|Any CPU.Build.0 = Release|Any CPU + {FE2D5F0D-F9F4-4F88-9D32-C33D8A4A42C9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FE2D5F0D-F9F4-4F88-9D32-C33D8A4A42C9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FE2D5F0D-F9F4-4F88-9D32-C33D8A4A42C9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FE2D5F0D-F9F4-4F88-9D32-C33D8A4A42C9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution Policies = $0 $0.StandardHeader = $1 $1.Text = @\n${FileName}\n \nAuthor:\n ${AuthorName} <${AuthorEmail}>\n\nCopyright (c) 2013-2017 Jean-Philippe Bruyère\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the "Software"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in\nall copies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\nTHE SOFTWARE. - $1.IncludeInNewFiles = True $0.DotNetNamingPolicy = $2 - $2.DirectoryNamespaceAssociation = None - $2.ResourceNamePolicy = FileFormatDefault $0.TextStylePolicy = $3 - $3.FileWidth = 120 - $3.TabsToSpaces = False $3.EolMarker = Unix - $3.inheritsSet = VisualStudio - $3.inheritsScope = text/plain $3.scope = text/x-csharp $0.CSharpFormattingPolicy = $4 $4.AfterDelegateDeclarationParameterComma = True - $4.inheritsSet = Mono - $4.inheritsScope = text/x-csharp $4.scope = text/x-csharp + $4.IndentSwitchSection = False + $4.NewLinesForBracesInProperties = False + $4.NewLinesForBracesInAccessors = False + $4.NewLinesForBracesInAnonymousMethods = False + $4.NewLinesForBracesInControlBlocks = False + $4.NewLinesForBracesInAnonymousTypes = False + $4.NewLinesForBracesInObjectCollectionArrayInitializers = False + $4.NewLinesForBracesInLambdaExpressionBody = False + $4.NewLineForElse = False + $4.NewLineForCatch = False + $4.NewLineForFinally = False + $4.NewLineForMembersInObjectInit = False + $4.NewLineForMembersInAnonymousTypes = False + $4.NewLineForClausesInQuery = False + $4.SpacingAfterMethodDeclarationName = True + $4.SpaceAfterMethodCallName = True + $4.SpaceBeforeOpenSquareBracket = True $0.VersionControlPolicy = $5 $5.CommitMessageStyle = $6 $6.Indent = @\t @@ -57,7 +71,6 @@ Global $6.LastFilePostfix = "@:\n " $6.LineAlign = 0 $6.Wrap = False - $5.inheritsSet = Mono description = @C.R.O.W. c# Rapid Open Widgets\n\nCrow is a pure c# widget toolkit with XML definition of interface, bindings, styling...\n version = 0.5 EndGlobalSection diff --git a/CrowIDE/CrowIDE.csproj b/CrowIDE/CrowIDE.csproj index 1cae7289..b0ed9dad 100644 --- a/CrowIDE/CrowIDE.csproj +++ b/CrowIDE/CrowIDE.csproj @@ -52,6 +52,12 @@ %24{SolutionDir}\build\%24{ProjectConfigName} false + + Program + %24{TargetName} + %24{SolutionDir}\build\%24{ProjectConfigName} + false + diff --git a/CrowIDE/src/Editors/CodeBuffer/TextEditor.cs b/CrowIDE/src/Editors/CodeBuffer/TextEditor.cs index 6b7234dc..cbb42e28 100644 --- a/CrowIDE/src/Editors/CodeBuffer/TextEditor.cs +++ b/CrowIDE/src/Editors/CodeBuffer/TextEditor.cs @@ -28,7 +28,7 @@ using System; using System.Xml.Serialization; using System.ComponentModel; using System.Collections; -using Cairo; +using vkvg; using System.Text; using System.Collections.Generic; using System.Text.RegularExpressions; diff --git a/CrowIDE/src/Editors/ImlVisualEditor.cs b/CrowIDE/src/Editors/ImlVisualEditor.cs index b1759fbc..84213080 100644 --- a/CrowIDE/src/Editors/ImlVisualEditor.cs +++ b/CrowIDE/src/Editors/ImlVisualEditor.cs @@ -29,7 +29,7 @@ using Crow.IML; using System.Text; using System.Xml; using System.Diagnostics; -using Cairo; +using vkvg; namespace Crow.Coding { diff --git a/CrowIDE/src/Editors/SourceEditor.cs b/CrowIDE/src/Editors/SourceEditor.cs index 4234a683..a25e13a9 100644 --- a/CrowIDE/src/Editors/SourceEditor.cs +++ b/CrowIDE/src/Editors/SourceEditor.cs @@ -28,7 +28,7 @@ using System; using System.Xml.Serialization; using System.ComponentModel; using System.Collections; -using Cairo; +using vkvg; using System.Text; using System.Collections.Generic; using System.Text.RegularExpressions; diff --git a/CrowIDE/src/Editors/SvgEditor.cs b/CrowIDE/src/Editors/SvgEditor.cs index 219eea67..bf01f96a 100644 --- a/CrowIDE/src/Editors/SvgEditor.cs +++ b/CrowIDE/src/Editors/SvgEditor.cs @@ -25,7 +25,7 @@ // THE SOFTWARE. using System; using System.ComponentModel; -using Cairo; +using vkvg; namespace Crow.Coding { diff --git a/CrowIDE/src/GraphicObjectDesignContainer.cs b/CrowIDE/src/GraphicObjectDesignContainer.cs index 4540898b..31528fd4 100644 --- a/CrowIDE/src/GraphicObjectDesignContainer.cs +++ b/CrowIDE/src/GraphicObjectDesignContainer.cs @@ -24,7 +24,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; -using Cairo; +using vkvg; namespace Crow.Coding { diff --git a/CrowIDE/src/MemberView/MembersView.cs b/CrowIDE/src/MemberView/MembersView.cs index d8a9ddcd..fc85a08d 100644 --- a/CrowIDE/src/MemberView/MembersView.cs +++ b/CrowIDE/src/MemberView/MembersView.cs @@ -25,7 +25,7 @@ using System.ComponentModel; using System.Reflection; using System.Collections.Generic; using System.Linq; -using Cairo; +using vkvg; namespace Crow.Coding { diff --git a/CrowIDE/src/VerticalLine.cs b/CrowIDE/src/VerticalLine.cs index 03afeea8..da442b96 100644 --- a/CrowIDE/src/VerticalLine.cs +++ b/CrowIDE/src/VerticalLine.cs @@ -25,6 +25,7 @@ // THE SOFTWARE. using System; using Crow; +using vkvg; namespace Crow.Coding { @@ -34,7 +35,7 @@ namespace Crow.Coding { } - protected override void onDraw (Cairo.Context gr) + protected override void onDraw (Context gr) { base.onDraw (gr); Foreground.SetAsSource (gr); diff --git a/Tests/GraphicObjects/ColorCircleSelector.cs b/Tests/GraphicObjects/ColorCircleSelector.cs index 7ab9a9bf..a6fe502d 100644 --- a/Tests/GraphicObjects/ColorCircleSelector.cs +++ b/Tests/GraphicObjects/ColorCircleSelector.cs @@ -24,7 +24,7 @@ // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; -using Cairo; +using vkvg; using Crow; namespace Test diff --git a/Tests/GraphicObjects/HexaContainer.cs b/Tests/GraphicObjects/HexaContainer.cs index 23964e9c..22eb1a81 100644 --- a/Tests/GraphicObjects/HexaContainer.cs +++ b/Tests/GraphicObjects/HexaContainer.cs @@ -25,7 +25,7 @@ // THE SOFTWARE. using System; using Crow; -using Cairo; +using vkvg; namespace Tutorials2 { diff --git a/Tests/GraphicObjects/SimpleGauge.cs b/Tests/GraphicObjects/SimpleGauge.cs index ce92abef..2ff9635c 100644 --- a/Tests/GraphicObjects/SimpleGauge.cs +++ b/Tests/GraphicObjects/SimpleGauge.cs @@ -26,7 +26,7 @@ using System; using Crow; using System.ComponentModel; -using Cairo; +using vkvg; namespace Tutorials { diff --git a/Tests/GraphicObjects/TechBorder.cs b/Tests/GraphicObjects/TechBorder.cs index 4f818e51..dd16c30c 100644 --- a/Tests/GraphicObjects/TechBorder.cs +++ b/Tests/GraphicObjects/TechBorder.cs @@ -25,6 +25,7 @@ // THE SOFTWARE. using System; using Crow; +using vkvg; namespace Tests { @@ -37,7 +38,7 @@ namespace Tests { return base.measureRawSize (lt) + 6; } - protected override void onDraw (Cairo.Context gr) + protected override void onDraw (Context gr) { gr.Save (); diff --git a/Tests/HelloWorld.cs b/Tests/HelloWorld.cs index 75cc9bd5..8149ac0e 100644 --- a/Tests/HelloWorld.cs +++ b/Tests/HelloWorld.cs @@ -26,28 +26,26 @@ using System; using Crow; -using Tutorials; +//using Tutorials; namespace Tests { - class HelloWorld : CrowWindow + class HelloWorld : CrowApplication { public HelloWorld () - : base(800, 600,"Crow Test with OpenTK") + : base(800, 600) { } - protected override void OnLoad (EventArgs e) - { - base.OnLoad (e); - LoadIMLFragment (@""); - } - [STAThread] static void Main () { - HelloWorld win = new HelloWorld (); - win.Run (30); + using (HelloWorld win = new HelloWorld ()) { + + //win.Load (@"Interfaces/Divers/0.crow").DataSource = win; + win.Load (@"Interfaces/GraphicObject/0.crow"); + win.Run (); + } } } } \ No newline at end of file diff --git a/Tests/InterfaceControler.cs b/Tests/InterfaceControler.cs index 034cab39..68bfc63b 100644 --- a/Tests/InterfaceControler.cs +++ b/Tests/InterfaceControler.cs @@ -133,7 +133,7 @@ namespace Crow public InterfaceControler(Rectangle ifaceBounds){ iRect = ifaceBounds; - CrowInterface = new Interface (); + //CrowInterface = new Interface (); CrowInterface.Init (); #if MEASURE_TIME diff --git a/Tests/Interfaces/GraphicObject/0.crow b/Tests/Interfaces/GraphicObject/0.crow index 7fdd607f..4856f1c3 100755 --- a/Tests/Interfaces/GraphicObject/0.crow +++ b/Tests/Interfaces/GraphicObject/0.crow @@ -1,3 +1,4 @@ - \ No newline at end of file + + \ No newline at end of file diff --git a/Tests/Tests.csproj b/Tests/Tests.csproj index c86ff9cb..082f1aab 100644 --- a/Tests/Tests.csproj +++ b/Tests/Tests.csproj @@ -8,7 +8,7 @@ Exe Tests Tests - Tests.BasicTests + Tests.HelloWorld v4.5 AnyCPU 0.5 @@ -75,6 +75,12 @@ %24{SolutionDir}\build\%24{ProjectConfigName} false + + Program + %24{TargetName} + %24{SolutionDir}\build\%24{ProjectConfigName} + false + @@ -86,24 +92,11 @@ - - - - - - - - - - - - - @@ -382,6 +375,19 @@ PreserveNewest + + + + + + + + + + + + + diff --git a/src/BmpPicture.cs b/src/BmpPicture.cs index e3af9c79..a549f339 100644 --- a/src/BmpPicture.cs +++ b/src/BmpPicture.cs @@ -26,7 +26,7 @@ using System; using System.IO; -using Cairo; +using vkvg; namespace Crow { @@ -110,14 +110,13 @@ namespace Crow widthRatio = heightRatio; } - using (ImageSurface tmp = new ImageSurface (Format.Argb32, bounds.Width, bounds.Height)) { + using (Surface tmp = new Surface (CrowApplication.dev, bounds.Width, bounds.Height)) { 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); - using (ImageSurface imgSurf = new ImageSurface (image, Format.Argb32, - Dimensions.Width, Dimensions.Height, 4 * Dimensions.Width)) { + using (Surface imgSurf = new Surface (CrowApplication.dev, ref image, Dimensions.Width, Dimensions.Height)) { gr.SetSourceSurface (imgSurf, 0,0); gr.Paint (); } @@ -157,8 +156,7 @@ namespace Crow gr.Scale (widthRatio, heightRatio); gr.Translate ((rect.Width/widthRatio - Dimensions.Width)/2, (rect.Height/heightRatio - Dimensions.Height)/2); - using (ImageSurface imgSurf = new ImageSurface (image, Format.Argb32, - Dimensions.Width, Dimensions.Height, 4 * Dimensions.Width)) { + using (Surface imgSurf = new Surface (CrowApplication.dev, ref image, Dimensions.Width, Dimensions.Height)) { gr.SetSourceSurface (imgSurf, 0,0); gr.Paint (); } diff --git a/src/Cairo/CairoHelpers.cs b/src/Cairo/CairoHelpers.cs index 44060259..2290e319 100644 --- a/src/Cairo/CairoHelpers.cs +++ b/src/Cairo/CairoHelpers.cs @@ -28,6 +28,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using vkvg; namespace Crow { @@ -57,18 +58,18 @@ namespace Crow return arr[minp]; } - public static void CairoRectangle(Cairo.Context gr, Rectangle r, double radius, double stroke = 0.0) + public static void CairoRectangle(Context gr, Rectangle r, double radius, double stroke = 0.0) { if (radius > 0) CairoHelpers.DrawRoundedRectangle (gr, r, radius, stroke); else gr.Rectangle (r, stroke); } - public static void CairoCircle(Cairo.Context gr, Rectangle r) + public static void CairoCircle(Context gr, Rectangle r) { gr.Arc(r.X + r.Width/2, r.Y + r.Height/2, Math.Min(r.Width,r.Height)/2, 0, 2*Math.PI); } - public static void DrawRoundedRectangle(Cairo.Context gr, Rectangle r, double radius, double stroke = 0.0) + public static void DrawRoundedRectangle(Context gr, Rectangle r, double radius, double stroke = 0.0) { if (stroke>0.0) { gr.LineWidth = stroke; @@ -78,7 +79,7 @@ namespace Crow }else DrawRoundedRectangle(gr, r.X, r.Y, r.Width, r.Height, radius); } - public static void DrawRoundedRectangle(Cairo.Context gr, double x, double y, double width, double height, double radius) + public static void DrawRoundedRectangle(Context gr, double x, double y, double width, double height, double radius) { gr.Save(); @@ -96,7 +97,7 @@ namespace Crow gr.ClosePath(); gr.Restore(); } - public static void StrokeRaisedRectangle(Cairo.Context gr, Rectangle r, double width = 1) + public static void StrokeRaisedRectangle(Context gr, Rectangle r, double width = 1) { gr.Save(); r.Inflate((int)-width / 2, (int)-width / 2); @@ -115,7 +116,7 @@ namespace Crow gr.Restore(); } - public static void StrokeLoweredRectangle(Cairo.Context gr, Rectangle r, double width = 1) + public static void StrokeLoweredRectangle(Context gr, Rectangle r, double width = 1) { gr.Save(); r.Inflate((int)-width / 2, (int)-width / 2); diff --git a/src/CrowApplication.cs b/src/CrowApplication.cs new file mode 100644 index 00000000..3f7f8ade --- /dev/null +++ b/src/CrowApplication.cs @@ -0,0 +1,101 @@ +// +// CrowApplication.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.Threading; +using vkglfw; + +namespace Crow +{ + public class CrowApplication : IDisposable + { + public static VkEngine vke; + public static vkvg.Device dev; + + Interface iFace; + vkvg.Surface surf; + + public CrowApplication (int width, int height) + { + vke = new VkEngine (width, height); + dev = new vkvg.Device (vke); + surf = new vkvg.Surface (dev, width, height); + + using (vkvg.Context ctx = new vkvg.Context (surf)) { + ctx.SetSource (0.1, 0.1, 0.1); + ctx.Paint (); + } + + + iFace = new Interface (surf); + iFace.Init (); + + Thread t = new Thread (interfaceThread); + t.IsBackground = true; + t.Start (); + } + ~CrowApplication () + { + Dispose (false); + } + + public void Run () { + vke.Run (surf); + } + public GraphicObject Load (string path){ + return iFace.AddWidget (path); + } + void interfaceThread() + { + while (iFace.ClientRectangle.Size.Width == 0) + Thread.Sleep (5); + + while (true) { + iFace.Update (); + Thread.Sleep (2); + } + } + + #region IDisposable implementation + public void Dispose () + { + Dispose (true); + GC.SuppressFinalize (this); + } + + protected virtual void Dispose (bool disposing) + { + if (!disposing) + return; + + surf.Dispose (); + dev.Dispose (); + vke.Dispose (); + } + #endregion + + } +} + diff --git a/src/ExtensionsMethods.cs b/src/ExtensionsMethods.cs index 340a8ceb..3d9716f8 100644 --- a/src/ExtensionsMethods.cs +++ b/src/ExtensionsMethods.cs @@ -26,6 +26,7 @@ using System; using System.Linq.Expressions; +using vkvg; namespace Crow { @@ -33,7 +34,7 @@ namespace Crow { #region Cairo extensions - public static void Rectangle(this Cairo.Context ctx, Rectangle r, double stroke = 0.0) + public static void Rectangle(this Context ctx, Rectangle r, double stroke = 0.0) { if (stroke > 0.0) { ctx.LineWidth = stroke; @@ -43,41 +44,41 @@ namespace Crow }else ctx.Rectangle (r.X, r.Y, r.Width, r.Height); } - public static double GetLength(this Cairo.PointD p){ + public static double GetLength(this PointD p){ return Math.Sqrt (Math.Pow (p.X, 2) + Math.Pow (p.Y, 2)); } - public static Cairo.PointD GetPerp(this Cairo.PointD p){ - return new Cairo.PointD(-p.Y, p.X); + public static PointD GetPerp(this PointD p){ + return new PointD(-p.Y, p.X); } - public static Cairo.PointD GetNormalized(this Cairo.PointD p){ + public static PointD GetNormalized(this PointD p){ double length = p.GetLength(); p.X /= length; p.Y /= length; return p; } - public static Cairo.PointD Substract(this Cairo.PointD p1, Cairo.PointD p2){ - return new Cairo.PointD(p1.X - p2.X, p1.Y - p2.Y); + public static PointD Substract(this PointD p1, PointD p2){ + return new PointD(p1.X - p2.X, p1.Y - p2.Y); } - public static Cairo.PointD Divide(this Cairo.PointD p1, double d){ - return new Cairo.PointD(p1.X / d, p1.Y / d); + public static PointD Divide(this PointD p1, double d){ + return new PointD(p1.X / d, p1.Y / d); } - public static Cairo.PointD Add(this Cairo.PointD p1, Cairo.PointD p2){ - return new Cairo.PointD(p1.X + p2.X, p1.Y + p2.Y); + public static PointD Add(this PointD p1, PointD p2){ + return new PointD(p1.X + p2.X, p1.Y + p2.Y); } - public static Cairo.PointD Multiply(this Cairo.PointD p1, double v){ - return new Cairo.PointD(p1.X * v, p1.Y * v); + public static PointD Multiply(this PointD p1, double v){ + return new PointD(p1.X * v, p1.Y * v); } - public static void DrawCote(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2, + public static void DrawCote(this Context ctx, PointD p1, PointD p2, double stroke = 1.0, bool fill = false, double arrowWidth = 3.0, double arrowLength = 7.0) { - Cairo.PointD vDir = p2.Substract(p1); + PointD vDir = p2.Substract(p1); vDir = vDir.GetNormalized (); - Cairo.PointD vPerp = vDir.GetPerp (); + PointD vPerp = vDir.GetPerp (); - Cairo.PointD pA0 = p1.Add(vDir.Multiply(arrowLength)); - Cairo.PointD pA1 = p2.Substract(vDir.Multiply(arrowLength)); + PointD pA0 = p1.Add(vDir.Multiply(arrowLength)); + PointD pA1 = p2.Substract(vDir.Multiply(arrowLength)); - Cairo.PointD vA = vPerp.Multiply (arrowWidth); + PointD vA = vPerp.Multiply (arrowWidth); ctx.MoveTo (p1); ctx.LineTo (pA0.Add (vA)); @@ -104,17 +105,17 @@ namespace Crow ctx.LineWidth = stroke; ctx.Stroke (); } - public static void DrawCoteInverse(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2, + public static void DrawCoteInverse(this Context ctx, PointD p1, PointD p2, double stroke = 1.0, bool fill = false, double arrowWidth = 3.0, double arrowLength = 7.0) { - Cairo.PointD vDir = p2.Substract(p1); + PointD vDir = p2.Substract(p1); vDir = vDir.GetNormalized (); - Cairo.PointD vPerp = vDir.GetPerp (); + PointD vPerp = vDir.GetPerp (); - Cairo.PointD pA0 = p1.Add(vDir.Multiply(arrowLength)); - Cairo.PointD pA1 = p2.Substract(vDir.Multiply(arrowLength)); + PointD pA0 = p1.Add(vDir.Multiply(arrowLength)); + PointD pA1 = p2.Substract(vDir.Multiply(arrowLength)); - Cairo.PointD vA = vPerp.Multiply (arrowWidth); + PointD vA = vPerp.Multiply (arrowWidth); ctx.MoveTo (p1.Add (vA)); ctx.LineTo (pA0); @@ -136,13 +137,13 @@ namespace Crow ctx.LineWidth = stroke; ctx.Stroke (); } - public static void DrawCoteFixed(this Cairo.Context ctx, Cairo.PointD p1, Cairo.PointD p2, + public static void DrawCoteFixed(this Context ctx, PointD p1, PointD p2, double stroke = 1.0, double coteWidth = 3.0) { - Cairo.PointD vDir = p2.Substract(p1); + PointD vDir = p2.Substract(p1); vDir = vDir.GetNormalized (); - Cairo.PointD vPerp = vDir.GetPerp (); - Cairo.PointD vA = vPerp.Multiply (coteWidth); + PointD vPerp = vDir.GetPerp (); + PointD vA = vPerp.Multiply (coteWidth); ctx.MoveTo (p1.Add (vA)); ctx.LineTo (p1.Substract (vA)); @@ -153,9 +154,9 @@ namespace Crow ctx.LineWidth = stroke; ctx.Stroke (); } - public static void SetSourceColor(this Cairo.Context ctx, Color c) + public static void SetSourceColor(this Context ctx, Color c) { - ctx.SetSourceRGBA(c.R,c.G,c.B,c.A); + ctx.SetSource (c.R,c.G,c.B,c.A); } public static void AddColorStop(this Cairo.Gradient grad, double offset, Color c) { diff --git a/src/Fill/Fill.cs b/src/Fill/Fill.cs index d98e47cf..5e36832b 100644 --- a/src/Fill/Fill.cs +++ b/src/Fill/Fill.cs @@ -26,7 +26,7 @@ using System; using System.Collections.Generic; -using Cairo; +using vkvg; namespace Crow { diff --git a/src/Font.cs b/src/Font.cs index bab2c853..e6782026 100644 --- a/src/Font.cs +++ b/src/Font.cs @@ -25,7 +25,7 @@ // THE SOFTWARE. using System; -using Cairo; +using vkvg; namespace Crow { diff --git a/src/Gradient.cs b/src/Gradient.cs index 0806e885..cc695795 100644 --- a/src/Gradient.cs +++ b/src/Gradient.cs @@ -26,7 +26,7 @@ using System; using System.Collections.Generic; -using Cairo; +using vkvg; namespace Crow { @@ -99,7 +99,7 @@ namespace Crow foreach (ColorStop cs in Stops) grad.AddColorStop (cs.Offset, cs.Color); - ctx.SetSource (grad); + //ctx.SetSource (grad); grad.Dispose (); } #endregion diff --git a/src/GraphicObjects/Border.cs b/src/GraphicObjects/Border.cs index adeb32e7..2c11d1db 100644 --- a/src/GraphicObjects/Border.cs +++ b/src/GraphicObjects/Border.cs @@ -28,7 +28,7 @@ using System; using System.Xml.Serialization; using System.ComponentModel; using System.Diagnostics; -using Cairo; +using vkvg; namespace Crow { diff --git a/src/GraphicObjects/Button.cs b/src/GraphicObjects/Button.cs index 8b60dcb9..43d03a02 100644 --- a/src/GraphicObjects/Button.cs +++ b/src/GraphicObjects/Button.cs @@ -33,7 +33,7 @@ using System.Text; using System.Diagnostics; using System.Xml.Serialization; -using Cairo; +using vkvg; using System.ComponentModel; namespace Crow diff --git a/src/GraphicObjects/DockStack.cs b/src/GraphicObjects/DockStack.cs index ae8b9c89..7cb4fe2a 100644 --- a/src/GraphicObjects/DockStack.cs +++ b/src/GraphicObjects/DockStack.cs @@ -25,6 +25,7 @@ // THE SOFTWARE. using System; using Crow.IML; +using vkvg; namespace Crow { @@ -82,7 +83,7 @@ namespace Crow // } Rectangle rIn = default(Rectangle); - double dockThresh = 0.2; + double dockThresh = 0.2f; GraphicObject focusedChild; internal GraphicObject stretchedChild; @@ -178,7 +179,7 @@ namespace Crow RegisterForGraphicUpdate (); } - protected override void onDraw (Cairo.Context gr) + protected override void onDraw (Context gr) { gr.Save (); @@ -237,9 +238,9 @@ namespace Crow break; } gr.LineWidth = 1; - gr.SetSourceRGBA (0.4, 0.4, 0.9, 0.4); + gr.SetSource (0.4, 0.4, 0.9, 0.4); gr.FillPreserve (); - gr.SetSourceRGBA (0.9, 0.9, 1.0, 0.8); + gr.SetSource (0.9, 0.9, 1.0, 0.8); gr.Stroke (); } gr.Restore (); diff --git a/src/GraphicObjects/GraduatedSlider.cs b/src/GraphicObjects/GraduatedSlider.cs index e1d4dd46..932378ba 100644 --- a/src/GraphicObjects/GraduatedSlider.cs +++ b/src/GraphicObjects/GraduatedSlider.cs @@ -28,7 +28,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; -using Cairo; +using vkvg; using System.Xml.Serialization; namespace Crow diff --git a/src/GraphicObjects/GraphicObject.cs b/src/GraphicObjects/GraphicObject.cs index bc955368..07954a63 100644 --- a/src/GraphicObjects/GraphicObject.cs +++ b/src/GraphicObjects/GraphicObject.cs @@ -31,7 +31,7 @@ using System.Xml.Serialization; using System.Reflection; using System.Reflection.Emit; using System.Runtime.CompilerServices; -using Cairo; +using vkvg; using System.Diagnostics; using Crow.IML; using System.Threading; @@ -127,10 +127,10 @@ namespace Crow parentElem.AppendChild (xe); } public Surface CreateIcon (int dragIconSize = 32) { - ImageSurface di = new ImageSurface (Format.Argb32, dragIconSize, dragIconSize); + Surface di = new Surface (CrowApplication.dev, dragIconSize, dragIconSize); using (Context ctx = new Context (di)) { - double div = Math.Max (LastPaintedSlot.Width, LastPaintedSlot.Height); - double s = (double)dragIconSize / div; + float div = Math.Max (LastPaintedSlot.Width, LastPaintedSlot.Height); + float s = (float)dragIconSize / div; ctx.Scale (s, s); if (bmp == null) this.onDraw (ctx); @@ -206,7 +206,7 @@ namespace Crow /// are repeated at each cached levels of the tree with correspondig coordinate system. This is done /// in a dedicated step of the update between layouting and drawing. /// - public Region Clipping; + public Cairo.Region Clipping; #region IValueChange implementation /// @@ -233,7 +233,7 @@ namespace Crow /// action. /// protected GraphicObject () { - Clipping = new Region (); + Clipping = new Cairo.Region(); #if DEBUG uid = currentUid; currentUid++; @@ -1628,9 +1628,9 @@ namespace Crow IsDirty = false; if (bmp != null) bmp.Dispose (); - bmp = new ImageSurface (Format.Argb32, Slot.Width, Slot.Height); + bmp = new Surface (CrowApplication.dev, Slot.Width, Slot.Height); using (Context gr = new Context (bmp)) { - gr.Antialias = Interface.Antialias; + //gr.Antialias = Interface.Antialias; onDraw (gr); } bmp.Flush (); @@ -1650,7 +1650,7 @@ namespace Crow ctx.SetSourceSurface (bmp, rb.X, rb.Y); ctx.Paint (); Clipping.Dispose (); - Clipping = new Region (); + Clipping = new Cairo.Region(); } /// Chained painting routine on the parent context of the actual cached version /// of the widget @@ -1692,7 +1692,7 @@ namespace Crow } void paintDisabled(Context gr, Rectangle rb){ gr.Operator = Operator.Xor; - gr.SetSourceRGBA (0.6, 0.6, 0.6, 0.3); + gr.SetSource (0.6, 0.6, 0.6, 0.3); gr.Rectangle (rb); gr.Fill (); gr.Operator = Operator.Over; diff --git a/src/GraphicObjects/Group.cs b/src/GraphicObjects/Group.cs index a90947a5..2d64fde1 100644 --- a/src/GraphicObjects/Group.cs +++ b/src/GraphicObjects/Group.cs @@ -28,7 +28,7 @@ using System; using System.Collections.Generic; using System.ComponentModel; using System.Xml.Serialization; -using Cairo; +using vkvg; using System.Diagnostics; using System.Reflection; using System.Threading; @@ -332,7 +332,7 @@ namespace Crow foreach (GraphicObject c in Children) { if (!c.Visible) continue; - if (Clipping.Contains (c.Slot + ClientRectangle.Position) == RegionOverlap.Out) + if (Clipping.Contains (c.Slot + ClientRectangle.Position) == Cairo.RegionOverlap.Out) continue; c.Paint (ref gr); } @@ -349,7 +349,7 @@ namespace Crow ctx.Paint (); Clipping.Dispose(); - Clipping = new Region (); + Clipping = new Cairo.Region(); } #endregion diff --git a/src/GraphicObjects/HueSelector.cs b/src/GraphicObjects/HueSelector.cs index 67f4ec6e..ad33243d 100644 --- a/src/GraphicObjects/HueSelector.cs +++ b/src/GraphicObjects/HueSelector.cs @@ -27,7 +27,7 @@ using System; using System.Xml.Serialization; using System.ComponentModel; -using Cairo; +using vkvg; namespace Crow { diff --git a/src/GraphicObjects/Image.cs b/src/GraphicObjects/Image.cs index e83183c0..dd383fc8 100644 --- a/src/GraphicObjects/Image.cs +++ b/src/GraphicObjects/Image.cs @@ -25,7 +25,7 @@ // THE SOFTWARE. using System; -using Cairo; +using vkvg; using System.Xml.Serialization; using System.ComponentModel; using System.Diagnostics; @@ -43,7 +43,7 @@ namespace Crow Picture _pic; string _svgSub; bool scaled, keepProps; - double opacity; + float opacity; #region Public properties /// @@ -138,7 +138,7 @@ namespace Crow /// // TODO:could be moved in GraphicObject [XmlAttributeAttribute()][DefaultValue(1.0)] - public virtual double Opacity { + public virtual float Opacity { get { return opacity; } set { if (opacity == value) @@ -203,7 +203,7 @@ namespace Crow _pic.Paint (gr, ClientRectangle, _svgSub); if (Opacity<1.0) { - gr.SetSourceRGBA (0.0, 0.0, 0.0, 1.0-Opacity); + gr.SetSource (0, 0, 0, 1-Opacity); gr.Operator = Operator.DestOut; gr.Rectangle (ClientRectangle); gr.Fill (); diff --git a/src/GraphicObjects/Label.cs b/src/GraphicObjects/Label.cs index 0e0d9fe1..da332d02 100644 --- a/src/GraphicObjects/Label.cs +++ b/src/GraphicObjects/Label.cs @@ -28,7 +28,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Diagnostics; -using Cairo; +using vkvg; using System.Text.RegularExpressions; using System.Xml.Serialization; using System.ComponentModel; @@ -447,14 +447,17 @@ namespace Crow if (lines == null) lines = getLines; if (!textMeasureIsUpToDate) { - using (ImageSurface img = new ImageSurface (Format.Argb32, 10, 10)) { - using (Context gr = new Context (img)) { + //using (Surface img = new Surface (CrowApplication.dev, 10, 10)) { + if (bmp == null) + bmp = new Surface (CrowApplication.dev, 10, 10); + using (Context gr = new Context (bmp)) { //Cairo.FontFace cf = gr.GetContextFontFace (); - gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); - gr.SetFontSize (Font.Size); - gr.FontOptions = Interface.FontRenderingOptions; - gr.Antialias = Interface.Antialias; + gr.FontFace = Font.Name; +// gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); +// gr.SetFontSize (Font.Size); +// gr.FontOptions = Interface.FontRenderingOptions; +// gr.Antialias = Interface.Antialias; fe = gr.FontExtents; te = new TextExtents (); @@ -476,7 +479,7 @@ namespace Crow return -1; } } - } + //} } return lt == LayoutingType.Height ? cachedTextSize.Height : cachedTextSize.Width; @@ -485,10 +488,11 @@ namespace Crow { base.onDraw (gr); - gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); - gr.SetFontSize (Font.Size); - gr.FontOptions = Interface.FontRenderingOptions; - gr.Antialias = Interface.Antialias; + gr.FontFace = Font.Name; +// gr.SelectFontFace (Font.Name, Font.Slant, Font.Wheight); +// gr.SetFontSize (Font.Size); +// gr.FontOptions = Interface.FontRenderingOptions; +// gr.Antialias = Interface.Antialias; rText = new Rectangle(new Size( measureRawSize(LayoutingType.Width), measureRawSize(LayoutingType.Height))); diff --git a/src/GraphicObjects/PrivateContainer.cs b/src/GraphicObjects/PrivateContainer.cs index d6637247..45aae6c1 100644 --- a/src/GraphicObjects/PrivateContainer.cs +++ b/src/GraphicObjects/PrivateContainer.cs @@ -27,7 +27,7 @@ using System; using System.Xml.Serialization; using System.ComponentModel; -using Cairo; +using vkvg; namespace Crow { @@ -211,7 +211,7 @@ namespace Crow ctx.SetSourceSurface (bmp, rb.X, rb.Y); ctx.Paint (); Clipping.Dispose(); - Clipping = new Region (); + Clipping = new Cairo.Region(); } #endregion diff --git a/src/GraphicObjects/ProgressBar.cs b/src/GraphicObjects/ProgressBar.cs index e8165fd2..d86e6b38 100644 --- a/src/GraphicObjects/ProgressBar.cs +++ b/src/GraphicObjects/ProgressBar.cs @@ -28,7 +28,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; -using Cairo; +using vkvg; using System.Diagnostics; using System.Xml.Serialization; using System.ComponentModel; diff --git a/src/GraphicObjects/SaturationValueSelector.cs b/src/GraphicObjects/SaturationValueSelector.cs index 485a33d2..e7da3ab7 100644 --- a/src/GraphicObjects/SaturationValueSelector.cs +++ b/src/GraphicObjects/SaturationValueSelector.cs @@ -25,7 +25,7 @@ // THE SOFTWARE. using System; -using Cairo; +using vkvg; using System.Xml.Serialization; namespace Crow diff --git a/src/GraphicObjects/Scroller.cs b/src/GraphicObjects/Scroller.cs index 30dd1480..72252c70 100644 --- a/src/GraphicObjects/Scroller.cs +++ b/src/GraphicObjects/Scroller.cs @@ -28,7 +28,7 @@ using System; using System.Xml.Serialization; using System.ComponentModel; using System.Diagnostics; -using Cairo; +using vkvg; namespace Crow { diff --git a/src/GraphicObjects/ScrollingObject.cs b/src/GraphicObjects/ScrollingObject.cs index de4b2113..893fe466 100644 --- a/src/GraphicObjects/ScrollingObject.cs +++ b/src/GraphicObjects/ScrollingObject.cs @@ -28,7 +28,7 @@ using System; using System.Xml.Serialization; using System.ComponentModel; using System.Collections; -using Cairo; +using vkvg; namespace Crow diff --git a/src/GraphicObjects/Shape.cs b/src/GraphicObjects/Shape.cs index a4b3193e..77345b31 100644 --- a/src/GraphicObjects/Shape.cs +++ b/src/GraphicObjects/Shape.cs @@ -28,7 +28,7 @@ using System.Xml.Serialization; using System.ComponentModel; using System.IO; using System.Text; -using Cairo; +using vkvg; namespace Crow { @@ -62,7 +62,7 @@ namespace Crow #endregion string path; - double strokeWidth; + float strokeWidth; public string Path { get { return path; } @@ -76,7 +76,7 @@ namespace Crow } } [XmlAttributeAttribute][DefaultValue(1.0)] - public double StokeWidth { + public float StokeWidth { get { return strokeWidth; } set { if (strokeWidth == value) @@ -113,22 +113,22 @@ namespace Crow continue; switch (c) { case 'M': - gr.MoveTo (sr.ReadDouble (), sr.ReadDouble ()); + gr.MoveTo ((float)sr.ReadDouble (), (float)sr.ReadDouble ()); break; case 'm': - gr.RelMoveTo (sr.ReadDouble (), sr.ReadDouble ()); + gr.RelMoveTo ((float)sr.ReadDouble (), (float)sr.ReadDouble ()); break; case 'L': - gr.LineTo (sr.ReadDouble (), sr.ReadDouble ()); + gr.LineTo ((float)sr.ReadDouble (), (float)sr.ReadDouble ()); break; case 'l': - gr.RelLineTo (sr.ReadDouble (), sr.ReadDouble ()); + gr.RelLineTo ((float)sr.ReadDouble (), (float)sr.ReadDouble ()); break; case 'C': - gr.CurveTo (sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble ()); + gr.CurveTo ((float)sr.ReadDouble (), (float)sr.ReadDouble (), (float)sr.ReadDouble (), (float)sr.ReadDouble (), (float)sr.ReadDouble (), (float)sr.ReadDouble ()); break; case 'c': - gr.RelCurveTo (sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble (), sr.ReadDouble ()); + gr.RelCurveTo ((float)sr.ReadDouble (), (float)sr.ReadDouble (), (float)sr.ReadDouble (), (float)sr.ReadDouble (), (float)sr.ReadDouble (), (float)sr.ReadDouble ()); break; case 'Z': gr.ClosePath (); @@ -145,20 +145,20 @@ namespace Crow } } } - protected override int measureRawSize (LayoutingType lt) - { - if ((lt == LayoutingType.Width && contentSize.Width == 0) || (lt == LayoutingType.Height && contentSize.Height == 0)) { - using (Surface drawing = new ImageSurface (Format.A1, 1,1)) { - using (Context ctx = new Context (drawing)) { - executePath (ctx); - Rectangle r = ctx.StrokeExtents (); - contentSize = new Size (r.Right, r.Bottom); - } - } - } - return lt == LayoutingType.Width ? - contentSize.Width + 2 * Margin: contentSize.Height + 2 * Margin; - } +// protected override int measureRawSize (LayoutingType lt) +// { +// if ((lt == LayoutingType.Width && contentSize.Width == 0) || (lt == LayoutingType.Height && contentSize.Height == 0)) { +// using (Surface drawing = new ImageSurface (Format.A1, 1,1)) { +// using (Context ctx = new Context (drawing)) { +// executePath (ctx); +// Rectangle r = ctx.StrokeExtents (); +// contentSize = new Size (r.Right, r.Bottom); +// } +// } +// } +// return lt == LayoutingType.Width ? +// contentSize.Width + 2 * Margin: contentSize.Height + 2 * Margin; +// } } } diff --git a/src/GraphicObjects/Slider.cs b/src/GraphicObjects/Slider.cs index 2bdd5b8a..33915a26 100644 --- a/src/GraphicObjects/Slider.cs +++ b/src/GraphicObjects/Slider.cs @@ -25,7 +25,7 @@ // THE SOFTWARE. using System; -using Cairo; +using vkvg; using System.Xml.Serialization; using System.ComponentModel; using System.Diagnostics; diff --git a/src/GraphicObjects/TabItem.cs b/src/GraphicObjects/TabItem.cs index 473fc313..37a33ac0 100644 --- a/src/GraphicObjects/TabItem.cs +++ b/src/GraphicObjects/TabItem.cs @@ -28,7 +28,7 @@ using System; using System.Xml.Serialization; using System.ComponentModel; using System.Diagnostics; -using Cairo; +using vkvg; using System.Linq; namespace Crow @@ -159,29 +159,29 @@ namespace Crow internal TabView savedParent = null; void makeFloating (TabView tv) { - lock (IFace.UpdateMutex) { - ImageSurface di = new ImageSurface (Format.Argb32, dis, dis); - IFace.DragImageHeight = dis; - IFace.DragImageWidth = dis; - using (Context ctx = new Context (di)) { - double div = Math.Max (LastPaintedSlot.Width, LastPaintedSlot.Height); - double s = (double)dis / div; - ctx.Scale (s, s); - if (bmp == null) - this.onDraw (ctx); - else { - if (LastPaintedSlot.Width>LastPaintedSlot.Height) - ctx.SetSourceSurface (bmp, 0, (LastPaintedSlot.Width-LastPaintedSlot.Height)/2); - else - ctx.SetSourceSurface (bmp, (LastPaintedSlot.Height-LastPaintedSlot.Width)/2, 0); - - ctx.Paint (); - } - } - IFace.DragImage = di; - } - tv.RemoveChild (this); - savedParent = tv; +// lock (IFace.UpdateMutex) { +// ImageSurface di = new ImageSurface (Format.Argb32, dis, dis); +// IFace.DragImageHeight = dis; +// IFace.DragImageWidth = dis; +// using (Context ctx = new Context (di)) { +// double div = Math.Max (LastPaintedSlot.Width, LastPaintedSlot.Height); +// double s = (double)dis / div; +// ctx.Scale (s, s); +// if (bmp == null) +// this.onDraw (ctx); +// else { +// if (LastPaintedSlot.Width>LastPaintedSlot.Height) +// ctx.SetSourceSurface (bmp, 0, (LastPaintedSlot.Width-LastPaintedSlot.Height)/2); +// else +// ctx.SetSourceSurface (bmp, (LastPaintedSlot.Height-LastPaintedSlot.Width)/2, 0); +// +// ctx.Paint (); +// } +// } +// IFace.DragImage = di; +// } +// tv.RemoveChild (this); +// savedParent = tv; } public override ILayoutable Parent { diff --git a/src/GraphicObjects/TabView.cs b/src/GraphicObjects/TabView.cs index 304e820d..339f707c 100644 --- a/src/GraphicObjects/TabView.cs +++ b/src/GraphicObjects/TabView.cs @@ -27,7 +27,7 @@ using System; using System.Xml.Serialization; using System.ComponentModel; -using Cairo; +using vkvg; using System.Diagnostics; using System.Linq; diff --git a/src/GraphicObjects/TemplatedControl.cs b/src/GraphicObjects/TemplatedControl.cs index 54991a41..d51268ed 100644 --- a/src/GraphicObjects/TemplatedControl.cs +++ b/src/GraphicObjects/TemplatedControl.cs @@ -34,7 +34,7 @@ using System.Linq; using System.Collections.Generic; using System.Text; using System.Reflection; -using Cairo; +using vkvg; namespace Crow { diff --git a/src/GraphicObjects/TextBox.cs b/src/GraphicObjects/TextBox.cs index e29ff9bf..7bfa62e0 100644 --- a/src/GraphicObjects/TextBox.cs +++ b/src/GraphicObjects/TextBox.cs @@ -25,7 +25,7 @@ // THE SOFTWARE. using System; -using Cairo; +using vkvg; using System.Diagnostics; using System.Xml.Serialization; diff --git a/src/GraphicObjects/TextRun.cs b/src/GraphicObjects/TextRun.cs index 17e3b770..1f0bb271 100644 --- a/src/GraphicObjects/TextRun.cs +++ b/src/GraphicObjects/TextRun.cs @@ -29,7 +29,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; using System.Diagnostics; -using Cairo; +using vkvg; using System.Text.RegularExpressions; using System.Xml.Serialization; using System.ComponentModel; @@ -259,7 +259,7 @@ namespace Crow } } - gr.FontMatrix = new Matrix (widthRatio * Font.Size, 0, 0, heightRatio * Font.Size, 0, 0); + //gr.FontMatrix = new Matrix (widthRatio * Font.Size, 0, 0, heightRatio * Font.Size, 0, 0); int curLineCount = 0; diff --git a/src/GraphicObjects/Trend.cs b/src/GraphicObjects/Trend.cs index e9d3c2d3..d1a835eb 100644 --- a/src/GraphicObjects/Trend.cs +++ b/src/GraphicObjects/Trend.cs @@ -28,7 +28,7 @@ using System; using System.Collections.Generic; using System.Xml.Serialization; using System.ComponentModel; -using Cairo; +using vkvg; namespace Crow { @@ -156,7 +156,7 @@ namespace Crow double stepX = (double)r.Width / (double)(nbValues-1); gr.LineWidth = 1.0; - gr.SetDash (new double[]{ 1.0 },0.0); + //gr.SetDash (new double[]{ 1.0 },0.0); @@ -175,7 +175,7 @@ namespace Crow gr.MoveTo (ptrX, values [i] * scaleY); Foreground.SetAsSource (gr); - gr.SetDash (new double[]{ }, 0.0); + //gr.SetDash (new double[]{ }, 0.0); while (i >= 0) { gr.LineTo (ptrX, r.Bottom - values [i] * scaleY); diff --git a/src/Interface.cs b/src/Interface.cs index cc62a1aa..f9821b73 100644 --- a/src/Interface.cs +++ b/src/Interface.cs @@ -33,7 +33,7 @@ using System.Reflection; using System.Threading; using System.Xml; using System.Xml.Serialization; -using Cairo; +using vkvg; using System.Globalization; using Crow.IML; @@ -83,19 +83,21 @@ namespace Crow foreach (string af in Directory.GetFiles (AppDomain.CurrentDomain.BaseDirectory, "*.dll")){ try { Assembly.LoadFrom (af); - } catch (Exception ex) { + } catch { Console.WriteLine ("{0} not loaded as assembly.", af); } } - FontRenderingOptions = new FontOptions (); - FontRenderingOptions.Antialias = Antialias.Subpixel; - FontRenderingOptions.HintMetrics = HintMetrics.On; - FontRenderingOptions.HintStyle = HintStyle.Full; - FontRenderingOptions.SubpixelOrder = SubpixelOrder.Rgb; +// FontRenderingOptions = new FontOptions (); +// FontRenderingOptions.Antialias = Antialias.Subpixel; +// FontRenderingOptions.HintMetrics = HintMetrics.On; +// FontRenderingOptions.HintStyle = HintStyle.Full; +// FontRenderingOptions.SubpixelOrder = SubpixelOrder.Rgb; } - public Interface(){ + public Interface(Surface surface){ CultureInfo.DefaultThreadCurrentCulture = System.Globalization.CultureInfo.InvariantCulture; + this.surf = surface; + this.clientRectangle = new Rectangle (0, 0, surface.Width, surface.Height); } #endregion @@ -104,8 +106,8 @@ namespace Crow loadCursors (); loadStyling (); findAvailableTemplates (); - initTooltip (); - initContextMenus (); + //initTooltip (); + //initContextMenus (); } #region Static and constants @@ -139,9 +141,9 @@ namespace Crow /// will not be rendered on screen public const int MaxDiscardCount = 5; /// Global font rendering settings for Cairo - public static FontOptions FontRenderingOptions; + //public static FontOptions FontRenderingOptions; /// Global font rendering settings for Cairo - public static Antialias Antialias = Antialias.Subpixel; + //public static Antialias Antialias = Antialias.Subpixel; /// /// Each control need a ref to the root interface containing it, if not set in GraphicObject.currentInterface, @@ -181,11 +183,6 @@ namespace Crow #region Public Fields /// Graphic Tree of this interface public List GraphicTree = new List(); - /// Interface's resulting bitmap - public byte[] bmp; - /// resulting bitmap limited to last redrawn part - public byte[] dirtyBmp; - /// True when host has to repaint Interface public bool IsDirty = false; /// Coordinate of the dirty bmp on the original bmp public Rectangle DirtyRect; @@ -231,11 +228,11 @@ namespace Crow /// Client rectangle in the host context Rectangle clientRectangle; /// Clipping rectangles on the root context - Region clipping = new Region(); + Cairo.Region clipping = new Cairo.Region(); /// Main Cairo context Context ctx; /// Main Cairo surface - Surface surf; + public Surface surf; #endregion #region Default values and Style loading @@ -643,8 +640,7 @@ namespace Crow drawingMeasure.StartCycle(); #endif if (DragImage != null) - clipping.UnionRectangle(new Rectangle (DragImageX, DragImageY, DragImageWidth, DragImageHeight)); - using (surf = new ImageSurface (bmp, Format.Argb32, ClientRectangle.Width, ClientRectangle.Height, ClientRectangle.Width * 4)) { + clipping.UnionRectangle(new Rectangle (DragImageX, DragImageY, DragImageWidth, DragImageHeight)); using (ctx = new Context (surf)){ if (!clipping.IsEmpty) { @@ -660,7 +656,7 @@ namespace Crow GraphicObject p = GraphicTree[i]; if (!p.Visible) continue; - if (clipping.Contains (p.Slot) == RegionOverlap.Out) + if (clipping.Contains (p.Slot) == Cairo.RegionOverlap.Out) continue; ctx.Save (); @@ -676,7 +672,7 @@ namespace Crow ctx.Save (); ctx.ResetClip (); ctx.SetSourceSurface (DragImage, DragImageX, DragImageY); - ctx.PaintWithAlpha (0.8); + //ctx.PaintWithAlpha (0.8); ctx.Restore (); DirtyRect += new Rectangle (DragImageX, DragImageY, DragImageWidth, DragImageHeight); IsDirty = true; @@ -687,6 +683,7 @@ namespace Crow #if DEBUG_CLIP_RECTANGLE clipping.stroke (ctx, Color.Red.AdjustAlpha(0.5)); #endif + /* lock (RenderMutex) { // Array.Copy (bmp, dirtyBmp, bmp.Length); @@ -714,11 +711,12 @@ namespace Crow } else IsDirty = false; } + */ clipping.Dispose (); - clipping = new Region (); + clipping = new Cairo.Region(); } //surf.WriteToPng (@"/mnt/data/test.png"); - } + } #if MEASURE_TIME drawingMeasure.StopCycle(); @@ -840,10 +838,10 @@ namespace Crow public void ProcessResize(Rectangle bounds){ lock (UpdateMutex) { clientRectangle = bounds; - int stride = 4 * ClientRectangle.Width; - int bmpSize = Math.Abs (stride) * ClientRectangle.Height; - bmp = new byte[bmpSize]; - dirtyBmp = new byte[bmpSize]; +// int stride = 4 * ClientRectangle.Width; +// int bmpSize = Math.Abs (stride) * ClientRectangle.Height; +// bmp = new byte[bmpSize]; +// dirtyBmp = new byte[bmpSize]; foreach (GraphicObject g in GraphicTree) g.RegisterForLayouting (LayoutingType.All); diff --git a/src/Mono.Cairo/Color.cs b/src/Mono.Cairo/Color.cs index 030089e8..4d76565f 100644 --- a/src/Mono.Cairo/Color.cs +++ b/src/Mono.Cairo/Color.cs @@ -1,5 +1,5 @@ // -// Mono.Cairo.Context.cs +// Mono.Context.cs // // Author: // Duncan Mak (duncan@ximian.com) diff --git a/src/Mono.Cairo/Context.cs b/src/Mono.Cairo/Context.cs index 264774dd..120a661f 100644 --- a/src/Mono.Cairo/Context.cs +++ b/src/Mono.Cairo/Context.cs @@ -1,5 +1,5 @@ // -// Mono.Cairo.Context.cs +// Mono.Context.cs // // Author: // Duncan Mak (duncan@ximian.com) @@ -37,11 +37,11 @@ using System; using System.Runtime.InteropServices; using System.Text; -using Cairo; +using vkvg; namespace Cairo { - [Obsolete ("Renamed Cairo.Context per suggestion from cairo binding guidelines.")] + [Obsolete ("Renamed Context per suggestion from cairo binding guidelines.")] public class Graphics : Context { public Graphics (IntPtr state) : base (state) {} public Graphics (Surface surface) : base (surface) {} diff --git a/src/Mono.Cairo/Distance.cs b/src/Mono.Cairo/Distance.cs index 7cba3729..68300e9d 100644 --- a/src/Mono.Cairo/Distance.cs +++ b/src/Mono.Cairo/Distance.cs @@ -1,5 +1,5 @@ // -// Mono.Cairo.Context.cs +// Mono.Context.cs // // Author: // Duncan Mak (duncan@ximian.com) diff --git a/src/Mono.Cairo/NativeMethods.cs b/src/Mono.Cairo/NativeMethods.cs index 53501369..7237f061 100644 --- a/src/Mono.Cairo/NativeMethods.cs +++ b/src/Mono.Cairo/NativeMethods.cs @@ -548,7 +548,7 @@ namespace Cairo internal static extern bool cairo_region_contains_point (IntPtr region, int x, int y); [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] - internal static extern RegionOverlap cairo_region_contains_rectangle (IntPtr region, ref Crow.Rectangle rectangle); + internal static extern Cairo.RegionOverlap cairo_region_contains_rectangle (IntPtr region, ref Crow.Rectangle rectangle); [DllImport (cairo, CallingConvention=CallingConvention.Cdecl)] internal static extern IntPtr cairo_region_copy (IntPtr original); diff --git a/src/Mono.Cairo/Path.cs b/src/Mono.Cairo/Path.cs index 184c606c..6807f38d 100644 --- a/src/Mono.Cairo/Path.cs +++ b/src/Mono.Cairo/Path.cs @@ -1,5 +1,5 @@ // -// Mono.Cairo.Context.cs +// Mono.Context.cs // // Author: // Miguel de Icaza (miguel@novell.com) @@ -30,7 +30,7 @@ using System; using System.Runtime.InteropServices; -using Cairo; +using vkvg; namespace Cairo { diff --git a/src/Mono.Cairo/Point.cs b/src/Mono.Cairo/Point.cs index e72ca6c5..d21abdc2 100644 --- a/src/Mono.Cairo/Point.cs +++ b/src/Mono.Cairo/Point.cs @@ -1,5 +1,5 @@ // -// Mono.Cairo.Context.cs +// Mono.Context.cs // // Author: // Duncan Mak (duncan@ximian.com) diff --git a/src/Mono.Cairo/PointD.cs b/src/Mono.Cairo/PointD.cs index c2e3587d..8c2b2e02 100644 --- a/src/Mono.Cairo/PointD.cs +++ b/src/Mono.Cairo/PointD.cs @@ -1,5 +1,5 @@ // -// Mono.Cairo.Context.cs +// Mono.Context.cs // // Author: // Duncan Mak (duncan@ximian.com) diff --git a/src/Mono.Cairo/Region.cs b/src/Mono.Cairo/Region.cs index 4a82842a..937457d1 100644 --- a/src/Mono.Cairo/Region.cs +++ b/src/Mono.Cairo/Region.cs @@ -138,7 +138,7 @@ namespace Cairo get { return NativeMethods.cairo_region_is_empty (Handle); } } - public RegionOverlap Contains (Crow.Rectangle rectangle) + public Cairo.RegionOverlap Contains (Crow.Rectangle rectangle) { return NativeMethods.cairo_region_contains_rectangle (Handle, ref rectangle); } diff --git a/src/Picture.cs b/src/Picture.cs index 3784780b..81069f31 100644 --- a/src/Picture.cs +++ b/src/Picture.cs @@ -26,7 +26,7 @@ using System; using System.IO; -using Cairo; +using vkvg; using System.Collections.Generic; namespace Crow diff --git a/src/Point.cs b/src/Point.cs index 6175efc7..cc486ac8 100644 --- a/src/Point.cs +++ b/src/Point.cs @@ -62,9 +62,9 @@ namespace Crow { return new Cairo.Point(p.X, p.Y); } - public static implicit operator Cairo.PointD(Point p) + public static implicit operator vkvg.PointD(Point p) { - return new Cairo.PointD(p.X, p.Y); + return new vkvg.PointD(p.X, p.Y); } public static implicit operator System.Drawing.Point(Point p) { diff --git a/src/SolidColor.cs b/src/SolidColor.cs index d6423d31..4cb212b1 100644 --- a/src/SolidColor.cs +++ b/src/SolidColor.cs @@ -31,7 +31,7 @@ using System.Text; using System.Xml.Serialization; using System.Reflection; using System.Diagnostics; -using Cairo; +using vkvg; @@ -51,7 +51,7 @@ namespace Crow public override void SetAsSource (Context ctx, Rectangle bounds = default(Rectangle)) { - ctx.SetSourceRGBA (color.R, color.G, color.B, color.A); + ctx.SetSource (color.R, color.G, color.B, color.A); } public static object Parse(string s) { diff --git a/src/SvgPicture.cs b/src/SvgPicture.cs index f676a497..1e03010d 100644 --- a/src/SvgPicture.cs +++ b/src/SvgPicture.cs @@ -26,7 +26,7 @@ using System; using System.IO; -using Cairo; +using vkvg; namespace Crow { @@ -95,16 +95,16 @@ namespace Crow widthRatio = heightRatio; } - using (ImageSurface tmp = new ImageSurface (Format.Argb32, bounds.Width, bounds.Height)) { - 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); - } - ctx.SetSource (tmp); - } +// using (Surface tmp = new Surface (bounds.Width, bounds.Height)) { +// 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); +// } +// ctx.SetSource (tmp); +// } } #endregion diff --git a/src/rsvg/Handle.cs b/src/rsvg/Handle.cs index e13f79ad..46a907c1 100644 --- a/src/rsvg/Handle.cs +++ b/src/rsvg/Handle.cs @@ -1,5 +1,5 @@ //Copyright GPL2 -using Cairo; +using vkvg; namespace Rsvg { @@ -108,7 +108,7 @@ namespace Rsvg { [DllImport("rsvg-2")] static extern void rsvg_handle_render_cairo_sub(IntPtr raw, IntPtr cr, string id); - public void RenderCairoSub(Cairo.Context cr, string id) { + public void RenderCairoSub(Context cr, string id) { rsvg_handle_render_cairo_sub(Raw, cr == null ? IntPtr.Zero : cr.Handle, id); } diff --git a/vkEngine/VkEngine.cs b/vkEngine/VkEngine.cs new file mode 100644 index 00000000..d4a43c5b --- /dev/null +++ b/vkEngine/VkEngine.cs @@ -0,0 +1,156 @@ +// +// VkEngine.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2018 jp +// +// 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.Runtime.InteropServices; +using vkh; + +namespace vkglfw +{ + public delegate void VKEmousebuttonfun(IntPtr win, MouseButton but, KeyAction action, KeyModifiers mods); + public delegate void VKEcursorposfun(IntPtr win, double x, double y); + public delegate void VKEscrollfun(IntPtr win, double xdelta, double ydelta); + public delegate void VKEkeyfun(IntPtr win, Key key, int scancode, KeyAction action, KeyModifiers mods); + public delegate void VKEcharfun(IntPtr win, uint codepoint); + + public class VkEngine : IDisposable + { + const string libvkglfw = "vkglfw"; + + [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkengine_create (VkPhysicalDeviceType devType, uint width, uint height); + + [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkengine_close (IntPtr e); + + [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkengine_destroy (IntPtr vkengine_handle); + + [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkengine_blitter_run (IntPtr vkengine_handle, IntPtr vkImage); + + [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkengine_get_device (IntPtr vkengine_handle); + + [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkengine_get_physical_device (IntPtr vkengine_handle); + + //[DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)] + //internal static extern void vkengine_get_queues_properties (IntPtr e, ref IntPtr ptrProps, out uint count); + + //[DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)] + //internal static extern void vkengine_free_ptr (IntPtr ptr); + + [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkengine_get_queue (IntPtr vkengine_handle); + + [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)] + internal static extern uint vkengine_get_queue_fam_idx (IntPtr vkengine_handle); + + [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkengine_set_mouse_but_callback (IntPtr e, VKEmousebuttonfun onMouseBut); + [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkengine_set_cursor_pos_callback (IntPtr e, VKEcursorposfun onMouseMove); + [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkengine_set_scroll_callback (IntPtr e, VKEscrollfun onScroll); + [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkengine_set_key_callback (IntPtr e, VKEkeyfun onKey); + [DllImport (libvkglfw, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkengine_set_char_callback (IntPtr e, VKEcharfun onChar); + + + void onMouseButton(IntPtr win, MouseButton but, KeyAction action, KeyModifiers mods){} + void onMouseMove(IntPtr win, double x, double y){ + Console.WriteLine("mouse ({0},{1})", x, y); + } + void onScroll(IntPtr win, double xdelta, double ydelta){} + void onKey(IntPtr win, Key key, int scancode, KeyAction action, KeyModifiers mods){ + if (key == Key.Escape && action == KeyAction.Press) + vkengine_close (handle); + } + void onChar(IntPtr win, uint codepoint){} + + IntPtr handle = IntPtr.Zero; + + public VkEngine (int width, int height) + { + handle = vkengine_create (VkPhysicalDeviceType.DiscreteGPU, (uint)width, (uint)height); + + vkengine_set_mouse_but_callback (handle, onMouseButton); + vkengine_set_cursor_pos_callback (handle, onMouseMove); + vkengine_set_scroll_callback (handle, onScroll); + vkengine_set_key_callback (handle, onKey); + vkengine_set_char_callback (handle, onChar); + } + ~VkEngine () + { + Dispose (false); + } + +// public QueueFamilyProperties[] AvailableQueues { +// get { +// IntPtr ptr = IntPtr.Zero, p; +// uint count; +// vkengine_get_queues_properties (handle, ref ptr, out count); +// QueueFamilyProperties[] qfps = new QueueFamilyProperties[count]; +// p = ptr; +// for (int i = 0; i < count; i++) { +// qfps[i] = (QueueFamilyProperties)Marshal.PtrToStructure(p, typeof(QueueFamilyProperties)); +// p += Marshal.SizeOf(typeof(QueueFamilyProperties)); +// } +// vkengine_free_ptr (ptr); +// return qfps; +// } +// } + + public IntPtr Handle { get { return handle; }} + public IntPtr Device { get { return vkengine_get_device (handle); }} + public IntPtr Phy { get { return vkengine_get_physical_device (handle); }} + public IntPtr Queue { get { return vkengine_get_queue (handle); }} + public uint QueueFamIdx { get { return vkengine_get_queue_fam_idx (handle); }} + + public void Run (vkvg.Surface surf) { + vkengine_blitter_run (handle, surf.VkImage); + } + + #region IDisposable implementation + public void Dispose () + { + Dispose (true); + GC.SuppressFinalize (this); + } + + protected virtual void Dispose (bool disposing) + { + if (!disposing || handle == IntPtr.Zero) + return; + + vkengine_destroy (handle); + handle = IntPtr.Zero; + } + #endregion + } +} + diff --git a/vkEngine/enums.cs b/vkEngine/enums.cs new file mode 100644 index 00000000..549d4401 --- /dev/null +++ b/vkEngine/enums.cs @@ -0,0 +1,203 @@ +// +// enums.cs +// +// Author: +// Copyright (c) 2013 Antonie Blom +// +// +// 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; + +namespace vkglfw +{ + public enum VkPhysicalDeviceType { + Other = 0, + IntegratedGPU = 1, + DiscreteGPU = 2, + VirtualGPU = 3, + CPU = 4, + } + //taken from pencil.gaming (Copyright (c) 2013 Antonie Blom) + public enum KeyModifiers + { + Shift = 1 << 0, //1 + Control = 1 << 1, //2 + Alt = 1 << 2, //4 + Super = 1 << 3 //8 + } + public enum KeyAction { + Release = 0, + Press, + Repeat, + } + public enum MouseButton { + Button1 = 0, + Button2, + Button3, + Button4, + Button5, + Button6, + Button7, + Button8, + LeftButton = 0, + RightButton, + MiddleButton, + } + public enum Joystick { + Joystick1 = 0, + Joystick2, + Joystick3, + Joystick4, + Joystick5, + Joystick6, + Joystick7, + Joystick8, + Joystick9, + Joystick10, + Joystick11, + Joystick12, + Joystick13, + Joystick14, + Joystick15, + Joystick16, + } + public enum Key { + Space = 32, + Apostrophe = 39, + Comma = 44, + Minus, + Period, + Slash, + Zero, + One, + Two, + Three, + Four, + Five, + Six, + Seven, + Eight, + Nine, + Semicolon = 59, + Equal = 61, + A = 65, + B, + C, + D, + E, + F, + G, + H, + I, + J, + K, + L, + M, + N, + O, + P, + Q, + R, + S, + T, + U, + V, + W, + X, + Y, + Z, + LeftBracket, + Backslash, + RightBracket, + GraveAccent = 96, + World1 = 161, + World2, + Escape = 256, + Enter, + Tab, + Backspace, + Insert, + Delete, + Right, + Left, + Down, + Up, + PageUp, + PageDown, + Home, + End, + CapsLock = 280, + ScrollLock, + NumLock, + PrintScreen, + Pause, + F1 = 290, + F2, + F3, + F4, + F5, + F6, + F7, + F8, + F9, + F10, + F11, + F12, + F13, + F14, + F15, + F16, + F17, + F18, + F19, + F20, + F21, + F22, + F23, + F24, + F25, + KP0 = 320, + KP1, + KP2, + KP3, + KP4, + KP5, + KP6, + KP7, + KP8, + KP9, + KPDecimal, + KPDivide, + KPMultiply, + KPSubtract, + KPAdd, + KPEnter, + KPEqual, + LeftShift = 340, + LeftControl, + LeftAlt, + LeftSuper, + RightShift, + RightControl, + RightAlt, + RightSuper, + Menu, + } +} + diff --git a/vkh/Device.cs b/vkh/Device.cs new file mode 100644 index 00000000..83a99173 --- /dev/null +++ b/vkh/Device.cs @@ -0,0 +1,64 @@ +// +// Context.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2018 jp +// +// 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; + +namespace vkh +{ + public class Device: IDisposable + { + + IntPtr handle = IntPtr.Zero; + + public Device (vkglfw.VkEngine engine) + { + //handle = NativeMethods.vkvg_device_create (engine.Phy, engine.Device, engine.Queue, engine.QueueFamIdx); + } + ~Device () + { + Dispose (false); + } + + public IntPtr Handle { get { return handle; }} + + #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_device_destroy (handle); + handle = IntPtr.Zero; + } + #endregion + } +} + diff --git a/vkh/NativeMethods.cs b/vkh/NativeMethods.cs new file mode 100644 index 00000000..e18d4f8e --- /dev/null +++ b/vkh/NativeMethods.cs @@ -0,0 +1,43 @@ +// +// NativeMethods.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2018 jp +// +// 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.Runtime.InteropServices; + +namespace vkh +{ + internal static class NativeMethods + { + const string libvkh = "vkh"; + + #region Device + [DllImport (libvkh, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkh_device_create (IntPtr phy, IntPtr dev, IntPtr queue, uint qFamIdx); + [DllImport (libvkh, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkh_device_destroy (IntPtr device); + #endregion + } +} + diff --git a/vkh/enums.cs b/vkh/enums.cs new file mode 100644 index 00000000..2d7b23c8 --- /dev/null +++ b/vkh/enums.cs @@ -0,0 +1,60 @@ +// +// enums.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2018 jp +// +// 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.Runtime.InteropServices; + +namespace vkh +{ + [Flags] + public enum QueueFlags : uint{ + Graphic = 0x01, + Compute = 0x02, + Transfer = 0x04, + SparseBinding = 0x08 + } + + [StructLayout(LayoutKind.Sequential)] + public struct Extent3D { + public uint width; + public uint height; + public uint depth; + } + + [StructLayout(LayoutKind.Sequential)] + public struct Extent2D { + public uint width; + public uint height; + } + + [StructLayout(LayoutKind.Sequential)] + public struct QueueFamilyProperties { + public QueueFlags queueFlags; + public uint queueCount; + public uint timestampValidBits; + public Extent3D minImageTransferGranularity; + } +} + diff --git a/vkvg/Context.cs b/vkvg/Context.cs new file mode 100644 index 00000000..029bd42f --- /dev/null +++ b/vkvg/Context.cs @@ -0,0 +1,243 @@ +// +// Context.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2018 jp +// +// 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 Crow; +using System.Text; + +namespace vkvg +{ + public class Context: IDisposable + { + + IntPtr handle = IntPtr.Zero; + + public Context (Surface surf) + { + handle = NativeMethods.vkvg_create (surf.Handle); + } + ~Context () + { + Dispose (false); + } + + public IntPtr Handle { get { return handle; }} + + public double LineWidth { + set { NativeMethods.vkvg_set_line_width (handle, (float)value); } + } + public uint FontSize { + set { NativeMethods.vkvg_set_font_size (handle, value); } + } + public string FontFace { + set { NativeMethods.vkvg_select_font_face (handle, value); } + } + public Operator Operator { + set { NativeMethods.vkvg_set_operator (handle, value); } + get { return NativeMethods.vkvg_get_operator (handle); } + } + public FontExtents FontExtents { + get { + FontExtents f_extents; + NativeMethods.vkvg_font_extents (handle, out f_extents); + return f_extents; + } + } + public TextExtents TextExtents(string s) + { + TextExtents extents; + NativeMethods.vkvg_text_extents (handle, TerminateUtf8(s), out extents); + return extents; + } + public void ShowText (string txt) { + NativeMethods.vkvg_show_text (handle, txt); + } + public void Save () { + NativeMethods.vkvg_save (handle); + } + public void Restore () { + NativeMethods.vkvg_restore (handle); + } + public void Flush () { + NativeMethods.vkvg_flush (handle); + } + + public void Paint () { + NativeMethods.vkvg_paint (handle); + } + public void Arc (float xc, float yc, float radius, float a1, float a2) { + NativeMethods.vkvg_arc (handle, xc, yc, radius, a1, a2); + } + public void Arc (double xc, double yc, double radius, double a1, double a2) { + NativeMethods.vkvg_arc (handle, (float)xc, (float)yc, (float)radius, (float)a1, (float)a2); + } + public void ArcNegative (float xc, float yc, float radius, float a1, float a2) { + NativeMethods.vkvg_arc_negative (handle, xc, yc, radius, a1, a2); + } + public void Rectangle (float x, float y, float width, float height) { + NativeMethods.vkvg_rectangle (handle, x, y, width, height); + } + public void Scale (float sx, float sy) { + NativeMethods.vkvg_scale (handle, sx, sy); + } + public void Translate (float dx, float dy) { + NativeMethods.vkvg_translate (handle, dx, dy); + } + public void Rotate (float alpha) { + NativeMethods.vkvg_rotate (handle, alpha); + } + public void ArcNegative (double xc, double yc, double radius, double a1, double a2) { + NativeMethods.vkvg_arc_negative (handle, (float)xc, (float)yc, (float)radius, (float)a1, (float)a2); + } + public void Rectangle (double x, double y, double width, double height) { + NativeMethods.vkvg_rectangle (handle, (float)x, (float)y, (float)width, (float)height); + } + public void Scale (double sx, double sy) { + NativeMethods.vkvg_scale (handle, (float)sx, (float)sy); + } + public void Translate (double dx, double dy) { + NativeMethods.vkvg_translate (handle, (float)dx, (float)dy); + } + public void Rotate (double alpha) { + NativeMethods.vkvg_rotate (handle, (float)alpha); + } + + public void Fill () { + NativeMethods.vkvg_fill (handle); + } + public void FillPreserve () { + NativeMethods.vkvg_fill_preserve (handle); + } + public void Stroke () { + NativeMethods.vkvg_stroke (handle); + } + public void StrokePreserve () { + NativeMethods.vkvg_stroke_preserve (handle); + } + public void Clip () { + NativeMethods.vkvg_clip (handle); + } + public void ClipPreserve () { + NativeMethods.vkvg_clip_preserve (handle); + } + public void ResetClip () { + NativeMethods.vkvg_reset_clip (handle); + } + public void ClosePath () { + NativeMethods.vkvg_close_path (handle); + } + +// public void Rectangle (float x, float y, float width, float height){ +// NativeMethods.vkvg_rectangle (); +// } + public void MoveTo (PointD p){ + NativeMethods.vkvg_move_to (handle, (float)p.X, (float)p.Y); + } + public void MoveTo (float x, float y){ + NativeMethods.vkvg_move_to (handle, x, y); + } + public void RelMoveTo (float x, float y){ + NativeMethods.vkvg_rel_move_to (handle, x, y); + } + public void LineTo (float x, float y){ + NativeMethods.vkvg_line_to (handle, x, y); + } + public void LineTo (Point p){ + NativeMethods.vkvg_line_to (handle, p.X, p.Y); + } + public void LineTo (PointD p){ + NativeMethods.vkvg_line_to (handle, (float)p.X, (float)p.Y); + } + public void RelLineTo (float x, float y){ + NativeMethods.vkvg_rel_line_to (handle, x, y); + } + public void CurveTo (float x1, float y1, float x2, float y2, float x3, float y3){ + NativeMethods.vkvg_curve_to (handle, x1, y1, x2, y2, x3, y3); + } + public void RelCurveTo (float x1, float y1, float x2, float y2, float x3, float y3){ + NativeMethods.vkvg_rel_curve_to (handle, x1, y1, x2, y2, x3, y3); + } + + public void MoveTo (double x, double y){ + NativeMethods.vkvg_move_to (handle, (float)x, (float)y); + } + public void RelMoveTo (double x, double y){ + NativeMethods.vkvg_rel_move_to (handle, (float)x, (float)y); + } + public void LineTo (double x, double y){ + NativeMethods.vkvg_line_to (handle, (float)x, (float)y); + } + public void RelLineTo (double x, double y){ + NativeMethods.vkvg_rel_line_to (handle, (float)x, (float)y); + } + public void CurveTo (double x1, double y1, double x2, double y2, double x3, double y3){ + NativeMethods.vkvg_curve_to (handle, (float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3); + } + public void RelCurveTo (double x1, double y1, double x2, double y2, double x3, double y3){ + NativeMethods.vkvg_rel_curve_to (handle, (float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3); + } + + + public void SetSource (float r, float g, float b, float a = 1f) { + NativeMethods.vkvg_set_source_rgba (handle, r, g, b, a); + } + public void SetSource (double r, double g, double b, double a = 1.0) { + NativeMethods.vkvg_set_source_rgba (handle, (float)r, (float)g, (float)b, (float)a); + } + public void SetSource (Surface surf, float x = 0f, float y = 0f) { + NativeMethods.vkvg_set_source_surface (handle, surf.Handle, x, y); + } + public void SetSourceSurface (Surface surf, float x = 0f, float y = 0f) { + NativeMethods.vkvg_set_source_surface (handle, surf.Handle, x, y); + } + + private static byte[] TerminateUtf8(string s) + { + // compute the byte count including the trailing \0 + var byteCount = Encoding.UTF8.GetMaxByteCount(s.Length + 1); + var bytes = new byte[byteCount]; + Encoding.UTF8.GetBytes(s, 0, s.Length, bytes, 0); + return bytes; + } + + #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_destroy (handle); + handle = IntPtr.Zero; + } + #endregion + } +} + diff --git a/vkvg/Device.cs b/vkvg/Device.cs new file mode 100644 index 00000000..09eca7ae --- /dev/null +++ b/vkvg/Device.cs @@ -0,0 +1,64 @@ +// +// Context.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2018 jp +// +// 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; + +namespace vkvg +{ + public class Device: IDisposable + { + + IntPtr handle = IntPtr.Zero; + + public Device (vkglfw.VkEngine engine) + { + handle = NativeMethods.vkvg_device_create (engine.Phy, engine.Device, engine.QueueFamIdx, 0); + } + ~Device () + { + Dispose (false); + } + + public IntPtr Handle { get { return handle; }} + + #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_device_destroy (handle); + handle = IntPtr.Zero; + } + #endregion + } +} + diff --git a/vkvg/Enums.cs b/vkvg/Enums.cs new file mode 100644 index 00000000..499ad135 --- /dev/null +++ b/vkvg/Enums.cs @@ -0,0 +1,61 @@ +// +// Enums.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; + +namespace vkvg +{ + public enum Operator + { + Clear, + Source, + Over, + In, + Out, + Atop, + + Dest, + DestOver, + DestIn, + DestOut, + DestAtop, + + Xor, + Add, + Saturate, + } + public enum FontSlant + { + Normal, + Italic, + Oblique + } + public enum FontWeight + { + Normal, + Bold, + } +} + diff --git a/vkvg/FontExtents.cs b/vkvg/FontExtents.cs new file mode 100644 index 00000000..c7f793df --- /dev/null +++ b/vkvg/FontExtents.cs @@ -0,0 +1,104 @@ +// +// Mono.Cairo.FontExtents.cs +// +// Authors: Duncan Mak (duncan@ximian.com) +// Hisham Mardam Bey (hisham.mardambey@gmail.com) +// +// (C) Ximian, Inc. 2003 +// +// This is a simplistic binding of the Cairo API to C#. All functions +// in cairo.h are transcribed into their C# equivelants +// +// Copyright (C) 2004 Novell, Inc (http://www.novell.com) +// +// 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.Runtime.InteropServices; + +namespace vkvg +{ + [StructLayout (LayoutKind.Sequential)] + public struct FontExtents + { + float ascent; + float descent; + float height; + float maxXAdvance; + float maxYAdvance; + + public float Ascent { + get { return ascent; } + set { ascent = value; } + } + + public float Descent { + get { return descent; } + set { descent = value; } + } + + public float Height { + get { return height; } + set { height = value; } + } + + public float MaxXAdvance { + get { return maxXAdvance; } + set { maxXAdvance = value; } + } + + public float MaxYAdvance { + get { return maxYAdvance; } + set { maxYAdvance = value; } + } + + public FontExtents (float ascent, float descent, float height, float maxXAdvance, float maxYAdvance) + { + this.ascent = ascent; + this.descent = descent; + this.height = height; + this.maxXAdvance = maxXAdvance; + this.maxYAdvance = maxYAdvance; + } + + public override bool Equals (object obj) + { + if (obj is FontExtents) + return this == (FontExtents) obj; + return false; + } + + public override int GetHashCode () + { + return (int) Ascent ^ (int) Descent ^ (int) Height ^ (int) MaxXAdvance ^ (int) MaxYAdvance; + } + + public static bool operator == (FontExtents extents, FontExtents other) + { + return extents.Ascent == other.Ascent && extents.Descent == other.Descent && extents.Height == other.Height && extents.MaxXAdvance == other.MaxXAdvance && extents.MaxYAdvance == other.MaxYAdvance; + } + + public static bool operator != (FontExtents extents, FontExtents other) + { + return !(extents == other); + } + } +} diff --git a/vkvg/NativeMethods.cs b/vkvg/NativeMethods.cs new file mode 100644 index 00000000..1cd3854e --- /dev/null +++ b/vkvg/NativeMethods.cs @@ -0,0 +1,137 @@ +// +// NativeMethods.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2018 jp +// +// 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.Runtime.InteropServices; + +namespace vkvg +{ + internal static class NativeMethods + { + const string libvkvg = "vkvg"; + + #region Device + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkvg_device_create (IntPtr phy, IntPtr dev, uint qFamIdx, uint qIndex); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkvg_device_destroy (IntPtr device); + #endregion + + #region Context + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkvg_create (IntPtr surface); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_destroy (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_flush (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_close_path (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_line_to (IntPtr ctx, float x, float y); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_rel_line_to (IntPtr ctx, float x, float y); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_move_to (IntPtr ctx, float x, float y); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_rel_move_to (IntPtr ctx, float x, float y); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_curve_to (IntPtr ctx, float x1, float y1, float x2, float y2, float x3, float y3); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_rel_curve_to (IntPtr ctx, float x1, float y1, float x2, float y2, float x3, float y3); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_rectangle (IntPtr ctx, float x, float y, float width, float height); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_arc (IntPtr ctx, float xc, float yc, float radius, float a1, float a2); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_arc_negative (IntPtr ctx, float xc, float yc, float radius, float a1, float a2); + + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_scale (IntPtr ctx, float sx, float sy); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_translate (IntPtr ctx, float dx, float dy); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_rotate (IntPtr ctx, float alpha); + + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_stroke (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_stroke_preserve (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_clip (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_clip_preserve (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_reset_clip (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_fill (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_fill_preserve (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_paint (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_set_source_rgba (IntPtr ctx, float r, float g, float b, float a); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_set_line_width (IntPtr ctx, float width); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_set_operator (IntPtr ctx, Operator op); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern Operator vkvg_get_operator (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_set_source_surface(IntPtr ctx, IntPtr surf, float x, float y); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_font_extents (IntPtr ctx, out FontExtents extents); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_text_extents (IntPtr ctx, byte[] utf8, out TextExtents extents); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_select_font_face (IntPtr ctx, string name); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_set_font_size (IntPtr ctx, uint size); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_show_text (IntPtr ctx, string text); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_save (IntPtr ctx); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern void vkvg_restore (IntPtr ctx); + #endregion + + #region Surface + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkvg_surface_create (IntPtr device, uint width, uint height); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern IntPtr vkvg_surface_create_from_image (IntPtr dev, string filePath); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + 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)] + internal static extern IntPtr vkvg_surface_get_vk_image (IntPtr surf); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern int vkvg_surface_get_width (IntPtr surf); + [DllImport (libvkvg, CallingConvention=CallingConvention.Cdecl)] + internal static extern int vkvg_surface_get_height (IntPtr surf); + #endregion + } +} + diff --git a/vkvg/PointD.cs b/vkvg/PointD.cs new file mode 100644 index 00000000..a36f8178 --- /dev/null +++ b/vkvg/PointD.cs @@ -0,0 +1,58 @@ +// +// Mono.Context.cs +// +// Author: +// Duncan Mak (duncan@ximian.com) +// Miguel de Icaza (miguel@novell.com) +// Hisham Mardam Bey (hisham.mardambey@gmail.com) +// Alp Toker (alp@atoker.com) +// +// (C) Ximian Inc, 2003. +// (C) Novell Inc, 2003. +// +// This is an OO wrapper API for the Cairo API. +// +// Copyright (C) 2004 Novell, Inc (http://www.novell.com) +// +// 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. +// + +namespace vkvg { + + public struct PointD + { + public PointD (double x, double y) + { + this.x = x; + this.y = y; + } + + double x, y; + public double X { + get { return x; } + set { x = value; } + } + + public double Y { + get { return y; } + set { y = value; } + } + } +} diff --git a/vkvg/Surface.cs b/vkvg/Surface.cs new file mode 100644 index 00000000..f8595c2b --- /dev/null +++ b/vkvg/Surface.cs @@ -0,0 +1,90 @@ +// +// Context.cs +// +// Author: +// Jean-Philippe Bruyère +// +// Copyright (c) 2018 jp +// +// 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; + +namespace vkvg +{ + public class Surface: IDisposable + { + IntPtr handle = IntPtr.Zero; + Device vkvgDev; + + public Surface (Device device, int width, int heigth) + { + vkvgDev = device; + handle = NativeMethods.vkvg_surface_create (device.Handle, (uint)width, (uint)heigth); + } + public Surface (Device device, ref byte[] data, int width, int heigth) + { + vkvgDev = device; + handle = NativeMethods.vkvg_surface_create (device.Handle, (uint)width, (uint)heigth); + } + public Surface (Device device, string imgPath) { + vkvgDev = device; + handle = NativeMethods.vkvg_surface_create_from_image (device.Handle, imgPath); + } + + Surface (IntPtr devHandle, int width, int heigth) + { + handle = NativeMethods.vkvg_surface_create (devHandle, (uint)width, (uint)heigth); + } + ~Surface () + { + Dispose (false); + } + + public IntPtr Handle { get { return handle; }} + public IntPtr VkImage { get { return NativeMethods.vkvg_surface_get_vk_image (handle); }} + public int Width { get { return NativeMethods.vkvg_surface_get_width (handle); }} + public int Height { get { return NativeMethods.vkvg_surface_get_height (handle); }} + +// public Surface CreateSimilar (uint width, uint height) { +// return new Surface (handle, width, height); +// } +// public Surface CreateSimilar (int width, int height) { +// return new Surface (handle, (uint)width, (uint)height); +// } + + public void Flush () {} + #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_surface_destroy (handle); + handle = IntPtr.Zero; + } + #endregion + } +} + diff --git a/vkvg/TextExtents.cs b/vkvg/TextExtents.cs new file mode 100644 index 00000000..2305d9a1 --- /dev/null +++ b/vkvg/TextExtents.cs @@ -0,0 +1,98 @@ +// +// Mono.Cairo.TextExtents.cs +// +// Authors: +// Duncan Mak (duncan@ximian.com) +// Hisham Mardam Bey (hisham.mardambey@gmail.com) +// +// (C) Ximian, Inc. 2003 +// Copyright (C) 2004 Novell, Inc (http://www.novell.com) +// +// 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.Runtime.InteropServices; + +namespace vkvg +{ + [StructLayout (LayoutKind.Sequential)] + public struct TextExtents + { + float xbearing; + float ybearing; + float width; + float height; + float xadvance; + float yadvance; + + public float XBearing { + get { return xbearing; } + set { xbearing = value; } + } + + public float YBearing { + get { return ybearing; } + set { ybearing = value; } + } + + public float Width { + get { return width; } + set { width = value; } + } + + public float Height { + get { return height; } + set { height = value; } + } + + public float XAdvance { + get { return xadvance; } + set { xadvance = value; } + } + + public float YAdvance { + get { return yadvance; } + set { yadvance = value; } + } + + public override bool Equals (object obj) + { + if (obj is TextExtents) + return this == (TextExtents)obj; + return false; + } + + public override int GetHashCode () + { + return (int)XBearing ^ (int)YBearing ^ (int)Width ^ (int)Height ^ (int)XAdvance ^ (int)YAdvance; + } + + public static bool operator == (TextExtents extents, TextExtents other) + { + return extents.XBearing == other.XBearing && extents.YBearing == other.YBearing && extents.Width == other.Width && extents.Height == other.Height && extents.XAdvance == other.XAdvance && extents.YAdvance == other.YAdvance; + } + + public static bool operator != (TextExtents extents, TextExtents other) + { + return !(extents == other); + } + } +}