Пример #1
0
            protected override void OnDraw(Canvas canvas)
            {
                canvas.DrawColor (Color.White);

                mPaint.SetTypeface (null);
                canvas.DrawText ("Default", 10, 100, mPaint);
                mPaint.SetTypeface (mFace);
                canvas.DrawText ("Custom", 10, 200, mPaint);
            }
Пример #2
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);
        }
Пример #3
0
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            TextPaint paint = Paint;

            paint.Color         = new Color(CurrentTextColor);
            paint.DrawableState = GetDrawableState();
            mViewWidth          = MeasuredWidth;
            String text = (String)this.Text;

            mLineY  = 0;
            mLineY += (int)TextSize;
            Layout layout = Layout;

            for (int i = 0; i < layout.LineCount; i++)
            {
                int    lineStart = layout.GetLineStart(i);
                int    lineEnd   = layout.GetLineEnd(i);
                String line      = text.Substring(lineStart, lineEnd - lineStart);

                float width = StaticLayout.GetDesiredWidth(text, lineStart, lineEnd, Paint);
                if (NeedScale(line))
                {
                    DrawScaledText(canvas, lineStart, line, width);
                }
                else
                {
                    canvas.DrawText(line, 0, mLineY, paint);
                }

                mLineY += LineHeight;
            }
        }
        public Bitmap GetBitmapMarker(Context mContext, int resourceId, string text)
        {
            Resources resources = mContext.Resources;
            float scale = resources.DisplayMetrics.Density;
            Bitmap bitmap = BitmapFactory.DecodeResource(resources, resourceId);

            Bitmap.Config bitmapConfig = bitmap.GetConfig();

            // set default bitmap config if none
            if (bitmapConfig == null)
                bitmapConfig = Bitmap.Config.Argb8888;

            bitmap = bitmap.Copy(bitmapConfig, true);

            Canvas canvas = new Canvas(bitmap);
            Paint paint = new Paint(PaintFlags.AntiAlias);
            paint.Color = global::Android.Graphics.Color.Black;
            paint.TextSize = ((int)(14 * scale));
            paint.SetShadowLayer(1f, 0f, 1f, global::Android.Graphics.Color.White);

            // draw text to the Canvas center
            Rect bounds = new Rect();
            paint.GetTextBounds(text, 0, text.Length, bounds);
            int x = (bitmap.Width - bounds.Width()) / 2;
            int y = (bitmap.Height + bounds.Height()) / 2 - 20;

            canvas.DrawText(text, x, y, paint);

            return bitmap;
        }
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            canvas.Save();

            canvas.Translate(_width, _height);
            canvas.Rotate(-90);

            TextPaint paint = this.Paint;

            //Android.Graphics.Color Colorr = Color.  //this.TextColors.DefaultColor;
            //
            //var defcolor = this.TextColors.DefaultColor;
            //var Redd = Color.GetRedComponent(defcolor);
            //var Blue = Color.GetBlueComponent(defcolor);
            //var Greenn = Color.GetGreenComponent(defcolor);
            //var Birlestir = Color.Rgb(Redd, Greenn, Blue);
            //ColorFilter cf = new PorterDuffColorFilter(Birlestir, PorterDuff.Mode.SrcAtop);
            //paint.SetColorFilter(cf);
            paint.Color = Color.White;
            String text = getTextt();

            paint.GetTextBounds(text, 0, text.Length, _bounds);
            canvas.DrawText(text, this.CompoundPaddingLeft, (_bounds.Height() - _width) / 2, paint);

            canvas.Restore();
        }
Пример #6
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);
        }
			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;
			}
Пример #8
0
 public override void Draw(Canvas canvas) {
     base.Draw(canvas);
     var paint = new Paint {
         Color = Color.White,
         TextSize = 40,
         AntiAlias = true
     };
     canvas.DrawText("Developers.IO", 100, 60, paint);
 }
Пример #9
0
		private void DrawScaledText(Canvas canvas, int lineStart, String line, float lineWidth) {
			float x = 0;
			if (IsFirstLineOfParagraph(lineStart, line)) {
				String blanks = "  ";
				canvas.DrawText(blanks, x, mLineY, Paint);
				float bw = StaticLayout.GetDesiredWidth(blanks, Paint);
				x += bw;

				line = line.Substring(3);
			}

			float d = (mViewWidth - lineWidth) / line.Length - 1;
			for (int i = 0; i < line.Length; i++) {
				String c = line[i].ToString();
				float cw = StaticLayout.GetDesiredWidth(c, Paint);
				canvas.DrawText(c, x, mLineY, Paint);
				x += cw + d;
			}
		}
