Exemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="style"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        private Pen ToPen(BaseStyle style, Func <double, float> scale)
        {
            var pen = new Pen(ToColor(style.Stroke), (float)(style.Thickness / _state.Zoom));

            switch (style.LineCap)
            {
            case Core2D.LineCap.Flat:
                pen.StartCap = System.Drawing.Drawing2D.LineCap.Flat;
                pen.EndCap   = System.Drawing.Drawing2D.LineCap.Flat;
                pen.DashCap  = System.Drawing.Drawing2D.DashCap.Flat;
                break;

            case Core2D.LineCap.Square:
                pen.StartCap = System.Drawing.Drawing2D.LineCap.Square;
                pen.EndCap   = System.Drawing.Drawing2D.LineCap.Square;
                pen.DashCap  = System.Drawing.Drawing2D.DashCap.Flat;
                break;

            case Core2D.LineCap.Round:
                pen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
                pen.EndCap   = System.Drawing.Drawing2D.LineCap.Round;
                pen.DashCap  = System.Drawing.Drawing2D.DashCap.Round;
                break;
            }
            if (style.Dashes != null)
            {
                // TODO: Convert to correct dash values.
                pen.DashPattern = style.Dashes.Select(x => (float)x).ToArray();
            }
            pen.DashOffset = (float)style.DashOffset;
            return(pen);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Copy base style from <see cref="BaseStyle"/> source.
 /// </summary>
 /// <param name="source">The BaseStyle source object.</param>
 public ArrowStyle(BaseStyle source)
 {
     Stroke = ArgbColor.Create
         (source.Stroke.A,
          source.Stroke.R,
          source.Stroke.G,
          source.Stroke.B);
     Fill = ArgbColor.Create
         (source.Fill.A,
          source.Fill.R,
          source.Fill.G,
          source.Fill.B);
     Thickness = source.Thickness;
     LineCap = source.LineCap;
     Dashes = source.Dashes != null ? source.Dashes : default(string);
     DashOffset = source.DashOffset;
 }
Exemplo n.º 3
0
        /// <summary>
        /// Copy base style from BaseStyle source.
        /// </summary>
        /// <param name="source">The BaseStyle source object.</param>
        public ArrowStyle(BaseStyle source)
        {
            Stroke = ArgbColor.Create
                         (source.Stroke.A,
                         source.Stroke.R,
                         source.Stroke.G,
                         source.Stroke.B);
            Fill = ArgbColor.Create
                       (source.Fill.A,
                       source.Fill.R,
                       source.Fill.G,
                       source.Fill.B);
            Thickness = source.Thickness;
            LineCap   = source.LineCap;
            Dashes    = source.Dashes != null?source.Dashes.ToArray() : default(double[]);

            DashOffset = source.DashOffset;
        }
Exemplo n.º 4
0
 /// <summary>
 /// Creates a new instance of the ArrowStyle class.
 /// </summary>
 /// <param name="name">The arrow style name.</param>
 /// <param name="source">The BaseStyle source object.</param>
 /// <param name="arrowType">The arrow type.</param>
 /// <param name="isStroked">The arow shape stroke flag.</param>
 /// <param name="isFilled">The arow shape fill flag.</param>
 /// <param name="radiusX">The arrow X axis radius.</param>
 /// <param name="radiusY">The arrow Y axis radius.</param>
 /// <returns>The new instance of the ArrowStyle class.</returns>
 public static ArrowStyle Create(
     string name,
     BaseStyle source,
     ArrowType arrowType = ArrowType.None,
     bool isStroked      = true,
     bool isFilled       = false,
     double radiusX      = 5.0,
     double radiusY      = 5.0)
 {
     return(new ArrowStyle(source)
     {
         Name = name,
         ArrowType = arrowType,
         IsStroked = isStroked,
         IsFilled = isFilled,
         RadiusX = radiusX,
         RadiusY = radiusY
     });
 }
Exemplo n.º 5
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="style"></param>
 /// <param name="scale"></param>
 /// <returns></returns>
 private Pen ToPen(BaseStyle style, Func<double, float> scale)
 {
     var pen = new Pen(ToColor(style.Stroke), (float)(style.Thickness / _state.Zoom));
     switch (style.LineCap)
     {
         case Core2D.LineCap.Flat:
             pen.StartCap = System.Drawing.Drawing2D.LineCap.Flat;
             pen.EndCap = System.Drawing.Drawing2D.LineCap.Flat;
             pen.DashCap = System.Drawing.Drawing2D.DashCap.Flat;
             break;
         case Core2D.LineCap.Square:
             pen.StartCap = System.Drawing.Drawing2D.LineCap.Square;
             pen.EndCap = System.Drawing.Drawing2D.LineCap.Square;
             pen.DashCap = System.Drawing.Drawing2D.DashCap.Flat;
             break;
         case Core2D.LineCap.Round:
             pen.StartCap = System.Drawing.Drawing2D.LineCap.Round;
             pen.EndCap = System.Drawing.Drawing2D.LineCap.Round;
             pen.DashCap = System.Drawing.Drawing2D.DashCap.Round;
             break;
     }
     if (style.Dashes != null)
     {
         // TODO: Convert to correct dash values.
         pen.DashPattern = style.Dashes.Select(x => (float)x).ToArray();
     }
     pen.DashOffset = (float)style.DashOffset;
     return pen;
 }
Exemplo n.º 6
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="style"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        private Pen ToPen(BaseStyle style, Func<double, float> scale)
        {
            var pen = new Pen(
                ToColor(style.Stroke),
                scale(style.Thickness / _state.Zoom));

            switch (style.LineCap)
            {
                case Core2D.LineCap.Flat:
                    pen.LineCap = PenLineCap.Butt;
                    break;
                case Core2D.LineCap.Square:
                    pen.LineCap = PenLineCap.Square;
                    break;
                case Core2D.LineCap.Round:
                    pen.LineCap = PenLineCap.Round;
                    break;
            }
            if (style.Dashes != null)
            {
                pen.DashStyle = new DashStyle(
                    (float)style.DashOffset,
                    style.Dashes.Select(x => (float)x).ToArray());
            }
            return pen;
        }
Exemplo n.º 7
0
 /// <summary>
 /// Creates a new <see cref="ArrowStyle"/> instance.
 /// </summary>
 /// <param name="name">The arrow style name.</param>
 /// <param name="source">The BaseStyle source object.</param>
 /// <param name="arrowType">The arrow type.</param>
 /// <param name="isStroked">The arow shape stroke flag.</param>
 /// <param name="isFilled">The arow shape fill flag.</param>
 /// <param name="radiusX">The arrow X axis radius.</param>
 /// <param name="radiusY">The arrow Y axis radius.</param>
 /// <returns>The new instance of the ArrowStyle class.</returns>
 public static ArrowStyle Create(
     string name,
     BaseStyle source,
     ArrowType arrowType = ArrowType.None,
     bool isStroked = true,
     bool isFilled = false,
     double radiusX = 5.0,
     double radiusY = 5.0)
 {
     return new ArrowStyle(source)
     {
         Name = name,
         ArrowType = arrowType,
         IsStroked = isStroked,
         IsFilled = isFilled,
         RadiusX = radiusX,
         RadiusY = radiusY
     };
 }
Exemplo n.º 8
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="style"></param>
 /// <param name="thickness"></param>
 /// <returns></returns>
 private static Pen CreatePen(BaseStyle style, double thickness)
 {
     var brush = CreateBrush(style.Stroke);
     var pen = new Pen(brush, thickness);
     switch (style.LineCap)
     {
         case LineCap.Flat:
             pen.StartLineCap = PenLineCap.Flat;
             pen.EndLineCap = PenLineCap.Flat;
             pen.DashCap = PenLineCap.Flat;
             break;
         case LineCap.Square:
             pen.StartLineCap = PenLineCap.Square;
             pen.EndLineCap = PenLineCap.Square;
             pen.DashCap = PenLineCap.Square;
             break;
         case LineCap.Round:
             pen.StartLineCap = PenLineCap.Round;
             pen.EndLineCap = PenLineCap.Round;
             pen.DashCap = PenLineCap.Round;
             break;
     }
     pen.DashStyle = new DashStyle(
         ShapeStyle.DashesToDoubleArray(style.Dashes),
         style.DashOffset);
     pen.DashStyle.Offset = style.DashOffset;
     pen.Freeze();
     return pen;
 }
Exemplo n.º 9
0
 private static CanvasStrokeStyle CreateStrokeStyle(BaseStyle style)
 {
     var ss = new CanvasStrokeStyle();
     switch (style.LineCap)
     {
         case LineCap.Flat:
             ss.StartCap = CanvasCapStyle.Flat;
             ss.EndCap = CanvasCapStyle.Flat;
             ss.DashCap = CanvasCapStyle.Flat;
             break;
         case LineCap.Square:
             ss.StartCap = CanvasCapStyle.Square;
             ss.EndCap = CanvasCapStyle.Square;
             ss.DashCap = CanvasCapStyle.Square;
             break;
         case LineCap.Round:
             ss.StartCap = CanvasCapStyle.Round;
             ss.EndCap = CanvasCapStyle.Round;
             ss.DashCap = CanvasCapStyle.Round;
             break;
     }
     if (style.Dashes != null)
     {
         ss.CustomDashStyle = ShapeStyle.DashesToFloatArray(style.Dashes);
     }
     ss.DashOffset = (float)style.DashOffset;
     return ss;
 }
Exemplo n.º 10
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="style"></param>
        /// <param name="scale"></param>
        /// <returns></returns>
        private Pen ToPen(BaseStyle style, Func<double, float> scale)
        {
            var lineCap = default(PenLineCap);
            var dashStyle = default(DashStyle);

            switch (style.LineCap)
            {
                case LineCap.Flat:
                    lineCap = PenLineCap.Flat;
                    break;
                case LineCap.Square:
                    lineCap = PenLineCap.Square;
                    break;
                case LineCap.Round:
                    lineCap = PenLineCap.Round;
                    break;
            }

            if (style.Dashes != null)
            {
                dashStyle = new DashStyle(
                    style.Dashes,
                    style.DashOffset);
            }

            var pen = new Pen(
                ToSolidBrush(style.Stroke),
                scale(style.Thickness / _state.Zoom),
                dashStyle, lineCap,
                lineCap, lineCap);

            return pen;
        }