Free cookie consent management tool by TermsFeed Policy Generator

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

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