Ejemplo n.º 1
0
        /// <summary>
        /// 创建调整网格线
        /// </summary>
        /// <param name="slotContaienr">当前插槽容器</param>
        private void CreateAdjustLine(SlotContainer slotContainer, Direction direction, bool autoAdjust)
        {
            canvas.CurrentGuideLine.ClearGuideLineList();

            Rectangle rectangle = Rectangle.Empty;
            rectangle.Location = canvas.ClientRectangle.Location - (Size)canvas.AutoScrollPosition;
            rectangle.Size = canvas.ClientSize;
            List<SlotContainer> list = regionManager.GetSlotContainerList(rectangle);            
            int leftX = -1;
            int rightX = -1;
            int topY = -1;
            int bottomY = -1;

            canvas.PaintCanvas = false;

            foreach(SlotContainer s in list)
            {
                if (s != slotContainer)
                {
                    // 插槽调整线
                    if (s.TextRectangle.Left < slotContainer.TextRectangle.Right &&
                        s.TextRectangle.Right > slotContainer.TextRectangle.Left)
                    {
                        if (s.TextRectangle.Bottom < slotContainer.TextRectangle.Top)
                        {
                            foreach (SlotGraphElement slot1 in s.GetOutSlotList())
                            {
                                foreach (SlotGraphElement slot2 in slotContainer.GetInSlotList())
                                {
                                    if (slot1.Location.X == slot2.Location.X)
                                    {
                                        canvas.CurrentGuideLine.AddGuideLine(new Point[] { slot1.Location, slot2.Location });
                                    }
                                }
                            }
                        }

                        if (s.TextRectangle.Top > slotContainer.TextRectangle.Bottom)
                        {
                            foreach (SlotGraphElement slot1 in s.GetInSlotList())
                            {
                                foreach (SlotGraphElement slot2 in slotContainer.GetOutSlotList())
                                {
                                    if (slot1.Location.X == slot2.Location.X)
                                    {
                                        canvas.CurrentGuideLine.AddGuideLine(new Point[] { slot1.Location, slot2.Location });
                                    }
                                }
                            }
                        }
                    }                   

                    // 显示边框调整线
                    switch (direction)
                    {
                        case Direction.Left:
                            {                                
                                if (slotContainer.TextRectangle.Left - s.TextRectangle.Left >= 0 &&
                                    slotContainer.TextRectangle.Left - s.TextRectangle.Left < moveAdjustWidth)
                                {
                                    canvas.CurrentGuideLine.AddGuideLine(new Point[]{ new Point(s.TextRectangle.Left, canvas.VisibleRectangle.Top), 
                                                                                      new Point(s.TextRectangle.Left, canvas.VisibleRectangle.Bottom)});   
                                    
                                    if (s.TextRectangle.Left < leftX || leftX == -1)
                                    {
                                        leftX = s.TextRectangle.Left;
                                    }
                                }

                                break;
                            }
                        case Direction.Right:
                            {
                                if (s.TextRectangle.Right - slotContainer.TextRectangle.Right >= 0 &&
                                    s.TextRectangle.Right - slotContainer.TextRectangle.Right < moveAdjustWidth)
                                {
                                    canvas.CurrentGuideLine.AddGuideLine(new Point[]{ new Point(s.TextRectangle.Right, canvas.VisibleRectangle.Top), 
                                                                                      new Point(s.TextRectangle.Right, canvas.VisibleRectangle.Bottom)});

                                    if (s.TextRectangle.Right > rightX || rightX == -1)
                                    {
                                        rightX = s.TextRectangle.Right;
                                    }
                                }

                                break;
                            }
                        case Direction.Up:
                            {
                                if (slotContainer.TextRectangle.Top - s.TextRectangle.Top >= 0 &&
                                    slotContainer.TextRectangle.Top - s.TextRectangle.Top < moveAdjustWidth)
                                {
                                    canvas.CurrentGuideLine.AddGuideLine(new Point[]{ new Point(canvas.VisibleRectangle.Left, s.TextRectangle.Top), 
                                                                                      new Point(canvas.VisibleRectangle.Right, s.TextRectangle.Top)});

                                    if (s.TextRectangle.Top < topY || topY == -1)
                                    {
                                        topY = s.TextRectangle.Top;
                                    }
                                }

                                break;
                            }
                        case Direction.Down:
                            {
                                if (s.TextRectangle.Bottom - slotContainer.TextRectangle.Bottom >= 0 &&
                                    s.TextRectangle.Bottom - slotContainer.TextRectangle.Bottom < moveAdjustWidth)
                                {
                                    canvas.CurrentGuideLine.AddGuideLine(new Point[]{ new Point(canvas.VisibleRectangle.Left, s.TextRectangle.Bottom), 
                                                                                      new Point(canvas.VisibleRectangle.Right, s.TextRectangle.Bottom)});

                                    if (s.TextRectangle.Bottom > bottomY || bottomY == -1)
                                    {
                                        bottomY = s.TextRectangle.Bottom;
                                    }
                                }

                                break;
                            }
                    }                                      
                }                
            }               
            
            if (autoAdjust) // 自动调整位置
            {
                bool requireAdjust = false;
                Size moveSize = Size.Empty;
                int lagPosition = -1;

                switch (direction)
                {
                    case Direction.Left:
                        {
                            if (leftX != -1)
                            {
                                moveSize.Width = leftX - slotContainer.TextRectangle.Left;
                                lagPosition = leftX;

                                if (moveSize.Width < moveLagOffset)
                                {
                                    requireAdjust = true;
                                }                                
                            }

                            break;
                        }
                    case Direction.Right:
                        {
                            if (rightX != -1)
                            {
                                moveSize.Width = rightX - slotContainer.TextRectangle.Right;
                                lagPosition = rightX;

                                if (moveSize.Width < moveLagOffset)
                                {
                                    requireAdjust = true;
                                }   
                            }

                            break;
                        }
                    case Direction.Up:
                        {
                            if (topY != -1)
                            {
                                moveSize.Height = topY - slotContainer.TextRectangle.Top;
                                lagPosition = topY;

                                if (moveSize.Height < moveLagOffset)
                                {
                                    requireAdjust = true;
                                }
                            }

                            break;
                        }
                    case Direction.Down:
                        {
                            if (bottomY != -1)
                            {
                                moveSize.Height = bottomY - slotContainer.TextRectangle.Bottom;
                                lagPosition = bottomY;

                                if (moveSize.Height < moveLagOffset)
                                {
                                    requireAdjust = true;
                                }   
                            }

                            break;
                        }
                    default:
                        {
                            break;
                        }
                }

                if (requireAdjust)
                {
                    slotContainer.Move(moveSize);

                    if (LagMove(direction, lagPosition)) // 移动延迟 
                    {
                        Cursor.Position += moveSize;     
                    }
                }
            }            

            canvas.PaintCanvas = true;
        }      
