Exemple #1
0
        protected override void OnDraw(Shape shape, Android.Graphics.Canvas canvas, Paint paint)
        {
            var height = canvas.ClipBounds.Bottom;
            var width  = canvas.ClipBounds.Right;

            if (noChild)
            {
                var borderHeight = (int)(this.borderThickness.Top + this.borderThickness.Bottom);
                var borderWidth  = (int)(this.borderThickness.Left + this.borderThickness.Right);
                height = borderHeight > 0 ? borderHeight : canvas.ClipBounds.Bottom;
                width  = borderWidth > 0 ? borderWidth : canvas.ClipBounds.Right;
            }
            shape.Resize(width, height);
            shape.Draw(canvas, strokepaint);

            var pathInner = new Path();
            var rect      = new RectF(
                (float)(borderThickness.Left),
                (float)(borderThickness.Top),
                (float)(canvas.ClipBounds.Right - borderThickness.Right),
                (float)(canvas.ClipBounds.Bottom - borderThickness.Bottom));

            pathInner.AddRoundRect(rect, cornerRadiusArray, Path.Direction.Cw);
            if (!noChild)
            {
                var clearPaint = new Paint();
                clearPaint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.Clear));
                canvas.DrawPath(pathInner, clearPaint);
            }
            canvas.DrawPath(pathInner, fillpaint);
        }
        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);
        }
        private void DrawBorder(ACanvas canvas, CorneredContentView control)
        {
            if (control.BorderThickness > 0)
            {
                float borderThickness     = this.Context.ToPixels(control.BorderThickness);
                float halfBorderThickness = borderThickness / 2;

                using (Paint paint = new Paint {
                    AntiAlias = true
                })
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Stroke)
                            using (RectF rect = new RectF(!control.HasShadow ? -halfBorderThickness : halfBorderThickness,
                                                          !control.HasShadow ? -halfBorderThickness : halfBorderThickness,
                                                          !control.HasShadow ? canvas.Width + halfBorderThickness : canvas.Width - halfBorderThickness,
                                                          !control.HasShadow ? canvas.Height + halfBorderThickness : canvas.Height - halfBorderThickness))
                            {
                                Path path = new Path();
                                path.AddRoundRect(rect, this.GetRadii(control), direction);

                                paint.Color = control.BorderColor.ToAndroid();

                                paint.StrokeCap   = Paint.Cap.Square;
                                paint.StrokeWidth = borderThickness;

                                paint.SetStyle(style);

                                canvas.DrawPath(path, paint);
                            }
            }
        }
Exemple #4
0
        void DrawOutline(Android.Graphics.Canvas canvas, int width, int height)
        {
            if (this.Element is FrameApp)
            {
                int strokeWidth = (int)TypedValue.ApplyDimension(ComplexUnitType.Dip, 1, Context.Resources.DisplayMetrics);

                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (var path = new Path())
                        using (Path.Direction direction = Path.Direction.Cw)
                            using (Paint.Style style = Paint.Style.Stroke)


                                using (var rect = new RectF(strokeWidth + strokeWidth / 2, strokeWidth + strokeWidth / 2, width - strokeWidth - strokeWidth / 2, height - strokeWidth - strokeWidth / 2))
                                {
                                    if (this.Element.CornerRadius > 0)
                                    {
                                        float rx = this.Context.ToPixels(this.Element.CornerRadius);
                                        float ry = this.Context.ToPixels(this.Element.CornerRadius);

                                        path.AddRoundRect(rect, rx, ry, direction);
                                    }
                                    else
                                    {
                                        path.AddRect(rect, direction);
                                    }
                                    paint.StrokeWidth = strokeWidth; //set outline stroke
                                    paint.SetStyle(style);
                                    paint.Color = (this.Element as FrameApp).BorderColor.ToAndroid();

                                    canvas.DrawPath(path, paint);
                                }
            }
        }
Exemple #5
0
        private void DrawStroke(Canvas canvas)
        {
            var stroke = Stroke;

            if (!HasStroke || stroke is ImageBrush)
            {
                return;
            }

            var strokeThickness = PhysicalStrokeThickness;

            using (var strokePaint = new Paint(stroke.GetStrokePaint(_drawArea)))
            {
                SetStrokeDashEffect(strokePaint);

                if (_drawArea.HasZeroArea())
                {
                    //Draw the stroke as a fill because the shape has no area
                    strokePaint.SetStyle(Paint.Style.Fill);
                    canvas.DrawCircle((float)(strokeThickness / 2), (float)(strokeThickness / 2), (float)(strokeThickness / 2), strokePaint);
                }
                else
                {
                    strokePaint.StrokeWidth = (float)strokeThickness;
                    canvas.DrawPath(_path, strokePaint);
                }
            }
        }
 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));
 }
Exemple #7
0
 protected void DrawShape(Canvas canvas)
 {
   Paint paint = new Paint();
   paint.Color = Color;
   switch (Shape)
   {
     case ShapeEnum.RectangleShape:
       canvas.DrawRect(0, 0, ShapeWidth, ShapeHeight, paint);
       break;
     case ShapeEnum.OvalShape:
       canvas.DrawOval(new RectF(0, 0, ShapeWidth, ShapeHeight), paint);
       break;
     case ShapeEnum.TriangleShape:
         Path path = new Path();
         path.MoveTo(ShapeWidth / 2, 0);
         path.LineTo(ShapeWidth, ShapeHeight);
         path.LineTo(0,ShapeHeight);
         path.Close();
       canvas.DrawPath(path, paint);
       break;
     default:
       canvas.DrawCircle(ShapeWidth / 2, ShapeHeight / 2, ShapeWidth / 2, paint); 
       break;
   }
 }
		protected override void OnDraw (Canvas canvas)
		{
			
			drawCanvas = canvas;
			canvas.DrawBitmap(canvasBitmap, 0, 0, canvasPaint);
			canvas.DrawPath(drawPath, drawPaint);
		}
