Example #1
0
 public void DrawBacks(SKCanvas canvas, SKRect rect_Card)
 {
     canvas.DrawRoundRect(rect_Card, 6, 6, _blackPaint);
     if (MainGraphics !.IsSelected == true)
     {
         canvas.DrawRoundRect(rect_Card, 6, 6, _aquaBorder);
     }
Example #2
0
        public void DrawDice(SKCanvas dc)
        {
            if (Visible == false)
            {
                return; //just in case.
            }
            if (CanStartDrawing() == false)
            {
                return;
            }
            dc.Clear();
            SKRect rect_Card;

            rect_Card = SKRect.Create(0, 0, ActualWidthHeight, ActualWidthHeight); //i think
            dc.DrawRoundRect(rect_Card, RoundedRadius, RoundedRadius, _fillPaint);
            if (IsSelected == true)
            {
                dc.DrawRoundRect(rect_Card, RoundedRadius, RoundedRadius, _selectPaint);
            }
            dc.DrawRoundRect(rect_Card, RoundedRadius, RoundedRadius, _borderPaint);
            var     fontSize  = rect_Card.Height * .5f;
            SKPaint textPaint = MiscHelpers.GetTextPaint(SKColors.White, fontSize);

            dc.DrawBorderText(Value, EnumLayoutOptions.Center, EnumLayoutOptions.Center, textPaint, _textBorder !, rect_Card);
        }
Example #3
0
        /* Method to create the underlying empty bar for nutritional visualizations
         * Called for each base cell of each nutrient
         */
        private void DrawBaseVisual(SKPaintSurfaceEventArgs e)
        {
            SKCanvas canvas = e.Surface.Canvas;

            using (SKPaint paint = new SKPaint())
            {
                canvas.Clear(BASEBACKGROUND);

                var HORIZONTALPADDING = 30f;
                var VERTICALPADDING   = 15f;

                var width  = e.Info.Width - 2 * HORIZONTALPADDING;
                var height = e.Info.Height - 2 * VERTICALPADDING;

                // The black outline to the visualize bar
                paint.Color = Color.Black.ToSKColor();
                canvas.DrawRoundRect(new SKRoundRect(new SKRect(HORIZONTALPADDING - 19, VERTICALPADDING - 4, width + HORIZONTALPADDING + 19, height + VERTICALPADDING + 4), 15f, 15f), paint);

                // The left rounded edge of the nutrition visual
                // Starts Red to indicate that it could fill up
                SKRoundRect firstRound = new SKRoundRect(new SKRect(HORIZONTALPADDING - 15f, VERTICALPADDING, HORIZONTALPADDING + 15f, height + VERTICALPADDING), 15f, 15f);
                paint.Color = Color.Red.ToSKColor();
                canvas.DrawRoundRect(firstRound, paint);

                // The right rounded edge
                SKRoundRect secondRound = new SKRoundRect(new SKRect(width + 15f, VERTICALPADDING, width + 45f, height + VERTICALPADDING), 15f, 15f);
                paint.Color = LIGHTRED;
                canvas.DrawRoundRect(secondRound, paint);

                // Rectangle for consumed DRI 0 tp Min Threshold
                SKRect firstRect = new SKRect(HORIZONTALPADDING, VERTICALPADDING, (width / 10) + HORIZONTALPADDING, height + VERTICALPADDING);
                paint.Color = LIGHTRED;
                canvas.DrawRect(firstRect, paint);

                // Rectangle for consumed DRI from Min Threshold to half way between Min and DRI
                SKRect secRect = new SKRect((width / 10) + HORIZONTALPADDING, VERTICALPADDING, (width / 10) * 3 + HORIZONTALPADDING, height + VERTICALPADDING);
                paint.Color = LIGHTYELLOW;
                canvas.DrawRect(secRect, paint);

                // Rectangle for consumed DRI from
                // half way between low thresh and DRI to half way from DRI to max threshhold
                SKRect thirdRect = new SKRect((width / 10) * 3 + HORIZONTALPADDING, VERTICALPADDING, (width / 10) * 7 + HORIZONTALPADDING, height + VERTICALPADDING);
                paint.Color = LIGHTGREEN;
                canvas.DrawRect(thirdRect, paint);

                // Rectangle for consumed DRI from
                // halfway between DRI and max threshhold to max threshold
                SKRect fourRect = new SKRect((width / 10) * 7 + HORIZONTALPADDING, VERTICALPADDING, (width / 10) * 9 + HORIZONTALPADDING, height + VERTICALPADDING);
                paint.Color = LIGHTYELLOW;
                canvas.DrawRect(fourRect, paint);

                // Rectangle for consumed DRI from max threshold to twice the regular DRI
                SKRect fiveRect = new SKRect(((width / 10) * 9) + HORIZONTALPADDING, VERTICALPADDING, width + HORIZONTALPADDING, height + VERTICALPADDING);
                paint.Color = LIGHTRED;
                canvas.DrawRect(fiveRect, paint);
            }
        }
        public void DrawRoundRect(SKRoundRect rect, SKPaint paint)
        {
            canvas.DrawRoundRect(rect, paint);

            if (calculateBounds)
            {
                displayObject.addBoundingRect(rect.Rect);
            }
        }
Example #5
0
        public void DrawRoundRectangle(Color color, float penWidth, RectangleF rect, float rx, float ry)
        {
            skPaint.Color       = new SKColor((uint)color.Value);
            skPaint.Style       = SKPaintStyle.Stroke;
            skPaint.StrokeWidth = penWidth;
            skPaint.IsAntialias = true;
            var r = Convert(rect);

            skCanvas.DrawRoundRect(r, rx, ry, skPaint);
        }
Example #6
0
        public void DrawLoginButton(SKCanvas canvas)
        {
            // Draw Round Rectangle shape
            VeryBerryFillPaint.Shader = SKShader.CreateLinearGradient(new SKPoint(94.86246f, 11.37462f), new SKPoint(92.07168f, 69.92178f), BerryBlastColors, BerryBlastWeights, SKShaderTileMode.Clamp);
            canvas.DrawRoundRect(new SKRect(8.925781f, 9.203125f, 192.2227f, 72.65234f), 32f, 32f, VeryBerryFillPaint);
            canvas.DrawRoundRect(new SKRect(8.925781f, 9.203125f, 192.2227f, 72.65234f), 32f, 32f, VeryBerryFramePaint);

            // Draw Text shape
            canvas.DrawText("Login", 100.0859f, 48.83594f, CustomFillPaint);
        }
Example #7
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            string str = "Hello SkiaSharp!";

            // Create an SKPaint object to display the text
            SKPaint textPaint = new SKPaint
            {
                Color = SKColors.Chocolate
            };

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

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

            // Find the text bounds
            SKRect textBounds;

            textPaint.MeasureText(str, 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(str, xText, yText, textPaint);

            // Create a new SKRect object for the frame around the text
            SKRect frameRect = textBounds;

            frameRect.Offset(xText, yText);
            frameRect.Inflate(10, 10);

            // Create an SKPaint object to display the frame
            SKPaint framePaint = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = 5,
                Color       = SKColors.Blue
            };

            // Draw one frame
            canvas.DrawRoundRect(frameRect, 20, 20, framePaint);

            // Inflate the frameRect and draw another
            frameRect.Inflate(10, 10);
            framePaint.Color = SKColors.DarkBlue;
            canvas.DrawRoundRect(frameRect, 30, 30, framePaint);
        }
        public void DrawDay(SKCanvas canvas, int width, int height, List <IAvailableTime> AvailabelToDay,
                            List <IReservation <ReserveTime> > ReservatToDay, Guid GuidForOwnerResv)
        {
            var PixPrMin = height / (24 * 60f);

            Box.Color = SKColors.LightGray;
            foreach (var availableTime in AvailabelToDay)
            {
                var theDay = new DateTime(availableTime.From.Year, availableTime.From.Month, availableTime.From.Day, 0,
                                          0, 0);
                var yTop    = (float)availableTime.From.TimeOfDay.TotalMinutes * PixPrMin;
                var yBotton = (float)availableTime.To.TimeOfDay.TotalMinutes * PixPrMin;
                canvas.DrawRect(new SKRect(0, yTop, width, yBotton), Box);
                if (yBotton - yTop > 25)
                {
                    canvas.DrawText(availableTime.From.TimeOfDay.ToString("hh':'mm"), 5, yTop + 24, Text);
                }
                canvas.DrawText(availableTime.To.TimeOfDay.ToString("hh':'mm"), 5, yBotton + 24, Text);
            }

            canvas.Save();
            foreach (var resrvation in ReservatToDay)
            {
                if (resrvation.UserId.Equals(GuidForOwnerResv))
                {
                    Box.Color = SKColors.CadetBlue;
                }
                else
                {
                    Box.Color = SKColors.LightGray;
                }

                IReserveTime reserveTime = resrvation.Timeslot;
                var          yTop        = (float)reserveTime.FromDate.TimeOfDay.TotalMinutes * PixPrMin;
                var          yBottum     = (float)reserveTime.ToDate.TimeOfDay.TotalMinutes * PixPrMin;

                var Boxen = new SKRect(0, yTop, width - 1, yBottum);
                canvas.DrawRoundRect(Boxen, xRounding, yRounding, Box);
                canvas.DrawRoundRect(Boxen, xRounding, yRounding, Outlinje);
                canvas.DrawRoundRect(Boxen.Left + 1, Boxen.Top + 1, Boxen.Width - 2, Boxen.Height - 2, xRounding,
                                     yRounding, Outlinje);
                canvas.DrawRoundRect(Boxen.Left + 2, Boxen.Top + 2, Boxen.Width - 4, Boxen.Height - 4, xRounding,
                                     yRounding, Outlinje);
                if (Boxen.Height > 25)
                {
                    canvas.DrawText(reserveTime.FromDate.TimeOfDay.ToString("hh':'mm"), Boxen.Left + 5, Boxen.Top + 24,
                                    Text);
                }
                canvas.DrawText(reserveTime.ToDate.TimeOfDay.ToString("hh':'mm"), Boxen.Left + 5, Boxen.Bottom + 24,
                                Text);
            }

            canvas.Restore();
        }
