Ejemplo n.º 1
0
        private void drawLegalityWarning(CustomDrawArgs e, object sender, Card card)
        {
            var legalityWarning = _legalitySubsystem.GetWarning(card);

            int deckCount = card.DeckCount(Ui);

            if (legalityWarning == Legality.Restricted && deckCount <= 1 && sender == _viewDeck)
            {
                legalityWarning = null;
            }

            if (string.IsNullOrEmpty(legalityWarning))
            {
                return;
            }

            var rect = getLegalityWarningRectangle(e);

            using var warningFont = getWarningFont();
            var lineSize = e.Graphics.MeasureText(legalityWarning, warningFont);

            rect.Offset((int)((rect.Width - lineSize.Width) / 2f), 0);

            e.Graphics.DrawText(legalityWarning, warningFont, rect,
                                Color.FromArgb(255 - 16,
                                               SystemColors.Highlight.TransformHsv(
                                                   h: _ => _ + Color.DodgerBlue.RotationTo(Color.OrangeRed)))
                                );
        }
Ejemplo n.º 2
0
        private void drawCount(object sender, CustomDrawArgs e, Card card)
        {
            var countText = getCountText(sender, card);

            if (string.IsNullOrEmpty(countText))
            {
                return;
            }

            var rect = getSelectionRectangle(e);

            var font = new Font("Arial Black", 18.ByDpiHeight(), GraphicsUnit.Pixel);

            var textSize = e.Graphics.MeasureText(countText, font);

            var targetRect = new Rectangle(
                (int)Math.Ceiling(rect.Left + 0.5f * (rect.Width - textSize.Width)),
                (int)Math.Ceiling(rect.Top + 0.5f * (rect.Height - textSize.Height)),
                textSize.Width,
                textSize.Height);

            targetRect.Inflate(1, 0);
            targetRect.Offset(2, 0);

            e.Graphics.DrawText(countText, font, targetRect, SystemColors.WindowText);
        }
Ejemplo n.º 3
0
        private Rectangle getCountWarningRectangle(CustomDrawArgs e)
        {
            var result = getLegalityWarningRectangle(e);

            result.Offset(new Point(0, -result.Height));
            return(result);
        }
Ejemplo n.º 4
0
        private void drawLegalityWarning(CustomDrawArgs e, object sender, Card card)
        {
            var legalityWarning = _legalitySubsystem.GetWarning(card);

            int deckCount = card.DeckCount(Ui);

            if (legalityWarning == Legality.Restricted && deckCount <= 1 && sender == _layoutViewDeck)
            {
                legalityWarning = null;
            }

            if (string.IsNullOrEmpty(legalityWarning))
            {
                return;
            }

            var       rect = getLegalityWarningRectangle(e);
            const int size = 18;
            var       font = new Font(FontFamily.GenericMonospace, size, FontStyle.Italic | FontStyle.Bold);

            var lineSize = e.Graphics.MeasureText(legalityWarning, font);

            rect.Offset((int)((rect.Width - lineSize.Width) / 2f), 0);

            e.Graphics.DrawText(legalityWarning, font, rect, Color.FromArgb(224, Color.OrangeRed));
        }
Ejemplo n.º 5
0
        private Rectangle getLegalityWarningRectangle(CustomDrawArgs e)
        {
            var stripSize = new Size(_imageLoader.CardSize.Width, 20.ByDpiHeight());

            var rect = new Rectangle(
                e.Bounds.Left,
                (int)(e.Bounds.Bottom - 2.625f * stripSize.Height),
                stripSize.Width,
                stripSize.Height);

            return(rect);
        }
Ejemplo n.º 6
0
        private Rectangle getSelectionRectangle(CustomDrawArgs e)
        {
            var size = new Size(80, 30).ByDpi();

            var rect = new Rectangle(
                e.Bounds.Left + (_imageLoader.CardSize.Width - size.Width) / 2,
                e.Bounds.Bottom - size.Height,
                size.Width,
                size.Height);

            return(rect);
        }
