UnplayedCountIndicator.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using ImageMagickSharp;
  2. using MediaBrowser.Common.Configuration;
  3. using MediaBrowser.Model.Drawing;
  4. using System.Globalization;
  5. using MediaBrowser.Common.IO;
  6. using MediaBrowser.Controller.IO;
  7. using MediaBrowser.Model.IO;
  8. namespace Emby.Drawing.ImageMagick
  9. {
  10. public class UnplayedCountIndicator
  11. {
  12. private const int OffsetFromTopRightCorner = 38;
  13. private readonly IApplicationPaths _appPaths;
  14. private readonly IFileSystem _fileSystem;
  15. public UnplayedCountIndicator(IApplicationPaths appPaths, IFileSystem fileSystem)
  16. {
  17. _appPaths = appPaths;
  18. _fileSystem = fileSystem;
  19. }
  20. public void DrawUnplayedCountIndicator(MagickWand wand, ImageSize imageSize, int count)
  21. {
  22. var x = imageSize.Width - OffsetFromTopRightCorner;
  23. var text = count.ToString(CultureInfo.InvariantCulture);
  24. using (var draw = new DrawingWand())
  25. {
  26. using (PixelWand pixel = new PixelWand())
  27. {
  28. pixel.Color = "#52B54B";
  29. pixel.Opacity = 0.2;
  30. draw.FillColor = pixel;
  31. draw.DrawCircle(x, OffsetFromTopRightCorner, x - 20, OffsetFromTopRightCorner - 20);
  32. pixel.Opacity = 0;
  33. pixel.Color = "white";
  34. draw.FillColor = pixel;
  35. draw.Font = PlayedIndicatorDrawer.ExtractFont("robotoregular.ttf", _appPaths, _fileSystem);
  36. draw.FontStyle = FontStyleType.NormalStyle;
  37. draw.TextAlignment = TextAlignType.CenterAlign;
  38. draw.FontWeight = FontWeightType.RegularStyle;
  39. draw.TextAntialias = true;
  40. var fontSize = 30;
  41. var y = OffsetFromTopRightCorner + 11;
  42. if (text.Length == 1)
  43. {
  44. x += 1;
  45. }
  46. else if (text.Length == 2)
  47. {
  48. x += 1;
  49. }
  50. else if (text.Length >= 3)
  51. {
  52. //x += 1;
  53. y -= 2;
  54. fontSize = 24;
  55. }
  56. draw.FontSize = fontSize;
  57. draw.DrawAnnotation(x, y, text);
  58. draw.FillColor = pixel;
  59. wand.CurrentImage.DrawImage(draw);
  60. }
  61. }
  62. }
  63. }
  64. }