Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/Canvas.cs @ 1248

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

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

File size: 1.7 KB
Line 
1using System;
2using System.Diagnostics;
3using System.Drawing;
4using System.Drawing.Drawing2D;
5
6namespace HeuristicLab.Visualization {
7  public class Canvas : IShape {
8    private readonly WorldShape worldShape;
9
10    private Rectangle viewport;
11
12    public Canvas() {
13      worldShape = new WorldShape();
14      worldShape.Parent = this;
15    }
16
17    public void AddShape(IShape shape) {
18      worldShape.AddShape(shape);
19    }
20
21    public void RemoveShape(IShape shape) {
22      worldShape.RemoveShape(shape);
23    }
24
25    public void ClearShapes() {
26      worldShape.ClearShapes();
27    }
28
29    public Rectangle Viewport {
30      get { return viewport; }
31      set {
32        viewport = value;
33        worldShape.ClippingArea = new RectangleD(0, 0, viewport.Width, viewport.Height);
34        worldShape.BoundingBox = worldShape.ClippingArea;
35      }
36    }
37
38    public RectangleD ClippingArea {
39      get { return worldShape.ClippingArea; }
40    }
41
42    public RectangleD BoundingBox {
43      get { throw new InvalidOperationException(); }
44    }
45
46    public IShape Parent {
47      get { throw new InvalidOperationException(); }
48      set { throw new InvalidOperationException(); }
49    }
50
51    public void Draw(Graphics graphics) {
52      Stopwatch sw = new Stopwatch();
53      sw.Start();
54
55      graphics.SmoothingMode = SmoothingMode.AntiAlias;
56      graphics.FillRectangle(Brushes.White, Viewport);
57
58      worldShape.Draw(graphics);
59
60      graphics.DrawRectangle(Pens.Black, 0, 0, Viewport.Width - 1, Viewport.Height - 1);
61
62      sw.Stop();
63      Trace.WriteLine(string.Format("Drawing time: {0:0.0}ms", sw.Elapsed.TotalMilliseconds));
64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.