[1559] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Drawing;
|
---|
| 4 | using System.Drawing.Drawing2D;
|
---|
| 5 | using System.Linq;
|
---|
| 6 | using System.Text;
|
---|
| 7 |
|
---|
| 8 | namespace HeuristicLab.Visualization {
|
---|
| 9 | class MarkerShape : IShape {
|
---|
| 10 |
|
---|
| 11 | private IShape parent;
|
---|
| 12 | private RectangleD boundingBox;
|
---|
| 13 |
|
---|
| 14 |
|
---|
| 15 | private Color color;
|
---|
| 16 | private int thickness;
|
---|
| 17 | private int width;
|
---|
| 18 | private DrawingStyle drawingStyle;
|
---|
| 19 |
|
---|
| 20 | private Pen pen;
|
---|
| 21 |
|
---|
| 22 | /// <summary>
|
---|
| 23 | /// Initializes the Marker.
|
---|
| 24 | /// </summary>
|
---|
| 25 | /// <param name="x">x coordinate of left dataPoint</param>
|
---|
| 26 | /// <param name="y">y coordinate of left dataPoint</param>
|
---|
| 27 | /// <param name="width">width of the whole marker</param>
|
---|
| 28 | /// <param name="color">color for the marker</param>
|
---|
| 29 | public MarkerShape(double x, double y, int width, Color color) {
|
---|
| 30 | this.boundingBox = new RectangleD(x , y , x, y );
|
---|
| 31 | this.width = width;
|
---|
| 32 | this.LSColor = color;
|
---|
| 33 | }
|
---|
| 34 |
|
---|
| 35 | public RectangleD BoundingBox {
|
---|
| 36 | get { return boundingBox; }
|
---|
| 37 | set { boundingBox = value; }
|
---|
| 38 | }
|
---|
| 39 |
|
---|
| 40 | public RectangleD ClippingArea {
|
---|
| 41 | get { return Parent.ClippingArea; }
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | public Rectangle Viewport {
|
---|
| 45 | get { return Parent.Viewport; }
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | public IShape Parent {
|
---|
| 49 | get { return parent; }
|
---|
| 50 | set { parent = value; }
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | public double Y {
|
---|
| 54 | get { return boundingBox.Y1; }
|
---|
| 55 | set {
|
---|
| 56 | boundingBox.Y1 = value ;
|
---|
| 57 | boundingBox.Y2 = value ;
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | public double X {
|
---|
| 63 | get { return (boundingBox.X1+boundingBox.X2)/2; }
|
---|
| 64 | set {
|
---|
| 65 | boundingBox.X1 = value;
|
---|
| 66 | boundingBox.X2 = value;
|
---|
| 67 | }
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 |
|
---|
| 71 |
|
---|
| 72 | /// <summary>
|
---|
| 73 | /// Draws the LineShape.
|
---|
| 74 | /// </summary>
|
---|
| 75 | /// <param name="graphics">graphics handle to draw to</param>
|
---|
| 76 | public virtual void Draw(Graphics graphics) {
|
---|
| 77 | Rectangle screenRect = Transform.ToScreen(boundingBox, Parent.Viewport, Parent.ClippingArea);
|
---|
| 78 | graphics.DrawEllipse(GetPen(),screenRect.Left-2, screenRect.Top-2,4,4);
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | private Pen GetPen() {
|
---|
| 82 | if (pen == null) {
|
---|
| 83 | pen = new Pen(Color.Black, 3);
|
---|
| 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 | }
|
---|
| 93 | }
|
---|
| 94 |
|
---|
| 95 | return pen;
|
---|
| 96 | }
|
---|
| 97 |
|
---|
| 98 | private void DisposePen() {
|
---|
| 99 | if (pen != null) {
|
---|
| 100 | pen.Dispose();
|
---|
| 101 | pen = null;
|
---|
| 102 | }
|
---|
| 103 | }
|
---|
| 104 |
|
---|
| 105 | public Color LSColor {
|
---|
| 106 | get { return color; }
|
---|
| 107 | set {
|
---|
| 108 | color = value;
|
---|
| 109 | DisposePen();
|
---|
| 110 | }
|
---|
| 111 | }
|
---|
| 112 |
|
---|
| 113 | public DrawingStyle LSDrawingStyle {
|
---|
| 114 | get { return drawingStyle; }
|
---|
| 115 | set {
|
---|
| 116 | drawingStyle = value;
|
---|
| 117 | DisposePen();
|
---|
| 118 | }
|
---|
| 119 | }
|
---|
| 120 |
|
---|
| 121 | }
|
---|
| 122 | }
|
---|