Пример #1
1
		void CreateBitmapData (string str, out byte[] bitmapData, out int width, out int height)
		{
			Paint paint = new Paint ();
			paint.TextSize = 128;
			paint.TextAlign = Paint.Align.Left;
			paint.SetTypeface (Typeface.Default);
			width = height = 256;
			float textWidth = paint.MeasureText (str);

			using (Bitmap bitmap = Bitmap.CreateBitmap (width, height, Bitmap.Config.Argb8888)) {
				Canvas canvas = new Canvas (bitmap);
				paint.Color = str != " " ? Color.White : Color.LightGray;
				canvas.DrawRect (new Rect (0, 0, width, height), paint);
				paint.Color = Color.Black;
				canvas.DrawText (str, (256 - textWidth) / 2f, (256 - paint.Descent () - paint.Ascent ()) / 2f, paint);
				bitmapData = new byte [width * height * 4];
				Java.Nio.ByteBuffer buffer = Java.Nio.ByteBuffer.Allocate (bitmapData.Length);
				bitmap.CopyPixelsToBuffer (buffer);
				buffer.Rewind ();
				buffer.Get (bitmapData, 0, bitmapData.Length);
			}
		}
		public override void Draw (Canvas canvas)
		{
			var bounds = Bounds;

			if (alpha != 255) {
				paint.Alpha = 255;
				if (SecondBitmap != null) {
					if (shader1 == null)
						shader1 = new BitmapShader (FirstBitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
					shader1.SetLocalMatrix (matrix);
					paint.SetShader (shader1);
					canvas.DrawRect (bounds, paint);
				} else
					canvas.DrawColor (defaultColor.ToAndroidColor());
			}
			if (alpha != 0) {
				paint.Alpha = alpha;
				if (FirstBitmap != null) {
					if (shader2 == null)
						shader2 = new BitmapShader (SecondBitmap, Shader.TileMode.Clamp, Shader.TileMode.Clamp);
					shader2.SetLocalMatrix (matrix);
					paint.SetShader (shader2);
					canvas.DrawRect (bounds, paint);
				} else
					canvas.DrawColor (defaultColor.ToAndroidColor());
			}
		}
Пример #3
0
        public override void Draw(Android.Graphics.Canvas canvas)
        {
            base.Draw(canvas);

            GLabBoxView boxView = (GLabBoxView)Element;

            Rect rect = new Rect();

            GetDrawingRect(rect);

            Rect inside = rect;

            inside.Inset(
                (int)boxView.BorderThickness,
                (int)boxView.BorderThickness
                );

            Paint p = new Paint();

            p.Color = boxView.Color.ToAndroid();

            canvas.DrawRect(inside, p);

            p.Color       = boxView.BorderColor.ToAndroid();
            p.StrokeWidth = (float)boxView.BorderThickness;
            p.SetStyle(Paint.Style.FillAndStroke);

            canvas.DrawRect(rect, p);
        }
 protected override void OnDraw(Canvas canvas)
 {
     base.OnDraw(canvas);
     canvas.DrawRect(0,0,Width,Height, new Paint
     {
         Color=Color.Black
     });
     canvas.DrawRect(1, 1, Width - 1, Height - 1, new Paint
     {
         Color = BackgroundColor
     });
     
 }
Пример #5
0
		public static void parse(SVGProperties pSVGProperties, Canvas pCanvas, SVGPaint pSVGPaint, RectF pRect) {
			float x = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_X, 0f);
			float y = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_Y, 0f);
			float width = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_WIDTH, 0f);
			float height = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_HEIGHT, 0f);

			pRect.Set(x, y, x + width, y + height);

			float? rX = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_X);
			float? rY = pSVGProperties.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS_Y);

			bool rXSpecified = rX != null && rX >= 0;
			bool rYSpecified = rY != null && rY >= 0;

			bool rounded = rXSpecified || rYSpecified;
			float rx;
			float ry;
			if(rXSpecified && rYSpecified) {
				rx = Math.Min(rX.Value, width * 0.5f);
				ry = Math.Min(rY.Value, height * 0.5f);
			} else if(rXSpecified) {
				ry = rx = Math.Min(rX.Value, width * 0.5f);
			} else if(rYSpecified) {
				rx = ry = Math.Min(rY.Value, height * 0.5f);
			} else {
				rx = 0;
				ry = 0;
			}

			bool fill = pSVGPaint.setFill(pSVGProperties);
			if (fill) {
				if(rounded) {
					pCanvas.DrawRoundRect(pRect, rx, ry, pSVGPaint.getPaint());
				} else {
					pCanvas.DrawRect(pRect, pSVGPaint.getPaint());
				}
			}

			bool stroke = pSVGPaint.setStroke(pSVGProperties);
			if (stroke) {
				if(rounded) {
					pCanvas.DrawRoundRect(pRect, rx, ry, pSVGPaint.getPaint());
				} else {
					pCanvas.DrawRect(pRect, pSVGPaint.getPaint());
				}
			}

			if(fill || stroke) {
				pSVGPaint.ensureComputedBoundsInclude(x, y, width, height);
			}
		}
Пример #6
0
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            int height          = Height;
            int childCount      = ChildCount;
            int dividerHeightPx = (int)(Math.Min(Math.Max(0f, _dividerHeight), 1f) * height);

            SlidingTabLayout.ITabColorizer tabColorizer = _customTabColorizer != null ? _customTabColorizer: _defaultTabColorizer;

            // Thick colored underline below the current selection
            if (childCount > 0)
            {
                View selectedTitle = GetChildAt(_selectedPosition);
                int  left          = selectedTitle.Left;
                int  right         = selectedTitle.Right;
                int  color         = tabColorizer.GetIndicatorColor(_selectedPosition);

                if (_selectionOffset > 0f && _selectedPosition < (ChildCount - 1))
                {
                    int nextColor = tabColorizer.GetIndicatorColor(_selectedPosition + 1);
                    if (color != nextColor)
                    {
                        color = BlendColors(nextColor, color, _selectionOffset);
                    }

                    // Draw the selection partway between the tabs
                    View nextTitle = GetChildAt(_selectedPosition + 1);
                    left  = (int)(_selectionOffset * nextTitle.Left + (1.0f - _selectionOffset) * left);
                    right = (int)(_selectionOffset * nextTitle.Right + (1.0f - _selectionOffset) * right);
                }

                _selectedIndicatorPaint.Color = Color.LightSkyBlue;


                canvas.DrawRect(left, height - _selectedIndicatorThickness, right,
                                height, _selectedIndicatorPaint);
            }

            // Thin underline along the entire bottom edge
            canvas.DrawRect(0, height - _bottomBorderThickness, Width, height, _bottomBorderPaint);

            // Vertical separators between the titles
            int separatorTop = (height - dividerHeightPx) / 2;

            for (int i = 0; i < childCount - 1; i++)
            {
                View child = GetChildAt(i);
                _dividerPaint.Color = Color.Gray;
                canvas.DrawLine(child.Right, separatorTop, child.Right,
                                separatorTop + dividerHeightPx, _dividerPaint);
            }
        }
