mirror of
				https://github.com/ocornut/imgui.git
				synced 2025-11-04 01:34:32 +00:00 
			
		
		
		
	Examples: GLFW*: Renamed GLFW callbacks exposed in .h to not include GL2/GL3/Vulkan in their name.
This commit is contained in:
		@@ -19,6 +19,7 @@
 | 
			
		||||
 | 
			
		||||
// CHANGELOG
 | 
			
		||||
// (minor and older changes stripped away, please see git history for details)
 | 
			
		||||
//  2018-02-20: Inputs: Renamed GLFW callbacks exposed in .h to not include GL2 in their name.
 | 
			
		||||
//  2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback and exposed ImGui_ImplGlfwGL2_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.
 | 
			
		||||
//  2018-02-06: Inputs: Added mapping for ImGuiKey_Space.
 | 
			
		||||
@@ -144,20 +145,20 @@ static void ImGui_ImplGlfwGL2_SetClipboardText(void* user_data, const char* text
 | 
			
		||||
    glfwSetClipboardString((GLFWwindow*)user_data, text);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImGui_ImplGlfwGL2_MouseButtonCallback(GLFWwindow*, int button, int action, int /*mods*/)
 | 
			
		||||
void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow*, int button, int action, int /*mods*/)
 | 
			
		||||
{
 | 
			
		||||
    if (action == GLFW_PRESS && button >= 0 && button < 3)
 | 
			
		||||
        g_MouseJustPressed[button] = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImGui_ImplGlfwGL2_ScrollCallback(GLFWwindow*, double xoffset, double yoffset)
 | 
			
		||||
void ImGui_ImplGlfw_ScrollCallback(GLFWwindow*, double xoffset, double yoffset)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiIO& io = ImGui::GetIO();
 | 
			
		||||
    io.MouseWheelH += (float)xoffset;
 | 
			
		||||
    io.MouseWheel += (float)yoffset;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImGui_ImplGlfwGL2_KeyCallback(GLFWwindow*, int key, int, int action, int mods)
 | 
			
		||||
void ImGui_ImplGlfw_KeyCallback(GLFWwindow*, int key, int, int action, int mods)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiIO& io = ImGui::GetIO();
 | 
			
		||||
    if (action == GLFW_PRESS)
 | 
			
		||||
@@ -172,7 +173,7 @@ void ImGui_ImplGlfwGL2_KeyCallback(GLFWwindow*, int key, int, int action, int mo
 | 
			
		||||
    io.KeySuper = io.KeysDown[GLFW_KEY_LEFT_SUPER] || io.KeysDown[GLFW_KEY_RIGHT_SUPER];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImGui_ImplGlfwGL2_CharCallback(GLFWwindow*, unsigned int c)
 | 
			
		||||
void ImGui_ImplGlfw_CharCallback(GLFWwindow*, unsigned int c)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiIO& io = ImGui::GetIO();
 | 
			
		||||
    if (c > 0 && c < 0x10000)
 | 
			
		||||
@@ -216,6 +217,14 @@ void    ImGui_ImplGlfwGL2_InvalidateDeviceObjects()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window)
 | 
			
		||||
{
 | 
			
		||||
    glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback);
 | 
			
		||||
    glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback);
 | 
			
		||||
    glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback);
 | 
			
		||||
    glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool    ImGui_ImplGlfwGL2_Init(GLFWwindow* window, bool install_callbacks)
 | 
			
		||||
{
 | 
			
		||||
    g_Window = window;
 | 
			
		||||
@@ -251,12 +260,7 @@ bool    ImGui_ImplGlfwGL2_Init(GLFWwindow* window, bool install_callbacks)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    if (install_callbacks)
 | 
			
		||||
    {
 | 
			
		||||
        glfwSetMouseButtonCallback(window, ImGui_ImplGlfwGL2_MouseButtonCallback);
 | 
			
		||||
        glfwSetScrollCallback(window, ImGui_ImplGlfwGL2_ScrollCallback);
 | 
			
		||||
        glfwSetKeyCallback(window, ImGui_ImplGlfwGL2_KeyCallback);
 | 
			
		||||
        glfwSetCharCallback(window, ImGui_ImplGlfwGL2_CharCallback);
 | 
			
		||||
    }
 | 
			
		||||
        ImGui_ImplGlfw_InstallCallbacks(window);
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -26,7 +26,7 @@ IMGUI_API bool        ImGui_ImplGlfwGL2_CreateDeviceObjects();
 | 
			
		||||
 | 
			
		||||
// GLFW callbacks (registered by default to GLFW if you enable 'install_callbacks' during initialization)
 | 
			
		||||
// Provided here if you want to chain callbacks yourself. You may also handle inputs yourself and use those as a reference.
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfwGL2_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfwGL2_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfwGL2_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfwGL2_CharCallback(GLFWwindow* window, unsigned int c);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c);
 | 
			
		||||
 
 | 
			
		||||
@@ -13,6 +13,7 @@
 | 
			
		||||
 | 
			
		||||
// CHANGELOG
 | 
			
		||||
// (minor and older changes stripped away, please see git history for details)
 | 
			
		||||
