PercentPlayedDrawer.cs 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. using System;
  2. using MediaBrowser.Model.Drawing;
  3. using SkiaSharp;
  4. namespace Jellyfin.Drawing.Skia
  5. {
  6. /// <summary>
  7. /// Static helper class used to draw percentage-played indicators on images.
  8. /// </summary>
  9. public static class PercentPlayedDrawer
  10. {
  11. private const int IndicatorHeight = 8;
  12. /// <summary>
  13. /// Draw a percentage played indicator on a canvas.
  14. /// </summary>
  15. /// <param name="canvas">The canvas to draw the indicator on.</param>
  16. /// <param name="imageSize">The size of the image being drawn on.</param>
  17. /// <param name="percent">The percentage played to display with the indicator.</param>
  18. public static void Process(SKCanvas canvas, ImageDimensions imageSize, double percent)
  19. {
  20. using (var paint = new SKPaint())
  21. {
  22. var endX = imageSize.Width - 1;
  23. var endY = imageSize.Height - 1;
  24. paint.Color = SKColor.Parse("#99000000");
  25. paint.Style = SKPaintStyle.Fill;
  26. canvas.DrawRect(SKRect.Create(0, (float)endY - IndicatorHeight, (float)endX, (float)endY), paint);
  27. double foregroundWidth = endX;
  28. foregroundWidth *= percent;
  29. foregroundWidth /= 100;
  30. paint.Color = SKColor.Parse("#FF00A4DC");
  31. canvas.DrawRect(SKRect.Create(0, (float)endY - IndicatorHeight, Convert.ToInt32(foregroundWidth), (float)endY), paint);
  32. }
  33. }
  34. }
  35. }