Пример #7
0
        protected override void OnDraw(Canvas canvas)
        {
            RectF rect = _colorRect;

            // ReSharper disable once ConditionIsAlwaysTrueOrFalse
            if (BorderWidthPx > 0)
            {
                _borderPaint.Color = new Color((int) _borderColor);
                canvas.DrawRect(_drawingRect, _borderPaint);
            }

            _colorPaint.Color = new Color((int) _color);
            canvas.DrawRect(rect, _colorPaint);
        }
			public override Android.Graphics.Drawables.Drawable GetBackgroundForPage (int row, int column)
			{
				Point pt = new Point (column, row);
				Drawable drawable;
				if (!mBackgrounds.ContainsKey(pt))
				{
					// the key wasn't found in Dictionary
					var bm = Bitmap.CreateBitmap(200, 200, Bitmap.Config.Argb8888);
					var c = new Canvas(bm);
					var p = new Paint();
					// Clear previous image.
					c.DrawRect(0, 0, 200, 200, p);
					p.AntiAlias = true;
					p.SetTypeface(Typeface.Default);
					p.TextSize = 64;
					p.Color = Color.LightGray;
					p.TextAlign = Paint.Align.Center;
					c.DrawText(column + "-" + row, 100, 100, p);
					drawable = new BitmapDrawable(owner.Resources, bm);
					mBackgrounds.Add(pt, drawable);
				}
				else
				{
					// the key was found
					drawable = mBackgrounds[pt];
				}
				return drawable;
			}
Пример #9
0
        protected override void OnDraw(Canvas canvas)
        {
            Paint p = new Paint();
            Paint n = new Paint();
            n.Color = (Color.Black);
            n.TextAlign = (Paint.Align.Center);
            p.Color = (Color.Blue);
            p.Alpha = (50);
            canvas.DrawRect(picker, p);
            int[,] field = GameController.getInstance().getNumbers();
            float widthStep = (float)MeasuredWidth/9;
            float heightStep = (float)MeasuredHeight/9;
            n.TextSize = (heightStep);
            int[,] initial = GameController.getInstance().getInitialNumber();
            for (int i = 0; i < 9; i++){
                for (int q = 0; q < 9; q++){
                    if (initial[i,q] != 0){
                        canvas.DrawText(initial[i,q] + "", widthStep*q + (widthStep / 2),
                            heightStep*i + heightStep - (heightStep*0.1f), n);
                    }
                }
            }
            n.Alpha = (150);
            for (int i = 0; i < 9; i++){
                for (int q = 0; q < 9; q++){
                    if (field[i,q] != 0){
                        canvas.DrawText(field[i,q] + "", widthStep*i + (widthStep / 2),
                            heightStep*q + heightStep - (heightStep*0.1f), n);
                    }
                }
            }

            base.OnDraw(canvas);
        }
Пример #10
0
 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;
   }
 }
Пример #11
0
		protected virtual void HandleShapeDraw (Canvas canvas)
		{
			// We need to account for offsetting the coordinates based on the padding
			var x = GetX () + Resize (this.ShapeView.Padding.Left);
			var y = GetY () + Resize (this.ShapeView.Padding.Top);

			switch (ShapeView.ShapeType) {
			case ShapeType.Box:
				HandleStandardDraw (canvas, p => {
					var rect = new RectF (x, y, x + this.Width, y + this.Height);
					if (ShapeView.CornerRadius > 0) {
						var cr = Resize (ShapeView.CornerRadius);
						canvas.DrawRoundRect (rect, cr, cr, p);
					} else {
						canvas.DrawRect (rect, p);
					}
				});
				break;
			case ShapeType.Circle:
				HandleStandardDraw (canvas, p => canvas.DrawCircle (x + this.Width / 2, y + this.Height / 2, (this.Width - 10) / 2, p));
				break;
			case ShapeType.CircleIndicator:
				HandleStandardDraw (canvas, p => canvas.DrawCircle (x + this.Width / 2, y + this.Height / 2, (this.Width - 10) / 2, p), drawFill: false);
				HandleStandardDraw (canvas, p => canvas.DrawArc (new RectF (x, y, x + this.Width, y + this.Height), QuarterTurnCounterClockwise, 360 * (ShapeView.IndicatorPercentage / 100), false, p), ShapeView.StrokeWidth + 3, false);
				break;
			}
		}
        protected override void DispatchDraw(Android.Graphics.Canvas canvas)
        {
            base.DispatchDraw(canvas);

            if (opened || isTracking || animator != null)
            {
                // Draw inset shadow on the menu
                canvas.Save();
                shadowDrawable.SetBounds(0, 0, Context.ToPixels(8), Height);
                canvas.Translate(ContentView.Left - shadowDrawable.Bounds.Width(), 0);
                shadowDrawable.Draw(canvas);
                canvas.Restore();

                if (contentOffsetX != 0)
                {
                    // Cover the area with a black overlay to display openess graphically
                    var openness = ((float)(MaxOffset - contentOffsetX)) / MaxOffset;
                    overlayPaint.Alpha = Math.Max(0, (int)(MaxOverlayAlpha * openness));
                    if (overlayPaint.Alpha > 0)
                    {
                        canvas.DrawRect(0, 0, ContentView.Left, Height, overlayPaint);
                    }
                }
            }
        }
Пример #13
0
        protected override void DispatchDraw (Canvas canvas)
        {
            base.DispatchDraw (canvas);

            if (FadeLength > 0) {
                var isHoriz = Orientation == Orientation.Horizontal;

                fadeRect.Right = canvas.Width;
                fadeRect.Bottom = canvas.Height;

                if (isHoriz) {
                    // On the right
                    fadeRect.Left = canvas.Width - FadeLength;
                    fadeRect.Top = 0;
                } else {
                    // On the bottom
                    fadeRect.Left = 0;
                    fadeRect.Top = canvas.Height - FadeLength;
                }

                var gradient = new LinearGradient (
                    fadeRect.Left, fadeRect.Top,
                    isHoriz ? fadeRect.Right : fadeRect.Left, isHoriz ? fadeRect.Top : fadeRect.Bottom,
                    new Color (255, 255, 255, 255), new Color (255, 255, 255, 0),
                    Shader.TileMode.Clamp);
                fadePaint.SetShader (gradient);

                canvas.DrawRect (fadeRect, fadePaint);
            }
        }
