/// <summary> 清除整个绘图面并以指定背景色填充 /// </summary> /// <param name="color">System.Drawing.Color 结构,它表示绘图面的背景色</param> public void Clear(Color color) { //this.DxRenderInfos.Clear(); if (color == Color.Transparent) { this.target.RenderTarget.Clear(DxConvert.ToColor4(color)); if (this.target is DUIWindowRenderTarget dUIWindowRenderTarget) { Control control = Control.FromHandle(dUIWindowRenderTarget.Handle); if (control != null) { using (Graphics ownerGraphics = Graphics.FromHwnd(dUIWindowRenderTarget.Handle)) using (DUIImage image = new DUIImage(control.ClientSize.Width, control.ClientSize.Height)) using (Graphics targetGraphics = Graphics.FromImage(image)) { IntPtr ownerDC = ownerGraphics.GetHdc(); IntPtr targetDC = targetGraphics.GetHdc(); DirectUI.Win32.NativeMethods.BitBlt(targetDC, 0, 0, control.ClientSize.Width, control.ClientSize.Height, ownerDC, 0, 0, 13369376); ownerGraphics.ReleaseHdc(ownerDC); targetGraphics.ReleaseHdc(targetDC); image.RenderTarget = this.target; this.target.RenderTarget.DrawBitmap(image, DxConvert.ToRectF(0, 0, control.ClientSize.Width, control.ClientSize.Height), 1, SharpDX.Direct2D1.BitmapInterpolationMode.NearestNeighbor, DxConvert.ToRectF(0, 0, image.Width, image.Height)); } } } } else { this.target.RenderTarget.Clear(DxConvert.ToColor4(color)); } }
/// <summary> 加入一个图层 /// </summary> /// <param name="width">图层宽度</param> /// <param name="height">图层深度</param> public void PushLayer(float x, float y, float width, float height) { this.target.RenderTarget.PushAxisAlignedClip(DxConvert.ToRectF(new RectangleF(x, y, width, height)), SharpDX.Direct2D1.AntialiasMode.PerPrimitive); //using (SharpDX.Direct2D1.Layer layer = new SharpDX.Direct2D1.Layer(this.target.RenderTarget)) //{ // layerParameters.ContentBounds = DxConvert.ToRectF(new RectangleF(x, y, width, height)); // this.target.RenderTarget.PushLayer(ref layerParameters, layer); //} isPushLayer.Push(true); }
public void DrawRectangle(DUIPen pen, float x, float y, float width, float height) { pen.RenderTarget = this.target; if (pen.IsDefaultStyleProperties) { this.target.RenderTarget.DrawRectangle(DxConvert.ToRectF(new RectangleF(x, y, width, height)), pen, pen.Width); } else { this.target.RenderTarget.DrawRectangle(DxConvert.ToRectF(new RectangleF(x, y, width, height)), pen, pen.Width, pen); } }
public void DrawString(string s, DUIFont font, DUIBrush brush, RectangleF layoutRectangle, StringFormat format) { brush.RenderTarget = this.target; try { this.target.RenderTarget.DrawText(s, font, DxConvert.ToRectF(new RectangleF(layoutRectangle.X, layoutRectangle.Y, float.MaxValue, 0)), brush); } catch (Exception ex) { Log.DUILog.GettingLog(ex); //这里报错率很高,但不知道为什么 } }
public void DrawImage(DUIImage image, RectangleF destRect, RectangleF srcRect, GraphicsUnit srcUnit, float opacity) { image.RenderTarget = this.target; this.target.RenderTarget.DrawBitmap(image, DxConvert.ToRectF(destRect), opacity, SharpDX.Direct2D1.BitmapInterpolationMode.NearestNeighbor, DxConvert.ToRectF(srcRect)); }
public void FillRectangle(DUIBrush brush, float x, float y, float width, float height) { brush.RenderTarget = this.target; this.target.RenderTarget.FillRectangle(DxConvert.ToRectF(new RectangleF(x, y, width, height)), brush); }
/// <summary> 将此 DUIRegion 更新为其自身与指定的 System.Drawing.Rectangle 结构的交集。 /// </summary> /// <param name="rect">要与此 DUIRegion 相交的 System.Drawing.Rectangle 结构。</param> public void Intersect(Rectangle rect) { this.region.Intersect(rect); this.actions.Add((dxGeometry, geometrySink) => { SharpDX.Direct2D1.RectangleGeometry rectangleGeometry = new SharpDX.Direct2D1.RectangleGeometry(RenderTarget.RenderTarget.Factory, DxConvert.ToRectF(rect)); this.rectangleGeometry.Combine(rectangleGeometry, SharpDX.Direct2D1.CombineMode.Intersect, geometrySink); }); }
/// <summary> 基于指定的 System.Drawing.RectangleF 结构初始化一个新的 DUIRegion。 /// </summary> /// <param name="rect">一个 System.Drawing.RectangleF 结构,用于定义新 DUIRegion 的内部</param> public DUIRegion(RectangleF rect) { this.region = new Region(rect); this.actions.Add((dxGeometry, geometrySink) => { SharpDX.Direct2D1.RectangleGeometry rectangleGeometry = new SharpDX.Direct2D1.RectangleGeometry(RenderTarget.RenderTarget.Factory, DxConvert.ToRectF(rect)); this.rectangleGeometry.Combine(rectangleGeometry, SharpDX.Direct2D1.CombineMode.Union, geometrySink); }); }