private void silum(object sender, RoutedEventArgs e) { canvas.Children.Clear(); double sun = 0; try { //sun = double.Parse(silumto.Text); if (sun > 1) { canvas.Width *= sun; canvas.Height *= sun; } } catch (Exception) { return; } string path = str; using (StreamReader sr = File.OpenText(path)) { double x1 = 0, x2 = 0, y1 = 0, y2 = 0; string s = ""; char[] outline = { '(', ',', ')' }; while ((s = sr.ReadLine()) != null) { if (s.IndexOf("#") > -1) { switch (s) { case "#Lines": while ((s = sr.ReadLine()) != null && s != "" && s.Length > 2) { string[] arr = s.Split(outline); arr = func(arr); x1 = int.Parse(arr[0]) * sun; y1 = int.Parse(arr[1]) * sun; x2 = int.Parse(arr[2]) * sun; y2 = int.Parse(arr[3]) * sun; x1 *= scale; y1 *= scale; x2 *= scale; y2 *= scale; Line l = new Line(); l.X1 = x1; l.Y1 = y1; l.X2 = x2; l.Y2 = y2; l.StrokeThickness = 4; l.Stroke = System.Windows.Media.Brushes.LightSteelBlue; canvas.Children.Add(l); } break; case "#Circles": while ((s = sr.ReadLine()) != null && s != "" && s.Length > 2) { string[] arr = s.Split(outline); arr = func(arr); x1 = int.Parse(arr[0]) * sun; y1 = int.Parse(arr[1]) * sun; //x2 = int.Parse(arr[2]); y2 = int.Parse(arr[3]) * sun; // RADIUS x1 *= scale; y1 *= scale; y2 *= scale; Ellipse ell = new Ellipse(); ell.Width = 2 * y2; ell.Height = 2 * y2; InkCanvas.SetTop(ell, y1 - y2); InkCanvas.SetLeft(ell, x1 - y2); ell.StrokeThickness = 4; ell.Fill = System.Windows.Media.Brushes.Transparent; ell.Stroke = System.Windows.Media.Brushes.LightSteelBlue; canvas.Children.Add(ell); } break; case "#Cruves": while ((s = sr.ReadLine()) != null && s != "" && s.Length > 2) { string[] arr = s.Split(outline); arr = func(arr); Point p1 = new Point((int.Parse(arr[0]) * sun) * scale, (int.Parse(arr[1]) * sun) * scale); Point p2 = new Point((int.Parse(arr[2]) * sun) * scale, (int.Parse(arr[3]) * sun) * scale); Point p3 = new Point((int.Parse(arr[4]) * sun) * scale, (int.Parse(arr[5]) * sun) * scale); Point p4 = new Point((int.Parse(arr[6]) * sun) * scale, (int.Parse(arr[7]) * sun) * scale); Point[] points = new[] { p1, p2, p3, p4 }; bezier bz = new bezier(); var Bezier_btb = bz.CreatebezierLinepoly(points, 500); PathFigure pathDiscriptionFigure = new PathFigure(Bezier_btb.Points[0], new[] { Bezier_btb }, false); PathFigureCollection pathColletion_ = new PathFigureCollection(); pathColletion_.Add(pathDiscriptionFigure); var GeomtricPath = new PathGeometry(); GeomtricPath.Figures = pathColletion_; System.Windows.Shapes.Path Path_Shapepattern = new System.Windows.Shapes.Path(); Path_Shapepattern.Data = GeomtricPath; Path_Shapepattern.Stroke = new SolidColorBrush(Color.FromRgb(255, 0, 0)); canvas.Children.Add(Path_Shapepattern); } break; } } } } }
private void preview_mouseup(object sender, MouseButtonEventArgs e) { if (gameclick % 2 == 0) { try { if (shapeFlag < 3) { if (gameclick % 2 == 0) { par[1] = Mouse.GetPosition(canvas); } } else { } switch (shapeFlag) { case 1: Ellipse ell = new Ellipse(); if (par[0].X < par[1].X) { ell.Width = par[1].X - par[0].X; ell.Height = par[1].Y - par[0].Y; InkCanvas.SetTop(ell, par[0].Y); InkCanvas.SetLeft(ell, par[0].X); } else { ell.Width = par[0].X - par[1].X; ell.Height = par[0].Y - par[1].Y; InkCanvas.SetTop(ell, par[1].Y); InkCanvas.SetLeft(ell, par[1].X); } ell.StrokeThickness = 4; ell.Fill = System.Windows.Media.Brushes.Transparent; ell.Stroke = System.Windows.Media.Brushes.LightSteelBlue; canvas.Children.Add(ell); break; case 2: Line l = new Line(); l.X1 = par[0].X; l.Y1 = par[0].Y; l.X2 = par[1].X; l.Y2 = par[1].Y; l.StrokeThickness = 4; l.Stroke = System.Windows.Media.Brushes.LightSteelBlue; canvas.Children.Add(l); break; case 3: if (i == 4) { Point[] points = new[] { par[0], par[1], par[2], par[3] }; bezier bz = new bezier(); var Bezier_btb = bz.CreatebezierLinepoly(points, 256); PathFigure pathDiscriptionFigure = new PathFigure(Bezier_btb.Points[0], new[] { Bezier_btb }, false); PathFigureCollection pathColletion_ = new PathFigureCollection(); pathColletion_.Add(pathDiscriptionFigure); var GeomtricPath = new PathGeometry(); GeomtricPath.Figures = pathColletion_; System.Windows.Shapes.Path Path_Shapepattern = new System.Windows.Shapes.Path(); Path_Shapepattern.Data = GeomtricPath; Path_Shapepattern.Stroke = new SolidColorBrush(Color.FromRgb(255, 0, 0)); curve_list.Add(Path_Shapepattern); canvas.Children.Add(Path_Shapepattern); } break; } }catch (Exception) { return; } } }