10 #define GLFW_EXPOSE_NATIVE_WIN32 14 #define GLFW_EXPOSE_NATIVE_X11 18 #include <GLFW/glfw3native.h> 22 namespace InternalImGui
27 GlfwClientApi_Unknown,
32 static GlfwClientApi g_ClientApi = GlfwClientApi_Unknown;
33 static bool g_MouseJustPressed[5] = {
false,
false,
false,
false,
false };
34 static bool g_InstalledCallbacks =
false;
37 static GLFWmousebuttonfun g_PrevUserCallbackMousebutton = NULL;
38 static GLFWscrollfun g_PrevUserCallbackScroll = NULL;
39 static GLFWkeyfun g_PrevUserCallbackKey = NULL;
40 static GLFWcharfun g_PrevUserCallbackChar = NULL;
42 static const char* ImGui_ImplGlfw_GetClipboardText(
void* user_data)
44 return glfwGetClipboardString((GLFWwindow*)user_data);
47 static void ImGui_ImplGlfw_SetClipboardText(
void* user_data,
const char* text)
49 glfwSetClipboardString((GLFWwindow*)user_data, text);
52 void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window,
int button,
int action,
int mods)
54 if (g_PrevUserCallbackMousebutton != NULL)
55 g_PrevUserCallbackMousebutton(window, button, action, mods);
57 if (action == GLFW_PRESS && button >= 0 && button < IM_ARRAYSIZE(g_MouseJustPressed))
58 g_MouseJustPressed[button] =
true;
61 void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window,
double xoffset,
double yoffset)
63 if (g_PrevUserCallbackScroll != NULL)
64 g_PrevUserCallbackScroll(window, xoffset, yoffset);
66 ImGuiIO& io = ImGui::GetIO();
67 io.MouseWheelH += (float)xoffset;
68 io.MouseWheel += (float)yoffset;
71 void ImGui_ImplGlfw_CharCallback(GLFWwindow* window,
unsigned int c)
73 if (g_PrevUserCallbackChar != NULL)
74 g_PrevUserCallbackChar(window, c);
76 ImGuiIO& io = ImGui::GetIO();
77 io.AddInputCharacter(c);
80 void ImGui_ImplGlfw_KeyCallback(GLFWwindow* window,
int key,
int scancode,
int action,
int mods)
82 if (g_PrevUserCallbackKey != NULL)
83 g_PrevUserCallbackKey(window, key, scancode, action, mods);
85 ImGuiIO& io = ImGui::GetIO();
86 if (action == GLFW_PRESS)
87 io.KeysDown[key] =
true;
88 if (action == GLFW_RELEASE)
89 io.KeysDown[key] =
false;
92 io.KeyCtrl = io.KeysDown[GLFW_KEY_LEFT_CONTROL] || io.KeysDown[GLFW_KEY_RIGHT_CONTROL];
93 io.KeyShift = io.KeysDown[GLFW_KEY_LEFT_SHIFT] || io.KeysDown[GLFW_KEY_RIGHT_SHIFT];
94 io.KeyAlt = io.KeysDown[GLFW_KEY_LEFT_ALT] || io.KeysDown[GLFW_KEY_RIGHT_ALT];
95 io.KeySuper = io.KeysDown[GLFW_KEY_LEFT_SUPER] || io.KeysDown[GLFW_KEY_RIGHT_SUPER];
98 void SetImGuiCallbacks()
100 if (!ImGui::GetCurrentContext())
102 ImGui::CreateContext();
105 ImGuiIO& io = ImGui::GetIO();
106 io.BackendFlags |= ImGuiBackendFlags_HasMouseCursors;
107 io.BackendFlags |= ImGuiBackendFlags_HasSetMousePos;
108 io.BackendPlatformName =
"imgui_impl_glfw";
137 io.SetClipboardTextFn = ImGui_ImplGlfw_SetClipboardText;
138 io.GetClipboardTextFn = ImGui_ImplGlfw_GetClipboardText;
139 io.ClipboardUserData = DesktopWin;
142 io.ImeWindowHandle = (
void*)glfwGetWin32Window(DesktopWin->GetGlfwWindow());
144 io.ImeWindowHandle = (
void*)glfwGetX11Window(DesktopWin->GetGlfwWindow());
147 g_PrevUserCallbackMousebutton =
nullptr;
148 g_PrevUserCallbackScroll =
nullptr;
149 g_PrevUserCallbackKey =
nullptr;
150 g_PrevUserCallbackChar =
nullptr;
152 GLFWwindow* Window = DesktopWin->GetGlfwWindow();
153 g_InstalledCallbacks =
true;
154 g_PrevUserCallbackMousebutton = glfwSetMouseButtonCallback(Window, ImGui_ImplGlfw_MouseButtonCallback);
155 g_PrevUserCallbackScroll = glfwSetScrollCallback(Window, ImGui_ImplGlfw_ScrollCallback);
156 g_PrevUserCallbackKey = glfwSetKeyCallback(Window, ImGui_ImplGlfw_KeyCallback);
157 g_PrevUserCallbackChar = glfwSetCharCallback(Window, ImGui_ImplGlfw_CharCallback);
159 g_ClientApi = GlfwClientApi_Vulkan;
#define FL_KEYCODE_END
Definition: LinuxKeycodes.h:74
#define FL_KEYCODE_C
Definition: LinuxKeycodes.h:29
#define FL_KEYCODE_PAGE_DOWN
Definition: LinuxKeycodes.h:72
#define FL_KEYCODE_TAB
Definition: LinuxKeycodes.h:63
#define FL_KEYCODE_RIGHT
Definition: LinuxKeycodes.h:67
#define FL_KEYCODE_ESCAPE
Definition: LinuxKeycodes.h:61
#define FL_KEYCODE_BACKSPACE
Definition: LinuxKeycodes.h:64
#define FL_KEYCODE_UP
Definition: LinuxKeycodes.h:70
#define FL_KEYCODE_A
Definition: LinuxKeycodes.h:27
#define FL_KEYCODE_DOWN
Definition: LinuxKeycodes.h:69
#define FL_KEYCODE_SPACE
Definition: LinuxKeycodes.h:9
#define FL_KEYCODE_V
Definition: LinuxKeycodes.h:48
#define FL_KEYCODE_HOME
Definition: LinuxKeycodes.h:73
#define FL_KEYCODE_ENTER
Definition: LinuxKeycodes.h:62
#define FL_KEYCODE_DELETE
Definition: LinuxKeycodes.h:66
#define FL_KEYCODE_PAGE_UP
Definition: LinuxKeycodes.h:71
FlingWindow * GetCurrentWindow() const
Definition: VulkanApp.h:57
#define FL_KEYCODE_Y
Definition: LinuxKeycodes.h:51
#define FL_KEYCODE_Z
Definition: LinuxKeycodes.h:52
#define FL_KEYCODE_X
Definition: LinuxKeycodes.h:50
static VulkanApp & Get()
Definition: Singleton.hpp:36
#define FL_KEYCODE_INSERT
Definition: LinuxKeycodes.h:65
#define FL_KEYCODE_KP_ENTER
Definition: LinuxKeycodes.h:120
#define FL_KEYCODE_LEFT
Definition: LinuxKeycodes.h:68