Exemple #1
0
        /// <summary>
        /// Calls Application.Run to host the overlay glass window such that it may be displayed.
        /// Want multiple windows (for some reason?). Create a thread and call this method.
        /// </summary>
        /// <param name="renderDelegate">
        ///     The user delegate which you may use for rendering to the external overlay
        ///     window with Direct2D.
        /// </param>
        /// <param name="targetWindowHandle">
        ///     The handle of the window to display the overlay on.
        /// </param>
        private void EnableOverlay(D2DWindowRenderer.DelegateRenderDirect2D renderDelegate, IntPtr targetWindowHandle)
        {
            // Set framerate
            SharpFPS          = new SharpFPS();
            SharpFPS.FPSLimit = 60F;

            // Enable the Overlay Window.
            WPFThread = new Thread(() =>
            {
                // Instantiate glass form
                OverlayForm = new TransparentWinform(targetWindowHandle);

                // Create D2D Window Renderer
                DirectD2DWindowRenderer = new D2DWindowRenderer(OverlayForm.Handle, renderDelegate);

                // Setup hook for when window resizes.
                OverlayForm.GameWindowResizeDelegate += () => DirectD2DWindowRenderer.ResizeWindow(OverlayForm.Handle);

                // Run the form in this thread.
                Application.Run(OverlayForm);
            });

            // Enable the rendering loop.
            RenderLoopThread = new Thread
                               (
                () =>
            {
                while (true)
                {
                    SharpFPS.StartFrame();
                    DirectD2DWindowRenderer?.DirectXRender();
                    SharpFPS.EndFrame();
                    SharpFPS.Sleep();
                }
            }
                               );
            WPFThread.SetApartmentState(ApartmentState.STA);
            WPFThread.Start();
            RenderLoopThread.Start();
        }
Exemple #2
0
        /// <summary>
        /// Calls Application.Run to host the overlay glass window such that it may be displayed.
        /// Want multiple windows (for some reason?). Create a thread and call this method.
        /// </summary>
        /// <param name="renderDelegate">
        ///     The user delegate which you may use for rendering to the external overlay
        ///     window with Direct2D.
        /// </param>
        /// <param name="targetWindowHandle">
        ///     The handle of the window to display the overlay on.
        /// </param>
        private void EnableOverlay(D2DWindowRenderer.DelegateRenderDirect2D renderDelegate, IntPtr targetWindowHandle)
        {
            // Set framerate
            FrameRate = 60;

            // Initiate the timer
            StopWatch = new Stopwatch();
            StopWatch.Start();

            // Enable the Overlay Window.
            WindowsFormThread = new Thread(() =>
            {
                // Instantiate glass form
                OverlayForm = new TransparentWinform(targetWindowHandle);

                // Create D2D Window Renderer
                DirectD2DWindowRenderer = new D2DWindowRenderer(OverlayForm.Handle, renderDelegate);

                // Setup hook for when window resizes.
                OverlayForm.GameWindowResizeDelegate += () => DirectD2DWindowRenderer.ResizeWindow(OverlayForm.Handle);

                // Run the form in this thread
                Application.Run(OverlayForm);
            });

            // Enable the rendering loop.
            RenderLoopThread = new Thread
                               (
                () =>
            {
                while (true)
                {
                    DirectD2DWindowRenderer?.DirectXRender();
                    SleepFrameRate();
                }
            }
                               );
            WindowsFormThread.Start();
            RenderLoopThread.Start();
        }