Пример #14
0
        public override void Draw(Canvas canvas)
        {
            LoadResources ();

            var blackPaint = new Paint () { Color = black.Value };
            var whitePaint = new Paint () { Color = white.Value };

            XamGame.RenderBoard ((RectangleF rect, Square.ColourNames color) =>
            {
                var paint = color == Square.ColourNames.White ? whitePaint : blackPaint;
                canvas.DrawRect (rect.X, rect.Y, rect.Right, rect.Bottom, paint);

            }, (RectangleF rect, object image) =>
            {
                if (image != null)
                    canvas.DrawBitmap ((Bitmap) image, rect.Left, rect.Top, null);
            });

            // New Game button
            whitePaint.Color = white.Value;
            whitePaint.SetStyle (Paint.Style.Fill);
            whitePaint.TextSize = 30;
            whitePaint.AntiAlias = true;
            Rect bounds = new Rect ();
            whitePaint.GetTextBounds ("New Game", 0, 8, bounds);
            canvas.DrawText ("New Game", (this.Width - bounds.Width ()) / 2, this.Bottom - (XamGame.BoardUpperLeftCorner.Y - bounds.Height ()) / 2, whitePaint);

            whitePaint.Dispose ();
            blackPaint.Dispose ();

            base.Draw (canvas);
        }
Пример #15
0
        public override void Draw (Canvas canvas)
        {
            if (gradientColor == null) {
                return;
            }

            canvas.DrawRect (Bounds, paint);
        }
Пример #16
0
 private static void DrawRectangle(Canvas canvas, RectF destination, Styles.Color outlineColor)
 {
     var paint = new Paint();
     paint.SetStyle(Paint.Style.Stroke);
     paint.Color = new AndroidColor(outlineColor.R, outlineColor.G, outlineColor.B, outlineColor.A);
     paint.StrokeWidth = 4;
     canvas.DrawRect(destination, paint);
 }
Пример #17
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);
        }
Пример #18
0
        protected override void OnDraw(Canvas canvas)
        {
            int canvasWidth = canvas.Width;
            int canvasHeight = canvas.Height;
            paint.SetStyle(Paint.Style.Fill);
            paint.Color=color(0xffff0000);
            canvas.DrawRect(dp2px(16), dp2px(16), dp2px(50), dp2px(50), paint);
            paint.Color= color(0xffcc9900);
            canvas.DrawRect(dp2px(100), dp2px(16), dp2px(133), dp2px(50), paint);
            paint.Color = color(0xff00ff00);
            canvas.DrawRect(dp2px(16), dp2px(106), dp2px(50), dp2px(140), paint);
            paint.Color = color(0xff6600ff);
            canvas.DrawRect(dp2px(100), dp2px(106), dp2px(133), dp2px(140), paint);

            canvas.Translate(canvasWidth / 2, canvasHeight / 2);
            paint.StrokeWidth=3;
            paint.SetStyle(Paint.Style.Stroke);
            paint.TextSize=dp2px(18);
            paint.Color= color(0xffffff00);
            canvas.DrawText("Custom View", -dp2px(53), dp2px(3), paint);
        }
Пример #19
0
		protected override void OnDraw (Canvas canvas)
		{
			base.OnDraw (canvas);

			float l = 0;
			float t = Height - PaddingBottom - DipToPixels (Context, 217);
			float r = Width - PaddingRight;
			float b = Height - DipToPixels (Context, 60);

			canvas.DrawRect (l, t, r, b, boxPaint);
			canvas.DrawPath (path, pathPaint);
		}
Пример #20
0
        public static void Draw(Canvas canvas, IViewport viewport, IStyle style, IFeature feature)
        {
            var point = feature.Geometry as Point;
            var dest = viewport.WorldToScreen(point);
            var symbolSize = (float)SymbolStyle.DefaultHeight;
            var symbolType = SymbolType.Ellipse;

            var symbolStyle = style as SymbolStyle;
            if (symbolStyle != null)
            {
                if (symbolStyle.BitmapId >= 0)
                {
                    // Bitmap
                    if (!feature.RenderedGeometry.ContainsKey(style))
                    {
                        var imageStream = BitmapRegistry.Instance.Get(symbolStyle.BitmapId);
                        imageStream.Position = 0;
                        var androidBitmap = BitmapFactory.DecodeStream(imageStream);
                        feature.RenderedGeometry[style] = androidBitmap;
                    }

                    var bitmap = (Bitmap)feature.RenderedGeometry[style];
                    var halfWidth = bitmap.Width / 2;
                    var halfHeight = bitmap.Height / 2;
                    var dstRectForRender = new RectF((float)dest.X - halfWidth, (float)dest.Y - halfHeight, (float)dest.X + halfWidth, (float)dest.Y + halfHeight);
                    canvas.DrawBitmap(bitmap, null, dstRectForRender, null);
                    return;
                }
                symbolType = symbolStyle.SymbolType;
                if (symbolStyle.SymbolScale > 0) symbolSize = (float)symbolStyle.SymbolScale * symbolSize;
            }

            // Drawing
            var paints = style.ToAndroid();
            if (symbolType == SymbolType.Ellipse)
            {
                foreach (var paint in paints)
                {
                    canvas.DrawCircle((int)dest.X, (int)dest.Y, symbolSize, paint);
                    paint.Dispose();
                }
            }
            else
            {
                foreach (var paint in paints)
                {
                    canvas.DrawRect(-(float)SymbolStyle.DefaultWidth, (float)SymbolStyle.DefaultHeight, (float)SymbolStyle.DefaultWidth, -(float)SymbolStyle.DefaultHeight, paint);
                    paint.Dispose();
                }
            }
        }
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            //Clean(canvas);

            rect = new Rect(App.DrawOffset, App.DrawOffset, App.DrawOffset + App.DrawWidth, App.DrawOffset + App.DrawHeight);
            canvas.DrawRect(rect, r_paint);
            if (App.planes != null && App.planes.Count > 0)
            {
                foreach (StructPlane plane in App.planes)
                {
                    plane.Draw(canvas);
                }
            }
            base.OnDraw(canvas);
        }
		protected override void OnDraw (Canvas canvas)
		{
			RectF rect = mColorRect;

			if(BORDER_WIDTH_PX > 0){

				//TODO : check the conversion
				byte[] byteArr = BitConverter.GetBytes (mBorderColor);
				mBorderPaint.Color = Color.Argb (byteArr [0], byteArr [1], byteArr [2], byteArr [3]);

				canvas.DrawRect(mDrawingRect, mBorderPaint);
			}

			if(mAlphaPattern != null){
				mAlphaPattern.Draw(canvas);
			}

			//TODO : check the conversion
			byte[] byteArr1 = BitConverter.GetBytes (mColor);
			mColorPaint.Color = Color.Argb (byteArr1 [0], byteArr1 [1], byteArr1 [2], byteArr1 [3]);
//			mColorPaint.Color = Color.Gold;

			canvas.DrawRect(rect, mColorPaint);
		}
		private static Bitmap RenderImage (PdfRenderer.Page page)
		{
			var bitmap = Bitmap.CreateBitmap (page.Width, page.Height, Bitmap.Config.Argb8888);

			// Fill with default while color first
			var canvas = new Canvas(bitmap);
			var paint = new Paint ()
			{
				Color = Color.White
			};
			canvas.DrawRect (new Rect (0, 0, page.Width, page.Height), paint);

			// Render content
			page.Render (bitmap, null, null, PdfRenderMode.ForDisplay);
			return bitmap;
		}
