public static void WriteShape(string path, GoodShape s) { using (FileStream fs = new FileStream(path, FileMode.Create, FileAccess.ReadWrite)) { XamlWriter.Save(s, fs); } }
private void canvas_KeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Delete) { if (CurrentShape != null) { CurrentShape.Bound.hide(); CurrentShape.removeBound(); drawingSurface.DeleteVisual(CurrentShape); currentShape = null; bo = null; gShapes.Remove(CurrentShape); } } }
private void Shape_Checked(object sender, RoutedEventArgs e) { if (sender == Rectangle) sim.setObjects(typeof(GoodRectangle), ShapeInfo); if (sender == Star) sim.setObjects(typeof(GoodStar), ShapeInfo); if (sender == Ellipse) sim.setObjects(typeof(GoodEllipse), ShapeInfo); if (sender == Polygon) sim.setObjects(typeof(GoodPolygon), ShapeInfo); if(currentShape != null) currentShape = null; if (bo != null) { bo.hide(); bo = null; } }
private void setActive(GoodShape shape) { if(shape != null) { if (bo != null) bo.hide(); bo = shape.Bound; currentShape = shape; sim.setObjects(shape.GetType(), ShapeInfo); bo.show(); bo.Focus(); } }
void removeFocus(GoodShape g) { g.Bound.hide(); }
void canvas_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Point pos = e.GetPosition(drawingSurface); if (bo != null) if (!bo.contains(pos)) { bo.hide(); bo = null; return; } if (bo == null) { bo = new Bound(canvas, pos); bo.LostFocus += bo_LostFocus; bo.Focus(); if (Star.IsChecked == true) { currentShape = new GoodStar(5, 0.4, bo); currentShape.Color = new SolidColorBrush(ShapeColor.SelectedColor); currentShape.BorderPen = new Pen(new SolidColorBrush(StrokeColor.SelectedColor), BorderThickness.Value); drawingSurface.AddVisual(currentShape); gShapes.Add(currentShape); } if (Polygon.IsChecked == true) { currentShape = new GoodPolygon(7, bo); currentShape.Color = new SolidColorBrush(ShapeColor.SelectedColor); currentShape.BorderPen = new Pen(new SolidColorBrush(StrokeColor.SelectedColor), BorderThickness.Value); drawingSurface.AddVisual(currentShape); gShapes.Add(currentShape); } if(Ellipse.IsChecked == true) { currentShape = new GoodEllipse(bo); currentShape.Color = new SolidColorBrush(ShapeColor.SelectedColor); currentShape.BorderPen = new Pen(new SolidColorBrush(StrokeColor.SelectedColor), BorderThickness.Value); drawingSurface.AddVisual(currentShape); gShapes.Add(currentShape); } if (Rectangle.IsChecked == true) { currentShape = new GoodRectangle(bo, 0, 0); currentShape.Color = new SolidColorBrush(ShapeColor.SelectedColor); currentShape.BorderPen = new Pen(new SolidColorBrush(StrokeColor.SelectedColor), 1); drawingSurface.AddVisual(currentShape); gShapes.Add(currentShape); } if (Picker.IsChecked == true) { } } }