Esempio n. 1
0
        /**
         * Adjusts this Edge position such that the resulting window will have the
         * given aspect ratio.
         *
         * @param aspectRatio the aspect ratio to achieve
         */
        public void adjustCoordinate(float aspectRatio)
        {
            float left   = EdgeManager.LEFT.coordinate;
            float top    = EdgeManager.TOP.coordinate;
            float right  = EdgeManager.RIGHT.coordinate;
            float bottom = EdgeManager.BOTTOM.coordinate;

            switch (edgeType)
            {
            case EdgeType.LEFT:
                coordinate = AspectRatioUtil.calculateLeft(top, right, bottom, aspectRatio);
                break;

            case EdgeType.TOP:
                coordinate = AspectRatioUtil.calculateTop(left, right, bottom, aspectRatio);
                break;

            case EdgeType.RIGHT:
                coordinate = AspectRatioUtil.calculateRight(left, top, bottom, aspectRatio);
                break;

            case EdgeType.BOTTOM:
                coordinate = AspectRatioUtil.calculateBottom(left, top, right, aspectRatio);
                break;
            }
        }
Esempio n. 2
0
        /**
         * Returns whether or not you can re-scale the image based on whether any edge would be out of bounds.
         * Checks all the edges for a possibility of jumping out of bounds.
         *
         * @param Edge the Edge that is about to be expanded
         * @param imageRect the rectangle of the picture
         * @param aspectratio the desired aspectRatio of the picture.
         *
         * @return whether or not the new image would be out of bounds.
         */
        public bool isNewRectangleOutOfBounds(Edge edge, Rect imageRect, float aspectRatio)
        {
            float offset = edge.snapOffset(imageRect);

            switch (edgeType)
            {
            case EdgeType.LEFT:
                if (edge.Equals(EdgeManager.TOP))
                {
                    float top    = imageRect.Top;
                    float bottom = EdgeManager.BOTTOM.coordinate - offset;
                    float right  = EdgeManager.RIGHT.coordinate;
                    float left   = AspectRatioUtil.calculateLeft(top, right, bottom, aspectRatio);

                    return(isOutOfBounds(top, left, bottom, right, imageRect));
                }
                else if (edge.Equals(EdgeManager.BOTTOM))
                {
                    float bottom = imageRect.Bottom;
                    float top    = EdgeManager.TOP.coordinate - offset;
                    float right  = EdgeManager.RIGHT.coordinate;
                    float left   = AspectRatioUtil.calculateLeft(top, right, bottom, aspectRatio);

                    return(isOutOfBounds(top, left, bottom, right, imageRect));
                }
                break;

            case EdgeType.TOP:
                if (edge.Equals(EdgeManager.LEFT))
                {
                    float left   = imageRect.Left;
                    float right  = EdgeManager.RIGHT.coordinate - offset;
                    float bottom = EdgeManager.BOTTOM.coordinate;
                    float top    = AspectRatioUtil.calculateTop(left, right, bottom, aspectRatio);

                    return(isOutOfBounds(top, left, bottom, right, imageRect));
                }
                else if (edge.Equals(EdgeManager.RIGHT))
                {
                    float right  = imageRect.Right;
                    float left   = EdgeManager.LEFT.coordinate - offset;
                    float bottom = EdgeManager.BOTTOM.coordinate;
                    float top    = AspectRatioUtil.calculateTop(left, right, bottom, aspectRatio);

                    return(isOutOfBounds(top, left, bottom, right, imageRect));
                }
                break;

            case EdgeType.RIGHT:
                if (edge.Equals(EdgeManager.TOP))
                {
                    float top    = imageRect.Top;
                    float bottom = EdgeManager.BOTTOM.coordinate - offset;
                    float left   = EdgeManager.LEFT.coordinate;
                    float right  = AspectRatioUtil.calculateRight(left, top, bottom, aspectRatio);

                    return(isOutOfBounds(top, left, bottom, right, imageRect));
                }
                else if (edge.Equals(EdgeManager.BOTTOM))
                {
                    float bottom = imageRect.Bottom;
                    float top    = EdgeManager.TOP.coordinate - offset;
                    float left   = EdgeManager.LEFT.coordinate;
                    float right  = AspectRatioUtil.calculateRight(left, top, bottom, aspectRatio);

                    return(isOutOfBounds(top, left, bottom, right, imageRect));
                }
                break;


            case EdgeType.BOTTOM:
                if (edge.Equals(EdgeManager.LEFT))
                {
                    float left   = imageRect.Left;
                    float right  = EdgeManager.RIGHT.coordinate - offset;
                    float top    = EdgeManager.TOP.coordinate;
                    float bottom = AspectRatioUtil.calculateBottom(left, top, right, aspectRatio);

                    return(isOutOfBounds(top, left, bottom, right, imageRect));
                }
                else if (edge.Equals(EdgeManager.RIGHT))
                {
                    float right  = imageRect.Right;
                    float left   = EdgeManager.LEFT.coordinate - offset;
                    float top    = EdgeManager.TOP.coordinate;
                    float bottom = AspectRatioUtil.calculateBottom(left, top, right, aspectRatio);

                    return(isOutOfBounds(top, left, bottom, right, imageRect));
                }
                break;
            }
            return(true);
        }