drawRect() public method

public drawRect ( android arg0, android arg1 ) : void
arg0 android
arg1 android
return void
Example #1
0
		protected override void onDraw (Canvas canvas)
		{
			canvas.drawColor (unchecked((int)0xFFDDDDDD));

			Paint paint = new Paint ();
			paint.setAntiAlias (true);
			paint.setStyle (Paint.Style.STROKE);
			paint.setStrokeWidth (3);
			paint.setStyle (Paint.Style.FILL);

			RectF r = new RectF ();
			float t, x, y;

			t = GetAnimScalar (25, 500);

			canvas.translate (320, 240);

			for (int i = 0; i < 35; i++) {
				paint.setColor (unchecked((int)0xFFF00FF0 - i * 0x04000000));
				double step = Math.PI / (55 - i);
				double angle = t * step;
				x = (20 + i * 5) * (float)Math.Sin (angle);
				y = (20 + i * 5) * (float)Math.Cos (angle);
				r.set (x, y, x + 10, y + 10);
				canvas.drawRect (r, paint);
			}
		}
Example #2
0
		static void drawCentered (Canvas c, Rect r, Paint p)
		{
			float inset = p.getStrokeWidth () * 0.5f;
			if (inset == 0) {   // catch hairlines
				inset = 0.5f;
			}
			c.drawRect (r.left + inset, r.top + inset,
                	r.right - inset, r.bottom - inset, p);
		}
Example #3
0
		// create a bitmap with a rect, used for the "src" image
		static Bitmap makeSrc (int w, int h)
		{
			Bitmap bm = Bitmap.createBitmap (w, h, Bitmap.Config.ARGB_8888);
			Canvas c = new Canvas (bm);
			Paint p = new Paint (Paint.ANTI_ALIAS_FLAG);

			p.setColor (unchecked((int)0xFF66AAFF));
			c.drawRect (w / 3, h / 3, w * 19 / 20, h * 19 / 20, p);
			return bm;
		}
Example #4
0
		protected override void onDraw (Canvas canvas)
		{

			Console.WriteLine ("DRAW: {0} {1}", canvas.getWidth (), canvas.getHeight ());

			RectF r = new RectF (0, 0, canvas.getWidth (), canvas.getHeight ());
			Paint paint = new Paint ();

			using (Shader shader = make_grad (canvas.getWidth(), canvas.getHeight()))
				paint.setShader (shader);
			canvas.drawRect (r, paint);
		}
Example #5
0
		static void test_alphagradients (Canvas canvas)
		{
			canvas.translate (20, 10);

			RectF r = new RectF (10, 10, 410, 30);
			Paint p = new Paint (), p2 = new Paint ();
			p2.setStyle (Paint.Style.STROKE);

			using (Shader shader = setgrad (r, 0xFF00FF00, 0x0000FF00))
				p.setShader (shader);
			canvas.drawRect (r, p);
			canvas.drawRect (r, p2);

			r.offset (0, r.height () + 4);
			using (Shader shader = setgrad(r, 0xFF00FF00, 0x00000000))
				p.setShader (shader);
			canvas.drawRect (r, p);
			canvas.drawRect (r, p2);

			r.offset (0, r.height () + 4);
			using (Shader shader = setgrad(r, 0xFF00FF00, 0x00FF0000))
				p.setShader (shader);
			canvas.drawRect (r, p);
			canvas.drawRect (r, p2);
		}
Example #6
0
		void drawFit (Canvas canvas, int index, Matrix.ScaleToFit stf)
		{
			canvas.save ();

			setSrcR (index);
			mMatrix.setRectToRect (mSrcR, mDstR, stf);
			canvas.concat (mMatrix);
			drawSrcR (canvas, index);

			canvas.restore ();

			canvas.drawRect (mDstR, mHairPaint);
		}
Example #7
0
		protected override void onDraw (Canvas canvas)
		{
			canvas.drawColor (unchecked((int)0xFFDDDDDD));

			Paint paint = new Paint ();
			paint.setAntiAlias (true);
			paint.setStyle (Paint.Style.STROKE);
			paint.setStrokeWidth (3);
			paint.setStyle (Paint.Style.FILL);

			RectF r = new RectF (10, 10, 110, 110);

			for (int i = 0; i < 256; ++i) {
				canvas.translate (1, 1);
				paint.setColor ((int)(0xFF000000 + i * 0x00010000));
				canvas.drawRect (r, paint);
			}
		}
