protected internal override void onDraw(android.graphics.Canvas canvas) { base.onDraw(canvas); bool changed = mChanged; if (changed) { mChanged = false; } int availableWidth = mRight - mLeft; int availableHeight = mBottom - mTop; int x = availableWidth / 2; int y = availableHeight / 2; android.graphics.drawable.Drawable dial = mDial; int w = dial.getIntrinsicWidth(); int h = dial.getIntrinsicHeight(); bool scaled = false; if (availableWidth < w || availableHeight < h) { scaled = true; float scale = System.Math.Min((float)availableWidth / (float)w, (float)availableHeight / (float)h); canvas.save(); canvas.scale(scale, scale, x, y); } if (changed) { dial.setBounds(x - (w / 2), y - (h / 2), x + (w / 2), y + (h / 2)); } dial.draw(canvas); canvas.save(); canvas.rotate(mHour / 12.0f * 360.0f, x, y); android.graphics.drawable.Drawable hourHand = mHourHand; if (changed) { w = hourHand.getIntrinsicWidth(); h = hourHand.getIntrinsicHeight(); hourHand.setBounds(x - (w / 2), y - (h / 2), x + (w / 2), y + (h / 2)); } hourHand.draw(canvas); canvas.restore(); canvas.save(); canvas.rotate(mMinutes / 60.0f * 360.0f, x, y); android.graphics.drawable.Drawable minuteHand = mMinuteHand; if (changed) { w = minuteHand.getIntrinsicWidth(); h = minuteHand.getIntrinsicHeight(); minuteHand.setBounds(x - (w / 2), y - (h / 2), x + (w / 2), y + (h / 2)); } minuteHand.draw(canvas); canvas.restore(); if (scaled) { canvas.restore(); } }
public override void draw(android.graphics.Canvas canvas, android.graphics.Paint paint) { canvas.save(); canvas.scale(mScaleX, mScaleY); canvas.drawPath(mPath, paint); canvas.restore(); }
/// <summary>Apply translation to the canvas that is necessary to draw the content.</summary> /// <remarks>Apply translation to the canvas that is necessary to draw the content.</remarks> public virtual void translateCanvas(android.graphics.Canvas canvas) { if (this.applicationScale == 1.5f) { float tinyOffset = 2.0f / (3 * 255); canvas.translate(tinyOffset, tinyOffset); } canvas.scale(this.applicationScale, this.applicationScale); }
public virtual void draw(android.graphics.Canvas canvas) { if (mDrawable == null) { return; } canvas.save(android.graphics.Canvas.MATRIX_SAVE_FLAG); canvas.translate(mTranslationX, mTranslationY); canvas.scale(mScaleX, mScaleY); canvas.translate(-0.5f * getWidth(), -0.5f * getHeight()); mDrawable.setAlpha((int)Sharpen.Util.Round(mAlpha * 255f)); mDrawable.draw(canvas); canvas.restore(); }
/// <summary>Draw this object to the canvas using the properties defined in this class. /// </summary> /// <remarks>Draw this object to the canvas using the properties defined in this class. /// </remarks> /// <param name="canvas">canvas to draw into</param> public virtual void draw(android.graphics.Canvas canvas) { float threshold = 1.0f / 256.0f; // contribution less than 1 LSB of RGB byte if (mAlpha <= threshold) { // don't bother if it won't show up return; } canvas.save(android.graphics.Canvas.MATRIX_SAVE_FLAG); canvas.translate(mX, mY); canvas.scale(mScaleX, mScaleY); canvas.translate(-0.5f * getWidth(), -0.5f * getHeight()); mDrawable.setAlpha((int)Sharpen.Util.Round(mAlpha * 255f)); mDrawable.draw(canvas); canvas.restore(); }