public MainWindow() { InitializeComponent(); this.DataContext = dataContainer; shapeContainer = new CanvasShapeContainer(); transform = new MatrixTransform(); tempForm = new Path(); newShapeIndex = 0; composite = new ShapeComposite(); }
private void Scene_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { ICommands com; EndMovePoint = e.GetPosition(Scene); double dX = EndMovePoint.X - StartMovePoint.X; double dY = EndMovePoint.Y - StartMovePoint.Y; switch (option.type) { case Options.op.newShape_regtangle: if (shapeContainer.shapes.ContainsKey(newShapeIndex)) { com = new CommandFinalizeRect(EndMovePoint.X, EndMovePoint.Y, newShapeIndex, shapeContainer, brush); com.Execute(); newShapeIndex++; Render(); } break; case Options.op.newShape_ellipse: if (shapeContainer.shapes.ContainsKey(newShapeIndex)) { com = new CommandFinalizeEllipse(EndMovePoint.X, EndMovePoint.Y, newShapeIndex, shapeContainer, brush); com.Execute(); newShapeIndex++; Render(); } break; case Options.op.newLine_Pencil: if (shapeContainer.shapes.ContainsKey(newShapeIndex)) { com = new CommandFinalizePencil(StartMovePoint, EndMovePoint, newShapeIndex, shapeContainer, brush); com.Execute(); newShapeIndex++; Render(); } break; case Options.op.newLine_Marker: if (shapeContainer.shapes.ContainsKey(newShapeIndex)) { com = new CommandFinalizeMarker(StartMovePoint, EndMovePoint, newShapeIndex, shapeContainer, brush); com.Execute(); newShapeIndex++; Render(); } break; case Options.op.resize: Path path_r = resize.VisualHit as Path; int index_r = Convert.ToInt32(path_r.Tag.ToString()); if (path_r.Data.GetType() == typeof(RectangleGeometry)) { int index = Convert.ToInt32(path_r.Tag.ToString()); GenericShape form = shapeContainer.shapes[index]; if (composite.child.Contains(form)) { foreach (var pair in composite.child) { int indexGroup = Convert.ToInt32(pair.Shape.Tag); com = new CommandResizeRect(dX, dY, indexGroup, shapeContainer, pair.Shape, Brushes.Blue); com.Execute(); } } else { com = new CommandResizeRect(dX, dY, index_r, shapeContainer, path_r, Brushes.Blue); com.Execute(); } Render(); } break; case Options.op.moveShape: HitTestResult result = VisualTreeHelper.HitTest(Scene, Mouse.GetPosition(Scene)); Path path = result.VisualHit as Path; if (path.Data.GetType() == typeof(RectangleGeometry)) { int index = Convert.ToInt32(path.Tag.ToString()); GenericShape form = shapeContainer.shapes[index]; if (composite.child.Contains(form)) { foreach (var pair in composite.child) { int indexGroup = Convert.ToInt32(pair.Shape.Tag); com = new CommandMoveRect(dX, dY, indexGroup, shapeContainer, pair.Shape, brush); com.Execute(); } } else{ com = new CommandMoveRect(dX, dY, index, shapeContainer, path, brush); com.Execute(); } } else if (path.Data.GetType() == typeof(EllipseGeometry)) { int index = Convert.ToInt32(path.Tag.ToString()); GenericShape form = shapeContainer.shapes[index]; if (composite.child.Contains(form)) { foreach (var pair in composite.child) { int indexGroup = Convert.ToInt32(pair.Shape.Tag); com = new CommandMoveEllipse(dX, dY, indexGroup, shapeContainer, pair.Shape, brush); com.Execute(); } } else{ com = new CommandMoveEllipse(dX, dY, index, shapeContainer, path, brush); com.Execute(); } Render(); } break; case Options.op.groupShape: ShapeComposite group = new ShapeComposite(); foreach (var pair in shapeContainer.shapes) { GenericShape temp = new GenericShape(); temp = pair.Value; if ((temp.position.X > StartMovePoint.X) && (temp.position.Y > StartMovePoint.Y) && (temp.position.X < EndMovePoint.X) && (temp.position.Y < EndMovePoint.Y)) { //group.add(temp); composite.add(temp); //Scene.Children.Add(temp.Shape); } } //composite.add(group); Scene.Children.Remove(select.Shape); Render(); break; } }