Afterglow.Graphics.SlimDX.ApiExamples.Text.Using_DirectWrite C# (CSharp) Method

Using_DirectWrite() private method

private Using_DirectWrite ( ) : void
return void
        public void Using_DirectWrite()
        {
            Device device;
            SwapChain swapChain;
            RenderTargetView renderTarget;

            EmptyWindow.CreateDeviceSwapChainAndRenderTarget(mForm, out device, out swapChain, out renderTarget);

            var direct2dfactory = new Direct2DFactory();
            var directWriteFactory = new DirectWriteFactory();

            var properties = new WindowRenderTargetProperties { Handle = mForm.Handle, PixelSize = mForm.ClientSize };
            var windowRenderTarget = new WindowRenderTarget(direct2dfactory, properties);
            var brush = new SolidColorBrush(windowRenderTarget, Color.Black);

            var textFormat = new TextFormat(directWriteFactory, "Gabriola",
                FontWeight.Normal, FontStyle.Normal, FontStretch.Normal, 72.0f, "en-us")
            {
                TextAlignment = TextAlignment.Center,
                ParagraphAlignment = ParagraphAlignment.Center
            };

            Application.Idle +=
                delegate
                {
                    device.ClearRenderTargetView(renderTarget, new Color4(1, 0, 0));

                    if (!windowRenderTarget.IsOccluded)
                    {
                        windowRenderTarget.BeginDraw();
                        windowRenderTarget.Transform = Matrix3x2.Identity;
                        windowRenderTarget.Clear(Color.White);

                        windowRenderTarget.DrawText("Hello World using DirectWrite!", textFormat, mForm.ClientRectangle, brush);

                        windowRenderTarget.EndDraw();
                    }

                    swapChain.Present(0, PresentFlags.None);

                    Application.DoEvents();
                };

            Application.Run(mForm);
        }