public static float[] getCenterFromRect(RectF r) { return new float[]{r.centerX(), r.centerY()}; }
/** * Sets the drawing position of the highlight object based on the riven bar-rect. * @param high */ protected void setHighlightDrawPos(Highlight high, RectF bar) { high.setDraw(bar.centerX(), bar.top); }
/** * returns the center of the circlebox * * @return */ public MPPointF getCenterCircleBox() { return MPPointF.getInstance(mCircleBox.centerX(), mCircleBox.centerY()); }
//Convert the progress in range of 0 to 100 to angle in range of 0 180. Easy math. float angle = (progress * 180) / 100; mClippingPath.reset(); //Define a rectangle containing the image RectF oval = new RectF(mPivotX, mPivotY, mPivotX + mBitmap.getWidth(), mPivotY + mBitmap.getHeight()); //Move the current position to center of rect mClippingPath.moveTo(oval.centerX(), oval.centerY()); //Draw an arc from center to given angle mClippingPath.addArc(oval, 180, angle); //Draw a line from end of arc to center mClippingPath.lineTo(oval.centerX(), oval.centerY());
private RectF createLeftEyeBall(RectF arcBounds, float offsetY) { //the center of the left eye float leftEyeCenterX = arcBounds.centerX() - mEyeInterval / 2.0f - mEyeCircleRadius; float leftEyeCenterY = arcBounds.centerY() - mEyeBallOffsetY + offsetY; RectF rectF = new RectF(leftEyeCenterX - mEyeBallWidth / 2.0f, leftEyeCenterY - mEyeBallHeight / 2.0f, leftEyeCenterX + mEyeBallWidth / 2.0f, leftEyeCenterY + mEyeBallHeight / 2.0f); return rectF; }
private RectF createRightEyeBall(RectF arcBounds, float offsetY) { //the center of the right eye float rightEyeCenterX = arcBounds.centerX() + mEyeInterval / 2.0f + mEyeCircleRadius; float rightEyeCenterY = arcBounds.centerY() - mEyeBallOffsetY + offsetY; RectF rectF = new RectF(rightEyeCenterX - mEyeBallWidth / 2.0f, rightEyeCenterY - mEyeBallHeight / 2.0f, rightEyeCenterX + mEyeBallWidth / 2.0f, rightEyeCenterY + mEyeBallHeight / 2.0f); return rectF; }
private boolean inTouchableArea(float x, float y) { return Math.pow(x - mBorderRect.centerX(), 2) + Math.pow(y - mBorderRect.centerY(), 2) <= Math.pow(mBorderRadius, 2); }
public MPPointF getContentCenter() { return MPPointF.getInstance(mContentRect.centerX(), mContentRect.centerY()); }
@Override public void draw(Canvas canvas) { int restoreCount = canvas.save(); float degrees = (mClockwise ? 180 : -180) * ((mPrevState < mCurState ? 0f : 1f) + mAnimProgress); if(mIsRtl) canvas.scale(-1f, 1f, mDrawBound.centerX(), mDrawBound.centerY()); canvas.rotate(degrees, mDrawBound.centerX(), mDrawBound.centerY()); canvas.drawPath(mPath, mPaint); canvas.restoreToCount(restoreCount); }
private Path createCannulaHeadPath(RectF cannulaRect) { Path path = new Path(); path.moveTo(cannulaRect.left, cannulaRect.top); path.lineTo(cannulaRect.right, cannulaRect.top); path.moveTo(cannulaRect.centerX(), cannulaRect.top); path.lineTo(cannulaRect.centerX(), cannulaRect.bottom - 0.833f * cannulaRect.width()); return path; }
private int getMaxRippleRadius(float x, float y){ float x1 = x < mBackgroundBounds.centerX() ? mBackgroundBounds.right : mBackgroundBounds.left; float y1 = y < mBackgroundBounds.centerY() ? mBackgroundBounds.bottom : mBackgroundBounds.top; return (int)Math.round(Math.sqrt(Math.pow(x1 - x, 2) + Math.pow(y1 - y, 2))); }
private int getMaxRippleRadius(float x, float y){ float x1 = x < mBackgroundBounds.centerX() ? mBackgroundBounds.right : mBackgroundBounds.left; float y1 = y < mBackgroundBounds.centerY() ? mBackgroundBounds.bottom : mBackgroundBounds.top; return (int)Math.round(Math.sqrt(Math.pow(x1 - x, 2) + Math.pow(y1 - y, 2))); }
@Override protected void onDraw(Canvas canvas) { if (mDisableCircularTransformation) { super.onDraw(canvas); return; } if (mBitmap == null) { return; } if (mCircleBackgroundColor != Color.TRANSPARENT) { canvas.drawCircle(mDrawableRect.centerX(), mDrawableRect.centerY(), mDrawableRadius, mCircleBackgroundPaint); } canvas.drawCircle(mDrawableRect.centerX(), mDrawableRect.centerY(), mDrawableRadius, mBitmapPaint); if (mBorderWidth > 0) { canvas.drawCircle(mBorderRect.centerX(), mBorderRect.centerY(), mBorderRadius, mBorderPaint); } }
/** * This method scales image down for given value related to image center. */ public void zoomOutImage(float deltaScale) { zoomOutImage(deltaScale, mCropRect.centerX(), mCropRect.centerY()); }
/** * This method scales image up for given value related to image center. */ public void zoomInImage(float deltaScale) { zoomInImage(deltaScale, mCropRect.centerX(), mCropRect.centerY()); }
/** * This method rotates image for given angle related to the image center. * * @param deltaAngle - angle to rotate */ public void postRotate(float deltaAngle) { postRotate(deltaAngle, mCropRect.centerX(), mCropRect.centerY()); }
@Override protected void onBoundsChange(Rect bounds) { super.onBoundsChange(bounds); RadialGradient vignette = new RadialGradient( mRect.centerX(), mRect.centerY() * 1.0f / 0.7f, mRect.centerX() * 1.3f, new int[]{0, 0, 0x7f000000}, new float[]{0.0f, 0.7f, 1.0f}, Shader.TileMode.CLAMP); Matrix oval = new Matrix(); oval.setScale(1.0f, 0.7f); vignette.setLocalMatrix(oval); paint.setShader(new ComposeShader(bitmapShader, vignette, PorterDuff.Mode.SRC_OVER)); } }
@Override protected void draw(Canvas canvas) { int saveCount = canvas.save(); mTempBounds.set(mBounds); mTempBounds.inset(mStrokeInset, mStrokeInset); canvas.rotate(mGroupRotation, mTempBounds.centerX(), mTempBounds.centerY()); if (mSwipeDegrees != 0) { mPaint.setColor(mCurrentColor); canvas.drawArc(mTempBounds, mStartDegrees, mSwipeDegrees, false, mPaint); } canvas.restoreToCount(saveCount); }
private Path createRiverPath(RectF arcBounds) { if (mRiverPath != null) { return mRiverPath; } mRiverPath = new Path(); RectF rectF = new RectF(arcBounds.centerX() - mRiverWidth / 2.0f, arcBounds.centerY() - mRiverHeight / 2.0f, arcBounds.centerX() + mRiverWidth / 2.0f, arcBounds.centerY() + mRiverHeight / 2.0f); rectF.inset(mRiverBankWidth / 2.0f, mRiverBankWidth / 2.0f); mRiverPath.addRect(rectF, Path.Direction.CW); return mRiverPath; }
private void updateGridPoints() { mCropGridCorners = RectUtils.getCornersFromRect(mCropViewRect); mCropGridCenter = RectUtils.getCenterFromRect(mCropViewRect); mGridPoints = null; mCircularPath.reset(); mCircularPath.addCircle(mCropViewRect.centerX(), mCropViewRect.centerY(), Math.min(mCropViewRect.width(), mCropViewRect.height()) / 2.f, Path.Direction.CW); }