예제 #1
0
        private void PaintLandScapeBackground(SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();
            using (SKPath path = new SKPath())
            {
                path.MoveTo(0, 0);
                path.LineTo(info.Width * 0.57f, 0);

                path.CubicTo(info.Width * 0.54f, info.Height * 0.14f,
                             info.Width * 0.46f, info.Height * 0.24f,
                             info.Width * 0.46f, info.Height * 0.45f);
                path.CubicTo(info.Width * 0.46f, info.Height * 0.68f,
                             info.Width * 0.57f, info.Height * 0.83f,
                             info.Width * 0.6f, info.Height);
                path.LineTo(0, info.Height);
                path.Close();


                using (SKPaint paint = new SKPaint())
                {
                    paint.IsAntialias = true;
                    paint.Style       = SKPaintStyle.Fill;
                    paint.Color       = SKColor.Parse("#9b1d75");

                    paint.Shader = SKShader.CreateLinearGradient(
                        new SKPoint(info.Width * 0.6f, info.Height),
                        new SKPoint(0, 0),
                        new SKColor[] { Color.FromHex("#511694").ToSKColor(), Color.FromHex("#9b1d75").ToSKColor() },
                        new float[] { 0.18f, 1 },
                        SKShaderTileMode.Clamp);

                    canvas.DrawPath(path, paint);
                }
            }
        }
예제 #2
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();
            using (SKPaint paint = new SKPaint())
            {
                SKColor SpideyBlueBckGrnd;
                SKColor.TryParse("#020f1f", out SpideyBlueBckGrnd);
                SKColor SpideyLightBlueBckGrnd;
                SKColor.TryParse("#001c41", out SpideyLightBlueBckGrnd);
                paint.Shader = SKShader.CreateLinearGradient(
                    new SKPoint(info.Rect.Top, info.Rect.Top),
                    new SKPoint(info.Rect.Bottom, info.Rect.Bottom),
                    new SKColor[] { SpideyBlueBckGrnd, SpideyLightBlueBckGrnd },
                    new float[] { 0, 0.60f },
                    SKShaderTileMode.Mirror);
                canvas.DrawRect(info.Rect, paint);
            }
        }
예제 #3
0
        private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e2)
        {
            var e = new SkiaGraphics(e2.Surface);

            e2.Surface.Canvas.Clear();
            int y = 0;
            {
                Size extent = e.MeasureString(desc, this.Font).ToSize();

                var mid = extent.Width / 2;

                e.DrawString(desc, this.Font, new SolidBrush(this.ForeColor), this.Width / 2 - mid, 0);

                y = extent.Height;
            }
            //
            {
                var numb = number.ToString(numberformat);

                Size extent = e.MeasureString("0".PadLeft(numb.Length + 1, '0'), new Font(this.Font.FontFamily, (float)newSize, this.Font.Style)).ToSize();

                float hRatio = (this.Height - y) / (float)(extent.Height);
                float wRatio = this.Width / (float)extent.Width;
                float ratio  = (hRatio < wRatio) ? hRatio : wRatio;

                newSize = (newSize * ratio);// * 0.75f; // pixel to points

                newSize -= newSize % 5;

                if (newSize < 8 || newSize > 999999)
                {
                    newSize = 8;
                }

                extent = e.MeasureString(numb, new Font(this.Font.FontFamily, (float)newSize, this.Font.Style)).ToSize();

                e.DrawString(numb, new Font(this.Font.FontFamily, (float)newSize, this.Font.Style), new SolidBrush(this.numberColor), this.Width / 2 - extent.Width / 2, y + ((this.Height - y) / 2 - extent.Height / 2));
            }
        }
예제 #4
0
        private void SKCanvasView_PaintSurface_1(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            using (SKPaint paint = new SKPaint())
            {
                SKRect rect = new SKRect(0, 0, info.Width, info.Height);

                paint.Shader = SKShader.CreateLinearGradient(
                    new SKPoint(0, info.Height / 2),
                    new SKPoint(info.Width, info.Height / 2),
                    new SKColor[] { Color.FromHex("#9b1d75").ToSKColor(), Color.FromHex("#511694").ToSKColor() },
                    new float[] { 0.15f, 1 },
                    SKShaderTileMode.Clamp);

                canvas.DrawRect(rect, paint);
            }
        }