Ejemplo n.º 7
0
        private void drawCard(object sender, CustomDrawArgs e)
        {
            var view = (LayoutViewControl)sender;
            var card = (Card)view.FindRow(e.RowHandle);

            if (card == null)
            {
                return;
            }

            if (e.FieldName != nameof(Card.Image))
            {
                return;
            }

            e.Handled = true;

            var image = card.Image(Ui);

            if (image != null)
            {
                var bounds = image.Size.FitIn(e.Bounds);
                e.Graphics.DrawImage(image, bounds);
            }

            if (card == _deckEditorModel.TouchedCard)
            {
                drawSelection(e, SystemColors.ActiveCaption, SystemColors.GradientActiveCaption, 255);
            }
            else
            {
                int deckCount       = card.DeckCount(Ui);
                int collectionCount = card.CollectionCount(Ui);

                var colorSelection         = SystemColors.InactiveCaption;
                var colorSelectionGradient = SystemColors.GradientInactiveCaption;

                if (deckCount > 0)
                {
                    drawSelection(e, colorSelection, colorSelectionGradient, 127 + 32);
                }
                else if (collectionCount > 0 || e.HotTracked)
                {
                    drawSelection(e, colorSelection, colorSelectionGradient, 127 - 32);
                }
            }

            drawLegalityWarning(e, sender, card);
            drawCountWarning(e, card);
            drawCount(sender, e, card);
        }
Ejemplo n.º 8
0
        private void drawCard(object sender, CustomDrawArgs e)
        {
            var card = _draggingSubsystem.GetCard(getView(sender), e.RowHandle);

            if (card == null)
            {
                return;
            }

            if (e.FieldName != nameof(Card.Image))
            {
                return;
            }

            e.Handled = true;

            var image = card.Image(Ui);

            if (image != null)
            {
                var bounds = image.Size.FitIn(e.Bounds);
                e.Graphics.DrawImage(image, bounds);
            }

            if (card == _deckEditorModel.TouchedCard)
            {
                drawSelection(e, SystemColors.ActiveCaption, SystemColors.GradientActiveCaption, 255 - 48);
            }
            else
            {
                int deckCount       = card.DeckCount(Ui);
                int collectionCount = card.CollectionCount(Ui);

                var colorSelection         = SystemColors.InactiveCaption;
                var colorSelectionGradient = SystemColors.GradientInactiveCaption;

                if (deckCount == 0 && collectionCount > 0)
                {
                    drawSelection(e, colorSelection, colorSelectionGradient, 127 - 32);
                }
                else if (deckCount > 0)
                {
                    drawSelection(e, colorSelection, colorSelectionGradient, 255 - 32);
                }
            }

            drawLegalityWarning(e, sender, card);
            drawCountWarning(e, card);
            drawCount(sender, e, card);
        }
Ejemplo n.º 9
0
        private void drawCard(object sender, CustomDrawArgs e)
        {
            var card = _draggingSubsystem.GetCard(getView(sender), e.RowHandle);

            if (card == null)
            {
                return;
            }

            if (e.FieldName != nameof(Card.Image))
            {
                return;
            }

            e.Handled = true;

            var image = card.Image(Ui);

            if (image != null)
            {
                var bounds = image.Size.FitIn(e.Bounds);
                e.Graphics.DrawImage(image, bounds);
            }

            if (card == _deckEditorModel.TouchedCard)
            {
                drawSelection(e, Color.LightSkyBlue, Color.LightCyan, 236);
            }
            else
            {
                int deckCount       = card.DeckCount(Ui);
                int collectionCount = card.CollectionCount(Ui);

                if (deckCount == 0 && collectionCount > 0)
                {
                    drawSelection(e, Color.Lavender, Color.White, 96);
                }
                else if (deckCount > 0)
                {
                    drawSelection(e, Color.Lavender, Color.White, 236);
                }
            }

            drawLegalityWarning(e, sender, card);

            drawCountWarning(e, card);

            drawCount(sender, e, card);
        }
