PlayedIndicatorDrawer.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using SkiaSharp;
  2. using MediaBrowser.Common.Configuration;
  3. using MediaBrowser.Common.Net;
  4. using MediaBrowser.Model.Drawing;
  5. using MediaBrowser.Model.IO;
  6. namespace Emby.Drawing.Skia
  7. {
  8. public class PlayedIndicatorDrawer
  9. {
  10. private const int OffsetFromTopRightCorner = 38;
  11. private readonly IApplicationPaths _appPaths;
  12. private readonly IHttpClient _iHttpClient;
  13. private readonly IFileSystem _fileSystem;
  14. public PlayedIndicatorDrawer(IApplicationPaths appPaths, IHttpClient iHttpClient, IFileSystem fileSystem)
  15. {
  16. _appPaths = appPaths;
  17. _iHttpClient = iHttpClient;
  18. _fileSystem = fileSystem;
  19. }
  20. public void DrawPlayedIndicator(SKCanvas canvas, ImageSize imageSize)
  21. {
  22. var x = imageSize.Width - OffsetFromTopRightCorner;
  23. using (var paint = new SKPaint())
  24. {
  25. paint.Color = SKColor.Parse("#CC52B54B");
  26. paint.Style = SKPaintStyle.Fill;
  27. canvas.DrawCircle((float)x, OffsetFromTopRightCorner, 20, paint);
  28. }
  29. using (var paint = new SKPaint())
  30. {
  31. paint.Color = new SKColor(255, 255, 255, 255);
  32. paint.Style = SKPaintStyle.Fill;
  33. paint.TextSize = 30;
  34. paint.IsAntialias = true;
  35. var text = "✔️";
  36. var emojiChar = StringUtilities.GetUnicodeCharacterCode(text, SKTextEncoding.Utf32);
  37. // or:
  38. //var emojiChar = 0x1F680;
  39. // ask the font manager for a font with that character
  40. var fontManager = SKFontManager.Default;
  41. var emojiTypeface = fontManager.MatchCharacter(emojiChar);
  42. paint.Typeface = emojiTypeface;
  43. canvas.DrawText(text, (float)x-20, OffsetFromTopRightCorner + 12, paint);
  44. }
  45. }
  46. }
  47. }