private void VisitGroupRecurs(IShape shape, int x, int y, double ratio) { SolidBrush b; if (shape.GetType() == typeof(Rectangle)) { var rect = (Rectangle)shape; b = new SolidBrush(rect.Color); _drawingRect = new System.Drawing.Rectangle(rect.X, rect.Y, rect.Width, rect.Height); _drawingRect = ReplaceShapeInGroup(_drawingRect, ratio, x, y); g.FillRectangle(b, _drawingRect); } else if (shape.GetType() == typeof(Circle)) { var circle = (Circle)shape; b = new SolidBrush(circle.Color); _drawingRect = new System.Drawing.Rectangle(circle.X, circle.Y, circle.Diameter, circle.Diameter); _drawingRect = ReplaceShapeInGroup(_drawingRect, ratio, x, y); g.FillEllipse(b, _drawingRect.X, _drawingRect.Y, _drawingRect.Width, _drawingRect.Height); } else if (shape.GetType() == typeof(GroupShapes)) { foreach (var child in ((GroupShapes)shape).Children) { VisitGroupRecurs(child, x, y, ratio); } } }
public void VisitCircle(Circle circle) { var b = new SolidBrush(circle.Color); _drawingRect = new System.Drawing.Rectangle(circle.X, circle.Y, circle.Diameter, circle.Diameter); _drawingRect = ReplaceShape(_drawingRect); g.FillEllipse(b, _drawingRect.X, _drawingRect.Y, _drawingRect.Width, _drawingRect.Height); }
public void VisitRectangle(Rectangle rect) { var b = new SolidBrush(rect.Color); _drawingRect = new System.Drawing.Rectangle(rect.X, rect.Y, rect.Width, rect.Height); _drawingRect = ReplaceShape(_drawingRect); g.FillRectangle(b, _drawingRect); }
private System.Drawing.Rectangle ReplaceShape(System.Drawing.Rectangle drawingRect) { while (drawingRect.Width >= _panelWidth || drawingRect.Height >= _panelHeight) { drawingRect.Width /= 2; drawingRect.Height /= 2; } drawingRect.X = _panelWidth / 2 - drawingRect.Width / 2; drawingRect.Y = _panelHeight / 2 - drawingRect.Height / 2; return(drawingRect); }
private System.Drawing.Rectangle ReplaceShapeInGroup(System.Drawing.Rectangle drawingRect, double ratio, int xMin, int yMin) { var newX = (ratio * (drawingRect.X - xMin)); var newY = (ratio * (drawingRect.Y - yMin)); var newWidth = (ratio * drawingRect.Width); var newHeight = (ratio * drawingRect.Height); drawingRect.X = (int)newX; drawingRect.Y = (int)newY; drawingRect.Width = (int)newWidth; drawingRect.Height = (int)newHeight; return(drawingRect); }