Exemple #1
0
        public Direct2DCanvas()
        {
            int width  = 1024;
            int height = 1024;

            SharpDX.Direct3D11.Device defaultDevice = new SharpDX.Direct3D11.Device(
                SharpDX.Direct3D.DriverType.Hardware,
                SharpDX.Direct3D11.DeviceCreationFlags.BgraSupport);

            // Query the default device for the supported device and context interfaces.
            var device = defaultDevice.QueryInterface <SharpDX.Direct3D11.Device1> ();

            // Query for the adapter and more advanced DXGI objects.
            SharpDX.DXGI.Device2  dxgiDevice2  = device.QueryInterface <SharpDX.DXGI.Device2> ();
            SharpDX.DXGI.Adapter  dxgiAdapter  = dxgiDevice2.Adapter;
            SharpDX.DXGI.Factory2 dxgiFactory2 = dxgiAdapter.GetParent <SharpDX.DXGI.Factory2> ();

            var swapChainDescription = new SharpDX.DXGI.SwapChainDescription1 {
                Width       = width,
                Height      = height,
                Format      = SharpDX.DXGI.Format.B8G8R8A8_UNorm,
                Stereo      = false,
                Usage       = SharpDX.DXGI.Usage.RenderTargetOutput,
                BufferCount = 2,
                Scaling     = SharpDX.DXGI.Scaling.Stretch,
                SwapEffect  = SharpDX.DXGI.SwapEffect.FlipSequential,
                Flags       = SharpDX.DXGI.SwapChainFlags.None,
            };

            swapChainDescription.SampleDescription.Count   = 1;
            swapChainDescription.SampleDescription.Quality = 0;

            swapChain = dxgiFactory2.CreateSwapChainForComposition(dxgiDevice2, ref swapChainDescription, null);
            swapChain.BackgroundColor = new Color4(1, 0, 0, 0);

            var native = SharpDX.ComObject.QueryInterface <SharpDX.DXGI.ISwapChainBackgroundPanelNative> (this);

            native.SwapChain = swapChain;

            g = new Direct2DGraphics(swapChain);

            _drawTimer = new WindowsDrawTimer {
                Continuous     = true,
                ShouldDrawFunc = () =>
                                 Content != null && ActualWidth > 0 && ActualHeight > 0,
                DrawFunc = Draw,
            };

            Unloaded      += HandleUnloaded;
            Loaded        += HandleLoaded;
            LayoutUpdated += HandleLayoutUpdated;
        }
Exemple #2
0
 public Direct2DGraphicsFontMetrics(Direct2DGraphics graphics, Font font)
 {
     this.graphics = graphics;
     this.font     = font;
 }