protected override void OnDraw(ACanvas canvas)
        {
            if (Element == null)
            {
                return;
            }

            var pancake = Element as PancakeView;

            SetClipChildren(true);

            //Create path to clip the child
            if (pancake.Sides != 4)
            {
                using (var path = DrawingExtensions.CreatePolygonPath(Width, Height, pancake.Sides, pancake.CornerRadius.TopLeft, pancake.OffsetAngle))
                {
                    canvas.Save();
                    canvas.ClipPath(path);
                }
            }
            else
            {
                using (var path = DrawingExtensions.CreateRoundedRectPath(Width, Height,
                                                                          Context.ToPixels(pancake.CornerRadius.TopLeft),
                                                                          Context.ToPixels(pancake.CornerRadius.TopRight),
                                                                          Context.ToPixels(pancake.CornerRadius.BottomRight),
                                                                          Context.ToPixels(pancake.CornerRadius.BottomLeft)))
                {
                    canvas.Save();
                    canvas.ClipPath(path);
                }
            }

            DrawBorder(canvas, pancake);
        }
Exemple #2
0
        protected override void OnDraw(ACanvas canvas)
        {
            if (Element == null)
            {
                return;
            }

            var control = (PancakeView)Element;

            SetClipChildren(true);

            //Create path to clip the child
            if (control.Sides != 4)
            {
                using (var path = ShapeUtils.CreatePolygonPath(Width, Height, control.Sides, control.CornerRadius.TopLeft, control.OffsetAngle))
                {
                    canvas.Save();
                    canvas.ClipPath(path);
                }
            }
            else
            {
                using (var path = ShapeUtils.CreateRoundedRectPath(Width, Height,
                                                                   Context.ToPixels(control.CornerRadius.TopLeft),
                                                                   Context.ToPixels(control.CornerRadius.TopRight),
                                                                   Context.ToPixels(control.CornerRadius.BottomRight),
                                                                   Context.ToPixels(control.CornerRadius.BottomLeft)))
                {
                    canvas.Save();
                    canvas.ClipPath(path);
                }
            }

            DrawBorder(canvas, control);
        }
Exemple #3
0
        protected override void OnDraw(ACanvas canvas)
        {
            if (Element == null)
            {
                return;
            }

            var control = (CanvasView)Element;

            SetClipChildren(true);

            //Create path to clip the child
            if (control.Sides != 4)
            {
                using (var path = PolygonUtils.GetPolygonCornerPath(Width, Height, control.Sides, control.CornerRadius.TopLeft, control.OffsetAngle))
                {
                    canvas.Save();
                    canvas.ClipPath(path);
                }
            }
            else
            {
                using (var path = new Path())
                {
                    path.AddRoundRect(new RectF(0, 0, Width, Height), GetRadii(control), Path.Direction.Ccw);

                    canvas.Save();
                    canvas.ClipPath(path);
                }
            }

            DrawBorder(canvas, control);
        }
		/// <Docs>The Canvas to which the View is rendered.</Docs>
		/// <summary>
		/// Draw the specified canvas.
		/// </summary>
		/// <param name="canvas">Canvas.</param>
		public override void Draw (Canvas canvas)
		{			
			try
			{
				var element = Element as RoundCornerView;
				var cornerRadius = (float)element.CornerRadius*Resources.DisplayMetrics.Density;

				// Paint rounded rect itself
				canvas.Save();
				var paint = new Paint();
				paint.AntiAlias = true;
				var strokeWidth = (((float)element.BorderWidth)*Resources.DisplayMetrics.Density);
				paint.StrokeWidth = strokeWidth;

				if(element.BackgroundColor != Xamarin.Forms.Color.Transparent)
				{
					paint.SetStyle(Paint.Style.Fill);
					paint.Color = element.BackgroundColor.ToAndroid();
					canvas.DrawRoundRect(new RectF(0, 0, Width, Height), cornerRadius, cornerRadius, paint);
				}

				if(element.BorderColor != Xamarin.Forms.Color.Transparent)
				{
					paint.SetStyle(Paint.Style.Stroke);
					paint.Color = element.BorderColor.ToAndroid();
					canvas.DrawRoundRect(new RectF(0, 0, Width, Height), cornerRadius, cornerRadius, paint);
				}

				//Properly dispose
				paint.Dispose();
				canvas.Restore();

				// Create clip path
				var path = new Path();
				path.AddRoundRect(new RectF(0.0f + (strokeWidth/2), 0.0f + (strokeWidth/2), 
					Width - (strokeWidth/2), Height - (strokeWidth/2)), cornerRadius, cornerRadius, Path.Direction.Cw);
				
				canvas.Save();
				canvas.ClipPath(path);

				// Do base drawing
				for(var i=0; i<ChildCount; i++)
					GetChildAt(i).Draw(canvas);

				canvas.Restore();
				path.Dispose();
			}
			catch (Exception)
			{				
			}				
		}
