public static DrawObject CreateDrawObject(SVGUnit svge) { DrawObject o = null; switch (svge.getElementType()) { case SVGUnit.SVGUnitType.typeLine: o = DrawLineObject.Create((SVGLine)svge); break; case SVGUnit.SVGUnitType.typeRect: o = DrawRectangleObject.Create((SVGRect)svge); break; case SVGUnit.SVGUnitType.typeEllipse: o = DrawEllipseObject.Create((SVGEllipse)svge); break; case SVGUnit.SVGUnitType.typePolyline: o = DrawPolygonObject.Create((SVGPolyline)svge); break; case SVGUnit.SVGUnitType.typeImage: o = DrawImageObject.Create((SVGImage)svge); break; case SVGUnit.SVGUnitType.typeText: o = DrawTextObject.Create((SVGText)svge); break; case SVGUnit.SVGUnitType.typePath: o = DrawPathObject.Create((SVGPath)svge); break; case SVGUnit.SVGUnitType.typeCircle: o = DrawCircleObject.Create((SVGCircle)svge); break; default: break; } return(o); }
/// <summary> /// 按下鼠标左键 /// </summary> public override void OnMouseDown(DrawArea drawArea, MouseEventArgs e) { _selectMode = SelectionMode.None; PointF point = new Point(e.X, e.Y); // 调整大小的测试(仅当选择了控件时,光标位于句柄上) int n = drawArea.GraphicsList.SelectionCount; for (int i = 0; i < n; i++) { DrawObject o = drawArea.GraphicsList.GetSelectedObject(i); int handleNumber = o.HitTest(point); bool hitOnOutline = o.HitOnCircumferance; if (handleNumber > 0) { _selectMode = SelectionMode.Size; #region LineConnect if (o is DrawConnectLine && handleNumber != 2) { ((DrawConnectLine)o).SetFollowObjectNull(handleNumber); } if (o is DrawConnectObject connect) { connect.SetFollowDrawObject(handleNumber, null, -1); } //if (o is WireConnectLineDrawObject && handleNumber != 2) //{ // ((WireConnectLineDrawObject)o).SetFollowObjectNull(handleNumber); //} #endregion //if ( o is SingleDisConnectorDrawObject && handleNumber == 9) //{ // float state = ((SingleDisConnectorDrawObject)o).Switch; // ((SingleDisConnectorDrawObject)o).Switch = state == 0 ? 1 : 0; //} // 在类成员中保留调整大小的对象 _resizedObject = o; _resizedObjectHandle = handleNumber; // 因为我们只想调整一个对象的大小,所以取消选择所有其他对象。 drawArea.GraphicsList.UnselectAll(); o.Selected = true; o.MouseClickOnHandle(handleNumber); break; } if (hitOnOutline && (n == 1)) { _selectMode = SelectionMode.Size; o.MouseClickOnBorder(); o.Selected = true; } } // 移动测试(光标在对象上) if (_selectMode == SelectionMode.None) { int n1 = drawArea.GraphicsList.Count; DrawObject o = null; for (int i = 0; i < n1; i++) { if (drawArea.GraphicsList[i].HitTest(point) == 0) { o = drawArea.GraphicsList[i]; break; } } if (o != null) { _selectMode = SelectionMode.Move; // 如果未按ctrl且尚未选择单击的对象,则取消全选 if ((Control.ModifierKeys & Keys.Control) == 0 && !o.Selected) { drawArea.GraphicsList.UnselectAll(); } // 选择单击的对象 o.Selected = true; drawArea.Cursor = Cursors.SizeAll; } } //判断是否点击到旋钮 if (_selectMode == SelectionMode.None) { for (int i = 0; i < n; i++) { DrawObject o = drawArea.GraphicsList.GetSelectedObject(i); bool hitonknob = o.HitKnobTest(point); if (hitonknob) { _selectMode = SelectionMode.Rotate; // 在类成员中保留调整角度的对象 _rerotateObject = o; // 因为我们只想调整一个对象的大小,所以取消选择所有其他对象。 drawArea.GraphicsList.UnselectAll(); o.Selected = true; break; } } } // 净选择 if (_selectMode == SelectionMode.None) { // 点击背景 if ((Control.ModifierKeys & Keys.Control) == 0) { drawArea.GraphicsList.UnselectAll(); } _selectMode = SelectionMode.NetSelection; drawArea.DrawNetRectangle = true; } //保存一次最近操作 _lastPoint.X = e.X; _lastPoint.Y = e.Y; _startPoint.X = e.X; _startPoint.Y = e.Y; drawArea.Capture = true; drawArea.NetRectangle = DrawRectangleObject.GetNormalizedRectangle(_startPoint, _lastPoint); drawArea.Refresh(); }
/// <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; } }