Exemplo n.º 1
0
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            var linearGradient = new Styles.Color.LinearGradient(
                new IRgb[] { ColorSwatches.FlatMint, ColorSwatches.FlatBlue },
                45
                );

            var radialGradient = new Styles.Color.RadialGradient(
                new IRgb[] { ColorSwatches.FlatMint, ColorSwatches.FlatBlue },
                .5f, .5f
                );

            var ellipticalGradient = new EllipticalGradient(
                new IRgb[] { ColorSwatches.FlatMint, ColorSwatches.FlatBlue, ColorSwatches.DeepPurple },
                .5f, .5f
                );

            ellipticalGradient.SetScale(1f, 2f);
            ellipticalGradient.Rotation = 45;

            var bounds = canvas.ClipBounds;
            var shader = ellipticalGradient.Draw(new RectF(bounds.Left, bounds.Top, bounds.Right, bounds.Bottom));

            var paint = new Paint();

            paint.SetShader(shader);

            canvas.DrawPaint(paint);
        }
Exemplo n.º 2
0
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);
            float middle = canvas.Width * (float)_position;

            canvas.DrawPaint(_negativePaint);

            canvas.DrawRect(0, 0, middle, canvas.Height, _positivePaint);
        }
Exemplo n.º 3
0
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);
            
            var paint = new Paint
            {
                Color = new Color(45, 45, 45)
            };

            canvas.DrawPaint(paint);

            DrawStopwatch(canvas);
            DrawSecondsHand(canvas);
            DrawMinutesHand(canvas);
        }
        protected override void DispatchDraw(Android.Graphics.Canvas canvas)
        {
            // Draw interior shadow
            canvas.Save();
            canvas.ClipRect(0, 0, Width, Height);
            canvas.DrawPaint(shadow);
            canvas.Restore();

            base.DispatchDraw(canvas);

            // Draw custom list separator
            canvas.Save();
            canvas.ClipRect(0, Height - 2, Width, Height);
            canvas.DrawColor(Android.Graphics.Color.Rgb(LightTone, LightTone, LightTone));
            canvas.Restore();
        }
Exemplo n.º 5
0
        void OnElementSizeChanged(object sender, EventArgs e)
        {
            var elem = sender as View;
            if (elem == null)
                return;
            using (var imageBitmap = Bitmap.CreateBitmap((int)elem.Width, (int)elem.Height, Bitmap.Config.Argb8888))
            using (var canvas = new Canvas(imageBitmap))
            using (var gradient = new RadialGradient(0, 250, 1000, currentElement.StartColor.ToAndroid(), currentElement.EndColor.ToAndroid(), Shader.TileMode.Clamp))
            using (var paint = new Paint() { Dither = true })
            {
                paint.SetShader(gradient);
                canvas.DrawPaint(paint);

                Container.Background = new BitmapDrawable(imageBitmap);
            }
        }
Exemplo n.º 6
0
        protected override void OnDraw(Canvas c)
        {
            Init(c);

            _p.SetStyle (Paint.Style.Fill);
            _p.Color = Color.White;
            c.DrawPaint(_p);

            float scale = (float) _cat.Width / (float) _cat.Height;
            int new_height = c.Height * 3 / 4;
            int new_width = (int) (new_height * scale);
            c.DrawBitmap(
                _cat,
                new Rect(0, 0, _cat.Width, _cat.Height),
                new Rect(0, c.Width / 4, new_width, new_height + c.Width / 4),
                //new Rect(0, (int) (c.Height-new_height), (int) new_width, (int) c.Height),
                _p
            );

            foreach (var purr in _purrs) {
                purr.Render(c, _p);
            }
        }
        public AndroidRepresentationProvider()
        {
            RegisterHandler <AG.Bitmap> (GraphicsExtensions.RemoteRepresentation);
            RegisterHandler <AG.Color> (agColor => new Representation(
                                            new Color(
                                                agColor.R / 255f,
                                                agColor.G / 255f,
                                                agColor.B / 255f,
                                                agColor.A / 255f),
                                            true));
            RegisterHandler <AG.Paint> (agPaint => {
                var cBitmap = AG.Bitmap.CreateBitmap(50, 50, AG.Bitmap.Config.Argb8888);
                try {
                    using (var canvas = new AG.Canvas(cBitmap)) {
                        canvas.DrawPaint(agPaint);
                        return(cBitmap.RemoteRepresentation());
                    }
                } finally {
                    cBitmap.Recycle();
                }
            });

            RegisterHandler <AL.Location> (LocationExtensions.RemoteRepresentation);
        }