예제 #5
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            // Find largest size rectangle in canvas
            float scale = Math.Min((float)info.Width / bitmap.Width,
                                   (float)info.Height / bitmap.Height);
            SKRect rect = SKRect.Create(scale * bitmap.Width, scale * bitmap.Height);
            float  x    = (info.Width - rect.Width) / 2;
            float  y    = (info.Height - rect.Height) / 2;

            rect.Offset(x, y);

            // Display bitmap
            canvas.DrawBitmap(bitmap, rect);

            // Display gray rectangle with blend mode
            using (SKPaint paint = new SKPaint())
            {
                if ((SKCanvasView)sender == dodgeCanvasView)
                {
                    byte value = (byte)(255 * dodgeSlider.Value);
                    paint.Color     = new SKColor(value, value, value);
                    paint.BlendMode = SKBlendMode.ColorDodge;
                }
                else
                {
                    byte value = (byte)(255 * (1 - burnSlider.Value));
                    paint.Color     = new SKColor(value, value, value);
                    paint.BlendMode = SKBlendMode.ColorBurn;
                }

                canvas.DrawRect(rect, paint);
            }
        }
예제 #6
0
        private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            SKColor[] colors     = new SKColor[] { StartColor.ToSKColor(), EndColor.ToSKColor() };
            var       startPoint = new SKPoint(0, 0);
            SKPoint   endPoint   = Horizontal ? new SKPoint(info.Width, 0) : new SKPoint(0, info.Height);

            SKShader shader = SKShader.CreateLinearGradient(startPoint, endPoint, colors, null, SKShaderTileMode.Clamp);

            var paint = new SKPaint
            {
                Style  = SKPaintStyle.Fill,
                Shader = shader
            };

            canvas.DrawRect(new SKRect(0, 0, info.Width, info.Height), paint);
        }
        private void CanvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            SKImageInfo imageInfo = e.Info;
            SKSurface   surface   = e.Surface;
            SKCanvas    canvas    = surface.Canvas;

            canvas.Clear();

            SKPaint paint = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                Color       = Color.Red.ToSKColor(),
                StrokeWidth = 25,
                IsAntialias = true
            };

            canvas.DrawCircle(imageInfo.Width / 2, imageInfo.Height / 2, 100, paint);

            paint.Color = Color.Blue.ToSKColor();
            paint.Style = SKPaintStyle.StrokeAndFill;
            canvas.DrawCircle(imageInfo.Width / 2, imageInfo.Height / 2, 75, paint);
        }
 private void PaintSurface(object sender, SKPaintSurfaceEventArgs e)
 {
     e.Surface.Canvas.Clear();
     if (sender == Monday)
     {
         var addDayese = ((int)DayOfWeek.Monday - (int)DateTime.Now.DayOfWeek + 7) % 7;
         page.DrawDay(e.Surface.Canvas, e.Info.Width, e.Info.Height, DateTime.Now.AddDays(addDayese));
     }
     else if (sender == Tuesday)
     {
         var addDayese = ((int)DayOfWeek.Tuesday - (int)DateTime.Now.DayOfWeek + 7) % 7;
         page.DrawDay(e.Surface.Canvas, e.Info.Width, e.Info.Height, DateTime.Now.AddDays(addDayese));
     }
     else if (sender == Wednesday)
     {
         var addDayese = ((int)DayOfWeek.Wednesday - (int)DateTime.Now.DayOfWeek + 7) % 7;
         page.DrawDay(e.Surface.Canvas, e.Info.Width, e.Info.Height, DateTime.Now.AddDays(addDayese));
     }
     else if (sender == Thursday)
     {
         var addDayese = ((int)DayOfWeek.Thursday - (int)DateTime.Now.DayOfWeek + 7) % 7;
         page.DrawDay(e.Surface.Canvas, e.Info.Width, e.Info.Height, DateTime.Now.AddDays(addDayese));
     }
     else if (sender == Friday)
     {
         var addDayese = ((int)DayOfWeek.Friday - (int)DateTime.Now.DayOfWeek + 7) % 7;
         page.DrawDay(e.Surface.Canvas, e.Info.Width, e.Info.Height, DateTime.Now.AddDays(addDayese));
     }
     else if (sender == Saturday)
     {
         var addDayese = ((int)DayOfWeek.Saturday - (int)DateTime.Now.DayOfWeek + 7) % 7;
         page.DrawDay(e.Surface.Canvas, e.Info.Width, e.Info.Height, DateTime.Now.AddDays(addDayese));
     }
     else if (sender == Sunday)
     {
         var addDayese = ((int)DayOfWeek.Sunday - (int)DateTime.Now.DayOfWeek + 7) % 7;
         page.DrawDay(e.Surface.Canvas, e.Info.Width, e.Info.Height, DateTime.Now.AddDays(addDayese));
     }
 }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            SKColor[]        colors   = { SKColors.Red, SKColors.Green, SKColors.Blue };
            SKShaderTileMode tileMode =
                (SKShaderTileMode)(tileModePicker.SelectedIndex == -1 ?
                                   0 : tileModePicker.SelectedItem);

            using (SKPaint paint = new SKPaint())
            {
                paint.Shader = SKShader.CreateTwoPointConicalGradient(touchPoints[0].Center,
                                                                      RADIUS1,
                                                                      touchPoints[1].Center,
                                                                      RADIUS2,
                                                                      colors,
                                                                      null,
                                                                      tileMode);
                canvas.DrawRect(info.Rect, paint);
            }

            // Display the touch points here rather than by TouchPoint
            using (SKPaint paint = new SKPaint())
            {
                paint.Style       = SKPaintStyle.Stroke;
                paint.Color       = SKColors.Black;
                paint.StrokeWidth = 3;

                foreach (TouchPoint touchPoint in touchPoints)
                {
                    canvas.DrawCircle(touchPoint.Center, touchPoint.Radius, paint);
                }
            }
        }
