/// <summary> /// Creates a Bezier curve between the current point and the point given as a /// parameter. /// </summary> /// <param name="nextPoint"></param> public void CreateBezier(ShapePointBase nextPoint) { LineDirections dir = GetLineDirection(nextPoint); ControlPoint1.Set(X + 10, Y); ControlPoint2.Set(nextPoint.X - 10, nextPoint.Y); }
/// <summary> /// Initializes a new instance of the ShapePoint class using an instance of the /// ShapePointBase class. /// </summary> /// <param name="point"></param> public ShapePointBase(ShapePointBase point) { this.x = point.X; this.y = point.Y; this.anchor = point.Anchor; this.locked = point.Locked; }
public void CreateBezier(ShapePointBase nextPoint) { int lineDirection = (int)this.GetLineDirection(nextPoint); this.ControlPoint1.Set(this.X + 10f, this.Y); this.ControlPoint2.Set(nextPoint.X - 10f, nextPoint.Y); }
private void verticallyToolStripMenuItem1_Click(object sender, EventArgs e) { int num = (int)MessageBox.Show("Please select the point to be used as a reference for the symmmetry", "Shape Editor", MessageBoxButtons.OK, MessageBoxIcon.Asterisk); this.isSymmetricPointMode = true; this.isVerticalSymmetry = true; this.newSymmetricPoint = this.point; }
private void verticallyToolStripMenuItem1_Click(object sender, EventArgs e) { MessageBox.Show("Please select the point to be used as a reference for the symmmetry", "Shape Editor", MessageBoxButtons.OK, MessageBoxIcon.Information); //set symmetric mode to true to trap the next mouse down on a point to use as a reference isSymmetricPointMode = true; //set vertical symmetry flag isVerticalSymmetry = true; //save the current point to be made symmetric vertically newSymmetricPoint = point; }
void menuItemRemovePoint_Click(object sender, EventArgs e) { if (points.Count > 2) { points.Remove(point as ShapePoint); point = null; propertyGrid.SelectedObject = null; Refresh(); } }
private void propertyGrid_PropertyValueChanged(object s, PropertyValueChangedEventArgs e) { if (this.propertyGrid.SelectedObject is ShapePoint) { int index = this.points.IndexOf(this.point as ShapePoint); this.points[index] = this.propertyGrid.SelectedObject as ShapePoint; this.point = (ShapePointBase)this.points[index]; } this.Refresh(); }
private void menuItemRemovePoint_Click(object sender, EventArgs e) { if (this.points.Count <= 2) { return; } this.points.Remove(this.point as ShapePoint); this.point = (ShapePointBase)null; this.propertyGrid.SelectedObject = (object)null; this.Refresh(); }
public RadShapeEditorControl() { snapToGrid = new SnapToGrid(); xoff = yoff = 0; xOverflowOffset = yOverflowOffset = 0; maxWidth = this.ClientRectangle.Width; maxHeight = this.ClientRectangle.Height; minWidth = 0; minHeight = 0; //width of the guide line grid snapToGrid.FieldWidth = FIELD_WIDTH; DRAWABLE_GRID_LINE_WIDTH = (int)snapToGrid.FieldWidth; //maximum distance from a guide line in pixels before snapping fires snapToGrid.SnapType = SnapToGrid.SnapTypes.Fixed; snapToGrid.SnapFixed = 6; newSymmetricPoint = referencePoint = null; dimensionPoints = new ShapePoint[4]; for (int i = 0; i < 4; ++i) { dimensionPoints[i] = new ShapePoint(); } InitializeComponent(); base.SetStyle( ControlStyles.OptimizedDoubleBuffer | ControlStyles.Opaque | ControlStyles.ContainerControl | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true); this.contextMenuPoint.RenderMode = ToolStripRenderMode.Professional; ((ToolStripProfessionalRenderer)this.contextMenuPoint.Renderer).ColorTable.UseSystemColors = true; this.contextMenuLine.RenderMode = ToolStripRenderMode.Professional; ((ToolStripProfessionalRenderer)this.contextMenuLine.Renderer).ColorTable.UseSystemColors = true; this.menuItemAddPoint.Click += new EventHandler(menuItemAddPoint_Click); this.menuItemConvert.Click += new EventHandler(menuItemConvert_Click); this.menuItemRemovePoint.Click += new EventHandler(menuItemRemovePoint_Click); this.menuItemRemoveLine.Click += new EventHandler(menuItemRemoveLine_Click); this.menuItemAnchorLeft.Click += new EventHandler(menuItemAnchorLeft_Click); this.menuItemAnchorRight.Click += new EventHandler(menuItemAnchorRight_Click); this.menuItemAnchorTop.Click += new EventHandler(menuItemAnchorTop_Click); this.menuItemAnchorBottom.Click += new EventHandler(menuItemAnchorBottom_Click); this.menuItemConvertLine.Click += new EventHandler(menuItemConvert_Click); this.menuItemLeftTopCorner.Click += new EventHandler(menuItemLeftTopCorner_Click); this.menuItemLeftBottomCorner.Click += new EventHandler(menuItemLeftBottomCorner_Click); this.menuItemRightTopCorner.Click += new EventHandler(menuItemRightTopCorner_Click); this.menuItemRightBottomCorner.Click += new EventHandler(menuItemRightBottomCorner_Click); this.menuItemLocked.Click += new EventHandler(menuItemLocked_Click); }
private void menuItemAddPoint_Click(object sender, EventArgs e) { int index = this.points.IndexOf(this.point as ShapePoint) + 1; if (index >= this.points.Count) { index = 0; } this.points.Insert(index, new ShapePoint(this.downPoint.X, this.downPoint.Y)); this.point = (ShapePointBase)this.points[index]; this.propertyGrid.SelectedObject = (object)this.point; this.Refresh(); }
void menuItemAddPoint_Click(object sender, EventArgs e) { int index = points.IndexOf(point as ShapePoint) + 1; if (index >= points.Count) { index = 0; } points.Insert(index, new ShapePoint(downPoint.X, downPoint.Y)); point = points[index]; propertyGrid.SelectedObject = point; Refresh(); }
private ShapePoint.LineDirections GetLineDirection(ShapePointBase nextPoint) { if ((double)this.X == (double)nextPoint.X) { return((double)this.Y < (double)nextPoint.Y ? ShapePoint.LineDirections.South : ShapePoint.LineDirections.Nord); } if ((double)this.Y == (double)nextPoint.Y) { return((double)this.X < (double)nextPoint.X ? ShapePoint.LineDirections.West : ShapePoint.LineDirections.East); } if ((double)this.X < (double)nextPoint.X) { return((double)this.Y < (double)nextPoint.Y ? ShapePoint.LineDirections.SouthWest : ShapePoint.LineDirections.NordWest); } return((double)this.Y < (double)nextPoint.Y ? ShapePoint.LineDirections.NordEast : ShapePoint.LineDirections.SouthEast); }
/// <summary> /// Retrieves the line direction of the line that passes through the instance /// point and the point given as an argument. /// </summary> /// <param name="nextPoint"></param> /// <returns></returns> LineDirections GetLineDirection(ShapePointBase nextPoint) { if (X == nextPoint.X) { if (Y < nextPoint.Y) { return(LineDirections.South); } else { return(LineDirections.Nord); } } else if (Y == nextPoint.Y) { if (X < nextPoint.X) { return(LineDirections.West); } else { return(LineDirections.East); } } else if (X < nextPoint.X) { if (Y < nextPoint.Y) { return(LineDirections.SouthWest); } else { return(LineDirections.NordWest); } } else if (Y < nextPoint.Y) { return(LineDirections.NordEast); } else { return(LineDirections.SouthEast); } }
/// <summary> /// Updates the bounds of the drawable area /// </summary> /// <param name="pt"></param> private void UpdateMaxSize(ShapePointBase pt) { if (pt.X > maxWidth) { maxWidth = (int)pt.X; } if (pt.Y > maxHeight) { maxHeight = (int)pt.Y; } if (pt.X < minWidth) { minWidth = (int)pt.X; } if (pt.Y < minHeight) { minHeight = (int)pt.Y; } }
private void verticallyToolStripMenuItem_Click(object sender, EventArgs e) { int index = this.points.IndexOf(this.point as ShapePoint) + 1; if (index >= this.points.Count) { index = 0; } Rectangle dimension = this.dimension; int num = dimension.Top + dimension.Height / 2; ShapePoint shapePoint = new ShapePoint(); shapePoint.X = this.point.X; shapePoint.Y = this.point.Y + (float)(2.0 * ((double)num - (double)this.point.Y)); this.points.Insert(index, shapePoint); this.point = (ShapePointBase)this.points[index]; this.propertyGrid.SelectedObject = (object)this.point; this.Refresh(); }
private void UpdateMaxSize(ShapePointBase pt) { if ((double)pt.X > (double)this.maxWidth) { this.maxWidth = (int)pt.X; } if ((double)pt.Y > (double)this.maxHeight) { this.maxHeight = (int)pt.Y; } if ((double)pt.X < (double)this.minWidth) { this.minWidth = (int)pt.X; } if ((double)pt.Y >= (double)this.minHeight) { return; } this.minHeight = (int)pt.Y; }
public RadShapeEditorControl() { this.snapToGrid = new SnapToGrid(); this.xoff = this.yoff = 0; this.xOverflowOffset = this.yOverflowOffset = 0; this.maxWidth = this.ClientRectangle.Width; this.maxHeight = this.ClientRectangle.Height; this.minWidth = 0; this.minHeight = 0; this.snapToGrid.FieldWidth = 20f; this.DRAWABLE_GRID_LINE_WIDTH = (int)this.snapToGrid.FieldWidth; this.snapToGrid.SnapType = SnapToGrid.SnapTypes.Fixed; this.snapToGrid.SnapFixed = 6f; this.newSymmetricPoint = this.referencePoint = (ShapePointBase)null; this.dimensionPoints = new ShapePoint[4]; for (int index = 0; index < 4; ++index) { this.dimensionPoints[index] = new ShapePoint(); } this.InitializeComponent(); this.SetStyle(ControlStyles.ContainerControl | ControlStyles.UserPaint | ControlStyles.Opaque | ControlStyles.ResizeRedraw | ControlStyles.AllPaintingInWmPaint | ControlStyles.OptimizedDoubleBuffer, true); this.contextMenuPoint.RenderMode = ToolStripRenderMode.Professional; ((ToolStripProfessionalRenderer)this.contextMenuPoint.Renderer).ColorTable.UseSystemColors = true; this.contextMenuLine.RenderMode = ToolStripRenderMode.Professional; ((ToolStripProfessionalRenderer)this.contextMenuLine.Renderer).ColorTable.UseSystemColors = true; this.menuItemAddPoint.Click += new EventHandler(this.menuItemAddPoint_Click); this.menuItemConvert.Click += new EventHandler(this.menuItemConvert_Click); this.menuItemRemovePoint.Click += new EventHandler(this.menuItemRemovePoint_Click); this.menuItemRemoveLine.Click += new EventHandler(this.menuItemRemoveLine_Click); this.menuItemAnchorLeft.Click += new EventHandler(this.menuItemAnchorLeft_Click); this.menuItemAnchorRight.Click += new EventHandler(this.menuItemAnchorRight_Click); this.menuItemAnchorTop.Click += new EventHandler(this.menuItemAnchorTop_Click); this.menuItemAnchorBottom.Click += new EventHandler(this.menuItemAnchorBottom_Click); this.menuItemConvertLine.Click += new EventHandler(this.menuItemConvert_Click); this.menuItemLeftTopCorner.Click += new EventHandler(this.menuItemLeftTopCorner_Click); this.menuItemLeftBottomCorner.Click += new EventHandler(this.menuItemLeftBottomCorner_Click); this.menuItemRightTopCorner.Click += new EventHandler(this.menuItemRightTopCorner_Click); this.menuItemRightBottomCorner.Click += new EventHandler(this.menuItemRightBottomCorner_Click); this.menuItemLocked.Click += new EventHandler(this.menuItemLocked_Click); }
private void verticallyToolStripMenuItem_Click(object sender, EventArgs e) { //creates a new point, symmetric to the given one on the other side of a horizontal symmetry line int index = points.IndexOf(point as ShapePoint) + 1; if (index >= points.Count) { index = 0; } //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; ShapePoint newPoint = new ShapePoint(); newPoint.X = point.X; newPoint.Y = point.Y + 2 * (midy - point.Y); //insert the point in the chain of points points.Insert(index, newPoint); point = points[index]; propertyGrid.SelectedObject = point; Refresh(); }
/// <summary> /// Translates a point in accordance with the offsets due to scrolling /// </summary> /// <param name="pt"></param> /// <returns></returns> private Point GetRealFromVirtualPoint(ShapePointBase pt) { return(new Point( (int)Math.Round((pt.GetPoint().X - xOverflowOffset) * zoomFactor), (int)Math.Round((pt.GetPoint().Y - yOverflowOffset) * zoomFactor))); }
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))); } } }
private Point GetRealFromVirtualPoint(ShapePointBase pt) { return(new Point((int)Math.Round((double)(pt.GetPoint().X - this.xOverflowOffset) * (double)this.zoomFactor), (int)Math.Round((double)(pt.GetPoint().Y - this.yOverflowOffset) * (double)this.zoomFactor))); }
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))); } } }