External/OxyPlot/OxyPlot/Foundation/OxyPen.cs
author StephaneLenclud
Tue, 03 Feb 2015 10:14:18 +0100
branchMiniDisplay
changeset 450 f2d8620e2434
permissions -rw-r--r--
Rebracer update.
     1 // --------------------------------------------------------------------------------------------------------------------
     2 // <copyright file="OxyPen.cs" company="OxyPlot">
     3 //   The MIT License (MIT)
     4 //
     5 //   Copyright (c) 2012 Oystein Bjorke
     6 //
     7 //   Permission is hereby granted, free of charge, to any person obtaining a
     8 //   copy of this software and associated documentation files (the
     9 //   "Software"), to deal in the Software without restriction, including
    10 //   without limitation the rights to use, copy, modify, merge, publish,
    11 //   distribute, sublicense, and/or sell copies of the Software, and to
    12 //   permit persons to whom the Software is furnished to do so, subject to
    13 //   the following conditions:
    14 //
    15 //   The above copyright notice and this permission notice shall be included
    16 //   in all copies or substantial portions of the Software.
    17 //
    18 //   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
    19 //   OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
    20 //   MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
    21 //   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
    22 //   CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
    23 //   TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
    24 //   SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
    25 // </copyright>
    26 // <summary>
    27 //   Describes a pen in terms of color, thickness, line style and line join type.
    28 // </summary>
    29 // --------------------------------------------------------------------------------------------------------------------
    30 namespace OxyPlot
    31 {
    32     using System;
    33 
    34     /// <summary>
    35     /// Describes a pen in terms of color, thickness, line style and line join type.
    36     /// </summary>
    37     public class OxyPen
    38     {
    39         /// <summary>
    40         /// Initializes a new instance of the <see cref="OxyPen"/> class.
    41         /// </summary>
    42         /// <param name="color">
    43         /// The color.
    44         /// </param>
    45         /// <param name="thickness">
    46         /// The thickness.
    47         /// </param>
    48         /// <param name="lineStyle">
    49         /// The line style.
    50         /// </param>
    51         /// <param name="lineJoin">
    52         /// The line join.
    53         /// </param>
    54         public OxyPen(
    55             OxyColor color,
    56             double thickness = 1.0,
    57             LineStyle lineStyle = LineStyle.Solid,
    58             OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter)
    59         {
    60             this.Color = color;
    61             this.Thickness = thickness;
    62             this.DashArray = LineStyleHelper.GetDashArray(lineStyle);
    63             this.LineStyle = lineStyle;
    64             this.LineJoin = lineJoin;
    65         }
    66 
    67         /// <summary>
    68         /// Gets or sets the color.
    69         /// </summary>
    70         /// <value>The color.</value>
    71         public OxyColor Color { get; set; }
    72 
    73         /// <summary>
    74         /// Gets or sets the dash array.
    75         /// </summary>
    76         /// <value>The dash array.</value>
    77         public double[] DashArray { get; set; }
    78 
    79         /// <summary>
    80         /// Gets or sets the line join.
    81         /// </summary>
    82         /// <value>The line join.</value>
    83         public OxyPenLineJoin LineJoin { get; set; }
    84 
    85         /// <summary>
    86         /// Gets or sets the line style.
    87         /// </summary>
    88         /// <value>The line style.</value>
    89         public LineStyle LineStyle { get; set; }
    90 
    91         /// <summary>
    92         /// Gets or sets the thickness.
    93         /// </summary>
    94         /// <value>The thickness.</value>
    95         public double Thickness { get; set; }
    96 
    97         /// <summary>
    98         /// Creates the specified pen.
    99         /// </summary>
   100         /// <param name="color">The color.</param>
   101         /// <param name="thickness">The thickness.</param>
   102         /// <param name="lineStyle">The line style.</param>
   103         /// <param name="lineJoin">The line join.</param>
   104         /// <returns>A pen.</returns>
   105         public static OxyPen Create(
   106             OxyColor color,
   107             double thickness,
   108             LineStyle lineStyle = LineStyle.Solid,
   109             OxyPenLineJoin lineJoin = OxyPenLineJoin.Miter)
   110         {
   111             if (color == null || lineStyle == LineStyle.None || Math.Abs(thickness) < double.Epsilon)
   112             {
   113                 return null;
   114             }
   115 
   116             return new OxyPen(color, thickness, lineStyle, lineJoin);
   117         }
   118 
   119         /// <summary>
   120         /// Returns a hash code for this instance.
   121         /// </summary>
   122         /// <returns>
   123         /// A hash code for this instance, suitable for use in hashing algorithms and data structures like a hash table.
   124         /// </returns>
   125         public override int GetHashCode()
   126         {
   127             unchecked
   128             {
   129                 int result = this.Color.GetHashCode();
   130                 result = (result * 397) ^ this.Thickness.GetHashCode();
   131                 result = (result * 397) ^ this.LineStyle.GetHashCode();
   132                 result = (result * 397) ^ this.LineJoin.GetHashCode();
   133                 return result;
   134             }
   135         }
   136 
   137     }
   138 }