예제 #10
0
        public void ContainerCanvasRendered(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            //resizing from dpi to pixels
            float xRatio = SkiaConverters.Dip2PixRatioX(info.Size, ContainerCanvas);
            float yRatio = SkiaConverters.Dip2PixRatioY(info.Size, ContainerCanvas);

            if (this.Points == null)
            {
                this.Points = new SKPoint[]
                {
                    new SKPoint(sizeX * 0.3f * xRatio, sizeY * 0.5f * yRatio), //left of cross
                    new SKPoint(sizeX * 0.5f * xRatio, sizeY * 0.7f * yRatio), //bottom ..
                    new SKPoint(sizeX * 0.7f * xRatio, sizeY * 0.5f * yRatio), //right ..
                    new SKPoint(sizeX * 0.5f * xRatio, sizeY * 0.3f * yRatio), //top ..

                    new SKPoint(sizeX * 0.5f * xRatio, sizeY * 0.5f * yRatio)  //center of circle
                };
            }

            canvas.DrawOval(Points[4].X, Points[4].Y, sizeX * 0.5f * xRatio, sizeY * 0.5f * yRatio, this.BackgroundPaint);

            if (this.PathOfCross == null)
            {
                PathOfCross = new SKPath();
                PathOfCross.MoveTo(Points[0]);
                PathOfCross.LineTo(Points[2]);
                PathOfCross.MoveTo(Points[1]);
                PathOfCross.LineTo(Points[3]);
            }

            canvas.DrawPath(PathOfCross, this.WhiteAddSignPaint);
        }
예제 #11
0
        void PaintContents(object sender, SKPaintSurfaceEventArgs e)
        {
            var canvas = e.Surface.Canvas;

            canvas.Clear(SKColors.Transparent);
            var b = canvas.LocalClipBounds;

            if (FillColor != Color.Transparent)
            {
                using (var paint = new SKPaint
                {
                    IsAntialias = true,
                    IsStroke = false,
                    Color = FillColor.ToSKColor(),
                })
                {
                    canvas.DrawRoundRect(b, (float)CornerRadius, (float)CornerRadius, paint);
                }
            }

            if (BorderColor != Color.Transparent)
            {
                using (var paint = new SKPaint
                {
                    IsAntialias = true,
                    IsStroke = true,
                    StrokeWidth = 1.5f,
                    Color = BorderColor.ToSKColor(),
                })
                {
                    var rect = new SKRect(b.Left + paint.StrokeWidth,
                                          b.Top + paint.StrokeWidth,
                                          b.Right - paint.StrokeWidth,
                                          b.Bottom - paint.StrokeWidth);
                    canvas.DrawRoundRect(rect, (float)CornerRadius, (float)CornerRadius, paint);
                }
            }
        }