Exemplo n.º 8
0
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            base.OnDraw(canvas);

            // Fill the background
            canvas.DrawPaint(mBackgroundPaint);

            // Test Text
            canvas.Save();
            var  textWidth  = mTextPaint.MeasureText("Hello");
            Rect textBounds = new Rect();

            mTextPaint.GetTextBounds("Hello", 0, 1, textBounds);
            canvas.DrawText("Hello", canvas.Width / 2 - textWidth / 2, canvas.Height / 2 - textBounds.Height() / 2, mTextPaint);

            textWidth  = mTextPaint.MeasureText("World");
            textBounds = new Rect();
            mTextPaint.GetTextBounds("World", 0, 1, textBounds);
            mTextPaint.Color = Color.Green;
            canvas.DrawText("World", (canvas.Width / 2 - textWidth / 2) + 100, (canvas.Height / 2 - textBounds.Height() / 2) + 100, mTextPaint);


            canvas.Restore();

            foreach (Box box in mBoxes)
            {
                float left   = Math.Min(box.Origin.X, box.Current.X);
                float right  = Math.Max(box.Origin.X, box.Current.X);
                float top    = Math.Min(box.Origin.Y, box.Current.Y);
                float bottom = Math.Max(box.Origin.Y, box.Current.Y);
                canvas.Save();
                canvas.Rotate(box.Rotation, (box.Origin.X + box.Current.X) / 2, (box.Origin.Y + box.Current.Y) / 2);
                canvas.DrawRect(left, top, right, bottom, mBoxPaint);
                canvas.Restore();
            }
        }
Exemplo n.º 9
0
		protected override void OnDraw (Canvas canvas)
		{
			base.OnDraw (canvas);

			// Clear screen to pink.
			paint.Color = new Color (255, 204, 204);
			canvas.DrawPaint (paint);

			// Overall transforms to shift (0, 0) to center and scale.
			canvas.Translate (this.Width / 2, this.Height / 2);
			float scale = Math.Min (this.Width, this.Height) / 2.0f / 100;
			canvas.Scale (scale, scale);

			// Attributes for tick marks.
			paint.Color = Color.Black;
			paint.StrokeCap = Paint.Cap.Round;
			paint.SetStyle (Paint.Style.Stroke);

			// Set line dash to draw tick marks for every minute.
			paint.StrokeWidth = 3;
			paint.SetPathEffect (minuteTickDashEffect);
			canvas.DrawPath (tickMarks, paint);

			// Set line dash to draw tick marks for every hour.
			paint.StrokeWidth = 6;
			paint.SetPathEffect (hourTickDashEffect);
			canvas.DrawPath (tickMarks, paint);

			// Set attributes common to all clock hands.
			Color strokeColor = Color.Black;
			Color fillColor = Color.Blue;
			paint.StrokeWidth = 2;
			paint.SetPathEffect (null);

			// Draw hour hand.
			canvas.Save ();
			canvas.Rotate (this.hourAngle);
			paint.Color = fillColor;
			paint.SetStyle (Paint.Style.Fill);
			canvas.DrawPath (hourHand, paint);
			paint.Color = strokeColor;
			paint.SetStyle (Paint.Style.Stroke);
			canvas.DrawPath (hourHand, paint);
			canvas.Restore ();

			// Draw minute hand.
			canvas.Save ();
			canvas.Rotate (this.minuteAngle);
			paint.Color = fillColor;
			paint.SetStyle (Paint.Style.Fill);
			canvas.DrawPath (minuteHand, paint);
			paint.Color = strokeColor;
			paint.SetStyle (Paint.Style.Stroke);
			canvas.DrawPath (minuteHand, paint);
			canvas.Restore ();

			// Draw second hand.
			canvas.Save ();
			canvas.Rotate (this.secondAngle);
			paint.Color = strokeColor;
			paint.SetStyle (Paint.Style.Stroke);
			canvas.DrawPath (secondHand, paint);
			canvas.Restore ();
		}