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.Common.IO;
  8. using MediaBrowser.Controller.IO;
  9. using MediaBrowser.Model.IO;
  10. namespace Emby.Drawing.Skia
  11. {
  12. public class UnplayedCountIndicator
  13. {
  14. private const int OffsetFromTopRightCorner = 38;
  15. private readonly IApplicationPaths _appPaths;
  16. private readonly IHttpClient _iHttpClient;
  17. private readonly IFileSystem _fileSystem;
  18. public UnplayedCountIndicator(IApplicationPaths appPaths, IHttpClient iHttpClient, IFileSystem fileSystem)
  19. {
  20. _appPaths = appPaths;
  21. _iHttpClient = iHttpClient;
  22. _fileSystem = fileSystem;
  23. }
  24. public void DrawUnplayedCountIndicator(SKCanvas canvas, ImageSize 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("#CC52B54B");
  31. paint.Style = SKPaintStyle.Fill;
  32. canvas.DrawCircle((float)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.Typeface = SKTypeface.FromFile(PlayedIndicatorDrawer.ExtractFont("robotoregular.ttf", _appPaths, _fileSystem));
  39. paint.TextSize = 24;
  40. paint.IsAntialias = true;
  41. var y = OffsetFromTopRightCorner + 9;
  42. if (text.Length == 1)
  43. {
  44. x -= 7;
  45. }
  46. if (text.Length == 2)
  47. {
  48. x -= 13;
  49. }
  50. else if (text.Length >= 3)
  51. {
  52. x -= 15;
  53. y -= 2;
  54. paint.TextSize = 18;
  55. }
  56. canvas.DrawText(text, (float)x, y, paint);
  57. }
  58. }
  59. }
  60. }