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