translate() public method

public translate ( float arg0, float arg1 ) : void
arg0 float
arg1 float
return void
示例#1
0
		protected override void onDraw (Canvas canvas)
		{
			canvas.drawColor (Color.GRAY);

			canvas.save ();
			canvas.translate (80, 5);
			drawOriginalRects (canvas, 0xFF);
			canvas.restore ();

			mPaint.setStyle (Paint.Style.FILL);

			canvas.save ();
			canvas.translate (0, 140);
			drawRgn (canvas, Color.RED, "Union", Region.Op.UNION);
			canvas.restore ();

			canvas.save ();
			canvas.translate (0, 280);
			drawRgn (canvas, Color.BLUE, "Xor", Region.Op.XOR);
			canvas.restore ();

			canvas.save ();
			canvas.translate (160, 140);
			drawRgn (canvas, Color.GREEN, "Difference", Region.Op.DIFFERENCE);
			canvas.restore ();

			canvas.save ();
			canvas.translate (160, 280);
			drawRgn (canvas, Color.WHITE, "Intersect", Region.Op.INTERSECT);
			canvas.restore ();
		}
示例#2
0
		protected override void onDraw (Canvas canvas)
		{
			canvas.drawColor (Color.WHITE);

			canvas.translate (10, 10);

			canvas.save ();
			for (int i = 0; i < N; i++) {
				setSrcR (i);
				drawSrcR (canvas, i);
				canvas.translate (mSrcR.width () + 15, 0);
			}
			canvas.restore ();

			canvas.translate (0, 100);
			for (int j = 0; j < sFits.Length; j++) {
				canvas.save ();
				for (int i = 0; i < N; i++) {
					drawFit (canvas, i, sFits [j]);
					canvas.translate (mDstR.width () + 8, 0);
				}
				canvas.drawText (sFitLabels [j], 0, HEIGHT * 2 / 3, mLabelPaint);
				canvas.restore ();
				canvas.translate (0, 80);
			}
		}
示例#3
0
		protected override void onDraw (Canvas canvas)
		{
			canvas.drawColor (Color.WHITE);

			canvas.save ();
			canvas.translate (10, 10);
			// translate (1 point)
			doDraw (canvas, new float[] { 0, 0 }, new float[] { 5, 5 });
			canvas.restore ();

			canvas.save ();
			canvas.translate (160, 10);
			// rotate/uniform-scale (2 points)
			doDraw (canvas, new float[] { 32, 32, 64, 32 },
                           new float[] { 32, 32, 64, 48 });
			canvas.restore ();

			canvas.save ();
			canvas.translate (10, 110);
			// rotate/skew (3 points)
			doDraw (canvas, new float[] { 0, 0, 64, 0, 0, 64 },
                           new float[] { 0, 0, 96, 0, 24, 64 });
			canvas.restore ();

			canvas.save ();
			canvas.translate (160, 110);
			// perspective (4 points)
			doDraw (canvas, new float[] { 0, 0, 64, 0, 64, 64, 0, 64 },
                           new float[] { 0, 0, 96, 0, 64, 96, 0, 64 });
			canvas.restore ();
		}
示例#4
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);
		}
示例#5
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);
			}
		}
示例#6
0
		protected override void onDraw (Canvas canvas)
		{
			canvas.drawColor (Color.WHITE);

			RectF bounds = new RectF ();
			mPath.computeBounds (bounds, false);
			canvas.translate (10 - bounds.left, 10 - bounds.top);

			makeEffects (mEffects, mPhase);
			mPhase += 1;

			for (int i = 0; i < mEffects.Length; i++) {
				mPaint.setPathEffect (mEffects [i]);
				mPaint.setColor (mColors [i]);
				canvas.drawPath (mPath, mPaint);
				canvas.translate (0, 28);
			}
		}
示例#7
0
		protected override void onDraw (Canvas canvas)
		{
			canvas.drawColor (Color.WHITE);

			mDrawable.setBounds (mRect);

			float r = 16;

			canvas.save ();
			canvas.translate (10, 10);
			mDrawable.setGradientType (GradientDrawable.LINEAR_GRADIENT);
			setCornerRadii (mDrawable, r, r, 0, 0);
			mDrawable.draw (canvas);
			canvas.restore ();

			canvas.save ();
			canvas.translate (10 + mRect.width () + 10, 10);
			mDrawable.setGradientType (GradientDrawable.RADIAL_GRADIENT);
			setCornerRadii (mDrawable, 0, 0, r, r);
			mDrawable.draw (canvas);
			canvas.restore ();

			canvas.translate (0, mRect.height () + 10);

			canvas.save ();
			canvas.translate (10, 10);
			mDrawable.setGradientType (GradientDrawable.SWEEP_GRADIENT);
			setCornerRadii (mDrawable, 0, r, r, 0);
			mDrawable.draw (canvas);
			canvas.restore ();

			canvas.save ();
			canvas.translate (10 + mRect.width () + 10, 10);
			mDrawable.setGradientType (GradientDrawable.LINEAR_GRADIENT);
			setCornerRadii (mDrawable, r, 0, 0, r);
			mDrawable.draw (canvas);
			canvas.restore ();

			canvas.translate (0, mRect.height () + 10);

			canvas.save ();
			canvas.translate (10, 10);
			mDrawable.setGradientType (GradientDrawable.RADIAL_GRADIENT);
			setCornerRadii (mDrawable, r, 0, r, 0);
			mDrawable.draw (canvas);
			canvas.restore ();

			canvas.save ();
			canvas.translate (10 + mRect.width () + 10, 10);
			mDrawable.setGradientType (GradientDrawable.SWEEP_GRADIENT);
			setCornerRadii (mDrawable, 0, r, 0, r);
			mDrawable.draw (canvas);
			canvas.restore ();
		}