Пример #24
0
            public override void Draw(Android.Graphics.Canvas canvas, MapView mapView, bool shadow)
            {
                base.Draw(canvas, mapView, shadow);

                var paint = new Paint();

                paint.AntiAlias = true;
                paint.Color     = Color.Purple;

                // to draw fixed graphics that will not move or scale with the map
                //canvas.DrawRect (0, 0, 100, 100, paint);

                // to draw graphics at a geocoded location that move and scale with the map
                var   gp       = new GeoPoint((int)41.940542E6, (int)-73.363447E6);
                var   pt       = mapView.Projection.ToPixels(gp, null);
                float distance = mapView.Projection.MetersToEquatorPixels(20000);

                canvas.DrawRect(pt.X, pt.Y, pt.X + distance, pt.Y + distance, paint);
            }
        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();
            }
        }
Пример #26
0
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            String rdText    = this.Text.ToString();
            Paint  textPaint = new Paint();

            textPaint.AntiAlias = true;
            textPaint.TextSize  = this.TextSize;
            textPaint.TextAlign = Android.Graphics.Paint.Align.Center;

            float canvasWidth = canvas.Width;
            float textWidth   = textPaint.MeasureText(rdText);

            if (Checked)
            {
                this.SetBackgroundResource(Resource.Drawable.RoundedShape);
                int[]            colors = new int[] { this.Context.Resources.GetColor(Resource.Color.radioUnselectTop), this.Context.Resources.GetColor(Resource.Color.radioSelectTop) };
                GradientDrawable grad   = new GradientDrawable(GradientDrawable.Orientation.TopBottom, colors);
                grad.SetBounds(0, 0, this.Width, this.Height);
                grad.SetCornerRadius(7f);
                this.SetBackgroundDrawable(grad);
            }
            else
            {
                this.SetBackgroundResource(Resource.Drawable.RoundedShape);
                int[]            colors = new int[] { this.Context.Resources.GetColor(Resource.Color.radioUnselectTop), this.Context.Resources.GetColor(Resource.Color.radioUnselectBottom) };
                GradientDrawable grad   = new GradientDrawable(GradientDrawable.Orientation.TopBottom, colors);
                grad.SetBounds(0, 0, this.Width, this.Height);
                grad.SetCornerRadius(7f);
                this.SetBackgroundDrawable(grad);
            }

            Paint paint = new Paint();

            paint.Color = Color.Transparent;
            paint.SetStyle(Android.Graphics.Paint.Style.Stroke);
            Rect rect = new Rect(0, 0, this.Width, this.Height);

            canvas.DrawRect(rect, paint);

            base.OnDraw(canvas);
        }
Пример #27
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();
            }
        }
Пример #28
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();
            }
        }
Пример #29
0
        public Bitmap Transform(Bitmap source)
        {
            Bitmap result = Bitmap.CreateBitmap(source.Width, source.Height, source.GetConfig());
            Bitmap noise;
            try
            {
                noise = picasso.Load(Resource.Drawable.noise).Get();
            }
            catch (Exception)
            {
                throw new Exception("Failed to apply transformation! Missing resource.");
            }

            BitmapShader shader = new BitmapShader(noise, Shader.TileMode.Repeat, Shader.TileMode.Repeat);

            ColorMatrix colorMatrix = new ColorMatrix();
            colorMatrix.SetSaturation(0);
            ColorMatrixColorFilter filter = new ColorMatrixColorFilter(colorMatrix);

            Paint paint = new Paint(PaintFlags.AntiAlias);
            paint.SetColorFilter(filter);

            Canvas canvas = new Canvas(result);
            canvas.DrawBitmap(source, 0, 0, paint);

            paint.SetColorFilter(null);
            paint.SetShader(shader);
            paint.SetXfermode(new PorterDuffXfermode(PorterDuff.Mode.Multiply));

            canvas.DrawRect(0, 0, canvas.Width, canvas.Height, paint);

            source.Recycle();
            noise.Recycle();

            return result;
        }
Пример #30
0
			/// <summary>
			/// Draws the ship, fuel/speed bars, and background to the provided
			/// Canvas.
			/// </summary>
			private void DoDraw(Canvas canvas)
			{
				// Draw the background image. Operations on the Canvas accumulate
				// so this is like clearing the screen.
				canvas.DrawBitmap(mBackgroundImage, 0, 0, null);

				int yTop = mCanvasHeight - ((int) mY + mLanderHeight / 2);
				int xLeft = (int) mX - mLanderWidth / 2;

				// Draw the fuel gauge
				int fuelWidth = (int)(UI_BAR * mFuel / PHYS_FUEL_MAX);
				mScratchRect.Set(4, 4, 4 + fuelWidth, 4 + UI_BAR_HEIGHT);
				canvas.DrawRect(mScratchRect, mLinePaint);

				// Draw the speed gauge, with a two-tone effect
				double speed = Math.Sqrt(mDX * mDX + mDY * mDY);
				int speedWidth = (int)(UI_BAR * speed / PHYS_SPEED_MAX);

				if (speed <= mGoalSpeed)
				{
					mScratchRect.Set(4 + UI_BAR + 4, 4, 4 + UI_BAR + 4 + speedWidth, 4 + UI_BAR_HEIGHT);
					canvas.DrawRect(mScratchRect, mLinePaint);
				}
				else
				{
					// Draw the bad color in back, with the good color in front of
					// it
					mScratchRect.Set(4 + UI_BAR + 4, 4, 4 + UI_BAR + 4 + speedWidth, 4 + UI_BAR_HEIGHT);
					canvas.DrawRect(mScratchRect, mLinePaintBad);
					int goalWidth = (UI_BAR * mGoalSpeed / PHYS_SPEED_MAX);
					mScratchRect.Set(4 + UI_BAR + 4, 4, 4 + UI_BAR + 4 + goalWidth, 4 + UI_BAR_HEIGHT);
					canvas.DrawRect(mScratchRect, mLinePaint);
				}

				// Draw the landing pad
				canvas.DrawLine(mGoalX, 1 + mCanvasHeight - TARGET_PAD_HEIGHT, mGoalX + mGoalWidth, 1 + mCanvasHeight - TARGET_PAD_HEIGHT, mLinePaint);


				// Draw the ship with its current rotation
				canvas.Save();
				canvas.Rotate((float) mHeading, (float) mX, mCanvasHeight - (float) mY);
				if (mMode == STATE_LOSE)
				{
					mCrashedImage.SetBounds(xLeft, yTop, xLeft + mLanderWidth, yTop + mLanderHeight);
					mCrashedImage.Draw(canvas);
				}
				else if (mEngineFiring)
				{
					mFiringImage.SetBounds(xLeft, yTop, xLeft + mLanderWidth, yTop + mLanderHeight);
					mFiringImage.Draw(canvas);
				}
				else
				{
					mLanderImage.SetBounds(xLeft, yTop, xLeft + mLanderWidth, yTop + mLanderHeight);
					mLanderImage.Draw(canvas);
				}
				canvas.Restore();
			}
