public override void Draw(Android.Graphics.Canvas canvas)
        {
            base.Draw(canvas);

            var rect = new RectF(0,0,300,300);
            switch (TheShape)
            {
                case Shape.Circle:
                    canvas.DrawOval(rect, new Paint() { Color = Color.Aqua });
                    break;
                case Shape.Square:
                    canvas.DrawRect(rect, new Paint() { Color = Color.Red });
                    break;
                case Shape.Triangle:
                    var path = new Path();
                    path.MoveTo(rect.CenterX(), 0);
                    path.LineTo(0, rect.Height());
                    path.LineTo(rect.Width(), rect.Height());
                    path.Close();

                    var paint = new Paint() {Color = Color.Magenta};
                    paint.SetStyle(Paint.Style.Fill);
                    canvas.DrawPath(path, paint);
                    break;

                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw (canvas);

            var stokewidth = TapUtil.dptodx (this.stokewidthdp);
            var progresswidth = TapUtil.dptodx (this.progresswidthdp);
            //draw border
            int center = Width / 2;
            nn_paint.SetStyle(Paint.Style.Stroke);
            nn_paint.Color=nn_outcolor;
            nn_paint.StrokeWidth = stokewidth;
            canvas.DrawCircle(center,center, nn_radius-stokewidth, nn_paint);

            //draw remainingsection of progress
            nn_paint.SetStyle (Paint.Style.Fill);
            nn_paint.Color=nn_progressremainingcolor;
            //RectF position is relative toparent
            canvas.DrawCircle(center,center, nn_radius-stokewidth*2, nn_paint);

            //draw progress
            nn_paint.SetStyle (Paint.Style.Stroke);
            nn_paint.Color=nn_progresscolor;
            nn_paint.StrokeWidth = progresswidthdp*2;
            //RectF position is relative toparent
            RectF oval = new RectF (0+(stokewidth*2)+Convert.ToSingle(progresswidthdp*1.5),0+(stokewidth*2)+Convert.ToSingle(progresswidthdp*1.5),nn_radius*2-(stokewidth*2)-Convert.ToSingle(progresswidthdp*1.5),nn_radius*2-(stokewidth*2)-Convert.ToSingle(progresswidthdp*1.5));
            canvas.DrawArc(oval, progresssstartangle, progresssendangle, false, nn_paint);

            //draw avatarcontainer (innercircle)
            nn_paint.SetStyle(Paint.Style.Fill);
            nn_paint.Color=nn_innercontainercolor;
            canvas.DrawCircle(center,center, nn_radius-progresswidth-stokewidth*2, nn_paint);
        }
Exemple #3
0
		public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint, RectF pRect) {
			float? centerX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_CENTER_X);
			float? centerY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_CENTER_Y);
			float? radiusX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_X);
			float? radiusY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_Y);
			if (centerX != null && centerY != null && radiusX != null && radiusY != null) {
				pRect.Set(centerX.Value - radiusX.Value,
				          centerY.Value - radiusY.Value,
				          centerX.Value + radiusX.Value,
				          centerY.Value + radiusY.Value);

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

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

				if(fill || stroke) {
					pSVGPaint.ensureComputedBoundsInclude(centerX.Value - radiusX.Value, centerY.Value - radiusY.Value);
					pSVGPaint.ensureComputedBoundsInclude(centerX.Value + radiusX.Value, centerY.Value + radiusY.Value);
				}
			}
		}
Exemple #4
0
        public override void Draw(Android.Graphics.Canvas canvas)
        {
            base.Draw (canvas);

            Paint mBgPaints = new Paint ();
            mBgPaints.AntiAlias = true;
            mBgPaints.SetStyle (Paint.Style.Fill);
            mBgPaints.Color = Color.Blue;
            mBgPaints.StrokeWidth = 0.5f;

            Paint tPaint = new Paint ();
            tPaint.Alpha = 0;
            canvas.DrawColor (tPaint.Color);

            RectF mOvals = new RectF (40, 40, layout.MeasuredWidth - 40, layout.MeasuredHeight - 40);

            decimal total = 0;
            foreach (SecuritiesViewModel.PieChartValue value in securitiesViewModel.DataForPieChart ()) {
                total += value.amount;
            }

            if (total == 0) {
                return;
            }

            decimal degressPerAmount = 360 / total;
            decimal currentAngle = 0;
            foreach (SecuritiesViewModel.PieChartValue value in securitiesViewModel.DataForPieChart ()) {
                canvas.DrawArc (mOvals, (float)currentAngle, (float)(degressPerAmount * value.amount), true, mBgPaints);
                currentAngle += (degressPerAmount * value.amount);
                mBgPaints.SetARGB (255, new Random ().Next (256), new Random ().Next (256), new Random ().Next (256));
            }
        }
 protected override void OnDraw(Canvas canvas)
 {
     Android.Graphics.Drawable.Drawable drawable = GetDrawable();
     if (drawable is BitmapDrawable)
     {
         RectF rectF = new RectF(drawable.GetBounds());
         int restoreCount = canvas.SaveLayer(rectF, null, Canvas.AllSaveFlag);
         GetImageMatrix().MapRect(rectF);
         Paint paint = ((BitmapDrawable)drawable).GetPaint();
         paint.SetAntiAlias(true);
         paint.SetColor(unchecked((int)(0xff000000)));
         canvas.DrawARGB(0, 0, 0, 0);
         canvas.DrawRoundRect(rectF, Radius, Radius, paint);
         Xfermode restoreMode = paint.GetXfermode();
         paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
         base.OnDraw(canvas);
         // Restore paint and canvas
         paint.SetXfermode(restoreMode);
         canvas.RestoreToCount(restoreCount);
     }
     else
     {
         base.OnDraw(canvas);
     }
 }