예제 #12
0
        private void SKCanvasView_OnPaintSurfacew_OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            var model = (PiecePieChart)BindingContext;

            var info    = e.Info;
            var surface = e.Surface;
            var canvas  = surface.Canvas;

            canvas.Clear();

            var dateTextPaint = new SKPaint
            {
                Color = Color.FromHex("#020203")
                        .ToSKColor(),
                TextSize    = 35,
                StrokeWidth = 100
            };

            canvas.DrawCircle(info.Width - 60, info.Height / 2f - 10, 20, new SKPaint
            {
                Style = SKPaintStyle.Fill,
                Color = model.Color.ToSKColor()
            });
            canvas.DrawCircle(info.Width - 60, info.Height / 2f - 10, 10, new SKPaint
            {
                Style = SKPaintStyle.Fill,
                Color = Color.White.ToSKColor()
            });

            canvas.DrawText(model.Name, 15, info.Height / 2f, dateTextPaint);
            canvas.DrawText($"{model.Percent}%", info.Width - dateTextPaint.StrokeWidth - 100, info.Height / 2f, dateTextPaint);
            canvas.DrawLine(0, info.Height, info.Width, info.Height, new SKPaint
            {
                Style       = SKPaintStyle.Fill,
                Color       = Color.FromHex("#838390").ToSKColor(),
                StrokeWidth = 2
            });
        }
예제 #13
0
        private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            if (_rendering)
            {
                System.Diagnostics.Debug.WriteLine("Canvas is being already rendered");
                return;
            }

            if (ViewModel is null)
            {
                System.Diagnostics.Debug.WriteLine("View model is null from OnCanvasViewPaintSurface");
                return;
            }

            System.Diagnostics.Debug.WriteLine("Invalidate was called");
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            float radius = Math.Min(info.Width / 2.5f, info.Height / 2.5f);
            float yPoint = info.Height / 2f;

            var center = new SKPoint(info.Width / 2f, yPoint);
            var rect   = new SKRect(center.X - radius, center.Y - radius,
                                    center.X + radius, center.Y + radius);

            try
            {
                System.Diagnostics.Debug.WriteLine($"--------------Rendering the timer started. Timer = {ViewModel.Name}");
                DrawIntervals(canvas, rect);
                System.Diagnostics.Debug.WriteLine($"--------------Rendering the timer completed. Timer = {ViewModel.Name}");
            }
            catch (Exception e)
            {
                System.Diagnostics.Debug.WriteLine(e.Message);
                throw;
            }
        }
예제 #14
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs args)
        {
            base.OnPaintSurface(args);

            var info    = args.Info;
            var surface = args.Surface;
            var canvas  = surface.Canvas;

            canvas.Clear();

            if (_cornerIsDirty)
            {
                var scaledCornerRadius = CornerRadius / 100f * Math.Min(info.Height, info.Width);
                CornerSize     = new SKSize(scaledCornerRadius, scaledCornerRadius);
                _cornerIsDirty = false;
            }

            switch (Style)
            {
            case MessageBubbleStyle.Default:
                DrawDefault(info, canvas);
                break;

            case MessageBubbleStyle.Shrunk:
                DrawShrunk(info, canvas);
                break;

            case MessageBubbleStyle.Circle:
                DrawCircle(info, canvas);
                break;

            default:
                DrawDefault(info, canvas);
                break;
            }

            canvas.Flush();
        }
