mirror of
https://github.com/Drezil/imgui.git
synced 2024-11-22 20:07:01 +00:00
Examples: Simplified mouse wheel handling. (#1463)
This commit is contained in:
parent
7dea158175
commit
7e7c017b75
@ -21,7 +21,6 @@
|
|||||||
// Data
|
// Data
|
||||||
static double g_Time = 0.0f;
|
static double g_Time = 0.0f;
|
||||||
static bool g_MousePressed[3] = { false, false, false };
|
static bool g_MousePressed[3] = { false, false, false };
|
||||||
static float g_MouseWheel = 0.0f;
|
|
||||||
static CIwTexture* g_FontTexture = NULL;
|
static CIwTexture* g_FontTexture = NULL;
|
||||||
static char* g_ClipboardText = NULL;
|
static char* g_ClipboardText = NULL;
|
||||||
static bool g_osdKeyboardEnabled = false;
|
static bool g_osdKeyboardEnabled = false;
|
||||||
@ -128,9 +127,9 @@ int32 ImGui_Marmalade_PointerButtonEventCallback(void* SystemData, void* pUserDa
|
|||||||
if (pEvent->m_Button == S3E_POINTER_BUTTON_MIDDLEMOUSE)
|
if (pEvent->m_Button == S3E_POINTER_BUTTON_MIDDLEMOUSE)
|
||||||
g_MousePressed[2] = true;
|
g_MousePressed[2] = true;
|
||||||
if (pEvent->m_Button == S3E_POINTER_BUTTON_MOUSEWHEELUP)
|
if (pEvent->m_Button == S3E_POINTER_BUTTON_MOUSEWHEELUP)
|
||||||
g_MouseWheel += pEvent->m_y;
|
io.MouseWheel += pEvent->m_y;
|
||||||
if (pEvent->m_Button == S3E_POINTER_BUTTON_MOUSEWHEELDOWN)
|
if (pEvent->m_Button == S3E_POINTER_BUTTON_MOUSEWHEELDOWN)
|
||||||
g_MouseWheel += pEvent->m_y;
|
io.MouseWheel += pEvent->m_y;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
@ -282,9 +281,6 @@ void ImGui_Marmalade_NewFrame()
|
|||||||
g_MousePressed[i] = false;
|
g_MousePressed[i] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
io.MouseWheel = g_MouseWheel;
|
|
||||||
g_MouseWheel = 0.0f;
|
|
||||||
|
|
||||||
// TODO: Hide OS mouse cursor if ImGui is drawing it
|
// TODO: Hide OS mouse cursor if ImGui is drawing it
|
||||||
// s3ePointerSetInt(S3E_POINTER_HIDE_CURSOR,(io.MouseDrawCursor ? 0 : 1));
|
// s3ePointerSetInt(S3E_POINTER_HIDE_CURSOR,(io.MouseDrawCursor ? 0 : 1));
|
||||||
|
|
||||||
|
@ -31,7 +31,6 @@
|
|||||||
static GLFWwindow* g_Window = NULL;
|
static GLFWwindow* g_Window = NULL;
|
||||||
static double g_Time = 0.0f;
|
static double g_Time = 0.0f;
|
||||||
static bool g_MouseJustPressed[3] = { false, false, false };
|
static bool g_MouseJustPressed[3] = { false, false, false };
|
||||||
static ImVec2 g_MouseWheel = ImVec2(0.0f, 0.0f);
|
|
||||||
static GLuint g_FontTexture = 0;
|
static GLuint g_FontTexture = 0;
|
||||||
|
|
||||||
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
|
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
|
||||||
@ -136,8 +135,9 @@ void ImGui_ImplGlfwGL2_MouseButtonCallback(GLFWwindow*, int button, int action,
|
|||||||
|
|
||||||
void ImGui_ImplGlfwGL2_ScrollCallback(GLFWwindow*, double xoffset, double yoffset)
|
void ImGui_ImplGlfwGL2_ScrollCallback(GLFWwindow*, double xoffset, double yoffset)
|
||||||
{
|
{
|
||||||
g_MouseWheel.x += (float)xoffset; // Use fractional mouse wheel.
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
g_MouseWheel.y += (float)yoffset;
|
io.MouseWheelH += (float)xoffset;
|
||||||
|
io.MouseWheel += (float)yoffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplGlfwGL2_KeyCallback(GLFWwindow*, int key, int, int action, int mods)
|
void ImGui_ImplGlfwGL2_KeyCallback(GLFWwindow*, int key, int, int action, int mods)
|
||||||
@ -296,10 +296,6 @@ void ImGui_ImplGlfwGL2_NewFrame()
|
|||||||
g_MouseJustPressed[i] = false;
|
g_MouseJustPressed[i] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
io.MouseWheel = g_MouseWheel.y;
|
|
||||||
io.MouseWheelH = g_MouseWheel.x;
|
|
||||||
g_MouseWheel.x = g_MouseWheel.x = 0.0f;
|
|
||||||
|
|
||||||
// Hide OS mouse cursor if ImGui is drawing it
|
// Hide OS mouse cursor if ImGui is drawing it
|
||||||
glfwSetInputMode(g_Window, GLFW_CURSOR, io.MouseDrawCursor ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(g_Window, GLFW_CURSOR, io.MouseDrawCursor ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL);
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
static GLFWwindow* g_Window = NULL;
|
static GLFWwindow* g_Window = NULL;
|
||||||
static double g_Time = 0.0f;
|
static double g_Time = 0.0f;
|
||||||
static bool g_MouseJustPressed[3] = { false, false, false };
|
static bool g_MouseJustPressed[3] = { false, false, false };
|
||||||
static ImVec2 g_MouseWheel = ImVec2(0.0f, 0.0f);
|
|
||||||
static GLuint g_FontTexture = 0;
|
static GLuint g_FontTexture = 0;
|
||||||
static int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
|
static int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
|
||||||
static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0;
|
static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0;
|
||||||
@ -157,8 +156,9 @@ void ImGui_ImplGlfwGL3_MouseButtonCallback(GLFWwindow*, int button, int action,
|
|||||||
|
|
||||||
void ImGui_ImplGlfwGL3_ScrollCallback(GLFWwindow*, double xoffset, double yoffset)
|
void ImGui_ImplGlfwGL3_ScrollCallback(GLFWwindow*, double xoffset, double yoffset)
|
||||||
{
|
{
|
||||||
g_MouseWheel.x += (float)xoffset; // Use fractional mouse wheel.
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
g_MouseWheel.y += (float)yoffset;
|
io.MouseWheelH += (float)xoffset;
|
||||||
|
io.MouseWheel += (float)yoffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplGlfwGL3_KeyCallback(GLFWwindow*, int key, int, int action, int mods)
|
void ImGui_ImplGlfwGL3_KeyCallback(GLFWwindow*, int key, int, int action, int mods)
|
||||||
@ -408,10 +408,6 @@ void ImGui_ImplGlfwGL3_NewFrame()
|
|||||||
g_MouseJustPressed[i] = false;
|
g_MouseJustPressed[i] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
io.MouseWheel = g_MouseWheel.y;
|
|
||||||
io.MouseWheelH = g_MouseWheel.x;
|
|
||||||
g_MouseWheel.x = g_MouseWheel.x = 0.0f;
|
|
||||||
|
|
||||||
// Hide OS mouse cursor if ImGui is drawing it
|
// Hide OS mouse cursor if ImGui is drawing it
|
||||||
glfwSetInputMode(g_Window, GLFW_CURSOR, io.MouseDrawCursor ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(g_Window, GLFW_CURSOR, io.MouseDrawCursor ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL);
|
||||||
|
|
||||||
|
@ -24,7 +24,6 @@
|
|||||||
// Data
|
// Data
|
||||||
static double g_Time = 0.0f;
|
static double g_Time = 0.0f;
|
||||||
static bool g_MousePressed[3] = { false, false, false };
|
static bool g_MousePressed[3] = { false, false, false };
|
||||||
static ImVec2 g_MouseWheel = ImVec2(0.0f, 0.0f);
|
|
||||||
static GLuint g_FontTexture = 0;
|
static GLuint g_FontTexture = 0;
|
||||||
|
|
||||||
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
|
// This is the main rendering function that you have to implement and provide to ImGui (via setting up 'RenderDrawListsFn' in the ImGuiIO structure)
|
||||||
@ -132,10 +131,10 @@ bool ImGui_ImplSdlGL2_ProcessEvent(SDL_Event* event)
|
|||||||
{
|
{
|
||||||
case SDL_MOUSEWHEEL:
|
case SDL_MOUSEWHEEL:
|
||||||
{
|
{
|
||||||
if (event->wheel.x > 0) g_MouseWheel.x = +1;
|
if (event->wheel.x > 0) io.MouseWheelH += 1;
|
||||||
if (event->wheel.x < 0) g_MouseWheel.x = -1;
|
if (event->wheel.x < 0) io.MouseWheelH -= 1;
|
||||||
if (event->wheel.y > 0) g_MouseWheel.y = +1;
|
if (event->wheel.y > 0) io.MouseWheel += 1;
|
||||||
if (event->wheel.y < 0) g_MouseWheel.y = -1;
|
if (event->wheel.y < 0) io.MouseWheel -= 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
@ -274,13 +273,10 @@ void ImGui_ImplSdlGL2_NewFrame(SDL_Window *window)
|
|||||||
int mx, my;
|
int mx, my;
|
||||||
Uint32 mouse_buttons = SDL_GetMouseState(&mx, &my);
|
Uint32 mouse_buttons = SDL_GetMouseState(&mx, &my);
|
||||||
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
|
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
|
||||||
io.MouseWheel = g_MouseWheel.y;
|
|
||||||
io.MouseWheelH = g_MouseWheel.x;
|
|
||||||
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[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[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;
|
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_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false;
|
||||||
g_MouseWheel.x = g_MouseWheel.x = 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)
|
// 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)
|
#if (SDL_MAJOR_VERSION >= 2) && (SDL_MINOR_VERSION >= 0) && (SDL_PATCHLEVEL >= 4)
|
||||||
|
@ -19,7 +19,6 @@
|
|||||||
// Data
|
// Data
|
||||||
static double g_Time = 0.0f;
|
static double g_Time = 0.0f;
|
||||||
static bool g_MousePressed[3] = { false, false, false };
|
static bool g_MousePressed[3] = { false, false, false };
|
||||||
static ImVec2 g_MouseWheel = ImVec2(0.0f, 0.0f);
|
|
||||||
static GLuint g_FontTexture = 0;
|
static GLuint g_FontTexture = 0;
|
||||||
static int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
|
static int g_ShaderHandle = 0, g_VertHandle = 0, g_FragHandle = 0;
|
||||||
static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0;
|
static int g_AttribLocationTex = 0, g_AttribLocationProjMtx = 0;
|
||||||
@ -154,10 +153,10 @@ bool ImGui_ImplSdlGL3_ProcessEvent(SDL_Event* event)
|
|||||||
{
|
{
|
||||||
case SDL_MOUSEWHEEL:
|
case SDL_MOUSEWHEEL:
|
||||||
{
|
{
|
||||||
if (event->wheel.x > 0) g_MouseWheel.x = +1;
|
if (event->wheel.x > 0) io.MouseWheelH += 1;
|
||||||
if (event->wheel.x < 0) g_MouseWheel.x = -1;
|
if (event->wheel.x < 0) io.MouseWheelH -= 1;
|
||||||
if (event->wheel.y > 0) g_MouseWheel.y = +1;
|
if (event->wheel.y > 0) io.MouseWheel += 1;
|
||||||
if (event->wheel.y < 0) g_MouseWheel.y = -1;
|
if (event->wheel.y < 0) io.MouseWheel -= 1;
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
case SDL_MOUSEBUTTONDOWN:
|
case SDL_MOUSEBUTTONDOWN:
|
||||||
@ -385,13 +384,10 @@ void ImGui_ImplSdlGL3_NewFrame(SDL_Window* window)
|
|||||||
int mx, my;
|
int mx, my;
|
||||||
Uint32 mouse_buttons = SDL_GetMouseState(&mx, &my);
|
Uint32 mouse_buttons = SDL_GetMouseState(&mx, &my);
|
||||||
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
|
io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
|
||||||
io.MouseWheel = g_MouseWheel.y;
|
|
||||||
io.MouseWheelH = g_MouseWheel.x;
|
|
||||||
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[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[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;
|
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_MousePressed[0] = g_MousePressed[1] = g_MousePressed[2] = false;
|
||||||
g_MouseWheel.x = g_MouseWheel.x = 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)
|
// 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)
|
#if (SDL_MAJOR_VERSION >= 2) && (SDL_MINOR_VERSION >= 0) && (SDL_PATCHLEVEL >= 4)
|
||||||
|
@ -24,8 +24,7 @@
|
|||||||
// GLFW Data
|
// GLFW Data
|
||||||
static GLFWwindow* g_Window = NULL;
|
static GLFWwindow* g_Window = NULL;
|
||||||
static double g_Time = 0.0f;
|
static double g_Time = 0.0f;
|
||||||
static bool g_MousePressed[3] = { false, false, false };
|
static bool g_MouseJustPressed[3] = { false, false, false };
|
||||||
static ImVec2 g_MouseWheel = ImVec2(0.0f, 0.0f);
|
|
||||||
|
|
||||||
// Vulkan Data
|
// Vulkan Data
|
||||||
static VkAllocationCallbacks* g_Allocator = NULL;
|
static VkAllocationCallbacks* g_Allocator = NULL;
|
||||||
@ -327,13 +326,14 @@ static void ImGui_ImplGlfwVulkan_SetClipboardText(void* user_data, const char* t
|
|||||||
void ImGui_ImplGlfwVulkan_MouseButtonCallback(GLFWwindow*, int button, int action, int /*mods*/)
|
void ImGui_ImplGlfwVulkan_MouseButtonCallback(GLFWwindow*, int button, int action, int /*mods*/)
|
||||||
{
|
{
|
||||||
if (action == GLFW_PRESS && button >= 0 && button < 3)
|
if (action == GLFW_PRESS && button >= 0 && button < 3)
|
||||||
g_MousePressed[button] = true;
|
g_MouseJustPressed[button] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplGlfwVulkan_ScrollCallback(GLFWwindow*, double xoffset, double yoffset)
|
void ImGui_ImplGlfwVulkan_ScrollCallback(GLFWwindow*, double xoffset, double yoffset)
|
||||||
{
|
{
|
||||||
g_MouseWheel.x += (float)xoffset; // Use fractional mouse wheel.
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
g_MouseWheel.y += (float)yoffset;
|
io.MouseWheelH += (float)xoffset;
|
||||||
|
io.MouseWheel += (float)yoffset;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ImGui_ImplGlfwVulkan_KeyCallback(GLFWwindow*, int key, int, int action, int mods)
|
void ImGui_ImplGlfwVulkan_KeyCallback(GLFWwindow*, int key, int, int action, int mods)
|
||||||
@ -822,14 +822,10 @@ void ImGui_ImplGlfwVulkan_NewFrame()
|
|||||||
|
|
||||||
for (int i = 0; i < 3; i++)
|
for (int i = 0; i < 3; i++)
|
||||||
{
|
{
|
||||||
io.MouseDown[i] = g_MousePressed[i] || glfwGetMouseButton(g_Window, i) != 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[i] = g_MouseJustPressed[i] || glfwGetMouseButton(g_Window, i) != 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.
|
||||||
g_MousePressed[i] = false;
|
g_MouseJustPressed[i] = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
io.MouseWheel = g_MouseWheel.y;
|
|
||||||
io.MouseWheelH = g_MouseWheel.x;
|
|
||||||
g_MouseWheel.x = g_MouseWheel.x = 0.0f;
|
|
||||||
|
|
||||||
// Hide OS mouse cursor if ImGui is drawing it
|
// Hide OS mouse cursor if ImGui is drawing it
|
||||||
glfwSetInputMode(g_Window, GLFW_CURSOR, io.MouseDrawCursor ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL);
|
glfwSetInputMode(g_Window, GLFW_CURSOR, io.MouseDrawCursor ? GLFW_CURSOR_HIDDEN : GLFW_CURSOR_NORMAL);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user