public static void Fill(Shape s, DrawParams dParams, Brush fillBrush) { Point[] pArray = new Point[s.Points.Count]; for (int i = 0; i < s.Points.Count; i++) { pArray[i] = dParams.Trans.TransPoint(s.Points[i]); } dParams.Graphics.FillPolygon(fillBrush, pArray); }
private void DrawArea(SelectShapeEnum fill) { DrawParams dp = new DrawParams(); dp.Graphics = this.CreateGraphics(); dp.Graphics.Clear(Color.White); dp.Trans = new Trans { XScale = 20, YScale = 20, Origin = new Point(240, 350) }; dp.Pen = new Pen(Color.Blue); dp.FillBrush = new SolidBrush(Color.GreenYellow); Sketcher.Draw(shapeMaker, dp, fill, userLines); List<Shape> flatList = shapeMaker.GetFlatListOfShapes(); int nShapes = flatList.Count; label5.Text = nShapes.ToString(); if (nShapes > 0) { label10.Text = shapeMaker.CalculateSmallestArea(flatList).ToString(); label11.Text = shapeMaker.CalculateLargestArea(flatList).ToString(); label12.Text = shapeMaker.CalculateLargestAdjacentArea(flatList).ToString(); } }
public static void Draw(Shape s, DrawParams dParams, bool fill = false) { if (fill) { Fill(s, dParams, dParams.FillBrush); foreach (Shape s2 in s.GetShapes()) { Draw(s2, dParams); Fill(s2, dParams, new SolidBrush(Color.White)); } } Point[] pArray = new Point[s.Points.Count]; for (int i = 0; i < s.Points.Count; i++) { pArray[i] = dParams.Trans.TransPoint(s.Points[i]); } for (int i = 0; i < s.Points.Count; i++) { dParams.Graphics.DrawLine(dParams.Pen, pArray[i], pArray[(i + 1) % s.Points.Count]); } }
public static void Draw(ShapeMaker a, DrawParams dParams, SelectShapeEnum fillMode, List<ILine> lines) { if (a.Shapes.Count == 0) { foreach (ILine line in lines) { Draw(line, dParams); } } else { List<Shape> flatList = a.GetFlatListOfShapes(); int [] fill = {-1, -1}; switch (fillMode) { case SelectShapeEnum.Largest: fill[0] = a.FindLargestShape(flatList); break; case SelectShapeEnum.Smallest: fill[0] = a.FindSmallestShape(flatList); break; case SelectShapeEnum.LargestAdjacentPair: fill = a.FindLargestAdjacentPair(flatList); break; } int nShape = flatList.Count; for (int i = 0; i < nShape; i++) { Draw(flatList[i], dParams, fill[0] == i || fill[1] == i); } } }
public static void Draw(ILine l, DrawParams dParams) { dParams.Graphics.DrawLine(dParams.Pen, dParams.Trans.TransPoint(l.Point1), dParams.Trans.TransPoint(l.Point2)); }