private void Shapes_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { switch (e.Action) { case NotifyCollectionChangedAction.Add: (e.NewItems[0] as INotifyPropertyChanged).PropertyChanged += Shapes_PropertyChanged; ShapesListMenu.IsEnabled = true; switch (e.NewItems[0]) { case MyPoint point: CanvasPaint.Children.Add(NewShapeForCancas(point)); ShapesListMenu.IsEnabled = false; break; case MyPolygon polygon: CanvasPaint.Children.Add(NewShapeForCancas(polygon)); break; default: break; } if (!(e.NewItems[0] is MyPoint) && !isOpen) { bus.ChooseShape((e.NewItems[0] as MyShape).Name); bus.FillShape(GetColor()); bus.ClearChoose(); } break; case NotifyCollectionChangedAction.Remove: switch (e.OldItems[0]) { case MyPoint point: var points = CanvasPaint.Children.OfType <Ellipse>().Where(p => p.Name == MyPoint.pointName).ToList(); foreach (var item in points) { CanvasPaint.Children.Remove(item); } break; default: break; } break; case NotifyCollectionChangedAction.Reset: ShapesListMenu.IsEnabled = false; action = null; CanvasPaint.Children.Clear(); break; } }
private void MenuItem_Shapes_Click(object sender, RoutedEventArgs e) { MenuItem menuItem = sender as MenuItem; bus.ChooseShape(menuItem.Header.ToString()); bus.isNewPolyline = false; Fill.IsEnabled = true; action = null; foreach (Shape item in CanvasPaint.Children) { item.MouseDown -= CanvasChildren_MouseDown; } CanvasPaint.Children[bus.ChoosenShapeIndex].MouseDown += CanvasChildren_MouseDown; }
public void MoveShapeTest1() { shapeBUS = new ShapeBUS(); shapeBUS.AddPoint(new Point(0, 0)); shapeBUS.AddPoint(new Point(5, 8)); shapeBUS.AddPoint(new Point(5, 4)); shapeBUS.AddPoint(new Point(0, 0)); shapeBUS.CreatePolygon(); shapeBUS.ChooseShape("Polygon 1"); shapeBUS.SetShapeMarginAndStartMovePoint(new Point(0, 1)); shapeBUS.MoveShape(new Point(2, 3)); }
public void ChooseShapeTest() { shapeBUS = new ShapeBUS(); shapeBUS.AddPoint(new Point(0, 0)); shapeBUS.AddPoint(new Point(5, 6)); shapeBUS.CreateEllipse(); shapeBUS.ChooseShape("Ellipse 1"); int expected = 0; int actual = shapeBUS.ChoosenShapeIndex; Assert.AreEqual(expected, actual); }
public void MoveShapeTest1() { shapeBUS = new ShapeBUS(); shapeBUS.AddPoint(new Point(0, 0)); shapeBUS.AddPoint(new Point(5, 5)); shapeBUS.AddPoint(new Point(6, 5)); shapeBUS.AddPoint(new Point(9, 5)); shapeBUS.AddPoint(new Point(15, 5)); shapeBUS.CreatePentagon(); shapeBUS.ChooseShape("Pentagon_1"); shapeBUS.SetShapeMarginAndStartMovePoint(new Point(0, 1)); shapeBUS.MoveShape(new Point(2, 3)); }
public void FillShapeTest1() { shapeBUS = new ShapeBUS(); shapeBUS.AddPoint(new Point(0, 0)); shapeBUS.AddPoint(new Point(5, 8)); shapeBUS.AddPoint(new Point(5, 4)); shapeBUS.AddPoint(new Point(0, 0)); shapeBUS.CreatePolygon(); shapeBUS.ChooseShape("Polygon 1"); Color color = Color.FromRgb(0, 0, 0); shapeBUS.FillShape(color); }
public void FillShapeTest1() { shapeBUS = new ShapeBUS(); shapeBUS.AddPoint(new Point(0, 0)); shapeBUS.AddPoint(new Point(5, 5)); shapeBUS.AddPoint(new Point(6, 5)); shapeBUS.AddPoint(new Point(9, 5)); shapeBUS.AddPoint(new Point(15, 5)); shapeBUS.CreatePentagon(); shapeBUS.ChooseShape("Pentagon_1"); Color color = Color.FromRgb(0, 0, 0); shapeBUS.FillShape(color); }
public void ChooseShapeTest() { shapeBUS = new ShapeBUS(); shapeBUS.AddPoint(new Point(0, 0)); shapeBUS.AddPoint(new Point(5, 5)); shapeBUS.AddPoint(new Point(6, 5)); shapeBUS.AddPoint(new Point(9, 5)); shapeBUS.AddPoint(new Point(15, 5)); shapeBUS.CreatePentagon(); shapeBUS.ChooseShape("Pentagon_1"); int expected = 0; int actual = shapeBUS.ChoosenShapeIndex; Assert.AreEqual(expected, actual); }