Free cookie consent management tool by TermsFeed Policy Generator

source: branches/Persistence Test/HeuristicLab.Visualization/3.2/Drawing/WorldShape.cs @ 4021

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

moved the canvas and the basic types of shapes to their own namespace. #498

File size: 2.1 KB
Line 
1using System.Collections.Generic;
2using System.Drawing;
3using System.Drawing.Drawing2D;
4
5namespace HeuristicLab.Visualization.Drawing {
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    private IShape parent;
14
15    protected readonly List<IShape> shapes = new List<IShape>();
16
17    public WorldShape() {
18      this.clippingArea = new RectangleD(0, 0, 1, 1);
19      this.boundingBox = new RectangleD(0, 0, 1, 1);
20    }
21
22    public virtual void Draw(Graphics graphics) {
23      GraphicsState gstate = graphics.Save();
24
25      graphics.SetClip(Viewport);
26
27      foreach (IShape shape in shapes) {
28        // draw child shapes using our own clipping area
29        shape.Draw(graphics);
30      }
31
32      graphics.Restore(gstate);
33    }
34
35    public RectangleD BoundingBox {
36      get { return boundingBox; }
37      set { boundingBox = value; }
38    }
39
40    /// <summary>
41    /// The world shape's own clipping area.
42    /// This overrides the clipping area of the parent shape.
43    /// </summary>
44    public RectangleD ClippingArea {
45      get { return clippingArea; }
46      set { clippingArea = value; }
47    }
48
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
68    public void AddShape(IShape shape) {
69      shape.Parent = this;
70      shapes.Add(shape);
71    }
72
73    public bool RemoveShape(IShape shape) {
74      return shapes.Remove(shape);
75    }
76  }
77}
Note: See TracBrowser for help on using the repository browser.