Exemple #5
0
        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 bool DrawChild(Android.Graphics.Canvas canvas, Android.Views.View child, long drawingTime)
 {
     try {
         var element     = (RoundedImage)Element;
         var radius      = Math.Min(Width, Height) / 2;
         var strokeWidth = 10;
         radius -= strokeWidth / 2;
         var path = new Path();
         path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
         canvas.Save();
         canvas.ClipPath(path);
         var result = base.DrawChild(canvas, child, drawingTime);
         canvas.Restore();
         path = new Path();
         path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
         var paint = new Paint();
         paint.AntiAlias   = true;
         paint.StrokeWidth = (float)element.BorderWidth;
         paint.SetStyle(Paint.Style.Stroke);
         paint.Color = element.BorderColor.ToAndroid();
         canvas.DrawPath(path, paint);
         paint.Dispose();
         path.Dispose();
         return(result);
     } catch (Exception ex) {
         Console.WriteLine(ex.Message);
     }
     return(base.DrawChild(canvas, child, drawingTime));
 }
        protected override void DispatchDraw(Android.Graphics.Canvas canvas)
        {
            base.DispatchDraw(canvas);

            if (opened || isTracking || animator != null)
            {
                // Draw inset shadow on the menu
                canvas.Save();
                shadowDrawable.SetBounds(0, 0, Context.ToPixels(8), Height);
                canvas.Translate(ContentView.Left - shadowDrawable.Bounds.Width(), 0);
                shadowDrawable.Draw(canvas);
                canvas.Restore();

                if (contentOffsetX != 0)
                {
                    // Cover the area with a black overlay to display openess graphically
                    var openness = ((float)(MaxOffset - contentOffsetX)) / MaxOffset;
                    overlayPaint.Alpha = Math.Max(0, (int)(MaxOverlayAlpha * openness));
                    if (overlayPaint.Alpha > 0)
                    {
                        canvas.DrawRect(0, 0, ContentView.Left, Height, overlayPaint);
                    }
                }
            }
        }
        public void DrawStopwatch(Canvas canvas)
        {
            canvas.Save();
            canvas.Translate(Width / 2F, Height / 2F);
            
            var tickMarks = new Path();
            tickMarks.AddCircle(0, 0, 90, Path.Direction.Cw);

            var scale = Math.Min(Width, Height) / 2F / 120;
            canvas.Scale(scale, scale);

            var paint = new Paint
            {
                StrokeCap = Paint.Cap.Square,
                Color = new Color(240, 240, 240)
            };

            paint.SetStyle(Paint.Style.Stroke);
            paint.StrokeWidth = 3;
            paint.SetPathEffect(MinuteDashEffect);
            canvas.DrawPath(tickMarks, paint);

            paint.Color = new Color(240, 240, 240);
            paint.StrokeWidth = 4;
            paint.SetPathEffect(FifthMinuteDashEffect);
            canvas.DrawPath(tickMarks, paint);
        }
		private void drawPorcentajeOnCanvas(Canvas canvas)
		{
			base.OnDraw (canvas);

			canvas.Save ();

			canvas.DrawColor(Android.Graphics.Color.White);

			//Obtenemos el centro de nuesto canvas
			float x = this.MeasuredWidth / 2;
			float y = this.MeasuredHeight / 2;

			//Obtenemos el radio R1
			//Obtenemos el radio R2
			float R1 = 0;
			float R2 = 0;
			//if (canvas.Width < canvas.Height) {
			if (this.MeasuredWidth  < this.MeasuredHeight) {
				R1 = x;//Obtenemos el radio R1
				R2 = x-(x*por_rango/100);
			} else {
				R1 = y ;//Obtenemos el radio R1
				R2 = y-(y *por_rango/100);//Obtenemos el radio R2 que dejamos un 20% de margen

			}

			//Dibujamos el fondo de nuestro grafico que va ir creciendo de acuerdo al porcentaje descargado
			RectF rectF2 = new RectF(x-R1, y-R1,x+R1, y+R1);
			mPaintFondo.Color= Android.Graphics.Color.Rgb(19,184,213);

			int grados = 0;
			grados = 360 * porcentaje / 100;
			canvas.DrawArc(rectF2, 270, grados, true, mPaintFondo);

			//Fondo superior de nuestro texto
			mPaintSuperior.Color= Android.Graphics.Color.Rgb(50,58,69);
			canvas.DrawCircle(x,y , R2, mPaintSuperior);


			//Texto que nos indica el procentaje descargado
			mPaintTexto.SetTypeface (mFace);
			mPaintTexto.Color = Color.White;

			//Obtenemos el 30 % de radio de nuestro circulo de fondo, el cual sera el tamaño de letra utilzar;
			float MYTEXTSIZE = R2 *30/100;
			// Get the screen's density scale
			float scale = Application.Context.Resources.DisplayMetrics.Density;
			//Convert the dps to pixels, based on density scale
			int textSizePx = (int) (MYTEXTSIZE * scale + 0.5f);
			mPaintTexto.TextSize = textSizePx;

			//Obtenemos la posicion para centrar adecuadamente nuesto texto
			int xPos = (this.MeasuredWidth  / 2);
			int yPos = (int) ((this.MeasuredHeight / 2) - ((mPaintTexto.Descent() + mPaintTexto.Ascent()) / 2)) ; 

			string Texto_Porcentaje =porcentaje.ToString();
			canvas.DrawText (Texto_Porcentaje+" %", xPos,yPos, mPaintTexto);

			canvas.Restore();
		}
        protected override void DispatchDraw(Android.Graphics.Canvas canvas)
        {
            // Draw interior shadow
            canvas.Save();
            canvas.ClipRect(0, 0, Width, Height);
            canvas.DrawPaint(shadow);
            canvas.Restore();

            base.DispatchDraw(canvas);

            // Draw custom list separator
            canvas.Save();
            canvas.ClipRect(0, Height - 2, Width, Height);
            canvas.DrawColor(Android.Graphics.Color.Rgb(LightTone, LightTone, LightTone));
            canvas.Restore();
        }
        protected override bool DrawChild(ACanvas canvas, global::Android.Views.View child, long drawingTime)
        {
            if (Element == null)
            {
                return(false);
            }

            var control = (PancakeView)Element;

            SetClipChildren(true);

            //Create path to clip the child
            using (var path = new Path())
            {
                path.AddRoundRect(new RectF(0, 0, Width, Height), GetRadii(control), Path.Direction.Ccw);

                canvas.Save();
                canvas.ClipPath(path);
            }

            // Draw the child first so that the border shows up above it.
            var result = base.DrawChild(canvas, child, drawingTime);

            canvas.Restore();

            DrawBorder(canvas, control);

            return(result);
        }
        protected override bool DrawChild(ACanvas canvas, global::Android.Views.View child, long drawingTime)
        {
            if (this.Element == null)
            {
                return(false);
            }

            CorneredContentView control = (CorneredContentView)this.Element;

            this.SetClipChildren(true);

            //Create path to clip the child
            using (Path path = new Path())
            {
                path.AddRoundRect(new RectF(0, 0, this.Width, this.Height), this.GetRadii(control), Path.Direction.Ccw);

                canvas.Save();
                canvas.ClipPath(path);
            }

            // Draw the child first so that the border shows up above it.
            bool result = base.DrawChild(canvas, child, drawingTime);

            canvas.Restore();

            this.DrawBorder(canvas, control);

            return(result);
        }
