Exemple #1
0
        private static PointInt32 AdjustNewLocation(SnapObstacle obstacle, PointInt32 newLocation, SnapDescription snapDescription)
        {
            obstacle.VerifyAccess();
            if ((snapDescription == null) || ((snapDescription.HorizontalEdge == HorizontalSnapEdge.Neither) && (snapDescription.VerticalEdge == VerticalSnapEdge.Neither)))
            {
                return(obstacle.Bounds.Location);
            }
            RectInt32          num            = new RectInt32(newLocation, obstacle.Bounds.Size);
            RectInt32          bounds         = snapDescription.SnappedTo.Bounds;
            HorizontalSnapEdge horizontalEdge = snapDescription.HorizontalEdge;
            VerticalSnapEdge   verticalEdge   = snapDescription.VerticalEdge;
            SnapRegion         snapRegion     = snapDescription.SnappedTo.SnapRegion;
            int num3 = 0;

            if ((horizontalEdge == HorizontalSnapEdge.Top) && (snapRegion == SnapRegion.Exterior))
            {
                int num7 = bounds.Top - snapDescription.YOffset;
                num3 = num.Bottom - num7;
            }
            else if ((horizontalEdge == HorizontalSnapEdge.Bottom) && (snapRegion == SnapRegion.Exterior))
            {
                int num8 = bounds.Bottom + snapDescription.YOffset;
                num3 = num.Top - num8;
            }
            else if ((horizontalEdge == HorizontalSnapEdge.Top) && (snapRegion == SnapRegion.Interior))
            {
                int num9 = Math.Min(bounds.Bottom, bounds.Top + snapDescription.YOffset);
                num3 = num.Top - num9;
            }
            else if ((horizontalEdge == HorizontalSnapEdge.Bottom) && (snapRegion == SnapRegion.Interior))
            {
                int num10 = Math.Max(bounds.Top, bounds.Bottom - snapDescription.YOffset);
                num3 = num.Bottom - num10;
            }
            int num4 = 0;

            if ((verticalEdge == VerticalSnapEdge.Left) && (snapRegion == SnapRegion.Exterior))
            {
                int num11 = bounds.Left - snapDescription.XOffset;
                num4 = num.Right - num11;
            }
            else if ((verticalEdge == VerticalSnapEdge.Right) && (snapRegion == SnapRegion.Exterior))
            {
                int num12 = bounds.Right + snapDescription.XOffset;
                num4 = num.Left - num12;
            }
            else if ((verticalEdge == VerticalSnapEdge.Left) && (snapRegion == SnapRegion.Interior))
            {
                int num13 = Math.Min(bounds.Right, bounds.Left + snapDescription.XOffset);
                num4 = num.Left - num13;
            }
            else if ((verticalEdge == VerticalSnapEdge.Right) && (snapRegion == SnapRegion.Interior))
            {
                int num14 = Math.Max(bounds.Left, bounds.Right - snapDescription.XOffset);
                num4 = num.Right - num14;
            }
            return(new PointInt32(num.Left - num4, num.Top - num3));
        }
Exemple #2
0
 internal SnapObstacle(string name, Rectangle bounds, SnapRegion snapRegion, bool stickyEdges, int snapProximity, int snapDistance)
 {
     this.name = name;
     this.bounds = bounds;
     this.previousBounds = bounds;
     this.snapRegion = snapRegion;
     this.stickyEdges = stickyEdges;
     this.snapProximity = snapProximity;
     this.snapDistance = snapDistance;
     this.enabled = true;
     this.enableSave = true;
 }
Exemple #3
0
 internal SnapObstacle(string name, Rectangle bounds, SnapRegion snapRegion, bool stickyEdges, int snapProximity, int snapDistance)
 {
     this.name           = name;
     this.bounds         = bounds;
     this.previousBounds = bounds;
     this.snapRegion     = snapRegion;
     this.stickyEdges    = stickyEdges;
     this.snapProximity  = snapProximity;
     this.snapDistance   = snapDistance;
     this.enabled        = true;
     this.enableSave     = true;
 }