Exemple #6
0
        public void PopClip()
        {
            RectF oldClip = this.clipStack.Pop();

            //this.canvas.Restore();
            this.canvas.ClipRect(oldClip, Region.Op.Replace);
        }
		public Transition GenerateNextTransition(RectF drawableBounds, RectF viewport)
		{
			bool firstTransition = _mLastGenTrans == null;
			bool drawableBoundsChanged = true;
			bool viewportRatioChanged = true;

			RectF srcRect = null;
			RectF dstRect = null;

			if (!firstTransition)
			{
				dstRect = _mLastGenTrans.GetDestinyRect();
				drawableBoundsChanged = !drawableBounds.Equals(_mLastDrawableBounds);
				viewportRatioChanged = !MathUtils.HaveSameAspectRatio(dstRect, viewport);
			}

			if (dstRect == null || drawableBoundsChanged || viewportRatioChanged)
			{
				srcRect = GenerateRandomRect(drawableBounds, viewport);
			}
			else
			{
				/* Sets the destiny rect of the last transition as the source one
				 if the current drawable has the same dimensions as the one of
				 the last transition. */
				srcRect = dstRect;
			}
			dstRect = GenerateRandomRect(drawableBounds, viewport);

			_mLastGenTrans = new Transition(srcRect, dstRect, _mTransitionDuration,
					_mTransitionIInterpolator);
			_mLastDrawableBounds = drawableBounds;

			return _mLastGenTrans;
		}
