protected override void OnGotContext(RenderContext context) { base.OnGotContext(context); var fps = Game.AsTheaterDays().FindSingleElement <FpsOverlay>(); var fpsHeight = fps != null ? (int)DirectWriteHelper.PointToDip(fps.FontSize) : 0; var clientSize = context.ClientSize; Location = new Point(clientSize.Width - 80, fpsHeight); }
protected override void OnGotContext(RenderContext context) { base.OnGotContext(context); var fontPath = Path.GetFullPath(GetFontFilePath()); var familyName = DirectWriteHelper.GetFontFamilyName(fontPath); _font = new D2DFont(context.DirectWriteFactory, familyName, FontSize, FontStyle.Regular, 10); _textBrush = new D2DSolidBrush(context, FillColor); }
protected override void OnGotContext(RenderContext context) { base.OnGotContext(context); var fontPath = Path.GetFullPath(GetFontFilePath()); var familyName = DirectWriteHelper.GetFontFamilyName(fontPath); _font = new D2DFont(context.DirectWriteFactory, familyName, FontSize, FontStyle.Regular, 10); _textFill = new D2DSolidBrush(context, FillColor); _textStroke = new D2DPen(context, StrokeColor, StrokeWidth); _fontFile = new FontFile(context.DirectWriteFactory, fontPath); _fontFace = new FontFace(context.DirectWriteFactory, FontFaceType.OpenTypeCollection, new[] { _fontFile }, 0, FontSimulations.None); _glyphRun = new GlyphRun { FontFace = _fontFace, FontSize = FontSize }; RegenerateFontPath(context); }
protected override void OnDraw(GameTime gameTime, RenderContext context) { base.OnDraw(gameTime, context); var text = Text; if (!string.IsNullOrWhiteSpace(text)) { var textSize = DirectWriteHelper.MeasureText(context.DirectWriteFactory, text, _font); var lineHeight = DirectWriteHelper.PointToDip(FontSize); OnBeforeTextRendering(context, textSize, lineHeight); var location = Location; context.Begin2D(); context.DrawText(text, _textBrush, _font, location.X, location.Y); context.End2D(); } }
private void Initialize(RenderContext context, string text, D2DFont d2dFont, FontFace fontFace) { Text = text; D2DFont = d2dFont; FontFace = fontFace; var fontSizeInEm = DirectWriteHelper.PointToDip(d2dFont.Size); LineHeight = fontSizeInEm; if (text.IndexOf('\n') >= 0) { var processedText = text.Replace("\r", string.Empty); var lines = processedText.Split('\n'); _pathDataArray = new D2DPathData[lines.Length]; _lineHeights = new float[lines.Length]; for (var i = 0; i < lines.Length; ++i) { var line = lines[i]; if (!string.IsNullOrWhiteSpace(line)) { var pathData = GetPathData(context, line, fontFace, fontSizeInEm); _pathDataArray[i] = pathData; } _lineHeights[i] = fontSizeInEm; } } else { var pathData = GetPathData(context, text, fontFace, fontSizeInEm); _pathDataArray = new[] { pathData }; _lineHeights = new[] { fontSizeInEm }; } }
public static SizeF MeasureText(this RenderContext context, string text, D2DFont font, float maxWidth, float maxHeight) { return(DirectWriteHelper.MeasureText(context.DirectWriteFactory, text, font, maxWidth, maxHeight)); }