using System.Globalization; using MediaBrowser.Model.Drawing; using SkiaSharp; namespace Jellyfin.Drawing.Skia; /// /// Static helper class for drawing unplayed count indicators. /// public static class UnplayedCountIndicator { /// /// The x-offset used when drawing an unplayed count indicator. /// private const int OffsetFromTopRightCorner = 38; /// /// Draw an unplayed count indicator in the top right corner of a canvas. /// /// The canvas to draw the indicator on. /// /// The dimensions of the image to draw the indicator on. The width is used to determine the x-position of the /// indicator. /// /// The number to draw in the indicator. public static void DrawUnplayedCountIndicator(SKCanvas canvas, ImageDimensions imageSize, int count) { var x = imageSize.Width - OffsetFromTopRightCorner; var text = count.ToString(CultureInfo.InvariantCulture); using var paint = new SKPaint { Color = SKColor.Parse("#CC00A4DC"), Style = SKPaintStyle.Fill }; canvas.DrawCircle(x, OffsetFromTopRightCorner, 20, paint); paint.Color = new SKColor(255, 255, 255, 255); paint.TextSize = 24; paint.IsAntialias = true; var y = OffsetFromTopRightCorner + 9; if (text.Length == 1) { x -= 7; } if (text.Length == 2) { x -= 13; } else if (text.Length >= 3) { x -= 15; y -= 2; paint.TextSize = 18; } canvas.DrawText(text, x, y, paint); } }