Esempio n. 1
0
        public void DrawText(string text, ITextConfig config, API.SizeF textSize, API.SizeF baseSize,
                             int maxWidth, int height, float xOffset)
        {
            _height   = height;
            _text     = text;
            _config   = config;
            _maxWidth = maxWidth;
            IFont  font         = _config.Font;
            IBrush outlineBrush = _config.OutlineBrush;

            float left    = xOffset + _config.AlignX(textSize.Width, baseSize);
            float top     = _config.AlignY(_bitmap.Height, textSize.Height, baseSize);
            float centerX = left + _config.OutlineWidth / 2f;
            float centerY = top + _config.OutlineWidth / 2f;
            float right   = left + _config.OutlineWidth;
            float bottom  = top + _config.OutlineWidth;

            var gfx = _gfx;

            lock (GraphicsLocker)
            {
                if (_config.OutlineWidth > 0f)
                {
                    drawString(gfx, outlineBrush, left, top);
                    drawString(gfx, outlineBrush, centerX, top);
                    drawString(gfx, outlineBrush, right, top);

                    drawString(gfx, outlineBrush, left, centerY);
                    drawString(gfx, outlineBrush, right, centerY);

                    drawString(gfx, outlineBrush, left, bottom);
                    drawString(gfx, outlineBrush, centerX, bottom);
                    drawString(gfx, outlineBrush, right, bottom);
                }
                if (_config.ShadowBrush != null)
                {
                    drawString(gfx, _config.ShadowBrush, centerX + _config.ShadowOffsetX,
                               centerY + _config.ShadowOffsetY);
                }
                drawString(gfx, _config.Brush, centerX, centerY);
            }

            //This should be a better way to render the outline (DrawPath renders the outline, and FillPath renders the text)
            //but for some reason some lines are missing when we render like that, at least on the mac

            /*if (_outlineWidth > 0f)
             *          {
             *                  GraphicsPath path = new GraphicsPath ();
             *                  Pen outlinePen = new Pen (_outlineBrush, _outlineWidth) { LineJoin = LineJoin.Round };
             *                  path.AddString(_text, _font.FontFamily, (int)_font.Style, _font.Size, new Point (), new StringFormat ());
             *                  //gfx.ScaleTransform(1.3f, 1.35f);
             *                  gfx.DrawPath(outlinePen, path);
             *                  gfx.FillPath(_brush, path);
             *          }
             *          else
             *                  gfx.DrawString (_text, _font, _brush, 0f, 0f);*/
        }
		public void DrawText(string text, ITextConfig config, AGS.API.SizeF textSize, AGS.API.SizeF baseSize, 
			int maxWidth, int height, float xOffset)
		{
            _height = height;
			_text = text;
			_config = config;
			_maxWidth = maxWidth;
			IFont font = _config.Font;
			IBrush outlineBrush = _config.OutlineBrush;

            float left = xOffset + _config.AlignX(textSize.Width, baseSize);
			float top = _config.AlignY(_bitmap.Height, textSize.Height, baseSize);
			float centerX = left + _config.OutlineWidth / 2f;
			float centerY = top + _config.OutlineWidth / 2f;
			float right = left + _config.OutlineWidth;
			float bottom = top + _config.OutlineWidth;

            var gfx = _gfx;
            if (_config.OutlineWidth > 0f)
			{
				drawString(gfx, outlineBrush, left, top);
				drawString(gfx, outlineBrush, centerX, top);
				drawString(gfx, outlineBrush, right, top);

				drawString(gfx, outlineBrush, left, centerY);
				drawString(gfx, outlineBrush, right, centerY);

				drawString(gfx, outlineBrush, left, bottom);
				drawString(gfx, outlineBrush, centerX, bottom);
				drawString(gfx, outlineBrush, right, bottom);
			}
			if (_config.ShadowBrush != null)
			{
				drawString(gfx, _config.ShadowBrush, centerX + _config.ShadowOffsetX, 
					centerY + _config.ShadowOffsetY);
			}
			drawString(gfx, _config.Brush, centerX, centerY);
                
            //This should be a better way to render the outline (DrawPath renders the outline, and FillPath renders the text)
            //but for some reason some lines are missing when we render like that, at least on the mac
            /*if (_outlineWidth > 0f)
			{
				GraphicsPath path = new GraphicsPath ();
				Pen outlinePen = new Pen (_outlineBrush, _outlineWidth) { LineJoin = LineJoin.Round };
				path.AddString(_text, _font.FontFamily, (int)_font.Style, _font.Size, new Point (), new StringFormat ());
				//gfx.ScaleTransform(1.3f, 1.35f);
				gfx.DrawPath(outlinePen, path);
				gfx.FillPath(_brush, path);
			}
			else 
				gfx.DrawString (_text, _font, _brush, 0f, 0f);*/            
		}