Пример #10
0
		// Found at http://stackoverflow.com/questions/13884603/dynamic-button-text-size

		public override void Draw(Canvas canvas)
		{
			// let the ImageButton paint background as normal
			base.Draw(canvas);

			// draw the text
			// position is centered on width
			// and the baseline is calculated to be positioned from the
			// view bottom
			canvas.DrawText(((Button)Element).Text, _viewWidth/2, _viewHeight - _textBaseline, _textPaint);
		}
Пример #11
0
        private static void DrawDebugInfo(Canvas canvas, IEnumerable<ILayer> layers)
        {
            using (var paint = new Paint {TextSize = 40})
            {
                var lineCounter = 1;
                const float tabWidth = 40f;
                const float lineHeight = 40f;

                foreach (var layer in layers)
                {
                    canvas.DrawText(layer.ToString(), tabWidth, lineHeight*(lineCounter++), paint);

                    if (layer is ITileLayer)
                    {
                        var text = "Tiles in memory: " + (layer as ITileLayer).MemoryCache.TileCount.ToString(CultureInfo.InvariantCulture);
                        canvas.DrawText(text, tabWidth, lineHeight*(lineCounter++), paint);
                    }
                }
            }
        }
Пример #12
0
        protected override void OnDraw(Android.Graphics.Canvas canvas)
        {
            base.OnDraw(canvas);
            var _red = new Paint();

            _red.SetStyle(Paint.Style.Fill);
            _red.SetARGB(255, 255, 0, 0);
            var _green = new Paint();

            _green.SetStyle(Paint.Style.Fill);
            _green.SetARGB(255, 0, 255, 0);


            int presetsDrawn = 1;

            for (int c = 0; c < _columns; c++)
            {
                var row  = ((float)_presets / (float)_columns);
                var rows = Math.Round(row, MidpointRounding.AwayFromZero);
                for (int r = 0; r < rows; r++)
                {
                    var x         = _columnWidth / 2 + _columnWidth * c;
                    var y         = _rowHeight / 2 + _rowHeight * r;
                    var radius    = _rowHeight / 2;
                    var diameter  = (_rowHeight / 4) * 3;
                    var xDrawable = (x) - (diameter / 2);
                    var yDrawable = (y) - (diameter / 2);


                    radius /= 2;
                    if (presetsDrawn <= _presets)
                    {
                        //Draw Buttons
                        if (_selectedPreset == GetPresetFromColumnAndRow(c, r))
                        {
                            white.SetBounds(xDrawable, yDrawable + _padding, xDrawable + diameter, yDrawable + _padding + diameter);
                            white.Draw(canvas);
                        }
                        else
                        {
                            green.SetBounds(xDrawable, yDrawable + _padding, xDrawable + diameter, yDrawable + _padding + diameter);
                            green.Draw(canvas);
                        }


                        //Draw Text
                        var text   = GetPresetFromColumnAndRow(c, r).ToString();
                        var offset = ((textPaint.Descent() + textPaint.Ascent()) / 2);
                        canvas.DrawText(text, x, y - offset + _padding, textPaint);
                        presetsDrawn++;
                    }
                }
            }
        }
Пример #13
0
 public override void Draw(Canvas canvas)
 {
     Rect bounds = Bounds;
     int height = bounds.Height();
     paint.TextSize = height;
     Rect textBounds = new Rect();
     string textValue = icon.Character.ToString();
     paint.GetTextBounds(textValue, 0, 1, textBounds);
     int textHeight = textBounds.Height();
     float textBottom = bounds.Top + (height - textHeight) / 2f + textHeight - textBounds.Bottom;
     canvas.DrawText(textValue, bounds.ExactCenterX(), textBottom, paint);
 }
Пример #14
0
        private void DrawLoadingText(Android.Graphics.Canvas canvas, float offset)
        {
            // TODO Perhaps replace with an animation later on?
            Paint paint = new Paint();

            paint.Color = Xamarin.Forms.Color.Black.ToAndroid();
            paint.SetStyle(Paint.Style.Fill);
            paint.TextSize = 50;
            var textWidth = paint.MeasureText(Element.ImageLoadingText);

            canvas.DrawText(Element.ImageLoadingText, this._halfWidth - (textWidth / 2) + _swipeCurrectXOffset + offset, this._halfHeight, paint);
        }
