Beispiel #1
0
 /// <summary>
 /// Draws a line with a gradient stroke.
 /// </summary>
 /// <param name="canvas">The canvas.</param>
 /// <param name="startPoint">The starting point.</param>
 /// <param name="startColor">The starting color.</param>
 /// <param name="endPoint">The end point.</param>
 /// <param name="endColor">The end color.</param>
 /// <param name="size">The stroke size.</param>
 public static void DrawGradientLine(this SKCanvas canvas, SKPoint startPoint, SKColor startColor, SKPoint endPoint, SKColor endColor, float size)
 {
     using (var shader = SKShader.CreateLinearGradient(startPoint, endPoint, new[] { startColor, endColor }, null, SKShaderTileMode.Clamp))
     {
         using (var paint = new SKPaint
         {
             Style = SKPaintStyle.Stroke,
             StrokeWidth = size,
             Shader = shader,
             IsAntialias = true,
         })
         {
             canvas.DrawLine(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y, paint);
         }
     }
 }
Beispiel #2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="RadialGradientPaint"/> class.
 /// </summary>
 /// <param name="centerColor">Color of the center.</param>
 /// <param name="outerColor">Color of the outer.</param>
 public RadialGradientPaintTask(SKColor centerColor, SKColor outerColor)
     : this(new[] { centerColor, outerColor })
 {
 }