Example #9
0
        public static void DrawCard(SKCanvas cv, Card c)
        {
            if (cardWhitePaint == null)
            {
                cardWhitePaint = new SKPaint
                {
                    Color    = SKColors.WhiteSmoke,
                    TextSize = 10
                };
                cardBlackPaint = new SKPaint
                {
                    Color    = SKColors.Black,
                    TextSize = 10
                };
                cardShadowPaint = new SKPaint
                {
                    Color     = SKColors.Gray,
                    BlendMode = SKBlendMode.Multiply
                };
            }
            SKPaint bgPaint, fgPaint;

            if (c.Type == CardType.Black)
            {
                bgPaint = cardWhitePaint;
                fgPaint = cardBlackPaint;
            }
            else
            {
                bgPaint = cardBlackPaint;
                fgPaint = cardWhitePaint;
            }
            cv.DrawRoundRect(2 - 3, 2 - 3, 2 + 106, 2 + 106, 10, 10, cardShadowPaint);
            cv.DrawRoundRect(-3, -3, 106, 106, 10, 10, fgPaint);
            cv.DrawRoundRect(0, 0, 100, 100, 7, 7, bgPaint);
            int   curChar = 0;
            float curY    = 8 + fgPaint.FontSpacing;

            while (curChar < c.Text.Length)
            {
                float  w;
                int    cnt      = (int)fgPaint.BreakText(c.Text.Substring(curChar).Trim(), 90, out w);
                bool   breaking = (curChar + cnt) < c.Text.Length;
                string text     = c.Text.Substring(curChar, cnt).TrimStart();
                if (!text.EndsWith(" ") && breaking)
                {
                    text += "-";
                }
                cv.DrawText(text, 8, curY, fgPaint);
                curChar += cnt;
                curY    += fgPaint.FontSpacing;
            }
        }
