UnplayedCountIndicator.cs 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. paint.Color = SKColor.Parse("#CC00A4DC");
  31. paint.Style = SKPaintStyle.Fill;
  32. canvas.DrawCircle(x, OffsetFromTopRightCorner, 20, paint);
  33. }
  34. using (var paint = new SKPaint())
  35. {
  36. paint.Color = new SKColor(255, 255, 255, 255);
  37. paint.Style = SKPaintStyle.Fill;
  38. paint.TextSize = 24;
  39. paint.IsAntialias = true;
  40. var y = OffsetFromTopRightCorner + 9;
  41. if (text.Length == 1)
  42. {
  43. x -= 7;
  44. }
  45. if (text.Length == 2)
  46. {
  47. x -= 13;
  48. }
  49. else if (text.Length >= 3)
  50. {
  51. x -= 15;
  52. y -= 2;
  53. paint.TextSize = 18;
  54. }
  55. canvas.DrawText(text, x, y, paint);
  56. }
  57. }
  58. }
  59. }