PlayedIndicatorDrawer.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  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. paint.Color = SKColor.Parse("#CC00A4DC");
  25. paint.Style = SKPaintStyle.Fill;
  26. canvas.DrawCircle((float)x, OffsetFromTopRightCorner, 20, paint);
  27. }
  28. using (var paint = new SKPaint())
  29. {
  30. paint.Color = new SKColor(255, 255, 255, 255);
  31. paint.Style = SKPaintStyle.Fill;
  32. paint.TextSize = 30;
  33. paint.IsAntialias = true;
  34. // or:
  35. // var emojiChar = 0x1F680;
  36. var text = "✔️";
  37. var emojiChar = StringUtilities.GetUnicodeCharacterCode(text, SKTextEncoding.Utf32);
  38. // ask the font manager for a font with that character
  39. var fontManager = SKFontManager.Default;
  40. var emojiTypeface = fontManager.MatchCharacter(emojiChar);
  41. paint.Typeface = emojiTypeface;
  42. canvas.DrawText(text, (float)x - 20, OffsetFromTopRightCorner + 12, paint);
  43. }
  44. }
  45. }
  46. }