コード例 #1
0
ファイル: SVGEllipseParser.cs プロジェクト: jdluzen/xamsvg
		public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint, RectF pRect) {
			float? centerX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_CENTER_X);
			float? centerY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_CENTER_Y);
			float? radiusX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_X);
			float? radiusY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_Y);
			if (centerX != null && centerY != null && radiusX != null && radiusY != null) {
				pRect.Set(centerX.Value - radiusX.Value,
				          centerY.Value - radiusY.Value,
				          centerX.Value + radiusX.Value,
				          centerY.Value + radiusY.Value);

				bool fill = pSVGPaint.setFill(pSVGProperties);
				if (fill) {
					pCanvas.DrawOval(pRect, pSVGPaint.getPaint());
				}

				bool stroke = pSVGPaint.setStroke(pSVGProperties);
				if (stroke) {
					pCanvas.DrawOval(pRect, pSVGPaint.getPaint());
				}

				if(fill || stroke) {
					pSVGPaint.ensureComputedBoundsInclude(centerX.Value - radiusX.Value, centerY.Value - radiusY.Value);
					pSVGPaint.ensureComputedBoundsInclude(centerX.Value + radiusX.Value, centerY.Value + radiusY.Value);
				}
			}
		}
コード例 #2
0
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            int saveCount = canvas.Save();

            for (int i = 1; i < mBallCount - 1; i++)
            {
                mPaint.Alpha = MAX_ALPHA;
                canvas.DrawCircle(mBallRadius * (i * 2 - 1) + mBallSideOffsets, mBallCenterY, mBallRadius, mPaint);

                mOvalRect.Set(mBallRadius * (i * 2 - 2) + mBallSideOffsets, Height - mOvalVerticalRadius * 2, mBallRadius * (i * 2) + mBallSideOffsets, Height);
                mPaint.Alpha = OVAL_ALPHA;
                canvas.DrawOval(mOvalRect, mPaint);
            }

            //draw the first ball
            mPaint.Alpha = MAX_ALPHA;
            canvas.DrawCircle(mBallSideOffsets - mBallRadius - mLeftBallMoveXOffsets, mBallCenterY - mLeftBallMoveYOffsets, mBallRadius, mPaint);

            mOvalRect.Set(mBallSideOffsets - mBallRadius - mBallRadius * mLeftOvalShapeRate - mLeftBallMoveXOffsets, Height - mOvalVerticalRadius - mOvalVerticalRadius * mLeftOvalShapeRate, mBallSideOffsets - mBallRadius + mBallRadius * mLeftOvalShapeRate - mLeftBallMoveXOffsets, Height - mOvalVerticalRadius + mOvalVerticalRadius * mLeftOvalShapeRate);
            mPaint.Alpha = OVAL_ALPHA;
            canvas.DrawOval(mOvalRect, mPaint);

            //draw the last ball
            mPaint.Alpha = MAX_ALPHA;
            canvas.DrawCircle(mBallRadius * (mBallCount * 2 - 3) + mBallSideOffsets + mRightBallMoveXOffsets, mBallCenterY - mRightBallMoveYOffsets, mBallRadius, mPaint);

            mOvalRect.Set(mBallRadius * (mBallCount * 2 - 3) - mBallRadius * mRightOvalShapeRate + mBallSideOffsets + mRightBallMoveXOffsets, Height - mOvalVerticalRadius - mOvalVerticalRadius * mRightOvalShapeRate, mBallRadius * (mBallCount * 2 - 3) + mBallRadius * mRightOvalShapeRate + mBallSideOffsets + mRightBallMoveXOffsets, Height - mOvalVerticalRadius + mOvalVerticalRadius * mRightOvalShapeRate);
            mPaint.Alpha = OVAL_ALPHA;
            canvas.DrawOval(mOvalRect, mPaint);

            canvas.RestoreToCount(saveCount);
        }