Exemple #13
0
		protected override void OnDraw(Canvas canvas) {
			base.OnDraw (canvas);
			if (mBlurredView != null) {
				if (prepare()) {
					// If the background of the blurred view is a color drawable, we use it to clear
					// the blurring canvas, which ensures that edges of the child views are blurred
					// as well; otherwise we clear the blurring canvas with a transparent color.
					if (mBlurredView.Background != null && mBlurredView.Background is ColorDrawable){
						mBitmapToBlur.EraseColor(((ColorDrawable) mBlurredView.Background).Color);
					}else {
						mBitmapToBlur.EraseColor(Color.Transparent);
					}

					mBlurredView.Draw(mBlurringCanvas);
					blur();

					canvas.Save();
					canvas.Translate(mBlurredView.GetX() - GetX(), mBlurredView.GetY() - GetY());
					canvas.Scale(mDownsampleFactor, mDownsampleFactor);
					canvas.DrawBitmap(mBlurredBitmap, 0, 0, null);
					canvas.Restore();
				}
				canvas.DrawColor(mOverlayColor);
			}
		}
 protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
 {
     try
     {
         var radius = Math.Min(Width, Height) / 2;
         var strokeWidth = 10;
         radius -= strokeWidth / 2;
         //Create path to clip
         var path = new Path();
         path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
         canvas.Save();
         canvas.ClipPath(path);
         var result = base.DrawChild(canvas, child, drawingTime);
         canvas.Restore();
         // Create path for circle border
         path = new Path();
         path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
         var paint = new Paint();
         paint.AntiAlias = true;
         paint.StrokeWidth = 5;
         paint.SetStyle(Paint.Style.Stroke);
         paint.Color = global::Android.Graphics.Color.White;
         canvas.DrawPath(path, paint);
         //Properly dispose
         paint.Dispose();
         path.Dispose();
         return result;
     }
     catch (Exception ex)
     {
         Console.WriteLine("Unable to create circle image: " + ex);
     }
     return base.DrawChild(canvas, child, drawingTime);
 }
        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 OnDraw(Android.Graphics.Canvas canvas)
        {
            canvas.Save();

            canvas.Translate(_width, _height);
            canvas.Rotate(-90);

            TextPaint paint = this.Paint;

            //Android.Graphics.Color Colorr = Color.  //this.TextColors.DefaultColor;
            //
            //var defcolor = this.TextColors.DefaultColor;
            //var Redd = Color.GetRedComponent(defcolor);
            //var Blue = Color.GetBlueComponent(defcolor);
            //var Greenn = Color.GetGreenComponent(defcolor);
            //var Birlestir = Color.Rgb(Redd, Greenn, Blue);
            //ColorFilter cf = new PorterDuffColorFilter(Birlestir, PorterDuff.Mode.SrcAtop);
            //paint.SetColorFilter(cf);
            paint.Color = Color.White;
            String text = getTextt();

            paint.GetTextBounds(text, 0, text.Length, _bounds);
            canvas.DrawText(text, this.CompoundPaddingLeft, (_bounds.Height() - _width) / 2, paint);

            canvas.Restore();
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="child"></param>
        /// <param name="drawingTime"></param>
        /// <returns></returns>
        protected override bool DrawChild(Canvas canvas, Android.Views.View child, long drawingTime)
        {
            try
            {
                
                var radius = Math.Min(Width, Height) / 2;
                var strokeWidth = ((CircleImage)Element).BorderThickness;
                radius -= strokeWidth / 2;


               

                var path = new Path();
                path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);

                
                canvas.Save();
                canvas.ClipPath(path);

               

                var paint = new Paint();
                paint.AntiAlias = true;
                paint.SetStyle(Paint.Style.Fill);
                paint.Color = ((CircleImage)Element).FillColor.ToAndroid();
                canvas.DrawPath(path, paint);
                paint.Dispose();


                var result = base.DrawChild(canvas, child, drawingTime);

                canvas.Restore();

                path = new Path();
                path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
                

                var thickness = ((CircleImage)Element).BorderThickness;
                if(thickness > 0.0f)
                {
                    paint = new Paint();
                    paint.AntiAlias = true;
                    paint.StrokeWidth = thickness;
                    paint.SetStyle(Paint.Style.Stroke);
                    paint.Color = ((CircleImage)Element).BorderColor.ToAndroid();
                    canvas.DrawPath(path, paint);
                    paint.Dispose();
                }
                
                path.Dispose();
                return result;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
            }

            return base.DrawChild(canvas, child, drawingTime);
        }