Beispiel #3
0
            protected override void OnSkiaPaint(SKSurface e)
            {
                try
                {
                    var canvas = e.Canvas;

                    canvas.Clear(SKColors.Gray);

                    canvas.Scale((float)scale.Width, (float)scale.Height);

                    foreach (Form form in Application.OpenForms.Select(a => a).ToArray())
                    {
                        if (form.IsHandleCreated)
                        {
                            if (form is MainV2 && form.WindowState != FormWindowState.Maximized)
                            {
                                form.BeginInvokeIfRequired(() => { form.WindowState = FormWindowState.Maximized; });
                            }

                            try
                            {
                                DrawOntoCanvas(form.Handle, canvas, true);
                            }
                            catch (Exception ex)
                            {
                                Console.WriteLine(ex);
                            }
                        }
                    }

                    IEnumerable <Hwnd> menu;
                    lock (Hwnd.windows)
                        menu = Hwnd.windows.Values.OfType <Hwnd>()
                               .Where(hw => hw.topmost && hw.Mapped && hw.Visible).ToArray();
                    foreach (Hwnd hw in menu)
                    {
                        var ctlmenu = Control.FromHandle(hw.ClientWindow);
                        if (ctlmenu != null)
                        {
                            DrawOntoCanvas(hw.ClientWindow, canvas, true);
                        }
                    }

                    // if (Device.RuntimePlatform != Device.macOS && Device.RuntimePlatform != Device.UWP)
                    {
                        canvas.ClipRect(
                            SKRect.Create(0, 0, Screen.PrimaryScreen.Bounds.Width,
                                          Screen.PrimaryScreen.Bounds.Height), (SKClipOperation)5);

                        var path = new SKPath();

                        path.MoveTo(cursorPoints.First());
                        cursorPoints.ForEach(a => path.LineTo(a));
                        path.Transform(new SKMatrix(1, 0, XplatUI.driver.MousePosition.X, 0, 1,
                                                    XplatUI.driver.MousePosition.Y, 0, 0, 1));

                        canvas.DrawPath(path,
                                        new SKPaint()
                        {
                            Color = SKColors.White, Style = SKPaintStyle.Fill, StrokeJoin = SKStrokeJoin.Miter
                        });
                        canvas.DrawPath(path,
                                        new SKPaint()
                        {
                            Color = SKColors.Black, Style = SKPaintStyle.Stroke, StrokeJoin = SKStrokeJoin.Miter, IsAntialias = true
                        });
                    }

                    canvas.DrawText("" + DateTime.Now.ToString("HH:mm:ss.fff"),
                                    new SKPoint(10, 10), new SKPaint()
                    {
                        Color = SKColor.Parse("ffff00")
                    });

                    canvas.Flush();
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                finally
                {
                }
            }
        private void AddText(SKCanvas canvas, PartEntityText textEntity, Vector2 position, SKColor textColor)
        {
            Vector2 start   = Scale(textEntity.Start) + position;
            int     padding = 20;

            using (var paintText = new SKPaint())
                using (var paintRect = new SKPaint())
                {
                    paintText.TextSize    = textEntity.TextSize * scale;
                    paintText.IsAntialias = true;
                    paintText.Color       = textColor;
                    paintText.IsStroke    = false;
                    paintText.Typeface    = SKTypeface.FromFamilyName(
                        "Arial",
                        textEntity.IsBold?SKFontStyleWeight.ExtraBold : SKFontStyleWeight.Normal,
                        SKFontStyleWidth.Normal,
                        textEntity.IsItalic ? SKFontStyleSlant.Italic : SKFontStyleSlant.Upright);

                    paintRect.IsAntialias = true;
                    paintRect.Color       = textColor;
                    paintRect.IsStroke    = true;
                    paintRect.StrokeWidth = 1;

                    canvas.Save();
                    canvas.RotateDegrees(textEntity.Rotation, start.X, start.Y);
                    canvas.DrawText(textEntity.Text, start.X, start.Y, paintText);

                    SKRect textBounds = new SKRect();
                    paintText.MeasureText(textEntity.Text, ref textBounds);

                    if (textEntity.ShowBoundingFrame)
                    {
                        canvas.DrawRoundRect(
                            (start.X) - padding / 2,
                            (start.Y - textBounds.Height) - padding / 2,
                            textBounds.Width + padding,
                            textBounds.Height + padding,
                            3, 3,
                            paintRect);
                    }
                    canvas.Restore();
                }
        }
        private Vector2 AddBezier(SKCanvas canvas, SKPath pathBuilder, PartEntityBezier entity, Vector2 position, SKColor lineColor,
                                  bool showAttribue, bool showConstruction, bool showSA)
        {
            if (showAttribue)
            {
                using (var paint = new SKPaint())
                {
                    paint.IsAntialias = true;
                    paint.Color       = colorAttributes;
                    paint.IsStroke    = false;
                    canvas.DrawCircle(ToP(Scale(entity.Control1) + position), 3f, paint);
                    canvas.DrawLine(ToP(Scale(entity.Control1) + position), ToP(Scale(entity.Start) + position), paint);
                    canvas.DrawCircle(ToP(Scale(entity.Control2) + position), 3f, paint);
                    canvas.DrawLine(ToP(Scale(entity.Control2) + position), ToP(Scale(entity.End) + position), paint);
                }
            }

            entity.Lines.ForEach(x =>
            {
                AddLine(canvas, pathBuilder, x, position, lineColor, showConstruction, showSA);
            });

            return(entity.End);
        }
Beispiel #6
0
        /*public SKBitmap B(List<Section> sections, Dictionary<Section, SKBitmap> bitmaps)
         * {
         *  List<int> featured = new List<int>();
         *  List<int> others = new List<int>();
         *
         *  int featuredCount = 0;
         *
         *  foreach (var section in sections)
         *  {
         *      if (section.SectionId.Contains("Featured"))
         *      {
         *          featured.Add(bitmaps.First(predicate: x => x.Key.SectionId == section.SectionId).Value.Width);
         *          featuredCount++;
         *          continue;
         *      }
         *      else //if (section.SectionId.Contains("Daily"))
         *      {
         *          others.Add(bitmaps.First(predicate: x => x.Key.SectionId == section.SectionId).Value.Width);
         *          continue;
         *      }
         *  };
         *
         *  int columnCount = featured.Count > 0 ? 2 : 1;
         *
         *  int width = columnCount * featured.Max();
         *  int featuredHeight = 0;
         *  int othersHeight = 0;
         *
         *  bitmaps.ToList().ForEach(pair =>
         *  {
         *      if (pair.Key.SectionId.Contains("Featured")) featuredHeight += pair.Value.Height;
         *      else othersHeight += pair.Value.Height;
         *  });
         *
         *  int height = Math.Max(featuredHeight, othersHeight) + 250;
         *
         *  int ratio = 0;
         *
         *  int fullHeight = 0;
         *  int fullWidth = 0;
         *
         *  if (height >= width) ratio = height / 9;
         *  else ratio = width / 16;
         *
         *  fullHeight = ratio * 9;
         *  fullWidth = ratio * 16;
         *
         *  var full = new SKBitmap(fullWidth, fullHeight);
         *
         *  using (var merge = new SKBitmap(width, height))
         *  {
         *      using (var c = new SKCanvas(merge))
         *      {
         *          int y = 0;
         *          int x = 0;
         *          int i = 0;
         *
         *          sections.ToList().ForEach(section =>
         *          {
         *              var bitmap = bitmaps.First(predicate: x => x.Key.SectionId == section.SectionId).Value;
         *
         *              c.DrawBitmap(bitmap, x, y);
         *              y += bitmap.Height;
         *              i++;
         *
         *              if (i == featuredCount)
         *              {
         *                  y = 0;
         *                  x += width / columnCount;
         *              }
         *          });
         *      }
         *
         *      using (var c = new SKCanvas(full))
         *      {
         *          c.DrawRect(0, 0, full.Width, full.Height,
         *              new SKPaint
         *              {
         *                  IsAntialias = true,
         *                  FilterQuality = SKFilterQuality.High,
         *                  Color = new SKColor(40, 40, 40)
         *              });
         *
         *          c.DrawBitmap(merge, (full.Width - merge.Width) / 2, 0,
         *              new SKPaint
         *              {
         *                  IsAntialias = true,
         *                  FilterQuality = SKFilterQuality.High
         *              });
         *
         *          var textPaint = new SKPaint
         *          {
         *              IsAntialias = true,
         *              FilterQuality = SKFilterQuality.High,
         *              TextSize = 200,
         *              Color = SKColors.White,
         *              Typeface = ChicTypefaces.BurbankBigRegularBlack,
         *              ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 10, 10, SKColors.Black)
         *          };
         *
         *          var sacText = "Code 'Chic' #Ad";
         *
         *          c.DrawText(sacText, (full.Width - textPaint.MeasureText(sacText)) / 2,
         *              full.Height - 50, textPaint);
         *      }
         *
         *      return full;
         *  }
         * }*/

        public Dictionary <Section, BitmapData> GenerateSections(Dictionary <StorefrontEntry, BitmapData> entries)
        {
            int maxEntriesPerRow = 6;

            Dictionary <Section, BitmapData> sectionsBitmaps = new Dictionary <Section, BitmapData>();

            var content = FortniteContent.Get();

            List <Section> sections = new List <Section>();

            entries.Keys.ToList().ForEach(key =>
            {
                if (!sections.Contains(x => x.SectionId == key.SectionId))
                {
                    if (content.ShopSections.Contains(key.SectionId))
                    {
                        sections.Add(content.ShopSections.Get(key.SectionId));
                    }
                    else
                    {
                        sections.Add(new Section
                        {
                            SectionId       = key.SectionId,
                            DisplayName     = "",
                            LandingPriority = 49
                        });
                    }
                }
            });

            List <int> entriesCount = new List <int>();

            sections.ForEach(section =>
            {
                int count = 0;

                entries.ToList().ForEach(entry =>
                {
                    if (entry.Key.SectionId == section.SectionId)
                    {
                        count++;
                    }
                });

                entriesCount.Add(count);
            });

            maxEntriesPerRow = Math.Clamp(entriesCount.Max(), 0, maxEntriesPerRow);

            int th = (int)(ChicRatios.Get1024(200) * EntryHeight);
            int hf = (int)(ChicRatios.Get1024(150) * EntryHeight);
            int h  = (int)(ChicRatios.Get1024(100) * EntryHeight);
            int f  = (int)(ChicRatios.Get1024(50) * EntryHeight);

            foreach (var section in sections)
            {
                Dictionary <StorefrontEntry, BitmapData> se = new Dictionary <StorefrontEntry, BitmapData>();

                entries.ToList().ForEach(entry =>
                {
                    if (entry.Key.SectionId == section.SectionId)
                    {
                        se.Add(entry);
                    }
                });

                Dictionary <StorefrontEntry, BitmapData> sectionEntries = new Dictionary <StorefrontEntry, BitmapData>();
                sectionEntries.Add(se.ToList().Sort(EntryComparer.Comparer, 0));

                int extraHeight = section.HasName ? th : 0;

                SKBitmap bitmap = new SKBitmap(h /*150*/ + maxEntriesPerRow * (EntryWidth + h /*+ 50*/), extraHeight + (int)Math.Ceiling((decimal)sectionEntries.Count / maxEntriesPerRow) * (EntryHeight + h /*+ 50*/));

                using (SKCanvas c = new SKCanvas(bitmap))
                {
                    using (var paint = new SKPaint
                    {
                        IsAntialias = true,
                        FilterQuality = SKFilterQuality.High,
                        Color = SKColor.Parse("#e7accb")//new SKColor(40, 40, 40)
                    }) c.DrawRect(0, 0, bitmap.Width, bitmap.Height, paint);

                    int x      = f;//100;
                    int y      = extraHeight;
                    int row    = 0;
                    int column = 0;

                    for (int i = 0; i < sectionEntries.Count; i++)
                    {
                        var entry = sectionEntries.ToList()[i];

                        using (var b = LoadFromCache(entry.Value))
                        {
                            using (var paint = new SKPaint {
                                IsAntialias = true, FilterQuality = SKFilterQuality.High
                            })
                                c.DrawBitmap(b, x, y, paint);
                        }

                        GC.Collect();

                        if (++column == maxEntriesPerRow)
                        {
                            row++;
                            column = 0;
                            //x = 50;//100;
                        }

                        x = f + (EntryWidth + h) * column; /*+ 50*/
                        y = extraHeight + (EntryHeight + h /*+ 50*/) * row;
                    }

                    using (var paint = new SKPaint
                    {
                        IsAntialias = true,
                        FilterQuality = SKFilterQuality.High,
                        Color = SKColors.White,
                        TextSize = h,
                        Typeface = ChicTypefaces.BurbankBigRegularBlack,
                        TextAlign = SKTextAlign.Left,
                        ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 10, 10, SKColors.Black)
                    }) if (section.HasName)
                        {
                            c.DrawText(section.DisplayName, h, hf, paint);
                        }
                }

                sectionEntries = null;

                sectionsBitmaps.Add(section, SaveToCache(bitmap, "section_" + section.SectionId));
            }

            content  = null;
            sections = null;
            entries  = null;

            GC.Collect();

            return(sectionsBitmaps);
        }
        private void DrawPart(PatternPart part, Vector2 position, SKColor fillColor, SKColor pathColor, SKColor textColor)
        {
            using (var pathBuilder = new SKPath())
            {
                pathBuilder.MoveTo(Scale(position.X), Scale(position.Y));

                foreach (PartEntity entity in part.Entities)
                {
                    if (entity is PartEntityBezier)
                    {
                        AddBezier(canvas, pathBuilder, ((PartEntityBezier)entity), Scale(position), MapEntityColors(entity.EntityType), part.ShowAttributes, part.ShowConstruction, part.ShowSA);
                    }
                    else if (entity is PartEntityLine)
                    {
                        AddLine(canvas, pathBuilder, ((PartEntityLine)entity), Scale(position), MapEntityColors(entity.EntityType), part.ShowConstruction, part.ShowSA);
                    }
                }
                pathBuilder.Close();

                SKPaint fillPaint = new SKPaint
                {
                    Style       = SKPaintStyle.Fill,
                    Color       = fillColor,
                    IsAntialias = true,
                };

                SKPaint strokePaint = new SKPaint
                {
                    Style       = SKPaintStyle.Stroke,
                    Color       = pathColor,
                    IsAntialias = true,
                    StrokeWidth = 1,
                };

                if (!part.ShowPath)
                {
                    strokePaint.Color = colorTransparent;
                }

                canvas.DrawPath(pathBuilder, fillPaint);
                canvas.DrawPath(pathBuilder, strokePaint);

                foreach (PartEntity entity in part.Entities)
                {
                    if (entity is PartEntityText)
                    {
                        if (part.ShowText)
                        {
                            AddText(canvas, (PartEntityText)entity, Scale(position), textColor);
                        }
                    }
                    else if (entity is PartEntityContainer)
                    {
                        if (part.ShowText)
                        {
                            AddPartPartEntityContainer(canvas, pathBuilder, (PartEntityContainer)entity, Scale(position), textColor, textColor);
                        }
                    }
                }
            }
        }
 public YearViewModel()
 {
     YearlyEmotionsData = YearlyEmotions();
     JoyChart           = GetYearChart(YearlyEmotionsData.Find(x => x.Emotion == "joy"), SKColor.Parse("#FF9EE4"));
     AngerChart         = GetYearChart(YearlyEmotionsData.Find(x => x.Emotion == "anger"), SKColor.Parse("#FF4874"));
     DisgustChart       = GetYearChart(YearlyEmotionsData.Find(x => x.Emotion == "disgust"), SKColor.Parse("#C1FF84"));
     ContemptChart      = GetYearChart(YearlyEmotionsData.Find(x => x.Emotion == "contempt"), SKColor.Parse("#FFE381"));
     SadnessChart       = GetYearChart(YearlyEmotionsData.Find(x => x.Emotion == "sadness"), SKColor.Parse("#92B7FE"));
     FearChart          = GetYearChart(YearlyEmotionsData.Find(x => x.Emotion == "fear"), SKColor.Parse("#FFFFFF"));
     SurpriseChart      = GetYearChart(YearlyEmotionsData.Find(x => x.Emotion == "surprise"), SKColor.Parse("#FF9D9D"));
 }