Пример #15
0
        public override void Draw (Canvas canvas)
        {
            base.Draw (canvas);

            var circleX = canvas.Width /2 - CircleShape.MinimumWidth /4;
            var circleY = canvas.Height /2 - CircleShape.MinimumHeight;
            CircleShape.SetBounds (circleX, circleY, circleX + CircleShape.MinimumWidth, circleY + CircleShape.MinimumHeight);
            CircleShape.Draw (canvas);

            LabelPaint.GetTextBounds (BubbleText, 0, BubbleText.Length, textBoundsRect);
            canvas.DrawText (BubbleText,
                             circleX + CircleShape.MinimumWidth /2 - textBoundsRect.Width () /2,
                             (canvas.Height - textBoundsRect.Height ())/2, LabelPaint);
        }
Пример #16
0
		private void drawString(Canvas gfx, TextPaint paint, float x, float y)
		{
			if (_maxWidth == int.MaxValue)
			{
				gfx.DrawText(_text, x, y, paint);
			}
			else
			{
				paint.TextAlign = alignWrap();
				StaticLayout layout = new StaticLayout (_text, paint, _maxWidth, Layout.Alignment.AlignNormal, 1f, 0f, false);
				gfx.Translate(x, y);
				layout.Draw(gfx);
				gfx.Translate(-x, -y);
			}
		}
Пример #17
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();
            }
        }
        public override void Draw(Canvas canvas, ICharSequence text, Int32 start, Int32 end, Single x, Int32 top, Int32 y, Int32 bottom, Paint paint)
        {
            ApplyCustomTypeFace(paint, _type);
            paint.GetTextBounds(_icon, 0, 1, TEXT_BOUNDS);
            canvas.Save();
            var baselineRatio = _baselineAligned ? 0f : BASELINE_RATIO;
            if (_rotate)
            {
                var rotation = (SystemClock.CurrentThreadTimeMillis() - _rotationStartTime) / (Single)ROTATION_DURATION * 360f;
                var centerX = x + TEXT_BOUNDS.Width() / 2f;
                var centerY = y - TEXT_BOUNDS.Height() / 2f + TEXT_BOUNDS.Height() * baselineRatio;
                canvas.Rotate(rotation, centerX, centerY);
            }

            canvas.DrawText(_icon, x - TEXT_BOUNDS.Left, y - TEXT_BOUNDS.Bottom + TEXT_BOUNDS.Height() * baselineRatio, paint);
            canvas.Restore();
        }
Пример #19
0
		public override void Draw (Canvas canvas)
		{
			child.Draw (canvas);
			if (count <= 0)
				return;
			badgePaint.Alpha = textPaint.Alpha = alpha;
			badgeBounds.Set (0, 0, Bounds.Width () / 2, Bounds.Height () / 2);
			canvas.DrawRoundRect (badgeBounds, 8, 8, badgePaint);
			textPaint.TextSize = (8 * badgeBounds.Height ()) / 10;
			var text = count.ToString ();
			textPaint.GetTextBounds (text, 0, text.Length, txtBounds);
			canvas.DrawText (
				text,
				badgeBounds.CenterX (),
				badgeBounds.Bottom - (badgeBounds.Height () - txtBounds.Height ()) / 2 - 1,
				textPaint
			);
		}
Пример #20
0
        public override void Draw(Canvas canvas, ICharSequence text, int start, int end, float x, int top, int y,
            int bottom, Paint paint)
        {
            ApplyCustomTypeFace(paint, _typeface);
            paint.GetTextBounds(_icon, 0, 1, TextBounds);
            canvas.Save();
            if (_rotate)
            {
                var rotation = (DateTimeHelpers.CurrentUnixTimeMillis() - _rotationStartTime)/(float) RotationDuration*
                               360f;
                var centerX = x + TextBounds.Width()/2f;
                var centerY = y - TextBounds.Height()/2f + TextBounds.Height()*BaselineRatio;
                canvas.Rotate(rotation, centerX, centerY);
            }

            canvas.DrawText(_icon, x - TextBounds.Left, y - TextBounds.Bottom + TextBounds.Height()*BaselineRatio,
                paint);
            canvas.Restore();
        }
