jellyfin/Emby.Drawing/PlayedIndicatorDrawer.cs

59 lines
1.9 KiB
C#
Raw Normal View History

using MediaBrowser.Common.Configuration;
2017-05-09 21:53:46 +02:00
using MediaBrowser.Common.Net;
using MediaBrowser.Model.Drawing;
using MediaBrowser.Model.IO;
using SkiaSharp;
2017-05-09 21:53:46 +02:00
namespace Emby.Drawing
2017-05-09 21:53:46 +02:00
{
public class PlayedIndicatorDrawer
{
private const int OffsetFromTopRightCorner = 38;
private readonly IApplicationPaths _appPaths;
private readonly IHttpClient _iHttpClient;
private readonly IFileSystem _fileSystem;
public PlayedIndicatorDrawer(IApplicationPaths appPaths, IHttpClient iHttpClient, IFileSystem fileSystem)
{
_appPaths = appPaths;
_iHttpClient = iHttpClient;
_fileSystem = fileSystem;
}
2018-09-12 19:26:21 +02:00
public void DrawPlayedIndicator(SKCanvas canvas, ImageSize imageSize)
2017-05-09 21:53:46 +02:00
{
var x = imageSize.Width - OffsetFromTopRightCorner;
using (var paint = new SKPaint())
{
paint.Color = SKColor.Parse("#CC52B54B");
paint.Style = SKPaintStyle.Fill;
canvas.DrawCircle((float)x, OffsetFromTopRightCorner, 20, paint);
}
using (var paint = new SKPaint())
{
paint.Color = new SKColor(255, 255, 255, 255);
paint.Style = SKPaintStyle.Fill;
2017-11-21 23:14:56 +01:00
paint.TextSize = 30;
paint.IsAntialias = true;
2017-05-09 21:53:46 +02:00
2017-11-21 23:14:56 +01:00
var text = "✔️";
var emojiChar = StringUtilities.GetUnicodeCharacterCode(text, SKTextEncoding.Utf32);
// or:
//var emojiChar = 0x1F680;
2017-05-09 21:53:46 +02:00
2017-11-21 23:14:56 +01:00
// ask the font manager for a font with that character
var fontManager = SKFontManager.Default;
var emojiTypeface = fontManager.MatchCharacter(emojiChar);
2017-05-09 21:53:46 +02:00
2017-11-21 23:14:56 +01:00
paint.Typeface = emojiTypeface;
2017-05-09 21:53:46 +02:00
canvas.DrawText(text, (float)x - 20, OffsetFromTopRightCorner + 12, paint);
2017-05-09 21:53:46 +02:00
}
}
}
}