protected void OnMouseMove(object sender, MouseEventArgs e) { this.ActivateShapeEditor(); this.snappingOccured = false; this.StopOnDebug(); if (this.isScrolling) { this.zoom.Location = new Point((int)Math.Round((double)this.scrollStartPos.X - (double)e.Location.X + (double)this.areaStartPos.X), (int)Math.Round((double)this.scrollStartPos.Y - (double)e.Location.Y + (double)this.areaStartPos.Y)); this.Refresh(); } if (this.isDragging) { if (!this.ClientRectangle.Contains(e.Location) && !this.scrollTimer.Enabled) { this.scrollTimer.Enabled = true; } this.snappingOccured = this.DoSnap(this.zoom.VisibleToPt((PointF)e.Location), 10f); this.snappedCtrlPoint.Location = this.snappedPoint; } else { this.snappingOccured = false; this.snappedCtrlPoint = (ShapePoint)null; this.snappedCurve = (IShapeCurve)null; this.StopOnDebug(); if (this.snappingOccured = this.DoSnap(this.zoom.VisibleToPt((PointF)e.Location), 10f)) { this.snappedCtrlPoint = this.shape.SnappedCtrlPoint; } } this.Refresh(); }
public ShapesIntersection() { this.curve1 = (IShapeCurve)null; this.curve2 = (IShapeCurve)null; this.curveIntersections = new List <PointF>(); this.extIntersections = new List <PointF>(); }
public bool SnapToSegments(PointF pt, float snapDistance) { bool res = false; float curDist; float minDist = snapDistance * snapDistance; for (int i = 0; i < lines.Count; i++) { if (!lines[i].SnapToCurve(pt, snapDistance)) { continue; } curDist = ShapePoint.DistSquared(lines[i].SnappedPoint, pt); if (minDist < curDist) { continue; } minDist = curDist; snappedPoint = lines[i].SnappedPoint; snappedCurve = lines[i]; res = true; } return(res); }
public ShapesIntersection() { curve1 = null; curve2 = null; curveIntersections = new List <PointF>(); extIntersections = new List <PointF>(); }
public void ConvertCurve(IShapeCurve curve) { if (curve is ShapeLine) { ShapePoint c1 = new ShapePoint( (2 * snappedCurve.Points[0].X + snappedCurve.Points[1].X) / 3, (2 * snappedCurve.Points[0].Y + snappedCurve.Points[1].Y) / 3 ); ShapePoint c2 = new ShapePoint( (snappedCurve.Points[0].X + 2 * snappedCurve.Points[1].X) / 3, (snappedCurve.Points[0].Y + 2 * snappedCurve.Points[1].Y) / 3 ); ShapeBezier bezier = new ShapeBezier(snappedCurve.FirstPoint, c1, c2, snappedCurve.LastPoint); lines[lines.IndexOf(curve)] = bezier; } else { ShapeLine line = new ShapeLine(snappedCurve.FirstPoint, snappedCurve.LastPoint); lines[lines.IndexOf(curve)] = line; } snappedCurve = null; }
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 void CopyFrom(ShapeLinesCollection shape) { Reset(); List <ShapePoint> pts = new List <ShapePoint>(); List <ShapePoint> newPts = new List <ShapePoint>(); for (int i = 0; i < shape.lines.Count; i++) { IShapeCurve tmp = shape.lines[i].Create(); for (int j = 0; j < shape.lines[i].ControlPoints.Length; j++) { int pos = pts.IndexOf(shape.lines[i].ControlPoints[j]); if (pos == -1) { pts.Add(shape.lines[i].ControlPoints[j]); pos = pts.IndexOf(shape.lines[i].ControlPoints[j]); newPts.Insert(pos, new ShapePoint(shape.lines[i].ControlPoints[j].Location)); } tmp.ControlPoints[j] = newPts[pos]; } Add(tmp); tmp.Update(); } }
public ShapesIntersection(IShapeCurve c1, IShapeCurve c2) { this.curve1 = c1; this.curve2 = c2; this.curveIntersections = new List <PointF>(); this.extIntersections = new List <PointF>(); }
public ShapesIntersection(IShapeCurve c1, IShapeCurve c2) { curve1 = c1; curve2 = c2; curveIntersections = new List <PointF>(); extIntersections = new List <PointF>(); }
// 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 void DeserializeProperties(string propertiesString) { string[] tokens = propertiesString.Split(':'); IShapeCurve curve = null; ShapePoint startPt = new ShapePoint(); ShapePoint endPt = startPt; for (int i = 1; i < tokens.Length - 1; i++) { string[] strpt = tokens[i].Split(','); endPt.Set(float.Parse(strpt[0], CultureInfo.InvariantCulture), float.Parse(strpt[1], CultureInfo.InvariantCulture)); if (bool.Parse(strpt[2])) { // Bezier curve curve = new ShapeBezier(); curve.ControlPoints[0] = endPt; //bool b = CultureInfo.CurrentCulture.UseUserOverride; NumberFormatInfo nfi = CultureInfo.CurrentCulture.NumberFormat; curve.ControlPoints[1] = new ShapePoint(float.Parse(strpt[3], CultureInfo.InvariantCulture), float.Parse(strpt[4], CultureInfo.InvariantCulture)); curve.ControlPoints[2] = new ShapePoint(float.Parse(strpt[5], CultureInfo.InvariantCulture), float.Parse(strpt[6], CultureInfo.InvariantCulture)); endPt = new ShapePoint(); curve.ControlPoints[3] = endPt; } else { // Straight Line curve = new ShapeLine(); curve.ControlPoints[0] = endPt; endPt = new ShapePoint(); curve.ControlPoints[1] = endPt; } this.Add(curve); } // Attach the end of the last line to the first point to close the shape if (curve != null) { curve.LastPoint = startPt; } }
public void ConvertCurve(IShapeCurve curve) { if (curve is ShapeLine) { ShapeBezier shapeBezier = new ShapeBezier(this.snappedCurve.FirstPoint, new ShapePoint((float)((2.0 * (double)this.snappedCurve.Points[0].X + (double)this.snappedCurve.Points[1].X) / 3.0), (float)((2.0 * (double)this.snappedCurve.Points[0].Y + (double)this.snappedCurve.Points[1].Y) / 3.0)), new ShapePoint((float)(((double)this.snappedCurve.Points[0].X + 2.0 * (double)this.snappedCurve.Points[1].X) / 3.0), (float)(((double)this.snappedCurve.Points[0].Y + 2.0 * (double)this.snappedCurve.Points[1].Y) / 3.0)), this.snappedCurve.LastPoint); this.lines[this.lines.IndexOf(curve)] = (IShapeCurve)shapeBezier; } else { ShapeLine shapeLine = new ShapeLine(this.snappedCurve.FirstPoint, this.snappedCurve.LastPoint); this.lines[this.lines.IndexOf(curve)] = (IShapeCurve)shapeLine; } this.snappedCurve = (IShapeCurve)null; }
private bool DoSnap(PointF location, float snapDist) { PointF pointF1 = new PointF(); int type = 0; snapDist /= this.zoom.ZoomFactor; this.snappedCurve = (IShapeCurve)null; if (this.IsSnappingActive(RadShapeEditorControl.SnapTypes.SnapToCtrl) && this.shape.SnapToCtrlPoints(location, snapDist)) { this.snappedPoint = this.shape.SnappedCtrlPoint.Location; return(true); } if (this.IsSnappingActive(RadShapeEditorControl.SnapTypes.SnapToGrid)) { type = this.snapToGrid.SnapPtToGrid(location); } PointF pointF2; bool flag; if (type > 0) { pointF2 = this.snapToGrid.SnappedPoint; flag = true; } else { pointF2 = location; flag = false; } if (type != 0 && this.shape.SnapToGrid(location, pointF2, type, snapDist)) { this.snappedCurve = this.shape.SnappedCurve; this.snappedPoint = this.shape.SnappedPoint; return(true); } if (this.IsSnappingActive(RadShapeEditorControl.SnapTypes.SnapToCurves) && this.shape.SnapToSegments(pointF2, snapDist)) { this.snappedCurve = this.shape.SnappedCurve; this.snappedPoint = this.shape.SnappedPoint; return(true); } if (this.IsSnappingActive(RadShapeEditorControl.SnapTypes.SnapToExtensions) && this.shape.SnapToExtensions(pointF2, snapDist)) { this.snappedPoint = this.shape.SnappedPoint; return(true); } this.snappedPoint = pointF2; return(flag); }
public void Reset() { this.snappingOccured = false; this.drawsGuideLines = true; this.isDragging = false; this.isScrolling = false; this.snappedPoint = new PointF(0.0f, 0.0f); this.snappedCtrlPoint = (ShapePoint)null; this.snappedCurve = (IShapeCurve)null; this.zoom.ZoomFactor = 1f; this.snapToGrid.SnapRelative = 0.2f; this.SetSnapping(RadShapeEditorControl.SnapTypes.SnapToGrid | RadShapeEditorControl.SnapTypes.SnapToCtrl | RadShapeEditorControl.SnapTypes.SnapToCurves | RadShapeEditorControl.SnapTypes.SnapToExtensions); this.scrollStartPos = new PointF(0.0f, 0.0f); this.areaStartPos = new PointF(0.0f, 0.0f); }
protected void OnMouseMove(object sender, MouseEventArgs e) { ActivateShapeEditor(); snappingOccured = false; StopOnDebug(); if (isScrolling) { Point pos = new Point( (int)Math.Round(scrollStartPos.X - e.Location.X + areaStartPos.X), (int)Math.Round(scrollStartPos.Y - e.Location.Y + areaStartPos.Y) ); zoom.Location = pos; Refresh(); //PointF.Subtract(scrollStartPos, areaStartPos); //return; } if (isDragging) { if (!ClientRectangle.Contains(e.Location) && (!scrollTimer.Enabled)) { scrollTimer.Enabled = true; } //scrollTimer.Start(); snappingOccured = DoSnap(zoom.VisibleToPt(e.Location), snapDistConst); snappedCtrlPoint.Location = snappedPoint; } else { snappingOccured = false; snappedCtrlPoint = null; snappedCurve = null; StopOnDebug(); if (snappingOccured = DoSnap(zoom.VisibleToPt(e.Location), snapDistConst)) { snappedCtrlPoint = shape.SnappedCtrlPoint; } } Refresh(); }
public void InsertPoint(IShapeCurve curve, PointF atPoint) { if (curve == null) { return; } if (curve is ShapeLine) { ShapePoint end = curve.LastPoint; ShapePoint middle = new ShapePoint(atPoint); ShapeLine newLine = new ShapeLine(middle, end); curve.LastPoint = middle; lines.Insert(lines.IndexOf(curve) + 1, newLine); return; } if (curve is ShapeBezier) { PointF tg1 = new PointF(), tg2 = new PointF(); ShapePoint end = snappedCurve.LastPoint; ShapePoint middle = new ShapePoint(snappedPoint); if (!(curve as ShapeBezier).TangentAt(snappedPoint, ref tg1, ref tg2)) { return; } ShapeBezier newBezier = new ShapeBezier(); newBezier.ControlPoints[0] = middle; newBezier.ControlPoints[1] = new ShapePoint(tg2); newBezier.ControlPoints[2] = curve.ControlPoints[2]; newBezier.ControlPoints[3] = curve.LastPoint; curve.ControlPoints[2] = new ShapePoint(tg1); curve.ControlPoints[3] = middle; curve.Update(); newBezier.Update(); lines.Insert(lines.IndexOf(curve) + 1, newBezier); return; } }
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 SnapToSegments(PointF pt, float snapDistance) { bool flag = false; float num1 = snapDistance * snapDistance; for (int index = 0; index < this.lines.Count; ++index) { if (this.lines[index].SnapToCurve(pt, snapDistance)) { float num2 = ShapePoint.DistSquared(this.lines[index].SnappedPoint, pt); if ((double)num1 >= (double)num2) { num1 = num2; this.snappedPoint = this.lines[index].SnappedPoint; this.snappedCurve = this.lines[index]; flag = true; } } } return(flag); }
public void InsertPoint(IShapeCurve curve, PointF atPoint) { if (curve == null) { return; } if (curve is ShapeLine) { ShapePoint lastPoint = curve.LastPoint; ShapePoint from = new ShapePoint(atPoint); ShapeLine shapeLine = new ShapeLine(from, lastPoint); curve.LastPoint = from; this.lines.Insert(this.lines.IndexOf(curve) + 1, (IShapeCurve)shapeLine); } else { if (!(curve is ShapeBezier)) { return; } PointF from = new PointF(); PointF to = new PointF(); ShapePoint lastPoint = this.snappedCurve.LastPoint; ShapePoint shapePoint = new ShapePoint(this.snappedPoint); if (!(curve as ShapeBezier).TangentAt(this.snappedPoint, ref from, ref to)) { return; } ShapeBezier shapeBezier = new ShapeBezier(); shapeBezier.ControlPoints[0] = shapePoint; shapeBezier.ControlPoints[1] = new ShapePoint(to); shapeBezier.ControlPoints[2] = curve.ControlPoints[2]; shapeBezier.ControlPoints[3] = curve.LastPoint; curve.ControlPoints[2] = new ShapePoint(from); curve.ControlPoints[3] = shapePoint; curve.Update(); shapeBezier.Update(); this.lines.Insert(this.lines.IndexOf(curve) + 1, (IShapeCurve)shapeBezier); } }
public void Reset() { snappingOccured = false; drawsGuideLines = true; isDragging = false; isScrolling = false; snappedPoint = new PointF(0, 0); snappedCtrlPoint = null; snappedCurve = null; zoom.ZoomFactor = 1f; snapToGrid.SnapRelative = 0.2f; SetSnapping( SnapTypes.SnapToCtrl | SnapTypes.SnapToCurves | SnapTypes.SnapToExtensions | SnapTypes.SnapToGrid ); scrollStartPos = new PointF(0, 0); areaStartPos = new PointF(0, 0); }
private bool FindLineContainingPoint(ShapePoint pt, out ShapePoint changeTo, out IShapeCurve line) { for (int i = 0; i < lines.Count; i++) { if (lines[i].FirstPoint == pt) { changeTo = lines[i].LastPoint; line = lines[i]; return(true); } if (lines[i].LastPoint == pt) { changeTo = lines[i].FirstPoint; line = lines[i]; return(true); } } changeTo = null; line = null; return(false); }
private bool FindLineContainingPoint( ShapePoint pt, out ShapePoint changeTo, out IShapeCurve line) { for (int index = 0; index < this.lines.Count; ++index) { if (this.lines[index].FirstPoint == pt) { changeTo = this.lines[index].LastPoint; line = this.lines[index]; return(true); } if (this.lines[index].LastPoint == pt) { changeTo = this.lines[index].FirstPoint; line = this.lines[index]; return(true); } } changeTo = (ShapePoint)null; line = (IShapeCurve)null; return(false); }
public void DeserializeProperties(string propertiesString) { string[] strArray1 = propertiesString.Split(':'); IShapeCurve el = (IShapeCurve)null; ShapePoint shapePoint1 = new ShapePoint(); ShapePoint shapePoint2 = shapePoint1; for (int index = 1; index < strArray1.Length - 1; ++index) { string[] strArray2 = strArray1[index].Split(','); shapePoint2.Set(float.Parse(strArray2[0], (IFormatProvider)CultureInfo.InvariantCulture), float.Parse(strArray2[1], (IFormatProvider)CultureInfo.InvariantCulture)); if (bool.Parse(strArray2[2])) { el = (IShapeCurve) new ShapeBezier(); el.ControlPoints[0] = shapePoint2; NumberFormatInfo numberFormat = CultureInfo.CurrentCulture.NumberFormat; el.ControlPoints[1] = new ShapePoint(float.Parse(strArray2[3], (IFormatProvider)CultureInfo.InvariantCulture), float.Parse(strArray2[4], (IFormatProvider)CultureInfo.InvariantCulture)); el.ControlPoints[2] = new ShapePoint(float.Parse(strArray2[5], (IFormatProvider)CultureInfo.InvariantCulture), float.Parse(strArray2[6], (IFormatProvider)CultureInfo.InvariantCulture)); shapePoint2 = new ShapePoint(); el.ControlPoints[3] = shapePoint2; } else { el = (IShapeCurve) new ShapeLine(); el.ControlPoints[0] = shapePoint2; shapePoint2 = new ShapePoint(); el.ControlPoints[1] = shapePoint2; } this.Add(el); } if (el == null) { return; } el.LastPoint = shapePoint1; }
public void CopyFrom(ShapeLinesCollection shape) { this.Reset(); List <ShapePoint> shapePointList1 = new List <ShapePoint>(); List <ShapePoint> shapePointList2 = new List <ShapePoint>(); for (int index1 = 0; index1 < shape.lines.Count; ++index1) { IShapeCurve el = shape.lines[index1].Create(); for (int index2 = 0; index2 < shape.lines[index1].ControlPoints.Length; ++index2) { int index3 = shapePointList1.IndexOf(shape.lines[index1].ControlPoints[index2]); if (index3 == -1) { shapePointList1.Add(shape.lines[index1].ControlPoints[index2]); index3 = shapePointList1.IndexOf(shape.lines[index1].ControlPoints[index2]); shapePointList2.Insert(index3, new ShapePoint(shape.lines[index1].ControlPoints[index2].Location)); } el.ControlPoints[index2] = shapePointList2[index3]; } this.Add(el); el.Update(); } }
public void Add(IShapeCurve el) { lines.Add(el); }
private bool DoSnap(PointF location, float snapDist) { bool res = false; PointF curPos = new PointF(); int snapType = 0; snapDist /= zoom.ZoomFactor; snappedCurve = null; // Snap to control points if possible if (IsSnappingActive(SnapTypes.SnapToCtrl) && shape.SnapToCtrlPoints(location, snapDist)) { snappedPoint = shape.SnappedCtrlPoint.Location; return(true); } // try snap to grid if (IsSnappingActive(SnapTypes.SnapToGrid)) { snapType = snapToGrid.SnapPtToGrid(location); } // Try snap to grid if (snapType > 0) { curPos = snapToGrid.SnappedPoint; res = true; } else { curPos = location; res = false; } // try snapping intersection between grid and shape curves/lines if ((snapType != 0) && shape.SnapToGrid(location, curPos, snapType, snapDist)) { snappedCurve = shape.SnappedCurve; snappedPoint = shape.SnappedPoint; return(true); } // try snapping to lines / curves' segments if (IsSnappingActive(SnapTypes.SnapToCurves) && shape.SnapToSegments(curPos, snapDist)) { snappedCurve = shape.SnappedCurve; snappedPoint = shape.SnappedPoint; return(true); } // try snapping to line extensions (end point tangents for curves) if (IsSnappingActive(SnapTypes.SnapToExtensions) && shape.SnapToExtensions(curPos, snapDist)) { snappedPoint = shape.SnappedPoint; return(true); } // no successfull snapping to lines/curves occured, use grid point snapping result snappedPoint = curPos; return(res); }
public bool Remove(IShapeCurve el) { return(lines.Remove(el)); }