Example #8
0
		void drawRgn (Canvas canvas, int color, String str, Region.Op op)
		{
			if (str != null) {
				mPaint.setColor (Color.BLACK);
				canvas.drawText (str, 80, 24, mPaint);
			}

			Region rgn = new Region ();
			rgn.set (mRect1);
			rgn.op (mRect2, op);

			mPaint.setColor (color);
			RegionIterator iter = new RegionIterator (rgn);
			Rect r = new Rect ();

			canvas.translate (0, 30);
			mPaint.setColor (color);
			while (iter.next(r)) {
				canvas.drawRect (r, mPaint);
			}
			drawOriginalRects (canvas, 0x80);
		}
Example #9
0
		void doDraw (Canvas canvas, float[] src, float[] dst)
		{
			canvas.save ();
			mMatrix.setPolyToPoly (src, 0, dst, 0, src.Length >> 1);
			canvas.concat (mMatrix);

			mPaint.setColor (Color.GRAY);
			mPaint.setStyle (Paint.Style.STROKE);
			canvas.drawRect (0, 0, 64, 64, mPaint);
			canvas.drawLine (0, 0, 64, 64, mPaint);
			canvas.drawLine (0, 64, 64, 0, mPaint);

			mPaint.setColor (Color.RED);
			mPaint.setStyle (Paint.Style.FILL);
			// how to draw the text center on our square
			// centering in X is easy... use alignment (and X at midpoint)
			float x = 64 / 2;
			// centering in Y, we need to measure ascent/descent first
			float y = 64 / 2 - (mFontMetrics.ascent + mFontMetrics.descent) / 2;
			canvas.drawText (src.Length / 2 + "", x, y, mPaint);

			canvas.restore ();
		}
Example #10
0
		void drawArcs (Canvas canvas, RectF oval, bool useCenter, Paint paint)
		{
			canvas.drawRect (oval, mFramePaint);
			canvas.drawArc (oval, mStart, mSweep, useCenter, paint);
		}
Example #11
0
		protected override void onDraw (Canvas canvas)
		{
			canvas.drawColor (unchecked((int)0xFFDDDDDD));

			test_alphagradients (canvas);

			RectF r = new RectF (0, 0, 100, 100);

			Paint paint = new Paint ();
			paint.setDither (true);

			canvas.save ();
			canvas.translate (20, 100);

			Shader.TileMode[] modes = {
				Shader.TileMode.CLAMP, Shader.TileMode.MIRROR, Shader.TileMode.CLAMP
			};

			foreach (Shader.TileMode tile in modes) {
				canvas.save ();
				foreach (GradData data in Grads) {
					canvas.save ();
					foreach (GradMaker maker in GradMakers) {
						using (Shader shader = maker(r, data, tile))
							paint.setShader (shader);
						canvas.drawRect (r, paint);
						canvas.translate (0, 120);
					}
					canvas.restore ();
					canvas.translate (120, 0);
				}
				canvas.translate (Grads.Length * 120, 0);
			}

			canvas.restore ();
			canvas.translate (0, 370);
		}
Example #12
0
		protected override void onDraw (Canvas canvas)
		{
			canvas.drawColor (Color.WHITE);

			Paint labelP = new Paint (Paint.ANTI_ALIAS_FLAG);
			labelP.setTextAlign (Paint.Align.CENTER);

			Paint paint = new Paint ();
			paint.setFilterBitmap (false);

			canvas.translate (15, 35);

			int x = 0;
			int y = 0;
			for (int i = 0; i < sModes.Length; i++) {
				// draw the border
				paint.setStyle (Paint.Style.STROKE);
				paint.setShader (null);
				canvas.drawRect (x - 0.5f, y - 0.5f,
						x + W + 0.5f, y + H + 0.5f, paint);

				// draw the checker-board pattern
				paint.setStyle (Paint.Style.FILL);
				paint.setShader (mBG);
				canvas.drawRect (x, y, x + W, y + H, paint);

				// draw the src/dst example into our offscreen bitmap
				int sc = canvas.saveLayer (x, y, x + W, y + H, null,
							  Canvas.MATRIX_SAVE_FLAG |
							  Canvas.CLIP_SAVE_FLAG |
							  Canvas.HAS_ALPHA_LAYER_SAVE_FLAG |
							  Canvas.FULL_COLOR_LAYER_SAVE_FLAG |
							  Canvas.CLIP_TO_LAYER_SAVE_FLAG);
				canvas.translate (x, y);
				canvas.drawBitmap (mDstB, 0, 0, paint);
				paint.setXfermode (sModes [i]);
				canvas.drawBitmap (mSrcB, 0, 0, paint);
				paint.setXfermode (null);
				canvas.restoreToCount (sc);

				// draw the label
				canvas.drawText (sLabels [i],
						x + W / 2, y - labelP.getTextSize () / 2, labelP);

				x += W + 10;

				// wrap around when we've drawn enough for one row
				if ((i % ROW_MAX) == ROW_MAX - 1) {
					x = 0;
					y += H + 30;
				}
			}
		}