Ejemplo n.º 1
0
        /// <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);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Snaps the lower left corner of the specified rectangle to the nearest bounds.
        /// </summary>
        /// <param name="rect">The rectangle.</param>
        /// <returns>New position.</returns>
        public Point SnapBottomLeftCorner(Rect rect)
        {
            Point point = rect.BottomLeft();

            if (SnapinEnabled)
            {
                Distance minDistance = new Distance();
                foreach (var bound in SnapinBounds)
                {
                    Distance distance = new Distance()
                    {
                        X = DistanceBetweenLeftEdgeAndRectangle(rect, bound),
                        Y = DistanceBetweenBottomEdgeAndRectangle(rect, bound)
                    };

                    minDistance = Distance.Min(distance, minDistance);
                }

                point = point.Add(minDistance);
            }

            return point;
        }
Ejemplo n.º 3
0
        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;
        }