1 | using System.Drawing;
|
---|
2 | using System.Drawing.Drawing2D;
|
---|
3 |
|
---|
4 | namespace 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.LSColor = color;
|
---|
24 | this.LSThickness = thickness;
|
---|
25 | if (style==DrawingStyle.Dashed) {
|
---|
26 | this.LSDashStyle = DashStyle.Dash;
|
---|
27 | }
|
---|
28 | else {
|
---|
29 | this.LSDashStyle = 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(LSColor, LSThickness)){
|
---|
65 | pen.DashStyle = this.LSDashStyle;
|
---|
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 | public Color LSColor {
|
---|
77 | get { return color; }
|
---|
78 | set { color = value; }
|
---|
79 | }
|
---|
80 |
|
---|
81 | public int LSThickness {
|
---|
82 | get { return thickness; }
|
---|
83 | set { thickness = value; }
|
---|
84 | }
|
---|
85 |
|
---|
86 | public DashStyle LSDashStyle {
|
---|
87 | get { return dashStyle; }
|
---|
88 | set { dashStyle = value; }
|
---|
89 | }
|
---|
90 | }
|
---|
91 | }
|
---|