mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-05 04:28:47 +02:00
Examples: Mouse cursor handling comments/tweaks to homogenize. (#1495)
This commit is contained in:
@ -44,7 +44,7 @@
|
||||
static Uint64 g_Time = 0;
|
||||
static bool g_MousePressed[3] = { false, false, false };
|
||||
static GLuint g_FontTexture = 0;
|
||||
static SDL_Cursor* g_SdlCursors[ImGuiMouseCursor_Count_] = { 0 };
|
||||
static SDL_Cursor* g_MouseCursors[ImGuiMouseCursor_Count_] = { 0 };
|
||||
|
||||
// OpenGL2 Render function.
|
||||
// (this used to be set in io.RenderDrawListsFn and called by ImGui::Render(), but you can now call this directly from your main loop)
|
||||
@ -252,13 +252,13 @@ bool ImGui_ImplSdlGL2_Init(SDL_Window* window)
|
||||
io.GetClipboardTextFn = ImGui_ImplSdlGL2_GetClipboardText;
|
||||
io.ClipboardUserData = NULL;
|
||||
|
||||
g_SdlCursors[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
||||
g_SdlCursors[ImGuiMouseCursor_TextInput] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM);
|
||||
g_SdlCursors[ImGuiMouseCursor_ResizeAll] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL);
|
||||
g_SdlCursors[ImGuiMouseCursor_ResizeNS] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS);
|
||||
g_SdlCursors[ImGuiMouseCursor_ResizeEW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE);
|
||||
g_SdlCursors[ImGuiMouseCursor_ResizeNESW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW);
|
||||
g_SdlCursors[ImGuiMouseCursor_ResizeNWSE] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE);
|
||||
g_MouseCursors[ImGuiMouseCursor_Arrow] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_ARROW);
|
||||
g_MouseCursors[ImGuiMouseCursor_TextInput] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_IBEAM);
|
||||
g_MouseCursors[ImGuiMouseCursor_ResizeAll] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEALL);
|
||||
g_MouseCursors[ImGuiMouseCursor_ResizeNS] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENS);
|
||||
g_MouseCursors[ImGuiMouseCursor_ResizeEW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZEWE);
|
||||
g_MouseCursors[ImGuiMouseCursor_ResizeNESW] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENESW);
|
||||
g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = SDL_CreateSystemCursor(SDL_SYSTEM_CURSOR_SIZENWSE);
|
||||
|
||||
#ifdef _WIN32
|
||||
SDL_SysWMinfo wmInfo;
|
||||
@ -274,10 +274,13 @@ bool ImGui_ImplSdlGL2_Init(SDL_Window* window)
|
||||
|
||||
void ImGui_ImplSdlGL2_Shutdown()
|
||||
{
|
||||
ImGui_ImplSdlGL2_InvalidateDeviceObjects();
|
||||
|
||||
// Destroy SDL mouse cursors
|
||||
for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_Count_; cursor_n++)
|
||||
SDL_FreeCursor(g_SdlCursors[cursor_n]);
|
||||
SDL_FreeCursor(g_MouseCursors[cursor_n]);
|
||||
memset(g_MouseCursors, 0, sizeof(g_MouseCursors));
|
||||
|
||||
// Destroy OpenGL objects
|
||||
ImGui_ImplSdlGL2_InvalidateDeviceObjects();
|
||||
}
|
||||
|
||||
void ImGui_ImplSdlGL2_NewFrame(SDL_Window *window)
|
||||
@ -326,7 +329,7 @@ void ImGui_ImplSdlGL2_NewFrame(SDL_Window *window)
|
||||
io.MousePos = ImVec2((float)mx, (float)my);
|
||||
#endif
|
||||
|
||||
// Hide OS mouse cursor if ImGui is drawing it
|
||||
// Update OS/hardware mouse cursor if imgui isn't drawing a software cursor
|
||||
ImGuiMouseCursor cursor = ImGui::GetMouseCursor();
|
||||
if (io.MouseDrawCursor || cursor == ImGuiMouseCursor_None)
|
||||
{
|
||||
@ -334,7 +337,7 @@ void ImGui_ImplSdlGL2_NewFrame(SDL_Window *window)
|
||||
}
|
||||
else
|
||||
{
|
||||
SDL_SetCursor(g_SdlCursors[cursor]);
|
||||
SDL_SetCursor(g_MouseCursors[cursor] ? g_MouseCursors[cursor] : g_MouseCursors[ImGuiMouseCursor_Arrow]);
|
||||
SDL_ShowCursor(1);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user