PlayedIndicatorDrawer.cs 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using MediaBrowser.Model.Drawing;
  2. using SkiaSharp;
  3. namespace Jellyfin.Drawing.Skia
  4. {
  5. /// <summary>
  6. /// Static helper class for drawing 'played' indicators.
  7. /// </summary>
  8. public static class PlayedIndicatorDrawer
  9. {
  10. private const int OffsetFromTopRightCorner = 38;
  11. /// <summary>
  12. /// Draw a 'played' indicator in the top right corner of a canvas.
  13. /// </summary>
  14. /// <param name="canvas">The canvas to draw the indicator on.</param>
  15. /// <param name="imageSize">
  16. /// The dimensions of the image to draw the indicator on. The width is used to determine the x-position of the
  17. /// indicator.
  18. /// </param>
  19. public static void DrawPlayedIndicator(SKCanvas canvas, ImageDimensions imageSize)
  20. {
  21. var x = imageSize.Width - OffsetFromTopRightCorner;
  22. using var paint = new SKPaint
  23. {
  24. Color = SKColor.Parse("#CC00A4DC"),
  25. Style = SKPaintStyle.Fill
  26. };
  27. canvas.DrawCircle(x, OffsetFromTopRightCorner, 20, paint);
  28. paint.Color = new SKColor(255, 255, 255, 255);
  29. paint.TextSize = 30;
  30. paint.IsAntialias = true;
  31. // or:
  32. // var emojiChar = 0x1F680;
  33. const string Text = "✔️";
  34. var emojiChar = StringUtilities.GetUnicodeCharacterCode(Text, SKTextEncoding.Utf32);
  35. // ask the font manager for a font with that character
  36. paint.Typeface = SKFontManager.Default.MatchCharacter(emojiChar);
  37. canvas.DrawText(Text, (float)x - 20, OffsetFromTopRightCorner + 12, paint);
  38. }
  39. }
  40. }