예제 #1
0
        public static void SetStrokeStyle(this Pen pen, UGStrokeStyle strokeStyle)
        {
            var lineCap = strokeStyle.LineCap.ToGDILineCap();
            var dashCap = strokeStyle.LineCap.ToGDIDashCap();

            pen.SetLineCap(lineCap, lineCap, dashCap);
            pen.LineJoin   = strokeStyle.LineJoin.ToGDILineJoin();
            pen.MiterLimit = strokeStyle.MiterLimit;
            if (strokeStyle.DashStyle.Value != null)
            {
                if (strokeStyle.LineCap != UGCapStyle.Flat)
                {
                    var style     = strokeStyle.DashStyle.Value;
                    var count     = style.Length;
                    var copyStyle = new float[count];
                    style.CopyTo(copyStyle, 0);
                    for (var i = 0; i < count; i += 2)
                    {
                        copyStyle[i]    += .999999F;
                        copyStyle[i + 1] = Math.Max(style[i + 1] - .999999F, 0F);
                    }
                    if (!copyStyle.Where((v, i) => i % 2 == 1).All(v => v == 0))
                    {
                        pen.DashPattern = copyStyle;
                        pen.DashOffset  = strokeStyle.DashOffset - .5F;
                    }
                }
                else
                {
                    pen.DashPattern = strokeStyle.DashStyle.Value;
                    pen.DashOffset  = strokeStyle.DashOffset;
                }
            }
        }
예제 #2
0
        public void OnDraw(IUGContext context)
        {
            context.ClearColor(WHITE);

            var offset = (context.CanvasSize.Height - 2F * MARGIN) / (count - 1);
            var start  = new Vector2()
            {
                X = MARGIN, Y = MARGIN
            };
            var end = new Vector2()
            {
                X = context.CanvasSize.Width - MARGIN, Y = MARGIN
            };
            var style = new UGStrokeStyle();

            foreach (var cap in caps)
            {
                style.LineCap = cap;

                foreach (var dashStyle in styles)
                {
                    style.DashStyle = new UGDashStyle(dashStyle);
                    context.DrawLine(start, end, BLUE, STROKE_WIDTH, style);
                    start.Y += offset;
                    end.Y   += offset;
                }
            }
        }
예제 #3
0
 public static void SetStrokeStyle(this CGContext context, float strokeWidth, UGStrokeStyle strokeStyle)
 {
     context.SetLineCap(strokeStyle.LineCap.ToCGLineCap());
     context.SetLineJoin(strokeStyle.LineJoin.ToCGLineJoin());
     context.SetMiterLimit(strokeStyle.MiterLimit);
     if (strokeStyle.DashStyle.Value != null)
     {
         context.SetLineDash(strokeStyle.DashOffset, strokeStyle.DashStyle.Value.Select(v => (nfloat)v * strokeWidth).ToArray());
     }
 }
예제 #4
0
        public static void SetStrokeStyle(this Pen pen, UGStrokeStyle strokeStyle)
        {
            var lineCap = strokeStyle.LineCap.ToWPFLineCap();

            pen.StartLineCap = lineCap;
            pen.EndLineCap   = lineCap;
            pen.LineJoin     = strokeStyle.LineJoin.ToWPFLineJoin();
            pen.MiterLimit   = strokeStyle.MiterLimit;
            if (strokeStyle.DashStyle.Value != null)
            {
                pen.DashStyle = new DashStyle(strokeStyle.DashStyle.Value.Select(v => (double)v), strokeStyle.DashOffset);
                pen.DashCap   = lineCap;
            }
        }
예제 #5
0
 public static void SetStrokeStyle(this Paint paint, float strokeWidth, UGStrokeStyle strokeStyle)
 {
     paint.StrokeCap   = strokeStyle.LineCap.ToAGPaintCap();
     paint.StrokeJoin  = strokeStyle.LineJoin.ToAGPaintJoin();
     paint.StrokeMiter = strokeStyle.MiterLimit;
     if (strokeStyle.DashStyle.Value != null)
     {
         using (var effect = new DashPathEffect(
                    strokeStyle.DashStyle.Value.Select(v => v * strokeWidth).ToArray(),
                    strokeStyle.DashOffset))
         {
             paint.SetPathEffect(effect);
         }
     }
 }
