Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.Visualization/3.2/LineShape.cs @ 1688

Last change on this file since 1688 was 1530, checked in by gkronber, 16 years ago

Moved source files of plugins Hive ... Visualization.Test into version-specific sub-folders. #576

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