Example #10
0
        protected override void InternalDraw(SKCanvas canvas)
        {
            base.InternalDraw(canvas);

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

                if (HasShadow)
                {
                    using (var filter = SKMaskFilter.CreateBlur(SKBlurStyle.Normal, 2.0f))
                    {
                        paint.MaskFilter = filter;
                        paint.Color      = Color.Gray.ToSKColor();

                        switch (Shape)
                        {
                        case MycoShapes.Rectangle:
                            canvas.DrawRect(RenderBounds.ToSKRect(), paint);
                            break;

                        case MycoShapes.RoundedRectangle:
                            canvas.DrawRoundRect(RenderBounds.ToSKRect(), RoundedRectRadius, RoundedRectRadius, paint);
                            break;

                        case MycoShapes.Oval:
                            canvas.DrawOval(RenderBounds.ToSKRect(), paint);
                            break;
                        }

                        paint.MaskFilter = null;
                    }
                }

                paint.Color = ShapeColor.ToSKColor();

                switch (Shape)
                {
                case MycoShapes.Rectangle:
                    canvas.DrawRect(RenderBounds.ToSKRect(), paint);
                    break;

                case MycoShapes.RoundedRectangle:
                    canvas.DrawRoundRect(RenderBounds.ToSKRect(), RoundedRectRadius, RoundedRectRadius, paint);
                    break;

                case MycoShapes.Oval:
                    canvas.DrawOval(RenderBounds.ToSKRect(), paint);
                    break;
                }
            }
        }
