Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/28/09 21:21:59 (15 years ago)
Author:
mstoeger
Message:

General housekeeping (#498) Removed some old unused Z-Order values. Replaced some var types by concrete types. Renamed some LineShape properties. Added caching of Pens and Brushes in LineShape and RectangleShape. Put axis tick calculation algorithm into its own class.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Visualization/LineShape.cs

    r1187 r1233  
    55  public class LineShape : IShape {
    66    private RectangleD boundingBox;
    7     private double z;
     7
    88    private Color color;
    99    private int thickness;
    10     private DashStyle dashStyle;
     10    private DrawingStyle drawingStyle;
     11
     12    private Pen pen;
    1113
    1214    /// <summary>
     
    1820    /// <param name="y2">y coordinate of right lineEndPoind</param>
    1921    /// <param name="color">color for the LineShape</param>
    20     public LineShape(double x1, double y1, double x2, double y2, double z, Color color, int thickness, DrawingStyle style) {
     22    /// <param name="thickness">tickness of the line in pixels</param>
     23    /// <param name="drawingStyle">drawing style of the line (solid, dashed, dotted,...)</param>
     24    public LineShape(double x1, double y1, double x2, double y2, Color color, int thickness, DrawingStyle drawingStyle) {
    2125      this.boundingBox = new RectangleD(x1, y1, x2, y2);
    22       this.z = z;
    2326      this.LSColor = color;
    2427      this.LSThickness = thickness;
    25       if (style==DrawingStyle.Dashed) {
    26         this.LSDashStyle = DashStyle.Dash;
    27       }
    28       else {
    29         this.LSDashStyle = DashStyle.Solid;        //default
    30       }
     28      this.LSDrawingStyle = drawingStyle;
    3129    }
    3230
     
    6260    /// <param name="clippingArea">rectangle in screen-coordinates to draw</param>
    6361    public void Draw(Graphics graphics, Rectangle viewport, RectangleD clippingArea) {
    64       using (Pen pen = new Pen(LSColor, LSThickness)){
    65         pen.DashStyle = this.LSDashStyle;
    66         Rectangle screenRect = Transform.ToScreen(boundingBox, viewport, clippingArea);
    67         graphics.DrawLine(pen,screenRect.Left, screenRect.Bottom, screenRect.Right, screenRect.Top);
    68       }
     62      Rectangle screenRect = Transform.ToScreen(boundingBox, viewport, clippingArea);
     63
     64      graphics.DrawLine(GetPen(), screenRect.Left, screenRect.Bottom, screenRect.Right, screenRect.Top);
    6965    }
    7066
    71     public double Z {
    72       get { return z; }
    73       set { z = value; }
     67    private Pen GetPen() {
     68      if (pen == null) {
     69        pen = new Pen(LSColor, LSThickness);
     70
     71        switch (LSDrawingStyle) {
     72          case DrawingStyle.Dashed:
     73            pen.DashStyle = DashStyle.Dash;
     74            break;
     75          default:
     76            pen.DashStyle = DashStyle.Solid;
     77            break;
     78        }
     79      }
     80
     81      return pen;
     82    }
     83
     84    private void DisposePen() {
     85      if (pen != null) {
     86        pen.Dispose();
     87        pen = null;
     88      }
    7489    }
    7590
    7691    public Color LSColor {
    7792      get { return color; }
    78       set { color = value; }
     93      set {
     94        color = value;
     95        DisposePen();
     96      }
    7997    }
    8098
    8199    public int LSThickness {
    82100      get { return thickness; }
    83       set { thickness = value; }
     101      set {
     102        thickness = value;
     103        DisposePen();
     104      }
    84105    }
    85106
    86     public DashStyle LSDashStyle {
    87       get { return dashStyle; }
    88       set { dashStyle = value; }
     107    public DrawingStyle LSDrawingStyle {
     108      get { return drawingStyle; }
     109      set {
     110        drawingStyle = value;
     111        DisposePen();
     112      }
    89113    }
    90114  }
Note: See TracChangeset for help on using the changeset viewer.