Exemple #9
0
            void DrawOutline(ACanvas canvas, int width, int height, Thickness cornerRadius)
            {
                var borderThickness     = _convertToPixels(_pancake.BorderThickness);
                var halfBorderThickness = borderThickness / 2;

                // TODO: This doesn't look entirely right yet when using it with rounded corners.
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (var path = new Path())
                        using (Path.Direction direction = Path.Direction.Cw)
                            using (Paint.Style style = Paint.Style.Stroke)
                                using (var rect = new RectF(halfBorderThickness, halfBorderThickness, width - halfBorderThickness, height - halfBorderThickness))
                                {
                                    float topLeft     = _convertToPixels(cornerRadius.Left);
                                    float topRight    = _convertToPixels(cornerRadius.Top);
                                    float bottomRight = _convertToPixels(cornerRadius.Right);
                                    float bottomLeft  = _convertToPixels(cornerRadius.Bottom);

                                    path.AddRoundRect(rect, new float[] { topLeft, topLeft, topRight, topRight, bottomRight, bottomRight, bottomLeft, bottomLeft }, direction);

                                    if (_pancake.BorderIsDashed)
                                    {
                                        paint.SetPathEffect(new DashPathEffect(new float[] { 10, 20 }, 0));
                                    }

                                    paint.StrokeCap   = Paint.Cap.Round;
                                    paint.StrokeWidth = borderThickness;
                                    paint.SetStyle(style);
                                    paint.Color = _pancake.BorderColor.ToAndroid();

                                    canvas.DrawPath(path, paint);
                                }
            }
		protected override void OnDraw (Canvas canvas)
		{
			if (this.currentPath == null || this.currentPath.IsEmpty)
				return;

			canvas.DrawPath (this.currentPath, this.currentPaint);
		}
        private void DrawBorder(ACanvas canvas, PancakeView control)
        {
            var borderThickness     = Context.ToPixels(control.BorderThickness);
            var halfBorderThickness = borderThickness / 2;

            // TODO: This doesn't look entirely right yet when using it with rounded corners.
            using (var paint = new Paint {
                AntiAlias = true
            })
                using (var path = new Path())
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Stroke)

                            using (var rect = new RectF(control.DrawBorderOnOutside && !control.HasShadow ? -halfBorderThickness : halfBorderThickness,
                                                        control.DrawBorderOnOutside && !control.HasShadow ? -halfBorderThickness : halfBorderThickness,
                                                        control.DrawBorderOnOutside && !control.HasShadow ? canvas.Width + halfBorderThickness : canvas.Width - halfBorderThickness,
                                                        control.DrawBorderOnOutside && !control.HasShadow ? canvas.Height + halfBorderThickness : canvas.Height - halfBorderThickness))
                            {
                                path.AddRoundRect(rect, GetRadii(control), direction);

                                if (control.BorderIsDashed)
                                {
                                    paint.SetPathEffect(new DashPathEffect(new float[] { 10, 20 }, 0));
                                }

                                paint.StrokeCap   = Paint.Cap.Square;
                                paint.StrokeWidth = borderThickness;
                                paint.SetStyle(style);
                                paint.Color = control.BorderColor.ToAndroid();

                                canvas.DrawPath(path, paint);
                            }
        }
Exemple #12
0
            void DrawBackground(ACanvas canvas, int width, int height, float cornerRadius, bool pressed)
            {
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (var path = new APath())
                        using (APath.Direction direction = APath.Direction.Cw)
                            using (Paint.Style style = Paint.Style.Fill)
                                using (var rect = new RectF(0, 0, width, height))
                                {
                                    float rx = _convertToPixels(cornerRadius);
                                    float ry = _convertToPixels(cornerRadius);
                                    path.AddRoundRect(rect, rx, ry, direction);

                                    paint.SetStyle(style);

                                    if (!Brush.IsNullOrEmpty(_frame.Background))
                                    {
                                        Brush background = _frame.Background;
                                        paint.UpdateBackground(background, height, width);
                                    }
                                    else
                                    {
                                        global::Android.Graphics.Color color = _frame.BackgroundColor.ToAndroid();
                                        paint.Color = color;
                                    }

                                    canvas.DrawPath(path, paint);
                                }
            }
 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);
 }
Exemple #14
0
        void DrawBackground(ACanvas canvas, int width, int height, CornerRadius cornerRadius, bool pressed)
        {
            using (Paint paint = new Paint {
                AntiAlias = true
            })
                using (Path.Direction direction = Path.Direction.Cw)
                    using (Paint.Style style = Paint.Style.Fill)
                    {
                        Path path = new Path();

                        using (RectF rect = new RectF(0, 0, width, height))
                        {
                            float topLeft     = this._convertToPixels(cornerRadius.TopLeft);
                            float topRight    = this._convertToPixels(cornerRadius.TopRight);
                            float bottomRight = this._convertToPixels(cornerRadius.BottomRight);
                            float bottomLeft  = this._convertToPixels(cornerRadius.BottomLeft);

                            if (!this._corneredContentView.HasShadow)
                            {
                                path.AddRoundRect(rect, new float[] { topLeft, topLeft, topRight, topRight, bottomRight, bottomRight, bottomLeft, bottomLeft }, direction);
                            }
                            else
                            {
                                path.AddRoundRect(rect, new float[] { topLeft, topLeft, topLeft, topLeft, topLeft, topLeft, topLeft, topLeft }, direction);
                            }
                        }

                        global::Android.Graphics.Color color = this._corneredContentView.BackgroundColor.ToAndroid();
                        paint.SetStyle(style);
                        paint.Color = color;

                        canvas.DrawPath(path, paint);
                    }
        }
Exemple #15
0
            void DrawBackground(ACanvas canvas, int width, int height, float cornerRadius, bool pressed)
            {
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (var path = new Path())
                        using (Path.Direction direction = Path.Direction.Cw)
                            using (Paint.Style style = Paint.Style.Fill)
                                using (var rect = new RectF(
                                           _bounds + _boundsDiff + _contentBounds,
                                           _bounds + _boundsDiff + _contentBounds,
                                           width - (_bounds + _boundsDiff + _contentBounds),
                                           height - (_bounds + _boundsDiff + _contentBounds)))
                                {
                                    float rx = _convertToPixels(cornerRadius);
                                    float ry = _convertToPixels(cornerRadius);
                                    path.AddRoundRect(rect, rx, ry, direction);

                                    global::Android.Graphics.Color color = _frame.BackgroundColor.ToAndroid();


                                    paint.SetStyle(style);
                                    paint.Color = color;

                                    canvas.DrawPath(path, paint);
                                }
            }
Exemple #16
0
            void DrawOutline(ACanvas canvas, int width, int height, float cornerRadius)
            {
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (var path = new Path())
                        using (Path.Direction direction = Path.Direction.Cw)
                            using (Paint.Style style = Paint.Style.Stroke)
                                using (var rect = new RectF(left: _bounds, top: _bounds, right: width - _bounds, bottom: height - _bounds))
                                    using (var innerRect = new RectF(
                                               left: _bounds + _boundsDiff,
                                               top: _bounds + _boundsDiff,
                                               right: width - (_bounds + _boundsDiff),
                                               bottom: height - (_bounds + _boundsDiff)))
                                    {
                                        float rx = _convertToPixels(cornerRadius);
                                        float ry = _convertToPixels(cornerRadius);
                                        path.AddRoundRect(rect, rx, ry, direction);
                                        path.AddRoundRect(innerRect, rx, ry, direction);

                                        paint.StrokeWidth = _frameThickness;
                                        paint.SetStyle(style);
                                        paint.Color = _frame.BorderColor.ToAndroid();

                                        canvas.DrawPath(path, paint);
                                    }
            }
Exemple #17
0
		public void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint) {
			Path path = this.parse(pSVGProperties);

			bool fill = pSVGPaint.setFill(pSVGProperties);
			if (fill) {
				pCanvas.DrawPath(path, pSVGPaint.getPaint());
			}

			bool stroke = pSVGPaint.setStroke(pSVGProperties);
			if (stroke) {
				pCanvas.DrawPath(path, pSVGPaint.getPaint());
			}

			if(fill || stroke) {
				pSVGPaint.ensureComputedBoundsInclude(path);
			}
		}
Exemple #18
0
		protected override void OnDraw(Canvas canvas)
		{
			base.OnDraw(canvas);

			DrawPaint.Color = CurrentLineColor;
			canvas.DrawBitmap(CanvasBitmap, 0, 0, CanvasPaint);
			canvas.DrawPath(DrawPath, DrawPaint);
		}
Exemple #19
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();
        }
 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();
 }
Exemple #21
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();
            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 #23
0
		protected override void OnDraw (Canvas canvas)
		{
			base.OnDraw (canvas);

			float l = 0;
			float t = Height - PaddingBottom - DipToPixels (Context, 217);
			float r = Width - PaddingRight;
			float b = Height - DipToPixels (Context, 60);

			canvas.DrawRect (l, t, r, b, boxPaint);
			canvas.DrawPath (path, pathPaint);
		}
        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 #25
