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