mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-07 21:39:54 +02:00
Backends: Win32, SDL, GLFW: only honor io.WantSetMousePos when focused + fix GLFW uninstalling handler + tweaks to reduce branch drift with docking. (#787, #2445, #2696, #3751, #4377)
This commit is contained in:
@ -219,31 +219,36 @@ static bool ImGui_ImplWin32_UpdateMouseCursor()
|
||||
|
||||
static void ImGui_ImplWin32_UpdateMousePos()
|
||||
{
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
ImGui_ImplWin32_Data* bd = ImGui_ImplWin32_GetBackendData();
|
||||
ImGuiIO& io = ImGui::GetIO();
|
||||
IM_ASSERT(bd->hWnd != 0);
|
||||
|
||||
// Set OS mouse position if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
|
||||
const ImVec2 mouse_pos_prev = io.MousePos;
|
||||
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
|
||||
|
||||
// Obtain focused and hovered window. We forward mouse input when focused or when hovered (and no other window is capturing)
|
||||
HWND focused_window = ::GetForegroundWindow();
|
||||
HWND hovered_window = bd->MouseHwnd;
|
||||
HWND mouse_window = NULL;
|
||||
if (hovered_window && (hovered_window == bd->hWnd || ::IsChild(hovered_window, bd->hWnd)))
|
||||
mouse_window = hovered_window;
|
||||
else if (focused_window && (focused_window == bd->hWnd || ::IsChild(focused_window, bd->hWnd)))
|
||||
mouse_window = focused_window;
|
||||
if (mouse_window == NULL)
|
||||
return;
|
||||
|
||||
// Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
|
||||
if (io.WantSetMousePos)
|
||||
{
|
||||
POINT pos = { (int)io.MousePos.x, (int)io.MousePos.y };
|
||||
POINT pos = { (int)mouse_pos_prev.x, (int)mouse_pos_prev.y };
|
||||
if (::ClientToScreen(bd->hWnd, &pos))
|
||||
::SetCursorPos(pos.x, pos.y);
|
||||
}
|
||||
|
||||
// Set mouse position
|
||||
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
|
||||
HWND focused_window = ::GetForegroundWindow();
|
||||
HWND hovered_window = bd->MouseHwnd;
|
||||
HWND mouse_window = NULL;
|
||||
if (hovered_window && (hovered_window == bd->hWnd) || ::IsChild(hovered_window, bd->hWnd))
|
||||
mouse_window = hovered_window;
|
||||
else if (focused_window && (focused_window == bd->hWnd) || ::IsChild(focused_window, bd->hWnd))
|
||||
mouse_window = focused_window;
|
||||
// Set Dear ImGui mouse position from OS position
|
||||
POINT pos;
|
||||
if (mouse_window)
|
||||
if (::GetCursorPos(&pos) && ::ScreenToClient(mouse_window, &pos))
|
||||
io.MousePos = ImVec2((float)pos.x, (float)pos.y);
|
||||
if (::GetCursorPos(&pos) && ::ScreenToClient(mouse_window, &pos))
|
||||
io.MousePos = ImVec2((float)pos.x, (float)pos.y);
|
||||
}
|
||||
|
||||
// Gamepad navigation mapping
|
||||
|
Reference in New Issue
Block a user