コード例 #1
0
 private void Begin(SharpDX.Matrix3x2 transform)
 {
     this.context = D2DFactory.Instance.GetContext(this.GraphicsDevice);
     if (this.context == null)
     {
         throw new Exception("Create D2D context failed.");
     }
     this.context.D2DRenderTarget.Transform = transform;
     this.context.D2DRenderTarget.BeginDraw();
     this.IsBeginEndPair = true;
 }
コード例 #2
0
        internal void DrawText(D2DContext context, string text, Vector2 position, Vector2 size, Color color)
        {
            var rt = context.D2DRenderTarget;

            using (var layout = this.LayoutString(text, size.X, size.Y))
            {
                rt.DrawTextLayout(new SharpDX.Vector2(position.X, position.Y),
                                  layout,
                                  context.GetBrush(color),
                                  DrawTextOptions.None);
            }
        }
コード例 #3
0
ファイル: D2DFactory.cs プロジェクト: PirateIzzy/WzComparerR2
        public D2DContext GetContext(GraphicsDevice graphicsDevice)
        {
            SharpDX.ComObject obj     = GetRenderTargetResource(graphicsDevice);
            D2DContext        context = GetOrCreateContext(obj);

            if (context == null)
            {
                return(null);
            }

            AlphaMode alphaMode = AlphaMode.Ignore;

            if (context.DxgiSurface == null || context.DxgiSurface.IsDisposed)
            {
                if (obj is SharpDX.DXGI.SwapChain)
                {
                    var swapChain = (SharpDX.DXGI.SwapChain)obj;
                    context.DxgiSurface = SharpDX.DXGI.Surface.FromSwapChain(swapChain, 0);
                    alphaMode           = AlphaMode.Ignore;
                }
                else if (obj is SharpDX.Direct3D11.Resource)
                {
                    context.DxgiSurface = obj.QueryInterface <SharpDX.DXGI.Surface>();
                    alphaMode           = AlphaMode.Premultiplied;
                }
                else
                {
                    return(null);
                }
            }

            if (context.D2DRenderTarget == null || context.D2DRenderTarget.IsDisposed)
            {
                var rtProp = new RenderTargetProperties(new PixelFormat(SharpDX.DXGI.Format.Unknown, alphaMode));
                var d2drt  = new RenderTarget(this.factory2D, context.DxgiSurface, rtProp);
                d2drt.TextRenderingParams      = new RenderingParams(factoryDWrite, 1f, 0f, 0f, PixelGeometry.Flat, RenderingMode.CleartypeGdiClassic);
                d2drt.TextAntialiasMode        = SharpDX.Direct2D1.TextAntialiasMode.Grayscale;
                context.D2DRenderTarget        = d2drt;
                context.DxgiSurface.Disposing += (o, e) => d2drt.Dispose();
            }

            return(context);
        }
コード例 #4
0
        private D2DContext GetOrCreateContext(SharpDX.ComObject comObject)
        {
            if (comObject == null)
            {
                return null;
            }

            if (comObject.IsDisposed)
            {
                dictContext.Remove(comObject);
                return null;
            }

            D2DContext context;
            if (!this.dictContext.TryGetValue(comObject, out context))
            {
                context = new D2DContext();
                comObject.Disposing += ComObject_Disposing;
                this.dictContext.Add(comObject, context);
            }
            return context;
        }
コード例 #5
0
 internal void DrawText(D2DContext context, string text, Vector2 position, Color color)
 {
     this.DrawText(context, text, position, Vector2.Zero, color);
 }