Пример #31
0
        protected override void OnDraw(Canvas canvas)
        {
            int height = Height;
            int tabCount = ChildCount;
            int dividerHeightPx = (int)(Math.Min(Math.Max(0f, mDividerHeight), 1f) * height);
            SlidingTabScrollView1.TabColorizer tabColorizer = mCustomTabColorizer != null ? mCustomTabColorizer : mDefaultTabColorizer;

            //Thick colored underline below the current selection
            if (tabCount > 0)
            {
                View selectedTitle = GetChildAt(mSelectedPosition);
                int left = selectedTitle.Left;
                int right = selectedTitle.Right;
                int color = tabColorizer.GetIndicatorColor(mSelectedPosition);

                if (mSelectionOffset > 0f && mSelectedPosition < (tabCount - 1))
                {
                    int nextColor = tabColorizer.GetIndicatorColor(mSelectedPosition + 1);
                    if (color != nextColor)
                    {
                        color = blendColor(nextColor, color, mSelectionOffset);
                    }

                    View nextTitle = GetChildAt(mSelectedPosition + 1);
                    left = (int)(mSelectionOffset * nextTitle.Left + (1.0f - mSelectionOffset) * left);
                    right = (int)(mSelectionOffset * nextTitle.Right + (1.0f - mSelectionOffset) * right);
                }

                mSelectedIndicatorPaint.Color = GetColorFromInteger(color);

                canvas.DrawRect(left, height - mSelectedIndicatorThickness, right, height, mSelectedIndicatorPaint);

                //Creat vertical dividers between tabs
                int separatorTop = (height - dividerHeightPx) / 2;
                for (int i = 0; i < ChildCount; i++)
                {
                    View child = GetChildAt(i);
                    mDividerPaint.Color = GetColorFromInteger(tabColorizer.GetDividerColor(i));
                    canvas.DrawLine(child.Right, separatorTop, child.Right, separatorTop + dividerHeightPx, mDividerPaint);
                }

                canvas.DrawRect(0, height - mBottomBorderThickness, Width, height, mBottomBorderPaint);
            }
        }
