예제 #1
0
 public void DrawString(string s, Font font, ARGB argb, Box bounds)
 {
     _context.Font        = font.Name + " " + font.Size + "px";
     _context.StrokeStyle = argb.ToColor();
     _context.GlobalAlpha = argb.A / 255.0f;
     _context.StrokeText(s, (int)bounds.X, (int)bounds.Y);
 }
예제 #2
0
 public void Clear(ARGB argb)
 {
     _context.FillStyle   = argb.ToColor();
     _context.GlobalAlpha = argb.A / 255.0f;
     _context.ClearRect(0, 0, _canvas.Width, _canvas.Height);
     _context.FillRect(0, 0, _canvas.Width, _canvas.Height);
 }
예제 #3
0
        public void DrawLines(ARGB argb, System.Collections.Generic.IEnumerable <Box> points, double width = 1)
        {
            var brush = new SolidColorBrush(argb.ToColor());

            var first    = true;
            var previous = Box.Empty;

            foreach (var point in points)
            {
                if (first)
                {
                    previous = point;
                    first    = false;
                    continue;
                }

                var line = new Line()
                {
                    X1 = previous.X, Y1 = previous.Y, X2 = point.X, Y2 = point.Y, StrokeThickness = width, Stroke = brush
                };
                _canvas.Children.Add(line);

                previous = point;
            }
        }
예제 #4
0
 public void FillEllipse(ARGB argb, Box bounds)
 {
     _context.BeginPath();
     _context.FillStyle   = argb.ToColor();
     _context.GlobalAlpha = argb.A / 255.0f;
     _context.Arc(bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2, bounds.Width / 2, 0, 2 * Math.PI);
     _context.Fill();
 }
예제 #5
0
 public void DrawEllipse(ARGB argb, Box bounds, double width = 1)
 {
     _context.StrokeStyle = argb.ToColor();
     _context.GlobalAlpha = argb.A / 255.0f;
     _context.BeginPath();
     _context.Arc(bounds.Left + bounds.Width / 2, bounds.Top + bounds.Height / 2, bounds.Width / 2, 0, 2 * Math.PI);
     _context.Stroke();
 }
예제 #6
0
 public void DrawLine(ARGB argb, Box p1, Box p2, double width = 1)
 {
     _context.StrokeStyle = argb.ToColor();
     _context.LineWidth   = width;
     _context.GlobalAlpha = Math.Min(1.0f, Math.Max(0.0f, argb.A / 255.0f));
     _context.BeginPath();
     _context.MoveTo(p1.X, p1.Y);
     _context.LineTo(p2.X, p2.Y);
     _context.Stroke();
 }
예제 #7
0
        static Brush GetBrush(ARGB argb)
        {
            Brush brush;

            if (!_brushLookup.TryGetValue(argb, out brush))
            {
                _brushLookup[argb] = brush = new SolidColorBrush(argb.ToColor());
            }

            return(brush);
        }
예제 #8
0
        public void FillEllipse(ARGB argb, Box bounds)
        {
            var ellipse = new Ellipse()
            {
                Fill = new SolidColorBrush(argb.ToColor()), Width = bounds.Width, Height = bounds.Height
            };

            Canvas.SetLeft(ellipse, bounds.Left);
            Canvas.SetTop(ellipse, bounds.Top);
            _canvas.Children.Add(ellipse);
        }
예제 #9
0
        public void DrawEllipse(ARGB argb, Box bounds, double width = 1)
        {
            var ellipse = new Ellipse()
            {
                Stroke = new SolidColorBrush(argb.ToColor()), StrokeThickness = width, Width = bounds.Width + 2 * width, Height = bounds.Height + 2 * width
            };

            Canvas.SetLeft(ellipse, bounds.Left - width);
            Canvas.SetTop(ellipse, bounds.Top - width);
            _canvas.Children.Add(ellipse);
        }
예제 #10
0
        public void DrawString(string s, Font font, ARGB argb, Box bounds)
        {
            using (var brush = new SolidBrush(argb.ToColor()))
                using (var gdiFont = new System.Drawing.Font(font.Name, font.Size))
                {
                    var format = new StringFormat();
                    format.Alignment     = StringAlignment.Center;
                    format.LineAlignment = StringAlignment.Center;

                    _graphics.DrawString(s, gdiFont, brush, bounds.ToRectangleF(), format);
                }
        }
예제 #11
0
        public void FillPolygon(ARGB argb, System.Collections.Generic.IEnumerable <Box> points)
        {
            var poly = new Polygon();

            foreach (var p in points)
            {
                poly.Points.Add(new Point(p.X, p.Y));
            }

            poly.Fill = new SolidColorBrush(argb.ToColor());

            _canvas.Children.Add(poly);
        }