Example #11
0
        protected void OnDrawSample(SKCanvas canvas, int width, int height)
        {
            var length = Math.Min(width / 6, height / 6);
            var rect   = new SKRect(-length, -length, length, length);
            var side   = rotationMatrix.MapPoint(new SKPoint(1, 0)).X > 0;

            canvas.Clear(SampleMedia.Colors.XamarinLightBlue);

            // first do 2D translation to the center of the screen
            canvas.Translate(width / 2, height / 2);

            // then apply the 3D rotation
            var matrix = rotationMatrix.Matrix;

            canvas.Concat(ref matrix);

            var paint = new SKPaint
            {
                Color       = side ? SampleMedia.Colors.XamarinPurple : SampleMedia.Colors.XamarinGreen,
                Style       = SKPaintStyle.Fill,
                IsAntialias = true
            };

            canvas.DrawRoundRect(rect, 30, 30, paint);

            var shadow = SKShader.CreateLinearGradient(
                new SKPoint(0, 0), new SKPoint(0, length * 2),
                new[] { paint.Color.WithAlpha(127), paint.Color.WithAlpha(0) },
                null,
                SKShaderTileMode.Clamp);

            paint = new SKPaint
            {
                Shader      = shadow,
                Style       = SKPaintStyle.Fill,
                IsAntialias = true
            };

            rect.Offset(0, length * 2 + 5);
            canvas.DrawRoundRect(rect, 30, 30, paint);

            Log.Debug("Demo", "Enter");

            if (cnt == 0)
            {
                Log.Debug("Demo", "Enter");
                InitEvent();
            }
        }
        public override void OnCanvasViewPaintSurface(SKPaintSurfaceEventArgs e)
        {
            SKImageInfo imageInfo = e.Info;
            SKSurface   surface   = e.Surface;
            SKCanvas    canvas    = surface.Canvas;

            if (isDead())
            {
                SKPoint rotatePoint = new SKPoint(rect.MidX, rect.MidY);

                canvas.RotateDegrees(deathAnimation, rotatePoint.X, rotatePoint.Y);
                canvas.DrawBitmap(getBitmap(), getRectangle(), paint);
                canvas.RotateDegrees(-deathAnimation, rotatePoint.X, rotatePoint.Y);

                deathAnimation += 15;
                ySpeed         += 0.2;
            }
            else
            {
                canvas.DrawBitmap(sprites[resID], getRectangle(), paint);

                //Draw health-bar
                int separate    = 20;
                var paintMargin = new SKPaint
                {
                    Style = SKPaintStyle.Stroke,
                    Color = SKColors.Black
                };
                var paintHP = new SKPaint
                {
                    Style = SKPaintStyle.Fill,
                    Color = SKColors.IndianRed
                };
                var paintFillWhite = new SKPaint
                {
                    Style = SKPaintStyle.Fill,
                    Color = SKColors.White
                };

                float hp = -((activity.getImageInfo().Width - separate) - (activity.getImageInfo().Width / 2 + separate)) * ((10 - (float)getHealth()) / 10);

                SKRect margin = new SKRect(activity.getImageInfo().Width / 2 + separate, activity.getImageInfo().Height - separate * 2, activity.getImageInfo().Width - separate, activity.getImageInfo().Height - separate);
                SKRect fill   = new SKRect(activity.getImageInfo().Width / 2 + separate, activity.getImageInfo().Height - separate * 2, activity.getImageInfo().Width - separate + (int)hp, activity.getImageInfo().Height - separate);

                canvas.DrawRoundRect(margin, 5, 5, paintFillWhite);
                canvas.DrawRoundRect(fill, 5, 5, paintHP);
                canvas.DrawRoundRect(margin, 5, 5, paintMargin);
            }
        }
Example #13
0
        private void DrawWild(SKCanvas thisCanvas, SKRect rect_Card)
        {
            var tempRect = GetStartingRect(rect_Card);

            thisCanvas.DrawRect(tempRect, GetColorUsed()); // i think
            var otherRect = GetCenterDiceRect();
            var tempSize  = MainGraphics !.GetFontSize(3);

            thisCanvas.DrawRoundRect(otherRect, tempSize, tempSize, _whitePaint);
            thisCanvas.DrawRoundRect(otherRect, tempSize, tempSize, _thickBorder);
            var fontSize  = otherRect.Height * 0.38f; // can adjust as needed
            var textPaint = MiscHelpers.GetTextPaint(SKColors.Black, fontSize);

            thisCanvas.DrawCustomText("WILD", TextExtensions.EnumLayoutOptions.Center, TextExtensions.EnumLayoutOptions.Center, textPaint, otherRect, out _);
        }