Пример #21
0
        public override void Draw(Canvas canvas, ICharSequence text, int start, int end, float x, int top, int y, int bottom, Paint paint)
        {
            ApplyCustomTypeFace(paint, type);
            paint.GetTextBounds(icon, 0, 1, TEXT_BOUNDS);
            canvas.Save();
            float baselineRatio = baselineAligned ? 0f : BASELINE_RATIO;
            if (rotate)
            {
                long time = DateTime.Now.Ticks / TimeSpan.TicksPerMillisecond;
                float rotation = (time - rotationStartTime) / (float)ROTATION_DURATION * 360f;
                float centerX = x + TEXT_BOUNDS.Width() / 2f;
                float centerY = y - TEXT_BOUNDS.Height() / 2f + TEXT_BOUNDS.Height() * baselineRatio;
                canvas.Rotate(rotation, centerX, centerY);
            }

            canvas.DrawText(icon,
                    x - TEXT_BOUNDS.Left,
                    y - TEXT_BOUNDS.Bottom + TEXT_BOUNDS.Height() * baselineRatio, paint);
            canvas.Restore();
        }
Пример #22
0
        public Bitmap GetPin(float ratio, int number, int width, int height, float alpha = 1)
        {
            int key = number + ((int)(ratio * 10000)) << 6;
            Bitmap bmp;
            if (pinCache.TryGetValue (key, out bmp))
                return bmp;

            var svg = SVGParser.ParseSVGFromResource (context.Resources,
                                                      Resource.Raw.pin,
                                                      SvgColorMapperFactory.FromFunc (c => ColorReplacer (c, ratio, alpha)));
            bmp = Bitmap.CreateBitmap (width, height, Bitmap.Config.Argb8888);
            using (var c = new Canvas (bmp)) {
                var dst = new RectF (0, 0, width, height);
                c.DrawPicture (svg.Picture, dst);
                c.DrawText (number.ToString (), width / 2 - 1, 16.ToPixels (), textPaint);
            }

            pinCache [key] = bmp;
            return bmp;
        }
Пример #23
0
        public override void Draw(Android.Graphics.Canvas canvas)
        {
            base.Draw(canvas);

            _logic.DoDraw(canvas);

            canvas.DrawText(fps.ToString(), 100, 100, fpsPaint);

            if (drawCounter >= howOfhenMeasueFps)
            {
                var now          = DateTime.Now;
                var betweenDraws = now - _lastDraw;
                fps = (int)((float)(new TimeSpan(0, 0, 1).Ticks) / (((float)betweenDraws.Ticks) / (float)drawCounter));
                //Console.WriteLine ( "fps" + fps );

                _lastDraw   = now;
                drawCounter = 0;
            }

            drawCounter++;
        }
Пример #24
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);
        }
Пример #25
0
        protected override void Draw(Canvas canvas, Rect bounds)
        {
            int saveCount = canvas.Save();

            RectF arcBounds = mCurrentBounds;

            arcBounds.Set(bounds);

            //draw draw gas tube
            mPaint.Color = new Color(mGasTubeColor);
            mPaint.SetStyle(Paint.Style.Stroke);
            mPaint.StrokeWidth = mStrokeWidth;
            canvas.DrawPath(CreateGasTubePath(mGasTubeBounds), mPaint);

            //draw balloon
            mPaint.Color = new Color(mBalloonColor);
            mPaint.SetStyle(Paint.Style.FillAndStroke);
            canvas.DrawPath(CreateBalloonPath(mBalloonBounds, mProgress), mPaint);

            //draw progress
            mPaint.Color       = new Color(mGasTubeColor);
            mPaint.TextSize    = mTextSize;
            mPaint.StrokeWidth = mStrokeWidth / 5.0f;
            canvas.DrawText(mProgressText, arcBounds.CenterX() - mProgressBounds.Width() / 2.0f, mGasTubeBounds.CenterY() + mProgressBounds.Height() / 2.0f, mPaint);

            //draw cannula
            mPaint.Color = new Color(mCannulaColor);
            mPaint.SetStyle(Paint.Style.Stroke);
            mPaint.StrokeWidth = mStrokeWidth;
            canvas.DrawPath(CreateCannulaHeadPath(mCannulaBounds), mPaint);
            mPaint.SetStyle(Paint.Style.Fill);
            canvas.DrawPath(CreateCannulaBottomPath(mCannulaBounds), mPaint);

            //draw pipe body
            mPaint.Color = new Color(mPipeBodyColor);
            mPaint.SetStyle(Paint.Style.Fill);
            canvas.DrawRoundRect(mPipeBodyBounds, mRectCornerRadius, mRectCornerRadius, mPaint);

            canvas.RestoreToCount(saveCount);
        }
Пример #26
0
		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);
			}
		}