0
            private void DrawBackground(ACanvas canvas, Path path, bool pressed)
            {
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (var style = Paint.Style.Fill)
                    {
                        paint.SetStyle(style);
                        paint.Color = _frame.BackgroundColor.ToAndroid();

                        canvas.DrawPath(path, paint);
                    }
            }
Exemple #26
0
		public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint) {
			var points = pSVGProperties.GetStringAttribute(SVGConstants.ATTRIBUTE_POINTS).ParseFloats ();
			if (points != null) {
				if (points.Length >= 2) {
					Path path = SVGPolylineParser.parse(points);

					bool fill = pSVGPaint.setFill(pSVGProperties);
					if (fill) {
						pCanvas.DrawPath(path, pSVGPaint.getPaint());
					}

					bool stroke = pSVGPaint.setStroke(pSVGProperties);
					if (stroke) {
						pCanvas.DrawPath(path, pSVGPaint.getPaint());
					}

					if(fill || stroke) {
						pSVGPaint.ensureComputedBoundsInclude(path);
					}
				}
			}
		}
        /// <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 #28
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);
        }
        void DrawBackground(ACanvas canvas, int width, int height, CornerRadius cornerRadius)
        {
            using (var paint = new Paint {
                AntiAlias = true
            })
                using (Path.Direction direction = Path.Direction.Cw)
                    using (Paint.Style style = Paint.Style.Fill)
                    {
                        var path = new Path();

                        if (_pancake.Sides != 4)
                        {
                            path = DrawingExtensions.CreatePolygonPath(width, height, _pancake.Sides, _pancake.CornerRadius.TopLeft, _pancake.OffsetAngle);
                        }
                        else
                        {
                            float topLeft     = _convertToPixels(cornerRadius.TopLeft);
                            float topRight    = _convertToPixels(cornerRadius.TopRight);
                            float bottomRight = _convertToPixels(cornerRadius.BottomRight);
                            float bottomLeft  = _convertToPixels(cornerRadius.BottomLeft);

                            path = DrawingExtensions.CreateRoundedRectPath(width, height, topLeft, topRight, bottomRight, bottomLeft);
                        }

                        if (_pancake.BackgroundGradientStops != null && _pancake.BackgroundGradientStops.Any())
                        {
                            // A range of colors is given. Let's add them.
                            var orderedStops = _pancake.BackgroundGradientStops.OrderBy(x => x.Offset).ToList();
                            var colors       = orderedStops.Select(x => x.Color.ToAndroid().ToArgb()).ToArray();
                            var locations    = orderedStops.Select(x => x.Offset).ToArray();

                            var shader = new LinearGradient((float)(canvas.Width * _pancake.BackgroundGradientStartPoint.X),
                                                            (float)(canvas.Height * _pancake.BackgroundGradientStartPoint.Y),
                                                            (float)(canvas.Width * _pancake.BackgroundGradientEndPoint.X),
                                                            (float)(canvas.Height * _pancake.BackgroundGradientEndPoint.Y),
                                                            colors, locations, Shader.TileMode.Clamp);

                            paint.SetShader(shader);
                        }
                        else
                        {
                            global::Android.Graphics.Color color = _pancake.BackgroundColor.ToAndroid();
                            paint.SetStyle(style);
                            paint.Color = color;
                        }

                        canvas.DrawPath(path, paint);
                    }
        }
        private void DrawBackground(ACanvas canvas, int width, int height, CornerRadius cornerRadius, bool pressed)
        {
            using (var paint = new Paint {
                AntiAlias = true
            })
                using (var path = PolygonUitls.RegularPolygonPath(width, height, _polygonFrame.Sides, _polygonFrame.CornerRadius, 0, _polygonFrame.OffsetAngle))
                    using (Paint.Style style = Paint.Style.Fill)
                    {
                        global::Android.Graphics.Color color = _polygonFrame.BackgroundColor.ToAndroid();
                        paint.SetStyle(style);
                        paint.Color = color;

                        canvas.DrawPath(path, paint);
                    }
        }
Exemple #31
0
            void DrawOutline(ACanvas canvas, Path path)
            {
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Stroke)
                        {
                            paint.StrokeWidth = 1;
                            paint.SetStyle(style);
                            paint.Color = _frame.OutlineColor.ToAndroid();

                            canvas.DrawPath(path, paint);
                        }
            }
Exemple #32
0
            void DrawBackground(ACanvas canvas, Path path, bool pressed)
            {
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Fill)
                        {
                            global::Android.Graphics.Color color = _frame.InnerBackground.ToAndroid();

                            paint.SetStyle(style);
                            paint.Color = color;

                            canvas.DrawPath(path, paint);
                        }
            }
        void DrawBackground(ACanvas canvas, int width, int height, CornerRadius cornerRadius, bool pressed)
        {
            using (var paint = new Paint {
                AntiAlias = true
            })
                using (var path = new Path())
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Fill)
                            using (var rect = new RectF(0, 0, width, height))
                            {
                                float topLeft     = _convertToPixels(cornerRadius.TopLeft);
                                float topRight    = _convertToPixels(cornerRadius.TopRight);
                                float bottomRight = _convertToPixels(cornerRadius.BottomRight);
                                float bottomLeft  = _convertToPixels(cornerRadius.BottomLeft);

                                if (!_pancake.HasShadow)
                                {
                                    path.AddRoundRect(rect, new float[] { topLeft, topLeft, topRight, topRight, bottomRight, bottomRight, bottomLeft, bottomLeft }, direction);
                                }
                                else
                                {
                                    path.AddRoundRect(rect, new float[] { topLeft, topLeft, topLeft, topLeft, topLeft, topLeft, topLeft, topLeft }, direction);
                                }

                                if (_pancake.BackgroundGradientStartColor != default(Xamarin.Forms.Color) && _pancake.BackgroundGradientEndColor != default(Xamarin.Forms.Color))
                                {
                                    var angle = _pancake.BackgroundGradientAngle / 360.0;

                                    // Calculate the new positions based on angle between 0-360.
                                    var a = width * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.75) / 2)), 2);
                                    var b = height * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.0) / 2)), 2);
                                    var c = width * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.25) / 2)), 2);
                                    var d = height * Math.Pow(Math.Sin(2 * Math.PI * ((angle + 0.5) / 2)), 2);

                                    var shader = new LinearGradient(width - (float)a, (float)b, width - (float)c, (float)d, _pancake.BackgroundGradientStartColor.ToAndroid(), _pancake.BackgroundGradientEndColor.ToAndroid(), Shader.TileMode.Clamp);
                                    paint.SetShader(shader);
                                }
                                else
                                {
                                    global::Android.Graphics.Color color = _pancake.BackgroundColor.ToAndroid();
                                    paint.SetStyle(style);
                                    paint.Color = color;
                                }

                                canvas.DrawPath(path, paint);
                            }
        }
 protected override void DrawRightThumb(Android.Graphics.Canvas p0, float x1, float y1, float x2, float y2)
 {
     float density = Context.Resources.DisplayMetrics.Density;
     Paint paint = new Paint();
     paint.AntiAlias = true;
     RectF rounderRectF = new RectF(x2 - (1.66f * density), y2 - (3.33f * density), x2 + (16.66f * density), y2 + (16.66f * density));
     paint.Color = (Color.ParseColor("#5f6872"));
     p0.DrawRoundRect(rounderRectF, 7, 7, paint);
     Path path = new Path();
     path.MoveTo(x2, y2 - (16.66f * density));
     path.LineTo(x2, y2);
     path.LineTo(x2 + (16.66f * density), y2 - (2 * density));
     path.Close();
     p0.DrawPath(path, paint);
     paint.StrokeWidth = (3.33f * density);
     p0.DrawLine(x1, y1, x2, y2, paint);
     SetRightThumbBounds(new RectF(x2 - 25, y1 - 25, x2 + 25, y2 + 25));
 }
