UnplayedCountIndicator.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using SkiaSharp;
  2. using MediaBrowser.Common.Configuration;
  3. using MediaBrowser.Common.Net;
  4. using MediaBrowser.Model.Drawing;
  5. using System.Globalization;
  6. using System.Threading.Tasks;
  7. using MediaBrowser.Controller.IO;
  8. using MediaBrowser.Model.IO;
  9. namespace Emby.Drawing.Skia
  10. {
  11. public class UnplayedCountIndicator
  12. {
  13. private const int OffsetFromTopRightCorner = 38;
  14. private readonly IApplicationPaths _appPaths;
  15. private readonly IHttpClient _iHttpClient;
  16. private readonly IFileSystem _fileSystem;
  17. public UnplayedCountIndicator(IApplicationPaths appPaths, IHttpClient iHttpClient, IFileSystem fileSystem)
  18. {
  19. _appPaths = appPaths;
  20. _iHttpClient = iHttpClient;
  21. _fileSystem = fileSystem;
  22. }
  23. public void DrawUnplayedCountIndicator(SKCanvas canvas, ImageSize imageSize, int count)
  24. {
  25. var x = imageSize.Width - OffsetFromTopRightCorner;
  26. var text = count.ToString(CultureInfo.InvariantCulture);
  27. using (var paint = new SKPaint())
  28. {
  29. paint.Color = SKColor.Parse("#CC52B54B");
  30. paint.Style = SKPaintStyle.Fill;
  31. canvas.DrawCircle((float)x, OffsetFromTopRightCorner, 20, paint);
  32. }
  33. using (var paint = new SKPaint())
  34. {
  35. paint.Color = new SKColor(255, 255, 255, 255);
  36. paint.Style = SKPaintStyle.Fill;
  37. paint.TextSize = 24;
  38. paint.IsAntialias = true;
  39. var y = OffsetFromTopRightCorner + 9;
  40. if (text.Length == 1)
  41. {
  42. x -= 7;
  43. }
  44. if (text.Length == 2)
  45. {
  46. x -= 13;
  47. }
  48. else if (text.Length >= 3)
  49. {
  50. x -= 15;
  51. y -= 2;
  52. paint.TextSize = 18;
  53. }
  54. canvas.DrawText(text, (float)x, y, paint);
  55. }
  56. }
  57. }
  58. }