UnplayedCountIndicator.cs 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. using System.Globalization;
  2. using MediaBrowser.Model.Drawing;
  3. using SkiaSharp;
  4. namespace Emby.Drawing
  5. {
  6. public static class UnplayedCountIndicator
  7. {
  8. private const int OffsetFromTopRightCorner = 38;
  9. public static void DrawUnplayedCountIndicator(SKCanvas canvas, ImageSize imageSize, int count)
  10. {
  11. var x = imageSize.Width - OffsetFromTopRightCorner;
  12. var text = count.ToString(CultureInfo.InvariantCulture);
  13. using (var paint = new SKPaint())
  14. {
  15. paint.Color = SKColor.Parse("#CC52B54B");
  16. paint.Style = SKPaintStyle.Fill;
  17. canvas.DrawCircle((float)x, OffsetFromTopRightCorner, 20, paint);
  18. }
  19. using (var paint = new SKPaint())
  20. {
  21. paint.Color = new SKColor(255, 255, 255, 255);
  22. paint.Style = SKPaintStyle.Fill;
  23. paint.TextSize = 24;
  24. paint.IsAntialias = true;
  25. var y = OffsetFromTopRightCorner + 9;
  26. if (text.Length == 1)
  27. {
  28. x -= 7;
  29. }
  30. if (text.Length == 2)
  31. {
  32. x -= 13;
  33. }
  34. else if (text.Length >= 3)
  35. {
  36. x -= 15;
  37. y -= 2;
  38. paint.TextSize = 18;
  39. }
  40. canvas.DrawText(text, (float)x, y, paint);
  41. }
  42. }
  43. }
  44. }