UnplayedCountIndicator.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System.Drawing;
  2. namespace Emby.Drawing.Net
  3. {
  4. public class UnplayedCountIndicator
  5. {
  6. private const int IndicatorHeight = 41;
  7. public const int IndicatorWidth = 41;
  8. private const int OffsetFromTopRightCorner = 10;
  9. public void DrawUnplayedCountIndicator(Graphics graphics, Size imageSize, int count)
  10. {
  11. var x = imageSize.Width - IndicatorWidth - OffsetFromTopRightCorner;
  12. using (var backdroundBrush = new SolidBrush(Color.FromArgb(225, 82, 181, 75)))
  13. {
  14. graphics.FillEllipse(backdroundBrush, x, OffsetFromTopRightCorner, IndicatorWidth, IndicatorHeight);
  15. var text = count.ToString();
  16. x = imageSize.Width - IndicatorWidth - OffsetFromTopRightCorner;
  17. var y = OffsetFromTopRightCorner + 6;
  18. var fontSize = 24;
  19. if (text.Length == 1)
  20. {
  21. x += 10;
  22. }
  23. else if (text.Length == 2)
  24. {
  25. x += 3;
  26. }
  27. else if (text.Length == 3)
  28. {
  29. x += 1;
  30. y += 1;
  31. fontSize = 20;
  32. }
  33. using (var font = new Font("Sans-Serif", fontSize, FontStyle.Regular, GraphicsUnit.Pixel))
  34. {
  35. using (var fontBrush = new SolidBrush(Color.White))
  36. {
  37. graphics.DrawString(text, font, fontBrush, x, y);
  38. }
  39. }
  40. }
  41. }
  42. }
  43. }