idTech4.UI.idDeviceContext.DrawText C# (CSharp) Метод

DrawText() приватный Метод

private DrawText ( float x, float y, float scale, Vector4 color, string text, float adjust, int limit, int style, int cursor ) : int
x float
y float
scale float
color Vector4
text string
adjust float
limit int
style int
cursor int
Результат int
		private int DrawText(float x, float y, float scale, Vector4 color, string text, float adjust, int limit, int style, int cursor)
		{
			SetFontByScale(scale);

			float useScale = scale * _currentFont.GlyphScale;
			int count = 0;
			idFontGlyph glyph;

			if((text != string.Empty) && (color.W != 0.0f))
			{
				char c, c2;
				int textPosition = 0;
				int length = text.Length;
				Vector4 newColor = color;

				idE.RenderSystem.Color = color;

				if((limit > 0) && (length > limit))
				{
					length = limit;
				}

				while(((c = idHelper.GetBufferCharacter(text, textPosition)) != '\0') && (count < length))
				{
					if((c < idE.GlyphStart) || (c > idE.GlyphEnd))
					{
						textPosition++;
						c = idHelper.GetBufferCharacter(text, textPosition);

						continue;
					}

					glyph = _currentFont.Glyphs[c];

					if(idHelper.IsColor(text, textPosition) == true)
					{
						c2 = idHelper.GetBufferCharacter(text, textPosition + 1);

						if(c2 == (int) idColorIndex.Default)
						{
							newColor = color;
						}
						else
						{
							newColor = idHelper.ColorForIndex(c2);
						}

						if((cursor == count) || (cursor == (count + 1)))
						{
							float partialSkip = ((glyph.SkipX * useScale) + adjust) / 5.0f;

							if(cursor == count)
							{
								partialSkip *= 2.0f;
							}
							else
							{
								idE.RenderSystem.Color = newColor;
							}

							// TODO: DrawEditCursor(x - partialSkip, y, scale);
						}

						idE.RenderSystem.Color = newColor;

						textPosition += 2;
						count += 2;
						c = idHelper.GetBufferCharacter(text, textPosition);

						continue;
					}
					else
					{
						float adjustY = useScale * glyph.Top;

						PaintCharacter(x, y - adjustY, glyph.ImageWidth, glyph.ImageHeight, useScale, glyph.S, glyph.T, glyph.S2, glyph.T2, glyph.Glyph);


						/* TODO: if(cursor == count)
						{
							// TODO: DrawEditCursor(x, y, scale);
						}*/

						x += (glyph.SkipX * useScale) + adjust;
						textPosition++;
						count++;
						c = idHelper.GetBufferCharacter(text, textPosition);
					}
				}

				if(cursor == length)
				{
					// TODO: DrawEditCursor(x, y, scale);
				}
			}

			return count;
		}

Same methods

idDeviceContext::DrawText ( string text, float textScale, TextAlign textAlign, Vector4 color, idRectangle rectDraw, bool wrap, int cursor = -1, bool calcOnly = false, List breaks = null, int limit ) : int

Usage Example

Пример #1
0
        public void Draw(float x, float y)
        {
            if (_visible == false)
            {
                return;
            }

            CalculateClientRectangle(0, 0);

            _context.FontFamily = _fontFamily;

            _drawRect.Offset(x, y);
            _clientRect.Offset(x, y);
            _textRect.Offset(x, y);

            SetupTransforms(x, y);

            if ((_flags & WindowFlags.NoClip) == WindowFlags.NoClip)
            {
                _context.ClippingEnabled = false;
            }

            DrawBackground(_drawRect);
            DrawBorderAndCaption(_drawRect);

            if (_textShadow > 0)
            {
                string shadowText = idHelper.RemoveColors(_text);

                idRectangle shadowRect = _textRect;
                shadowRect.X += _textShadow;
                shadowRect.Y += _textShadow;

                _context.DrawText(shadowText, _textScale, _textAlign, idColor.Black, shadowRect, (_flags & WindowFlags.NoWrap) == 0, -1);
            }

            _context.DrawText(_text, _textScale, _textAlign, _foreColor, _textRect, (_flags & WindowFlags.NoWrap) == 0, -1);
            _context.SetTransformInformation(Vector3.Zero, Matrix.Identity);

            if ((_flags & WindowFlags.NoClip) == WindowFlags.NoClip)
            {
                _context.ClippingEnabled = true;
            }

            _drawRect.Offset(-x, -y);
            _clientRect.Offset(-x, -y);
            _textRect.Offset(-x, -y);
        }