예제 #1
0
        void DoPaint()
        {
            try
            {
                var padding = 30;
                var w       = _dotCanvas.ActualWidth - 2 * padding;
                var h       = _dotCanvas.ActualHeight - 2 * padding;
                var maxY    = _nextLocation.Y;

                var vs = _verticalScale;

                if (vs < 0)
                {
                    vs = (h / 3) / 10;
                }

                if (vs * maxY > h / 3)
                {
                    vs = (h / 3) / maxY;
                }

                var dotWidth  = Math.Max(5, w / GridWidth / 2);
                var dotHeight = Math.Max(5, vs / 2);

                dotWidth  = Math.Min(dotWidth, dotHeight);
                dotHeight = dotWidth;

                var count    = _boardInfo.Count;
                var wonCount = _boardInfo.Count(bi => bi.IsRemoved);

                foreach (var bi in _boardInfo)
                {
                    if (bi.Shape == null)
                    {
                        bi.Shape = new Ellipse()
                        {
                            Width = dotWidth, Height = dotHeight
                        };
                        _dotCanvas.Children.Add(bi.Shape);
                    }

                    var x = padding + bi.InitialLocation.X * w / GridWidth - dotWidth / 2;
                    var y = padding + bi.InitialLocation.Y * vs - dotHeight / 2;

                    if (bi.IsRemoved)
                    {
                        var toY = h - y;
                        y = (float)(bi.T * toY + (1.0 - bi.T) * y);
                    }

                    if (bi.Shape.Fill == null || ((SolidColorBrush)bi.Shape.Fill).Color != bi.Color)
                    {
                        bi.Shape.Fill = new SolidColorBrush(bi.Color);
                    }

                    Canvas.SetLeft(bi.Shape, x);
                    Canvas.SetTop(bi.Shape, y);
                }

                var s1 = string.Format("{0} boards remaining" + _parenthetical, count - wonCount);
                var s2 = string.Format("{0} boards won", wonCount);

                if (_remainingBlock == null)
                {
                    _remainingBlock = DrawString(s1, _infoFont, White, new Box(w / 2, h / 2 - padding * 2 + 15), _dotCanvas);
                }
                if (_wonBlock == null)
                {
                    _wonBlock = DrawString(s2, _infoFont, White, new Box(w / 2, h / 2 + padding * 2 - 5), _dotCanvas);
                }

                if (_dividerLine == null)
                {
                    _dividerLine = new Line()
                    {
                        X1 = 0, Y1 = _dotCanvas.ActualHeight / 2, X2 = _dotCanvas.ActualWidth, Y2 = _dotCanvas.ActualHeight / 2, StrokeThickness = 2, Stroke = new SolidColorBrush(White.ToColor())
                    };
                    _dotCanvas.Children.Add(_dividerLine);
                }

                _remainingBlock.Text = s1;
                _wonBlock.Text       = s2;
                CenterTextBlock(_remainingBlock, new Box(w / 2, h / 2 - padding * 2 + 15));
                CenterTextBlock(_wonBlock, new Box(w / 2, h / 2 + padding * 2 - 5));
            }
            catch { }
        }