コード例 #1
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);
                                }
            }
コード例 #2
0
		void DrawBackground(Canvas canvas, int width, int height, bool pressed)
		{
			var paint = new Paint { AntiAlias = true };
			var path = new APath();

			float borderRadius = ConvertCornerRadiusToPixels();

			RectF rect = new RectF(0, 0, width, height);

			rect.Inset(PaddingLeft, PaddingTop);

			path.AddRoundRect(rect, borderRadius, borderRadius, APath.Direction.Cw);

			paint.Color = pressed ? PressedBackgroundColor.ToAndroid() : BackgroundColor.ToAndroid();
			paint.SetStyle(Paint.Style.Fill);
			paint.SetShadowLayer(_shadowRadius, _shadowDx, _shadowDy, _shadowColor);

			if (BorderElement.IsBackgroundSet())
			{
				Brush background = BorderElement.Background;
				paint.UpdateBackground(background, height, width);
			}

			canvas.DrawPath(path, paint);
		}
コード例 #3
0
		public void DrawOutline(Canvas canvas, int width, int height)
		{
			if (BorderElement.BorderWidth <= 0)
				return;

			using (var paint = new Paint { AntiAlias = true })
			using (var path = new APath())
			{
				float borderWidth = _convertToPixels(BorderElement.BorderWidth);
				float inset = borderWidth / 2;

				// adjust border radius so outer edge of stroke is same radius as border radius of background
				float borderRadius = Math.Max(ConvertCornerRadiusToPixels() - inset, 0);

				RectF rect = new RectF(0, 0, width, height);
				rect.Inset(inset + PaddingLeft, inset + PaddingTop);

				path.AddRoundRect(rect, borderRadius, borderRadius, APath.Direction.Cw);
				paint.StrokeWidth = borderWidth;
				paint.SetStyle(Paint.Style.Stroke);
				paint.Color = BorderElement.BorderColor.ToAndroid(Graphics.Colors.Black);

				canvas.DrawPath(path, paint);
			}
		}
コード例 #4
0
        /// <inheritdoc />
        protected override Size ArrangeOverride(Size finalSize)
        {
            var(shapeSize, renderingArea) = ArrangeRelativeShape(finalSize);

            Android.Graphics.Path path;

            if (renderingArea.Width > 0 && renderingArea.Height > 0)
            {
                path = new Android.Graphics.Path();

                //Android's path rendering logic rounds values down to the nearest int, make sure we round up here instead using the ViewHelper scaling logic. However we only want to round the height and width, not the frame offsets.
                var physicalRenderingArea = renderingArea.LogicalToPhysicalPixels();
                if (FrameRoundingAdjustment is { } fra)
                {
                    physicalRenderingArea.Height += fra.Height;
                    physicalRenderingArea.Width  += fra.Width;
                }

                var logicalRenderingArea = physicalRenderingArea.PhysicalToLogicalPixels();
                logicalRenderingArea.X = renderingArea.X;
                logicalRenderingArea.Y = renderingArea.Y;

                path.AddRoundRect(logicalRenderingArea.ToRectF(), (float)RadiusX, (float)RadiusY, Android.Graphics.Path.Direction.Cw);
            }
            else
            {
                path = null;
            }

            Render(path);

            return(shapeSize);
        }
コード例 #5
0
ファイル: RectangleRenderer.cs プロジェクト: sung-su/maui
        void UpdateShape()
        {
            var path = new APath();

            path.AddRoundRect(new RectF(0, 0, 1, 1), RadiusX, RadiusY, APath.Direction.Cw);
            UpdateShape(path);
        }
コード例 #6
0
        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);
        }
コード例 #7
0
        /// <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);
        }
コード例 #8
0
		/// <Docs>The Canvas to which the View is rendered.</Docs>
		/// <summary>
		/// Draw the specified canvas.
		/// </summary>
		/// <param name="canvas">Canvas.</param>
		public override void Draw (Canvas canvas)
		{			
			try
			{
				var element = Element as RoundCornerView;
				var cornerRadius = (float)element.CornerRadius*Resources.DisplayMetrics.Density;

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

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

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

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

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

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

				canvas.Restore();
				path.Dispose();
			}
			catch (Exception)
			{				
			}				
		}
コード例 #9
0
ファイル: Rectangle.Android.cs プロジェクト: jokm1/uno-2
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);
            var drawArea = GetDrawArea(canvas);
            var rx       = ViewHelper.LogicalToPhysicalPixels(RadiusX);
            var ry       = ViewHelper.LogicalToPhysicalPixels(RadiusY);

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

            fillRect.AddRoundRect(drawArea.ToRectF(), rx, ry, Android.Graphics.Path.Direction.Cw);

            DrawFill(canvas, drawArea, fillRect);
            DrawStroke(canvas, drawArea, (c, r, p) => c.DrawRoundRect(r.ToRectF(), rx, ry, p));
        }
コード例 #10
0
            protected override void OnDraw(Canvas canvas)
            {
                var cornerRadius = BaseUIHelper.ConvertDPToPixels(Element.CornerRadius);

                if (cornerRadius > 0)
                {
                    Android.Graphics.Path clipPath = new Android.Graphics.Path();
                    RectF   rect  = new RectF(0, 0, BaseUIHelper.ConvertDPToPixels(Element.WidthRequest), BaseUIHelper.ConvertDPToPixels(Element.HeightRequest));
                    float[] radii = new float[] { cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius, cornerRadius };
                    clipPath.AddRoundRect(rect, radii, Android.Graphics.Path.Direction.Cw);
                    canvas.ClipPath(clipPath);
                }
                base.OnDraw(canvas);
            }
