Last change
on this file since 1519 was
1240,
checked in by mstoeger, 16 years ago
|
Transformations on shapes are possible outside of the Draw method. (#424)
|
File size:
1.6 KB
|
Line | |
---|
1 | using System;
|
---|
2 | using System.Collections.Generic;
|
---|
3 | using System.Drawing;
|
---|
4 |
|
---|
5 | namespace HeuristicLab.Visualization {
|
---|
6 | public class CompositeShape : IShape {
|
---|
7 | private IShape parent;
|
---|
8 |
|
---|
9 | protected readonly List<IShape> shapes = new List<IShape>();
|
---|
10 | protected RectangleD boundingBox = RectangleD.Empty;
|
---|
11 |
|
---|
12 | public virtual void Draw(Graphics graphics) {
|
---|
13 | foreach (IShape shape in shapes) {
|
---|
14 | shape.Draw(graphics);
|
---|
15 | }
|
---|
16 | }
|
---|
17 |
|
---|
18 | public RectangleD BoundingBox {
|
---|
19 | get {
|
---|
20 | if (shapes.Count == 0) {
|
---|
21 | throw new InvalidOperationException("No shapes, no bounding box.");
|
---|
22 | }
|
---|
23 |
|
---|
24 | return boundingBox;
|
---|
25 | }
|
---|
26 | }
|
---|
27 |
|
---|
28 | public RectangleD ClippingArea {
|
---|
29 | get { return Parent.ClippingArea; }
|
---|
30 | }
|
---|
31 |
|
---|
32 | public Rectangle Viewport {
|
---|
33 | get { return Parent.Viewport; }
|
---|
34 | }
|
---|
35 |
|
---|
36 | public IShape Parent {
|
---|
37 | get { return parent; }
|
---|
38 | set { parent = value; }
|
---|
39 | }
|
---|
40 |
|
---|
41 | public void ClearShapes() {
|
---|
42 | shapes.Clear();
|
---|
43 | boundingBox = RectangleD.Empty;
|
---|
44 | }
|
---|
45 |
|
---|
46 | public void AddShape(IShape shape) {
|
---|
47 | shape.Parent = this;
|
---|
48 |
|
---|
49 | if (shapes.Count == 0) {
|
---|
50 | boundingBox = shape.BoundingBox;
|
---|
51 | } else {
|
---|
52 | boundingBox = new RectangleD(Math.Min(boundingBox.X1, shape.BoundingBox.X1),
|
---|
53 | Math.Min(boundingBox.Y1, shape.BoundingBox.Y1),
|
---|
54 | Math.Max(boundingBox.X2, shape.BoundingBox.X2),
|
---|
55 | Math.Max(boundingBox.Y2, shape.BoundingBox.Y2));
|
---|
56 | }
|
---|
57 | shapes.Add(shape);
|
---|
58 | }
|
---|
59 | }
|
---|
60 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.