/// <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)
			{				
			}				
		}
 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));
 }
示例#3
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 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();
        }
        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 (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);
        }
        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 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);
                    }
                }
            }
        }
 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);
 }
示例#10
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();
 }
示例#11
0
        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);
        }
		protected override void OnDraw (Canvas canvas)
		{
			base.OnDraw (canvas);
			canvas.Save ();
			canvas.Translate (_posX, _posY);
			canvas.Scale (_scaleFactor, _scaleFactor);
			_icon.Draw (canvas);
			canvas.Restore ();
		}
示例#13
0
        // 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 ();
        }
 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)
 {
     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();
        }
        /// <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);
        }
示例#18
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();
            }
        }
示例#19
0
			protected override void OnDraw (Canvas canvas)
			{
				canvas.DrawColor (Color.White);

				canvas.Translate (10, 10);

				canvas.SaveLayerAlpha (0, 0, 200, 200, 0x88, SaveFlags.All);

				mPaint.Color = Color.Red;
				canvas.DrawCircle (75, 75, 75, mPaint);
				mPaint.Color = Color.Blue;
				canvas.DrawCircle (125, 125, 75, mPaint);

				canvas.Restore ();
			}
        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();
        }
示例#21
0
		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;
		}
        /// <summary>
        /// 
        /// </summary>
        /// <param name="canvas"></param>
        /// <param name="child"></param>
        /// <param name="drawingTime"></param>
        /// <returns></returns>
        protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
        {
            try
            {

                var radius = Math.Min(Width, Height) / 2;
                var strokeWidth = ((ImageCircle.Forms.Plugin.Abstractions.CircleImage)Element).BorderThickness;
                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 thickness = ((ImageCircle.Forms.Plugin.Abstractions.CircleImage)Element).BorderThickness;
                if(thickness > 0.0f)
                {
                    var paint = new Paint();
                    paint.AntiAlias = true;
                    paint.StrokeWidth = thickness;
                    paint.SetStyle(Paint.Style.Stroke);
                    paint.Color = ((ImageCircle.Forms.Plugin.Abstractions.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);
        }
        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);
        }
示例#24
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();
        }
        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 ();
            }
        }
示例#26
0
        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();
        }
        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);
        }
        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();
        }
示例#29
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));
        }
示例#30
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();
        }
示例#31
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);
        }
示例#32
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));
        }
示例#33
0
		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 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(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();
        }
示例#36
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();
            }
        }
		public override void Draw (Canvas canvas)
		{
			if (flip) {
				canvas.Save();
				canvas.Scale(1f, -1f, IntrinsicWidth / 2, IntrinsicHeight / 2);
			}
			topLine.draw(canvas);
			middleLine.draw(canvas);
			bottomLine.draw(canvas);

			if (flip) canvas.Restore();
			//			throw new NotImplementedException ();
		}
示例#38
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 ();
		}
示例#39
0
			/// <summary>
			/// Draws the ship, fuel/speed bars, and background to the provided
			/// Canvas.
			/// </summary>
			private void DoDraw(Canvas canvas)
			{
				// Draw the background image. Operations on the Canvas accumulate
				// so this is like clearing the screen.
				canvas.DrawBitmap(mBackgroundImage, 0, 0, null);

				int yTop = mCanvasHeight - ((int) mY + mLanderHeight / 2);
				int xLeft = (int) mX - mLanderWidth / 2;

				// Draw the fuel gauge
				int fuelWidth = (int)(UI_BAR * mFuel / PHYS_FUEL_MAX);
				mScratchRect.Set(4, 4, 4 + fuelWidth, 4 + UI_BAR_HEIGHT);
				canvas.DrawRect(mScratchRect, mLinePaint);

				// Draw the speed gauge, with a two-tone effect
				double speed = Math.Sqrt(mDX * mDX + mDY * mDY);
				int speedWidth = (int)(UI_BAR * speed / PHYS_SPEED_MAX);

				if (speed <= mGoalSpeed)
				{
					mScratchRect.Set(4 + UI_BAR + 4, 4, 4 + UI_BAR + 4 + speedWidth, 4 + UI_BAR_HEIGHT);
					canvas.DrawRect(mScratchRect, mLinePaint);
				}
				else
				{
					// Draw the bad color in back, with the good color in front of
					// it
					mScratchRect.Set(4 + UI_BAR + 4, 4, 4 + UI_BAR + 4 + speedWidth, 4 + UI_BAR_HEIGHT);
					canvas.DrawRect(mScratchRect, mLinePaintBad);
					int goalWidth = (UI_BAR * mGoalSpeed / PHYS_SPEED_MAX);
					mScratchRect.Set(4 + UI_BAR + 4, 4, 4 + UI_BAR + 4 + goalWidth, 4 + UI_BAR_HEIGHT);
					canvas.DrawRect(mScratchRect, mLinePaint);
				}

				// Draw the landing pad
				canvas.DrawLine(mGoalX, 1 + mCanvasHeight - TARGET_PAD_HEIGHT, mGoalX + mGoalWidth, 1 + mCanvasHeight - TARGET_PAD_HEIGHT, mLinePaint);


				// Draw the ship with its current rotation
				canvas.Save();
				canvas.Rotate((float) mHeading, (float) mX, mCanvasHeight - (float) mY);
				if (mMode == STATE_LOSE)
				{
					mCrashedImage.SetBounds(xLeft, yTop, xLeft + mLanderWidth, yTop + mLanderHeight);
					mCrashedImage.Draw(canvas);
				}
				else if (mEngineFiring)
				{
					mFiringImage.SetBounds(xLeft, yTop, xLeft + mLanderWidth, yTop + mLanderHeight);
					mFiringImage.Draw(canvas);
				}
				else
				{
					mLanderImage.SetBounds(xLeft, yTop, xLeft + mLanderWidth, yTop + mLanderHeight);
					mLanderImage.Draw(canvas);
				}
				canvas.Restore();
			}
		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();
		}
