private void Cylinder_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { DoodleCylinder cylinder = (DoodleCylinder)sender; ShapeSettingSelected(cylinder); e.Handled = true; }
/// <summary> /// 能否涂鸦 /// </summary> /// <param name="value"></param> public void SetCanDraw(bool value = true) { canDraw = value; if (canDraw) { foreach (var child in doodleCanvas.Children) { if (child is DoodleCube) { DoodleCube cube = (DoodleCube)child; cube.SetBackground(Brushes.Transparent); cube.MouseLeftButtonDown -= Cube_MouseLeftButtonDown; } else if (child is DoodleCone) { DoodleCone cone = (DoodleCone)child; cone.SetBackground(Brushes.Transparent); cone.MouseLeftButtonDown -= Cone_MouseLeftButtonDown; } else if (child is DoodleCylinder) { DoodleCylinder cylinder = (DoodleCylinder)child; cylinder.SetBackground(Brushes.Transparent); cylinder.MouseLeftButtonDown -= Cylinder_MouseLeftButtonDown; } } } else { foreach (var child in doodleCanvas.Children) { if (child is DoodleCube) { DoodleCube cube = (DoodleCube)child; cube.SetBackground(Brushes.Transparent); cube.MouseLeftButtonDown += Cube_MouseLeftButtonDown; } else if (child is DoodleCone) { DoodleCone cone = (DoodleCone)child; cone.SetBackground(Brushes.Transparent); cone.MouseLeftButtonDown += Cone_MouseLeftButtonDown; } else if (child is DoodleCylinder) { DoodleCylinder cylinder = (DoodleCylinder)child; cylinder.SetBackground(Brushes.Transparent); cylinder.MouseLeftButtonDown += Cylinder_MouseLeftButtonDown; } } } }
private void ShapeSettingSelected(UIElement element) { if (element is DoodleCube) { DoodleCube cube = (DoodleCube)element; ShapeSettingSelected(cube, cube.startPoint, cube.endPoint, cube.rotate); } else if (element is DoodleCylinder) { DoodleCylinder cylinder = (DoodleCylinder)element; ShapeSettingSelected(cylinder, cylinder.startPoint, cylinder.endPoint, cylinder.rotate); } else if (element is DoodleCone) { DoodleCone cone = (DoodleCone)element; ShapeSettingSelected(cone, cone.startPoint, cone.endPoint, cone.rotate); } }
private void SetRotate(UIElement element, double rotate) { if (element is DoodleCube) { DoodleCube cube = (DoodleCube)element; cube.SetRotate(rotate); } else if (element is DoodleCone) { DoodleCone cone = (DoodleCone)element; cone.SetRotate(rotate); } else if (element is DoodleCylinder) { DoodleCylinder cylinder = (DoodleCylinder)element; cylinder.SetRotate(rotate); } }
private void SetElement(UIElement element, Point startPoint, Point endPoint) { if (element is DoodleCube) { DoodleCube cube = (DoodleCube)element; cube.SetPoints(startPoint, endPoint); } else if (element is DoodleCone) { DoodleCone cone = (DoodleCone)element; cone.SetPoints(startPoint, endPoint); } else if (element is DoodleCylinder) { DoodleCylinder cylinder = (DoodleCylinder)element; cylinder.SetPoints(startPoint, endPoint); } }
private void drawWithModel(DoodleModel model) { switch (model.drawType) { case DoodleEnumType.eraser: { } break; case DoodleEnumType.draw: { Path path = new Path() { StrokeThickness = getBrushWidth(model.lineWidth), Stroke = getBrushColor(model.lineColor) }; PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = getLocalPoint(model.points[0].GetPoint); List <Point> controls = new List <Point>(); for (int i = 0; i < model.points.Count; i++) { controls.AddRange(BezierControlPoints(model.points, i)); } for (int i = 1; i < model.points.Count; i++) { BezierSegment bs = new BezierSegment(controls[i * 2 - 1], controls[i * 2], getLocalPoint(model.points[i].GetPoint), true); bs.IsSmoothJoin = true; pathFigure.Segments.Add(bs); } PathFigureCollection pathFigureCollection = new PathFigureCollection(); pathFigureCollection.Add(pathFigure); PathGeometry pathGeometry = new PathGeometry(pathFigureCollection); path.Data = pathGeometry; doodleCanvas.Children.Add(path); } break; case DoodleEnumType.rect: { Point startPoint = getLocalPoint(model.startPoint.GetPoint); Point point = getLocalPoint(model.points[model.points.Count - 1].GetPoint); Rectangle rect = new Rectangle() { Margin = new Thickness(getSmallX(startPoint, point), getSmallY(startPoint, point), 0, 0), Width = Math.Abs(startPoint.X - point.X), Height = Math.Abs(startPoint.Y - point.Y), StrokeThickness = getBrushWidth(model.lineWidth), Stroke = getBrushColor(model.lineColor) }; doodleCanvas.Children.Add(rect); } break; case DoodleEnumType.line: { Point startPoint = getLocalPoint(model.startPoint.GetPoint); Point point = getLocalPoint((Point)model.points[model.points.Count - 1].GetPoint); Line line = new Line() { X1 = startPoint.X, Y1 = startPoint.Y, X2 = point.X, Y2 = point.Y, StrokeThickness = getBrushWidth(model.lineWidth), Stroke = getBrushColor(model.lineColor) }; doodleCanvas.Children.Add(line); } break; case DoodleEnumType.circle: { Point startPoint = getLocalPoint(model.startPoint.GetPoint); Point point = getLocalPoint((Point)model.points[model.points.Count - 1].GetPoint); Ellipse circle = new Ellipse() { Margin = new Thickness(getSmallX(startPoint, point), getSmallY(startPoint, point), 0, 0), Width = Math.Abs(startPoint.X - point.X), Height = Math.Abs(startPoint.Y - point.Y), StrokeThickness = getBrushWidth(model.lineWidth), Stroke = getBrushColor(model.lineColor) }; doodleCanvas.Children.Add(circle); } break; case DoodleEnumType.arrow: { Point startPoint = getLocalPoint(model.startPoint.GetPoint); Point point = getLocalPoint(model.points[model.points.Count - 1].GetPoint); Arrow arrow = new Arrow() { X1 = startPoint.X, Y1 = startPoint.Y, X2 = point.X, Y2 = point.Y, StrokeThickness = getBrushWidth(model.lineWidth), Stroke = getBrushColor(model.lineColor) }; doodleCanvas.Children.Add(arrow); } break; case DoodleEnumType.cube: { Point startPoint = getLocalPoint(model.startPoint.GetPoint); Point point = getLocalPoint(model.points[model.points.Count - 1].GetPoint); DoodleCube cone = new DoodleCube(startPoint, point, getBrushWidth(model.lineWidth), getBrushColor(model.lineColor)); doodleCanvas.Children.Add(cone); } break; case DoodleEnumType.cylinder: { Point startPoint = getLocalPoint(model.startPoint.GetPoint); Point point = getLocalPoint(model.points[model.points.Count - 1].GetPoint); DoodleCylinder cone = new DoodleCylinder(startPoint, point, getBrushWidth(model.lineWidth), getBrushColor(model.lineColor)); doodleCanvas.Children.Add(cone); } break; case DoodleEnumType.cone: { Point startPoint = getLocalPoint(model.startPoint.GetPoint); Point point = getLocalPoint(model.points[model.points.Count - 1].GetPoint); DoodleCone cone = new DoodleCone(startPoint, point, getBrushWidth(model.lineWidth), getBrushColor(model.lineColor)); doodleCanvas.Children.Add(cone); } break; default: break; } }
private void drawWithMovePoint(Point point) { DoodleModel model = (DoodleModel)doodleModels[doodleModels.Count - 1]; model.points.Add(new DoodlePoint(getLogicPoint(point))); switch (model.drawType) { case DoodleEnumType.eraser: { if (doodleCanvas is InkCanvas) { double eraserWidth = getEraserWidth(); eraserPointList.Add(point); if (eraserPointList.Count > 5) { eraserPointList.RemoveAt(0); } doodleCanvas.Strokes.Erase(eraserPointList, new RectangleStylusShape(eraserWidth, eraserWidth)); } } break; case DoodleEnumType.draw: { if (doodleCanvas is InkCanvas) { List <Point> pointList = new List <Point>(); pointList.Add(point); Stroke s = stroke; s.StylusPoints.Add(new StylusPointCollection(pointList)); } else if (doodleCanvas is Canvas) { Path path = (Path)element; doodleCanvas.Children.Remove(path); PathFigure pathFigure = new PathFigure(); pathFigure.StartPoint = getLocalPoint(model.points[0].GetPoint); List <Point> controls = new List <Point>(); for (int i = 0; i < model.points.Count; i++) { controls.AddRange(BezierControlPoints(model.points, i)); } for (int i = 1; i < model.points.Count; i++) { BezierSegment bs = new BezierSegment(controls[i * 2 - 1], controls[i * 2], getLocalPoint(model.points[i].GetPoint), true); bs.IsSmoothJoin = true; pathFigure.Segments.Add(bs); } PathFigureCollection pathFigureCollection = new PathFigureCollection(); pathFigureCollection.Add(pathFigure); PathGeometry pathGeometry = new PathGeometry(pathFigureCollection); path.Data = pathGeometry; doodleCanvas.Children.Add(path); } } break; case DoodleEnumType.rect: { Point startPoint = getLocalPoint(model.startPoint.GetPoint); Rectangle rect = (Rectangle)element; rect.Margin = new Thickness(getSmallX(startPoint, point), getSmallY(startPoint, point), 0, 0); rect.Width = Math.Abs(startPoint.X - point.X); rect.Height = Math.Abs(startPoint.Y - point.Y); } break; case DoodleEnumType.line: { Point startPoint = getLocalPoint(model.startPoint.GetPoint); Line line = (Line)element; line.X1 = startPoint.X; line.Y1 = startPoint.Y; line.X2 = point.X; line.Y2 = point.Y; } break; case DoodleEnumType.circle: { Point startPoint = getLocalPoint(model.startPoint.GetPoint); Ellipse circle = (Ellipse)element; circle.Margin = new Thickness(getSmallX(startPoint, point), getSmallY(startPoint, point), 0, 0); circle.Width = Math.Abs(startPoint.X - point.X); circle.Height = Math.Abs(startPoint.Y - point.Y); } break; case DoodleEnumType.arrow: { Point startPoint = getLocalPoint(model.startPoint.GetPoint); Arrow arrow = (Arrow)element; arrow.X1 = startPoint.X; arrow.Y1 = startPoint.Y; arrow.X2 = point.X; arrow.Y2 = point.Y; } break; case DoodleEnumType.cube: { Point startPoint = getLocalPoint(model.startPoint.GetPoint); DoodleCube cone = (DoodleCube)element; cone.SetPoints(startPoint, point); } break; case DoodleEnumType.cylinder: { Point startPoint = getLocalPoint(model.startPoint.GetPoint); DoodleCylinder cone = (DoodleCylinder)element; cone.SetPoints(startPoint, point); } break; case DoodleEnumType.cone: { Point startPoint = getLocalPoint(model.startPoint.GetPoint); DoodleCone cone = (DoodleCone)element; cone.SetPoints(startPoint, point); } break; default: break; } }
private void drawWithBeganPoint(Point point) { DoodleModel model = new DoodleModel(); model.points.Add(new DoodlePoint(getLogicPoint(point))); model.drawType = drawType; model.lineColor = lineColor; model.lineWidth = lineWidth; doodleModels.Add(model); switch (model.drawType) { case DoodleEnumType.eraser: { if (doodleCanvas is InkCanvas) { double eraserWidth = getEraserWidth(); eraserPointList = new List <Point>(); eraserPointList.Add(point); doodleCanvas.Strokes.Erase(eraserPointList, new RectangleStylusShape(eraserWidth, eraserWidth)); } } break; case DoodleEnumType.draw: { if (doodleCanvas is InkCanvas) { DrawingAttributes attributes = new DrawingAttributes(); attributes.Color = getColor(lineColor); attributes.Width = attributes.Height = getBrushWidth(lineWidth); List <Point> pointList = new List <Point>(); pointList.Add(point); Stroke s = new Stroke(new StylusPointCollection(pointList), attributes); doodleCanvas.Strokes.Add(s); stroke = s; } else if (doodleCanvas is Canvas) { Path path = new Path() { StrokeThickness = getBrushWidth(lineWidth), Stroke = getBrushColor(lineColor) }; doodleCanvas.Children.Add(path); element = path; } } break; case DoodleEnumType.rect: { Rectangle rect = new Rectangle() { Margin = new Thickness(point.X, point.Y, 0, 0), Width = 0, Height = 0, StrokeThickness = getBrushWidth(lineWidth), Stroke = getBrushColor(lineColor) }; doodleCanvas.Children.Add(rect); element = rect; } break; case DoodleEnumType.line: { Line line = new Line() { X1 = point.X, Y1 = point.Y, X2 = point.X, Y2 = point.Y, StrokeThickness = getBrushWidth(lineWidth), Stroke = getBrushColor(lineColor) }; doodleCanvas.Children.Add(line); element = line; } break; case DoodleEnumType.circle: { Ellipse circle = new Ellipse() { Margin = new Thickness(point.X, point.Y, 0, 0), Width = 0, Height = 0, StrokeThickness = getBrushWidth(lineWidth), Stroke = getBrushColor(lineColor) }; doodleCanvas.Children.Add(circle); element = circle; } break; case DoodleEnumType.arrow: { Arrow arrow = new Arrow() { X1 = point.X, Y1 = point.Y, X2 = point.X, Y2 = point.Y, StrokeThickness = getBrushWidth(lineWidth), Stroke = getBrushColor(lineColor) }; doodleCanvas.Children.Add(arrow); element = arrow; } break; case DoodleEnumType.cube: { DoodleCube cone = new DoodleCube(point, point, getBrushWidth(lineWidth), getBrushColor(lineColor)); doodleCanvas.Children.Add(cone); element = cone; } break; case DoodleEnumType.cylinder: { DoodleCylinder cone = new DoodleCylinder(point, point, getBrushWidth(lineWidth), getBrushColor(lineColor)); doodleCanvas.Children.Add(cone); element = cone; } break; case DoodleEnumType.cone: { DoodleCone cone = new DoodleCone(point, point, getBrushWidth(lineWidth), getBrushColor(lineColor)); doodleCanvas.Children.Add(cone); element = cone; } break; default: break; } }