Пример #32
0
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            base.OnDraw(canvas);

            try
            {
                // 3000 -|
                //       |
                // 2000 -|
                //       |
                //    0 ---------------------------
                //         Tu We Th Fr Sa Su Mo Avg
                //  # Breakf  # Lunch  # Dinner  # Snack


                /*
                 * string[] yaxis = { "3.000", "2.250", "1.500", "750", "0" };
                 * string[] xaxis = { "Tue", "Wed", "Thu", "Fri", "Sat", "Sun", "Today", "Avg" };
                 * string[] legend = { "Breakfast", "Lunch", "Dinner", Property };//"Snack" };
                 * Single[][] values = new Single[4][];
                 * values [0] = new Single[]{ 0.1F, 0.13F, 0.2F, 0.03F, 0.12F, 0.13F, 0.12F, 0.03F };
                 * values [1] = new Single[]{ .3F, .2F, .3F, .2F, .3F, .2F, .3F, .2F };
                 * values [2] = new Single[]{ .2F, .3F, .2F, .3F, .2F, .3F, .2F, .3F };
                 * values [3] = new Single[]{ .3F, .2F, .3F, .2F, .3F, .2F, .3F, .2F };
                 */
                string[]   yaxis;
                string[]   xaxis = new string[8];
                string[]   legend;
                Single[][] values;

                Single goalBar;// = 0.7F;


                // calculate data
                Single goal = UserSettings.Current.GetGoal(property);

                Amount Goal;

                if (Single.IsNaN(goal) || goal == 0)
                {
                    Goal = Amount.Zero;
                }
                else
                {
                    Goal = Amount.FromProperty(goal, property);
                }

                Amount Max = Goal;

                HashSet <Period> UsedPeriods = new HashSet <Period>();

                int firstdate = -1;

                // query values
                for (int i = 0; i < 7; i++)
                {
                    DateTime date = DateTime.Now.Date.AddDays(-6 + i);

                    int    j = 0;
                    Amount amount;
                    Amount total = Amount.Zero;
                    foreach (Period p in PeriodList.All)
                    {
                        amount = Cache.GetPeriodPropertyValue(date, p, property);
                        total += amount;
                        if (!amount.IsZero && !UsedPeriods.Contains(p))
                        {
                            UsedPeriods.Add(p);
                        }
                        j++;
                    }

                    if (!total.IsZero && firstdate == -1)
                    {
                        firstdate = i;
                    }

                    if (i == 6)
                    {
                        xaxis[i] = AppResources.Today;
                    }
                    else if (i >= firstdate)
                    {
                        xaxis[i] = date.ToString("ddd");
                    }
                    else
                    {
                        xaxis[i] = "";
                    }

                    if (Max < total)
                    {
                        Max = total;
                    }
                }

                xaxis[7] = "";

                // determine legend periods
                List <Period> DisplayPeriods = new List <Period>(); // in order
                foreach (Period p in PeriodList.All)
                {
                    if (UsedPeriods.Contains(p))
                    {
                        DisplayPeriods.Add(p);
                    }
                }

                goalBar = Top(Goal, Max);

                yaxis = new string[] {
                    Max.ValueString(),
                    (Max * .75).ValueString(),
                    (Max * .5).ValueString(),
                    (Max * .25).ValueString(),
                    "0"
                };

                legend = new string[DisplayPeriods.Count];
                values = new float[DisplayPeriods.Count][];

                for (int j = 0; j < DisplayPeriods.Count; j++)
                {
                    Single sum = 0;
                    legend[j] = Strings.FromEnum(DisplayPeriods[j]);
                    values[j] = new float[8];

                    for (int i = 0; i < 7; i++)
                    {
                        DateTime date   = DateTime.Now.Date.AddDays(-6 + i);
                        Amount   amount = Cache.GetPeriodPropertyValue(date, DisplayPeriods[j], property);

                        values[j][i] = Top(amount, Max);
                        sum         += values[j][i];
                    }
                    values[j][7] = (sum / (7 - firstdate));
                }

                /*
                 * Color[] colors = {
                 *  Color.Rgb (200, 150, 0),
                 *  Color.Rgb (239, 179, 0),
                 *  Color.Rgb (255, 202, 105),
                 *  Color.Rgb (255, 221, 173)
                 * };
                 */

                Color[] colors; // = {					Resources.GetColor(Resource.Color.bar_color),					Resources.GetColor(Resource.Color.baralternate_color)				};

                int dcnt = DisplayPeriods.Count;

                colors = new Color[dcnt];
                for (float i = 0; i < dcnt; i++)
                {
                    Color refcolor = this.property.Color;// Resources.GetColor (Resource.Color.baralternate_color);
                    colors[(int)i] = new Color(MakeColor(refcolor.R, i / dcnt), MakeColor(refcolor.G, i / dcnt), MakeColor(refcolor.B, i / dcnt));
                }
                // start drawing

                Paint paint = new Paint();
                paint.Color    = Color.Black;
                paint.TextSize = Resources.GetDimensionPixelSize(Resource.Dimension.graphtextsize);

                Paint faintpaint = new Paint();
                faintpaint.Color = Color.Rgb(230, 230, 230);                                         // Color.LightGray;

                int middlemargin = Resources.GetDimensionPixelSize(Resource.Dimension.graphpadding); //10; // margin inbetween drawing regions only

                Rect   ylargest;
                Rect   xlargest;
                Rect   llargest;
                Rect[] ybounds = GetTextBounds(yaxis, paint, out ylargest);
                Rect[] xbounds = GetTextBounds(xaxis, paint, out xlargest);
                Rect[] lbounds = GetTextBounds(legend, paint, out llargest);

                // if labels are rotated 45 degrees; height = sqrt((label width + labelhieght)^2/2)
                //int xaxisheight = Math.Sqrt (((xlargest.Width + xlargest.Height) ^ 2) / 2);
                int xaxisheight = xlargest.Height();

                Rect bounds     = canvas.ClipBounds;
                Rect legendrect = new Rect(ylargest.Width() + middlemargin, bounds.Height() - llargest.Height(), bounds.Width() - middlemargin, bounds.Height() - middlemargin);
                Rect plotrect   = new Rect(ylargest.Width() + middlemargin, ylargest.Height(), bounds.Width(), legendrect.Top - xaxisheight - (int)(middlemargin * 1.5) - ylargest.Height() / 2);
                Rect yaxisrect  = new Rect(0, 0, ylargest.Width(), plotrect.Height() + llargest.Height());
                Rect xaxisrect  = new Rect(plotrect.Left, plotrect.Bottom + middlemargin, plotrect.Right, legendrect.Top - (int)(middlemargin * 1.5));

                // draw avg background
                canvas.DrawRect(plotrect.Left + plotrect.Width() * (xaxis.Length - 1) / xaxis.Length, plotrect.Top, plotrect.Right, plotrect.Bottom, faintpaint);

                // canvas.DrawRect (legendrect, faintpaint);
                // canvas.DrawRect (xaxisrect, faintpaint);

                // y axis
                for (int i = 0; i < yaxis.Length; i++)
                {
                    // draw y axis text
                    Single y = plotrect.Top + plotrect.Height() * i / (yaxis.Length - 1);
                    canvas.DrawText(yaxis[i], yaxisrect.Right - ybounds[i].Width(), y + ybounds[i].Height() / 2, paint);
                    // draw notch
                    canvas.DrawLine(yaxisrect.Right + middlemargin / 2, y, plotrect.Left, y, paint);

                    // draw horizontal line
                    canvas.DrawLine(plotrect.Left, y, plotrect.Right, y, (i == yaxis.Length - 1) ? paint : faintpaint);
                }
                canvas.DrawLine(plotrect.Left, plotrect.Top, plotrect.Left, plotrect.Bottom + middlemargin / 2, paint);

                // x axis
                for (int i = 0; i < xaxis.Length; i++)
                {
                    // draw x axis text
                    Single x = xaxisrect.Left + plotrect.Width() * (i + 0.5F) / xaxis.Length;
                    canvas.DrawText(xaxis[i], x - xbounds[i].Width() / 2, xaxisrect.Bottom, paint);
                    // draw notch
                    x = xaxisrect.Right - plotrect.Width() * i / xaxis.Length - 1;
                    canvas.DrawLine(x, plotrect.Bottom, x, plotrect.Bottom + middlemargin / 2, paint);
                }

                // legend
                int cubesize = middlemargin;
                int legendw  = (cubesize + middlemargin * 2) * legend.Length;
                for (int i = 0; i < legend.Length; i++)
                {
                    legendw += lbounds[i].Right;
                }

                legendrect.Left += (legendrect.Width() - legendw) / 2;

                Paint colorPaint = new Paint();
                int   dx         = 0;
                for (int i = 0; i < legend.Length; i++)
                {
                    // cube
                    colorPaint.Color = colors[i % colors.Length];
                    Single x = legendrect.Left + dx; // legendrect.Width () * i / legend.Length;
                    Single y = legendrect.Top + legendrect.Height() / 2;
                    canvas.DrawRect(x, y - (int)(cubesize / 2.5), x + cubesize, y + (int)(cubesize / 1.5), colorPaint);
                    // legend text
                    canvas.DrawText(legend[i], x + cubesize + middlemargin / 2, y + (int)(cubesize / 1.5), paint);
                    dx += cubesize + middlemargin * 2 + lbounds[i].Right;
                }
                dateOfValues.Clear();
                int      barwidth = middlemargin * 2;
                Single[] bottoms  = new Single[xaxis.Length];
                for (int i = 0; i < values.Length; i++)
                {
                    colorPaint.Color = colors[i % colors.Length];

                    for (int j = 0; j < values[i].Length; j++)
                    {
                        DateTime date = DateTime.Now.Date.AddDays(-6 + j);

                        if (i == 0)
                        {
                            bottoms[j] = plotrect.Bottom;
                        }

                        Single x       = plotrect.Left + plotrect.Width() * (j + 0.5F) / xaxis.Length;
                        Single h       = plotrect.Height() * values[i][j];
                        var    dLeft   = x - barwidth / 2;
                        var    dTop    = bottoms[j] - h;
                        var    dRight  = x + barwidth / 2;
                        var    dBottom = bottoms[j];
                        if (dateOfValues.Count < 7)
                        {
                            dateOfValues.Add(new KeyValuePair <DateTime, float[]>(date, new float[2] {
                                dLeft, dRight
                            }));
                        }
                        canvas.DrawRect(dLeft, dTop, dRight, dBottom, colorPaint);

                        bottoms[j] -= h;
                    }
                }
                foreach (var item in dateOfValues)
                {
                    System.Diagnostics.Debug.WriteLine(item.Key.Day + "  " + item.Value[0] + "-" + item.Value[1]);
                }
                // draw goal
                Paint dashespaint = new Paint();
                dashespaint.Color = Color.DarkGray;
                dashespaint.SetStyle(Paint.Style.Stroke);
                dashespaint.SetPathEffect(new DashPathEffect(new float[] { 10, 5 }, 0));
                //canvas.DrawLine (plotrect.Left, plotrect.Bottom - plotrect.Height () * goalBar, plotrect.Right, plotrect.Bottom - plotrect.Height () * goalBar, dashespaint);

                // use a path to draw dashes
                Path baseline = new Path();
                baseline.MoveTo(plotrect.Left, plotrect.Bottom - plotrect.Height() * goalBar);
                baseline.LineTo(plotrect.Right, plotrect.Bottom - plotrect.Height() * goalBar);
                canvas.DrawPath(baseline, dashespaint);
            }
            catch (Exception ex)
            {
                LittleWatson.ReportException(ex);
            }
        }