Beispiel #9
0
        public static void GetInGameRarity(BaseIcon icon, EnumProperty e)
        {
            Package p = Utils.GetPropertyPakPackage("/Game/Balance/RarityData");

            if (p != null && p.HasExport())
            {
                var d = p.GetExport <UObject>();
                if (d != null)
                {
                    EFortRarity rarity = EFortRarity.Uncommon;
                    switch (e?.Value.String)
                    {
                    case "EFortRarity::Common":
                    case "EFortRarity::Handmade":
                        rarity = EFortRarity.Common;
                        break;

                    case "EFortRarity::Rare":
                    case "EFortRarity::Sturdy":
                        rarity = EFortRarity.Rare;
                        break;

                    case "EFortRarity::Epic":
                    case "EFortRarity::Quality":
                        rarity = EFortRarity.Epic;
                        break;

                    case "EFortRarity::Legendary":
                    case "EFortRarity::Fine":
                        rarity = EFortRarity.Legendary;
                        break;

                    case "EFortRarity::Mythic":
                    case "EFortRarity::Elegant":
                        rarity = EFortRarity.Mythic;
                        break;

                    case "EFortRarity::Transcendent":
                    case "EFortRarity::Masterwork":
                        rarity = EFortRarity.Transcendent;
                        break;

                    case "EFortRarity::Unattainable":
                    case "EFortRarity::Badass":
                        rarity = EFortRarity.Unattainable;
                        break;
                    }

                    if (d.Values.ElementAt((int)rarity) is StructProperty s && s.Value is UObject colors)
                    {
                        if (colors.TryGetValue("Color1", out var c1) && c1 is StructProperty s1 && s1.Value is FLinearColor color1 &&
                            colors.TryGetValue("Color2", out var c2) && c2 is StructProperty s2 && s2.Value is FLinearColor color2 &&
                            colors.TryGetValue("Color3", out var c3) && c3 is StructProperty s3 && s3.Value is FLinearColor color3)
                        {
                            icon.RarityBackgroundColors = new SKColor[2] {
                                SKColor.Parse(color1.Hex), SKColor.Parse(color3.Hex)
                            };
                            icon.RarityBorderColor = new SKColor[2] {
                                SKColor.Parse(color2.Hex), SKColor.Parse(color1.Hex)
                            };
                        }
                    }
                }
            }
            else
            {
                GetHardCodedRarity(icon, e);
            }
        }
Beispiel #10
0
 public TextBlock(Font font, SKColor color, string text, LineBreakMode lineBreakMode) : this(font, color, text)
 {
     LineBreakMode = lineBreakMode;
 }
        private Chart GetYearChart(EmotionDuringYear EmotionDuringYear, SKColor EmotionColor)
        {
            Chart chart = new LineChart();

            List <double> Percentages = EmotionDuringYear.Percentage;

            var entries = new[]
            {
                new Microcharts.Entry((float)Percentages[0])
                {
                    Label      = "January",
                    ValueLabel = Percentages[0].ToString() + "%",
                    Color      = EmotionColor,
                    TextColor  = SKColors.White
                },

                new Microcharts.Entry((float)Percentages[1])
                {
                    Label      = "February",
                    ValueLabel = Percentages[1].ToString() + "%",
                    Color      = EmotionColor,
                    TextColor  = SKColors.White
                },
                new Microcharts.Entry((float)Percentages[2])
                {
                    Label      = "March",
                    ValueLabel = Percentages[2].ToString() + "%",
                    Color      = EmotionColor,
                    TextColor  = SKColors.White
                },
                new Microcharts.Entry((float)Percentages[3])
                {
                    Label      = "April",
                    ValueLabel = Percentages[3].ToString() + "%",
                    Color      = EmotionColor,
                    TextColor  = SKColors.White
                },
                new Microcharts.Entry((float)Percentages[4])
                {
                    Label      = "May",
                    ValueLabel = Percentages[4].ToString() + "%",
                    Color      = EmotionColor,
                    TextColor  = SKColors.White
                },
                new Microcharts.Entry((float)Percentages[5])
                {
                    Label      = "June",
                    ValueLabel = Percentages[5].ToString() + "%",
                    Color      = EmotionColor,
                    TextColor  = SKColors.White
                },
                new Microcharts.Entry((float)Percentages[6])
                {
                    Label      = "July",
                    ValueLabel = Percentages[6].ToString() + "%",
                    Color      = EmotionColor,
                    TextColor  = SKColors.White
                },
                new Microcharts.Entry((float)Percentages[7])
                {
                    Label      = "August",
                    ValueLabel = Percentages[7].ToString() + "%",
                    Color      = EmotionColor,
                    TextColor  = SKColors.White
                },
                new Microcharts.Entry((float)Percentages[8])
                {
                    Label      = "September",
                    ValueLabel = Percentages[8].ToString() + "%",
                    Color      = EmotionColor,
                    TextColor  = SKColors.White
                },
                new Microcharts.Entry((float)Percentages[9])
                {
                    Label      = "October",
                    ValueLabel = Percentages[9].ToString() + "%",
                    Color      = EmotionColor,
                    TextColor  = SKColors.White
                },
                new Microcharts.Entry((float)Percentages[10])
                {
                    Label      = "November",
                    ValueLabel = Percentages[10].ToString() + "%",
                    Color      = EmotionColor,
                    TextColor  = SKColors.White
                },
                new Microcharts.Entry((float)Percentages[11])
                {
                    Label      = "December",
                    ValueLabel = Percentages[11].ToString() + "%",
                    Color      = EmotionColor,
                    TextColor  = SKColors.White
                },
            };

            chart.Entries         = entries;
            chart.BackgroundColor = SKColors.Transparent;
            chart.LabelColor      = SKColors.White;
            chart.MaxValue        = 100;
            chart.MinValue        = 0;


            return(chart);
        }
Beispiel #12
0
 public TextBlock(Font font, SKColor color, string text)
 {
     Font  = font;
     Color = color;
     Text  = text ?? "";
 }
Beispiel #13
0
        public SKRect Draw(SKCanvas canvas, SKRect rect, TextShaper textShaper = null, FlowDirection flowDirection = FlowDirection.LeftToRight)
        {
            LoadMeasures(textShaper);

            var y = rect.Top + FontHeight + MarginY;

            if (LineBreakMode == LineBreakMode.MiddleTruncation)
            {
                var spans = GetSpans(rect.Width);
                if (flowDirection == FlowDirection.LeftToRight)
                {
                    var x = rect.Left;
                    if (spans.Count > 0)
                    {
                        canvas.DrawGlyphSpan(GlyphSpan, x, y, Color, spans[0]);
                        x += spans[0].width;
                    }
                    if (spans.Count > 1)
                    {
                        canvas.DrawGlyphSpan(EllipsisGlyphSpan, x, y, Color, spans[1]);
                        x += spans[1].width;
                    }
                    if (spans.Count > 2)
                    {
                        canvas.DrawGlyphSpan(GlyphSpan, x, y, Color, spans[2]);
                    }
                }
                else
                {
                    var x = rect.Right;
                    if (spans.Count > 0)
                    {
                        x -= spans[0].width;
                        canvas.DrawGlyphSpan(GlyphSpan, x, y, Color, spans[0]);
                    }
                    if (spans.Count > 1)
                    {
                        x -= spans[1].width;
                        canvas.DrawGlyphSpan(EllipsisGlyphSpan, x, y, Color, spans[1]);
                    }
                    if (spans.Count > 2)
                    {
                        x -= spans[2].width;
                        canvas.DrawGlyphSpan(GlyphSpan, x, y, Color, spans[2]);
                    }
                }
                y += LineHeight;
            }
            else
            {
                var lines = GetLines(rect.Width);
                var i     = 0;
                foreach (var line in lines)
                {
                    if (GetLineColor != null)
                    {
                        Color = GetLineColor(i++, lines.Count);
                    }
                    if (LineBreakMode == LineBreakMode.WordWrap)
                    {
                        float x;
                        if (flowDirection == FlowDirection.LeftToRight)
                        {
                            x = rect.Left;
                        }
                        else
                        {
                            x = rect.Right - line.width;
                        }
                        canvas.DrawGlyphSpan(GlyphSpan, x, y, Color, line, GlyphAnimation);
                    }
                    else if (LineBreakMode == LineBreakMode.Center)
                    {
                        var x = rect.Left + (rect.Width - line.width) / 2;
                        canvas.DrawGlyphSpan(GlyphSpan, x, y, Color, line, GlyphAnimation);
                    }
                    y += LineHeight;
                }
            }

            var paintrect = new SKRect(rect.Left, rect.Top, rect.Right, y - LineHeight + MarginY);

#if DEBUGCONTAINER
            if (canvas != null)
            {
                using (var borderpaint = new SKPaint()
                {
                    Color = SKColors.Red.WithAlpha(64), IsStroke = true
                })
                    canvas.DrawRect(paintrect, borderpaint);
            }
#endif

            return(paintrect);
        }
