private bool ValidateMarginOrPaddingLine(SnapLine snapLine, Rectangle dragBounds) { Rectangle rectangle = (Rectangle)this.snapLineToBounds[snapLine]; if (snapLine.IsVertical) { if (rectangle.Top >= dragBounds.Top) { if ((dragBounds.Top + dragBounds.Height) < rectangle.Top) { return(false); } } else if ((rectangle.Top + rectangle.Height) < dragBounds.Top) { return(false); } } else if (rectangle.Left < dragBounds.Left) { if ((rectangle.Left + rectangle.Width) < dragBounds.Left) { return(false); } } else if ((dragBounds.Left + dragBounds.Width) < rectangle.Left) { return(false); } return(true); }
public static bool ShouldSnap(SnapLine line1, SnapLine line2) { if (line1.SnapLineType != line2.SnapLineType) { return(false); } if ((line1.Filter == null) && (line2.Filter == null)) { return(true); } if ((line1.Filter == null) || (line2.Filter == null)) { return(false); } if (line1.Filter.Contains("Margin")) { if (((!line1.Filter.Equals("Margin.Right") || (!line2.Filter.Equals("Margin.Left") && !line2.Filter.Equals("Padding.Right"))) && (!line1.Filter.Equals("Margin.Left") || (!line2.Filter.Equals("Margin.Right") && !line2.Filter.Equals("Padding.Left")))) && (((!line1.Filter.Equals("Margin.Top") || (!line2.Filter.Equals("Margin.Bottom") && !line2.Filter.Equals("Padding.Top"))) && (!line1.Filter.Equals("Margin.Bottom") || !line2.Filter.Equals("Margin.Top"))) && !line2.Filter.Equals("Padding.Bottom"))) { return(false); } return(true); } if (line1.Filter.Contains("Padding")) { if (((!line1.Filter.Equals("Padding.Left") || !line2.Filter.Equals("Margin.Left")) && (!line1.Filter.Equals("Padding.Right") || !line2.Filter.Equals("Margin.Right"))) && ((!line1.Filter.Equals("Padding.Top") || !line2.Filter.Equals("Margin.Top")) && (!line1.Filter.Equals("Padding.Bottom") || !line2.Filter.Equals("Margin.Bottom")))) { return(false); } return(true); } return(line1.Filter.Equals(line2.Filter)); }
public static bool ShouldSnap(SnapLine line1, SnapLine line2) { if (line1.SnapLineType != line2.SnapLineType) { return false; } if ((line1.Filter == null) && (line2.Filter == null)) { return true; } if ((line1.Filter == null) || (line2.Filter == null)) { return false; } if (line1.Filter.Contains("Margin")) { if (((!line1.Filter.Equals("Margin.Right") || (!line2.Filter.Equals("Margin.Left") && !line2.Filter.Equals("Padding.Right"))) && (!line1.Filter.Equals("Margin.Left") || (!line2.Filter.Equals("Margin.Right") && !line2.Filter.Equals("Padding.Left")))) && (((!line1.Filter.Equals("Margin.Top") || (!line2.Filter.Equals("Margin.Bottom") && !line2.Filter.Equals("Padding.Top"))) && (!line1.Filter.Equals("Margin.Bottom") || !line2.Filter.Equals("Margin.Top"))) && !line2.Filter.Equals("Padding.Bottom"))) { return false; } return true; } if (line1.Filter.Contains("Padding")) { if (((!line1.Filter.Equals("Padding.Left") || !line2.Filter.Equals("Margin.Left")) && (!line1.Filter.Equals("Padding.Right") || !line2.Filter.Equals("Margin.Right"))) && ((!line1.Filter.Equals("Padding.Top") || !line2.Filter.Equals("Margin.Top")) && (!line1.Filter.Equals("Padding.Bottom") || !line2.Filter.Equals("Margin.Bottom")))) { return false; } return true; } return line1.Filter.Equals(line2.Filter); }
private static bool IsMarginOrPaddingSnapLine(SnapLine snapLine) { if (snapLine.Filter == null) { return(false); } if (!snapLine.Filter.StartsWith("Margin")) { return(snapLine.Filter.StartsWith("Padding")); } return(true); }
/// <summary> /// Builds up an array of snaplines used during resize to adjust/snap the controls bounds. /// </summary> private SnapLine[] GenerateSnapLines(SelectionRules rules, Point loc) { ArrayList lines = new ArrayList(2); //the four margins and edges of our control if ((rules & SelectionRules.BottomSizeable) != 0) { lines.Add(new SnapLine(SnapLineType.Bottom, loc.Y - 1)); if (_primaryControl != null) { lines.Add(new SnapLine(SnapLineType.Horizontal, loc.Y + _primaryControl.Margin.Bottom, SnapLine.MarginBottom, SnapLinePriority.Always)); } } else if ((rules & SelectionRules.TopSizeable) != 0) { lines.Add(new SnapLine(SnapLineType.Top, loc.Y)); if (_primaryControl != null) { lines.Add(new SnapLine(SnapLineType.Horizontal, loc.Y - _primaryControl.Margin.Top, SnapLine.MarginTop, SnapLinePriority.Always)); } } if ((rules & SelectionRules.RightSizeable) != 0) { lines.Add(new SnapLine(SnapLineType.Right, loc.X - 1)); if (_primaryControl != null) { lines.Add(new SnapLine(SnapLineType.Vertical, loc.X + _primaryControl.Margin.Right, SnapLine.MarginRight, SnapLinePriority.Always)); } } else if ((rules & SelectionRules.LeftSizeable) != 0) { lines.Add(new SnapLine(SnapLineType.Left, loc.X)); if (_primaryControl != null) { lines.Add(new SnapLine(SnapLineType.Vertical, loc.X - _primaryControl.Margin.Left, SnapLine.MarginLeft, SnapLinePriority.Always)); } } SnapLine[] l = new SnapLine[lines.Count]; lines.CopyTo(l); return(l); }
private int BuildDistanceArray(ArrayList snapLines, ArrayList targetSnapLines, int[] distances, Rectangle dragBounds) { int num = 0x1111; int num2 = 0; for (int i = 0; i < snapLines.Count; i++) { SnapLine snapLine = (SnapLine)snapLines[i]; if (IsMarginOrPaddingSnapLine(snapLine) && !this.ValidateMarginOrPaddingLine(snapLine, dragBounds)) { distances[i] = 0x1111; } else { int num4 = 0x1111; for (int j = 0; j < targetSnapLines.Count; j++) { SnapLine line2 = (SnapLine)targetSnapLines[j]; if (SnapLine.ShouldSnap(snapLine, line2)) { int num6 = line2.Offset - snapLine.Offset; if (Math.Abs(num6) < Math.Abs(num4)) { num4 = num6; } } } distances[i] = num4; int priority = (int)((SnapLine)snapLines[i]).Priority; if ((Math.Abs(num4) < Math.Abs(num)) || ((Math.Abs(num4) == Math.Abs(num)) && (priority > num2))) { num = num4; if (priority != 4) { num2 = priority; } } } } return(num); }
private SnapLine[] GenerateSnapLines(SelectionRules rules, Point loc) { ArrayList list = new ArrayList(2); if ((rules & SelectionRules.BottomSizeable) != SelectionRules.None) { list.Add(new SnapLine(SnapLineType.Bottom, loc.Y - 1)); if (this.primaryControl != null) { list.Add(new SnapLine(SnapLineType.Horizontal, loc.Y + this.primaryControl.Margin.Bottom, "Margin.Bottom", SnapLinePriority.Always)); } } else if ((rules & SelectionRules.TopSizeable) != SelectionRules.None) { list.Add(new SnapLine(SnapLineType.Top, loc.Y)); if (this.primaryControl != null) { list.Add(new SnapLine(SnapLineType.Horizontal, loc.Y - this.primaryControl.Margin.Top, "Margin.Top", SnapLinePriority.Always)); } } if ((rules & SelectionRules.RightSizeable) != SelectionRules.None) { list.Add(new SnapLine(SnapLineType.Right, loc.X - 1)); if (this.primaryControl != null) { list.Add(new SnapLine(SnapLineType.Vertical, loc.X + this.primaryControl.Margin.Right, "Margin.Right", SnapLinePriority.Always)); } } else if ((rules & SelectionRules.LeftSizeable) != SelectionRules.None) { list.Add(new SnapLine(SnapLineType.Left, loc.X)); if (this.primaryControl != null) { list.Add(new SnapLine(SnapLineType.Vertical, loc.X - this.primaryControl.Margin.Left, "Margin.Left", SnapLinePriority.Always)); } } SnapLine[] array = new SnapLine[list.Count]; list.CopyTo(array); return(array); }
private SnapLine[] GenerateSnapLines(SelectionRules rules, Point loc) { ArrayList list = new ArrayList(2); if ((rules & SelectionRules.BottomSizeable) != SelectionRules.None) { list.Add(new SnapLine(SnapLineType.Bottom, loc.Y - 1)); if (this.primaryControl != null) { list.Add(new SnapLine(SnapLineType.Horizontal, loc.Y + this.primaryControl.Margin.Bottom, "Margin.Bottom", SnapLinePriority.Always)); } } else if ((rules & SelectionRules.TopSizeable) != SelectionRules.None) { list.Add(new SnapLine(SnapLineType.Top, loc.Y)); if (this.primaryControl != null) { list.Add(new SnapLine(SnapLineType.Horizontal, loc.Y - this.primaryControl.Margin.Top, "Margin.Top", SnapLinePriority.Always)); } } if ((rules & SelectionRules.RightSizeable) != SelectionRules.None) { list.Add(new SnapLine(SnapLineType.Right, loc.X - 1)); if (this.primaryControl != null) { list.Add(new SnapLine(SnapLineType.Vertical, loc.X + this.primaryControl.Margin.Right, "Margin.Right", SnapLinePriority.Always)); } } else if ((rules & SelectionRules.LeftSizeable) != SelectionRules.None) { list.Add(new SnapLine(SnapLineType.Left, loc.X)); if (this.primaryControl != null) { list.Add(new SnapLine(SnapLineType.Vertical, loc.X - this.primaryControl.Margin.Left, "Margin.Left", SnapLinePriority.Always)); } } SnapLine[] array = new SnapLine[list.Count]; list.CopyTo(array); return array; }
/// <summary> /// Returns true if SnapLine s1 should snap to SnapLine s2. /// </summary> public static bool ShouldSnap(SnapLine line1, SnapLine line2) { throw new NotImplementedException(SR.NotImplementedByDesign); }
private bool ValidateMarginOrPaddingLine(SnapLine snapLine, Rectangle dragBounds) { Rectangle rectangle = (Rectangle) this.snapLineToBounds[snapLine]; if (snapLine.IsVertical) { if (rectangle.Top >= dragBounds.Top) { if ((dragBounds.Top + dragBounds.Height) < rectangle.Top) { return false; } } else if ((rectangle.Top + rectangle.Height) < dragBounds.Top) { return false; } } else if (rectangle.Left < dragBounds.Left) { if ((rectangle.Left + rectangle.Width) < dragBounds.Left) { return false; } } else if ((dragBounds.Left + dragBounds.Width) < rectangle.Left) { return false; } return true; }
private void StoreSnapLine(SnapLine snapLine, Rectangle dragBounds) { Rectangle rectangle = (Rectangle) this.snapLineToBounds[snapLine]; Line line = null; LineType standard = LineType.Standard; if (IsMarginOrPaddingSnapLine(snapLine)) { standard = snapLine.Filter.StartsWith("Margin") ? LineType.Margin : LineType.Padding; } else if (snapLine.SnapLineType == SnapLineType.Baseline) { standard = LineType.Baseline; } if (snapLine.IsVertical) { line = new Line(snapLine.Offset, Math.Min(dragBounds.Top + ((this.snapPointY != 0x1111) ? this.snapPointY : 0), rectangle.Top), snapLine.Offset, Math.Max(dragBounds.Bottom + ((this.snapPointY != 0x1111) ? this.snapPointY : 0), rectangle.Bottom)) { LineType = standard }; CombineSnaplines(line, this.tempVertLines); } else { line = new Line(Math.Min(dragBounds.Left + ((this.snapPointX != 0x1111) ? this.snapPointX : 0), rectangle.Left), snapLine.Offset, Math.Max(dragBounds.Right + ((this.snapPointX != 0x1111) ? this.snapPointX : 0), rectangle.Right), snapLine.Offset) { LineType = standard }; CombineSnaplines(line, this.tempHorzLines); } if (IsMarginOrPaddingSnapLine(snapLine)) { string str; line.OriginalBounds = rectangle; if ((line.LineType == LineType.Padding) && ((str = snapLine.Filter) != null)) { if (!(str == "Padding.Right")) { if (!(str == "Padding.Left")) { if (!(str == "Padding.Top")) { if (str == "Padding.Bottom") { line.PaddingLineType = PaddingLineType.PaddingBottom; } return; } line.PaddingLineType = PaddingLineType.PaddingTop; return; } } else { line.PaddingLineType = PaddingLineType.PaddingRight; return; } line.PaddingLineType = PaddingLineType.PaddingLeft; } } }
internal Point OnMouseMove(Control targetControl, SnapLine[] snapLines, ref bool didSnap, bool shouldSnapHorizontally) { Rectangle dragBounds = new Rectangle(this.behaviorService.ControlToAdornerWindow(targetControl), targetControl.Size); didSnap = false; return this.OnMouseMove(dragBounds, snapLines, ref didSnap, shouldSnapHorizontally); }
internal Point OnMouseMove(Rectangle dragBounds, SnapLine[] snapLines, ref bool didSnap, bool shouldSnapHorizontally) { if ((snapLines == null) || (snapLines.Length == 0)) { return Point.Empty; } this.targetHorizontalSnapLines.Clear(); this.targetVerticalSnapLines.Clear(); foreach (SnapLine line in snapLines) { if (line.IsHorizontal) { this.targetHorizontalSnapLines.Add(line); } else { this.targetVerticalSnapLines.Add(line); } } return this.OnMouseMove(dragBounds, false, ref didSnap, shouldSnapHorizontally); }
internal Point OnMouseMove(Rectangle dragBounds, SnapLine[] snapLines) { bool didSnap = false; return this.OnMouseMove(dragBounds, snapLines, ref didSnap, true); }
private static bool IsMarginOrPaddingSnapLine(SnapLine snapLine) { if (snapLine.Filter == null) { return false; } if (!snapLine.Filter.StartsWith("Margin")) { return snapLine.Filter.StartsWith("Padding"); } return true; }
private void StoreSnapLine(SnapLine snapLine, Rectangle dragBounds) { Rectangle rectangle = (Rectangle)this.snapLineToBounds[snapLine]; Line line = null; LineType standard = LineType.Standard; if (IsMarginOrPaddingSnapLine(snapLine)) { standard = snapLine.Filter.StartsWith("Margin") ? LineType.Margin : LineType.Padding; } else if (snapLine.SnapLineType == SnapLineType.Baseline) { standard = LineType.Baseline; } if (snapLine.IsVertical) { line = new Line(snapLine.Offset, Math.Min(dragBounds.Top + ((this.snapPointY != 0x1111) ? this.snapPointY : 0), rectangle.Top), snapLine.Offset, Math.Max(dragBounds.Bottom + ((this.snapPointY != 0x1111) ? this.snapPointY : 0), rectangle.Bottom)) { LineType = standard }; CombineSnaplines(line, this.tempVertLines); } else { line = new Line(Math.Min(dragBounds.Left + ((this.snapPointX != 0x1111) ? this.snapPointX : 0), rectangle.Left), snapLine.Offset, Math.Max(dragBounds.Right + ((this.snapPointX != 0x1111) ? this.snapPointX : 0), rectangle.Right), snapLine.Offset) { LineType = standard }; CombineSnaplines(line, this.tempHorzLines); } if (IsMarginOrPaddingSnapLine(snapLine)) { string str; line.OriginalBounds = rectangle; if ((line.LineType == LineType.Padding) && ((str = snapLine.Filter) != null)) { if (!(str == "Padding.Right")) { if (!(str == "Padding.Left")) { if (!(str == "Padding.Top")) { if (str == "Padding.Bottom") { line.PaddingLineType = PaddingLineType.PaddingBottom; } return; } line.PaddingLineType = PaddingLineType.PaddingTop; return; } } else { line.PaddingLineType = PaddingLineType.PaddingRight; return; } line.PaddingLineType = PaddingLineType.PaddingLeft; } } }