Exemple #35
0
 protected void DrawFill(Android.Graphics.Canvas canvas, Windows.Foundation.Rect fillArea, Android.Graphics.Path fillPath)
 {
     if (!fillArea.HasZeroArea())
     {
         var imageBrushFill = Fill as ImageBrush;
         if (imageBrushFill != null)
         {
             imageBrushFill.ScheduleRefreshIfNeeded(fillArea, Invalidate);
             imageBrushFill.DrawBackground(canvas, fillArea, fillPath);
         }
         else
         {
             var fill      = Fill ?? SolidColorBrushHelper.Transparent;
             var fillPaint = fill.GetFillPaint(fillArea);
             canvas.DrawPath(fillPath, fillPaint);
         }
     }
 }
        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 #37
0
        private void DrawFill(Canvas canvas)
        {
            if (_drawArea.HasZeroArea())
            {
                return;
            }

            if (Fill is ImageBrush imageBrushFill)
            {
                imageBrushFill.ScheduleRefreshIfNeeded(_drawArea, Invalidate);
                imageBrushFill.DrawBackground(canvas, _drawArea, _path);
            }
            else
            {
                var fill      = Fill ?? SolidColorBrushHelper.Transparent;
                var fillPaint = fill.GetFillPaint(_drawArea);
                canvas.DrawPath(_path, fillPaint);
            }
        }
Exemple #38
0
            private void DrawOutline(ACanvas canvas, Path path)
            {
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (var style = Paint.Style.Stroke)
                    {
                        paint.StrokeWidth = (float)_frame.StrokeThickness;
                        paint.SetStyle(style);
                        paint.Color = _frame.BorderColor.ToAndroid();

                        if (_frame.StrokeDashLength > 0 && _frame.StrokeDashGap > 0)
                        {
                            paint.SetPathEffect(new DashPathEffect(new[] { (float)_frame.StrokeDashLength, (float)_frame.StrokeDashGap }, 0));
                        }

                        canvas.DrawPath(path, paint);
                    }
            }
Exemple #39
0
        void DrawOutline(ACanvas canvas, int width, int height, float cornerRadius)
        {
            using (var paint = new Paint {
                AntiAlias = true
            })
                using (var path = new Path())
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Stroke)
                            using (var rect = new RectF(0, 0, width, height)) {
                                float rx = Forms.Context.ToPixels(cornerRadius);
                                float ry = Forms.Context.ToPixels(cornerRadius);
                                path.AddRoundRect(rect, rx, ry, direction);

                                paint.StrokeWidth = element.OutlineWidth;  //set outline stroke
                                paint.SetStyle(style);
                                paint.Color = element.OutlineColor.ToAndroid();
                                //paint.Color = Color.ParseColor("#A7AE22");//set outline color //_frame.OutlineColor.ToAndroid();
                                canvas.DrawPath(path, paint);
                            }
        }
Exemple #40
0
            void DrawOutline(ACanvas canvas, int width, int height)
            {
                using (var paint = new Paint {
                    AntiAlias = true
                })
                    using (var path = new Path())
                        using (Path.Direction direction = Path.Direction.Cw)
                            using (Paint.Style style = Paint.Style.Stroke)
                                using (var rect = new RectF(0, 0, width, height)) {
                                    float rx = Forms.Context.ToPixels(_frame.CornerRadius);
                                    float ry = Forms.Context.ToPixels(_frame.CornerRadius);
                                    path.AddRoundRect(rect, rx, ry, direction);

                                    paint.StrokeWidth = Forms.Context.ToPixels(_frame.BorderWidth);
                                    paint.SetStyle(style);
                                    paint.Color = _frame.BorderColor.ToAndroid();

                                    canvas.DrawPath(path, paint);
                                }
            }
Exemple #41
0
        void DrawOutline(ACanvas canvas, int width, int height, float cornerRadius)
        {
            using (var paint = new Paint {
                AntiAlias = true
            })
                using (var path = new Path())
                    using (Path.Direction direction = Path.Direction.Cw)
                        using (Paint.Style style = Paint.Style.Stroke)
                            using (var rect = new RectF(0, 0, width, height))
                            {
                                float rx = Forms.Context.ToPixels(cornerRadius);
                                float ry = Forms.Context.ToPixels(cornerRadius);
                                path.AddRoundRect(rect, rx, ry, direction);

                                paint.StrokeWidth = 2f;
                                paint.SetStyle(style);
                                paint.Color = Color.ParseColor("#4CAF50");
                                canvas.DrawPath(path, paint);
                            }
        }
Exemple #42
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));
        }
    /// <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 = 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 = ((CircleImage)Element).BorderThickness;
        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);

            var path = new Path();
            path.MoveTo(_points[0].X, _points[0].Y);
            for (var i = 1; i < _points.Length; i++)
            {
                path.LineTo(_points[i].X, _points[i].Y);
            }

            var paint = new Paint
                            {
                                Color = Color.White
                            };

            // We can use Paint.Style.Stroke if we want to draw a "hollow" polygon,
            // But then we had better set the .StrokeWidth property on the paint.
            paint.SetStyle(Paint.Style.Fill);

            canvas.DrawPath(path, paint);
        }
		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);
		}
Exemple #46
0
            protected override void OnDraw (Canvas canvas)
            {
                base.OnDraw (canvas);

                var width = canvas.Width;
                var height = canvas.Height;

                // Center the canvas
                canvas.Translate (width / 2f, height / 2f);

                if (slicePath.IsEmpty) {
                    if (startAngle == 0 && endAngle == 360) {
                        slicePath.AddCircle (0, 0, radius - thickness, Path.Direction.Cw);
                        slicePath.AddCircle (0, 0, radius, Path.Direction.Ccw);
                        slicePath.Close ();
                    } else {
                        // Inner arc
                        rect.Set (-radius + thickness, -radius + thickness, radius - thickness, radius - thickness);
                        slicePath.ArcTo (rect, -90 + startAngle, endAngle - startAngle);

                        // Outer arc
                        rect.Set (-radius, -radius, radius, radius);
                        slicePath.ArcTo (rect, -90 + endAngle, startAngle - endAngle);

                        slicePath.Close ();
                    }
                }

                canvas.DrawPath (slicePath, slicePaint);
            }
        private void DrawTriangle(Canvas c, float startAngle, float sweepAngle, Rect bounds)
        {
            if (mShowArrow)
            {
                if (mArrow == null)
                {
                    mArrow = new Path();
                    mArrow.SetFillType(Path.FillType.EvenOdd);
                }
                else
                {
                    mArrow.Reset();
                }

                float x = (float)(RingCenterRadius * Math.Cos(0) + bounds.ExactCenterX());
                float y = (float)(RingCenterRadius * Math.Sin(0) + bounds.ExactCenterY());

                mArrow.MoveTo(0, 0);
                mArrow.LineTo((mArrowWidth) * mArrowScale, 0);
                mArrow.LineTo(((mArrowWidth) * mArrowScale / 2), (mArrowHeight * mArrowScale));
                mArrow.Offset(x - ((mArrowWidth) * mArrowScale / 2), y);
                mArrow.Close();

                mArrowPaint.Color = mColors[mColorIndex];
                c.Rotate(startAngle + (sweepAngle < 0 ? 0 : sweepAngle) - ARROW_OFFSET_ANGLE, bounds.ExactCenterX(), bounds.ExactCenterY());
                c.DrawPath(mArrow, mArrowPaint);
            }
        }
