public override void DrawPath(RBrush brush, RGraphicsPath path) { var b = brush.ToBrushA(); var p = path.ToPathA(); if (b.isImage) { //Console.WriteLine("Graphics.DrawPath(B.Image)"); var rect = p.rect; var texture = b.RenderTexture(IntPtr.Zero, rect); var rects = p.GetSDLRects(); foreach (SDL.SDL_Rect r in rects) { var dst_rect = r; SDL.SDL_Rect src_rect = dst_rect; src_rect.x -= rect.x; src_rect.y -= rect.y; if (SDL.SDL_RenderCopy(_renderer, texture, ref src_rect, ref dst_rect) < 0) { Helpers.ShowSDLError("Graphics.DrawPath(B):Unable to SDL_RenderCopy!"); } } SDL.SDL_DestroyTexture(texture); } else { //Console.WriteLine("Graphics.DrawPath(B.Color)"); b.color.SetToSDLRenderer(); var rects = p.GetSDLRects(); SDL.SDL_RenderFillRects(_renderer, rects.ToArray(), rects.Count); } }
public override void DrawPath(RPen pen, RGraphicsPath path) { //! Arcs draws with width 1px pen.ToPenA().color.SetToSDLRenderer(); var p = path.ToPathA(); for (int i = 1; i < p.pathItems.Count; i++) { if (p.pathItems[i].arc) { var points = p.GetArcSDLPoints(pen.ToPenA(), p.pathItems[i]); SDL.SDL_RenderDrawPoints(_renderer, points.ToArray(), points.Count); } else { this.DrawLine(pen, p.pathItems[i - 1].x, p.pathItems[i - 1].y, p.pathItems[i].x, p.pathItems[i].y); } } }
/// <summary> /// Makes a border path for rounded borders.<br/> /// To support rounded dotted/dashed borders we need to use arc in the border path.<br/> /// Return null if the border is not rounded.<br/> /// </summary> /// <param name="g">the device to draw into</param> /// <param name="border">Desired border</param> /// <param name="b">Box which the border corresponds</param> /// <param name="r">the rectangle the border is enclosing</param> /// <returns>Beveled border path, null if there is no rounded corners</returns> private static RGraphicsPath GetRoundedBorderPath(RGraphics g, Border border, CssBox b, RRect r) { RGraphicsPath path = null; switch (border) { case Border.Top: if (b.ActualCornerNw > 0 || b.ActualCornerNe > 0) { path = g.GetGraphicsPath(); path.Start(r.Left + b.ActualBorderLeftWidth / 2, r.Top + b.ActualBorderTopWidth / 2 + b.ActualCornerNw); if (b.ActualCornerNw > 0) { path.ArcTo(r.Left + b.ActualBorderLeftWidth / 2 + b.ActualCornerNw, r.Top + b.ActualBorderTopWidth / 2, b.ActualCornerNw, RGraphicsPath.Corner.TopLeft); } path.LineTo(r.Right - b.ActualBorderRightWidth / 2 - b.ActualCornerNe, r.Top + b.ActualBorderTopWidth / 2); if (b.ActualCornerNe > 0) { path.ArcTo(r.Right - b.ActualBorderRightWidth / 2, r.Top + b.ActualBorderTopWidth / 2 + b.ActualCornerNe, b.ActualCornerNe, RGraphicsPath.Corner.TopRight); } } break; case Border.Bottom: if (b.ActualCornerSw > 0 || b.ActualCornerSe > 0) { path = g.GetGraphicsPath(); path.Start(r.Right - b.ActualBorderRightWidth / 2, r.Bottom - b.ActualBorderBottomWidth / 2 - b.ActualCornerSe); if (b.ActualCornerSe > 0) { path.ArcTo(r.Right - b.ActualBorderRightWidth / 2 - b.ActualCornerSe, r.Bottom - b.ActualBorderBottomWidth / 2, b.ActualCornerSe, RGraphicsPath.Corner.BottomRight); } path.LineTo(r.Left + b.ActualBorderLeftWidth / 2 + b.ActualCornerSw, r.Bottom - b.ActualBorderBottomWidth / 2); if (b.ActualCornerSw > 0) { path.ArcTo(r.Left + b.ActualBorderLeftWidth / 2, r.Bottom - b.ActualBorderBottomWidth / 2 - b.ActualCornerSw, b.ActualCornerSw, RGraphicsPath.Corner.BottomLeft); } } break; case Border.Right: if (b.ActualCornerNe > 0 || b.ActualCornerSe > 0) { path = g.GetGraphicsPath(); var noTop = b.BorderTopStyle == CssConstants.None || b.BorderTopStyle == CssConstants.Hidden; var noBottom = b.BorderBottomStyle == CssConstants.None || b.BorderBottomStyle == CssConstants.Hidden; path.Start(r.Right - b.ActualBorderRightWidth / 2 - (noTop ? b.ActualCornerNe : 0), r.Top + b.ActualBorderTopWidth / 2 + (noTop ? 0 : b.ActualCornerNe)); if (b.ActualCornerNe > 0 && noTop) { path.ArcTo(r.Right - b.ActualBorderLeftWidth / 2, r.Top + b.ActualBorderTopWidth / 2 + b.ActualCornerNe, b.ActualCornerNe, RGraphicsPath.Corner.TopRight); } path.LineTo(r.Right - b.ActualBorderRightWidth / 2, r.Bottom - b.ActualBorderBottomWidth / 2 - b.ActualCornerSe); if (b.ActualCornerSe > 0 && noBottom) { path.ArcTo(r.Right - b.ActualBorderRightWidth / 2 - b.ActualCornerSe, r.Bottom - b.ActualBorderBottomWidth / 2, b.ActualCornerSe, RGraphicsPath.Corner.BottomRight); } } break; case Border.Left: if (b.ActualCornerNw > 0 || b.ActualCornerSw > 0) { path = g.GetGraphicsPath(); var noTop = b.BorderTopStyle == CssConstants.None || b.BorderTopStyle == CssConstants.Hidden; var noBottom = b.BorderBottomStyle == CssConstants.None || b.BorderBottomStyle == CssConstants.Hidden; path.Start(r.Left + b.ActualBorderLeftWidth / 2 + (noBottom ? b.ActualCornerSw : 0), r.Bottom - b.ActualBorderBottomWidth / 2 - (noBottom ? 0 : b.ActualCornerSw)); if (b.ActualCornerSw > 0 && noBottom) { path.ArcTo(r.Left + b.ActualBorderLeftWidth / 2, r.Bottom - b.ActualBorderBottomWidth / 2 - b.ActualCornerSw, b.ActualCornerSw, RGraphicsPath.Corner.BottomLeft); } path.LineTo(r.Left + b.ActualBorderLeftWidth / 2, r.Top + b.ActualBorderTopWidth / 2 + b.ActualCornerNw); if (b.ActualCornerNw > 0 && noTop) { path.ArcTo(r.Left + b.ActualBorderLeftWidth / 2 + b.ActualCornerNw, r.Top + b.ActualBorderTopWidth / 2, b.ActualCornerNw, RGraphicsPath.Corner.TopLeft); } } break; } return(path); }
public override void DrawPath(RBrush brush, RGraphicsPath path) { ReleaseHdc(); _g.FillPath(((BrushAdapter)brush).Brush, ((GraphicsPathAdapter)path).GraphicsPath); }
public override void DrawPath(RPen pen, RGraphicsPath path) { _g.DrawPath(((PenAdapter)pen).Pen, ((GraphicsPathAdapter)path).GraphicsPath); }
public override void DrawPath(RBrush brush, RGraphicsPath path) { this._g.DrawPath((XBrush)((BrushAdapter)brush).Brush, ((GraphicsPathAdapter)path).GraphicsPath); }
public override void DrawPath(RBrush brush, RGraphicsPath path) { _g.DrawGeometry(((BrushAdapter)brush).Brush, null, ((GraphicsPathAdapter)path).GetClosedGeometry()); }
public override void DrawPath(RPen pen, RGraphicsPath path) { _g.DrawGeometry(null, ((PenAdapter)pen).CreatePen(), ((GraphicsPathAdapter)path).GetClosedGeometry()); }
public override void DrawPath(RBrush brush, RGraphicsPath path) { _g.FillPath(brush, ((GraphicsPathAdapter)path).GraphicsPath); }
/// <summary> /// Draw the background image of the given box in the given rectangle.<br/> /// Handle background-repeat and background-position values. /// </summary> /// <param name="g">the device to draw into</param> /// <param name="box">the box to draw its background image</param> /// <param name="imageLoadHandler">the handler that loads image to draw</param> /// <param name="rectangle">the rectangle to draw image in</param> public static void DrawBackgroundImage(RGraphics g, CssBox box, ImageLoadHandler imageLoadHandler, RRect rectangle, RGraphicsPath roundrect = null) { // image size depends if specific rectangle given in image loader var imgSize = new RSize(imageLoadHandler.Rectangle == RRect.Empty ? imageLoadHandler.Image.Width : imageLoadHandler.Rectangle.Width, imageLoadHandler.Rectangle == RRect.Empty ? imageLoadHandler.Image.Height : imageLoadHandler.Rectangle.Height); // get the location by BackgroundPosition value var location = GetLocation(box.BackgroundPosition, rectangle, imgSize, box); var srcRect = imageLoadHandler.Rectangle == RRect.Empty ? new RRect(0, 0, imgSize.Width, imgSize.Height) : new RRect(imageLoadHandler.Rectangle.Left, imageLoadHandler.Rectangle.Top, imgSize.Width, imgSize.Height); // initial image destination rectangle var destRect = new RRect(location, imgSize); // need to clip so repeated image will be cut on rectangle var lRectangle = rectangle; lRectangle.Intersect(g.GetClip()); g.PushClip(lRectangle); //rectangle - box to draw in //imgSize - image size //localion - inital location of image wo repeat //destRect - RRect(location, imgSize) //srcRect (0,0,imgSize) //brushRect - This is rectangle which needs to be filled with Image from brushRect.Location with brushRect.Size multiple to Image size. RRect brushRect = new RRect(location, imgSize); switch (box.BackgroundRepeat) { case "no-repeat": //brushRect = destRect; break; case "repeat-x": if (brushRect.X > rectangle.X) { brushRect.X -= imgSize.Width * ((int)((brushRect.X - rectangle.X) / imgSize.Width) + 1); } if (brushRect.X + brushRect.Width < rectangle.X + rectangle.Width) { brushRect.Width = imgSize.Width * ((int)((rectangle.X + rectangle.Width - brushRect.X) / imgSize.Width) + 1); } break; case "repeat-y": if (brushRect.Y > rectangle.Y) { brushRect.Y -= imgSize.Height * ((int)((brushRect.Y - rectangle.Y) / imgSize.Height) + 1); } if (brushRect.Y + brushRect.Height < rectangle.Y + rectangle.Height) { brushRect.Height = imgSize.Height * ((int)((rectangle.Y + rectangle.Height - brushRect.Y) / imgSize.Height) + 1); } break; default: if (brushRect.X > rectangle.X) { brushRect.X -= imgSize.Width * ((int)((brushRect.X - rectangle.X) / imgSize.Width) + 1); } if (brushRect.X + brushRect.Width < rectangle.X + rectangle.Width) { brushRect.Width = imgSize.Width * ((int)((rectangle.X + rectangle.Width - brushRect.X) / imgSize.Width) + 1); } if (brushRect.Y > rectangle.Y) { brushRect.Y -= imgSize.Height * ((int)((brushRect.Y - rectangle.Y) / imgSize.Height) + 1); } if (brushRect.Y + brushRect.Height < rectangle.Y + rectangle.Height) { brushRect.Height = imgSize.Height * ((int)((rectangle.Y + rectangle.Height - brushRect.Y) / imgSize.Height) + 1); } break; } using (var brush = g.GetTextureBrush(imageLoadHandler.Image, brushRect, brushRect.Location)) { if (roundrect == null) { g.DrawRectangle(brush, rectangle.X, rectangle.Y, rectangle.Width, rectangle.Height); } else { g.DrawPath(brush, roundrect); } } g.PopClip(); }
internal static Adapters.GraphicsPathAdapter ToPathA(this RGraphicsPath path) { return(path as Adapters.GraphicsPathAdapter); }