コード例 #1
0
        //UPDATE: Return text limit
        private float DrawText(Canvas canvas, Paint paint,
                               string text, Paint.Align align, Color color, float offset,
                               RectF holderRect, Rect textRect)
        {
            paint.Color     = color;
            paint.TextAlign = align;
            paint.GetTextBounds(text, 0, text.Length, textRect);
            var   textWidth  = paint.MeasureText(text, 0, text.Length);
            float textLimitX = -1;

            float x = 0.0f;

            if (align == Paint.Align.Left) //Draw startText
            {
                x          = offset;
                textLimitX = x + textWidth;
            }
            else if (align == Paint.Align.Center)
            {
                x = holderRect.CenterX();
            }
            else if (align == Paint.Align.Right) //Draw endText
            {
                x          = holderRect.Right - offset;
                textLimitX = x - textWidth;
            }

            var y = holderRect.CenterY() + textRect.Height() / 2f - textRect.Bottom;

            canvas.DrawText(text.ToCharArray(), 0, text.Length, x, y, paint);

            return(textLimitX);
        }
コード例 #2
0
ファイル: DailyGraphView.cs プロジェクト: ihatead/XWeather
        void drawLabel(Canvas canvas, float xCoord, float yCoord, Paint.Align alignment, string label, bool centerVertical = false)
        {
            var fontColor = Color.White;

            var textPaint = new TextPaint();

            textPaint.Color = fontColor;

            textPaint.TextSize = fontSize;

            textPaint.TextAlign = alignment;

            textPaint.SetStyle(Paint.Style.Stroke);


            var frame = new Rect();

            textPaint.GetTextBounds(label, 0, label.Length, frame);

            if (centerVertical)
            {
                yCoord -= frame.CenterY();
            }
            else
            {
                yCoord += frame.Height();
            }

            canvas.DrawText(label, xCoord, yCoord, textPaint);
        }
コード例 #3
0
ファイル: GameField.cs プロジェクト: entdark/ColorLinesNG
 public CLLabel(string text, float textSize, float x, float y, float width, float height, Paint.Align align, Color textColour, float textInterval = 1.337f)
 {
     this.text         = text;
     this.x            = x;
     this.y            = y;
     this.width        = width;
     this.height       = height;
     this.textSize     = textSize;
     this.align        = align;
     this.textColour   = textColour;
     this.textInterval = textInterval;
 }
コード例 #4
0
        public void DrawString(Canvas gfx, string text, float x, float y, Paint.Align align, int maxWidth = 2147483647)
        {
            y = y + _metrics.LineHeight;
            if (maxWidth != int.MaxValue)
            {
                _paint.TextAlign = align;
            }

            int index  = 0;
            int length = text.Length;

            while (index < length)
            {
                string line = getNextLine(text, length, maxWidth, ref index);
                if (index >= length - 1)
                {
                    y -= _metrics.Descent;
                }
                gfx.DrawText(line, x, y, _paint);
                y += _metrics.LineHeight;
            }
        }
コード例 #5
0
ファイル: Renderer.cs プロジェクト: entdark/ColorLinesNG
 public CLReLabelEntity(string text, float x, float y, float size, Color colour, Paint.Align align, float textInterval)
 {
     this.text            = text;
     this.x               = x;
     this.y               = y;
     this.textInterval    = textInterval;
     this.paint           = new Paint(PaintFlags.AntiAlias);
     this.paint.TextSize  = size * 50;
     this.paint.Color     = colour;
     this.paint.TextAlign = align;
 }
コード例 #6
0
ファイル: Renderer.cs プロジェクト: entdark/ColorLinesNG
 public static void Text(string text, float x, float y, float size, Color colour, Paint.Align align, float textInterval = 1.337f)
 {
     CLReQueue.AddToQueue(new CLReLabelEntity(text, x, y, size, colour, align, textInterval));
 }