/// <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 DXImage GetImageForImageElement(ImageElement element) { DXImage result = null; if (!this.ImageCache.TryGetValue(element, out result)) { result = new DXImage(this.Device, this.DeviceContext); result.Initialize(element.Bitmap); this.ImageCache[element] = result; } return(result); }
public void DrawImage(Int32 x, Int32 y, Single scale, Single angle, System.Drawing.Color?color, DXImage image) { Debug.Assert(this.Initialized, "Ensure initalized"); 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(image.GetSRV()); this.Draw(new RawRectangle(x, y, (Int32)(scale * image.Width), (Int32)(scale * image.Height)), new RawRectangle(0, 0, image.Width, image.Height), color.HasValue ? ToColor4(color.Value) : new RawColor4(), 1.0f, angle); this.EndBatch(); this.DeviceContext.OutputMerger.SetBlendState(backupBlendState, backupBlendFactor, backupMask); } }