|
@@ -1,7 +1,7 @@
|
|
-// dear imgui: Platform Binding for FreeGLUT
|
|
|
|
|
|
+// dear imgui: Platform Binding for GLUT/FreeGLUT
|
|
// This needs to be used along with a Renderer (e.g. OpenGL2)
|
|
// This needs to be used along with a Renderer (e.g. OpenGL2)
|
|
|
|
|
|
-// !!! GLUT IS OBSOLETE SOFTWARE. Using GLUT is not recommended unless you really miss the 90's. !!!
|
|
|
|
|
|
+// !!! GLUT/FreeGLUT IS OBSOLETE SOFTWARE. Using GLUT is not recommended unless you really miss the 90's. !!!
|
|
// !!! If someone or something is teaching you GLUT in 2019, you are being abused. Please show some resistance. !!!
|
|
// !!! If someone or something is teaching you GLUT in 2019, you are being abused. Please show some resistance. !!!
|
|
|
|
|
|
// Issues:
|
|
// Issues:
|
|
@@ -15,13 +15,18 @@
|
|
|
|
|
|
// CHANGELOG
|
|
// CHANGELOG
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
// (minor and older changes stripped away, please see git history for details)
|
|
|
|
+// 2019-04-03: Misc: Renamed imgui_impl_freeglut.cpp/.h to imgui_impl_glut.cpp/.h.
|
|
// 2019-03-25: Misc: Made io.DeltaTime always above zero.
|
|
// 2019-03-25: Misc: Made io.DeltaTime always above zero.
|
|
// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
|
|
// 2018-11-30: Misc: Setting up io.BackendPlatformName so it can be displayed in the About Window.
|
|
-// 2018-03-22: Added FreeGLUT Platform binding.
|
|
|
|
|
|
+// 2018-03-22: Added GLUT Platform binding.
|
|
|
|
|
|
#include "imgui.h"
|
|
#include "imgui.h"
|
|
-#include "imgui_impl_freeglut.h"
|
|
|
|
-#include <GL/freeglut.h>
|
|
|
|
|
|
+#include "imgui_impl_glut.h"
|
|
|
|
+#ifdef __APPLE__
|
|
|
|
+ #include <GLUT/glut.h>
|
|
|
|
+#else
|
|
|
|
+ #include <GL/freeglut.h>
|
|
|
|
+#endif
|
|
|
|
|
|
#ifdef _MSC_VER
|
|
#ifdef _MSC_VER
|
|
#pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
|
|
#pragma warning (disable: 4505) // unreferenced local function has been removed (stb stuff)
|
|
@@ -29,10 +34,10 @@
|
|
|
|
|
|
static int g_Time = 0; // Current time, in milliseconds
|
|
static int g_Time = 0; // Current time, in milliseconds
|
|
|
|
|
|
-bool ImGui_ImplFreeGLUT_Init()
|
|
|
|
|
|
+bool ImGui_ImplGLUT_Init()
|
|
{
|
|
{
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
- io.BackendPlatformName ="imgui_impl_freeglut";
|
|
|
|
|
|
+ io.BackendPlatformName ="imgui_impl_glut";
|
|
|
|
|
|
g_Time = 0;
|
|
g_Time = 0;
|
|
|
|
|
|
@@ -62,24 +67,26 @@ bool ImGui_ImplFreeGLUT_Init()
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
-void ImGui_ImplFreeGLUT_InstallFuncs()
|
|
|
|
|
|
+void ImGui_ImplGLUT_InstallFuncs()
|
|
{
|
|
{
|
|
- glutReshapeFunc(ImGui_ImplFreeGLUT_ReshapeFunc);
|
|
|
|
- glutMotionFunc(ImGui_ImplFreeGLUT_MotionFunc);
|
|
|
|
- glutPassiveMotionFunc(ImGui_ImplFreeGLUT_MotionFunc);
|
|
|
|
- glutMouseFunc(ImGui_ImplFreeGLUT_MouseFunc);
|
|
|
|
- glutMouseWheelFunc(ImGui_ImplFreeGLUT_MouseWheelFunc);
|
|
|
|
- glutKeyboardFunc(ImGui_ImplFreeGLUT_KeyboardFunc);
|
|
|
|
- glutKeyboardUpFunc(ImGui_ImplFreeGLUT_KeyboardUpFunc);
|
|
|
|
- glutSpecialFunc(ImGui_ImplFreeGLUT_SpecialFunc);
|
|
|
|
- glutSpecialUpFunc(ImGui_ImplFreeGLUT_SpecialUpFunc);
|
|
|
|
|
|
+ glutReshapeFunc(ImGui_ImplGLUT_ReshapeFunc);
|
|
|
|
+ glutMotionFunc(ImGui_ImplGLUT_MotionFunc);
|
|
|
|
+ glutPassiveMotionFunc(ImGui_ImplGLUT_MotionFunc);
|
|
|
|
+ glutMouseFunc(ImGui_ImplGLUT_MouseFunc);
|
|
|
|
+#ifdef __FREEGLUT_EXT_H__
|
|
|
|
+ glutMouseWheelFunc(ImGui_ImplGLUT_MouseWheelFunc);
|
|
|
|
+#endif
|
|
|
|
+ glutKeyboardFunc(ImGui_ImplGLUT_KeyboardFunc);
|
|
|
|
+ glutKeyboardUpFunc(ImGui_ImplGLUT_KeyboardUpFunc);
|
|
|
|
+ glutSpecialFunc(ImGui_ImplGLUT_SpecialFunc);
|
|
|
|
+ glutSpecialUpFunc(ImGui_ImplGLUT_SpecialUpFunc);
|
|
}
|
|
}
|
|
|
|
|
|
-void ImGui_ImplFreeGLUT_Shutdown()
|
|
|
|
|
|
+void ImGui_ImplGLUT_Shutdown()
|
|
{
|
|
{
|
|
}
|
|
}
|
|
|
|
|
|
-void ImGui_ImplFreeGLUT_NewFrame()
|
|
|
|
|
|
+void ImGui_ImplGLUT_NewFrame()
|
|
{
|
|
{
|
|
// Setup time step
|
|
// Setup time step
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
@@ -94,7 +101,7 @@ void ImGui_ImplFreeGLUT_NewFrame()
|
|
ImGui::NewFrame();
|
|
ImGui::NewFrame();
|
|
}
|
|
}
|
|
|
|
|
|
-static void ImGui_ImplFreeGLUT_UpdateKeyboardMods()
|
|
|
|
|
|
+static void ImGui_ImplGLUT_UpdateKeyboardMods()
|
|
{
|
|
{
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
int mods = glutGetModifiers();
|
|
int mods = glutGetModifiers();
|
|
@@ -103,7 +110,7 @@ static void ImGui_ImplFreeGLUT_UpdateKeyboardMods()
|
|
io.KeyAlt = (mods & GLUT_ACTIVE_ALT) != 0;
|
|
io.KeyAlt = (mods & GLUT_ACTIVE_ALT) != 0;
|
|
}
|
|
}
|
|
|
|
|
|
-void ImGui_ImplFreeGLUT_KeyboardFunc(unsigned char c, int x, int y)
|
|
|
|
|
|
+void ImGui_ImplGLUT_KeyboardFunc(unsigned char c, int x, int y)
|
|
{
|
|
{
|
|
// Send character to imgui
|
|
// Send character to imgui
|
|
//printf("char_down_func %d '%c'\n", c, c);
|
|
//printf("char_down_func %d '%c'\n", c, c);
|
|
@@ -121,11 +128,11 @@ void ImGui_ImplFreeGLUT_KeyboardFunc(unsigned char c, int x, int y)
|
|
io.KeysDown[c] = io.KeysDown[c - 'A' + 'a'] = true;
|
|
io.KeysDown[c] = io.KeysDown[c - 'A' + 'a'] = true;
|
|
else
|
|
else
|
|
io.KeysDown[c] = true;
|
|
io.KeysDown[c] = true;
|
|
- ImGui_ImplFreeGLUT_UpdateKeyboardMods();
|
|
|
|
|
|
+ ImGui_ImplGLUT_UpdateKeyboardMods();
|
|
(void)x; (void)y; // Unused
|
|
(void)x; (void)y; // Unused
|
|
}
|
|
}
|
|
|
|
|
|
-void ImGui_ImplFreeGLUT_KeyboardUpFunc(unsigned char c, int x, int y)
|
|
|
|
|
|
+void ImGui_ImplGLUT_KeyboardUpFunc(unsigned char c, int x, int y)
|
|
{
|
|
{
|
|
//printf("char_up_func %d '%c'\n", c, c);
|
|
//printf("char_up_func %d '%c'\n", c, c);
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
@@ -137,31 +144,31 @@ void ImGui_ImplFreeGLUT_KeyboardUpFunc(unsigned char c, int x, int y)
|
|
io.KeysDown[c] = io.KeysDown[c - 'A' + 'a'] = false;
|
|
io.KeysDown[c] = io.KeysDown[c - 'A' + 'a'] = false;
|
|
else
|
|
else
|
|
io.KeysDown[c] = false;
|
|
io.KeysDown[c] = false;
|
|
- ImGui_ImplFreeGLUT_UpdateKeyboardMods();
|
|
|
|
|
|
+ ImGui_ImplGLUT_UpdateKeyboardMods();
|
|
(void)x; (void)y; // Unused
|
|
(void)x; (void)y; // Unused
|
|
}
|
|
}
|
|
|
|
|
|
-void ImGui_ImplFreeGLUT_SpecialFunc(int key, int x, int y)
|
|
|
|
|
|
+void ImGui_ImplGLUT_SpecialFunc(int key, int x, int y)
|
|
{
|
|
{
|
|
//printf("key_down_func %d\n", key);
|
|
//printf("key_down_func %d\n", key);
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
if (key + 256 < IM_ARRAYSIZE(io.KeysDown))
|
|
if (key + 256 < IM_ARRAYSIZE(io.KeysDown))
|
|
io.KeysDown[key + 256] = true;
|
|
io.KeysDown[key + 256] = true;
|
|
- ImGui_ImplFreeGLUT_UpdateKeyboardMods();
|
|
|
|
|
|
+ ImGui_ImplGLUT_UpdateKeyboardMods();
|
|
(void)x; (void)y; // Unused
|
|
(void)x; (void)y; // Unused
|
|
}
|
|
}
|
|
|
|
|
|
-void ImGui_ImplFreeGLUT_SpecialUpFunc(int key, int x, int y)
|
|
|
|
|
|
+void ImGui_ImplGLUT_SpecialUpFunc(int key, int x, int y)
|
|
{
|
|
{
|
|
//printf("key_up_func %d\n", key);
|
|
//printf("key_up_func %d\n", key);
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
if (key + 256 < IM_ARRAYSIZE(io.KeysDown))
|
|
if (key + 256 < IM_ARRAYSIZE(io.KeysDown))
|
|
io.KeysDown[key + 256] = false;
|
|
io.KeysDown[key + 256] = false;
|
|
- ImGui_ImplFreeGLUT_UpdateKeyboardMods();
|
|
|
|
|
|
+ ImGui_ImplGLUT_UpdateKeyboardMods();
|
|
(void)x; (void)y; // Unused
|
|
(void)x; (void)y; // Unused
|
|
}
|
|
}
|
|
|
|
|
|
-void ImGui_ImplFreeGLUT_MouseFunc(int glut_button, int state, int x, int y)
|
|
|
|
|
|
+void ImGui_ImplGLUT_MouseFunc(int glut_button, int state, int x, int y)
|
|
{
|
|
{
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
io.MousePos = ImVec2((float)x, (float)y);
|
|
io.MousePos = ImVec2((float)x, (float)y);
|
|
@@ -175,7 +182,8 @@ void ImGui_ImplFreeGLUT_MouseFunc(int glut_button, int state, int x, int y)
|
|
io.MouseDown[button] = false;
|
|
io.MouseDown[button] = false;
|
|
}
|
|
}
|
|
|
|
|
|
-void ImGui_ImplFreeGLUT_MouseWheelFunc(int button, int dir, int x, int y)
|
|
|
|
|
|
+#ifdef __FREEGLUT_EXT_H__
|
|
|
|
+void ImGui_ImplGLUT_MouseWheelFunc(int button, int dir, int x, int y)
|
|
{
|
|
{
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
io.MousePos = ImVec2((float)x, (float)y);
|
|
io.MousePos = ImVec2((float)x, (float)y);
|
|
@@ -185,14 +193,15 @@ void ImGui_ImplFreeGLUT_MouseWheelFunc(int button, int dir, int x, int y)
|
|
io.MouseWheel -= 1.0;
|
|
io.MouseWheel -= 1.0;
|
|
(void)button; // Unused
|
|
(void)button; // Unused
|
|
}
|
|
}
|
|
|
|
+#endif
|
|
|
|
|
|
-void ImGui_ImplFreeGLUT_ReshapeFunc(int w, int h)
|
|
|
|
|
|
+void ImGui_ImplGLUT_ReshapeFunc(int w, int h)
|
|
{
|
|
{
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
io.DisplaySize = ImVec2((float)w, (float)h);
|
|
io.DisplaySize = ImVec2((float)w, (float)h);
|
|
}
|
|
}
|
|
|
|
|
|
-void ImGui_ImplFreeGLUT_MotionFunc(int x, int y)
|
|
|
|
|
|
+void ImGui_ImplGLUT_MotionFunc(int x, int y)
|
|
{
|
|
{
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
ImGuiIO& io = ImGui::GetIO();
|
|
io.MousePos = ImVec2((float)x, (float)y);
|
|
io.MousePos = ImVec2((float)x, (float)y);
|