Nemirtingas / ingame_overlay

GNU General Public License v3.0
14 stars 4 forks source link

[Suggestion] Update ImGui window size when hook state becomes `Reset` #19

Closed otavepto closed 4 months ago

otavepto commented 4 months ago

Currently on Dx12/Dx11 and probably others when the game's window is changed the overlay size stays the same and doesn't update. This is (to my knowledge) the part which invokes the OveralyHookReady with state == Reset https://github.com/Nemirtingas/ingame_overlay/blob/843888fd1fee1ed29cf74490a49dd9ece6d2eabe/src/Windows/DX12Hook.cpp#L457-L468

I'm relying solely on the callbacks OverlayProc and OverlayHookReady to get notifications, and as a workaround I have this code inside the callback for OverlayHookReady

ImGuiIO &io = ImGui::GetIO();
auto bd = ImGui::GetCurrentContext() ? (ImGui_ImplWin32_Data*)ImGui::GetIO().BackendPlatformUserData : nullptr;;
if (bd) {
    // Setup display size (every frame to accommodate for window resizing)
    RECT rect = { 0, 0, 0, 0 };
    ::GetClientRect(bd->hWnd, &rect);
    io.DisplaySize = ImVec2((float)(rect.right - rect.left), (float)(rect.bottom - rect.top));
}

The above code is copied from ImGui backend for win32 https://github.com/ocornut/imgui/blob/fbf45ad149b10ff8d9cb97aefe0dc5a9562fd66e/backends/imgui_impl_win32.cpp#L373-L382

I have 2 suggestions:

Also wanted to ask, what's the point of invoking the callback OverlayHookReady with state == Reset ?, I didn't understand it very well.

I can submit a PR for suggestion 1 if you see this is a fitting change, I just don't know how to do this similarly for Linux/Mac, haven't looked at the other ImGui examples yet.

Please feel completely free to close this one if it's not fitting, out of scope, too much burden, etc...

Nemirtingas commented 4 months ago

Hi, OverlayHookState::Reset is sent back to the user so that the user is aware that a window/swapchain size has changed. It allows the user to do things when the game has been resized.

As for the overlay not resizing, I don't know what you are talking about. This library is not about drawing a fullscreen overlay, it allows someone to draw an overlay.

If you want your overlay to be the same size as your game, you just set your window size, like in the example :

https://github.com/Nemirtingas/ingame_overlay/blob/843888fd1fee1ed29cf74490a49dd9ece6d2eabe/tests/overlay_example/library_main.cpp#L113-L120

Animation

otavepto commented 4 months ago

Interesting, I can't achieve the same behavior. On my end, even after using the suggested code the overlay stays the same, io.DisplaySize still holds the old window size. Since it's working in the example, then it's something wrong on my end. Thanks nonetheless. I apologize for nagging lately.

Nemirtingas commented 4 months ago

Well, Maybe InGameOverlay has a bug, but if you have an issue, you should procure a reproductible example so people can work on the issue.

I'm trying to reproduce the issue right now, but I don't understand what might not be working.

Nemirtingas commented 4 months ago

No need to apologize. Better ask questions if you don't know/understand something.

otavepto commented 4 months ago

I figured it out, I compared the code I have with the example and the only part I didn't copy was this one https://github.com/Nemirtingas/ingame_overlay/blob/843888fd1fee1ed29cf74490a49dd9ece6d2eabe/tests/overlay_example/library_main.cpp#L162-L177

I thought it just prevents input confusion between game's window and overlay's window so just for testing I ignored it, but it turns out that HideOverlayInputs(bool flag) has a very important side effect, the boolean flag eventually propagates to this part of the code https://github.com/Nemirtingas/ingame_overlay/blob/843888fd1fee1ed29cf74490a49dd9ece6d2eabe/src/Windows/WindowsHook.cpp#L219-L224

Which does exactly what I suggested previously in point 1 😄 Told you it must be something wrong on my end. I truly apologize for what might seem like a waste of time, trust me it's quite difficult for someone who is not familiar with any of that to get things running the first time. Your project and the example (which I must read carefully) makes it an easy walk in the park. Thank you for this project really.

Nemirtingas commented 4 months ago

Learning something is never a waste of time. Glad you figured it out. 👍