Esempio n. 1
0
        /// <summary>
        /// Draw border at specified position.
        /// </summary>
        /// <param name="g">Instance for graphics object.</param>
        /// <param name="x">X coordinate of start point.</param>
        /// <param name="y">Y coordinate of start point.</param>
        /// <param name="x2">X coordinate of end point.</param>
        /// <param name="y2">Y coordinate of end point.</param>
        /// <param name="style">Style flag of border.</param>
        /// <param name="color">Color of border.</param>
        /// <param name="bgPen">Fill pen used when drawing double outline.</param>
        public void DrawLine(PlatformGraphics g, RGFloat x, RGFloat y, RGFloat x2, RGFloat y2, BorderLineStyle style,
                             SolidColor color, RGPen bgPen = null)
        {
            if (style == BorderLineStyle.None)
            {
                return;
            }

#if WINFORM || WPF || ANDROID
#if WINFORM
            RGPen p = pens[(byte)style];

            lock (p)
            {
                p.Color    = color;
                p.StartCap = System.Drawing.Drawing2D.LineCap.Square;
                p.EndCap   = System.Drawing.Drawing2D.LineCap.Square;
                g.DrawLine(p, new RGPointF(x, y), new RGPointF(x2, y2));
            }
#elif WPF
            // get template pen from cache list
            var tp = pens[(byte)style];

            // create new WPF pen
            var p = new RGPen(new RGSolidBrush(color), tp.Thickness);
            // copy the pen style from template
            p.DashStyle = tp.DashStyle;

            p.StartLineCap = System.Windows.Media.PenLineCap.Square;
            p.EndLineCap   = System.Windows.Media.PenLineCap.Square;

            System.Windows.Media.GuidelineSet gs = new System.Windows.Media.GuidelineSet();
            double halfPenWidth = p.Thickness / 2;
            gs.GuidelinesX.Add(x + halfPenWidth);
            gs.GuidelinesY.Add(y + halfPenWidth);
            gs.GuidelinesX.Add(x2 + halfPenWidth);
            gs.GuidelinesY.Add(y2 + halfPenWidth);
            g.PushGuidelineSet(gs);
            g.DrawLine(p, new RGPointF(x, y), new RGPointF(x2, y2));
#elif ANDROID
            g.DrawLine(x, y, x2, y2, p);
#endif



            if (style == BorderLineStyle.DoubleLine && bgPen != null)
            {
                lock (bgPen)
                {
#if WINFORM || WPF
                    g.DrawLine(bgPen, new RGPointF(x, y), new RGPointF(x2, y2));
#elif ANDROID
                    g.DrawLine(x, y, x2, y2, bgPen);
#endif // WPF
                }
            }

#if WPF
            g.Pop();
#endif // WPF

//#endif // WINFORM || WPF || ANDROID
#elif iOS
            using (var path = new CGPath())
            {
                path.AddLines(new CGPoint[] { new CGPoint(x, y), new CGPoint(x2, y2) });

                switch (style)
                {
                default:
                case BorderLineStyle.Solid:
                    g.AddPath(path);
                    g.SetStrokeColor(color);
                    g.DrawPath(CGPathDrawingMode.Stroke);
                    break;
                }
            }
#endif // iOS
        }