예제 #15
0
        //METHODS
        // do the drawing
        void PaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            info = e.Info;
            //canvas object
            SKSurface surface = e.Surface;

            canvas = surface.Canvas;

            //Important! Otherwise the drawing will look messed up in iOS
            if (canvas != null)
            {
                canvas.Clear();
            }

            //calculate some stuff and make the paint
            CalculateNeededNumbers();
            CalculateNeededVariables();
            MakeSKPaint(); //depends on xe and ye and therfore has to be called after they were initialized

            /*********************HERE GOES THE DRAWING************************/
            DrawBackground(canvas);
            DrawTable();

            //draw Network
            DrawConnections();
            DrawRouters();
            DrawWeights();

            DrawTableContents();
            if (currentStep == maxStep)
            {
                DrawForwardingTable();
            }


            //execute all drawing actions
            canvas.Flush();
        }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            using (SKPaint strokePaint = new SKPaint
            {
                Style = SKPaintStyle.Stroke,
                Color = SKColors.Red,
                StrokeWidth = 3,
                PathEffect = SKPathEffect.CreateDash(new float[] { 7, 7 }, 0)
            })
                using (SKPaint textPaint = new SKPaint
                {
                    Style = SKPaintStyle.Fill,
                    Color = SKColors.Blue,
                    TextSize = 50
                })
                {
                    SKRect textBounds = new SKRect();
                    textPaint.MeasureText(Title, ref textBounds);
                    float margin = (info.Width - textBounds.Width) / 2;

                    float sx = (float)xScaleSlider.Value;
                    float sy = (float)yScaleSlider.Value;
                    float px = margin + textBounds.Width / 2;
                    float py = margin + textBounds.Height / 2;

                    canvas.Scale(sx, sy, px, py);

                    SKRect borderRect = SKRect.Create(new SKPoint(margin, margin), textBounds.Size);
                    canvas.DrawRoundRect(borderRect, 20, 20, strokePaint);
                    canvas.DrawText(Title, margin, -textBounds.Top + margin, textPaint);
                }
        }
예제 #17
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            SKRect rect = new SKRect(50, 50, info.Width - 50, info.Width - 50);

            canvas.DrawOval(rect, outlinePaint);

            using (SKPath path = new SKPath())
            {
                path.AddArc(rect, startAngle, endAngle);
                SKPaint arcPaint;
                if (endAngle <= 45)
                {
                    arcPaint = arcPaintGreen;
                }
                else if (endAngle >= 315)
                {
                    arcPaint = arcPaintRed;
                }
                else
                {
                    arcPaint = arcPaintYellow;
                }

                canvas.DrawPath(path, arcPaint);
            }

            //var v = new Models.Voucher() { Token = "abc" };
            //v.AtualizarQrCode(new System.TimeSpan());

            //var image = SKImage.FromBitmap(SKBitmap.Decode(v.QrCodeStream));
            //canvas.DrawImage(image, 50, 100);
        }
예제 #18
0
        private void SkCanvas_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            SKSurface surface;
            SKCanvas  canvas;

            surface = e.Surface;
            canvas  = surface.Canvas;

            canvas.Clear(SKColors.SandyBrown); // 바탕색

            SKPaint pathStroke = new SKPaint   // 선 정의
            {
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                Color       = SKColors.Black,
                StrokeWidth = 5
            };
            SKPath path = new SKPath();

            var mainDisplayInfo = DeviceDisplay.MainDisplayInfo;

            for (int x = 0; x < mainDisplayInfo.Width; x += (int)mainDisplayInfo.Width / 10)
            {
                path.MoveTo(x, 0);
                path.LineTo(x, (float)mainDisplayInfo.Height);
            }
            for (int y = 0; y < mainDisplayInfo.Height; y += (int)mainDisplayInfo.Width / 10)
            {
                path.MoveTo(0, y);
                path.LineTo((float)mainDisplayInfo.Width, y);
            }
            canvas.DrawPath(path, pathStroke);

            foreach (SKPoint point in completedCircles)
            {
                canvas.DrawCircle(point, 25, paintCircle);
            }
        }
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            float z             = (float)zSlider.Value;
            float surfaceScale  = (float)surfaceScaleSlider.Value;
            float lightConstant = (float)lightConstantSlider.Value;

            using (SKPaint paint = new SKPaint())
            {
                paint.IsAntialias = true;

                // Size text to 90% of canvas width
                paint.TextSize = 100;
                float textWidth = paint.MeasureText(TEXT);
                paint.TextSize *= 0.9f * info.Width / textWidth;

                // Find coordinates to center text
                SKRect textBounds = new SKRect();
                paint.MeasureText(TEXT, ref textBounds);

                float xText = info.Rect.MidX - textBounds.MidX;
                float yText = info.Rect.MidY - textBounds.MidY;

                // Create distant light image filter
                paint.ImageFilter = SKImageFilter.CreateDistantLitDiffuse(
                    new SKPoint3(2, 3, z),
                    SKColors.White,
                    surfaceScale,
                    lightConstant);

                canvas.DrawText(TEXT, xText, yText, paint);
            }
        }
