/// <summary> /// Draw the overlay(s) /// </summary> public void Draw() { if (!_initialised) { return; } Begin(); lock (_hook._overlayLock) foreach (var overlay in Overlays) { foreach (var element in overlay.Elements) { if (element.Hidden) { continue; } var textElement = element as TextElement; var imageElement = element as ImageElement; if (textElement != null) { DXFont font = GetFontForTextElement(textElement); if (font != null && !String.IsNullOrEmpty(textElement.Text)) { _spriteEngine.DrawString(textElement.Location.X, textElement.Location.Y, textElement.Text, textElement.Color, font); } } else if (imageElement != null) { lock (_imageCache) { DXImage image = GetImageForImageElement(imageElement); if (image != null) { _spriteEngine.DrawImage(imageElement.Location.X, imageElement.Location.Y, imageElement.Scale, imageElement.Angle, imageElement.Tint, image); } } } } } End(); }
public void DrawImage(int x, int y, float scale, float angle, System.Drawing.Color?color, DXImage image) { //Debug.Assert(_initialized); if (!_initialized) { return; } Color4 blendFactor = new Color4(1.0f); Color4 backupBlendFactor; int backupMask; using (var backupBlendState = _deviceContext.OutputMerger.GetBlendState(out backupBlendFactor, out backupMask)) { _deviceContext.OutputMerger.SetBlendState(_transparentBS, blendFactor); try { BeginBatch(image.GetSRV()); Draw(new Rectangle(x, y, (int)(scale * image.Width), (int)(scale * image.Height)), new Rectangle(0, 0, image.Width, image.Height), color.HasValue ? ToColor4(color.Value) : Color4.White, 1.0f, angle); } finally { EndBatch(); } _deviceContext.OutputMerger.SetBlendState(backupBlendState, backupBlendFactor, backupMask); } }