Esempio n. 1
0
        private void Initialize()
        {
            var scaledDensity = Context.Resources.DisplayMetrics.ScaledDensity;

            SetLayerType(LayerType.Software, null);

            _paintBorder = new Paint(PaintFlags.AntiAlias) { Color = Color.DarkGray };

            _paintGrid = new Paint(PaintFlags.AntiAlias) { Color = Color.LightGray };
            _paintGrid.SetStyle(Paint.Style.Stroke);
            _paintGrid.SetPathEffect(new DashPathEffect(new float[] { 5, 5 }, 0));
            _paintGrid.StrokeWidth = 5;

            _paintSubGrid = new Paint(PaintFlags.AntiAlias) { Color = Color.LightGray };
            _paintSubGrid.SetStyle(Paint.Style.Stroke);
            _paintSubGrid.SetPathEffect(new DashPathEffect(new float[] { 5, 5 }, 0));
            _paintSubGrid.StrokeWidth = 2;

            _paintPos = new Paint(PaintFlags.AntiAlias) { Color = Color.CornflowerBlue };

            _paintGridText = new Paint(PaintFlags.AntiAlias)
            {
                Color = Color.LightGray,
                TextSize = 20*scaledDensity
            };
        }
        public CreateAnimationDrawer(Context c, BrushItem brush, Canvas canvas, Bitmap myBmp, bool tooAdd = false, int cell = 1, string DrawerState = "brush_selection", Path pathToUse = null)
            : base(c)
        {
            myBitmap = myBmp;
            myCanvas = canvas;
            DrawerStateInternal = DrawerState;
            addOnly = tooAdd;
            status = 0;
            myPath = new Path();
            myPaint = new Paint(PaintFlags.Dither);
            myPaint.AntiAlias = true;
            myPaint.Dither = true;
            myPaint.SetStyle(Paint.Style.Stroke);
            myPaint.StrokeJoin = Paint.Join.Round;
            myPaint.StrokeWidth = brush.Thickness;
            myPaint.StrokeCap = Paint.Cap.Round;
            myPaint.SetARGB(colorUtil.a, colorUtil.r, colorUtil.g, colorUtil.b);

            if (brush.BrushType == AnimationTypesBrushType.Spray)
                myPaint.SetShadowLayer(brush.Thickness, 0, 0, ImageHelper.convWZColorToColor(brush.BrushColor));

            if (DrawerState == "brush_selection")
            {
                if (pathToUse != null)
                {
                    myBoundsPaint = new Paint();
                    myBoundsPaint = new Paint(PaintFlags.Dither);
                    myBoundsPaint.AntiAlias = true;
                    myBoundsPaint.Dither = true;
                    myBoundsPaint.SetStyle(Paint.Style.Stroke);
                    myBoundsPaint.StrokeJoin = Paint.Join.Round;
                    myBoundsPaint.StrokeWidth = 10f;
                    myBoundsPaint.StrokeCap = Paint.Cap.Round;
                    myBoundsPaint.SetARGB(255, 0, 0, 0);
                    myBoundsPaint.SetPathEffect(new DashPathEffect(new float[]
                    {
                        10f,
                        20f
                    }, 0));

                    myPath = pathToUse;
                    AnimationUtil.theCanvas.DrawPath(myPath, myPaint);
                    AnimationUtil.theCanvas.DrawPath(myPath, myPaint);

                    myBoundsRect = new RectF();
                    myPath.ComputeBounds(myBoundsRect, true);
                    AnimationUtil.theCanvas.DrawRect(myBoundsRect, myBoundsPaint);
                }
            }
        }
        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);
            }
        }
Esempio n. 4
0
        public void DrawLine(float x1, float y1, float x2, float y2, SolidColor color, float width, LineStyles style)
        {
            using (var p = new Paint())
            {
                p.Color       = color;
                p.StrokeWidth = width;

                switch (style)
                {
                case LineStyles.Dot:
                    p.SetPathEffect(new DashPathEffect(new float[] { 1, 1 }, 1));
                    break;
                }

                this.canvas.DrawLine(x1, y1, x2, y2, p);
            }
        }
		void DrawHexagon (Canvas canvas)
		{
			// The extra padding is to avoid edges being clipped
			var padding = (int)TypedValue.ApplyDimension (ComplexUnitType.Dip, 8, Resources.DisplayMetrics);
			var halfHeight = (Height - padding) / 2;
			var side = (Width - padding) / 2;
			var foo = (int)Math.Sqrt (side * side - halfHeight * halfHeight);

			var path = hexagon ?? (hexagon = new Path ());
			hexagon.Reset ();
			path.MoveTo (Width / 2, padding / 2);
			path.RLineTo (-side / 2, 0);
			path.RLineTo (-foo, halfHeight);
			path.RLineTo (foo, halfHeight);
			path.RLineTo (side, 0);
			path.RLineTo (foo, -halfHeight);
			path.RLineTo (-foo, -halfHeight);
			path.Close ();

			var m = transformationMatrix ?? (transformationMatrix = new Matrix ());
			m.Reset ();
			var centerX = Width / 2;
			var centerY = Height / 2;
			m.PostRotate (Rotation, centerX, centerY);
			m.PostScale (ScaleX, ScaleY, centerX, centerY);
			path.Transform (m);

			if (hexagonPaint == null) {
				hexagonPaint = new Paint {
					Color = new Android.Graphics.Color (0x22, 0x76, 0xB9),
					AntiAlias = true,
				};
				hexagonPaint.SetPathEffect (new CornerPathEffect (30));
			}

			canvas.DrawPath (path, hexagonPaint);
		}
        /// <summary>
        ///     Implement this to do your drawing.
        /// </summary>
        /// <param name="canvas">the canvas on which the background will be drawn</param>
        /// <since version="Added in API level 1" />
        /// <remarks>
        ///     <para tool="javadoc-to-mdoc">Implement this to do your drawing.</para>
        ///     <para tool="javadoc-to-mdoc">
        ///         <format type="text/html">
        ///             <a href="http://developer.android.com/reference/android/view/View.html#onDraw(android.graphics.Canvas)"
        ///                 target="_blank">
        ///                 [Android Documentation]
        ///             </a>
        ///         </format>
        ///     </para>
        /// </remarks>
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            var r = new Rect(0, 0, canvas.Width, canvas.Height);
            var dAdjustedThicnkess = (float)Thickness * _dm;

            var paint = new Paint { Color = StrokeColor, StrokeWidth = dAdjustedThicnkess, AntiAlias = true };
            paint.SetStyle(Paint.Style.Stroke);
            switch (StrokeType)
            {
                case StrokeType.Dashed:
                    paint.SetPathEffect(new DashPathEffect(new[] { 6 * _dm, 2 * _dm }, 0));
                    break;
                case StrokeType.Dotted:
                    paint.SetPathEffect(new DashPathEffect(new[] { dAdjustedThicnkess, dAdjustedThicnkess }, 0));
                    break;
            }

            var thicknessOffset = (dAdjustedThicnkess) / 2.0f;

            var p = new Path();
            if (Orientation == SeparatorOrientation.Horizontal)
            {
                p.MoveTo(0, thicknessOffset);
                p.LineTo(r.Width(), thicknessOffset);
            }
            else
            {
                p.MoveTo(thicknessOffset, 0);
                p.LineTo(thicknessOffset, r.Height());
            }
            canvas.DrawPath(p, paint);
        }
