Last change
on this file since 1235 was
1234,
checked in by mstoeger, 16 years ago
|
Added Xml comments for IShape, WorldShape and Transforms. (#406)
|
File size:
1.7 KB
|
Line | |
---|
1 | using System.Drawing;
|
---|
2 |
|
---|
3 | namespace HeuristicLab.Visualization {
|
---|
4 | public class RectangleShape : IShape {
|
---|
5 | private RectangleD rectangle;
|
---|
6 |
|
---|
7 | private Color color;
|
---|
8 | private int opacity = 255;
|
---|
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 Rectangle {
|
---|
23 | get { return rectangle; }
|
---|
24 | set { rectangle = value; }
|
---|
25 | }
|
---|
26 |
|
---|
27 | public void Draw(Graphics graphics, Rectangle parentViewport, RectangleD parentClippingArea) {
|
---|
28 | Rectangle screenRect = Transform.ToScreen(rectangle, parentViewport, parentClippingArea);
|
---|
29 |
|
---|
30 | graphics.DrawRectangle(GetPen(), screenRect);
|
---|
31 | graphics.FillRectangle(GetBrush(), screenRect);
|
---|
32 | }
|
---|
33 |
|
---|
34 | private Pen GetPen() {
|
---|
35 | if (pen == null)
|
---|
36 | pen = new Pen(color, 1);
|
---|
37 | return pen;
|
---|
38 | }
|
---|
39 |
|
---|
40 | private Brush GetBrush() {
|
---|
41 | if (brush == null)
|
---|
42 | brush = new SolidBrush(Color.FromArgb(opacity, color));
|
---|
43 | return brush;
|
---|
44 | }
|
---|
45 |
|
---|
46 | public int Opacity {
|
---|
47 | get { return opacity; }
|
---|
48 | set {
|
---|
49 | opacity = value;
|
---|
50 | DisposeDrawingTools();
|
---|
51 | }
|
---|
52 | }
|
---|
53 |
|
---|
54 | public Color Color {
|
---|
55 | get { return color; }
|
---|
56 | set {
|
---|
57 | color = value;
|
---|
58 | DisposeDrawingTools();
|
---|
59 | }
|
---|
60 | }
|
---|
61 |
|
---|
62 | private void DisposeDrawingTools() {
|
---|
63 | if (pen != null) {
|
---|
64 | pen.Dispose();
|
---|
65 | pen = null;
|
---|
66 | }
|
---|
67 |
|
---|
68 | if (brush != null) {
|
---|
69 | brush.Dispose();
|
---|
70 | brush = null;
|
---|
71 | }
|
---|
72 | }
|
---|
73 | }
|
---|
74 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.