private Path CreateWaterPath(RectF waterRect, float progress) { Path path = new Path(); path.MoveTo(waterRect.Left, waterRect.Top); //Similar to the way draw the bottle's Bottom sides float radius = (waterRect.Width() - mStrokeWidth) / 2.0f; float CenterY = waterRect.Bottom - 0.86f * radius; float bottleBottomWidth = waterRect.Width() / 2.0f; RectF bodyRect = new RectF(waterRect.Left, CenterY - radius, waterRect.Right, CenterY + radius); path.AddArc(bodyRect, 187.5f, -67.5f); path.LineTo(waterRect.CenterX() - bottleBottomWidth / 2.0f, waterRect.Bottom); path.LineTo(waterRect.CenterX() + bottleBottomWidth / 2.0f, waterRect.Bottom); path.AddArc(bodyRect, 60, -67.5f); //draw the water waves float cubicXChangeSize = waterRect.Width() * 0.35f * progress; float cubicYChangeSize = waterRect.Height() * 1.2f * progress; path.CubicTo(waterRect.Left + waterRect.Width() * 0.80f - cubicXChangeSize, waterRect.Top - waterRect.Height() * 1.2f + cubicYChangeSize, waterRect.Left + waterRect.Width() * 0.55f - cubicXChangeSize, waterRect.Top - cubicYChangeSize, waterRect.Left, waterRect.Top - mStrokeWidth / 2.0f); path.LineTo(waterRect.Left, waterRect.Top); return(path); }
private Path CreateBottlePath(RectF bottleRect) { float bottleneckWidth = bottleRect.Width() * 0.3f; float bottleneckHeight = bottleRect.Height() * 0.415f; float bottleneckDecorationWidth = bottleneckWidth * 1.1f; float bottleneckDecorationHeight = bottleneckHeight * 0.167f; Path path = new Path(); //draw the Left side of the bottleneck decoration path.MoveTo(bottleRect.CenterX() - bottleneckDecorationWidth * 0.5f, bottleRect.Top); path.QuadTo(bottleRect.CenterX() - bottleneckDecorationWidth * 0.5f - bottleneckWidth * 0.15f, bottleRect.Top + bottleneckDecorationHeight * 0.5f, bottleRect.CenterX() - bottleneckWidth * 0.5f, bottleRect.Top + bottleneckDecorationHeight); path.LineTo(bottleRect.CenterX() - bottleneckWidth * 0.5f, bottleRect.Top + bottleneckHeight); //draw the Left side of the bottle's body float radius = (bottleRect.Width() - mStrokeWidth) / 2.0f; float CenterY = bottleRect.Bottom - 0.86f * radius; RectF bodyRect = new RectF(bottleRect.Left, CenterY - radius, bottleRect.Right, CenterY + radius); path.AddArc(bodyRect, 255, -135); //draw the Bottom of the bottle float bottleBottomWidth = bottleRect.Width() / 2.0f; path.LineTo(bottleRect.CenterX() - bottleBottomWidth / 2.0f, bottleRect.Bottom); path.LineTo(bottleRect.CenterX() + bottleBottomWidth / 2.0f, bottleRect.Bottom); //draw the Right side of the bottle's body path.AddArc(bodyRect, 60, -135); //draw the Right side of the bottleneck decoration path.LineTo(bottleRect.CenterX() + bottleneckWidth * 0.5f, bottleRect.Top + bottleneckDecorationHeight); path.QuadTo(bottleRect.CenterX() + bottleneckDecorationWidth * 0.5f + bottleneckWidth * 0.15f, bottleRect.Top + bottleneckDecorationHeight * 0.5f, bottleRect.CenterX() + bottleneckDecorationWidth * 0.5f, bottleRect.Top); return(path); }
protected override void Draw(Canvas canvas, Rect bounds) { int saveCount = canvas.Save(); RectF arcBounds = mCurrentBounds; arcBounds.Set(bounds); //draw bottle mPaint.SetStyle(Paint.Style.Stroke); mPaint.Color = new Color(mBottleColor); canvas.DrawPath(CreateBottlePath(mBottleBounds), mPaint); //draw water mPaint.SetStyle(Paint.Style.FillAndStroke); mPaint.Color = new Color(mWaterColor); canvas.DrawPath(CreateWaterPath(mWaterBounds, mProgress), mPaint); //draw water drop mPaint.SetStyle(Paint.Style.Fill); mPaint.Color = new Color(mWaterColor); foreach (WaterDropHolder waterDropHolder in mWaterDropHolders) { if (waterDropHolder.mNeedDraw) { canvas.DrawCircle(waterDropHolder.mInitX, waterDropHolder.mCurrentY, waterDropHolder.mRadius, mPaint); } } //draw loading text mPaint.Color = new Color(mBottleColor); canvas.DrawText(LOADING_TEXT, mBottleBounds.CenterX() - mLoadingBounds.Width() / 2.0f, mBottleBounds.Bottom + mBottleBounds.Height() * 0.2f, mPaint); canvas.RestoreToCount(saveCount); }