Ejemplo n.º 2
0
        /// <summary>
        /// 获取连出的插槽容器链表
        /// </summary>
        /// <param name="slotContainer">当前插槽容器</param>
        /// <returns>连出的插槽容器链表</returns>
        public List<SlotContainer> GetNextSlotContainers(SlotContainer slotContainer)
        {
            List<SlotContainer> list = new List<SlotContainer>();

            foreach(SlotGraphElement slot in slotContainer.GetOutSlotList())
            {
                if(slot.Binded && slot.BindingConnector.Line.OutSlotContainer != null
                    && !list.Contains(slot.BindingConnector.Line.OutSlotContainer))
                {
                    list.Add(slot.BindingConnector.Line.OutSlotContainer);
                }
            }

            return list;
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 检查插槽容器的所有连出的线是否有效
        /// </summary>
        /// <param name="slotContainer">插槽容器</param>
        private void CheckLineValid(DataManager dataManager, SlotContainer slotContainer)
        {
            int invalidLineCount = 0;
            List<ConnectorContainer> list = new List<ConnectorContainer>();

            foreach (SlotGraphElement slot in slotContainer.GetOutSlotList())
            {
                if (slot.Binded)
                {
                    object data = dataManager.GetData(slot.BindingConnector.Line);
                    if (data == null)
                    {
                        list.Add(slot.BindingConnector.Line);
                        invalidLineCount++;
                    }
                    else
                    {
                        slot.BindingConnector.Line.Invalid = false;
                    }
                }
            }

            if (invalidLineCount == 1) // 无效连接线数等于1
            {
                foreach (ConnectorContainer line in list)
                {
                    line.Invalid = false;
                    line.Text = "else";
                    line.ShowText = true;
                    line.AdjustText();
                }
            }
            else if (invalidLineCount > 1) // 无效连接线数大于1
            {
                foreach (ConnectorContainer line in list)
                {
                    line.Invalid = true;
                    line.Text = "×";
                    line.ShowText = true;
                    line.AdjustText();
                }
            }
            else
            {
                foreach (ConnectorContainer line in list)
                {
                    line.Invalid = false;
                    line.ShowText = false;
                }
            }
        }
Ejemplo n.º 4
0
        /// <summary>
        /// 获取连出的所有插槽容器的链表(辅助函数)
        /// </summary>
        /// <param name="slotContainer">当前插槽容器</param>
        /// <param name="list">当前搜索的所有插槽容器的链表</param>
        public void GetAllNextSlotContainers(SlotContainer slotContainer, List<SlotContainer> list)
        {
            if(!list.Contains(slotContainer)) // 避免出现死循环
            {
                list.Add(slotContainer);

                foreach (SlotGraphElement slot in slotContainer.GetOutSlotList())
                {
                    if (slot.Binded && slot.BindingConnector.Line.OutSlotContainer != null)
                    {
                        GetAllNextSlotContainers(slot.BindingConnector.Line.OutSlotContainer, list);
                    }
                }
            }
        }