Пример #33
0
 public void DoDraw(Android.Graphics.Canvas canvas)
 {
     canvas.DrawRect(0f, _offset, 100, _offset + 100, rectPaint);
 }
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            if(null == _viewPager) return;

            var count = _viewPager.Adapter.Count;
            if (count == 0) return;

            if(_currentPage >= count)
            {
                CurrentItem = count - 1;
                return;
            }

            var pageWidth = (Width - PaddingLeft - PaddingRight) / (1f * count);
            var left = PaddingLeft + pageWidth * (_currentPage + _positionOffset);
            var right = left + pageWidth;
            var top = PaddingTop;
            var bottom = Height - PaddingBottom;
            canvas.DrawRect(left, top, right, bottom, _paint);
        }
Пример #35
0
        protected override bool DrawChild(Canvas canvas, View child, long drawingTime)
        {
            var lp = (LayoutParams) child.LayoutParameters;
            var save = canvas.Save(SaveFlags.Clip);

            var drawScrim = false;

            if (_canSlide && !lp.Slideable && _slideableView != null)
            {
                if (!OverlayContent)
                {
                    canvas.GetClipBounds(_tmpRect);
                    if (_isSlidingUp)
                        _tmpRect.Bottom = Math.Min(_tmpRect.Bottom, _slideableView.Top);
                    else
                        _tmpRect.Top = Math.Max(_tmpRect.Top, _slideableView.Bottom);

                    canvas.ClipRect(_tmpRect);
                }

                if (_slideOffset < 1)
                    drawScrim = true;
            }

            var result = base.DrawChild(canvas, child, drawingTime);
            canvas.RestoreToCount(save);

            if (drawScrim)
            {
                var baseAlpha = (_coveredFadeColor.ToArgb() & 0xff000000) >> 24;
                var imag = (int) (baseAlpha * (1 - _slideOffset));
                var color = imag << 24 | (_coveredFadeColor.ToArgb() & 0xffffff);
                _coveredFadePaint.Color = new Color(color);
                canvas.DrawRect(_tmpRect, _coveredFadePaint);
            }

            return result;
        }
Пример #36
0
        private void drawResultPoints(Bitmap barcode, ZXing.Result rawResult)
        {
            var points = rawResult.ResultPoints;

            if (points != null && points.Length > 0)
            {
                var canvas = new Canvas(barcode);
                Paint paint = new Paint();
                paint.Color = Android.Graphics.Color.White;
                paint.StrokeWidth = 3.0f;
                paint.SetStyle(Paint.Style.Stroke);

                var border = new RectF(2, 2, barcode.Width - 2, barcode.Height - 2);
                canvas.DrawRect(border, paint);

                paint.Color = Android.Graphics.Color.Purple;

                if (points.Length == 2)
                {
                    paint.StrokeWidth = 4.0f;
                    drawLine(canvas, paint, points[0], points[1]);
                }
                else if (points.Length == 4 &&
                         (rawResult.BarcodeFormat == BarcodeFormat.UPC_A ||
                 rawResult.BarcodeFormat == BarcodeFormat.EAN_13))
                {
                    // Hacky special case -- draw two lines, for the barcode and metadata
                    drawLine(canvas, paint, points[0], points[1]);
                    drawLine(canvas, paint, points[2], points[3]);
                }
                else
                {
                    paint.StrokeWidth = 10.0f;

                    foreach (ResultPoint point in points)
                        canvas.DrawPoint(point.X, point.Y, paint);
                }
            }
        }
Пример #37
0
        //--------------------------------------------------------------
        // EVENT METHODS
        //--------------------------------------------------------------
        // Draw every proposed piece in the accorded space
        // each piece have the space for 5 blocks to draw itself on the width
        // On the Height, each piece have 4 blocks to draw itself and there is one pixel to separate each one of them (because there is less space on the height)
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            // If it is the first draw, calculate the size of the block according to the size of the canvas
            if(_blockSize == 0)
            {
                // Calculate the size of the block, Space for each piece set to 5 blocks (except for the last one)
                _blockSize = Math.Min((Width - (_nbPieceByLine - 1) * StrokeWidthBorder)/(_nbPieceByLine*5),
                                        (Height - (Constants.NbLinePropPiece - 1) * StrokeWidthBorder)/(Constants.NbLinePropPiece*5));

                // Create the blocks images with the right size
                foreach(TetrisColor color in Enum.GetValues(typeof(TetrisColor)))
                {
                    Bitmap image = BlockView.CreateImage(_blockSize, color);
                    if(image != null)
                    {
                        _blockImages.Add(color, image);
                    }
                }

                _offset = new Point((Width - _nbPieceByLine*5*_blockSize - (_nbPieceByLine - 1) * StrokeWidthBorder) / 2,
                                    (Height - Constants.NbLinePropPiece*5*_blockSize - (Constants.NbLinePropPiece - 1) * StrokeWidthBorder) / 2);
            }

            // Draw the pieces and highlight the selected one
            for(int i = 0; i < Constants.NbProposedPiece; i++)
            {
                if(_proposedPieces[i] != null)
                {
                    // Show the selected piece
                    if(i == _selectedPiece)
                    {
                        int left = ((i % _nbPieceByLine) == 0) ? 0 : _offset.X;
                        int right = (((i + 1) % _nbPieceByLine) == 0) ? Width : _offset.X;
                        int top = ((i / _nbPieceByLine) == 0) ? 0 : _offset.Y;
                        int bottom = (i >= (_nbPieceByLine * (Constants.NbLinePropPiece - 1))) ? Height : _offset.Y;

                        RectF rect = new RectF((i % _nbPieceByLine) * _blockSize * 5 + (i % _nbPieceByLine) * StrokeWidthBorder + left,
                                                (_blockSize * 5) * (i / _nbPieceByLine) + (i / _nbPieceByLine) * StrokeWidthBorder + top,
                                                ((i % _nbPieceByLine) + 1) * _blockSize * 5 + (i % _nbPieceByLine) * StrokeWidthBorder + right,
                                                (_blockSize * 5) * (1 + i / _nbPieceByLine) + (i / _nbPieceByLine) * StrokeWidthBorder + bottom);

                        Paint paint = new Paint {AntiAlias = true, Color = Utils.getAndroidReallyLightColor(TetrisColor.Red)};
                        //canvas.DrawRoundRect(rect, Constants.RadiusHighlight, Constants.RadiusHighlight, paint);
                        canvas.DrawRect(rect, paint);
                        paint.Dispose();
                    }
                    float xSize = 0;
                    float ySize = 0;
                    _proposedPieces[i].GetDrawnSize(_blockSize, ref xSize, ref ySize);

                    // Draw each piece
                    _proposedPieces[i].Draw(canvas, _blockSize, _blockImages,
                        (i % _nbPieceByLine) * _blockSize * 5 + (_blockSize * 5 - xSize) / 2 + _offset.X + (i % _nbPieceByLine) * StrokeWidthBorder,
                        Height - ((i / _nbPieceByLine + 1) * _blockSize * 5 - (_blockSize * 5 - ySize) / 2 + _offset.Y + (i / _nbPieceByLine) * StrokeWidthBorder),
                        Height);
                }
            }

            // Grid
            for(int i = 1; i < _nbPieceByLine; i++)
            {
                // Vertical
                int x = _offset.X + i*5*_blockSize + (i - 1) * StrokeWidthBorder;
                canvas.DrawRect(x, 0, x + StrokeWidthBorder, Height, GridPaint);
            }
            for(int i = 1; i < Constants.NbLinePropPiece; i++)
            {
                // Horizontal
                int y = _offset.Y + i*5*_blockSize + (i - 1) * StrokeWidthBorder;
                canvas.DrawRect(0, y, Width, y + StrokeWidthBorder, GridPaint);
            }
        }
