Free cookie consent management tool by TermsFeed Policy Generator

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

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

Transformations on shapes are possible outside of the Draw method. (#424)

File size: 2.1 KB
RevLine 
[635]1using System.Collections.Generic;
2using System.Drawing;
3using System.Drawing.Drawing2D;
4
5namespace 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;
[1240]13    private IShape parent;
[635]14
[1240]15    private readonly List<IShape> shapes = new List<IShape>();
[635]16
[1240]17    public WorldShape() {
18      this.clippingArea = new RectangleD(0, 0, 1, 1);
19      this.boundingBox = new RectangleD(0, 0, 1, 1);
[635]20    }
21
[1240]22    public virtual void Draw(Graphics graphics) {
[635]23      GraphicsState gstate = graphics.Save();
24
[1240]25      graphics.SetClip(Viewport);
[635]26
27      foreach (IShape shape in shapes) {
[1234]28        // draw child shapes using our own clipping area
[1240]29        shape.Draw(graphics);
[635]30      }
[984]31
[635]32      graphics.Restore(gstate);
33    }
34
35    public RectangleD BoundingBox {
36      get { return boundingBox; }
[1038]37      set { boundingBox = value; }
[635]38    }
39
[1234]40    /// <summary>
41    /// The world shape's own clipping area.
42    /// This overrides the clipping area of the parent shape.
43    /// </summary>
[928]44    public RectangleD ClippingArea {
45      get { return clippingArea; }
46      set { clippingArea = value; }
47    }
48
[1240]49    public Rectangle Viewport {
50      get {
51        // calculate our drawing area on the screen using our location and
52        // size in the parent (boundingBox), the parent's viewport and the
53        // parent's clipping area
54        Rectangle viewport = Transform.ToScreen(boundingBox, Parent.Viewport, Parent.ClippingArea);
55        return viewport;
56      }
57    }
58
59    public IShape Parent {
60      get { return parent; }
61      set { parent = value; }
62    }
63
64    public void ClearShapes() {
65      shapes.Clear();
66    }
67
[635]68    public void AddShape(IShape shape) {
[1240]69      shape.Parent = this;
[635]70      shapes.Add(shape);
71    }
[984]72
73    public bool RemoveShape(IShape shape) {
74      return shapes.Remove(shape);
75    }
[635]76  }
[984]77}
Note: See TracBrowser for help on using the repository browser.