Пример #1
0
        /// <summary>
        /// Resizes the Direct2D window to match the client area size of a specified window handle.
        /// </summary>
        /// <param name="targetWindowHandle">The handle of the window of whose client area size should be matched.</param>
        public void ResizeWindow(IntPtr targetWindowHandle)
        {
            // Wait for any draw operation to finish.
            lock (RenderLock)
            {
                // Retrieve window size of target window.
                Point windowSize = WindowProperties.GetClientAreaSize2(targetWindowHandle);

                // Resize the D2D WindowRenderTarget
                Direct2DWindowTarget.Resize(new Size2(windowSize.X, windowSize.Y));
            }
        }
Пример #2
0
        /// <summary>
        /// Initializes a Direct2D device used to draw to the screen.
        /// For drawing, you MUST add your methods to the Direct2D Rendering Delegate (direct2DRenderMethod).
        /// </summary>
        public void InitializeDirectX(IntPtr targetWindowHandle)
        {
            try
            {
                // Wait for any draw operation to finish.
                lock (RenderLock)
                {
                    // Mark D2D Setup as incomplete, disallow Rendering.
                    Direct2DSetupComplete = false;

                    // Dispose Render Target if Necessary
                    Direct2DWindowTarget?.Dispose();

                    // Create the D2D Factory which aids with the creation of a WindowRenderTarget object.
                    Factory direct2DFactory = new Factory(FactoryType.SingleThreaded);

                    // Retrieve window size of target window.
                    Point windowSize = WindowProperties.GetClientAreaSize2(targetWindowHandle);

                    // Set the render properties!
                    HwndRenderTargetProperties direct2DRenderTargetProperties = new HwndRenderTargetProperties
                    {
                        Hwnd           = targetWindowHandle,
                        PixelSize      = new Size2(windowSize.X, windowSize.Y),
                        PresentOptions = PresentOptions.None
                    };

                    // Assign the Window Render Target
                    Direct2DWindowTarget = new WindowRenderTarget
                                           (
                        direct2DFactory,
                        new RenderTargetProperties(new PixelFormat(Format.B8G8R8A8_UNorm, AlphaMode.Premultiplied)),
                        direct2DRenderTargetProperties
                                           );

                    // Clear the screen of the Window Render Target.
                    DirectXClearScreen();

                    // Mark D2D Setup as Complete, allow Rendering.
                    Direct2DSetupComplete = true;
                }
            }
            catch (Exception ex)
            {
                Bindings.PrintError?.Invoke("[libReloaded] Failed to initialize DirectX rendering to window | " + ex.Message);
            }
        }