Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImGui window not rendering in entire screen #8311

Closed
Roseclear opened this issue Jan 12, 2025 · 4 comments
Closed

ImGui window not rendering in entire screen #8311

Roseclear opened this issue Jan 12, 2025 · 4 comments

Comments

@Roseclear
Copy link

Version/Branch of Dear ImGui:

Version 1.91.5

Back-ends:

imgui_impl_dx9.cpp + imgui_impl_opengl3.cpp

Compiler, OS:

Microsoft Visual C/C++ (19.36.34435) [C++] [Windows]

Full config/build information:

Compiler and linker

CC = cl
LD = link

Object files (manually concatenate)

OBJS = cimgui.obj
./imgui/imgui.obj
./imgui/imgui_draw.obj
./imgui/imgui_demo.obj
./imgui/imgui_tables.obj
./imgui/imgui_widgets.obj
./imgui/backends/imgui_impl_dx9.obj
./imgui/backends/imgui_impl_win32.obj
./imgui/backends/imgui_impl_opengl3.obj
cimgui_impl.obj

Compiler flags

CXXFLAGS = /O2 /EHsc /nologo /I./imgui /DUNICODE /D_UNICODE
LINKFLAGS = /DLL /nologo /OUT:cimgui.dll d3dcompiler.lib opengl32.lib gdi32.lib dwmapi.lib

Targets

all: cimgui.dll

Rule for building the DLL

cimgui.dll: $(OBJS)
( L D ) (LINKFLAGS) $(OBJS)

Rule for compiling .cpp to .obj

.cpp.obj:
( C C ) (CXXFLAGS) /c < / F o @

Clean

clean:
del /q ( s u b s t / , , (OBJS))

Details:

I am currently working on a c# project and as you can see, the ImGui window is stuck on an invisible wall and cannot cross this limit. (the avalable area only covers a fifth of my screen, wich is problematic).
does anyone have any clue what's causing all of this ?

