public static void MeasureText(Font fnt, string text, ref float textwidth, ref float textheight, int fontSize) { if (text[0] == ' ') // anti-trim { text = "_" + text.Substring(1); } if (text[text.Length - 1] == ' ') { text = text.Substring(0, text.Length - 1) + '_'; } // Text drawing doesnt work with DX9Ex & sprite if (GUIGraphicsContext.IsDirectX9ExUsed()) { MeasureText(text, ref textwidth, ref textheight, fontSize); } else { if (_sprite == null) { _sprite = new Sprite(GUIGraphicsContext.DX9Device); } Rectangle rect = fnt.MeasureString(_sprite, text, DrawTextFormat.NoClip, Color.Black); textwidth = rect.Width; textheight = rect.Height; } }
public static void Present() { lock (Renderlock) { DXNative.FontEnginePresentTexturesSync(); foreach (GUIFont font in ListFonts) { font.Present(); } if (_spriteUsed) { if (_sprite == null) { _sprite = new Sprite(GUIGraphicsContext.DX9Device); } _sprite.Begin(SpriteFlags.AlphaBlend | SpriteFlags.SortTexture); Viewport orgView = GUIGraphicsContext.DX9Device.Viewport; Matrix orgProj = GUIGraphicsContext.DX9Device.Transform.View; Matrix projm = orgProj; foreach (FontManagerDrawText draw in _listDrawText) { Matrix finalm; finalm.M11 = draw.Matrix[0, 0]; finalm.M21 = draw.Matrix[0, 1]; finalm.M31 = draw.Matrix[0, 2]; finalm.M41 = draw.Matrix[0, 3]; finalm.M12 = draw.Matrix[1, 0]; finalm.M22 = draw.Matrix[1, 1]; finalm.M32 = draw.Matrix[1, 2]; finalm.M42 = draw.Matrix[1, 3]; finalm.M13 = draw.Matrix[2, 0]; finalm.M23 = draw.Matrix[2, 1]; finalm.M33 = draw.Matrix[2, 2]; finalm.M43 = draw.Matrix[2, 3]; finalm.M14 = 0; finalm.M24 = 0; finalm.M34 = 0; finalm.M44 = 1.0f; _sprite.Transform = finalm; GUIGraphicsContext.DX9Device.Viewport = draw.Viewport; float wfactor = (float)orgView.Width / draw.Viewport.Width; float hfactor = (float)orgView.Height / draw.Viewport.Height; float xoffset = (float)orgView.X - draw.Viewport.X; float yoffset = (float)orgView.Y - draw.Viewport.Y; projm.M11 = (orgProj.M11 + orgProj.M14 * xoffset) * wfactor; projm.M21 = (orgProj.M21 + orgProj.M24 * xoffset) * wfactor; projm.M31 = (orgProj.M31 + orgProj.M34 * xoffset) * wfactor; projm.M41 = (orgProj.M41 + orgProj.M44 * xoffset) * wfactor; projm.M12 = (orgProj.M12 + orgProj.M14 * yoffset) * hfactor; projm.M22 = (orgProj.M22 + orgProj.M24 * yoffset) * hfactor; projm.M32 = (orgProj.M32 + orgProj.M34 * yoffset) * hfactor; projm.M42 = (orgProj.M42 + orgProj.M44 * yoffset) * hfactor; GUIGraphicsContext.DX9Device.Transform.View = projm; if (GUIGraphicsContext.IsDirectX9ExUsed()) { DrawTextUsingTexture(draw, draw.FontHeight); } else { draw.Fnt.DrawText(_sprite, draw.Text, new Rectangle((int)draw.Xpos, (int)draw.Ypos, 0, 0), DrawTextFormat.NoClip, draw.Color); } _sprite.Flush(); } GUIGraphicsContext.DX9Device.Viewport = orgView; GUIGraphicsContext.DX9Device.Transform.View = orgProj; _sprite.End(); _listDrawText = new List <FontManagerDrawText>(); _spriteUsed = false; } } }