Example #14
0
 public void DrawRectangle(Pen pen, Rect rect, float cornerRadius = 0)
 {
     using (var paint = CreatePaint(pen, rect.Size))
     {
         var rc = rect.ToSKRect();
         if (cornerRadius == 0)
         {
             Canvas.DrawRect(rc, paint.Paint);
         }
         else
         {
             Canvas.DrawRoundRect(rc, cornerRadius, cornerRadius, paint.Paint);
         }
     }
 }
        public void DrawImage(SKCanvas ThisCanvas, float Width, float Height) // i think this is it.
        {
            var ThisRect = SKRect.Create(0, 0, Width, Height);

            ThisCanvas.Clear();
            ThisCanvas.DrawBitmap(_img_LilyPad, ThisRect, _bitPaint);
            if (HasFrog == true)
            {
                ThisCanvas.DrawBitmap(_img_Frog, ThisRect, _bitPaint);
            }
            SKPaint?ThisPaint = null;

            if (IsSelected == true)
            {
                ThisPaint = MiscHelpers.GetStrokePaint(SKColors.Red, Width / 30);
            }
            else if (IsTarget == true)
            {
                ThisPaint = MiscHelpers.GetStrokePaint(SKColors.Lime, Width / 10);
                float[] Ins;
                Ins    = new float[2];
                Ins[0] = Width / 20;
                Ins[1] = Width / 20;
                ThisPaint.PathEffect = SKPathEffect.CreateDash(Ins, 1); // not sure
            }
            if (IsSelected == true || IsTarget == true)
            {
                ThisCanvas.DrawRoundRect(ThisRect, Width / 10, Width / 10, ThisPaint);
            }
        }
Example #16
0
        private static void DrawHyperlink(SKCanvas canvas, double screenWidth, double screenHeight, Hyperlink textBox)
        {
            if (textBox.Text == null)
            {
                return;                       // todo: fix this for widgets without text
            }
            var textPaint = new SKPaint {
                Color = textBox.TextColor.ToSkia(), IsAntialias = true
            };
            var backPaint = new SKPaint {
                Color = textBox.BackColor.ToSkia(),
            };
            // The textRect has an offset which can be confusing.
            // This is because DrawText's origin is the baseline of the text, not the bottom.
            // Read more here: https://developer.xamarin.com/guides/xamarin-forms/advanced/skiasharp/basics/text/
            var textRect = new SKRect();

            textPaint.MeasureText(textBox.Text, ref textRect);
            // The backRect is straight forward. It is leading for our purpose.
            var backRect = new SKRect(0, 0,
                                      textRect.Width + textBox.PaddingX * 2,
                                      textPaint.TextSize + textBox.PaddingY * 2); // Use the font's TextSize for consistency
            var offsetX = GetOffsetX(backRect.Width, textBox.MarginX, textBox.HorizontalAlignment, screenWidth);
            var offsetY = GetOffsetY(backRect.Height, textBox.MarginY, textBox.VerticalAlignment, screenHeight);

            backRect.Offset(offsetX, offsetY);
            canvas.DrawRoundRect(backRect, textBox.CornerRadius, textBox.CornerRadius, backPaint);
            textBox.Envelope = backRect.ToMapsui();
            // To position the text within the backRect correct using the textRect's offset.
            canvas.DrawText(textBox.Text,
                            offsetX - textRect.Left + textBox.PaddingX,
                            offsetY - textRect.Top + textBox.PaddingY, textPaint);
        }
Example #17
0
        private void DrawTooltip(SKCanvas canvas, ChartEntry entry)
        {
            using (var textPaint = new SKPaint
            {
                Style = SKPaintStyle.StrokeAndFill,
                Color = TooltipTextColor,
                TextAlign = SKTextAlign.Center,
                TextSize = TooltipTextSize
            })
            {
                var topBottomMargin      = TooltipTextSize;
                var tooltipTextYPosition = _tooltipPoint.Y - TooltipYOffset - topBottomMargin;
                var textPath             = textPaint.GetTextPath(entry.Label, _tooltipPoint.X, tooltipTextYPosition);
                using (var tooltipBackgroundPaint = new SKPaint
                {
                    Style = SKPaintStyle.StrokeAndFill,
                    Color = TooltipBackgroundColor
                })
                {
                    var leftRightMargin = TooltipTextSize / 2;
                    canvas.DrawRoundRect(new SKRect(textPath.Bounds.Left - leftRightMargin, textPath.Bounds.Top - topBottomMargin, textPath.Bounds.Right + leftRightMargin, textPath.Bounds.Bottom + topBottomMargin), TooltipRadius, TooltipRadius, tooltipBackgroundPaint);
                }

                canvas.DrawText(entry.Label, _tooltipPoint.X, tooltipTextYPosition, textPaint);
            }
        }
Example #18
0
        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
                })
                {
                    canvas.Scale((float)xScaleSlider.Value,
                                 (float)yScaleSlider.Value);

                    SKRect textBounds = new SKRect();
                    textPaint.MeasureText(Title, ref textBounds);

                    float  margin     = 10;
                    SKRect borderRect = SKRect.Create(new SKPoint(margin, margin), textBounds.Size);
                    canvas.DrawRoundRect(borderRect, 20, 20, strokePaint);
                    canvas.DrawText(Title, margin, -textBounds.Top + margin, textPaint);
                }
        }
