Example #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);
        }
Example #2
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;
        }
Example #3
0
        /// <summary>
        /// Resizes the window by the bottom right corner of the window.
        /// </summary>
        /// <param name="dx">Increment by X-coordinate.</param>
        /// <param name="dy">Increment by Y-coordinate.</param>
        private void ResizeBottomRight(double dx, double dy)
        {
            Rect newBounds = new Rect(initialPosition, initialSize.Add(dx, dy));
            Point point = element.SnapinController.SnapBottomRightCorner(newBounds);

            // If only one coordinate was changed - restore the other after snap in
            if (dx == 0)
                point.X = newBounds.BottomRight().X;

            if (dy == 0)
                point.Y = newBounds.BottomRight().Y;

            point = point.EnsureInBounds(bounds);

            element.Width = point.X - initialPosition.X;
            element.Height = point.Y - initialPosition.Y;
        }
Example #4
0
        /// <summary>
        /// Snaps the bottom right corner of the specified rectangle to the nearest bounds.
        /// </summary>
        /// <param name="rect">The rectangle.</param>
        /// <returns>New position.</returns>
        public Point SnapBottomRightCorner(Rect rect)
        {
            Point point = rect.BottomRight();

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

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

                point = point.Add(minDistance);
            }

            return point;
        }