|
@@ -13,6 +13,7 @@
|
|
|
|
|
|
// CHANGELOG
|
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
|
+// 2018-02-20: Inputs: Added support for mouse cursors (ImGui::GetMouseCursor() value and WM_SETCURSOR message handling).
|
|
|
// 2018-02-20: Inputs: Renamed GLFW callbacks exposed in .h to not include GL3 in their name.
|
|
|
// 2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplGlfwGL3_RenderDrawData() in the .h file so you can call it yourself.
|
|
|
// 2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
|
|
@@ -42,10 +43,13 @@
|
|
|
#include <GLFW/glfw3native.h>
|
|
|
#endif
|
|
|
|
|
|
-// Data
|
|
|
+// GLFW data
|
|
|
static GLFWwindow* g_Window = NULL;
|
|
|
static double g_Time = 0.0f;
|
|
|
static bool g_MouseJustPressed[3] = { false, false, false };
|
|
|
+static GLFWcursor* g_MouseCursors[ImGuiMouseCursor_Count_] = { 0 };
|
|
|
+
|
|
|
+// OpenGL3 data
|
|
|
static GLuint g_FontTexture = 0;
|
|
|
static int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
|
|
|
static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0;
|
|
@@ -374,6 +378,16 @@ bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks)
|
|
|
io.ImeWindowHandle = glfwGetWin32Window(g_Window);
|
|
|
#endif
|
|
|
|
|
|
+ // Load cursors
|
|
|
+ // FIXME: GLFW doesn't expose suitable cursors for ResizeAll, ResizeNESW, ResizeNWSE. We revert to arrow cursor for those.
|
|
|
+ g_MouseCursors[ImGuiMouseCursor_Arrow] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
|
|
+ g_MouseCursors[ImGuiMouseCursor_TextInput] = glfwCreateStandardCursor(GLFW_IBEAM_CURSOR);
|
|
|
+ g_MouseCursors[ImGuiMouseCursor_ResizeAll] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
|
|
+ g_MouseCursors[ImGuiMouseCursor_ResizeNS] = glfwCreateStandardCursor(GLFW_VRESIZE_CURSOR);
|
|
|
+ g_MouseCursors[ImGuiMouseCursor_ResizeEW] = glfwCreateStandardCursor(GLFW_HRESIZE_CURSOR);
|
|
|
+ g_MouseCursors[ImGuiMouseCursor_ResizeNESW] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
|
|
+ g_MouseCursors[ImGuiMouseCursor_ResizeNWSE] = glfwCreateStandardCursor(GLFW_ARROW_CURSOR);
|
|
|
+
|
|
|
if (install_callbacks)
|
|
|
ImGui_ImplGlfw_InstallCallbacks(window);
|
|
|
|
|
@@ -382,6 +396,12 @@ bool ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks)
|
|
|
|
|
|
void ImGui_ImplGlfwGL3_Shutdown()
|
|
|
{
|
|
|
+ // Destroy GLFW mouse cursors
|
|
|
+ for (ImGuiMouseCursor cursor_n = 0; cursor_n < ImGuiMouseCursor_Count_; cursor_n++)
|
|
|
+ glfwDestroyCursor(g_MouseCursors[cursor_n]);
|
|
|
+ memset(g_MouseCursors, 0, sizeof(g_MouseCursors));
|
|
|
+
|
|
|
+ // Destroy OpenGL objects
|
|
|
ImGui_ImplGlfwGL3_InvalidateDeviceObjects();
|
|
|
}
|
|
|
|
|
@@ -432,8 +452,17 @@ void ImGui_ImplGlfwGL3_NewFrame()
|
|
|
g_MouseJustPressed[i] = false;
|
|
|
}
|
|
|
|
|
|
- // Hide OS mouse cursor if ImGui is drawing it
|
|
|
- glfwSetInputMode(g_Window, GLFW_CURSOR, io.MouseDrawCursor ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL);
|
|
|
+ // Update mouse cursor
|
|
|
+ ImGuiMouseCursor cursor = ImGui::GetMouseCursor();
|
|
|
+ if (io.MouseDrawCursor || cursor == ImGuiMouseCursor_None)
|
|
|
+ {
|
|
|
+ glfwSetInputMode(g_Window, GLFW_CURSOR, GLFW_CURSOR_HIDDEN);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ glfwSetInputMode(g_Window, GLFW_CURSOR, GLFW_CURSOR_NORMAL);
|
|
|
+ glfwSetCursor(g_Window, g_MouseCursors[cursor] ? g_MouseCursors[cursor] : g_MouseCursors[ImGuiMouseCursor_Arrow]);
|
|
|
+ }
|
|
|
|
|
|
// Gamepad navigation mapping [BETA]
|
|
|
memset(io.NavInputs, 0, sizeof(io.NavInputs));
|