Exemple #48
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 ();
		}
		private void DrawStrokesOnCanvas (Canvas canvas, Color strokeColor, Color fillColor, bool shouldCrop, RectF croppedRectangle = null) {
			canvas.DrawColor (fillColor);

			paint.Color = strokeColor;
			foreach (var path in paths) {
				var tempPath = path;

				if (shouldCrop) {
					tempPath = new Path (path);

					var translate = new Matrix ();
					translate.SetTranslate (-croppedRectangle.Left, -croppedRectangle.Top);
					tempPath.Transform (translate);
				}
				canvas.DrawPath (tempPath, paint);

				tempPath = null;
			}
			paint.Color = this.strokeColor;
		}
		void DrawHexagon (Canvas canvas)
		{
			// The extra padding is to avoid edges being clipped
			var padding = (int)TypedValue.ApplyDimension (ComplexUnitType.Dip, 8, Resources.DisplayMetrics);
			var halfHeight = (Height - padding) / 2;
			var side = (Width - padding) / 2;
			var foo = (int)Math.Sqrt (side * side - halfHeight * halfHeight);

			var path = hexagon ?? (hexagon = new Path ());
			hexagon.Reset ();
			path.MoveTo (Width / 2, padding / 2);
			path.RLineTo (-side / 2, 0);
			path.RLineTo (-foo, halfHeight);
			path.RLineTo (foo, halfHeight);
			path.RLineTo (side, 0);
			path.RLineTo (foo, -halfHeight);
			path.RLineTo (-foo, -halfHeight);
			path.Close ();

			var m = transformationMatrix ?? (transformationMatrix = new Matrix ());
			m.Reset ();
			var centerX = Width / 2;
			var centerY = Height / 2;
			m.PostRotate (Rotation, centerX, centerY);
			m.PostScale (ScaleX, ScaleY, centerX, centerY);
			path.Transform (m);

			if (hexagonPaint == null) {
				hexagonPaint = new Paint {
					Color = new Android.Graphics.Color (0x22, 0x76, 0xB9),
					AntiAlias = true,
				};
				hexagonPaint.SetPathEffect (new CornerPathEffect (30));
			}

			canvas.DrawPath (path, hexagonPaint);
		}
Exemple #51
0
            protected override void OnDraw(Canvas canvas)
            {
                Paint paint = mPaint;

                canvas.DrawColor (Color.White);

                paint.AntiAlias = true;
                paint.Color = Color.Black;
                paint.SetStyle (Paint.Style.Fill);

                int w = canvas.Width;
                int h = canvas.Height;
                int cx = w / 2;
                int cy = h / 2;

                canvas.Translate (cx, cy);

                if (compass.mValues != null)
                    canvas.Rotate (-compass.mValues[0]);

                canvas.DrawPath (mPath, mPaint);
            }
		protected override void OnDraw(Canvas canvas)  {
			canvas.DrawColor(Color.Transparent);
			paint.Reset();
			paint.AntiAlias = true;
			float midX, midY, radius, innerRadius;
			path.Reset();

			float currentAngle = 270;
			float currentSweep;
			float totalValue = 0;
			float padding = 2;

			midX = Width / 2;
			midY = Height/2;
			if (midX < midY){
				radius = midX;
			} else {
				radius = midY;
			}
			radius -= padding;
			innerRadius = radius - thickness;

			foreach (PieSlice slice in slices) {
				totalValue += slice.getValue();
			}

			int count = 0;
			foreach (PieSlice slice in slices) {
				Path p = new Path();
				paint.Color = slice.getColor ();
				currentSweep = (slice.getValue()/totalValue)*(360);
				p.ArcTo(new RectF(midX-radius, midY-radius, midX+radius, midY+radius), currentAngle+padding, currentSweep - padding);
				p.ArcTo(new RectF(midX-innerRadius, midY-innerRadius, midX+innerRadius, midY+innerRadius), (currentAngle+padding) + (currentSweep - padding), -(currentSweep-padding));
				p.Close ();

				slice.setPath(p);
				slice.setRegion(new Region((int)(midX-radius), (int)(midY-radius), (int)(midX+radius), (int)(midY+radius)));
				canvas.DrawPath(p, paint);

				if (indexSelected == count && listener != null){
					path.Reset();
					paint.Color = slice.getColor ();
					paint.Color = Color.ParseColor ("#33B5E5");
					paint.Alpha=100;

					if (slices.Count > 1) {
						path.ArcTo(new RectF(midX-radius-(padding*2), midY-radius-(padding*2), midX+radius+(padding*2), midY+radius+(padding*2)), currentAngle, currentSweep+padding);
						path.ArcTo(new RectF(midX-innerRadius+(padding*2), midY-innerRadius+(padding*2), midX+innerRadius-(padding*2), midY+innerRadius-(padding*2)), currentAngle + currentSweep + padding, -(currentSweep + padding));
						path.Close();
					} else {
						path.AddCircle(midX, midY, radius+padding, Android.Graphics.Path.Direction.Cw);
					}

					canvas.DrawPath(path, paint);
					paint.Alpha=255;
				}

				currentAngle = currentAngle+currentSweep;

				count++;
			}
		}
		void DrawCross (Canvas canvas)
		{
			var smallSegment = Width / 6;

			var path = cross ?? (cross = new Path ());
			cross.Reset ();

			path.MoveTo (0, 0);
			path.RLineTo (smallSegment, 0);
			path.LineTo (Width / 2, Height / 2);
			path.LineTo (Width - smallSegment, 0);
			path.RLineTo (smallSegment, 0);
			path.LineTo (Width / 2 + smallSegment, Height / 2);
			path.LineTo (Width, Height);
			path.RLineTo (-smallSegment, 0);
			path.LineTo (Width / 2, Height / 2);
			path.LineTo (smallSegment, Height);
			path.RLineTo (-smallSegment, 0);
			path.LineTo (Width / 2 - smallSegment, Height / 2);
			path.Close ();

			if (crossPaint == null) {
				crossPaint = new Paint {
					AntiAlias = true,
					Color = Android.Graphics.Color.White
				};
			}

			canvas.DrawPath (path, crossPaint);
		}
		public static Bitmap ToTransformedCorners(Bitmap source, double topLeftCornerSize, double topRightCornerSize, double bottomLeftCornerSize, double bottomRightCornerSize, 
			CornerTransformType cornersTransformType, double cropWidthRatio, double cropHeightRatio)
		{
			double sourceWidth = source.Width;
			double sourceHeight = source.Height;

			double desiredWidth = sourceWidth;
			double desiredHeight = sourceHeight;

			double desiredRatio = cropWidthRatio / cropHeightRatio;
			double currentRatio = sourceWidth / sourceHeight;

			if (currentRatio > desiredRatio)
			{
				desiredWidth = (cropWidthRatio * sourceHeight / cropHeightRatio);
			}
			else if (currentRatio < desiredRatio)
			{
				desiredHeight = (cropHeightRatio * sourceWidth / cropWidthRatio);
			}

			topLeftCornerSize = topLeftCornerSize * (desiredWidth + desiredHeight) / 2 / 100;
			topRightCornerSize = topRightCornerSize * (desiredWidth + desiredHeight) / 2 / 100;
			bottomLeftCornerSize = bottomLeftCornerSize * (desiredWidth + desiredHeight) / 2 / 100;
			bottomRightCornerSize = bottomRightCornerSize * (desiredWidth + desiredHeight) / 2 / 100;

			float cropX = (float)((sourceWidth - desiredWidth) / 2);
			float cropY = (float)((sourceHeight - desiredHeight) / 2);

			Bitmap bitmap = Bitmap.CreateBitmap((int)desiredWidth, (int)desiredHeight, Bitmap.Config.Argb8888);

			using (Canvas canvas = new Canvas(bitmap))
			using (Paint paint = new Paint())
			using (BitmapShader shader = new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp))
			using (Matrix matrix = new Matrix())
			using (var path = new Path())
			{
				if (cropX != 0 || cropY != 0)
				{
					matrix.SetTranslate(-cropX, -cropY);
					shader.SetLocalMatrix(matrix);
				}

				paint.SetShader(shader);
				paint.AntiAlias = true;

				// TopLeft
				if (cornersTransformType.HasFlag(CornerTransformType.TopLeftCut)) 
				{
					path.MoveTo(0, (float)topLeftCornerSize);
					path.LineTo((float)topLeftCornerSize, 0);
				}
				else if (cornersTransformType.HasFlag(CornerTransformType.TopLeftRounded)) 
				{
					path.MoveTo(0, (float)topLeftCornerSize);
					path.QuadTo(0, 0, (float)topLeftCornerSize, 0);
				}
				else
				{
					path.MoveTo(0, 0);
				}

				// TopRight
				if (cornersTransformType.HasFlag(CornerTransformType.TopRightCut)) 
				{
					path.LineTo((float)(desiredWidth - topRightCornerSize), 0);
					path.LineTo((float)desiredWidth, (float)topRightCornerSize);
				}
				else if (cornersTransformType.HasFlag(CornerTransformType.TopRightRounded))
				{
					path.LineTo((float)(desiredWidth - topRightCornerSize), 0);
					path.QuadTo((float)desiredWidth, 0, (float)desiredWidth, (float)topRightCornerSize);
				}
				else
				{
					path.LineTo((float)desiredWidth ,0);
				}

				// BottomRight
				if (cornersTransformType.HasFlag(CornerTransformType.BottomRightCut)) 
				{
					path.LineTo((float)desiredWidth, (float)(desiredHeight - bottomRightCornerSize));
					path.LineTo((float)(desiredWidth - bottomRightCornerSize), (float)desiredHeight);
				}
				else if (cornersTransformType.HasFlag(CornerTransformType.BottomRightRounded))
				{
					path.LineTo((float)desiredWidth, (float)(desiredHeight - bottomRightCornerSize));
					path.QuadTo((float)desiredWidth, (float)desiredHeight, (float)(desiredWidth - bottomRightCornerSize), (float)desiredHeight);
				}
				else
				{
					path.LineTo((float)desiredWidth, (float)desiredHeight);
				}

				// BottomLeft
				if (cornersTransformType.HasFlag(CornerTransformType.BottomLeftCut)) 
				{
					path.LineTo((float)bottomLeftCornerSize, (float)desiredHeight);
					path.LineTo(0, (float)(desiredHeight - bottomLeftCornerSize));
				}
				else if (cornersTransformType.HasFlag(CornerTransformType.BottomLeftRounded)) 
				{
					path.LineTo((float)bottomLeftCornerSize, (float)desiredHeight);
					path.QuadTo(0, (float)desiredHeight, 0, (float)(desiredHeight - bottomLeftCornerSize));
				}
				else
				{
					path.LineTo(0, (float)desiredHeight);
				}

				path.Close();
				canvas.DrawPath(path, paint);

				return bitmap;				
			}
		}
