2019-01-13 12:54:44 -07:00
|
|
|
using System;
|
2017-05-09 12:53:46 -07:00
|
|
|
using MediaBrowser.Model.Drawing;
|
2019-01-13 12:16:43 -07:00
|
|
|
using SkiaSharp;
|
2017-05-09 12:53:46 -07:00
|
|
|
|
2019-01-26 12:43:13 -07:00
|
|
|
namespace Jellyfin.Drawing.Skia
|
2017-05-09 12:53:46 -07:00
|
|
|
{
|
2019-12-13 12:57:23 -07:00
|
|
|
/// <summary>
|
|
|
|
/// Static helper class used to draw percentage-played indicators on images.
|
|
|
|
/// </summary>
|
2019-01-20 06:25:13 -07:00
|
|
|
public static class PercentPlayedDrawer
|
2017-05-09 12:53:46 -07:00
|
|
|
{
|
|
|
|
private const int IndicatorHeight = 8;
|
|
|
|
|
2019-12-13 12:57:23 -07:00
|
|
|
/// <summary>
|
|
|
|
/// Draw a percentage played indicator on a canvas.
|
|
|
|
/// </summary>
|
|
|
|
/// <param name="canvas">The canvas to draw the indicator on.</param>
|
|
|
|
/// <param name="imageSize">The size of the image being drawn on.</param>
|
|
|
|
/// <param name="percent">The percentage played to display with the indicator.</param>
|
2019-01-26 05:16:47 -07:00
|
|
|
public static void Process(SKCanvas canvas, ImageDimensions imageSize, double percent)
|
2017-05-09 12:53:46 -07:00
|
|
|
{
|
2020-07-19 11:12:53 -07:00
|
|
|
using var paint = new SKPaint();
|
|
|
|
var endX = imageSize.Width - 1;
|
|
|
|
var endY = imageSize.Height - 1;
|
2017-05-09 12:53:46 -07:00
|
|
|
|
2020-07-19 11:12:53 -07:00
|
|
|
paint.Color = SKColor.Parse("#99000000");
|
|
|
|
paint.Style = SKPaintStyle.Fill;
|
2020-07-19 11:13:18 -07:00
|
|
|
canvas.DrawRect(SKRect.Create(0, (float)endY - IndicatorHeight, endX, endY), paint);
|
2017-05-09 12:53:46 -07:00
|
|
|
|
2020-07-19 11:13:56 -07:00
|
|
|
double foregroundWidth = (endX * percent) / 100;
|
2017-05-09 12:53:46 -07:00
|
|
|
|
2020-07-19 11:12:53 -07:00
|
|
|
paint.Color = SKColor.Parse("#FF00A4DC");
|
2020-07-19 11:13:18 -07:00
|
|
|
canvas.DrawRect(SKRect.Create(0, (float)endY - IndicatorHeight, Convert.ToInt32(foregroundWidth), endY), paint);
|
2017-05-09 12:53:46 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|