UnplayedCountIndicator.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System.Globalization;
  2. using MediaBrowser.Model.Drawing;
  3. using SkiaSharp;
  4. namespace Jellyfin.Drawing.Skia
  5. {
  6. /// <summary>
  7. /// Static helper class for drawing unplayed count indicators.
  8. /// </summary>
  9. public static class UnplayedCountIndicator
  10. {
  11. /// <summary>
  12. /// The x-offset used when drawing an unplayed count indicator.
  13. /// </summary>
  14. private const int OffsetFromTopRightCorner = 38;
  15. /// <summary>
  16. /// Draw an unplayed count indicator in the top right corner of a canvas.
  17. /// </summary>
  18. /// <param name="canvas">The canvas to draw the indicator on.</param>
  19. /// <param name="imageSize">
  20. /// The dimensions of the image to draw the indicator on. The width is used to determine the x-position of the
  21. /// indicator.
  22. /// </param>
  23. /// <param name="count">The number to draw in the indicator.</param>
  24. public static void DrawUnplayedCountIndicator(SKCanvas canvas, ImageDimensions imageSize, int count)
  25. {
  26. var x = imageSize.Width - OffsetFromTopRightCorner;
  27. var text = count.ToString(CultureInfo.InvariantCulture);
  28. using var paint = new SKPaint
  29. {
  30. Color = SKColor.Parse("#CC00A4DC"),
  31. Style = SKPaintStyle.Fill
  32. };
  33. canvas.DrawCircle(x, OffsetFromTopRightCorner, 20, paint);
  34. paint.Color = new SKColor(255, 255, 255, 255);
  35. paint.TextSize = 24;
  36. paint.IsAntialias = true;
  37. var y = OffsetFromTopRightCorner + 9;
  38. if (text.Length == 1)
  39. {
  40. x -= 7;
  41. }
  42. if (text.Length == 2)
  43. {
  44. x -= 13;
  45. }
  46. else if (text.Length >= 3)
  47. {
  48. x -= 15;
  49. y -= 2;
  50. paint.TextSize = 18;
  51. }
  52. canvas.DrawText(text, x, y, paint);
  53. }
  54. }
  55. }