public override eDrawObjectMouseDown OnMouseDown(ICanvas canvas, UnitPoint point, ISnapPoint snappoint) { if (m_tanSnap != null && Control.MouseButtons == MouseButtons.Right) { ReverseTangent(canvas); return(eDrawObjectMouseDown.Continue); } if (m_perSnap != null || m_tanSnap != null) { if (snappoint != null) { point = snappoint.SnapPoint; } OnMouseMove(canvas, point); if (m_singleLineSegment) { return(eDrawObjectMouseDown.Done); } return(eDrawObjectMouseDown.DoneRepeat); } eDrawObjectMouseDown result = base.OnMouseDown(canvas, point, snappoint); if (m_singleLineSegment) { return(eDrawObjectMouseDown.Done); } return(eDrawObjectMouseDown.DoneRepeat); }
/// <summary> /// 处理鼠标按下的绘图 /// </summary> /// <param name="mouseunitpoint"></param> /// <param name="snappoint"></param> protected virtual void HandleMouseDownWhenDrawing(UnitPoint mouseunitpoint, ISnapPoint snappoint) { if (m_commandType != eCommandType.draw) { return; } if (m_newObject == null) { m_newObject = m_model.CreateObject(m_drawObjectId, mouseunitpoint, snappoint); DoInvalidate(false, m_newObject.GetBoundingRect(m_canvaswrapper)); return; } eDrawObjectMouseDown result = m_newObject.OnMouseDown(m_canvaswrapper, mouseunitpoint, snappoint); switch (result) { case eDrawObjectMouseDown.Done: m_model.AddObject(m_model.ActiveLayer, m_newObject); m_newObject = null; DoInvalidate(true); break; case eDrawObjectMouseDown.DoneRepeat: m_model.AddObject(m_model.ActiveLayer, m_newObject); m_newObject = m_model.CreateObject(m_newObject.Id, m_newObject.RepeatStartingPoint, null); DoInvalidate(true); break; case eDrawObjectMouseDown.Continue: break; } }
protected virtual void HandleMouseDownWhenDrawing(UnitPoint mouseunitpoint, ISnapPoint snappoint) { if (m_commandType == eCommandType.draw) { if (m_newObject == null) { m_newObject = m_model.CreateObject(m_drawObjectId, mouseunitpoint, snappoint); DoInvalidate(false, m_newObject.GetBoundingRect(m_canvaswrapper)); } else { if (m_newObject != null) { eDrawObjectMouseDown result = m_newObject.OnMouseDown(m_canvaswrapper, mouseunitpoint, snappoint); switch (result) { case eDrawObjectMouseDown.Done: IDrawObject addedObj = m_model.AddObject(m_model.ActiveLayer, m_newObject); if (m_newObject is IConnectionCurve) { m_model.TrySnapConnectCrvToRectShape(m_canvaswrapper, (IConnectionCurve)addedObj); } m_newObject = null; DoInvalidate(true); break; case eDrawObjectMouseDown.DoneRepeat: addedObj = m_model.AddObject(m_model.ActiveLayer, m_newObject); if (addedObj is IConnectionCurve) { m_model.TrySnapConnectCrvToRectShape(m_canvaswrapper, (IConnectionCurve)addedObj); } m_newObject = m_model.CreateObject(m_newObject.Id, m_newObject.RepeatStartingPoint, null); DoInvalidate(true); break; case eDrawObjectMouseDown.Continue: break; case eDrawObjectMouseDown.Cancel: m_newObject = null; DoInvalidate(true); break; } } } } }
/// <summary> /// 鼠标按下事件 /// </summary> /// <param name="e"></param> protected override void OnMouseDown(MouseEventArgs e) { m_mousedownPoint = new PointF(e.X, e.Y); // used when panning m_dragOffset = new PointF(0, 0); UnitPoint mousepoint = ToUnit(m_mousedownPoint); //获取当前光标世界坐标 if (m_snappoint != null) { mousepoint = m_snappoint.SnapPoint; } if (m_commandType == eCommandType.editNode) //如果为编辑节点 { bool handled = false; if (m_nodeMoveHelper.HandleMouseDown(mousepoint, ref handled)) { FinishNodeEdit(); base.OnMouseDown(e); return; } } if (m_commandType == eCommandType.select) //如果为选中 { bool handled = false; if (m_nodeMoveHelper.HandleMouseDown(mousepoint, ref handled)) { m_commandType = eCommandType.editNode; m_snappoint = null; base.OnMouseDown(e); return; } m_selection = new SelectionRectangle(m_mousedownPoint); } if (m_commandType == eCommandType.move) //如果为移动 { m_moveHelper.HandleMouseDownForMove(mousepoint, m_snappoint); } if (m_commandType == eCommandType.draw) //如果为绘制 { HandleMouseDownWhenDrawing(mousepoint, null); DoInvalidate(true); } if (m_commandType == eCommandType.edit) //如果为编辑 { if (m_editTool == null) //如果编辑工具为空 { m_editTool = m_model.GetEditTool(m_editToolId); } if (m_editTool != null) //如果编辑工具不为空 { if (m_editTool.SupportSelection) { m_selection = new SelectionRectangle(m_mousedownPoint); } eDrawObjectMouseDown mouseresult = m_editTool.OnMouseDown(m_canvaswrapper, mousepoint, m_snappoint); /* * if (mouseresult == eDrawObjectMouseDown.Continue) * { * if (m_editTool.SupportSelection) * m_selection = new SelectionRectangle(m_mousedownPoint); * } * */ if (mouseresult == eDrawObjectMouseDown.Done) //如果绘制已经完成 { m_editTool.Finished(); m_editTool = m_model.GetEditTool(m_editToolId); // continue with new tool //m_editTool = null; if (m_editTool.SupportSelection) { m_selection = new SelectionRectangle(m_mousedownPoint); } } } DoInvalidate(true); UpdateCursor(); //更新光标 } base.OnMouseDown(e); }
protected override void OnMouseDown(MouseEventArgs e) { if (m_rectBaseTextBox != null && m_rectBaseTextBox.Tag != null) { ((DrawTools.RectBase)m_rectBaseTextBox.Tag).Text = m_rectBaseTextBox.Text; ((DrawTools.RectBase)m_rectBaseTextBox.Tag).Selected = false; Controls.Remove(m_rectBaseTextBox); m_model.ClearSelectedObjects(); m_rectBaseTextBox = null; DoInvalidate(true); return; } if (e.Button == MouseButtons.Middle) { CommandEscape(); CommandPan(); } if (e.Button == MouseButtons.Right) { CommandEscape(); } m_mousedownPoint = new PointF(e.X, e.Y); // used when panning m_dragOffset = new PointF(0, 0); UnitPoint mousepoint = ToUnit(m_mousedownPoint); if (m_snappoint != null) { mousepoint = m_snappoint.SnapPoint; //snap point: rect point } if (m_commandType == eCommandType.editNode) { //modify a obj's node, e.g: move node bool handled = false; if (m_nodeMoveHelper.HandleMouseDown(mousepoint, ref handled, m_snappoint)) { FinishNodeEdit(); base.OnMouseDown(e); return; } } if (m_commandType == eCommandType.select) { //select an exsiting obj bool handled = false; if (m_nodeMoveHelper.HandleMouseDown(mousepoint, ref handled, m_snappoint)) { m_commandType = eCommandType.editNode; m_snappoint = null; base.OnMouseDown(e); return; } m_selection = new SelectionRectangle(m_mousedownPoint); } if (m_commandType == eCommandType.move) { m_moveHelper.HandleMouseDownForMove(mousepoint, m_snappoint); } if (m_commandType == eCommandType.draw) { //make a new obj and add it to model HandleMouseDownWhenDrawing(mousepoint, m_snappoint); DoInvalidate(true); } if (m_commandType == eCommandType.edit) { if (m_editTool == null) { m_editTool = m_model.GetEditTool(m_editToolId); } if (m_editTool != null) { if (m_editTool.SupportSelection) { m_selection = new SelectionRectangle(m_mousedownPoint); } eDrawObjectMouseDown mouseresult = m_editTool.OnMouseDown(m_canvaswrapper, mousepoint, m_snappoint); /* * if (mouseresult == eDrawObjectMouseDown.Continue) * { * if (m_editTool.SupportSelection) * m_selection = new SelectionRectangle(m_mousedownPoint); * } * */ if (mouseresult == eDrawObjectMouseDown.Done) { m_editTool.Finished(); m_editTool = m_model.GetEditTool(m_editToolId); // continue with new tool //m_editTool = null; if (m_editTool.SupportSelection) { m_selection = new SelectionRectangle(m_mousedownPoint); } } } DoInvalidate(true); UpdateCursor(); } base.OnMouseDown(e); }