protected override void OnDraw(ACanvas canvas) { if (Element == null) { return; } var pancake = Element as PancakeView; SetClipChildren(true); //Create path to clip the child if (pancake.Sides != 4) { using (var path = DrawingExtensions.CreatePolygonPath(Width, Height, pancake.Sides, pancake.CornerRadius.TopLeft, pancake.OffsetAngle)) { canvas.Save(); canvas.ClipPath(path); } } else { using (var path = DrawingExtensions.CreateRoundedRectPath(Width, Height, Context.ToPixels(pancake.CornerRadius.TopLeft), Context.ToPixels(pancake.CornerRadius.TopRight), Context.ToPixels(pancake.CornerRadius.BottomRight), Context.ToPixels(pancake.CornerRadius.BottomLeft))) { canvas.Save(); canvas.ClipPath(path); } } DrawBorder(canvas, pancake); }
protected override void OnDraw(ACanvas canvas) { if (Element == null) { return; } var control = (PancakeView)Element; SetClipChildren(true); //Create path to clip the child if (control.Sides != 4) { using (var path = ShapeUtils.CreatePolygonPath(Width, Height, control.Sides, control.CornerRadius.TopLeft, control.OffsetAngle)) { canvas.Save(); canvas.ClipPath(path); } } else { using (var path = ShapeUtils.CreateRoundedRectPath(Width, Height, Context.ToPixels(control.CornerRadius.TopLeft), Context.ToPixels(control.CornerRadius.TopRight), Context.ToPixels(control.CornerRadius.BottomRight), Context.ToPixels(control.CornerRadius.BottomLeft))) { canvas.Save(); canvas.ClipPath(path); } } DrawBorder(canvas, control); }
protected override void OnDraw(ACanvas canvas) { if (Element == null) { return; } var control = (CanvasView)Element; SetClipChildren(true); //Create path to clip the child if (control.Sides != 4) { using (var path = PolygonUtils.GetPolygonCornerPath(Width, Height, control.Sides, control.CornerRadius.TopLeft, control.OffsetAngle)) { canvas.Save(); canvas.ClipPath(path); } } else { using (var path = new Path()) { path.AddRoundRect(new RectF(0, 0, Width, Height), GetRadii(control), Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); } } DrawBorder(canvas, control); }
protected override bool DrawChild(ACanvas canvas, global::Android.Views.View child, long drawingTime) { if (this.Element == null) { return(false); } CorneredContentView control = (CorneredContentView)this.Element; this.SetClipChildren(true); //Create path to clip the child using (Path path = new Path()) { path.AddRoundRect(new RectF(0, 0, this.Width, this.Height), this.GetRadii(control), Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); } // Draw the child first so that the border shows up above it. bool result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); this.DrawBorder(canvas, control); return(result); }
protected override bool DrawChild(ACanvas canvas, global::Android.Views.View child, long drawingTime) { if (Element == null) { return(false); } var control = (PancakeView)Element; SetClipChildren(true); //Create path to clip the child using (var path = new Path()) { path.AddRoundRect(new RectF(0, 0, Width, Height), GetRadii(control), Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); } // Draw the child first so that the border shows up above it. var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); DrawBorder(canvas, control); return(result); }
protected override bool DrawChild(Android.Graphics.Canvas canvas, Android.Views.View child, long drawingTime) { try { var element = (RoundedImage)Element; var radius = Math.Min(Width, Height) / 2; var strokeWidth = 10; radius -= strokeWidth / 2; var path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); var paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = (float)element.BorderWidth; paint.SetStyle(Paint.Style.Stroke); paint.Color = element.BorderColor.ToAndroid(); canvas.DrawPath(path, paint); paint.Dispose(); path.Dispose(); return(result); } catch (Exception ex) { Console.WriteLine(ex.Message); } return(base.DrawChild(canvas, child, drawingTime)); }
protected override 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); }
/// <summary> /// /// </summary> /// <param name="canvas"></param> /// <param name="child"></param> /// <param name="drawingTime"></param> /// <returns></returns> protected override bool DrawChild(Canvas canvas, Android.Views.View child, long drawingTime) { try { var radius = Math.Min(Width, Height) / 2; var strokeWidth = ((CircleImage)Element).BorderThickness; radius -= strokeWidth / 2; var path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); var paint = new Paint(); paint.AntiAlias = true; paint.SetStyle(Paint.Style.Fill); paint.Color = ((CircleImage)Element).FillColor.ToAndroid(); canvas.DrawPath(path, paint); paint.Dispose(); var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); var thickness = ((CircleImage)Element).BorderThickness; if(thickness > 0.0f) { paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = thickness; paint.SetStyle(Paint.Style.Stroke); paint.Color = ((CircleImage)Element).BorderColor.ToAndroid(); canvas.DrawPath(path, paint); paint.Dispose(); } path.Dispose(); return result; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex); } return base.DrawChild(canvas, child, drawingTime); }
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); }
/// <summary> /// This method is called from the OnDraw of elements supporting rounded corners: /// Border, Rectangle, Panel... /// </summary> private protected void AdjustCornerRadius(Android.Graphics.Canvas canvas, CornerRadius cornerRadius) { if (cornerRadius != CornerRadius.None) { var rect = new RectF(canvas.ClipBounds); var clipPath = cornerRadius.GetOutlinePath(rect); canvas.ClipPath(clipPath); } }
protected override bool DrawChild(ACanvas canvas, global::Android.Views.View child, long drawingTime) { if (Element == null) { return(false); } var pancake = Element as PancakeView; SetClipChildren(true); //Create path to clip the child if (pancake.Sides != 4) { using (var path = DrawingExtensions.CreatePolygonPath(Width, Height, pancake.Sides, pancake.CornerRadius.TopLeft, pancake.OffsetAngle)) { canvas.Save(); canvas.ClipPath(path); } } else { using (var path = DrawingExtensions.CreateRoundedRectPath(Width, Height, Context.ToPixels(pancake.CornerRadius.TopLeft), Context.ToPixels(pancake.CornerRadius.TopRight), Context.ToPixels(pancake.CornerRadius.BottomRight), Context.ToPixels(pancake.CornerRadius.BottomLeft))) { canvas.Save(); canvas.ClipPath(path); } } // Draw the child first so that the border shows up above it. var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); DrawBorder(canvas, pancake); return(result); }
protected override bool DrawChild(ACanvas canvas, global::Android.Views.View child, long drawingTime) { if (Element == null) { return(false); } var control = (CanvasView)Element; SetClipChildren(true); //Create path to clip the child if (control.Sides != 4) { using (var path = PolygonUtils.GetPolygonCornerPath(Width, Height, control.Sides, control.CornerRadius.TopLeft, control.OffsetAngle)) { canvas.Save(); canvas.ClipPath(path); } } else { using (var path = new Path()) { path.AddRoundRect(new RectF(0, 0, Width, Height), GetRadii(control), Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); } } // Draw the child first so that the border shows up above it. var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); DrawBorder(canvas, control); return(result); }
/// <summary> /// Redraws the child. /// </summary> protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime) { try { var radius = (float)((RoundedImage)Element).BorderRadius; var stroke = (float)((RoundedImage)Element).BorderThickness; var delta = (float)stroke / 2.0f; if (radius < 0) { radius = Math.Min(Width, Height) / 2.0f; } radius -= delta; // Clip with rounded rect var path = new Path(); path.AddRoundRect(new RectF(delta, delta, Width - stroke, Height - stroke), radius, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); path.Dispose(); var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); // Add stroke for smoother border path = new Path(); path.AddRoundRect(new RectF(delta, delta, Width - stroke, Height - stroke), radius, radius, Path.Direction.Ccw); var paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = stroke; paint.SetStyle(Paint.Style.Stroke); paint.Color = ((RoundedImage)Element).BorderColor.ToAndroid(); canvas.DrawPath(path, paint); paint.Dispose(); // Clean up path.Dispose(); return result; } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex); } return base.DrawChild(canvas, child, drawingTime); }
/// <Docs>The Canvas to which the View is rendered.</Docs> /// <summary> /// Draw the specified canvas. /// </summary> /// <param name="canvas">Canvas.</param> public override void Draw (Canvas canvas) { try { var element = Element as RoundCornerView; var cornerRadius = (float)element.CornerRadius*Resources.DisplayMetrics.Density; // Paint rounded rect itself canvas.Save(); var paint = new Paint(); paint.AntiAlias = true; var strokeWidth = (((float)element.BorderWidth)*Resources.DisplayMetrics.Density); paint.StrokeWidth = strokeWidth; if(element.BackgroundColor != Xamarin.Forms.Color.Transparent) { paint.SetStyle(Paint.Style.Fill); paint.Color = element.BackgroundColor.ToAndroid(); canvas.DrawRoundRect(new RectF(0, 0, Width, Height), cornerRadius, cornerRadius, paint); } if(element.BorderColor != Xamarin.Forms.Color.Transparent) { paint.SetStyle(Paint.Style.Stroke); paint.Color = element.BorderColor.ToAndroid(); canvas.DrawRoundRect(new RectF(0, 0, Width, Height), cornerRadius, cornerRadius, paint); } //Properly dispose paint.Dispose(); canvas.Restore(); // Create clip path var path = new Path(); path.AddRoundRect(new RectF(0.0f + (strokeWidth/2), 0.0f + (strokeWidth/2), Width - (strokeWidth/2), Height - (strokeWidth/2)), cornerRadius, cornerRadius, Path.Direction.Cw); canvas.Save(); canvas.ClipPath(path); // Do base drawing for(var i=0; i<ChildCount; i++) GetChildAt(i).Draw(canvas); canvas.Restore(); path.Dispose(); } catch (Exception) { } }
protected override void OnDraw(ACanvas canvas) { if (Element != null) { var cornerRadius = Forms.Context.ToPixels(Element.CornerRadius); using (var clipPath = new Path()) using (var pathDirection = Path.Direction.Cw) { clipPath.AddRoundRect(new RectF(canvas.ClipBounds), cornerRadius, cornerRadius, Path.Direction.Cw); canvas.ClipPath(clipPath); } } base.OnDraw(canvas); }
/// <summary> /// Draw one child of this View Group. /// </summary> /// <param name="canvas">The canvas on which to draw the child</param> /// <param name="child">Who to draw</param> /// <param name="drawingTime">The time at which draw is occurring</param> /// <returns>To be added.</returns> /// <since version="Added in API level 1" /> /// <remarks><para tool="javadoc-to-mdoc">Draw one child of this View Group. This method is responsible for getting /// the canvas in the right state. This includes clipping, translating so /// that the child's scrolled origin is at 0, 0, and applying any animation /// transformations.</para> /// <para tool="javadoc-to-mdoc"> /// <format type="text/html"> /// <a href="http://developer.android.com/reference/android/view/ViewGroup.html#drawChild(android.graphics.Canvas, android.view.View, long)" target="_blank">[Android Documentation]</a> /// </format> /// </para></remarks> protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime) { if (this.Element.Aspect != Aspect.AspectFit) { return base.DrawChild(canvas, child, drawingTime); } using (var path = new Path()) { path.AddCircle(Width / 2, Height / 2, (Math.Min(Width, Height) - 10) / 2, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); } return base.DrawChild(canvas, child, drawingTime); }
protected override bool DrawChild(Canvas canvas, View child, long drawingTime) { if(!ClipOutlines && Target != null) return base.DrawChild(canvas, child, drawingTime); var state = canvas.Save(); RevealPath.Reset(); RevealPath.AddCircle(CentreX, CentreY, getRadius(), Path.Direction.Cw); canvas.ClipPath(RevealPath); var isInvalid = base.DrawChild(canvas, child, drawingTime); canvas.RestoreToCount(state); return isInvalid; }
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); }
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); }
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)); }
protected override bool DrawChild(Android.Graphics.Canvas canvas, Android.Views.View child, long drawingTime) { try { var radius = Math.Min(Width, Height) / 2; var strokeWidth = Convert.ToInt32(element.BorderWidth); radius -= strokeWidth / 2; Path path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); var paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = element.BorderWidth; paint.SetStyle(Paint.Style.Stroke); paint.Color = global::Android.Graphics.Color.White; canvas.DrawPath(path, paint); paint.Dispose(); path.Dispose(); return(result); } catch (Exception ex) { var msg = ex.Message; } return(base.DrawChild(canvas, child, drawingTime)); }
protected override void OnDraw(ACanvas canvas) { if (this.Element == null) { return; } CorneredContentView control = (CorneredContentView)this.Element; this.SetClipChildren(true); //Create path to clip the child using (Path path = new Path()) { path.AddRoundRect(new RectF(0, 0, this.Width, this.Height), this.GetRadii(control), Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); } this.DrawBorder(canvas, control); }
protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime) { try { var radius = Math.Min(Width, Height) / 2; var strokeWidth = 10; radius -= strokeWidth / 2; Path path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); path = new Path(); path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); var paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = 5; paint.SetStyle(Paint.Style.Stroke); paint.Color = global::Android.Graphics.Color.White; canvas.DrawPath(path, paint); paint.Dispose(); path.Dispose(); return result; } catch (Exception ex) { } return base.DrawChild(canvas, child, drawingTime); }
protected override 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); }
public static Bitmap getRoundedShape(Bitmap scaleBitmapImage, int targetWidth, int targetHeight) { Bitmap targetBitmap = Bitmap.CreateBitmap(targetWidth, targetHeight, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(targetBitmap); Android.Graphics.Path path = new Android.Graphics.Path(); path.AddCircle(((float)targetWidth - 1) / 2, ((float)targetHeight - 1) / 2, (Math.Min(((float)targetWidth), ((float)targetHeight)) / 2), Android.Graphics.Path.Direction.Ccw); canvas.ClipPath(path); Bitmap sourceBitmap = scaleBitmapImage; canvas.DrawBitmap(sourceBitmap, new Rect(0, 0, sourceBitmap.Width, sourceBitmap.Height), new Rect(0, 0, targetWidth, targetHeight), null); return targetBitmap; }
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); } } }
public override void Draw(Canvas canvas) { // Draw background canvas.Save (); canvas.ClipPath (clipMask); canvas.DrawColor (bgColor); canvas.Restore (); // Draw labels var middleX = Width / 2; var selectedIndex = SelectedIndex; float deltaY = PaddingTop; for (int i = 0; i < words.Length; i++) { var word = words [i]; var layout = textLayouts [word]; var colorRatio = Math.Abs (i - selectedIndex) > 1 ? 0 : 1 - Math.Abs (i - scrollPosition); textPaint.Color = ImageUtils.InterpolateColor (colorRatio, normalColor, selectedColor); canvas.Save (SaveFlags.Matrix); canvas.Translate (middleX, deltaY); layout.Draw (canvas); canvas.Restore (); deltaY += layout.Height + spacing; } // Draw knob canvas.Save (); var top = selectedIndex * spacing + words.Take (selectedIndex).Select (w => textLayouts[w].Height).Sum () - knobPadding + PaddingTop; var selectedWordHeight = textLayouts [words [selectedIndex]].Height; var bottom = top + selectedWordHeight + 2 * knobPadding; var offset = scrollPosition - SelectedIndex; if (offset > 0 && selectedIndex < words.Length - 1) { var extraY = offset * (spacing + selectedWordHeight); var nextWordHeight = textLayouts [words [selectedIndex + 1]].Height; top += extraY; bottom += extraY; bottom += offset * (nextWordHeight - selectedWordHeight); } canvas.ClipRect (0, top, knobWidth, bottom); canvas.DrawColor (Color.White); canvas.Restore (); }
private void DrawRing(Canvas c) { var sc = c.Save(); c.Rotate(-this.Degree, c.Width / 2, c.Height / 2); //���ĵ� var cx = c.Width / 2; var cy = c.Height / 2; //������Բ Path ����һ�� Բ����ʾ����, ���ڿ���Բ var pInner = new Path(); pInner.AddCircle(cx, cy, this.BitmapRadius + SPACE / 2, Path.Direction.Cw); var pOut = new Path(); pOut.AddCircle(cx, cy, this.Radius, Path.Direction.Cw); c.ClipPath(pOut); c.ClipPath(pInner, Region.Op.Difference); //var color = new Color((int)(DateTime.Now.Ticks % 0xFFFFFFFF)); //c.DrawColor(color); //�ýǶȽ��������Բ�ķ�Χ var g = new SweepGradient(cx, cy, Color.Green, Color.Transparent); var paint = new Paint(); paint.SetShader(g); c.DrawCircle(cx, cy, this.Radius, paint); c.RestoreToCount(sc); }
private void DrawBitmap(Canvas c, Bitmap bmp) { var sc = c.Save(); this.Degree = this.Degree % 360 + DEGREE_STEP; //Ҫ����ת����ͼ����Ч�� c.Rotate(this.Degree, c.Width / 2, c.Height / 2); //���ĵ� var cx = c.Width / 2; var cy = c.Height / 2; //����ʾ��Χ, ָ���뾶��Բ var path = new Path(); path.AddCircle(cx, cy, this.BitmapRadius, Path.Direction.Cw); c.ClipPath(path); c.DrawColor(Color.White); //ͼƬ�Ļ��Ʒ�Χ var w = (this.ShowType == ShowTypes.Inner ? this.IWH : this.OWH) / 2; var rect = new Rect(cx - w, cy - w, cx + w, cy + w); //����ͼƬ var paint = new Paint(); //srcΪnull, ��������ͼƬ��ΪԴ c.DrawBitmap(bmp, null, rect, paint); c.RestoreToCount(sc); }
protected override void DispatchDraw(Canvas canvas) { if (showcaseX < 0 || showcaseY < 0 || isRedundant) { base.DispatchDraw(canvas); return; } bool recalculatedCling = mShowcaseDrawer.CalculateShowcaseRect(showcaseX, showcaseY); bool recalculateText = recalculatedCling || mAlteredText; mAlteredText = false; if (Build.VERSION.SdkInt <= BuildVersionCodes.Honeycomb && !mHasNoTarget) { var path = new Path(); path.AddCircle(showcaseX, showcaseY, showcaseRadius, Path.Direction.Cw); canvas.ClipPath(path, Region.Op.Difference); } //Draw background color canvas.DrawColor(mBackgroundColor); // Draw the showcase drawable if (!mHasNoTarget) { mShowcaseDrawer.DrawShowcase(canvas, showcaseX, showcaseY, scaleMultiplier, showcaseRadius); } // Draw the text on the screen, recalculating its position if necessary if (recalculateText) { mTextDrawer.CalculateTextPosition(canvas.Width, canvas.Height, this); } mTextDrawer.Draw(canvas, recalculateText); base.DispatchDraw(canvas); }
protected override bool DrawChild(Android.Graphics.Canvas canvas, Android.Views.View child, long drawingTime) { var fImage = (CircularImage)this.Element; try { var radius = (float)Math.Min(Width, Height) / 2f; var borderThickness = fImage.BorderWidth; float strokeWidth = 0f; if (borderThickness > 0) { var logicalDensity = Xamarin.Forms.Forms.Context.Resources.DisplayMetrics.Density; strokeWidth = (float)Math.Ceiling(borderThickness * logicalDensity + .5f); } radius -= strokeWidth / 2f; var path = new Path(); path.AddCircle(Width / 2.0f, Height / 2.0f, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); var paint = new Paint { AntiAlias = true }; paint.SetStyle(Paint.Style.Fill); paint.Color = fImage.BorderColor.ToAndroid(); canvas.DrawPath(path, paint); paint.Dispose(); var result = base.DrawChild(canvas, child, drawingTime); path.Dispose(); canvas.Restore(); path = new Path(); path.AddCircle(Width / 2f, Height / 2f, radius, Path.Direction.Ccw); if (strokeWidth > 0.0f) { paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = strokeWidth; paint.SetStyle(Paint.Style.Stroke); paint.Color = fImage.BorderColor.ToAndroid(); canvas.DrawPath(path, paint); paint.Dispose(); } path.Dispose(); return(result); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex); } return(base.DrawChild(canvas, child, drawingTime)); }
protected override bool DrawChild(Android.Graphics.Canvas canvas, Android.Views.View child, long drawingTime) { if (Element == null) { return(false); } RoundedCornerView rcv = (RoundedCornerView)Element; this.SetClipChildren(true); rcv.Padding = new Thickness(0, 0, 0, 0); //rcv.HasShadow = false; int radius = (int)(rcv.RoundedCornerRadius); // Check if make circle is set to true. If so, then we just use the width and // height of the control to calculate the radius. RoundedCornerRadius will be ignored // in this case. if (rcv.MakeCircle) { radius = Math.Min(Width, Height) / 2; } // When we create a round rect, we will have to double the radius since it is not // the same as creating a circle. radius *= 2; try { //Create path to clip the child var path = new Path(); path.AddRoundRect(new RectF(0, 0, Width, Height), new float[] { radius, radius, radius, radius, radius, radius, radius, radius }, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); // Draw the child first so that the border shows up above it. var result = base.DrawChild(canvas, child, drawingTime); canvas.Restore(); /* * If a border is specified, we use the same path created above to stroke * with the border color. * */ if (rcv.BorderWidth > 0) { // Draw a filled circle. var paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = rcv.BorderWidth; paint.SetStyle(Paint.Style.Stroke); paint.Color = rcv.BorderColor.ToAndroid(); canvas.DrawPath(path, paint); paint.Dispose(); } //Properly dispose path.Dispose(); return(result); } catch (Exception ex) { System.Console.Write(ex.Message); } return(base.DrawChild(canvas, child, drawingTime)); }
/// <summary> /// Draw one child of this View Group. /// </summary> /// <param name="canvas">The canvas on which to draw the child</param> /// <param name="child">Who to draw</param> /// <param name="drawingTime">The time at which draw is occurring</param> /// <returns>To be added.</returns> /// <since version="Added in API level 1" /> /// <remarks><para tool="javadoc-to-mdoc">Draw one child of this View Group. This method is responsible for getting /// the canvas in the right state. This includes clipping, translating so /// that the child's scrolled origin is at 0, 0, and applying any animation /// transformations.</para> /// <para tool="javadoc-to-mdoc"> /// <format type="text/html"> /// <a href="http://developer.android.com/reference/android/view/ViewGroup.html#drawChild(android.graphics.Canvas, android.view.View, long)" target="_blank">[Android Documentation]</a> /// </format> /// </para></remarks> protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime) { if (this.Element.Aspect == Aspect.AspectFit) { 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); path.Dispose(); return result; } return base.DrawChild(canvas, child, drawingTime); }
void DrawWater(Canvas canvas) { canvas.Save (); var circle = new Path (); circle.AddCircle (Width / 2, Height / 2, Height / 2, Path.Direction.Ccw); circle.Close (); canvas.ClipPath (circle); wavy.Draw (canvas); canvas.Restore (); }
internal void Draw(Canvas canvas, bool isRound) { if (Hidden) { return; } canvas.Save(); var resizerPaint = new Paint { Color = new Color(255, 255, 255, 200) }; //if (!Focused) //{ // outlinePaint.Color = Color.White; // canvas.DrawRect(DrawRect, outlinePaint); // //canvas.DrawCircle(DrawRect.CenterX(), DrawRect.CenterY(), DrawRect.Width(), resizerPaint); //} //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(); if (isRound) { path.AddCircle(DrawRect.CenterX(), DrawRect.CenterY(), DrawRect.Width() / 2, Path.Direction.Cw); canvas.ClipPath(path, Region.Op.Difference); canvas.DrawCircle(viewDrawingRect.CenterX(), viewDrawingRect.CenterY(), viewDrawingRect.Width(), focusPaint); } else { path.AddRect(new RectF(DrawRect), Path.Direction.Cw); canvas.ClipPath(path, Region.Op.Difference); canvas.DrawRect(viewDrawingRect, focusPaint); } //canvas.ClipPath(path, Region.Op.Difference); //if (isRound) // canvas.DrawCircle(viewDrawingRect.CenterX(), viewDrawingRect.CenterY(), viewDrawingRect.Width(), focusPaint); //else // canvas.DrawRect(viewDrawingRect, focusPaint); canvas.Restore(); canvas.DrawPath(path, outlinePaint); var resizerTriangle = new Path(); var resizerOffset = 4; var triangleSize = resizerSize + resizerOffset; resizerTriangle.MoveTo(DrawRect.Right - resizerOffset, DrawRect.Bottom - triangleSize); resizerTriangle.LineTo(DrawRect.Right - resizerOffset, DrawRect.Bottom - resizerOffset); resizerTriangle.LineTo(DrawRect.Right - triangleSize, DrawRect.Bottom - resizerOffset); resizerPaint.SetStyle(Paint.Style.Fill); canvas.DrawPath(resizerTriangle, resizerPaint); if (isRound) { // Draw the rectangle around the round cropper var roundCropperRectangle = new Path(); roundCropperRectangle.MoveTo(DrawRect.Left, DrawRect.Top); roundCropperRectangle.LineTo(DrawRect.Right, DrawRect.Top); roundCropperRectangle.LineTo(DrawRect.Right, DrawRect.Bottom); roundCropperRectangle.LineTo(DrawRect.Left, DrawRect.Bottom); roundCropperRectangle.LineTo(DrawRect.Left, DrawRect.Top); resizerPaint.SetStyle(Paint.Style.Stroke); canvas.DrawPath(roundCropperRectangle, resizerPaint); } }