예제 #12
0
        public void FillPolygon(ARGB argb, IEnumerable <Box> points)
        {
            _context.FillStyle   = argb.ToColor();
            _context.GlobalAlpha = argb.A / 255.0f;
            _context.BeginPath();
            var first = true;

            foreach (var b in points)
            {
                if (first)
                {
                    _context.MoveTo(b.X, b.Y);
                    first = false;
                }
                else
                {
                    _context.LineTo(b.X, b.Y);
                }
            }
            _context.Fill();
        }
예제 #13
0
        public void DrawLines(ARGB argb, IEnumerable <Box> points, double width = 1)
        {
            _context.StrokeStyle = argb.ToColor();
            _context.GlobalAlpha = argb.A / 255.0f;
            _context.LineWidth   = width;
            _context.BeginPath();
            var first = true;

            foreach (var b in points)
            {
                if (first)
                {
                    _context.MoveTo(b.X, b.Y);
                    first = false;
                }
                else
                {
                    _context.LineTo(b.X, b.Y);
                }
            }
            _context.Stroke();
        }
예제 #14
0
        TextBlock DrawString(string s, Font font, ARGB argb, Box bounds, Canvas canvas)
        {
            var t = new TextBlock()
            {
                Text = s, FontFamily = new FontFamily(font.Name), FontSize = 1.3 * font.Size, Foreground = new SolidColorBrush(argb.ToColor())
            };

            CenterTextBlock(t, bounds);

            canvas.Children.Add(t);

            return(t);
        }
예제 #15
0
        public void DrawString(string s, Font font, ARGB argb, Box bounds)
        {
            var text = new TextBlock()
            {
                Text = s, FontFamily = new FontFamily(font.Name), FontSize = 1.3 * font.Size, Foreground = new SolidColorBrush(argb.ToColor())
            };

            text.Measure(new Size(double.MaxValue, double.MaxValue));

            Canvas.SetLeft(text, bounds.Left + bounds.Width / 2 - text.ActualWidth / 2);
            Canvas.SetTop(text, bounds.Top +  +bounds.Height / 2 - text.ActualHeight / 2);

            _canvas.Children.Add(text);
        }
예제 #16
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 { }
        }
예제 #17
0
 public void FillEllipse(ARGB argb, Box bounds)
 {
     using (var brush = new SolidBrush(argb.ToColor()))
         _graphics.FillEllipse(brush, bounds.ToRectangleF());
 }
예제 #18
0
 public void Clear(ARGB argb)
 {
     _canvas.Background = new SolidColorBrush(argb.ToColor());
 }
예제 #19
0
 public void FillPolygon(ARGB argb, IEnumerable <Box> points)
 {
     using (var brush = new SolidBrush(argb.ToColor()))
         _graphics.FillPolygon(brush, points.ToPointF().ToArray());
 }
예제 #20
0
 public void DrawEllipse(ARGB argb, Box bounds, double width = 1)
 {
     using (var pen = new Pen(argb.ToColor(), (float)width))
         _graphics.DrawEllipse(pen, bounds.ToRectangleF());
 }
예제 #21
0
 public void DrawLines(ARGB argb, IEnumerable <Box> points, double width = 1)
 {
     using (var pen = new Pen(argb.ToColor(), (float)width))
         _graphics.DrawLines(pen, points.ToPointF().ToArray());
 }
예제 #22
0
 public void DrawLine(ARGB argb, Box p1, Box p2, double width = 1)
 {
     using (var pen = new Pen(argb.ToColor(), (float)width))
         _graphics.DrawLine(pen, p1.ToPointF(), p2.ToPointF());
 }
예제 #23
0
 public void Clear(ARGB argb)
 {
     _graphics.Clear(argb.ToColor());
 }
예제 #24
0
        public void DrawLine(ARGB argb, Box p1, Box p2, double width = 1)
        {
            var line = new Line()
            {
                X1 = p1.X, Y1 = p1.Y, X2 = p2.X, Y2 = p2.Y, StrokeThickness = width, Stroke = new SolidColorBrush(argb.ToColor())
            };

            _canvas.Children.Add(line);
        }
예제 #25
0
        public void DrawLine(ARGB argb, double x1, double y1, double x2, double y2, double width = 1)
        {
            var line = new Line()
            {
                X1 = x1, Y1 = y1, X2 = x2, Y2 = y2, StrokeThickness = width, Stroke = new SolidColorBrush(argb.ToColor())
            };

            _canvas.Children.Add(line);
        }