Exemple #8
0
		protected virtual void HandleShapeDraw (Canvas canvas)
		{
			// We need to account for offsetting the coordinates based on the padding
			var x = GetX () + Resize (this.ShapeView.Padding.Left);
			var y = GetY () + Resize (this.ShapeView.Padding.Top);

			switch (ShapeView.ShapeType) {
			case ShapeType.Box:
				HandleStandardDraw (canvas, p => {
					var rect = new RectF (x, y, x + this.Width, y + this.Height);
					if (ShapeView.CornerRadius > 0) {
						var cr = Resize (ShapeView.CornerRadius);
						canvas.DrawRoundRect (rect, cr, cr, p);
					} else {
						canvas.DrawRect (rect, p);
					}
				});
				break;
			case ShapeType.Circle:
				HandleStandardDraw (canvas, p => canvas.DrawCircle (x + this.Width / 2, y + this.Height / 2, (this.Width - 10) / 2, p));
				break;
			case ShapeType.CircleIndicator:
				HandleStandardDraw (canvas, p => canvas.DrawCircle (x + this.Width / 2, y + this.Height / 2, (this.Width - 10) / 2, p), drawFill: false);
				HandleStandardDraw (canvas, p => canvas.DrawArc (new RectF (x, y, x + this.Width, y + this.Height), QuarterTurnCounterClockwise, 360 * (ShapeView.IndicatorPercentage / 100), false, p), ShapeView.StrokeWidth + 3, false);
				break;
			}
		}
        public static Bitmap ToRounded(Bitmap source, float rad)
        {
            int size = Math.Min(source.Width, source.Height);

            int dx = (source.Width - size) / 2;
            int dy = (source.Height - size) / 2;

            Bitmap bitmap = Bitmap.CreateBitmap(size, size, 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())
            {
                if (dx != 0 || dy != 0)
                {
                    // source isn't square, move viewport to centre
                    matrix.SetTranslate(-dx, -dy);
                    shader.SetLocalMatrix(matrix);
                }
                paint.SetShader(shader);
                paint.AntiAlias = true;

                RectF rectF = new RectF(0, 0, size, size);
                canvas.DrawRoundRect(rectF, rad, rad, paint);

                return bitmap;
            }
        }
		// If you would like to create a circle of the image set pixels to half the width of the image.
		internal static   Bitmap GetRoundedCornerBitmap(Bitmap bitmap, int pixels)
		{
			Bitmap output = null;

			try
			{
				output = Bitmap.CreateBitmap(bitmap.Width, bitmap.Height, Bitmap.Config.Argb8888);
				Canvas canvas = new Canvas(output);

				Color color = new Color(66, 66, 66);
				Paint paint = new Paint();
				Rect rect = new Rect(0, 0, bitmap.Width, bitmap.Height);
				RectF rectF = new RectF(rect);
				float roundPx = pixels;

				paint.AntiAlias = true;
				canvas.DrawARGB(0, 0, 0, 0);
				paint.Color = color;
				canvas.DrawRoundRect(rectF, roundPx, roundPx, paint);

				paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
				canvas.DrawBitmap(bitmap, rect, rect, paint);
			}
			catch (System.Exception err)
			{
				System.Console.WriteLine ("GetRoundedCornerBitmap Error - " + err.Message);
			}

			return output;
		}
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            var rect = new RectF(0, 0, 300, 300);
            switch (Shape)
            {
                case Shape.Circle:
                    canvas.DrawOval(rect, new Paint() { Color = Color.CornflowerBlue });
                    break;
                case Shape.Square:
                    canvas.DrawRect(rect, new Paint() { Color = Color.Crimson });
                    break;
                case Shape.Triangle:

                    var path = new Path();
                    path.MoveTo(rect.CenterX(), rect.Top);
                    path.LineTo(rect.Left, rect.Bottom);
                    path.LineTo(rect.Right, rect.Bottom);
                    path.Close();
                    var paint = new Paint() {Color = Color.Crimson};
                    paint.Color = Color.Gold;
                    paint.SetStyle(Paint.Style.Fill);
                    canvas.DrawPath(path, paint);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
Exemple #12
0
 private static void DrawOutline(Canvas canvas, IStyle style, RectF destination)
 {
     var vectorStyle = (style as VectorStyle);
     if (vectorStyle == null) return;
     if (vectorStyle.Outline == null) return;
     if (vectorStyle.Outline.Color == null) return;
     DrawRectangle(canvas, destination, vectorStyle.Outline.Color);
 }
Exemple #13
0
 private static void DrawRectangle(Canvas canvas, RectF destination, Styles.Color outlineColor)
 {
     var paint = new Paint();
     paint.SetStyle(Paint.Style.Stroke);
     paint.Color = new AndroidColor(outlineColor.R, outlineColor.G, outlineColor.B, outlineColor.A);
     paint.StrokeWidth = 4;
     canvas.DrawRect(destination, paint);
 }
 public override void DrawRectBounds( FastColour colour, float lineWidth, int x, int y, int width, int height )
 {
     RectF rec = new RectF( x, y, x + width, y + height );
     Paint brush = GetOrCreateBrush( colour );
     brush.SetStyle( Paint.Style.Stroke );
     c.DrawRect( rec, brush );
     brush.SetStyle( Paint.Style.FillAndStroke );
 }
 public CircleDrawable(Bitmap bmp)
 {
     this.bmp = bmp;
     this.bmpShader = new BitmapShader(bmp, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
     this.paint = new Paint() { AntiAlias = true };
     this.paint.SetShader(bmpShader);
     this.oval = new RectF();
 }
 public override void Clear( FastColour colour, int x, int y, int width, int height )
 {
     RectF rec = new RectF( x, y, x + width, y + height );
     Paint brush = GetOrCreateBrush( colour );
     brush.AntiAlias = false;
     c.DrawRect( rec, brush );
     brush.AntiAlias = true;
 }
        private Path CreateCannulaBottomPath(RectF cannulaRect)
        {
            RectF cannulaHeadRect = new RectF(cannulaRect.Left, cannulaRect.Bottom - 0.833f * cannulaRect.Width(), cannulaRect.Right, cannulaRect.Bottom);

            Path path = new Path();

            path.AddRoundRect(cannulaHeadRect, mRectCornerRadius, mRectCornerRadius, Path.Direction.Ccw);
            return(path);
        }
		protected override bool SetFrame (int l, int t, int r, int b)
		{
			bool changed = base.SetFrame(l, t, r, b);
	        mBounds = new Rect(0, 0, r - l, b - t);
	        mBoundsF = new RectF(mBounds);
	        mBorderDrawable.Bounds = mBounds;
	        mMaskDrawable.Bounds = mBounds;
	        return changed;
		}
		internal static bool HaveSameAspectRatio(RectF r1, RectF r2)
		{
			// Reduces precision to avoid problems when comparing aspect ratios.
			float srcRectRatio = Truncate(GetRectRatio(r1), 2);
			float dstRectRatio = Truncate(GetRectRatio(r2), 2);

			// Compares aspect ratios that allows for a tolerance range of [0, 0.01] 
			return (Math.Abs(srcRectRatio - dstRectRatio) <= 0.01f);
		}
        private Path CreateGasTubePath(RectF gasTubeRect)
        {
            Path path = new Path();

            path.MoveTo(gasTubeRect.Left, gasTubeRect.Top);
            path.LineTo(gasTubeRect.Left, gasTubeRect.Bottom);
            path.LineTo(gasTubeRect.Right, gasTubeRect.Bottom);
            path.LineTo(gasTubeRect.Right, gasTubeRect.Top);
            return(path);
        }
        private Path CreateCannulaHeadPath(RectF cannulaRect)
        {
            Path path = new Path();

            path.MoveTo(cannulaRect.Left, cannulaRect.Top);
            path.LineTo(cannulaRect.Right, cannulaRect.Top);
            path.MoveTo(cannulaRect.CenterX(), cannulaRect.Top);
            path.LineTo(cannulaRect.CenterX(), cannulaRect.Bottom - 0.833f * cannulaRect.Width());
            return(path);
        }
		public RoundRectDrawable (Color background, float radius)
		{
			this.radius = radius;
			this.paint = new Paint {
				Color = background,
				Dither = true,
				AntiAlias = true
			};
			this.bounds = new RectF ();
		}
        private RectF CreateRightEyeBall(RectF arcBounds, float offsetY)
        {
            //the center of the right eye
            float rightEyeCenterX = arcBounds.CenterX() + mEyeInterval / 2.0f + mEyeCircleRadius;
            float rightEyeCenterY = arcBounds.CenterY() - mEyeBallOffsetY + offsetY;

            RectF rectF = new RectF(rightEyeCenterX - mEyeBallWidth / 2.0f, rightEyeCenterY - mEyeBallHeight / 2.0f, rightEyeCenterX + mEyeBallWidth / 2.0f, rightEyeCenterY + mEyeBallHeight / 2.0f);

            return(rectF);
        }
		public static IRenderer Renderer(AnimationMode mode, FitChartValue value, RectF drawingArea)
		{
			if (mode == AnimationMode.Linear)
			{
				return new LinearValueRenderer (drawingArea, value);
			}
			else
			{
				return new OverdrawValueRenderer (drawingArea, value);
			}
		}
Exemple #25
0
 public static Bitmap GetBitmapFromSvgString(string svgString, int width, int height)
 {
     var svg = SVGParser.ParseSVGFromString (svgString);
     var bmp = Bitmap.CreateBitmap (width, height, Bitmap.Config.Argb8888);
     using (var c = new Canvas (bmp)) {
         var dst = new RectF (0, 0, width, height);
         c.DrawPicture (svg.Picture, dst);
     }
     // Returns an immutable copy
     return Bitmap.CreateBitmap (bmp);
 }
Exemple #26
0
		internal static Bitmap MakeBitmapFromPicture (Picture pic, int width, int height)
		{
			using (var bmp = Bitmap.CreateBitmap (width, height, Bitmap.Config.Argb8888)) {
				using (var c = new Canvas (bmp)) {
					var dst = new RectF (0, 0, width, height); 
					c.DrawPicture (pic, dst);
				}
				// Returns an immutable copy
				return Bitmap.CreateBitmap (bmp);
			}
		}
Exemple #27
0
        public static Bitmap GetBitmapFromSvgRes(Android.Content.Res.Resources resources, int resID,
		                                          int width, int height)
        {
            var svg = SVGParser.ParseSVGFromResource (resources,
                                                      resID);
            var bmp = Bitmap.CreateBitmap (width, height, Bitmap.Config.Argb8888);
            using (var c = new Canvas (bmp)) {
                var dst = new RectF (0, 0, width, height);
                c.DrawPicture (svg.Picture, dst);
            }
            // Returns an immutable copy
            return Bitmap.CreateBitmap (bmp);
        }
Exemple #28
0
        public static void Draw(Canvas canvas, IViewport viewport, IStyle style, IFeature feature)
        {
            var point = feature.Geometry as Point;
            var dest = viewport.WorldToScreen(point);
            var symbolSize = (float)SymbolStyle.DefaultHeight;
            var symbolType = SymbolType.Ellipse;

            var symbolStyle = style as SymbolStyle;
            if (symbolStyle != null)
            {
                if (symbolStyle.BitmapId >= 0)
                {
                    // Bitmap
                    if (!feature.RenderedGeometry.ContainsKey(style))
                    {
                        var imageStream = BitmapRegistry.Instance.Get(symbolStyle.BitmapId);
                        imageStream.Position = 0;
                        var androidBitmap = BitmapFactory.DecodeStream(imageStream);
                        feature.RenderedGeometry[style] = androidBitmap;
                    }

                    var bitmap = (Bitmap)feature.RenderedGeometry[style];
                    var halfWidth = bitmap.Width / 2;
                    var halfHeight = bitmap.Height / 2;
                    var dstRectForRender = new RectF((float)dest.X - halfWidth, (float)dest.Y - halfHeight, (float)dest.X + halfWidth, (float)dest.Y + halfHeight);
                    canvas.DrawBitmap(bitmap, null, dstRectForRender, null);
                    return;
                }
                symbolType = symbolStyle.SymbolType;
                if (symbolStyle.SymbolScale > 0) symbolSize = (float)symbolStyle.SymbolScale * symbolSize;
            }

            // Drawing
            var paints = style.ToAndroid();
            if (symbolType == SymbolType.Ellipse)
            {
                foreach (var paint in paints)
                {
                    canvas.DrawCircle((int)dest.X, (int)dest.Y, symbolSize, paint);
                    paint.Dispose();
                }
            }
            else
            {
                foreach (var paint in paints)
                {
                    canvas.DrawRect(-(float)SymbolStyle.DefaultWidth, (float)SymbolStyle.DefaultHeight, (float)SymbolStyle.DefaultWidth, -(float)SymbolStyle.DefaultHeight, paint);
                    paint.Dispose();
                }
            }
        }
Exemple #29
0
		public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint, RectF pRect) {
			float x = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_X, 0f);
			float y = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_Y, 0f);
			float width = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_WIDTH, 0f);
			float height = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_HEIGHT, 0f);

			pRect.Set(x, y, x + width, y + height);

			float? rX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_X);
			float? rY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_Y);

			bool rXSpecified = rX != null && rX >= 0;
			bool rYSpecified = rY != null && rY >= 0;

			bool rounded = rXSpecified || rYSpecified;
			float rx;
			float ry;
			if(rXSpecified && rYSpecified) {
				rx = Math.Min(rX.Value, width * 0.5f);
				ry = Math.Min(rY.Value, height * 0.5f);
			} else if(rXSpecified) {
				ry = rx = Math.Min(rX.Value, width * 0.5f);
			} else if(rYSpecified) {
				rx = ry = Math.Min(rY.Value, height * 0.5f);
			} else {
				rx = 0;
				ry = 0;
			}

			bool fill = pSVGPaint.setFill(pSVGProperties);
			if (fill) {
				if(rounded) {
					pCanvas.DrawRoundRect(pRect, rx, ry, pSVGPaint.getPaint());
				} else {
					pCanvas.DrawRect(pRect, pSVGPaint.getPaint());
				}
			}

			bool stroke = pSVGPaint.setStroke(pSVGProperties);
			if (stroke) {
				if(rounded) {
					pCanvas.DrawRoundRect(pRect, rx, ry, pSVGPaint.getPaint());
				} else {
					pCanvas.DrawRect(pRect, pSVGPaint.getPaint());
				}
			}

			if(fill || stroke) {
				pSVGPaint.ensureComputedBoundsInclude(x, y, width, height);
			}
		}
		/// <Docs>The Canvas to which the View is rendered.</Docs>
		/// <summary>
		/// BoxViewのカスタマイズはDrawで行う
		/// </summary>
		/// <param name="canvas">Canvas.</param>
		public override void Draw(Android.Graphics.Canvas canvas)
		{
			// 2重に描画してしまうので、baseは描画しない
			//base.Draw(canvas);

			// ElementをキャストしてFormsで定義したCustomBoxViewを取得
			var formsBox = (CustomBoxView)Element;

			// Androidの描画はPaintを使用
			using (var paint = new Paint()) 
			{
				// 塗りつぶし色の設定
				paint.Color = formsBox.FillColor.ToAndroid();

				// 吹き出し部分の設定
				// パスの生成
				var path = new Path();

				// スタート地点の設定
				path.MoveTo(0, 0);

				// 経由地点の設定
				path.LineTo(100, 10);
				path.LineTo(100, 100);

				// パスを繋げる
				path.Close();

				// 描画
				canvas.DrawPath(path, paint);


				// 角の丸い四角の設定
				// 角丸の直径を決める
				// widthとheightを比較して小さい方を基準にする
				var minSize = Math.Min(Width, Height);

				// 指定するのは直径なので、指定半径を2倍する
				var diameter = formsBox.Radius * 2;
				// 角丸の直径はminSize以下でなければならない
				if (diameter > minSize)
					diameter = minSize;

				// 描画領域の設定
				var rect = new RectF(0, 0, (float)Width, (float)Height);

				//四角形描画
				canvas.DrawRoundRect(rect, diameter, diameter, paint);
			}
		}
        public CreateAnimationDrawer(Context c, BrushItem brush, Canvas canvas, Bitmap myBmp, bool tooAdd = false, int cell = 1, string DrawerState = "brush_selection", Path pathToUse = null)
            : base(c)
        {
            myBitmap = myBmp;
            myCanvas = canvas;
            DrawerStateInternal = DrawerState;
            addOnly = tooAdd;
            status = 0;
            myPath = new Path();
            myPaint = new Paint(PaintFlags.Dither);
            myPaint.AntiAlias = true;
            myPaint.Dither = true;
            myPaint.SetStyle(Paint.Style.Stroke);
            myPaint.StrokeJoin = Paint.Join.Round;
            myPaint.StrokeWidth = brush.Thickness;
            myPaint.StrokeCap = Paint.Cap.Round;
            myPaint.SetARGB(colorUtil.a, colorUtil.r, colorUtil.g, colorUtil.b);

            if (brush.BrushType == AnimationTypesBrushType.Spray)
                myPaint.SetShadowLayer(brush.Thickness, 0, 0, ImageHelper.convWZColorToColor(brush.BrushColor));

            if (DrawerState == "brush_selection")
            {
                if (pathToUse != null)
                {
                    myBoundsPaint = new Paint();
                    myBoundsPaint = new Paint(PaintFlags.Dither);
                    myBoundsPaint.AntiAlias = true;
                    myBoundsPaint.Dither = true;
                    myBoundsPaint.SetStyle(Paint.Style.Stroke);
                    myBoundsPaint.StrokeJoin = Paint.Join.Round;
                    myBoundsPaint.StrokeWidth = 10f;
                    myBoundsPaint.StrokeCap = Paint.Cap.Round;
                    myBoundsPaint.SetARGB(255, 0, 0, 0);
                    myBoundsPaint.SetPathEffect(new DashPathEffect(new float[]
                    {
                        10f,
                        20f
                    }, 0));

                    myPath = pathToUse;
                    AnimationUtil.theCanvas.DrawPath(myPath, myPaint);
                    AnimationUtil.theCanvas.DrawPath(myPath, myPaint);

                    myBoundsRect = new RectF();
                    myPath.ComputeBounds(myBoundsRect, true);
                    AnimationUtil.theCanvas.DrawRect(myBoundsRect, myBoundsPaint);
                }
            }
        }
