Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/3.2/RectangleShape.cs @ 3039

Last change on this file since 3039 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: 1.8 KB
Line 
1using System.Drawing;
2using HeuristicLab.Visualization.Drawing;
3
4namespace HeuristicLab.Visualization {
5  public class RectangleShape : IShape {
6    private IShape parent;
7    private RectangleD rectangle;
8
9    private Color color;
10
11    private Pen pen;
12    private Brush brush;
13
14    public RectangleShape(double x1, double y1, double x2, double y2, Color color) {
15      rectangle = new RectangleD(x1, y1, x2, y2);
16      this.color = color;
17    }
18
19    public RectangleD BoundingBox {
20      get { return rectangle; }
21    }
22
23    public RectangleD ClippingArea {
24      get { return Parent.ClippingArea; }
25    }
26
27    public Rectangle Viewport {
28      get { return Parent.Viewport; }
29    }
30
31    public IShape Parent {
32      get { return parent; }
33      set { parent = value; }
34    }
35
36    public RectangleD Rectangle {
37      get { return rectangle; }
38      set { rectangle = value; }
39    }
40
41    public void Draw(Graphics graphics) {
42      Rectangle screenRect = Transform.ToScreen(rectangle, Parent.Viewport, Parent.ClippingArea);
43
44      graphics.DrawRectangle(GetPen(), screenRect);
45      graphics.FillRectangle(GetBrush(), screenRect);
46    }
47
48    private Pen GetPen() {
49      if (pen == null)
50        pen = new Pen(color, 1);
51      return pen;
52    }
53
54    private Brush GetBrush() {
55      if (brush == null)
56        brush = new SolidBrush(color);
57      return brush;
58    }
59
60    public Color Color {
61      get { return color; }
62      set {
63        color = value;
64        DisposeDrawingTools();
65      }
66    }
67
68    private void DisposeDrawingTools() {
69      if (pen != null) {
70        pen.Dispose();
71        pen = null;
72      }
73
74      if (brush != null) {
75        brush.Dispose();
76        brush = null;
77      }
78    }
79  }
80}
Note: See TracBrowser for help on using the repository browser.