예제 #20
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            string text = Text;

            // Create an SKPaint object to display the text
            SKPaint textPaint = new SKPaint
            {
                //Style = SKPaintStyle.Stroke,
                //StrokeWidth = 1,
                FakeBoldText = Bold,
                Color        = TextColor.ToSKColor()
            };



            // Adjust TextSize property so text is 95% of screen width
            float textWidth = textPaint.MeasureText(text);

            textPaint.TextSize = 0.95f * info.Width * textPaint.TextSize / textWidth;

            // Find the text bounds
            SKRect textBounds = new SKRect();

            textPaint.MeasureText(text, ref textBounds);

            // Calculate offsets to center the text on the screen
            float xText = info.Width / 2 - textBounds.MidX;
            float yText = info.Height / 2 - textBounds.MidY;

            // And draw the text
            canvas.DrawText(text, xText, yText, textPaint);
        }
예제 #21
0
        private void PaintSurface(SKPaintSurfaceEventArgs e)
        {
            var canvas = e.Surface.Canvas;

            canvas.Clear(SKColors.Crimson);
            var canvasSize = e.Info.Rect;

            var path = SKPath.ParseSvgPathData("M 926 878 c -46 -79 -113 -137 -186 -163 c -24 -8 -45 -14 -47 -12 c -2 2 5 24 16 48 c 10 24 21 59 25 77 l 6 33 l -38 -30 c -73 -59 -124 -74 -277 -82 c -88 -4 -156 -12 -183 -22 c -165 -62 -267 -249 -232 -423 c 44 -214 218 -328 453 -296 c 95 14 223 71 272 122 l 30 31 l -45 -25 c -85 -47 -185 -70 -300 -71 c -95 0 -111 3 -166 28 c -114 53 -176 143 -182 264 c -5 97 16 158 79 227 c 66 73 130 101 229 100 c 66 0 83 -4 138 -34 c 105 -56 165 -154 166 -270 c 1 -75 -22 -118 -74 -140 c -35 -15 -98 -1 -120 25 c -11 13 -16 12 -42 -10 c -63 -53 -178 -24 -218 56 c -25 47 -25 82 -1 135 c 28 63 71 84 168 84 c 110 0 116 -5 122 -119 c 6 -94 14 -110 53 -111 c 31 0 48 29 48 83 c -1 177 -194 291 -351 209 c -143 -75 -180 -250 -77 -367 c 59 -67 106 -88 208 -93 c 291 -14 551 199 592 485 c 14 94 2 198 -30 259 l -18 34 l -18 -32 Z");

            var pathSize = path.Bounds;

            canvas.Translate(canvasSize.MidX, canvasSize.MidY);
            var shortSideRatio = Math.Min(canvasSize.Width / pathSize.Width, canvasSize.Height / pathSize.Width);

            canvas.Scale(0.7f * shortSideRatio);
            canvas.RotateDegrees(rotation);
            canvas.Translate(-pathSize.MidX, -pathSize.MidY);

            canvas.Scale(-1);

            var paint = new SKPaint
            {
                Color = SKColors.Purple,
                Style = SKPaintStyle.Fill,
            };

            var matrix = SKMatrix.Identity;

            matrix.ScaleX = -1;
            matrix.TransY = -canvasSize.Height * 1.5f;
            path.Transform(matrix);
            canvas.DrawPath(path, paint);

            path = SKPath.ParseSvgPathData("M 317 459 c -11 -6 -25 -26 -33 -45 c -38 -91 78 -165 146 -92 c 16 17 20 35 20 85 l 0 63 l -57 0 c -32 0 -66 -5 -76 -11 Z");
            path.Transform(matrix);

            canvas.DrawPath(path, paint);
        }
예제 #22
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs eventArgs)
        {
            var givenCanvas = eventArgs.Surface.Canvas;

            givenCanvas.Clear();

            canvasWidth  = eventArgs.Info.Width;
            canvasHeight = eventArgs.Info.Height;

            SKColor colorBackground = this.chatMessageSender ? this.colorBackgroundSender : this.colorBackgroundClient;

            SKRect rectBackground = new SKRect(
                0,
                0,
                this.canvasWidth,
                this.canvasHeight
                );

            SKRoundRect roundRectBackground = new SKRoundRect(
                rectBackground,
                0,
                0
                );

            roundRectBackground.SetRectRadii(
                rectBackground,
                this.getRadiusPoints()
                );

            SKPaint paintBackground = new SKPaint()
            {
                Color       = colorBackground,
                Style       = SKPaintStyle.Fill,
                IsAntialias = true
            };

            givenCanvas.DrawRoundRect(roundRectBackground, paintBackground);
        }
