Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1904 was 1530, checked in by gkronber, 16 years ago

Moved source files of plugins Hive ... Visualization.Test into version-specific sub-folders. #576

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