Exemple #4
0
        private static Point AdjustNewLocation(SnapObstacle obstacle, Point newLocation, SnapDescription snapDescription)
        {
            if (snapDescription == null ||
                (snapDescription.HorizontalEdge == HorizontalSnapEdge.Neither &&
                 snapDescription.VerticalEdge == VerticalSnapEdge.Neither))
            {
                return(obstacle.Bounds.Location);
            }

            Rectangle          obstacleRect  = new Rectangle(newLocation, obstacle.Bounds.Size);
            Rectangle          snappedToRect = snapDescription.SnappedTo.Bounds;
            HorizontalSnapEdge hEdge         = snapDescription.HorizontalEdge;
            VerticalSnapEdge   vEdge         = snapDescription.VerticalEdge;
            SnapRegion         region        = snapDescription.SnappedTo.SnapRegion;

            int deltaY = 0;

            if (hEdge == HorizontalSnapEdge.Top && region == SnapRegion.Exterior)
            {
                int newBottomEdge = snappedToRect.Top - snapDescription.YOffset;
                deltaY = obstacleRect.Bottom - newBottomEdge;
            }
            else if (hEdge == HorizontalSnapEdge.Bottom && region == SnapRegion.Exterior)
            {
                int newTopEdge = snappedToRect.Bottom + snapDescription.YOffset;
                deltaY = obstacleRect.Top - newTopEdge;
            }
            else if (hEdge == HorizontalSnapEdge.Top && region == SnapRegion.Interior)
            {
                int newTopEdge = Math.Min(snappedToRect.Bottom, snappedToRect.Top + snapDescription.YOffset);
                deltaY = obstacleRect.Top - newTopEdge;
            }
            else if (hEdge == HorizontalSnapEdge.Bottom && region == SnapRegion.Interior)
            {
                int newBottomEdge = Math.Max(snappedToRect.Top, snappedToRect.Bottom - snapDescription.YOffset);
                deltaY = obstacleRect.Bottom - newBottomEdge;
            }

            int deltaX = 0;

            if (vEdge == VerticalSnapEdge.Left && region == SnapRegion.Exterior)
            {
                int newRightEdge = snappedToRect.Left - snapDescription.XOffset;
                deltaX = obstacleRect.Right - newRightEdge;
            }
            else if (vEdge == VerticalSnapEdge.Right && region == SnapRegion.Exterior)
            {
                int newLeftEdge = snappedToRect.Right + snapDescription.XOffset;
                deltaX = obstacleRect.Left - newLeftEdge;
            }
            else if (vEdge == VerticalSnapEdge.Left && region == SnapRegion.Interior)
            {
                int newLeftEdge = Math.Min(snappedToRect.Right, snappedToRect.Left + snapDescription.XOffset);
                deltaX = obstacleRect.Left - newLeftEdge;
            }
            else if (vEdge == VerticalSnapEdge.Right && region == SnapRegion.Interior)
            {
                int newRightEdge = Math.Max(snappedToRect.Left, snappedToRect.Right - snapDescription.XOffset);
                deltaX = obstacleRect.Right - newRightEdge;
            }

            Point adjustedLocation = new Point(obstacleRect.Left - deltaX, obstacleRect.Top - deltaY);

            return(adjustedLocation);
        }
Exemple #5
0
 internal SnapObstacle(string name, Rectangle bounds, SnapRegion snapRegion, bool stickyEdges)
     : this(name, bounds, snapRegion, stickyEdges, DefaultSnapProximity, DefaultSnapDistance)
 {
 }
