protected override void OnDraw(Canvas canvas) { Android.Graphics.Drawable.Drawable drawable = GetDrawable(); if (drawable is BitmapDrawable) { RectF rectF = new RectF(drawable.GetBounds()); int restoreCount = canvas.SaveLayer(rectF, null, Canvas.AllSaveFlag); GetImageMatrix().MapRect(rectF); Paint paint = ((BitmapDrawable)drawable).GetPaint(); paint.SetAntiAlias(true); paint.SetColor(unchecked((int)(0xff000000))); canvas.DrawARGB(0, 0, 0, 0); canvas.DrawRoundRect(rectF, Radius, Radius, paint); Xfermode restoreMode = paint.GetXfermode(); paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn)); base.OnDraw(canvas); // Restore paint and canvas paint.SetXfermode(restoreMode); canvas.RestoreToCount(restoreCount); } else { base.OnDraw(canvas); } }
protected override void Draw(Canvas canvas, Rect bounds) { int saveCount = canvas.Save(); for (int i = 0; i < mBallCount; i++) { if (i == mSwapIndex) { mPaint.SetStyle(Paint.Style.Fill); canvas.DrawCircle(mBallSideOffsets + mBallRadius * (i * 2 + 1) + i * mBallInterval + mSwapBallOffsetX, mBallCenterY - mSwapBallOffsetY, mBallRadius, mPaint); } else if (i == (mSwapIndex + 1) % mBallCount) { mPaint.SetStyle(Paint.Style.Stroke); canvas.DrawCircle(mBallSideOffsets + mBallRadius * (i * 2 + 1) + i * mBallInterval - mSwapBallOffsetX, mBallCenterY + mSwapBallOffsetY, mBallRadius - mStrokeWidth / 2, mPaint); } else { mPaint.SetStyle(Paint.Style.Stroke); canvas.DrawCircle(mBallSideOffsets + mBallRadius * (i * 2 + 1) + i * mBallInterval, mBallCenterY, mBallRadius - mStrokeWidth / 2, mPaint); } } canvas.RestoreToCount(saveCount); }
protected override void Draw(Canvas canvas, Rect bounds) { int saveCount = canvas.Save(); for (int i = 1; i < mBallCount - 1; i++) { mPaint.Alpha = MAX_ALPHA; canvas.DrawCircle(mBallRadius * (i * 2 - 1) + mBallSideOffsets, mBallCenterY, mBallRadius, mPaint); mOvalRect.Set(mBallRadius * (i * 2 - 2) + mBallSideOffsets, Height - mOvalVerticalRadius * 2, mBallRadius * (i * 2) + mBallSideOffsets, Height); mPaint.Alpha = OVAL_ALPHA; canvas.DrawOval(mOvalRect, mPaint); } //draw the first ball mPaint.Alpha = MAX_ALPHA; canvas.DrawCircle(mBallSideOffsets - mBallRadius - mLeftBallMoveXOffsets, mBallCenterY - mLeftBallMoveYOffsets, mBallRadius, mPaint); mOvalRect.Set(mBallSideOffsets - mBallRadius - mBallRadius * mLeftOvalShapeRate - mLeftBallMoveXOffsets, Height - mOvalVerticalRadius - mOvalVerticalRadius * mLeftOvalShapeRate, mBallSideOffsets - mBallRadius + mBallRadius * mLeftOvalShapeRate - mLeftBallMoveXOffsets, Height - mOvalVerticalRadius + mOvalVerticalRadius * mLeftOvalShapeRate); mPaint.Alpha = OVAL_ALPHA; canvas.DrawOval(mOvalRect, mPaint); //draw the last ball mPaint.Alpha = MAX_ALPHA; canvas.DrawCircle(mBallRadius * (mBallCount * 2 - 3) + mBallSideOffsets + mRightBallMoveXOffsets, mBallCenterY - mRightBallMoveYOffsets, mBallRadius, mPaint); mOvalRect.Set(mBallRadius * (mBallCount * 2 - 3) - mBallRadius * mRightOvalShapeRate + mBallSideOffsets + mRightBallMoveXOffsets, Height - mOvalVerticalRadius - mOvalVerticalRadius * mRightOvalShapeRate, mBallRadius * (mBallCount * 2 - 3) + mBallRadius * mRightOvalShapeRate + mBallSideOffsets + mRightBallMoveXOffsets, Height - mOvalVerticalRadius + mOvalVerticalRadius * mRightOvalShapeRate); mPaint.Alpha = OVAL_ALPHA; canvas.DrawOval(mOvalRect, mPaint); canvas.RestoreToCount(saveCount); }
protected override void OnDraw (Canvas canvas) { int sc = canvas.SaveLayer(mBoundsF, mCopyPaint, SaveFlags.HasAlphaLayer | SaveFlags.FullColorLayer); mMaskDrawable.Draw(canvas); canvas.SaveLayer(mBoundsF, mMaskedPaint, 0); base.OnDraw(canvas); canvas.RestoreToCount(sc); mBorderDrawable.Draw(canvas); }
protected override void Draw(Canvas canvas, Rect bounds) { int SaveCount = canvas.Save(); RectF arcBounds = mCurrentBounds; arcBounds.Set(bounds); //Draw background canvas.DrawColor(new Color(mCurrentBackgroundColor)); //Draw reveal circle if (mRevealCircleRadius > 0) { mPaint.Color = new Color(mCurrentBackgroundColor == mBackgroundColor ? mBackgroundDeepColor : mBackgroundColor); canvas.DrawCircle(arcBounds.CenterX(), arcBounds.CenterY(), mRevealCircleRadius, mPaint); } //Draw mother oval mPaint.Color = new Color(mCurrentOvalColor); int motherSaveCount = canvas.Save(); canvas.Rotate(mRotateDegrees, mMotherPosition[0], mMotherPosition[1]); canvas.DrawPath(CreateMotherPath(), mPaint); canvas.DrawPath(CreateLinkPath(), mPaint); canvas.RestoreToCount(motherSaveCount); int childSaveCount = canvas.Save(); canvas.Rotate(mRotateDegrees, mChildPosition[0], mChildPosition[1]); canvas.DrawPath(CreateChildPath(), mPaint); canvas.RestoreToCount(childSaveCount); canvas.RestoreToCount(SaveCount); // canvas.DrawPath(mMotherMovePath, mPaint); // canvas.DrawPath(mChildMovePath, mPaint); // canvas.DrawLine(mMotherPosition[0], mMotherPosition[1], mChildPosition[0], mChildPosition[1], mPaint); }
protected override void Draw(Canvas canvas, Rect bounds) { int saveCount = canvas.Save(); mTempBounds.Set(Bounds); mTempBounds.Inset(mStrokeInset, mStrokeInset); canvas.Rotate(mGroupRotation, mTempBounds.CenterX(), mTempBounds.CenterY()); if (mSwipeDegrees != 0) { mPaint.Color = new Color(mCurrentColor); canvas.DrawArc(mTempBounds, mStartDegrees, mSwipeDegrees, false, mPaint); } canvas.RestoreToCount(saveCount); }
protected override bool DrawChild(Canvas canvas, View child, long drawingTime) { if(!ClipOutlines && Target != null) return base.DrawChild(canvas, child, drawingTime); var state = canvas.Save(); RevealPath.Reset(); RevealPath.AddCircle(CentreX, CentreY, getRadius(), Path.Direction.Cw); canvas.ClipPath(RevealPath); var isInvalid = base.DrawChild(canvas, child, drawingTime); canvas.RestoreToCount(state); return isInvalid; }
protected override void Draw(Canvas canvas, Rect bounds) { RectF arcBounds = mTempBounds; arcBounds.Set(bounds); arcBounds.Inset(mStrokeInset, mStrokeInset); mCurrentBounds.Set(arcBounds); int saveCount = canvas.Save(); //draw circle trim float startAngle = (mStartTrim + mRotation) * 360; float endAngle = (mEndTrim + mRotation) * 360; float sweepAngle = endAngle - startAngle; if (sweepAngle != 0) { mPaint.Color = new Color(mColor); mPaint.SetStyle(Paint.Style.Stroke); canvas.DrawArc(arcBounds, startAngle, sweepAngle, false, mPaint); } //draw water wave if (mWaveProgress < 1.0f) { var nColor = new Color(mColor); mPaint.Color = Color.Argb((int)(Color.GetAlphaComponent(mColor) * (1.0f - mWaveProgress)), Color.GetRedComponent(mColor), Color.GetGreenComponent(mColor), Color.GetBlueComponent(mColor)); mPaint.SetStyle(Paint.Style.Stroke); float radius = Math.Min(arcBounds.Width(), arcBounds.Height()) / 2.0f; canvas.DrawCircle(arcBounds.CenterX(), arcBounds.CenterY(), radius * (1.0f + mWaveProgress), mPaint); } //draw ball bounce if (mPathMeasure != null) { mPaint.Color = new Color(mBallColor); mPaint.SetStyle(Paint.Style.Fill); canvas.DrawCircle(mCurrentPosition[0], mCurrentPosition[1], mSkipBallSize * mScale, mPaint); } canvas.RestoreToCount(saveCount); }
protected override void Draw(Canvas canvas, Rect bounds) { int saveCount = canvas.Save(); mTempBounds.Set(Bounds); mTempBounds.Inset(mStrokeInset, mStrokeInset); canvas.Rotate(mGroupRotation, mTempBounds.CenterX(), mTempBounds.CenterY()); for (int i = 0; i < 3; i++) { if (mLevelSwipeDegrees[i] != 0) { mPaint.Color = new Color(mLevelColors[i]); canvas.DrawArc(mTempBounds, mEndDegrees, mLevelSwipeDegrees[i], false, mPaint); } } canvas.RestoreToCount(saveCount); }
protected override void Draw(Canvas canvas, Rect bounds) { int saveCount = canvas.Save(); mTempBounds.Set(bounds); mTempBounds.Inset(mStrokeInset, mStrokeInset); mCurrentBounds.Set(mTempBounds); float outerCircleRadius = Math.Min(mTempBounds.Height(), mTempBounds.Width()) / 2.0f; float interCircleRadius = outerCircleRadius / 2.0f; float centerRingWidth = interCircleRadius - mStrokeWidth / 2; mPaint.SetStyle(Paint.Style.Stroke); mPaint.Color = new Color(mColor); mPaint.StrokeWidth = mStrokeWidth; canvas.DrawCircle(mTempBounds.CenterX(), mTempBounds.CenterY(), outerCircleRadius, mPaint); mPaint.SetStyle(Paint.Style.Fill); canvas.DrawCircle(mTempBounds.CenterX(), mTempBounds.CenterY(), interCircleRadius * mScale, mPaint); if (mRotation != 0) { mPaint.Color = new Color(mArcColor); mPaint.SetStyle(Paint.Style.Stroke); //strokeWidth / 2.0f + mStrokeWidth / 2.0f is the center of the inter circle width mTempBounds.Inset(centerRingWidth / 2.0f + mStrokeWidth / 2.0f, centerRingWidth / 2.0f + mStrokeWidth / 2.0f); mPaint.StrokeWidth = centerRingWidth; canvas.DrawArc(mTempBounds, RING_START_ANGLE, mRotation, false, mPaint); } mPaint.Color = new Color(mColor); mPaint.SetStyle(Paint.Style.Fill); for (int i = 0; i < NUM_POINTS; i++) { canvas.Rotate(i * DANCE_INTERVAL_ANGLE, POINT_X[i], POINT_Y[i]); RectF rectF = new RectF(POINT_X[i] - mDanceBallRadius - mShapeChangeWidth / 2.0f, POINT_Y[i] - mDanceBallRadius - mShapeChangeHeight / 2.0f, POINT_X[i] + mDanceBallRadius + mShapeChangeWidth / 2.0f, POINT_Y[i] + mDanceBallRadius + mShapeChangeHeight / 2.0f); canvas.DrawOval(rectF, mPaint); canvas.Rotate(-i * DANCE_INTERVAL_ANGLE, POINT_X[i], POINT_Y[i]); } canvas.RestoreToCount(saveCount); }
protected override void Draw(Canvas canvas, Rect bounds) { int saveCount = canvas.Save(); RectF arcBounds = mTempBounds; arcBounds.Set(bounds); mPaint.Color = new Color(mColor); mPaint.SetStyle(Paint.Style.Stroke); canvas.DrawPath(CreateLeftEyeCircle(arcBounds, mLeftEyeCircleOffsetY), mPaint); canvas.DrawPath(CreateRightEyeCircle(arcBounds, mRightEyeCircleOffsetY), mPaint); mPaint.SetStyle(Paint.Style.Fill); //create left eye ball canvas.DrawOval(CreateLeftEyeBall(arcBounds, mLeftEyeBallOffsetY), mPaint); //create right eye ball canvas.DrawOval(CreateRightEyeBall(arcBounds, mRightEyeBallOffsetY), mPaint); canvas.RestoreToCount(saveCount); }
protected override void Draw(Canvas canvas, Rect bounds) { int saveCount = canvas.Save(); mTempBounds.Set(Bounds); mTempBounds.Inset(mStrokeInSet, mStrokeInSet); canvas.Rotate(mGroupRotation, mTempBounds.CenterX(), mTempBounds.CenterY()); if (mSwipeDegrees != 0) { for (int i = 0; i < mColors.Length; i++) { mPaint.StrokeWidth = mStrokeWidth / (i + 1); mPaint.Color = new Color(mColors[i]); canvas.DrawArc(CreateArcBounds(mTempBounds, i), mStartDegrees + DEGREE_180 * (i % 2), mSwipeDegrees, false, mPaint); } } canvas.RestoreToCount(saveCount); }
protected override void Draw(Canvas canvas, Rect bounds) { int saveCount = canvas.Save(); RectF arcBounds = mCurrentBounds; arcBounds.Set(bounds); //draw draw gas tube mPaint.Color = new Color(mGasTubeColor); mPaint.SetStyle(Paint.Style.Stroke); mPaint.StrokeWidth = mStrokeWidth; canvas.DrawPath(CreateGasTubePath(mGasTubeBounds), mPaint); //draw balloon mPaint.Color = new Color(mBalloonColor); mPaint.SetStyle(Paint.Style.FillAndStroke); canvas.DrawPath(CreateBalloonPath(mBalloonBounds, mProgress), mPaint); //draw progress mPaint.Color = new Color(mGasTubeColor); mPaint.TextSize = mTextSize; mPaint.StrokeWidth = mStrokeWidth / 5.0f; canvas.DrawText(mProgressText, arcBounds.CenterX() - mProgressBounds.Width() / 2.0f, mGasTubeBounds.CenterY() + mProgressBounds.Height() / 2.0f, mPaint); //draw cannula mPaint.Color = new Color(mCannulaColor); mPaint.SetStyle(Paint.Style.Stroke); mPaint.StrokeWidth = mStrokeWidth; canvas.DrawPath(CreateCannulaHeadPath(mCannulaBounds), mPaint); mPaint.SetStyle(Paint.Style.Fill); canvas.DrawPath(CreateCannulaBottomPath(mCannulaBounds), mPaint); //draw pipe body mPaint.Color = new Color(mPipeBodyColor); mPaint.SetStyle(Paint.Style.Fill); canvas.DrawRoundRect(mPipeBodyBounds, mRectCornerRadius, mRectCornerRadius, mPaint); canvas.RestoreToCount(saveCount); }
protected override void Draw(Canvas canvas, Rect bounds) { int saveCount = canvas.Save(); mTempBounds.Set(Bounds); mTempBounds.Inset(mStrokeInset, mStrokeInset); mTempBounds.Inset(mTempBounds.Width() * (1.0f - mScale) / 2.0f, mTempBounds.Width() * (1.0f - mScale) / 2.0f); canvas.Rotate(mGroupRotation, mTempBounds.CenterX(), mTempBounds.CenterY()); mPaint.Color = new Color(mColor); mPaint.Alpha = (int)(MAX_ALPHA * mScale); mPaint.StrokeWidth = mStrokeWidth * mScale; if (mSwipeDegrees != 0) { for (int i = 0; i < mGearCount; i++) { canvas.DrawArc(mTempBounds, mStartDegrees + DEGREE_360 / mGearCount * i, mSwipeDegrees, false, mPaint); } } canvas.RestoreToCount(saveCount); }
protected override bool DrawChild(Canvas canvas, View child, long drawingTime) { var lp = (LayoutParams) child.LayoutParameters; var save = canvas.Save(SaveFlags.Clip); var drawScrim = false; if (_canSlide && !lp.Slideable && _slideableView != null) { if (!OverlayContent) { canvas.GetClipBounds(_tmpRect); if (_isSlidingUp) _tmpRect.Bottom = Math.Min(_tmpRect.Bottom, _slideableView.Top); else _tmpRect.Top = Math.Max(_tmpRect.Top, _slideableView.Bottom); canvas.ClipRect(_tmpRect); } if (_slideOffset < 1) drawScrim = true; } var result = base.DrawChild(canvas, child, drawingTime); canvas.RestoreToCount(save); if (drawScrim) { var baseAlpha = (_coveredFadeColor.ToArgb() & 0xff000000) >> 24; var imag = (int) (baseAlpha * (1 - _slideOffset)); var color = imag << 24 | (_coveredFadeColor.ToArgb() & 0xffffff); _coveredFadePaint.Color = new Color(color); canvas.DrawRect(_tmpRect, _coveredFadePaint); } return result; }
private void DrawRing(Canvas c) { var sc = c.Save(); c.Rotate(-this.Degree, c.Width / 2, c.Height / 2); //���ĵ� var cx = c.Width / 2; var cy = c.Height / 2; //������Բ Path ����һ�� Բ����ʾ����, ���ڿ���Բ var pInner = new Path(); pInner.AddCircle(cx, cy, this.BitmapRadius + SPACE / 2, Path.Direction.Cw); var pOut = new Path(); pOut.AddCircle(cx, cy, this.Radius, Path.Direction.Cw); c.ClipPath(pOut); c.ClipPath(pInner, Region.Op.Difference); //var color = new Color((int)(DateTime.Now.Ticks % 0xFFFFFFFF)); //c.DrawColor(color); //�ýǶȽ��������Բ�ķ�Χ var g = new SweepGradient(cx, cy, Color.Green, Color.Transparent); var paint = new Paint(); paint.SetShader(g); c.DrawCircle(cx, cy, this.Radius, paint); c.RestoreToCount(sc); }
public void draw(Canvas canvas) { int width = mBounds.Width (); int height = mBounds.Height(); int cx = width / 2; int cy = height / 2; Boolean drawTriggerWhileFinishing = false; int restoreCount = canvas.Save(); canvas.ClipRect(mBounds); if (mRunning || (mFinishTime > 0)) { long now = AnimationUtils.CurrentAnimationTimeMillis(); long elapsed = (now - mStartTime) % ANIMATION_DURATION_MS; long iterations = (now - mStartTime) / ANIMATION_DURATION_MS; float rawProgress = (elapsed / (ANIMATION_DURATION_MS / 100f)); // If we're not running anymore, that means we're running through // the finish animation. if (!mRunning) { // If the finish animation is done, don't draw anything, and // don't repost. if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) { mFinishTime = 0; return; } // Otherwise, use a 0 opacity alpha layer to clear the animation // from the inside out. This layer will prevent the circles from // drawing within its bounds. long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS; float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f)); float pct = (finishProgress / 100f); // Radius of the circle is half of the screen. float clearRadius = width / 2;//* INTERPOLATOR.getInterpolation(pct); mClipRect.Set(cx - clearRadius, 0, cx + clearRadius, height); canvas.SaveLayerAlpha(mClipRect, 0, 0); // Only draw the trigger if there is a space in the center of // this refreshing view that needs to be filled in by the // trigger. If the progress view is just still animating, let it // continue animating. drawTriggerWhileFinishing = true; } // First fill in with the last color that would have finished drawing. if (iterations == 0) { canvas.DrawColor (Android.Graphics.Color.Blue); } else { if (rawProgress >= 0 && rawProgress < 25) { canvas.DrawColor(Android.Graphics.Color.AliceBlue); } else if (rawProgress >= 25 && rawProgress < 50) { canvas.DrawColor (Android.Graphics.Color.Blue); } else if (rawProgress >= 50 && rawProgress < 75) { canvas.DrawColor (Android.Graphics.Color.BlueViolet); } else { canvas.DrawColor (Android.Graphics.Color.CadetBlue); } } // Then draw up to 4 overlapping concentric circles of varying radii, based on how far // along we are in the cycle. // progress 0-50 draw mColor2 // progress 25-75 draw mColor3 // progress 50-100 draw mColor4 // progress 75 (wrap to 25) draw mColor1 if ((rawProgress >= 0 && rawProgress <= 25)) { float pct = (((rawProgress + 25) * 2) / 100f); drawCircle(canvas, cx, cy, mColor1, pct); } if (rawProgress >= 0 && rawProgress <= 50) { float pct = ((rawProgress * 2) / 100f); drawCircle(canvas, cx, cy, mColor2, pct); } if (rawProgress >= 25 && rawProgress <= 75) { float pct = (((rawProgress - 25) * 2) / 100f); drawCircle(canvas, cx, cy, mColor3, pct); } if (rawProgress >= 50 && rawProgress <= 100) { float pct = (((rawProgress - 50) * 2) / 100f); drawCircle(canvas, cx, cy, mColor4, pct); } if ((rawProgress >= 75 && rawProgress <= 100)) { float pct = (((rawProgress - 75) * 2) / 100f); drawCircle(canvas, cx, cy, mColor1, pct); } if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) { // There is some portion of trigger to draw. Restore the canvas, // then draw the trigger. Otherwise, the trigger does not appear // until after the bar has finished animating and appears to // just jump in at a larger width than expected. canvas.RestoreToCount(restoreCount); restoreCount = canvas.Save(); canvas.ClipRect(mBounds); drawTrigger(canvas, cx, cy); } // Keep running until we finish out the last cycle. ViewCompat.PostInvalidateOnAnimation(mParent); } else { // Otherwise if we're in the middle of a trigger, draw that. if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) { drawTrigger(canvas, cx, cy); } } canvas.RestoreToCount(restoreCount); }
private void DrawBitmap(Canvas c, Bitmap bmp) { var sc = c.Save(); this.Degree = this.Degree % 360 + DEGREE_STEP; //Ҫ����ת����ͼ����Ч�� c.Rotate(this.Degree, c.Width / 2, c.Height / 2); //���ĵ� var cx = c.Width / 2; var cy = c.Height / 2; //����ʾ��Χ, ָ���뾶��Բ var path = new Path(); path.AddCircle(cx, cy, this.BitmapRadius, Path.Direction.Cw); c.ClipPath(path); c.DrawColor(Color.White); //ͼƬ�Ļ��Ʒ�Χ var w = (this.ShowType == ShowTypes.Inner ? this.IWH : this.OWH) / 2; var rect = new Rect(cx - w, cy - w, cx + w, cy + w); //����ͼƬ var paint = new Paint(); //srcΪnull, ��������ͼƬ��ΪԴ c.DrawBitmap(bmp, null, rect, paint); c.RestoreToCount(sc); }
public override void Draw(Canvas canvas) { Rect bounds = Bounds; int saveCount = canvas.Save(); canvas.Rotate(mRotation, bounds.ExactCenterX(), bounds.ExactCenterY()); mRing.Draw(canvas, bounds); canvas.RestoreToCount(saveCount); }