public bool Draw(SKCanvas canvas, IReadOnlyViewport viewport, ILayer layer, IFeature feature, IStyle style, ISymbolCache symbolCache) { var vectorTile = ((DrawableTile)feature.Geometry).Data; vectorTile.Context.Zoom = (float)viewport.Resolution.ToZoomLevel(); var boundingBox = feature.Geometry.BoundingBox; if (viewport.IsRotated) { var priorMatrix = canvas.TotalMatrix; var matrix = CreateRotationMatrix(viewport, boundingBox, priorMatrix); // TODO canvas.SetMatrix(matrix); var destination = new BoundingBox(0.0, 0.0, boundingBox.Width, boundingBox.Height).ToSkia(); canvas.DrawDrawable(vectorTile, destination.Left, destination.Top); } else { var destination = RoundToPixel(WorldToScreen(viewport, feature.Geometry.BoundingBox)).ToSkia(); //var clipRect = vectorTile.Bounds; var scale = Math.Max(destination.Width, destination.Height) / vectorTile.Bounds.Width; vectorTile.Context.Scale = 1f / scale; //canvas.ClipRect(canvas.DeviceClipBounds); canvas.Translate(new SKPoint(destination.Left, destination.Top)); canvas.Scale(scale, scale); canvas.ClipRect(new SKRect(0, 0, vectorTile.Bounds.Width, vectorTile.Bounds.Height)); canvas.DrawDrawable(vectorTile, 0, 0); var frame = SKRect.Inflate(vectorTile.Bounds, (float)-vectorTile.Context.Zoom, (float)-vectorTile.Context.Zoom); canvas.DrawRect(frame, new SKPaint() { Style = SKPaintStyle.Stroke, Color = new SKColor((byte)rnd.Next(0, 256), (byte)rnd.Next(0, 256), (byte)rnd.Next(0, 256)) }); } return(true); }
public void CanvasDrawsDrawable() { using (var drawable = new TestDrawable()) using (var bmp = new SKBitmap(100, 100)) using (var canvas = new SKCanvas(bmp)) { canvas.DrawDrawable(drawable, 0, 0); Assert.Equal(SKColors.Blue, bmp.GetPixel(50, 50)); } }
public void CanInstantiateDrawable() { using (var drawable = new TestDrawable()) { Assert.Equal(SKRect.Create(100, 100), drawable.Bounds); Assert.Equal(1, drawable.BoundsFireCount); using (var bmp = new SKBitmap(100, 100)) using (var canvas = new SKCanvas(bmp)) { drawable.Draw(canvas, 0, 0); Assert.Equal(1, drawable.DrawFireCount); canvas.DrawDrawable(drawable, 0, 0); Assert.Equal(2, drawable.DrawFireCount); } var picture = drawable.Snapshot(); Assert.NotNull(picture); Assert.Equal(1, drawable.SnapshotFireCount); } }
private bool DrawOntoCanvas(IntPtr handle, SKCanvas Canvas, bool forcerender = false) { var hwnd = Hwnd.ObjectFromHandle(handle); var x = 0; var y = 0; var wasdrawn = false; XplatUI.driver.ClientToScreen(hwnd.client_window, ref x, ref y); var width = 0; var height = 0; var client_width = 0; var client_height = 0; if (hwnd.hwndbmp != null && hwnd.Mapped && hwnd.Visible && !hwnd.zombie) { // setup clip var parent = hwnd; Canvas.ClipRect( SKRect.Create(0, 0, Screen.PrimaryScreen.Bounds.Width * 2, Screen.PrimaryScreen.Bounds.Height * 2), (SKClipOperation)5); while (parent != null) { var xp = 0; var yp = 0; XplatUI.driver.ClientToScreen(parent.client_window, ref xp, ref yp); Canvas.ClipRect(SKRect.Create(xp, yp, parent.Width, parent.Height), SKClipOperation.Intersect); parent = parent.parent; } Monitor.Enter(XplatUIMine.paintlock); if (hwnd.ClientWindow != hwnd.WholeWindow) { var frm = Control.FromHandle(hwnd.ClientWindow) as Form; Hwnd.Borders borders = new Hwnd.Borders(); if (frm != null) { borders = Hwnd.GetBorders(frm.GetCreateParams(), null); Canvas.ClipRect( SKRect.Create(0, 0, Screen.PrimaryScreen.Bounds.Width * 2, Screen.PrimaryScreen.Bounds.Height * 2), (SKClipOperation)5); } if (Canvas.DeviceClipBounds.Width > 0 && Canvas.DeviceClipBounds.Height > 0) { if (hwnd.DrawNeeded || forcerender) { if (hwnd.hwndbmpNC != null) { Canvas.DrawImage(hwnd.hwndbmpNC, new SKPoint(x - borders.left, y - borders.top), new SKPaint() { ColorFilter = SKColorFilter.CreateColorMatrix(new float[] { 0.75f, 0.25f, 0.025f, 0, 0, 0.25f, 0.75f, 0.25f, 0, 0, 0.25f, 0.25f, 0.75f, 0, 0, 0, 0, 0, 1, 0 }) }); } Canvas.ClipRect( SKRect.Create(x, y, hwnd.width - borders.right - borders.left, hwnd.height - borders.top - borders.bottom), SKClipOperation.Intersect); Canvas.DrawDrawable(hwnd.hwndbmp, new SKPoint(x, y)); wasdrawn = true; } hwnd.DrawNeeded = false; } else { Monitor.Exit(XplatUIMine.paintlock); return(true); } } else { if (Canvas.DeviceClipBounds.Width > 0 && Canvas.DeviceClipBounds.Height > 0) { if (hwnd.DrawNeeded || forcerender) { Canvas.DrawDrawable(hwnd.hwndbmp, new SKPoint(x + 0, y + 0)); wasdrawn = true; } hwnd.DrawNeeded = false; /* * surface.Canvas.DrawText(Control.FromHandle(hwnd.ClientWindow).Name, * new SKPoint(x, y + 15), * new SKPaint() {Color = SKColor.Parse("55ffff00")}); * /*surface.Canvas.DrawText(hwnd.ClientWindow.ToString(), new SKPoint(x,y+15), * new SKPaint() {Color = SKColor.Parse("ffff00")});*/ } else { Monitor.Exit(XplatUIMine.paintlock); return(true); } } Monitor.Exit(XplatUIMine.paintlock); } var ctrl = Control.FromHandle(hwnd.ClientWindow); Canvas.DrawText(x + " " + y + " " + ctrl.Name + " " + hwnd.width + " " + hwnd.Height, x, y + 10, new SKPaint() { Color = SKColors.Red }); if (hwnd.Mapped && hwnd.Visible) { IEnumerable <Hwnd> children; lock (Hwnd.windows) children = Hwnd.windows.OfType <System.Collections.DictionaryEntry>() .Where(hwnd2 => { var Key = (IntPtr)hwnd2.Key; var Value = (Hwnd)hwnd2.Value; if (Value.ClientWindow == Key && Value.Parent == hwnd && Value.Visible && Value.Mapped && !Value.zombie) { return(true); } return(false); }).Select(a => (Hwnd)a.Value).ToArray(); children = children.OrderBy((hwnd2) => { var info = XplatUIMine.GetInstance().GetZOrder(hwnd2.client_window); if (info.top) { return(1000); } if (info.bottom) { return(0); } return(500); }); foreach (var child in children) { DrawOntoCanvas(child.ClientWindow, Canvas, true); } } return(true); }