Пример #27
0
        public override void Draw(Android.Graphics.Canvas canvas)
        {
            canvas.DrawCircle(mainCenter, mainCenter + 2, radius + radiusBorder, shadowPaint);
            canvas.DrawCircle(mainCenter, mainCenter, radius + radiusBorder, darkerBackPaint);
            canvas.DrawCircle(mainCenter, mainCenter, radius, backPaint);
            canvas.DrawBitmap(icon, mainCenter - icon.Width / 2, mainCenter - icon.Height / 2, imgPaint);

            if (Count != 0)
            {
                int bubbleCenter = center - removeRadius - bubbleOffset;
                greenPaint.Alpha  = redPaint.Alpha = currentBubbleTransparency;
                removePaint.Alpha = 255 - currentBubbleTransparency;
                canvas.DrawCircle(bubbleCenter, bubbleCenter, removeRadius, removePaint);
                canvas.DrawCircle(bubbleCenter, bubbleCenter, innerRadius, Count < 0 ? redPaint : greenPaint);

                var c          = Math.Abs(Count).ToString();
                var textBounds = new Rect();
                removePaint.GetTextBounds(c, 0, c.Length, textBounds);

                canvas.DrawText(c, bubbleCenter, bubbleCenter + textBounds.Height() / 2, removePaint);
            }
            DrawingCacheEnabled = true;
        }
Пример #28
0
        public Size GetCharData(char c, out  UInt32[] cdata)
        {
            float height=(fontsize * 1.25f);
            int ih = (int)height;
            if ((height - ih) > 0) ih++;
            float width = paint.MeasureText(c.ToString());
            int iw = (int)width;
            if ((width - iw) > 0) iw++;

            //canvas.Restore();
            Bitmap bitmap = Bitmap.CreateBitmap(iw, ih, Bitmap.Config.Argb8888);
            Canvas canvas = new Canvas(bitmap);
            canvas.DrawColor(Android.Graphics.Color.Transparent);
            canvas.DrawText(c.ToString(), 0, fontsize, paint);

            cdata = new UInt32[iw * ih];
            int[] data = new int[iw * ih];
            bitmap.GetPixels(data, 0, iw, 0, 0, iw, ih);
            for (int i = 0; i < data.Length; i++)
            {
                cdata[i] = (uint)data[i];
            }
            return new Size(iw, ih);
        }
Пример #29
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);
            }
        }
Пример #30
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);
        }
Пример #31
0
        protected override void OnDraw(Canvas canvas)
        {
            if (!parmsSet)
                return;
            float border = 20;
            float horstart = border * 2;
            float height = Height;
            float width = Width - 1;
            float max = getMax();
            float min = getMin();
            float diff = max - min;
            float graphheight = height - (2 * border);
            float graphwidth = width - (2 * border);

            paint.TextAlign = Paint.Align.Left;
            int vers = verlabels.Length - 1;
            for (int i = 0; i < verlabels.Length; i++) {
                paint.Color = Color.DarkGray;
                float y = ((graphheight / vers) * i) + border;
                canvas.DrawLine(horstart, y, width, y, paint);
                paint.Color = Color.White;
                canvas.DrawText(verlabels[i], 0, y, paint);
            }
            int hors = horlabels.Length - 1;
            for (int i = 0; i < horlabels.Length; i++) {
                paint.Color = Color.DarkGray;
                float x = ((graphwidth / hors) * i) + horstart;
                canvas.DrawLine(x, height - border, x, border, paint);
                paint.TextAlign = Paint.Align.Center;
                if (i == horlabels.Length - 1)
                    paint.TextAlign = Paint.Align.Right;
                if (i == 0)
                    paint.TextAlign = Paint.Align.Left;
                paint.Color = Color.White;
                canvas.DrawText(horlabels[i], x, height - 4, paint);
            }

            paint.TextAlign = Paint.Align.Center;
            canvas.DrawText(title, (graphwidth / 2) + horstart, border - 4, paint);

            if (max != min) {
                paint.Color = Color.LightGray;
                if (type == BAR) {
                    float datalength = values.Length;
                    float colwidth = (width - (2 * border)) / datalength;
                    for (int i = 0; i < values.Length; i++) {
                        float val = values[i] - min;
                        float rat = val / diff;
                        float h = graphheight * rat;
                        canvas.DrawRect((i * colwidth) + horstart, (border - h) + graphheight, ((i * colwidth) + horstart) + (colwidth - 1), height - (border - 1), paint);
                    }
                } else {
                    float datalength = values.Length;
                    float colwidth = (width - (2 * border)) / datalength;
                    float halfcol = colwidth / 2;
                    float lasth = 0;
                    for (int i = 0; i < values.Length; i++) {
                        float val = values[i] - min;
                        float rat = val / diff;
                        float h = graphheight * rat;
                        if (i > 0)
                            canvas.DrawLine(((i - 1) * colwidth) + (horstart + 1) + halfcol, (border - lasth) + graphheight, (i * colwidth) + (horstart + 1) + halfcol, (border - h) + graphheight, paint);
                        lasth = h;
                    }
                }
            }
        }
            private void DrawIntoBitmap(Bitmap bm)
            {
                float x = bm.Width;
                float y = bm.Height;
                Canvas c = new Canvas (bm);
                Paint p = new Paint ();
                p.AntiAlias = true;

                p.Alpha = 0x80;
                c.DrawCircle (x / 2, y / 2, x / 2, p);

                p.Alpha = 0x30;
                p.SetXfermode (new PorterDuffXfermode (PorterDuff.Mode.Src));
                p.TextSize = 60;
                p.TextAlign = Paint.Align.Center;
                Paint.FontMetrics fm = p.GetFontMetrics ();
                c.DrawText ("Alpha", x / 2, (y - fm.Ascent) / 2, p);
            }
