UnplayedCountIndicator.cs 2.4 KB

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