diff --git a/Xwt.Gtk/Xwt.CairoBackend/CairoContextBackendHandler.cs b/Xwt.Gtk/Xwt.CairoBackend/CairoContextBackendHandler.cs index 18325810..b4955723 100644 --- a/Xwt.Gtk/Xwt.CairoBackend/CairoContextBackendHandler.cs +++ b/Xwt.Gtk/Xwt.CairoBackend/CairoContextBackendHandler.cs @@ -343,7 +343,7 @@ namespace Xwt.CairoBackend } } - public object CreatePath () + public override object CreatePath () { Cairo.Surface sf = new Cairo.ImageSurface (null, Cairo.Format.A1, 0, 0, 0); return new CairoContextBackend { @@ -352,7 +352,7 @@ namespace Xwt.CairoBackend }; } - public void AppendPath (object backend, object otherBackend) + public override void AppendPath (object backend, object otherBackend) { Cairo.Context dest = ((CairoContextBackend)backend).Context; Cairo.Context src = ((CairoContextBackend)otherBackend).Context; @@ -361,17 +361,17 @@ namespace Xwt.CairoBackend dest.AppendPath (path); } - public bool IsPointInFill (object backend, double x, double y) + public override bool IsPointInFill (object backend, double x, double y) { return ((CairoContextBackend)backend).Context.InFill (x, y); } - public bool IsPointInStroke (object backend, double x, double y) + public override bool IsPointInStroke (object backend, double x, double y) { return ((CairoContextBackend)backend).Context.InStroke (x, y); } - public void Dispose (object backend) + public override void Dispose (object backend) { var ctx = (CairoContextBackend) backend; IDisposable d = (IDisposable) ctx.Context; diff --git a/Xwt.Gtk/Xwt.GtkBackend/GtkEngine.cs b/Xwt.Gtk/Xwt.GtkBackend/GtkEngine.cs index 4f11ddb6..3d3d4d9c 100755 --- a/Xwt.Gtk/Xwt.GtkBackend/GtkEngine.cs +++ b/Xwt.Gtk/Xwt.GtkBackend/GtkEngine.cs @@ -62,6 +62,7 @@ namespace Xwt.GtkBackend WidgetRegistry.RegisterBackend (typeof(Xwt.Drawing.Context), typeof(ContextBackendHandler)); WidgetRegistry.RegisterBackend (typeof(Xwt.Drawing.TextLayout), typeof(CairoTextLayoutBackendHandler)); #endif + RegisterBackend (typeof(Xwt.Drawing.Path), typeof(CairoContextBackendHandler)); RegisterBackend (typeof(Xwt.Drawing.Gradient), typeof(CairoGradientBackendHandler)); RegisterBackend (typeof(Xwt.Drawing.Font), typeof(GtkFontBackendHandler)); RegisterBackend (typeof(Xwt.Menu), typeof(MenuBackend)); diff --git a/Xwt.Mac/Xwt.Mac/ContextBackendHandler.cs b/Xwt.Mac/Xwt.Mac/ContextBackendHandler.cs index a8686525..742f8ee7 100644 --- a/Xwt.Mac/Xwt.Mac/ContextBackendHandler.cs +++ b/Xwt.Mac/Xwt.Mac/ContextBackendHandler.cs @@ -113,7 +113,7 @@ namespace Xwt.Mac CGContextBackend gc = (CGContextBackend)backend; CGContext ctx = SetupContextForDrawing (gc, out needsRestore); if (gc.Gradient != null) - GradientBackendHandler.Draw (ctx, gc.Gradient); + MacGradientBackendHandler.Draw (ctx, gc.Gradient); else ctx.DrawPath (CGPathDrawingMode.Fill); if (needsRestore) @@ -238,7 +238,7 @@ namespace Xwt.Mac { bool needsRestore; CGContext ctx = SetupContextForDrawing ((CGContextBackend)backend, out needsRestore); - MacTextLayoutBackendHandler.Draw (ctx, WidgetRegistry.GetBackend (layout), x, y); + MacTextLayoutBackendHandler.Draw (ctx, Toolkit.GetBackend (layout), x, y); if (needsRestore) ctx.RestoreState (); } @@ -342,12 +342,12 @@ namespace Xwt.Mac } } - public object CreatePath () + public override object CreatePath () { return new CGPath (); } - public void AppendPath (object backend, object otherBackend) + public override void AppendPath (object backend, object otherBackend) { CGContext dest = ((CGContextBackend)backend).Context; CGContextBackend src = otherBackend as CGContextBackend; @@ -360,17 +360,17 @@ namespace Xwt.Mac } } - public bool IsPointInFill (object backend, double x, double y) + public override bool IsPointInFill (object backend, double x, double y) { return ((CGContextBackend)backend).Context.PathContainsPoint (new PointF ((float)x, (float)y), CGPathDrawingMode.Fill); } - public bool IsPointInStroke (object backend, double x, double y) + public override bool IsPointInStroke (object backend, double x, double y) { return ((CGContextBackend)backend).Context.PathContainsPoint (new PointF ((float)x, (float)y), CGPathDrawingMode.Stroke); } - public void Dispose (object backend) + public override void Dispose (object backend) { ((CGContextBackend)backend).Context.Dispose (); } diff --git a/Xwt.Mac/Xwt.Mac/MacEngine.cs b/Xwt.Mac/Xwt.Mac/MacEngine.cs index d1b54d83..5db0aa55 100644 --- a/Xwt.Mac/Xwt.Mac/MacEngine.cs +++ b/Xwt.Mac/Xwt.Mac/MacEngine.cs @@ -67,7 +67,7 @@ namespace Xwt.Mac RegisterBackend (typeof(Xwt.Canvas), typeof(CanvasBackend)); RegisterBackend (typeof(Xwt.Drawing.Image), typeof(ImageHandler)); RegisterBackend (typeof(Xwt.Drawing.Context), typeof(MacContextBackendHandler)); - WidgetRegistry.RegisterBackend (typeof(Xwt.Drawing.Path), typeof(PathBackendHandler)); + RegisterBackend (typeof(Xwt.Drawing.Path), typeof(MacPathBackendHandler)); RegisterBackend (typeof(Xwt.Drawing.ImageBuilder), typeof(MacImageBuilderBackendHandler)); RegisterBackend (typeof(Xwt.Drawing.ImagePattern), typeof(MacImagePatternBackendHandler)); RegisterBackend (typeof(Xwt.Drawing.Gradient), typeof(MacGradientBackendHandler)); diff --git a/Xwt.Mac/Xwt.Mac/PathBackendHandler.cs b/Xwt.Mac/Xwt.Mac/PathBackendHandler.cs index 08c56ea3..eec090c8 100644 --- a/Xwt.Mac/Xwt.Mac/PathBackendHandler.cs +++ b/Xwt.Mac/Xwt.Mac/PathBackendHandler.cs @@ -26,7 +26,6 @@ using System; using Xwt.Backends; -using Xwt.Engine; using MonoMac.AppKit; using Xwt.Drawing; using MonoMac.Foundation; @@ -35,76 +34,76 @@ using System.Drawing; namespace Xwt.Mac { - public class PathBackendHandler: IPathBackendHandler + public class MacPathBackendHandler: PathBackendHandler { const double degrees = System.Math.PI / 180d; - public PathBackendHandler () + public MacPathBackendHandler () { } - public void Arc (object backend, double xc, double yc, double radius, double angle1, double angle2) + public override void Arc (object backend, double xc, double yc, double radius, double angle1, double angle2) { ((CGPath)backend).AddArc ((float)xc, (float)yc, (float)radius, (float)(angle1 * degrees), (float)(angle2 * degrees), false); } - public void ArcNegative (object backend, double xc, double yc, double radius, double angle1, double angle2) + public override void ArcNegative (object backend, double xc, double yc, double radius, double angle1, double angle2) { ((CGPath)backend).AddArc ((float)xc, (float)yc, (float)radius, (float)(angle1 * degrees), (float)(angle2 * degrees), true); } - public void ClosePath (object backend) + public override void ClosePath (object backend) { ((CGPath)backend).CloseSubpath (); } - public void CurveTo (object backend, double x1, double y1, double x2, double y2, double x3, double y3) + public override void CurveTo (object backend, double x1, double y1, double x2, double y2, double x3, double y3) { ((CGPath)backend).AddCurveToPoint ((float)x1, (float)y1, (float)x2, (float)y2, (float)x3, (float)y3); } - public void LineTo (object backend, double x, double y) + public override void LineTo (object backend, double x, double y) { ((CGPath)backend).AddLineToPoint ((float)x, (float)y); } - public void MoveTo (object backend, double x, double y) + public override void MoveTo (object backend, double x, double y) { ((CGPath)backend).MoveToPoint ((float)x, (float)y); } - public void Rectangle (object backend, double x, double y, double width, double height) + public override void Rectangle (object backend, double x, double y, double width, double height) { ((CGPath)backend).AddRect (new RectangleF ((float)x, (float)y, (float)width, (float)height)); } - public void RelCurveTo (object backend, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3) + public override void RelCurveTo (object backend, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3) { CGPath path = (CGPath)backend; PointF p = path.CurrentPoint; path.AddCurveToPoint ((float)(p.X + dx1), (float)(p.Y + dy1), (float)(p.X + dx2), (float)(p.Y + dy2), (float)(p.X + dx3), (float)(p.Y + dy3)); } - public void RelLineTo (object backend, double dx, double dy) + public override void RelLineTo (object backend, double dx, double dy) { CGPath path = (CGPath)backend; PointF p = path.CurrentPoint; path.AddLineToPoint ((float)(p.X + dx), (float)(p.Y + dy)); } - public void RelMoveTo (object backend, double dx, double dy) + public override void RelMoveTo (object backend, double dx, double dy) { CGPath path = (CGPath)backend; PointF p = path.CurrentPoint; path.MoveToPoint ((float)(p.X + dx), (float)(p.Y + dy)); } - public object CreatePath () + public override object CreatePath () { return new CGPath (); } - public void AppendPath (object backend, object otherBackend) + public override void AppendPath (object backend, object otherBackend) { CGPath dest = (CGPath)backend; CGContextBackend src = otherBackend as CGContextBackend; @@ -117,12 +116,12 @@ namespace Xwt.Mac } } - public bool IsPointInFill (object backend, double x, double y) + public override bool IsPointInFill (object backend, double x, double y) { return ((CGPath)backend).ContainsPoint (new PointF ((float)x, (float)y), false); } - public void Dispose (object backend) + public override void Dispose (object backend) { ((CGPath)backend).Dispose (); } diff --git a/Xwt.Mac/Xwt.Mac/TextLayoutBackendHandler.cs b/Xwt.Mac/Xwt.Mac/TextLayoutBackendHandler.cs index 8ed5c63d..bb5f9690 100644 --- a/Xwt.Mac/Xwt.Mac/TextLayoutBackendHandler.cs +++ b/Xwt.Mac/Xwt.Mac/TextLayoutBackendHandler.cs @@ -30,7 +30,6 @@ using MonoMac.AppKit; using MonoMac.Foundation; using MonoMac.CoreText; using MonoMac.CoreGraphics; -using Xwt.Engine; using Xwt.Drawing; using PointF = System.Drawing.PointF; diff --git a/Xwt.sln b/Xwt.sln index fda34d18..8ca282f1 100644 --- a/Xwt.sln +++ b/Xwt.sln @@ -103,7 +103,7 @@ Global {3C7623A9-9E16-41F6-BBB2-0B550F28E749}.Win-Debug|Any CPU.Build.0 = Debug|Any CPU EndGlobalSection GlobalSection(MonoDevelopProperties) = preSolution - StartupItem = MacTest\MacTest.csproj + StartupItem = GtkTest\GtkTest.csproj Policies = $0 $0.DotNetNamingPolicy = $1 $1.DirectoryNamespaceAssociation = None diff --git a/Xwt/Xwt.Backends/ContextBackendHandler.cs b/Xwt/Xwt.Backends/ContextBackendHandler.cs index 200d4239..3eea6fe3 100644 --- a/Xwt/Xwt.Backends/ContextBackendHandler.cs +++ b/Xwt/Xwt.Backends/ContextBackendHandler.cs @@ -30,44 +30,24 @@ using Xwt.Drawing; namespace Xwt.Backends { - public abstract class ContextBackendHandler: BackendHandler + public abstract class ContextBackendHandler: PathBackendHandler { public abstract void Save (object backend); public abstract void Restore (object backend); - public abstract void Arc (object backend, double xc, double yc, double radius, double angle1, double angle2); - - public abstract void ArcNegative (object backend, double xc, double yc, double radius, double angle1, double angle2); - public abstract void Clip (object backend); public abstract void ClipPreserve(object backend); public abstract void ResetClip (object backend); - public abstract void ClosePath(object backend); - - public abstract void CurveTo (object backend, double x1, double y1, double x2, double y2, double x3, double y3); - public abstract void Fill (object backend); public abstract void FillPreserve (object backend); - public abstract void LineTo (object backend, double x, double y); - - public abstract void MoveTo (object backend, double x, double y); - public abstract void NewPath (object backend); - public abstract void Rectangle (object backend, double x, double y, double width, double height); - - public abstract void RelCurveTo (object backend, double dx1, double dy1, double dx2, double dy2, double dx3, double dy3); - - public abstract void RelLineTo (object backend, double dx, double dy); - - public abstract void RelMoveTo (object backend, double dx, double dy); - public abstract void Stroke (object backend); public abstract void StrokePreserve (object backend); @@ -105,14 +85,14 @@ namespace Xwt.Backends public abstract void TransformPoints (object backend, Point[] points); public abstract void TransformDistances (object backend, Distance[] vectors); + + public abstract bool IsPointInStroke (object backend, double x, double y); /// /// Sets a global alpha to be applied to all drawing operations. /// It doesn't affect colors that have already been set. /// public abstract void SetGlobalAlpha (object backend, double globalAlpha); - - public abstract void Dispose (object backend); } } diff --git a/Xwt/Xwt.Drawing/Context.cs b/Xwt/Xwt.Drawing/Context.cs index dda701a1..33c64691 100644 --- a/Xwt/Xwt.Drawing/Context.cs +++ b/Xwt/Xwt.Drawing/Context.cs @@ -36,12 +36,7 @@ namespace Xwt.Drawing Font font; double globalAlpha = 1; - internal Context (object backend): base (backend) - { - handler = ToolkitEngine.ContextBackendHandler; - } - - internal Context (object backend): base (backend, ToolkitEngine.ContextBackendHandler) + internal Context (object backend, Toolkit toolkit): base (backend, toolkit, toolkit.ContextBackendHandler) { handler = ToolkitEngine.ContextBackendHandler; } diff --git a/Xwt/Xwt.Drawing/ImageBuilder.cs b/Xwt/Xwt.Drawing/ImageBuilder.cs index bfa93d06..d0823901 100644 --- a/Xwt/Xwt.Drawing/ImageBuilder.cs +++ b/Xwt/Xwt.Drawing/ImageBuilder.cs @@ -48,7 +48,7 @@ namespace Xwt.Drawing this.width = width; this.height = height; backend = handler.CreateImageBuilder (width, height, format); - ctx = new Context (handler.CreateContext (backend)); + ctx = new Context (handler.CreateContext (backend), ToolkitEngine); } public int Width { diff --git a/Xwt/Xwt.Drawing/Path.cs b/Xwt/Xwt.Drawing/Path.cs index 7c7d51ed..4443a8e7 100644 --- a/Xwt/Xwt.Drawing/Path.cs +++ b/Xwt/Xwt.Drawing/Path.cs @@ -25,34 +25,20 @@ // THE SOFTWARE. using System; using Xwt.Backends; -using Xwt.Engine; namespace Xwt.Drawing { public class Path: XwtObject, IDisposable { - static IPathBackendHandler pathHandler; - - static Path () - { - pathHandler = WidgetRegistry.CreateSharedBackend (typeof(Path)); - } - - IPathBackendHandler handler; - - protected override IBackendHandler BackendHandler { - get { - return handler; - } - } + PathBackendHandler handler; public Path () { - handler = pathHandler; + handler = ToolkitEngine.PathBackendHandler; Backend = handler.CreatePath (); } - internal Path (object backend, IPathBackendHandler h): base (backend) + internal Path (object backend, Toolkit toolkit, PathBackendHandler h): base (backend, toolkit) { handler = h; } diff --git a/Xwt/Xwt/Canvas.cs b/Xwt/Xwt/Canvas.cs index 074e50ce..7c63ff31 100644 --- a/Xwt/Xwt/Canvas.cs +++ b/Xwt/Xwt/Canvas.cs @@ -69,7 +69,7 @@ namespace Xwt { Context ctx = null; try { - ctx = new Context (context); + ctx = new Context (context, ToolkitEngine); ((Canvas)Parent).OnDraw (ctx, dirtyRect); } finally { diff --git a/Xwt/Xwt/Toolkit.cs b/Xwt/Xwt/Toolkit.cs index dabb8c72..62fc171c 100644 --- a/Xwt/Xwt/Toolkit.cs +++ b/Xwt/Xwt/Toolkit.cs @@ -140,6 +140,7 @@ namespace Xwt ImageBuilderBackendHandler = Backend.CreateSharedBackend (typeof(ImageBuilder)); ImagePatternBackendHandler = Backend.CreateSharedBackend (typeof(ImagePattern)); ImageBackendHandler = Backend.CreateSharedBackend (typeof(Image)); + PathBackendHandler = Backend.CreateSharedBackend (typeof(Path)); } internal void SetActive () @@ -293,6 +294,7 @@ namespace Xwt internal ImageBuilderBackendHandler ImageBuilderBackendHandler; internal ImagePatternBackendHandler ImagePatternBackendHandler; internal ImageBackendHandler ImageBackendHandler; + internal PathBackendHandler PathBackendHandler; } class NativeWindowFrame: WindowFrame