コード例 #1
0
        /// <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);
            }
        }
コード例 #2
0
        /// <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);
            }
        }