示例#1
0
		public override void Draw(ICanvas canvas, Rect rect)
		{
			if(DrawingFunction != null)
			{
				base.Draw(canvas, rect);
				return;
			}

			var borderColro = NGraphics.Color.FromHSL(
				                  BorderColor.Hue,
				                  BorderColor.Saturation,
				                  BorderColor.Luminosity,
				                  BorderColor.A);
			var pen = new Pen(borderColro, BorderWidth);
			var fillColor = NGraphics.Color.FromHSL(
				                BackColor.Hue,
				                BackColor.Saturation,
				                BackColor.Luminosity,
				                BackColor.A);
			var brush = new SolidBrush(fillColor);

			var padding = BorderWidth <= 0 ? 0.0 : BorderWidth;
			var newRect = rect.GetInflated(-padding);
			var curveSize = newRect.Height / 2;

			canvas.DrawPath(new PathOp []{ 
				new MoveTo(newRect.Left+curveSize, newRect.Top),
				new LineTo(newRect.Right-curveSize, newRect.Top),
				new CurveTo(
					new NGraphics.Point(newRect.Right-curveSize, newRect.Top),
					newRect.TopRight,
					new NGraphics.Point(newRect.Right, newRect.Top+curveSize)
				),
				new CurveTo(
					new NGraphics.Point(newRect.Right, newRect.Bottom-curveSize),
					newRect.BottomRight,
					new NGraphics.Point(newRect.Right-curveSize, newRect.Bottom)
				),
				new LineTo(newRect.Left+curveSize, newRect.Bottom),
				new CurveTo(
					new NGraphics.Point(newRect.Left+curveSize, newRect.Bottom),
					newRect.BottomLeft,
					new NGraphics.Point(newRect.Left, newRect.Bottom-curveSize)
				),
				new CurveTo(
					new NGraphics.Point(newRect.Left, newRect.Top+curveSize),
					newRect.TopLeft,
					new NGraphics.Point(newRect.Left+curveSize, newRect.Top)
				),
				new ClosePath()
			}, pen, brush);
		}
示例#2
0
        /// <summary>
        /// Draw the specified canvas.
        /// </summary>
        /// <param name="canvas">Canvas.</param>
        /// <param name="rect">Rect.</param>
        public override void Draw(NGraphics.ICanvas canvas, NGraphics.Rect rect)
        {
            base.Draw(canvas, rect);

            var backgroundBrush = new SolidBrush(new NGraphics.Color(BackgroundColor.R,
                BackgroundColor.G, BackgroundColor.B, BackgroundColor.A));
            
            var curveSize = CornerRadius;
            var width = rect.Width;
            var height = rect.Height;
            canvas.DrawPath(new PathOp []{ 
                new MoveTo(curveSize, 0),
                // Top Right corner
                new LineTo(width-curveSize, 0),
                new CurveTo(
                    new NGraphics.Point(width-curveSize, 0),
                    new NGraphics.Point(width, 0),
                    new NGraphics.Point(width, curveSize)
                ),
                new LineTo(width, height-curveSize),
                // Bottom right corner
                new CurveTo(
                    new NGraphics.Point(width, height-curveSize),
                    new NGraphics.Point(width, height),
                    new NGraphics.Point(width-curveSize, height)
                ),
                new LineTo(curveSize, height),
                // Bottom left corner
                new CurveTo(
                    new NGraphics.Point(curveSize, height),
                    new NGraphics.Point(0, height),
                    new NGraphics.Point(0, height-curveSize)
                ),
                new LineTo(0, curveSize),
                new CurveTo(
                    new NGraphics.Point(0, curveSize),
                    new NGraphics.Point(0, 0),
                    new NGraphics.Point(curveSize, 0)
                ),
                new ClosePath()
            }, null, backgroundBrush);

        }
示例#3
0
 public void SetPixel(int x, int y, NGraphics.SolidBrush brush)
 {
     canvas.FillRectangle(x, y, 1, 1, brush);
 }
