aboutsummaryrefslogtreecommitdiff
path: root/src/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs
diff options
context:
space:
mode:
authorBond-009 <bond.009@outlook.com>2023-01-11 09:22:35 +0100
committerGitHub <noreply@github.com>2023-01-11 09:22:35 +0100
commitaefa8da4ee2167e5ec63f27d83cd0ef41f01a8ae (patch)
tree6697e861af0f23ec0c0bb285b42e23ef61d3b57a /src/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs
parent3ed0e70eaba16da29b212acc0d4f4ee50f15405b (diff)
parent16e33665a217cb6b37d88cca244eb1538d41b873 (diff)
Merge pull request #9064 from barronpm/move-jellyfin-drawing-skia
Diffstat (limited to 'src/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs')
-rw-r--r--src/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs64
1 files changed, 64 insertions, 0 deletions
diff --git a/src/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs b/src/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs
new file mode 100644
index 000000000..58f887c96
--- /dev/null
+++ b/src/Jellyfin.Drawing.Skia/UnplayedCountIndicator.cs
@@ -0,0 +1,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);
+ }
+ }
+}