56 lines
2.5 KiB
Diff
56 lines
2.5 KiB
Diff
--- a/backends/imgui_impl_glfw.cpp
|
|
+++ b/backends/imgui_impl_glfw.cpp
|
|
@@ -422,6 +422,21 @@ void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused)
|
|
io.AddFocusEvent(focused != 0);
|
|
}
|
|
|
|
+static void ImGui_ImplGlfw_ScaleMousePos(GLFWwindow* window, double &x, double &y) {
|
|
+ // Get Window Size
|
|
+ int window_width, window_height;
|
|
+ glfwGetWindowSize(window, &window_width, &window_height);
|
|
+ if (window_width <= 0 || window_height <= 0) {
|
|
+ return;
|
|
+ }
|
|
+ // Get Framebuffer Size
|
|
+ int framebuffer_width, framebuffer_height;
|
|
+ glfwGetFramebufferSize(window, &framebuffer_width, &framebuffer_height);
|
|
+ // Multiply
|
|
+ x *= double(framebuffer_width) / double(window_width);
|
|
+ y *= double(framebuffer_height) / double(window_height);
|
|
+}
|
|
+
|
|
void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y)
|
|
{
|
|
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
|
|
@@ -429,6 +444,7 @@ void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y)
|
|
bd->PrevUserCallbackCursorPos(window, x, y);
|
|
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
+ ImGui_ImplGlfw_ScaleMousePos(window, x, y);
|
|
io.AddMousePosEvent((float)x, (float)y);
|
|
bd->LastValidMousePos = ImVec2((float)x, (float)y);
|
|
}
|
|
@@ -738,6 +754,7 @@ static void ImGui_ImplGlfw_UpdateMouseData()
|
|
{
|
|
double mouse_x, mouse_y;
|
|
glfwGetCursorPos(window, &mouse_x, &mouse_y);
|
|
+ ImGui_ImplGlfw_ScaleMousePos(window, mouse_x, mouse_y);
|
|
bd->LastValidMousePos = ImVec2((float)mouse_x, (float)mouse_y);
|
|
io.AddMousePosEvent((float)mouse_x, (float)mouse_y);
|
|
}
|
|
@@ -831,13 +848,9 @@ void ImGui_ImplGlfw_NewFrame()
|
|
IM_ASSERT(bd != nullptr && "Context or backend not initialized! Did you call ImGui_ImplGlfw_InitForXXX()?");
|
|
|
|
// Setup display size (every frame to accommodate for window resizing)
|
|
- int w, h;
|
|
int display_w, display_h;
|
|
- glfwGetWindowSize(bd->Window, &w, &h);
|
|
glfwGetFramebufferSize(bd->Window, &display_w, &display_h);
|
|
- io.DisplaySize = ImVec2((float)w, (float)h);
|
|
- if (w > 0 && h > 0)
|
|
- io.DisplayFramebufferScale = ImVec2((float)display_w / (float)w, (float)display_h / (float)h);
|
|
+ io.DisplaySize = ImVec2((float)display_w, (float)display_h);
|
|
|
|
// Setup time step
|
|
// (Accept glfwGetTime() not returning a monotonically increasing value. Seems to happens on disconnecting peripherals and probably on VMs and Emscripten, see #6491, #6189, #6114, #3644)
|