(Sorry, my project is written in c#, using modified cimgui [Implement backends for this])
(Sorry for can't post the real screenshot, but my issuse like this screenshot too)

Screenshots/Video:

v0-7nc3g90f02zc1

Minimal, Complete and Verifiable Example code:

   private static string ClientName = "DebugClient";
   private static string ClientVersion = "0.15.0";
   private static string ClientTag = "DEV";
   //Implement backends to cimgui is pain as f*ck
  //F*k the cimgui
   private unsafe static void Init_Draw(IntPtr device, IntPtr hDc)
   {
       try
       {
           if (ImGuiInited || pending)
               return;

           ImGui.CreateContext();
           InitStyle();
           pending = true;
           var io = ImGui.GetIO();
           io.WantSaveIniSettings = false;
           io.Key
           NativeApi.CImguiWrapper.CImGui_ImplWin32_Init((void*)hwnd);
           switch (graphicType)
           {
               case GraphicsType.d3d9:
                   NativeApi.CImguiWrapper.CImGui_ImplDX9_Init((void*)device);
                   break;
               case GraphicsType.opengl:
                   Wgl.MakeCurrent(hDc, Wgl.GetCurrentContext());
                   NativeApi.CImguiWrapper.CImGui_ImplOpenGL3_Init(null);
                   break;
               default:
                   throw new Exception("Not support " + graphicType);
           }

        
           InitPage();

           GameBase = new GameBase();
           Player = new Player();
           NetworkClient = new NetworkClient();
           InputManager = new InputManager();
           AudioEngine = new AudioEngine();

           ImGuiInited = true;
           pending = false;
           Logging.Log("Debug GUI initialized");

       }
       catch (Exception e)
       {
           Logging.Log("Error!" + e.ToString());
           pending = false;
       }
   }


   private static void BeginDraw()
   {
       switch (graphicType)
       {
           case GraphicsType.d3d9:
               NativeApi.CImguiWrapper.CImGui_ImplDX9_NewFrame();
               NativeApi.CImguiWrapper.CImGui_ImplWin32_NewFrame();
               break;
           case GraphicsType.opengl:
               NativeApi.CImguiWrapper.CImGui_ImplOpenGL3_NewFrame();
               NativeApi.CImguiWrapper.CImGui_ImplWin32_NewFrame();
               break;
           default:
               throw new Exception("Not support " + graphicType);
       }

       ImGui.NewFrame();

   }
   private static void HandleIO()
   {
       //Somehow ImGui.IsKeyDown doesn't work :v
       //Mess with GetAsyncKeyState Instead

       var x = NativeApi.GetAsyncKeyState(Keys.Home);
       if (x == 1 || x == Int16.MinValue)
       {
           ShowMenu = !ShowMenu;
       }

     
       InputManager.HandleInput = !ShowMenu;
       var io = ImGui.GetIO();
       io.MouseDrawCursor = ShowMenu;
   }

   private static Permissions ChoosenPermissions;
   private delegate bool MatchRequirement();
   private static Dictionary<string, Action> Pages = new Dictionary<string, Action>();
   private static Dictionary<Action, MatchRequirement> DebugsUI = new Dictionary<Action, MatchRequirement>();
   private static string SelectedPage = "Main Menu";
   private static bool ShowMenu = true;
   private static void InitPage()
   {
       Pages.Add("UserInfo", Draw_UserInfo);
       Pages.Add("Debug", DrawDebugCfg);

       DebugsUI.Add(Draw_Beatmap_Debug, () =>
       {
           return ConfigManagement.GetValue<bool>("BeatmapDbg") && player.Beatmap != null;
       });
   }

   private static void DrawDebugCfg()
   {
       bool toggled = ConfigManagement.GetValue<bool>("BeatmapDbg");
       if (ImGui.Checkbox("Beatmap Debug", ref toggled))
       {
           ConfigManagement.SetValue("BeatmapDbg", toggled);
       }

   }
   private unsafe static void Draw_UserInfo()
   {
       var info = GameBase.User;
       if (info != null)
       {
           try
           {
               ImGui.Text("User Info:");
               ImGui.Text($"Username: {info.Username}");
               ImGui.Text($"Id: {info.Id}");
               ImGui.Text($"Country Code: {info.CountryCode}");
               ImGui.Text($"Rank: {info.Ranks}");
           }
           catch (Exception ex) { ImGui.Text(ex.ToString()); }
       }
       ImGui.Text($"Tournament: {GameBase.Tournament}");
       ImGui.Text($"Has login: {GameBase.HasLogin}");
       ImGui.Text($"Connected: {NetworkClient.Connected}");
       ImGui.Text($"Authenticated: {NetworkClient.Authenticated}");
       ImGui.Text($"Restricted: {NetworkClient.Restricted}");

     
   }
   private static void Draw_MainMenu()
   {
       ImGui.Text("Wellcome Developer");
       ImGui.Text($"Version: {ClientVersion}");
       ImGui.Text($"Stream: {ClientTag}");
       ImGui.Text("If you are using this version, it's mean i trust you");
       ImGui.Text("Don't share it, my friend");
       ImGui.Text("Thanks ocornut for ImGui, it's save my time haha");
       ImGui.Text("Developer: Vynk");
   }
   private unsafe static void Draw_Beatmap_Debug()
   {
       ImGui.Begin("Beatmap Debug", ImGuiWindowFlags.AlwaysAutoResize);

       try
       {

           var beatmap = Player.CurrentLevel;
           ImGui.Text($"Type: {Player.BeatmapInstance.GetType().Name}");
           ImGui.Text($"Artist: {beatmap.Artist}");
           ImGui.Text($"Title: {beatmap.Title}");
           ImGui.Text($"Creator: {beatmap.Creator}");
           ImGui.Text($"Version: {beatmap.Version}");
           ImGui.Text($"Checksum: {beatmap.BeatmapChecksum}");
           ImGui.Text($"Path: {beatmap.FileName}");
           ImGui.Text($"Objects: {beatmap.ObjectCounts}");
           ImGui.Text($"Time: {audioEngine.Time}");
       }
       catch (Exception ex)
       {
           ImGui.Text(ex.ToString());
       }
       ImGui.End();
   }

   private static bool ShownDemoWindow = false;
   private unsafe static void Draw()
   {
       try
       {
         
           if (ShowMenu)
           {
               ImGui.Begin($"{ClientName} {ClientVersion} [{ClientTag}]");
               var keys = Pages.Keys.ToArray();
               for (int i = 0; i < keys.Length; i++)
               {
                   ImGui.SameLine();
                   if (ImGui.Button(keys[i]))
                   {
                       SelectedPage = keys[i];
                       break;
                   }
               }
               if (Pages.ContainsKey(SelectedPage))
                   Pages[SelectedPage].Invoke();
               else
                   Draw_MainMenu();

               ImGui.End();
           }

           var dbgsKey = DebugsUI.Keys.ToArray();
           for (int i = 0; i < dbgsKey.Length; i++)
           {
               var key = dbgsKey[i];
               if (DebugsUI[key]())
                   key();
           }
       }
       catch (Exception e)
       {
           Logging.Log("Error!" + e.ToString());
       }
   }

   private unsafe static void Render()
   {
       ImGui.EndFrame();
       ImGui.Render();

       switch (graphicType)
       {
           case GraphicsType.d3d9:
               NativeApi.CImguiWrapper.CImGui_ImplDX9_RenderDrawData(ImGui.GetDrawData().NativePtr);
               break;
           case GraphicsType.opengl:
               NativeApi.CImguiWrapper.CImGui_ImplOpenGL3_RenderDrawData(ImGui.GetDrawData().NativePtr);
               break;
       }

   }

   private unsafe static void ImGUI_Render(IntPtr device, IntPtr hDc)
   {
       if (!ImGuiInited)
       {
           Init_Draw(device, hDc);
           return;
       }
       BeginDraw();
       HandleIO();
       Draw();
       Render();

   }
   private static void InitStyle()
   {
       ImGui.GetStyle().WindowRounding = 0.0f;
       ImGui.GetStyle().ChildRounding = 0.0f;
       ImGui.GetStyle().FrameRounding = 0.0f;
       ImGui.GetStyle().GrabRounding = 0.0f;
       ImGui.GetStyle().PopupRounding = 0.0f;
       ImGui.GetStyle().ScrollbarRounding = 0.0f;
    

       //    ImGui.PopStyleVar();

   }

 private static int MouseProcHook(int code, IntPtr wParam, IntPtr lParam)
 {

     return NativeApi.CallNextHookEx(hk_mhook, code, wParam, lParam);
 }
 private static int KeyboardProcHook(int code, IntPtr wParam, IntPtr lParam)
 {

     return NativeApi.CallNextHookEx(hk_khook, code, wParam, lParam);
 }
 private static int GetMsgHook(int code, IntPtr wParam, IntPtr lParam)
 {
     if (ImGuiInited)
         NativeApi.CImguiWrapper.CImGui_ImplWin32_WndProcHandler(hwnd, (uint)code, wParam, lParam);

     return NativeApi.CallNextHookEx(hk_msghook, code, wParam, lParam);
 }
 private delegate int WNDHook(int code, IntPtr wParam, IntPtr lParam);


 private static IntPtr hk_mhook;
 private static IntPtr hk_khook;
 private static IntPtr hk_msghook;
 private static bool FallbackMode = false;
 private static unsafe void InstallWindowsHookEx()
 {
     if (FallbackMode)
     {
         IntPtr msHookPtr = Marshal.GetFunctionPointerForDelegate(new WNDHook(MouseProcHook));
         IntPtr msKHookPtr = Marshal.GetFunctionPointerForDelegate(new WNDHook(KeyboardProcHook));
         IntPtr msgHookPtr = Marshal.GetFunctionPointerForDelegate(new WNDHook(GetMsgHook));

         hk_khook = NativeApi.SetWindowsHookEx(2, msKHookPtr, Marshal.GetHINSTANCE(typeof(VynkL).Module), 0);
         hk_mhook = NativeApi.SetWindowsHookEx(7, msHookPtr, Marshal.GetHINSTANCE(typeof(VynkL).Module), 0);
         hk_msghook = NativeApi.SetWindowsHookEx(3, msgHookPtr, Marshal.GetHINSTANCE(typeof(VynkL).Module), 0);
     }
     else
     {
         DefWindowProc defWindowProc = new DefWindowProc();
         defWindowProc.WindowHandle = hwnd;
         defWindowProc.Install();
         Hooks.Add(defWindowProc);
         defWindowProc.WindowProc += (IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) =>
         {
             try
             {
                 if (ImGuiInited && ShowMenu)
                 {
                     NativeApi.CImguiWrapper.CImGui_ImplWin32_WndProcHandler(hwnd, msg, wParam, lParam);
                 }
             }
             catch { }
             return IntPtr.Zero;
         };
         SetCursorPos NewHookCursor = new SetCursorPos();
         NewHookCursor.Install();
         Hooks.Add(NewHookCursor);
         NewHookCursor.SetCursorPos_Event += (int x, int y) =>
         {
             NewHookCursor.BlockInput = ShowMenu;
             return false;
         };
     }
 }
@ocornut ocornut changed the title ImGui window cannot navigate the entire screen ImGui window not rendering in entire screen Jan 12, 2025
@ocornut
Copy link
Owner

ocornut commented Jan 12, 2025

Sorry but #1586

@ocornut ocornut closed this as completed Jan 12, 2025
@H2143
Copy link

H2143 commented Jan 12, 2025

  if (FallbackMode)
     {
         IntPtr msHookPtr = Marshal.GetFunctionPointerForDelegate(new WNDHook(MouseProcHook));
         IntPtr msKHookPtr = Marshal.GetFunctionPointerForDelegate(new WNDHook(KeyboardProcHook));
         IntPtr msgHookPtr = Marshal.GetFunctionPointerForDelegate(new WNDHook(GetMsgHook));

         hk_khook = NativeApi.SetWindowsHookEx(2, msKHookPtr, Marshal.GetHINSTANCE(typeof(VynkL).Module), 0);
         hk_mhook = NativeApi.SetWindowsHookEx(7, msHookPtr, Marshal.GetHINSTANCE(typeof(VynkL).Module), 0);
         hk_msghook = NativeApi.SetWindowsHookEx(3, msgHookPtr, Marshal.GetHINSTANCE(typeof(VynkL).Module), 0);
     }
     else
     {
         DefWindowProc defWindowProc = new DefWindowProc();
         defWindowProc.WindowHandle = hwnd;
         defWindowProc.Install();
         Hooks.Add(defWindowProc);
         defWindowProc.WindowProc += (IntPtr hWnd, uint msg, IntPtr wParam, IntPtr lParam) =>
         {
             try
             {
                 if (ImGuiInited && ShowMenu)
                 {
                     NativeApi.CImguiWrapper.CImGui_ImplWin32_WndProcHandler(hwnd, msg, wParam, lParam);
                 }
             }
             catch { }
             return IntPtr.Zero;
         };
         SetCursorPos NewHookCursor = new SetCursorPos();
         NewHookCursor.Install();
         Hooks.Add(NewHookCursor);
         NewHookCursor.SetCursorPos_Event += (int x, int y) =>
         {
             NewHookCursor.BlockInput = ShowMenu;
             return false;
         };
     }

Hey... I am still new to ImGui and the intricacies of handling input correctly, which is why I’ve been experimenting with these methods (I didn't found a correct way to handle custom input ;-;). My goal is to build a user interface and debugging tools for my 2d multiplayer game (a rythm game!), these sample code I post here is a part of debugging ui.

I know I'm hooking some windows api which kinda like cheating program, can you help me how to handle input correctly? (or just a way to send cursor/keyboard input to imgui)

I would greatly appreciate any guidance or support you can provide, as I am eager to improve my understanding of this process and create a legitimate application.

@ocornut
Copy link
Owner

ocornut commented Jan 12, 2025

The Getting Started guide states everything you need to do for the win32 backend which you are using. It seems pretty clear that you haven’t read those pages nor the FAQ. Your profile violates the rules as specified by #1586, those rules are designed to protect our time and energy and prevent help vampires from consuming too many resources which is detrimental to the development of dear imgui.

@H2143
Copy link

H2143 commented Jan 12, 2025

Sorry for violate the rules, I will try to read those pages and FAQ then try to fix it myself 😓
Thanks for respond, have a nice day!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants