aboutsummaryrefslogtreecommitdiff
path: root/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs
blob: 58f887c9600776a4a682ea46c70c49b9db4f909f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
using System.Globalization;
using MediaBrowser.Model.Drawing;
using SkiaSharp;

namespace Jellyfin.Drawing.Skia
{
    /// <summary>
    /// Static helper class for drawing unplayed count indicators.
    /// </summary>
    public static class UnplayedCountIndicator
    {
        /// <summary>
        /// The x-offset used when drawing an unplayed count indicator.
        /// </summary>
        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)
        {
            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);
        }
    }
}