/// <summary> /// Draws a string using a transformation matrix /// </summary> /// <param name="deviceContext">A valid dirct3d11 device context</param> /// <param name="s">String to draw</param> /// <param name="fontSize">Font size</param> /// <param name="color">Color</param> /// <param name="flags">Draw flags</param> /// <param name="fontFamily">Font family</param> /// <param name="transform">A 3d transformation</param> public void DrawString(DeviceContext deviceContext, string s, string fontFamily, float fontSize, Matrix transform, Color4 color, TextFlags flags) { IntPtr clipRectanglePtr = IntPtr.Zero; SharpDX.Mathematics.Interop.RawRectangleF emptyRect = new SharpDX.Mathematics.Interop.RawRectangleF(0.0f, 0.0f, 0.0f, 0.0f); this.DrawString(deviceContext, s, fontFamily, fontSize, emptyRect, color.ToRgba(), IntPtr.Zero, new IntPtr(&transform), flags); }
public void DrawImage(Object image, System.Drawing.RectangleF srcRect, System.Drawing.RectangleF destRect) { if (image is SharpDX.Direct2D1.Bitmap) { SharpDX.Direct2D1.Bitmap bImg = (SharpDX.Direct2D1.Bitmap)image; if (!bImg.IsDisposed) { SharpDX.Mathematics.Interop.RawRectangleF src = new SharpDX.Mathematics.Interop.RawRectangleF { Top = srcRect.Top, Left = srcRect.Left, Bottom = srcRect.Bottom, Right = srcRect.Width }; SharpDX.Mathematics.Interop.RawRectangleF dest = new SharpDX.Mathematics.Interop.RawRectangleF { Top = destRect.Top, Left = destRect.Left, Bottom = destRect.Bottom, Right = destRect.Right }; d2dRenderTarget.DrawBitmap(bImg, dest, 1.0f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear, src); } // Endif image is not disposed } // Endif image is DirectX Bitmap }
private void DrawInventoryIcon(InventoryEntry entry, int offsetX, int offsetY) { int imageX = offsetX + entry.SlotColumn * ICON_SLOT_WIDTH; int imageY = offsetY + entry.SlotRow * ICON_SLOT_HEIGHT; SharpDX.Mathematics.Interop.RawRectangleF drawRegion = new SharpDX.Mathematics.Interop.RawRectangleF(imageX, imageY, ICON_SLOT_WIDTH, ICON_SLOT_HEIGHT); SharpDX.Mathematics.Interop.RawRectangleF imageRegion; if (_inventoryToImageTranslation.ContainsKey(entry.Type)) { imageRegion = _inventoryToImageTranslation[entry.Type]; } else { imageRegion = new SharpDX.Mathematics.Interop.RawRectangleF(0, 0, ICON_SLOT_WIDTH, ICON_SLOT_HEIGHT); } imageRegion.Right += imageRegion.Left; imageRegion.Bottom += imageRegion.Top; drawRegion.Right += drawRegion.Left; drawRegion.Bottom += drawRegion.Top; if (_inventoryToImageTranslation.ContainsKey(entry.Type)) { _device.DrawBitmap(_inventorySheet, drawRegion, (float)Config.Opacity / 255, SharpDX.Direct2D1.BitmapInterpolationMode.Linear, imageRegion); } if (entry.HasQuantity) { Point textSize = _graphics.MeasureString(_consolas16Bold, entry.Quantity.ToString()); _graphics.DrawText(_consolas16Bold, _white, imageX, imageY + ICON_SLOT_HEIGHT - textSize.Y, entry.Quantity.ToString()); } }
public void DrawText(String message, String fontFamily, float fontSize, System.Drawing.Color clr, System.Drawing.Rectangle area) { SharpDX.DirectWrite.TextFormat fmt = new SharpDX.DirectWrite.TextFormat(dwFactory, fontFamily, fontSize); SharpDX.Mathematics.Interop.RawRectangleF rect = ToRectangle(area); SharpDX.Direct2D1.SolidColorBrush brush = new SharpDX.Direct2D1.SolidColorBrush(d2dRenderTarget, ToColor(clr)); d2dRenderTarget.DrawText(message, fmt, rect, brush); fmt.Dispose(); brush.Dispose(); }
private void DrawTexture(SharpDX.Direct2D1.RenderTarget renderTarget, Texture2D texture) { using (var surf = texture.QueryInterface <SharpDX.DXGI.Surface1>()) { var prop = new SharpDX.Direct2D1.BitmapProperties(new SharpDX.Direct2D1.PixelFormat(SharpDX.DXGI.Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied)); SharpDX.Direct2D1.Bitmap screenBits = new SharpDX.Direct2D1.Bitmap(renderTarget, surf, prop); try { var srcDecr = surf.Description; float srcWidth = srcDecr.Width; float srcHeight = srcDecr.Height; float destX = 0; float destY = 0; float destWidth = DestSize.Width; float destHeight = DestSize.Height; float scaleX = destWidth / srcWidth; float scaleY = destHeight / srcHeight; if (AspectRatio) { if (scaleY < scaleX) { scaleX = scaleY; destX = ((destWidth - srcWidth * scaleX) / 2); } else { scaleY = scaleX; destY = ((destHeight - srcHeight * scaleY) / 2); } } destWidth = srcWidth * scaleX; destHeight = srcHeight * scaleY; var destRect = new SharpDX.Mathematics.Interop.RawRectangleF { Left = destX, Right = destX + destWidth, Top = destY, Bottom = destY + destHeight, }; renderTarget.DrawBitmap(screenBits, destRect, 1.0f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear); } finally { screenBits?.Dispose(); } } }
public void FillRectangle(float x, float y, float width, float height, System.Drawing.Color clr) { SharpDX.Mathematics.Interop.RawRectangleF rect = new SharpDX.Mathematics.Interop.RawRectangleF { Left = x, Top = y, Right = x + width, Bottom = y + height }; SharpDX.Direct2D1.SolidColorBrush brush = new SharpDX.Direct2D1.SolidColorBrush(d2dRenderTarget, ToColor(clr)); d2dRenderTarget.FillRectangle(rect, brush); brush.Dispose(); }
public static void DrawSlowBoxShadow(RenderTarget g, Rectangle rect, int width) { float f = Util.GetScaleFactor(); RectangleF rectf = new RectangleF(rect.X / f, rect.Y / f, rect.Width / f, rect.Height / f); for (int i = 0; i < width; i++) { Color _c = Slerp(sc1, sc2, i / (float)width);; SolidColorBrush b = new SolidColorBrush(g, new SharpDX.Mathematics.Interop.RawColor4(_c.R / 255f, _c.G / 255f, _c.B / 255f, _c.A / 255f)); var rrect = new SharpDX.Mathematics.Interop.RawRectangleF(rectf.Left, rectf.Top, rectf.Right, rectf.Bottom); g.DrawRectangle(rrect, b, 1); b.Dispose(); rectf = rectf.Expand(1); } }
/// <summary> /// начальная инициализация формы, игровых часов и цветов /// </summary> protected virtual void initForm() { mainRenderForm = new RenderForm(gameFormTitle); Factory = new SharpDX.Direct2D1.Factory(SharpDX.Direct2D1.FactoryType.SingleThreaded); fpsModel = new FPSModel() { FPS = 60 }; fpsTextBox = new SharpDX.Mathematics.Interop.RawRectangleF(4, 32, 255, 4); TitleTextBox = new SharpDX.Mathematics.Interop.RawRectangleF(4, 4, 255, 4); textFormat = new TextFormat(new SharpDX.DirectWrite.Factory(), "Tahoma", 15) { TextAlignment = TextAlignment.Leading, ParagraphAlignment = ParagraphAlignment.Center }; mainRenderForm.Width = FormStyle.Width; mainRenderForm.Height = FormStyle.Height; fps = fpsModel.FPS; gameClock = Stopwatch.StartNew(); // rndTargetProperties = new RenderTargetProperties(new PixelFormat(Format.B8G8R8A8_UNorm, SharpDX.Direct2D1.AlphaMode.Premultiplied)); hwndTargetProperties = new HwndRenderTargetProperties(); // hwndTargetProperties.Hwnd = mainRenderForm.Handle; hwndTargetProperties.PixelSize = new Size2(mainRenderForm.ClientSize.Width, mainRenderForm.ClientSize.Height); hwndTargetProperties.PresentOptions = PresentOptions.None; RenderTarget = new WindowRenderTarget(Factory, rndTargetProperties, hwndTargetProperties); blackBrush = new SolidColorBrush(RenderTarget, SharpDX.Color.Black); greenBrush = new SolidColorBrush(RenderTarget, SharpDX.Color.Green); yellowBrush = new SolidColorBrush(RenderTarget, SharpDX.Color.YellowGreen); mainRenderForm.Show(); }
static Screen() { ScreenSize = new Size((int)System.Windows.SystemParameters.PrimaryScreenWidth, (int)System.Windows.SystemParameters.PrimaryScreenHeight); ScreenRect = new SharpDX.Mathematics.Interop.RawRectangleF(0, 0, ScreenSize.Width, ScreenSize.Height); }
// SharpDX.Direct2D1.RenderTarget の拡張メソッド /// <summary> /// 指定した領域をクリアする。 /// </summary> /// <param name="rt">レンダーターゲット。</param> /// <param name="color">クリアする色。</param> /// <param name="rect">クリアする領域。</param> public static void Clear(this SharpDX.Direct2D1.RenderTarget rt, Color color, SharpDX.Mathematics.Interop.RawRectangleF rect) { rt.PushAxisAlignedClip(rect, SharpDX.Direct2D1.AntialiasMode.PerPrimitive); rt.Clear(color); rt.PopAxisAlignedClip(); }
public DUIRectangleF(System.Drawing.RectangleF rectangle) { this.rectangle = rectangle; this.dxRectangleF = new SharpDX.Mathematics.Interop.RawRectangleF(this.rectangle.Left, this.rectangle.Top, this.rectangle.Right, this.rectangle.Bottom); }
private void InventoryDraw(OverlayWindow w, Graphics g, int xOffset, int yOffset) { foreach (InventoryEntry inv in Program.gameMemory.PlayerInventory) { if (inv == default || inv.SlotPosition < 0 || inv.SlotPosition > 19 || inv.IsEmptySlot) { continue; } int slotColumn = inv.SlotPosition % 4; int slotRow = inv.SlotPosition / 4; int imageX = xOffset + (slotColumn * Program.INV_SLOT_WIDTH); int imageY = yOffset + (slotRow * Program.INV_SLOT_HEIGHT); int textX = imageX + (int)(Program.INV_SLOT_WIDTH * 0.7); int textY = imageY + (int)(Program.INV_SLOT_HEIGHT * 0.7); bool evenSlotColumn = slotColumn % 2 == 0; SolidBrush textBrush = whiteBrush; if (inv.Quantity == 0) { textBrush = darkRedBrush; } System.Drawing.Rectangle r; SharpDX.Direct2D1.Bitmap b; Weapon weapon; if (inv.IsItem && Program.ItemToImageTranslation.ContainsKey(inv.ItemID)) { r = Program.ItemToImageTranslation[inv.ItemID]; if (inv.ItemID == ItemEnumeration.OldKey) { b = inventoryImagePatch1; } else { b = inventoryImage; } } else if (inv.IsWeapon && Program.WeaponToImageTranslation.ContainsKey(weapon = new Weapon() { WeaponID = inv.WeaponID, Attachments = inv.Attachments })) { r = Program.WeaponToImageTranslation[weapon]; b = inventoryImage; } else { r = new System.Drawing.Rectangle(0, 0, Program.INV_SLOT_WIDTH, Program.INV_SLOT_HEIGHT); b = inventoryError; } // Double-slot item. if (b.Size.Width == Program.INV_SLOT_WIDTH * 2) { // Shift the quantity text over into the 2nd slot's area. textX += Program.INV_SLOT_WIDTH; } SharpDX.Mathematics.Interop.RawRectangleF drrf = new SharpDX.Mathematics.Interop.RawRectangleF(imageX, imageY, imageX + r.Width, imageY + r.Height); using (SharpDX.Direct2D1.Bitmap croppedBitmap = new SharpDX.Direct2D1.Bitmap(g.GetRenderTarget(), new SharpDX.Size2(r.Width, r.Height), new SharpDX.Direct2D1.BitmapProperties() { PixelFormat = new SharpDX.Direct2D1.PixelFormat() { AlphaMode = SharpDX.Direct2D1.AlphaMode.Premultiplied, Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm } })) { croppedBitmap.CopyFromBitmap(b, new SharpDX.Mathematics.Interop.RawPoint(0, 0), RectangleToRawRectangle(r)); g.GetRenderTarget().DrawBitmap(croppedBitmap, drrf, 1f, SharpDX.Direct2D1.BitmapInterpolationMode.Linear); } g.DrawText(consolasBold, 18f, textBrush, textX, textY, (inv.Quantity != -1) ? inv.Quantity.ToString() : "∞"); } }
private void sDXThread(object sender) { SharpDX.Mathematics.Interop.RawRectangleF rec = new SharpDX.Mathematics.Interop.RawRectangleF(); rec.Bottom = yResolution; rec.Top = 0; rec.Right = xResolution; rec.Left = 0; SharpDX.Mathematics.Interop.RawRectangleF rec1 = new SharpDX.Mathematics.Interop.RawRectangleF(); rec1.Bottom = 187f / 1080f * yResolution; rec1.Top = 31f / 1080f * yResolution; rec1.Right = (1636f - 78f * 4f + xAdjustment) / 1920f * xResolution; rec1.Left = (1559f - 78f * 4f + xAdjustment) / 1920f * xResolution; SharpDX.Mathematics.Interop.RawRectangleF rec2 = new SharpDX.Mathematics.Interop.RawRectangleF(); rec2.Bottom = 187f / 1080f * yResolution; rec2.Top = 31f / 1080f * yResolution; rec2.Right = (1636f - 78f * 3f + xAdjustment) / 1920f * xResolution; rec2.Left = (1559f - 78f * 3f + xAdjustment) / 1920f * xResolution; SharpDX.Mathematics.Interop.RawRectangleF rec3 = new SharpDX.Mathematics.Interop.RawRectangleF(); rec3.Bottom = 187f / 1080f * yResolution; rec3.Top = 31f / 1080f * yResolution; rec3.Right = (1636f - 78f * 2f + xAdjustment) / 1920f * xResolution; rec3.Left = (1559f - 78f * 2f + xAdjustment) / 1920f * xResolution; SharpDX.Mathematics.Interop.RawRectangleF rec4 = new SharpDX.Mathematics.Interop.RawRectangleF(); rec4.Bottom = 187f / 1080f * yResolution; rec4.Top = 31f / 1080f * yResolution; rec4.Right = (1636f - 78f + xAdjustment) / 1920f * xResolution; rec4.Left = (1559f - 78f + xAdjustment) / 1920f * xResolution; SharpDX.Mathematics.Interop.RawRectangleF rec5 = new SharpDX.Mathematics.Interop.RawRectangleF(); rec5.Bottom = 187f / 1080f * yResolution; rec5.Top = 31f / 1080f * yResolution; rec5.Right = (1636f + xAdjustment) / 1920f * xResolution; rec5.Left = (1559f + xAdjustment) / 1920f * xResolution; SharpDX.Mathematics.Interop.RawRectangleF recwc = new SharpDX.Mathematics.Interop.RawRectangleF(); recwc.Bottom = (276f / 1080) * yResolution; recwc.Top = (224f / 1080) * yResolution; recwc.Right = (1641f / 1920f) * xResolution; recwc.Left = (1589f / 1920f) * xResolution; List <SharpDX.Mathematics.Interop.RawRectangleF> rectangles = new List <SharpDX.Mathematics.Interop.RawRectangleF>(); rectangles.Add(rec1); rectangles.Add(rec2); rectangles.Add(rec3); rectangles.Add(rec4); rectangles.Add(rec5); SharpDX.Mathematics.Interop.RawColor4 r4color2 = new SharpDX.Mathematics.Interop.RawColor4(); r4color2.A = 255; r4color2.R = 125; r4color2.G = 0; r4color2.B = 0; while (true) { device.BeginDraw(); SharpDX.Mathematics.Interop.RawColor4 transparent = new SharpDX.Mathematics.Interop.RawColor4(); transparent.A = 0; transparent.R = 255; transparent.G = 255; transparent.B = 255; device.Clear(transparent); solidColorBrush.Color = r4color2; for (int i = 0; i <= Flasks.Count() - 1; i++) { if (Flasks[i].inUse && Flasks[i].visible) { if (Flasks[i].useDuration > 0) { device.DrawBitmap(LoadFromFile(device, Flasks[i].flaskImageLocation), rectangles[i], flaskAlpha / 100, BitmapInterpolationMode.Linear, rec); } } } if (WCCD && showWC) { device.DrawBitmap(LoadFromFile(device, "FlaskImages\\WC.png"), recwc, 1.0f, BitmapInterpolationMode.Linear, rec); } device.EndDraw(); Thread.Sleep(200); } //whatever you want }
private void RenderOverlay() { Point textSize; int xWidth = 216; int yHeight = 29; int yMargin = 10; int alignX = _graphics.Width - xWidth; int alignY = 0; int baseX = alignX - 10; int baseY = alignY + 10; int offsetX = baseX; int offsetY = baseY; for (int i = 0; i < _gameMemory.Characters.Length; ++i) { CharacterEntry entry = _gameMemory.Characters[i]; SolidBrush healthBrush; if (!entry.IsAlive) { healthBrush = _red; } else if (entry.IsPoison) { healthBrush = _violet; } else if (entry.IsCaution) { healthBrush = _gold; } else if (entry.IsDanger) { healthBrush = _red; } else { healthBrush = _green; } int imageX = offsetX; int imageY = offsetY += i > 0 ? CHR_SLOT_HEIGHT : 0; int textX = imageX + CHR_SLOT_WIDTH + 2; int textY = imageY + 1; SharpDX.Mathematics.Interop.RawRectangleF drawRegion = new SharpDX.Mathematics.Interop.RawRectangleF(imageX, imageY, CHR_SLOT_WIDTH, CHR_SLOT_HEIGHT); SharpDX.Mathematics.Interop.RawRectangleF imageRegion; if (_characterToImageTranslation.ContainsKey(entry.Character)) { imageRegion = _characterToImageTranslation[entry.Character]; } else { imageRegion = new SharpDX.Mathematics.Interop.RawRectangleF(0, 0, CHR_SLOT_WIDTH, CHR_SLOT_HEIGHT); } imageRegion.Right += imageRegion.Left; imageRegion.Bottom += imageRegion.Top; drawRegion.Right += drawRegion.Left; drawRegion.Bottom += drawRegion.Top; if (_characterToImageTranslation.ContainsKey(entry.Character)) { _device.DrawBitmap(_characterSheet, drawRegion, (float)Config.Opacity / 255, SharpDX.Direct2D1.BitmapInterpolationMode.Linear, imageRegion); } DrawProgressBar(_darkergrey, healthBrush, textX, textY, 172, 36, entry.CurrentHP, entry.MaximumHP); DrawText(_consolas14Bold, _white, textX + 5, textY + 10, entry.HealthMessage); } if (Config.ShowTimer) { int timerX = offsetX + 3; int timerY = offsetY += CHR_SLOT_HEIGHT; textSize = DrawText(_consolas32Bold, _white, timerX, timerY, _gameMemory.IGT.FormattedString); offsetY += (int)textSize.Y + yMargin; } else { offsetY += CHR_SLOT_HEIGHT + yMargin; } if (Config.Debug) { textSize = DrawText(_consolas16Bold, _grey, offsetX, offsetY, String.Format("T: {0:0000000000}", _gameMemory.IGT.FrameCount.ToString("D10"))); offsetY += (int)textSize.Y; textSize = DrawText(_consolas16Bold, _grey, offsetX, offsetY, String.Format("P: {0}", _gameMemory.Process.ProcessName)); offsetY += (int)textSize.Y; textSize = DrawText(_consolas16Bold, _grey, offsetX, offsetY, String.Format("I: {0}", _gameMemory.Process.Id.ToString())); offsetY += (int)textSize.Y + yMargin; } if (Config.ShowEnemy) { int headerX = offsetX + 3; int headerY = offsetY; textSize = DrawText(_consolas16Bold, _red, headerX, headerY, "Enemy HP"); offsetY += (int)textSize.Y + yMargin; int index = -1; for (int i = 0; i < _gameMemory.Enemy.Length; ++i) { EnemyEntry enemy = _gameMemory.Enemy[i]; if (enemy.IsEmpty) { continue; } int healthX = offsetX - 2; int healthY = offsetY += ++index > 0 ? yHeight : 0; DrawProgressBar(_darkergrey, _darkred, healthX, healthY, xWidth, yHeight, enemy.DisplayHP, enemy.MaximumHP); DrawText(_consolas14Bold, _red, healthX + 5, healthY + 5, enemy.HealthMessage); } } }