示例#1
0
        /// <Docs>The Canvas to which the View is rendered.</Docs>
        /// <summary>
        /// Draw the specified canvas.
        /// </summary>
        /// <param name="canvas">Canvas.</param>
        public override void Draw(Android.Graphics.Canvas canvas)
        {
            if (Element == null)
            {
                base.Draw(canvas);
                return;
            }

            // Draws the background and default android setup. Children will also be redrawn here
            // base.Draw(canvas);

            // Set up clipping
            if (Element.IsClippedToBounds)
            {
                canvas.ClipRect(new Android.Graphics.Rect(0, 0, Width, Height));
            }

            // Perform custom drawing from the NGraphics subsystems
            var ncanvas = new CanvasCanvas(canvas);

            var rect = new NGraphics.Rect(0, 0, Width, Height);

            // Fill background
            ncanvas.FillRectangle(rect, new NGraphics.Color(Element.BackgroundColor.R, Element.BackgroundColor.G, Element.BackgroundColor.B, Element.BackgroundColor.A));

            // Custom drawing
            Element.Draw(ncanvas, rect);

            // Redraw children - since we might have a composite control containing both children
            // and custom drawing code, we want children to be drawn last. The reason for this double-
            // drawing is that the base.Draw(canvas) call will handle background which is needed before
            // doing NGraphics drawing - but unfortunately it also draws children - which then will
            // be drawn below NGraphics drawings.
            base.Draw(canvas);
        }
示例#2
0
        protected override void DispatchDraw(Android.Graphics.Canvas canvas)
        {
            base.DispatchDraw(canvas);

            if (Header == null && Divider != null)
            {
                //Drawable.setbounds does not work on pre honeycomb, so you have to do a little work around
                //for anything pre-HC.
                if ((int)Build.VERSION.SdkInt < 11)
                {
                    canvas.ClipRect(0, 0, Width, DividerHeight);
                }
                Divider.Draw(canvas);
            }
        }
示例#3
0
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            int   saveCount = canvas.Save();
            RectF arcBounds = mTempBounds;

            arcBounds.Set(bounds);

            mPaint.Color = new Color(mColor);

            //calculate fish clip bounds
            //clip the width of the fish need to increase mPathDottedLineSize * 1.2f
            RectF  fishRectF = new RectF(mFishHeadPos[0] - mFishWidth / 2.0f - mPathDottedLineSize * 1.2f, mFishHeadPos[1] - mFishHeight / 2.0f, mFishHeadPos[0] + mFishWidth / 2.0f + mPathDottedLineSize * 1.2f, mFishHeadPos[1] + mFishHeight / 2.0f);
            Matrix matrix    = new Matrix();

            matrix.PostRotate(mFishRotateDegrees, fishRectF.CenterX(), fishRectF.CenterY());
            matrix.MapRect(fishRectF);

            //draw river
            int riverSaveCount = canvas.Save();

            mPaint.SetStyle(Paint.Style.Stroke);
            canvas.ClipRect(fishRectF, Region.Op.Difference);
            canvas.DrawPath(CreateRiverPath(arcBounds), mPaint);
            canvas.RestoreToCount(riverSaveCount);

            //draw fish
            int fishSaveCount = canvas.Save();

            mPaint.SetStyle(Paint.Style.Fill);
            canvas.Rotate(mFishRotateDegrees, mFishHeadPos[0], mFishHeadPos[1]);
            canvas.ClipPath(CreateFishEyePath(mFishHeadPos[0], mFishHeadPos[1] - mFishHeight * 0.06f), Region.Op.Difference);
            canvas.DrawPath(CreateFishPath(mFishHeadPos[0], mFishHeadPos[1]), mPaint);
            canvas.RestoreToCount(fishSaveCount);

            canvas.RestoreToCount(saveCount);
        }