Пример #38
0
        private void DoDraw(Canvas canvas)
        {
			// Increment / reset
            size += delta;
            if (size > 250)
            {
				delta = -1;
            } 
			else if (size < 30) 
			{
				delta = 1;
			}

            // Set background color
            canvas.DrawColor(Color.BLUE); 
            var paint = new Paint();
            paint.TextAlign =(Paint.Align.CENTER);

            // Draw some lines
            canvas.DrawLine(mX, mY, mY + 33, mX + 100, paint);
            paint.Color =(Color.RED);
            paint.StrokeWidth = (10);
            canvas.DrawLine(87, 0, 75, 100, paint);
            paint.Color =(Color.GREEN);
            paint.StrokeWidth = (5);
            for (int y = 30, alpha = 128; alpha > 2; alpha >>= 1, y += 10)
            {
                paint.Alpha = (alpha);

                canvas.DrawLine(mY, y, mY + 100, y, paint);
            }

            // Draw a red rectangle
            paint.Color =(Color.RED);
            var rect = new Rect();
            rect.Set(size + 120, 130, size + 156, 156);
            canvas.DrawRect(rect, paint);

            // Draw a circle
            paint.Color =(Color.ParseColor("#ffd700"));
            canvas.DrawCircle(size * 2, 220, 30, paint); //faster circle

            // Draw red'ish rectangle
            paint.Color =(Color.Rgb(128, 20, 20));
            canvas.DrawRect(size, 67, 68, 45, paint);

            // Draw green circle
            paint.Color =(Color.GREEN);
            canvas.DrawCircle(size, 140.0f - size / 3, 45.0f, paint); //move circle across screen
            paint.Color =(Color.RED);
            canvas.DrawText("Dot42", size, 140.0f - size / 3, paint);

            // Draw magenta circle
            paint.Color =(Color.MAGENTA);
            canvas.DrawCircle(mX, mY, size / 4.0f, paint); //move circle down screen
            paint.Color =(Color.GREEN);
            canvas.DrawText("is", mX, mY, paint);

            // Draw yellow rectangle
            paint.Alpha = (64);
            paint.Color =(Color.YELLOW);
            canvas.DrawRect(size, size, size + 45, size + 45, paint);
            // Draw text on rectangle
            paint.Alpha = (255);
            paint.Color =(Color.DKGRAY);
            canvas.DrawText("fun!", size + 45 / 2, size + 45 / 2, paint);
        }
Пример #39
-1
        protected override void OnDraw(Canvas canvas)
        {
            try {
                var radius = Math.Min(Width, Height) / 2;
                using (var paint1 = new Paint())
                using (var paint2 = new Paint()) {

                    paint1.Color = Android.Graphics.Color.Transparent;
                    canvas.DrawRect(0, 0, this.Width, this.Height, paint1);

                    paint2.Color = this.Element.Color.ToAndroid();
                    canvas.DrawCircle(Width / 2, Height / 2, radius, paint2);
                }
            } catch {
                //Debug.WriteLine("Unable to create circle image: " + ex);
            }

            base.OnDraw(canvas);
        }
Пример #40
-1
		public static Bitmap GetImage(int width, int height, string intensiteit)
		{
			intensity = intensiteit;
			sizeBlocks = width / 7;
			int amountImages = 56;
			List<Bitmap> bitmaps = DrawImages.CreateBitmapBlocks (amountImages,false);
			Paint p = new Paint ();
			p.StrokeWidth = 0.5f;
			p.SetStyle (Paint.Style.Fill);
			p.Color = Color.White;
			Bitmap b = Bitmap.CreateBitmap (width, height, Bitmap.Config.Argb8888);
			Canvas c = new Canvas (b);
			//Make background White
			c.DrawRect (new Rect (0, 0, width, height), p);
			//Draw Blocks
			for(int i=0;i<amountImages;i++)
			{
				c.DrawBitmap (bitmaps[i], (i % 7) * (width / 7), (i % 8) * (height / 8), p);
			}
			p.Dispose ();
			c.Dispose ();
			return b;
		}
			public override ImageReference GetBackground (int row, int col)
			{
				var pt = new Point (row, col);
				ImageReference imgRef = null;
				if(mBackgrounds.ContainsKey(pt))
					imgRef = mBackgrounds [pt];
				if (imgRef == null) {
					var bm = Bitmap.CreateBitmap (200, 200, Bitmap.Config.Argb8888);
					var c = new Canvas (bm);
					var p = new Paint ();
					c.DrawRect (0, 0, 200, 200, p);
					p.AntiAlias = true;
					p.SetTypeface (Typeface.Default);
					p.TextSize = 64;
					p.Color = Color.LightGray;
					c.DrawText (col + "-" + row, 20, 100, p);
					imgRef = ImageReference.ForBitmap (bm);
					mBackgrounds.Add (pt, imgRef);
				}
				return imgRef;
			}