Esempio n. 7
0
        public void DrawStopwatch(Canvas canvas)
        {
            canvas.Save();
            canvas.Translate(Width / 2F, Height / 2F);
            
            var tickMarks = new Path();
            tickMarks.AddCircle(0, 0, 90, Path.Direction.Cw);

            var scale = Math.Min(Width, Height) / 2F / 120;
            canvas.Scale(scale, scale);

            var paint = new Paint
            {
                StrokeCap = Paint.Cap.Square,
                Color = new Color(240, 240, 240)
            };

            paint.SetStyle(Paint.Style.Stroke);
            paint.StrokeWidth = 3;
            paint.SetPathEffect(MinuteDashEffect);
            canvas.DrawPath(tickMarks, paint);

            paint.Color = new Color(240, 240, 240);
            paint.StrokeWidth = 4;
            paint.SetPathEffect(FifthMinuteDashEffect);
            canvas.DrawPath(tickMarks, paint);
        }
Esempio n. 8
0
		Paint GetPenPaint (Pen pen)
		{
			var paint = new Paint (PaintFlags.AntiAlias);
			paint.SetStyle (Paint.Style.Stroke);
			paint.SetARGB (pen.Color.A, pen.Color.R, pen.Color.G, pen.Color.B);
			paint.StrokeWidth = (float)pen.Width;

            if (pen.DashPattern != null && pen.DashPattern.Any ()) {
                var dashPathEffect = new DashPathEffect(pen.DashPattern.ToArray(), 0);
                paint.SetPathEffect(dashPathEffect);
            }

			return paint;
		}
		protected override void OnDraw(Canvas canvas)
		{
			base.OnDraw (canvas);

			var r = new Rect (0,0,canvas.Width,canvas.Height);
			float dAdjustedThicnkess = (float)this.Thickness * dm;
		

			var paint = new Paint()
			{
				Color = this.StrokeColor,
				StrokeWidth = dAdjustedThicnkess,
				AntiAlias = true
			
			};
			paint.SetStyle(Paint.Style.Stroke);
			switch(StrokeType) {
			case StrokeType.Dashed:
				paint.SetPathEffect(new DashPathEffect(new float[]{ 6*dm, 2*dm}, 0));
				break;
			case StrokeType.Dotted:
				paint.SetPathEffect(new DashPathEffect(new float[]{ dAdjustedThicnkess, dAdjustedThicnkess}, 0));
				break;
			default:

				break;
			}

			var desiredTotalSpacing = (SpacingAfter + SpacingBefore)*dm;
			float leftForSpacing = 0;
			float actualSpacingBefore = 0;
			float actualSpacingAfter = 0;
			if(Orientation == SeparatorOrientation.Horizontal){
				leftForSpacing = r.Height() - dAdjustedThicnkess;
			}else{
				leftForSpacing = r.Width() - dAdjustedThicnkess;
			}
			if(desiredTotalSpacing > 0) {
				float spacingCompressionRatio = (float)(leftForSpacing / desiredTotalSpacing) ;
				actualSpacingBefore = (float)SpacingBefore*dm * spacingCompressionRatio;
				actualSpacingAfter = (float)SpacingAfter*dm * spacingCompressionRatio;
			}else{
				actualSpacingBefore = 0;
				actualSpacingAfter = 0;
			}
			float thicknessOffset = (dAdjustedThicnkess)/2.0f;



			Path p = new Path();
			if(Orientation == SeparatorOrientation.Horizontal){
				p.MoveTo(0, actualSpacingBefore + thicknessOffset);
				p.LineTo(r.Width(), actualSpacingBefore + thicknessOffset);
			}else{
				p.MoveTo(actualSpacingBefore+thicknessOffset, 0);
				p.LineTo(actualSpacingBefore+thicknessOffset, r.Height());
			}
			canvas.DrawPath(p, paint);
		}