From 6b02331dfe7c6d8290c136ce20b4a7c655b47aae Mon Sep 17 00:00:00 2001 From: Jean-Philippe Bruyère Date: Mon, 7 May 2018 08:12:56 +0200 Subject: first tests with vkvg as backend --- src/ExtensionsMethods.cs | 63 ++++++++++++++++++++++++------------------------ 1 file changed, 32 insertions(+), 31 deletions(-) (limited to 'src/ExtensionsMethods.cs') 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) { -- cgit v1.3.1-4-g156e