jellyfin/Jellyfin.Drawing.Skia/PlayedIndicatorDrawer.cs

53 lines
1.8 KiB
C#
Raw Normal View History

2017-05-09 12:53:46 -07:00
using MediaBrowser.Model.Drawing;
using SkiaSharp;
2017-05-09 12:53:46 -07:00
2019-01-26 12:43:13 -07:00
namespace Jellyfin.Drawing.Skia
2017-05-09 12:53:46 -07:00
{
/// <summary>
/// Static helper class for drawing 'played' indicators.
/// </summary>
2019-01-20 06:25:13 -07:00
public static class PlayedIndicatorDrawer
2017-05-09 12:53:46 -07:00
{
private const int OffsetFromTopRightCorner = 38;
/// <summary>
/// Draw a 'played' 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>
public static void DrawPlayedIndicator(SKCanvas canvas, ImageDimensions imageSize)
2017-05-09 12:53:46 -07:00
{
var x = imageSize.Width - OffsetFromTopRightCorner;
using (var paint = new SKPaint())
{
paint.Color = SKColor.Parse("#CC00A4DC");
2017-05-09 12:53:46 -07:00
paint.Style = SKPaintStyle.Fill;
canvas.DrawCircle(x, OffsetFromTopRightCorner, 20, paint);
2017-05-09 12:53:46 -07:00
}
using (var paint = new SKPaint())
{
paint.Color = new SKColor(255, 255, 255, 255);
paint.Style = SKPaintStyle.Fill;
2017-11-21 15:14:56 -07:00
paint.TextSize = 30;
paint.IsAntialias = true;
2017-05-09 12:53:46 -07:00
// or:
// var emojiChar = 0x1F680;
const string Text = "✔️";
var emojiChar = StringUtilities.GetUnicodeCharacterCode(Text, SKTextEncoding.Utf32);
2017-05-09 12:53:46 -07:00
2017-11-21 15:14:56 -07:00
// ask the font manager for a font with that character
paint.Typeface = SKFontManager.Default.MatchCharacter(emojiChar);
2017-05-09 12:53:46 -07:00
canvas.DrawText(Text, (float)x - 20, OffsetFromTopRightCorner + 12, paint);
2017-05-09 12:53:46 -07:00
}
}
}
}