/// <summary> /// 鼠标移动事件 /// </summary> /// <param name="e"></param> protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (m_selection != null) { Graphics dc = Graphics.FromHwnd(Handle); m_selection.SetMousePoint(dc, new PointF(e.X, e.Y)); dc.Dispose(); return; } if (m_commandType == eCommandType.pan && e.Button == MouseButtons.Left) //如果选择pan(移动画布),切按住鼠标左键 { m_dragOffset.X = -(m_mousedownPoint.X - e.X); m_dragOffset.Y = -(m_mousedownPoint.Y - e.Y); m_lastCenterPoint = CenterPointUnit(); DoInvalidate(true); } UnitPoint mousepoint; UnitPoint unitpoint = ToUnit(new PointF(e.X, e.Y)); if (m_commandType == eCommandType.draw || m_commandType == eCommandType.move || m_nodeMoveHelper.IsEmpty == false) //如果使绘制或者移动或节点移动或节点移动为空 { Rectangle invalidaterect = Rectangle.Empty; ISnapPoint newsnap = null; mousepoint = GetMousePoint(); if (RunningSnapsEnabled) { newsnap = m_model.SnapPoint(m_canvaswrapper, mousepoint, m_runningSnapTypes, null); } if (newsnap == null) { newsnap = m_model.GridLayer.SnapPoint(m_canvaswrapper, mousepoint, null); } if ((m_snappoint != null) && ((newsnap == null) || (newsnap.SnapPoint != m_snappoint.SnapPoint) || m_snappoint.GetType() != newsnap.GetType())) //绘图时点击左键生成节点 { Console.WriteLine("canvas 688"); invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, m_snappoint.BoundingRect)); invalidaterect.Inflate(2, 2); RepaintStatic(invalidaterect); // remove old snappoint m_snappoint = newsnap; } if (m_commandType == eCommandType.move)//使用移动工具时,重画图像 { Invalidate(invalidaterect); } if (m_snappoint == null) { m_snappoint = newsnap; } } m_owner.SetPositionInfo(unitpoint); //给出绘制信息 m_owner.SetSnapInfo(m_snappoint); //给出绘制信息 //UnitPoint mousepoint; if (m_snappoint != null) { mousepoint = m_snappoint.SnapPoint; } else { mousepoint = GetMousePoint(); } if (m_newObject != null) //如果不为空则重画* { //MessageBox.Show(m_newObject.ToString()); //Console.WriteLine(m_newObject.ToString()); Rectangle invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, m_newObject.GetBoundingRect(m_canvaswrapper))); invalidaterect.Inflate(2, 2); RepaintStatic(invalidaterect); m_newObject.OnMouseMove(m_canvaswrapper, mousepoint); RepaintObject(m_newObject); } if (m_snappoint != null) //如果不为空则重画 { RepaintSnappoint(m_snappoint); } if (m_moveHelper.HandleMouseMoveForMove(mousepoint)) //重绘 { Refresh(); //Invalidate(); } RectangleF rNoderect = m_nodeMoveHelper.HandleMouseMoveForNode(mousepoint); //坐标获取 if (rNoderect != RectangleF.Empty) { Rectangle invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, rNoderect)); //坐标转换 RepaintStatic(invalidaterect); //重绘 CanvasWrapper dc = new CanvasWrapper(this, Graphics.FromHwnd(Handle), ClientRectangle); dc.Graphics.Clip = new Region(ClientRectangle); //m_nodeMoveHelper.DrawOriginalObjects(dc, rNoderect); m_nodeMoveHelper.DrawObjects(dc, rNoderect); if (m_snappoint != null) { RepaintSnappoint(m_snappoint); //重绘 } dc.Graphics.Dispose(); dc.Dispose(); } }
protected override void OnMouseMove(MouseEventArgs e) { base.OnMouseMove(e); if (m_selection != null) { Graphics dc = Graphics.FromHwnd(Handle); m_selection.SetMousePoint(dc, new PointF(e.X, e.Y)); dc.Dispose(); return; } if (m_commandType == eCommandType.pan && (e.Button == MouseButtons.Left || e.Button == MouseButtons.Middle)) { m_dragOffset.X = -(m_mousedownPoint.X - e.X); m_dragOffset.Y = -(m_mousedownPoint.Y - e.Y); m_lastCenterPoint = CenterPointUnit(); DoInvalidate(true); } UnitPoint mousepoint; UnitPoint unitpoint = ToUnit(new PointF(e.X, e.Y)); if (m_commandType == eCommandType.draw || m_commandType == eCommandType.move || m_nodeMoveHelper.IsEmpty == false) { Rectangle invalidaterect = Rectangle.Empty; ISnapPoint newsnap = null; mousepoint = GetMousePoint(); if (RunningSnapsEnabled) { newsnap = m_model.SnapPoint(m_canvaswrapper, mousepoint, m_runningSnapTypes, null); } if (newsnap == null) { newsnap = m_model.GridLayer.SnapPoint(m_canvaswrapper, mousepoint, null); } if ((m_snappoint != null) && ((newsnap == null) || (newsnap.SnapPoint != m_snappoint.SnapPoint) || m_snappoint.GetType() != newsnap.GetType())) { invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, m_snappoint.BoundingRect)); invalidaterect.Inflate(2, 2); RepaintStatic(invalidaterect); // remove old snappoint m_snappoint = newsnap; } if (m_commandType == eCommandType.move) { Invalidate(invalidaterect); } if (m_snappoint == null) { m_snappoint = newsnap; } } m_owner.SetPositionInfo(unitpoint); m_owner.SetSnapInfo(m_snappoint); //UnitPoint mousepoint; if (m_snappoint != null) { mousepoint = m_snappoint.SnapPoint; } else { mousepoint = GetMousePoint(); } if (m_newObject != null) { Rectangle invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, m_newObject.GetBoundingRect(m_canvaswrapper))); invalidaterect.Inflate(2, 2); RepaintStatic(invalidaterect); m_newObject.OnMouseMove(m_canvaswrapper, mousepoint); RepaintObject(m_newObject); } if (m_snappoint != null) { RepaintSnappoint(m_snappoint); } if (m_moveHelper.HandleMouseMoveForMove(mousepoint)) { Refresh(); //Invalidate(); } RectangleF rNoderect = m_nodeMoveHelper.HandleMouseMoveForNode(mousepoint); if (rNoderect != RectangleF.Empty) { Rectangle invalidaterect = ScreenUtils.ConvertRect(ScreenUtils.ToScreenNormalized(m_canvaswrapper, rNoderect)); RepaintStatic(invalidaterect); CanvasWrapper dc = new CanvasWrapper(this, Graphics.FromHwnd(Handle), ClientRectangle); dc.Graphics.Clip = new Region(ClientRectangle); //m_nodeMoveHelper.DrawOriginalObjects(dc, rNoderect); m_nodeMoveHelper.DrawObjects(dc, rNoderect); if (m_snappoint != null) { RepaintSnappoint(m_snappoint); } dc.Graphics.Dispose(); dc.Dispose(); } }