Browse Source

OpenGL/GLFW: hide system cursor if imgui is soft-rendering cursor

Adam D. Moss 10 năm trước cách đây
mục cha
commit
c1766c95ed

+ 11 - 0
examples/opengl3_example/imgui_impl_glfw_gl3.cpp

@@ -351,6 +351,17 @@ void ImGui_ImplGlfwGL3_NewFrame()
     io.MouseWheel = g_MouseWheel;
     g_MouseWheel = 0.0f;
 
+    // Hide/show hardware mouse cursor
+    if (io.MouseDrawCursor)
+    {
+    	// imgui draws cursor itself
+    	glfwSetInputMode(g_Window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
+    }
+    else
+    {
+    	glfwSetInputMode(g_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
+    }
+
     // Start the frame
     ImGui::NewFrame();
 }

+ 11 - 0
examples/opengl_example/imgui_impl_glfw.cpp

@@ -255,6 +255,17 @@ void ImGui_ImplGlfw_NewFrame()
     io.MouseWheel = g_MouseWheel;
     g_MouseWheel = 0.0f;
 
+    // Hide/show hardware mouse cursor
+    if (io.MouseDrawCursor)
+    {
+    	// imgui draws cursor itself
+    	glfwSetInputMode(g_Window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
+    }
+    else
+    {
+    	glfwSetInputMode(g_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
+    }
+
     // Start the frame
     ImGui::NewFrame();
 }