Exemple #32
0
 public static Bitmap GetRoundedCornerBitmap(this Bitmap bitmap, int roundPixelSize)
 {
     Bitmap output = Bitmap.CreateBitmap(bitmap.Width, bitmap.Height, Bitmap.Config.Argb8888);
     var canvas = new Canvas(output);
     var paint = new Paint();
     var rect = new Rect(0, 0, bitmap.Width, bitmap.Height);
     var rectF = new RectF(rect);
     var roundPx = roundPixelSize;
     paint.AntiAlias = true;
     canvas.DrawRoundRect(rectF,roundPx,roundPx, paint);
     paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
     canvas.DrawBitmap(bitmap, rect, rect, paint);
     return output;
 }
		protected override void OnElementChanged (ElementChangedEventArgs<View> e)
		{
			base.OnElementChanged (e);

			var formsView = e.NewElement;

			float viewWidth = (float)(formsView.WidthRequest * Resources.DisplayMetrics.Density);
			float viewHeight = (float)(formsView.HeightRequest * Resources.DisplayMetrics.Density);
			RectF rect = new RectF (0, 0, viewWidth, viewHeight);

			Android.Views.View circleView = new CircleView (Context, rect);

			SetNativeControl (circleView);
		}
        public RoundedImage(Bitmap bitmap)
        {
            mBitmap = bitmap;
            mRectF = new RectF();
            mPaint = new Paint();
            mPaint.AntiAlias = true;
            mPaint.Dither = true;
            BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
            mPaint.SetShader(shader);

            // NOTE: we assume bitmap is properly scaled to current density
            mBitmapWidth = mBitmap.Width;
            mBitmapHeight = mBitmap.Height;
        }
        public RoundedDrawable(Bitmap bitmap) : base()
        {
            mBitmap = bitmap;
            mRectF = new RectF();
            mPaint = new Paint();
            mPaint.AntiAlias = true;
            mPaint.Dither = true;

            BitmapShader shader = new BitmapShader(bitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
            mPaint.SetShader(shader);

            // Try to get it circular, even if the given bitmap isn't square
            mBitmapWidth = Math.Min( mBitmap.Width, mBitmap.Height);
            mBitmapHeight = Math.Min(mBitmap.Width, mBitmap.Height);
        }
        private Path CreateRightEyeCircle(RectF arcBounds, float offsetY)
        {
            Path path = new Path();

            //the center of the right eye
            float rightEyeCenterX = arcBounds.CenterX() + mEyeInterval / 2.0f + mEyeCircleRadius;
            float rightEyeCenterY = arcBounds.CenterY() + offsetY;
            //the bounds of left eye
            RectF leftEyeBounds = new RectF(rightEyeCenterX - mEyeCircleRadius, rightEyeCenterY - mEyeCircleRadius, rightEyeCenterX + mEyeCircleRadius, rightEyeCenterY + mEyeCircleRadius);

            path.AddArc(leftEyeBounds, 180, -(DEGREE_180 + 15));
            //the above radian of of the eye
            path.QuadTo(leftEyeBounds.Right - mAboveRadianEyeOffsetX, leftEyeBounds.Top + mEyeCircleRadius * 0.2f, leftEyeBounds.Right - mAboveRadianEyeOffsetX / 4.0f, leftEyeBounds.Top - mEyeCircleRadius * 0.15f);

            return(path);
        }
Exemple #37
0
        private RectF CreateArcBounds(RectF sourceArcBounds, int index)
        {
            int intervalWidth = 0;

            for (int i = 0; i < index; i++)
            {
                intervalWidth += (int)(mStrokeWidth / (i + 1.0f) * 1.5f);
            }

            int arcBoundsLeft   = (int)(sourceArcBounds.Left + intervalWidth);
            int arcBoundsTop    = (int)(sourceArcBounds.Top + intervalWidth);
            int arcBoundsRight  = (int)(sourceArcBounds.Right - intervalWidth);
            int arcBoundsBottom = (int)(sourceArcBounds.Bottom - intervalWidth);

            mTempArcBounds.Set(arcBoundsLeft, arcBoundsTop, arcBoundsRight, arcBoundsBottom);

            return(mTempArcBounds);
        }
Exemple #38
0
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            RectF arcBounds = mTempBounds;

            arcBounds.Set(bounds);
            arcBounds.Inset(mStrokeInset, mStrokeInset);
            mCurrentBounds.Set(arcBounds);

            int saveCount = canvas.Save();

            //draw circle trim
            float startAngle = (mStartTrim + mRotation) * 360;
            float endAngle   = (mEndTrim + mRotation) * 360;
            float sweepAngle = endAngle - startAngle;

            if (sweepAngle != 0)
            {
                mPaint.Color = new Color(mColor);
                mPaint.SetStyle(Paint.Style.Stroke);
                canvas.DrawArc(arcBounds, startAngle, sweepAngle, false, mPaint);
            }

            //draw water wave
            if (mWaveProgress < 1.0f)
            {
                var nColor = new Color(mColor);


                mPaint.Color = Color.Argb((int)(Color.GetAlphaComponent(mColor) * (1.0f - mWaveProgress)), Color.GetRedComponent(mColor), Color.GetGreenComponent(mColor), Color.GetBlueComponent(mColor));

                mPaint.SetStyle(Paint.Style.Stroke);
                float radius = Math.Min(arcBounds.Width(), arcBounds.Height()) / 2.0f;
                canvas.DrawCircle(arcBounds.CenterX(), arcBounds.CenterY(), radius * (1.0f + mWaveProgress), mPaint);
            }
            //draw ball bounce
            if (mPathMeasure != null)
            {
                mPaint.Color = new Color(mBallColor);
                mPaint.SetStyle(Paint.Style.Fill);
                canvas.DrawCircle(mCurrentPosition[0], mCurrentPosition[1], mSkipBallSize * mScale, mPaint);
            }

            canvas.RestoreToCount(saveCount);
        }
        public override void Draw(Canvas canvas)
        {
            base.Draw(canvas);

            var paint = new Android.Graphics.Paint()
            {
                Dither      = true,
                StrokeWidth = 4,
                AntiAlias   = true,
                Color       = Android.Graphics.Color.Gray
            };

            paint.SetShadowLayer(20f, 0f, 0f, Android.Graphics.Color.Black);
            paint.SetStyle(Paint.Style.Stroke);

            var rect = new Android.Graphics.RectF(0, 0, Width, Height);

            canvas.DrawRoundRect(rect, Control.Radius, Control.Radius, paint);
        }
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            int saveCount = canvas.Save();

            mTempBounds.Set(bounds);
            mTempBounds.Inset(mStrokeInset, mStrokeInset);
            mCurrentBounds.Set(mTempBounds);

            float outerCircleRadius = Math.Min(mTempBounds.Height(), mTempBounds.Width()) / 2.0f;
            float interCircleRadius = outerCircleRadius / 2.0f;
            float centerRingWidth   = interCircleRadius - mStrokeWidth / 2;

            mPaint.SetStyle(Paint.Style.Stroke);
            mPaint.Color       = new Color(mColor);
            mPaint.StrokeWidth = mStrokeWidth;
            canvas.DrawCircle(mTempBounds.CenterX(), mTempBounds.CenterY(), outerCircleRadius, mPaint);
            mPaint.SetStyle(Paint.Style.Fill);
            canvas.DrawCircle(mTempBounds.CenterX(), mTempBounds.CenterY(), interCircleRadius * mScale, mPaint);

            if (mRotation != 0)
            {
                mPaint.Color = new Color(mArcColor);
                mPaint.SetStyle(Paint.Style.Stroke);
                //strokeWidth / 2.0f + mStrokeWidth / 2.0f is the center of the inter circle width
                mTempBounds.Inset(centerRingWidth / 2.0f + mStrokeWidth / 2.0f, centerRingWidth / 2.0f + mStrokeWidth / 2.0f);
                mPaint.StrokeWidth = centerRingWidth;
                canvas.DrawArc(mTempBounds, RING_START_ANGLE, mRotation, false, mPaint);
            }

            mPaint.Color = new Color(mColor);
            mPaint.SetStyle(Paint.Style.Fill);
            for (int i = 0; i < NUM_POINTS; i++)
            {
                canvas.Rotate(i * DANCE_INTERVAL_ANGLE, POINT_X[i], POINT_Y[i]);
                RectF rectF = new RectF(POINT_X[i] - mDanceBallRadius - mShapeChangeWidth / 2.0f, POINT_Y[i] - mDanceBallRadius - mShapeChangeHeight / 2.0f, POINT_X[i] + mDanceBallRadius + mShapeChangeWidth / 2.0f, POINT_Y[i] + mDanceBallRadius + mShapeChangeHeight / 2.0f);
                canvas.DrawOval(rectF, mPaint);
                canvas.Rotate(-i * DANCE_INTERVAL_ANGLE, POINT_X[i], POINT_Y[i]);
            }

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

            arcBounds.Set(bounds);

            mPaint.Color = new Color(mColor);

            mPaint.SetStyle(Paint.Style.Stroke);
            canvas.DrawPath(CreateLeftEyeCircle(arcBounds, mLeftEyeCircleOffsetY), mPaint);
            canvas.DrawPath(CreateRightEyeCircle(arcBounds, mRightEyeCircleOffsetY), mPaint);

            mPaint.SetStyle(Paint.Style.Fill);
            //create left eye ball
            canvas.DrawOval(CreateLeftEyeBall(arcBounds, mLeftEyeBallOffsetY), mPaint);
            //create right eye ball
            canvas.DrawOval(CreateRightEyeBall(arcBounds, mRightEyeBallOffsetY), mPaint);

            canvas.RestoreToCount(saveCount);
        }
        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);
        }
        /// <summary>
        /// Coordinates are approximate, you have better cooperate with the designer's design draft
        /// </summary>
        private Path CreateBalloonPath(RectF balloonRect, float progress)
        {
            Path path = new Path();

            path.MoveTo(balloonRect.CenterX(), balloonRect.Bottom);

            float progressWidth  = balloonRect.Width() * progress;
            float progressHeight = balloonRect.Height() * progress;
            //draw left half
            float leftIncrementX1 = progressWidth * -0.48f;
            float leftIncrementY1 = progressHeight * 0.75f;
            float leftIncrementX2 = progressWidth * -0.03f;
            float leftIncrementY2 = progressHeight * -1.6f;
            float leftIncrementX3 = progressWidth * 0.9f;
            float leftIncrementY3 = progressHeight * -1.0f;

            path.CubicTo(balloonRect.Left + balloonRect.Width() * 0.25f + leftIncrementX1, balloonRect.CenterY() - balloonRect.Height() * 0.4f + leftIncrementY1, balloonRect.Left - balloonRect.Width() * 0.20f + leftIncrementX2, balloonRect.CenterY() + balloonRect.Height() * 1.15f + leftIncrementY2, balloonRect.Left - balloonRect.Width() * 0.4f + leftIncrementX3, balloonRect.Bottom + leftIncrementY3);

            //        the results of the left final transformation
            //        path.cubicTo(balloonRect.left - balloonRect.width() * 0.13f, balloonRect.CenterY() + balloonRect.height() * 0.35f,
            //                balloonRect.left - balloonRect.width() * 0.23f, balloonRect.CenterY() - balloonRect.height() * 0.45f,
            //                balloonRect.left + balloonRect.width() * 0.5f, balloonRect.bottom - balloonRect.height());

            //draw right half
            float rightIncrementX1 = progressWidth * 1.51f;
            float rightIncrementY1 = progressHeight * -0.05f;
            float rightIncrementX2 = progressWidth * 0.03f;
            float rightIncrementY2 = progressHeight * 0.5f;
            float rightIncrementX3 = 0.0f;
            float rightIncrementY3 = 0.0f;

            path.CubicTo(balloonRect.Left - balloonRect.Width() * 0.38f + rightIncrementX1, balloonRect.CenterY() - balloonRect.Height() * 0.4f + rightIncrementY1, balloonRect.Left + balloonRect.Width() * 1.1f + rightIncrementX2, balloonRect.CenterY() - balloonRect.Height() * 0.15f + rightIncrementY2, balloonRect.Left + balloonRect.Width() * 0.5f + rightIncrementX3, balloonRect.Bottom + rightIncrementY3);

            //        the results of the right final transformation
            //        path.cubicTo(balloonRect.left + balloonRect.width() * 1.23f, balloonRect.CenterY() - balloonRect.height() * 0.45f,
            //                balloonRect.left + balloonRect.width() * 1.13f, balloonRect.CenterY() + balloonRect.height() * 0.35f,
            //                balloonRect.left + balloonRect.width() * 0.5f, balloonRect.bottom);

            return(path);
        }
        droidGraphics.Matrix ComputeStretchMatrix()
        {
            droidGraphics.Matrix matrix = new droidGraphics.Matrix();

            // Get the drawable bounds decreased by stroke thickness
            droidGraphics.RectF drawableBounds = new droidGraphics.RectF(drawable.Bounds);
            float halfStrokeWidth = drawable.Paint.StrokeWidth / 2;

            drawableBounds.Left   += halfStrokeWidth;
            drawableBounds.Top    += halfStrokeWidth;
            drawableBounds.Right  -= halfStrokeWidth;
            drawableBounds.Bottom -= halfStrokeWidth;

            switch (stretch)
            {
            case Stretch.None:
                break;

            case Stretch.Fill:
                matrix.SetRectToRect(pathFillBounds, drawableBounds, droidGraphics.Matrix.ScaleToFit.Fill);
                break;

            case Stretch.Uniform:
                matrix.SetRectToRect(pathFillBounds, drawableBounds, droidGraphics.Matrix.ScaleToFit.Center);
                break;

            case Stretch.UniformToFill:
                float widthScale  = drawableBounds.Width() / pathFillBounds.Width();
                float heightScale = drawableBounds.Height() / pathFillBounds.Height();
                float maxScale    = Math.Max(widthScale, heightScale);

                matrix.SetScale(maxScale, maxScale);
                matrix.PostTranslate(drawableBounds.Left - maxScale * pathFillBounds.Left,
                                     drawableBounds.Top - maxScale * pathFillBounds.Top);
                break;
            }
            return(matrix);
        }
        protected internal override void ComputeRender(float renderProgress)
        {
            RectF arcBounds = mCurrentBounds;

            //compute gas tube bounds
            mGasTubeBounds.Set(arcBounds.CenterX() - mGasTubeWidth / 2.0f, arcBounds.CenterY(), arcBounds.CenterX() + mGasTubeWidth / 2.0f, arcBounds.CenterY() + mGasTubeHeight);
            //compute pipe body bounds
            mPipeBodyBounds.Set(arcBounds.CenterX() + mGasTubeWidth / 2.0f - mPipeBodyWidth / 2.0f, arcBounds.CenterY() - mPipeBodyHeight, arcBounds.CenterX() + mGasTubeWidth / 2.0f + mPipeBodyWidth / 2.0f, arcBounds.CenterY());
            //compute cannula bounds
            mCannulaBounds.Set(arcBounds.CenterX() + mGasTubeWidth / 2.0f - mCannulaWidth / 2.0f, arcBounds.CenterY() - mCannulaHeight - mCannulaOffsetY, arcBounds.CenterX() + mGasTubeWidth / 2.0f + mCannulaWidth / 2.0f, arcBounds.CenterY() - mCannulaOffsetY);
            //compute balloon bounds
            float insetX = mBalloonWidth * 0.333f * (1 - mProgress);
            float insetY = mBalloonHeight * 0.667f * (1 - mProgress);

            mBalloonBounds.Set(arcBounds.CenterX() - mGasTubeWidth / 2.0f - mBalloonWidth / 2.0f + insetX, arcBounds.CenterY() - mBalloonHeight + insetY, arcBounds.CenterX() - mGasTubeWidth / 2.0f + mBalloonWidth / 2.0f - insetX, arcBounds.CenterY());

            if (renderProgress <= START_INHALE_DURATION_OFFSET)
            {
                mCannulaBounds.Offset(0, -mCannulaMaxOffsetY * renderProgress / START_INHALE_DURATION_OFFSET);

                mProgress     = 0.0f;
                mProgressText = 10 + PERCENT_SIGN;

                mPaint.TextSize = mTextSize;
                mPaint.GetTextBounds(mProgressText, 0, mProgressText.Length, mProgressBounds);
            }
            else
            {
                float exhaleProgress = ACCELERATE_INTERPOLATOR.GetInterpolation(1.0f - (renderProgress - START_INHALE_DURATION_OFFSET) / (1.0f - START_INHALE_DURATION_OFFSET));
                mCannulaBounds.Offset(0, -mCannulaMaxOffsetY * exhaleProgress);

                mProgress     = 1.0f - exhaleProgress;
                mProgressText = AdjustProgress((int)(exhaleProgress * 100.0f)) + PERCENT_SIGN;

                mPaint.TextSize = mTextSize;
                mPaint.GetTextBounds(mProgressText, 0, mProgressText.Length, mProgressBounds);
            }
        }
