Beispiel #1
0
		protected override void OnDraw(Canvas canvas) {
			base.OnDraw (canvas);
			if (mBlurredView != null) {
				if (prepare()) {
					// If the background of the blurred view is a color drawable, we use it to clear
					// the blurring canvas, which ensures that edges of the child views are blurred
					// as well; otherwise we clear the blurring canvas with a transparent color.
					if (mBlurredView.Background != null && mBlurredView.Background is ColorDrawable){
						mBitmapToBlur.EraseColor(((ColorDrawable) mBlurredView.Background).Color);
					}else {
						mBitmapToBlur.EraseColor(Color.Transparent);
					}

					mBlurredView.Draw(mBlurringCanvas);
					blur();

					canvas.Save();
					canvas.Translate(mBlurredView.GetX() - GetX(), mBlurredView.GetY() - GetY());
					canvas.Scale(mDownsampleFactor, mDownsampleFactor);
					canvas.DrawBitmap(mBlurredBitmap, 0, 0, null);
					canvas.Restore();
				}
				canvas.DrawColor(mOverlayColor);
			}
		}
        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);
        }
		protected override void OnDraw (Canvas canvas)
		{
			base.OnDraw (canvas);
			canvas.Save ();
			canvas.Translate (_posX, _posY);
			canvas.Scale (_scaleFactor, _scaleFactor);
			_icon.Draw (canvas);
			canvas.Restore ();
		}
Beispiel #4
0
        public object ConvertToBitmap(double width, double height, double scaleFactor, ImageFormat format)
        {
            if (_drawCallback != null)
            {
                var image = new DroidImage((int)width, (int)height, format);
                using (var canvas = new AG.Canvas(image.Image))
                    using (var dc = new DroidContext {
                        Canvas = canvas
                    }) {
                        canvas.Scale((float)scaleFactor, (float)scaleFactor);
                        _drawCallback(dc, new Xwt.Rectangle(0, 0, width, height));
                    }
                return(image);
            }

            throw new NotSupportedException();
        }
                protected override void OnDraw(Android.Graphics.Canvas canvas)
                {
                    BorderedRectPaintDrawable paintDrawable = Background as BorderedRectPaintDrawable;

                    if (paintDrawable != null)
                    {
                        float borderWidth = TypedValue.ApplyDimension(ComplexUnitType.Dip, paintDrawable.BorderWidth, Rock.Mobile.PlatformSpecific.Android.Core.Context.Resources.DisplayMetrics);

                        // perform just a vertical translation to ensure the text is centered
                        canvas.Translate(0, borderWidth);

                        // create a scalar to uniformly scale down the text so it fits within the border
                        float scalar = (canvas.Width - (borderWidth * 2)) / canvas.Width;
                        canvas.Scale(scalar, scalar);
                    }

                    base.OnDraw(canvas);
                }
