Пример #1
0
        private void DrawIndicator(SKCanvas canvas, int imageWidth, int imageHeight, ImageProcessingOptions options)
        {
            try
            {
                var currentImageSize = new ImageSize(imageWidth, imageHeight);

                if (options.AddPlayedIndicator)
                {
                    var task = new PlayedIndicatorDrawer(_appPaths, _httpClientFactory(), _fileSystem).DrawPlayedIndicator(canvas, currentImageSize);
                    Task.WaitAll(task);
                }
                else if (options.UnplayedCount.HasValue)
                {
                    new UnplayedCountIndicator(_appPaths, _httpClientFactory(), _fileSystem).DrawUnplayedCountIndicator(canvas, currentImageSize, options.UnplayedCount.Value);
                }

                if (options.PercentPlayed > 0)
                {
                    new PercentPlayedDrawer().Process(canvas, currentImageSize, options.PercentPlayed);
                }
            }
            catch (Exception ex)
            {
                _logger.ErrorException("Error drawing indicator overlay", ex);
            }
        }
Пример #2
0
        public void DrawUnplayedCountIndicator(SKCanvas canvas, ImageSize imageSize, int count)
        {
            var x    = imageSize.Width - OffsetFromTopRightCorner;
            var text = count.ToString(CultureInfo.InvariantCulture);

            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;
                paint.Typeface    = SKTypeface.FromFile(PlayedIndicatorDrawer.ExtractFont("robotoregular.ttf", _appPaths, _fileSystem));
                paint.TextSize    = 24;
                paint.IsAntialias = true;

                var y = OffsetFromTopRightCorner + 9;

                if (text.Length == 1)
                {
                    x -= 7;
                }
                if (text.Length == 2)
                {
                    x -= 13;
                }
                else if (text.Length >= 3)
                {
                    x -= 15;
                    y -= 2;
                    paint.TextSize = 18;
                }

                canvas.DrawText(text, (float)x, y, paint);
            }
        }