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 void InitWaterDropHolders(RectF bottleRect, RectF waterRect)
        {
            float bottleRadius         = bottleRect.Width() / 2.0f;
            float lowestWaterPointY    = waterRect.Top;
            float twoSidesInterval     = 0.2f * bottleRect.Width();
            float atLeastDelayDuration = 0.1f;

            float unitDuration        = 0.1f;
            float delayDurationRange  = 0.6f;
            int   radiusRandomRange   = MAX_WATER_DROP_RADIUS - MIN_WATER_DROP_RADIUS;
            float currentXRandomRange = bottleRect.Width() * 0.6f;

            for (int i = 0; i < DEFAULT_WATER_DROP_COUNT; i++)
            {
                WaterDropHolder waterDropHolder = new WaterDropHolder
                {
                    mRadius = MIN_WATER_DROP_RADIUS + mRandom.Next(radiusRandomRange),
                    mInitX  = bottleRect.Left + twoSidesInterval + (float)mRandom.NextDouble() * currentXRandomRange
                };
                waterDropHolder.mInitY         = lowestWaterPointY + waterDropHolder.mRadius / 2.0f;
                waterDropHolder.mRiseHeight    = GetMaxRiseHeight(bottleRadius, waterDropHolder.mRadius, waterDropHolder.mInitX - bottleRect.Left) * (0.2f + 0.8f * (float)mRandom.NextDouble());
                waterDropHolder.mDelayDuration = atLeastDelayDuration + (float)mRandom.NextDouble() * delayDurationRange;
                waterDropHolder.mDuration      = waterDropHolder.mRiseHeight / bottleRadius * unitDuration;

                mWaterDropHolders.Add(waterDropHolder);
            }
        }
Example #3
0
        private Path CreateWaitPath(RectF bounds)
        {
            Path path = new Path();

            //create circle
            path.MoveTo(bounds.CenterX() + mWaitCircleRadius, bounds.CenterY());

            //create w
            path.CubicTo(bounds.CenterX() + mWaitCircleRadius, bounds.CenterY() - mWaitCircleRadius * 0.5f, bounds.CenterX() + mWaitCircleRadius * 0.3f, bounds.CenterY() - mWaitCircleRadius, bounds.CenterX() - mWaitCircleRadius * 0.35f, bounds.CenterY() + mWaitCircleRadius * 0.5f);
            path.QuadTo(bounds.CenterX() + mWaitCircleRadius, bounds.CenterY() - mWaitCircleRadius, bounds.CenterX() + mWaitCircleRadius * 0.05f, bounds.CenterY() + mWaitCircleRadius * 0.5f);
            path.LineTo(bounds.CenterX() + mWaitCircleRadius * 0.75f, bounds.CenterY() - mWaitCircleRadius * 0.2f);

            path.CubicTo(bounds.CenterX(), bounds.CenterY() + mWaitCircleRadius * 1f, bounds.CenterX() + mWaitCircleRadius, bounds.CenterY() + mWaitCircleRadius * 0.4f, bounds.CenterX() + mWaitCircleRadius, bounds.CenterY());

            //create arc
            path.ArcTo(new RectF(bounds.CenterX() - mWaitCircleRadius, bounds.CenterY() - mWaitCircleRadius, bounds.CenterX() + mWaitCircleRadius, bounds.CenterY() + mWaitCircleRadius), 0, -359);
            path.ArcTo(new RectF(bounds.CenterX() - mWaitCircleRadius, bounds.CenterY() - mWaitCircleRadius, bounds.CenterX() + mWaitCircleRadius, bounds.CenterY() + mWaitCircleRadius), 1, -359);
            path.ArcTo(new RectF(bounds.CenterX() - mWaitCircleRadius, bounds.CenterY() - mWaitCircleRadius, bounds.CenterX() + mWaitCircleRadius, bounds.CenterY() + mWaitCircleRadius), 2, -2);
            //create w
            path.CubicTo(bounds.CenterX() + mWaitCircleRadius, bounds.CenterY() - mWaitCircleRadius * 0.5f, bounds.CenterX() + mWaitCircleRadius * 0.3f, bounds.CenterY() - mWaitCircleRadius, bounds.CenterX() - mWaitCircleRadius * 0.35f, bounds.CenterY() + mWaitCircleRadius * 0.5f);
            path.QuadTo(bounds.CenterX() + mWaitCircleRadius, bounds.CenterY() - mWaitCircleRadius, bounds.CenterX() + mWaitCircleRadius * 0.05f, bounds.CenterY() + mWaitCircleRadius * 0.5f);
            path.LineTo(bounds.CenterX() + mWaitCircleRadius * 0.75f, bounds.CenterY() - mWaitCircleRadius * 0.2f);

            path.CubicTo(bounds.CenterX(), bounds.CenterY() + mWaitCircleRadius * 1f, bounds.CenterX() + mWaitCircleRadius, bounds.CenterY() + mWaitCircleRadius * 0.4f, bounds.CenterX() + mWaitCircleRadius, bounds.CenterY());

            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);
        }