Esempio n. 3
0
        public void DrawText(string text, ITextConfig config, SizeF textSize, SizeF baseSize, int maxWidth, int height, float xOffset)
        {
            _maxWidth = maxWidth;
            _height   = height;
            _config   = config;
            _text     = text;

            float left = xOffset + _config.AlignX(textSize.Width, baseSize);

            //Unlike desktop and android which start the bitmap from the top (and draws the text from the top),
            //in ios the bitmap starts from the bottom (and draws the text from the bottom), so we need to adjust
            //the value returned by _config.AlignY which assumes drawing from top.
            float topOfTextFromTopOfBitmap = _config.AlignY(_image.CGImage.Height, textSize.Height, baseSize);
            float bottom = _image.CGImage.Height - (topOfTextFromTopOfBitmap + textSize.Height);

            float centerX = left + _config.OutlineWidth / 2f;
            float centerY = bottom - _config.OutlineWidth / 2f;
            float right   = left + _config.OutlineWidth;
            float top     = bottom - _config.OutlineWidth;

            if (_config.OutlineWidth > 0f)
            {
                IBrush brush = _config.OutlineBrush;
                drawString(brush, left, top);
                drawString(brush, centerX, top);
                drawString(brush, right, top);

                drawString(brush, left, centerY);
                drawString(brush, right, centerY);

                drawString(brush, left, bottom);
                drawString(brush, centerX, bottom);
                drawString(brush, right, bottom);
            }
            if (_config.ShadowBrush != null)
            {
                drawString(_config.ShadowBrush, centerX + _config.ShadowOffsetX,
                           centerY + _config.ShadowOffsetY);
            }
            drawString(_config.Brush, centerX, centerY);
        }
        public void DrawText(string text, ITextConfig config, AGS.API.SizeF textSize, AGS.API.SizeF baseSize, int maxWidth, int height, float xOffset)
        {
            //_height = height; todo: support height
            _text     = text;
            _config   = config;
            _maxWidth = maxWidth;

            TextPaint paint = getPaint(_config.Brush);

            float centerX = xOffset + _config.AlignX(textSize.Width, baseSize);
            float centerY = _config.AlignY(_bitmap.Height, textSize.Height, baseSize);
            float left    = centerX - _config.OutlineWidth / 2f;
            float top     = centerY - _config.OutlineWidth / 2f;
            float right   = left + _config.OutlineWidth;
            float bottom  = top + _config.OutlineWidth;

            var canvas = _canvas;

            if (_config.OutlineWidth > 0f)
            {
                TextPaint         outlinePaint  = getPaint(_config.OutlineBrush);
                AndroidTextLayout outlineLayout = new AndroidTextLayout(outlinePaint);
                drawString(canvas, outlineLayout, left, top);
                drawString(canvas, outlineLayout, centerX, top);
                drawString(canvas, outlineLayout, right, top);

                drawString(canvas, outlineLayout, left, centerY);
                drawString(canvas, outlineLayout, right, centerY);

                drawString(canvas, outlineLayout, left, bottom);
                drawString(canvas, outlineLayout, centerX, bottom);
                drawString(canvas, outlineLayout, right, bottom);
            }
            if (_config.ShadowBrush != null)
            {
                TextPaint shadowPaint = getPaint(_config.ShadowBrush);
                drawString(canvas, new AndroidTextLayout(shadowPaint), centerX + _config.ShadowOffsetX,
                           centerY + _config.ShadowOffsetY);
            }
            drawString(canvas, new AndroidTextLayout(paint), centerX, centerY);
        }
		public void DrawText(string text, ITextConfig config, AGS.API.SizeF textSize, AGS.API.SizeF baseSize, int maxWidth, int height, float xOffset)
		{
			//_height = height; todo: support height
			_text = text;
			_config = config;
			_maxWidth = maxWidth;

			TextPaint paint = getPaint(_config.Brush);

			float left = xOffset + _config.AlignX(textSize.Width, baseSize);
			float top = _config.AlignY(_bitmap.Height, textSize.Height, baseSize);
			float centerX = left + _config.OutlineWidth / 2f;
			float centerY = top + _config.OutlineWidth / 2f;
			float right = left + _config.OutlineWidth;
			float bottom = top + _config.OutlineWidth;

            var canvas = _canvas;
			if (_config.OutlineWidth > 0f)
			{
				TextPaint outlinePaint = getPaint(_config.OutlineBrush);
				drawString(canvas, outlinePaint, left, top);
				drawString(canvas, outlinePaint, centerX, top);
				drawString(canvas, outlinePaint, right, top);

				drawString(canvas, outlinePaint, left, centerY);
				drawString(canvas, outlinePaint, right, centerY);

				drawString(canvas, outlinePaint, left, bottom);
				drawString(canvas, outlinePaint, centerX, bottom);
				drawString(canvas, outlinePaint, right, bottom);
			}
			if (_config.ShadowBrush != null)
			{
				TextPaint shadowPaint = getPaint(_config.ShadowBrush);
				drawString(canvas, shadowPaint, centerX + _config.ShadowOffsetX, 
					centerY + _config.ShadowOffsetY);
			}
			drawString(canvas, paint, centerX, centerY);
		}