mirror of
https://github.com/ocornut/imgui.git
synced 2024-12-12 12:09:02 +08:00
Viewport, Platform: Cleaned up xxx_UpdateMouseCursor() functions to make them more consistent. (#1542)
This commit is contained in:
parent
d574604a5d
commit
090eb437ed
@ -196,7 +196,7 @@ void ImGui_ImplGlfw_Shutdown()
|
|||||||
g_ClientApi = GlfwClientApi_Unknown;
|
g_ClientApi = GlfwClientApi_Unknown;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplGlfw_UpdateMouse()
|
static void ImGui_ImplGlfw_UpdateMousePosAndButtons()
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
const ImVec2 mouse_pos_backup = io.MousePos;
|
const ImVec2 mouse_pos_backup = io.MousePos;
|
||||||
@ -241,26 +241,32 @@ static void ImGui_ImplGlfw_UpdateMouse()
|
|||||||
io.MouseHoveredViewport = viewport->ID;
|
io.MouseHoveredViewport = viewport->ID;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Update OS/hardware mouse cursor if imgui isn't drawing a software cursor
|
static void ImGui_ImplGlfw_UpdateMouseCursor()
|
||||||
// FIXME-PLATFORM: Unfocused windows seems to fail changing the mouse cursor with GLFW 3.2, but 3.3 works here.
|
{
|
||||||
if ((io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) == 0 && glfwGetInputMode(g_Window, GLFW_CURSOR) != GLFW_CURSOR_DISABLED)
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
{
|
if ((io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) || glfwGetInputMode(g_Window, GLFW_CURSOR) == GLFW_CURSOR_DISABLED)
|
||||||
ImGuiMouseCursor cursor = ImGui::GetMouseCursor();
|
return;
|
||||||
|
|
||||||
|
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
||||||
|
ImGuiPlatformIO& platform_io = ImGui::GetPlatformIO();
|
||||||
for (int n = 0; n < platform_io.Viewports.Size; n++)
|
for (int n = 0; n < platform_io.Viewports.Size; n++)
|
||||||
{
|
{
|
||||||
GLFWwindow* window = (GLFWwindow*)platform_io.Viewports[n]->PlatformHandle;
|
GLFWwindow* window = (GLFWwindow*)platform_io.Viewports[n]->PlatformHandle;
|
||||||
if (io.MouseDrawCursor || cursor == ImGuiMouseCursor_None)
|
if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor)
|
||||||
{
|
{
|
||||||
|
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
glfwSetCursor(window, g_MouseCursors[cursor] ? g_MouseCursors[cursor] : g_MouseCursors[ImGuiMouseCursor_Arrow]);
|
// Show OS mouse cursor
|
||||||
|
// FIXME-PLATFORM: Unfocused windows seems to fail changing the mouse cursor with GLFW 3.2, but 3.3 works here.
|
||||||
|
glfwSetCursor(window, g_MouseCursors[imgui_cursor] ? g_MouseCursors[imgui_cursor] : g_MouseCursors[ImGuiMouseCursor_Arrow]);
|
||||||
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplGlfw_NewFrame()
|
void ImGui_ImplGlfw_NewFrame()
|
||||||
@ -283,7 +289,8 @@ void ImGui_ImplGlfw_NewFrame()
|
|||||||
io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f);
|
io.DeltaTime = g_Time > 0.0 ? (float)(current_time - g_Time) : (float)(1.0f/60.0f);
|
||||||
g_Time = current_time;
|
g_Time = current_time;
|
||||||
|
|
||||||
ImGui_ImplGlfw_UpdateMouse();
|
ImGui_ImplGlfw_UpdateMousePosAndButtons();
|
||||||
|
ImGui_ImplGlfw_UpdateMouseCursor();
|
||||||
|
|
||||||
// Gamepad navigation mapping [BETA]
|
// Gamepad navigation mapping [BETA]
|
||||||
memset(io.NavInputs, 0, sizeof(io.NavInputs));
|
memset(io.NavInputs, 0, sizeof(io.NavInputs));
|
||||||
|
@ -197,7 +197,7 @@ void ImGui_ImplSDL2_Shutdown()
|
|||||||
memset(g_MouseCursors, 0, sizeof(g_MouseCursors));
|
memset(g_MouseCursors, 0, sizeof(g_MouseCursors));
|
||||||
}
|
}
|
||||||
|
|
||||||
static void ImGui_ImplSDL2_UpdateMouse()
|
static void ImGui_ImplSDL2_UpdateMousePosAndButtons()
|
||||||
{
|
{
|
||||||
ImGuiIO& io = ImGui::GetIO();
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
const ImVec2 mouse_pos_backup = io.MousePos;
|
const ImVec2 mouse_pos_backup = io.MousePos;
|
||||||
@ -250,21 +250,26 @@ static void ImGui_ImplSDL2_UpdateMouse()
|
|||||||
if (SDL_GetWindowFlags(g_Window) & SDL_WINDOW_INPUT_FOCUS)
|
if (SDL_GetWindowFlags(g_Window) & SDL_WINDOW_INPUT_FOCUS)
|
||||||
io.MousePos = ImVec2((float)mx, (float)my);
|
io.MousePos = ImVec2((float)mx, (float)my);
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
// Update OS/hardware mouse cursor if imgui isn't drawing a software cursor
|
static void ImGui_ImplSDL2_UpdateMouseCursor()
|
||||||
if ((io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange) == 0)
|
{
|
||||||
{
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
ImGuiMouseCursor cursor = ImGui::GetMouseCursor();
|
if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
|
||||||
if (io.MouseDrawCursor || cursor == ImGuiMouseCursor_None)
|
return;
|
||||||
|
|
||||||
|
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
||||||
|
if (io.MouseDrawCursor || imgui_cursor == ImGuiMouseCursor_None)
|
||||||
{
|
{
|
||||||
|
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
||||||
SDL_ShowCursor(SDL_FALSE);
|
SDL_ShowCursor(SDL_FALSE);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
SDL_SetCursor(g_MouseCursors[cursor] ? g_MouseCursors[cursor] : g_MouseCursors[ImGuiMouseCursor_Arrow]);
|
// Show OS mouse cursor
|
||||||
|
SDL_SetCursor(g_MouseCursors[imgui_cursor] ? g_MouseCursors[imgui_cursor] : g_MouseCursors[ImGuiMouseCursor_Arrow]);
|
||||||
SDL_ShowCursor(SDL_TRUE);
|
SDL_ShowCursor(SDL_TRUE);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplSDL2_NewFrame(SDL_Window* window)
|
void ImGui_ImplSDL2_NewFrame(SDL_Window* window)
|
||||||
@ -286,7 +291,8 @@ void ImGui_ImplSDL2_NewFrame(SDL_Window* window)
|
|||||||
io.DeltaTime = g_Time > 0 ? (float)((double)(current_time - g_Time) / frequency) : (float)(1.0f / 60.0f);
|
io.DeltaTime = g_Time > 0 ? (float)((double)(current_time - g_Time) / frequency) : (float)(1.0f / 60.0f);
|
||||||
g_Time = current_time;
|
g_Time = current_time;
|
||||||
|
|
||||||
ImGui_ImplSDL2_UpdateMouse();
|
ImGui_ImplSDL2_UpdateMousePosAndButtons();
|
||||||
|
ImGui_ImplSDL2_UpdateMouseCursor();
|
||||||
|
|
||||||
// Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application.
|
// Start the frame. This call will update the io.WantCaptureMouse, io.WantCaptureKeyboard flag that you can use to dispatch inputs (or not) to your application.
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
@ -94,15 +94,15 @@ static bool ImGui_ImplWin32_UpdateMouseCursor()
|
|||||||
if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
|
if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
ImGuiMouseCursor imgui_cursor = io.MouseDrawCursor ? ImGuiMouseCursor_None : ImGui::GetMouseCursor();
|
ImGuiMouseCursor imgui_cursor = ImGui::GetMouseCursor();
|
||||||
if (imgui_cursor == ImGuiMouseCursor_None)
|
if (imgui_cursor == ImGuiMouseCursor_None || io.MouseDrawCursor)
|
||||||
{
|
{
|
||||||
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
// Hide OS mouse cursor if imgui is drawing it or if it wants no cursor
|
||||||
::SetCursor(NULL);
|
::SetCursor(NULL);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Hardware cursor type
|
// Show OS mouse cursor
|
||||||
LPTSTR win32_cursor = IDC_ARROW;
|
LPTSTR win32_cursor = IDC_ARROW;
|
||||||
switch (imgui_cursor)
|
switch (imgui_cursor)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user