Beispiel #6
0
        protected void DrawAt(Canvas canvas, Drawable drawable, int x, int y, bool shadow)
        {
            try
            {
                canvas.Save();
                canvas.Translate(x, y);
                if (shadow)
                {
                    drawable.SetColorFilter(Util.Int32ToColor(2130706432), PorterDuff.Mode.SrcIn);
                    canvas.Skew(-0.9F, 0.0F);
                    canvas.Scale(1.0F, 0.5F);
                }

                drawable.Draw(canvas);
                if (shadow)
                {
                    drawable.ClearColorFilter();
                }
            }
            finally
            {
                canvas.Restore();
            }
        }
    protected override void OnDraw(Canvas canvas)
    {
      canvas.DrawColor(Color.Transparent);

      Paint p = new Paint(); 
      p.AntiAlias = true; 
      SetLayerType(LayerType.Software, p);
      long now = Android.OS.SystemClock.UptimeMillis();
      if (movieStart == 0)
      {   // first time
        movieStart = now;
      }
      if (movie != null)
      {
        int dur = movie.Duration();
        if (dur == 0)
        {
          dur = 1000;
        }
        var relTime = (int)((now - movieStart) % dur);
        movie.SetTime(relTime);
        var movieWidth = (float)movie.Width();
        var movieHeight = (float)movie.Height();
        var scale = 1.0f;
        if (movieWidth > movieHeight)
        {
          scale = this.Width/movieWidth;
          if (scale*movieHeight > Height)
            scale = Height/movieHeight;
        }
        else
        {
          scale = this.Height/movieHeight;
          if (scale*movieWidth > Width)
            scale = Height/movieWidth;
        }


        
        canvas.Scale(scale, scale);
        try
        {
          
          movie.Draw(canvas, 0, 0, p);
        }catch(Exception ex)
        {

        }

        if(playing)
          Invalidate();
      }
    }
 public void transformCanvas(Canvas canvas, float percentOpen)
 {
     mtrans.transformCanvas(canvas, percentOpen);
     float f = minterp.GetInterpolation(percentOpen);
     canvas.Scale((mopenedX - mclosedX) * f + mclosedX,
             (mopenedY - mclosedY) * f + mclosedY, mpx, mpy);
 }
		Bitmap GetImage (Color strokeColor, Color fillColor, System.Drawing.SizeF size, float scale, 
		                 bool shouldCrop = true)
		{
			if (size.Width == 0 || size.Height == 0 || scale <= 0)
				return null;

			float uncroppedScale;
			System.Drawing.SizeF uncroppedSize;
			RectF croppedRectangle;

			if (shouldCrop && Points.Count () != 0) {
				croppedRectangle = getCroppedRectangle ();
				float scaleX = (croppedRectangle.Right - croppedRectangle.Left) / Width;
				float scaleY = (croppedRectangle.Bottom - croppedRectangle.Top) / Height;
				uncroppedScale = 1 / Math.Max (scaleX, scaleY);
				//uncroppedScale = 1 / getScaleFromSize (croppedRectangle.Size, Bounds);
				uncroppedSize = getSizeFromScale (uncroppedScale, size.Width, size.Height);
			} else {
				uncroppedScale = scale;
				uncroppedSize = size;
			}

			Bitmap image = Bitmap.CreateBitmap ((int)uncroppedSize.Width, (int)uncroppedSize.Height, 
			                                    Bitmap.Config.Argb8888);
			Canvas canvas = new Canvas (image);
			canvas.Scale (uncroppedScale, uncroppedScale);

			DrawStrokesOnCanvas (canvas, strokeColor, fillColor);
	
			if (shouldCrop && Points.Count () != 0) {
				croppedRectangle = getCroppedRectangle ();
				RectF scaledRectangle = new RectF (croppedRectangle.Left * uncroppedScale,
				                                   croppedRectangle.Top * uncroppedScale,
				                                   croppedRectangle.Right * uncroppedScale,
				                                   croppedRectangle.Bottom * uncroppedScale);

				if (scaledRectangle.Left >= 5)
					scaledRectangle.Left -= 5;
				if (scaledRectangle.Right <= uncroppedSize.Width - 5)
					scaledRectangle.Right += 5;
				if (scaledRectangle.Top >= 5)
					scaledRectangle.Top -= 5;
				if (scaledRectangle.Bottom <= uncroppedSize.Height - 5)
					scaledRectangle.Bottom += 5;
				image = Bitmap.CreateBitmap (image, 
				                             (int) scaledRectangle.Left, 
				                             (int) scaledRectangle.Top,
				                             (int) scaledRectangle.Width (),
				                             (int) scaledRectangle.Height ());
			}
			return image;
		}
Beispiel #10
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 ();
		}
 public void transformCanvas(Canvas canvas, float percentOpen)
 {
     float scale = (float)(percentOpen * 0.25 + 0.75);
     canvas.Scale(scale, scale, canvas.Width / 2, canvas.Height / 2);
 }
		public override void Draw (Canvas canvas)
		{
			if (flip) {
				canvas.Save();
				canvas.Scale(1f, -1f, IntrinsicWidth / 2, IntrinsicHeight / 2);
			}
			topLine.draw(canvas);
			middleLine.draw(canvas);
			bottomLine.draw(canvas);

			if (flip) canvas.Restore();
			//			throw new NotImplementedException ();
		}
			/**
         * Draws a circle centered in the view.
         *
         * @param canvas the canvas to draw on
         * @param cx the center x coordinate
         * @param cy the center y coordinate
         * @param color the color to draw
         * @param pct the percentage of the view that the circle should cover
         */
			private void drawCircle(Canvas canvas, float cx, float cy, int color, float pct) {
				mPaint.Color = Android.Graphics.Color.Brown;
				//mPaint.SetColor(color);
				canvas.Save();
				canvas.Translate (cx, cy);
				float radiusScale = INTERPOLATOR.GetInterpolation (pct);
				canvas.Scale(radiusScale, radiusScale);
				canvas.DrawCircle(0, 0, cx, mPaint);
				canvas.Restore();
			}
