[635] | 1 | using System.Collections.Generic;
|
---|
| 2 | using System.Drawing;
|
---|
| 3 | using System.Drawing.Drawing2D;
|
---|
| 4 |
|
---|
| 5 | namespace HeuristicLab.Visualization {
|
---|
[1234] | 6 | /// <summary>
|
---|
| 7 | /// World shapes are composite shapes that have their own coordinate system
|
---|
| 8 | /// which is independent from their parent's coordinate system.
|
---|
| 9 | /// </summary>
|
---|
[635] | 10 | public class WorldShape : IShape {
|
---|
[1234] | 11 | private RectangleD clippingArea; // own clipping area
|
---|
[635] | 12 | private RectangleD boundingBox;
|
---|
| 13 |
|
---|
[1038] | 14 | protected readonly List<IShape> shapes = new List<IShape>();
|
---|
[635] | 15 |
|
---|
[1182] | 16 | public WorldShape()
|
---|
| 17 | : this(new RectangleD(0, 0, 1, 1), new RectangleD(0, 0, 1, 1)) {}
|
---|
| 18 |
|
---|
[1234] | 19 | /// <param name="clippingArea">The new clipping area of this world shape</param>
|
---|
| 20 | /// <param name="boundingBox">The location and the size of this world shape in the parent's coordinate system</param>
|
---|
[635] | 21 | public WorldShape(RectangleD clippingArea, RectangleD boundingBox) {
|
---|
| 22 | this.clippingArea = clippingArea;
|
---|
| 23 | this.boundingBox = boundingBox;
|
---|
| 24 | }
|
---|
| 25 |
|
---|
[1234] | 26 | public virtual void Draw(Graphics graphics, Rectangle parentViewport, RectangleD parentClippingArea) {
|
---|
[635] | 27 | GraphicsState gstate = graphics.Save();
|
---|
| 28 |
|
---|
[1234] | 29 | // calculate our drawing area on the screen using our location and
|
---|
| 30 | // size in the parent (boundingBox), the parent's viewport and the
|
---|
| 31 | // parent's clipping area
|
---|
| 32 | Rectangle viewport = Transform.ToScreen(boundingBox, parentViewport, parentClippingArea);
|
---|
[635] | 33 |
|
---|
[1234] | 34 | graphics.SetClip(viewport);
|
---|
[984] | 35 |
|
---|
[635] | 36 | foreach (IShape shape in shapes) {
|
---|
[1234] | 37 | // draw child shapes using our own clipping area
|
---|
| 38 | shape.Draw(graphics, viewport, clippingArea);
|
---|
[635] | 39 | }
|
---|
[984] | 40 |
|
---|
[635] | 41 | graphics.Restore(gstate);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | public RectangleD BoundingBox {
|
---|
| 45 | get { return boundingBox; }
|
---|
[1038] | 46 | set { boundingBox = value; }
|
---|
[635] | 47 | }
|
---|
| 48 |
|
---|
[1234] | 49 | /// <summary>
|
---|
| 50 | /// The world shape's own clipping area.
|
---|
| 51 | /// This overrides the clipping area of the parent shape.
|
---|
| 52 | /// </summary>
|
---|
[928] | 53 | public RectangleD ClippingArea {
|
---|
| 54 | get { return clippingArea; }
|
---|
| 55 | set { clippingArea = value; }
|
---|
| 56 | }
|
---|
| 57 |
|
---|
[635] | 58 | public void AddShape(IShape shape) {
|
---|
| 59 | shapes.Add(shape);
|
---|
| 60 | }
|
---|
[984] | 61 |
|
---|
| 62 | public bool RemoveShape(IShape shape) {
|
---|
| 63 | return shapes.Remove(shape);
|
---|
| 64 | }
|
---|
[635] | 65 | }
|
---|
[984] | 66 | } |
---|