private void InscribePolygon(PaintGraphics graphics, PaintRectangleF rectangle, int numSides) { float Radius = (float)((double)Math.Min(rectangle.Width, rectangle.Height) / 2.0); ShapePointF Center = new ShapePointF( (float)(rectangle.Location.X + rectangle.Width / 2.0), (float)(rectangle.Location.Y + rectangle.Height / 2.0)); PaintRectangleF rectangleF = new PaintRectangleF(Center, new ShaipSizeF(1, 1)); rectangleF.Inflate(Radius, Radius); float Sides = (float)numSides; float ExteriorAngle = (float)360 / Sides; float InteriorAngle = (Sides - (float)2) / Sides * (float)180; float SideLength = (float)2 * Radius * (float)Math.Sin(Math.PI / (double)Sides); for (int i = 1; i <= Sides; i++) { graphics.ResetTransform(); graphics.TranslateTransform(Center.X, Center.Y); graphics.RotateTransform((i - 1) * ExteriorAngle); graphics.TranslateTransform(0, -Radius); graphics.RotateTransform(180 - InteriorAngle / 2); graphics.MySmoothingMode = EPaintSmoothingMode.AntiAlias; PaintPen pen = new PaintPen(Color, Thickness); pen.StartCap = EPaintLineCap.Round; pen.EndCap = EPaintLineCap.Round; graphics.DrawLine( pen, new ShapePointF(0, 0).ToPointF(), new ShapePointF(0, -SideLength).ToPointF()); } }
public override void Draw(PaintGraphics graphics) { (int x, int y, int width, int height) = CalculateHexagon(); if (width == 0 || height == 0) { return; } if (Cornes == 0) { Cornes = _cornes; } width += Thickness; height += Thickness; int Radius = (int)((double)Math.Min(width, height) / (double)2.0 * (double)0.8); ShapePointF Center = new ShapePointF((int)((double)width / (double)2.0), (int)((double)height / (double)2.0)); PaintRectangleF rectangle = new PaintRectangleF(Center, new ShaipSizeF(1, 1)); rectangle.Inflate(Radius, Radius); PaintImage img = new PaintBitmap(Size.Width, Size.Height); PaintGraphics tmpGraphics = PaintGraphics.FromImage(img); InscribePolygon(tmpGraphics, rectangle, _cornes); graphics.DrawImage(img, x, y); }
public override void Draw(PaintGraphics graphics) { (int x, int y, int width, int height) = CalculateRoundRect(); graphics.MySmoothingMode = EPaintSmoothingMode.AntiAlias; PaintPen pen = new PaintPen(Color, Thickness); pen.LineJoin = EPainLinejoin.Round; PaintRectangleF rect = new PaintRectangleF(x, y, width, height); PaintGraphicsPath path = this.GetRoundRectangle(rect, radius); graphics.DrawPath(pen, path); }
private PaintGraphicsPath GetCapsule(PaintRectangleF baseRect) { float diameter; PaintRectangleF arc; PaintGraphicsPath path = new PaintGraphicsPath(new GraphicsPath()); try { if (baseRect.Width > baseRect.Height) { diameter = baseRect.Height; ShaipSizeF sizeF = new ShaipSizeF(diameter, diameter); arc = new PaintRectangleF(baseRect.Location, sizeF); path.AddArc(arc, 90, 180); arc.X = baseRect.Right - diameter; path.AddArc(arc, 270, 180); } else if (baseRect.Width < baseRect.Height) { diameter = baseRect.Width; ShaipSizeF sizeF = new ShaipSizeF(diameter, diameter); arc = new PaintRectangleF(baseRect.Location, sizeF); path.AddArc(arc, 180, 180); arc.Y = baseRect.Bottom - diameter; path.AddArc(arc, 0, 180); } else { path.AddEllipse(baseRect); } } catch (Exception) { path.AddEllipse(baseRect); } finally { path.CloseFigure(); } return(path); }
private PaintGraphicsPath GetRoundRectangle(PaintRectangleF baseRect, float radius) { if (radius <= 0.0F) { PaintGraphicsPath mPath = new PaintGraphicsPath(new GraphicsPath()); mPath.AddRectangle(baseRect); mPath.CloseFigure(); return(mPath); } if (radius >= (Math.Min(baseRect.Width, baseRect.Height)) / 2.0) { return(GetCapsule(baseRect)); } float diameter = radius * 2.0F; ShaipSizeF sizeF = new ShaipSizeF(diameter, diameter); PaintRectangleF arc = new PaintRectangleF(baseRect.Location, sizeF); PaintGraphicsPath path = new PaintGraphicsPath(new GraphicsPath()); path.AddArc(arc, 180, 90); arc.X = baseRect.Right - diameter; path.AddArc(arc, 270, 90); arc.Y = baseRect.Bottom - diameter; path.AddArc(arc, 0, 90); arc.X = baseRect.Left; path.AddArc(arc, 90, 90); path.CloseFigure(); return(path); }