示例#1
0
        private void HoveringMoving(MouseEventArgs e)
        {
            Point currentLocation = e.Location;

            Element.Element currentHovered = null;

            #region 节点Hover检查
            for (int idx = this._nodes.Count - 1; idx >= 0; idx--)
            {
                NodeElement node = this._nodes[idx];
                if (node.CaughtBy(currentLocation))
                {
                    currentHovered = node;
                    break;
                }
                else
                {
                    AnchorElement anchor = node.AnchorCaughtBy(currentLocation);
                    if (anchor != null)
                    {
                        currentHovered = anchor;
                        break;
                    }
                }
            }
            #endregion

            #region 连接Hover检查
            for (int idx = this._connections.Count - 1; idx >= 0; idx--)
            {
                ConnectionElement conn = this._connections[idx];
                if (conn.CaughtBy(currentLocation))
                {
                    currentHovered = conn;
                    break;
                }
            }
            #endregion

            #region 更新Hovered元素
            if (currentHovered != this._theHovered)
            {
                if (currentHovered != null)
                {
                    currentHovered.Hovered = true;
                }
                if (this._theHovered != null)
                {
                    this._theHovered.Hovered = false;
                }
                this._theHovered = currentHovered;
            }
            #endregion
        }
示例#2
0
        private void LeftMouseDown(MouseEventArgs e)
        {
            Point currentLocation = e.Location;

            this._clickLocation = currentLocation;
            Element.Element currentSelected = null;

            #region 节点Select检查
            for (int idx = this._nodes.Count - 1; idx >= 0; idx--)
            {
                NodeElement node = this._nodes[idx];
                if (node.CaughtBy(currentLocation))
                {
                    currentSelected = node;
                    break;
                }
                else
                {
                    AnchorElement anchor = node.AnchorCaughtBy(currentLocation);
                    if (anchor != null)
                    {
                        currentSelected = anchor;
                        break;
                    }
                }
            }
            #endregion

            #region 连接Select检查
            for (int idx = this._connections.Count - 1; idx >= 0; idx--)
            {
                ConnectionElement conn = this._connections[idx];
                if (conn.CaughtBy(currentLocation))
                {
                    currentSelected = conn;
                    break;
                }
            }
            #endregion

            #region 更新当前被选择的元素
            if (currentSelected != this._theSelected)
            {
                if (currentSelected != null)
                {
                    currentSelected.Selected = true;
                }
                if (this._theSelected != null)
                {
                    this._theSelected.Selected = false;
                }
                this._theSelected = currentSelected;
            }
            #endregion

            this._dragging = true;
            // 若为锚点,则开始进行连接行为
            if (!(this._theSelected is AnchorElement from))
            {
                return;
            }
            AnchorElement     tempTo   = ElementFactory.AnchorElement(currentLocation.X, currentLocation.Y, null, this);
            ConnectionElement tempConn = ElementFactory.ConnectionElement(@from, tempTo, this);
            this._tempConnection = tempConn;
            @from.Selected       = false;
            tempTo.Selected      = true;
            this._theSelected    = tempTo;
        }