コード例 #11
0
        public static void SetClipPath(this BorderRenderer br, Canvas canvas)
        {
            var clipPath = new Path();
            //float padding = br;// radius / 2;
            float radius = (float)br.Element.CornerRadius - br.Context.ToPixels((float)br.Element.Padding.ThickestSide());// - padding / 2; // + MaxStrokeThickness());

            int w = (int)br.Width;
            int h = (int)br.Height;

            clipPath.AddRoundRect(new RectF(
                br.ViewGroup.PaddingLeft,
                br.ViewGroup.PaddingTop,
                w - br.ViewGroup.PaddingRight,
                h - br.ViewGroup.PaddingBottom),
                radius,
                radius,
                Path.Direction.Cw);

            canvas.ClipPath(clipPath);
        }
コード例 #12
0
		public void DrawCircle(Canvas canvas, int width, int height, Action<Canvas> finishDraw)
		{
			try
			{
				var radius = (float)BorderElement.CornerRadius;
				if (radius <= 0)
				{
					finishDraw(canvas);
					return;
				}

				var borderThickness = _convertToPixels(BorderElement.BorderWidth);

				using (var path = new APath())
				{
					float borderWidth = _convertToPixels(BorderElement.BorderWidth);
					float inset = borderWidth / 2;

					// adjust border radius so outer edge of stroke is same radius as border radius of background
					float borderRadius = Math.Max(ConvertCornerRadiusToPixels() - inset, 0);

					RectF rect = new RectF(0, 0, width, height);
					rect.Inset(PaddingLeft, PaddingTop);
					path.AddRoundRect(rect, borderRadius, borderRadius, APath.Direction.Ccw);

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

					finishDraw(canvas);
				}

				canvas.Restore();
				return;
			}
			catch (Exception ex)
			{
				Internals.Log.Warning(nameof(BorderDrawable), $"Unable to create circle image: {ex}");
			}

			finishDraw(canvas);
		}
コード例 #13
0
            void DrawOutline(ACanvas canvas, int width, int height, float cornerRadius)
            {
                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.Stroke)
                                using (var rect = new RectF(0, 0, width, height))
                                {
                                    float rx = _convertToPixels(cornerRadius);
                                    float ry = _convertToPixels(cornerRadius);
                                    path.AddRoundRect(rect, rx, ry, direction);

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

                                    canvas.DrawPath(path, paint);
                                }
            }
コード例 #14
0
		protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime)
		{
			try
			{
				var path = new Path ();
				path.AddRoundRect (new RectF (0, 0, Width, Height), 15f, 15f, Path.Direction.Ccw);
				canvas.Save ();
				canvas.ClipPath (path);

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

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

			return base.DrawChild(canvas, child, drawingTime);
		}
コード例 #15
0
        /// <inheritdoc />
        protected override Size ArrangeOverride(Size finalSize)
        {
            var(shapeSize, renderingArea) = ArrangeRelativeShape(finalSize);

            Android.Graphics.Path path;

            if (renderingArea.Width > 0 && renderingArea.Height > 0)
            {
                var rx = ViewHelper.LogicalToPhysicalPixels(RadiusX);
                var ry = ViewHelper.LogicalToPhysicalPixels(RadiusY);

                path = new Android.Graphics.Path();
                path.AddRoundRect(renderingArea.ToRectF(), rx, ry, Android.Graphics.Path.Direction.Cw);
            }
            else
            {
                path = null;
            }

            Render(path);

            return(shapeSize);
        }
コード例 #16
0
ファイル: ButtonDrawable.cs プロジェクト: Costo/Xamarin.Forms
		void DrawBackground(Canvas canvas, int width, int height, bool pressed)
		{
			var paint = new Paint { AntiAlias = true };
			var path = new Path();

			float borderRadius = Forms.Context.ToPixels(Button.BorderRadius);

			path.AddRoundRect(new RectF(0, 0, width, height), borderRadius, borderRadius, Path.Direction.Cw);

			paint.Color = pressed ? Button.BackgroundColor.AddLuminosity(-0.1).ToAndroid() : Button.BackgroundColor.ToAndroid();
			paint.SetStyle(Paint.Style.Fill);
			canvas.DrawPath(path, paint);
		}
コード例 #17
0
ファイル: ButtonDrawable.cs プロジェクト: Costo/Xamarin.Forms
		void DrawOutline(Canvas canvas, int width, int height)
		{
			if (Button.BorderWidth <= 0)
				return;

			using (var paint = new Paint { AntiAlias = true })
			using (var path = new Path())
			{
				float borderWidth = Forms.Context.ToPixels(Button.BorderWidth);
				float inset = borderWidth / 2;

				// adjust border radius so outer edge of stroke is same radius as border radius of background
				float borderRadius = Forms.Context.ToPixels(Button.BorderRadius) - inset;

				path.AddRoundRect(new RectF(inset, inset, width - inset, height - inset), borderRadius, borderRadius, Path.Direction.Cw);
				paint.StrokeWidth = borderWidth;
				paint.SetStyle(Paint.Style.Stroke);
				paint.Color = Button.BorderColor.ToAndroid();

				canvas.DrawPath(path, paint);
			}
		}
コード例 #18
0
ファイル: Border.Droid.cs プロジェクト: evnik/UIFramework
        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);
        }
コード例 #19
0
 protected override void OnLayout(bool changed, int left, int top, int right, int bottom)
 {
     base.OnLayout (changed, left, top, right, bottom);
     clipMask = new Path ();
     var rect = new RectF (0, 0, Width, Height);
     clipMask.AddRoundRect (rect, cornerRadius, cornerRadius, Path.Direction.Cw);
 }