Skip to content

Commit 0647ba3

Browse files
committed
Merge branch 'master' into docking
# Conflicts: # backends/imgui_impl_glfw.cpp # backends/imgui_impl_osx.h # backends/imgui_impl_osx.mm # backends/imgui_impl_sdl.cpp # backends/imgui_impl_win32.cpp
2 parents acfc779 + 200a8f1 commit 0647ba3

20 files changed

+315
-200
lines changed

backends/imgui_impl_allegro5.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -414,8 +414,6 @@ bool ImGui_ImplAllegro5_Init(ALLEGRO_DISPLAY* display)
414414
};
415415
bd->VertexDecl = al_create_vertex_decl(elems, sizeof(ImDrawVertAllegro));
416416

417-
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
418-
419417
#if ALLEGRO_HAS_CLIPBOARD
420418
io.SetClipboardTextFn = ImGui_ImplAllegro5_SetClipboardText;
421419
io.GetClipboardTextFn = ImGui_ImplAllegro5_GetClipboardText;

backends/imgui_impl_dx10.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
// CHANGELOG
1515
// (minor and older changes stripped away, please see git history for details)
16-
// 2021-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
16+
// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
1717
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
1818
// 2021-05-19: DirectX10: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
1919
// 2021-02-18: DirectX10: Change blending equation to preserve alpha in output buffer.

backends/imgui_impl_dx11.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
// CHANGELOG
1515
// (minor and older changes stripped away, please see git history for details)
16-
// 2021-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
16+
// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
1717
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
1818
// 2021-05-19: DirectX11: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
1919
// 2021-02-18: DirectX11: Change blending equation to preserve alpha in output buffer.

backends/imgui_impl_dx12.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
// CHANGELOG
2424
// (minor and older changes stripped away, please see git history for details)
25-
// 2021-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
25+
// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
2626
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
2727
// 2021-05-19: DirectX12: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)
2828
// 2021-02-18: DirectX12: Change blending equation to preserve alpha in output buffer.

backends/imgui_impl_dx9.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
// CHANGELOG
1515
// (minor and older changes stripped away, please see git history for details)
16-
// 2021-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
16+
// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
1717
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
1818
// 2021-06-25: DirectX9: Explicitly disable texture state stages after >= 1.
1919
// 2021-05-19: DirectX9: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)

backends/imgui_impl_glfw.cpp

+63-40
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020

2121
// CHANGELOG
2222
// (minor and older changes stripped away, please see git history for details)
23-
// 2021-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
23+
// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
24+
// 2022-01-12: *BREAKING CHANGE*: Now using glfwSetCursorPosCallback(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetCursorPosCallback() and forward it to the backend via ImGui_ImplGlfw_CursorPosCallback().
2425
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
2526
// 2022-01-05: Inputs: Converting GLFW untranslated keycodes back to translated keycodes (in the ImGui_ImplGlfw_KeyCallback() function) in order to match the behavior of every other backend, and facilitate the use of GLFW with lettered-shortcuts API.
2627
// 2021-08-17: *BREAKING CHANGE*: Now using glfwSetWindowFocusCallback() to calling io.AddFocusEvent(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetWindowFocusCallback() and forward it to the backend via ImGui_ImplGlfw_WindowFocusCallback().
@@ -111,6 +112,7 @@ struct ImGui_ImplGlfw_Data
111112

112113
// Chain GLFW callbacks: our callbacks will call the user's previously installed callbacks, if any.
113114
GLFWwindowfocusfun PrevUserCallbackWindowFocus;
115+
GLFWcursorposfun PrevUserCallbackCursorPos;
114116
GLFWcursorenterfun PrevUserCallbackCursorEnter;
115117
GLFWmousebuttonfun PrevUserCallbackMousebutton;
116118
GLFWscrollfun PrevUserCallbackScroll;
@@ -336,16 +338,37 @@ void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused)
336338
io.AddFocusEvent(focused != 0);
337339
}
338340

