/// <summary> /// Converts shape of <see cref="Rect"/> to a List of <see cref="Point"/> /// </summary> public static List <Point> ToPoints(this Rect rect) { var points = new List <Point>(); points.Add(rect.TopLeft()); points.Add(rect.TopRight()); points.Add(rect.BottomRight()); points.Add(rect.BottomLeft()); //points.Add(rect.TopLeft()); return(points); }
void Page_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) { if(_dragged != null) { //Set correct Z-index Rect r = new Rect(Canvas.GetLeft(_dragged), Canvas.GetTop(_dragged), _dragged.Width, _dragged.Height); var t = from uc in _objects where uc != _dragged && ( uc.ContainsPoint(r.TopLeft()) || uc.ContainsPoint(r.TopRight()) || uc.ContainsPoint(r.BottomLeft()) || uc.ContainsPoint(r.BottomRight())) orderby Canvas.GetZIndex(uc) descending select uc; int z; if(t.Count() > 0) z = Canvas.GetZIndex(t.FirstOrDefault()) + 1; else z = 0; Canvas.SetZIndex(_dragged, z); } _dragged = null; }
/// <summary> /// Snaps the upper right corner of the specified rectangle to the nearest bounds. /// </summary> /// <param name="rect">The rectangle.</param> /// <returns>New position.</returns> public Point SnapTopRightCorner(Rect rect) { Point point = rect.TopRight(); if (SnapinEnabled) { Distance minDistance = new Distance(); foreach (var bound in SnapinBounds) { Distance distance = new Distance() { X = DistanceBetweenRightEdgeAndRectangle(rect, bound), Y = DistanceBetweenTopEdgeAndRectangle(rect, bound) }; minDistance = Distance.Min(distance, minDistance); } point = point.Add(minDistance); } return point; }