Example #1
0
        /// <summary>
        /// Resizes the window by the top left corner of the window.
        /// </summary>
        /// <param name="dx">Increment by X-coordinate.</param>
        /// <param name="dy">Increment by Y-coordinate.</param>
        private void ResizeTopLeft(double dx, double dy)
        {
            Rect newBounds = new Rect(initialPosition.Add(dx, dy), initialSize);
            Point point = element.SnapinController.SnapTopLeftCorner(newBounds).EnsureInBounds(bounds);

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

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

            element.Position = point;

            Point lowerRight = initialPosition.Add(initialSize);
            element.Width = lowerRight.X - point.X;
            element.Height = lowerRight.Y - point.Y;
        }
Example #2
0
        /// <summary>
        /// Returns new position of the specified rectangle
        /// taking into account bounds the rectangle can be attracted to.
        /// </summary>
        /// <param name="rect">The rectangle.</param>
        /// <returns>New position.</returns>
        public Point SnapRectangle(Rect rect)
        {
            Point point = rect.Position();

            if (SnapinEnabled)
            {
                Distance minDistance = new Distance();
                foreach (var bound in SnapinBounds)
                {
                    Distance distance = DistanceBetweenRectangles(rect, bound);
                    minDistance = Distance.Min(distance, minDistance);
                }

                point = point.Add(minDistance);
            }

            return point;
        }
Example #3
0
        /// <summary>
        /// Snaps the upper left corner of the specified rectangle to the nearest bounds.
        /// </summary>
        /// <param name="rect">The rectangle.</param>
        /// <returns>New position.</returns>
        public Point SnapTopLeftCorner(Rect rect)
        {
            Point point = rect.Position();

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

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

                point = point.Add(minDistance);
            }

            return point;
        }
Example #4
0
 /// <summary>
 /// Moves and resizes the object.
 /// </summary>
 /// <param name="target">The target object.</param>
 /// <param name="position">Ending position.</param>
 /// <param name="width">New width.</param>
 /// <param name="height">New height.</param>
 /// <param name="milliseconds">Duration of the animation in milliseconds.</param>
 /// <param name="completed">Event handler called when animation completed.</param>
 public static void MoveAndResize(this DependencyObject target, Rect bounds,
     double milliseconds, EventHandler completed = null)
 {
     //target.MoveAndResize(bounds.Position, bounds.Width, bounds.Height, milliseconds, completed); //!!! seems we cannot assume an extension method is defined and use it if it's in the same class
       MoveAndResize(target, bounds.Position(), bounds.Width, bounds.Height, milliseconds, completed); //!!! strangely we can't use "bounds.Position", compiler says "Can't convert from method group to Point"
 }