Exemple #1
0
        /// <summary>
        /// Updates the location of the edit handles when the bounds has been relocated or
        /// resized.
        /// </summary>
        public virtual void BoundsChanged()
        {
            // Anything to process?
            if (TopLeftHandle == null)
            {
                return;
            }

            // Adjust the four courner drag handles
            TopLeftHandle.MoveTo(Left - KimonoHandle.DrawOffset, Top - KimonoHandle.DrawOffset);
            TopRightHandle.MoveTo(Right - KimonoHandle.DrawOffset, Top - KimonoHandle.DrawOffset);
            BottomRightHandle.MoveTo(Right - KimonoHandle.DrawOffset, Bottom - KimonoHandle.DrawOffset);
            BottomLeftHandle.MoveTo(Left - KimonoHandle.DrawOffset, Bottom - KimonoHandle.DrawOffset);

            // Set handle state
            var newHandleState = (State == KimonoShapeState.Selected) ? KimonoShapeState.Unselected : State;

            // Adjust top and bottom drag handles based on width
            if (Width < 50)
            {
                // Too small so remove handles
                TopHandle    = null;
                BottomHandle = null;
            }
            else
            {
                // Move or create handles as needed
                if (TopHandle == null)
                {
                    TopHandle        = new KimonoHandle(HorizontalCenter - KimonoHandle.DrawOffset, Top - KimonoHandle.DrawOffset, KimonoHandleConstraint.Vertical, newHandleState);
                    TopHandle.Moved += (point) =>
                    {
                        Top = point.Y;
                    };
                }
                else
                {
                    TopHandle.MoveTo(HorizontalCenter - KimonoHandle.DrawOffset, Top - KimonoHandle.DrawOffset);
                }

                if (BottomHandle == null)
                {
                    BottomHandle        = new KimonoHandle(HorizontalCenter - KimonoHandle.DrawOffset, Bottom - KimonoHandle.DrawOffset, KimonoHandleConstraint.Vertical, newHandleState);
                    BottomHandle.Moved += (point) =>
                    {
                        Bottom = point.Y;
                    };
                }
                else
                {
                    BottomHandle.MoveTo(HorizontalCenter - KimonoHandle.DrawOffset, Bottom - KimonoHandle.DrawOffset);
                }
            }

            // Adjust left and right drag handles based on the height
            if (Height < 50)
            {
                // Too small so remove handles
                LeftHandle  = null;
                RightHandle = null;
            }
            else
            {
                // Move or create handles as needed
                if (LeftHandle == null)
                {
                    LeftHandle        = new KimonoHandle(Left - KimonoHandle.DrawOffset, VerticalCenter - KimonoHandle.DrawOffset, KimonoHandleConstraint.Horizontal, newHandleState);
                    LeftHandle.Moved += (point) =>
                    {
                        Left = point.X;
                    };
                }
                else
                {
                    LeftHandle.MoveTo(Left - KimonoHandle.DrawOffset, VerticalCenter - KimonoHandle.DrawOffset);
                }

                if (RightHandle == null)
                {
                    RightHandle        = new KimonoHandle(Right - KimonoHandle.DrawOffset, VerticalCenter - KimonoHandle.DrawOffset, KimonoHandleConstraint.Horizontal, newHandleState);
                    RightHandle.Moved += (point) =>
                    {
                        Right = point.X;
                    };
                }
                else
                {
                    RightHandle.MoveTo(Right - KimonoHandle.DrawOffset, VerticalCenter - KimonoHandle.DrawOffset);
                }
            }
        }