Example #5
0
 public void FillEllipse(Brush brush, int x, int y, int w, int h)
 {
     APaint.Color = brush.Color.AColor();
     APaint.Flags = (Android.Graphics.PaintFlags) 0;
     APaint.Flags = Flags;
     APaint.SetStyle(Android.Graphics.Paint.Style.Fill);
     using (var r = new Android.Graphics.RectF(x, y, x + w, y + h))
     {
         ACanvas.DrawOval(r, APaint);
     }
 }
        protected internal override void ComputeRender(float renderProgress)
        {
            if (mCurrentBounds.Width() <= 0)
            {
                return;
            }

            RectF arcBounds = mCurrentBounds;

            //compute gas tube bounds
            mBottleBounds.Set(arcBounds.CenterX() - mBottleWidth / 2.0f, arcBounds.CenterY() - mBottleHeight / 2.0f, arcBounds.CenterX() + mBottleWidth / 2.0f, arcBounds.CenterY() + mBottleHeight / 2.0f);
            //compute pipe body bounds
            mWaterBounds.Set(mBottleBounds.Left + mStrokeWidth * 1.5f, mBottleBounds.Top + mWaterLowestPointToBottleneckDistance, mBottleBounds.Right - mStrokeWidth * 1.5f, mBottleBounds.Bottom - mStrokeWidth * 1.5f);

            //compute wave progress
            float totalWaveProgress   = renderProgress * mWaveCount;
            float currentWaveProgress = totalWaveProgress - ((int)totalWaveProgress);

            if (currentWaveProgress > 0.5f)
            {
                mProgress = 1.0f - MATERIAL_INTERPOLATOR.GetInterpolation((currentWaveProgress - 0.5f) * 2.0f);
            }
            else
            {
                mProgress = MATERIAL_INTERPOLATOR.GetInterpolation(currentWaveProgress * 2.0f);
            }

            //init water drop holders
            if (mWaterDropHolders.Count == 0)
            {
                InitWaterDropHolders(mBottleBounds, mWaterBounds);
            }

            //compute the location of these water drops
            foreach (WaterDropHolder waterDropHolder in mWaterDropHolders)
            {
                if (waterDropHolder.mDelayDuration < renderProgress && waterDropHolder.mDelayDuration + waterDropHolder.mDuration > renderProgress)
                {
                    float riseProgress = (renderProgress - waterDropHolder.mDelayDuration) / waterDropHolder.mDuration;
                    riseProgress = riseProgress < 0.5f ? riseProgress * 2.0f : 1.0f - (riseProgress - 0.5f) * 2.0f;
                    waterDropHolder.mCurrentY = waterDropHolder.mInitY - MATERIAL_INTERPOLATOR.GetInterpolation(riseProgress) * waterDropHolder.mRiseHeight;
                    waterDropHolder.mNeedDraw = true;
                }
                else
                {
                    waterDropHolder.mNeedDraw = false;
                }
            }

            //measure loading text
            mPaint.TextSize = mTextSize;
            mPaint.GetTextBounds(LOADING_TEXT, 0, LOADING_TEXT.Length, mLoadingBounds);
        }
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            int saveCount = canvas.Save();

            RectF arcBounds = mTempBounds;

            arcBounds.Set(bounds);

            mPaint.Alpha = MAX_ALPHA;
            mPaint.SetStyle(Paint.Style.Stroke);
            mPaint.Color = new Color(mCurrentColor);

            if (mSunCoordinateY < mInitSun_MoonCoordinateY)
            {
                canvas.DrawCircle(arcBounds.CenterX(), mSunCoordinateY, mSun_MoonRadius, mPaint);
            }

            if (mMoonCoordinateY < mInitSun_MoonCoordinateY)
            {
                int moonSaveCount = canvas.Save();
                canvas.Rotate(mMoonRotation, arcBounds.CenterX(), mMoonCoordinateY);
                canvas.DrawPath(CreateMoonPath(arcBounds.CenterX(), mMoonCoordinateY), mPaint);
                canvas.RestoreToCount(moonSaveCount);
            }

            for (int i = 0; i < mSunRayCount; i++)
            {
                int sunRaySaveCount = canvas.Save();
                //rotate 45 degrees can change the direction of 0 degrees to 1:30 clock
                //-mSunRayRotation means reverse rotation
                canvas.Rotate(45 - mSunRayRotation + (mIsExpandSunRay ? i : MAX_SUN_RAY_COUNT - i) * DEGREE_360 / MAX_SUN_RAY_COUNT, arcBounds.CenterX(), mSunCoordinateY);

                canvas.DrawLine(arcBounds.CenterX(), mSunRayStartCoordinateY, arcBounds.CenterX(), mSunRayEndCoordinateY, mPaint);
                canvas.RestoreToCount(sunRaySaveCount);
            }

            if (mShowStar)
            {
                if (mStarHolders.Count == 0)
                {
                    InitStarHolders(arcBounds);
                }

                for (int i = 0; i < mStarHolders.Count; i++)
                {
                    mPaint.SetStyle(Paint.Style.Fill);
                    mPaint.Alpha = mStarHolders[i].mAlpha;
                    canvas.DrawCircle(mStarHolders[i].mCurrentPoint.X, mStarHolders[i].mCurrentPoint.Y, mStarRadius, mPaint);
                }
            }

            canvas.RestoreToCount(saveCount);
        }
