Example #1
0
		public override void draw(android.graphics.Canvas canvas, android.graphics.Paint 
			paint)
		{
			canvas.drawOval(rect(), paint);
		}
Example #2
0
		public override void draw(android.graphics.Canvas canvas)
		{
			if (!ensureValidRect())
			{
				// nothing to draw
				return;
			}
			// remember the alpha values, in case we temporarily overwrite them
			// when we modulate them with mAlpha
			int prevFillAlpha = mFillPaint.getAlpha();
			int prevStrokeAlpha = mStrokePaint != null ? mStrokePaint.getAlpha() : 0;
			// compute the modulate alpha values
			int currFillAlpha = modulateAlpha(prevFillAlpha);
			int currStrokeAlpha = modulateAlpha(prevStrokeAlpha);
			bool haveStroke = currStrokeAlpha > 0 && mStrokePaint.getStrokeWidth() > 0;
			bool haveFill = currFillAlpha > 0;
			android.graphics.drawable.GradientDrawable.GradientState st = mGradientState;
			bool useLayer = haveStroke && haveFill && st.mShape != LINE && currStrokeAlpha < 
				255 && (mAlpha < 255 || mColorFilter != null);
			if (useLayer)
			{
				if (mLayerPaint == null)
				{
					mLayerPaint = new android.graphics.Paint();
				}
				mLayerPaint.setDither(mDither);
				mLayerPaint.setAlpha(mAlpha);
				mLayerPaint.setColorFilter(mColorFilter);
				float rad = mStrokePaint.getStrokeWidth();
				canvas.saveLayer(mRect.left - rad, mRect.top - rad, mRect.right + rad, mRect.bottom
					 + rad, mLayerPaint, android.graphics.Canvas.HAS_ALPHA_LAYER_SAVE_FLAG);
				// don't perform the filter in our individual paints
				// since the layer will do it for us
				mFillPaint.setColorFilter(null);
				mStrokePaint.setColorFilter(null);
			}
			else
			{
				mFillPaint.setAlpha(currFillAlpha);
				mFillPaint.setDither(mDither);
				mFillPaint.setColorFilter(mColorFilter);
				if (haveStroke)
				{
					mStrokePaint.setAlpha(currStrokeAlpha);
					mStrokePaint.setDither(mDither);
					mStrokePaint.setColorFilter(mColorFilter);
				}
			}
			switch (st.mShape)
			{
				case RECTANGLE:
				{
					if (st.mRadiusArray != null)
					{
						if (mPathIsDirty || mRectIsDirty)
						{
							mPath.reset();
							mPath.addRoundRect(mRect, st.mRadiusArray, android.graphics.Path.Direction.CW);
							mPathIsDirty = mRectIsDirty = false;
						}
						canvas.drawPath(mPath, mFillPaint);
						if (haveStroke)
						{
							canvas.drawPath(mPath, mStrokePaint);
						}
					}
					else
					{
						if (st.mRadius > 0.0f)
						{
							// since the caller is only giving us 1 value, we will force
							// it to be square if the rect is too small in one dimension
							// to show it. If we did nothing, Skia would clamp the rad
							// independently along each axis, giving us a thin ellipse
							// if the rect were very wide but not very tall
							float rad = st.mRadius;
							float r = System.Math.Min(mRect.width(), mRect.height()) * 0.5f;
							if (rad > r)
							{
								rad = r;
							}
							canvas.drawRoundRect(mRect, rad, rad, mFillPaint);
							if (haveStroke)
							{
								canvas.drawRoundRect(mRect, rad, rad, mStrokePaint);
							}
						}
						else
						{
							canvas.drawRect(mRect, mFillPaint);
							if (haveStroke)
							{
								canvas.drawRect(mRect, mStrokePaint);
							}
						}
					}
					break;
				}

				case OVAL:
				{
					canvas.drawOval(mRect, mFillPaint);
					if (haveStroke)
					{
						canvas.drawOval(mRect, mStrokePaint);
					}
					break;
				}

				case LINE:
				{
					android.graphics.RectF r = mRect;
					float y = r.centerY();
					canvas.drawLine(r.left, y, r.right, y, mStrokePaint);
					break;
				}

				case RING:
				{
					android.graphics.Path path = buildRing(st);
					canvas.drawPath(path, mFillPaint);
					if (haveStroke)
					{
						canvas.drawPath(path, mStrokePaint);
					}
					break;
				}
			}
			if (useLayer)
			{
				canvas.restore();
			}
			else
			{
				mFillPaint.setAlpha(prevFillAlpha);
				if (haveStroke)
				{
					mStrokePaint.setAlpha(prevStrokeAlpha);
				}
			}
		}