jellyfin/Emby.Drawing.ImageMagick/UnplayedCountIndicator.cs

76 lines
2.5 KiB
C#
Raw Normal View History

2015-03-09 04:56:42 +01:00
using ImageMagickSharp;
using MediaBrowser.Common.Configuration;
using MediaBrowser.Model.Drawing;
2015-03-09 04:56:42 +01:00
using System.Globalization;
2016-10-25 21:02:04 +02:00
using MediaBrowser.Common.IO;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.IO;
2015-04-08 16:38:02 +02:00
namespace Emby.Drawing.ImageMagick
{
public class UnplayedCountIndicator
{
private const int OffsetFromTopRightCorner = 38;
2015-03-09 04:56:42 +01:00
private readonly IApplicationPaths _appPaths;
2015-09-14 01:07:54 +02:00
private readonly IFileSystem _fileSystem;
2015-03-09 04:56:42 +01:00
2015-09-14 01:07:54 +02:00
public UnplayedCountIndicator(IApplicationPaths appPaths, IFileSystem fileSystem)
2015-03-09 04:56:42 +01:00
{
_appPaths = appPaths;
2015-09-14 01:07:54 +02:00
_fileSystem = fileSystem;
2015-03-09 04:56:42 +01:00
}
public void DrawUnplayedCountIndicator(MagickWand wand, ImageSize imageSize, int count)
{
var x = imageSize.Width - OffsetFromTopRightCorner;
var text = count.ToString(CultureInfo.InvariantCulture);
using (var draw = new DrawingWand())
{
using (PixelWand pixel = new PixelWand())
{
pixel.Color = "#52B54B";
pixel.Opacity = 0.2;
draw.FillColor = pixel;
draw.DrawCircle(x, OffsetFromTopRightCorner, x - 20, OffsetFromTopRightCorner - 20);
pixel.Opacity = 0;
pixel.Color = "white";
draw.FillColor = pixel;
2015-09-13 23:32:02 +02:00
draw.Font = PlayedIndicatorDrawer.ExtractFont("robotoregular.ttf", _appPaths, _fileSystem);
draw.FontStyle = FontStyleType.NormalStyle;
draw.TextAlignment = TextAlignType.CenterAlign;
draw.FontWeight = FontWeightType.RegularStyle;
draw.TextAntialias = true;
var fontSize = 30;
var y = OffsetFromTopRightCorner + 11;
if (text.Length == 1)
{
2015-03-09 04:56:42 +01:00
x += 1;
}
else if (text.Length == 2)
{
x += 1;
}
else if (text.Length >= 3)
{
2015-03-09 04:58:16 +01:00
//x += 1;
y -= 2;
fontSize = 24;
}
draw.FontSize = fontSize;
draw.DrawAnnotation(x, y, text);
draw.FillColor = pixel;
wand.CurrentImage.DrawImage(draw);
}
}
}
}
}