Exemple #18
0
 public void Draw(Canvas canvas)
 {
     canvas.Save();
     canvas.Translate((float)Position.X, (float)Position.Y);
     canvas.Rotate((float)Acceleration.Direction + ROTATION_OFFSET);
     mDrawable.Draw(canvas);
     canvas.Restore();
 }
        protected override bool DrawChild(Canvas canvas, View child, long drawingTime)
        {
            try
            {

                var radius = Math.Min(Width, Height) / 2;

                var borderThickness = (float)((CircleImage)Element).BorderThickness;

                int strokeWidth = 0;

                if (borderThickness > 0)
                {
                    var logicalDensity = Xamarin.Forms.Forms.Context.Resources.DisplayMetrics.Density;
                    strokeWidth = (int)Math.Ceiling(borderThickness * logicalDensity + .5f);
                }

                radius -= strokeWidth / 2;

                var path = new Path();
                path.AddCircle(Width / 2.0f, Height / 2.0f, radius, Path.Direction.Ccw);

                canvas.Save();
                canvas.ClipPath(path);

                var paint = new Paint();
                paint.AntiAlias = true;
                paint.SetStyle(Paint.Style.Fill);
                paint.Color = ((CircleImage)Element).FillColor.ToAndroid();
                canvas.DrawPath(path, paint);
                paint.Dispose();

                var result = base.DrawChild(canvas, child, drawingTime);

                canvas.Restore();

                path = new Path();
                path.AddCircle((float) Width / 2, (float) Height / 2, radius, Path.Direction.Ccw);

                if (strokeWidth > 0.0f)
                {
                    paint = new Paint {AntiAlias = true, StrokeWidth = strokeWidth};
                    paint.SetStyle(Paint.Style.Stroke);
                    paint.Color = ((CircleImage)Element).BorderColor.ToAndroid();
                    canvas.DrawPath(path, paint);
                    paint.Dispose();
                }

                path.Dispose();
                return result;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
            }

            return base.DrawChild(canvas, child, drawingTime);
        }
        // Rotate the canvas before drawing
        protected override void DispatchDraw(Canvas canvas)
        {
            canvas.Save (SaveFlags.Matrix);
            canvas.Rotate (-heading, Width * 0.5f, Height * 0.5f);

            base.DispatchDraw (canvas);

            canvas.Restore ();
        }
		protected override void OnDraw (Canvas canvas)
		{
			base.OnDraw (canvas);
			canvas.Save ();
			canvas.Translate (_posX, _posY);
			canvas.Scale (_scaleFactor, _scaleFactor);
			_icon.Draw (canvas);
			canvas.Restore ();
		}
 private void ShowPath(Canvas canvas, int x, int y, Path.FillType ft, Paint paint)
 {
     canvas.Save();
     canvas.Translate(x, y);
     canvas.ClipRect(0, 0, 120, 120);
     canvas.DrawColor(Color.White);
     mPath.SetFillType(ft);
     canvas.DrawPath(mPath, paint);
     canvas.Restore();
 }
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);
            DrawHexagon(canvas);

            canvas.Save();
            canvas.Scale(.4f, .5f, Width / 2, Height / 2);
            DrawCross(canvas);
            canvas.Restore();
        }
        protected override bool DrawChild(ACanvas canvas, global::Android.Views.View child, long drawingTime)
        {
            if (Element == null)
            {
                return(false);
            }

            var pancake = Element as PancakeView;

            SetClipChildren(true);

            //Create path to clip the child
            if (pancake.Sides != 4)
            {
                using (var path = DrawingExtensions.CreatePolygonPath(Width, Height, pancake.Sides, pancake.CornerRadius.TopLeft, pancake.OffsetAngle))
                {
                    canvas.Save();
                    canvas.ClipPath(path);
                }
            }
            else
            {
                using (var path = DrawingExtensions.CreateRoundedRectPath(Width, Height,
                                                                          Context.ToPixels(pancake.CornerRadius.TopLeft),
                                                                          Context.ToPixels(pancake.CornerRadius.TopRight),
                                                                          Context.ToPixels(pancake.CornerRadius.BottomRight),
                                                                          Context.ToPixels(pancake.CornerRadius.BottomLeft)))
                {
                    canvas.Save();
                    canvas.ClipPath(path);
                }
            }

            // Draw the child first so that the border shows up above it.
            var result = base.DrawChild(canvas, child, drawingTime);

            canvas.Restore();

            DrawBorder(canvas, pancake);

            return(result);
        }
        protected override void OnDraw(Canvas canvas)
        {
            canvas.Save();
            if (RotationPivotPoint != null) {
                canvas.Rotate(RotationDegress, RotationPivotPoint.X, RotationPivotPoint.Y);
            } else {
                canvas.Rotate(RotationDegress);
            }

            base.OnDraw(canvas);
        }
 protected override void OnDraw(Canvas canvas)
 {
     for (int i = 0; i < balls.Count; ++i)
     {
         ShapeHolder shapeHolder = balls[i];
         canvas.Save();
         canvas.Translate(shapeHolder.X, shapeHolder.Y);
         shapeHolder.Shape.Draw(canvas);
         canvas.Restore();
     }
 }
        public override void Draw(Canvas canvas, ICharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint)
        {
            PrepView();

            canvas.Save();

            //Centering the token looks like a better strategy that aligning the bottom
            int padding = (bottom - top - View.Bottom) / 2;
            canvas.Translate(x, bottom - View.Bottom - padding);
            View.Draw(canvas);
            canvas.Restore();
        }
Exemple #28
0
        protected override bool DrawChild(ACanvas canvas, global::Android.Views.View child, long drawingTime)
        {
            if (Element == null)
            {
                return(false);
            }

            var control = (CanvasView)Element;

            SetClipChildren(true);

            //Create path to clip the child
            if (control.Sides != 4)
            {
                using (var path = PolygonUtils.GetPolygonCornerPath(Width, Height, control.Sides, control.CornerRadius.TopLeft, control.OffsetAngle))
                {
                    canvas.Save();
                    canvas.ClipPath(path);
                }
            }
            else
            {
                using (var path = new Path())
                {
                    path.AddRoundRect(new RectF(0, 0, Width, Height), GetRadii(control), Path.Direction.Ccw);

                    canvas.Save();
                    canvas.ClipPath(path);
                }
            }

            // Draw the child first so that the border shows up above it.
            var result = base.DrawChild(canvas, child, drawingTime);

            canvas.Restore();

            DrawBorder(canvas, control);

            return(result);
        }
        /// <summary>
        /// Redraws the child.
        /// </summary>
        protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
        {
            try
            {
                var radius = (float)((RoundedImage)Element).BorderRadius;
                var stroke = (float)((RoundedImage)Element).BorderThickness;
                var delta = (float)stroke / 2.0f;

                if (radius < 0)
                {
                    radius = Math.Min(Width, Height) / 2.0f;
                }

                radius -= delta;

                // Clip with rounded rect
                var path = new Path();
                path.AddRoundRect(new RectF(delta, delta, Width - stroke, Height - stroke),
                    radius, radius, Path.Direction.Ccw);
                canvas.Save();
                canvas.ClipPath(path);
                path.Dispose();

                var result = base.DrawChild(canvas, child, drawingTime);

                canvas.Restore();

                // Add stroke for smoother border
                path = new Path();
                path.AddRoundRect(new RectF(delta, delta, Width - stroke, Height - stroke),
                    radius, radius, Path.Direction.Ccw);
                var paint = new Paint();
                paint.AntiAlias = true;
                paint.StrokeWidth = stroke;
                paint.SetStyle(Paint.Style.Stroke);
                paint.Color = ((RoundedImage)Element).BorderColor.ToAndroid();
                canvas.DrawPath(path, paint);
                paint.Dispose();

                // Clean up
                path.Dispose();

                return result;
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
            }

            return base.DrawChild(canvas, child, drawingTime);
        }
