protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (m_commandType == eCommandType.pan) { m_panOffset.X += m_dragOffset.X; m_panOffset.Y += m_dragOffset.Y; m_dragOffset = new PointF(0, 0); } List<IDrawObject> hitlist = null; Rectangle screenSelRect = Rectangle.Empty; if (m_selection != null) { screenSelRect = m_selection.ScreenRect(); RectangleF selectionRect = m_selection.Selection(m_canvaswrapper); if (selectionRect != RectangleF.Empty) { // is any selection rectangle. use it for selection hitlist = m_model.GetHitObjects(m_canvaswrapper, selectionRect, m_selection.AnyPoint()); DoInvalidate(true); } else { // else use mouse point UnitPoint mousepoint = ToUnit(new PointF(e.X, e.Y)); hitlist = m_model.GetHitObjects(m_canvaswrapper, mousepoint); } m_selection = null; } if (m_commandType == eCommandType.select) { if (hitlist != null) HandleSelection(hitlist); } if (m_commandType == eCommandType.edit && m_editTool != null) { UnitPoint mousepoint = ToUnit(m_mousedownPoint); if (m_snappoint != null) mousepoint = m_snappoint.SnapPoint; if (screenSelRect != Rectangle.Empty) m_editTool.SetHitObjects(mousepoint, hitlist); m_editTool.OnMouseUp(m_canvaswrapper, mousepoint, m_snappoint); } if (m_commandType == eCommandType.draw && m_newObject != null) { UnitPoint mousepoint = ToUnit(m_mousedownPoint); if (m_snappoint != null) mousepoint = m_snappoint.SnapPoint; m_newObject.OnMouseUp(m_canvaswrapper, mousepoint, m_snappoint); } }
protected override void OnMouseDown(MouseEventArgs e) { m_mousedownPoint = new PointF(e.X, e.Y); // used when panning m_dragOffset = new PointF(0,0); if (e.Button == System.Windows.Forms.MouseButtons.Right) CommandEscape(); 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; } DoInvalidate(true); UpdateCursor(); m_selection = new SelectionRectangle(m_mousedownPoint); } if (m_commandType == eCommandType.move) { m_moveHelper.HandleMouseDownForMove(mousepoint, m_snappoint); } if (m_commandType == eCommandType.draw) { if (e.Button == System.Windows.Forms.MouseButtons.Middle && m_newObject != null) { if (m_newObject is ModuleItems.Module) (m_newObject as ModuleItems.Module).horizontal = !(m_newObject as ModuleItems.Module).horizontal; return; } 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); }
/// <summary> /// 鼠标抬起时 /// </summary> /// <param name="e"></param> protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (m_commandType == eCommandType.pan) //如果是移动画布 { m_panOffset.X += m_dragOffset.X; m_panOffset.Y += m_dragOffset.Y; m_dragOffset = new PointF(0, 0); } List <IDrawObject> hitlist = null; Rectangle screenSelRect = Rectangle.Empty; if (m_selection != null) //如果被选中的区域不为空 { screenSelRect = m_selection.ScreenRect(); RectangleF selectionRect = m_selection.Selection(m_canvaswrapper); if (selectionRect != RectangleF.Empty) { // is any selection rectangle. use it for selection选中是任意选择矩形。使用它进行选择 hitlist = m_model.GetHitObjects(m_canvaswrapper, selectionRect, m_selection.AnyPoint()); DoInvalidate(true); } else { // else use mouse point否则使用光标指向的点 UnitPoint mousepoint = ToUnit(new PointF(e.X, e.Y)); hitlist = m_model.GetHitObjects(m_canvaswrapper, mousepoint); } m_selection = null; } if (m_commandType == eCommandType.select) //如果是选中 { if (hitlist != null) { HandleSelection(hitlist); } } if (m_commandType == eCommandType.edit && m_editTool != null) //如果是编辑 { UnitPoint mousepoint = ToUnit(m_mousedownPoint); if (m_snappoint != null) { mousepoint = m_snappoint.SnapPoint; } if (screenSelRect != Rectangle.Empty) { m_editTool.SetHitObjects(mousepoint, hitlist); } m_editTool.OnMouseUp(m_canvaswrapper, mousepoint, m_snappoint); } if (m_commandType == eCommandType.draw && m_newObject != null) //如果是绘制且绘图工具不为 { UnitPoint mousepoint = ToUnit(m_mousedownPoint); if (m_snappoint != null) { mousepoint = m_snappoint.SnapPoint; } m_newObject.OnMouseUp(m_canvaswrapper, mousepoint, m_snappoint); } }
/// <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); }
/// <summary> /// 鼠标弹起 /// </summary> /// <param name="e"></param> protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); if (m_commandType == eCommandType.pan) { m_panOffset.X += m_dragOffset.X; m_panOffset.Y += m_dragOffset.Y; m_dragOffset = new PointF(0, 0); } List <IDrawObject> hitlist = null; Rectangle screenSelRect = Rectangle.Empty; if (m_selection != null) { screenSelRect = m_selection.ScreenRect(); RectangleF selectionRect = m_selection.Selection(m_canvaswrapper); if (selectionRect != RectangleF.Empty) { //是否选择矩形用它来选择 is any selection rectangle. use it for selection hitlist = m_model.GetHitObjects(m_canvaswrapper, selectionRect, m_selection.AnyPoint()); DoInvalidate(true); } else { //否则使用鼠标点 else use mouse point UnitPoint mousepoint = ToUnit(new PointF(e.X, e.Y)); hitlist = m_model.GetHitObjects(m_canvaswrapper, mousepoint); } m_selection = null; } //选择命令 if (m_commandType == eCommandType.select) { if (hitlist != null) { HandleSelection(hitlist); } } //编辑命令 if (m_commandType == eCommandType.edit && m_editTool != null) { UnitPoint mousepoint = ToUnit(m_mousedownPoint); if (m_snappoint != null) { mousepoint = m_snappoint.SnapPoint; } if (screenSelRect != Rectangle.Empty) { m_editTool.SetHitObjects(mousepoint, hitlist); } m_editTool.OnMouseUp(m_canvaswrapper, mousepoint, m_snappoint); } //绘制命令 if (m_commandType == eCommandType.draw && m_newObject != null) { UnitPoint mousepoint = ToUnit(m_mousedownPoint); if (m_snappoint != null) { mousepoint = m_snappoint.SnapPoint; } m_newObject.OnMouseUp(m_canvaswrapper, mousepoint, m_snappoint); } }
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); }