Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1256 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
RevLine 
[1240]1using System;
[1038]2using System.Diagnostics;
[635]3using System.Drawing;
4using System.Drawing.Drawing2D;
5
6namespace HeuristicLab.Visualization {
[1240]7  public class Canvas : IShape {
8    private readonly WorldShape worldShape;
[635]9
[1240]10    private Rectangle viewport;
11
12    public Canvas() {
13      worldShape = new WorldShape();
14      worldShape.Parent = this;
[635]15    }
16
[1240]17    public void AddShape(IShape shape) {
18      worldShape.AddShape(shape);
19    }
[1038]20
[1240]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) {
[1038]52      Stopwatch sw = new Stopwatch();
53      sw.Start();
54
[1240]55      graphics.SmoothingMode = SmoothingMode.AntiAlias;
56      graphics.FillRectangle(Brushes.White, Viewport);
[635]57
[1240]58      worldShape.Draw(graphics);
[635]59
[1240]60      graphics.DrawRectangle(Pens.Black, 0, 0, Viewport.Width - 1, Viewport.Height - 1);
[635]61
[1038]62      sw.Stop();
63      Trace.WriteLine(string.Format("Drawing time: {0:0.0}ms", sw.Elapsed.TotalMilliseconds));
[635]64    }
65  }
66}
Note: See TracBrowser for help on using the repository browser.