diff --git a/Engine/include/Engine/ImGui/ImGuiLayer.h b/Engine/include/Engine/ImGui/ImGuiLayer.h index 2abc262..b427ed0 100644 --- a/Engine/include/Engine/ImGui/ImGuiLayer.h +++ b/Engine/include/Engine/ImGui/ImGuiLayer.h @@ -68,6 +68,7 @@ namespace Engine { // 生命周期保证:Application 成员序中 ImGuiLayer 在 Renderer 之后声明 //(先析构),因此 Device 引用在整个层生命周期内有效 Device& m_Device; + Window& m_Window; // 光标捕获状态查询(NewFrame hover 门控) vk::DescriptorPool m_Pool; bool m_Enabled = true; ImTextureID m_SceneTextures[kMaxFramesInFlight]{}; diff --git a/Engine/src/ImGui/ImGuiLayer.cpp b/Engine/src/ImGui/ImGuiLayer.cpp index 2cb9ecb..b0512d9 100644 --- a/Engine/src/ImGui/ImGuiLayer.cpp +++ b/Engine/src/ImGui/ImGuiLayer.cpp @@ -24,7 +24,7 @@ namespace Engine { } ImGuiLayer::ImGuiLayer(Window& window, Renderer& renderer) - : m_Device(renderer.GetDevice()) + : m_Device(renderer.GetDevice()), m_Window(window) { Device& device = renderer.GetDevice(); @@ -133,6 +133,13 @@ namespace Engine { { ImGui_ImplVulkan_NewFrame(); ImGui_ImplGlfw_NewFrame(); + // 光标捕获期间(RMB 自由视角 / MMB 环绕,GLFW_CURSOR_DISABLED), + // 官方后端每帧喂的虚拟无界坐标没有屏幕语义——hover 会随移动在 + // 面板间乱窜("鼠标被隐藏但 UI 被 hover")。在 NewFrame 处理 + // 事件前追加"鼠标离开"事件清空 hover,ImGui 本帧视为无鼠标 + if (m_Window.IsCursorCaptured()) { + ImGui::GetIO().AddMousePosEvent(-FLT_MAX, -FLT_MAX); + } ImGui::NewFrame(); }