Example #19
0
        SKRoundRect makeBox(SKImageInfo info, SKCanvas canvas, TypeShadow typeShadow, float x, float y, Color color, Color backgroundColor)
        {
            SKPaint skPaint = new SKPaint()
            {
                Style = SKPaintStyle.Fill,
                Color = backgroundColor.ToSKColor(),
                //StrokeWidth = 20,
                IsAntialias = true,
            };

            SKRect skRectangle = new SKRect();

            if (!ShowOut)
            {
                skRectangle.Size     = new SKSize(info.Width, info.Height);
                skRectangle.Location = new SKPoint(0, 0);
            }
            else
            {
                skRectangle.Size     = new SKSize(info.Width - (SizeShadow * 2), info.Height - (SizeShadow * 2));
                skRectangle.Location = new SKPoint(SizeShadow, SizeShadow);
            }
            var mask = new SKRoundRect(skRectangle, BorderRadius, BorderRadius);

            canvas.DrawRoundRect(skRectangle, BorderRadius, BorderRadius, skPaint);
            //canvas.ClipRoundRect(mask, SKClipOperation.Difference);
            return(mask);
        }
Example #20
0
        private void SKCanvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            using (SKPaint paint = new SKPaint())
            {
                // define the color for the shadow
                SKColor shadowColor = Color.FromHex("#000000").ToSKColor();

                paint.IsDither    = true;
                paint.IsAntialias = true;
                paint.Color       = shadowColor;

                // create filter for drop shadow
                paint.ImageFilter = SKImageFilter.CreateDropShadowOnly(
                    dx: 0, dy: 0,
                    sigmaX: 40, sigmaY: 40,
                    color: shadowColor);

                // define where I want to draw the object
                var corner       = info.Width / 2;
                var shadowBounds = new SKRect(65, 65, 460, 460);
                canvas.DrawRoundRect(shadowBounds, corner, corner, paint);
            }
        }
Example #21
0
        void makeInnerShadow(SKImageInfo info, SKCanvas canvas, TypeShadow typeShadow, float x, float y, Color color, Color backgroundColor)
        {
            SKPaint skPaint = new SKPaint()
            {
                Style       = SKPaintStyle.Stroke,
                Color       = color.ToSKColor().WithAlpha((byte)(0xFF * OpacityShadow)),
                StrokeWidth = SizeStroker,
                IsAntialias = true,
                ImageFilter = SKImageFilter.CreateDropShadow(
                    x,
                    y,
                    SizeStroker,
                    SizeStroker,
                    color.ToSKColor().WithAlpha((byte)(0xFF * OpacityShadow)),
                    SKDropShadowImageFilterShadowMode.DrawShadowAndForeground)
            };

            SKRect skRectangle = new SKRect();

            if (!ShowOut)
            {
                skRectangle.Size     = new SKSize(info.Width, info.Height);
                skRectangle.Location = new SKPoint(0, 0);
            }
            else
            {
                skRectangle.Size     = new SKSize(info.Width - (SizeShadow * 2), info.Height - (SizeShadow * 2));
                skRectangle.Location = new SKPoint(SizeShadow, SizeShadow);
            }



            skRectangle.Inflate(SizeStroker, SizeStroker);
            canvas.DrawRoundRect(skRectangle, BorderRadius, BorderRadius, skPaint);
        }
Example #22
0
        void makeShadow(SKImageInfo info, SKCanvas canvas, TypeShadow typeShadow, float x, float y, Color color, Color backgroundColor)
        {
            SKPaint skPaint = new SKPaint()
            {
                Style = SKPaintStyle.Fill,
                Color = backgroundColor.ToSKColor(),
                //StrokeWidth = 1,
                IsAntialias = true,


                ImageFilter = SKImageFilter.CreateDropShadow(
                    x,
                    y,
                    SizeStroker,
                    SizeStroker,
                    color.ToSKColor().WithAlpha((byte)(0xFF * OpacityShadow)),
                    SKDropShadowImageFilterShadowMode.DrawShadowAndForeground)
            };
            var    auxSize     = SizeShadow;
            SKRect skRectangle = new SKRect();

            skRectangle.Size = new SKSize(info.Width - (auxSize * 2), info.Height - (auxSize * 2));

            skRectangle.Location = new SKPoint(auxSize, auxSize);



            canvas.DrawRoundRect(skRectangle, BorderRadius, BorderRadius, skPaint);
        }
