/// <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; }