1 | using System.Drawing;
|
---|
2 |
|
---|
3 | namespace HeuristicLab.Visualization {
|
---|
4 | public class LineShape : IShape {
|
---|
5 | private RectangleD boundingBox;
|
---|
6 | private double z;
|
---|
7 | private Color color;
|
---|
8 | private int thickness;
|
---|
9 |
|
---|
10 | /// <summary>
|
---|
11 | /// Initializes the LineShape.
|
---|
12 | /// </summary>
|
---|
13 | /// <param name="x1">x coordinate of left lineEndPoind</param>
|
---|
14 | /// <param name="y1">y coordinate of left lineEndPoind</param>
|
---|
15 | /// <param name="x2">x coordinate of right lineEndPoind</param>
|
---|
16 | /// <param name="y2">y coordinate of right lineEndPoind</param>
|
---|
17 | /// <param name="color">color for the LineShape</param>
|
---|
18 | public LineShape(double x1, double y1, double x2, double y2, double z, Color color, int thickness) {
|
---|
19 | this.boundingBox = new RectangleD(x1, y1, x2, y2);
|
---|
20 | this.z = z;
|
---|
21 | this.color = color;
|
---|
22 | this.thickness = thickness;
|
---|
23 | }
|
---|
24 |
|
---|
25 | public RectangleD BoundingBox {
|
---|
26 | get { return boundingBox; }
|
---|
27 | }
|
---|
28 |
|
---|
29 | public double Y1 {
|
---|
30 | get { return boundingBox.Y1; }
|
---|
31 | set { boundingBox.Y1 = value; }
|
---|
32 | }
|
---|
33 |
|
---|
34 | public double Y2 {
|
---|
35 | get { return boundingBox.Y2; }
|
---|
36 | set { boundingBox.Y2 = value; }
|
---|
37 | }
|
---|
38 |
|
---|
39 | public double X1 {
|
---|
40 | get { return boundingBox.X1; }
|
---|
41 | set { boundingBox.X1 = value; }
|
---|
42 | }
|
---|
43 |
|
---|
44 | public double X2 {
|
---|
45 | get { return boundingBox.X2; }
|
---|
46 | set { boundingBox.X2 = value; }
|
---|
47 | }
|
---|
48 |
|
---|
49 | /// <summary>
|
---|
50 | /// Draws the LineShape.
|
---|
51 | /// </summary>
|
---|
52 | /// <param name="graphics">graphics handle to draw to</param>
|
---|
53 | /// <param name="viewport">rectangle in value-coordinates to display</param>
|
---|
54 | /// <param name="clippingArea">rectangle in screen-coordinates to draw</param>
|
---|
55 | public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
|
---|
56 | using (Pen pen = new Pen(color, thickness)){
|
---|
57 | // TODO there seems to be a bug with drawing straight lines.
|
---|
58 | Rectangle screenRect = Transform.ToScreen(boundingBox, viewport, clippingArea);
|
---|
59 | graphics.DrawLine(pen,screenRect.Left, screenRect.Bottom, screenRect.Right, screenRect.Top);
|
---|
60 | }
|
---|
61 | }
|
---|
62 |
|
---|
63 | public double Z {
|
---|
64 | get { return z; }
|
---|
65 | set { z = value; }
|
---|
66 | }
|
---|
67 | }
|
---|
68 | }
|
---|