Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/CompositeShape.cs @ 1035

Last change on this file since 1035 was 987, checked in by mstoeger, 16 years ago

Implemented simple XAxis (#433)

File size: 1.3 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Drawing;
4
5namespace HeuristicLab.Visualization {
6  public class CompositeShape : IShape {
7    protected readonly List<IShape> shapes = new List<IShape>();
8    protected RectangleD boundingBox = RectangleD.Empty;
9
10    public virtual void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
11      foreach (IShape shape in shapes) {
12        shape.Draw(graphics, viewport, clippingArea);
13      }
14    }
15
16    public RectangleD BoundingBox {
17      get {
18        if (shapes.Count == 0) {
19          throw new InvalidOperationException("No shapes, no bounding box.");
20        }
21
22        return boundingBox;
23      }
24    }
25
26    public void ClearShapes() {
27      shapes.Clear();
28      boundingBox = RectangleD.Empty;
29    }
30
31    public void AddShape(IShape shape) {
32      if (shapes.Count == 0) {
33        boundingBox = shape.BoundingBox;
34      } else {
35        boundingBox = new RectangleD(Math.Min(boundingBox.X1, shape.BoundingBox.X1),
36                                     Math.Min(boundingBox.Y1, shape.BoundingBox.Y1),
37                                     Math.Max(boundingBox.X2, shape.BoundingBox.X2),
38                                     Math.Max(boundingBox.Y2, shape.BoundingBox.Y2));
39      }
40      shapes.Add(shape);
41    }
42  }
43}
Note: See TracBrowser for help on using the repository browser.