Exemple #6
0
        private SnapDescription DetermineNewSnapDescription(SnapObstacle avoider, PointInt32 newLocation, SnapObstacle avoidee, SnapDescription currentSnapDescription)
        {
            int  snapProximity;
            int  num4;
            int  num5;
            int  num6;
            int  num7;
            bool flag3;

            base.VerifyAccess();
            avoider.VerifyAccess();
            avoidee.VerifyAccess();
            if ((currentSnapDescription != null) && ((currentSnapDescription.HorizontalEdge != HorizontalSnapEdge.Neither) || (currentSnapDescription.VerticalEdge != VerticalSnapEdge.Neither)))
            {
                snapProximity = avoidee.SnapProximity * 2;
            }
            else
            {
                snapProximity = avoidee.SnapProximity;
            }
            RectInt32 bounds = avoider.Bounds;

            bounds.X = newLocation.X;
            bounds.Y = newLocation.Y;
            RectInt32  num3       = avoidee.Bounds;
            bool       flag       = AreEdgesClose(bounds.Top, bounds.Bottom, num3.Top, num3.Bottom);
            bool       flag2      = AreEdgesClose(bounds.Left, bounds.Right, num3.Left, num3.Right);
            SnapRegion snapRegion = avoidee.SnapRegion;

            if (snapRegion != SnapRegion.Interior)
            {
                if (snapRegion != SnapRegion.Exterior)
                {
                    throw ExceptionUtil.InvalidEnumArgumentException <SnapRegion>(avoidee.SnapRegion, "avoidee.SnapRegion");
                }
            }
            else
            {
                num4 = Math.Abs((int)(bounds.Left - num3.Left));
                num5 = Math.Abs((int)(bounds.Right - num3.Right));
                num6 = Math.Abs((int)(bounds.Top - num3.Top));
                num7 = Math.Abs((int)(bounds.Bottom - num3.Bottom));
                goto Label_0184;
            }
            num4 = Math.Abs((int)(bounds.Left - num3.Right));
            num5 = Math.Abs((int)(bounds.Right - num3.Left));
            num6 = Math.Abs((int)(bounds.Top - num3.Bottom));
            num7 = Math.Abs((int)(bounds.Bottom - num3.Top));
Label_0184:
            flag3 = num4 < snapProximity;
            bool             flag4   = num5 < snapProximity;
            bool             flag5   = num6 < snapProximity;
            bool             flag6   = num7 < snapProximity;
            VerticalSnapEdge neither = VerticalSnapEdge.Neither;

            if (flag)
            {
                if ((flag3 && (avoidee.SnapRegion == SnapRegion.Exterior)) || (flag4 && (avoidee.SnapRegion == SnapRegion.Interior)))
                {
                    neither = VerticalSnapEdge.Right;
                }
                else if ((flag4 && (avoidee.SnapRegion == SnapRegion.Exterior)) || (flag3 && (avoidee.SnapRegion == SnapRegion.Interior)))
                {
                    neither = VerticalSnapEdge.Left;
                }
            }
            HorizontalSnapEdge horizontalEdge = HorizontalSnapEdge.Neither;

            if (flag2)
            {
                if ((flag5 && (avoidee.SnapRegion == SnapRegion.Exterior)) || (flag6 && (avoidee.SnapRegion == SnapRegion.Interior)))
                {
                    horizontalEdge = HorizontalSnapEdge.Bottom;
                }
                else if ((flag6 && (avoidee.SnapRegion == SnapRegion.Exterior)) || (flag5 && (avoidee.SnapRegion == SnapRegion.Interior)))
                {
                    horizontalEdge = HorizontalSnapEdge.Top;
                }
            }
            if ((horizontalEdge != HorizontalSnapEdge.Neither) || (neither != VerticalSnapEdge.Neither))
            {
                int snapDistance = avoider.SnapDistance;
                int yOffset      = avoider.SnapDistance;
                if ((horizontalEdge == HorizontalSnapEdge.Neither) && (avoidee.SnapRegion == SnapRegion.Interior))
                {
                    yOffset        = bounds.Top - num3.Top;
                    horizontalEdge = HorizontalSnapEdge.Top;
                }
                if ((neither == VerticalSnapEdge.Neither) && (avoidee.SnapRegion == SnapRegion.Interior))
                {
                    snapDistance = bounds.Left - num3.Left;
                    neither      = VerticalSnapEdge.Left;
                }
                return(new SnapDescription(avoidee, horizontalEdge, neither, snapDistance, yOffset));
            }
            return(null);
        }
 public SnapObstacleController(string name, Rectangle bounds, SnapRegion snapRegion, bool stickyEdges, int snapProximity, int snapDistance)
     : base(name, bounds, snapRegion, stickyEdges, snapProximity, snapDistance)
 {
 }
 public SnapObstacleController(string name, Rectangle bounds, SnapRegion snapRegion, bool stickyEdges)
     : base(name, bounds, snapRegion, stickyEdges)
 {
 }
Exemple #9
0
 internal SnapObstacle(string name, Rectangle bounds, SnapRegion snapRegion, bool stickyEdges)
     : this(name, bounds, snapRegion, stickyEdges, DefaultSnapProximity, DefaultSnapDistance)
 {
 }
 public SnapObstacleController(string name, Rectangle bounds, SnapRegion snapRegion, bool stickyEdges, int snapProximity, int snapDistance)
     : base(name, bounds, snapRegion, stickyEdges, snapProximity, snapDistance)
 {
 }
 public SnapObstacleController(string name, Rectangle bounds, SnapRegion snapRegion, bool stickyEdges)
     : base(name, bounds, snapRegion, stickyEdges)
 {
 }
 public SnapObstacleController(string name, RectInt32 bounds, SnapRegion snapRegion, bool stickyEdges, int snapProximity, int snapDistance, ISnapObstaclePersist persistenceHandler) : base(name, bounds, snapRegion, stickyEdges, snapProximity, snapDistance, persistenceHandler)
 {
 }