Ejemplo n.º 10
0
        private void drawDraggingMark(CustomDrawArgs e)
        {
            const int opacity = 66;

            var gradientRectangle = e.Bounds;

            gradientRectangle.Inflate(new Size(-70, -30).ByDpi());

            var brush = new LinearGradientBrush(
                gradientRectangle,
                Color.FromArgb(opacity, Color.LightBlue),
                Color.FromArgb(opacity, Color.AliceBlue),
                LinearGradientMode.BackwardDiagonal);

            e.Graphics.FillRectangle(brush, new Rectangle(e.Bounds.Location, _imageLoader.CardSize));
        }
Ejemplo n.º 11
0
        private void drawDraggingMark(CustomDrawArgs e)
        {
            const int opacity = 127 - 32;

            var gradientRectangle = e.Bounds;

            gradientRectangle.Inflate(new Size(-70, -30).ByDpi());

            var brush = new LinearGradientBrush(
                gradientRectangle,
                Color.FromArgb(opacity, SystemColors.GradientActiveCaption),
                Color.FromArgb(opacity, SystemColors.ActiveCaption),
                LinearGradientMode.BackwardDiagonal);

            using (brush)
                e.Graphics.FillRectangle(brush, new Rectangle(e.Bounds.Location, _imageLoader.CardSize));
        }
Ejemplo n.º 12
0
        private Rectangle getLegalityWarningRectangle(CustomDrawArgs e)
        {
            Size stripSize;

            using (var warningFont = getWarningFont())
                stripSize = new Size(
                    Ui.ImageLoader.CardSize.Width,
                    warningFont.Height + _countInputSubsystem.CountBorder);

            var rect = new Rectangle(
                e.Bounds.Left,
                (int)(e.Bounds.Bottom - 2.625f * stripSize.Height),
                stripSize.Width,
                stripSize.Height);

            return(rect);
        }
Ejemplo n.º 13
0
        private void drawSelection(CustomDrawArgs e, Color colorGrad1, Color colorGrad2, int opacity)
        {
            var rect = _countInputSubsystem.GetCountRectangle(e.Bounds);

            int       countBorder  = _countInputSubsystem.CountBorder;
            const int cornerOffset = -1;
            int       cornerShare  = countBorder * 2;

            rect.Inflate(-countBorder, -countBorder);

            int cornerYSize = rect.Height / cornerShare;
            int cornerXSize = rect.Height / cornerShare;

            var points = new[]
            {
                new Point(rect.Left - cornerOffset + cornerXSize, rect.Top - cornerOffset),
                new Point(rect.Right + cornerOffset - cornerXSize, rect.Top - cornerOffset),

                new Point(rect.Right + cornerOffset, rect.Top - cornerOffset + cornerYSize),
                new Point(rect.Right + cornerOffset, rect.Bottom + cornerOffset - cornerYSize),

                new Point(rect.Right + cornerOffset - cornerXSize, rect.Bottom + cornerOffset),
                new Point(rect.Left - cornerOffset + cornerXSize, rect.Bottom + cornerOffset),

                new Point(rect.Left - cornerOffset, rect.Bottom + cornerOffset - cornerYSize),
                new Point(rect.Left - cornerOffset, rect.Top - cornerOffset + cornerYSize)
            };

            var gradientRect = rect;

            gradientRect.Inflate((int)(-rect.Width * 0.33f), (int)(-rect.Height * 0.16f));

            var brush = new LinearGradientBrush(
                gradientRect,
                Color.FromArgb(opacity, colorGrad1),
                Color.FromArgb(opacity, colorGrad2),
                LinearGradientMode.BackwardDiagonal);

            using (brush)
            {
                brush.SetBlendTriangularShape(0.99f, 1f);
                e.Graphics.FillClosedCurve(brush, points, FillMode.Alternate, 0.05f);
            }
        }
