UnplayedCountIndicator.cs 2.0 KB

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