Exemple #46
0
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            int SaveCount = canvas.Save();

            RectF arcBounds = mCurrentBounds;

            arcBounds.Set(bounds);

            //Draw background
            canvas.DrawColor(new Color(mCurrentBackgroundColor));
            //Draw reveal circle
            if (mRevealCircleRadius > 0)
            {
                mPaint.Color = new Color(mCurrentBackgroundColor == mBackgroundColor ? mBackgroundDeepColor : mBackgroundColor);
                canvas.DrawCircle(arcBounds.CenterX(), arcBounds.CenterY(), mRevealCircleRadius, mPaint);
            }

            //Draw mother oval
            mPaint.Color = new Color(mCurrentOvalColor);

            int motherSaveCount = canvas.Save();

            canvas.Rotate(mRotateDegrees, mMotherPosition[0], mMotherPosition[1]);
            canvas.DrawPath(CreateMotherPath(), mPaint);
            canvas.DrawPath(CreateLinkPath(), mPaint);
            canvas.RestoreToCount(motherSaveCount);

            int childSaveCount = canvas.Save();

            canvas.Rotate(mRotateDegrees, mChildPosition[0], mChildPosition[1]);
            canvas.DrawPath(CreateChildPath(), mPaint);
            canvas.RestoreToCount(childSaveCount);
            canvas.RestoreToCount(SaveCount);

            //    canvas.DrawPath(mMotherMovePath, mPaint);
            //    canvas.DrawPath(mChildMovePath, mPaint);
            //    canvas.DrawLine(mMotherPosition[0], mMotherPosition[1], mChildPosition[0], mChildPosition[1], mPaint);
        }
