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)); }
// if sweepAngle is negative, the gradient will fade inward, if it's positive, outward. public static void DrawGradientArc(Canvas canvas, TinyTypeLib.PointF center, float radius, float startAngle, float sweepAngle, int gradientSize, Color color) { //center = new TinyTypeLib.PointF(center.X + 30, center.Y); float radiusToUse = sweepAngle < 0 ? radius : radius + gradientSize; float gradientPercent = gradientSize / (float)radius; int[] colors; float[] positions; Paint paint = new Paint(); paint.SetStyle(Paint.Style.FillAndStroke); if (sweepAngle > 0) { // We need to clip out the middle of the circle so the mirrored gradient doesn't show Path cp = new Path(); cp.AddCircle(center.X, center.Y, radius, Path.Direction.Cw); canvas.ClipPath(cp, Region.Op.Difference); } colors = new int[] { AndroidUtil.GetTransparentColor(color), AndroidUtil.GetTransparentColor(color), color }; positions = new float[] { 0f, 1 - gradientPercent, 1f }; paint.SetShader(new RadialGradient(center.X, center.Y, radius, colors, positions, Shader.TileMode.Mirror)); RectF square = new RectF(center.X - radiusToUse, center.Y - radiusToUse, center.X + radiusToUse, center.Y + radiusToUse); canvas.DrawArc(square, startAngle, sweepAngle, true, paint); /* Draw circles for reference * Paint circlePaint = new Paint(); * circlePaint.Color = Color.Black; * circlePaint.SetStyle(Paint.Style.Stroke); * canvas.DrawCircle(center.X, center.Y, radius, circlePaint); * canvas.DrawCircle(center.X, center.Y, radiusToUse, circlePaint); */ }
protected override bool DrawChild(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 using (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(); return(result); } } catch { } return(base.DrawChild(canvas, child, drawingTime)); }
protected override bool DrawChild(Canvas canvas, Android.Views.View child, long drawingTime) { try { var radius = (float)Math.Min(Width, Height) / 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 = Xamarin.Forms.Color.Transparent.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); path.Dispose(); return(result); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex); } return(base.DrawChild(canvas, child, drawingTime)); }
void Initialize() { // Create Paint for all drawing paint = new Paint(); // All paths are based on 100-unit clock radius // centered at (0, 0). // Define circle for tick marks. tickMarks = new Path(); tickMarks.AddCircle(0, 0, 90, Path.Direction.Cw); // Hour, minute, second hands defined to point straight up. // Define hour hand. hourHand = new Path(); hourHand.MoveTo(0, -60); hourHand.CubicTo(0, -30, 20, -30, 5, -20); hourHand.LineTo(5, 0); hourHand.CubicTo(5, 7.5f, -5, 7.5f, -5, 0); hourHand.LineTo(-5, -20); hourHand.CubicTo(-20, -30, 0, -30, 0, -60); hourHand.Close(); // Define minute hand. minuteHand = new Path(); minuteHand.MoveTo(0, -80); minuteHand.CubicTo(0, -75, 0, -70, 2.5f, -60); minuteHand.LineTo(2.5f, 0); minuteHand.CubicTo(2.5f, 5, -2.5f, 5, -2.5f, 0); minuteHand.LineTo(-2.5f, -60); minuteHand.CubicTo(0, -70, 0, -75, 0, -80); minuteHand.Close(); // Define second hand. secondHand = new Path(); secondHand.MoveTo(0, 10); secondHand.LineTo(0, -80); }
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)); }
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); }
static void Main() { // Create new document Document pdfDocument = new Document(); pdfDocument.RegistrationName = "demo"; pdfDocument.RegistrationKey = "demo"; // Add page Page page = new Page(PaperFormat.A4); pdfDocument.Pages.Add(page); PointF center = new PointF(200, 200); // Create clipping path from circle Path path = new Path(); path.AddCircle(center, 100); page.Canvas.SetClip(path); // Paint rectangle over the clipping circle. // Only part of the rectangle intersecting the clipping circle will be drawn. SolidBrush brush = new SolidBrush(new ColorRGB(255, 0, 0)); page.Canvas.DrawRectangle(brush, center.X - 50, center.Y - 50, 200, 200); // Save document to file pdfDocument.Save("result.pdf"); // Cleanup pdfDocument.Dispose(); // Open result document in default associated application (for demo purpose) ProcessStartInfo processStartInfo = new ProcessStartInfo("result.pdf"); processStartInfo.UseShellExecute = true; Process.Start(processStartInfo); }
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) { System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex); } return(base.DrawChild(canvas, child, drawingTime)); }
public override void Draw(Canvas canvas) { if (Flag) { //抗锯齿 canvas.DrawFilter = new PaintFlagsDrawFilter(PaintFlags.AntiAlias | PaintFlags.FilterBitmap, PaintFlags.AntiAlias | PaintFlags.FilterBitmap); var density = this.Context.Resources.DisplayMetrics.Density; var path = new Path(); path.AddCircle(canvas.Width / 2, canvas.Height / 2, (float)this.Element.Radius * density, Path.Direction.Ccw); canvas.ClipPath(path, Region.Op.Intersect); canvas.DrawColor(this.Element.BackgroundColor.ToAndroid()); path.Dispose(); } else { var bmp = this.GetClip(canvas.Width, canvas.Height, this.BgColor); var paint = new Paint(PaintFlags.AntiAlias); canvas.DrawBitmap(bmp, 0, 0, paint); paint.Dispose(); bmp.Dispose(); } base.Draw(canvas); }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); double paddedWidth = Width - Graph.Padding.HorizontalThickness, paddedHeight = Height - Graph.Padding.VerticalThickness; paint.AntiAlias = true; //canvas.DrawColor(Color.Aqua); paint.StrokeWidth = 2; paint.SetPathEffect(new DashPathEffect(new float[] { 15, 10 }, 0)); for (int i = 0; i <= 5; i++) { canvas.DrawLine(0, 1 + i * (Height - 2) / 5, Width, 1 + i * (Height - 2) / 5, paint); } if (Graph.X.Length > 0 && Graph.Y.Length > 0) { paint.StrokeWidth = 6; paint.SetPathEffect(null); canvas.Translate((float)Graph.Padding.Left, (float)Graph.Padding.Top); canvas.Scale((float)paddedWidth / Width, (float)paddedHeight / Height); var path = new Path(); path.MoveTo(Width * Graph.X[0] / Graph.XAxis, Height - Height * Graph.Y[0] / Graph.YAxis); for (int i = 0; i < Graph.X.Length; i++) { path.LineTo(Width * Graph.X[i] / Graph.XAxis, Height - Height * Graph.Y[i] / Graph.YAxis); path.AddCircle(Width * Graph.X[i] / Graph.XAxis, Height - Height * Graph.Y[i] / Graph.YAxis, 3, Path.Direction.Cw); } canvas.DrawPath(path, paint); } }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); Paint paint = new Paint(); switch (Mode) { case StylerButtonMode.sbDisabled: paint.Color = disabledColor; break; case StylerButtonMode.sbEnabled: paint.Color = enabledColor; break; case StylerButtonMode.SbActive: paint.Color = activeColor; break; case StylerButtonMode.sbFlash: if (isLight) { paint.Color = activeColor; } else { paint.Color = enabledColor; } break; default: throw new ApplicationException("Mode undefined!!!"); } paint.SetStyle(Paint.Style.Fill); Path path = new Path(); path.Reset(); path.MoveTo(measureWidth / 2, measureHeight / 2); path.AddCircle(measureWidth / 2, measureHeight / 2, measureHeight / 6, Path.Direction.Ccw); canvas.DrawPath(path, paint); }
protected override bool DrawChild(Canvas canvas, View child, long drawingTime) { // Define a circle that fills the canvas var path = new Path(); var bounds = canvas.ClipBounds; int minDimension = Math.Min(bounds.Width(), bounds.Height()); // This may round to zero but Android should always draw at least one pixel float strokeWidth = (float)Math.Round(minDimension / DiameterToStrokeRatio); float radius = (minDimension - strokeWidth) / 2f; path.AddCircle(bounds.ExactCenterX(), bounds.ExactCenterY(), radius, Path.Direction.Cw); var paint = new Paint(PaintFlags.AntiAlias) { Color = Color.Black, StrokeWidth = strokeWidth }; // Fill inside the circle if the switch is toggled on paint.SetStyle(Element.IsToggled ? Paint.Style.FillAndStroke : Paint.Style.Stroke); // Draw the circle canvas.DrawPath(path, paint); return(true); }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); // set canvas background color // canvas.DrawColor(bgColor); // set stroke width paint.StrokeWidth = ((float)(0.02083 * screenW)); // initializing paths path = new Path(); path1 = new Path(); // positioning Sun with respect to cloud PointF P5c1 = cloud.getP5c1(X, Y, screenW, count); if (XSun == 0) { // center point for Sun XSun = P5c1.X; YSun = P5c1.Y + (int)(0.042 * screenW); } //incrementing counter for rotation count = count + 0.5; //comparison to check 360 degrees rotation int retval = Double.Compare(count, 360.00); if (retval == 0) { if (!isAnimated) { // mark completion of animation isAnimated = true; //resetting counter on completion of a rotation count = 0; } else { //resetting counter on completion of a rotation count = 0; } } // drawing center circle path.AddCircle(XSun, YSun, (int)(0.083 * screenW), Path.Direction.Cw); // drawing arms of sun for (int i = 0; i < 360; i += 45) { path1.MoveTo(XSun, YSun); float x1 = (float)((int)(0.1146 * screenW) * Math.Cos(Math.ToRadians(i + count / 4)) + XSun); //arm pointX at radius 50 with incrementing angle from center of sun float y1 = (float)((int)(0.1146 * screenW) * Math.Sin(Math.ToRadians(i + count / 4)) + YSun); //arm pointY at radius 50 with incrementing angle from center of sun float X2 = (float)((int)(0.1563 * screenW) * Math.Cos(Math.ToRadians(i + count / 4)) + XSun); //arm pointX at radius 65 with incrementing angle from center of sun float Y2 = (float)((int)(0.1563 * screenW) * Math.Sin(Math.ToRadians(i + count / 4)) + YSun); //arm pointY at radius 65 with incrementing angle from center of sun path1.MoveTo(x1, y1); // draw arms of sun path1.LineTo(X2, Y2); } // drawing sun canvas.DrawPath(path, paint); canvas.DrawPath(path1, paint); // drawing cloud with fill paint.Color = (bgColor); paint.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paint); // drawing cloud with stroke paint.Color = (strokeColor); paint.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paint); if (!isStatic || !isAnimated) { // invalidate if not static or not animating Invalidate(); } }
protected override void OnDraw(Canvas canvas) { float centerX = Width / 2F; float centerY = Height / 2F; float uniformWidth = Math.Min(Math.Min(centerX, centerY), RenderSize); // Path pathClip = new Path(); switch (shape) { case AvatarShape.Circle: pathClip.AddCircle(centerX, centerY, uniformWidth - (BorderRadius * 2), Path.Direction.Cw); break; case AvatarShape.RoundedRect: pathClip.AddRoundRect(0, 0, Width, Height, 5, 5, Path.Direction.Ccw); break; } canvas.Save(SaveFlags.Clip); canvas.ClipPath(pathClip); // canvas.DrawColor(backgroundColor); if (_fetchImage && placeHolderImage == null) { canvas.DrawColor(Color.LightGray); } else { if (image != null) { float subX = imageSize != null ? imageSize.Width / 2F : image.Width / 2F; float subY = imageSize != null ? imageSize.Height / 2F : image.Height / 2F; canvas.DrawBitmap(image, new Rect(0, 0, image.Width, image.Height), new Rect((int)(centerX - subX), (int)(centerY - subY), (int)(centerX - subX + subX * 2F), (int)(centerY - subY + subY * 2F)), null); } else if (placeHolderImage != null) { float subX = placeHolderImageSize != null ? placeHolderImageSize.Width / 2F : placeHolderImage.Width / 2F; float subY = placeHolderImageSize != null ? placeHolderImageSize.Height / 2F : placeHolderImage.Height / 2F; canvas.DrawBitmap(placeHolderImage, new Rect(0, 0, placeHolderImage.Width, placeHolderImage.Height), new Rect((int)(centerX - subX), (int)(centerY - subY), (int)((centerX - subX) + subX * 2F), (int)((centerY - subY) + subY * 2F)), null); if (_fetchImage) { canvas.DrawColor(OverlayColor); } } else if (Name != null) { string avatarName = AvatarName; Paint p = new Paint() { Color = GetAvatarBackgroundColor(avatarName), }; p.Flags |= PaintFlags.AntiAlias; // p.SetStyle(Paint.Style.Fill); canvas.DrawPaint(p); // Set p.Color = Color.White; p.SetTypeface(Typeface.SansSerif); p.TextSize = 60; // var metrics = p.GetFontMetrics(); float width = p.MeasureText(avatarName); canvas.DrawText(avatarName, centerX - width / 2F, centerY + metrics.Bottom, p); } } if (BorderRadius > 0) { canvas.Restore(); // var cPaint = new Paint(); cPaint.Flags |= PaintFlags.AntiAlias; cPaint.Color = BorderColor; cPaint.StrokeWidth = BorderRadius; cPaint.SetStyle(Paint.Style.Stroke); if (DrawShadow && !canvas.IsHardwareAccelerated) { cPaint.SetShadowLayer(ShadowRadius, ShadowOffsetX, ShadowOffsetY, ShadowColor); } // switch (shape) { case AvatarShape.Circle: canvas.DrawCircle(centerX, centerY, uniformWidth - (BorderRadius * 2F), cPaint); break; case AvatarShape.RoundedRect: { canvas.DrawRoundRect(0, 0, Width, Height, 5, 5, cPaint); } break; } } }
private void Initialize() { mPath = new Path(); mPath.AddCircle(40, 40, 45, Path.Direction.Ccw); mPath.AddCircle(80, 80, 45, Path.Direction.Ccw); }
void drawLines(Canvas canvas, Paint paint) { float x, y; // Draw curved graph line var whiteAlpha25 = Color.Argb(64, 255, 255, 255); //var whiteAlpha70 = Color.Argb (64, 255, 255, 255); var start = new PointF(); var end = new PointF(); using (Path path = new Path()) { var count = hourly ? HourlyTemps.Count : (Forecasts.Count * 2); for (int i = 0; i < count; i++) { // adjusted index var ai = i; double temp; if (hourly) { temp = HourlyTemps [ai]; } else { // reset start when switching from highs to lows if (i == Forecasts.Count) { start = new PointF(); } var highs = i < Forecasts.Count; ai = highs ? i : i - Forecasts.Count; temp = highs ? HighTemps [ai] : LowTemps [ai]; } var percent = ((float)temp - scaleLow) / scaleRange; x = padding + inset + (ai * scaleX); y = graphRect.Bottom - (graphRect.Height() * percent); end = new PointF(x, y); if (!hourly) { path.AddCircle(end.X - lineWidth, end.Y - lineWidth, lineWidth / 2, Path.Direction.Cw); } if (start.IsEmpty()) { path.MoveTo(end); } else { path.MoveTo(start); if (hourly) { path.LineTo(end); } else { var diff = (end.X - start.X) / 2; path.CubicTo(end.X - diff, start.Y, start.X + diff, end.Y, end.X, end.Y); } } start = end; } paint.Color = whiteAlpha25; paint.StrokeWidth = lineWidth; paint.SetStyle(Paint.Style.Stroke); canvas.DrawPath(path, paint); } }
public override void CreateBorderedPath(Path path, Circle shape, int width, int height, int strokeWidth) { var radius = (Math.Min(width, height) - strokeWidth) / 2f; path.AddCircle(width / 2f, height / 2f, radius, Path.Direction.Ccw); }
/// <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 { float radius = Math.Min(Width, Height) / 2f; float borderThickness = ((DonorPlus.Renderers.ImageRenderer)Element).BorderThickness; float strokeWidth = 0f; if (borderThickness > 0) { float logicalDensity = Android.App.Application.Context.Resources.DisplayMetrics.Density; strokeWidth = (float)Math.Ceiling(borderThickness * logicalDensity + .5f); } radius -= strokeWidth / 2f; Path path = new Path(); path.AddCircle(Width / 2.0f, Height / 2.0f, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); Paint paint = new Paint { AntiAlias = true }; paint.SetStyle(Paint.Style.Fill); paint.Color = ((DonorPlus.Renderers.ImageRenderer)Element).FillColor.ToAndroid(); canvas.DrawPath(path, paint); paint.Dispose(); bool 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 { AntiAlias = true, StrokeWidth = strokeWidth }; paint.SetStyle(Paint.Style.Stroke); paint.Color = ((DonorPlus.Renderers.ImageRenderer)Element).BorderColor.ToAndroid(); canvas.DrawPath(path, paint); paint.Dispose(); } path.Dispose(); return(result); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex); } return(base.DrawChild(canvas, child, drawingTime)); }
private void Init(Context context, IAttributeSet attrs) { var thumbNormal = Resource.Drawable.seek_thumb_normal; var thumbPressed = Resource.Drawable.seek_thumb_pressed; var thumbDisabled = Resource.Drawable.seek_thumb_disabled; Color thumbShadowColor; var defaultShadowColor = Color.Argb(75, 0, 0, 0); var defaultShadowYOffset = PixelUtil.DpToPx(context, 2); var defaultShadowXOffset = PixelUtil.DpToPx(context, 0); var defaultShadowBlur = PixelUtil.DpToPx(context, 2); _distanceToTop = PixelUtil.DpToPx(context, DefaultTextDistanceToTopInDp); if (attrs == null) { SetRangeToDefaultValues(); _internalPad = PixelUtil.DpToPx(context, InitialPaddingInDp); _barHeight = PixelUtil.DpToPx(context, LineHeightInDp); ActiveColor = DefaultActiveColor; DefaultColor = Color.Gray; AlwaysActive = false; ShowTextAboveThumbs = true; TextAboveThumbsColor = Color.White; thumbShadowColor = defaultShadowColor; ThumbShadowXOffset = defaultShadowXOffset; ThumbShadowYOffset = defaultShadowYOffset; _thumbShadowBlur = defaultShadowBlur; ActivateOnDefaultValues = false; TextSizeInSp = DefaultTextSizeInSp; } else { var a = Context.ObtainStyledAttributes(attrs, Resource.Styleable.RangeSliderControl, 0, 0); try { SetRangeValues(ExtractNumericValueFromAttributes(a, Resource.Styleable.RangeSliderControl_absoluteMinValue, DefaultMinimum), ExtractNumericValueFromAttributes(a, Resource.Styleable.RangeSliderControl_absoluteMaxValue, DefaultMaximum)); ShowTextAboveThumbs = a.GetBoolean(Resource.Styleable.RangeSliderControl_valuesAboveThumbs, true); TextAboveThumbsColor = a.GetColor(Resource.Styleable.RangeSliderControl_textAboveThumbsColor, Color.White); MinThumbHidden = a.GetBoolean(Resource.Styleable.RangeSliderControl_minThumbHidden, false); MaxThumbHidden = a.GetBoolean(Resource.Styleable.RangeSliderControl_maxThumbHidden, false); ShowLabels = a.GetBoolean(Resource.Styleable.RangeSliderControl_showRangeLabels, true); _internalPad = a.GetDimensionPixelSize(Resource.Styleable.RangeSliderControl_internalPadding, InitialPaddingInDp); _barHeight = a.GetDimensionPixelSize(Resource.Styleable.RangeSliderControl_barHeight, LineHeightInDp); ActiveColor = a.GetColor(Resource.Styleable.RangeSliderControl_activeColor, DefaultActiveColor); DefaultColor = a.GetColor(Resource.Styleable.RangeSliderControl_defaultColor, Color.Gray); AlwaysActive = a.GetBoolean(Resource.Styleable.RangeSliderControl_alwaysActive, false); StepValue = ExtractNumericValueFromAttributes(a, Resource.Styleable.RangeSliderControl_stepValue, DefaultStepValue); StepValueContinuously = a.GetBoolean(Resource.Styleable.RangeSliderControl_stepValueContinuously, false); var normalDrawable = a.GetDrawable(Resource.Styleable.RangeSliderControl_thumbNormal); if (normalDrawable != null) { ThumbImage = BitmapUtil.DrawableToBitmap(normalDrawable); } var disabledDrawable = a.GetDrawable(Resource.Styleable.RangeSliderControl_thumbDisabled); if (disabledDrawable != null) { ThumbDisabledImage = BitmapUtil.DrawableToBitmap(disabledDrawable); } var pressedDrawable = a.GetDrawable(Resource.Styleable.RangeSliderControl_thumbPressed); if (pressedDrawable != null) { ThumbPressedImage = BitmapUtil.DrawableToBitmap(pressedDrawable); } ThumbShadow = a.GetBoolean(Resource.Styleable.RangeSliderControl_thumbShadow, false); thumbShadowColor = a.GetColor(Resource.Styleable.RangeSliderControl_thumbShadowColor, defaultShadowColor); ThumbShadowXOffset = a.GetDimensionPixelSize(Resource.Styleable.RangeSliderControl_thumbShadowXOffset, defaultShadowXOffset); ThumbShadowYOffset = a.GetDimensionPixelSize(Resource.Styleable.RangeSliderControl_thumbShadowYOffset, defaultShadowYOffset); _thumbShadowBlur = a.GetDimensionPixelSize(Resource.Styleable.RangeSliderControl_thumbShadowBlur, defaultShadowBlur); ActivateOnDefaultValues = a.GetBoolean(Resource.Styleable.RangeSliderControl_activateOnDefaultValues, false); TextSizeInSp = a.GetInt(Resource.Styleable.RangeSliderControl_textSize, DefaultTextSizeInSp); } finally { a.Recycle(); } } if (ThumbImage == null) { ThumbImage = BitmapFactory.DecodeResource(Resources, thumbNormal); } if (ThumbPressedImage == null) { ThumbPressedImage = BitmapFactory.DecodeResource(Resources, thumbPressed); } if (ThumbDisabledImage == null) { ThumbDisabledImage = BitmapFactory.DecodeResource(Resources, thumbDisabled); } _thumbHalfWidth = 0.5f * ThumbImage.Width; _thumbHalfHeight = 0.5f * ThumbImage.Height; SetBarHeight(_barHeight); // make RangeSliderControl focusable. This solves focus handling issues in case EditText widgets are being used along with the RangeSliderControl within ScrollViews. Focusable = true; FocusableInTouchMode = true; _scaledTouchSlop = ViewConfiguration.Get(Context).ScaledTouchSlop; if (ThumbShadow) { // We need to remove hardware acceleration in order to blur the shadow SetLayerType(LayerType.Software, null); _shadowPaint.Color = thumbShadowColor; _shadowPaint.SetMaskFilter(new BlurMaskFilter(_thumbShadowBlur, BlurMaskFilter.Blur.Normal)); _thumbShadowPath = new Path(); _thumbShadowPath.AddCircle(0, 0, _thumbHalfHeight, Path.Direction.Cw); } }
protected override bool DrawChild(Canvas canvas, 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 = ((CircleButton)Element).CircleBorderWidth; //paint.SetStyle(Paint.Style.Stroke); //paint.Color = ((CircleButton)Element).CircleBorderColor.ToAndroid(); //canvas.DrawPath(path, paint); //////Properly dispose //paint.Dispose(); //path.Dispose(); return(result); } catch (Exception ex) { //Debug.WriteLine("Unable to create circle image: " + ex); } return(base.DrawChild(canvas, child, drawingTime)); //try //{ // var radius = Math.Min(Width, Height) / 2; // var strokeWidth = ((CircleButton)Element).CircleBorderWidth; // radius -= strokeWidth / 2; // //Create path to clip // var path = new Path(); // path.AddCircle(Width / 2, Height / 2, (float)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 = strokeWidth; // //paint.SetStyle(Paint.Style.Stroke); // //paint.Color = ((CircleButton)Element).CircleBorderColor.ToAndroid(); // //canvas.DrawPath(path, paint); // ////Properly dispose // //paint.Dispose(); // //path.Dispose(); // //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; // //var button = ((CircleButton)Element); // //Android.Graphics.Color color; // //if (button.BackgroundColor.R == -1.0 && button.BackgroundColor.G == -1.0 && button.BackgroundColor.B == -1.0) // // color = (Android.Graphics.Color.ParseColor("#ff2c2e2f")); // //else // // color = (button.BackgroundColor.ToAndroid()); // //paint.Color = color; // ////canvas.DrawPath(path, paint); // //canvas.DrawCircle(0, 0, radius, paint); // ////Properly dispose // //paint.Dispose(); // //path.Dispose(); // return result; //} //catch (Exception ex) //{ // //Debug.WriteLine("Unable to create circle image: " + ex); //} //return base.DrawChild(canvas, child, drawingTime); }
protected override void OnDraw(Canvas ca) { if (fullImage == null || shouldUpdate) { fullImage = Bitmap.CreateBitmap(Width, Height, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(fullImage); String max = (int)maxY + ""; // used to display max String min = (int)minY + ""; // used to display min paint.Reset(); Path path = new Path(); float bottomPadding = 1, topPadding = 0; float sidePadding = 10; if (this.showMinAndMax) { sidePadding = txtPaint.MeasureText(max); } float usableHeight = Height - bottomPadding - topPadding; float usableWidth = Width - sidePadding * 2; float lineSpace = usableHeight / 10; int lineCount = 0; foreach (Line line in lines) { int count = 0; float lastXPixels = 0, newYPixels; float lastYPixels = 0, newXPixels; float maxYd = getMaxY(); float minYd = getMinY(); float maxXd = getMaxX(); float minXd = getMinX(); if (lineCount == lineToFill) { paint.Color = Color.White; paint.Alpha = 30; paint.StrokeWidth = 2; for (int i = 10; i - Width < Height; i = i + 20) { canvas.DrawLine(i, Height - bottomPadding, 0, Height - bottomPadding - i, paint); } paint.Reset(); paint.SetXfermode(new PorterDuffXfermode(Android.Graphics.PorterDuff.Mode.Clear)); foreach (LinePoint p in line.getPoints()) { float yPercent = (p.getY() - minY) / (maxYd - minYd); float xPercent = (p.getX() - minX) / (maxXd - minXd); if (count == 0) { lastXPixels = sidePadding + (xPercent * usableWidth); lastYPixels = Height - bottomPadding - (usableHeight * yPercent); path.MoveTo(lastXPixels, lastYPixels); } else { newXPixels = sidePadding + (xPercent * usableWidth); newYPixels = Height - bottomPadding - (usableHeight * yPercent); path.LineTo(newXPixels, newYPixels); Path pa = new Path(); pa.MoveTo(lastXPixels, lastYPixels); pa.LineTo(newXPixels, newYPixels); pa.LineTo(newXPixels, 0); pa.LineTo(lastXPixels, 0); pa.Close(); canvas.DrawPath(pa, paint); lastXPixels = newXPixels; lastYPixels = newYPixels; } count++; } path.Reset(); path.MoveTo(0, Height - bottomPadding); path.LineTo(sidePadding, Height - bottomPadding); path.LineTo(sidePadding, 0); path.LineTo(0, 0); path.Close(); canvas.DrawPath(path, paint); path.Reset(); path.MoveTo(Width, Height - bottomPadding); path.LineTo(Width - sidePadding, Height - bottomPadding); path.LineTo(Width - sidePadding, 0); path.LineTo(Width, 0); path.Close(); canvas.DrawPath(path, paint); } lineCount++; } paint.Reset(); paint.Color = Color.White; //paint.setColor(this.gridColor); paint.Alpha = 50; paint.AntiAlias = true; canvas.DrawLine(sidePadding, Height - bottomPadding, Width, Height - bottomPadding, paint); if (this.showHorizontalGrid1) { for (int i = 1; i <= 10; i++) { canvas.DrawLine(sidePadding, Height - bottomPadding - (i * lineSpace), Width, Height - bottomPadding - (i * lineSpace), paint); } } paint.Alpha = 255; foreach (Line line in lines) { int count = 0; float lastXPixels = 0, newYPixels; float lastYPixels = 0, newXPixels; float maxYd = getMaxY(); float minYd = getMinY(); float maxXd = getMaxX(); float minXd = getMinX(); paint.Color = Color.Yellow; //paint.setColor(line.getColor()); paint.StrokeWidth = 6; foreach (LinePoint p in line.getPoints()) { float yPercent = (p.getY() - minY) / (maxYd - minYd); float xPercent = (p.getX() - minX) / (maxXd - minXd); if (count == 0) { lastXPixels = sidePadding + (xPercent * usableWidth); lastYPixels = Height - bottomPadding - (usableHeight * yPercent); } else { newXPixels = sidePadding + (xPercent * usableWidth); newYPixels = Height - bottomPadding - (usableHeight * yPercent); canvas.DrawLine(lastXPixels, lastYPixels, newXPixels, newYPixels, paint); lastXPixels = newXPixels; lastYPixels = newYPixels; } count++; } } int pointCount = 0; foreach (Line line in lines) { float maxYd = getMaxY(); float minYd = getMinY(); float maxXd = getMaxX(); float minXd = getMinX(); paint.Color = Color.Yellow; //paint.setColor(line.getColor()); paint.StrokeWidth = 6; paint.StrokeCap = Paint.Cap.Round; if (line.isShowingPoints()) { foreach (LinePoint p in line.getPoints()) { float yPercent = (p.getY() - minYd) / (maxYd - minYd); float xPercent = (p.getX() - minXd) / (maxXd - minXd); float xPixels = sidePadding + (xPercent * usableWidth); float yPixels = Height - bottomPadding - (usableHeight * yPercent); paint.Color = Color.Gray; canvas.DrawCircle(xPixels, yPixels, 10, paint); paint.Color = Color.White; canvas.DrawCircle(xPixels, yPixels, 5, paint); Path path2 = new Path(); path2.AddCircle(xPixels, yPixels, 30, Android.Graphics.Path.Direction.Cw); p.setPath(path2); p.setRegion(new Region((int)(xPixels - 30), (int)(yPixels - 30), (int)(xPixels + 30), (int)(yPixels + 30))); if (indexSelected == pointCount && listener != null) { paint.Color = Color.ParseColor("#33B5E5"); paint.Alpha = 100; canvas.DrawPath(p.getPath(), paint); paint.Alpha = 255; } pointCount++; } } } shouldUpdate = false; if (this.showMinAndMax) { ca.DrawText(max, 0, txtPaint.TextSize, txtPaint); ca.DrawText(min, 0, this.Height, txtPaint); } } ca.DrawBitmap(fullImage, 0, 0, null); }
protected override bool DrawChild(Canvas canvas, Android.Views.View child, long drawingTime) { SetColorTint(); var isCircle = ((BMImage)Element).IsCircle; var borderSize = ((BMImage)Element).BorderSize; var borderColor = ((BMImage)Element).BorderColor.ToAndroid(); try { var strokeWidth = 0f; if (borderSize > 0) { var logicalDensity = Android.App.Application.Context.Resources.DisplayMetrics.Density; strokeWidth = (float)Math.Ceiling(borderSize * logicalDensity + .5f); } var radius = 0f; var path = new Path(); var result = true; if (isCircle) { radius = Math.Min(Width, Height) / 2f; radius -= strokeWidth / 2f; path.AddCircle(Width / 2.0f, Height / 2.0f, radius, Path.Direction.Ccw); canvas.Save(); canvas.ClipPath(path); result = base.DrawChild(canvas, child, drawingTime); path.Dispose(); canvas.Restore(); path = new Path(); path.AddCircle(Width / 2f, Height / 2f, radius, Path.Direction.Ccw); } else { result = base.DrawChild(canvas, child, drawingTime); path = new Path(); path.AddRect(0f, 0f, Width, Height, Path.Direction.Ccw); } if (strokeWidth > 0.0f) { var paint = new Paint { AntiAlias = true, StrokeWidth = strokeWidth }; paint.SetStyle(Paint.Style.Stroke); paint.Color = borderColor; canvas.DrawPath(path, paint); paint.Dispose(); } path.Dispose(); return(result); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex); } return(base.DrawChild(canvas, child, drawingTime)); }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); // set canvas background color canvas.DrawColor(bgColor); count = count + 0.5; paintCloud.StrokeWidth = ((float)(0.02083 * screenW)); paintSnow.StrokeWidth = ((float)(0.01 * screenW)); int retval = Double.Compare(count, 360.00); if (retval == 0) { if (!isAnimated) { // mark completion of animation isAnimated = true; //resetting counter on completion of a rotation count = 0; } else { //resetting counter on completion of a rotation count = 0; } } PointF P1c1 = cloud.getP1c1(X, Y, screenW, count); PointF P1c2 = cloud.getP1c2(X, Y, screenW, count); PointF P2c1 = cloud.getP2c1(X, Y, screenW, count); PointF P2c2 = cloud.getP2c2(X, Y, screenW, count); float P1Y = ((float)((int)(0.1041667 * screenW) * Math.Sin(Math.ToRadians(80 + (0.111 * count))) + Y)); float P2Y = ((float)(((int)(0.1041667 * screenW) + ((0.00023125 * screenW) * count)) * Math.Sin(Math.ToRadians(120 + (0.222 * count))) + Y)); if (x1 == 0) { x1 = (int)P1c2.X + 10; } if (y1 == 0) { float value = (int)P1c2.Y - ((P1c1.Y + P1Y) / 2); y1 = (int)(P1c2.Y - value / 2); } if (x2 == 0) { x2 = (int)P2c2.X + 10; } if (y2 == 0) { float value = (int)P2c2.Y - ((P2c1.Y + P2Y) / 2); y2 = (int)(P2c2.Y - value / 2); } if (!pointsStored) { // Store path coordinates for snow fall 1 cubicPath11 = new Path(); int height = screenH - y1; cubicPath11.MoveTo(x1, y1); cubicPath11.CubicTo(x1 - screenW * 0.06f, y1 + height * 0.3f, x1 - screenW * 0.12f, y1 + height * 0.7f, x1 - screenW * 0.18f, y1 + height * 1.1f); pathPoints11 = getPoints(cubicPath11); // Store path coordinates for snow fall 2 cubicPath12 = new Path(); int x = x1 - 5; cubicPath12.MoveTo(x, y1); cubicPath12.CubicTo(x + screenW * 0.06f, y1 + height * 0.3f, x + screenW * 0.1f, y1 + height * 0.7f, x - screenW * 0.03f, y1 + height * 1.1f); pathPoints12 = getPoints(cubicPath12); // Store path coordinates for snow fall 3 cubicPath21 = new Path(); cubicPath21.MoveTo(x2, y2); cubicPath21.CubicTo(x2 + screenW * 0.06f, y2 + height * 0.3f, x2 + screenW * 0.12f, y2 + height * 0.7f, x2 + screenW * 0.18f, y2 + height * 1.1f); pathPoints21 = getPoints(cubicPath21); // Store path coordinates for snow fall 4 cubicPath22 = new Path(); int xx = x2 + 5; cubicPath22.MoveTo(xx, y2); cubicPath22.CubicTo(xx - screenW * 0.06f, y2 + height * 0.3f, xx - screenW * 0.1f, y2 + height * 0.6f, xx + screenW * 0.03f, y2 + height * 1.1f); pathPoints22 = getPoints(cubicPath22); pointsStored = true; } if (isAnimated && isStatic) { //Initial static view int x = 55; pathCircle2 = new Path(); pathCircle2.AddCircle(pathPoints12[x].getX(), pathPoints12[x].getY(), screenW * 0.03f, Path.Direction.Cw); pointsCircle12 = getPoints(pathCircle2); //2nd drop path21 = new Path(); path22 = new Path(); path23 = new Path(); int a = (25 + x / 5) >= 100 ? 25 + x / 5 - 100 : 25 + x / 5; int b = (8 + x / 5) >= 100 ? 8 + x / 5 - 100 : 8 + x / 5; int c = (40 + x / 5) >= 100 ? 40 + x / 5 - 100 : 40 + x / 5; path21.MoveTo(pointsCircle12[a].getX(), pointsCircle12[a].getY()); path22.MoveTo(pointsCircle12[b].getX(), pointsCircle12[b].getY()); path23.MoveTo(pointsCircle12[c].getX(), pointsCircle12[c].getY()); a = (75 + x / 5) >= 100 ? 75 + x / 5 - 100 : 75 + x / 5; b = (59 + x / 5) >= 100 ? 59 + x / 5 - 100 : 59 + x / 5; c = (90 + x / 5) >= 100 ? 90 + x / 5 - 100 : 90 + x / 5; path21.LineTo(pointsCircle12[a].getX(), (pointsCircle12[a].getY())); path22.LineTo(pointsCircle12[b].getX(), (pointsCircle12[b].getY())); path23.LineTo(pointsCircle12[c].getX(), (pointsCircle12[c].getY())); canvas.DrawPath(path21, paintSnow); canvas.DrawPath(path22, paintSnow); canvas.DrawPath(path23, paintSnow); // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); int y = 35; pathCircle2 = new Path(); pathCircle2.AddCircle(pathPoints22[y].getX(), pathPoints22[y].getY(), screenW * 0.03f, Path.Direction.Cw); pointsCircle22 = getPoints(pathCircle2); //2nd drop path21 = new Path(); path22 = new Path(); path23 = new Path(); a = (25 + y / 5) >= 100 ? 25 + y / 5 - 100 : 25 + y / 5; b = (8 + y / 5) >= 100 ? 8 + y / 5 - 100 : 8 + y / 5; c = (40 + y / 5) >= 100 ? 40 + y / 5 - 100 : 40 + y / 5; path21.MoveTo(pointsCircle22[a].getX(), pointsCircle22[a].getY()); path22.MoveTo(pointsCircle22[b].getX(), pointsCircle22[b].getY()); path23.MoveTo(pointsCircle22[c].getX(), pointsCircle22[c].getY()); a = (75 + y / 5) >= 100 ? 75 + y / 5 - 100 : 75 + y / 5; b = (59 + y / 5) >= 100 ? 59 + y / 5 - 100 : 59 + y / 5; c = (90 + y / 5) >= 100 ? 90 + y / 5 - 100 : 90 + y / 5; path21.LineTo(pointsCircle22[a].getX(), (pointsCircle22[a].getY())); path22.LineTo(pointsCircle22[b].getX(), (pointsCircle22[b].getY())); path23.LineTo(pointsCircle22[c].getX(), (pointsCircle22[c].getY())); canvas.DrawPath(path21, paintSnow); canvas.DrawPath(path22, paintSnow); canvas.DrawPath(path23, paintSnow); // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); } else // Animating view { if (drop11) { pathCircle1 = new Path(); pathCircle1.AddCircle(pathPoints11[m].getX(), pathPoints11[m].getY(), screenW * 0.03f, Path.Direction.Cw); pointsCircle11 = getPoints(pathCircle1); //1st drop path11 = new Path(); path12 = new Path(); path13 = new Path(); int a = (25 + m / 5) >= 100 ? 25 + m / 5 - 100 : 25 + m / 5; int b = (8 + m / 5) >= 100 ? 8 + m / 5 - 100 : 8 + m / 5; int c = (40 + m / 5) >= 100 ? 40 + m / 5 - 100 : 40 + m / 5; path11.MoveTo(pointsCircle11[a].getX(), pointsCircle11[a].getY()); path12.MoveTo(pointsCircle11[b].getX(), pointsCircle11[b].getY()); path13.MoveTo(pointsCircle11[c].getX(), pointsCircle11[c].getY()); a = (75 + m / 5) >= 100 ? 75 + m / 5 - 100 : 75 + m / 5; b = (59 + m / 5) >= 100 ? 59 + m / 5 - 100 : 59 + m / 5; c = (90 + m / 5) >= 100 ? 90 + m / 5 - 100 : 90 + m / 5; path11.LineTo(pointsCircle11[a].getX(), (pointsCircle11[a].getY())); path12.LineTo(pointsCircle11[b].getX(), (pointsCircle11[b].getY())); path13.LineTo(pointsCircle11[c].getX(), (pointsCircle11[c].getY())); canvas.DrawPath(path11, paintSnow); canvas.DrawPath(path12, paintSnow); canvas.DrawPath(path13, paintSnow); // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); m = m + 1; if (m > 75) { pathCircle2 = new Path(); pathCircle2.AddCircle(pathPoints12[n].getX(), pathPoints12[n].getY(), screenW * 0.03f, Path.Direction.Cw); pointsCircle12 = getPoints(pathCircle2); //2nd drop path21 = new Path(); path22 = new Path(); path23 = new Path(); a = (25 + n / 5) >= 100 ? 25 + n / 5 - 100 : 25 + n / 5; b = (8 + n / 5) >= 100 ? 8 + n / 5 - 100 : 8 + n / 5; c = (40 + n / 5) >= 100 ? 40 + n / 5 - 100 : 40 + n / 5; path21.MoveTo(pointsCircle12[a].getX(), pointsCircle12[a].getY()); path22.MoveTo(pointsCircle12[b].getX(), pointsCircle12[b].getY()); path23.MoveTo(pointsCircle12[c].getX(), pointsCircle12[c].getY()); a = (75 + n / 5) >= 100 ? 75 + n / 5 - 100 : 75 + n / 5; b = (59 + n / 5) >= 100 ? 59 + n / 5 - 100 : 59 + n / 5; c = (90 + n / 5) >= 100 ? 90 + n / 5 - 100 : 90 + n / 5; path21.LineTo(pointsCircle12[a].getX(), (pointsCircle12[a].getY())); path22.LineTo(pointsCircle12[b].getX(), (pointsCircle12[b].getY())); path23.LineTo(pointsCircle12[c].getX(), (pointsCircle12[c].getY())); canvas.DrawPath(path21, paintSnow); canvas.DrawPath(path22, paintSnow); canvas.DrawPath(path23, paintSnow); // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); n = n + 1; } if (m == 100) { m = 0; path11.Reset(); path11.MoveTo(0, 0); path12.Reset(); path12.MoveTo(0, 0); path13.Reset(); path13.MoveTo(0, 0); x1 = 0; y1 = 0; x2 = 0; y2 = 0; drop12 = true; drop11 = false; } } if (drop12) { pathCircle2 = new Path(); pathCircle2.AddCircle(pathPoints12[n].getX(), pathPoints12[n].getY(), screenW * 0.03f, Path.Direction.Cw); pointsCircle12 = getPoints(pathCircle2); //2nd drop path21 = new Path(); path22 = new Path(); path23 = new Path(); int a = (25 + n / 5) >= 100 ? 25 + n / 5 - 100 : 25 + n / 5; int b = (8 + n / 5) >= 100 ? 8 + n / 5 - 100 : 8 + n / 5; int c = (40 + n / 5) >= 100 ? 40 + n / 5 - 100 : 40 + n / 5; path21.MoveTo(pointsCircle12[a].getX(), pointsCircle12[a].getY()); path22.MoveTo(pointsCircle12[b].getX(), pointsCircle12[b].getY()); path23.MoveTo(pointsCircle12[c].getX(), pointsCircle12[c].getY()); a = (75 + n / 5) >= 100 ? 75 + n / 5 - 100 : 75 + n / 5; b = (59 + n / 5) >= 100 ? 59 + n / 5 - 100 : 59 + n / 5; c = (90 + n / 5) >= 100 ? 90 + n / 5 - 100 : 90 + n / 5; path21.LineTo(pointsCircle12[a].getX(), (pointsCircle12[a].getY())); path22.LineTo(pointsCircle12[b].getX(), (pointsCircle12[b].getY())); path23.LineTo(pointsCircle12[c].getX(), (pointsCircle12[c].getY())); canvas.DrawPath(path21, paintSnow); canvas.DrawPath(path22, paintSnow); canvas.DrawPath(path23, paintSnow); // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); n = n + 1; if (n == 100) { m = 0; n = 0; path21.Reset(); path21.MoveTo(0, 0); path22.Reset(); path22.MoveTo(0, 0); path23.Reset(); path23.MoveTo(0, 0); x1 = 0; y1 = 0; drop21 = true; drop11 = false; drop12 = false; } } if (drop21) { pathCircle1 = new Path(); pathCircle1.AddCircle(pathPoints21[m].getX(), pathPoints21[m].getY(), screenW * 0.03f, Path.Direction.Cw); pointsCircle21 = getPoints(pathCircle1); //1st drop path11 = new Path(); path12 = new Path(); path13 = new Path(); int a = (25 + m / 5) >= 100 ? 25 + m / 5 - 100 : 25 + m / 5; int b = (8 + m / 5) >= 100 ? 8 + m / 5 - 100 : 8 + m / 5; int c = (40 + m / 5) >= 100 ? 40 + m / 5 - 100 : 40 + m / 5; path11.MoveTo(pointsCircle21[a].getX(), pointsCircle21[a].getY()); path12.MoveTo(pointsCircle21[b].getX(), pointsCircle21[b].getY()); path13.MoveTo(pointsCircle21[c].getX(), pointsCircle21[c].getY()); a = (75 + m / 5) >= 100 ? 75 + m / 5 - 100 : 75 + m / 5; b = (59 + m / 5) >= 100 ? 59 + m / 5 - 100 : 59 + m / 5; c = (90 + m / 5) >= 100 ? 90 + m / 5 - 100 : 90 + m / 5; path11.LineTo(pointsCircle21[a].getX(), (pointsCircle21[a].getY())); path12.LineTo(pointsCircle21[b].getX(), (pointsCircle21[b].getY())); path13.LineTo(pointsCircle21[c].getX(), (pointsCircle21[c].getY())); canvas.DrawPath(path11, paintSnow); canvas.DrawPath(path12, paintSnow); canvas.DrawPath(path13, paintSnow); // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); m = m + 1; if (m > 75) { pathCircle2 = new Path(); pathCircle2.AddCircle(pathPoints22[n].getX(), pathPoints22[n].getY(), screenW * 0.03f, Path.Direction.Cw); pointsCircle22 = getPoints(pathCircle2); //2nd drop path21 = new Path(); path22 = new Path(); path23 = new Path(); a = (25 + n / 5) >= 100 ? 25 + n / 5 - 100 : 25 + n / 5; b = (8 + n / 5) >= 100 ? 8 + n / 5 - 100 : 8 + n / 5; c = (40 + n / 5) >= 100 ? 40 + n / 5 - 100 : 40 + n / 5; path21.MoveTo(pointsCircle22[a].getX(), pointsCircle22[a].getY()); path22.MoveTo(pointsCircle22[b].getX(), pointsCircle22[b].getY()); path23.MoveTo(pointsCircle22[c].getX(), pointsCircle22[c].getY()); a = (75 + n / 5) >= 100 ? 75 + n / 5 - 100 : 75 + n / 5; b = (59 + n / 5) >= 100 ? 59 + n / 5 - 100 : 59 + n / 5; c = (90 + n / 5) >= 100 ? 90 + n / 5 - 100 : 90 + n / 5; path21.LineTo(pointsCircle22[a].getX(), (pointsCircle22[a].getY())); path22.LineTo(pointsCircle22[b].getX(), (pointsCircle22[b].getY())); path23.LineTo(pointsCircle22[c].getX(), (pointsCircle22[c].getY())); canvas.DrawPath(path21, paintSnow); canvas.DrawPath(path22, paintSnow); canvas.DrawPath(path23, paintSnow); // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); n = n + 1; } if (m == 100) { m = 0; path11.Reset(); path11.MoveTo(0, 0); path12.Reset(); path12.MoveTo(0, 0); path13.Reset(); path13.MoveTo(0, 0); x1 = 0; y1 = 0; drop22 = true; drop21 = false; } } if (drop22) { pathCircle2 = new Path(); pathCircle2.AddCircle(pathPoints22[n].getX(), pathPoints22[n].getY(), screenW * 0.03f, Path.Direction.Cw); pointsCircle22 = getPoints(pathCircle2); //2nd drop path21 = new Path(); path22 = new Path(); path23 = new Path(); int a = (25 + n / 5) >= 100 ? 25 + n / 5 - 100 : 25 + n / 5; int b = (8 + n / 5) >= 100 ? 8 + n / 5 - 100 : 8 + n / 5; int c = (40 + n / 5) >= 100 ? 40 + n / 5 - 100 : 40 + n / 5; path21.MoveTo(pointsCircle22[a].getX(), pointsCircle22[a].getY()); path22.MoveTo(pointsCircle22[b].getX(), pointsCircle22[b].getY()); path23.MoveTo(pointsCircle22[c].getX(), pointsCircle22[c].getY()); a = (75 + n / 5) >= 100 ? 75 + n / 5 - 100 : 75 + n / 5; b = (59 + n / 5) >= 100 ? 59 + n / 5 - 100 : 59 + n / 5; c = (90 + n / 5) >= 100 ? 90 + n / 5 - 100 : 90 + n / 5; path21.LineTo(pointsCircle22[a].getX(), (pointsCircle22[a].getY())); path22.LineTo(pointsCircle22[b].getX(), (pointsCircle22[b].getY())); path23.LineTo(pointsCircle22[c].getX(), (pointsCircle22[c].getY())); canvas.DrawPath(path21, paintSnow); canvas.DrawPath(path22, paintSnow); canvas.DrawPath(path23, paintSnow); // drawing cloud with fill paintCloud.Color = (bgColor); paintCloud.SetStyle(Paint.Style.Fill); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); // drawing cloud with stroke paintCloud.Color = (strokeColor); paintCloud.SetStyle(Paint.Style.Stroke); canvas.DrawPath(cloud.getCloud(X, Y, screenW, count), paintCloud); n = n + 1; if (n == 100) { m = 0; n = 0; path21.Reset(); path21.MoveTo(0, 0); path22.Reset(); path22.MoveTo(0, 0); path23.Reset(); path23.MoveTo(0, 0); x1 = 0; y1 = 0; drop11 = true; drop12 = false; drop21 = false; drop22 = false; } } } if (!isStatic || !isAnimated) { Invalidate(); } }
public void Draw(Canvas canvas) { if (this.Hidden) { return; } canvas.Save(); Path path = new Path(); if (!this.Focused) { this.OutlinePaint.Color = this.OutlineColor; canvas.DrawRect(this.MDrawRect, this.OutlinePaint); } else { Rect viewDrawingRect = new Rect(); mContext.GetDrawingRect(viewDrawingRect); if (this.Circling) { float width = this.MDrawRect.Width(); float height = this.MDrawRect.Height(); path.AddCircle(this.MDrawRect.Left + (width / 2), this.MDrawRect.Top + (height / 2), width / 2, Path.Direction.Cw); this.OutlinePaint.Color = this.OutlineColor; } else { path.AddRect(new RectF(this.MDrawRect), Path.Direction.Cw); this.OutlinePaint.Color = this.OutlineColor; } canvas.ClipPath(path, Region.Op.Difference); canvas.DrawRect(viewDrawingRect, this.Focused ? this.FocusPaint : this.NoFocusPaint); canvas.Restore(); canvas.DrawPath(path, this.OutlinePaint); if (this.MMode == ModifyMode.Grow) { if (this.Circling) { int width = this.ResizeDrawableDiagonal.IntrinsicWidth; int height = this.ResizeDrawableDiagonal.IntrinsicHeight; int d = (int)Math.Round(Math.Cos(/*45deg*/ Math.PI / 4D) * (this.MDrawRect.Width() / 2D)); int x = this.MDrawRect.Left + (this.MDrawRect.Width() / 2) + d - width / 2; int y = this.MDrawRect.Top + (this.MDrawRect.Height() / 2) - d - height / 2; this.ResizeDrawableDiagonal.SetBounds(x, y, x + this.ResizeDrawableDiagonal.IntrinsicWidth, y + this.ResizeDrawableDiagonal.IntrinsicHeight); this.ResizeDrawableDiagonal.Draw(canvas); } else { int left = this.MDrawRect.Left + 1; int right = this.MDrawRect.Right + 1; int top = this.MDrawRect.Top + 4; int bottom = this.MDrawRect.Bottom + 3; int widthWidth = this.ResizeDrawableWidth.IntrinsicWidth / 2; int widthHeight = this.ResizeDrawableWidth.IntrinsicHeight / 2; int heightHeight = this.ResizeDrawableHeight.IntrinsicHeight / 2; int heightWidth = this.ResizeDrawableHeight.IntrinsicWidth / 2; int xMiddle = this.MDrawRect.Left + ((this.MDrawRect.Right - this.MDrawRect.Left) / 2); int yMiddle = this.MDrawRect.Top + ((this.MDrawRect.Bottom - this.MDrawRect.Top) / 2); this.ResizeDrawableWidth.SetBounds(left - widthWidth, yMiddle - widthHeight, left + widthWidth, yMiddle + widthHeight); this.ResizeDrawableWidth.Draw(canvas); this.ResizeDrawableWidth.SetBounds(right - widthWidth, yMiddle - widthHeight, right + widthWidth, yMiddle + widthHeight); this.ResizeDrawableWidth.Draw(canvas); this.ResizeDrawableHeight.SetBounds(xMiddle - heightWidth, top - heightHeight, xMiddle + heightWidth, top + heightHeight); this.ResizeDrawableHeight.Draw(canvas); this.ResizeDrawableHeight.SetBounds(xMiddle - heightWidth, bottom - heightHeight, xMiddle + heightWidth, bottom + heightHeight); this.ResizeDrawableHeight.Draw(canvas); } } } }
private void DrawLetters(Canvas canvas) { Paint letterPaint = new Paint(); letterPaint.StrokeWidth = 1; letterPaint.SetStyle(Paint.Style.Stroke); int rectWidth = (int)(mViewInfo.Width / 11.0); int rectHeight = (int)(mViewInfo.Height / 11.0); letterPaint.TextSize = Math.Min(rectHeight, 80); for (int i = 0; i < 11; i++) { for (int j = 0; j < 11; j++) { letterPaint.SetStyle(Paint.Style.Stroke); //canvas.DrawRect(new Android.Graphics.Rect(i * rectWidth, j * rectHeight, (i + 1) * rectWidth, (j + 1) * rectHeight), paint); KeyValuePair <int, int> index = new KeyValuePair <int, int>(i, j); if (sSignatureLocations.ContainsKey(index)) { Signature sig = sSignatureLocations[index]; char chr = Arrangement.Layout[sig].Character; char chrToMeasure = chr == ' ' ? 'X' : chr; int x = i * rectWidth; int y = j * rectHeight; Android.Graphics.Rect rect = new Android.Graphics.Rect(x, y, x + rectWidth, y + rectHeight); // The actual character is used for horizontal positioning Android.Graphics.Rect characterBounds = new Android.Graphics.Rect(); letterPaint.GetTextBounds(chrToMeasure.ToString(), 0, 1, characterBounds); // A standard character is used for vertical positioning so all the characters line up Android.Graphics.Rect xBounds = new Android.Graphics.Rect(); letterPaint.GetTextBounds("X", 0, 1, xBounds); // Center the character in the rectangle int textLeft = rect.Left + (int)((rect.Width() - characterBounds.Width()) / 2.0); int textBottom = rect.Bottom - (int)((rect.Height() - xBounds.Width()) / 2.0); // Lift the bottom up away from the border if we're on the bottom row //int textBottom = rect.Bottom - (j == 10 ? 10 : 0); TinyTypeLib.Rect boundsInLocation = new TinyTypeLib.Rect(rect.Left, textBottom - xBounds.Height(), rect.Right, textBottom); if (sig == mViewInfo.CurrentSignature) { // Don't draw within the MiddleSquare canvas.ClipRect(new Android.Graphics.Rect(mViewInfo.Left, mViewInfo.Top, mViewInfo.Right, mViewInfo.Bottom)); Path cp = new Path(); cp.AddCircle(mViewInfo.MiddleSquare.Center.X, mViewInfo.MiddleSquare.Center.Y, mViewInfo.MiddleSquare.Width / 2f, Path.Direction.Cw); canvas.ClipPath(cp, Region.Op.Difference); //canvas.ClipRect(Converter.TinyTypeRectToAndroidRect(mViewInfo.MiddleSquare), Region.Op.Difference); int gradientSize = 20; Paint linePaint = new Paint(); // Draw a line to the circle we're about to draw Line lineToLetter = new Line(mViewInfo.MiddleSquare.Center, boundsInLocation.Center); Line perpendicular = lineToLetter.GetPerpendicular(gradientSize); Color color = GetPositionColor((Position)mViewInfo.CurrentSignature.StartHeading.Quadrant); Color transparent = AndroidUtil.GetTransparentColor(color); linePaint.SetShader(new LinearGradient(perpendicular.Start.X, perpendicular.Start.Y, perpendicular.End.X, perpendicular.End.Y, color, transparent, Shader.TileMode.Mirror)); linePaint.SetStyle(Paint.Style.Stroke); linePaint.StrokeWidth = gradientSize * 2; linePaint.StrokeCap = Paint.Cap.Round; canvas.DrawLine(lineToLetter.Start.X, lineToLetter.Start.Y, lineToLetter.End.X, lineToLetter.End.Y, linePaint); } else { //letterPaint.Color = new Color(255, 0, 255); } if (chr != char.MinValue) { // Fill a circle in the background of the circle Paint letterBackgroundPaint = new Paint(); Color letterBackgroundColor = GetPositionColor((Position)sig.StartQuadrant); Color letterBackgroundTransparent = AndroidUtil.GetTransparentColor(letterBackgroundColor); float radius = Math.Max(boundsInLocation.Width, boundsInLocation.Height) / 2f; letterBackgroundPaint.SetShader(new RadialGradient(boundsInLocation.Center.X, boundsInLocation.Center.Y, radius, letterBackgroundColor, letterBackgroundTransparent, Shader.TileMode.Mirror)); letterBackgroundPaint.SetStyle(Paint.Style.FillAndStroke); canvas.DrawCircle(boundsInLocation.Center.X, boundsInLocation.Center.Y, (float)(Math.Max(boundsInLocation.Width, boundsInLocation.Height) / 2.0), letterBackgroundPaint); letterPaint.SetStyle(Paint.Style.FillAndStroke); canvas.DrawText(chr.ToString(), textLeft, textBottom, letterPaint); } } } } letterPaint.SetStyle(Paint.Style.FillAndStroke); letterPaint.Color = GetPositionColor(Position.Middle); letterPaint.TextSize = mViewInfo.MiddleSquare.Height * 0.75f; Drawing.ClearClip(canvas, mViewInfo); // Draw the selected character in the middle of the square if (mViewInfo.CurrentSignature.Gesture == Signature.Gestures.Normal) { char chr = Arrangement.Layout[mViewInfo.CurrentSignature].Character; // Center the character in the rectangle Android.Graphics.Rect bounds = new Android.Graphics.Rect(); letterPaint.GetTextBounds(chr.ToString(), 0, 1, bounds); int textLeft = mViewInfo.MiddleSquare.Left + (int)((mViewInfo.MiddleSquare.Width - bounds.Width()) / 2.0); int textBottom = mViewInfo.MiddleSquare.Bottom - (int)((mViewInfo.MiddleSquare.Height - bounds.Height()) / 2.0); canvas.DrawText(chr.ToString(), textLeft, textBottom, letterPaint); } /* * // Draw the previous character above the center square * if (mPreviousCharacter != char.MinValue) * { * TinyTypeLib.Rect rect = mViewInfo.MiddleSquare.Offset(0, -mViewInfo.MiddleSquare.Height); * * //paint.SetStyle(Paint.Style.Stroke); * //canvas.DrawRect(Converter.TinyTypeRectToAndroidRect(rect), paint); * //paint.SetStyle(Paint.Style.FillAndStroke); * * // Center the character in the rectangle * Android.Graphics.Rect bounds = new Android.Graphics.Rect(); * letterPaint.GetTextBounds(mPreviousCharacter.ToString(), 0, 1, bounds); * * int textLeft = rect.Left + (int)((rect.Width - bounds.Width()) / 2.0); * int textBottom = rect.Bottom - (int)((rect.Height - bounds.Height()) / 2.0); * * canvas.DrawText(mPreviousCharacter.ToString(), textLeft, textBottom, letterPaint); * }*/ }
public override void CreatePath(Path path, Circle shape, int width, int height) { var radius = Math.Min(width, height) / 2f; path.AddCircle(width / 2f, height / 2f, radius, Path.Direction.Ccw); }
/// <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 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(Width / 2, Height / 2, radius, Path.Direction.Ccw); if (strokeWidth > 0.0f) { paint = new Paint(); paint.AntiAlias = true; paint.StrokeWidth = strokeWidth; paint.SetStyle(Paint.Style.Stroke); paint.Color = ((CircleImage)Element).BorderColor.ToAndroid(); canvas.DrawPath(path, paint); paint.Dispose(); } path.Dispose(); return(result); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex); } return(base.DrawChild(canvas, child, drawingTime)); }
protected override bool DrawChild(Canvas canvas, global::Android.Views.View child, long drawingTime) { try { var cornerRadius = ((CircleImage)Element).BorderRadius; var radius = Math.Min(Width, Height) / 2; var strokeWidth = 10; radius -= strokeWidth / 2; //Create path to clip var path = new Path(); var rect = new RectF(0, 0, Width, Height); float rx = Forms.Context.ToPixels(cornerRadius); float ry = Forms.Context.ToPixels(cornerRadius); if (cornerRadius == 0) { path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); } else { path.AddRoundRect(rect, rx, ry, 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(); if (cornerRadius == 0) { path.AddCircle(Width / 2, Height / 2, radius, Path.Direction.Ccw); } else { path.AddRoundRect(rect, rx, ry, Path.Direction.Cw); } 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) { System.Diagnostics.Debug.WriteLine("Unable to create circle image: " + ex); } return(base.DrawChild(canvas, child, drawingTime)); }