示例#4
0
        void ApplyStyle(Dictionary<string, string> style, ref Pen pen, out bool hasPen, ref Brush brush, out bool hasBrush)
        {
            //
            // Pen attributes
            //
            var strokeWidth = GetString (style, "stroke-width");
            if (!string.IsNullOrWhiteSpace (strokeWidth)) {
                if (pen == null)
                    pen = new Pen ();
                pen.Width = ReadNumber (strokeWidth);
            }

            var strokeOpacity = GetString (style, "stroke-opacity");
            if (!string.IsNullOrWhiteSpace (strokeOpacity)) {
                if (pen == null)
                    pen = new Pen ();
                pen.Color = pen.Color.WithAlpha (ReadNumber (strokeOpacity));
            }

            //
            // Pen
            //
            var stroke = GetString (style, "stroke").Trim ();
            if (string.IsNullOrEmpty (stroke)) {
                // No change
                hasPen = false;
            } else if (stroke.Equals("none", StringComparison.OrdinalIgnoreCase)) {
                hasPen = true;
                pen = null;
            } else {
                hasPen = true;
                if (pen == null)
                    pen = new Pen ();
                Color color;
                if (Colors.TryParse (stroke, out color)) {
                    if (pen.Color.Alpha == 1)
                        pen.Color = color;
                    else
                        pen.Color = color.WithAlpha (pen.Color.Alpha);
                }
            }

            //
            // Brush attributes
            //
            var fillOpacity = GetString (style, "fill-opacity");
            if (!string.IsNullOrWhiteSpace (fillOpacity)) {
                if (brush == null)
                    brush = new SolidBrush ();
                var sb = brush as SolidBrush;
                if (sb != null)
                    sb.Color = sb.Color.WithAlpha (ReadNumber (fillOpacity));
            }

            //
            // Brush
            //
            var fill = GetString (style, "fill").Trim ();
            if (string.IsNullOrEmpty (fill)) {
                // No change
                hasBrush = false;
            } else if (fill.Equals("none", StringComparison.OrdinalIgnoreCase)) {
                hasBrush = true;
                brush = null;
            } else {
                hasBrush = true;
                Color color;
                if (Colors.TryParse (fill, out color)) {
                    var sb = brush as SolidBrush;
                    if (sb == null) {
                        brush = new SolidBrush (color);
                    } else {
                        if (sb.Color.Alpha == 1)
                            sb.Color = color;
                        else
                            sb.Color = color.WithAlpha (sb.Color.Alpha);
                    }
                } else {
                    var urlM = fillUrlRe.Match (fill);
                    if (urlM.Success) {
                        var id = urlM.Groups [1].Value.Trim ();
                        brush = GetGradientBrush(id, null);
                    } else {
                        throw new NotSupportedException ("Fill " + fill);
                    }
                }
            }
        }
