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); }
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); }
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; } }
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(); }
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(); }
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(); }
static Brush GetBrush(ARGB argb) { Brush brush; if (!_brushLookup.TryGetValue(argb, out brush)) { _brushLookup[argb] = brush = new SolidColorBrush(argb.ToColor()); } return(brush); }
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); }
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); }
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); } }
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); }
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(); }
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(); }
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); }
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); }
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 { } }
public void FillEllipse(ARGB argb, Box bounds) { using (var brush = new SolidBrush(argb.ToColor())) _graphics.FillEllipse(brush, bounds.ToRectangleF()); }
public void Clear(ARGB argb) { _canvas.Background = new SolidColorBrush(argb.ToColor()); }
public void FillPolygon(ARGB argb, IEnumerable <Box> points) { using (var brush = new SolidBrush(argb.ToColor())) _graphics.FillPolygon(brush, points.ToPointF().ToArray()); }
public void DrawEllipse(ARGB argb, Box bounds, double width = 1) { using (var pen = new Pen(argb.ToColor(), (float)width)) _graphics.DrawEllipse(pen, bounds.ToRectangleF()); }
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()); }
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()); }
public void Clear(ARGB argb) { _graphics.Clear(argb.ToColor()); }
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); }
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); }