예제 #23
0
        protected override void DrawCanvas(object sender, SKPaintSurfaceEventArgs e)
        {
            var info   = e.Info;
            var canvas = e.Surface.Canvas;

            canvas.Clear();
            foreach (var l in Layer_Manager.Layers)

            {
                var bmp = l.GetBitmap;

                //l.Canvas.SCanvas.DrawBitmapNinePatch()
                var rect = new SKRect(0, 0, info.Width, info.Height);

                canvas.DrawBitmap(l.GetBitmap, new SKRect(0, 0, l.GetBitmap.Width, l.GetBitmap.Height));
                if (Layer_Manager.IsActive(l))
                {
                    var temp     = Layer_Manager.TempLayer.GetBitmap;
                    var temprect = new SKRect(0, 0, temp.Width, temp.Height);
                    canvas.DrawBitmap(temp, temprect);
                }
            }
        }
예제 #24
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            using (SKPaint paint = new SKPaint())
            {
                paint.Color = SKColors.Red;

                using (SKPathEffect pathEffect =
                           SKPathEffect.Create2DPath(SKMatrix.MakeScale(64, 64), tilePath))
                {
                    paint.PathEffect = pathEffect;

                    canvas.DrawRoundRect(
                        new SKRect(50, 50, info.Width - 50, info.Height - 50),
                        100, 100, paint);
                }
            }
        }
예제 #25
0
        private void OnPaintBackground(object sender, SKPaintSurfaceEventArgs e)
        {
            var scale     = e.Info.Width / (float)((View)sender).Width;
            var blockSize = BaseBlockSize * scale;

            var offsetMatrix = SKMatrix.CreateScale(2 * blockSize, blockSize);
            var skewMatrix   = SKMatrix.CreateSkew(0.5f, 0);
            var matrix       = offsetMatrix.PreConcat(skewMatrix);

            using var path = new SKPath();
            path.AddRect(SKRect.Create(blockSize / -2, blockSize / -2, blockSize, blockSize));

            using var paint = new SKPaint
                  {
                      PathEffect = SKPathEffect.Create2DPath(matrix, path),
                      Color      = 0xFFF0F0F0
                  };

            var canvas = e.Surface.Canvas;
            var area   = SKRect.Create(e.Info.Width + blockSize, e.Info.Height + blockSize);

            canvas.DrawRect(area, paint);
        }
예제 #26
0
        private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            var skiaDrawingSurface = new SkiaDrawingSurface(surface.Canvas);

            var   diagramRequiredWidth = scaleDiagramRenderer.GetDiagramWidth();
            var   canvasWidth          = info.Width;
            float scaleFactor          = (float)canvasWidth / (float)diagramRequiredWidth;

            if (scaleFactor < 2)
            {
                scaleFactor = 2;
            }

            skiaDrawingSurface.SetScale((float)scaleFactor);

            canvas.Clear();

            scaleDiagramRenderer.Render(skiaDrawingSurface);
        }
예제 #27
0
        private void DrawGraph(SKCanvas canvas, SKPaintSurfaceEventArgs e)
        {
            // Draw the rectangle that will contain the graph Grid
            canvas.DrawRect(0, 0, 2000, 180, graphLinePaint);

            // Draw vertical grid lines and label them at certain intervals
            // Here I just divided the height and width evenly to draw some lines. We can come up with a formula for line spacings
            for (int i = 50; i < 2000; i += 50)
            {
                canvas.DrawLine(i, 0, i, 180, graphLinePaint);

                if (i % 200 == 0)
                {
                    canvas.DrawText($"{i/50}", x: i, y: 190, graphIntervalsPaint);
                }
            }

            // draw horizontal grid lines
            for (int i = 18; i < 180; i += 18)
            {
                canvas.DrawLine(0, i, 2000, i, graphLinePaint);
            }
        }
