public void Execute() { _itemResized.MoveHandleTo(_newPoint, _handle); }
/// <summary> /// Mouse is moved. /// None button is pressed, or left button is pressed. /// </summary> /// <param name="drawArea"></param> /// <param name="e"></param> public override void OnMouseMove(DrawArea drawArea, MouseEventArgs e) { Point point = new Point(e.X, e.Y); Point oldPoint = lastPoint; wasMove = true; // set cursor when mouse button is not pressed if (e.Button == MouseButtons.None) { Cursor cursor = null; for (int i = 0; i < drawArea.GraphicsList.Count; i++) { int n = drawArea.GraphicsList[i].HitTest(point); if (n > 0) { cursor = drawArea.GraphicsList[i].GetHandleCursor(n); break; } } if (cursor == null) { cursor = Cursors.Default; } drawArea.Cursor = cursor; return; } if (e.Button != MouseButtons.Left) { return; } /// Left button is pressed // Find difference between previous and current position int dx = e.X - lastPoint.X; int dy = e.Y - lastPoint.Y; lastPoint.X = e.X; lastPoint.Y = e.Y; // resize if (selectMode == SelectionMode.Size) { if (resizedObject != null) { resizedObject.MoveHandleTo(point, resizedObjectHandle); drawArea.SetDirty(); drawArea.Refresh(); } } // move if (selectMode == SelectionMode.Move) { List <DrawObject> selectList = new List <DrawObject>(); int n = drawArea.GraphicsList.Count; for (int i = 0; i < n; i++) { if (drawArea.GraphicsList[i].Selected) { drawArea.GraphicsList.SelectAlist(drawArea.GraphicsList[i].TagIDBase); selectList.Add(drawArea.GraphicsList[i]); } } foreach (DrawObject o in selectList) { o.Move(dx, dy); } drawArea.Cursor = Cursors.SizeAll; drawArea.SetDirty(); drawArea.Refresh(); } if (selectMode == SelectionMode.NetSelection) { // Remove old selection rectangle ControlPaint.DrawReversibleFrame( drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, oldPoint)), Color.Black, FrameStyle.Dashed); // Draw new selection rectangle ControlPaint.DrawReversibleFrame( drawArea.RectangleToScreen(DrawRectangle.GetNormalizedRectangle(startPoint, point)), Color.Black, FrameStyle.Dashed); return; } }
/// <summary> /// 鼠标移动。 /// 无按钮按下,OT左按钮按下。 /// </summary> public override void OnMouseMove(DrawArea drawArea, MouseEventArgs e) { var point = new Point(e.X, e.Y); // 不按鼠标按钮时设置光标 if (e.Button == MouseButtons.None) { Cursor cursor = null; for (int i = 0; i < drawArea.GraphicsList.Count; i++) { int n = drawArea.GraphicsList[i].HitTest(point); if (n > 0) { cursor = drawArea.GraphicsList[i].GetHandleCursor(n); break; } if (drawArea.GraphicsList[i].HitOnCircumferance) { cursor = drawArea.GraphicsList[i].GetOutlineCursor(n); break; } bool hitknob = drawArea.GraphicsList[i].HitKnobTest(point); if (hitknob) { cursor = drawArea.GraphicsList[i].GetKnodCursor(); } } if (cursor == null) { cursor = Cursors.Default; } drawArea.Cursor = cursor; return; } if (e.Button != MouseButtons.Left) { return; } // 查找上一个位置和当前位置之间的差异 float dx = e.X - _lastPoint.X; float dy = e.Y - _lastPoint.Y; _lastPoint.X = e.X; _lastPoint.Y = e.Y; // resize if (_selectMode == SelectionMode.Size) { if (_resizedObject != null) { _resizedObject.MoveHandleTo(point, _resizedObjectHandle); drawArea.SetDirty(); drawArea.Refresh(); } } // move if (_selectMode == SelectionMode.Move) { int n = drawArea.GraphicsList.SelectionCount; for (int i = 0; i < n; i++) { drawArea.GraphicsList.GetSelectedObject(i).Move(dx, dy); } drawArea.Cursor = Cursors.SizeAll; drawArea.SetDirty(); drawArea.Refresh(); } if (_selectMode == SelectionMode.Rotate) { if (_rerotateObject != null) { //_rerotateObject.RotateKnobTo(point); _rerotateObject.Rotate((dx + dy) / 2); drawArea.SetDirty(); drawArea.Refresh(); } } if (_selectMode == SelectionMode.NetSelection) { drawArea.NetRectangle = DrawRectangleObject.GetNormalizedRectangle(_startPoint, _lastPoint); drawArea.Refresh(); return; } }