Exemple #30
0
        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);
        }
Exemple #31
0
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            base.OnDraw(canvas);

            // Fill the background
            canvas.DrawPaint(mBackgroundPaint);

            // Test Text
            canvas.Save();
            var  textWidth  = mTextPaint.MeasureText("Hello");
            Rect textBounds = new Rect();

            mTextPaint.GetTextBounds("Hello", 0, 1, textBounds);
            canvas.DrawText("Hello", canvas.Width / 2 - textWidth / 2, canvas.Height / 2 - textBounds.Height() / 2, mTextPaint);

            textWidth  = mTextPaint.MeasureText("World");
            textBounds = new Rect();
            mTextPaint.GetTextBounds("World", 0, 1, textBounds);
            mTextPaint.Color = Color.Green;
            canvas.DrawText("World", (canvas.Width / 2 - textWidth / 2) + 100, (canvas.Height / 2 - textBounds.Height() / 2) + 100, mTextPaint);


            canvas.Restore();

            foreach (Box box in mBoxes)
            {
                float left   = Math.Min(box.Origin.X, box.Current.X);
                float right  = Math.Max(box.Origin.X, box.Current.X);
                float top    = Math.Min(box.Origin.Y, box.Current.Y);
                float bottom = Math.Max(box.Origin.Y, box.Current.Y);
                canvas.Save();
                canvas.Rotate(box.Rotation, (box.Origin.X + box.Current.X) / 2, (box.Origin.Y + box.Current.Y) / 2);
                canvas.DrawRect(left, top, right, bottom, mBoxPaint);
                canvas.Restore();
            }
        }
        /// <summary>
        /// Draw one child of this View Group.
        /// </summary>
        /// <param name="canvas">The canvas on which to draw the child</param>
        /// <param name="child">Who to draw</param>
        /// <param name="drawingTime">The time at which draw is occurring</param>
        /// <returns>To be added.</returns>
        /// <since version="Added in API level 1" />
        /// <remarks><para tool="javadoc-to-mdoc">Draw one child of this View Group. This method is responsible for getting
        /// the canvas in the right state. This includes clipping, translating so
        /// that the child's scrolled origin is at 0, 0, and applying any animation
        /// transformations.</para>
        /// <para tool="javadoc-to-mdoc">
        ///   <format type="text/html">
        ///     <a href="http://developer.android.com/reference/android/view/ViewGroup.html#drawChild(android.graphics.Canvas, android.view.View, long)" target="_blank">[Android Documentation]</a>
        ///   </format>
        /// </para></remarks>
        protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
        {
            if (this.Element.Aspect != Aspect.AspectFit)
            {
                return base.DrawChild(canvas, child, drawingTime);
            }

            using (var path = new Path())
            {
                path.AddCircle(Width / 2, Height / 2, (Math.Min(Width, Height) - 10) / 2, Path.Direction.Ccw);
                canvas.Save();
                canvas.ClipPath(path);
            }

            return base.DrawChild(canvas, child, drawingTime);
        }
        public override void Draw(Canvas canvas, ICharSequence text, Int32 start, Int32 end, Single x, Int32 top, Int32 y, Int32 bottom, Paint paint)
        {
            ApplyCustomTypeFace(paint, _type);
            paint.GetTextBounds(_icon, 0, 1, TEXT_BOUNDS);
            canvas.Save();
            var baselineRatio = _baselineAligned ? 0f : BASELINE_RATIO;
            if (_rotate)
            {
                var rotation = (SystemClock.CurrentThreadTimeMillis() - _rotationStartTime) / (Single)ROTATION_DURATION * 360f;
                var centerX = x + TEXT_BOUNDS.Width() / 2f;
                var centerY = y - TEXT_BOUNDS.Height() / 2f + TEXT_BOUNDS.Height() * baselineRatio;
                canvas.Rotate(rotation, centerX, centerY);
            }

            canvas.DrawText(_icon, x - TEXT_BOUNDS.Left, y - TEXT_BOUNDS.Bottom + TEXT_BOUNDS.Height() * baselineRatio, paint);
            canvas.Restore();
        }
Exemple #34
0
        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);
        }
		public static Bitmap ToRotatedBitmap(this Bitmap sourceBitmap, int rotationDegrees)
		{
			if (rotationDegrees == 0)
				return sourceBitmap;

			int width = sourceBitmap.Width;
			int height = sourceBitmap.Height;

			if (rotationDegrees == 90 || rotationDegrees == 270)
			{
				width = sourceBitmap.Height;
				height = sourceBitmap.Width;
			}

			Bitmap bitmap = Bitmap.CreateBitmap(width, height, sourceBitmap.GetConfig());
			using (Canvas canvas = new Canvas(bitmap))
			using (Paint paint = new Paint())
			using (BitmapShader shader = new BitmapShader(sourceBitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp))
			using (Matrix matrix = new Matrix())
			{
				// paint.AntiAlias = true;
				// paint.Dither = true;
				// paint.FilterBitmap = true;

				canvas.Save(Android.Graphics.SaveFlags.Matrix);

				if (rotationDegrees == 90)
					canvas.Rotate(rotationDegrees, width / 2, width / 2);
				else if (rotationDegrees == 270)
					canvas.Rotate(rotationDegrees, height / 2, height / 2);
				else
					canvas.Rotate(rotationDegrees, width / 2, height / 2);

				canvas.DrawBitmap(sourceBitmap, matrix, paint);
				canvas.Restore();
			}

			if (sourceBitmap != null && sourceBitmap.Handle != IntPtr.Zero && !sourceBitmap.IsRecycled)
			{
				sourceBitmap.Recycle();
				sourceBitmap.Dispose();
			}

			return bitmap;
		}
