private void OnMouseDown(object sender, MouseEventArgs e) { if (this.snappedCtrlPoint != null) { if ((double)ShapePoint.DistSquared(this.zoom.VisibleToPt((PointF)e.Location), this.snappedCtrlPoint.Location) > 100.0) { this.snappedCtrlPoint = (ShapePoint)null; } this.SelectedProperty = (object)this.snappedCtrlPoint; } if (this.snappedCurve != null) { this.SelectedProperty = (object)this.snappedCurve; } if (e.Button == MouseButtons.Left && this.snappedCtrlPoint != null) { this.snappedCtrlPoint.IsModified = true; this.isDragging = true; } if (e.Button == MouseButtons.Middle || e.Button == MouseButtons.Right && Control.ModifierKeys == Keys.Shift) { Cursor.Current = Cursors.Hand; this.isScrolling = true; this.scrollStartPos = (PointF)e.Location; this.areaStartPos = (PointF)this.zoom.Location; } else { if (e.Button != MouseButtons.Right || this.ShowSnappedPointMenu(e) || this.ShowSnappedLineMenu(e)) { return; } this.contextMenuGeneral.Show(this.PointToScreen(e.Location)); } }
public bool SnapToCurve(PointF pt, float snapDistance) { bool flag = false; PointF pointF = new PointF(); PointF snapPoint = new PointF(); float num = snapDistance * snapDistance; float dist = 0.0f; if (this.IsModified) { return(false); } for (int index = 0; index < this.detailLevel - 1; ++index) { if (ShapeBezier.SnapToCurveSegment(ref snapPoint, pt, this.points[index], this.points[index + 1], snapDistance, ref dist)) { dist = ShapePoint.DistSquared(pt, snapPoint); if ((double)num >= (double)dist) { num = dist; pointF = snapPoint; this.snapSegmentNum = index; flag = true; } } } if (!flag) { return(false); } this.snappedPoint = pointF; return(true); }
public bool SnapToCtrlPoints(PointF pt, float snapDistance) { bool res = false; float minDist = snapDistance * snapDistance; float curDist; snappedCtrl = null; for (int i = 0; i < lines.Count; i++) { if (!lines[i].SnapToCtrlPoints(pt, snapDistance)) { continue; } curDist = ShapePoint.DistSquared(pt, lines[i].SnappedCtrlPoint.Location); if (minDist < curDist) { continue; } minDist = curDist; snappedCtrl = lines[i].SnappedCtrlPoint; res = true; } return(res); }
public bool SnapToExtensions(PointF pt, float snapDistance) { bool res = false; float minDist = snapDistance * snapDistance; float curDist; for (int i = 0; i < lines.Count; i++) { if (!lines[i].SnapToCurveExtension(pt, snapDistance)) { continue; } curDist = ShapePoint.DistSquared(lines[i].SnappedPoint, pt); if (minDist < curDist) { continue; } minDist = curDist; snappedPoint = lines[i].SnappedPoint; res = true; } return(res); }
public bool SnapToVertical(PointF pt, float xVal, float snapDistance) { bool flag = false; float num1 = snapDistance * snapDistance; PointF pointF = new PointF(); IShapeCurve shapeCurve = (IShapeCurve)null; for (int index = 0; index < this.lines.Count; ++index) { if (this.lines[index].SnapToVertical(pt, xVal, snapDistance)) { float num2 = ShapePoint.DistSquared(this.lines[index].SnappedPoint, pt); if ((double)num1 >= (double)num2) { num1 = num2; pointF = this.lines[index].SnappedPoint; shapeCurve = this.lines[index]; flag = true; } } } if (flag) { this.snappedPoint = pointF; this.snappedCurve = shapeCurve; } return(flag); }
public bool SnapToHorizontal(PointF pt, float yVal, float snapDistance) { bool res = false; float curDist; float minDist = snapDistance * snapDistance; PointF snapPt = new PointF(); IShapeCurve snapCurve = null; for (int i = 0; i < lines.Count; i++) { if (!lines[i].SnapToHorizontal(pt, yVal, snapDistance)) { continue; } curDist = ShapePoint.DistSquared(lines[i].SnappedPoint, pt); if (minDist < curDist) { continue; } minDist = curDist; snapPt = lines[i].SnappedPoint; snapCurve = lines[i]; res = true; } if (res) { snappedPoint = snapPt; snappedCurve = snapCurve; } return(res); }
public bool SnapToCtrlPoints(PointF pt, float snapDistance) { float curDist; float minDist = snapDistance * snapDistance; snappedCtrl = null; for (int i = 0; i < 4; i++) { if (ctrl[i].IsModified) { continue; // do not snap to a point whose location is being modified } curDist = ShapePoint.DistSquared(ctrl[i].Location, pt); if (minDist < curDist) { continue; } minDist = curDist; snappedCtrl = ctrl[i]; } return(snappedCtrl != null); }
public bool SnapToCtrlPoints(PointF pt, float snapDistance) { float num1 = snapDistance * snapDistance; float num2 = num1 + 2f; float num3 = num1 + 2f; if (!this.points[0].IsModified) { num2 = ShapePoint.DistSquared(this.points[0].Location, pt); } if (!this.points[1].IsModified) { num3 = ShapePoint.DistSquared(this.points[1].Location, pt); } ShapePoint point; if ((double)num2 < (double)num3) { point = this.points[0]; } else { num2 = num3; point = this.points[1]; } if ((double)num2 >= (double)num1) { return(false); } this.snapCtrl = point; return(true); }
// SnapToGrid types: // 1 - snap to horizontal // 2 - snap to vertical // 3 - snap to both public bool SnapToGrid(PointF pt, PointF gridPt, int type, float snapDistance) { bool snappingOccured = false; int tmpRes = 0; // temporary result to find the closer snapped point PointF point1 = new PointF(); IShapeCurve snapCurve = null; if ((type & 0x01) != 0) { tmpRes += SnapToHorizontal(pt, gridPt.Y, snapDistance) ? 1 : 0; point1 = snappedPoint; snapCurve = snappedCurve; } if ((type & 0x02) != 0) { tmpRes += SnapToVertical(pt, gridPt.X, snapDistance) ? 2 : 0; } switch (tmpRes) { default: case 0: // no snapping occured snappingOccured = false; break; case 1: // only horizontal snapping occured // snappedPoint already contains the right snapping point snappingOccured = true; break; case 2: // only vertical snapping occured // snappedPoint already contains the right snapping point snappingOccured = true; break; case 3: // take the closer point and snap to it if (ShapePoint.DistSquared(pt, point1) < ShapePoint.DistSquared(pt, snappedPoint)) { snappedPoint = point1; snappedCurve = snapCurve; } snappingOccured = true; break; } return(snappingOccured); }
public bool SnapToCurveExtension(PointF pt, float snapDistance) { PointF point1 = new PointF(); PointF point2 = new PointF(); bool finalSnapResult = true; int snapResult = 0; float dist1 = 0, dist2 = 0; if (!ctrl[0].IsModified && !ctrl[1].IsModified) { snapResult += SnapToExtension(ref point1, pt, ctrl[0], ctrl[1], snapDistance, ref dist1) ? 1 : 0; } if (!ctrl[3].IsModified && !ctrl[2].IsModified) { snapResult += SnapToExtension(ref point2, pt, ctrl[3], ctrl[2], snapDistance, ref dist2) ? 2 : 0; } switch (snapResult) { default: case 0: // none is snapped finalSnapResult = false; break; case 1: // point1 is snapped to extension 1 snappedPoint = point1; break; case 2: // point2 is snapped to extension 2 snappedPoint = point2; break; case 3: // both lines are snapped-to-, should find closer one if (ShapePoint.DistSquared(pt, point1) <= ShapePoint.DistSquared(pt, point2)) { snappedPoint = point1; } else { snappedPoint = point2; } break; } return(finalSnapResult); }
private void OnMouseDown(object sender, MouseEventArgs e) { if (snappedCtrlPoint != null) { if (ShapePoint.DistSquared(zoom.VisibleToPt(e.Location), snappedCtrlPoint.Location) > snapDistConst * snapDistConst) { snappedCtrlPoint = null; } SelectedProperty = snappedCtrlPoint; } if (snappedCurve != null) { SelectedProperty = snappedCurve; } if (e.Button == MouseButtons.Left) { if (snappedCtrlPoint != null) { snappedCtrlPoint.IsModified = true; isDragging = true; } } if ((e.Button == MouseButtons.Middle) || ((e.Button == MouseButtons.Right) && (Control.ModifierKeys == Keys.Shift))) { Cursor.Current = Cursors.Hand; isScrolling = true; scrollStartPos = e.Location; areaStartPos = zoom.Location; return; } if (e.Button == MouseButtons.Right) { if (ShowSnappedPointMenu(e)) { return; } if (ShowSnappedLineMenu(e)) { return; } contextMenuGeneral.Show(PointToScreen(e.Location)); } }
public bool SnapToGrid(PointF pt, PointF gridPt, int type, float snapDistance) { int num = 0; PointF b = new PointF(); IShapeCurve shapeCurve = (IShapeCurve)null; if ((type & 1) != 0) { num += this.SnapToHorizontal(pt, gridPt.Y, snapDistance) ? 1 : 0; b = this.snappedPoint; shapeCurve = this.snappedCurve; } if ((type & 2) != 0) { num += this.SnapToVertical(pt, gridPt.X, snapDistance) ? 2 : 0; } bool flag; switch (num) { case 1: flag = true; break; case 2: flag = true; break; case 3: if ((double)ShapePoint.DistSquared(pt, b) < (double)ShapePoint.DistSquared(pt, this.snappedPoint)) { this.snappedPoint = b; this.snappedCurve = shapeCurve; } flag = true; break; default: flag = false; break; } return(flag); }
public bool SnapToCtrlPoints(PointF pt, float snapDistance) { float num1 = snapDistance * snapDistance; this.snappedCtrl = (ShapePoint)null; for (int index = 0; index < 4; ++index) { if (!this.ctrl[index].IsModified) { float num2 = ShapePoint.DistSquared(this.ctrl[index].Location, pt); if ((double)num1 >= (double)num2) { num1 = num2; this.snappedCtrl = this.ctrl[index]; } } } return(this.snappedCtrl != null); }
public bool SnapToCurve(PointF pt, float snapDistance) { bool res = false; PointF minPt = new PointF(); PointF curPt = new PointF(); float minDist = snapDistance * snapDistance; float curDist = 0; if (IsModified) { return(false); } for (int i = 0; i < detailLevel - 1; i++) { if (!SnapToCurveSegment(ref curPt, pt, points[i], points[i + 1], snapDistance, ref curDist)) { continue; } curDist = ShapePoint.DistSquared(pt, curPt); if (minDist < curDist) { continue; } minDist = curDist; minPt = curPt; snapSegmentNum = i; res = true; } if (!res) { return(false); } snappedPoint = minPt; return(true); }
public bool SnapToExtensions(PointF pt, float snapDistance) { bool flag = false; float num1 = snapDistance * snapDistance; for (int index = 0; index < this.lines.Count; ++index) { if (this.lines[index].SnapToCurveExtension(pt, snapDistance)) { float num2 = ShapePoint.DistSquared(this.lines[index].SnappedPoint, pt); if ((double)num1 >= (double)num2) { num1 = num2; this.snappedPoint = this.lines[index].SnappedPoint; flag = true; } } } return(flag); }
public bool SnapToCtrlPoints(PointF pt, float snapDistance) { bool flag = false; float num1 = snapDistance * snapDistance; this.snappedCtrl = (ShapePoint)null; for (int index = 0; index < this.lines.Count; ++index) { if (this.lines[index].SnapToCtrlPoints(pt, snapDistance)) { float num2 = ShapePoint.DistSquared(pt, this.lines[index].SnappedCtrlPoint.Location); if ((double)num1 >= (double)num2) { num1 = num2; this.snappedCtrl = this.lines[index].SnappedCtrlPoint; flag = true; } } } return(flag); }
public bool SnapToCurveExtension(PointF pt, float snapDistance) { PointF snapPoint1 = new PointF(); PointF snapPoint2 = new PointF(); bool flag = true; int num = 0; float dist1 = 0.0f; float dist2 = 0.0f; if (!this.ctrl[0].IsModified && !this.ctrl[1].IsModified) { num += ShapeBezier.SnapToExtension(ref snapPoint1, pt, this.ctrl[0], this.ctrl[1], snapDistance, ref dist1) ? 1 : 0; } if (!this.ctrl[3].IsModified && !this.ctrl[2].IsModified) { num += ShapeBezier.SnapToExtension(ref snapPoint2, pt, this.ctrl[3], this.ctrl[2], snapDistance, ref dist2) ? 2 : 0; } switch (num) { case 1: this.snappedPoint = snapPoint1; break; case 2: this.snappedPoint = snapPoint2; break; case 3: this.snappedPoint = (double)ShapePoint.DistSquared(pt, snapPoint1) > (double)ShapePoint.DistSquared(pt, snapPoint2) ? snapPoint2 : snapPoint1; break; default: flag = false; break; } return(flag); }
public bool SnapToCtrlPoints(PointF pt, float snapDistance) { float distSq = snapDistance * snapDistance; ShapePoint point; float dist1 = distSq + 2; float dist2 = distSq + 2; if (!points[0].IsModified) { dist1 = ShapePoint.DistSquared(points[0].Location, pt); } if (!points[1].IsModified) { dist2 = ShapePoint.DistSquared(points[1].Location, pt); } if (dist1 < dist2) { point = points[0]; } else { dist1 = dist2; point = points[1]; } if (dist1 >= distSq) { return(false); } snapCtrl = point; return(true); }