コード例 #1
0
        /// <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);
        }
コード例 #2
0
ファイル: Canvas.cs プロジェクト: xiaoxiongnpu/Fake-Visio
        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);
        }