Exemple #36
0
        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;
        }
        public override void Draw(Canvas canvas)
        {
            // Draw background
            canvas.Save ();
            canvas.ClipPath (clipMask);
            canvas.DrawColor (bgColor);
            canvas.Restore ();

            // Draw labels
            var middleX = Width / 2;
            var selectedIndex = SelectedIndex;

            float deltaY = PaddingTop;
            for (int i = 0; i < words.Length; i++) {
                var word = words [i];
                var layout = textLayouts [word];
                var colorRatio = Math.Abs (i - selectedIndex) > 1 ? 0 : 1 - Math.Abs (i - scrollPosition);
                textPaint.Color = ImageUtils.InterpolateColor (colorRatio, normalColor, selectedColor);

                canvas.Save (SaveFlags.Matrix);
                canvas.Translate (middleX, deltaY);
                layout.Draw (canvas);
                canvas.Restore ();
                deltaY += layout.Height + spacing;
            }

            // Draw knob
            canvas.Save ();
            var top = selectedIndex * spacing + words.Take (selectedIndex).Select (w => textLayouts[w].Height).Sum () - knobPadding + PaddingTop;
            var selectedWordHeight = textLayouts [words [selectedIndex]].Height;
            var bottom = top + selectedWordHeight + 2 * knobPadding;
            var offset = scrollPosition - SelectedIndex;
            if (offset > 0 && selectedIndex < words.Length - 1) {
                var extraY = offset * (spacing + selectedWordHeight);
                var nextWordHeight = textLayouts [words [selectedIndex + 1]].Height;
                top += extraY;
                bottom += extraY;
                bottom += offset * (nextWordHeight - selectedWordHeight);
            }

            canvas.ClipRect (0, top, knobWidth, bottom);
            canvas.DrawColor (Color.White);
            canvas.Restore ();
        }
        protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
        {
            try {
                // Extract properties
                var source = (CircularImage)Element;
                var borderWidth = source.BorderWidth;
                var borderColor = source.BorderColor.ToAndroid();

                var radius = Math.Min(Width, Height) / 2;
                var strokeWidth = 10;
                radius -= strokeWidth / 2;

                //Create path to clip
                var path = new Path();
                path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
                canvas.Save();
                canvas.ClipPath(path);

                var result = base.DrawChild(canvas, child, drawingTime);

                canvas.Restore();

                // Create path for circle border
                path = new Path();
                path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);

                var paint = new Paint();
                paint.AntiAlias = true;
                paint.StrokeWidth = borderWidth;
                paint.SetStyle(Paint.Style.Stroke);
                paint.Color = borderColor;

                canvas.DrawPath(path, paint);

                //Properly dispose
                paint.Dispose();
                path.Dispose();
                return result;
            } catch (Exception ex) {
                System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
            }

            return base.DrawChild(canvas, child, drawingTime);
        }
Exemple #39
0
        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 OnDraw(Canvas canvas)
        {
            if (_image != null && _filter != null) {
                var cFilter = new ColorMatrixColorFilter (_filter);
                Paint paint = new Paint ();
                paint.SetColorFilter (cFilter);

                Matrix matrix = new Matrix ();
                canvas.Save ();
                float horizotalScale = (Right - Left) / (float)_image.Width;
                float verticalScale = (Bottom - Top) / (float)_image.Height;
                float scale = horizotalScale < verticalScale ? horizotalScale : verticalScale;

                matrix.SetScale (scale,scale);

                canvas.DrawBitmap (_image, matrix, paint);
                canvas.Restore ();
            }
        }
        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);
        }
        public override void Draw(Canvas canvas, ICharSequence text, int start, int end, float x, int top, int y,
            int bottom, Paint paint)
        {
            ApplyCustomTypeFace(paint, _typeface);
            paint.GetTextBounds(_icon, 0, 1, TextBounds);
            canvas.Save();
            if (_rotate)
            {
                var rotation = (DateTimeHelpers.CurrentUnixTimeMillis() - _rotationStartTime)/(float) RotationDuration*
                               360f;
                var centerX = x + TextBounds.Width()/2f;
                var centerY = y - TextBounds.Height()/2f + TextBounds.Height()*BaselineRatio;
                canvas.Rotate(rotation, centerX, centerY);
            }

            canvas.DrawText(_icon, x - TextBounds.Left, y - TextBounds.Bottom + TextBounds.Height()*BaselineRatio,
                paint);
            canvas.Restore();
        }
Exemple #43
0
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            var rect = new Rect();

            this.GetDrawingRect(rect);
            Paint paint;

            // circleDotFill
            if (Element.Active)
            {
                RectF circleDotFillRect = new RectF(
                    rect.Left + 1f,
                    rect.Top + 1f,
                    rect.Right - 1f,
                    rect.Bottom - 1f);
                Path circleDotFillPath = new Path();
                circleDotFillPath.AddOval(circleDotFillRect, Path.Direction.Cw);

                paint = new Paint(PaintFlags.AntiAlias);
                paint.SetStyle(Paint.Style.Fill);
                paint.Color = Element.FillColor.ToAndroid();
                canvas.DrawPath(circleDotFillPath, paint);
            }

            // circleDotStroke
            RectF circleDotStrokeRect = new RectF(
                rect.Left + 1f,
                rect.Top + 1f,
                rect.Right - 1f,
                rect.Bottom - 1f);
            Path circleDotStrokePath = new Path();

            circleDotStrokePath.AddOval(circleDotStrokeRect, Path.Direction.Cw);

            paint             = new Paint(PaintFlags.AntiAlias);
            paint.StrokeWidth = 2.5f;
            paint.StrokeMiter = 10f;
            canvas.Save();
            paint.SetStyle(Paint.Style.Stroke);
            paint.Color = Element.StrokeColor.ToAndroid();
            canvas.DrawPath(circleDotStrokePath, paint);
            canvas.Restore();
        }
        public override void Draw(Canvas canvas, ICharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint)
        {
            ApplyCustomTypeFace(paint, type);
            paint.GetTextBounds(icon, 0, 1, TEXT_BOUNDS);
            canvas.Save();
            float baselineRatio = baselineAligned ? 0f : BASELINE_RATIO;
            if (rotate)
            {
                long time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                float rotation = (time - rotationStartTime) / (float)ROTATION_DURATION * 360f;
                float centerX = x + TEXT_BOUNDS.Width() / 2f;
                float centerY = y - TEXT_BOUNDS.Height() / 2f + TEXT_BOUNDS.Height() * baselineRatio;
                canvas.Rotate(rotation, centerX, centerY);
            }

            canvas.DrawText(icon,
                    x - TEXT_BOUNDS.Left,
                    y - TEXT_BOUNDS.Bottom + TEXT_BOUNDS.Height() * baselineRatio, paint);
            canvas.Restore();
        }