Exemple #55
0
        protected override void OnDraw(Canvas canvas)
        {
            // draw grid lines
            mPaint.Color = new Color(255, 0, 0);
            mPaint.StrokeWidth = 1;

            for ( float y = GRID_GAP; y < canvas.Height; y += GRID_GAP)
            {
                gridpath.Reset ();
                gridpath.MoveTo (0, y);
                gridpath.LineTo (canvas.Width, y);
                canvas.DrawPath(gridpath, mPaint);
            }
            mPaint.Color = new Color(0, 0, 255);
            mPaint.StrokeWidth = 3;

            // draw strokes
            foreach(var aMPathList in mPathList)
            {
                canvas.DrawPath(aMPathList, mPaint);
            }
            canvas.DrawPath(mPath, mPaint);
        }
        public void Draw(Canvas canvas)
        {
            if (Hidden)
            {
                return;
            }

            canvas.Save();

            if (!Focused)
            {
                outlinePaint.Color = Color.White;
                canvas.DrawRect(DrawRect, outlinePaint);
            }
            else
            {
                Rect viewDrawingRect = new Rect();
                context.GetDrawingRect(viewDrawingRect);

                outlinePaint.Color = Color.White;// new Color(0XFF, 0xFF, 0x8A, 0x00);
                focusPaint.Color = new Color(50, 50, 50, 125);

                Path path = new Path();
                path.AddRect(new RectF(DrawRect), Path.Direction.Cw);

                canvas.ClipPath(path, Region.Op.Difference);
                canvas.DrawRect(viewDrawingRect, focusPaint);

                canvas.Restore();
                canvas.DrawPath(path, outlinePaint);

                if (mode == ModifyMode.Grow)
                {
                    int left = DrawRect.Left + 1;
                    int right = DrawRect.Right + 1;
                    int top = DrawRect.Top + 4;
                    int bottom = DrawRect.Bottom + 3;

                    int widthWidth = resizeDrawableWidth.IntrinsicWidth / 2;
                    int widthHeight = resizeDrawableWidth.IntrinsicHeight / 2;
                    int heightHeight = resizeDrawableHeight.IntrinsicHeight / 2;
                    int heightWidth = resizeDrawableHeight.IntrinsicWidth / 2;

                    int xMiddle = DrawRect.Left + ((DrawRect.Right - DrawRect.Left) / 2);
                    int yMiddle = DrawRect.Top + ((DrawRect.Bottom - DrawRect.Top) / 2);

                    resizeDrawableWidth.SetBounds(left - widthWidth,
                                                   yMiddle - widthHeight,
                                                   left + widthWidth,
                                                   yMiddle + widthHeight);
                    resizeDrawableWidth.Draw(canvas);

                    resizeDrawableWidth.SetBounds(right - widthWidth,
                                                   yMiddle - widthHeight,
                                                   right + widthWidth,
                                                   yMiddle + widthHeight);
                    resizeDrawableWidth.Draw(canvas);

                    resizeDrawableHeight.SetBounds(xMiddle - heightWidth,
                                                    top - heightHeight,
                                                    xMiddle + heightWidth,
                                                    top + heightHeight);
                    resizeDrawableHeight.Draw(canvas);

                    resizeDrawableHeight.SetBounds(xMiddle - heightWidth,
                                                    bottom - heightHeight,
                                                    xMiddle + heightWidth,
                                                    bottom + heightHeight);
                    resizeDrawableHeight.Draw(canvas);
                }
            }
        }
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            if(null == _viewPager) return;

            var count = _viewPager.Adapter.Count;

            if(0 == count) return;

            if(-1 == _currentPage && _viewPager != null)
                _currentPage = _viewPager.CurrentItem;

            var bounds = CalculateAllBounds(_paintText);
            var boundsSize = bounds.Count;

            if(_currentPage >= boundsSize)
            {
                CurrentItem = boundsSize - 1;
                return;
            }

            var countMinusOne = count - 1;
            var halfWidth = Width / 2f;
            var leftClip = Left + ClipPadding;
            var right = Left + Width;
            var rightClip = right - ClipPadding;
            var height = Height;
            var left = Left;

            var page = _currentPage;
            float offsetPercent;
            if(_pageOffset <= 0.5)
                offsetPercent = _pageOffset;
            else
            {
                page += 1;
                offsetPercent = 1 - _pageOffset;
            }

            var currentSelected = (offsetPercent <= SelectionFadePercentage);
            var currentBold = (offsetPercent <= BoldFadePercentage);
            var selectedPercent = (SelectionFadePercentage - offsetPercent) / SelectionFadePercentage;

            //Verify if the current view must be clipped to the screen
            var curPageBound = bounds[_currentPage];
            var curPageWidth = curPageBound.Right - curPageBound.Left;
            if(curPageBound.Left < leftClip)
                ClipViewOnTheLeft(curPageBound, curPageWidth, left);
            if(curPageBound.Right > rightClip)
                ClipViewOnTheRight(curPageBound, curPageWidth, right);

            //Left view is starting from the current position
            if(_currentPage > 0)
            {
                for(var i = _currentPage - 1; i >= 0; i--)
                {
                    var bound = bounds[i];
                    //Is left side outside the screen?
                    if(bound.Left < leftClip)
                    {
                        var w = bound.Right - bound.Left;
                        //Clip to the left screen side
                        ClipViewOnTheLeft(bound, w, left);

                        var rightBound = bounds[i + 1];
                        //Except if there is an intersection with the right view
                        if(bound.Right + TitlePadding > rightBound.Left)
                        {
                            bound.Left = (int)(rightBound.Left - w - TitlePadding);
                            bound.Right = bound.Left + w;
                        }
                    }
                }
            }

            //Right view is starting from the current position
            if(_currentPage < countMinusOne)
            {
                for(var i = _currentPage + 1; i < count; i++)
                {
                    var bound = bounds[i];
                    //Is right side outside the screen?
                    if(bound.Right > rightClip)
                    {
                        var w = bound.Right - bound.Left;
                        //Clip to the right screen side
                        ClipViewOnTheRight(bound, w, Right);

                        var leftBound = bounds[i - 1];
                        //Except if there is an intersection with the left view
                        if(bound.Left - TitlePadding < leftBound.Right)
                        {
                            bound.Left = (int)(leftBound.Right + TitlePadding);
                            bound.Right = bound.Left + w;
                        }
                    }
                }
            }

            //Now draw views!
            var colorTextAlpha = _colorText >> 24;
            for(var i = 0; i < count; i++)
            {
                //Get the title
                var bound = bounds[i];
                //Only if one side is visible
                if((bound.Left > left && bound.Left < right) || (bound.Right > left && bound.Right < right))
                {
                    var currentPage = (i == page);
                    var pageTitle = GetTitle(i);

                    //Only set bold if we are within bounds
                    _paintText.FakeBoldText = currentPage && currentBold && _boldText;

                    //Draw text as unselected
                    _paintText.Color = _colorText;
                    if(currentPage && currentSelected)
                        //Fade out/in unselected text as the selected text fades in/out
                        _paintText.Alpha = colorTextAlpha - (int)(colorTextAlpha * selectedPercent);

                    //Except if there is an intersection with the right view
                    if(i < boundsSize - 1)
                    {
                        var rightBound = bounds[i + 1];
                        if(bound.Right + TitlePadding > rightBound.Left)
                        {
                            var w = bound.Right - bound.Left;
                            bound.Left = (int)(rightBound.Left - w - TitlePadding);
                            bound.Right = bound.Left + w;
                        }
                    }
                    canvas.DrawText(pageTitle, 0, pageTitle.Length, bound.Left, bound.Bottom + TopPadding, _paintText);

                    //If we are within the selected bound draw the selected text
                    if(currentPage && currentSelected)
                    {
                        _paintText.Color = _colorSelected;
                        _paintText.Alpha = (int)((_colorSelected >> 24) * selectedPercent);
                        canvas.DrawText(pageTitle, 0, pageTitle.Length, bound.Left, bound.Bottom + TopPadding, _paintText);
                    }
                }
            }

            //If we want the line on the top change height to zero and invert line height to trick the drawing code
            var footerLineHeight = _footerLineHeight;
            var footerIndicatorLineHeight = _footerIndicatorHeight;
            if(_linePosition == LinePosition.Top)
            {
                height = 0;
                footerLineHeight = -footerLineHeight;
                footerIndicatorLineHeight = -footerIndicatorLineHeight;
            }

            //Draw the footer line
            _path.Reset();
            _path.MoveTo(0, height - footerLineHeight / 2f);
            _path.MoveTo(Width, height - footerLineHeight / 2f);
            _path.Close();
            canvas.DrawPath(_path, _paintFooterLine);

            var heightMinusLine = height - footerLineHeight;
            switch(_footerIndicatorStyle)
            {
                case IndicatorStyle.Triangle:
                    _path.Reset();
                    _path.MoveTo(halfWidth, heightMinusLine - footerIndicatorLineHeight);
                    _path.LineTo(halfWidth + footerIndicatorLineHeight, heightMinusLine);
                    _path.LineTo(halfWidth - footerIndicatorLineHeight, heightMinusLine);
                    _path.Close();
                    canvas.DrawPath(_path, _paintFooterIndicator);
                    break;
                case IndicatorStyle.Underline:
                    if(!currentSelected || page >= boundsSize)
                        break;

                    var underlineBounds = bounds[page];
                    var rightPlusPadding = underlineBounds.Right + _footerIndicatorUnderlinePadding;
                    var leftMinusPadding = underlineBounds.Left - _footerIndicatorUnderlinePadding;
                    var heightMinusLineMinusIndicator = heightMinusLine - footerIndicatorLineHeight;

                    _path.Reset();
                    _path.MoveTo(leftMinusPadding, heightMinusLine);
                    _path.LineTo(rightPlusPadding, heightMinusLine);
                    _path.LineTo(rightPlusPadding, heightMinusLineMinusIndicator);
                    _path.LineTo(leftMinusPadding, heightMinusLineMinusIndicator);
                    _path.Close();

                    _paintFooterIndicator.Alpha = (int)(0xFF * selectedPercent);
                    canvas.DrawPath(_path, _paintFooterIndicator);
                    _paintFooterIndicator.Alpha = 0xFF;
                    break;
            }
        }
        /// <summary>
        ///     Implement this to do your drawing.
        /// </summary>
        /// <param name="canvas">the canvas on which the background will be drawn</param>
        /// <since version="Added in API level 1" />
        /// <remarks>
        ///     <para tool="javadoc-to-mdoc">Implement this to do your drawing.</para>
        ///     <para tool="javadoc-to-mdoc">
        ///         <format type="text/html">
        ///             <a href="http://developer.android.com/reference/android/view/View.html#onDraw(android.graphics.Canvas)"
        ///                 target="_blank">
        ///                 [Android Documentation]
        ///             </a>
        ///         </format>
        ///     </para>
        /// </remarks>
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            var r = new Rect(0, 0, canvas.Width, canvas.Height);
            var dAdjustedThicnkess = (float)Thickness * _dm;

            var paint = new Paint { Color = StrokeColor, StrokeWidth = dAdjustedThicnkess, AntiAlias = true };
            paint.SetStyle(Paint.Style.Stroke);
            switch (StrokeType)
            {
                case StrokeType.Dashed:
                    paint.SetPathEffect(new DashPathEffect(new[] { 6 * _dm, 2 * _dm }, 0));
                    break;
                case StrokeType.Dotted:
                    paint.SetPathEffect(new DashPathEffect(new[] { dAdjustedThicnkess, dAdjustedThicnkess }, 0));
                    break;
            }

            var thicknessOffset = (dAdjustedThicnkess) / 2.0f;

            var p = new Path();
            if (Orientation == SeparatorOrientation.Horizontal)
            {
                p.MoveTo(0, thicknessOffset);
                p.LineTo(r.Width(), thicknessOffset);
            }
            else
            {
                p.MoveTo(thicknessOffset, 0);
                p.LineTo(thicknessOffset, r.Height());
            }
            canvas.DrawPath(p, paint);
        }
		public static Bitmap Draw(int width, int height, double direction)
		{
			if(width == 0 || height == 0)
					return null;

			int w2 = width / 2;
			int h2 = height / 2;

			Paint light = new Paint(PaintFlags.AntiAlias);
			Paint dark = new Paint(PaintFlags.AntiAlias);
			Paint black = new Paint(PaintFlags.AntiAlias);

			light.Color = new Color(128, 0, 0, 255);
			light.StrokeWidth = 0f;
			light.SetStyle(Paint.Style.FillAndStroke);

			dark.Color = new Color(255, 0, 0, 255);
			dark.StrokeWidth = 0f;
			dark.SetStyle(Paint.Style.FillAndStroke);

			black.Color = new Color(0, 0, 0, 255);
			black.StrokeWidth = 0f;
			black.SetStyle(Paint.Style.Stroke);

			// Values of direction are between 0° and 360°, but for drawing we need -180° to +180°
			direction -= 180;

			double rad1 = direction / 180.0 * Math.PI;
			double rad2 = (direction + 180.0 + 30.0) / 180.0 * Math.PI;
			double rad3 = (direction + 180.0 - 30.0) / 180.0 * Math.PI; 
			double rad4 = (direction + 180.0) / 180.0 * Math.PI; 

			PointF p1 = new PointF((float) (w2 + w2 * Math.Sin (rad1)), (float) (h2 + h2 * Math.Cos (rad1)));
			PointF p2 = new PointF((float) (w2 + w2 * Math.Sin (rad2)), (float) (h2 + h2 * Math.Cos (rad2)));
			PointF p3 = new PointF((float) (w2 + w2 * Math.Sin (rad3)), (float) (h2 + h2 * Math.Cos (rad3)));
			PointF p4 = new PointF((float) (w2 + width / 3 * Math.Sin (rad4)), (float) (h2 + height / 3 * Math.Cos (rad4)));

			Bitmap b = Bitmap.CreateBitmap(width, height, Bitmap.Config.Argb8888);

			using(Canvas c = new Canvas(b)) {
				int cx = c.Width / 2 - 1;
				int cy = c.Height / 2 - 1;

				global::Android.Graphics.Path path1 = new global::Android.Graphics.Path ();
				global::Android.Graphics.Path path2 = new global::Android.Graphics.Path ();
				global::Android.Graphics.Path path3 = new global::Android.Graphics.Path ();

				path1.MoveTo (p1.X,p1.Y);
				path1.LineTo (p2.X,p2.Y);
				path1.LineTo (p4.X,p4.Y);
				path1.LineTo (p1.X,p1.Y);

				path2.MoveTo (p1.X,p1.Y);
				path2.LineTo (p3.X,p3.Y);
				path2.LineTo (p4.X,p4.Y);
				path2.LineTo (p1.X,p1.Y);

				path3.MoveTo (p1.X,p1.Y);
				path3.LineTo (p2.X,p2.Y);
				path3.LineTo (p4.X,p4.Y);
				path3.LineTo (p1.X,p1.Y);
				path3.LineTo (p3.X,p3.Y);
				path3.LineTo (p4.X,p4.Y);

				light.Color = new Color (128, 0, 0, 255);
				dark.Color = new Color (255, 0, 0, 255);
				black.Color = new Color (0, 0, 0, 255);

				c.DrawPath (path1, light);
				c.DrawPath (path2, dark);
				c.DrawPath (path3, black);
			}

			return b;
		}
