Skip to content

Commit

Permalink
Added ImGui_ImplPlatform_SetUpdateMonitors() for edge case where DPI …
Browse files Browse the repository at this point in the history
…is 0.
  • Loading branch information
AndrewRichards-Code committed Nov 21, 2024
1 parent 2e47608 commit d129b9d
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 6 deletions.
46 changes: 46 additions & 0 deletions ImGui/imgui_impl_platform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include "Platform/CrossPlatform/Macros.h"
#include "Platform/CrossPlatform/GraphicsDeviceInterface.h"

#include "Platform/External/glfw/include/GLFW/glfw3.h"

using namespace platform;
using namespace crossplatform;

Expand All @@ -35,6 +37,43 @@ TextureHash MakeTextureHash(TextureCreate *tc)
return hash;
}

// GLFW data
enum GlfwClientApi
{
GlfwClientApi_Unknown,
GlfwClientApi_OpenGL,
GlfwClientApi_Vulkan
};

struct ImGui_ImplGlfw_Data
{
GLFWwindow *Window;
GlfwClientApi ClientApi;
double Time;
GLFWwindow *MouseWindow;
GLFWcursor *MouseCursors[ImGuiMouseCursor_COUNT];
ImVec2 LastValidMousePos;
GLFWwindow *KeyOwnerWindows[GLFW_KEY_LAST];
bool InstalledCallbacks;
bool CallbacksChainForAllWindows;
bool WantUpdateMonitors;
#ifdef _WIN32
WNDPROC GlfwWndProc;
#endif

// Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
GLFWwindowfocusfun PrevUserCallbackWindowFocus;
GLFWcursorposfun PrevUserCallbackCursorPos;
GLFWcursorenterfun PrevUserCallbackCursorEnter;
GLFWmousebuttonfun PrevUserCallbackMousebutton;
GLFWscrollfun PrevUserCallbackScroll;
GLFWkeyfun PrevUserCallbackKey;
GLFWcharfun PrevUserCallbackChar;
GLFWmonitorfun PrevUserCallbackMonitor;

ImGui_ImplGlfw_Data() { memset((void *)this, 0, sizeof(*this)); }
};

// Platform data
struct ImGui_ImplPlatform_Data
{
Expand Down Expand Up @@ -465,6 +504,13 @@ void ImGui_ImplPlatform_RenderDrawData(GraphicsDeviceContext &deviceContext,ImDr
renderPlatform->EndEvent(deviceContext);
}

void ImGui_ImplPlatform_SetUpdateMonitors()
{
ImGui_ImplGlfw_Data *bd = ImGui::GetCurrentContext() ? (ImGui_ImplGlfw_Data *)ImGui::GetIO().BackendPlatformUserData : nullptr;
if (bd)
bd->WantUpdateMonitors = true;
}

static void ImGui_ImplPlatform_CreateFontsTexture()
{
// Build texture atlas
Expand Down
14 changes: 8 additions & 6 deletions ImGui/imgui_impl_platform.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,17 @@ struct ImGui_ImplPlatform_TextureView

//! Initialize the Platform implementation. If hosted is set to true, this will also fill in ImGuiPlatformIO, e.g. if imgui is hosted
//! in a game engine etc instead of needing Win32 behaviour etc.
IMGUI_IMPL_API bool ImGui_ImplPlatform_Init(platform::crossplatform::RenderPlatform* r,bool hosted=false);
IMGUI_IMPL_API void ImGui_ImplPlatform_Shutdown();
IMGUI_IMPL_API void ImGui_ImplPlatform_NewFrame(bool in3d=false, int ui_pixel_width=400, int ui_pixel_height=300,const float *menupos=nullptr, float az=0.0f, float tilt=0.0f,float width_m=2.0f);
IMGUI_IMPL_API bool ImGui_ImplPlatform_Init(platform::crossplatform::RenderPlatform* r,bool hosted=false);
IMGUI_IMPL_API void ImGui_ImplPlatform_Shutdown();
IMGUI_IMPL_API void ImGui_ImplPlatform_NewFrame(bool in3d=false, int ui_pixel_width=400, int ui_pixel_height=300,const float *menupos=nullptr, float az=0.0f, float tilt=0.0f,float width_m=2.0f);
IMGUI_IMPL_API void ImGui_ImplPlatform_Win32_NewFrame();
IMGUI_IMPL_API void ImGui_ImplPlatform_RenderDrawData(platform::crossplatform::GraphicsDeviceContext& deviceContext, ImDrawData* draw_data);
IMGUI_IMPL_API void ImGui_ImplPlatform_RenderDrawData(platform::crossplatform::GraphicsDeviceContext& deviceContext, ImDrawData* draw_data);

IMGUI_IMPL_API void ImGui_ImplPlatform_SetUpdateMonitors();

// Use if you want to reset your rendering device without losing Dear ImGui state.
IMGUI_IMPL_API void ImGui_ImplPlatform_InvalidateDeviceObjects();
IMGUI_IMPL_API bool ImGui_ImplPlatform_CreateDeviceObjects();
IMGUI_IMPL_API void ImGui_ImplPlatform_InvalidateDeviceObjects();
IMGUI_IMPL_API bool ImGui_ImplPlatform_CreateDeviceObjects();

IMGUI_IMPL_API void ImGui_ImplPlatform_RecompileShaders();
IMGUI_IMPL_API void ImGui_ImplPlatform_LoadShaders();
Expand Down

0 comments on commit d129b9d

Please sign in to comment.