Beispiel #14
0
        protected virtual void GraphData(float padding, List <IGraphItem> graphItems, float xPos, float yPos, double minimum, List <IDataPoint> dataPoints, float labelWidth, float graphHeight, float pointWidth, double minimumGraphValue, double maximumGraphValue, List <decimal> vValues, float ySectionHeight, float zeroYPos, float scale)
        {
            for (var iLine = 0; iLine < ViewModel.DataGroups[0].Lines.Count; iLine++)
            {
                SKColor lineColor = ViewModel.DataGroups[0].Lines[iLine].LineColor;
                dataPoints.Clear();
                foreach (var dataGroup in ViewModel.DataGroups)
                {
                    dataPoints.AddRange(dataGroup.Lines[iLine].DataPoints);
                }
                float xDP = xPos; // Essentially, this is X zero for graph on the canvas!
                float yDP = -1;
                float lastXdp;
                float lastYdp;

                double     range             = maximumGraphValue - minimumGraphValue;
                IDataPoint previousDataPoint = null;
                foreach (var dataPoint in dataPoints)
                {
                    if (yDP == -1 || !dataPoint.Value.HasValue) // First data point or current data point does not have a value.
                    {
                        yDP = graphHeight - Convert.ToSingle(graphHeight * (dataPoint.Value - minimumGraphValue) / range);
                        if (yDP != -1 && !dataPoint.Value.HasValue)
                        {
                            xDP += pointWidth;
                        }
                    }
                    else
                    {
                        lastXdp = xDP;
                        lastYdp = yDP;
                        xDP    += pointWidth;
                        yDP     = graphHeight - Convert.ToSingle(graphHeight * (dataPoint.Value - minimumGraphValue) / range);
                        GraphLine graphLine = new GraphLine
                        {
                            Color       = lineColor,
                            StrokeWidth = 3,
                            XPosStart   = lastXdp,
                            YPosStart   = yPos + padding + lastYdp,
                            XPosEnd     = xDP,
                            YPosEnd     = yPos + padding + yDP
                        };
                        if (previousDataPoint != null && previousDataPoint.Value.HasValue) // If previous data point exists, but is null, then skip drawing line
                        {
                            graphItems.Add(graphLine);
                        }
                        var lineDataPoint = dataPoint as LineDataPoint;
                        if (lineDataPoint != null && lineDataPoint.CircleType != CircleType.None)
                        {
                            float strokeWidth = 3;
                            graphItems.Add(new GraphCircle
                            {
                                Color       = dataPoint.Color != null ? dataPoint.Color.Value : lineColor,
                                XPos        = graphLine.XPosEnd,
                                YPos        = graphLine.YPosEnd,
                                Radius      = lineDataPoint.CircleRadius * scale,
                                PaintStyle  = SKPaintStyle.Fill,
                                StrokeWidth = strokeWidth,
                            });
                            if (lineDataPoint.CircleType == CircleType.Donut)
                            {
                                graphItems.Add(new GraphCircle
                                {
                                    Color       = ViewModel.BackgroundColor.HasValue ? ViewModel.BackgroundColor.Value : SKColors.White,
                                    XPos        = graphLine.XPosEnd,
                                    YPos        = graphLine.YPosEnd,
                                    Radius      = (lineDataPoint.CircleRadius - strokeWidth) * scale,
                                    PaintStyle  = SKPaintStyle.Fill,
                                    StrokeWidth = strokeWidth,
                                });
                            }
                        }
                        if (dataPoint.Label != null)
                        {
                            graphItems.Add(new GraphText
                            {
                                Alignment = dataPoint.Label.TextAlignment,
                                Color     = dataPoint.Label.Color,
                                PointSize = dataPoint.Label.PointSize * scale,
                                Text      = dataPoint.Label.Text,
                                XPos      = xDP + dataPoint.Label.XOffSet * scale,
                                YPos      = yPos + padding + yDP + dataPoint.Label.YOffSet * scale,
                                Bold      = dataPoint.Label.Bold
                            });
                        }
                    }
                    if (dataPoint.IndicatorLine)
                    {
                        SKColor color;
                        if (ViewModel.VerticalLineColor.HasValue)
                        {
                            color = ViewModel.VerticalLineColor.Value;
                        }
                        else if (ViewModel.HorizontalBottomLineColor.HasValue)
                        {
                            color = ViewModel.HorizontalBottomLineColor.Value;
                        }
                        else if (ViewModel.HorizontalLineColor.HasValue)
                        {
                            color = ViewModel.HorizontalLineColor.Value;
                        }
                        else
                        {
                            color = SKColors.Black;
                        }
                        graphItems.Add(new GraphLine
                        {
                            Color       = color,
                            StrokeWidth = 2,
                            XPosStart   = xDP,
                            YPosStart   = yPos + graphHeight + padding,
                            XPosEnd     = xDP,
                            YPosEnd     = yPos + graphHeight + padding + ViewModel.InidicatorLineLength * scale
                        });
                    }
                    previousDataPoint = dataPoint;
                }
            }
        }
Beispiel #15
0
        public static SKColor[] CreatePalette(int N, int BandSize, int?Seed, ScriptNode Node)
        {
            if (N <= 0)
            {
                throw new ScriptRuntimeException("N in RandomLinearRGB(N[,BandSize]) has to be positive.", Node);
            }

            if (BandSize <= 0)
            {
                throw new ScriptRuntimeException("BandSize in RandomLinearRGB(N[,BandSize]) has to be positive.", Node);
            }

            SKColor[] Result = new SKColor[N];
            int       R1, G1, B1;
            int       R2, G2, B2;
            int       R, G, B;
            int       i, j, c, d;
            int       BandSize2 = BandSize / 2;
            Random    Generator;

            if (Seed.HasValue)
            {
                Generator = new Random(Seed.Value);
            }
            else
            {
                Generator = gen;
            }

            lock (Generator)
            {
                R2 = Generator.Next(256);
                G2 = Generator.Next(256);
                B2 = Generator.Next(256);

                i = 0;
                while (i < N)
                {
                    R1 = R2;
                    G1 = G2;
                    B1 = B2;

                    R2 = Generator.Next(256);
                    G2 = Generator.Next(256);
                    B2 = Generator.Next(256);

                    c = BandSize;
                    j = N - i;
                    if (c > j)
                    {
                        c = j;
                    }

                    d = N - i;
                    if (d > c)
                    {
                        d = c;
                    }

                    for (j = 0; j < d; j++)
                    {
                        R = ((R2 * j) + (R1 * (BandSize - j)) + BandSize2) / BandSize;
                        G = ((G2 * j) + (G1 * (BandSize - j)) + BandSize2) / BandSize;
                        B = ((B2 * j) + (B1 * (BandSize - j)) + BandSize2) / BandSize;

                        if (R > 255)
                        {
                            R = 255;
                        }

                        if (G > 255)
                        {
                            G = 255;
                        }

                        if (B > 255)
                        {
                            B = 255;
                        }

                        Result[i++] = new SKColor((byte)R, (byte)G, (byte)B);
                    }
                }
            }

            return(Result);
        }
