protected override void CreateTexture() { if (ControlTexture != null && !ControlTexture.Disposed && Size != TextureSize) { ControlTexture.Dispose(); } if (ControlTexture == null || ControlTexture.Disposed) { DXManager.ControlList.Add(this); ControlTexture = new Texture(DXManager.Device, Size.Width, Size.Height, 1, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default); ControlTexture.Disposing += ControlTexture_Disposing; TextureSize = Size; } Surface oldSurface = DXManager.CurrentSurface; Surface surface = ControlTexture.GetSurfaceLevel(0); DXManager.SetSurface(surface); DXManager.Device.Clear(ClearFlags.Target, BackColour, 0, 0); BeforeDrawControl(); DrawChildControls(); AfterDrawControl(); DXManager.Sprite.Flush(); DXManager.SetSurface(oldSurface); TextureValid = true; surface.Dispose(); }
protected override unsafe void CreateTexture() { if (string.IsNullOrEmpty(Text)) { return; } if (Size.Width == 0 || Size.Height == 0) { return; } if (ControlTexture != null && !ControlTexture.Disposed && TextureSize != Size) { ControlTexture.Dispose(); } if (ControlTexture == null || ControlTexture.Disposed) { DXManager.ControlList.Add(this); ControlTexture = new Texture(DXManager.Device, Size.Width, Size.Height, 1, Usage.None, Format.A8R8G8B8, Pool.Managed); ControlTexture.Disposing += ControlTexture_Disposing; TextureSize = Size; } using (GraphicsStream stream = ControlTexture.LockRectangle(0, LockFlags.Discard)) using (Bitmap image = new Bitmap(Size.Width, Size.Height, Size.Width * 4, PixelFormat.Format32bppArgb, (IntPtr)stream.InternalDataPointer)) { using (Graphics graphics = Graphics.FromImage(image)) { graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.TextContrast = 0; graphics.Clear(BackColour); if (OutLine) { TextRenderer.DrawText(graphics, Text, Font, new Rectangle(1, 0, Size.Width, Size.Height), OutLineColour, DrawFormat); TextRenderer.DrawText(graphics, Text, Font, new Rectangle(0, 1, Size.Width, Size.Height), OutLineColour, DrawFormat); TextRenderer.DrawText(graphics, Text, Font, new Rectangle(2, 1, Size.Width, Size.Height), OutLineColour, DrawFormat); TextRenderer.DrawText(graphics, Text, Font, new Rectangle(1, 2, Size.Width, Size.Height), OutLineColour, DrawFormat); TextRenderer.DrawText(graphics, Text, Font, new Rectangle(1, 1, Size.Width, Size.Height), ForeColour, DrawFormat); } else { TextRenderer.DrawText(graphics, Text, Font, new Rectangle(1, 0, Size.Width, Size.Height), ForeColour, DrawFormat); } } } ControlTexture.UnlockRectangle(0); DXManager.Sprite.Flush(); TextureValid = true; }
public override void OnResolutionChanged() { base.OnResolutionChanged(); if (ControlTexture != null) { ControlTexture.Dispose(); ControlTexture = null; } Manager.Game.Camera.RecreateProjection(); }
protected unsafe override void CreateTexture() { if (!Settings.FullScreen) { return; } if (Size.Width == 0 || Size.Height == 0) { return; } if (ControlTexture != null && !ControlTexture.Disposed && TextureSize != Size) { ControlTexture.Dispose(); } if (ControlTexture == null || ControlTexture.Disposed) { DXManager.ControlList.Add(this); ControlTexture = new Texture(DXManager.Device, Size.Width, Size.Height, 1, Usage.None, Format.A8R8G8B8, Pool.Managed); ControlTexture.Disposing += ControlTexture_Disposing; TextureSize = Size; } Point caret = GetCaretPosition(); using (GraphicsStream stream = ControlTexture.LockRectangle(0, LockFlags.Discard)) using (Bitmap bm = new Bitmap(Size.Width, Size.Height, Size.Width * 4, PixelFormat.Format32bppArgb, (IntPtr)stream.InternalDataPointer)) { TextBox.DrawToBitmap(bm, new Rectangle(0, 0, Size.Width, Size.Height)); using (Graphics graphics = Graphics.FromImage(bm)) { graphics.DrawImage(bm, Point.Empty); if (TextBox.Focused) { graphics.DrawLine(CaretPen, new Point(caret.X, caret.Y), new Point(caret.X, caret.Y + TextBox.Font.Height)); } } } ControlTexture.UnlockRectangle(0); DXManager.Sprite.Flush(); TextureValid = true; }
protected override bool CreateTexture() { if (string.IsNullOrEmpty(Text) || !Main.This.Created) { return(false); } if (DXFont == null || DXFont.Disposed) { if (Font != null) { DXFont = new Microsoft.DirectX.Direct3D.Font(DXManager.Device, Font); } else { return(false); } } if (AutoSize) { Size = DXFont.MeasureString(null, Text, DrawFormat, ForeColor).Size; if (OutLine && Size != Size.Empty) { Size = new Size(Size.Width + 2, Size.Height + 2); } } if (Size == Size.Empty) { return(false); } if (ControlTexture != null && !ControlTexture.Disposed) { ControlTexture.Dispose(); } ControlTexture = new Texture(DXManager.Device, Size.Width, Size.Height, 0, Usage.RenderTarget, Format.A8R8G8B8, Pool.Default); ControlTexture.Disposing += ControlTexture_Disposing; Surface OldSurface = DXManager.CurrentSurface; DXManager.SetSurface(ControlTexture.GetSurfaceLevel(0)); DXManager.Device.Clear(ClearFlags.Target, BackColor, 0, 0); Point TempPoint = Point.Empty; if (OutLine) { TempPoint.X = 1; TempPoint.Y = 0; if (DrawFormat == DrawTextFormat.None) { DXFont.DrawText(null, Text, TempPoint, OutLineColor); } else { DXFont.DrawText(null, Text, new Rectangle(TempPoint, Size), DrawFormat, OutLineColor); } TempPoint.X = 0; TempPoint.Y = 1; if (DrawFormat == DrawTextFormat.None) { DXFont.DrawText(null, Text, TempPoint, OutLineColor); } else { DXFont.DrawText(null, Text, new Rectangle(TempPoint, Size), DrawFormat, OutLineColor); } TempPoint.X = 2; TempPoint.Y = 1; if (DrawFormat == DrawTextFormat.None) { DXFont.DrawText(null, Text, TempPoint, OutLineColor); } else { DXFont.DrawText(null, Text, new Rectangle(TempPoint, Size), DrawFormat, OutLineColor); } TempPoint.X = 1; TempPoint.Y = 2; if (DrawFormat == DrawTextFormat.None) { DXFont.DrawText(null, Text, TempPoint, OutLineColor); } else { DXFont.DrawText(null, Text, new Rectangle(TempPoint, Size), DrawFormat, OutLineColor); } TempPoint = new Point(1, 1); } if (DrawFormat == DrawTextFormat.None) { DXFont.DrawText(null, Text, TempPoint, ForeColor); } else { DXFont.DrawText(null, Text, new Rectangle(TempPoint, Size), DrawFormat, ForeColor); } DXManager.SetSurface(OldSurface); TextureValid = true; return(true); }
protected override unsafe void CreateTexture() { if (string.IsNullOrEmpty(Text)) { return; } if (Size.Width == 0 || Size.Height == 0) { return; } if (ControlTexture != null && !ControlTexture.Disposed && TextureSize != Size) { ControlTexture.Dispose(); } if (ControlTexture == null || ControlTexture.Disposed) { DXManager.ControlList.Add(this); ControlTexture = new Texture(DXManager.Device, Size.Width, Size.Height, 1, Usage.None, Format.A8R8G8B8, Pool.Managed); TextureSize = Size; } DataRectangle stream = ControlTexture.LockRectangle(0, LockFlags.Discard); using (Bitmap image = new Bitmap(Size.Width, Size.Height, Size.Width * 4, PixelFormat.Format32bppArgb, stream.Data.DataPointer)) { using (Graphics graphics = Graphics.FromImage(image)) { graphics.SmoothingMode = SmoothingMode.AntiAlias; graphics.TextRenderingHint = TextRenderingHint.AntiAliasGridFit; graphics.CompositingQuality = CompositingQuality.HighQuality; graphics.InterpolationMode = InterpolationMode.NearestNeighbor; graphics.PixelOffsetMode = PixelOffsetMode.HighQuality; graphics.TextContrast = 0; graphics.Clear(BackColour); if (OutLine) { TextRenderer.DrawText(graphics, Text, Font, new Rectangle(1, 0, Size.Width, Size.Height), OutLineColour, DrawFormat); TextRenderer.DrawText(graphics, Text, Font, new Rectangle(0, 1, Size.Width, Size.Height), OutLineColour, DrawFormat); TextRenderer.DrawText(graphics, Text, Font, new Rectangle(2, 1, Size.Width, Size.Height), OutLineColour, DrawFormat); TextRenderer.DrawText(graphics, Text, Font, new Rectangle(1, 2, Size.Width, Size.Height), OutLineColour, DrawFormat); TextRenderer.DrawText(graphics, Text, Font, new Rectangle(1, 1, Size.Width, Size.Height), ForeColour, DrawFormat); //LinearGradientBrush brush = new LinearGradientBrush(new Rectangle(0, 0, this.Size.Width, this.Size.Height), Color.FromArgb(239, 243, 239), Color.White, LinearGradientMode.Vertical); ////graphics.DrawString(Text, Font, brush, 37, 9); ////graphics.DrawString(this.Text, this.Font, new SolidBrush(Color.Black), 39, 9, StringFormat.GenericDefault); } else { TextRenderer.DrawText(graphics, Text, Font, new Rectangle(1, 0, Size.Width, Size.Height), ForeColour, DrawFormat); } } } ControlTexture.UnlockRectangle(0); DXManager.Sprite.Flush(); TextureValid = true; }