Beispiel #14
0
		protected bool prepare() {
			int width = mBlurredView.Width;
			int height = mBlurredView.Height;

			if (mBlurringCanvas == null || mDownsampleFactorChanged
				|| mBlurredViewWidth != width || mBlurredViewHeight != height) {
				mDownsampleFactorChanged = false;

				mBlurredViewWidth = width;
				mBlurredViewHeight = height;

				int scaledWidth = width / mDownsampleFactor;
				int scaledHeight = height / mDownsampleFactor;

				// The following manipulation is to avoid some RenderScript artifacts at the edge.
				scaledWidth = scaledWidth - scaledWidth % 4 + 4;
				scaledHeight = scaledHeight - scaledHeight % 4 + 4;

				if (mBlurredBitmap == null
					|| mBlurredBitmap.Width != scaledWidth
					|| mBlurredBitmap.Height != scaledHeight) {
					mBitmapToBlur = Bitmap.CreateBitmap(scaledWidth, scaledHeight,
						Bitmap.Config.Argb8888);
					if (mBitmapToBlur == null) {
						return false;
					}

					mBlurredBitmap = Bitmap.CreateBitmap(scaledWidth, scaledHeight,
						Bitmap.Config.Argb8888);
					if (mBlurredBitmap == null) {
						return false;
					}
				}

				mBlurringCanvas = new Canvas(mBitmapToBlur);
				mBlurringCanvas.Scale(1f / mDownsampleFactor, 1f / mDownsampleFactor);
				mBlurInput = Allocation.CreateFromBitmap(mRenderScript, mBitmapToBlur,
					Allocation.MipmapControl.MipmapNone,AllocationUsage.Script);
				mBlurOutput = Allocation.CreateTyped(mRenderScript, mBlurInput.Type);
			}
			return true;
		}
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);
            //TODO: Step 7 - Apply Gesture updates
            canvas.Save();
            canvas.Translate(_posX, _posY);
            canvas.Scale(_scaleFactor, _scaleFactor);

            _icon.Draw(canvas);

            canvas.Restore();
        }
Beispiel #16
0
        protected override void OnDraw(Canvas canvas)
        {
            canvas.DrawColor(Color.Transparent);
            var p = new Paint()
            {
                AntiAlias = true
            };
            SetLayerType(LayerType.Software, p);
            var now = SystemClock.UptimeMillis();
            if (movieStart == 0)
                movieStart = now;
            if (movie != null)
            {
                int dur = movie.Duration();
                if (dur == 0)
                    dur = 1000;
                var relTime = (int)((now - movieStart) % dur);
                movie.SetTime(relTime);
                var movieWidth = (float)movie.Width();
                var movieHeight = (float)movie.Height();
                var scale = 1.0f;
                if (movieWidth > movieHeight)
                {
                    scale = Width / movieWidth;
                    if (scale * movieHeight > Height)
                        scale = Height / movieHeight;
                }
                else
                {
                    scale = Height / movieHeight;
                    if (scale * movieWidth > Width)
                        scale = Height / movieWidth;
                }
                canvas.Scale(scale, scale);
                try
                {
                    movie.Draw(canvas, 0, 0, p);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("Exception thrown in OnDraw : {0}--{1}", ex.Message, ex.StackTrace);
                }

                if (playing)
                    Invalidate();
            }
        }
