PercentPlayedDrawer.cs 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  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. var endX = imageSize.Width - 1;
  22. var endY = imageSize.Height - 1;
  23. paint.Color = SKColor.Parse("#99000000");
  24. paint.Style = SKPaintStyle.Fill;
  25. canvas.DrawRect(SKRect.Create(0, (float)endY - IndicatorHeight, endX, endY), paint);
  26. double foregroundWidth = (endX * percent) / 100;
  27. paint.Color = SKColor.Parse("#FF00A4DC");
  28. canvas.DrawRect(SKRect.Create(0, (float)endY - IndicatorHeight, Convert.ToInt32(foregroundWidth), endY), paint);
  29. }
  30. }
  31. }