Example #8
0
 public void DrawEllipse(Pen pen, int x, int y, int w, int h)
 {
     APaint.Color = pen.Color.AColor();
     APaint.Flags = (Android.Graphics.PaintFlags) 0;
     APaint.Flags = Flags;
     APaint.SetStyle(Android.Graphics.Paint.Style.Stroke);
     APaint.StrokeWidth = LineWidth;
     using (var r = new Android.Graphics.RectF(x, y, x + w, y + h))
     {
         ACanvas.DrawOval(r, APaint);
     }
 }
        private Path CreateProgressPath(float progress, float circleRadius, RectF progressRect)
        {
            RectF arcProgressRect  = new RectF(progressRect.Left, progressRect.Top, progressRect.Left + circleRadius * 2, progressRect.Bottom);
            RectF rectProgressRect = null;

            float progressWidth     = progress * progressRect.Width();
            float progressModeWidth = mMode == MODE_LEAF_COUNT ? (float)mCurrentLeafCount / (float)LEAF_COUNT * progressRect.Width() : progress *progressRect.Width();

            float swipeAngle = DEGREE_180;

            //the Left half circle of the progressbar
            if (progressModeWidth < circleRadius)
            {
                swipeAngle = progressModeWidth / circleRadius * DEGREE_180;
            }

            //the center rect of the progressbar
            if (progressModeWidth < progressRect.Width() - circleRadius && progressModeWidth >= circleRadius)
            {
                rectProgressRect = new RectF(progressRect.Left + circleRadius, progressRect.Top, progressRect.Left + progressModeWidth, progressRect.Bottom);
            }

            //the Right half circle of the progressbar
            if (progressWidth >= progressRect.Width() - circleRadius)
            {
                rectProgressRect = new RectF(progressRect.Left + circleRadius, progressRect.Top, progressRect.Right - circleRadius, progressRect.Bottom);
                mScale           = (progressRect.Width() - progressWidth) / circleRadius;
            }

            //the Left of the Right half circle
            if (progressWidth < progressRect.Width() - circleRadius)
            {
                mRotation = (progressWidth / (progressRect.Width() - circleRadius)) * FULL_GROUP_ROTATION % DEGREE_360;

                RectF leafRect = new RectF(progressRect.Left + progressWidth, progressRect.Top, progressRect.Right - circleRadius, progressRect.Bottom);
                AddLeaf(progress, leafRect);
            }

            Path path = new Path();

            path.AddArc(arcProgressRect, DEGREE_180 - swipeAngle / 2, swipeAngle);

            if (rectProgressRect != null)
            {
                path.AddRect(rectProgressRect, Path.Direction.Cw);
            }

            return(path);
        }
