2
0

UnplayedCountIndicator.cs 2.3 KB

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