//  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.
 | 
			
		||||
//  2018-02-06: Inputs: Added mapping for ImGuiKey_Space.
 | 
			
		||||
@@ -168,20 +169,20 @@ static void ImGui_ImplGlfwGL3_SetClipboardText(void* user_data, const char* text
 | 
			
		||||
    glfwSetClipboardString((GLFWwindow*)user_data, text);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImGui_ImplGlfwGL3_MouseButtonCallback(GLFWwindow*, int button, int action, int /*mods*/)
 | 
			
		||||
void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow*, int button, int action, int /*mods*/)
 | 
			
		||||
{
 | 
			
		||||
    if (action == GLFW_PRESS && button >= 0 && button < 3)
 | 
			
		||||
        g_MouseJustPressed[button] = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImGui_ImplGlfwGL3_ScrollCallback(GLFWwindow*, double xoffset, double yoffset)
 | 
			
		||||
void ImGui_ImplGlfw_ScrollCallback(GLFWwindow*, double xoffset, double yoffset)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiIO& io = ImGui::GetIO();
 | 
			
		||||
    io.MouseWheelH += (float)xoffset;
 | 
			
		||||
    io.MouseWheel += (float)yoffset;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImGui_ImplGlfwGL3_KeyCallback(GLFWwindow*, int key, int, int action, int mods)
 | 
			
		||||
void ImGui_ImplGlfw_KeyCallback(GLFWwindow*, int key, int, int action, int mods)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiIO& io = ImGui::GetIO();
 | 
			
		||||
    if (action == GLFW_PRESS)
 | 
			
		||||
@@ -196,7 +197,7 @@ void ImGui_ImplGlfwGL3_KeyCallback(GLFWwindow*, int key, int, int action, int mo
 | 
			
		||||
    io.KeySuper = io.KeysDown[GLFW_KEY_LEFT_SUPER] || io.KeysDown[GLFW_KEY_RIGHT_SUPER];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImGui_ImplGlfwGL3_CharCallback(GLFWwindow*, unsigned int c)
 | 
			
		||||
void ImGui_ImplGlfw_CharCallback(GLFWwindow*, unsigned int c)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiIO& io = ImGui::GetIO();
 | 
			
		||||
    if (c > 0 && c < 0x10000)
 | 
			
		||||
@@ -331,6 +332,14 @@ void    ImGui_ImplGlfwGL3_InvalidateDeviceObjects()
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window)
 | 
			
		||||
{
 | 
			
		||||
    glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback);
 | 
			
		||||
    glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback);
 | 
			
		||||
    glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback);
 | 
			
		||||
    glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool    ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks)
 | 
			
		||||
{
 | 
			
		||||
    g_Window = window;
 | 
			
		||||
@@ -366,12 +375,7 @@ bool    ImGui_ImplGlfwGL3_Init(GLFWwindow* window, bool install_callbacks)
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    if (install_callbacks)
 | 
			
		||||
    {
 | 
			
		||||
        glfwSetMouseButtonCallback(window, ImGui_ImplGlfwGL3_MouseButtonCallback);
 | 
			
		||||
        glfwSetScrollCallback(window, ImGui_ImplGlfwGL3_ScrollCallback);
 | 
			
		||||
        glfwSetKeyCallback(window, ImGui_ImplGlfwGL3_KeyCallback);
 | 
			
		||||
        glfwSetCharCallback(window, ImGui_ImplGlfwGL3_CharCallback);
 | 
			
		||||
    }
 | 
			
		||||
        ImGui_ImplGlfw_InstallCallbacks(window);
 | 
			
		||||
 | 
			
		||||
    return true;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -25,7 +25,7 @@ IMGUI_API bool        ImGui_ImplGlfwGL3_CreateDeviceObjects();
 | 
			
		||||
// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization)
 | 
			
		||||
// Provided here if you want to chain callbacks.
 | 
			
		||||
// You can also handle inputs yourself and use those as a reference.
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfwGL3_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfwGL3_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfwGL3_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfwGL3_CharCallback(GLFWwindow* window, unsigned int c);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c);
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,7 @@
 | 
			
		||||
 | 
			
		||||
// CHANGELOG
 | 
			
		||||
// (minor and older changes stripped away, please see git history for details)
 | 
			
		||||
//  2018-02-20: Inputs: Renamed GLFW callbacks exposed in .h to not include Vulkan in their name.
 | 
			
		||||
//  2018-02-16: Misc: Obsoleted the io.RenderDrawListsFn callback, ImGui_ImplGlfwVulkan_Render() calls ImGui_ImplGlfwVulkan_RenderDrawData() itself.
 | 
			
		||||
//  2018-02-06: Misc: Removed call to ImGui::Shutdown() which is not available from 1.60 WIP, user needs to call CreateContext/DestroyContext themselves.
 | 
			
		||||
//  2018-02-06: Inputs: Added mapping for ImGuiKey_Space.
 | 
			
		||||