Example #10
0
        public void PlatformToSystemF()
        {
#if __IOS__
            var platform = new CoreGraphics.CGRect(x, y, width, height);
#elif __ANDROID__
            var platform = new Android.Graphics.RectF(x, y, x + width, y + height);
#else
            var platform = new Windows.Foundation.Rect(x, y, width, height);
#endif

            var system = platform.ToSystemRectangleF();
            Assert.Equal(x, system.X);
            Assert.Equal(y, system.Y);
            Assert.Equal(width, system.Width);
            Assert.Equal(height, system.Height);
        }
Example #11
0
        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);
        }
Example #12
0
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            int   SaveCount = canvas.Save();
            RectF arcBounds = mCurrentBounds;

            arcBounds.Set(bounds);

            mPaint.Color = new Color(mBottomColor);
            canvas.DrawPath(mCurrentBottomWaitPath, mPaint);

            mPaint.Color = new Color(mMiddleColor);
            canvas.DrawPath(mCurrentMiddleWaitPath, mPaint);

            mPaint.Color = new Color(mTopColor);
            canvas.DrawPath(mCurrentTopWaitPath, mPaint);

            canvas.RestoreToCount(SaveCount);
        }
Example #13
0
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            int   saveCount = canvas.Save();
            RectF arcBounds = mTempBounds;

            arcBounds.Set(bounds);

            mPaint.Color = new Color(mColor);

            //calculate fish clip bounds
            //clip the width of the fish need to increase mPathDottedLineSize * 1.2f
            RectF  fishRectF = new RectF(mFishHeadPos[0] - mFishWidth / 2.0f - mPathDottedLineSize * 1.2f, mFishHeadPos[1] - mFishHeight / 2.0f, mFishHeadPos[0] + mFishWidth / 2.0f + mPathDottedLineSize * 1.2f, mFishHeadPos[1] + mFishHeight / 2.0f);
            Matrix matrix    = new Matrix();

            matrix.PostRotate(mFishRotateDegrees, fishRectF.CenterX(), fishRectF.CenterY());
            matrix.MapRect(fishRectF);

            //draw river
            int riverSaveCount = canvas.Save();

            mPaint.SetStyle(Paint.Style.Stroke);
            canvas.ClipRect(fishRectF, Region.Op.Difference);
            canvas.DrawPath(CreateRiverPath(arcBounds), mPaint);
            canvas.RestoreToCount(riverSaveCount);

            //draw fish
            int fishSaveCount = canvas.Save();

            mPaint.SetStyle(Paint.Style.Fill);
            canvas.Rotate(mFishRotateDegrees, mFishHeadPos[0], mFishHeadPos[1]);
            canvas.ClipPath(CreateFishEyePath(mFishHeadPos[0], mFishHeadPos[1] - mFishHeight * 0.06f), Region.Op.Difference);
            canvas.DrawPath(CreateFishPath(mFishHeadPos[0], mFishHeadPos[1]), mPaint);
            canvas.RestoreToCount(fishSaveCount);

            canvas.RestoreToCount(saveCount);
        }
        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);
        }
Example #15
0
 public void FillEllipse(Brush brush, int x, int y, int w, int h)
 {
     APaint.Color = brush.Color.AColor();
     APaint.Flags = (Android.Graphics.PaintFlags)0;
     APaint.Flags = Flags;
     APaint.SetStyle(Android.Graphics.Paint.Style.Fill);
     using(var r = new Android.Graphics.RectF(x, y, x+w, y+h))
     {
         ACanvas.DrawOval(r, APaint);
     }
 }