예제 #6
0
        public static CanvasStrokeStyle ToWin2DStrokeStyle(this UGStrokeStyle strokeStyle)
        {
            var lineCap        = strokeStyle.LineCap.ToWin2DLineCap();
            var retStrokeStyle = new CanvasStrokeStyle()
            {
                StartCap   = lineCap,
                EndCap     = lineCap,
                LineJoin   = strokeStyle.LineJoin.ToWin2DLineJoin(),
                MiterLimit = strokeStyle.MiterLimit,
            };

            if (strokeStyle.DashStyle.Value != null)
            {
                retStrokeStyle.DashCap         = lineCap;
                retStrokeStyle.CustomDashStyle = strokeStyle.DashStyle.Value;
                retStrokeStyle.DashOffset      = strokeStyle.DashOffset;
            }
            return(retStrokeStyle);
        }
예제 #7
0
 public static void DrawRoundedRectangle(this IUGContext context, float x, float y, UGSize size, float radiusX, float radiusY, UGColor color, float strokeWidth, UGStrokeStyle strokeStyle)
 => context.DrawRoundedRectangle(x, y, size.Width, size.Height, radiusX, radiusY, color, strokeWidth, strokeStyle);
예제 #8
0
 public static void DrawRoundedRectangle(this IUGContext context, Vector2 point, float width, float height, float radius, UGColor color, float strokeWidth, UGStrokeStyle strokeStyle)
 => context.DrawRoundedRectangle(point.X, point.Y, width, height, radius, radius, color, strokeWidth, strokeStyle);
예제 #9
0
 public static void DrawPath(this IUGContext context, IUGPath path, Vector2 offset, UGColor color, float strokeWidth, UGStrokeStyle strokeStyle)
 => context.DrawPath(path, offset.X, offset.Y, color, strokeWidth, strokeStyle);
예제 #10
0
 public static void DrawPath(this IUGContext context, IUGPath path, UGColor color, float strokeWidth, UGStrokeStyle strokeStyle)
 => context.DrawPath(path, color, strokeWidth, strokeStyle);
예제 #11
0
 public static void DrawEllipseInRectangle(this IUGContext context, UGRect rect, UGColor color, float strokeWidth, UGStrokeStyle strokeStyle)
 => context.DrawEllipseInRectangle(rect.X, rect.Y, rect.Width, rect.Height, color, strokeWidth, strokeStyle);
예제 #12
0
 public static void DrawEllipseInRectangle(this IUGContext context, Vector2 point, UGSize size, UGColor color, float strokeWidth, UGStrokeStyle strokeStyle)
 => context.DrawEllipseInRectangle(point.X, point.Y, size.Width, size.Height, color, strokeWidth, strokeStyle);
예제 #13
0
 public static void DrawEllipse(this IUGContext context, Vector2 centerPoint, float radiusX, float radiusY, UGColor color, float strokeWidth, UGStrokeStyle strokeStyle)
 => context.DrawEllipse(centerPoint.X, centerPoint.Y, radiusX, radiusY, color, strokeWidth, strokeStyle);
예제 #14
0
 public static void DrawCircleInRectangle(this IUGContext context, Vector2 point, float length, UGColor color, float strokeWidth, UGStrokeStyle strokeStyle)
 => context.DrawCircleInRectangle(point.X, point.Y, length, color, strokeWidth, strokeStyle);
예제 #15
0
 public static void DrawLine(this IUGContext context, Vector2 start, Vector2 end, UGColor color, float strokeWidth, UGStrokeStyle strokeStyle)
 => context.DrawLine(start.X, start.Y, end.X, end.Y, color, strokeWidth, strokeStyle);
예제 #16
0
 public static void DrawRoundedRectangle(this IUGContext context, Vector2 point, UGSize size, float radiusX, float radiusY, UGColor color, float strokeWidth, UGStrokeStyle strokeStyle)
 => context.DrawRoundedRectangle(point.X, point.Y, size.Width, size.Height, radiusX, radiusY, color, strokeWidth, strokeStyle);
예제 #17
0
 public static void DrawRoundedRectangle(this IUGContext context, UGRect rect, float radiusX, float radiusY, UGColor color, float strokeWidth, UGStrokeStyle strokeStyle)
 => context.DrawRoundedRectangle(rect.X, rect.Y, rect.Width, rect.Height, radiusX, radiusY, color, strokeWidth, strokeStyle);
예제 #18
0
 public static void DrawEllipseInRectangle(this IUGContext context, float x, float y, UGSize size, UGColor color, float strokeWidth, UGStrokeStyle strokeStyle)
 => context.DrawEllipseInRectangle(x, y, size.Width, size.Height, color, strokeWidth, strokeStyle);