Пример #1
0
        private void UpdateCards(IEnumerable <Card> cards)
        {
            var cardsRectangles = cardsCanvas.Children.OfType <Rectangle>().ToArray();

            foreach (var cardsRectangle in cardsRectangles)
            {
                cardsCanvas.Children.Remove(cardsRectangle);
            }

            var cardImagesProvider = CardImagesProvider;

            if (cards != null && cardImagesProvider != null)
            {
                var cardsArray = cards.ToArray();

                var height = 200.0;
                var width  = height * cardImagesProvider.GetCardImageRatio();

                double left = 40 + TextSizeMeasurer.MeasureString(Title, caption).Width;

                var cardsFieldWidth      = 1280 - left - 40;
                var distanceBetweenCards = Math.Min(20,
                                                    cardsFieldWidth / cardsArray.Length - width);

                bool firstCard = true;
                foreach (var card in cardsArray)
                {
                    var cardShouldBeFlipped = firstCard && FirtsCardShouldBeFlipped;

                    var cardImage = cardShouldBeFlipped
                        ? cardImagesProvider.GetImageForBack()
                        : cardImagesProvider.GetImageForCard(card);
                    var cardViewbox = cardShouldBeFlipped
                        ? cardImagesProvider.GetViewboxForBack()
                        : cardImagesProvider.GetViewboxForCard(card);

                    var rectangle = new Rectangle
                    {
                        Width  = width,
                        Height = height,
                        Fill   = new ImageBrush
                        {
                            ImageSource = cardImage,
                            Viewbox     = cardViewbox,
                            Stretch     = cardShouldBeFlipped ? Stretch.Fill : Stretch.Uniform
                        }
                    };
                    Canvas.SetLeft(rectangle, left);
                    Canvas.SetTop(rectangle, 30);
                    cardsCanvas.Children.Add(rectangle);
                    left     += width + distanceBetweenCards;
                    firstCard = false;
                }
            }
        }
Пример #2
0
        private static void OnCurrentBetChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var text = string.Format(Properties.Resources.CurrentBet, e.NewValue);

            var scoreControl = (ScoreControl)d;

            var size = TextSizeMeasurer.MeasureString(text, scoreControl.currentBet);

            scoreControl.currentBet.Text = text;

            Canvas.SetLeft(scoreControl.currentBet, (1280 - size.Width) / 2);
        }
Пример #3
0
        private static void OnPlayerScoreChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
            var text = string.Format(Properties.Resources.PlayersMoney, e.NewValue);

            var scoreControl = (ScoreControl)d;

            var size = TextSizeMeasurer.MeasureString(text, scoreControl.playerMoney);

            scoreControl.playerMoney.Text = text;

            Canvas.SetLeft(scoreControl.playerMoney, 1280 - size.Width - 10);
        }