private void drawChild(Canvas canvas, View child, LayoutParams lp) { mSrcCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); mDstCanvas.drawColor(Color.TRANSPARENT, PorterDuff.Mode.CLEAR); mSrcCanvas.save(); int childLeft = child.getLeft(); int childTop = child.getTop(); int childRight = child.getRight(); int childBottom = child.getBottom(); mSrcCanvas.clipRect(childLeft, childTop, childRight, childBottom, Op.REPLACE); mSrcCanvas.translate(childLeft, childTop); child.draw(mSrcCanvas); mSrcCanvas.restore(); mXferPaint.setXfermode(null); mXferPaint.setColor(Color.BLACK); float sweepAngle = (lp.endAngle - lp.startAngle) % 361; mDstCanvas.drawArc(mBounds, lp.startAngle, sweepAngle, true, mXferPaint); mXferPaint.setXfermode(mXfer); mDstCanvas.drawBitmap(mSrc, 0f, 0f, mXferPaint); canvas.drawBitmap(mDst, 0f, 0f, null); }
void commitSelectionOval(Rect rect, Op op) { ActionSelectionChange action = new ActionSelectionChange(image); action.setOldRegion(); RectF rectF = new RectF(rect); Path ovalPath = new Path(); ovalPath.addOval(rectF, CW); Region ovalRegion = new Region(); ovalRegion.setPath(ovalPath, new Region(0, 0, imageRect.right, imageRect.bottom)); region.op(ovalRegion, op); updatePath(); action.applyAction(); }
private final boolean a(ghu paramghu, boolean paramBoolean, Canvas paramCanvas) { int j = 255; if (getDrawingTime() >= paramghu.e + this.g) { return false; } if (paramBoolean) { float f1 = 1.0F - (float)(getDrawingTime() - paramghu.e) / this.g; j = efj.a(Math.round(255.0F * (f1 * f1)), 0, j); } this.d.setAlpha(j); if (this.h != null) { this.h.setBounds(paramghu.a(0, 0)); this.h.draw(paramCanvas); } for (;;) { return true; paramCanvas.clipRect(paramghu.a(0, 0), Region.Op.UNION); paramCanvas.drawCircle(paramghu.a, paramghu.b, paramghu.c, this.d); } }
/** * Draw this BubbleTextView into the given Canvas. * * @param destCanvas the canvas to draw on * @param padding the horizontal and vertical padding to use when drawing */ private void drawWithPadding(Canvas destCanvas, int padding) { final Rect clipRect = mTempRect; getDrawingRect(clipRect); // adjust the clip rect so that we don't include the text label clipRect.bottom = getExtendedPaddingTop() - (int) BubbleTextView.PADDING_V + getLayout().getLineTop(0); // Draw the View into the bitmap. // The translate of scrollX and scrollY is necessary when drawing TextViews, because // they set scrollX and scrollY to large values to achieve centered text destCanvas.save(); destCanvas.scale(getScaleX(), getScaleY(), (getWidth() + padding) / 2, (getHeight() + padding) / 2); destCanvas.translate(-getScrollX() + padding / 2, -getScrollY() + padding / 2); destCanvas.clipRect(clipRect, Op.REPLACE); draw(destCanvas); destCanvas.restore(); }
/** * Sets the bitmap to be used for the zoomed view. */ public void setBitmap(Bitmap bitmap) { if (mZoomedBitmap != null) { mZoomedBitmap.recycle(); mZoomedBitmap = null; } mZoomedBitmap = bitmap; // Round the corners of the bitmap so it doesn't stick out around the overlay. Canvas canvas = new Canvas(mZoomedBitmap); Path path = new Path(); RectF canvasRect = new RectF(0, 0, canvas.getWidth(), canvas.getHeight()); float overlayCornerRadius = getOverlayCornerRadius(getContext()); path.addRoundRect(canvasRect, overlayCornerRadius, overlayCornerRadius, Direction.CCW); canvas.clipPath(path, Op.XOR); Paint clearPaint = new Paint(); clearPaint.setXfermode(new PorterDuffXfermode(Mode.SRC)); clearPaint.setColor(Color.TRANSPARENT); canvas.drawPaint(clearPaint); }
/** * Draw the View v into the given Canvas. * * @param v the view to draw * @param destCanvas the canvas to draw on * @param padding the horizontal and vertical padding to use when drawing */ private static void drawDragView(View v, Canvas destCanvas, int padding) { final Rect clipRect = sTempRect; v.getDrawingRect(clipRect); destCanvas.save(); if (v instanceof TextView) { Drawable d = ((TextView) v).getCompoundDrawables()[1]; Rect bounds = getDrawableBounds(d); clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding); destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top); d.draw(destCanvas); } else { destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2); destCanvas.clipRect(clipRect, Op.REPLACE); v.draw(destCanvas); } destCanvas.restore(); }
/** * Draw this BubbleTextView into the given Canvas. * * @param destCanvas the canvas to draw on * @param padding the horizontal and vertical padding to use when drawing */ private void drawWithPadding(Canvas destCanvas, int padding) { final Rect clipRect = mTempRect; getDrawingRect(clipRect); // adjust the clip rect so that we don't include the text label clipRect.bottom = getExtendedPaddingTop() - (int) BubbleTextView.PADDING_V + getLayout().getLineTop(0); // Draw the View into the bitmap. // The translate of scrollX and scrollY is necessary when drawing TextViews, because // they set scrollX and scrollY to large values to achieve centered text destCanvas.save(); destCanvas.translate(-getScrollX() + padding / 2, -getScrollY() + padding / 2); destCanvas.clipRect(clipRect, Op.REPLACE); draw(destCanvas); destCanvas.restore(); }
private boolean testTouch() { mTouchRect.offset(mTouchX, mTouchY); Iterator<Region> ir = mRegions.iterator(); mSelectedRegion = null; boolean hit = false; while (ir.hasNext()) { Region original = ir.next(); Region region = new Region(original); if (region.op(mTouchRect, Op.INTERSECT)) { mSelectedRegion = original; hit = true; } } mTouchRect.offset(-mTouchX, -mTouchY); return hit; }
/** * Draws the {@link #mView} into the given {@param destCanvas}. */ private void drawDragView(Canvas destCanvas) { destCanvas.save(); if (mView instanceof TextView) { Drawable d = Workspace.getTextViewIcon((TextView) mView); Rect bounds = getDrawableBounds(d); destCanvas.translate(blurSizeOutline / 2 - bounds.left, blurSizeOutline / 2 - bounds.top); d.draw(destCanvas); } else { final Rect clipRect = mTempRect; mView.getDrawingRect(clipRect); boolean textVisible = false; if (mView instanceof FolderIcon) { // For FolderIcons the text can bleed into the icon area, and so we need to // hide the text completely (which can't be achieved by clipping). if (((FolderIcon) mView).getTextVisible()) { ((FolderIcon) mView).setTextVisible(false); textVisible = true; } } destCanvas.translate(-mView.getScrollX() + blurSizeOutline / 2, -mView.getScrollY() + blurSizeOutline / 2); destCanvas.clipRect(clipRect, Op.REPLACE); mView.draw(destCanvas); // Restore text visibility of FolderIcon if necessary if (textVisible) { ((FolderIcon) mView).setTextVisible(true); } } destCanvas.restore(); }
protected void drawDimmedLayer(@NonNull Canvas canvas) { canvas.save(); if (this.mOvalDimmedLayer) { canvas.clipPath(this.mCircularPath, Op.DIFFERENCE); } else { canvas.clipRect(this.mCropViewRect, Op.DIFFERENCE); } canvas.drawColor(this.mDimmedColor); canvas.restore(); if (this.mOvalDimmedLayer) { canvas.drawOval(this.mCropViewRect, this.mDimmedStrokePaint); } }
/** * Draws the {@link #mView} into the given {@param destCanvas}. */ private void drawDragView(Canvas destCanvas) { destCanvas.save(); if (mView instanceof TextView) { Drawable d = Workspace.getTextViewIcon((TextView) mView); Rect bounds = getDrawableBounds(d); destCanvas.translate(DRAG_BITMAP_PADDING / 2 - bounds.left, DRAG_BITMAP_PADDING / 2 - bounds.top); d.draw(destCanvas); } else { final Rect clipRect = mTempRect; mView.getDrawingRect(clipRect); boolean textVisible = false; if (mView instanceof FolderIcon) { // For FolderIcons the text can bleed into the icon area, and so we need to // hide the text completely (which can't be achieved by clipping). if (((FolderIcon) mView).getTextVisible()) { ((FolderIcon) mView).setTextVisible(false); textVisible = true; } } destCanvas.translate(-mView.getScrollX() + DRAG_BITMAP_PADDING / 2, -mView.getScrollY() + DRAG_BITMAP_PADDING / 2); destCanvas.clipRect(clipRect, Op.REPLACE); mView.draw(destCanvas); // Restore text visibility of FolderIcon if necessary if (textVisible) { ((FolderIcon) mView).setTextVisible(true); } } destCanvas.restore(); }
/** * Draw the View v into the given Canvas. * * @param v the view to draw * @param destCanvas the canvas to draw on * @param padding the horizontal and vertical padding to use when drawing */ private static void drawDragView(View v, Canvas destCanvas, int padding) { final Rect clipRect = sTempRect; v.getDrawingRect(clipRect); boolean textVisible = false; destCanvas.save(); if (v instanceof TextView) { Drawable d = getTextViewIcon((TextView) v); Rect bounds = getDrawableBounds(d); clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding); destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top); d.draw(destCanvas); } else { if (v instanceof FolderIcon) { // For FolderIcons the text can bleed into the icon area, and so we need to // hide the text completely (which can't be achieved by clipping). if (((FolderIcon) v).getTextVisible()) { ((FolderIcon) v).setTextVisible(false); textVisible = true; } } destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2); destCanvas.clipRect(clipRect, Op.REPLACE); v.draw(destCanvas); // Restore text visibility of FolderIcon if necessary if (textVisible) { ((FolderIcon) v).setTextVisible(true); } } destCanvas.restore(); }
void commitSelectionRectangle(Rect rect, Op op) { ActionSelectionChange action = new ActionSelectionChange(image); action.setOldRegion(); region.op(rect, op); updatePath(); action.applyAction(); }
@Override protected void dispatchDraw(Canvas canvas) { if (showcaseX < 0 || showcaseY < 0 || isRedundant) { super.dispatchDraw(canvas); return; } boolean recalculatedCling = mShowcaseDrawer.calculateShowcaseRect(showcaseX, showcaseY); boolean recalculateText = recalculatedCling || mAlteredText; mAlteredText = false; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB && !mHasNoTarget) { Path path = new Path(); path.addCircle(showcaseX, showcaseY, showcaseRadius, Path.Direction.CW); canvas.clipPath(path, Op.DIFFERENCE); } //Draw background color canvas.drawColor(mBackgroundColor); // Draw the showcase drawable if (!mHasNoTarget) { mShowcaseDrawer.drawShowcase(canvas, showcaseX, showcaseY, scaleMultiplier, showcaseRadius); } // Draw the text on the screen, recalculating its position if necessary if (recalculateText) { mTextDrawer.calculateTextPosition(canvas.getWidth(), canvas.getHeight(), this); } mTextDrawer.draw(canvas, recalculateText); super.dispatchDraw(canvas); }
@Override protected void dispatchDraw(Canvas canvas) { if (showcaseX < 0 || showcaseY < 0 || isRedundant) { super.dispatchDraw(canvas); return; } boolean recalculatedCling = mShowcaseDrawer.calculateShowcaseRect(showcaseX, showcaseY); boolean recalculateText = recalculatedCling || mAlteredText; mAlteredText = false; if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.HONEYCOMB && !mHasNoTarget) { Path path = new Path(); path.addCircle(showcaseX, showcaseY, showcaseRadius, Path.Direction.CW); canvas.clipPath(path, Op.DIFFERENCE); } //Draw background color canvas.drawColor(mBackgroundColor); // Draw the showcase drawable if (!mHasNoTarget) { mShowcaseDrawer .drawShowcase(canvas, showcaseX, showcaseY, scaleMultiplier, showcaseRadius); } // Draw the text on the screen, recalculating its position if necessary if (recalculateText) { mTextDrawer.calculateTextPosition(canvas.getWidth(), canvas.getHeight(), this); } mTextDrawer.draw(canvas, recalculateText); super.dispatchDraw(canvas); }
protected void drawSubpatchContent(Canvas canvas) { canvas.save(); Matrix matrix = new Matrix(); matrix.postTranslate(x - HMargin, y - VMargin); canvas.concat(matrix); canvas.clipRect(new RectF(HMargin, VMargin, HMargin + dRect.width(), VMargin + dRect.height()), Op.INTERSECT); for(Widget widget : widgets) { widget.draw(canvas); } canvas.restore(); }
public void draw(Canvas canvas) { canvas.save(); canvas.clipRect(dRect.left, dRect.top, dRect.right, dRect.bottom + 1, Op.INTERSECT); if (bg.draw(canvas)) { paint.setColor(bgcolor); paint.setStyle(Paint.Style.FILL); canvas.drawRect(dRect,paint); paint.setColor(fgcolor); paint.setStrokeWidth(1); canvas.drawLine(dRect.left /*+ 1*/, dRect.top, dRect.right, dRect.top, paint); canvas.drawLine(dRect.left /*+ 1*/, dRect.bottom, dRect.right, dRect.bottom, paint); canvas.drawLine(dRect.left, dRect.top /*+ 1*/, dRect.left, dRect.bottom, paint); canvas.drawLine(dRect.right, dRect.top /*+ 1*/, dRect.right, dRect.bottom, paint); paint.setColor(fgcolor); paint.setStrokeWidth(3); if (horizontal) { canvas.drawLine(Math.round(dRect.left + getNormalizedPosition() * dRect.width()), Math.round(dRect.top /*+ 2*/), Math.round(dRect.left + getNormalizedPosition() * dRect.width()), Math.round(dRect.bottom /*- 2*/), paint); } else { canvas.drawLine(Math.round(dRect.left /*+ 2*/), Math.round(dRect.bottom - getNormalizedPosition() * dRect.height()), Math.round(dRect.right /*- 2*/), Math.round(dRect.bottom - getNormalizedPosition() * dRect.height()), paint); } } else if (!slider.none()) { if (horizontal) { sRect.offsetTo(getNormalizedPosition() * (dRect.width() - sRect.width()) + dRect.left, dRect.top); } else { sRect.offsetTo(dRect.left, (1 - getNormalizedPosition()) * (dRect.height() - sRect.height()) + dRect.top); } slider.draw(canvas,sRect); fg.draw(canvas); } canvas.restore(); drawLabel(canvas); }
/** * 画圆形窗口 * * @param canvas * @param view * @return */ private Canvas drawCircleWingdow(Canvas canvas, View view) { canvas.save(); Path path = new Path(); // 计算矩形区域的宽度 int witdh = getClipWindowWidth(); // 中心坐标 int centerX = getWidth() / 2; int centerY = getHeight() / 2; // 半径 int radius = witdh / 2; Paint paint = new Paint(); paint.setAntiAlias(true); paint.setColor(Color.parseColor("#aa000000")); paint.setStyle(Style.FILL); Rect viewDrawingRect = new Rect(); view.getDrawingRect(viewDrawingRect); path.addCircle(centerX, centerY, radius, Direction.CW); // 画外边 canvas.clipPath(path, Op.DIFFERENCE); canvas.drawRect(viewDrawingRect, paint); // TODO 绘制外边框 // 绘制外边框 // canvas.restore(); // canvas.clipPath(path,Op.INTERSECT); // paint.setColor(mBorderColor); // paint.setStrokeWidth(mBorderWidth); // paint.setStyle(Style.STROKE); // canvas.drawRect(viewDrawingRect, paint); canvas.restore(); return canvas; }
private void doBitmap(Canvas canvas, float x, float y, float width, float height, byte[] bytes) { Bitmap bm = BitmapFactory.decodeByteArray(bytes, 0, bytes.length); if (bm != null) { // Log.d(TAG, String.format("Image %f x %f %s", width, height, bm)); bm.prepareToDraw(); Paint paint = new Paint(Paint.FILTER_BITMAP_FLAG | Paint.ANTI_ALIAS_FLAG); RectF rect = new RectF(x, y, x+width, y+height); canvas.clipRect(rect, Op.REPLACE); canvas.drawBitmap(bm, null, rect, paint); bm.recycle(); } }
/** * Draw the View v into the given Canvas. * * @param v the view to draw * @param destCanvas the canvas to draw on * @param padding the horizontal and vertical padding to use when drawing */ private static void drawDragView(View v, Canvas destCanvas, int padding) { final Rect clipRect = sTempRect; v.getDrawingRect(clipRect); boolean textVisible = false; destCanvas.save(); if (v instanceof TextView) { Drawable d = ((TextView) v).getCompoundDrawables()[1]; Rect bounds = getDrawableBounds(d); clipRect.set(0, 0, bounds.width() + padding, bounds.height() + padding); destCanvas.translate(padding / 2 - bounds.left, padding / 2 - bounds.top); d.draw(destCanvas); } else { if (v instanceof FolderIcon) { // For FolderIcons the text can bleed into the icon area, and so we need to // hide the text completely (which can't be achieved by clipping). if (((FolderIcon) v).getTextVisible()) { ((FolderIcon) v).setTextVisible(false); textVisible = true; } } destCanvas.translate(-v.getScrollX() + padding / 2, -v.getScrollY() + padding / 2); destCanvas.clipRect(clipRect, Op.REPLACE); v.draw(destCanvas); // Restore text visibility of FolderIcon if necessary if (textVisible) { ((FolderIcon) v).setTextVisible(true); } } destCanvas.restore(); }
@Override public void setClip_arrowSpace(Canvas canvas) { /* Note: if we need midpt to depend on button locations or something, * we can move the logic of this method to GUIHandler * (in the same manner as timeToY and pitchToX) */ boolean fallingDown = false; switch (Tools.gameMode) { case Tools.STANDARD: fallingDown = false; break; case Tools.REVERSE: fallingDown = true; break; case Tools.OSU_MOD: setClip_screen(canvas); return; } int ymin, ymax, midpt; switch (noteAppearance) { case 1: //Hidden (appear, then disappear) midpt = Tools.screen_h / 2 - Tools.button_h; ymin = fallingDown ? 0 : (Tools.screen_h - midpt); ymax = fallingDown ? midpt : Tools.screen_h; break; case 2: //Sudden (appear very late) midpt = Tools.screen_h / 2 - Tools.button_h; ymin = fallingDown ? midpt : 0; ymax = fallingDown ? Tools.screen_h : (Tools.screen_h - midpt); break; case 3: // Invisible (never appear) ymin = -1; ymax = -1; break; case 0: default: //Visible (normal) ymin = 0; ymax = Tools.screen_h; break; } canvas.clipRect(0, ymin, Tools.screen_w, ymax, Op.REPLACE); }
protected static void clipArea1(float angle, int r, Canvas canvas) { if(angle > 45)angle = 45; mPath.reset(); mPath.moveTo(r, r); mPath.lineTo(r, 0); mPath.lineTo((int)(r + r*Math.tan(getRadian(angle))), 0); Log.d("ClipCircleArea","r:"+r+" dot:"+(int)(r + r*Math.tan(getRadian(angle)))); mPath.lineTo(r, r); canvas.clipPath(mPath,Op.UNION); }
protected static void clipArea2(float angle, int r, Canvas canvas) { if(angle > 90)angle = 90; mPath.reset(); mPath.moveTo(r, r); mPath.lineTo(2*r, 0); mPath.lineTo(2*r,(int)( r - r*Math.tan(getRadian(90 - angle)))); mPath.lineTo(r, r); canvas.clipPath(mPath, Op.UNION); }
protected static void clipArea3(float angle, int r, Canvas canvas) { if(angle > 135)angle = 135; mPath.reset(); mPath.moveTo(r, r); mPath.lineTo(2*r, r); mPath.lineTo(2*r, (int)(r + r*Math.tan(getRadian(angle-90)))); mPath.lineTo(r, r); canvas.clipPath(mPath, Op.UNION); }
protected static void clipArea4(float angle, int r, Canvas canvas) { if(angle > 180)angle = 180; mPath.reset(); mPath.moveTo(r, r); mPath.lineTo(2*r, 2*r); mPath.lineTo((int)(r + r * Math.tan(getRadian(180-angle))) , 2*r); mPath.lineTo(r, r); canvas.clipPath(mPath, Op.UNION); }
protected static void clipArea5(float angle, int r, Canvas canvas) { if(angle > 225)angle = 225; mPath.reset(); mPath.moveTo(r, r); mPath.lineTo(r, 2*r); mPath.lineTo((int)(r - r*Math.tan(getRadian(angle-180))), 2*r); mPath.lineTo(r, r); canvas.clipPath(mPath, Op.UNION); }
protected static void clipArea6(float angle, int r, Canvas canvas) { if(angle > 270)angle = 270; mPath.reset(); mPath.moveTo(r, r); mPath.lineTo(0, 2*r); mPath.lineTo(0, (int)(r + r*Math.tan(getRadian(270-angle)))); mPath.lineTo(r, r); canvas.clipPath(mPath, Op.UNION); }