コード例 #3
0
ファイル: ShapeView.cs プロジェクト: rfcclub/dot42
 protected void DrawShape(Canvas canvas)
 {
   Paint paint = new Paint();
   paint.Color = Color;
   switch (Shape)
   {
     case ShapeEnum.RectangleShape:
       canvas.DrawRect(0, 0, ShapeWidth, ShapeHeight, paint);
       break;
     case ShapeEnum.OvalShape:
       canvas.DrawOval(new RectF(0, 0, ShapeWidth, ShapeHeight), paint);
       break;
     case ShapeEnum.TriangleShape:
         Path path = new Path();
         path.MoveTo(ShapeWidth / 2, 0);
         path.LineTo(ShapeWidth, ShapeHeight);
         path.LineTo(0,ShapeHeight);
         path.Close();
       canvas.DrawPath(path, paint);
       break;
     default:
       canvas.DrawCircle(ShapeWidth / 2, ShapeHeight / 2, ShapeWidth / 2, paint); 
       break;
   }
 }
コード例 #4
0
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            int   saveCount = canvas.Save();
            RectF arcBounds = mTempBounds;

            arcBounds.Set(bounds);

            mPaint.Color = new Color(mColor);

            mPaint.SetStyle(Paint.Style.Stroke);
            canvas.DrawPath(CreateLeftEyeCircle(arcBounds, mLeftEyeCircleOffsetY), mPaint);
            canvas.DrawPath(CreateRightEyeCircle(arcBounds, mRightEyeCircleOffsetY), mPaint);

            mPaint.SetStyle(Paint.Style.Fill);
            //create left eye ball
            canvas.DrawOval(CreateLeftEyeBall(arcBounds, mLeftEyeBallOffsetY), mPaint);
            //create right eye ball
            canvas.DrawOval(CreateRightEyeBall(arcBounds, mRightEyeBallOffsetY), mPaint);

            canvas.RestoreToCount(saveCount);
        }
コード例 #5
0
        public override void Draw(Canvas canvas)
        {
            base.Draw (canvas);

            var element = Element as CircleView;
            var paint = new Paint ();

            paint.SetStyle (Paint.Style.FillAndStroke);
            paint.SetPathEffect(new DashPathEffect
                (new float[] {element.StrokeDash, element.StrokeDash}, 0.0f));

            using (var rect = new RectF (Left, Top, Right, Bottom)) {
                canvas.DrawOval (new RectF (Left, Top, Right, Bottom), paint);
            }
        }
コード例 #6
0
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            int saveCount = canvas.Save();

            mTempBounds.Set(bounds);
            mTempBounds.Inset(mStrokeInset, mStrokeInset);
            mCurrentBounds.Set(mTempBounds);

            float outerCircleRadius = Math.Min(mTempBounds.Height(), mTempBounds.Width()) / 2.0f;
            float interCircleRadius = outerCircleRadius / 2.0f;
            float centerRingWidth   = interCircleRadius - mStrokeWidth / 2;

            mPaint.SetStyle(Paint.Style.Stroke);
            mPaint.Color       = new Color(mColor);
            mPaint.StrokeWidth = mStrokeWidth;
            canvas.DrawCircle(mTempBounds.CenterX(), mTempBounds.CenterY(), outerCircleRadius, mPaint);
            mPaint.SetStyle(Paint.Style.Fill);
            canvas.DrawCircle(mTempBounds.CenterX(), mTempBounds.CenterY(), interCircleRadius * mScale, mPaint);

            if (mRotation != 0)
            {
                mPaint.Color = new Color(mArcColor);
                mPaint.SetStyle(Paint.Style.Stroke);
                //strokeWidth / 2.0f + mStrokeWidth / 2.0f is the center of the inter circle width
                mTempBounds.Inset(centerRingWidth / 2.0f + mStrokeWidth / 2.0f, centerRingWidth / 2.0f + mStrokeWidth / 2.0f);
                mPaint.StrokeWidth = centerRingWidth;
                canvas.DrawArc(mTempBounds, RING_START_ANGLE, mRotation, false, mPaint);
            }

            mPaint.Color = new Color(mColor);
            mPaint.SetStyle(Paint.Style.Fill);
            for (int i = 0; i < NUM_POINTS; i++)
            {
                canvas.Rotate(i * DANCE_INTERVAL_ANGLE, POINT_X[i], POINT_Y[i]);
                RectF rectF = new RectF(POINT_X[i] - mDanceBallRadius - mShapeChangeWidth / 2.0f, POINT_Y[i] - mDanceBallRadius - mShapeChangeHeight / 2.0f, POINT_X[i] + mDanceBallRadius + mShapeChangeWidth / 2.0f, POINT_Y[i] + mDanceBallRadius + mShapeChangeHeight / 2.0f);
                canvas.DrawOval(rectF, mPaint);
                canvas.Rotate(-i * DANCE_INTERVAL_ANGLE, POINT_X[i], POINT_Y[i]);
            }

            canvas.RestoreToCount(saveCount);
        }
