/// <summary> /// Draws the shape. /// </summary> /// <param name="G">The g.</param> /// <param name="FillShape">The fill shape.</param> /// <param name="DrawShape">The draw shape.</param> /// <exception cref="ArgumentOutOfRangeException"> /// FillModes - null /// or /// FillModes - null /// or /// ShapeTypes - null /// </exception> public void DrawShape(System.Drawing.Graphics G, Brush FillShape, Pen DrawShape) { foreach (List <Point> points in Points) { switch (ShapeType) { case ShapeTypes.Polygon: switch (FillMode) { case FillModes.Fill: G.FillPolygon(FillShape, points.ToArray()); break; case FillModes.Border: G.DrawPolygon(DrawShape, points.ToArray()); break; case FillModes.Both: G.FillPolygon(FillShape, points.ToArray()); G.DrawPolygon(DrawShape, points.ToArray()); break; default: throw new ArgumentOutOfRangeException(nameof(FillModes), FillMode, null); } break; case ShapeTypes.Spline: switch (FillMode) { case FillModes.Fill: G.FillClosedCurve(FillShape, points.ToArray()); break; case FillModes.Border: G.DrawClosedCurve(DrawShape, points.ToArray()); break; case FillModes.Both: G.FillClosedCurve(FillShape, points.ToArray()); G.DrawClosedCurve(DrawShape, points.ToArray()); break; default: throw new ArgumentOutOfRangeException(nameof(FillModes), FillMode, null); } break; default: throw new ArgumentOutOfRangeException(nameof(ShapeTypes), ShapeType, null); } } }
public override void OnDraw(System.Drawing.Graphics g) { try { if (pts != null) { System.Drawing.Pen pen = new System.Drawing.Pen(Color, width); if (pts.Length > 2) { g.DrawClosedCurve(pen, pts, tension, FillMode.Winding); if (fill) { g.FillClosedCurve(new System.Drawing.SolidBrush(fillColor), pts, FillMode.Winding, tension); } } else if (pts.Length > 1) { g.DrawCurve(pen, pts); } if ((pts.Length == 1 || pts.Length == 2) && step >= 0) { g.DrawLine(pen, pts[pts.Length - 1], ptNew); } } } catch { } }
private void DrawHexagon(Hexagon hexagon, Graphics graphics, Pen borderPen, Brush unitBrush, Brush lockedBrush, int x, int y) { if (hexagon.HasColor) { var brush = hexagon.Color == Hexagon.UnitColor ? unitBrush : lockedBrush; graphics.FillClosedCurve(brush, new[] { hexagon.Point1, hexagon.Point2, hexagon.Point3, hexagon.Point4, hexagon.Point5, hexagon.Point6 }); } graphics.DrawLine(borderPen, hexagon.Point1, hexagon.Point2); graphics.DrawLine(borderPen, hexagon.Point2, hexagon.Point3); graphics.DrawLine(borderPen, hexagon.Point3, hexagon.Point4); graphics.DrawLine(borderPen, hexagon.Point4, hexagon.Point5); graphics.DrawLine(borderPen, hexagon.Point5, hexagon.Point6); graphics.DrawLine(borderPen, hexagon.Point6, hexagon.Point1); if (!string.IsNullOrEmpty(hexagon.Text)) { graphics.DrawString(hexagon.Text, new Font(FontFamily.GenericMonospace, hexagon.FontSize), borderPen.Brush, hexagon.Point6.X, hexagon.Point6.Y); } if (hexagon.HasCircle) { graphics.DrawEllipse(borderPen, hexagon.Circle); } }
public void DrawPolygon(PointF[] points, System.Drawing.Color color) { this.bitmap.Lock(); using (GDI.Bitmap backBufferBitmap = new GDI.Bitmap(width, height, this.bitmap.BackBufferStride, GDI.Imaging.PixelFormat.Format24bppRgb, this.bitmap.BackBuffer)) { using (GDI.Graphics backBufferGraphics = GDI.Graphics.FromImage(backBufferBitmap)) { backBufferGraphics.SmoothingMode = GDI.Drawing2D.SmoothingMode.HighSpeed; backBufferGraphics.CompositingQuality = GDI.Drawing2D.CompositingQuality.HighSpeed; //backBufferGraphics.DrawLines(new System.Drawing.Pen(LINE_COLOR, (float)0.2), points); //add if (points[0] == points[points.Count() - 1]) { backBufferGraphics.FillClosedCurve(new GDI.SolidBrush(color), points, GDI.Drawing2D.FillMode.Winding); //backBufferGraphics.FillPolygon(FILL_COLOR, points, GDI.Drawing2D.FillMode.Alternate); } backBufferGraphics.Flush(); } } this.bitmap.AddDirtyRect(new Int32Rect(0, 0, width, height)); this.bitmap.Unlock(); }
public static void DrawFillEllipse(Graphics g, Brush b, float x, float y, float width, float height, Matrix m = null, double eps = 0.001) { List<PointF> ps = new List<PointF>(); if (m == null) PointsForEllipse(x, y, width, height).ToList().ForEach(p => ps.AddRange(SplinePoints(p, eps))); else PointsForEllipse(x, y, width, height).ToList().ForEach(p => ps.AddRange(SplinePoints(m * p, eps))); g.FillClosedCurve(b, ps.ToArray()); }
public override void Draw(RectangleF rect) { Graphics g = new Graphics(); //g.Clear(Color.White); g.SmoothingMode = SmoothingMode.AntiAlias; // Create a pen object: Pen aPen = new Pen(Color.Blue, 2); // Create a brush object with a transparent red color: SolidBrush aBrush = new SolidBrush(Color.Red); HatchBrush hBrush = new HatchBrush(HatchStyle.Shingle, Color.Blue, Color.LightCoral); HatchBrush hBrush2 = new HatchBrush(HatchStyle.Cross, Color.Blue, Color.LightCoral); HatchBrush hBrush3 = new HatchBrush(HatchStyle.BackwardDiagonal, Color.Blue, Color.LightCoral); HatchBrush hBrush4 = new HatchBrush(HatchStyle.Sphere, Color.Blue, Color.LightCoral); // Draw a rectangle: g.DrawRectangle(aPen, 20, 20, 100, 50); // Draw a filled rectangle: g.FillRectangle(hBrush, 20, 90, 100, 50); // Draw ellipse: g.DrawEllipse(aPen, new Rectangle(20, 160, 100, 50)); // Draw filled ellipse: g.FillEllipse(hBrush2, new Rectangle(170, 20, 100, 50)); // Draw arc: g.DrawArc(aPen, new Rectangle(170, 90, 100, 50), -90, 180); // Draw filled pie pieces g.FillPie(aBrush, new Rectangle(170, 160, 100, 100), -90, 90); g.FillPie(hBrush4, new Rectangle(170, 160, 100, 100), -90, -90); // Create pens. Pen redPen = new Pen(Color.Red, 3); Pen greenPen = new Pen(Color.Green, 3); greenPen.DashStyle = DashStyle.DashDotDot; SolidBrush transparentBrush = new SolidBrush(Color.FromArgb(150, Color.Wheat)); // define point array to draw a curve: Point point1 = new Point(300, 250); Point point2 = new Point(350, 125); Point point3 = new Point(400, 110); Point point4 = new Point(450, 210); Point point5 = new Point(500, 300); Point[] curvePoints ={ point1, point2, point3, point4, point5}; // Draw lines between original points to screen. g.DrawLines(redPen, curvePoints); // Fill Curve g.FillClosedCurve(transparentBrush, curvePoints); // Draw closed curve to screen. g.DrawClosedCurve(greenPen, curvePoints); g.Dispose(); }
/// <summary> /// Draw a polyline using an array of points and fills the interior /// cfr Lasso Select in Paint.Net /// </summary> /// <param name="graphics"></param> /// <param name="color"></param> /// <param name="points"></param> public static void DrawSelectionLasso(Graphics graphics, Color color, PointF[] points) { if (points.Length < 2) { return; } Pen pen = new Pen(color); graphics.DrawCurve(pen, points); pen.Dispose(); Brush brush = new SolidBrush(Color.FromArgb(30, color)); graphics.FillClosedCurve(brush, points); brush.Dispose(); }
public void DrawClosedCurve(Pen pen, PointD[] points, double tension, FillMode fillMode, bool fill = false) { if (pen == null) { throw new ArgumentNullException("pen"); } if (points == null) { throw new ArgumentNullException("points"); } lock (bitmapLock) { double maxX = 0.0d; double maxY = 0.0d; for (long i = 0L; i < points.LongLength; i++) { if (points[i].X * tension > maxX) { maxX = points[i].X * tension; } if (points[i].Y * tension > maxY) { maxY = points[i].Y * tension; } } TryExpand(0.0d, 0.0d, maxX, maxY, pen.Width); using (System.Drawing.Graphics g = System.Drawing.Graphics.FromImage(bitmap)) { g.SmoothingMode = (Antialiasing) ? SmoothingMode.AntiAlias : SmoothingMode.None; if (fill) { g.FillClosedCurve(pen.Brush, ToPointFArray(points), fillMode, (float)tension); } else { g.DrawClosedCurve(pen, ToPointFArray(points), (float)tension, fillMode); } } Texturize(); } }
//Render a polygon private static void Render(DnaPolygon polygon, Graphics g, int scale) { if (polygon.IsComplex) return; Point[] points = GetGdiPoints(polygon.Points, scale); using (Brush brush = GetGdiBrush(polygon.Brush)) { if (polygon.Splines) { if (polygon.Filled) { g.FillClosedCurve(brush, points, FillMode.Winding); } else { using (Pen pen = new Pen(brush, Math.Max(1, polygon.Width))) { g.DrawCurve(pen, points, 3F); } } } else { if (polygon.Filled) { g.FillPolygon(brush, points, FillMode.Winding); } else { using (Pen pen = new Pen(brush, Math.Max(1, polygon.Width))) { g.DrawPolygon(pen, points); } } } } }
public void DrawCustomer(Graphics g) { if (Drawable) { g.FillRectangle(DrawingClass.GetColor(Shirt), X, Y, 40, 100); g.DrawRectangle(Pens.Black, X, Y, 40, 100); g.DrawRectangle(Pens.Black, X + 10, Y + 15, 20, 80); g.FillRectangle(DrawingClass.GetColor(Pants), X + 5, Y + 100, 30, 100); g.DrawRectangle(Pens.Black, X + 5, Y + 100, 30, 100); g.DrawEllipse(Pens.Black, X + 5, Y - 30, 30, 30); Rectangle Rect = new Rectangle(X - 5, Y - 100, 50, 50); switch (State) { case 1: //Только идет g.FillEllipse(Brushes.Yellow, Rect); g.FillRectangle(Brushes.Black, X + 10, Y - 65, 20, 3); break; case 2: //Получил g.FillEllipse(Brushes.LightGreen, Rect); g.FillClosedCurve(Brushes.Black, new Point[6] { new Point(X + 10, Y - 68), new Point(X + 20, Y - 65), new Point(X + 30, Y - 68), new Point(X + 30, Y - 65), new Point(X + 20, Y - 62), new Point(X + 10, Y - 65) }); break; case 3: //Не получил g.FillEllipse(Brushes.Red, Rect); g.FillClosedCurve(Brushes.Black, new Point[6] { new Point(X + 10, Y - 65), new Point(X + 20, Y - 68), new Point(X + 30, Y - 65), new Point(X + 30, Y - 62), new Point(X + 20, Y - 65), new Point(X + 10, Y - 62) }); break; } g.FillEllipse(Brushes.Black, X + 5, Y - 85, 10, 10); g.FillEllipse(Brushes.Black, X + 25, Y - 85, 10, 10); g.DrawString(Desire.ToString() + " p.", new Font("Arial", 10), Brushes.Black, X + 5, Y - 50); g.DrawEllipse(Pens.Black, Rect); } }
internal static void DrawSmileySign(Graphics g, Rectangle rect, Brush background, Brush foreground) { SmoothingMode osm = g.SmoothingMode; // old smoothing mode, to restore it at the end. g.SmoothingMode = SmoothingMode.AntiAlias; int unit = Math.Min(rect.Width, rect.Height) * 2 / 5; float u = unit / 20f; PointF[] points = new PointF[] { new PointF(-5, 0), new PointF(-7, 1), new PointF(-6, 5), new PointF(-2, 8), new PointF(2, 8), new PointF(6, 5), new PointF(7, 1), new PointF(5, 0), new PointF(0, 2) }; for (int i = 0; i < points.Length; i++) { points[i].X *= u; points[i].Y *= u; } g.TranslateTransform(rect.Left + rect.Width / 2, rect.Top + rect.Height / 2); g.FillEllipse(foreground, new Rectangle(-unit / 2, -unit / 2, unit, unit)); g.FillClosedCurve(background, points, System.Drawing.Drawing2D.FillMode.Winding, 0.5f); g.FillEllipse(background, new Rectangle((int)(-7 * u), (int)(-7 * u), (int)(5 * u), (int)(5 * u))); g.FillEllipse(background, new Rectangle((int)(2 * u), (int)(-7 * u), (int)(5 * u), (int)(5 * u))); g.TranslateTransform(-(rect.Left + rect.Width / 2), -(rect.Top + rect.Height / 2)); g.SmoothingMode = osm; }
private void OnPaintDrawSliderAndBar(System.Drawing.Graphics myGraphics, PaintEventArgs e) { System.Drawing.Brush brSolidBrush; System.Drawing.Pen myPen; // If Interesting mouse event happened on the Thumb1 Draw Thumb1 if (bMouseEventThumb1) { brSolidBrush = new System.Drawing.SolidBrush(this.BackColor); if (null != strLeftImagePath) { myGraphics.FillRectangle(brSolidBrush, ptThumbPoints1[0].X, ptThumbPoints1[1].Y, fWidthOfThumb, fHeightOfThumb); } else { myGraphics.FillClosedCurve(brSolidBrush, ptThumbPoints1, System.Drawing.Drawing2D.FillMode.Winding, 0f); } } //if interesting mouse event happened on Thumb2 draw thumb2 if (bMouseEventThumb2) { brSolidBrush = new System.Drawing.SolidBrush(this.BackColor); if (null != strRightImagePath) { myGraphics.FillRectangle(brSolidBrush, ptThumbPoints2[2].X, ptThumbPoints2[1].Y, fWidthOfThumb, fHeightOfThumb); } else { myGraphics.FillClosedCurve(brSolidBrush, ptThumbPoints2, System.Drawing.Drawing2D.FillMode.Winding, 0f); } } // The Below lines are to draw the Thumb and the Lines // The Infocus and the Disabled colors are drawn properly based // onthe calculated values //brSolidBrush = new System.Drawing.SolidBrush(clrInFocusRangeLabelColor); //myPen = new System.Drawing.Pen(clrInFocusRangeLabelColor, unSizeOfMiddleBar); //Debug.WriteLine("Nut 1 : + {0}", fThumb1Point); // Nut 1 ptThumbPoints1[0].X = fThumb1Point; ptThumbPoints1[1].X = fThumb1Point; ptThumbPoints1[2].X = fThumb1Point + fWidthOfThumb; // Nut 2 //Debug.WriteLine("Nut 2 : + {0}", fThumb2Point); ptThumbPoints2[0].X = fThumb2Point; ptThumbPoints2[1].X = fThumb2Point; ptThumbPoints2[2].X = fThumb2Point - fWidthOfThumb; myPen = new System.Drawing.Pen(clrDisabledBarColor, unSizeOfMiddleBar); myGraphics.DrawLine(myPen, fLeftCol, ptThumbPoints1[2].Y, fThumb1Point, ptThumbPoints1[2].Y); //myGraphics.DrawLine(myPen, fLeftCol, ptThumbPoints1[2].Y, fLeftCol, ptThumbPoints1[2].Y + fntLabelFont.SizeInPoints); //myGraphics.DrawLine(myPen, fRightCol, ptThumbPoints1[2].Y, fRightCol, ptThumbPoints1[2].Y + fntLabelFont.SizeInPoints); //brSolidBrush = new System.Drawing.SolidBrush(clrStringOutputFontColor); //myGraphics.DrawString(strRangeString, fntRangeOutputStringFont, brSolidBrush, fLeftCol, fLeftRow * 2 - fntRangeOutputStringFont.Size - 3); myPen = new System.Drawing.Pen(clrInFocusBarColor, unSizeOfMiddleBar); myGraphics.DrawLine(myPen, ptThumbPoints1[2].X, ptThumbPoints1[2].Y, fThumb2Point, /* - fWidthOfThumb*/ ptThumbPoints1[2].Y); myPen = new System.Drawing.Pen(clrDisabledBarColor, unSizeOfMiddleBar); myGraphics.DrawLine(myPen, fThumb2Point, ptThumbPoints2[2].Y, fRightCol, ptThumbPoints2[2].Y); // If the Thumb is an Image it draws the Image or else it draws the Thumb if (null != strLeftImagePath) { myGraphics.DrawImage(imImageLeft, ptThumbPoints1[0].X, ptThumbPoints1[1].Y, fWidthOfThumb, fHeightOfThumb); } else { brSolidBrush = new System.Drawing.SolidBrush(clrThumbColor); myGraphics.FillClosedCurve(brSolidBrush, ptThumbPoints1, System.Drawing.Drawing2D.FillMode.Winding, 0f); } // If the Thumb is an Image it draws the Image or else it draws the Thumb if (null != strRightImagePath) { myGraphics.DrawImage(imImageRight, ptThumbPoints2[2].X, ptThumbPoints2[1].Y, fWidthOfThumb, fHeightOfThumb); } else { brSolidBrush = new System.Drawing.SolidBrush(clrThumbColor); myGraphics.FillClosedCurve(brSolidBrush, ptThumbPoints2, System.Drawing.Drawing2D.FillMode.Winding, 0f); } }
public void Balloon(Graphics gr, Rectangle rect, Point target, Color color, IFieldControlContext context) { Point[] balloon = VectorUtils.VectorizeBalloon(rect, target, Math.PI / 8); gr.SmoothingMode = SmoothingMode.AntiAlias; using (LinearGradientBrush br = new LinearGradientBrush(rect, Color.White, color, LinearGradientMode.ForwardDiagonal) ) { br.WrapMode = WrapMode.TileFlipXY; gr.FillClosedCurve(br, balloon, FillMode.Alternate, 0.08f); } gr.DrawClosedCurve(Pens.Black, balloon, 0.08f, FillMode.Alternate); }
public void DrawEllipse(Graphics g, RectangleD worldRect, Rectangle canvasRect, BrushesStorage brushStorage, PenStorage penStorage, Font font) { const int markerSize = 3; var pen = penStorage.GetPen(Color, Selected ? 3f : 1f); var screenPoints = new List<PointD>(); foreach (var pt in points) { screenPoints.Add(Conversion.WorldToScreen(new PointD(pt.X, pt.Y), worldRect, canvasRect)); } foreach (var pt in screenPoints) { g.DrawRectangle(pen, (float)pt.X - markerSize, (float)pt.Y - markerSize, markerSize * 2F, markerSize * 2F); } if (screenPoints.Count == 2) { g.DrawLine(pen, screenPoints[0].ToPointF(), screenPoints[1].ToPointF()); } if (screenPoints.Count == 3) { // нарисовать собственно эллипс double newAngle; float newCx, newCy, newA, newB; correctEllipse = Geometry.GetEllipseParams(screenPoints[0].ToPointF(), screenPoints[1].ToPointF(), screenPoints[2].ToPointF(), out newAngle, out newA, out newB, out newCx, out newCy); if (correctEllipse) // можно построить эллипс - рисуем его { a = newA; b = newB; angle = newAngle; cx = newCx; cy = newCy; var ellipseBezierPoints = Geometry.GetEllipseBezierPoints(newAngle, newA, newB, newCx, newCy); g.DrawBeziers(pen, ellipseBezierPoints); if (BrushAlpha > 0) { var brush = brushStorage.GetBrush(Color.FromArgb(BrushAlpha, BrushColor)); g.FillClosedCurve(brush, ellipseBezierPoints); } // строить касательную if (BuildTangent) DrawTangent(screenPoints, canvasRect, g, penStorage, brushStorage, font); } else // построить эллипс по указанным координатам невозможно { g.DrawLine(pen, screenPoints[1].ToPointF(), screenPoints[2].ToPointF()); g.DrawLine(pen, screenPoints[0].ToPointF(), screenPoints[2].ToPointF()); } } // маркеры if (Selected) DrawComments(g, worldRect, canvasRect, penStorage, brushStorage); }
private void RenderPolygons(Graphics g) { g.SmoothingMode = Settings.SmoothingMode; foreach (Polygon poly in polyList) { Point centerPoint = CalculateCenterPoint(poly.Corners); if (poly.Type == Type.POLYGON) { if (Settings.RoundedPolygons) g.FillClosedCurve(new SolidBrush(Color.FromArgb(poly.Alpha,poly.FillColor.R,poly.FillColor.G,poly.FillColor.B)), poly.Corners); else g.FillPolygon(new SolidBrush(poly.FillColor), poly.Corners); } else { Range rX = MinMaxRangeFromPolygon(poly,true); Range rY = MinMaxRangeFromPolygon(poly,false); g.FillEllipse(new SolidBrush(poly.FillColor),new Rectangle(new Point(rX.Min,rY.Min),new Size(rX.Difference,rY.Difference))); } if (selectedIndex > -1) { if (poly == polyList[selectedIndex]) { for (int i = 0; i < poly.Corners.Length; i++) { Point p = poly.Corners[i]; Color fillColor; if (poly.SelectedCorner > -1 && p == poly.Corners[poly.SelectedCorner]) fillColor = Settings.DragSquareSelectionFillColor; else fillColor = Settings.DragSquareFillColor; Rectangle dragSpotSize = PointToRectangle(p, Settings.DragSquareSize); Rectangle dragSpotBorder = PointToRectangle(p, Settings.DragSquareSize); g.FillRectangle(new SolidBrush(fillColor), dragSpotSize); g.DrawRectangle(new Pen(new SolidBrush(Settings.DragSquareBorderColor), Settings.DragSquareBorderSize), dragSpotBorder); } if (Settings.DrawCenterPoint) { g.FillEllipse(new SolidBrush(Settings.DragCircleFillColor), PointToRectangle(centerPoint, Settings.DragCircleSize)); g.DrawEllipse(new Pen(new SolidBrush(Settings.DragCircleBorderColor), Settings.DragSquareBorderSize), PointToRectangle(centerPoint, Settings.DragCircleSize)); } } } } if (Mode == Modes.DRAWMODE && drawRect != null && mouseClicked && drawPolygon !=null) { if (Settings.DrawMode == DrawMode.POLYGON) DrawSelectionPolygon(g); else if (Settings.DrawMode == DrawMode.SELECTIONRECTANGLE) DrawSelectionRectangle(g); else{ DrawSelectionPolygon(g); DrawSelectionRectangle(g); } } }
private void DrawSelectionPolygon(Graphics g) { g.FillClosedCurve(new SolidBrush(drawPolygon.FillColor), drawPolygon.Corners); }
/// <summary> /// Draws hand-drawn-looking highlighter color stick lines on top of text. The text itself is not drawn. /// Text may span multiple lines /// </summary> /// <param name="gr">Graphical context</param> /// <param name="rect">Bounding rectangle</param> /// <param name="font">Font to measure text in</param> /// <param name="text">Text to measure, the text is not drawn rather charecters position is determined</param> /// <param name="align">Text alignment</param> /// <param name="color">Color of highlighter including opacity</param> public static void DrawTextHighlight(System.Drawing.Graphics gr, Rectangle rect, Font font, string text, StringAlignment align, Color color) { Rectangle textRect; int lineHeight; using (StringFormat fmt = new StringFormat()) { fmt.Alignment = align; SizeF size = gr.MeasureString(text, font, new SizeF(rect.Width, rect.Height), fmt); lineHeight = (int)gr.MeasureString("`~_W", font).Height; if (//RIGHT (align == StringAlignment.Near && Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft) || (align == StringAlignment.Far) ) { textRect = new Rectangle(rect.Right - (int)size.Width, rect.Top, (int)size.Width, (int)size.Height); } else if (align == StringAlignment.Center) { textRect = new Rectangle(rect.Left + (rect.Width / 2) - (int)size.Width / 2, rect.Location.Y, (int)size.Width, (int)size.Height); } else//LEFT { textRect = new Rectangle(rect.Left, rect.Top, (int)size.Width, (int)size.Height); } } textRect.Inflate(lineHeight, 0); if (textRect.Left < rect.Left) { textRect.X = rect.Left; } if (textRect.Right > rect.Right) { textRect.Width -= textRect.Right - rect.Right; } Rectangle brRect = textRect;//gets rid of brush wrap brRect.Inflate(lineHeight / 2, lineHeight / 2); using (LinearGradientBrush br = new LinearGradientBrush(brRect, color, Color.FromArgb(16, Color.Silver), (align == StringAlignment.Far) ? 180f : 360f)) { gr.SmoothingMode = SmoothingMode.AntiAlias; Random rnd = new Random(); //gr.DrawRectangle(Pens.Red, textRect); int y = textRect.Top + lineHeight / 2; Point[] pnt = new Point[4]; while (y /*+ lineHeight / 2*/ < textRect.Bottom) { pnt[0] = new Point(textRect.Left, y - lineHeight / 2); pnt[1] = new Point(textRect.Right - lineHeight / 2, y - lineHeight / 2); pnt[2] = new Point(textRect.Right - lineHeight, y + lineHeight / 2); pnt[3] = new Point(textRect.Left + lineHeight / 2, y + lineHeight / 2); for (int i = 0; i < pnt.Length; i++) { pnt[i].Offset(rnd.Next(0, 2), rnd.Next(-2, 2)); } gr.FillClosedCurve(br, pnt, FillMode.Alternate, 0.07f + (float)(rnd.NextDouble() / 6d)); y += lineHeight + 2;//1 px padding top and bottom } }//using brush }
/// <summary> /// Draws the closed curve /// </summary> /// <param name="g">the graphics object</param> internal override void Draw(Graphics g) { g.FillClosedCurve(myBrush, points); }
private void DrawOne(Graphics g, int xmin, int xmax, int ymin, int ymax) { var shape = Shape.Arc; var color = new Color(); var randomValue = RandomProvider.RandomGenerator.NextDouble(); foreach (var probabilitiesOfShape in ProbabilitiesOfShapes) { if (randomValue < probabilitiesOfShape.Probability) { shape = probabilitiesOfShape.Value; break; } } randomValue = RandomProvider.RandomGenerator.NextDouble(); foreach (var colorProbabilityPair in colorsCDFs) { if (randomValue < colorProbabilityPair.probability) { color = colorProbabilityPair.color; break; } } var pen = new Pen(color); var x1 = RandomProvider.RandomGenerator.Next(xmin, xmax + 1); var y1 = RandomProvider.RandomGenerator.Next(ymin, ymax + 1); var x2 = RandomProvider.RandomGenerator.Next(xmin, xmax + 1); var y2 = RandomProvider.RandomGenerator.Next(ymin, ymax + 1); var x3 = RandomProvider.RandomGenerator.Next(xmin, xmax + 1); var y3 = RandomProvider.RandomGenerator.Next(ymin, ymax + 1); var x4 = RandomProvider.RandomGenerator.Next(xmin, xmax + 1); var y4 = RandomProvider.RandomGenerator.Next(ymin, ymax + 1); var w1 = RandomProvider.RandomGenerator.Next(x1, xmax + 1); var h1 = RandomProvider.RandomGenerator.Next(y1, ymax + 1); var angle1 = RandomProvider.RandomGenerator.Next(0, 360); switch (shape) { case Shape.Arc: g.DrawArc(pen, x1, y1, w1, h1, RandomProvider.RandomGenerator.Next(0, 360), RandomProvider.RandomGenerator.Next(0, 360)); break; case Shape.Bezier: g.DrawBezier(pen, x1, y1, x2, y2, x3, y3, x4, y4); break; case Shape.ClosedCurve: g.DrawClosedCurve(pen, new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)}); break; case Shape.Curve: g.DrawCurve(pen, new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)}); break; case Shape.Ellipse: g.DrawEllipse(pen, x1, y1, w1, h1); break; case Shape.Line: g.DrawLine(pen, x1, y1, x2, y2); break; case Shape.Lines: g.DrawLines(pen, new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)}); break; case Shape.Pie: g.DrawPie(pen, x1, y1, w1, h1, RandomProvider.RandomGenerator.Next(0, 360), RandomProvider.RandomGenerator.Next(0, 360)); break; case Shape.Polygon: g.DrawPolygon(pen, new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)}); break; case Shape.Rectangle: g.DrawRectangle(pen, x1, y1, w1, h1); break; case Shape.String: g.DrawString(EnglishWordsDictionary.GetRandomWord(), new Font("Cambria", RandomProvider.RandomGenerator.Next(1, 50)), new SolidBrush(color), new PointF(x1, y1)); break; case Shape.FillClosedCurve: g.FillClosedCurve(new SolidBrush(color), new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)}); break; case Shape.FillEllipse: g.FillEllipse(new SolidBrush(color), x1, y1, w1, h1); break; case Shape.FillPie: g.FillPie(new SolidBrush(color), x1, y1, w1, h1, RandomProvider.RandomGenerator.Next(0, 360), RandomProvider.RandomGenerator.Next(0, 360)); break; case Shape.FillPolygon: g.FillPolygon(new SolidBrush(color), new[] {new PointF(x1, y1), new PointF(x2, y2), new PointF(x3, y3), new PointF(x4, y4)}); break; case Shape.FillRectangle: g.FillRectangle(new SolidBrush(color), x1, y1, w1, h1); break; default: throw new ArgumentOutOfRangeException(); } // g.Save(); }
void ShadeRanges2(Graphics gr, int dxAdjust, DateTime dttmFirst, SolidBrush hBrushTrans, int nPctSlop, int nPctAbove) { // ok // shade the regions float yMin = YFromReading(80, m_dyPerBgUnit); float yMax = YFromReading(120, m_dyPerBgUnit); // ok, there are 7 days, starting at dttmFirst int iDay = 0; DateTime dttmCur; dttmCur = dttmFirst.AddMinutes(m_iFirstQuarter * 15.0); dttmCur = new DateTime(dttmCur.Year, dttmCur.Month, dttmCur.Day); ArrayList plptf = new ArrayList(); double []dMeals = { 8.0, 12.0, 18.0 }; double dHours = 0.0; int iplptfi = 0; while (iplptfi < m_plptfi.Count) { PTFI ptfi = (PTFI)m_plptfi[iplptfi]; if (ptfi.bge.Date >= dttmCur) break; iplptfi++; } AddCurvePoint(24.0, 0, ref dHours, ref plptf, dxAdjust, dttmFirst, ref dttmCur, 0, 130, 0, nPctAbove); for (; iDay < m_cgp.nHalfDays / 2 + 2; iDay++) { // now, first analyze the day and determine when the meals are...otherwise, use the default meal times dMeals[0] = 8.0; dMeals[1] = 12.0; dMeals[2] = 18.0; // now, see if we can find meals in our day DateTime dttmNext = dttmCur.AddDays(1); while (iplptfi < m_plptfi.Count) { PTFI ptfi = (PTFI)m_plptfi[iplptfi]; if (ptfi.bge.Date >= dttmNext) break; if (ptfi.bge.Type == BGE.ReadingType.Dinner) dMeals[2] = ptfi.bge.Date.Hour; else if (ptfi.bge.Type == BGE.ReadingType.Breakfast) dMeals[0] = ptfi.bge.Date.Hour; else if (ptfi.bge.Type == BGE.ReadingType.Lunch) dMeals[1] = ptfi.bge.Date.Hour; iplptfi++; } dHours = 0; AddCurvePoint(dMeals[0], 0.0, ref dHours, ref plptf, dxAdjust, dttmFirst, ref dttmCur, dMeals[0], 120, -nPctSlop, nPctAbove); // 0800 dHours = 0; AddCurvePoint(dMeals[1], dMeals[0], ref dHours, ref plptf, dxAdjust, dttmFirst, ref dttmCur, 0.5, 180, -nPctSlop, nPctAbove); // 0830 AddCurvePoint(dMeals[1], dMeals[0], ref dHours, ref plptf, dxAdjust, dttmFirst, ref dttmCur, 1.0, 180, 0, nPctAbove); // 0930 AddCurvePoint(dMeals[1], dMeals[0], ref dHours, ref plptf, dxAdjust, dttmFirst, ref dttmCur, 0.5, 160, nPctSlop, nPctAbove); // 1000 AddCurvePoint(dMeals[1], dMeals[0], ref dHours, ref plptf, dxAdjust, dttmFirst, ref dttmCur, 1.5, 120, nPctSlop, nPctAbove); // 1130 AddCurvePoint(dMeals[1], dMeals[0], ref dHours, ref plptf, dxAdjust, dttmFirst, ref dttmCur, dMeals[1] - dMeals[0] - dHours, 120, 0, nPctAbove); // 1200 dHours = 0; AddCurvePoint(dMeals[2], dMeals[1], ref dHours, ref plptf, dxAdjust, dttmFirst, ref dttmCur, 0.5, 180, -nPctSlop, nPctAbove); // 1230 AddCurvePoint(dMeals[2], dMeals[1], ref dHours, ref plptf, dxAdjust, dttmFirst, ref dttmCur, 1.0, 180, 0, nPctAbove); // 1330 AddCurvePoint(dMeals[2], dMeals[1], ref dHours, ref plptf, dxAdjust, dttmFirst, ref dttmCur, 0.5, 160, nPctSlop, nPctAbove); // 1400 AddCurvePoint(dMeals[2], dMeals[1], ref dHours, ref plptf, dxAdjust, dttmFirst, ref dttmCur, 1.5, 120, nPctSlop, nPctAbove); // 1530 AddCurvePoint(dMeals[2], dMeals[1], ref dHours, ref plptf, dxAdjust, dttmFirst, ref dttmCur, dMeals[2] - dMeals[1] - dHours, 120, 0, nPctAbove); // 1800 dHours = 0; AddCurvePoint(24.00, dMeals[2], ref dHours, ref plptf, dxAdjust, dttmFirst, ref dttmCur, 0.5, 180, -nPctSlop, nPctAbove); // 1830 AddCurvePoint(24.00, dMeals[2], ref dHours, ref plptf, dxAdjust, dttmFirst, ref dttmCur, 1.0, 180, 0, nPctAbove); // 1930 AddCurvePoint(24.00, dMeals[2], ref dHours, ref plptf, dxAdjust, dttmFirst, ref dttmCur, 0.5, 160, nPctSlop, nPctAbove); // 2000 AddCurvePoint(24.00, dMeals[2], ref dHours, ref plptf, dxAdjust, dttmFirst, ref dttmCur, 24.0 - dMeals[2] - dHours, 140, nPctSlop, nPctAbove); // 2400 // repeat for 7 days worth } // ok, now just fill a line back to the beginning while (iDay >= 0) { float x = XFromDate(dttmFirst, dttmCur, m_dxQuarter) - dxAdjust; float y = YFromReading(80 - (80 * nPctAbove) / 100, m_dyPerBgUnit); PointF ptf = new PointF(x, y); plptf.Add(ptf); dttmCur = dttmCur.AddDays(-1); iDay--; } PointF[] points; points = new PointF[plptf.Count]; int iptf = 0; foreach (PointF ptf in plptf) { points[iptf] = ptf; iptf++; } FillMode fm = FillMode.Winding; gr.FillClosedCurve(hBrushTrans, points, fm, 0.2F); }
public void Draw(Graphics g) { g.FillClosedCurve(Brush, ControlPoints.ToArray(), FillMode.Alternate, Tension); }
public void DrawIt(Graphics e, bool light) { if (light) e.FillClosedCurve(new SolidBrush(FaceColor), new[] { pt1.ToPoitntFxy(), pt2.ToPoitntFxy(), pt3.ToPoitntFxy(), pt4.ToPoitntFxy(),pt1.ToPoitntFxy()}, FillMode.Alternate); else e.DrawLines(new Pen(FaceColor,1), new[] { pt1.ToPoitntFxy(), pt2.ToPoitntFxy(), pt3.ToPoitntFxy(), pt4.ToPoitntFxy(), pt1.ToPoitntFxy() }); }
/// <summary> /// Draws hand-drawn-looking highlighter color stick lines on top of text. The text itself is not drawn. /// Text may span multiple lines /// </summary> /// <param name="gr">Graphical context</param> /// <param name="rect">Bounding rectangle</param> /// <param name="font">Font to measure text in</param> /// <param name="text">Text to measure, the text is not drawn rather charecters position is determined</param> /// <param name="align">Text alignment</param> /// <param name="color">Color of highlighter including opacity</param> public static void DrawTextHighlight(Graphics gr, Rectangle rect, Font font, string text, StringAlignment align, Color color) { Rectangle textRect; int lineHeight; using (StringFormat fmt = new StringFormat()) { fmt.Alignment = align; SizeF size = gr.MeasureString(text, font, new SizeF(rect.Width, rect.Height), fmt); lineHeight = (int)gr.MeasureString("`~_W", font).Height; if (//RIGHT (align == StringAlignment.Near && Thread.CurrentThread.CurrentUICulture.TextInfo.IsRightToLeft) || (align == StringAlignment.Far) ) textRect = new Rectangle(rect.Right - (int)size.Width, rect.Top, (int)size.Width, (int)size.Height); else if (align == StringAlignment.Center) textRect = new Rectangle(rect.Left + (rect.Width / 2) - (int)size.Width / 2, rect.Location.Y, (int)size.Width, (int)size.Height); else//LEFT textRect = new Rectangle(rect.Left, rect.Top, (int)size.Width, (int)size.Height); } textRect.Inflate(lineHeight, 0); if (textRect.Left < rect.Left) textRect.X = rect.Left; if (textRect.Right > rect.Right) textRect.Width -= textRect.Right - rect.Right; Rectangle brRect = textRect;//gets rid of brush wrap brRect.Inflate(lineHeight / 2, lineHeight / 2); using (LinearGradientBrush br = new LinearGradientBrush(brRect, color, Color.FromArgb(16, Color.Silver), (align == StringAlignment.Far) ? 180f : 360f)) { gr.SmoothingMode = SmoothingMode.AntiAlias; Random rnd = new Random(); //gr.DrawRectangle(Pens.Red, textRect); int y = textRect.Top + lineHeight / 2; Point[] pnt = new Point[4]; while (y /*+ lineHeight / 2*/ < textRect.Bottom) { pnt[0] = new Point(textRect.Left, y - lineHeight / 2); pnt[1] = new Point(textRect.Right - lineHeight / 2, y - lineHeight / 2); pnt[2] = new Point(textRect.Right - lineHeight, y + lineHeight / 2); pnt[3] = new Point(textRect.Left + lineHeight / 2, y + lineHeight / 2); for (int i = 0; i < pnt.Length; i++) pnt[i].Offset(rnd.Next(0, 2), rnd.Next(-2, 2)); gr.FillClosedCurve(br, pnt, FillMode.Alternate, 0.07f + (float)(rnd.NextDouble() / 6d)); y += lineHeight + 2;//1 px padding top and bottom } }//using brush }
/// <summary> /// Paints a line of the memory control, starting with the address. /// </summary> /// <remarks> /// The strategy is to find any items present at the current address, and try /// to paint as many adjacent items as possible. /// </remarks> /// <param name="g"></param> /// <param name="rc"></param> /// <param name="rdr"></param> private Address PaintLine(Graphics g, Rectangle rc, ImageReader rdr, Point ptAddr, bool render) { StringBuilder sbCode = new StringBuilder(" "); // Draw the address part. rc.X = 0; string s = string.Format("{0}", rdr.Address); int cx = (int) g.MeasureString(s + "X", ctrl.Font, rc.Width, StringFormat.GenericTypographic).Width; if (!render && new Rectangle(rc.X, rc.Y, cx, rc.Height).Contains(ctrl.ptDown)) { return rdr.Address; } else { g.FillRectangle(SystemBrushes.Window, rc.X, rc.Y, cx, rc.Height); g.DrawString(s, ctrl.Font, SystemBrushes.ControlText, rc.X, rc.Y, StringFormat.GenericTypographic); } cx -= cellSize.Width / 2; rc = new Rectangle(cx, rc.Top, rc.Width - cx, rc.Height); uint rowBytesLeft = ctrl.cbRow; ulong linearSelected = ctrl.addrSelected != null ? ctrl.addrSelected.ToLinear() : ~0UL; ulong linearAnchor = ctrl.addrAnchor != null ? ctrl.addrAnchor.ToLinear() : ~0UL; ulong linearBeginSelection = Math.Min(linearSelected, linearAnchor); ulong linearEndSelection = Math.Max(linearSelected, linearAnchor); do { Address addr = rdr.Address; ulong linear = addr.ToLinear(); ImageMapItem item; if (!ctrl.ImageMap.TryFindItem(addr, out item)) break; ulong cbIn = (linear - item.Address.ToLinear()); // # of bytes 'inside' the block we are. uint cbToDraw = 16; // item.Size - cbIn; // See if the chunk goes off the edge of the line. If so, clip it. if (cbToDraw > rowBytesLeft) cbToDraw = rowBytesLeft; // Now paint the bytes in this span. for (int i = 0; i < cbToDraw; ++i) { Address addrByte = rdr.Address; ctrl.ImageMap.TryFindItem(addrByte, out item); bool isSelected = linearBeginSelection <= addrByte.ToLinear() && addrByte.ToLinear() <= linearEndSelection; bool isCursor = addrByte.ToLinear() == linearSelected; if (rdr.IsValid) { byte b = rdr.ReadByte(); s = string.Format("{0:X2}", b); char ch = (char) b; sbCode.Append(Char.IsControl(ch) ? '.' : ch); } else { s = "??"; sbCode.Append(' '); } cx = cellSize.Width * 3; Rectangle rcByte = new Rectangle( rc.Left, rc.Top, cx, rc.Height); if (!render && rcByte.Contains(ptAddr)) return addrByte; var theme = GetBrushTheme(item, isSelected); g.FillRectangle(theme.Background, rc.Left, rc.Top, cx, rc.Height); if (!isSelected && theme.StartMarker != null && addrByte.ToLinear() == item.Address.ToLinear()) { var pts = new Point[] { rc.Location, rc.Location, rc.Location, }; pts[1].Offset(4, 0); pts[2].Offset(0, 4); g.FillClosedCurve(theme.StartMarker, pts); } g.DrawString(s, ctrl.Font, theme.Foreground, rc.Left + cellSize.Width / 2, rc.Top, StringFormat.GenericTypographic); if (isCursor) { ControlPaint.DrawFocusRectangle(g, rc); } rc = new Rectangle(rc.X + cx, rc.Y, rc.Width - cx, rc.Height); } rowBytesLeft -= cbToDraw; } while (rowBytesLeft > 0); if (render) { g.FillRectangle(SystemBrushes.Window, rc); g.DrawString(sbCode.ToString(), ctrl.Font, SystemBrushes.WindowText, rc.X + cellSize.Width, rc.Top, StringFormat.GenericTypographic); } return null; }