From df8e46aea2696bcec2aa9d3f98b4d506225a80d1 Mon Sep 17 00:00:00 2001 From: Zaafar Ahmed Date: Sun, 27 Jan 2019 13:13:09 -0500 Subject: [PATCH] Added Debug Mode. In this mode overlay will not Hide the Console Added API to change the FPS new and improved sample demo --- ClickableTransparentOverlay/Overlay.cs | 24 +++++++- DriverProgram/Program.cs | 82 +++++++++++++++----------- 2 files changed, 70 insertions(+), 36 deletions(-) diff --git a/ClickableTransparentOverlay/Overlay.cs b/ClickableTransparentOverlay/Overlay.cs index dc08618..ff21b16 100644 --- a/ClickableTransparentOverlay/Overlay.cs +++ b/ClickableTransparentOverlay/Overlay.cs @@ -33,6 +33,7 @@ namespace ClickableTransparentOverlay private static Vector2 futurePos; private static Vector2 futureSize; private static bool requireResize; + private static bool debugMode; /// /// Initializes a new instance of the class. @@ -52,11 +53,15 @@ namespace ClickableTransparentOverlay /// /// fps of the overlay /// - public Overlay(int x, int y, int width, int height, int fps) + /// + /// In this mode, overlay will not hide the Console + /// + public Overlay(int x, int y, int width, int height, int fps, bool debug) { clearColor = new Vector4(0.00f, 0.00f, 0.00f, 0.00f); myFps = fps; isClosed = false; + debugMode = debug; // Stuff related to (thread safe) resizing of SDL2Window requireResize = false; @@ -97,10 +102,25 @@ namespace ClickableTransparentOverlay { uiThread.Start(); hookController.EnableHooks(); - NativeMethods.HideConsoleWindow(); + if (!debugMode) + { + NativeMethods.HideConsoleWindow(); + } + Application.Run(new ApplicationContext()); } + /// + /// Set the overlay FPS. + /// + /// + /// FPS to set + /// + public void SetFps(int fps) + { + myFps = fps; + } + /// /// Resizes the overlay /// diff --git a/DriverProgram/Program.cs b/DriverProgram/Program.cs index c45ca71..c102006 100644 --- a/DriverProgram/Program.cs +++ b/DriverProgram/Program.cs @@ -2,52 +2,66 @@ { using ClickableTransparentOverlay; using ImGuiNET; - using System; using System.Threading; class Program { - private static Overlay demo; - private static int Width = 2560; - private static int Height = 1440; + private static bool isRunning = true; private static int Fps = 144; - private static int RunFor = 10; - static void Main(string[] args) - { - Console.Write("Enter Screen Width:"); - Width = Convert.ToInt32(Console.ReadLine()); - - Console.Write("Enter Screen Height:"); - Height = Convert.ToInt32(Console.ReadLine()); + private static int[] resizeHelper = new int[4] { 0, 0, 2560, 1440 }; + private static int seconds = 5; + private static Overlay overlay = new Overlay(0, 0, 2560, 1440, Fps, false); - Console.Write("Enter Monitor Max FPS:"); - Fps = Convert.ToInt32(Console.ReadLine()); - - Console.Write("You want to run this demo for X (seconds):"); - RunFor = Convert.ToInt32(Console.ReadLine()); - - var EndDemo = new Thread(DistroyDemo); - EndDemo.Start(); - StartDemo(); + private static void MainApplicationLogic() + { + while (isRunning) + { + Thread.Sleep(10); + } + overlay.Dispose(); } - public static void StartDemo() + static void Main(string[] args) { - demo = new Overlay(0, 0, Width, Height, Fps); - demo.SubmitUI += (object sender, EventArgs e) => ImGui.ShowDemoWindow(); - demo.Run(); + overlay.SubmitUI += RenderUi; + Thread p = new Thread(MainApplicationLogic); + p.Start(); + overlay.Run(); + p.Join(); } - public static void DistroyDemo() + private static void RenderUi(object sender, System.EventArgs e) { - Thread.Sleep(RunFor * 1000); - demo.Resize(200, 200, 1024, 1024); - Thread.Sleep(RunFor * 1000); - demo.Hide(); - Thread.Sleep(RunFor * 1000); - demo.Show(); - Thread.Sleep(RunFor * 1000); - demo.Dispose(); + if (isRunning) + { + ImGui.ShowDemoWindow(ref isRunning); + } + + ImGui.Begin("SDL2Window Config", ImGuiWindowFlags.NoResize | ImGuiWindowFlags.AlwaysAutoResize); + ImGui.Text($"Current FPS: {Fps}"); + if (ImGui.SliderInt("Set FPS", ref Fps, 30, 144)) + { + overlay.SetFps(Fps); + } + + ImGui.NewLine(); + ImGui.Text($"Current Position: {resizeHelper[0]}, {resizeHelper[1]}"); + ImGui.Text($"Current Size: {resizeHelper[2]}, {resizeHelper[3]}"); + ImGui.SliderInt4("Set Position & Size", ref resizeHelper[0], 0, 3840); + if (ImGui.Button("Resize")) + { + overlay.Resize(resizeHelper[0], resizeHelper[1], resizeHelper[2], resizeHelper[3]); + } + + ImGui.NewLine(); + ImGui.DragInt("Set Hidden Time", ref seconds); + if (ImGui.Button("Hide for X Seconds")) + { + new Thread(() => { Thread.Sleep(seconds * 1000); overlay.Show(); }).Start(); + overlay.Hide(); + } + + ImGui.End(); } } } \ No newline at end of file