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); }
public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint, RectF pRect) { float? centerX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_CENTER_X); float? centerY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_CENTER_Y); float? radiusX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_X); float? radiusY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_Y); if (centerX != null && centerY != null && radiusX != null && radiusY != null) { pRect.Set(centerX.Value - radiusX.Value, centerY.Value - radiusY.Value, centerX.Value + radiusX.Value, centerY.Value + radiusY.Value); bool fill = pSVGPaint.setFill(pSVGProperties); if (fill) { pCanvas.DrawOval(pRect, pSVGPaint.getPaint()); } bool stroke = pSVGPaint.setStroke(pSVGProperties); if (stroke) { pCanvas.DrawOval(pRect, pSVGPaint.getPaint()); } if(fill || stroke) { pSVGPaint.ensureComputedBoundsInclude(centerX.Value - radiusX.Value, centerY.Value - radiusY.Value); pSVGPaint.ensureComputedBoundsInclude(centerX.Value + radiusX.Value, centerY.Value + radiusY.Value); } } }
public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint, RectF pRect) { float x = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_X, 0f); float y = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_Y, 0f); float width = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_WIDTH, 0f); float height = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_HEIGHT, 0f); pRect.Set(x, y, x + width, y + height); float? rX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_X); float? rY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_Y); bool rXSpecified = rX != null && rX >= 0; bool rYSpecified = rY != null && rY >= 0; bool rounded = rXSpecified || rYSpecified; float rx; float ry; if(rXSpecified && rYSpecified) { rx = Math.Min(rX.Value, width * 0.5f); ry = Math.Min(rY.Value, height * 0.5f); } else if(rXSpecified) { ry = rx = Math.Min(rX.Value, width * 0.5f); } else if(rYSpecified) { rx = ry = Math.Min(rY.Value, height * 0.5f); } else { rx = 0; ry = 0; } bool fill = pSVGPaint.setFill(pSVGProperties); if (fill) { if(rounded) { pCanvas.DrawRoundRect(pRect, rx, ry, pSVGPaint.getPaint()); } else { pCanvas.DrawRect(pRect, pSVGPaint.getPaint()); } } bool stroke = pSVGPaint.setStroke(pSVGProperties); if (stroke) { if(rounded) { pCanvas.DrawRoundRect(pRect, rx, ry, pSVGPaint.getPaint()); } else { pCanvas.DrawRect(pRect, pSVGPaint.getPaint()); } } if(fill || stroke) { pSVGPaint.ensureComputedBoundsInclude(x, y, width, height); } }
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); }
private RectF CreateArcBounds(RectF sourceArcBounds, int index) { int intervalWidth = 0; for (int i = 0; i < index; i++) { intervalWidth += (int)(mStrokeWidth / (i + 1.0f) * 1.5f); } int arcBoundsLeft = (int)(sourceArcBounds.Left + intervalWidth); int arcBoundsTop = (int)(sourceArcBounds.Top + intervalWidth); int arcBoundsRight = (int)(sourceArcBounds.Right - intervalWidth); int arcBoundsBottom = (int)(sourceArcBounds.Bottom - intervalWidth); mTempArcBounds.Set(arcBoundsLeft, arcBoundsTop, arcBoundsRight, arcBoundsBottom); return(mTempArcBounds); }
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(); 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 internal override void ComputeRender(float renderProgress) { RectF arcBounds = mCurrentBounds; //compute gas tube bounds mGasTubeBounds.Set(arcBounds.CenterX() - mGasTubeWidth / 2.0f, arcBounds.CenterY(), arcBounds.CenterX() + mGasTubeWidth / 2.0f, arcBounds.CenterY() + mGasTubeHeight); //compute pipe body bounds mPipeBodyBounds.Set(arcBounds.CenterX() + mGasTubeWidth / 2.0f - mPipeBodyWidth / 2.0f, arcBounds.CenterY() - mPipeBodyHeight, arcBounds.CenterX() + mGasTubeWidth / 2.0f + mPipeBodyWidth / 2.0f, arcBounds.CenterY()); //compute cannula bounds mCannulaBounds.Set(arcBounds.CenterX() + mGasTubeWidth / 2.0f - mCannulaWidth / 2.0f, arcBounds.CenterY() - mCannulaHeight - mCannulaOffsetY, arcBounds.CenterX() + mGasTubeWidth / 2.0f + mCannulaWidth / 2.0f, arcBounds.CenterY() - mCannulaOffsetY); //compute balloon bounds float insetX = mBalloonWidth * 0.333f * (1 - mProgress); float insetY = mBalloonHeight * 0.667f * (1 - mProgress); mBalloonBounds.Set(arcBounds.CenterX() - mGasTubeWidth / 2.0f - mBalloonWidth / 2.0f + insetX, arcBounds.CenterY() - mBalloonHeight + insetY, arcBounds.CenterX() - mGasTubeWidth / 2.0f + mBalloonWidth / 2.0f - insetX, arcBounds.CenterY()); if (renderProgress <= START_INHALE_DURATION_OFFSET) { mCannulaBounds.Offset(0, -mCannulaMaxOffsetY * renderProgress / START_INHALE_DURATION_OFFSET); mProgress = 0.0f; mProgressText = 10 + PERCENT_SIGN; mPaint.TextSize = mTextSize; mPaint.GetTextBounds(mProgressText, 0, mProgressText.Length, mProgressBounds); } else { float exhaleProgress = ACCELERATE_INTERPOLATOR.GetInterpolation(1.0f - (renderProgress - START_INHALE_DURATION_OFFSET) / (1.0f - START_INHALE_DURATION_OFFSET)); mCannulaBounds.Offset(0, -mCannulaMaxOffsetY * exhaleProgress); mProgress = 1.0f - exhaleProgress; mProgressText = AdjustProgress((int)(exhaleProgress * 100.0f)) + PERCENT_SIGN; mPaint.TextSize = mTextSize; mPaint.GetTextBounds(mProgressText, 0, mProgressText.Length, mProgressBounds); } }
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 void OnSizeChanged (int w, int h, int oldW, int oldH) { HEIGHT = h; WIDTH = w; HALF_WIDTH = (int)Math.Round ((Double)w / 2); HALF_HEIGHT = (int)(Math.Round ((Double)h / 2)); //int OFFSET = mCenterOval.Width () / 3.0f; mCenterOval = new RectF (); //float OFFSET = 140f; //Change the OFFSET to relative value according to the screen width float OFFSET = WIDTH / 5; //mCenterOval.Set (OFFSET, OFFSET, WIDTH - OFFSET, WIDTH - OFFSET); //move the mCenterOval a little bit up mCenterOval.Set (OFFSET, OFFSET * (float)0.5, WIDTH - OFFSET, WIDTH - (float)1.5 * OFFSET); mCx = (int)Math.Round (mCenterOval.CenterX ()); mCy = (int)Math.Round (mCenterOval.CenterY ()); mRadius = (int)Math.Round (mCenterOval.Width () / 2.0f); mInnerCircleRadius = mRadius - (mPaint.StrokeWidth * 0.9f); updateCircleCoordinate (mCx, 0); }