예제 #28
0
        private void TrendView8(object sender, SKPaintSurfaceEventArgs e)
        {
            SKSurface surface = e.Surface;
            SKCanvas  canvas  = surface.Canvas;

            DrawGraph(canvas, e);

            // draw trend line
            trendLinePaint.Color = SKColors.Red;
            canvas.DrawPoints(SKPointMode.Lines, _SKPointsVS8.ToArray(), trendLinePaint);
            foreach (SKPoint point in _SKPointsVS8)
            {
                dataPointPaint.Style = SKPaintStyle.Stroke;
                dataPointPaint.Color = SKColors.Red;
                canvas.DrawCircle(point, 6, dataPointPaint);
                dataPointPaint.Style = SKPaintStyle.Fill;
                dataPointPaint.Color = SKColors.White;
                canvas.DrawCircle(point, 6, dataPointPaint);
            }

            // Draw box for latest values?
            // canvas.DrawRect(2000,0,180, 180, dataPointPaint);
        }
예제 #29
0
        private void TrendView2(object sender, SKPaintSurfaceEventArgs e)
        {
            SKSurface surface = e.Surface;
            SKCanvas  canvas  = surface.Canvas;

            DrawGraph(canvas, e);

            // draw trend line
            trendLinePaint.Color = SKColors.Green;
            canvas.DrawPoints(SKPointMode.Lines, _SKPointsVS2.ToArray(), trendLinePaint);
            foreach (SKPoint point in _SKPointsVS2)
            {
                dataPointPaint.Style = SKPaintStyle.Stroke;
                dataPointPaint.Color = SKColors.Green;
                canvas.DrawCircle(point, 6, dataPointPaint);
                dataPointPaint.Style = SKPaintStyle.Fill;
                dataPointPaint.Color = SKColors.White;
                canvas.DrawCircle(point, 6, dataPointPaint);

                dataTextPaint.Color = SKColors.Green;
                canvas.DrawText($"{180 - point.Y}", point.X, point.Y - 8, dataTextPaint);
            }
        }
예제 #30
0
        private async void OnPaintCanvas(object sender, SKPaintSurfaceEventArgs e)
        {
            if (this.Percentage > 0)
            {
                if (this._currentValue <= Percentage)
                {
                    ((ChartView)sender).Chart = CreateChart(_currentValue, Height);
                    _currentValue            += Speed;
                }
                else
                {
                    ((ChartView)sender).PaintSurface -= OnPaintCanvas;
                }
            }
            else
            {
                ((ChartView)sender).Chart = CreateChart(_currentValue, Height);
            }

            await Task.Delay(TimeSpan.FromSeconds(1.0 / 30));

            ((ChartView)sender).InvalidateSurface();
        }
예제 #31
0
        private void _renderTarget_PaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            if (!_viewportInitialized) InitializeViewport();
            if (!_viewportInitialized) return; //stop if the line above failed. 
            if (!_invalid) return;

            if ((_renderer != null) && (_map != null))
            {
                if (_skiaScale == null) _skiaScale = GetSkiaScale();
                e.Surface.Canvas.Scale((float)_skiaScale.X, (float)_skiaScale.Y);
                _renderer.Render(e.Surface.Canvas, Map.Viewport, _map.Layers, _map.BackColor);
                _renderTarget.Arrange(new Rect(0, 0, Map.Viewport.Width, Map.Viewport.Height));
                _invalid = false;
            }
        }
예제 #32
0
        private void SKElementOnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            if (!_viewportInitialized) InitializeViewport();
            if (!_viewportInitialized) return; // Stop if the line above failed.
            if (!_invalid && !DeveloperTools.DeveloperMode)
                return; // In developermode always render so that fps can be counted

            if (_skiaScale == null) _skiaScale = GetSkiaScale();
            e.Surface.Canvas.Scale((float) _skiaScale.X, (float) _skiaScale.Y);
            OnPaintSurface(e.Surface.Canvas, e.Info.Width, e.Info.Height);
        }
예제 #33
0
        private void OnPaintSurface(object sender, SKPaintSurfaceEventArgs skPaintSurfaceEventArgs)
        {
            if (!_viewportInitialized) InitializeViewport();
            if (!_viewportInitialized) return;

            if (Width != _map.Viewport.Width) _map.Viewport.Width = Width;
            if (Height != _map.Viewport.Height) _map.Viewport.Height = Height;

            var scaleFactor = 2; // todo: figure out how to get this value programatically
            skPaintSurfaceEventArgs.Surface.Canvas.Scale(scaleFactor, scaleFactor);

            _renderer.Render(skPaintSurfaceEventArgs.Surface.Canvas, _map.Viewport, _map.Layers, _map.BackColor);
        }