RTEditor/src/main/java/com/onegravity/rteditor/media/crop/HighlightView.java
void growBy(float dx, float dy) {
        if (mMaintainAspectRatio) {
            if (dx != 0) {
                dy = dx / mInitialAspectRatio;
            } else if (dy != 0) {
                dx = dy * mInitialAspectRatio;
            }
        }

        // Don't let the cropping rectangle grow too fast.
        // Grow at most half of the difference between the image rectangle and
        // the cropping rectangle.
        RectF r = new RectF(mCropRect);
        if (dx > 0F && r.width() + 2 * dx > mImageRect.width()) {
            float adjustment = (mImageRect.width() - r.width()) / 2F;
            dx = adjustment;
            if (mMaintainAspectRatio) {
                dy = dx / mInitialAspectRatio;
            }
        }
        if (dy > 0F && r.height() + 2 * dy > mImageRect.height()) {
            float adjustment = (mImageRect.height() - r.height()) / 2F;
            dy = adjustment;
            if (mMaintainAspectRatio) {
                dx = dy * mInitialAspectRatio;
            }
        }

        r.inset(-dx, -dy);

        // Don't let the cropping rectangle shrink too fast.
        final float widthCap = 25F;
        if (r.width() < widthCap) {
            r.inset(-(widthCap - r.width()) / 2F, 0F);
        }
        float heightCap = mMaintainAspectRatio ? (widthCap / mInitialAspectRatio)
                : widthCap;
        if (r.height() < heightCap) {
            r.inset(0F, -(heightCap - r.height()) / 2F);
        }

        // Put the cropping rectangle inside the image rectangle.
        if (r.left < mImageRect.left) {
            r.offset(mImageRect.left - r.left, 0F);
        } else if (r.right > mImageRect.right) {
            r.offset(-(r.right - mImageRect.right), 0);
        }
        if (r.top < mImageRect.top) {
            r.offset(0F, mImageRect.top - r.top);
        } else if (r.bottom > mImageRect.bottom) {
            r.offset(0F, -(r.bottom - mImageRect.bottom));
        }

        mCropRect.set(r);
        mDrawRect = computeLayout();
        mContext.invalidate();
    }
void growBy(float dx, float dy) {
        if (mMaintainAspectRatio) {
            if (dx != 0) {
                dy = dx / mInitialAspectRatio;
            } else if (dy != 0) {
                dx = dy * mInitialAspectRatio;
            }
        }

        // Don't let the cropping rectangle grow too fast.
        // Grow at most half of the difference between the image rectangle and
        // the cropping rectangle.
        RectF r = new RectF(mCropRect);
        if (dx > 0F && r.width() + 2 * dx > mImageRect.width()) {
            float adjustment = (mImageRect.width() - r.width()) / 2F;
            dx = adjustment;
            if (mMaintainAspectRatio) {
                dy = dx / mInitialAspectRatio;
            }
        }
        if (dy > 0F && r.height() + 2 * dy > mImageRect.height()) {
            float adjustment = (mImageRect.height() - r.height()) / 2F;
            dy = adjustment;
            if (mMaintainAspectRatio) {
                dx = dy * mInitialAspectRatio;
            }
        }

        r.inset(-dx, -dy);

        // Don't let the cropping rectangle shrink too fast.
        final float widthCap = 25F;
        if (r.width() < widthCap) {
            r.inset(-(widthCap - r.width()) / 2F, 0F);
        }
        float heightCap = mMaintainAspectRatio ? (widthCap / mInitialAspectRatio)
                : widthCap;
        if (r.height() < heightCap) {
            r.inset(0F, -(heightCap - r.height()) / 2F);
        }

        // Put the cropping rectangle inside the image rectangle.
        if (r.left < mImageRect.left) {
            r.offset(mImageRect.left - r.left, 0F);
        } else if (r.right > mImageRect.right) {
            r.offset(-(r.right - mImageRect.right), 0);
        }
        if (r.top < mImageRect.top) {
            r.offset(0F, mImageRect.top - r.top);
        } else if (r.bottom > mImageRect.bottom) {
            r.offset(0F, -(r.bottom - mImageRect.bottom));
        }

        mCropRect.set(r);
        mDrawRect = computeLayout();
        mContext.invalidate();
    }
void growBy ( float dx , float dy ) { if ( mMaintainAspectRatio ) { if ( dx != 0 ) { dy = dx / mInitialAspectRatio ; } else if ( dy != 0 ) { dx = dy * mInitialAspectRatio ; } } // Don't let the cropping rectangle grow too fast. // Grow at most half of the difference between the image rectangle and // the cropping rectangle. RectF r = new RectF ( mCropRect ) ; if ( dx > 0F && r . width ( ) + 2 * dx > mImageRect . width ( ) ) { float adjustment = ( mImageRect . width ( ) - r . width ( ) ) / 2F ; dx = adjustment ; if ( mMaintainAspectRatio ) { dy = dx / mInitialAspectRatio ; } } if ( dy > 0F && r . height ( ) + 2 * dy > mImageRect . height ( ) ) { float adjustment = ( mImageRect . height ( ) - r . height ( ) ) / 2F ; dy = adjustment ; if ( mMaintainAspectRatio ) { dx = dy * mInitialAspectRatio ; } } r . inset ( - dx , - dy ) ; // Don't let the cropping rectangle shrink too fast. final float widthCap = 25F ; if ( r . width ( ) < widthCap ) { r . inset ( - ( widthCap - r . width ( ) ) / 2F , 0F ) ; } float heightCap = mMaintainAspectRatio ? ( widthCap / mInitialAspectRatio ) : widthCap ; if ( r . height ( ) < heightCap ) { r . inset ( 0F , - ( heightCap - r . height ( ) ) / 2F ) ; } // Put the cropping rectangle inside the image rectangle. if ( r . left < mImageRect . left ) { r . offset ( mImageRect . left - r . left , 0F ) ; } else if ( r . right > mImageRect . right ) { r . offset ( - ( r . right - mImageRect . right ) , 0 ) ; } if ( r . top < mImageRect . top ) { r . offset ( 0F , mImageRect . top - r . top ) ; } else if ( r . bottom > mImageRect . bottom ) { r . offset ( 0F , - ( r . bottom - mImageRect . bottom ) ) ; } mCropRect . set ( r ) ; mDrawRect = computeLayout ( ) ; mContext . invalidate ( ) ; }
Grows the cropping rectange by (dx, dy) in image space.
Grows the cropping rectange by ( dx dy ) in image space .