Rev | Line | |
---|
[635] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Drawing;
|
---|
| 4 |
|
---|
| 5 | namespace 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 |
|
---|
[987] | 26 | public void ClearShapes() {
|
---|
| 27 | shapes.Clear();
|
---|
| 28 | boundingBox = RectangleD.Empty;
|
---|
| 29 | }
|
---|
| 30 |
|
---|
[635] | 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.