Пример #33
0
		private void drawPorcentajeOnCanvas(Canvas canvas)
		{
			base.OnDraw (canvas);

			canvas.Save ();

			canvas.DrawColor(Android.Graphics.Color.White);

			//Obtenemos el centro de nuesto canvas
			float x = this.MeasuredWidth / 2;
			float y = this.MeasuredHeight / 2;

			//Obtenemos el radio R1
			//Obtenemos el radio R2
			float R1 = 0;
			float R2 = 0;
			//if (canvas.Width < canvas.Height) {
			if (this.MeasuredWidth  < this.MeasuredHeight) {
				R1 = x;//Obtenemos el radio R1
				R2 = x-(x*por_rango/100);
			} else {
				R1 = y ;//Obtenemos el radio R1
				R2 = y-(y *por_rango/100);//Obtenemos el radio R2 que dejamos un 20% de margen

			}

			//Dibujamos el fondo de nuestro grafico que va ir creciendo de acuerdo al porcentaje descargado
			RectF rectF2 = new RectF(x-R1, y-R1,x+R1, y+R1);
			mPaintFondo.Color= Android.Graphics.Color.Rgb(19,184,213);

			int grados = 0;
			grados = 360 * porcentaje / 100;
			canvas.DrawArc(rectF2, 270, grados, true, mPaintFondo);

			//Fondo superior de nuestro texto
			mPaintSuperior.Color= Android.Graphics.Color.Rgb(50,58,69);
			canvas.DrawCircle(x,y , R2, mPaintSuperior);


			//Texto que nos indica el procentaje descargado
			mPaintTexto.SetTypeface (mFace);
			mPaintTexto.Color = Color.White;

			//Obtenemos el 30 % de radio de nuestro circulo de fondo, el cual sera el tamaño de letra utilzar;
			float MYTEXTSIZE = R2 *30/100;
			// Get the screen's density scale
			float scale = Application.Context.Resources.DisplayMetrics.Density;
			//Convert the dps to pixels, based on density scale
			int textSizePx = (int) (MYTEXTSIZE * scale + 0.5f);
			mPaintTexto.TextSize = textSizePx;

			//Obtenemos la posicion para centrar adecuadamente nuesto texto
			int xPos = (this.MeasuredWidth  / 2);
			int yPos = (int) ((this.MeasuredHeight / 2) - ((mPaintTexto.Descent() + mPaintTexto.Ascent()) / 2)) ; 

			string Texto_Porcentaje =porcentaje.ToString();
			canvas.DrawText (Texto_Porcentaje+" %", xPos,yPos, mPaintTexto);

			canvas.Restore();
		}
