private Rectangle GetRectangle(ResizePosition value) { Shape tempShape = doc.allShapes[indexOfSelectedShape.Value]; switch (value) { case ResizePosition.LeftUp: return(new Rectangle(tempShape.StartOrigin.X - 7, tempShape.StartOrigin.Y - 7, sizeNodeRect, sizeNodeRect)); case ResizePosition.LeftMiddle: return(new Rectangle(tempShape.StartOrigin.X - 7, tempShape.StartOrigin.Y + tempShape.Height / 2, sizeNodeRect, sizeNodeRect)); case ResizePosition.LeftBottom: return(new Rectangle(tempShape.StartOrigin.X - 7, tempShape.StartOrigin.Y + 5 + tempShape.Height, sizeNodeRect, sizeNodeRect)); case ResizePosition.BottomMiddle: return(new Rectangle(tempShape.StartOrigin.X + tempShape.Width / 2, tempShape.StartOrigin.Y + 5 + tempShape.Height, sizeNodeRect, sizeNodeRect)); case ResizePosition.RightUp: return(new Rectangle(tempShape.StartOrigin.X + 5 + tempShape.Width, tempShape.StartOrigin.Y - 7, sizeNodeRect, sizeNodeRect)); case ResizePosition.RightBottom: return(new Rectangle(tempShape.StartOrigin.X + 5 + tempShape.Width, tempShape.StartOrigin.Y + 5 + tempShape.Height, sizeNodeRect, sizeNodeRect)); case ResizePosition.RightMiddle: return(new Rectangle(tempShape.StartOrigin.X + 5 + tempShape.Width, tempShape.StartOrigin.Y + tempShape.Height / 2, sizeNodeRect, sizeNodeRect)); case ResizePosition.UpMiddle: return(new Rectangle(tempShape.StartOrigin.X + tempShape.Width / 2, tempShape.StartOrigin.Y - 6, sizeNodeRect, sizeNodeRect)); default: return(new Rectangle()); } }
private Cursor GetCursor(ResizePosition p) { switch (p) { case ResizePosition.LeftUp: return(Cursors.SizeNWSE); case ResizePosition.LeftMiddle: return(Cursors.SizeWE); case ResizePosition.LeftBottom: return(Cursors.SizeNESW); case ResizePosition.BottomMiddle: return(Cursors.SizeNS); case ResizePosition.RightUp: return(Cursors.SizeNESW); case ResizePosition.RightBottom: return(Cursors.SizeNWSE); case ResizePosition.RightMiddle: return(Cursors.SizeWE); case ResizePosition.UpMiddle: return(Cursors.SizeNS); default: return(Cursors.Default); } }
private Point GetResizeOrigin(Rect bounds, ResizePosition resizePos) { switch (resizePos) { case ResizePosition.TopLeft: return(bounds.BottomRight); case ResizePosition.Top: return(new Point(bounds.Left + bounds.Width / 2.0, bounds.Bottom)); case ResizePosition.TopRight: return(bounds.BottomLeft); case ResizePosition.Left: return(new Point(bounds.Right, bounds.Top + bounds.Height / 2.0)); case ResizePosition.Right: return(new Point(bounds.Left, bounds.Top + bounds.Height / 2.0)); case ResizePosition.BottomLeft: return(bounds.TopRight); case ResizePosition.Bottom: return(new Point(bounds.Left + bounds.Width / 2.0, bounds.Top)); case ResizePosition.BottomRight: return(bounds.TopLeft); } throw new NotImplementedException("The desired ResizePos is not implemented in GetResizeOrigin"); }
public override void OnStartResize(ResizePosition resizePos, Point resizeOrigin) { base.OnStartResize(resizePos, resizeOrigin); if (Line == null) { return; } _DragStartPoint1 = Line.StartPoint; _DragStartPoint2 = Line.EndPoint; }
public override void OnStartResize(ResizePosition resizePos, Point resizeOrigin) { base.OnStartResize(resizePos, resizeOrigin); if (Ellipse == null) { return; } var s = new Vector(Ellipse.RadiusX, Ellipse.RadiusY); _DragStartRect = new Rect(Ellipse.Center - s, Ellipse.Center + s); }
public override void OnStartResize(ResizePosition resizePos, Point resizeOrigin) { base.OnStartResize(resizePos, resizeOrigin); if (Path == null) { return; } _DragStartPoints = new List <Point>(); ForEachAbsPoint(args => _DragStartPoints.Add(args.Point)); }
public override void OnUpdateResize(Rect newBounds, ResizePosition resizePos, Point resizeOrigin) { base.OnUpdateResize(newBounds, resizePos, resizeOrigin); if (Rectangle == null) { return; } Rectangle.Rect = newBounds; GeometryChanged(); }
private void pnlGraphic_MouseDown(object sender, MouseEventArgs e) { mIsClick = true; if (selectionMode && doc.allShapes.Count == 0) { MessageBox.Show("Няма фигури за избиране !"); } else if (selectionMode && doc.allShapes.Count != 0) { for (int i = doc.allShapes.Count - 1; i >= 0; i--) { if (doc.allShapes[i].ContainsPoint(e.Location)) { isShapeWasSelected = true; Shape tempShape = doc.allShapes[i]; if (doc.allShapes.Count == 2 && tempShape != doc.allShapes[doc.allShapes.Count - 1]) { doc.allShapes[i] = doc.allShapes[i + 1]; doc.allShapes[i + 1] = tempShape; } else if (doc.allShapes.Count > 2 && tempShape != doc.allShapes[doc.allShapes.Count - 1]) { for (int j = i; j < doc.allShapes.Count - 1; j++) { doc.allShapes[j] = doc.allShapes[j + 1]; } doc.allShapes[doc.allShapes.Count - 1] = tempShape; } indexOfSelectedShape = doc.allShapes.Count - 1; mMove = true; break; } } if (isShapeWasSelected && indexOfSelectedShape != null) { btnDefaultColor.BackColor = doc.allShapes[indexOfSelectedShape.Value].ChosenColor; nodeSelected = ResizePosition.None; nodeSelected = GetNodeSelectable(e.Location); } } else if (!selectionMode) { paint = true; } startPoint.X = e.X; startPoint.Y = e.Y; pnlGraphic.Invalidate(); }
public override void OnUpdateResize(Rect newBounds, ResizePosition resizePos, Point resizeOrigin) { base.OnUpdateResize(newBounds, resizePos, resizeOrigin); if (Ellipse == null) { return; } Ellipse.RadiusX = newBounds.Width / 2.0; Ellipse.RadiusY = newBounds.Height / 2.0; Ellipse.Center = newBounds.TopLeft + new Vector(Ellipse.RadiusX, Ellipse.RadiusY); GeometryChanged(); }
public override void OnUpdateResize(Rect newBounds, ResizePosition resizePos, Point resizeOrigin) { base.OnUpdateResize(newBounds, resizePos, resizeOrigin); if (Line == null) { return; } var transform = CalcResizeTransform(newBounds, resizeOrigin); Line.StartPoint = transform.Transform(_DragStartPoint1); Line.EndPoint = transform.Transform(_DragStartPoint2); GeometryChanged(); }
public override void OnUpdateResize(Rect newBounds, ResizePosition resizePos, Point resizeOrigin) { base.OnUpdateResize(newBounds, resizePos, resizeOrigin); if (Path == null || _DragStartPoints == null) { return; } var transform = CalcResizeTransform(newBounds, resizeOrigin); int n = 0; ForEachAbsPoint(args => { if (n < _DragStartPoints.Count) { args.Point = transform.Transform(_DragStartPoints[n++]); args.PointModified = true; } }); GeometryChanged(); }
private void ShowResizeMouseCursor(MouseEventArgsEx e) { Point p = PointToClient(new Point(e.ScreenX, e.ScreenY)); int w = this.Content.Width; int h = this.Content.Height; int x = this.Content.Left; int y = this.Content.Top; int offset = this.resizeCornerOffset; // x1 y1 x2 y2 x3 y3 x4 y4 的 1 2 3 4 的 顺序 是 左上角 左下角 右下角 右上角 int x1 = x - offset; int y1 = y - offset; int x2 = x - offset; int y2 = y + h - 1 + offset; int x3 = x + w - 1 + offset; int y3 = y + h - 1 + offset; int x4 = x + w - 1 + offset; int y4 = y - offset; int c = this.resizeCornerSize; if (p.X >= x3 - c && p.X <= x3 && p.Y >= y3 - c && p.Y <= y3) { this.Cursor = Cursors.SizeNWSE; this.isMouseInResizeArea = true; this.resizePosition = ResizePosition.RightBottom; } else if (p.X >= x1 && p.X <= x1 + c && p.Y >= y1 && p.Y <= y1 + c) { this.Cursor = Cursors.SizeNWSE; this.isMouseInResizeArea = true; this.resizePosition = ResizePosition.LeftTop; } else if (p.X >= x2 && p.X <= x2 + c && p.Y >= y2 - c && p.Y <= y2) { this.Cursor = Cursors.SizeNESW; this.isMouseInResizeArea = true; this.resizePosition = ResizePosition.LeftBottom; } else if (p.X >= x4 - c && p.X <= x4 && p.Y >= y4 && p.Y <= y4 + c) { this.Cursor = Cursors.SizeNESW; this.isMouseInResizeArea = true; this.resizePosition = ResizePosition.RightTop; } else if (p.X >= x2 && p.X <= x3 && p.Y >= y2 - c && p.Y <= y2) { this.Cursor = Cursors.SizeNS; this.isMouseInResizeArea = true; this.resizePosition = ResizePosition.Bottom; } else if (p.X >= x1 && p.X <= x4 && p.Y >= y1 && p.Y <= y1 + c) { this.Cursor = Cursors.SizeNS; this.isMouseInResizeArea = true; this.resizePosition = ResizePosition.Top; } else if (p.X >= x1 && p.X <= x1 + c && p.Y >= y1 && p.Y <= y2) { this.Cursor = Cursors.SizeWE; this.isMouseInResizeArea = true; this.resizePosition = ResizePosition.Left; } else if (p.X >= x4 - c && p.X <= x4 && p.Y >= y4 && p.Y <= y3) { this.Cursor = Cursors.SizeWE; this.isMouseInResizeArea = true; this.resizePosition = ResizePosition.Right; } else { if (this.isMouseInResizeArea) { this.Cursor = Cursors.Default; this.isMouseInResizeArea = false; } } }
public override void OnStartResize(ResizePosition resizePos, Point resizeOrigin) { base.OnStartResize(resizePos, resizeOrigin); }
public override void OnUpdateResize(Rect newBounds, ResizePosition resizePos, Point resizeOrigin) { base.OnUpdateResize(newBounds, resizePos, resizeOrigin); Position = newBounds.TopLeft; Size = newBounds.Size; }
private Rect CalcNewResizeBounds(Rect oldBounds, ResizePosition resizePos, Vector delta) { switch (resizePos) { case ResizePosition.TopLeft: if (delta.X > oldBounds.Width) { delta.X = oldBounds.Width; } if (delta.Y > oldBounds.Height) { delta.Y = oldBounds.Height; } return(new Rect(oldBounds.TopLeft + delta, oldBounds.BottomRight)); case ResizePosition.Top: delta.X = 0.0; if (delta.Y > oldBounds.Height) { delta.Y = oldBounds.Height; } return(new Rect(oldBounds.TopLeft + delta, oldBounds.BottomRight)); case ResizePosition.TopRight: if (delta.X < -oldBounds.Width) { delta.X = -oldBounds.Width; } if (delta.Y > oldBounds.Height) { delta.Y = oldBounds.Height; } return(new Rect(oldBounds.TopRight + delta, oldBounds.BottomLeft)); case ResizePosition.Left: if (delta.X > oldBounds.Width) { delta.X = oldBounds.Width; } delta.Y = 0.0; return(new Rect(oldBounds.TopLeft + delta, oldBounds.BottomRight)); case ResizePosition.Right: if (delta.X < -oldBounds.Width) { delta.X = -oldBounds.Width; } delta.Y = 0.0; return(new Rect(oldBounds.TopRight + delta, oldBounds.BottomLeft)); case ResizePosition.BottomLeft: if (delta.X > oldBounds.Width) { delta.X = oldBounds.Width; } if (delta.Y < -oldBounds.Height) { delta.Y = -oldBounds.Height; } return(new Rect(oldBounds.BottomLeft + delta, oldBounds.TopRight)); case ResizePosition.Bottom: delta.X = 0.0; if (delta.Y < -oldBounds.Height) { delta.Y = -oldBounds.Height; } return(new Rect(oldBounds.BottomLeft + delta, oldBounds.TopRight)); case ResizePosition.BottomRight: if (delta.X < -oldBounds.Width) { delta.X = -oldBounds.Width; } if (delta.Y < -oldBounds.Height) { delta.Y = -oldBounds.Height; } return(new Rect(oldBounds.BottomRight + delta, oldBounds.TopLeft)); } return(oldBounds); }
public virtual void OnStartResize(ResizePosition resizePos, Point resizeOrigin) { _ResizeStartBounds = VertexBounds; SetModified(); }
public virtual void OnFinishResize(Rect newBounds, ResizePosition resizePos, Point resizeOrigin) { SetModified(); }