public void ParkObstacle(SnapObstacle obstacle, SnapObstacle snappedTo, HorizontalSnapEdge hEdge, VerticalSnapEdge vEdge) { SnapDescription sd = new SnapDescription(snappedTo, hEdge, vEdge, obstacle.SnapDistance, obstacle.SnapDistance); this.obstacles[obstacle] = sd; ParkObstacle(obstacle, sd); }
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)); }
public SnapDescription(SnapObstacle snappedTo, HorizontalSnapEdge horizontalEdge, VerticalSnapEdge verticalEdge, int xOffset, int yOffset) { Validate.IsNotNull <SnapObstacle>(snappedTo, "snappedTo"); this.snappedTo = snappedTo; this.horizontalEdge = horizontalEdge; this.verticalEdge = verticalEdge; this.xOffset = xOffset; this.yOffset = yOffset; }
public void ParkObstacle(SnapObstacle obstacle, SnapObstacle snappedTo, HorizontalSnapEdge hEdge, VerticalSnapEdge vEdge) { base.VerifyAccess(); obstacle.VerifyAccess(); snappedTo.VerifyAccess(); SnapDescription snapDescription = new SnapDescription(snappedTo, hEdge, vEdge, obstacle.SnapDistance, obstacle.SnapDistance); this.obstacles[obstacle] = snapDescription; ParkObstacle(obstacle, snapDescription); }
private void LoadSnapObstacleData(ISimpleCollection <string, string> loadFrom, SnapObstacle so) { string prefix = so.Name + "."; SnapDescription sd; string isSnappedString = loadFrom.Get(prefix + isSnappedValueName); bool isSnapped = bool.Parse(isSnappedString); if (isSnapped) { string snappedToString = loadFrom.Get(prefix + snappedToValueName); SnapObstacle snappedTo = FindObstacle(snappedToString); string horizontalEdgeString = loadFrom.Get(prefix + horizontalEdgeValueName); HorizontalSnapEdge horizontalEdge = (HorizontalSnapEdge)Enum.Parse(typeof(HorizontalSnapEdge), horizontalEdgeString, true); string verticalEdgeString = loadFrom.Get(prefix + verticalEdgeValueName); VerticalSnapEdge verticalEdge = (VerticalSnapEdge)Enum.Parse(typeof(VerticalSnapEdge), verticalEdgeString, true); string xOffsetString = loadFrom.Get(prefix + xOffsetValueName); int xOffset = int.Parse(xOffsetString, CultureInfo.InvariantCulture); string yOffsetString = loadFrom.Get(prefix + yOffsetValueName); int yOffset = int.Parse(yOffsetString, CultureInfo.InvariantCulture); sd = new SnapDescription(snappedTo, horizontalEdge, verticalEdge, xOffset, yOffset); } else { sd = null; } this.obstacles[so] = sd; string leftString = loadFrom.Get(prefix + leftValueName); int left = int.Parse(leftString, CultureInfo.InvariantCulture); string topString = loadFrom.Get(prefix + topValueName); int top = int.Parse(topString, CultureInfo.InvariantCulture); string widthString = loadFrom.Get(prefix + widthValueName); int width = int.Parse(widthString, CultureInfo.InvariantCulture); string heightString = loadFrom.Get(prefix + heightValueName); int height = int.Parse(heightString, CultureInfo.InvariantCulture); Rectangle newBounds = new Rectangle(left, top, width, height); so.RequestBoundsChange(newBounds); if (sd != null) { ParkObstacle(so, sd); } }
public SnapDescription( SnapObstacle snappedTo, HorizontalSnapEdge horizontalEdge, VerticalSnapEdge verticalEdge, int xOffset, int yOffset) { if (snappedTo == null) { throw new ArgumentNullException("snappedTo"); } this.snappedTo = snappedTo; this.horizontalEdge = horizontalEdge; this.verticalEdge = verticalEdge; this.xOffset = xOffset; this.yOffset = yOffset; }
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); }
private SnapDescription DetermineNewSnapDescription( SnapObstacle avoider, Point newLocation, SnapObstacle avoidee, SnapDescription currentSnapDescription) { int ourSnapProximity; if (currentSnapDescription != null && (currentSnapDescription.HorizontalEdge != HorizontalSnapEdge.Neither || currentSnapDescription.VerticalEdge != VerticalSnapEdge.Neither)) { // the avoider is already snapped to the avoidee -- make it more difficult to un-snap ourSnapProximity = avoidee.SnapProximity * 2; } else { ourSnapProximity = avoidee.SnapProximity; } Rectangle avoiderRect = avoider.Bounds; avoiderRect.Location = newLocation; Rectangle avoideeRect = avoidee.Bounds; // Are the vertical edges close enough for snapping? bool vertProximity = AreEdgesClose(avoiderRect.Top, avoiderRect.Bottom, avoideeRect.Top, avoideeRect.Bottom); // Are the horizontal edges close enough for snapping? bool horizProximity = AreEdgesClose(avoiderRect.Left, avoiderRect.Right, avoideeRect.Left, avoideeRect.Right); // Compute distances from pertinent edges // (e.g. if SnapRegion.Interior, figure out distance from avoider's right edge to avoidee's right edge, // if SnapRegion.Exterior, figure out distance from avoider's right edge to avoidee's left edge) int leftDistance; int rightDistance; int topDistance; int bottomDistance; switch (avoidee.SnapRegion) { case SnapRegion.Interior: leftDistance = Math.Abs(avoiderRect.Left - avoideeRect.Left); rightDistance = Math.Abs(avoiderRect.Right - avoideeRect.Right); topDistance = Math.Abs(avoiderRect.Top - avoideeRect.Top); bottomDistance = Math.Abs(avoiderRect.Bottom - avoideeRect.Bottom); break; case SnapRegion.Exterior: leftDistance = Math.Abs(avoiderRect.Left - avoideeRect.Right); rightDistance = Math.Abs(avoiderRect.Right - avoideeRect.Left); topDistance = Math.Abs(avoiderRect.Top - avoideeRect.Bottom); bottomDistance = Math.Abs(avoiderRect.Bottom - avoideeRect.Top); break; default: throw new InvalidEnumArgumentException("avoidee.SnapRegion"); } bool leftClose = (leftDistance < ourSnapProximity); bool rightClose = (rightDistance < ourSnapProximity); bool topClose = (topDistance < ourSnapProximity); bool bottomClose = (bottomDistance < ourSnapProximity); VerticalSnapEdge vEdge = VerticalSnapEdge.Neither; if (vertProximity) { if ((leftClose && avoidee.SnapRegion == SnapRegion.Exterior) || (rightClose && avoidee.SnapRegion == SnapRegion.Interior)) { vEdge = VerticalSnapEdge.Right; } else if ((rightClose && avoidee.SnapRegion == SnapRegion.Exterior) || (leftClose && avoidee.SnapRegion == SnapRegion.Interior)) { vEdge = VerticalSnapEdge.Left; } } HorizontalSnapEdge hEdge = HorizontalSnapEdge.Neither; if (horizProximity) { if ((topClose && avoidee.SnapRegion == SnapRegion.Exterior) || (bottomClose && avoidee.SnapRegion == SnapRegion.Interior)) { hEdge = HorizontalSnapEdge.Bottom; } else if ((bottomClose && avoidee.SnapRegion == SnapRegion.Exterior) || (topClose && avoidee.SnapRegion == SnapRegion.Interior)) { hEdge = HorizontalSnapEdge.Top; } } SnapDescription sd; if (hEdge != HorizontalSnapEdge.Neither || vEdge != VerticalSnapEdge.Neither) { int xOffset = avoider.SnapDistance; int yOffset = avoider.SnapDistance; if (hEdge == HorizontalSnapEdge.Neither) { if (avoidee.SnapRegion == SnapRegion.Interior) { yOffset = avoiderRect.Top - avoideeRect.Top; hEdge = HorizontalSnapEdge.Top; } } if (vEdge == VerticalSnapEdge.Neither) { if (avoidee.SnapRegion == SnapRegion.Interior) { xOffset = avoiderRect.Left - avoideeRect.Left; vEdge = VerticalSnapEdge.Left; } } sd = new SnapDescription(avoidee, hEdge, vEdge, xOffset, yOffset); } else { sd = null; } return(sd); }
public void ParkObstacle(ISnapObstacleHost obstacle, ISnapObstacleHost snappedTo, HorizontalSnapEdge hEdge, VerticalSnapEdge vEdge) { ParkObstacle(obstacle.SnapObstacle, snappedTo.SnapObstacle, hEdge, vEdge); }
public void ParkObstacle(ISnapObstacleHost obstacle, ISnapObstacleHost snappedTo, HorizontalSnapEdge hEdge, VerticalSnapEdge vEdge) { base.VerifyAccess(); obstacle.VerifyAccess(); snappedTo.VerifyAccess(); this.ParkObstacle(obstacle.SnapObstacle, snappedTo.SnapObstacle, hEdge, vEdge); }
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 SnapDescription(SnapObstacle snappedTo, HorizontalSnapEdge horizontalEdge, VerticalSnapEdge verticalEdge, PointInt32 offset) : this(snappedTo, horizontalEdge, verticalEdge, offset.X, offset.Y) { }