/// <summary> /// Draw the overlay(s) /// </summary> public void Draw() { this.EnsureInitiliazed(); this.Begin(); dynamic element = null; TextElement textElement = element as TextElement; ImageElement imageElement = element as ImageElement; if (textElement != null) { DXFont font = this.GetFontForTextElement(textElement); if (font != null && !String.IsNullOrEmpty(textElement.Text)) { this.SpriteEngine.DrawString(textElement.Location.X, textElement.Location.Y, textElement.Text, textElement.Color, font); } } else if (imageElement != null) { DXImage image = this.GetImageForImageElement(imageElement); if (image != null) { this.SpriteEngine.DrawImage(imageElement.Location.X, imageElement.Location.Y, imageElement.Scale, imageElement.Angle, System.Drawing.Color.White, image); } } this.End(); }
private DXFont GetFontForTextElement(TextElement element) { DXFont result = null; String fontKey = String.Format("{0}{1}{2}", element.Font.Name, element.Font.Size, element.Font.Style, true); if (!this.FontCache.TryGetValue(fontKey, out result)) { result = new DXFont(this.Device, this.DeviceContext); result.Initialize(element.Font.Name, element.Font.Size, element.Font.Style, true); this.FontCache[fontKey] = result; } return(result); }
public void DrawString(Int32 x, Int32 y, String text, System.Drawing.Color color, DXFont font) { RawColor4 blendFactor = new RawColor4(1.0f, 1.0f, 1.0f, 1.0f); RawColor4 backupBlendFactor; Int32 backupMask; using (BlendState backupBlendState = DeviceContext.OutputMerger.GetBlendState(out backupBlendFactor, out backupMask)) { this.DeviceContext.OutputMerger.SetBlendState(this.TransparentBlendState, blendFactor); this.BeginBatch(font.GetFontSheetSRV()); Int32 length = text.Length; Int32 positionX = x; Int32 positionY = y; RawColor4 color4 = ToColor4(color); for (Int32 index = 0; index < length; ++index) { Char character = text[index]; if (character == ' ') { positionX += font.GetSpaceWidth(); } else if (character == '\n') { positionX = x; positionY += font.GetCharHeight(); } else { RawRectangle charRectangle = font.GetCharRect(character); Int32 width = charRectangle.Right - charRectangle.Left; Int32 height = charRectangle.Bottom - charRectangle.Top; this.Draw(new RawRectangle(positionX, positionY, width, height), charRectangle, color4); positionX += width + 1; } } this.EndBatch(); this.DeviceContext.OutputMerger.SetBlendState(backupBlendState, backupBlendFactor, backupMask); } }