示例#8
0
		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 ();
		}
示例#9
0
		protected override void onDraw (Canvas canvas)
		{
			canvas.drawColor (Color.WHITE);

			canvas.translate (10, 10);

			canvas.saveLayerAlpha (0, 0, 200, 200, 0x88, LAYER_FLAGS);

			mPaint.setColor (Color.RED);
			canvas.drawCircle (75, 75, 75, mPaint);
			mPaint.setColor (Color.BLUE);
			canvas.drawCircle (125, 125, 75, mPaint);

			canvas.restore ();
		}
示例#10
0
		protected override void onDraw (Canvas canvas)
		{
			canvas.drawColor (unchecked((int)0xFFCCCCCC));
			canvas.save ();
			canvas.concat (mMatrix);

			canvas.drawVertices (Canvas.VertexMode.TRIANGLE_FAN, 10, mVerts, 0,
                                mTexs, 0, null, 0, null, 0, 0, mPaint);

			canvas.translate (0, 240);
			canvas.drawVertices (Canvas.VertexMode.TRIANGLE_FAN, 10, mVerts, 0,
                                mTexs, 0, null, 0, mIndices, 0, 6, mPaint);

			canvas.restore ();
		}
示例#11
0
		protected override void onDraw (Canvas canvas)
		{
			Paint paint = new Paint (Paint.ANTI_ALIAS_FLAG);

			canvas.drawColor (unchecked((int)0xFFCCCCCC));

			canvas.translate (20, 20);

			paint.setAntiAlias (true);

			showPath (canvas, 0, 0, Path.FillType.WINDING, paint);
			showPath (canvas, 160, 0, Path.FillType.EVEN_ODD, paint);
			showPath (canvas, 0, 160, Path.FillType.INVERSE_WINDING, paint);
			showPath (canvas, 160, 160, Path.FillType.INVERSE_EVEN_ODD, paint);
		}
示例#12
0
		protected override void onDraw (Canvas canvas)
		{
			Paint paint = new Paint ();

			canvas.translate (10, 10);

			canvas.drawColor (Color.WHITE);

			paint.setColor (Color.RED);
			paint.setStrokeWidth (0);
			canvas.drawLines (mPts, paint);

			paint.setColor (Color.BLUE);
			paint.setStrokeWidth (3);
			canvas.drawPoints (mPts, paint);
		}
示例#13
0
文件: Box.cs 项目: hakeemsm/XobotOS
		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);
			}
		}
示例#14
0
		protected override void onDraw (Canvas canvas)
		{
			canvas.drawColor (unchecked((int)0xFFDDDDDD));

			canvas.save ();

			Paint paint = new Paint ();
			paint.setColor (Color.BLUE);

			MaskFilter mf = new BlurMaskFilter (128, BlurMaskFilter.Blur.NORMAL);
			paint.setMaskFilter (mf);
			mf.Dispose ();

			canvas.translate (200, 200);
			canvas.drawCircle (100, 100, 200, paint);

			canvas.restore ();

			paint.Dispose ();
		}
示例#15
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);
		}
示例#16
0
		protected override void onDraw (Canvas canvas)
		{
			canvas.drawColor (Color.GRAY);

			canvas.save ();
			canvas.translate (10, 10);
			drawScene (canvas);
			canvas.restore ();

			canvas.save ();
			canvas.translate (160, 10);
			canvas.clipRect (10, 10, 90, 90);
			canvas.clipRect (30, 30, 70, 70, Region.Op.DIFFERENCE);
			drawScene (canvas);
			canvas.restore ();

			canvas.save ();
			canvas.translate (10, 160);
			mPath.reset ();
			canvas.clipPath (mPath); // makes the clip empty
			mPath.addCircle (50, 50, 50, Path.Direction.CCW);
			canvas.clipPath (mPath, Region.Op.REPLACE);
			drawScene (canvas);
			canvas.restore ();

			canvas.save ();
			canvas.translate (160, 160);
			canvas.clipRect (0, 0, 60, 60);
			canvas.clipRect (40, 40, 100, 100, Region.Op.UNION);
			drawScene (canvas);
			canvas.restore ();

			canvas.save ();
			canvas.translate (10, 310);
			canvas.clipRect (0, 0, 60, 60);
			canvas.clipRect (40, 40, 100, 100, Region.Op.XOR);
			drawScene (canvas);
			canvas.restore ();

			canvas.save ();
			canvas.translate (160, 310);
			canvas.clipRect (0, 0, 60, 60);
			canvas.clipRect (40, 40, 100, 100, Region.Op.REVERSE_DIFFERENCE);
			drawScene (canvas);
			canvas.restore ();
		}
示例#17
0
		protected override void onDraw (Canvas canvas)
		{
			canvas.drawColor (unchecked((int)0xFFCCCCCC));

			canvas.translate (8, 12);
			foreach (int color in mColors) {
				ColorFilter filter;
				if (color == 0) {
					filter = null;
				} else {
					filter = new PorterDuffColorFilter (color,
                                                       mModes [mModeIndex]);
				}
				drawSample (canvas, filter);
				canvas.translate (0, 55);
			}
		}
示例#18
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;
				}
			}
		}
示例#19
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);
		}