Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/02/09 22:03:41 (16 years ago)
Author:
mstoeger
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization/Canvas.cs

    r1038 r1240  
     1using System;
    12using System.Diagnostics;
    23using System.Drawing;
     
    45
    56namespace HeuristicLab.Visualization {
    6   public class Canvas : ICanvas {
    7     private WorldShape world;
     7  public class Canvas : IShape {
     8    private readonly WorldShape worldShape;
    89
    9     public WorldShape WorldShape {
    10       get { return world; }
    11       set { world = value; }
     10    private Rectangle viewport;
     11
     12    public Canvas() {
     13      worldShape = new WorldShape();
     14      worldShape.Parent = this;
    1215    }
    1316
     17    public void AddShape(IShape shape) {
     18      worldShape.AddShape(shape);
     19    }
    1420
    15     public void Draw(Graphics graphics, Rectangle viewport) {
     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) {
    1652      Stopwatch sw = new Stopwatch();
    1753      sw.Start();
    1854
    19       GraphicsState gstate = graphics.Save();
     55      graphics.SmoothingMode = SmoothingMode.AntiAlias;
     56      graphics.FillRectangle(Brushes.White, Viewport);
    2057
    21       graphics.SetClip(viewport);
     58      worldShape.Draw(graphics);
    2259
    23       world.Draw(graphics, viewport, world.BoundingBox);
    24 
    25       graphics.Restore(gstate);
     60      graphics.DrawRectangle(Pens.Black, 0, 0, Viewport.Width - 1, Viewport.Height - 1);
    2661
    2762      sw.Stop();
Note: See TracChangeset for help on using the changeset viewer.