Ejemplo n.º 14
0
        private void drawDraggingMark(object sender, CustomDrawArgs e)
        {
            var view = (LayoutViewControl)sender;
            var card = (Card)view.FindRow(e.RowHandle);

            if (card == null)
            {
                return;
            }

            if (e.FieldName != nameof(Card.Image))
            {
                return;
            }

            if (card == _deckEditorModel.DraggedCard)
            {
                drawDraggingMark(e);
            }
        }
Ejemplo n.º 15
0
        private void drawDraggingMark(object sender, CustomDrawArgs e)
        {
            var view = getView(sender);
            var card = GetCard(view, e.RowHandle);

            if (card == null)
            {
                return;
            }

            if (e.FieldName != nameof(Card.Image))
            {
                return;
            }

            if (card == _deckEditorModel.DraggedCard)
            {
                drawDraggingMark(e);
            }
        }
Ejemplo n.º 16
0
        private void drawSelection(CustomDrawArgs e, Color borderColor, Color foreColor, int opacity)
        {
            var rect = getSelectionRectangle(e);

            const int borderWidth  = 2;
            const int cornerOffset = -1;
            var       cornerShare  = 4;

            rect.Inflate(new Size(-borderWidth, -borderWidth));

            int cornerYSize = rect.Height / cornerShare;
            int cornerXSize = rect.Height / cornerShare;

            var points = new[]
            {
                new Point(rect.Left - cornerOffset + cornerXSize, rect.Top - cornerOffset),
                new Point(rect.Right + cornerOffset - cornerXSize, rect.Top - cornerOffset),

                new Point(rect.Right + cornerOffset, rect.Top - cornerOffset + cornerYSize),
                new Point(rect.Right + cornerOffset, rect.Bottom + cornerOffset - cornerYSize),

                new Point(rect.Right + cornerOffset - cornerXSize, rect.Bottom + cornerOffset),
                new Point(rect.Left - cornerOffset + cornerXSize, rect.Bottom + cornerOffset),

                new Point(rect.Left - cornerOffset, rect.Bottom + cornerOffset - cornerYSize),
                new Point(rect.Left - cornerOffset, rect.Top - cornerOffset + cornerYSize)
            };

            var gradientRect = rect;

            gradientRect.Inflate((int)(-rect.Width * 0.33f), (int)(-rect.Height * 0.16f));

            var brush = new LinearGradientBrush(
                gradientRect,
                Color.FromArgb(opacity, borderColor),
                Color.FromArgb(opacity, foreColor),
                LinearGradientMode.BackwardDiagonal);

            brush.SetBlendTriangularShape(0.99f, 1f);
            e.Graphics.FillClosedCurve(brush, points, FillMode.Alternate, 0.05f);
        }
Ejemplo n.º 17
0
        private void drawCount(object sender, CustomDrawArgs e, Card card)
        {
            var countText = getCountText(sender, card);

            if (string.IsNullOrEmpty(countText))
            {
                return;
            }

            var rect = _countInputSubsystem.GetCountRectangle(e.Bounds);
            var font = _countInputSubsystem.CountFont;

            var textSize = e.Graphics.MeasureText(countText, font);

            var targetRect = new Rectangle(
                (int)Math.Ceiling(rect.Left + 0.5f * (rect.Width - textSize.Width)),
                (int)Math.Ceiling(rect.Top + 0.5f * (rect.Height - textSize.Height)),
                textSize.Width,
                textSize.Height);

            targetRect.Offset(0, 1);
            e.Graphics.DrawText(countText, font, targetRect, SystemColors.WindowText);
        }
