Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/LineShape.cs @ 1248

Last change on this file since 1248 was 1242, checked in by dwagner, 16 years ago

Changed Behaviour of Single value lines; They are now shown without bounds.
OptionsDialog now modifies the model and not the view; (#501 and #502)

File size: 3.3 KB
Line 
1using System.Drawing;
2using System.Drawing.Drawing2D;
3
4namespace HeuristicLab.Visualization {
5  public class LineShape : IShape {
6    private IShape parent;
7    private RectangleD boundingBox;
8
9    private Color color;
10    private int thickness;
11    private DrawingStyle drawingStyle;
12
13    private Pen pen;
14
15    /// <summary>
16    /// Initializes the LineShape.
17    /// </summary>
18    /// <param name="x1">x coordinate of left lineEndPoind</param>
19    /// <param name="y1">y coordinate of left lineEndPoind</param>
20    /// <param name="x2">x coordinate of right lineEndPoind</param>
21    /// <param name="y2">y coordinate of right lineEndPoind</param>
22    /// <param name="color">color for the LineShape</param>
23    /// <param name="thickness">tickness of the line in pixels</param>
24    /// <param name="drawingStyle">drawing style of the line (solid, dashed, dotted,...)</param>
25    public LineShape(double x1, double y1, double x2, double y2, Color color, int thickness, DrawingStyle drawingStyle) {
26      this.boundingBox = new RectangleD(x1, y1, x2, y2);
27      this.LSColor = color;
28      this.LSThickness = thickness;
29      this.LSDrawingStyle = drawingStyle;
30    }
31
32    public RectangleD BoundingBox {
33      get { return boundingBox; }
34      set { boundingBox = value; }
35    }
36
37    public RectangleD ClippingArea {
38      get { return Parent.ClippingArea; }
39    }
40
41    public Rectangle Viewport {
42      get { return Parent.Viewport; }
43    }
44
45    public IShape Parent {
46      get { return parent; }
47      set { parent = value; }
48    }
49
50    public double Y1 {
51      get { return boundingBox.Y1; }
52      set { boundingBox.Y1 = value; }
53    }
54
55    public double Y2 {
56      get { return boundingBox.Y2; }
57      set { boundingBox.Y2 = value; }
58    }
59
60    public double X1 {
61      get { return boundingBox.X1; }
62      set { boundingBox.X1 = value; }
63    }
64
65    public double X2 {
66      get { return boundingBox.X2; }
67      set { boundingBox.X2 = value; }
68    }
69
70    /// <summary>
71    /// Draws the LineShape.
72    /// </summary>
73    /// <param name="graphics">graphics handle to draw to</param>
74    public virtual void Draw(Graphics graphics) {
75      Rectangle screenRect = Transform.ToScreen(boundingBox, Parent.Viewport, Parent.ClippingArea);
76
77      graphics.DrawLine(GetPen(), screenRect.Left, screenRect.Bottom, screenRect.Right, screenRect.Top);
78    }
79
80    private Pen GetPen() {
81      if (pen == null) {
82        pen = new Pen(LSColor, LSThickness);
83
84        switch (LSDrawingStyle) {
85          case DrawingStyle.Dashed:
86            pen.DashStyle = DashStyle.Dash;
87            break;
88          default:
89            pen.DashStyle = DashStyle.Solid;
90            break;
91        }
92      }
93
94      return pen;
95    }
96
97    private void DisposePen() {
98      if (pen != null) {
99        pen.Dispose();
100        pen = null;
101      }
102    }
103
104    public Color LSColor {
105      get { return color; }
106      set {
107        color = value;
108        DisposePen();
109      }
110    }
111
112    public int LSThickness {
113      get { return thickness; }
114      set {
115        thickness = value;
116        DisposePen();
117      }
118    }
119
120    public DrawingStyle LSDrawingStyle {
121      get { return drawingStyle; }
122      set {
123        drawingStyle = value;
124        DisposePen();
125      }
126    }
127  }
128}
Note: See TracBrowser for help on using the repository browser.