private void BTNStartEnter_Click(object sender, RoutedEventArgs e) { Shell.Instance.Clear(); pol = new ShellExt.Polygon(); BTNStroke.IsEnabled = false; BTNFillEO.IsEnabled = false; BTNFillNZW.IsEnabled = false; isEntering = true; TBPointsCount.Text = "PointsCount - 0"; TBType.Text = ""; }
/// <summary> /// нарисовать линию /// </summary> /// <param name="w">толщина</param> /// <param name="color">цвет</param> /// <param name="type">тип законцовки</param> public static void DrawLine(this Shell shell, int x1, int y1, int x2, int y2, int w, Color color, LineCap type = LineCap.FLAP) { int x1old = x1, x2old = x2, y1old = y1, y2old = y2; if (w < 3) { shell.DrawLine(x1, y1, x2, y2, color); return; } double alpha = Math.Atan(((double)(x2 - x1)) / ((double)(y2 - y1))); if (y1 <= y2) { Utils.Swap(ref x1, ref x2); Utils.Swap(ref y1, ref y2); } if (type == LineCap.SQUARE) { x1 += (int)(w * Math.Sin(alpha) / 2); y1 += (int)(w * Math.Cos(alpha) / 2); x2 -= (int)(w * Math.Sin(alpha) / 2); y2 -= (int)(w * Math.Cos(alpha) / 2); } Polygon pol = new Polygon(); double dx = w * Math.Cos(alpha) / 2; double dy = w * Math.Sin(alpha) / 2; // pol.AddPoint(x1 - (int)dx, y1 + (int)dy); if (type == LineCap.ROUND) { int n = w / 2; if (n < 5) { n = 5; } double al = alpha; for (int i = 0; i < n; i++) { al += Math.PI / n; pol.AddPoint(x1 - (int)(w * Math.Cos(al) / 2), y1 + (int)(w * Math.Sin(al) / 2)); } for (int i = 0; i < n; i++) { pol.AddPoint(x2 - (int)(w * Math.Cos(al) / 2), y2 + (int)(w * Math.Sin(al) / 2)); al += Math.PI / n; } } else { pol.AddPoint(x1 - (int)dx, y1 + (int)dy); pol.AddPoint(x1 + (int)dx, y1 - (int)dy); pol.AddPoint(x2 + (int)dx, y2 - (int)dy); pol.AddPoint(x2 - (int)dx, y2 + (int)dy); } shell.FillPolygon(pol, color); //shell.DrawLine(x1old, y1old, x2old, y2old, Colors.Red); }