Example #16
0
        public override Carto.Graphics.Bitmap OnDrawPopup(PopupDrawInfo popupDrawInfo)
        {
            PopupStyle style = popupDrawInfo.Popup.Style;

            // Calculate scaled dimensions
            float DPToPX = popupDrawInfo.DPToPX;
            float PXTODP = 1 / DPToPX;

            if (style.ScaleWithDPI)
            {
                DPToPX = 1;
            }
            else
            {
                PXTODP = 1;
            }

            float screenWidth  = popupDrawInfo.ScreenBounds.GetWidth() * PXTODP;
            float screenHeight = popupDrawInfo.ScreenBounds.GetHeight() * PXTODP;

            // Update sizes based on scale (uses extension method, cf. Shared/Extensions
            int fontSize = FontSize.Update(DPToPX);

            int triangleWidth  = TriangleSize.Update(DPToPX);
            int triangleHeight = TriangleSize.Update(DPToPX);

            int strokeWidth   = StrokeWidth.Update(DPToPX);
            int screenPadding = ScreenPadding.Update(DPToPX);

            // Set font
            var font = Android.Graphics.Typeface.Create("HelveticaNeue-Light", Android.Graphics.TypefaceStyle.Normal);

            // Calculate the maximum popup size, adjust with dpi
            int maxPopupWidth = (int)(Math.Min(screenWidth, screenHeight));

            float halfStrokeWidth = strokeWidth * 0.5f;
            int   maxTextWidth    = maxPopupWidth - (2 * screenPadding + strokeWidth);

            // Measure text
            TextPaint textPaint = new TextPaint {
                Color = TextColor, TextSize = fontSize
            };

            textPaint.SetTypeface(font);

            var textLayout = new StaticLayout(text, textPaint, maxTextWidth, Layout.Alignment.AlignNormal, 1, 0, false);

            int textX = (int)Math.Min(textPaint.MeasureText(text), textLayout.Width);
            int textY = textLayout.Height;

            int popupWidth  = textX + (2 * PopupPadding + strokeWidth + triangleWidth);
            int popupHeight = textY + (2 * PopupPadding + strokeWidth);

            var bitmap = Android.Graphics.Bitmap.CreateBitmap(popupWidth, popupHeight, Android.Graphics.Bitmap.Config.Argb8888);
            var canvas = new Android.Graphics.Canvas(bitmap);

            var trianglePath = new Android.Graphics.Path();

            trianglePath.MoveTo(triangleWidth, 0);
            trianglePath.LineTo(halfStrokeWidth, triangleHeight * 0.5f);
            trianglePath.LineTo(triangleWidth, triangleHeight);
            trianglePath.Close();

            int triangleOffsetX = 0;
            int triangleOffsetY = (popupHeight - triangleHeight) / 2;

            // Create paint object
            var paint = new Android.Graphics.Paint();

            paint.AntiAlias = true;
            paint.SetStyle(Android.Graphics.Paint.Style.Stroke);
            paint.StrokeWidth = strokeWidth;
            paint.Color       = StrokeColor;

            // Stroke background
            var background = new Android.Graphics.RectF();

            background.Left   = triangleWidth;
            background.Top    = halfStrokeWidth;
            background.Right  = popupWidth - strokeWidth;
            background.Bottom = popupHeight - strokeWidth;
            canvas.DrawRect(background, paint);

            // Stroke triangle
            canvas.Save();
            canvas.Translate(triangleOffsetX, triangleOffsetY);
            canvas.DrawPath(trianglePath, paint);
            canvas.Restore();

            // Fill background
            paint.SetStyle(Android.Graphics.Paint.Style.Fill);
            paint.Color = BackgroundColor;
            canvas.DrawRect(background, paint);

            // Fill triangle
            canvas.Save();
            canvas.Translate(triangleOffsetX, triangleOffsetY);
            canvas.DrawPath(trianglePath, paint);
            canvas.Restore();

            if (textLayout != null)
            {
                // Draw text
                canvas.Save();
                canvas.Translate(halfStrokeWidth + triangleWidth + PopupPadding, halfStrokeWidth + PopupPadding);
                textLayout.Draw(canvas);
                canvas.Restore();
            }

            return(BitmapUtils.CreateBitmapFromAndroidBitmap(bitmap));
        }
        private ScanSettings CreateScanSettings()
        {
            var settings     = pickerView.Settings;
            var scanSettings = ScanSettings.Create();

            // Symbologies
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyEan13, settings.Ean13Upc12);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyUpca, settings.Ean13Upc12);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyEan8, settings.Ean8);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyUpce, settings.Upce);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyTwoDigitAddOn, settings.TwoDigitAddOn);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyFiveDigitAddOn, settings.FiveDigitAddOn);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyCode11, settings.Code11);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyCode25, settings.Code25);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyCode32, settings.Code32);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyCode39, settings.Code39);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyCode93, settings.Code93);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyCode128, settings.Code128);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyInterleaved2Of5, settings.Interleaved2Of5);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyMsiPlessey, settings.MsiPlessey);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyGs1Databar, settings.Gs1Databar);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyGs1DatabarExpanded, settings.Gs1DatabarExpanded);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyGs1DatabarLimited, settings.Gs1DatabarLimited);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyCodabar, settings.Codabar);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyQr, settings.Qr);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyDataMatrix, settings.DataMatrix);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyPdf417, settings.Pdf417);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyMicroPdf417, settings.MicroPdf417);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyAztec, settings.Aztec);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyMaxicode, settings.MaxiCode);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyRm4scc, settings.Rm4scc);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyKix, settings.Kix);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyDotcode, settings.Kix);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyMicroQr, settings.MicroQR);
            scanSettings.SetSymbologyEnabled(Barcode.SymbologyLapa4sc, settings.Lapa4sc);

            if (settings.QrInverted)
            {
                var qrSettings = scanSettings.GetSymbologySettings(Barcode.SymbologyQr);
                qrSettings.ColorInvertedEnabled = true;
            }

            var isScanningAreaOverridden = false;

            if (settings.DataMatrix)
            {
                var datamatrixSettings = scanSettings.GetSymbologySettings(Barcode.SymbologyDataMatrix);

                datamatrixSettings.ColorInvertedEnabled = settings.DataMatrixInverted;

                if (settings.DpmMode)
                {
                    scanSettings.RestrictedAreaScanningEnabled = true;
                    var scanninArea = new Android.Graphics.RectF(0.33f, 0.33f, 0.66f, 0.66f);
                    scanSettings.SetActiveScanningArea(ScanSettings.OrientationPortrait, scanninArea);
                    scanSettings.SetActiveScanningArea(ScanSettings.OrientationLandscape, scanninArea);

                    isScanningAreaOverridden = true;

                    // Enabling the direct_part_marking_mode extension comes at the cost of increased frame processing times.
                    // It is recommended to restrict the scanning area to a smaller part of the image for best performance.
                    datamatrixSettings.SetExtensionEnabled("direct_part_marking_mode", true);
                }
            }

            if (settings.RestrictScanningArea && !isScanningAreaOverridden)
            {
                float y      = (float)settings.HotSpotY;
                float width  = (float)settings.HotSpotWidth;
                float height = (float)settings.HotSpotHeight;
                scanSettings.SetScanningHotSpot(0.5f, y);
                var scanninArea = new Android.Graphics.RectF(0.5f - (width / 2), y - (height / 2), 0.5f + (width / 2), y + (height / 2));
                scanSettings.SetActiveScanningArea(ScanSettings.OrientationPortrait, scanninArea);
                scanSettings.SetActiveScanningArea(ScanSettings.OrientationLandscape, scanninArea);
            }

            scanSettings.MaxNumberOfCodesPerFrame = settings.TwoDigitAddOn || settings.FiveDigitAddOn ? 2 : 1;

            scanSettings.HighDensityModeEnabled = (settings.Resolution == Resolution.HD);

            scanSettings.MatrixScanEnabled = (settings.GuiStyle == GuiStyle.MatrixScan);

            return(scanSettings);
        }
        public override Carto.Graphics.Bitmap OnDrawPopup(PopupDrawInfo popupDrawInfo)
        {
            PopupStyle style = popupDrawInfo.Popup.Style;

            // Calculate scaled dimensions
            float DPToPX = popupDrawInfo.DPToPX;
            float PXTODP = 1 / DPToPX;

            if (style.ScaleWithDPI)
            {
                DPToPX = 1;
            }
            else
            {
                PXTODP = 1;
            }

            float screenWidth = popupDrawInfo.ScreenBounds.GetWidth() * PXTODP;
            float screenHeight = popupDrawInfo.ScreenBounds.GetHeight() * PXTODP;

            // Update sizes based on scale (uses extension method, cf. Shared/Extensions
            int fontSize = FontSize.Update(DPToPX);

            int triangleWidth = TriangleSize.Update(DPToPX);
            int triangleHeight = TriangleSize.Update(DPToPX);

            int strokeWidth = StrokeWidth.Update(DPToPX);
            int screenPadding = ScreenPadding.Update(DPToPX);

            // Set font
            var font = Android.Graphics.Typeface.Create("HelveticaNeue-Light", Android.Graphics.TypefaceStyle.Normal);

            // Calculate the maximum popup size, adjust with dpi
            int maxPopupWidth = (int)(Math.Min(screenWidth, screenHeight));

            float halfStrokeWidth = strokeWidth * 0.5f;
            int maxTextWidth = maxPopupWidth - (2 * screenPadding + strokeWidth);

            // Measure text
            TextPaint textPaint = new TextPaint { Color = TextColor, TextSize = fontSize };
            textPaint.SetTypeface(font);

            var textLayout = new StaticLayout(text, textPaint, maxTextWidth, Layout.Alignment.AlignNormal, 1, 0, false);

            int textX = (int)Math.Min(textPaint.MeasureText(text), textLayout.Width);
            int textY = textLayout.Height;

            int popupWidth = textX + (2 * PopupPadding + strokeWidth + triangleWidth);
            int popupHeight = textY + (2 * PopupPadding + strokeWidth);

            var bitmap = Android.Graphics.Bitmap.CreateBitmap(popupWidth, popupHeight, Android.Graphics.Bitmap.Config.Argb8888);
            var canvas = new Android.Graphics.Canvas(bitmap);

            var trianglePath = new Android.Graphics.Path();
            trianglePath.MoveTo(triangleWidth, 0);
            trianglePath.LineTo(halfStrokeWidth, triangleHeight * 0.5f);
            trianglePath.LineTo(triangleWidth, triangleHeight);
            trianglePath.Close();

            int triangleOffsetX = 0;
            int triangleOffsetY = (popupHeight - triangleHeight) / 2;

            // Create paint object
            var paint = new Android.Graphics.Paint();
            paint.AntiAlias = true;
            paint.SetStyle(Android.Graphics.Paint.Style.Stroke);
            paint.StrokeWidth = strokeWidth;
            paint.Color = StrokeColor;

            // Stroke background
            var background = new Android.Graphics.RectF();
            background.Left = triangleWidth;
            background.Top = halfStrokeWidth;
            background.Right = popupWidth - strokeWidth;
            background.Bottom = popupHeight - strokeWidth;
            canvas.DrawRect(background, paint);

            // Stroke triangle
            canvas.Save();
            canvas.Translate(triangleOffsetX, triangleOffsetY);
            canvas.DrawPath(trianglePath, paint);
            canvas.Restore();

            // Fill background
            paint.SetStyle(Android.Graphics.Paint.Style.Fill);
            paint.Color = BackgroundColor;
            canvas.DrawRect(background, paint);

            // Fill triangle
            canvas.Save();
            canvas.Translate(triangleOffsetX, triangleOffsetY);
            canvas.DrawPath(trianglePath, paint);
            canvas.Restore();

            if (textLayout != null)
            {
                // Draw text
                canvas.Save();
                canvas.Translate(halfStrokeWidth + triangleWidth + PopupPadding, halfStrokeWidth + PopupPadding);
                textLayout.Draw(canvas);
                canvas.Restore();
            }

            return BitmapUtils.CreateBitmapFromAndroidBitmap(bitmap);
        }