Exemple #45
0
        protected override bool DrawChild(Android.Graphics.Canvas canvas, Android.Views.View child, long drawingTime)
        {
            try
            {
                var radius      = Math.Min(Width, Height) / 2;
                var strokeWidth = 10;
                radius -= strokeWidth / 2;

                //Create path to clip
                var path = new Path();
                path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
                canvas.Save();
                canvas.ClipPath(path);

                var result = base.DrawChild(canvas, child, drawingTime);

                canvas.Restore();

                // Create path for circle border
                path = new Path();
                path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);

                var paint = new Paint();
                paint.AntiAlias   = true;
                paint.StrokeWidth = 5;
                paint.SetStyle(Paint.Style.Stroke);
                paint.Color = global::Android.Graphics.Color.White;

                canvas.DrawPath(path, paint);

                //Properly dispose
                paint.Dispose();
                path.Dispose();
                return(result);
            }
            catch (Exception)
            {
            }

            return(base.DrawChild(canvas, child, drawingTime));
        }
Exemple #46
0
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            var rect = new Rect();

            this.GetDrawingRect(rect);
            Paint paint;

            var halfThickness = Element.StrokeThickness / 2f;

            var ellipseRect = new RectF(
                rect.Left + halfThickness,
                rect.Top + halfThickness,
                rect.Right - halfThickness,
                rect.Bottom - halfThickness);

            // circleDotFill
            if (Element.Fill.A != 0)
            {
                var circleDotFillPath = new Path();
                circleDotFillPath.AddOval(ellipseRect, Path.Direction.Cw);

                paint = new Paint(PaintFlags.AntiAlias);
                paint.SetStyle(Paint.Style.Fill);
                paint.Color = Element.Fill.ToAndroid();
                canvas.DrawPath(circleDotFillPath, paint);
            }

            // circleDotStroke
            Path circleDotStrokePath = new Path();

            circleDotStrokePath.AddOval(ellipseRect, Path.Direction.Cw);

            paint             = new Paint(PaintFlags.AntiAlias);
            paint.StrokeWidth = Element.StrokeThickness;
            paint.StrokeMiter = 10f;
            canvas.Save();
            paint.SetStyle(Paint.Style.Stroke);
            paint.Color = Element.Stroke.ToAndroid();
            canvas.DrawPath(circleDotStrokePath, paint);
            canvas.Restore();
        }
        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);
        }
Exemple #49
0
        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);
        }
Exemple #51
0
        protected override bool DrawChild(Android.Graphics.Canvas canvas, Android.Views.View child, long drawingTime)
        {
            try
            {
                var radius      = Math.Min(Width, Height) / 2;
                var strokeWidth = Convert.ToInt32(element.BorderWidth);
                radius -= strokeWidth / 2;


                Path path = new Path();
                path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
                canvas.Save();
                canvas.ClipPath(path);

                var result = base.DrawChild(canvas, child, drawingTime);

                canvas.Restore();

                path = new Path();
                path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);

                var paint = new Paint();
                paint.AntiAlias   = true;
                paint.StrokeWidth = element.BorderWidth;
                paint.SetStyle(Paint.Style.Stroke);
                paint.Color = global::Android.Graphics.Color.White;

                canvas.DrawPath(path, paint);

                paint.Dispose();
                path.Dispose();
                return(result);
            }
            catch (Exception ex)
            {
                var msg = ex.Message;
            }

            return(base.DrawChild(canvas, child, drawingTime));
        }
		protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
		{
			try
			{
				var radius = Math.Min(Width, Height) / 2;
				var strokeWidth = 10;
				radius -= strokeWidth / 2;


				Path path = new Path();
				path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);
				canvas.Save();
				canvas.ClipPath(path);

				var result = base.DrawChild(canvas, child, drawingTime);

				canvas.Restore();

				path = new Path();
				path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw);

				var paint = new Paint();
				paint.AntiAlias = true;
				paint.StrokeWidth = 5;
				paint.SetStyle(Paint.Style.Stroke);
				paint.Color = global::Android.Graphics.Color.White;

				canvas.DrawPath(path, paint);

				paint.Dispose();
				path.Dispose();
				return result;
			}
			catch (Exception ex)
			{
			}

			return base.DrawChild(canvas, child, drawingTime);
		}
        protected override void OnDraw(ACanvas canvas)
        {
            if (this.Element == null)
            {
                return;
            }

            CorneredContentView control = (CorneredContentView)this.Element;

            this.SetClipChildren(true);

            //Create path to clip the child
            using (Path path = new Path())
            {
                path.AddRoundRect(new RectF(0, 0, this.Width, this.Height), this.GetRadii(control), Path.Direction.Ccw);

                canvas.Save();
                canvas.ClipPath(path);
            }

            this.DrawBorder(canvas, control);
        }
		protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
		{
			try
			{
				var path = new Path ();
				path.AddRoundRect (new RectF (0, 0, Width, Height), 15f, 15f, Path.Direction.Ccw);
				canvas.Save ();
				canvas.ClipPath (path);

				var result = base.DrawChild(canvas, child, drawingTime);

				canvas.Restore();
				path.Dispose();
				return result;
			}
			catch (Exception ex)
			{
				System.Diagnostics.Debug.WriteLine("Unable to create rounded rectangle image: " + ex);
			}

			return base.DrawChild(canvas, child, drawingTime);
		}
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            var textPaint = this.Paint;

            textPaint.Color = new Color(this.CurrentTextColor);

            canvas.Save();

            if (m_TopDown)
            {
                canvas.Translate(this.Width, 0);
                canvas.Rotate(90.0f);
            }
            else
            {
                canvas.Translate(0, this.Height);
                canvas.Rotate(-90.0f);
            }

            canvas.Translate(this.CompoundPaddingLeft, this.ExtendedPaddingTop);
            this.Layout.Draw(canvas);
            canvas.Restore();
        }
        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);
        }
