Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 1035 was 980, checked in by dwagner, 16 years ago

Added feature: Drawingstyle for lines; #345

File size: 2.4 KB
Line 
1using System.Drawing;
2using System.Drawing.Drawing2D;
3
4namespace HeuristicLab.Visualization {
5  public class LineShape : IShape {
6    private RectangleD boundingBox;
7    private double z;
8    private Color color;
9    private int thickness;
10    private DashStyle dashStyle;
11
12    /// <summary>
13    /// Initializes the LineShape.
14    /// </summary>
15    /// <param name="x1">x coordinate of left lineEndPoind</param>
16    /// <param name="y1">y coordinate of left lineEndPoind</param>
17    /// <param name="x2">x coordinate of right lineEndPoind</param>
18    /// <param name="y2">y coordinate of right lineEndPoind</param>
19    /// <param name="color">color for the LineShape</param>
20    public LineShape(double x1, double y1, double x2, double y2, double z, Color color, int thickness, DrawingStyle style) {
21      this.boundingBox = new RectangleD(x1, y1, x2, y2);
22      this.z = z;
23      this.color = color;
24      this.thickness = thickness;
25      if (style==DrawingStyle.Dashed) {
26        this.dashStyle = DashStyle.Dash;
27      }
28      else {
29        this.dashStyle = DashStyle.Solid;        //default
30      }
31    }
32
33    public RectangleD BoundingBox {
34      get { return boundingBox; }
35    }
36
37    public double Y1 {
38      get { return boundingBox.Y1; }
39      set { boundingBox.Y1 = value; }
40    }
41
42    public double Y2 {
43      get { return boundingBox.Y2; }
44      set { boundingBox.Y2 = value; }
45    }
46
47    public double X1 {
48      get { return boundingBox.X1; }
49      set { boundingBox.X1 = value; }
50    }
51
52    public double X2 {
53      get { return boundingBox.X2; }
54      set { boundingBox.X2 = value; }
55    }
56
57    /// <summary>
58    /// Draws the LineShape.
59    /// </summary>
60    /// <param name="graphics">graphics handle to draw to</param>
61    /// <param name="viewport">rectangle in value-coordinates to display</param>
62    /// <param name="clippingArea">rectangle in screen-coordinates to draw</param>
63    public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
64      using (Pen pen = new Pen(color, thickness)){
65        pen.DashStyle = this.dashStyle;
66        Rectangle screenRect = Transform.ToScreen(boundingBox, viewport, clippingArea);
67        graphics.DrawLine(pen,screenRect.Left, screenRect.Bottom, screenRect.Right, screenRect.Top);
68      }
69    }
70
71    public double Z {
72      get { return z; }
73      set { z = value; }
74    }
75  }
76}
Note: See TracBrowser for help on using the repository browser.