示例#41
0
        protected override bool DrawChild(Android.Graphics.Canvas canvas, Android.Views.View child, long drawingTime)
        {
            if (Element == null)
            {
                return(false);
            }

            RoundedCornerView rcv = (RoundedCornerView)Element;

            this.SetClipChildren(true);

            rcv.Padding = new Thickness(0, 0, 0, 0);
            //rcv.HasShadow = false;

            int radius = (int)(rcv.RoundedCornerRadius);

            // Check if make circle is set to true. If so, then we just use the width and
            // height of the control to calculate the radius. RoundedCornerRadius will be ignored
            // in this case.
            if (rcv.MakeCircle)
            {
                radius = Math.Min(Width, Height) / 2;
            }

            // When we create a round rect, we will have to double the radius since it is not
            // the same as creating a circle.
            radius *= 2;

            try
            {
                //Create path to clip the child
                var path = new Path();
                path.AddRoundRect(new RectF(0, 0, Width, Height),
                                  new float[] { radius, radius, radius, radius, radius, radius, radius, radius },
                                  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();

                /*
                 * If a border is specified, we use the same path created above to stroke
                 * with the border color.
                 * */
                if (rcv.BorderWidth > 0)
                {
                    // Draw a filled circle.
                    var paint = new Paint();
                    paint.AntiAlias   = true;
                    paint.StrokeWidth = rcv.BorderWidth;
                    paint.SetStyle(Paint.Style.Stroke);
                    paint.Color = rcv.BorderColor.ToAndroid();

                    canvas.DrawPath(path, paint);

                    paint.Dispose();
                }

                //Properly dispose
                path.Dispose();
                return(result);
            }
            catch (Exception ex)
            {
                System.Console.Write(ex.Message);
            }

            return(base.DrawChild(canvas, child, drawingTime));
        }
		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 ();
		}
示例#43
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));
        }
 public void DrawSelector(View content, Canvas canvas, float openPercent)
 {
     if (!SelectorEnabled) return;
     if (_selectorDrawable != null && SelectedView != null)
     {
         var tag = (string)SelectedView.GetTag(Resource.Id.selected_view);
         if (tag.Equals(Tag + "SelectedView"))
         {
             canvas.Save();
             int left, right;
             var offset = (int)(SelectorBitmap.Width * openPercent);
             if (Mode == MenuMode.Left)
             {
                 right = content.Left;
                 left = right - offset;
                 canvas.ClipRect(left, 0, right, Height);
                 canvas.DrawBitmap(SelectorBitmap, left, SelectorTop, null);
             }
             else if (Mode == MenuMode.Right)
             {
                 left = content.Right;
                 right = left + offset;
                 canvas.ClipRect(left, 0, right, Height);
                 canvas.DrawBitmap(SelectorBitmap, right - SelectorBitmap.Width, SelectorTop, null);
             }
             canvas.Restore();
         }
     }
 }
示例#45
0
        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();
            }
        }
 protected override void DispatchDraw(Canvas canvas)
 {
     if (_transformer != null)
     {
         canvas.Save();
         _transformer.TransformCanvas(canvas, CustomViewAbove.PercentOpen);
         base.DispatchDraw(canvas);
         canvas.Restore();
     }
     else
         base.DispatchDraw(canvas);
 }