jellyfin/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs

65 lines
1.9 KiB
C#
Raw Normal View History

using System.Globalization;
2017-05-09 19:53:46 +00:00
using MediaBrowser.Model.Drawing;
using SkiaSharp;
2017-05-09 19:53:46 +00:00
2019-01-26 19:43:13 +00:00
namespace Jellyfin.Drawing.Skia
2017-05-09 19:53:46 +00:00
{
/// <summary>
/// Static helper class for drawing unplayed count indicators.
/// </summary>
2019-01-20 13:25:13 +00:00
public static class UnplayedCountIndicator
2017-05-09 19:53:46 +00:00
{
/// <summary>
/// The x-offset used when drawing an unplayed count indicator.
/// </summary>
2017-05-09 19:53:46 +00:00
private const int OffsetFromTopRightCorner = 38;
/// <summary>
/// Draw an unplayed count indicator in the top right corner of a canvas.
/// </summary>
/// <param name="canvas">The canvas to draw the indicator on.</param>
/// <param name="imageSize">
/// The dimensions of the image to draw the indicator on. The width is used to determine the x-position of the
/// indicator.
/// </param>
/// <param name="count">The number to draw in the indicator.</param>
public static void DrawUnplayedCountIndicator(SKCanvas canvas, ImageDimensions imageSize, int count)
2017-05-09 19:53:46 +00:00
{
var x = imageSize.Width - OffsetFromTopRightCorner;
var text = count.ToString(CultureInfo.InvariantCulture);
2020-07-19 18:39:11 +00:00
using var paint = new SKPaint
2017-05-09 19:53:46 +00:00
{
2020-07-19 18:39:11 +00:00
Color = SKColor.Parse("#CC00A4DC"),
Style = SKPaintStyle.Fill
};
2017-11-21 22:14:56 +00:00
2020-07-19 18:39:11 +00:00
canvas.DrawCircle(x, OffsetFromTopRightCorner, 20, paint);
2017-05-09 19:53:46 +00:00
2020-07-19 18:39:11 +00:00
paint.Color = new SKColor(255, 255, 255, 255);
paint.TextSize = 24;
paint.IsAntialias = true;
2017-05-09 19:53:46 +00:00
2020-07-19 18:39:11 +00:00
var y = OffsetFromTopRightCorner + 9;
2019-12-14 11:20:52 +00:00
2020-07-19 18:39:11 +00:00
if (text.Length == 1)
{
x -= 7;
}
2017-05-09 19:53:46 +00:00
2020-07-19 18:39:11 +00:00
if (text.Length == 2)
{
x -= 13;
}
else if (text.Length >= 3)
{
x -= 15;
y -= 2;
paint.TextSize = 18;
2017-05-09 19:53:46 +00:00
}
2020-07-19 18:39:11 +00:00
canvas.DrawText(text, x, y, paint);
2017-05-09 19:53:46 +00:00
}
}
}