Example #23
0
        public void Draw(SKCanvas canvas, IReadOnlyViewport viewport, IWidget widget, float layerOpacity)
        {
            var hyperlink = (Hyperlink)widget;

            if (string.IsNullOrEmpty(hyperlink.Text))
            {
                return;
            }
            using var textPaint = new SKPaint { Color = hyperlink.TextColor.ToSkia(layerOpacity), IsAntialias = true };
            using var backPaint = new SKPaint { Color = hyperlink.BackColor.ToSkia(layerOpacity) };
            // The textRect has an offset which can be confusing.
            // This is because DrawText's origin is the baseline of the text, not the bottom.
            // Read more here: https://developer.xamarin.com/guides/xamarin-forms/advanced/skiasharp/basics/text/
            var textRect = new SKRect();

            textPaint.MeasureText(hyperlink.Text, ref textRect);
            // The backRect is straight forward. It is leading for our purpose.
            var backRect = new SKRect(0, 0,
                                      textRect.Width + hyperlink.PaddingX * 2,
                                      textPaint.TextSize + hyperlink.PaddingY * 2); // Use the font's TextSize for consistency
            var offsetX = GetOffsetX(backRect.Width, hyperlink.MarginX, hyperlink.HorizontalAlignment, viewport.Width);
            var offsetY = GetOffsetY(backRect.Height, hyperlink.MarginY, hyperlink.VerticalAlignment, viewport.Height);

            backRect.Offset(offsetX, offsetY);
            canvas.DrawRoundRect(backRect, hyperlink.CornerRadius, hyperlink.CornerRadius, backPaint);
            hyperlink.Envelope = backRect.ToMRect();
            // To position the text within the backRect correct using the textRect's offset.
            canvas.DrawText(hyperlink.Text,
                            offsetX - textRect.Left + hyperlink.PaddingX,
                            offsetY - textRect.Top + hyperlink.PaddingY, textPaint);
        }
        private void CarouselGradient_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs e)
        {
            SKImageInfo info    = e.Info;
            SKSurface   surface = e.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            // get the brush based on the theme
            SKColor gradientStart = ((Color)Application.Current.Resources["CarouselGradientStartColor"]).ToSKColor();
            SKColor gradientMid   = ((Color)Application.Current.Resources["CarouselGradientMidColor"]).ToSKColor();
            SKColor gradientEnd   = ((Color)Application.Current.Resources["CarouselGradientEndColor"]).ToSKColor();

            // gradient background with 3 colors
            backgroundBrush.Shader = SKShader.CreateLinearGradient(
                new SKPoint(0, 0),
                new SKPoint(info.Width, info.Height),
                new SKColor[] { gradientStart, gradientMid, gradientEnd },
                new float[] { 0, .5f, 1 },
                SKShaderTileMode.Clamp);

            SKRect backgroundBounds = new SKRect(0, 0, info.Width, info.Height);

            canvas.DrawRoundRect(new SKRoundRect(backgroundBounds, 60, 60), backgroundBrush);
        }
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs args)
        {
            base.OnPaintSurface(args);

            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();
            canvas.Save();

            using (SKPaint paint = new SKPaint())
            {
                // Set SKPaint properties
                paint.Color       = SKColors.White;
                paint.ImageFilter = SKImageFilter.CreateDropShadow(
                    OffsetX,
                    OffsetY,
                    BlurX,
                    BlurY,
                    ShadowColor.ToSKColor(),
                    SKDropShadowImageFilterShadowMode.DrawShadowAndForeground);

                canvas.DrawRoundRect(new SKRect(20f, 20f, info.Width - 20, info.Height - 20), Radius, Radius, paint);

                canvas.Restore();
            }
        }