341+
void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y)
342+
{
343+
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
344+
if (bd->PrevUserCallbackCursorPos != NULL && window == bd->Window)
345+
bd->PrevUserCallbackCursorPos(window, x, y);
346+
347+
ImGuiIO& io = ImGui::GetIO();
348+
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
349+
{
350+
int window_x, window_y;
351+
glfwGetWindowPos(window, &window_x, &window_y);
352+
x += window_x;
353+
y += window_y;
354+
}
355+
io.MousePos = ImVec2((float)x, (float)y);
356+
}
357+
339358
void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered)
340359
{
341360
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
342361
if (bd->PrevUserCallbackCursorEnter != NULL && window == bd->Window)
343362
bd->PrevUserCallbackCursorEnter(window, entered);
344363

364+
ImGuiIO& io = ImGui::GetIO();
345365
if (entered)
346366
bd->MouseWindow = window;
347367
if (!entered && bd->MouseWindow == window)
368+
{
348369
bd->MouseWindow = NULL;
370+
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
371+
}
349372
}
350373

351374
void ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c)
@@ -424,6 +447,7 @@ static bool ImGui_ImplGlfw_Init(GLFWwindow* window, bool install_callbacks, Glfw
424447
bd->InstalledCallbacks = true;
425448
bd->PrevUserCallbackWindowFocus = glfwSetWindowFocusCallback(window, ImGui_ImplGlfw_WindowFocusCallback);
426449
bd->PrevUserCallbackCursorEnter = glfwSetCursorEnterCallback(window, ImGui_ImplGlfw_CursorEnterCallback);
450+
bd->PrevUserCallbackCursorPos = glfwSetCursorPosCallback(window, ImGui_ImplGlfw_CursorPosCallback);
427451
bd->PrevUserCallbackMousebutton = glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback);
428452
bd->PrevUserCallbackScroll = glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback);
429453
bd->PrevUserCallbackKey = glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback);
@@ -475,6 +499,7 @@ void ImGui_ImplGlfw_Shutdown()
475499
{
476500
glfwSetWindowFocusCallback(bd->Window, bd->PrevUserCallbackWindowFocus);
477501
glfwSetCursorEnterCallback(bd->Window, bd->PrevUserCallbackCursorEnter);
502+
glfwSetCursorPosCallback(bd->Window, bd->PrevUserCallbackCursorPos);
478503
glfwSetMouseButtonCallback(bd->Window, bd->PrevUserCallbackMousebutton);
479504
glfwSetScrollCallback(bd->Window, bd->PrevUserCallbackScroll);
480505
glfwSetKeyCallback(bd->Window, bd->PrevUserCallbackKey);
@@ -490,61 +515,52 @@ void ImGui_ImplGlfw_Shutdown()
490515
IM_DELETE(bd);
491516
}
492517