@@ -340,20 +341,20 @@ static void ImGui_ImplGlfwVulkan_SetClipboardText(void* user_data, const char* t
 | 
			
		||||
    glfwSetClipboardString((GLFWwindow*)user_data, text);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImGui_ImplGlfwVulkan_MouseButtonCallback(GLFWwindow*, int button, int action, int /*mods*/)
 | 
			
		||||
void ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow*, int button, int action, int /*mods*/)
 | 
			
		||||
{
 | 
			
		||||
    if (action == GLFW_PRESS && button >= 0 && button < 3)
 | 
			
		||||
        g_MouseJustPressed[button] = true;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImGui_ImplGlfwVulkan_ScrollCallback(GLFWwindow*, double xoffset, double yoffset)
 | 
			
		||||
void ImGui_ImplGlfw_ScrollCallback(GLFWwindow*, double xoffset, double yoffset)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiIO& io = ImGui::GetIO();
 | 
			
		||||
    io.MouseWheelH += (float)xoffset;
 | 
			
		||||
    io.MouseWheel += (float)yoffset;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImGui_ImplGlfwVulkan_KeyCallback(GLFWwindow*, int key, int, int action, int mods)
 | 
			
		||||
void ImGui_ImplGlfw_KeyCallback(GLFWwindow*, int key, int, int action, int mods)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiIO& io = ImGui::GetIO();
 | 
			
		||||
    if (action == GLFW_PRESS)
 | 
			
		||||
@@ -368,7 +369,7 @@ void ImGui_ImplGlfwVulkan_KeyCallback(GLFWwindow*, int key, int, int action, int
 | 
			
		||||
    io.KeySuper = io.KeysDown[GLFW_KEY_LEFT_SUPER] || io.KeysDown[GLFW_KEY_RIGHT_SUPER];
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ImGui_ImplGlfwVulkan_CharCallback(GLFWwindow*, unsigned int c)
 | 
			
		||||
void ImGui_ImplGlfw_CharCallback(GLFWwindow*, unsigned int c)
 | 
			
		||||
{
 | 
			
		||||
    ImGuiIO& io = ImGui::GetIO();
 | 
			
		||||
    if (c > 0 && c < 0x10000)
 | 
			
		||||
@@ -746,6 +747,14 @@ void    ImGui_ImplGlfwVulkan_InvalidateDeviceObjects()
 | 
			
		||||
    if (g_Pipeline)             { vkDestroyPipeline(g_Device, g_Pipeline, g_Allocator); g_Pipeline = VK_NULL_HANDLE; }
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
static void ImGui_ImplGlfw_InstallCallbacks(GLFWwindow* window)
 | 
			
		||||
{
 | 
			
		||||
    glfwSetMouseButtonCallback(window, ImGui_ImplGlfw_MouseButtonCallback);
 | 
			
		||||
    glfwSetScrollCallback(window, ImGui_ImplGlfw_ScrollCallback);
 | 
			
		||||
    glfwSetKeyCallback(window, ImGui_ImplGlfw_KeyCallback);
 | 
			
		||||
    glfwSetCharCallback(window, ImGui_ImplGlfw_CharCallback);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool    ImGui_ImplGlfwVulkan_Init(GLFWwindow* window, bool install_callbacks, ImGui_ImplGlfwVulkan_Init_Data *init_data)
 | 
			
		||||
{
 | 
			
		||||
    g_Allocator = init_data->allocator;
 | 
			
		||||
@@ -789,12 +798,7 @@ bool    ImGui_ImplGlfwVulkan_Init(GLFWwindow* window, bool install_callbacks, Im
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
    if (install_callbacks)
 | 
			
		||||
    {
 | 
			
		||||
        glfwSetMouseButtonCallback(window, ImGui_ImplGlfwVulkan_MouseButtonCallback);
 | 
			
		||||
        glfwSetScrollCallback(window, ImGui_ImplGlfwVulkan_ScrollCallback);
 | 
			
		||||
        glfwSetKeyCallback(window, ImGui_ImplGlfwVulkan_KeyCallback);
 | 
			
		||||
        glfwSetCharCallback(window, ImGui_ImplGlfwVulkan_CharCallback);
 | 
			
		||||
    }
 | 
			
		||||
        ImGui_ImplGlfw_InstallCallbacks(window);
 | 
			
		||||
 | 
			
		||||
    ImGui_ImplGlfwVulkan_CreateDeviceObjects();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -39,8 +39,8 @@ IMGUI_API bool        ImGui_ImplGlfwVulkan_CreateDeviceObjects();
 | 
			
		||||
// GLFW callbacks (installed by default if you enable 'install_callbacks' during initialization)
 | 
			
		||||
// Provided here if you want to chain callbacks.
 | 
			
		||||
// You can also handle inputs yourself and use those as a reference.
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfwVulkan_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfwVulkan_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfwVulkan_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfwVulkan_CharCallback(GLFWwindow* window, unsigned int c);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfw_MouseButtonCallback(GLFWwindow* window, int button, int action, int mods);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfw_KeyCallback(GLFWwindow* window, int key, int scancode, int action, int mods);
 | 
			
		||||
IMGUI_API void        ImGui_ImplGlfw_CharCallback(GLFWwindow* window, unsigned int c);
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user