Ejemplo n.º 18
0
        private void drawCountWarning(CustomDrawArgs e, Card card)
        {
            if (!_deckEditorModel.Deck.Contains(card))
            {
                return;
            }

            var namesakeCounts = new[]
            {
                _deckEditorModel.MainDeck.NamesakeIds(card).Sum(_deckEditorModel.MainDeck.GetCount),
                _deckEditorModel.SideDeck.NamesakeIds(card).Sum(_deckEditorModel.SideDeck.GetCount),
            };

            Color color;

            int[] counts;
            int   maxCount;

            int maxCountInDeck = card.MaxCountInDeck();

            if (namesakeCounts.Sum() > maxCountInDeck)
            {
                counts   = namesakeCounts;
                maxCount = maxCountInDeck;
                color    = SystemColors.HotTrack.TransformHsv(
                    h: _ => _ + Color.Blue.RotationTo(Color.Crimson));
            }
            else
            {
                int collectionCount = card.CollectionCount(Ui);
                if (collectionCount == 0)
                {
                    return;
                }

                counts = new[]
                {
                    _deckEditorModel.MainDeck.GetCount(card.Id),
                    _deckEditorModel.SideDeck.GetCount(card.Id),
                };

                if (counts.Sum() > collectionCount)
                {
                    maxCount = collectionCount;
                    color    = SystemColors.HotTrack;
                }
                else
                {
                    return;
                }
            }

            string warning = $"{string.Join("+", counts.Where(c => c != 0))} / {maxCount}";
            var    rect    = getCountWarningRectangle(e);

            using var warningFont = getWarningFont();
            var lineSize = e.Graphics.MeasureText(warning, warningFont);

            rect.Offset((int)((rect.Width - lineSize.Width) / 2f), 0);

            using var bgBrush = new SolidBrush(Color.FromArgb(160, SystemColors.Window));
            var bgRect = new Rectangle(rect.Location, lineSize);

            bgRect.Inflate(2 * _countInputSubsystem.CountBorder, 0);
            bgRect.Offset(_countInputSubsystem.CountBorder, 0);
            e.Graphics.FillRectangle(bgBrush, bgRect);
            e.Graphics.DrawText(warning, warningFont, rect, color);
        }
Ejemplo n.º 19
0
        private void drawCountWarning(CustomDrawArgs e, Card card)
        {
            int countInMain      = _deckEditorModel.MainDeck.GetCount(card.Id);
            int countInSideboard = _deckEditorModel.SideDeck.GetCount(card.Id);

            if (countInMain == 0 || countInSideboard == 0)
            {
                // the excessive count is not due to main + side sum
                // therefore it is obvious, warning is not necessary
                return;
            }

            var totalCount = countInMain + countInSideboard;

            Color color;
            int   maxCount;

            if (totalCount > card.MaxCountInDeck())
            {
                maxCount = card.MaxCountInDeck();
                color    = SystemColors.HotTrack.TransformHsv(
                    h: _ => _ + Color.Blue.RotationTo(Color.Crimson));
            }
            else
            {
                int collectionCount = card.CollectionCount(Ui);

                if (totalCount > collectionCount && collectionCount > 0)
                {
                    maxCount = collectionCount;
                    color    = SystemColors.HotTrack;
                }
                else
                {
                    return;
                }
            }

            string warning;

            if (countInMain == 0)
            {
                warning = $"{countInSideboard}/{maxCount}";
            }
            else if (countInSideboard == 0)
            {
                warning = $"{countInMain}/{maxCount}";
            }
            else
            {
                warning = $"{countInMain}+{countInSideboard}/{maxCount}";
            }

            var rect = getCountWarningRectangle(e);

            const int size = 16;
            var       font = new Font(FontFamily.GenericMonospace, size, FontStyle.Italic | FontStyle.Bold);

            var lineSize = e.Graphics.MeasureText(warning, font);

            rect.Offset((int)((rect.Width - lineSize.Width) / 2f), 0);

            e.Graphics.DrawText(warning, font, rect, Color.FromArgb(224, color));
        }