493-
static void ImGui_ImplGlfw_UpdateMousePosAndButtons()
518+
static void ImGui_ImplGlfw_UpdateMouseData()
494519
{
495520
ImGui_ImplGlfw_Data* bd = ImGui_ImplGlfw_GetBackendData();
496521
ImGuiIO& io = ImGui::GetIO();
497522
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
498523

499-
const ImVec2 mouse_pos_prev = io.MousePos;
500-
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
501524
io.MouseHoveredViewport = 0;
502525

503-
// Update mouse buttons
504-
// (if a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame)
505-
for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++)
506-
{
507-
io.MouseDown[i] = bd->MouseJustPressed[i] || glfwGetMouseButton(bd->Window, i) != 0;
508-
bd->MouseJustPressed[i] = false;
509-
}
510-
526+
const ImVec2 mouse_pos_prev = io.MousePos;
527+
int mouse_buttons_mask = 0x00;
511528
for (int n = 0; n < platform_io.Viewports.Size; n++)
512529
{
513530
ImGuiViewport* viewport = platform_io.Viewports[n];
514531
GLFWwindow* window = (GLFWwindow*)viewport->PlatformHandle;
515532

516533
#ifdef __EMSCRIPTEN__
517-
const bool focused = true;
534+
const bool is_window_focused = true;
518535
#else
519-
const bool focused = glfwGetWindowAttrib(window, GLFW_FOCUSED) != 0;
536+
const bool is_window_focused = glfwGetWindowAttrib(window, GLFW_FOCUSED) != 0;
520537
#endif
521-
GLFWwindow* mouse_window = (bd->MouseWindow == window || focused) ? window : NULL;
522-
523-
// Update mouse buttons
524-
if (focused)
538+
if (is_window_focused)
539+
{
540+
// Update mouse button mask (applied below)
525541
for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++)
526-
io.MouseDown[i] |= glfwGetMouseButton(window, i) != 0;
542+
if (glfwGetMouseButton(window, i) != 0)
543+
mouse_buttons_mask |= (1 << i);
527544

528-
// Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
529-
// (When multi-viewports are enabled, all Dear ImGui positions are same as OS positions)
530-
if (io.WantSetMousePos && focused)
531-
glfwSetCursorPos(window, (double)(mouse_pos_prev.x - viewport->Pos.x), (double)(mouse_pos_prev.y - viewport->Pos.y));
545+
// (Optional) Set OS mouse position from Dear ImGui if requested (rarely used, only when ImGuiConfigFlags_NavEnableSetMousePos is enabled by user)
546+
// When multi-viewports are enabled, all Dear ImGui positions are same as OS positions.
547+
if (io.WantSetMousePos)
548+
glfwSetCursorPos(window, (double)(mouse_pos_prev.x - viewport->Pos.x), (double)(mouse_pos_prev.y - viewport->Pos.y));
532549

533-
// Set Dear ImGui mouse position from OS position
534-
if (mouse_window != NULL)
535-
{
536-
double mouse_x, mouse_y;
537-
glfwGetCursorPos(mouse_window, &mouse_x, &mouse_y);
538-
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
539-
{
540-
// Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor)
541-
int window_x, window_y;
542-
glfwGetWindowPos(window, &window_x, &window_y);
543-
io.MousePos = ImVec2((float)mouse_x + window_x, (float)mouse_y + window_y);
544-
}
545-
else
550+
// (Optional) Fallback to provide mouse position when focused (ImGui_ImplGlfw_CursorPosCallback already provides this when hovered or captured)
551+
if (bd->MouseWindow == NULL)
546552
{
547-
// Single viewport mode: mouse position in client window coordinates (io.MousePos is (0,0) when the mouse is on the upper-left corner of the app window)
553+
double mouse_x, mouse_y;
554+
glfwGetCursorPos(window, &mouse_x, &mouse_y);
555+
if (io.ConfigFlags & ImGuiConfigFlags_ViewportsEnable)
556+
{
557+
// Single viewport mode: mouse position in client window coordinates (io.MousePos is (0,0) when the mouse is on the upper-left corner of the app window)
558+
// Multi-viewport mode: mouse position in OS absolute coordinates (io.MousePos is (0,0) when the mouse is on the upper-left of the primary monitor)
559+
int window_x, window_y;
560+
glfwGetWindowPos(window, &window_x, &window_y);
561+
mouse_x += window_x;
562+
mouse_y += window_y;
563+
}
548564
io.MousePos = ImVec2((float)mouse_x, (float)mouse_y);
549565
}
550566
}
@@ -566,6 +582,14 @@ static void ImGui_ImplGlfw_UpdateMousePosAndButtons()
566582
io.MouseHoveredViewport = viewport->ID;
567583
#endif
568584
}
585+
586+
// Update mouse buttons
587+
// (if a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame)
588+
for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++)
589+
{
590+
io.MouseDown[i] = bd->MouseJustPressed[i] || (mouse_buttons_mask & (1 << i)) != 0;
591+
bd->MouseJustPressed[i] = false;
592+
}
569593
}
570594

571595
static void ImGui_ImplGlfw_UpdateMouseCursor()
@@ -701,10 +725,8 @@ void ImGui_ImplGlfw_NewFrame()
701725
io.DeltaTime = bd->Time > 0.0 ? (float)(current_time - bd->Time) : (float)(1.0f / 60.0f);
702726
bd->Time = current_time;
703727

704-
// Update key modifiers
705728
ImGui_ImplGlfw_UpdateKeyModifiers();
706-
707-
ImGui_ImplGlfw_UpdateMousePosAndButtons();
729+
ImGui_ImplGlfw_UpdateMouseData();
708730
ImGui_ImplGlfw_UpdateMouseCursor();
709731