Example #26
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
        {
            base.OnPaintSurface(e);

            SKRoundRect skRoundRect = new SKRoundRect(e.Info.Rect, myRoundRadius);
            SKSurface   surface     = e.Surface;
            SKCanvas    canvas      = surface.Canvas;

            canvas.Clear(myBackgroundColor);

            SKPaint paint = new SKPaint
            {
                Style       = SKPaintStyle.Fill,
                TextSize    = 48,
                StrokeWidth = myCircleStrokeWidth,
                IsAntialias = true
            };

            paint.Style = SKPaintStyle.Fill;
            paint.Color = myColor1;

            paint.Shader = SKShader.CreateLinearGradient(
                new SKPoint(skRoundRect.Rect.Left, skRoundRect.Rect.Top),
                new SKPoint(skRoundRect.Rect.Right, skRoundRect.Rect.Bottom),
                new SKColor[] { myColor1, myColor2 },
                new float[] { 0, 1f },
                SKShaderTileMode.Repeat);


            canvas.DrawRoundRect(skRoundRect, paint);
        }
        private void Paint_RoundRect_withoutBorder(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            using (SKPaint paint = new SKPaint())
            {
                var    radius = info.Height / 2;
                SKRect rect;

                //half of the strokewidth to get border inside is added to left-top and subtracted from bottom-right
                rect = new SKRect(info.Rect.Left, info.Rect.Top, info.Rect.Right, info.Rect.Bottom);

                SKColor borderColor = ((Color)Application.Current.Resources["ButtonBackgroundColor"]).ToSKColor();
                paint.Color = borderColor;
                //paint.StrokeWidth = 5;
                //paint.Style = SKPaintStyle.Stroke;
                paint.IsAntialias = true;
                paint.Style       = SKPaintStyle.Fill;



                canvas.DrawRoundRect(rect, radius, radius, paint);
                //canvas.DrawColor(borderColor, SKBlendMode.ColorDodge);
            }
        }
        private void SKCanvasView_PaintSurface(object sender, SkiaSharp.Views.Forms.SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            using (SKPaint paint = new SKPaint())
            {
                // define the color for the shadow

                SKColor shadowColor = ((Color)Application.Current.Resources["ButtonBackgroundColor"]).ToSKColor();

                paint.IsDither    = true;
                paint.IsAntialias = true;
                paint.Color       = shadowColor;

                // create filter for drop shadow
                paint.ImageFilter = SKImageFilter.CreateDropShadow(
                    dx: 0, dy: 0,
                    sigmaX: 40, sigmaY: 40,
                    color: shadowColor,
                    shadowMode: SKDropShadowImageFilterShadowMode.DrawShadowOnly);

                // define where I want to draw the object
                var margin       = info.Width / 10;
                var shadowBounds = new SKRect(margin, -40, info.Width - margin, 10);
                canvas.DrawRoundRect(shadowBounds, 10, 10, paint);
            }
        }
Example #29
0
        private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();
            string str = "Hello SkiaSharp!";
            // crea un SKPaint oggetto per visualizzare il testo
            SKPaint textPaint = new SKPaint
            {
                Color = SKColors.Chocolate
            };
            // regola la proprietà TextSize in modo che il testo sia 90% della larghezza dello schermo
            float textWidth = textPaint.MeasureText(str);

            textPaint.TextSize = 0.9f * info.Width * textPaint.TextSize / textWidth;
            // trovare i limiti del testo
            SKRect textBounds = new SKRect();

            textPaint.MeasureText(str, ref textBounds);
            // calcola gli offset per centrare il testo sullo schermo
            float xText = info.Width / 2 - textBounds.MidX;
            float yText = info.Height / 2 - textBounds.MidY;

            // e disegna il testo
            canvas.DrawText(str, xText, yText, textPaint);
            // crea un nuovo skRect oggetto per la cornice intorno al testo
            SKRect frameRect = textBounds;

            frameRect.Offset(xText, yText);
            frameRect.Inflate(10, 10);
            // crea un SKPaint oggetto per visualizzare il frame
            SKPaint framePaint = new SKPaint
            {
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = 5,
                Color       = SKColors.Blue
            };

            // disegna un frame
            canvas.DrawRoundRect(frameRect, 20, 20, framePaint);
            // gonfiare il frameRect e disegnarne un altro
            frameRect.Inflate(10, 10);
            framePaint.Color = SKColors.DarkBlue;
            canvas.DrawRoundRect(frameRect, 30, 30, framePaint);
        }
        private static void MeasureText(SKImageInfo info, SKCanvas canvas)
        {
            string str = "SkiaSharp Demo";

            SKRect textBounds = new SKRect();
            float  xText;
            float  yText;

            using (SKPaint textPaint = new SKPaint()
            {
                Color = SKColors.Chocolate
            })
            {
                float textWidth = textPaint.MeasureText(str);
                textPaint.TextSize = 0.9f * info.Width * textPaint.TextSize / textWidth;

                // Find the text bounds
                textPaint.MeasureText(str, ref textBounds);

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

                // And draw the text
                canvas.DrawText(str, xText, yText, textPaint);
            }


            using (SKPaint framePaint = new SKPaint()
            {
                Color = SKColors.Blue, StrokeWidth = 5, Style = SKPaintStyle.Stroke
            })
            {
                SKRect frameRect = textBounds;
                frameRect.Offset(xText, yText);
                frameRect.Inflate(10, 10);

                canvas.DrawRoundRect(frameRect, 20, 20, framePaint);

                // Inflate the frameRect and draw another
                frameRect.Inflate(10, 10);
                framePaint.Color = SKColors.DarkBlue;

                canvas.DrawRoundRect(frameRect, 30, 30, framePaint);
            }
        }