Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/WorldShape.cs @ 1234

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

Added Xml comments for IShape, WorldShape and Transforms. (#406)

File size: 2.2 KB
Line 
1using System.Collections.Generic;
2using System.Drawing;
3using System.Drawing.Drawing2D;
4
5namespace HeuristicLab.Visualization {
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>
10  public class WorldShape : IShape {
11    private RectangleD clippingArea; // own clipping area
12    private RectangleD boundingBox;
13
14    protected readonly List<IShape> shapes = new List<IShape>();
15
16    public WorldShape()
17      : this(new RectangleD(0, 0, 1, 1), new RectangleD(0, 0, 1, 1)) {}
18
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>
21    public WorldShape(RectangleD clippingArea, RectangleD boundingBox) {
22      this.clippingArea = clippingArea;
23      this.boundingBox = boundingBox;
24    }
25
26    public virtual void Draw(Graphics graphics, Rectangle parentViewport, RectangleD parentClippingArea) {
27      GraphicsState gstate = graphics.Save();
28
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);
33
34      graphics.SetClip(viewport);
35
36      foreach (IShape shape in shapes) {
37        // draw child shapes using our own clipping area
38        shape.Draw(graphics, viewport, clippingArea);
39      }
40
41      graphics.Restore(gstate);
42    }
43
44    public RectangleD BoundingBox {
45      get { return boundingBox; }
46      set { boundingBox = value; }
47    }
48
49    /// <summary>
50    /// The world shape's own clipping area.
51    /// This overrides the clipping area of the parent shape.
52    /// </summary>
53    public RectangleD ClippingArea {
54      get { return clippingArea; }
55      set { clippingArea = value; }
56    }
57
58    public void AddShape(IShape shape) {
59      shapes.Add(shape);
60    }
61
62    public bool RemoveShape(IShape shape) {
63      return shapes.Remove(shape);
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.