Beispiel #16
0
        public All_Reports()
        {
            InitializeComponent();
            ExpensesDatabaseController expenses = new ExpensesDatabaseController();
            IncomeDabataseController   income   = new IncomeDabataseController();
            List <Entry> entries = new List <Entry>
            {
                new Entry(Convert.ToSingle(expenses.Total(1, DateTime.Now.Year)))
                {
                    Color      = SKColor.Parse("#FF0000"),
                    Label      = "January",
                    ValueLabel = expenses.Total(1, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(income.Total(1, DateTime.Now.Year)))
                {
                    Color = SKColor.Parse("#008000"),

                    ValueLabel = income.Total(1, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(expenses.Total(2, DateTime.Now.Year)))
                {
                    Color      = SKColor.Parse("#FF0000"),
                    Label      = "February",
                    ValueLabel = expenses.Total(2, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(income.Total(2, DateTime.Now.Year)))
                {
                    Color = SKColor.Parse("#008000"),

                    ValueLabel = income.Total(2, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(expenses.Total(3, DateTime.Now.Year)))
                {
                    Color      = SKColor.Parse("#FF0000"),
                    Label      = "March",
                    ValueLabel = expenses.Total(3, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(income.Total(3, DateTime.Now.Year)))
                {
                    Color = SKColor.Parse("#008000"),

                    ValueLabel = income.Total(3, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(expenses.Total(4, DateTime.Now.Year)))
                {
                    Color      = SKColor.Parse("#FF0000"),
                    Label      = "April",
                    ValueLabel = expenses.Total(4, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(income.Total(4, DateTime.Now.Year)))
                {
                    Color = SKColor.Parse("#008000"),

                    ValueLabel = income.Total(4, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(expenses.Total(5, DateTime.Now.Year)))
                {
                    Color      = SKColor.Parse("#FF0000"),
                    Label      = "May",
                    ValueLabel = expenses.Total(5, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(income.Total(5, DateTime.Now.Year)))
                {
                    Color = SKColor.Parse("#008000"),

                    ValueLabel = income.Total(5, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(expenses.Total(6, DateTime.Now.Year)))
                {
                    Color      = SKColor.Parse("#FF0000"),
                    Label      = "June",
                    ValueLabel = expenses.Total(6, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(income.Total(6, DateTime.Now.Year)))
                {
                    Color = SKColor.Parse("#008000"),

                    ValueLabel = income.Total(6, DateTime.Now.Year).ToString()
                },

                new Entry(Convert.ToSingle(expenses.Total(7, DateTime.Now.Year)))
                {
                    Color      = SKColor.Parse("#FF0000"),
                    Label      = "July",
                    ValueLabel = expenses.Total(7, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(income.Total(7, DateTime.Now.Year)))
                {
                    Color = SKColor.Parse("#008000"),

                    ValueLabel = income.Total(7, DateTime.Now.Year).ToString()
                },

                new Entry(Convert.ToSingle(expenses.Total(8, DateTime.Now.Year)))
                {
                    Color      = SKColor.Parse("#FF0000"),
                    Label      = "August",
                    ValueLabel = expenses.Total(8, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(income.Total(8, DateTime.Now.Year)))
                {
                    Color = SKColor.Parse("#008000"),

                    ValueLabel = income.Total(8, DateTime.Now.Year).ToString()
                },

                new Entry(Convert.ToSingle(expenses.Total(9, DateTime.Now.Year)))
                {
                    Color      = SKColor.Parse("#FF0000"),
                    Label      = "September",
                    ValueLabel = expenses.Total(9, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(income.Total(9, DateTime.Now.Year)))
                {
                    Color = SKColor.Parse("#008000"),

                    ValueLabel = income.Total(9, DateTime.Now.Year).ToString()
                },

                new Entry(Convert.ToSingle(expenses.Total(10, DateTime.Now.Year)))
                {
                    Color      = SKColor.Parse("#FF0000"),
                    Label      = "October",
                    ValueLabel = expenses.Total(10, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(income.Total(10, DateTime.Now.Year)))
                {
                    Color = SKColor.Parse("#008000"),

                    ValueLabel = income.Total(10, DateTime.Now.Year).ToString()
                },

                new Entry(Convert.ToSingle(expenses.Total(11, DateTime.Now.Year)))
                {
                    Color      = SKColor.Parse("#FF0000"),
                    Label      = "November",
                    ValueLabel = expenses.Total(11, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(income.Total(11, DateTime.Now.Year)))
                {
                    Color = SKColor.Parse("#008000"),

                    ValueLabel = income.Total(11, DateTime.Now.Year).ToString()
                },


                new Entry(Convert.ToSingle(expenses.Total(12, DateTime.Now.Year)))
                {
                    Color      = SKColor.Parse("#FF0000"),
                    Label      = "Decemeber",
                    ValueLabel = expenses.Total(12, DateTime.Now.Year).ToString()
                },
                new Entry(Convert.ToSingle(income.Total(12, DateTime.Now.Year)))
                {
                    Color = SKColor.Parse("#008000"),

                    ValueLabel = income.Total(12, DateTime.Now.Year).ToString()
                }
            };

            //list income
            //List<Entry> entriesIncome = new List<Entry>
            //{
            //     new Entry(Convert.ToSingle(income.Total(1,DateTime.Now.Year)))
            //     {
            //        Color = SKColor.Parse("#228B22"),
            //        Label ="January",
            //        ValueLabel =income.Total(1,DateTime.Now.Year).ToString()
            //    },
            //    new Entry(Convert.ToSingle(income.Total(2,DateTime.Now.Year)))
            //     {
            //        Color = SKColor.Parse("#530023"),
            //        Label ="February",
            //        ValueLabel =income.Total(2,DateTime.Now.Year).ToString()
            //    },
            //      new Entry(Convert.ToSingle(income.Total(3,DateTime.Now.Year)))
            //     {
            //        Color = SKColor.Parse("#f15277"),
            //        Label ="March",
            //        ValueLabel =income.Total(3,DateTime.Now.Year).ToString()
            //    },
            //    new Entry(Convert.ToSingle(income.Total(4,DateTime.Now.Year)))
            //     {
            //        Color = SKColor.Parse("#551a8b"),
            //        Label ="April",
            //        ValueLabel =income.Total(4,DateTime.Now.Year).ToString()
            //    },
            //      new Entry(Convert.ToSingle(income.Total(5,DateTime.Now.Year)))
            //     {
            //        Color = SKColor.Parse("#7face8"),
            //        Label ="May",
            //        ValueLabel =income.Total(5,DateTime.Now.Year).ToString()
            //    },
            //    new Entry(Convert.ToSingle(income.Total(6,DateTime.Now.Year)))
            //     {
            //        Color = SKColor.Parse("#ab82ff"),
            //        Label ="June",
            //        ValueLabel =income.Total(6,DateTime.Now.Year).ToString()
            //    },
            //      new Entry(Convert.ToSingle(income.Total(7,DateTime.Now.Year)))
            //     {
            //        Color = SKColor.Parse("#00cc66"),
            //        Label ="July",
            //        ValueLabel =income.Total(7,DateTime.Now.Year).ToString()
            //    },
            //    new Entry(Convert.ToSingle(income.Total(8,DateTime.Now.Year)))
            //     {
            //        Color = SKColor.Parse("#d01679"),
            //        Label ="August",
            //        ValueLabel =income.Total(8,DateTime.Now.Year).ToString()
            //    },
            //      new Entry(Convert.ToSingle(income.Total(9,DateTime.Now.Year)))
            //     {
            //        Color = SKColor.Parse("#6464b6"),
            //        Label ="September",
            //        ValueLabel =income.Total(9,DateTime.Now.Year).ToString()
            //    },
            //    new Entry(Convert.ToSingle(income.Total(10,DateTime.Now.Year)))
            //     {
            //        Color = SKColor.Parse("#d4e3ff"),
            //        Label ="October",
            //        ValueLabel =income.Total(10,DateTime.Now.Year).ToString()
            //    },
            //      new Entry(Convert.ToSingle(income.Total(11,DateTime.Now.Year)))
            //     {
            //        Color = SKColor.Parse("#f22232"),
            //        Label ="November",
            //        ValueLabel =income.Total(11,DateTime.Now.Year).ToString()
            //    },
            //    new Entry(Convert.ToSingle(income.Total(12,DateTime.Now.Year)))
            //     {
            //        Color = SKColor.Parse("#241707"),
            //        Label ="Decemeber",
            //        ValueLabel =income.Total(12,DateTime.Now.Year).ToString()
            //    },
            //};


            Chart1.Chart = new BarChart {
                Entries = entries
            };                                                //from the xaml end
        }
Beispiel #17
0
        public SKBitmap A(List <Section> sections, Dictionary <Section, BitmapData> bitmaps)
        {
            int width  = 0;
            int height = 250;

            bitmaps.Values.ToList().ForEach(b =>
            {
                if (b.Width > width)
                {
                    width = b.Width;
                }

                height += b.Height;
            });

            var merge = new SKBitmap(width, height);

            using (var c = new SKCanvas(merge))
            {
                int y = 0;

                using (var paint = new SKPaint
                {
                    IsAntialias = true,
                    FilterQuality = SKFilterQuality.High,
                    Color = SKColor.Parse("#e7accb")//new SKColor(40, 40, 40)
                }) c.DrawRect(0, 0, merge.Width, merge.Height, paint);

                sections.ToList().ForEach(section =>
                {
                    var bitmapData = bitmaps.First(predicate: x => x.Key.SectionId == section.SectionId).Value;

                    using (var bitmap = LoadFromCache(bitmapData))
                    {
                        c.DrawBitmap(bitmap, 0, y);
                        y += bitmap.Height;
                    }

                    GC.Collect();
                    ;
                });

                using (var textPaint = new SKPaint
                {
                    IsAntialias = true,
                    FilterQuality = SKFilterQuality.High,
                    TextSize = (int)(ChicRatios.Get1024(150) * EntryHeight),
                    Color = SKColors.White,
                    Typeface = ChicTypefaces.BurbankBigRegularBlack,
                    ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 10, 10, SKColors.Black)
                })
                {
                    var sacText   = "Code 'Chic'\n#Ad";
                    int textWidth = (int)textPaint.MeasureText(sacText);

                    int left   = (merge.Width - textWidth) / 2;
                    int top    = merge.Height - (int)(ChicRatios.Get1024(150) * EntryHeight * 2);
                    int right  = left + textWidth;
                    int bottom = merge.Height - (int)(ChicRatios.Get1024(150) * EntryHeight);

                    ChicText.DrawMultilineText(c, sacText, new SKRect(left, top, right, bottom), textPaint);

                    sacText = "";
                }

                using (var shadow = new SKPaint
                {
                    IsAntialias = true,
                    FilterQuality = SKFilterQuality.High,
                    ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 10, 10, SKColors.Black)
                })
                {
                    using (var heart = SKBitmap.Decode($"{Root}Resources/heartTopLeft.png"))
                    {
                        c.DrawBitmap(heart, 0, 0, shadow);
                    }

                    using (var hearts = SKBitmap.Decode($"{Root}Resources/heartsBottomRight.png"))
                    {
                        c.DrawBitmap(hearts, merge.Width - hearts.Width, merge.Height - hearts.Height, shadow);
                    }
                }
            }

            sections = null;
            bitmaps  = null;

            return(merge);
        }
        private void UpdatePaint()
        {
            if (_brush.Properties.ColorMode.CurrentValue == ColorType.Random && Paint == null)
            {
                Paint = new SKPaint {
                    Color = SKColor.FromHsv(_brush.Rand.Next(0, 360), 100, 100)
                };
            }
            else if (_brush.Properties.ColorMode.CurrentValue == ColorType.Solid)
            {
                Paint?.Dispose();
                Paint = new SKPaint {
                    Color = _brush.Properties.Color.CurrentValue
                };
            }
            else if (_brush.Properties.ColorMode.CurrentValue == ColorType.Gradient)
            {
                Paint?.Dispose();
                Paint = new SKPaint
                {
                    Shader = SKShader.CreateRadialGradient(
                        Position,
                        _brush.Properties.RippleWidth,
                        _brush.Properties.Colors.BaseValue.GetColorsArray(),
                        _brush.Properties.Colors.BaseValue.GetPositionsArray(),
                        // Changed from Clamp to repeat. It just looks a lot better this way.
                        // Repeat will need a color position calculation by the way to get the inner ripple color ir order to paint the Trail.
                        SKShaderTileMode.Repeat
                        )
                };
            }
            else if (_brush.Properties.ColorMode.CurrentValue == ColorType.ColorChange)
            {
                Paint?.Dispose();
                Paint = new SKPaint {
                    Color = _brush.Properties.Colors.CurrentValue.GetColor(_progress)
                };
            }

            byte alpha = 255;

            // Add fade away effect
            if (_brush.Properties.RippleFadeAway != RippleFadeOutMode.None)
            {
                alpha = (byte)(255d * Easings.Interpolate(1f - _progress, (Easings.Functions)_brush.Properties.RippleFadeAway.CurrentValue));
            }

            // If we have to paint a trail
            if (_brush.Properties.RippleTrail)
            {
                // Moved trail color calculation here to avoid extra overhead when trail is not enabled
                _trailColor = _brush.Properties.ColorMode.CurrentValue switch
                {
                    // If gradient is used, calculate the inner color to a given position.
                    ColorType.Gradient => _brush.Properties.Colors.CurrentValue.GetColor((Size - _brush.Properties.RippleWidth / 2f) % _brush.Properties.RippleWidth / _brush.Properties.RippleWidth),
                    // If not gradient, we can just copy the color of the ripple Paint.
                    _ => Paint.Color
                };

                // Dispose before to create a new one. Thanks for the lesson.
                _trailPaint?.Dispose();
                _trailPaint = new SKPaint
                {
                    Shader = SKShader.CreateRadialGradient(
                        Position,
                        Size,
                        // Trail is simply a gradient from full inner ripple color to the same color but with alpha 0. Just an illution :D
                        new[] { _trailColor.WithAlpha(0), _trailColor.WithAlpha(alpha) },
                        new[] { 0f, 1f },
                        SKShaderTileMode.Clamp
                        )
                };
                _trailPaint.Style = SKPaintStyle.Fill;
            }

            // Set ripple size and final color alpha
            Paint.Color       = Paint.Color.WithAlpha(alpha);
            Paint.Style       = SKPaintStyle.Stroke;
            Paint.StrokeWidth = _brush.Properties.RippleWidth.CurrentValue;
        }
Beispiel #19
0
        /// <summary>
        /// Draws a block of text onto the document and returns the height of that block.
        /// </summary>
        /// <param name="canvas">The skia canvas to draw onto.</param>
        /// <param name="text">The text to be printed onto the document.</param>
        /// <param name="y">The y position of the text block.</param>
        /// <param name="typeface">The font to be used for drawing the text.</param>
        /// <param name="textSize">The size of the text.</param>
        /// <param name="color">The color to be used for drawing the text.</param>
        /// <param name="textAlign">The alignment for the text to be drawn.</param>
        /// <param name="lineHeightFactor">A value indicating the line heigt. The default line heigt factor is 1.</param>
        /// <returns>Returns the height of the text block which was drawn to the document.</returns>
        private static float DrawTextBlock(SKCanvas canvas, string text, float y, SKTypeface typeface, float textSize,
                                           SKColor color, SKTextAlign textAlign = SKTextAlign.Center, float lineHeightFactor = 1.0f)
        {
            List <string> lineBreakSequences = new List <string>()
            {
                "\r", "\n", "\r\n"
            };

            using (var paint = new SKPaint())
            {
                paint.Typeface    = typeface;
                paint.TextSize    = textSize;
                paint.IsAntialias = true;
                paint.Color       = color;
                paint.TextAlign   = textAlign;

                float blockWidth = PAGE_WIDTH - (MARGIN_LEFT * 2);

                // Define x position according to chosen text alignment
                float xPos = 0f;
                switch (textAlign)
                {
                case SKTextAlign.Left:
                    xPos = MARGIN_LEFT;
                    break;

                case SKTextAlign.Center:
                    xPos = PAGE_WIDTH / 2;
                    break;

                case SKTextAlign.Right:
                    xPos = PAGE_WIDTH - MARGIN_LEFT;
                    break;
                }

                // Measure the height of one line of text
                SKRect bounds = new SKRect();
                paint.MeasureText(text, ref bounds);
                float lineHeight = bounds.Height * lineHeightFactor;

                // Now loop through all the tokens and build the
                // text block, adding new lines when we're either
                // out of space or when a newline if forced in the
                // token list.
                int           lines  = 1;
                StringBuilder line   = new StringBuilder();
                var           tokens = Tokenize(text);

                for (int i = 0; i < tokens.Count; i++)
                {
StartLine:
                    var token = tokens[i];
                    float totalLineWidth = 0;

                    if (token != null && token != "")
                    {
                        totalLineWidth = line.Length > 0 ?
                                         paint.MeasureText(line + " " + token) :
                                         paint.MeasureText(token);
                    }

                    if (totalLineWidth >= blockWidth || token == null)
                    {
                        canvas.DrawText(line.ToString(), xPos, y, paint);
                        line.Clear();
                        lines++;
                        y += lineHeight;
                        if (token != null)
                        {
                            goto StartLine;
                        }
                    }
                    else
                    {
                        if (line.Length != 0)
                        {
                            line.Append(" ");
                        }
                        line.Append(token);

                        if (i == tokens.Count - 1) // Last word
                        {
                            canvas.DrawText(line.ToString(), xPos, y, paint);
                            line.Clear();
                            lines++;
                            y += lineHeight;
                        }
                    }
                }

                // Return the total height of the text block
                return(lines * lineHeight);
            }
        }
Beispiel #20
0
 public static SKColor Copy(this SKColor c)
 {
     return(new SKColor(c.Red, c.Green, c.Blue, c.Alpha));
 }
 private void AddPartPartEntityContainer(SKCanvas canvas, SKPath pathBuilder, PartEntityContainer partEntityContainer, Vector2 position, SKColor textColor, SKColor lineColor)
 {
     foreach (PartEntity entity in partEntityContainer.Entities)
     {
         if (entity is PartEntityText)
         {
             AddText(canvas, (PartEntityText)entity, position, textColor);
         }
         if (entity is PartEntityLine)
         {
             AddLine(canvas, pathBuilder, (PartEntityLine)entity, position, lineColor, true, true);
         }
     }
 }
Beispiel #22
0
 public static float GetSaturation(this SKColor col)
 {
     col.ToHsv(out float h, out float s, out float b);
     return(s);
 }
        private Vector2 AddLine(SKCanvas canvas, SKPath pathBuilder, PartEntityLine entity, Vector2 position, SKColor lineColor,
                                bool showConstruction, bool showSA)
        {
            Vector2 start = new Vector2(Scale(entity.Start.X) + position.X, Scale(entity.Start.Y) + position.Y);
            Vector2 end   = new Vector2(Scale(entity.End.X) + position.X, Scale(entity.End.Y) + position.Y);

            if (entity.EntityType == EntityType.Normal)
            {
                pathBuilder.LineTo(end.X, end.Y);
            }
            else
            {
                bool draw = true;
                if ((entity.EntityType == EntityType.Construction || entity.EntityType == EntityType.PerpConstruction) && !showConstruction)
                {
                    draw = false;
                }
                if ((entity.EntityType == EntityType.SA || entity.EntityType == EntityType.HA) && !showSA)
                {
                    draw = false;
                }

                if (draw)
                {
                    using (var paint = new SKPaint())
                    {
                        paint.IsAntialias = true;
                        paint.Color       = lineColor;
                        paint.IsStroke    = true;
                        paint.StrokeWidth = 1;
                        canvas.DrawLine(ToP(start), ToP(end), paint);
                    }
                }
            }
            return(entity.End);
        }
Beispiel #24
0
 public static float GetValue(this SKColor col)
 {
     col.ToHsv(out float h, out float s, out float b);
     return(b);
 }
Beispiel #25
0
 public Task LightText()
 {
     this.Animate("LightText", p => TextColor = new SKColor(255, 255, 255, (byte)p), 0, 255, 8, (uint)_animationMs,
                  Easing.CubicInOut);
     return(Task.Delay(_animationMs));
 }
        public MasterDetailPage1Detail()
        {
            InitializeComponent();
            _connection = DependencyService.Get <ISQLiteDb>().GetConnection();
            Baza();
            stack.BackgroundColor = Color.FromHex("#1FAECE");

            //var norma = (_connection.QueryAsync<int>("SELECT Value FROM Glukoza", list).ConfigureAwait(false))
            List <int> maslo = new List <int> {
                72, 79, 82, 75, 78, 74, 85, 83, 78, 73, 82, 71, 70, 76, 81
            };
            List <Entry> entries2 = new List <Entry>();

            foreach (var number in maslo)
            {
                string color;
                if (number < 80)
                {
                    color = "#1faece";
                }
                else
                {
                    color = "#F17A0A";
                }

                var zmienna = new Entry(number)
                {
                    Color      = SKColor.Parse(color),
                    Label      = Convert.ToString("22-01-2017"),
                    ValueLabel = Convert.ToString(number),
                };
                entries2.Add(zmienna);
            }

            myChart.Chart = new LineChart()
            {
                Entries = entries2, PointMode = PointMode.Square, AnimationDuration = TimeSpan.FromSeconds(10)
            };

            List <float> maslo2 = new List <float> {
                2.3f, 3.3f, 2.5f, 0f, 2.4f, 2.1f, 2.8f, 2.7f, 2.1f, 2.9f, 1.2f, 3.1f, 2.5f, 2.3f
            };
            List <Entry> entries3 = new List <Entry>();

            foreach (var number in maslo2)
            {
                string color;
                if (number < 3)
                {
                    color = "#1faece";
                }
                else
                {
                    color = "#F17A0A";
                }

                var zmienna = new Entry(number)
                {
                    Color      = SKColor.Parse(color),
                    Label      = Convert.ToString("22-01-2017"),
                    ValueLabel = Convert.ToString(number),
                };
                entries3.Add(zmienna);
            }

            myChart2.Chart = new BarChart()
            {
                Entries = entries3, AnimationDuration = TimeSpan.FromSeconds(10)
            };

            List <int> maslo3 = new List <int> {
                2950, 3121, 2920, 3100, 2850, 2912, 2750, 3100, 3060, 2750, 2950
            };
            List <Entry> entries4 = new List <Entry>();

            foreach (var number in maslo3)
            {
                string color;
                if (number < 3000)
                {
                    color = "#1faece";
                }
                else
                {
                    color = "#F17A0A";
                }

                var zmienna = new Entry(number)
                {
                    Color      = SKColor.Parse(color),
                    Label      = Convert.ToString("22-01-2017"),
                    ValueLabel = Convert.ToString(number),
                };
                entries4.Add(zmienna);
            }

            myChart3.Chart = new RadarChart()
            {
                Entries = entries4, AnimationProgress = 12.2F, AnimationDuration = TimeSpan.FromSeconds(10)
            };

            List <float> maslo4 = new List <float> {
                21.5f, 22.0f, 20.3f, 22.1f, 22.5f, 21.9f, 21.6f, 22.0f, 20.9f
            };
            List <Entry> entries5 = new List <Entry>();

            foreach (var number in maslo4)
            {
                string color;
                if (number < 3000)
                {
                    color = "#1faece";
                }
                else
                {
                    color = "#F17A0A";
                }

                var zmienna = new Entry(number)
                {
                    Color      = SKColor.Parse(color),
                    Label      = Convert.ToString("22-01-2017"),
                    ValueLabel = Convert.ToString(number),
                };
                entries5.Add(zmienna);
            }

            myChart5.Chart = new BarChart()
            {
                Entries = entries5, AnimationDuration = TimeSpan.FromSeconds(10)
            };
        }
Beispiel #27
0
        public SSRReports(object obj)
        {
            InitializeComponent();

            var result = obj as IncentiveReport;

            lblEmpName.Text = result.EmpName;

            entries.Add(new Entry(Convert.ToInt64(result.Basic_Salary))
            {
                Label      = result.Basic_Salary,
                TextColor  = SKColor.Parse("#54d25b"),
                Color      = SKColor.Parse("#54d25b"),
                ValueLabel = "Basic Salary",
            });
            entries.Add(new Entry(Convert.ToInt64(result.Cash_Discount))
            {
                Label      = result.Cash_Discount,
                TextColor  = SKColor.Parse("#3dbac5"),
                Color      = SKColor.Parse("#3dbac5"),
                ValueLabel = "Cash Discount"
            });
            entries.Add(new Entry(Convert.ToInt64(result.Cheque_Bounce))
            {
                Label      = result.Cheque_Bounce,
                TextColor  = SKColor.Parse("#f6841b"),
                Color      = SKColor.Parse("#f6841b"),
                ValueLabel = "Cheque Bounce"
            });
            entries.Add(new Entry(Convert.ToInt64(result.Credit_Note))
            {
                Label      = result.Credit_Note,
                TextColor  = SKColor.Parse("#fb727e"),
                Color      = SKColor.Parse("#fb727e"),
                ValueLabel = "Credit Note"
            });
            entries.Add(new Entry(Convert.ToInt64(result.Receipt))
            {
                Label      = result.Receipt,
                TextColor  = SKColor.Parse("#dd3434"),
                Color      = SKColor.Parse("#dd3434"),
                ValueLabel = "Receipt"
            });
            //entries.Add(new Entry(Convert.ToInt64(result.Salary_Incentive))
            //{
            //    Label = "Salary Incentive",
            //    TextColor = SKColor.Parse("#266489"),
            //    Color = SKColor.Parse("#266489"),
            //    ValueLabel = result.Salary_Incentive
            //});
            entries.Add(new Entry(Convert.ToInt64(result.Spacial_Discount))
            {
                Label      = result.Spacial_Discount,
                TextColor  = SKColor.Parse("#fc616f"),
                Color      = SKColor.Parse("#fc616f"),
                ValueLabel = "Spacial Discount"
            });
            //entries.Add(new Entry(Convert.ToInt64(result.Total_Incentive))
            //{
            //    Label = "Total Incentive",
            //    TextColor = SKColor.Parse("#fc616f"),
            //    Color = SKColor.Parse("#fc616f"),
            //    ValueLabel = result.Total_Incentive
            //});
            entries.Add(new Entry(Convert.ToInt64(result.Total_Receipts))
            {
                Label      = result.Total_Receipts,
                TextColor  = SKColor.Parse("#05aded"),
                Color      = SKColor.Parse("#05aded"),
                ValueLabel = "Total Receipts"
            });
            //var chart = new LineChart() { Entries = entries, LineMode = LineMode.Spline, LabelTextSize = 20};
            var chart = new BarChart()
            {
                Entries = entries
            };

            this.chartView.Chart = chart;
        }
Beispiel #28
0
        public async void GetSkillsData(string country)
        {
            using (var client = new HttpClient())
            {
                if (country == "USA")
                {
                    country = "usa";
                }
                // send a GET request
                var uri    = "https://corona.lmao.ninja/v2/historical/" + country;
                var result = await client.GetStringAsync(uri);

                result = result.Replace("}", "");
                //result = result.Substring(44, result.Length - 47).ToString();
                string[] s      = result.Split(',');
                int      index  = 0;
                int      rIndex = 0;
                for (int i = 0; i < s.Length; i++)
                {
                    if (s[i].Contains("deaths"))
                    {
                        index = i;
                        break;
                    }
                }

                for (int i = 0; i < s.Length; i++)
                {
                    if (s[i].Contains("recovered"))
                    {
                        rIndex = i;
                        break;
                    }
                }

                // char[] MyChar = { '"', '{', '}' };
                //result = result.TrimEnd(MyChar);

                // result = result.Remove('"');
                string[] date           = new string[10];
                string[] value          = new string[10];
                string[] deathDate      = new string[10];
                string[] deatthValue    = new string[10];
                string[] recoveredDate  = new string[10];
                string[] recoveredValue = new string[10];
                int      c = 0;
                for (int i = index - 11; i < index - 1; i++)
                {
                    string[] m = s[i].Split(':');
                    string[] n = s[i + 1].Split(':');
                    date[c]  = (n[0]);
                    value[c] = (Convert.ToInt32(n[1]) - Convert.ToInt32(m[1])).ToString();
                    c++;
                }
                c = 0;
                for (int i = rIndex - 11; i < rIndex - 1; i++)
                {
                    string[] m = s[i].Split(':');
                    string[] n = s[i + 1].Split(':');
                    deathDate[c]   = (n[0]);
                    deatthValue[c] = (Convert.ToInt32(n[1]) - Convert.ToInt32(m[1])).ToString();
                    c++;
                }
                c = 0;
                for (int i = s.Length - 11; i < s.Length - 1; i++)
                {
                    string[] m = s[i].Split(':');
                    string[] n = s[i + 1].Split(':');
                    recoveredDate[c]  = (n[0]);
                    recoveredValue[c] = (Convert.ToInt32(n[1]) - Convert.ToInt32(m[1])).ToString();
                    c++;
                }

                List <Entry> entries = new List <Entry>
                {
                };
                List <Entry> deathData = new List <Entry>
                {
                };
                List <Entry> recoveredData = new List <Entry>
                {
                };
                for (int i = 0; i < date.Length; i++)
                {
                    if (i % 2 == 0)
                    {
                        entries.Add(new Entry(Convert.ToInt32(value[i]))
                        {
                            Color      = SKColor.Parse("#FF1943"),
                            Label      = date[i].Replace('"', ' '),
                            ValueLabel = value[i],
                        });
                    }
                    else
                    {
                        entries.Add(new Entry(Convert.ToInt32(value[i]))
                        {
                            Color      = SKColor.Parse("#68B9C0"),
                            Label      = date[i].Replace('"', ' '),
                            ValueLabel = value[i],
                        });
                    }
                }
                for (int i = 0; i < deathDate.Length; i++)
                {
                    if (i % 2 == 0)
                    {
                        deathData.Add(new Entry(Convert.ToInt32(deatthValue[i]))
                        {
                            Color      = SKColor.Parse("#FF1943"),
                            Label      = date[i].Replace('"', ' '),
                            ValueLabel = deatthValue[i],
                        });
                    }
                    else
                    {
                        deathData.Add(new Entry(Convert.ToInt32(deatthValue[i]))
                        {
                            Color      = SKColor.Parse("#68B9C0"),
                            Label      = deathDate[i].Replace('"', ' '),
                            ValueLabel = deatthValue[i],
                        });
                    }
                }
                for (int i = 0; i < recoveredDate.Length; i++)
                {
                    if (i % 2 == 0)
                    {
                        recoveredData.Add(new Entry(Convert.ToInt32(recoveredValue[i]))
                        {
                            Color      = SKColor.Parse("#FF1943"),
                            Label      = recoveredDate[i].Replace('"', ' '),
                            ValueLabel = recoveredValue[i],
                        });
                    }
                    else
                    {
                        recoveredData.Add(new Entry(Convert.ToInt32(recoveredValue[i]))
                        {
                            Color      = SKColor.Parse("#68B9C0"),
                            Label      = recoveredDate[i].Replace('"', ' '),
                            ValueLabel = recoveredValue[i],
                        });
                    }
                }
                Chart1.Chart = new LineChart()
                {
                    Entries = entries
                };
                ChartDeath.Chart = new LineChart()
                {
                    Entries = deathData
                };
                ChartRecovered.Chart = new LineChart()
                {
                    Entries = recoveredData
                };
                //_scollectionSkills = collectionSkills;
                //IsRefreshing = false;
            }
        }
Beispiel #29
0
 private static bool IsTransparent(SKColor color)
 => (color.Red == 255 && color.Green == 255 && color.Blue == 255) || color.Alpha == 0;
Beispiel #30
0
        public List <BitmapData> DrawSections(ShopV2 shop)
        {
            int maxEntriesPerRow = 6;
            var result           = new List <BitmapData>();

            maxEntriesPerRow = Math.Clamp(shop.Sections.Max(x => x.Value.Count), 0, maxEntriesPerRow);

            int th = (int)(ChicRatios.Get1024(200) * EntryHeight);
            int hf = (int)(ChicRatios.Get1024(150) * EntryHeight);
            int h  = (int)(ChicRatios.Get1024(100) * EntryHeight);
            int f  = (int)(ChicRatios.Get1024(50) * EntryHeight);

            int width = h + maxEntriesPerRow * (EntryWidth + h);

            foreach (var section in shop.Sections)
            {
                var sectionInfo = shop.SectionInfos.Find(x => x.SectionId == section.Key);
                int extraHeight = sectionInfo.HasName ? th : 0;
                int height      = extraHeight + (int)Math.Ceiling((decimal)section.Value.Count / maxEntriesPerRow) * (EntryHeight + h);

                using (SKBitmap bitmap = new SKBitmap(width, height))
                {
                    using (SKCanvas c = new SKCanvas(bitmap))
                    {
                        using (var paint = new SKPaint
                        {
                            IsAntialias = true,
                            FilterQuality = SKFilterQuality.High,
                            Color = SKColor.Parse("#e7accb")//new SKColor(40, 40, 40)
                        }) c.DrawRect(0, 0, width, height, paint);

                        int x      = f;//100;
                        int y      = extraHeight;
                        int row    = 0;
                        int column = 0;

                        for (int i = 0; i < section.Value.Count; i++)
                        {
                            var entry = section.Value[i];

                            using (var b = DrawEntry(entry) /*LoadFromCache(entry.CacheId)*/)
                            {
                                using (var paint = new SKPaint {
                                    IsAntialias = true, FilterQuality = SKFilterQuality.High
                                })
                                    c.DrawBitmap(b, x, y, paint);
                            }

                            GC.Collect();

                            if (++column == maxEntriesPerRow)
                            {
                                row++;
                                column = 0;
                                //x = 50;//100;
                            }

                            x = f + (EntryWidth + h) * column; /*+ 50*/
                            y = extraHeight + (EntryHeight + h /*+ 50*/) * row;
                        }

                        using (var paint = new SKPaint
                        {
                            IsAntialias = true,
                            FilterQuality = SKFilterQuality.High,
                            Color = SKColors.White,
                            TextSize = h,
                            Typeface = ChicTypefaces.BurbankBigRegularBlack,
                            TextAlign = SKTextAlign.Left,
                            ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 10, 10, SKColors.Black)
                        }) if (sectionInfo.HasName)
                            {
                                c.DrawText(sectionInfo.DisplayName, h, hf, paint);
                            }
                    }

                    result.Add(SaveToCache(bitmap, section.Key));
                }
            }

            return(result);
        }
		private void cacheCanvasClearColor()
		{
			_canvasClearColor = CanvasClear.ToSkia();
		}
Beispiel #32
0
        public void ColorWithComponent()
        {
            var color = new SKColor();
            Assert.AreEqual(0, color.Red);
            Assert.AreEqual(0, color.Green);
            Assert.AreEqual(0, color.Blue);
            Assert.AreEqual(0, color.Alpha);

            var red = color.WithRed(255);
            Assert.AreEqual(255, red.Red);
            Assert.AreEqual(0, red.Green);
            Assert.AreEqual(0, red.Blue);
            Assert.AreEqual(0, red.Alpha);

            var green = color.WithGreen(255);
            Assert.AreEqual(0, green.Red);
            Assert.AreEqual(255, green.Green);
            Assert.AreEqual(0, green.Blue);
            Assert.AreEqual(0, green.Alpha);

            var blue = color.WithBlue(255);
            Assert.AreEqual(0, blue.Red);
            Assert.AreEqual(0, blue.Green);
            Assert.AreEqual(255, blue.Blue);
            Assert.AreEqual(0, blue.Alpha);

            var alpha = color.WithAlpha(255);
            Assert.AreEqual(0, alpha.Red);
            Assert.AreEqual(0, alpha.Green);
            Assert.AreEqual(0, alpha.Blue);
            Assert.AreEqual(255, alpha.Alpha);
        }