/// <summary> /// Get <see cref="XLine"/> maximum length for <see cref="LineFixedLengthFlags.All"/> mode. /// </summary> /// <param name="line">The line shape.</param> /// <param name="x1">The calculated X coordinate for <see cref="XLine.Start"/> point.</param> /// <param name="y1">The calculated Y coordinate for <see cref="XLine.Start"/> point.</param> /// <param name="x2">The calculated X coordinate for <see cref="XLine.End"/> point.</param> /// <param name="y2">The calculated Y coordinate for <see cref="XLine.End"/> point.</param> public static void GetMaxLengthAll(this XLine line, ref double x1, ref double y1, ref double x2, ref double y2) { var ls = line.Style.LineStyle; bool shortenStart = ls.FixedLength.StartTrigger.Flags != ShapeStateFlags.Default && line.Start.State.Flags.HasFlag(ls.FixedLength.StartTrigger.Flags) && ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.Start); bool shortenEnd = ls.FixedLength.EndTrigger.Flags != ShapeStateFlags.Default && line.End.State.Flags.HasFlag(ls.FixedLength.EndTrigger.Flags) && ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.End); if (shortenStart && !shortenEnd) { double dx = x1 - x2; double dy = y1 - y2; double distance = Sqrt(dx * dx + dy * dy); x1 = x2 - (x2 - x1) / distance * ls.FixedLength.Length; y1 = y2 - (y2 - y1) / distance * ls.FixedLength.Length; } if (!shortenStart && shortenEnd) { double dx = x2 - x1; double dy = y2 - y1; double distance = Sqrt(dx * dx + dy * dy); x2 = x1 - (x1 - x2) / distance * ls.FixedLength.Length; y2 = y1 - (y1 - y2) / distance * ls.FixedLength.Length; } }
/// <summary> /// Get <see cref="XLine"/> maximum length using <see cref="LineFixedLengthFlags"/>. /// </summary> /// <param name="line">The line shape.</param> /// <param name="x1">The calculated X coordinate for <see cref="XLine.Start"/> point.</param> /// <param name="y1">The calculated Y coordinate for <see cref="XLine.Start"/> point.</param> /// <param name="x2">The calculated X coordinate for <see cref="XLine.End"/> point.</param> /// <param name="y2">The calculated Y coordinate for <see cref="XLine.End"/> point.</param> public static void GetMaxLength(this XLine line, ref double x1, ref double y1, ref double x2, ref double y2) { var ls = line.Style.LineStyle; if (ls.FixedLength.Flags == LineFixedLengthFlags.Disabled) { return; } if (ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.All)) { GetMaxLengthAll(line, ref x1, ref y1, ref x2, ref y2); } else { if (ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.Vertical)) { bool isVertical = Round(x1, 1) == Round(x2, 1); if (isVertical) { GetMaxLengthVertical(line, ref y1, ref y2); } } if (ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.Horizontal)) { bool isHorizontal = Round(y1, 1) == Round(y2, 1); if (isHorizontal) { GetMaxLengthHorizontal(line, ref x1, ref x2); } } } }
/// <summary> /// Transfer selection state to <see cref="ToolState.Two"/>. /// </summary> public void ToStateTwo() { _line12 = XLine.Create(0, 0, _style, null); _helperPoint2 = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_line12); _layer.Shapes = _layer.Shapes.Add(_helperPoint2); }
/// <summary> /// Transfer selection state to <see cref="ToolState.Three"/>. /// </summary> public void ToStateThree() { _line43 = XLine.Create(0, 0, _style, null); _line23 = XLine.Create(0, 0, _style, null); _helperPoint3 = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_line43); _layer.Shapes = _layer.Shapes.Add(_line23); _layer.Shapes = _layer.Shapes.Add(_helperPoint3); }
/// <summary> /// /// </summary> /// <param name="line"></param> /// <param name="rect"></param> /// <param name="selected"></param> /// <param name="threshold"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static bool HitTestLine(XLine line, Rect2 rect, ISet<BaseShape> selected, double threshold, double dx, double dy) { if (ShapeBounds.GetPointBounds(line.Start, threshold, dx, dy).IntersectsWith(rect) || ShapeBounds.GetPointBounds(line.End, threshold, dx, dy).IntersectsWith(rect) || MathHelpers.LineIntersectsWithRect(rect, new Point2(line.Start.X, line.Start.Y), new Point2(line.End.X, line.End.Y))) { if (selected != null) { selected.Add(line); return false; } else { return true; } } return false; }
/// <summary> /// /// </summary> /// <param name="line"></param> /// <param name="v"></param> /// <param name="threshold"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static BaseShape HitTestLine(XLine line, Vector2 v, double threshold, double dx, double dy) { if (ShapeBounds.GetPointBounds(line.Start, threshold, dx, dy).Contains(v)) { return line.Start; } if (ShapeBounds.GetPointBounds(line.End, threshold, dx, dy).Contains(v)) { return line.End; } if (ShapeBounds.Contains(line, v, threshold, dx, dy)) { return line; } return null; }
/// <summary> /// Transfer selection state to <see cref="ToolState.Two"/>. /// </summary> public void ToStateTwo() { if (_p1HelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_p1HelperPoint); _p1HelperPoint = null; } if (_p2HelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_p2HelperPoint); _p2HelperPoint = null; } _startLine = XLine.Create(0, 0, _style, null); _startHelperPoint = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_startLine); _layer.Shapes = _layer.Shapes.Add(_startHelperPoint); }
/// <summary> /// Get <see cref="XLine"/> maximum length for <see cref="LineFixedLengthFlags.Vertical"/> mode. /// </summary> /// <param name="line">The line shape.</param> /// <param name="y1">The calculated Y coordinate for <see cref="XLine.Start"/> point.</param> /// <param name="y2">The calculated Y coordinate for <see cref="XLine.End"/> point.</param> public static void GetMaxLengthVertical(this XLine line, ref double y1, ref double y2) { var ls = line.Style.LineStyle; bool shortenStart = ls.FixedLength.StartTrigger.Flags != ShapeStateFlags.Default && line.Start.State.Flags.HasFlag(ls.FixedLength.StartTrigger.Flags) && ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.Start); bool shortenEnd = ls.FixedLength.EndTrigger.Flags != ShapeStateFlags.Default && line.End.State.Flags.HasFlag(ls.FixedLength.EndTrigger.Flags) && ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.End); if (shortenStart && !shortenEnd) { if (y2 > y1) { y1 = y2 - ls.FixedLength.Length; } else { y1 = y2 + ls.FixedLength.Length; } } if (!shortenStart && shortenEnd) { if (y2 > y1) { y2 = y1 + ls.FixedLength.Length; } else { y2 = y1 - ls.FixedLength.Length; } } }
/// <summary> /// Get <see cref="XLine"/> maximum length for <see cref="LineFixedLengthFlags.Horizontal"/> mode. /// </summary> /// <param name="line">The line shape.</param> /// <param name="x1">The calculated X coordinate for <see cref="XLine.Start"/> point.</param> /// <param name="x2">The calculated X coordinate for <see cref="XLine.End"/> point.</param> public static void GetMaxLengthHorizontal(this XLine line, ref double x1, ref double x2) { var ls = line.Style.LineStyle; bool shortenStart = ls.FixedLength.StartTrigger.Flags != ShapeStateFlags.Default && line.Start.State.Flags.HasFlag(ls.FixedLength.StartTrigger.Flags) && ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.Start); bool shortenEnd = ls.FixedLength.EndTrigger.Flags != ShapeStateFlags.Default && line.End.State.Flags.HasFlag(ls.FixedLength.EndTrigger.Flags) && ls.FixedLength.Flags.HasFlag(LineFixedLengthFlags.End); if (shortenStart && !shortenEnd) { if (x2 > x1) { x1 = x2 - ls.FixedLength.Length; } else { x1 = x2 + ls.FixedLength.Length; } } if (!shortenStart && shortenEnd) { if (x2 > x1) { x2 = x1 + ls.FixedLength.Length; } else { x2 = x1 - ls.FixedLength.Length; } } }
/// <inheritdoc/> public override void Draw(object dc, XLine line, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var canvas = dc as SKCanvas; using (SKPaint strokeLine = ToSKPaintPen(line.Style, _scaleToPage, _sourceDpi, _targetDpi)) { SKPoint pt1, pt2; DrawLineArrowsInternal(canvas, line, dx, dy, out pt1, out pt2); if (line.Style.LineStyle.IsCurved) { DrawLineCurveInternal( canvas, strokeLine, line.IsStroked, ref pt1, ref pt2, line.Style.LineStyle.Curvature, line.Style.LineStyle.CurveOrientation, line.Start.Alignment, line.End.Alignment); } else { DrawLineInternal(canvas, strokeLine, line.IsStroked, ref pt1, ref pt2); } } }
private void DrawLineArrowsInternal(SKCanvas canvas, XLine line, double dx, double dy, out SKPoint pt1, out SKPoint pt2) { using (SKPaint fillStartArrow = ToSKPaintBrush(line.Style.StartArrowStyle.Fill)) using (SKPaint strokeStartArrow = ToSKPaintPen(line.Style.StartArrowStyle, _scaleToPage, _sourceDpi, _targetDpi)) using (SKPaint fillEndArrow = ToSKPaintBrush(line.Style.EndArrowStyle.Fill)) using (SKPaint strokeEndArrow = ToSKPaintPen(line.Style.EndArrowStyle, _scaleToPage, _sourceDpi, _targetDpi)) { double _x1 = line.Start.X + dx; double _y1 = line.Start.Y + dy; double _x2 = line.End.X + dx; double _y2 = line.End.Y + dy; line.GetMaxLength(ref _x1, ref _y1, ref _x2, ref _y2); float x1 = _scaleToPage(_x1); float y1 = _scaleToPage(_y1); float x2 = _scaleToPage(_x2); float y2 = _scaleToPage(_y2); var sas = line.Style.StartArrowStyle; var eas = line.Style.EndArrowStyle; double a1 = Math.Atan2(y1 - y2, x1 - x2); double a2 = Math.Atan2(y2 - y1, x2 - x1); // Draw start arrow. pt1 = DrawLineArrowInternal(canvas, strokeStartArrow, fillStartArrow, x1, y1, a1, sas); // Draw end arrow. pt2 = DrawLineArrowInternal(canvas, strokeEndArrow, fillEndArrow, x2, y2, a2, eas); } }
/// <inheritdoc/> public override void Draw(object dc, XLine line, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { // TODO: Implement Draw line. }
/// <inheritdoc/> public override void Draw(object dc, XLine line, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var _dc = dc as AM.DrawingContext; AM.Pen strokeLine = ToPen(line.Style, _scaleToPage); A.Point pt1, pt2; DrawLineArrowsInternal(_dc, line, dx, dy, out pt1, out pt2); if (line.Style.LineStyle.IsCurved) { DrawLineCurveInternal( _dc, strokeLine, line.IsStroked, ref pt1, ref pt2, line.Style.LineStyle.Curvature, line.Style.LineStyle.CurveOrientation, line.Start.Alignment, line.End.Alignment); } else { DrawLineInternal(_dc, strokeLine, line.IsStroked, ref pt1, ref pt2); } }
public void Inherits_From_BaseShape() { var target = new XLine(); Assert.True(target is BaseShape); }
/// <inheritdoc/> public override void Draw(object dc, XLine line, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var _dc = dc as DrawingContext; var style = line.Style; if (style == null) return; double zoom = _state.ZoomX; double thicknessLine = style.Thickness / zoom; double halfLine = thicknessLine / 2.0; double thicknessStartArrow = style.StartArrowStyle.Thickness / zoom; double halfStartArrow = thicknessStartArrow / 2.0; double thicknessEndArrow = style.EndArrowStyle.Thickness / zoom; double halfEndArrow = thicknessEndArrow / 2.0; // Line style. Tuple<Brush, Pen> styleCached = _styleCache.Get(style); Brush fillLine; Pen strokeLine; if (styleCached != null) { fillLine = styleCached.Item1; strokeLine = styleCached.Item2; } else { fillLine = CreateBrush(style.Fill); strokeLine = CreatePen(style, thicknessLine); _styleCache.Set(style, Tuple.Create(fillLine, strokeLine)); } Point pt1, pt2; DrawLineArrowsInternal(_dc, line, style, halfStartArrow, halfEndArrow, thicknessStartArrow, thicknessEndArrow, dx, dy, out pt1, out pt2); if (line.Style.LineStyle.IsCurved) { DrawLineCurveInternal(_dc, halfLine, strokeLine, line, ref pt1, ref pt2, dx, dy); } else { DrawLineInternal(_dc, halfLine, strokeLine, line.IsStroked, ref pt1, ref pt2); } }
/// <summary> /// Remove selection. /// </summary> public void Remove() { if (_line12 != null) { _layer.Shapes = _layer.Shapes.Remove(_line12); _line12 = null; } if (_line43 != null) { _layer.Shapes = _layer.Shapes.Remove(_line43); _line43 = null; } if (_line23 != null) { _layer.Shapes = _layer.Shapes.Remove(_line23); _line23 = null; } if (_helperPoint1 != null) { _layer.Shapes = _layer.Shapes.Remove(_helperPoint1); _helperPoint1 = null; } if (_helperPoint2 != null) { _layer.Shapes = _layer.Shapes.Remove(_helperPoint2); _helperPoint2 = null; } if (_helperPoint3 != null) { _layer.Shapes = _layer.Shapes.Remove(_helperPoint3); _helperPoint3 = null; } if (_helperPoint4 != null) { _layer.Shapes = _layer.Shapes.Remove(_helperPoint4); _helperPoint4 = null; } _layer.Invalidate(); }
/// <inheritdoc/> public override void Draw(object dc, XLine line, double dx, double dy, ImmutableArray<XProperty> db, XRecord r) { var _gfx = dc as Graphics; Pen strokeLine = ToPen(line.Style, _scaleToPage); PointF pt1, pt2; DrawLineArrowsInternal(line, dx, dy, _gfx, out pt1, out pt2); if (line.Style.LineStyle.IsCurved) { DrawLineCurveInternal( _gfx, strokeLine, line.IsStroked, ref pt1, ref pt2, line.Style.LineStyle.Curvature, line.Style.LineStyle.CurveOrientation, line.Start.Alignment, line.End.Alignment); } else { DrawLineInternal(_gfx, strokeLine, line.IsStroked, ref pt1, ref pt2); } strokeLine.Dispose(); }
private void DrawLineArrowsInternal(XLine line, double dx, double dy, Graphics gfx, out PointF pt1, out PointF pt2) { Brush fillStartArrow = ToSolidBrush(line.Style.StartArrowStyle.Fill); Pen strokeStartArrow = ToPen(line.Style.StartArrowStyle, _scaleToPage); Brush fillEndArrow = ToSolidBrush(line.Style.EndArrowStyle.Fill); Pen strokeEndArrow = ToPen(line.Style.EndArrowStyle, _scaleToPage); double _x1 = line.Start.X + dx; double _y1 = line.Start.Y + dy; double _x2 = line.End.X + dx; double _y2 = line.End.Y + dy; line.GetMaxLength(ref _x1, ref _y1, ref _x2, ref _y2); float x1 = _scaleToPage(_x1); float y1 = _scaleToPage(_y1); float x2 = _scaleToPage(_x2); float y2 = _scaleToPage(_y2); var sas = line.Style.StartArrowStyle; var eas = line.Style.EndArrowStyle; float a1 = (float)(Math.Atan2(y1 - y2, x1 - x2) * 180.0 / Math.PI); float a2 = (float)(Math.Atan2(y2 - y1, x2 - x1) * 180.0 / Math.PI); // Draw start arrow. pt1 = DrawLineArrowInternal(gfx, strokeStartArrow, fillStartArrow, x1, y1, a1, sas); // Draw end arrow. pt2 = DrawLineArrowInternal(gfx, strokeEndArrow, fillEndArrow, x2, y2, a2, eas); fillStartArrow.Dispose(); strokeStartArrow.Dispose(); fillEndArrow.Dispose(); strokeEndArrow.Dispose(); }
/// <inheritdoc/> public override void LeftDown(double x, double y) { base.LeftDown(x, y); var editor = _serviceProvider.GetService<ProjectEditor>(); double sx = editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(x, editor.Project.Options.SnapX) : x; double sy = editor.Project.Options.SnapToGrid ? ProjectEditor.Snap(y, editor.Project.Options.SnapY) : y; switch (_currentState) { case ToolState.None: { var style = editor.Project.CurrentStyleLibrary.Selected; _line = XLine.Create( sx, sy, editor.Project.Options.CloneStyle ? style.Clone() : style, editor.Project.Options.PointShape, editor.Project.Options.DefaultIsStroked); if (editor.Project.Options.TryToConnect) { var result = editor.TryToGetConnectionPoint(sx, sy); if (result != null) { _line.Start = result; } else { editor.TryToSplitLine(x, y, _line.Start); } } editor.Project.CurrentContainer.WorkingLayer.Shapes = editor.Project.CurrentContainer.WorkingLayer.Shapes.Add(_line); editor.Project.CurrentContainer.WorkingLayer.Invalidate(); ToStateOne(); Move(_line); _currentState = ToolState.One; editor.CancelAvailable = true; } break; case ToolState.One: { if (_line != null) { _line.End.X = sx; _line.End.Y = sy; if (editor.Project.Options.TryToConnect) { var result = editor.TryToGetConnectionPoint(sx, sy); if (result != null) { _line.End = result; } else { editor.TryToSplitLine(x, y, _line.End); } } editor.Project.CurrentContainer.WorkingLayer.Shapes = editor.Project.CurrentContainer.WorkingLayer.Shapes.Remove(_line); Remove(); base.Finalize(_line); editor.Project.AddShape(editor.Project.CurrentContainer.CurrentLayer, _line); _currentState = ToolState.None; editor.CancelAvailable = false; } } break; } }
private void DrawLineCurveInternal(DrawingContext dc, double half, Pen pen, XLine line, ref Point pt1, ref Point pt2, double dx, double dy) { double p1x = pt1.X; double p1y = pt1.Y; double p2x = pt2.X; double p2y = pt2.Y; XLineExtensions.GetCurvedLineBezierControlPoints( line.Style.LineStyle.CurveOrientation, line.Style.LineStyle.Curvature, line.Start.Alignment, line.End.Alignment, ref p1x, ref p1y, ref p2x, ref p2y); PathGeometry pg = _curvedLineCache.Get(line); if (pg != null) { var pf = pg.Figures[0]; pf.StartPoint = new Point(pt1.X + dx, pt1.Y + dy); pf.IsFilled = false; var bs = pf.Segments[0] as BezierSegment; bs.Point1 = new Point(p1x + dx, p1y + dy); bs.Point2 = new Point(p2x + dx, p2y + dy); bs.Point3 = new Point(pt2.X + dx, pt2.Y + dy); bs.IsStroked = line.IsStroked; } else { var pf = new PathFigure() { StartPoint = new Point(pt1.X + dx, pt1.Y + dy), IsFilled = false }; var bs = new BezierSegment( new Point(p1x + dx, p1y + dy), new Point(p2x + dx, p2y + dy), new Point(pt2.X + dx, pt2.Y + dy), line.IsStroked); //bs.Freeze(); pf.Segments.Add(bs); //pf.Freeze(); pg = new PathGeometry(); pg.Figures.Add(pf); //pg.Freeze(); _curvedLineCache.Set(line, pg); } DrawPathGeometryInternal(dc, half, null, pen, line.IsStroked, false, pg); }
private void DrawLineArrowsInternal(DrawingContext dc, XLine line, ShapeStyle style, double halfStart, double halfEnd, double thicknessStart, double thicknessEnd, double dx, double dy, out Point pt1, out Point pt2) { // Start arrow style. Tuple<Brush, Pen> startArrowCache = _arrowStyleCache.Get(style.StartArrowStyle); Brush fillStartArrow; Pen strokeStartArrow; if (startArrowCache != null) { fillStartArrow = startArrowCache.Item1; strokeStartArrow = startArrowCache.Item2; } else { fillStartArrow = CreateBrush(style.StartArrowStyle.Fill); strokeStartArrow = CreatePen(style.StartArrowStyle, thicknessStart); _arrowStyleCache.Set(style.StartArrowStyle, Tuple.Create(fillStartArrow, strokeStartArrow)); } // End arrow style. Tuple<Brush, Pen> endArrowCache = _arrowStyleCache.Get(style.EndArrowStyle); Brush fillEndArrow; Pen strokeEndArrow; if (endArrowCache != null) { fillEndArrow = endArrowCache.Item1; strokeEndArrow = endArrowCache.Item2; } else { fillEndArrow = CreateBrush(style.EndArrowStyle.Fill); strokeEndArrow = CreatePen(style.EndArrowStyle, thicknessEnd); _arrowStyleCache.Set(style.EndArrowStyle, Tuple.Create(fillEndArrow, strokeEndArrow)); } // Line max length. double x1 = line.Start.X + dx; double y1 = line.Start.Y + dy; double x2 = line.End.X + dx; double y2 = line.End.Y + dy; line.GetMaxLength(ref x1, ref y1, ref x2, ref y2); // Arrow transforms. var sas = style.StartArrowStyle; var eas = style.EndArrowStyle; double a1 = Math.Atan2(y1 - y2, x1 - x2) * 180.0 / Math.PI; double a2 = Math.Atan2(y2 - y1, x2 - x1) * 180.0 / Math.PI; // Draw start arrow. pt1 = DrawLineArrowInternal(dc, halfStart, strokeStartArrow, fillStartArrow, x1, y1, a1, sas); // Draw end arrow. pt2 = DrawLineArrowInternal(dc, halfEnd, strokeEndArrow, fillEndArrow, x2, y2, a2, eas); }
/// <summary> /// Checks if line contains point. /// </summary> /// <param name="line"></param> /// <param name="v"></param> /// <param name="threshold"></param> /// <param name="dx"></param> /// <param name="dy"></param> /// <returns></returns> public static bool Contains(XLine line, Vector2 v, double threshold, double dx, double dy) { var a = new Vector2(line.Start.X + dx, line.Start.Y + dy); var b = new Vector2(line.End.X + dx, line.End.Y + dy); var nearest = MathHelpers.NearestPointOnLine(a, b, v); double distance = MathHelpers.Distance(v.X, v.Y, nearest.X, nearest.Y); return distance < threshold; }
/// <summary> /// Remove selection. /// </summary> public void Remove() { if (_ellipse != null) { _layer.Shapes = _layer.Shapes.Remove(_ellipse); _ellipse = null; } if (_startLine != null) { _layer.Shapes = _layer.Shapes.Remove(_startLine); _startLine = null; } if (_endLine != null) { _layer.Shapes = _layer.Shapes.Remove(_endLine); _endLine = null; } if (_p1HelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_p1HelperPoint); _p1HelperPoint = null; } if (_p2HelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_p2HelperPoint); _p2HelperPoint = null; } if (_centerHelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_centerHelperPoint); _centerHelperPoint = null; } if (_startHelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_startHelperPoint); _startHelperPoint = null; } if (_endHelperPoint != null) { _layer.Shapes = _layer.Shapes.Remove(_endHelperPoint); _endHelperPoint = null; } _layer.Invalidate(); }
private void DrawLineArrowsInternal(AM.DrawingContext dc, XLine line, double dx, double dy, out A.Point pt1, out A.Point pt2) { AM.IBrush fillStartArrow = ToBrush(line.Style.StartArrowStyle.Fill); AM.Pen strokeStartArrow = ToPen(line.Style.StartArrowStyle, _scaleToPage); AM.IBrush fillEndArrow = ToBrush(line.Style.EndArrowStyle.Fill); AM.Pen strokeEndArrow = ToPen(line.Style.EndArrowStyle, _scaleToPage); double _x1 = line.Start.X + dx; double _y1 = line.Start.Y + dy; double _x2 = line.End.X + dx; double _y2 = line.End.Y + dy; line.GetMaxLength(ref _x1, ref _y1, ref _x2, ref _y2); float x1 = _scaleToPage(_x1); float y1 = _scaleToPage(_y1); float x2 = _scaleToPage(_x2); float y2 = _scaleToPage(_y2); var sas = line.Style.StartArrowStyle; var eas = line.Style.EndArrowStyle; double a1 = Math.Atan2(y1 - y2, x1 - x2); double a2 = Math.Atan2(y2 - y1, x2 - x1); // Draw start arrow. pt1 = DrawLineArrowInternal(dc, strokeStartArrow, fillStartArrow, x1, y1, a1, sas); // Draw end arrow. pt2 = DrawLineArrowInternal(dc, strokeEndArrow, fillEndArrow, x2, y2, a2, eas); }
/// <summary> /// Transfer selection state to <see cref="ToolState.Three"/>. /// </summary> public void ToStateThree() { if (_ellipse != null) { _layer.Shapes = _layer.Shapes.Remove(_ellipse); _ellipse = null; } _endLine = XLine.Create(0, 0, _style, null); _endHelperPoint = XPoint.Create(0, 0, _point); _layer.Shapes = _layer.Shapes.Add(_endLine); _layer.Shapes = _layer.Shapes.Add(_endHelperPoint); }
/// <summary> /// Draws a <see cref="XLine"/> shape using drawing context. /// </summary> /// <param name="dc">The native drawing context.</param> /// <param name="line">The <see cref="XLine"/> shape.</param> /// <param name="dx">The X coordinate offset.</param> /// <param name="dy">The Y coordinate offset.</param> /// <param name="db">The properties database.</param> /// <param name="r">The data record.</param> public abstract void Draw(object dc, XLine line, double dx, double dy, ImmutableArray<XProperty> db, XRecord r);