| | 1 | | using System.Globalization; |
| | 2 | | using MediaBrowser.Model.Drawing; |
| | 3 | | using SkiaSharp; |
| | 4 | |
|
| | 5 | | namespace Jellyfin.Drawing.Skia; |
| | 6 | |
|
| | 7 | | /// <summary> |
| | 8 | | /// Static helper class for drawing unplayed count indicators. |
| | 9 | | /// </summary> |
| | 10 | | public static class UnplayedCountIndicator |
| | 11 | | { |
| | 12 | | /// <summary> |
| | 13 | | /// The x-offset used when drawing an unplayed count indicator. |
| | 14 | | /// </summary> |
| | 15 | | private const int OffsetFromTopRightCorner = 38; |
| | 16 | |
|
| | 17 | | /// <summary> |
| | 18 | | /// Draw an unplayed count indicator in the top right corner of a canvas. |
| | 19 | | /// </summary> |
| | 20 | | /// <param name="canvas">The canvas to draw the indicator on.</param> |
| | 21 | | /// <param name="imageSize"> |
| | 22 | | /// The dimensions of the image to draw the indicator on. The width is used to determine the x-position of the |
| | 23 | | /// indicator. |
| | 24 | | /// </param> |
| | 25 | | /// <param name="count">The number to draw in the indicator.</param> |
| | 26 | | public static void DrawUnplayedCountIndicator(SKCanvas canvas, ImageDimensions imageSize, int count) |
| | 27 | | { |
| 0 | 28 | | var x = imageSize.Width - OffsetFromTopRightCorner; |
| 0 | 29 | | var text = count.ToString(CultureInfo.InvariantCulture); |
| | 30 | |
|
| 0 | 31 | | using var paint = new SKPaint |
| 0 | 32 | | { |
| 0 | 33 | | Color = SKColor.Parse("#CC00A4DC"), |
| 0 | 34 | | Style = SKPaintStyle.Fill |
| 0 | 35 | | }; |
| | 36 | |
|
| 0 | 37 | | canvas.DrawCircle(x, OffsetFromTopRightCorner, 20, paint); |
| | 38 | |
|
| 0 | 39 | | paint.Color = new SKColor(255, 255, 255, 255); |
| 0 | 40 | | paint.TextSize = 24; |
| 0 | 41 | | paint.IsAntialias = true; |
| | 42 | |
|
| 0 | 43 | | var y = OffsetFromTopRightCorner + 9; |
| | 44 | |
|
| 0 | 45 | | if (text.Length == 1) |
| | 46 | | { |
| 0 | 47 | | x -= 7; |
| | 48 | | } |
| | 49 | |
|
| 0 | 50 | | if (text.Length == 2) |
| | 51 | | { |
| 0 | 52 | | x -= 13; |
| | 53 | | } |
| 0 | 54 | | else if (text.Length >= 3) |
| | 55 | | { |
| 0 | 56 | | x -= 15; |
| 0 | 57 | | y -= 2; |
| 0 | 58 | | paint.TextSize = 18; |
| | 59 | | } |
| | 60 | |
|
| 0 | 61 | | canvas.DrawText(text, x, y, paint); |
| 0 | 62 | | } |
| | 63 | | } |