UnplayedCountIndicator.cs 2.2 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.Typeface = SKTypeface.FromFile(PlayedIndicatorDrawer.ExtractFont("robotoregular.ttf", _appPaths, _fileSystem));
  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, (float)x, y, paint);
  56. }
  57. }
  58. }
  59. }