示例#5
0
        void ApplyStyle(Dictionary <string, string> style, ref Pen pen, out bool hasPen, ref Brush brush, out bool hasBrush)
        {
            //
            // Pen attributes
            //
            var strokeWidth = GetString(style, "stroke-width");

            if (!string.IsNullOrWhiteSpace(strokeWidth))
            {
                if (pen == null)
                {
                    pen = new Pen();
                }
                pen.Width = ReadNumber(strokeWidth);
            }

            var strokeOpacity = GetString(style, "stroke-opacity");

            if (!string.IsNullOrWhiteSpace(strokeOpacity))
            {
                if (pen == null)
                {
                    pen = new Pen();
                }
                pen.Color = pen.Color.WithAlpha(ReadNumber(strokeOpacity));
            }

            var strokeLineCap = GetString(style, "stroke-linecap");

            if (!string.IsNullOrWhiteSpace(strokeLineCap))
            {
                if (pen == null)
                {
                    pen = new Pen();
                }
                strokeLineCap = strokeLineCap.ToLower();
                switch (strokeLineCap)
                {
                case "butt":
                    pen.Cap = LineCaps.Butt;
                    break;

                case "square":
                    pen.Cap = LineCaps.Square;
                    break;

                case "round":
                    pen.Cap = LineCaps.Round;
                    break;
                }
            }
            var strokeLineJoin = GetString(style, "stroke-linejoin");

            if (!string.IsNullOrWhiteSpace(strokeLineJoin))
            {
                if (pen == null)
                {
                    pen = new Pen();
                }
                strokeLineJoin = strokeLineJoin.ToLower();
                switch (strokeLineJoin)
                {
                case "bevel":
                    throw new NotSupportedException();

                case "miter":
                    pen.Join = LineJoin.Miter;
                    break;

                case "round":
                    pen.Join = LineJoin.Round;
                    break;
                }
            }

            var strokeMiterLimit = GetString(style, "stroke-miterlimit");

            if (!string.IsNullOrWhiteSpace(strokeLineJoin))
            {
                if (pen == null)
                {
                    pen = new Pen();
                }
                pen.MiterLimit = ReadNumber(strokeMiterLimit);
            }
            //
            // Pen
            //
            var stroke = GetString(style, "stroke").Trim();

            if (string.IsNullOrEmpty(stroke))
            {
                // No change
                hasPen = false;
            }
            else if (stroke.Equals("none", StringComparison.OrdinalIgnoreCase))
            {
                hasPen = true;
                pen    = null;
            }
            else
            {
                hasPen = true;
                if (pen == null)
                {
                    pen = new Pen();
                }
                Color color;
                if (Colors.TryParse(stroke, out color))
                {
                    if (pen.Color.Alpha == 1)
                    {
                        pen.Color = color;
                    }
                    else
                    {
                        pen.Color = color.WithAlpha(pen.Color.Alpha);
                    }
                }
            }

            //
            // Brush attributes
            //
            var fillOpacity = GetString(style, "fill-opacity");

            if (!string.IsNullOrWhiteSpace(fillOpacity))
            {
                if (brush == null)
                {
                    brush = new SolidBrush();
                }
                var sb = brush as SolidBrush;
                if (sb != null)
                {
                    sb.Color = sb.Color.WithAlpha(ReadNumber(fillOpacity));
                }
            }
            var fillMode = GetString(style, "fill-rule");

            if (!string.IsNullOrWhiteSpace(fillMode))
            {
                if (brush == null)
                {
                    brush = new SolidBrush();
                }
                var sb = brush as SolidBrush;
                if (sb != null)
                {
                    switch (fillMode)
                    {
                    case "evenodd":
                        brush.FillMode = FillMode.EvenOdd;
                        break;

                    case "nonzero":
                        brush.FillMode = FillMode.NonZero;
                        break;
                    }
                }
            }

            //
            // Brush
            //
            var fill = GetString(style, "fill").Trim();

            if (string.IsNullOrEmpty(fill))
            {
                // No change
                hasBrush = false;
            }
            else if (fill.Equals("none", StringComparison.OrdinalIgnoreCase))
            {
                hasBrush = true;
                brush    = null;
            }
            else
            {
                hasBrush = true;
                Color color;
                if (Colors.TryParse(fill, out color))
                {
                    var sb = brush as SolidBrush;
                    if (sb == null)
                    {
                        brush = new SolidBrush(color);
                    }
                    else
                    {
                        if (sb.Color.Alpha == 1)
                        {
                            sb.Color = color;
                        }
                        else
                        {
                            sb.Color = color.WithAlpha(sb.Color.Alpha);
                        }
                    }
                }
                else
                {
                    var urlM = fillUrlRe.Match(fill);
                    if (urlM.Success)
                    {
                        var id = urlM.Groups[1].Value.Trim();
                        brush = GetGradientBrush(id, null);
                    }
                    else
                    {
                        throw new NotSupportedException("Fill " + fill);
                    }
                }
            }
        }