Пример #34
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);
        }
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

            if(null == _viewPager) return;

            var count = _viewPager.Adapter.Count;

            if(0 == count) return;

            if(-1 == _currentPage && _viewPager != null)
                _currentPage = _viewPager.CurrentItem;

            var bounds = CalculateAllBounds(_paintText);
            var boundsSize = bounds.Count;

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

            var countMinusOne = count - 1;
            var halfWidth = Width / 2f;
            var leftClip = Left + ClipPadding;
            var right = Left + Width;
            var rightClip = right - ClipPadding;
            var height = Height;
            var left = Left;

            var page = _currentPage;
            float offsetPercent;
            if(_pageOffset <= 0.5)
                offsetPercent = _pageOffset;
            else
            {
                page += 1;
                offsetPercent = 1 - _pageOffset;
            }

            var currentSelected = (offsetPercent <= SelectionFadePercentage);
            var currentBold = (offsetPercent <= BoldFadePercentage);
            var selectedPercent = (SelectionFadePercentage - offsetPercent) / SelectionFadePercentage;

            //Verify if the current view must be clipped to the screen
            var curPageBound = bounds[_currentPage];
            var curPageWidth = curPageBound.Right - curPageBound.Left;
            if(curPageBound.Left < leftClip)
                ClipViewOnTheLeft(curPageBound, curPageWidth, left);
            if(curPageBound.Right > rightClip)
                ClipViewOnTheRight(curPageBound, curPageWidth, right);

            //Left view is starting from the current position
            if(_currentPage > 0)
            {
                for(var i = _currentPage - 1; i >= 0; i--)
                {
                    var bound = bounds[i];
                    //Is left side outside the screen?
                    if(bound.Left < leftClip)
                    {
                        var w = bound.Right - bound.Left;
                        //Clip to the left screen side
                        ClipViewOnTheLeft(bound, w, left);

                        var rightBound = bounds[i + 1];
                        //Except if there is an intersection with the right view
                        if(bound.Right + TitlePadding > rightBound.Left)
                        {
                            bound.Left = (int)(rightBound.Left - w - TitlePadding);
                            bound.Right = bound.Left + w;
                        }
                    }
                }
            }

            //Right view is starting from the current position
            if(_currentPage < countMinusOne)
            {
                for(var i = _currentPage + 1; i < count; i++)
                {
                    var bound = bounds[i];
                    //Is right side outside the screen?
                    if(bound.Right > rightClip)
                    {
                        var w = bound.Right - bound.Left;
                        //Clip to the right screen side
                        ClipViewOnTheRight(bound, w, Right);

                        var leftBound = bounds[i - 1];
                        //Except if there is an intersection with the left view
                        if(bound.Left - TitlePadding < leftBound.Right)
                        {
                            bound.Left = (int)(leftBound.Right + TitlePadding);
                            bound.Right = bound.Left + w;
                        }
                    }
                }
            }

            //Now draw views!
            var colorTextAlpha = _colorText >> 24;
            for(var i = 0; i < count; i++)
            {
                //Get the title
                var bound = bounds[i];
                //Only if one side is visible
                if((bound.Left > left && bound.Left < right) || (bound.Right > left && bound.Right < right))
                {
                    var currentPage = (i == page);
                    var pageTitle = GetTitle(i);

                    //Only set bold if we are within bounds
                    _paintText.FakeBoldText = currentPage && currentBold && _boldText;

                    //Draw text as unselected
                    _paintText.Color = _colorText;
                    if(currentPage && currentSelected)
                        //Fade out/in unselected text as the selected text fades in/out
                        _paintText.Alpha = colorTextAlpha - (int)(colorTextAlpha * selectedPercent);

                    //Except if there is an intersection with the right view
                    if(i < boundsSize - 1)
                    {
                        var rightBound = bounds[i + 1];
                        if(bound.Right + TitlePadding > rightBound.Left)
                        {
                            var w = bound.Right - bound.Left;
                            bound.Left = (int)(rightBound.Left - w - TitlePadding);
                            bound.Right = bound.Left + w;
                        }
                    }
                    canvas.DrawText(pageTitle, 0, pageTitle.Length, bound.Left, bound.Bottom + TopPadding, _paintText);

                    //If we are within the selected bound draw the selected text
                    if(currentPage && currentSelected)
                    {
                        _paintText.Color = _colorSelected;
                        _paintText.Alpha = (int)((_colorSelected >> 24) * selectedPercent);
                        canvas.DrawText(pageTitle, 0, pageTitle.Length, bound.Left, bound.Bottom + TopPadding, _paintText);
                    }
                }
            }

            //If we want the line on the top change height to zero and invert line height to trick the drawing code
            var footerLineHeight = _footerLineHeight;
            var footerIndicatorLineHeight = _footerIndicatorHeight;
            if(_linePosition == LinePosition.Top)
            {
                height = 0;
                footerLineHeight = -footerLineHeight;
                footerIndicatorLineHeight = -footerIndicatorLineHeight;
            }

            //Draw the footer line
            _path.Reset();
            _path.MoveTo(0, height - footerLineHeight / 2f);
            _path.MoveTo(Width, height - footerLineHeight / 2f);
            _path.Close();
            canvas.DrawPath(_path, _paintFooterLine);

            var heightMinusLine = height - footerLineHeight;
            switch(_footerIndicatorStyle)
            {
                case IndicatorStyle.Triangle:
                    _path.Reset();
                    _path.MoveTo(halfWidth, heightMinusLine - footerIndicatorLineHeight);
                    _path.LineTo(halfWidth + footerIndicatorLineHeight, heightMinusLine);
                    _path.LineTo(halfWidth - footerIndicatorLineHeight, heightMinusLine);
                    _path.Close();
                    canvas.DrawPath(_path, _paintFooterIndicator);
                    break;
                case IndicatorStyle.Underline:
                    if(!currentSelected || page >= boundsSize)
                        break;

                    var underlineBounds = bounds[page];
                    var rightPlusPadding = underlineBounds.Right + _footerIndicatorUnderlinePadding;
                    var leftMinusPadding = underlineBounds.Left - _footerIndicatorUnderlinePadding;
                    var heightMinusLineMinusIndicator = heightMinusLine - footerIndicatorLineHeight;

                    _path.Reset();
                    _path.MoveTo(leftMinusPadding, heightMinusLine);
                    _path.LineTo(rightPlusPadding, heightMinusLine);
                    _path.LineTo(rightPlusPadding, heightMinusLineMinusIndicator);
                    _path.LineTo(leftMinusPadding, heightMinusLineMinusIndicator);
                    _path.Close();

                    _paintFooterIndicator.Alpha = (int)(0xFF * selectedPercent);
                    canvas.DrawPath(_path, _paintFooterIndicator);
                    _paintFooterIndicator.Alpha = 0xFF;
                    break;
            }
        }
