Merge branch 'tseeker/20171127-feature-horiz-wheel' of https://github.com/tseeker/imgui into tseeker-tseeker/20171127-feature-horiz-wheel

# Conflicts:
#	examples/sdl_opengl2_example/imgui_impl_sdl_gl2.cpp
#	examples/sdl_opengl3_example/imgui_impl_sdl_gl3.cpp
This commit is contained in:
omar
2018-01-20 12:06:06 +01:00
6 changed files with 45 additions and 8 deletions

View File

@ -31,6 +31,7 @@
static GLFWwindow* g_Window = NULL;
static double g_Time = 0.0f;
static bool g_MouseJustPressed[3] = { false, false, false };
static float g_MouseHorizWheel = 0.0f;
static float g_MouseWheel = 0.0f;
static GLuint g_FontTexture = 0;
@ -134,9 +135,10 @@ void ImGui_ImplGlfwGL2_MouseButtonCallback(GLFWwindow*, int button, int action,
g_MouseJustPressed[button] = true;
}
void ImGui_ImplGlfwGL2_ScrollCallback(GLFWwindow*, double /*xoffset*/, double yoffset)
void ImGui_ImplGlfwGL2_ScrollCallback(GLFWwindow*, double xoffset, double yoffset)
{
g_MouseWheel += (float)yoffset; // Use fractional mouse wheel.
g_MouseHorizWheel += (float)xoffset; // Use fractional mouse wheel.
g_MouseWheel += (float)yoffset;
}
void ImGui_ImplGlfwGL2_KeyCallback(GLFWwindow*, int key, int, int action, int mods)
@ -295,8 +297,9 @@ void ImGui_ImplGlfwGL2_NewFrame()
g_MouseJustPressed[i] = false;
}
io.MouseHorizWheel = g_MouseHorizWheel;
io.MouseWheel = g_MouseWheel;
g_MouseWheel = 0.0f;
g_MouseHorizWheel = g_MouseWheel = 0.0f;
// Hide OS mouse cursor if ImGui is drawing it
glfwSetInputMode(g_Window, GLFW_CURSOR, io.MouseDrawCursor ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL);

View File

@ -25,6 +25,7 @@
static GLFWwindow* g_Window = NULL;
static double g_Time = 0.0f;
static bool g_MouseJustPressed[3] = { false, false, false };
static float g_MouseHorizWheel = 0.0f;
static float g_MouseWheel = 0.0f;
static GLuint g_FontTexture = 0;
static int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
@ -155,9 +156,10 @@ void ImGui_ImplGlfwGL3_MouseButtonCallback(GLFWwindow*, int button, int action,
g_MouseJustPressed[button] = true;
}
void ImGui_ImplGlfwGL3_ScrollCallback(GLFWwindow*, double /*xoffset*/, double yoffset)
void ImGui_ImplGlfwGL3_ScrollCallback(GLFWwindow*, double xoffset, double yoffset)
{
g_MouseWheel += (float)yoffset; // Use fractional mouse wheel.
g_MouseHorizWheel += (float)xoffset; // Use fractional mouse wheel.
g_MouseWheel += (float)yoffset;
}
void ImGui_ImplGlfwGL3_KeyCallback(GLFWwindow*, int key, int, int action, int mods)
@ -407,8 +409,9 @@ void ImGui_ImplGlfwGL3_NewFrame()
g_MouseJustPressed[i] = false;
}
io.MouseHorizWheel = g_MouseHorizWheel;
io.MouseWheel = g_MouseWheel;
g_MouseWheel = 0.0f;
g_MouseHorizWheel = g_MouseWheel = 0.0f;
// Hide OS mouse cursor if ImGui is drawing it
glfwSetInputMode(g_Window, GLFW_CURSOR, io.MouseDrawCursor ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL);

View File

@ -24,6 +24,7 @@
// Data
static double g_Time = 0.0f;
static bool g_MousePressed[3] = { false, false, false };
static float g_MouseHorizWheel = 0.0f;
static float g_MouseWheel = 0.0f;
static GLuint g_FontTexture = 0;
@ -132,6 +133,10 @@ bool ImGui_ImplSdlGL2_ProcessEvent(SDL_Event* event)
{
case SDL_MOUSEWHEEL:
{
if (event->wheel.x > 0)
g_MouseHorizWheel = 1;
if (event->wheel.x < 0)
g_MouseHorizWheel = -1;
if (event->wheel.y > 0)
g_MouseWheel = 1;
if (event->wheel.y < 0)
@ -275,11 +280,12 @@ void ImGui_ImplSdlGL2_NewFrame(SDL_Window *window)
Uint32 mouse_buttons = SDL_GetMouseState(&mx, &my);
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
io.MouseWheel = g_MouseWheel;
io.MouseHorizWheel = g_MouseHorizWheel;
io.MouseDown[0] = g_MousePressed[0] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
io.MouseDown[1] = g_MousePressed[1] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
io.MouseDown[2] = g_MousePressed[2] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0;
g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false;
g_MouseWheel = 0.0f;
g_MouseWheel = g_MouseHorizWheel = 0.0f;
// We need to use SDL_CaptureMouse() to easily retrieve mouse coordinates outside of the client area. This is only supported from SDL 2.0.4 (released Jan 2016)
#if (SDL_MAJOR_VERSION >= 2) && (SDL_MINOR_VERSION >= 0) && (SDL_PATCHLEVEL >= 4)

View File

@ -19,6 +19,7 @@
// Data
static double g_Time = 0.0f;
static bool g_MousePressed[3] = { false, false, false };
static float g_MouseHorizWheel = 0.0f;
static float g_MouseWheel = 0.0f;
static GLuint g_FontTexture = 0;
static int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
@ -154,6 +155,10 @@ bool ImGui_ImplSdlGL3_ProcessEvent(SDL_Event* event)
{
case SDL_MOUSEWHEEL:
{
if (event->wheel.x > 0)
g_MouseHorizWheel = 1;
if (event->wheel.x < 0)
g_MouseHorizWheel = -1;
if (event->wheel.y > 0)
g_MouseWheel = 1;
if (event->wheel.y < 0)
@ -386,11 +391,12 @@ void ImGui_ImplSdlGL3_NewFrame(SDL_Window* window)
Uint32 mouse_buttons = SDL_GetMouseState(&mx, &my);
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
io.MouseWheel = g_MouseWheel;
io.MouseHorizWheel = g_MouseHorizWheel;
io.MouseDown[0] = g_MousePressed[0] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_LEFT)) != 0; // If a mouse press event came, always pass it as "mouse held this frame", so we don't miss click-release events that are shorter than 1 frame.
io.MouseDown[1] = g_MousePressed[1] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
io.MouseDown[2] = g_MousePressed[2] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0;
g_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false;
g_MouseWheel = 0.0f;
g_MouseHorizWheel = g_MouseWheel = 0.0f;
// We need to use SDL_CaptureMouse() to easily retrieve mouse coordinates outside of the client area. This is only supported from SDL 2.0.4 (released Jan 2016)
#if (SDL_MAJOR_VERSION >= 2) && (SDL_MINOR_VERSION >= 0) && (SDL_PATCHLEVEL >= 4)