// Implement DrawRectangle public void DrawRectangle(DrawingModel.Point startPoint, DrawingModel.Point endPoint) { RectangleF rectangle = GetRectangle(startPoint, endPoint); _graphics.FillRectangle(new SolidBrush(Color.Yellow), rectangle); _graphics.DrawRectangle(Pens.Black, System.Drawing.Rectangle.Round(rectangle)); }
// 創建 rectangle private RectangleF GetRectangle(DrawingModel.Point startPoint, DrawingModel.Point endPoint) { float left = (float)startPoint.GetSmallLeft(endPoint); float top = (float)startPoint.GetSmallTop(endPoint); float width = (float)startPoint.GetLeftDifference(endPoint); float height = (float)startPoint.GetTopDifference(endPoint); return(new RectangleF(new PointF(left, top), new SizeF(new PointF(width, height)))); }
// 劃出標示線 private void DrawMarkLines(DrawingModel.Point startPoint, DrawingModel.Point endPoint) { float[] dashValues = { Constant.TWO, Constant.TWO }; Pen redPen = new Pen(Color.Red); redPen.DashPattern = dashValues; RectangleF rectangle = GetRectangle(startPoint, endPoint); _graphics.DrawRectangle(redPen, System.Drawing.Rectangle.Round(rectangle)); }
// Implement DrawSixSide public void DrawSixSide(DrawingModel.Point startPoint, DrawingModel.Point endPoint) { Windows.UI.Xaml.Shapes.Polygon sixSide = new Windows.UI.Xaml.Shapes.Polygon(); PointCollection collection = GetSixSidePoints(startPoint, endPoint); sixSide.Points = collection; sixSide.Fill = new SolidColorBrush(Colors.Orange); sixSide.Stroke = new SolidColorBrush(Colors.Black); _canvas.Children.Add(sixSide); }
/// <summary> Draw line. </summary> /// /// <param name="point1.X"> The first x value. </param> /// <param name="point1.Y"> The first y value. </param> /// <param name="point2.X"> The second x value. </param> /// <param name="point2.Y"> The second y value. </param> /// <param name="isRedLine"> True if is red line, false if not. </param> /// /// ### <remarks> Chen-Tai,Peng, 12/12/2018. </remarks> public void DrawLine(DrawingModel.Point point1, DrawingModel.Point point2, bool isRedLine) { Windows.UI.Xaml.Shapes.Line line = new Windows.UI.Xaml.Shapes.Line(); line.X1 = point1.X; line.Y1 = point1.Y; line.X2 = point2.X; line.Y2 = point2.Y; line.Stroke = new SolidColorBrush(isRedLine ? Colors.Red : Colors.Black); _canvas.Children.Add(line); }
/// <summary> Draw ellipse. </summary> /// /// <param name="point1.X"> The first x value. </param> /// <param name="point1.Y"> The first y value. </param> /// <param name="point2.X"> The second x value. </param> /// <param name="point2.Y"> The second y value. </param> /// <param name="isRedLine"> True if is red line, false if not. </param> public void DrawEllipse(DrawingModel.Point point1, DrawingModel.Point point2, bool isRedLine) { Windows.UI.Xaml.Shapes.Ellipse shape = new Windows.UI.Xaml.Shapes.Ellipse(); shape.Fill = new SolidColorBrush(Colors.AliceBlue); shape.Stroke = new SolidColorBrush(isRedLine ? Colors.Red : Colors.Black); shape.Width = Math.Abs(point2.X - point1.X); shape.Height = Math.Abs(point2.Y - point1.Y); Canvas.SetTop(shape, (point1.Y < point2.Y) ? point1.Y : point2.Y); Canvas.SetLeft(shape, (point1.X < point2.X) ? point1.X : point2.X); _canvas.Children.Add(shape); }
// 劃出標示線 private void DrawMarkLines(DrawingModel.Point startPoint, DrawingModel.Point endPoint) { DoubleCollection dashCollection = new DoubleCollection(); dashCollection.Add(Constant.TWO); dashCollection.Add(Constant.TWO); Windows.UI.Xaml.Shapes.Rectangle rectangle = GetRectangle(startPoint, endPoint); rectangle.StrokeDashArray = dashCollection; rectangle.Stroke = new SolidColorBrush(Colors.Red); _canvas.Children.Add(rectangle); }
// use start, end points to calculate six side points private PointCollection GetSixSidePoints(DrawingModel.Point startPoint, DrawingModel.Point endPoint) { double horizontalLine = CalculateHorizontalLine(startPoint, endPoint); PointCollection points = new PointCollection(); for (int side = 0; side < Constant.SIX; side++) { points.Add(CalculatePointPosition(side, horizontalLine, startPoint, endPoint)); } return(points); }
// use start, end points to calculate six side points private PointF[] GetSixSidePoints(DrawingModel.Point startPoint, DrawingModel.Point endPoint) { double horizontalLine = CalculateHorizontalLine(startPoint, endPoint); PointF[] points = new PointF[Constant.SIX]; for (int side = 0; side < Constant.SIX; side++) { points[side] = CalculatePointPosition(side, horizontalLine, startPoint, endPoint); } return(points); }
/// <summary> Draw diamond. </summary> /// /// <param name="x1"> The first x value. </param> /// <param name="y1"> The first y value. </param> /// <param name="x2"> The second x value. </param> /// <param name="y2"> The second y value. </param> /// <param name="isRedLine"> True if is red line, false if not. </param> /// /// ### <remarks> Chen-Tai,Peng, 12/12/2018. </remarks> public void DrawDiamond(DrawingModel.Point point1, DrawingModel.Point point2, bool isRedLine) { int middleX = (int)(point1.X + (point2.X - point1.X) / TWO); int middleY = (int)(point1.Y + (point2.Y - point1.Y) / TWO); System.Drawing.Point[] points = { new System.Drawing.Point(middleX, (int)point1.Y), new System.Drawing.Point((int)point1.X, middleY), new System.Drawing.Point(middleX, (int)point2.Y), new System.Drawing.Point((int)point2.X, middleY) }; _graphics.FillPolygon(Brushes.BlueViolet, points); _graphics.DrawPolygon(isRedLine ? Pens.Red : Pens.Black, points); }
// 取得 4 個corner 的圓座標 private List <DrawingModel.Point> GetCornerPointsPosition(DrawingModel.Point startPoint, DrawingModel.Point endPoint) { List <DrawingModel.Point> points = new List <DrawingModel.Point>(); for (int count = 0; count < Constant.FOUR; count++) { double left = (count % Constant.TWO == 0) ? startPoint.GetSmallLeft(endPoint) : startPoint.GetBigLeft(endPoint); double top = (count / Constant.TWO == 0) ? startPoint.GetSmallTop(endPoint) : startPoint.GetBigTop(endPoint); left -= Constant.MARK_CIRCLE_RADIUS; top -= Constant.MARK_CIRCLE_RADIUS; points.Add(new DrawingModel.Point(left, top)); } return(points); }
// Draw four corner private void DrawCorners(DrawingModel.Point startPoint, DrawingModel.Point endPoint) { List <DrawingModel.Point> points = GetCornerPointsPosition(startPoint, endPoint); foreach (DrawingModel.Point point in points) { float left = (float)point.Left; float top = (float)point.Top; float diameter = Constant.TWO * Constant.MARK_CIRCLE_RADIUS; RectangleF rectangle = new RectangleF(new PointF(left, top), new SizeF(new PointF(diameter, diameter))); _graphics.FillEllipse(new SolidBrush(Color.White), rectangle); _graphics.DrawEllipse(Pens.Black, rectangle); } }
// caculate horizontal line length private double CalculateHorizontalLine(DrawingModel.Point startPoint, DrawingModel.Point endPoint) { double length = startPoint.GetLeftDifference(endPoint); double width = startPoint.GetTopDifference(endPoint); double horizontalLine = 0; if (IsLengthBiggerThanWidth(length, width)) { horizontalLine = GetHorizontalLineWithBiggerLength(length, width); } else { horizontalLine = GetHorizontalLineWithBiggerWidth(length, width); } return(horizontalLine); }
/// <summary> Draw diamond. </summary> /// /// <param name="point1.X"> The first x value. </param> /// <param name="point1.Y"> The first y value. </param> /// <param name="point2.X"> The second x value. </param> /// <param name="point2.Y"> The second y value. </param> /// <param name="isRedLine"> True if is red line, false if not. </param> /// /// ### <remarks> Chen-Tai,Peng, 12/12/2018. </remarks> public void DrawDiamond(DrawingModel.Point point1, DrawingModel.Point point2, bool isRedLine) { Windows.UI.Xaml.Shapes.Polygon shape = new Windows.UI.Xaml.Shapes.Polygon(); int middleX = (int)(point1.X + (point2.X - point1.X) / TWO); int middleY = (int)(point1.Y + (point2.Y - point1.Y) / TWO); PointCollection points = new PointCollection(); points.Add(new Windows.Foundation.Point(middleX, (int)point1.Y)); points.Add(new Windows.Foundation.Point((int)point1.X, middleY)); points.Add(new Windows.Foundation.Point(middleX, (int)point2.Y)); points.Add(new Windows.Foundation.Point((int)point2.X, middleY)); shape.Points = points; shape.Margin = new Windows.UI.Xaml.Thickness(THICK); shape.Fill = new SolidColorBrush(Colors.AliceBlue); shape.Stroke = new SolidColorBrush(isRedLine ? Colors.Red : Colors.Black); _canvas.Children.Add(shape); }
// Draw four corner private void DrawCorners(DrawingModel.Point startPoint, DrawingModel.Point endPoint) { List <DrawingModel.Point> points = GetCornerPointsPosition(startPoint, endPoint); foreach (DrawingModel.Point point in points) { float left = (float)point.Left; float top = (float)point.Top; float diameter = Constant.TWO * Constant.MARK_CIRCLE_RADIUS; Ellipse circle = new Ellipse(); circle.Width = diameter; circle.Height = diameter; circle.Margin = new Windows.UI.Xaml.Thickness(left, top, 0, 0); circle.Fill = new SolidColorBrush(Colors.White); circle.Stroke = new SolidColorBrush(Colors.Black); _canvas.Children.Add(circle); } }
// use side to calculate point's position private PointF CalculatePointPosition(int side, double horizontalLine, DrawingModel.Point startPoint, DrawingModel.Point endPoint) { double left = 0; double top = 0; double length = startPoint.GetLeftDifference(endPoint); double width = startPoint.GetTopDifference(endPoint); if (side % Constant.THREE == 0) { left = (side == 0) ? length : 0; top = width / Constant.TWO; } else { left = (side % Constant.TWO == 0) ? length - horizontalLine : horizontalLine; top = (side < Constant.THREE) ? 0 : width; } DetermineAbsolutePosition(ref left, ref top, startPoint, endPoint); return(new PointF((float)left, (float)top)); }
// Implement DrawLine public void DrawLine(DrawingModel.Point startPoint, DrawingModel.Point endPoint) { _graphics.DrawLine(Pens.Black, (float)startPoint.Left, (float)startPoint.Top, (float)endPoint.Left, (float)endPoint.Top); }
// Implement mark outlines public void MarkOutlines(DrawingModel.Point startPoint, DrawingModel.Point endPoint) { DrawMarkLines(startPoint, endPoint); DrawCorners(startPoint, endPoint); }
// Determine the position on canvas private void DetermineAbsolutePosition(ref double left, ref double top, DrawingModel.Point startPoint, DrawingModel.Point endPoint) { left += startPoint.GetSmallLeft(endPoint); top += startPoint.GetSmallTop(endPoint); }
// Implement DrawSixSide public void DrawSixSide(DrawingModel.Point startPoint, DrawingModel.Point endPoint) { PointF[] points = GetSixSidePoints(startPoint, endPoint); _graphics.FillPolygon(new SolidBrush(Color.Orange), points); _graphics.DrawPolygon(Pens.Black, points); }
/// <summary> Draw line. </summary> /// /// <param name="point1"> The first x value. </param> /// <param name="point2"> The second y value. </param> /// <param name="isRedLine"> True if is red line, false if not. </param> /// /// ### <remarks> Chen-Tai,Peng, 12/12/2018. </remarks> public void DrawLine(DrawingModel.Point point1, DrawingModel.Point point2, bool isRedLine) { _graphics.DrawLine(isRedLine ? Pens.Red : Pens.Black, (float)point1.X, (float)point1.Y, (float)point2.X, (float)point2.Y); }