Пример #36
0
        protected override void OnDraw(Canvas canvas)
        {
            base.OnDraw(canvas);

	        if (_indiagram == null)
	        {
		        return;
	        }

            canvas.DrawRect(_backgroundRect, _backgroundPainter);


			if (!_indiagram.IsEnabled) {
				_picturePainter.Alpha = 128;
			} else {
				_picturePainter.Alpha = 255;
			}
            //draw picture or a red rectangle if error with picture
            try
            {
                Bitmap image = ImageHelper.LoadImage(_indiagram.ImagePath, _pictureWidth, _pictureHeight);
                canvas.DrawBitmap(image, _marginLeft, _marginTop, _picturePainter);
            }
            catch (Exception)
            {
                canvas.DrawRect(_marginLeft, _marginTop, _pictureWidth + _marginLeft, _pictureHeight + _marginTop, _picturePainter);
            }

            if (!string.IsNullOrEmpty(_indiagram.Text))
            {
                //write text
                int yindex = _marginTop + _pictureHeight + SettingsService.FontSize;
                int xindex = _marginLeft + _pictureWidth / 2;
                string text = _indiagram.Text;

                if (_isOneLineText)
                {
                    canvas.DrawText(text, xindex, yindex, _textPainter);
                }
                else
                {
                    int txtOffset = 0;

                    while (txtOffset < text.Length)
                    {
                        int textSize = _textPainter.BreakText(text, txtOffset, text.Length, true, _pictureWidth, null);
                        string text2 = text.Substring(txtOffset, textSize);

                        canvas.DrawText(text2, xindex, yindex, _textPainter);

                        yindex += SettingsService.FontSize;
                        txtOffset += textSize;
                    }
                }
            }
        }
Пример #37
0
 protected void Draw(Canvas canvas)
 {
     canvas.DrawText(string.Format("{0}", mDayOfMonth), (mBound.CenterX() - dx), (mBound.CenterY() + dy), mPaint);
 }
Пример #38
0
 protected override void OnDraw(Canvas canvas)
 {
     base.OnDraw (canvas);
                 //create an instance of class Paint, set color and font size
                 var textPaint = new Paint {
                         AntiAlias = true,
                         Color = _textColor,
                         TextSize = _textSize };
                 //In order to show text in a middle, we need to know its size
                 var bounds = new Rect ();
                 textPaint.GetTextBounds (_text, 0, _text.Length, bounds);
                 //Now we store font size in bounds variable and can calculate it's position
                 var x = (Width / 2) - bounds.CenterX ();
                 var y = (Height / 2) - bounds.CenterY ();
                 //drawing text with appropriate color and size in the center
                 canvas.DrawText (_text, x, y, textPaint);
 }
			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;
			}