Exemple #57
0
        protected void DrawAt(Canvas canvas, Drawable drawable, int x, int y, bool shadow)
        {
            try
            {
                canvas.Save();
                canvas.Translate(x, y);
                if (shadow)
                {
                    drawable.SetColorFilter(Util.Int32ToColor(2130706432), PorterDuff.Mode.SrcIn);
                    canvas.Skew(-0.9F, 0.0F);
                    canvas.Scale(1.0F, 0.5F);
                }

                drawable.Draw(canvas);
                if (shadow)
                {
                    drawable.ClearColorFilter();
                }
            }
            finally
            {
                canvas.Restore();
            }
        }
        protected override void DispatchDraw(Canvas canvas)
        {
            base.DispatchDraw(canvas);

            if (mDrag && (mShadowBuilder != null))
            {
                Point size = new Point();
                Point touchPoint = new Point();

                mShadowBuilder.OnProvideShadowMetrics(size, touchPoint);

                canvas.Save();
                canvas.Translate(mX - touchPoint.X, mY - touchPoint.Y);
                mShadowBuilder.OnDraw(canvas);
                canvas.Restore();
            }
        }
Exemple #59
0
		protected override void OnDraw (Canvas canvas)
		{
			base.OnDraw (canvas);

			// Clear screen to pink.
			paint.Color = new Color (255, 204, 204);
			canvas.DrawPaint (paint);

			// Overall transforms to shift (0, 0) to center and scale.
			canvas.Translate (this.Width / 2, this.Height / 2);
			float scale = Math.Min (this.Width, this.Height) / 2.0f / 100;
			canvas.Scale (scale, scale);

			// Attributes for tick marks.
			paint.Color = Color.Black;
			paint.StrokeCap = Paint.Cap.Round;
			paint.SetStyle (Paint.Style.Stroke);

			// Set line dash to draw tick marks for every minute.
			paint.StrokeWidth = 3;
			paint.SetPathEffect (minuteTickDashEffect);
			canvas.DrawPath (tickMarks, paint);

			// Set line dash to draw tick marks for every hour.
			paint.StrokeWidth = 6;
			paint.SetPathEffect (hourTickDashEffect);
			canvas.DrawPath (tickMarks, paint);

			// Set attributes common to all clock hands.
			Color strokeColor = Color.Black;
			Color fillColor = Color.Blue;
			paint.StrokeWidth = 2;
			paint.SetPathEffect (null);

			// Draw hour hand.
			canvas.Save ();
			canvas.Rotate (this.hourAngle);
			paint.Color = fillColor;
			paint.SetStyle (Paint.Style.Fill);
			canvas.DrawPath (hourHand, paint);
			paint.Color = strokeColor;
			paint.SetStyle (Paint.Style.Stroke);
			canvas.DrawPath (hourHand, paint);
			canvas.Restore ();

			// Draw minute hand.
			canvas.Save ();
			canvas.Rotate (this.minuteAngle);
			paint.Color = fillColor;
			paint.SetStyle (Paint.Style.Fill);
			canvas.DrawPath (minuteHand, paint);
			paint.Color = strokeColor;
			paint.SetStyle (Paint.Style.Stroke);
			canvas.DrawPath (minuteHand, paint);
			canvas.Restore ();

			// Draw second hand.
			canvas.Save ();
			canvas.Rotate (this.secondAngle);
			paint.Color = strokeColor;
			paint.SetStyle (Paint.Style.Stroke);
			canvas.DrawPath (secondHand, paint);
			canvas.Restore ();
		}
Exemple #60
0
        protected override bool DrawChild(Android.Graphics.Canvas canvas, Android.Views.View child, long drawingTime)
        {
            var fImage = (CircularImage)this.Element;

            try
            {
                var radius = (float)Math.Min(Width, Height) / 2f;

                var borderThickness = fImage.BorderWidth;

                float strokeWidth = 0f;

                if (borderThickness > 0)
                {
                    var logicalDensity = Xamarin.Forms.Forms.Context.Resources.DisplayMetrics.Density;
                    strokeWidth = (float)Math.Ceiling(borderThickness * logicalDensity + .5f);
                }

                radius -= strokeWidth / 2f;



                var path = new Path();
                path.AddCircle(Width / 2.0f, Height / 2.0f, radius, Path.Direction.Ccw);


                canvas.Save();
                canvas.ClipPath(path);



                var paint = new Paint
                {
                    AntiAlias = true
                };
                paint.SetStyle(Paint.Style.Fill);
                paint.Color = fImage.BorderColor.ToAndroid();
                canvas.DrawPath(path, paint);
                paint.Dispose();


                var result = base.DrawChild(canvas, child, drawingTime);

                path.Dispose();
                canvas.Restore();

                path = new Path();
                path.AddCircle(Width / 2f, Height / 2f, radius, Path.Direction.Ccw);


                if (strokeWidth > 0.0f)
                {
                    paint             = new Paint();
                    paint.AntiAlias   = true;
                    paint.StrokeWidth = strokeWidth;
                    paint.SetStyle(Paint.Style.Stroke);
                    paint.Color = fImage.BorderColor.ToAndroid();
                    canvas.DrawPath(path, paint);
                    paint.Dispose();
                }

                path.Dispose();
                return(result);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex);
            }

            return(base.DrawChild(canvas, child, drawingTime));
        }