Example #19
0
 public void DrawEllipse(Pen pen, int x, int y, int w, int h)
 {
     APaint.Color = pen.Color.AColor();
     APaint.Flags = (Android.Graphics.PaintFlags)0;
     APaint.Flags = Flags;
     APaint.SetStyle(Android.Graphics.Paint.Style.Stroke);
     APaint.StrokeWidth = LineWidth;
     using (var r = new Android.Graphics.RectF(x, y, x+w, y+h))
     {
         ACanvas.DrawOval(r, APaint);
     }
 }
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            int saveCount = canvas.Save();

            RectF arcBounds = mTempBounds;

            arcBounds.Set(bounds);
            arcBounds.Inset(mStrokeXInset, mStrokeYInset);

            mCurrentProgressBounds.Set(arcBounds.Left, arcBounds.Bottom - 2 * mCenterRadius, arcBounds.Right, arcBounds.Bottom);

            //Draw loading Drawable
            mLoadingDrawable.SetBounds((int)arcBounds.CenterX() - mLoadingDrawable.IntrinsicWidth / 2, 0, (int)arcBounds.CenterX() + mLoadingDrawable.IntrinsicWidth / 2, mLoadingDrawable.IntrinsicHeight);
            mLoadingDrawable.Draw(canvas);

            //Draw progress background
            float progressInset = mCenterRadius - mProgressCenterRadius;
            RectF progressRect  = new RectF(mCurrentProgressBounds);

            //sub DEFAULT_STROKE_INTERVAL, otherwise will have a interval between progress background and progress outline
            progressRect.Inset(progressInset - DEFAULT_STROKE_INTERVAL, progressInset - DEFAULT_STROKE_INTERVAL);
            mPaint.Color = new Color(mProgressBgColor);
            mPaint.SetStyle(Paint.Style.Fill);
            canvas.DrawRoundRect(progressRect, mProgressCenterRadius, mProgressCenterRadius, mPaint);

            //Draw progress
            mPaint.Color = new Color(mProgressColor);
            mPaint.SetStyle(Paint.Style.Fill);
            canvas.DrawPath(CreateProgressPath(mProgress, mProgressCenterRadius, progressRect), mPaint);

            //Draw leaves
            for (int i = 0; i < mLeafHolders.Count; i++)
            {
                int        leafSaveCount = canvas.Save();
                LeafHolder leafHolder    = mLeafHolders[i];
                Rect       leafBounds    = leafHolder.mLeafRect;

                canvas.Rotate(leafHolder.mLeafRotation, leafBounds.CenterX(), leafBounds.CenterY());
                mLeafDrawable.Bounds = leafBounds;
                mLeafDrawable.Draw(canvas);

                canvas.RestoreToCount(leafSaveCount);
            }

            //Draw progress background outline,
            //after Drawing the leaves and then Draw the outline of the progress background can
            //prevent the leaves from flying to the outside
            RectF progressOutlineRect        = new RectF(mCurrentProgressBounds);
            float progressOutlineStrokeInset = (mCenterRadius - mProgressCenterRadius) / 2.0f;

            progressOutlineRect.Inset(progressOutlineStrokeInset, progressOutlineStrokeInset);
            mPaint.SetStyle(Paint.Style.Stroke);
            mPaint.Color       = new Color(mProgressBgColor);
            mPaint.StrokeWidth = mCenterRadius - mProgressCenterRadius;
            canvas.DrawRoundRect(progressOutlineRect, mCenterRadius, mCenterRadius, mPaint);

            //Draw electric fan outline
            float electricFanCenterX = arcBounds.Right - mCenterRadius;
            float electricFanCenterY = arcBounds.Bottom - mCenterRadius;

            mPaint.Color = new Color(mElectricFanOutlineColor);
            mPaint.SetStyle(Paint.Style.Stroke);
            mPaint.StrokeWidth = mStrokeWidth;
            canvas.DrawCircle(arcBounds.Right - mCenterRadius, arcBounds.Bottom - mCenterRadius, mCenterRadius - mStrokeWidth / 2.0f, mPaint);

            //Draw electric background
            mPaint.Color = new Color(mElectricFanBgColor);
            mPaint.SetStyle(Paint.Style.Fill);
            canvas.DrawCircle(arcBounds.Right - mCenterRadius, arcBounds.Bottom - mCenterRadius, mCenterRadius - mStrokeWidth + DEFAULT_STROKE_INTERVAL, mPaint);

            //Draw electric fan
            int rotateSaveCount = canvas.Save();

            canvas.Rotate(mRotation, electricFanCenterX, electricFanCenterY);
            mElectricFanDrawable.SetBounds((int)(electricFanCenterX - mElectricFanDrawable.IntrinsicWidth / 2 * mScale), (int)(electricFanCenterY - mElectricFanDrawable.IntrinsicHeight / 2 * mScale), (int)(electricFanCenterX + mElectricFanDrawable.IntrinsicWidth / 2 * mScale), (int)(electricFanCenterY + mElectricFanDrawable.IntrinsicHeight / 2 * mScale));
            mElectricFanDrawable.Draw(canvas);
            canvas.RestoreToCount(rotateSaveCount);

            //Draw 100% text
            if (mScale < 1.0f)
            {
                mPaint.TextSize = mTextSize * (1 - mScale);
                mPaint.Color    = new Color(mElectricFanOutlineColor);
                Rect textRect = new Rect();
                mPaint.GetTextBounds(PERCENTAGE_100, 0, PERCENTAGE_100.Length, textRect);
                canvas.DrawText(PERCENTAGE_100, electricFanCenterX - textRect.Width() / 2.0f, electricFanCenterY + textRect.Height() / 2.0f, mPaint);
            }

            canvas.RestoreToCount(saveCount);
        }