void mPanel_MouseMove(object sender, MouseEventArgs e) { ISnapPoint newsnap = null; Point point = this.PointToClient(Control.MousePosition); RgPoint mousepoint = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(point.X, point.Y)); //获取捕捉点 if (RunningSnapsEnabled) { newsnap = (mMap as Map).SnapPoint(mousepoint, m_runningSnapTypes, null); } //if (newsnap == null) // newsnap = mMap.GridLayer.SnapPoint(m_canvaswrapper, mousepoint, null); if ((m_snappoint != null) && ((newsnap == null) || (newsnap.SnapPoint != m_snappoint.SnapPoint) || m_snappoint.GetType() != newsnap.GetType())) { PointF pt1 = mScreenDisplay.DisplayTransformation.ToScreen(m_snappoint.SnapPoint); Rectangle invalidaterect = new Rectangle((int)pt1.X - 2, (int)pt1.Y - 2, 4, 4); invalidaterect.Inflate(2, 2); //注意查看 mScreenDisplay.RepaintStatic(invalidaterect); // remove old snappoint m_snappoint = newsnap; } if (m_snappoint == null) { m_snappoint = newsnap; } if (m_snappoint != null) { RepaintSnappoint(m_snappoint); } if (CurrentTool != null) { CurrentTool.OnMouseMove(e.X, e.Y); } RgPoint pt = mScreenDisplay.DisplayTransformation.ToUnit(new PointF(e.X, e.Y)); }
/// <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(); } }
public void SetSnapInfo(ISnapPoint snap) { m_snapHint = string.Empty; if (snap != null) { m_snapHint = string.Format("Snap@{0}, {1}", snap.SnapPoint.PosAsString(), snap.GetType()); } m_snapInfoLabel.Text = m_snapHint; }
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(); } }
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 (moving) //如果有选中的区域正在移动 { Invalidate(); mr.moving(e.X - lastX, e.Y - lastY); lastX = e.X; lastY = e.Y; } if (ispaste) //如果有选中的区域正在移动 { Invalidate(); pr.moving(e.X - lastX, e.Y - lastY); lastX = e.X; lastY = e.Y; } UnitPoint mousepoint; 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; } } ////////////////////////////////////////////////////////////////////////// //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(); * } */ }
public void SetSnapInfo(ISnapPoint snap) { m_snapHint = string.Empty; if (snap != null) m_snapHint = string.Format("Snap@{0}, {1}", snap.SnapPoint.PosAsString(), snap.GetType()); m_snapInfoLabel.Text = m_snapHint; }