示例#6
0
 public override void Draw(ICanvas canvas, Rect rect)
 {
     // base.Draw(canvas, rect);
     canvas.DrawLine(rect.Left, rect.Top, rect.Width, rect.Top, _custLineColour, 3);
     canvas.DrawLine(rect.Left, rect.Height, rect.Width, rect.Height, _custLineColour, 3);
     var font = new Font {Size = 20};
     var pen = new Pen(Colors.Blue, width: 10);
     var brush = new SolidBrush(Colors.White);
     canvas.DrawRectangle(new Point(20, 20), new Size(20), pen, brush);
     //canvas.DrawText("B", rect, font, TextAlignment.Center, pen);
 }
示例#7
0
        void ApplyStyle(Dictionary <string, string> style, ref Pen pen, out bool hasPen, ref Brush brush, out bool hasBrush)
        {
            //
            // Pen attributes
            //
            var strokeWidth = GetString(style, "stroke-width");

            if (!string.IsNullOrWhiteSpace(strokeWidth))
            {
                if (pen == null)
                {
                    pen = new Pen();
                }
                pen.Width = ReadNumber(strokeWidth);
            }

            var strokeOpacity = GetString(style, "stroke-opacity");

            if (string.IsNullOrWhiteSpace(strokeOpacity))
            {
                strokeOpacity = GetString(style, "opacity");
            }

            if (!string.IsNullOrWhiteSpace(strokeOpacity))
            {
                if (pen == null)
                {
                    pen = new Pen();
                }
                pen.Color = pen.Color.WithAlpha(ReadNumber(strokeOpacity));
            }

            //
            // Pen
            //
            var stroke = GetString(style, "stroke").Trim();

            if (string.IsNullOrEmpty(stroke))
            {
                // No change
                hasPen = false;
            }
            else if (stroke.Equals("none", StringComparison.OrdinalIgnoreCase))
            {
                hasPen = true;
                pen    = null;
            }
            else
            {
                hasPen = true;
                if (pen == null)
                {
                    pen = new Pen();
                }
                Color color;
                if (Colors.TryParse(stroke, out color))
                {
                    if (pen.Color.Alpha == 1)
                    {
                        pen.Color = color;
                    }
                    else
                    {
                        pen.Color = color.WithAlpha(pen.Color.Alpha);
                    }
                }
            }

            //
            // Brush attributes
            //
            var fillOpacity = GetString(style, "fill-opacity");

            if (string.IsNullOrWhiteSpace(fillOpacity))
            {
                fillOpacity = GetString(style, "opacity");
            }

            if (!string.IsNullOrWhiteSpace(fillOpacity))
            {
                if (brush == null)
                {
                    brush = new SolidBrush();
                }
                var sb = brush as SolidBrush;
                if (sb != null)
                {
                    sb.Color = sb.Color.WithAlpha(ReadNumber(fillOpacity));
                }
            }

            //
            // Brush
            //
            var fill = GetString(style, "fill").Trim();

            if (string.IsNullOrEmpty(fill))
            {
                // No change
                hasBrush = false;
            }
            else if (fill.Equals("none", StringComparison.OrdinalIgnoreCase))
            {
                hasBrush = true;
                brush    = null;
            }
            else
            {
                hasBrush = true;
                Color color;
                if (Colors.TryParse(fill, out color))
                {
                    var sb = brush as SolidBrush;
                    if (sb == null)
                    {
                        brush = new SolidBrush(color);
                    }
                    else
                    {
                        if (sb.Color.Alpha == 1)
                        {
                            sb.Color = color;
                        }
                        else
                        {
                            sb.Color = color.WithAlpha(sb.Color.Alpha);
                        }
                    }
                }
                else
                {
                    var urlM = fillUrlRe.Match(fill);
                    if (urlM.Success)
                    {
                        var id = urlM.Groups [1].Value.Trim();
                        brush = GetGradientBrush(id, null);
                    }
                    else
                    {
                        throw new NotSupportedException("Fill " + fill);
                    }
                }
            }
        }