protected override void DispatchDraw(Android.Graphics.Canvas canvas) { // Draw interior shadow canvas.Save(); canvas.ClipRect(0, 0, Width, Height); canvas.DrawPaint(shadow); canvas.Restore(); base.DispatchDraw(canvas); // Draw custom list separator canvas.Save(); canvas.ClipRect(0, Height - 2, Width, Height); canvas.DrawColor(Android.Graphics.Color.Rgb(LightTone, LightTone, LightTone)); canvas.Restore(); }
protected override void DispatchDraw(Canvas canvas) { if (ShouldClip) { canvas.ClipRect (new Rect (Left, Top, Right, Bottom + Offset)); } base.DispatchDraw (canvas); }
/// <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(Android.Graphics.Canvas canvas) { if (Element == null) { base.Draw(canvas); return; } // Draws the background and default android setup. Children will also be redrawn here // base.Draw(canvas); // Set up clipping if (Element.IsClippedToBounds) { canvas.ClipRect(new Android.Graphics.Rect(0, 0, Width, Height)); } // Perform custom drawing from the NGraphics subsystems var ncanvas = new CanvasCanvas(canvas); var rect = new NGraphics.Rect(0, 0, Width, Height); // Fill background ncanvas.FillRectangle(rect, new NGraphics.Color(Element.BackgroundColor.R, Element.BackgroundColor.G, Element.BackgroundColor.B, Element.BackgroundColor.A)); // Custom drawing Element.Draw(ncanvas, rect); // Redraw children - since we might have a composite control containing both children // and custom drawing code, we want children to be drawn last. The reason for this double- // drawing is that the base.Draw(canvas) call will handle background which is needed before // doing NGraphics drawing - but unfortunately it also draws children - which then will // be drawn below NGraphics drawings. base.Draw(canvas); }
/// <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(Android.Graphics.Canvas canvas) { if (Element == null) { base.Draw(canvas); return; } // Should we clip? if (Element.IsClippedToBounds) { canvas.ClipRect(new Android.Graphics.Rect(0, 0, Width, Height), Region.Op.Replace); } // Draws the background and default android setup. Children will also be redrawn here base.Draw(canvas); // Perform custom drawing from the NGraphics subsystems var ncanvas = new CanvasCanvas(canvas); var rect = new NGraphics.Rect(0, 0, Width, Height); Element.Draw(ncanvas, rect); // Redraw children - since we might have a composite control containing both children // and custom drawing code, we want children to be drawn last. The reason for this double- // drawing is that the base.Draw(canvas) call will handle background which is needed before // doing NGraphics drawing - but unfortunately it also draws children - which then will // be drawn below NGraphics drawings. for (var i = 0; i < ChildCount; i++) { GetChildAt(i).Draw(canvas); } }
private void ShowPath(Canvas canvas, int x, int y, Path.FillType ft, Paint paint) { canvas.Save(); canvas.Translate(x, y); canvas.ClipRect(0, 0, 120, 120); canvas.DrawColor(Color.White); mPath.SetFillType(ft); canvas.DrawPath(mPath, paint); canvas.Restore(); }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); if (_path == null) { return; } //Drawing paths on the canvas does not respect the canvas' ClipBounds canvas.ClipRect(ClippedFrame?.LogicalToPhysicalPixels().ToRectF()); DrawFill(canvas); DrawStroke(canvas); }
/// <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(Android.Graphics.Canvas canvas) { // Should we clip? if (Element != null && Element.IsClippedToBounds) { canvas.ClipRect(new Android.Graphics.Rect(0, 0, Width, Height), Region.Op.Replace); } // Perform custom drawing var ncanvas = new CanvasCanvas(canvas); Element.Draw(ncanvas, new NGraphics.Rect(0, 0, Width, Height)); // Draw elements/children etc. base.Draw(canvas); }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); if (_path == null) { return; } //Drawing paths on the canvas does not respect the canvas' ClipBounds if (ClippedFrame is { } clippedFrame) { clippedFrame = clippedFrame.LogicalToPhysicalPixels(); if (FrameRoundingAdjustment is { } fra) { clippedFrame.Width += fra.Width; clippedFrame.Height += fra.Height; } canvas.ClipRect(clippedFrame.ToRectF()); } DrawFill(canvas); DrawStroke(canvas); }
public void drawSelector(View content, Canvas canvas, float openPercent) { if (!mSelectorEnabled) return; if (mSelectorDrawable != null && mSelectedView != null) { string tag = (string)mSelectedView.GetTag(Resource.Id.selected_view); if (tag.Equals(TAG + "SelectedView")) { canvas.Save(); int left, right, offset; offset = (int)(mSelectorDrawable.Width * openPercent); if (mMode == SlidingMenuMode.LEFT) { right = content.Left; left = right - offset; canvas.ClipRect(left, 0, right, Height); canvas.DrawBitmap(mSelectorDrawable, left, getSelectorTop(), null); } else if (mMode == SlidingMenuMode.RIGHT) { left = content.Right; right = left + offset; canvas.ClipRect(left, 0, right, Height); canvas.DrawBitmap(mSelectorDrawable, right - mSelectorDrawable.Width, getSelectorTop(), null); } canvas.Restore(); } } }
private void DrawStickyHeader(Canvas canvas) { var headerHeight = GetHeaderHeight(); var top = m_HeaderBottomPosition - headerHeight; //clip the headers drawing area m_ClippingRect.Left = PaddingLeft; m_ClippingRect.Right = Width - PaddingRight; m_ClippingRect.Bottom = top + headerHeight; m_ClippingRect.Top = m_ClippingToPadding ? PaddingTop : 0; canvas.Save(); canvas.ClipRect(m_ClippingRect); canvas.Translate(PaddingLeft, top); m_Header.Draw(canvas); canvas.Restore(); }
protected override void DispatchDraw(Canvas canvas) { if ((int)Build.VERSION.SdkInt < 8) //froyo { ScrollChanged(FirstVisiblePosition); } PositionSelectorRect(); if (!AreHeadersSticky || m_Header == null) { base.DispatchDraw(canvas); return; } if (!IsDrawingListUnderStickyHeader) { m_ClippingRect.Set(0, m_HeaderBottomPosition, Width, Height); canvas.Save(); canvas.ClipRect(m_ClippingRect); } base.DispatchDraw(canvas); if (!IsDrawingListUnderStickyHeader) { canvas.Restore(); } DrawStickyHeader(canvas); }
protected override void DispatchDraw (Canvas canvas) { base.DispatchDraw (canvas); if (mPinnedSection != null) { // prepare variables int pLeft = ListPaddingLeft; int pTop = ListPaddingTop; View view = mPinnedSection.view; // draw child canvas.Save(); int clipHeight = view.Height + (mShadowDrawable == null ? 0 : Math.Min(mShadowHeight, mSectionsDistanceY)); canvas.ClipRect(pLeft, pTop, pLeft + view.Width, pTop + clipHeight); canvas.Translate(pLeft, pTop + mTranslateY); DrawChild(canvas, mPinnedSection.view, DrawingTime); if (mShadowDrawable != null && mSectionsDistanceY > 0) { mShadowDrawable.SetBounds(mPinnedSection.view.Left, mPinnedSection.view.Bottom, mPinnedSection.view.Right, mPinnedSection.view.Bottom + mShadowHeight); mShadowDrawable.Draw(canvas); } canvas.Restore(); } }
public override void Draw(Canvas canvas) { _bounds = Bounds; canvas.ClipRect(_bounds); if (_reversed) { canvas.Translate(_bounds.Width(), 0); canvas.Scale(-1, 1); } DrawStrokes(canvas); }
protected override void DispatchDraw(Canvas canvas) { if (!_isFoldPrepared || FloatNearlyEqual(_foldFactor, 0)) { base.DispatchDraw(canvas); return; } if (!_shouldDraw) return; for (var x = 0; x < _numberOfFolds; x++) { var src = _foldRectArray[x]; canvas.Save(); canvas.Concat(_matrix[x]); if (Build.VERSION.SdkInt == BuildVersionCodes.JellyBeanMr2) { _dstRect.Set(0, 0, src.Width(), src.Height()); canvas.DrawBitmap(_fullBitmap, src, _dstRect, null); } else { canvas.ClipRect(0, 0, src.Right - src.Left, src.Bottom - src.Top); if (_isHorizontal) canvas.Translate(-src.Left, 0); else canvas.Translate(0, -src.Top); base.DispatchDraw(canvas); if (_isHorizontal) canvas.Translate(src.Left, 0); else canvas.Translate(0, src.Top); } canvas.DrawRect(0, 0, _foldDrawWidth, _foldDrawHeight, x % 2 == 0 ? _solidShadow : _gradientShadow); canvas.Restore(); } }
public override void Draw(Canvas canvas) { canvas.ClipRect(canvas.ClipBounds); base.Draw(canvas); }
public void DrawSelector(View content, Canvas canvas, float openPercent) { if (!SelectorEnabled) return; if (_selectorDrawable != null && SelectedView != null) { var tag = (string)SelectedView.GetTag(Resource.Id.selected_view); if (tag.Equals(Tag + "SelectedView")) { canvas.Save(); int left, right; var offset = (int)(SelectorBitmap.Width * openPercent); if (Mode == MenuMode.Left) { right = content.Left; left = right - offset; canvas.ClipRect(left, 0, right, Height); canvas.DrawBitmap(SelectorBitmap, left, SelectorTop, null); } else if (Mode == MenuMode.Right) { left = content.Right; right = left + offset; canvas.ClipRect(left, 0, right, Height); canvas.DrawBitmap(SelectorBitmap, right - SelectorBitmap.Width, SelectorTop, null); } canvas.Restore(); } } }
public void DrawOn(Canvas canvas, List<IFilter> filters) { foreach (var filter in filters) { filter.TransformImg (this); } canvas.Save (); canvas.ClipRect (BorderRect.Left, BorderRect.Top, BorderRect.Right, BorderRect.Bottom); Matrix.SetScale (Rect.Width / (float)Bitmap.Width, Rect.Height / (float)Bitmap.Height); Matrix.PostTranslate (Rect.Left, Rect.Top); Matrix.PostRotate (Rect.RotationDg, Rect.Left, Rect.Top); canvas.DrawBitmap (Bitmap, Matrix, Paint); canvas.Restore (); foreach (var filter in filters) { filter.DrawOn (canvas); } }
private void DrawPict(Canvas canvas, int x, int y, int w, int h, float sx, float sy) { canvas.Save (); canvas.Translate (x, y); canvas.ClipRect (0, 0, w, h); canvas.Scale (0.5f, 0.5f); canvas.Scale (sx, sy, w, h); canvas.DrawPicture (mPicture); canvas.Restore (); }
public void draw(Canvas canvas) { int width = mBounds.Width (); int height = mBounds.Height(); int cx = width / 2; int cy = height / 2; Boolean drawTriggerWhileFinishing = false; int restoreCount = canvas.Save(); canvas.ClipRect(mBounds); if (mRunning || (mFinishTime > 0)) { long now = AnimationUtils.CurrentAnimationTimeMillis(); long elapsed = (now - mStartTime) % ANIMATION_DURATION_MS; long iterations = (now - mStartTime) / ANIMATION_DURATION_MS; float rawProgress = (elapsed / (ANIMATION_DURATION_MS / 100f)); // If we're not running anymore, that means we're running through // the finish animation. if (!mRunning) { // If the finish animation is done, don't draw anything, and // don't repost. if ((now - mFinishTime) >= FINISH_ANIMATION_DURATION_MS) { mFinishTime = 0; return; } // Otherwise, use a 0 opacity alpha layer to clear the animation // from the inside out. This layer will prevent the circles from // drawing within its bounds. long finishElapsed = (now - mFinishTime) % FINISH_ANIMATION_DURATION_MS; float finishProgress = (finishElapsed / (FINISH_ANIMATION_DURATION_MS / 100f)); float pct = (finishProgress / 100f); // Radius of the circle is half of the screen. float clearRadius = width / 2;//* INTERPOLATOR.getInterpolation(pct); mClipRect.Set(cx - clearRadius, 0, cx + clearRadius, height); canvas.SaveLayerAlpha(mClipRect, 0, 0); // Only draw the trigger if there is a space in the center of // this refreshing view that needs to be filled in by the // trigger. If the progress view is just still animating, let it // continue animating. drawTriggerWhileFinishing = true; } // First fill in with the last color that would have finished drawing. if (iterations == 0) { canvas.DrawColor (Android.Graphics.Color.Blue); } else { if (rawProgress >= 0 && rawProgress < 25) { canvas.DrawColor(Android.Graphics.Color.AliceBlue); } else if (rawProgress >= 25 && rawProgress < 50) { canvas.DrawColor (Android.Graphics.Color.Blue); } else if (rawProgress >= 50 && rawProgress < 75) { canvas.DrawColor (Android.Graphics.Color.BlueViolet); } else { canvas.DrawColor (Android.Graphics.Color.CadetBlue); } } // Then draw up to 4 overlapping concentric circles of varying radii, based on how far // along we are in the cycle. // progress 0-50 draw mColor2 // progress 25-75 draw mColor3 // progress 50-100 draw mColor4 // progress 75 (wrap to 25) draw mColor1 if ((rawProgress >= 0 && rawProgress <= 25)) { float pct = (((rawProgress + 25) * 2) / 100f); drawCircle(canvas, cx, cy, mColor1, pct); } if (rawProgress >= 0 && rawProgress <= 50) { float pct = ((rawProgress * 2) / 100f); drawCircle(canvas, cx, cy, mColor2, pct); } if (rawProgress >= 25 && rawProgress <= 75) { float pct = (((rawProgress - 25) * 2) / 100f); drawCircle(canvas, cx, cy, mColor3, pct); } if (rawProgress >= 50 && rawProgress <= 100) { float pct = (((rawProgress - 50) * 2) / 100f); drawCircle(canvas, cx, cy, mColor4, pct); } if ((rawProgress >= 75 && rawProgress <= 100)) { float pct = (((rawProgress - 75) * 2) / 100f); drawCircle(canvas, cx, cy, mColor1, pct); } if (mTriggerPercentage > 0 && drawTriggerWhileFinishing) { // There is some portion of trigger to draw. Restore the canvas, // then draw the trigger. Otherwise, the trigger does not appear // until after the bar has finished animating and appears to // just jump in at a larger width than expected. canvas.RestoreToCount(restoreCount); restoreCount = canvas.Save(); canvas.ClipRect(mBounds); drawTrigger(canvas, cx, cy); } // Keep running until we finish out the last cycle. ViewCompat.PostInvalidateOnAnimation(mParent); } else { // Otherwise if we're in the middle of a trigger, draw that. if (mTriggerPercentage > 0 && mTriggerPercentage <= 1.0) { drawTrigger(canvas, cx, cy); } } canvas.RestoreToCount(restoreCount); }
// This drawing routine assume all columns have equal heights, don't use while animating wave void DrawBubbles(Canvas canvas, int columnWidth) { const int Range = 200; const int MinRadius = 2; const int FadeStartLevel = 50; var level = u1 [0]; var maxRadius = ((columnWidth >> 1) * 8) / 10; var maxHeight = height >> 2; canvas.Save (); canvas.ClipRect (0, height - level, width, height); int alphaDecrement = (int)((1 - Math.Min (FadeStartLevel, MaxWavyLevel - level) / ((float)FadeStartLevel)) * 255); for (int i = 0; i < Count; i++) { var dispersion = ((float)Math.Sin (i * ((4 * Math.PI) / Count)) + 1) * Range; var ratio = ((level + dispersion) % Range) / Range; var alpha = (int)Math.Round (255 - ratio * 200); alpha = Math.Max (0, alpha - alphaDecrement); bubblePaint.Color = BlendColor (BackgroundColor, BubbleColor, alpha); var cx = i * columnWidth + columnWidth / 2; var cy = height - level + (1 - ratio) * (maxHeight - maxRadius); var radius = MinRadius + ratio * (maxRadius - MinRadius); canvas.DrawCircle (cx, cy, radius, bubblePaint); } canvas.Restore (); }
protected override void OnDraw (Canvas canvas) { _rect = canvas.ClipBounds; _rect.Inset(0, -_height / 2); canvas.ClipRect(_rect, Region.Op.Replace); if (!_isUserTouching) { if (DeltaY > -_maxCurvature && DeltaY < _maxCurvature) Curvature = DeltaY * 2; TopCellPath(OneFifthWidth, FourFifthWith, Curvature); BottomCellPath(FourFifthWith, OneFifthWidth, _height + Curvature); } else { float Curvatured = _isSelectedView?-Curvature:Curvature; TopCellPath(_fingerX,_fingerX,Curvatured); Curvatured = _isSelectedView?_height-Curvatured:_height; BottomCellPath(_fingerX,_fingerX,Curvatured); } canvas.DrawPath(_path, _paint); }
protected override bool DrawChild(Canvas canvas, View child, long drawingTime) { var lp = (LayoutParams) child.LayoutParameters; var save = canvas.Save(SaveFlags.Clip); var drawScrim = false; if (_canSlide && !lp.Slideable && _slideableView != null) { if (!OverlayContent) { canvas.GetClipBounds(_tmpRect); if (_isSlidingUp) _tmpRect.Bottom = Math.Min(_tmpRect.Bottom, _slideableView.Top); else _tmpRect.Top = Math.Max(_tmpRect.Top, _slideableView.Bottom); canvas.ClipRect(_tmpRect); } if (_slideOffset < 1) drawScrim = true; } var result = base.DrawChild(canvas, child, drawingTime); canvas.RestoreToCount(save); if (drawScrim) { var baseAlpha = (_coveredFadeColor.ToArgb() & 0xff000000) >> 24; var imag = (int) (baseAlpha * (1 - _slideOffset)); var color = imag << 24 | (_coveredFadeColor.ToArgb() & 0xffffff); _coveredFadePaint.Color = new Color(color); canvas.DrawRect(_tmpRect, _coveredFadePaint); } return result; }
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 (); }