private void RadShapeEditorControl_MouseDown(object sender, MouseEventArgs e) { this.Cursor = Cursors.Cross; this.mouseDown = true; this.downPoint = new Point(e.X, e.Y); Point point1 = new Point((int)Math.Round((double)this.downPoint.X / Math.Pow((double)this.zoomFactor, 2.0)) + this.xOverflowOffset, (int)Math.Round((double)this.downPoint.Y / Math.Pow((double)this.zoomFactor, 2.0)) + this.yOverflowOffset); this.curPoint = this.downPoint; this.point = (ShapePointBase)null; foreach (ShapePoint point2 in this.points) { if (point2.IsVisible(point1.X, point1.Y, (int)Math.Round(8.0 * (double)this.zoomFactor))) { this.pointType = RadShapeEditorControl.PointTypes.Point; this.point = (ShapePointBase)point2; break; } if (point2.Bezier) { if (point2.ControlPoint1.IsVisible(point1.X, point1.Y, (int)Math.Round(8.0 * (double)this.zoomFactor))) { this.pointType = RadShapeEditorControl.PointTypes.ControlPoint; this.point = point2.ControlPoint1; break; } if (point2.ControlPoint2.IsVisible(point1.X, point1.Y, (int)Math.Round(8.0 * (double)this.zoomFactor))) { this.pointType = RadShapeEditorControl.PointTypes.ControlPoint; this.point = point2.ControlPoint2; break; } } } if (this.isSymmetricPointMode) { if (this.point == null) { this.isSymmetricPointMode = false; } else { this.referencePoint = this.point; Rectangle dimension = this.dimension; int num1 = dimension.Top + dimension.Height / 2; int num2 = dimension.Left + dimension.Width / 2; if (this.isVerticalSymmetry) { this.newSymmetricPoint.Y = this.referencePoint.Y + (float)(2.0 * ((double)num1 - (double)this.point.Y)); } else { this.newSymmetricPoint.X = this.referencePoint.X + (float)(2.0 * ((double)num2 - (double)this.point.X)); } this.isSymmetricPointMode = false; this.Refresh(); } } else { if (this.point == null) { for (int index = 0; index < this.points.Count; ++index) { ShapePoint point2 = this.points[index]; ShapePoint nextPoint = index < this.points.Count - 1 ? this.points[index + 1] : this.points[0]; if (point2.IsVisible(nextPoint, new Point(point1.X, point1.Y), 3)) { this.pointType = RadShapeEditorControl.PointTypes.Line; this.point = (ShapePointBase)point2; break; } } } if (this.propertyGrid != null) { this.propertyGrid.SelectedObject = this.point == null ? (object)null : (object)this.point; } this.Refresh(); if (e.Button == MouseButtons.Left && (this.point == null || !this.point.Selected)) { foreach (ShapePoint point2 in this.points) { point2.Selected = false; point2.ControlPoint1.Selected = false; point2.ControlPoint2.Selected = false; } } if (this.point != null) { this.mouseDown = false; } if (e.Button != MouseButtons.Right || this.point == null) { return; } if (this.pointType == RadShapeEditorControl.PointTypes.Point && this.point is ShapePoint) { this.menuItemAnchorLeft.Checked = (this.point.Anchor & AnchorStyles.Left) != AnchorStyles.None; this.menuItemAnchorRight.Checked = (this.point.Anchor & AnchorStyles.Right) != AnchorStyles.None; this.menuItemAnchorTop.Checked = (this.point.Anchor & AnchorStyles.Top) != AnchorStyles.None; this.menuItemAnchorBottom.Checked = (this.point.Anchor & AnchorStyles.Bottom) != AnchorStyles.None; if (this.points.Count <= 2) { this.menuItemRemoveLine.Enabled = false; this.menuItemRemovePoint.Enabled = false; } this.menuItemLocked.Checked = this.point.Locked; if ((this.point as ShapePoint).Bezier) { this.contextMenuPoint.Items[1].Text = "Convert to Line"; } else { this.contextMenuPoint.Items[1].Text = "Convert to Bezier Curve"; } this.contextMenuPoint.Show(this.PointToScreen(new Point(e.X, e.Y))); } else { if (this.pointType != RadShapeEditorControl.PointTypes.Line) { return; } if ((this.point as ShapePoint).Bezier) { this.contextMenuLine.Items[1].Text = "Convert to Line"; } else { this.contextMenuLine.Items[1].Text = "Convert to Bezier Curve"; } this.contextMenuLine.Show(this.PointToScreen(new Point(e.X, e.Y))); } } }
void RadShapeEditorControl_MouseDown(object sender, MouseEventArgs e) { this.Cursor = Cursors.Cross; mouseDown = true; downPoint = new Point(e.X, e.Y); Point scaledTranslatedDownPoint = new Point( (int)Math.Round((downPoint.X) / Math.Pow(zoomFactor, 2)) + xOverflowOffset, (int)Math.Round((downPoint.Y) / Math.Pow(zoomFactor, 2)) + yOverflowOffset); curPoint = downPoint; point = null; //find the point underneath the mouse foreach (ShapePoint pos1 in points) { if (pos1.IsVisible(scaledTranslatedDownPoint.X, scaledTranslatedDownPoint.Y, (int)Math.Round(8 * zoomFactor))) { pointType = PointTypes.Point; point = pos1; break; } else if (pos1.Bezier) { if (pos1.ControlPoint1.IsVisible(scaledTranslatedDownPoint.X, scaledTranslatedDownPoint.Y, (int)Math.Round(8 * zoomFactor))) { pointType = PointTypes.ControlPoint; point = pos1.ControlPoint1; break; } else if (pos1.ControlPoint2.IsVisible(scaledTranslatedDownPoint.X, scaledTranslatedDownPoint.Y, (int)Math.Round(8 * zoomFactor))) { pointType = PointTypes.ControlPoint; point = pos1.ControlPoint2; break; } } } if (isSymmetricPointMode) { if (point == null) { isSymmetricPointMode = false; return; } //use the currently selected node as a reference point to make the previously selected node symmetric to it referencePoint = point; //get the size of the drawable area and compute the coordinates of the new point Rectangle r = dimension; int midy = r.Top + r.Height / 2; int midx = r.Left + r.Width / 2; if (isVerticalSymmetry) { newSymmetricPoint.Y = referencePoint.Y + 2 * (midy - point.Y); } else { newSymmetricPoint.X = referencePoint.X + 2 * (midx - point.X); } isSymmetricPointMode = false; Refresh(); return; } if (point == null) { for (int i = 0; i < points.Count; i++) { ShapePoint pos1 = points[i]; ShapePoint pos2 = i < points.Count - 1 ? points[i + 1] : points[0]; if (pos1.IsVisible(pos2, new Point(scaledTranslatedDownPoint.X, scaledTranslatedDownPoint.Y), 3)) { pointType = PointTypes.Line; point = pos1; break; } } } if (point != null) { propertyGrid.SelectedObject = point; } else { propertyGrid.SelectedObject = null; } Refresh(); //in case the mouse was clicked outside of any point, unselect all points (and their control points) if (e.Button == MouseButtons.Left) { if (point == null || !point.Selected) { foreach (ShapePoint pos in points) { pos.Selected = false; pos.ControlPoint1.Selected = false; pos.ControlPoint2.Selected = false; } } } if (point != null) { mouseDown = false; } if (e.Button == MouseButtons.Right && point != null) { if (pointType == PointTypes.Point && point is ShapePoint) { menuItemAnchorLeft.Checked = (point.Anchor & AnchorStyles.Left) != 0; menuItemAnchorRight.Checked = (point.Anchor & AnchorStyles.Right) != 0; menuItemAnchorTop.Checked = (point.Anchor & AnchorStyles.Top) != 0; menuItemAnchorBottom.Checked = (point.Anchor & AnchorStyles.Bottom) != 0; if (this.points.Count <= 2) { menuItemRemoveLine.Enabled = false; menuItemRemovePoint.Enabled = false; } menuItemLocked.Checked = point.Locked; if ((point as ShapePoint).Bezier) { contextMenuPoint.Items[1].Text = "Convert to Line"; } else { contextMenuPoint.Items[1].Text = "Convert to Bezier Curve"; } contextMenuPoint.Show(PointToScreen(new Point(e.X, e.Y))); } else if (pointType == PointTypes.Line) { if ((point as ShapePoint).Bezier) { contextMenuLine.Items[1].Text = "Convert to Line"; } else { contextMenuLine.Items[1].Text = "Convert to Bezier Curve"; } contextMenuLine.Show(PointToScreen(new Point(e.X, e.Y))); } } }