UnplayedCountIndicator.cs 2.4 KB

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