Exemple #60
0
        protected virtual void DrawLineCore(IGeometry line, Paint linePaint, Rect imageRegion, Rect clipBounds,
                                            BoundingBox screenBox, MapView mapView, Canvas canvas)
        {
            var projection = mapView.Projection;
            List<GeoPoint> data = Simplify(mapView, ((LineString) line).Vertices);
            if (Rect.Intersects(imageRegion, clipBounds))
            {
                //long start = System.CurrentTimeMillis();

                _path.Reset();
                Point currentPoint = null;
                Point nextPoint = null;
                for (int i = 0; i < data.Count; i++)
                {
                    var currentGeoPoint = data[i];
                    if (!screenBox.Contains(currentGeoPoint))
                    {
                        if (i + 1 < data.Count)
                        {
                            currentPoint = projection.ToPixels(currentGeoPoint, currentPoint);
                            var nextGeoPoint = data[i + 1];
                            if (screenBox.Contains(nextGeoPoint))
                            {
                                nextPoint = projection.ToPixels(nextGeoPoint, null);
                                DrawLine(nextPoint, currentPoint);
                            }
                        }
                    }
                    else
                    {
                        currentPoint = projection.ToPixels(currentGeoPoint, currentPoint);
                        if (ShowPoints)
                        {
                            if (PointPaint == null)
                            {
                                PointPaint = CreatePointPaint();
                            }
                            canvas.DrawCircle(currentPoint.X, currentPoint.Y, PointPaint.StrokeWidth, PointPaint);
                        }
                        GeoPoint nextGeoPoint = null;
                        if (data.Count > i + 1)
                        {
                            nextGeoPoint = (GeoPoint) data[i + 1];
                        }
                        if (nextGeoPoint != null)
                        {
                            nextPoint = projection.ToPixels(nextGeoPoint, null);
                            DrawLine(currentPoint, nextPoint);
                        }
                    }
                }
                if (_path.IsEmpty)
                {
                    for (int i = 0; i < data.Count; i++)
                    {
                        GeoPoint currentGeoPoint = data[i];

                        GeoPoint nextGeoPoint = null;
                        if (data.Count > i + 1)
                        {
                            nextGeoPoint = data[i + 1];
                        }
                        if (nextGeoPoint != null)
                        {
                            currentPoint = projection.ToPixels(currentGeoPoint, null);
                            nextPoint = projection.ToPixels(nextGeoPoint, null);
                            DrawLine(currentPoint, nextPoint);
                        }
                    }
                }
                
                //long end = System.currentTimeMillis();
#if DEBUG
                //Log.Debug("com.mapquest.android.maps.lineoverlay", "Time to process shapepoints: " + (float)(end - start) / 1000.0F + "; no. of points: " + data.Count);
#endif
                canvas.DrawPath(_path, LinePaint);
#if DEBUG
                //Log.Debug("com.mapquest.android.maps.lineoverlay", "Time to draw path shapepoints: " + (float)(System.currentTimeMillis() - end) / 1000.0F + "; no. of points: " + data.Count);
#endif
            }

        }