コード例 #7
0
        public override void Draw(Android.Graphics.Canvas canvas)
        {
            base.Draw(canvas);

            var rect = new RectF(0, 0, 300, 300);

            switch (TheShape)
            {
            case Shape.Circle:
                canvas.DrawOval(rect, new Paint()
                {
                    Color = Color.Aqua
                });
                break;

            case Shape.Square:
                canvas.DrawRect(rect, new Paint()
                {
                    Color = Color.Red
                });
                break;

            case Shape.Triangle:
                var path = new Path();
                path.MoveTo(rect.CenterX(), 0);
                path.LineTo(0, rect.Height());
                path.LineTo(rect.Width(), rect.Height());
                path.Close();

                var paint = new Paint()
                {
                    Color = Color.Magenta
                };
                paint.SetStyle(Paint.Style.Fill);
                canvas.DrawPath(path, paint);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #8
0
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            var rect = new RectF(0, 0, 300, 300);

            switch (Shape)
            {
            case Shape.Circle:
                canvas.DrawOval(rect, new Paint()
                {
                    Color = Color.CornflowerBlue
                });
                break;

            case Shape.Square:
                canvas.DrawRect(rect, new Paint()
                {
                    Color = Color.Crimson
                });
                break;

            case Shape.Triangle:

                var path = new Path();
                path.MoveTo(rect.CenterX(), rect.Top);
                path.LineTo(rect.Left, rect.Bottom);
                path.LineTo(rect.Right, rect.Bottom);
                path.Close();
                var paint = new Paint()
                {
                    Color = Color.Crimson
                };
                paint.Color = Color.Gold;
                paint.SetStyle(Paint.Style.Fill);
                canvas.DrawPath(path, paint);
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
コード例 #9
0
        protected override void OnDraw(Canvas canvas)
        {
            var r = CenterX - _paint.StrokeWidth * 0.5f;

            canvas.Translate(CenterX, CenterX);

            canvas.DrawOval(new RectF(-r, -r, r, r), _paint);
            canvas.DrawCircle(0, 0, CenterRadius, _centerPaint);

            if (_trackingCenter)
            {
                var c = _centerPaint.Color;
                _centerPaint.SetStyle(Paint.Style.Stroke);

                _centerPaint.Alpha = _highlightCenter ? 255 : 128;

                canvas.DrawCircle(0, 0,
                                  CenterRadius + _centerPaint.StrokeWidth,
                                  _centerPaint);

                _centerPaint.SetStyle(Paint.Style.Fill);
                _centerPaint.Color = c;
            }
        }
コード例 #10
0
			void DrawOval (Canvas canvas, float x, float y, float major, float minor,
				float orientation, Paint paint)
			{
				canvas.Save (SaveFlags.Matrix);
				canvas.Rotate ((float) (orientation * 180 / Math.PI), x, y);
				mReusableOvalRect.Left = x - minor / 2;
				mReusableOvalRect.Right = x + minor / 2;
				mReusableOvalRect.Top = y - major / 2;
				mReusableOvalRect.Bottom = y + major / 2;
				canvas.DrawOval (mReusableOvalRect, paint);
				canvas.Restore ();
			}
コード例 #11
0
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);
            float r = strokeWidth - myPaint.StrokeWidth * 0.5f;
            canvas.Translate((float)wowZapp.LaffOutOut.Singleton.ScreenXWidth / 1.5f, (float)wowZapp.LaffOutOut.Singleton.ScreenYHeight / 2.5f);
            canvas.DrawOval(new RectF(-r, -r, r, r), myPaint);
            canvas.DrawRect(new RectF(0f, 0f, 0f, 0f), myCenterPaint);

            if (trackingCentre)
            {
                Color c = myCenterPaint.Color;
                myCenterPaint.SetStyle(Paint.Style.Stroke);
                myCenterPaint.Alpha = (highlightCentre == true ? 0xff : 0x80);
                Rect rect = new Rect(0, 0, 0, 0);
                myCenterPaint.SetStyle(Paint.Style.Fill);
                myCenterPaint.Color = c;
                canvas.DrawRect(rect, myCenterPaint);
            }
        }
コード例 #12
0
 public override void Draw(Canvas canvas)
 {
     if (_mOval)
     {
         if (_mBorderWidth > 0)
         {
             canvas.DrawOval(_mDrawableRect, _mBitmapPaint);
             canvas.DrawOval(_mBorderRect, _mBorderPaint);
         }
         else
         {
             canvas.DrawOval(_mDrawableRect, _mBitmapPaint);
         }
     }
     else
     {
         if (_mBorderWidth > 0)
         {
             canvas.DrawRoundRect(_mDrawableRect, Math.Max(_mCornerRadius, 0),
                 Math.Max(_mCornerRadius, 0), _mBitmapPaint);
             canvas.DrawRoundRect(_mBorderRect, _mCornerRadius, _mCornerRadius, _mBorderPaint);
         }
         else
         {
             canvas.DrawRoundRect(_mDrawableRect, _mCornerRadius, _mCornerRadius, _mBitmapPaint);
         }
     }
 }
コード例 #13
0
 public override void Draw(Canvas canvas)
 {
     canvas.DrawOval(oval, paint);
 }
コード例 #14
0
 public override void Draw(Canvas canvas)
 {
     canvas.DrawOval(mRectF, mPaint);
 }
コード例 #15
0
ファイル: Sensors.cs プロジェクト: rudini/monodroid-samples
            protected override void OnDraw(Canvas canvas)
            {
                lock (this) {
                    if (mBitmap != null) {
                        Path path = mPath;
                        int outer = new Color (192, 192, 192);
                        int inner = new Color (255, 112, 16);

                        if (mLastX >= mMaxX) {
                            mLastX = 0;
                            Canvas cavas = mCanvas;
                            float yoffset = mYOffset;
                            float maxx = mMaxX;
                            float oneG = SensorManager.StandardGravity * mScale[0];
                            paint.Color = new Color (170, 170, 170);
                            cavas.DrawColor (Color.Black);
                            cavas.DrawLine (0, yoffset, maxx, yoffset, paint);
                            cavas.DrawLine (0, yoffset + oneG, maxx, yoffset + oneG, paint);
                            cavas.DrawLine (0, yoffset - oneG, maxx, yoffset - oneG, paint);
                        }
                        canvas.DrawBitmap (mBitmap, 0, 0, null);

                        float[] values = mOrientationValues;
                        if (mWidth < mHeight) {
                            float w0 = mWidth * 0.333333f;
                            float w = w0 - 32;
                            float x = w0 * 0.5f;
                            for (int i = 0; i < 3; i++) {
                                canvas.Save (SaveFlags.Matrix);
                                canvas.Translate (x, w * 0.5f + 4.0f);
                                canvas.Save (SaveFlags.Matrix);
                                paint.Color = outer;
                                canvas.Scale (w, w);
                                canvas.DrawOval (mRect, paint);
                                canvas.Restore ();
                                canvas.Scale (w - 5, w - 5);
                                paint.Color = inner;
                                canvas.Rotate (-values[i]);
                                canvas.DrawPath (path, paint);
                                canvas.Restore ();
                                x += w0;
                            }
                        } else {
                            float h0 = mHeight * 0.333333f;
                            float h = h0 - 32;
                            float y = h0 * 0.5f;
                            for (int i = 0; i < 3; i++) {
                                canvas.Save (SaveFlags.Matrix);
                                canvas.Translate (mWidth - (h * 0.5f + 4.0f), y);
                                canvas.Save (SaveFlags.Matrix);
                                paint.Color = outer;
                                canvas.Scale (h, h);
                                canvas.DrawOval (mRect, paint);
                                canvas.Restore ();
                                canvas.Scale (h - 5, h - 5);
                                paint.Color = inner;
                                canvas.Rotate (-values[i]);
                                canvas.DrawPath (path, paint);
                                canvas.Restore ();
                                y += h0;
                            }
                        }

                    }
                }
            }
コード例 #16
0
        //@SuppressLint("DrawAllocation")
        //@Override
        protected override void OnDraw(Canvas canvas)
        {

            int centerX = Width / 2;
            int centerY = Height / 2;

            // drawing color wheel

            canvas.DrawBitmap(colorWheelBitmap, centerX - colorWheelRadius, centerY - colorWheelRadius, null);

            // drawing color view

            colorViewPaint.Color = Color.HSVToColor(colorHSV);
            canvas.DrawPath(colorViewPath, colorViewPaint);

            // drawing value slider

            float[] hsv = new float[] { colorHSV[0], colorHSV[1], 1f };

            SweepGradient sweepGradient = new SweepGradient(centerX, centerY, new int[] { Color.Black, Color.HSVToColor(hsv), Color.White }, null);
            sweepGradient.SetLocalMatrix(gradientRotationMatrix);
            valueSliderPaint.SetShader(sweepGradient);

            canvas.DrawPath(valueSliderPath, valueSliderPaint);

            // drawing color wheel pointer

            float hueAngle = (float)Math.ToRadians(colorHSV[0]);
            int colorPointX = (int)(-Math.Cos(hueAngle) * colorHSV[1] * colorWheelRadius) + centerX;
            int colorPointY = (int)(-Math.Sin(hueAngle) * colorHSV[1] * colorWheelRadius) + centerY;

            float pointerRadius = 0.075f * colorWheelRadius;
            int pointerX = (int)(colorPointX - pointerRadius / 2);
            int pointerY = (int)(colorPointY - pointerRadius / 2);

            colorPointerCoords.Set(pointerX, pointerY, pointerX + pointerRadius, pointerY + pointerRadius);
            canvas.DrawOval(colorPointerCoords, colorPointerPaint);

            // drawing value pointer

            valuePointerPaint.Color = Color.HSVToColor(new float[] { 0f, 0f, 1f - colorHSV[2] });

            double valueAngle = (colorHSV[2] - 0.5f) * Math.Pi;
            float valueAngleX = (float)Math.Cos(valueAngle);
            float valueAngleY = (float)Math.Sin(valueAngle);

            canvas.DrawLine(valueAngleX * innerWheelRadius + centerX, valueAngleY * innerWheelRadius + centerY, valueAngleX * outerWheelRadius + centerX,
                    valueAngleY * outerWheelRadius + centerY, valuePointerPaint);

            // drawing pointer arrow

            if (arrowPointerSize > 0)
            {
                drawPointerArrow(canvas);
            }

        }
コード例 #17
0
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw (canvas);
            float r = 100 - myPaint.StrokeWidth * 0.5f;
            float outr = 120;
            canvas.Translate (144f, 140f);
            canvas.DrawOval (new RectF (-r, -r, r, r), myPaint);
            canvas.DrawOval (new RectF (-outr, -outr, outr, outr), myOuterPaint);
            canvas.DrawRect (new RectF (-50f, 140f, 100f, 160f), myCenterPaint);

            if (trackingCentre) {
                Color c = myCenterPaint.Color;
                myCenterPaint.SetStyle (Paint.Style.Stroke);
                myCenterPaint.Alpha = (highlightCentre == true ? 0xff : 0x80);
                Rect rect = new Rect (-50, 140, 100, 160);
                myCenterPaint.SetStyle (Paint.Style.Fill);
                myCenterPaint.Color = c;
                canvas.DrawRect (rect, myCenterPaint);
            }
        }
コード例 #18
0
		/// <summary>
		/// Gets the oval bitmap.
		/// </summary>
		/// <returns>The oval bitmap.</returns>
		/// <param name="bitmap">Bitmap.</param>
		private Bitmap GetOvalBitmap(Bitmap bitmap) 
		{
			Bitmap output = null;

			if(bitmap != null)
			{
				output = Bitmap.CreateBitmap(bitmap.Width, bitmap.Height, Bitmap.Config.Argb8888);
				Canvas canvas = new Canvas(output);

				Paint paint = new Paint();
				Rect rect = new Rect(0, 0, bitmap.Width, bitmap.Height);
				RectF rectF = new RectF(rect);

				paint.AntiAlias = true;
				canvas.DrawARGB(0, 0, 0, 0);
				paint.Color = Color.Red;
				canvas.DrawOval(rectF, paint);

				paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.SrcIn));
				canvas.DrawBitmap(bitmap, rect, rect, paint);
			}

			return output;
		}