/** * draw the ring * * @param canvas to draw the Ring * @param bounds the ring's rect */ private void drawRing(Canvas canvas, Rect bounds) { final RectF arcBounds = mTempBounds; final Ring ring = mRing; arcBounds.set(bounds); arcBounds.inset(ring.strokeInset, ring.strokeInset); canvas.drawArc(arcBounds, ring.start, ring.sweep, false, mPaint); }
@Override protected void onSizeChanged(int w, int h, int oldw, int oldh) { mPaint.setStrokeWidth(Math.min(w, h) / 12.0f); mRectF.set(0, 0, w, h); mRectF.inset(w / 48.0f * 5.0f, h / 48.0f * 5.0f); }
private static void drawRect(Canvas canvas, RectF rect, int color, float stroke) { paint.setStyle(Paint.Style.STROKE); paint.setStrokeWidth(stroke); rectF.inset(0.5f * stroke, 0.5f * stroke); paint.setColor(color); canvas.drawRect(rect, paint); }
@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); }
public RectF getGridClippingRect() { mGridClippingRect.set(mViewPortHandler.getContentRect()); mGridClippingRect.inset(-mAxis.getGridLineWidth(), 0.f); return mGridClippingRect; }
@Override public RectF getGridClippingRect() { mGridClippingRect.set(mViewPortHandler.getContentRect()); mGridClippingRect.inset(-mAxis.getGridLineWidth(), 0.f); return mGridClippingRect; }
public RectF getGridClippingRect() { mGridClippingRect.set(mViewPortHandler.getContentRect()); mGridClippingRect.inset(0.f, -mAxis.getGridLineWidth()); return mGridClippingRect; }
@Override public RectF getGridClippingRect() { mGridClippingRect.set(mViewPortHandler.getContentRect()); mGridClippingRect.inset(0.f, -mAxis.getGridLineWidth()); return mGridClippingRect; }
@Override protected void draw(Canvas canvas) { int saveCount = canvas.save(); mTempBounds.set(mBounds); mTempBounds.inset(mStrokeInset, mStrokeInset); canvas.rotate(mGroupRotation, mTempBounds.centerX(), mTempBounds.centerY()); for (int i = 0; i < 3; i++) { if (mLevelSwipeDegrees[i] != 0) { mPaint.setColor(mLevelColors[i]); canvas.drawArc(mTempBounds, mEndDegrees, mLevelSwipeDegrees[i], 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 setBounds(RectF rect, float rounding) { this.areaRect.set(rect); this.rounding = rounding; // We want to stroke outside of cropping rectangle, while by default stroke is centered strokeRect.set(rect); float halfStroke = 0.5f * borderWidth; strokeRect.inset(-halfStroke, -halfStroke); invalidate(); }
public void draw(Canvas c, Rect bounds) { final RectF arcBounds = mTempBounds; arcBounds.set(bounds); arcBounds.inset(mStrokeInset, mStrokeInset); final float startAngle = (mStartTrim + mRotation) * 360; final float endAngle = (mEndTrim + mRotation) * 360; float sweepAngle = endAngle - startAngle; if (sweepAngle != 0) { mPaint.setColor(mCurrentColor); c.drawArc(arcBounds, startAngle, sweepAngle, false, mPaint); } drawTriangle(c, startAngle, sweepAngle, bounds); if (mAlpha < 255) { mCirclePaint.setColor(mBackgroundColor); mCirclePaint.setAlpha(255 - mAlpha); c.drawCircle(bounds.exactCenterX(), bounds.exactCenterY(), bounds.width() / 2, mCirclePaint); } }
private void drawBorder(Canvas canvas) { RectF rect = new RectF(getBounds()); rect.inset(borderThickness / 2, borderThickness / 2); if (shape instanceof OvalShape) { canvas.drawOval(rect, borderPaint); } else if (shape instanceof RoundRectShape) { canvas.drawRoundRect(rect, radius, radius, borderPaint); } else { canvas.drawRect(rect, borderPaint); } }
/** Best case possible, all colors are the same and all widths are the same */ private void drawAllBorders(Canvas canvas, float strokeWidth, @ColorInt int color) { float inset = strokeWidth / 2f; sDrawBounds.set(getBounds()); sDrawBounds.inset(inset, inset); mPaint.setStrokeWidth(strokeWidth); mPaint.setColor(color); drawBorder(canvas, sDrawBounds, path(), mState.mBorderRadius, mPaint); }
/** * Adjust left and right edges by current crop window height and the given aspect ratio, both * right and left edges adjusts equally relative to center to keep aspect ratio to the height. */ private void adjustLeftRightByAspectRatio(RectF rect, RectF bounds, float aspectRatio) { rect.inset((rect.width() - rect.height() * aspectRatio) / 2, 0); if (rect.left < bounds.left) { rect.offset(bounds.left - rect.left, 0); } if (rect.right > bounds.right) { rect.offset(bounds.right - rect.right, 0); } }
@Override protected void drawZeroLine(Canvas c) { int clipRestoreCount = c.save(); mZeroLineClippingRect.set(mViewPortHandler.getContentRect()); mZeroLineClippingRect.inset(-mYAxis.getZeroLineWidth(), 0.f); c.clipRect(mLimitLineClippingRect); // draw zero line MPPointD pos = mTrans.getPixelForValues(0f, 0f); mZeroLinePaint.setColor(mYAxis.getZeroLineColor()); mZeroLinePaint.setStrokeWidth(mYAxis.getZeroLineWidth()); Path zeroLinePath = mDrawZeroLinePathBuffer; zeroLinePath.reset(); zeroLinePath.moveTo((float) pos.x - 1, mViewPortHandler.contentTop()); zeroLinePath.lineTo((float) pos.x - 1, mViewPortHandler.contentBottom()); // draw a path because lines don't support dashing on lower android versions c.drawPath(zeroLinePath, mZeroLinePaint); c.restoreToCount(clipRestoreCount); }
/** * Adjust top and bottom edges by current crop window width and the given aspect ratio, both top * and bottom edges adjusts equally relative to center to keep aspect ratio to the width. */ private void adjustTopBottomByAspectRatio(RectF rect, RectF bounds, float aspectRatio) { rect.inset(0, (rect.height() - rect.width() / aspectRatio) / 2); if (rect.top < bounds.top) { rect.offset(0, bounds.top - rect.top); } if (rect.bottom > bounds.bottom) { rect.offset(0, bounds.bottom - rect.bottom); } }
/** * Draws the zero line. */ protected void drawZeroLine(Canvas c) { int clipRestoreCount = c.save(); mZeroLineClippingRect.set(mViewPortHandler.getContentRect()); mZeroLineClippingRect.inset(0.f, -mYAxis.getZeroLineWidth()); c.clipRect(mZeroLineClippingRect); // draw zero line MPPointD pos = mTrans.getPixelForValues(0f, 0f); mZeroLinePaint.setColor(mYAxis.getZeroLineColor()); mZeroLinePaint.setStrokeWidth(mYAxis.getZeroLineWidth()); Path zeroLinePath = mDrawZeroLinePath; zeroLinePath.reset(); zeroLinePath.moveTo(mViewPortHandler.contentLeft(), (float) pos.y); zeroLinePath.lineTo(mViewPortHandler.contentRight(), (float) pos.y); // draw a path because lines don't support dashing on lower android versions c.drawPath(zeroLinePath, mZeroLinePaint); c.restoreToCount(clipRestoreCount); }
/** Draw borders of the crop area. */ private void drawBorders(Canvas canvas) { if (mBorderPaint != null) { float w = mBorderPaint.getStrokeWidth(); RectF rect = mCropWindowHandler.getRect(); rect.inset(w / 2, w / 2); if (mCropShape == CropImageView.CropShape.RECTANGLE) { // Draw rectangle crop window border. canvas.drawRect(rect, mBorderPaint); } else { // Draw circular crop window border canvas.drawOval(rect, mBorderPaint); } } }
/** * Draws the LimitLines associated with this axis to the screen. * * @param c */ @Override public void renderLimitLines(Canvas c) { List<LimitLine> limitLines = mXAxis.getLimitLines(); if (limitLines == null || limitLines.size() <= 0) return; float[] position = mRenderLimitLinesBuffer; position[0] = 0; position[1] = 0; for (int i = 0; i < limitLines.size(); i++) { LimitLine l = limitLines.get(i); if (!l.isEnabled()) continue; int clipRestoreCount = c.save(); mLimitLineClippingRect.set(mViewPortHandler.getContentRect()); mLimitLineClippingRect.inset(-l.getLineWidth(), 0.f); c.clipRect(mLimitLineClippingRect); position[0] = l.getLimit(); position[1] = 0.f; mTrans.pointValuesToPixel(position); renderLimitLineLine(c, l, position); renderLimitLineLabel(c, l, position, 2.f + l.getYOffset()); c.restoreToCount(clipRestoreCount); } }