Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/RectangleShape.cs @ 1473

Last change on this file since 1473 was 1351, checked in by mstoeger, 16 years ago

Fixed Zoom & Pan. Improved Mouse-Wheel-Zoom. (#424)

File size: 1.7 KB
Line 
1using System.Drawing;
2
3namespace HeuristicLab.Visualization {
4  public class RectangleShape : IShape {
5    private IShape parent;
6    private RectangleD rectangle;
7
8    private Color color;
9
10    private Pen pen;
11    private Brush brush;
12
13    public RectangleShape(double x1, double y1, double x2, double y2, Color color) {
14      rectangle = new RectangleD(x1, y1, x2, y2);
15      this.color = color;
16    }
17
18    public RectangleD BoundingBox {
19      get { return rectangle; }
20    }
21
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
35    public RectangleD Rectangle {
36      get { return rectangle; }
37      set { rectangle = value; }
38    }
39
40    public void Draw(Graphics graphics) {
41      Rectangle screenRect = Transform.ToScreen(rectangle, Parent.Viewport, Parent.ClippingArea);
42
43      graphics.DrawRectangle(GetPen(), screenRect);
44      graphics.FillRectangle(GetBrush(), screenRect);
45    }
46
47    private Pen GetPen() {
48      if (pen == null)
49        pen = new Pen(color, 1);
50      return pen;
51    }
52
53    private Brush GetBrush() {
54      if (brush == null)
55        brush = new SolidBrush(color);
56      return brush;
57    }
58
59    public Color Color {
60      get { return color; }
61      set {
62        color = value;
63        DisposeDrawingTools();
64      }
65    }
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    }
78  }
79}
Note: See TracBrowser for help on using the repository browser.