710732
// Update game controllers (if enabled and available)
@@ -800,6 +822,7 @@ static void ImGui_ImplGlfw_CreateWindow(ImGuiViewport* viewport)
800822
// Install GLFW callbacks for secondary viewports
801823
glfwSetWindowFocusCallback(vd->Window, ImGui_ImplGlfw_WindowFocusCallback);
802824
glfwSetCursorEnterCallback(vd->Window, ImGui_ImplGlfw_CursorEnterCallback);
825+
glfwSetCursorPosCallback(vd->Window, ImGui_ImplGlfw_CursorPosCallback);
803826
glfwSetMouseButtonCallback(vd->Window, ImGui_ImplGlfw_MouseButtonCallback);
804827
glfwSetScrollCallback(vd->Window, ImGui_ImplGlfw_ScrollCallback);
805828
glfwSetKeyCallback(vd->Window, ImGui_ImplGlfw_KeyCallback);

backends/imgui_impl_glfw.h

+3-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ IMGUI_IMPL_API void ImGui_ImplGlfw_NewFrame();
3737
// GLFW callbacks
3838
// - When calling Init with 'install_callbacks=true': GLFW callbacks will be installed for you. They will call user's previously installed callbacks, if any.
3939
// - When calling Init with 'install_callbacks=false': GLFW callbacks won't be installed. You will need to call those function yourself from your own GLFW callbacks.
40-
IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused);
41-
IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered);
40+
IMGUI_IMPL_API void ImGui_ImplGlfw_WindowFocusCallback(GLFWwindow* window, int focused); // Since 1.84
41+
IMGUI_IMPL_API void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered); // Since 1.84
42+
IMGUI_IMPL_API void ImGui_ImplGlfw_CursorPosCallback(GLFWwindow* window, double x, double y); // Since 1.87
4243
IMGUI_IMPL_API void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
4344
IMGUI_IMPL_API void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
4445
IMGUI_IMPL_API void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);

backends/imgui_impl_opengl2.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
// CHANGELOG
2222
// (minor and older changes stripped away, please see git history for details)
23-
// 2021-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
23+
// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
2424
// 2021-12-08: OpenGL: Fixed mishandling of the the ImDrawCmd::IdxOffset field! This is an old bug but it never had an effect until some internal rendering changes in 1.86.
2525
// 2021-06-29: Reorganized backend to pull data from a single structure to facilitate usage with multiple-contexts (all g_XXXX access changed to bd->XXXX).
2626
// 2021-05-19: OpenGL: Replaced direct access to ImDrawCmd::TextureId with a call to ImDrawCmd::GetTexID(). (will become a requirement)

backends/imgui_impl_opengl3.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616
// CHANGELOG
1717
// (minor and older changes stripped away, please see git history for details)
18-
// 2021-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
18+
// 2022-XX-XX: Platform: Added support for multiple windows via the ImGuiPlatformIO interface.
1919
// 2021-12-15: OpenGL: Using buffer orphaning + glBufferSubData(), seems to fix leaks with multi-viewports with some Intel HD drivers.
2020
// 2021-08-23: OpenGL: Fixed ES 3.0 shader ("#version 300 es") use normal precision floats to avoid wobbly rendering at HD resolutions.
2121
// 2021-08-19: OpenGL: Embed and use our own minimal GL loader (imgui_impl_opengl3_loader.h), removing requirement and support for third-party loader.

backends/imgui_impl_osx.h

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
// [X] Platform: Keyboard support. Since 1.87 we are using the io.AddKeyEvent() function. Pass ImGuiKey values to all key functions e.g. ImGui::IsKeyPressed(ImGuiKey_Space). [Legacy kVK_* values will also be supported unless IMGUI_DISABLE_OBSOLETE_KEYIO is set]
88
// [X] Platform: OSX clipboard is supported within core Dear ImGui (no specific code in this backend).
99
// [X] Platform: Gamepad support. Enabled with 'io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad'.
10+
// [X] Platform: IME support.
1011
// Issues:
1112
// [ ] Platform: Multi-viewport / platform windows.
1213

0 commit comments

Comments
 (0)