Exemple #47
0
 internal Region(Android.Graphics.RectF native)
     : base(native)
 {
 }
Exemple #48
0
        protected override void OnDraw(Canvas canvas)
        {
            coreX       = Width / 2;
            coreY       = Height / 2;
            roundRadius = (int)(Width / 2 * radiusDistance); //计算中心圆圈半径

            RectF rect = new RectF(0, 0, Width, Height);

            if (roundMenus != null && roundMenus.Count > 0)
            {
                float sweepAngle = 360 / roundMenus.Count; //每个弧形的角度
                deviationDegree = sweepAngle / 2;          //其实的偏移角度,如果4个扇形的时候是X形状,而非+,设为0试试就知道什么意思了
                for (int i = 0; i < roundMenus.Count; i++)
                {
                    RoundMenu roundMenu = roundMenus[i];
                    //填充
                    Paint paint = new Paint();
                    paint.AntiAlias = true;
                    if (onClickState == i)
                    {
                        //选中
                        paint.Color = new Color(roundMenu.selectSolidColor);
                    }
                    else
                    {
                        //未选中
                        paint.Color = new Color(roundMenu.solidColor);
                    }
                    canvas.DrawArc(rect, deviationDegree + (i * sweepAngle), sweepAngle, true, paint);

                    //画描边
                    paint             = new Paint();
                    paint.AntiAlias   = true;
                    paint.StrokeWidth = roundMenu.strokeSize;
                    paint.SetStyle(Paint.Style.Stroke);
                    paint.Color = new Color(roundMenu.strokeColor);
                    canvas.DrawArc(rect, deviationDegree + (i * sweepAngle), sweepAngle, roundMenu.useCenter, paint);

                    //画图案
                    Matrix matrix = new Matrix();
                    matrix.PostTranslate((float)((coreX + Width / 2 * roundMenu.iconDistance) - (roundMenu.icon.Width / 2)), coreY - (roundMenu.icon.Height / 2));
                    matrix.PostRotate(((i + 1) * sweepAngle), coreX, coreY);
                    canvas.DrawBitmap(roundMenu.icon, matrix, null);
                }
            }

            //画中心圆圈
            if (isCoreMenu)
            {
                //填充
                RectF rect1 = new RectF(coreX - roundRadius, coreY - roundRadius, coreX + roundRadius, coreY + roundRadius);
                Paint paint = new Paint();
                paint.AntiAlias   = true;
                paint.StrokeWidth = coreMenuStrokeSize;
                if (onClickState == -1)
                {
                    paint.Color = new Color(coreMenuSelectColor);
                }
                else
                {
                    paint.Color = new Color(coreMenuColor);
                }
                canvas.DrawArc(rect1, 0, 360, true, paint);

                //画描边
                paint             = new Paint();
                paint.AntiAlias   = true;
                paint.StrokeWidth = coreMenuStrokeSize;
                paint.SetStyle(Paint.Style.Stroke);
                paint.Color = new Color(coreMenuStrokeColor);
                canvas.DrawArc(rect1, 0, 360, true, paint);
                if (coreBitmap != null)
                {
                    //画中心圆圈的"OK"图标
                    canvas.DrawBitmap(coreBitmap, coreX - coreBitmap.Width / 2, coreY - coreBitmap.Height / 2, null); //在 0,0坐标开始画入src
                }
            }
        }
        droidGraphics.LinearGradient CreateLinearGradient(LinearGradientBrush xamBrush,
                                                          droidGraphics.RectF pathBounds,
                                                          droidGraphics.Matrix stretchMatrix)
        {
            if (Path == null)
            {
                return(null);
            }

            int[]   colors  = new int[xamBrush.GradientStops.Count];
            float[] offsets = new float[xamBrush.GradientStops.Count];

            for (int index = 0; index < xamBrush.GradientStops.Count; index++)
            {
                colors[index]  = ConvertColor(xamBrush.GradientStops[index].Color);
                offsets[index] = (float)xamBrush.GradientStops[index].Offset;
            }

            droidGraphics.Shader.TileMode tilemode = droidGraphics.Shader.TileMode.Clamp;

            switch (xamBrush.SpreadMethod)
            {
            case GradientSpreadMethod.Pad:
                tilemode = droidGraphics.Shader.TileMode.Clamp;
                break;

            case GradientSpreadMethod.Refect:
                tilemode = droidGraphics.Shader.TileMode.Mirror;
                break;

            case GradientSpreadMethod.Repeat:
                tilemode = droidGraphics.Shader.TileMode.Repeat;
                break;
            }

            // pathBounds has already been stretched
            using (droidGraphics.RectF xformedBounds = new droidGraphics.RectF(pathBounds))
            {
                if (xamBrush.Transform != null)
                {
                    // But the brush transform offsets needs to be stretched
                    droidGraphics.Matrix transform = xamBrush.Transform.GetNativeObject() as droidGraphics.Matrix;

                    float[] stretchValues = new float[9];
                    stretchMatrix.GetValues(stretchValues);

                    float[] transformValues = new float[9];
                    transform.GetValues(transformValues);

                    // Scale x-offset by stretch
                    transformValues[2] *= stretchValues[0];

                    // Scale y-offset by stretch
                    transformValues[5] *= stretchValues[4];

                    using (droidGraphics.Matrix matx = new droidGraphics.Matrix())
                    {
                        matx.SetValues(transformValues);

                        float[] a2 = new float[9];
                        matx.GetValues(a2);

                        matx.MapRect(xformedBounds);
                    }
                }

                return(new droidGraphics.LinearGradient((float)xamBrush.StartPoint.X * xformedBounds.Width() + xformedBounds.Left,
                                                        (float)xamBrush.StartPoint.Y * xformedBounds.Height() + xformedBounds.Top,
                                                        (float)xamBrush.EndPoint.X * xformedBounds.Width() + xformedBounds.Left,
                                                        (float)xamBrush.EndPoint.Y * xformedBounds.Height() + xformedBounds.Top,
                                                        colors, offsets, tilemode));
            }
        }
Exemple #50
0
 public static RectangleF ToEto(this ag.RectF rect)
 {
     return(new RectangleF(rect.Left, rect.Top, rect.Width(), rect.Height()));
 }
Exemple #51
0
 public static XIR.Rectangle RemoteRepresentation(this AG.RectF rectangle)
 => new XIR.Rectangle(
     rectangle.Left,
     rectangle.Top,
     rectangle.Width(),
     rectangle.Height());