Beispiel #17
0
        public override void Draw(Canvas canvas)
        {
            base.Draw (canvas);
            DrawWater (canvas);

            var center = Width / 2;

            descPaint.GetTextBounds (desc, 0, desc.Length, bounds);
            canvas.DrawText (desc, center, padding + bounds.Height (), descPaint);

            var dt = prefs.GetDisplayDistance (Distance, strictValue: true);
            var unit = prefs.GetUnitForDistance (Distance);
            digitPaint.GetTextBounds (dt, 0, dt.Length, bounds);
            canvas.Save ();
            canvas.Scale (1 - currentEffect, (1 - currentEffect) * .4f + .6f, center, Height / 2);
            digitPaint.Alpha = (int)((1 - currentEffect) * 255);
            canvas.DrawText (dt, center, Height / 2 + bounds.Height () / 2, digitPaint);
            canvas.Restore ();

            canvas.DrawText (unit, center, Height - 1.2f * padding, unitPaint);
        }
 private void DrawPict(Canvas canvas, int x, int y, int w, int h, float sx, float sy)
 {
     canvas.Save ();
     canvas.Translate (x, y);
     canvas.ClipRect (0, 0, w, h);
     canvas.Scale (0.5f, 0.5f);
     canvas.Scale (sx, sy, w, h);
     canvas.DrawPicture (mPicture);
     canvas.Restore ();
 }
 public void TransformCanvas(Canvas canvas, float percentOpen)
 {
     canvas.Scale(percentOpen, 1, 0, 0);
 }
Beispiel #20
0
            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;
                            }
                        }

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

			canvas.Save ();
			canvas.Scale (.4f, .5f, Width / 2, Height / 2);
			DrawCross (canvas);
			canvas.Restore ();
		}
        protected override void OnDraw(Canvas canvas)
        {
            if (!_clockwise)
            {
                canvas.Scale(-1, 1, _arcRect.CenterX(), _arcRect.CenterY());
            }

            // Draw the arcs
            var arcStart = _startAngle + MAngleOffset + _arcRotation;
            var arcSweep = _sweepAngle;
            canvas.DrawArc(_arcRect, arcStart, arcSweep, false, _arcPaint);
            canvas.DrawArc(_arcRect, arcStart, _progressSweep, false,
                    _progressPaint);

            // Draw the thumb nail
            canvas.Translate(_translateX - _thumbXPos, _translateY - _thumbYPos);
            _thumb.Draw(canvas);
        }
Beispiel #23
0
		Bitmap GetImage (Color strokeColor, Color fillColor, System.Drawing.SizeF size, float scale, 
		                 bool shouldCrop = true, bool keepAspectRatio = true)
		{
			if (size.Width == 0 || size.Height == 0 || scale <= 0)
				return null;

			float uncroppedScale;
			RectF croppedRectangle = new RectF ();

			System.Drawing.PointF [] cachedPoints;

			if (shouldCrop && (cachedPoints = Points).Any ()) {
				croppedRectangle = getCroppedRectangle (cachedPoints);

				if (croppedRectangle.Left >= 5)
					croppedRectangle.Left -= 5;
				if (croppedRectangle.Right <= size.Width - 5)
					croppedRectangle.Right += 5;
				if (croppedRectangle.Top >= 5)
					croppedRectangle.Top -= 5;
				if (croppedRectangle.Bottom <= size.Height - 5)
					croppedRectangle.Bottom += 5;

				float scaleX = (croppedRectangle.Right - croppedRectangle.Left) / Width;
				float scaleY = (croppedRectangle.Bottom - croppedRectangle.Top) / Height;
				uncroppedScale = 1 / Math.Max (scaleX, scaleY);
			} else {
				uncroppedScale = scale;
			}

			Bitmap image;
			if (keepAspectRatio)
				image = Bitmap.CreateBitmap ((int)size.Width, (int)size.Height, 
					Bitmap.Config.Argb8888);
			else
				image = Bitmap.CreateBitmap ((int)(croppedRectangle.Width () * uncroppedScale), (int)(croppedRectangle.Height () * uncroppedScale),
					Bitmap.Config.Argb8888);
			Canvas canvas = new Canvas (image);
			canvas.Scale (uncroppedScale, uncroppedScale);

			DrawStrokesOnCanvas (canvas, strokeColor, fillColor, shouldCrop, croppedRectangle);

			return image;
		}
        public override void Draw(Canvas canvas)
        {
            _bounds = Bounds;
            canvas.ClipRect(_bounds);

            if (_reversed)
            {
                canvas.Translate(_bounds.Width(), 0);
                canvas.Scale(-1, 1);
            }

            DrawStrokes(canvas);
        }