WIP inputqueue 7, with recorded event trail, characters.
Build all
diff --git a/backends/imgui_impl_allegro5.cpp b/backends/imgui_impl_allegro5.cpp
index ac03b3c..1c633e0 100644
--- a/backends/imgui_impl_allegro5.cpp
+++ b/backends/imgui_impl_allegro5.cpp
@@ -17,6 +17,7 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
+// 2022-01-XX: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
// 2021-12-08: Renderer: Fixed mishandling of the the ImDrawCmd::IdxOffset field! This is an old bug but it never had an effect until some internal rendering changes in 1.86.
// 2021-08-17: Calling io.AddFocusEvent() on ALLEGRO_EVENT_DISPLAY_SWITCH_OUT/ALLEGRO_EVENT_DISPLAY_SWITCH_IN events.
@@ -454,29 +455,28 @@
case ALLEGRO_EVENT_MOUSE_AXES:
if (ev->mouse.display == bd->Display)
{
- io.MouseWheel += ev->mouse.dz;
- io.MouseWheelH -= ev->mouse.dw;
- io.MousePos = ImVec2(ev->mouse.x, ev->mouse.y);
+ io.AddMousePosEvent(ev->mouse.x, ev->mouse.y);
+ io.AddMouseWheelEvent(-ev->mouse.dw, ev->mouse.dz);
}
return true;
case ALLEGRO_EVENT_MOUSE_BUTTON_DOWN:
case ALLEGRO_EVENT_MOUSE_BUTTON_UP:
- if (ev->mouse.display == bd->Display && ev->mouse.button <= 5)
- io.MouseDown[ev->mouse.button - 1] = (ev->type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN);
+ if (ev->mouse.display == bd->Display && ev->mouse.button > 0 && ev->mouse.button <= 5)
+ io.AddMouseButtonEvent(ev->mouse.button - 1, ev->type == ALLEGRO_EVENT_MOUSE_BUTTON_DOWN);
return true;
case ALLEGRO_EVENT_TOUCH_MOVE:
if (ev->touch.display == bd->Display)
- io.MousePos = ImVec2(ev->touch.x, ev->touch.y);
+ io.AddMousePosEvent(ev->touch.x, ev->touch.y);
return true;
case ALLEGRO_EVENT_TOUCH_BEGIN:
case ALLEGRO_EVENT_TOUCH_END:
case ALLEGRO_EVENT_TOUCH_CANCEL:
if (ev->touch.display == bd->Display && ev->touch.primary)
- io.MouseDown[0] = (ev->type == ALLEGRO_EVENT_TOUCH_BEGIN);
+ io.AddMouseButtonEvent(0, ev->type == ALLEGRO_EVENT_TOUCH_BEGIN);
return true;
case ALLEGRO_EVENT_MOUSE_LEAVE_DISPLAY:
if (ev->mouse.display == bd->Display)
- io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
+ io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
return true;
case ALLEGRO_EVENT_KEY_CHAR:
if (ev->keyboard.display == bd->Display)
diff --git a/backends/imgui_impl_android.cpp b/backends/imgui_impl_android.cpp
index fdf482f..825a7ab 100644
--- a/backends/imgui_impl_android.cpp
+++ b/backends/imgui_impl_android.cpp
@@ -19,6 +19,7 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
+// 2022-01-XX: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
// 2021-03-04: Initial version.
@@ -227,26 +228,25 @@
if((AMotionEvent_getToolType(input_event, event_pointer_index) == AMOTION_EVENT_TOOL_TYPE_FINGER)
|| (AMotionEvent_getToolType(input_event, event_pointer_index) == AMOTION_EVENT_TOOL_TYPE_UNKNOWN))
{
- io.MouseDown[0] = (event_action == AMOTION_EVENT_ACTION_DOWN);
- io.MousePos = ImVec2(AMotionEvent_getX(input_event, event_pointer_index), AMotionEvent_getY(input_event, event_pointer_index));
+ io.AddMousePosEvent(AMotionEvent_getX(input_event, event_pointer_index), AMotionEvent_getY(input_event, event_pointer_index));
+ io.AddMouseButtonEvent(0, event_action == AMOTION_EVENT_ACTION_DOWN);
}
break;
case AMOTION_EVENT_ACTION_BUTTON_PRESS:
case AMOTION_EVENT_ACTION_BUTTON_RELEASE:
{
int32_t button_state = AMotionEvent_getButtonState(input_event);
- io.MouseDown[0] = ((button_state & AMOTION_EVENT_BUTTON_PRIMARY) != 0);
- io.MouseDown[1] = ((button_state & AMOTION_EVENT_BUTTON_SECONDARY) != 0);
- io.MouseDown[2] = ((button_state & AMOTION_EVENT_BUTTON_TERTIARY) != 0);
+ io.AddMouseButtonEvent(0, (button_state & AMOTION_EVENT_BUTTON_PRIMARY) != 0);
+ io.AddMouseButtonEvent(1, (button_state & AMOTION_EVENT_BUTTON_SECONDARY) != 0);
+ io.AddMouseButtonEvent(2, (button_state & AMOTION_EVENT_BUTTON_TERTIARY) != 0);
}
break;
case AMOTION_EVENT_ACTION_HOVER_MOVE: // Hovering: Tool moves while NOT pressed (such as a physical mouse)
case AMOTION_EVENT_ACTION_MOVE: // Touch pointer moves while DOWN
- io.MousePos = ImVec2(AMotionEvent_getX(input_event, event_pointer_index), AMotionEvent_getY(input_event, event_pointer_index));
+ io.AddMousePosEvent(AMotionEvent_getX(input_event, event_pointer_index), AMotionEvent_getY(input_event, event_pointer_index));
break;
case AMOTION_EVENT_ACTION_SCROLL:
- io.MouseWheel = AMotionEvent_getAxisValue(input_event, AMOTION_EVENT_AXIS_VSCROLL, event_pointer_index);
- io.MouseWheelH = AMotionEvent_getAxisValue(input_event, AMOTION_EVENT_AXIS_HSCROLL, event_pointer_index);
+ io.AddMouseWheelEvent(AMotionEvent_getAxisValue(input_event, AMOTION_EVENT_AXIS_HSCROLL, event_pointer_index), AMotionEvent_getAxisValue(input_event, AMOTION_EVENT_AXIS_VSCROLL, event_pointer_index));
break;
default:
break;
diff --git a/backends/imgui_impl_glfw.cpp b/backends/imgui_impl_glfw.cpp
index 83d4bd6..a6244f2 100644
--- a/backends/imgui_impl_glfw.cpp
+++ b/backends/imgui_impl_glfw.cpp
@@ -16,6 +16,7 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
+// 2022-01-XX: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
// 2022-01-12: *BREAKING CHANGE*: Now using glfwSetCursorPosCallback(). If you called ImGui_ImplGlfw_InitXXX() with install_callbacks = false, you MUST install glfwSetCursorPosCallback() and forward it to the backend via ImGui_ImplGlfw_CursorPosCallback().
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
// 2022-01-05: Inputs: Converting GLFW untranslated keycodes back to translated keycodes (in the ImGui_ImplGlfw_KeyCallback() function) in order to match the behavior of every other backend, and facilitate the use of GLFW with lettered-shortcuts API.
@@ -85,7 +86,6 @@
GlfwClientApi ClientApi;
double Time;
GLFWwindow* MouseWindow;
- bool MouseJustPressed[ImGuiMouseButton_COUNT];
GLFWcursor* MouseCursors[ImGuiMouseCursor_COUNT];
bool InstalledCallbacks;
@@ -244,8 +244,9 @@
if (bd->PrevUserCallbackMousebutton != NULL && window == bd->Window)
bd->PrevUserCallbackMousebutton(window, button, action, mods);
- if (action == GLFW_PRESS && button >= 0 && button < IM_ARRAYSIZE(bd->MouseJustPressed))
- bd->MouseJustPressed[button] = true;
+ ImGuiIO& io = ImGui::GetIO();
+ if (button >= 0 && button < ImGuiMouseButton_COUNT)
+ io.AddMouseButtonEvent(button, action == GLFW_PRESS);
}
void ImGui_ImplGlfw_ScrollCallback(GLFWwindow* window, double xoffset, double yoffset)
@@ -255,8 +256,7 @@
bd->PrevUserCallbackScroll(window, xoffset, yoffset);
ImGuiIO& io = ImGui::GetIO();
- io.MouseWheelH += (float)xoffset;
- io.MouseWheel += (float)yoffset;
+ io.AddMouseWheelEvent((float)xoffset, (float)yoffset);
}
static int ImGui_ImplGlfw_TranslateUntranslatedKey(int key, int scancode)
@@ -318,7 +318,7 @@
bd->PrevUserCallbackCursorPos(window, x, y);
ImGuiIO& io = ImGui::GetIO();
- io.MousePos = ImVec2((float)x, (float)y);
+ io.AddMousePosEvent((float)x, (float)y);
}
void ImGui_ImplGlfw_CursorEnterCallback(GLFWwindow* window, int entered)
@@ -333,7 +333,7 @@
if (!entered && bd->MouseWindow == window)
{
bd->MouseWindow = NULL;
- io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
+ io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
}
}
@@ -486,16 +486,9 @@
{
double mouse_x, mouse_y;
glfwGetCursorPos(bd->Window, &mouse_x, &mouse_y);
- io.MousePos = ImVec2((float)mouse_x, (float)mouse_y);
+ io.AddMousePosEvent((float)mouse_x, (float)mouse_y);
}
}
-
- // Update buttons
- for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++)
- {
- io.MouseDown[i] = bd->MouseJustPressed[i] || glfwGetMouseButton(bd->Window, i) != 0;
- bd->MouseJustPressed[i] = false;
- }
}
static void ImGui_ImplGlfw_UpdateMouseCursor()
diff --git a/backends/imgui_impl_glut.cpp b/backends/imgui_impl_glut.cpp
index 6eec280..9f7db1b 100644
--- a/backends/imgui_impl_glut.cpp
+++ b/backends/imgui_impl_glut.cpp
@@ -20,6 +20,7 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
+// 2022-01-XX: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
// 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.
@@ -264,26 +265,22 @@
void ImGui_ImplGLUT_MouseFunc(int glut_button, int state, int x, int y)
{
ImGuiIO& io = ImGui::GetIO();
- io.MousePos = ImVec2((float)x, (float)y);
+ io.AddMousePosEvent((float)x, (float)y);
int button = -1;
if (glut_button == GLUT_LEFT_BUTTON) button = 0;
if (glut_button == GLUT_RIGHT_BUTTON) button = 1;
if (glut_button == GLUT_MIDDLE_BUTTON) button = 2;
- if (button != -1 && state == GLUT_DOWN)
- io.MouseDown[button] = true;
- if (button != -1 && state == GLUT_UP)
- io.MouseDown[button] = false;
+ if (button != -1 && state == GLUT_DOWN || state == GLUT_UP)
+ io.AddMouseButtonEvent(button, state == GLUT_DOWN);
}
#ifdef __FREEGLUT_EXT_H__
void ImGui_ImplGLUT_MouseWheelFunc(int button, int dir, int x, int y)
{
ImGuiIO& io = ImGui::GetIO();
- io.MousePos = ImVec2((float)x, (float)y);
- if (dir > 0)
- io.MouseWheel += 1.0;
- else if (dir < 0)
- io.MouseWheel -= 1.0;
+ io.AddMousePosEvent((float)x, (float)y);
+ if (dir != 0)
+ io.AddMouseWheelEvent(0.0f, dir > 0 ? 1.0f : -1.0f);
(void)button; // Unused
}
#endif
@@ -297,5 +294,5 @@
void ImGui_ImplGLUT_MotionFunc(int x, int y)
{
ImGuiIO& io = ImGui::GetIO();
- io.MousePos = ImVec2((float)x, (float)y);
+ io.AddMousePosEvent((float)x, (float)y);
}
diff --git a/backends/imgui_impl_osx.mm b/backends/imgui_impl_osx.mm
index 55f269d..a54277d 100644
--- a/backends/imgui_impl_osx.mm
+++ b/backends/imgui_impl_osx.mm
@@ -23,6 +23,7 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
+// 2022-01-XX: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
// 2022-01-12: Inputs: Added basic Platform IME support, hooking the io.SetPlatformImeDataFn() function.
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
// 2021-12-13: *BREAKING CHANGE* Add NSView parameter to ImGui_ImplOSX_Init(). Generally fix keyboard support. Using kVK_* codes for keyboard keys.
@@ -51,8 +52,6 @@
static double g_Time = 0.0;
static NSCursor* g_MouseCursors[ImGuiMouseCursor_COUNT] = {};
static bool g_MouseCursorHidden = false;
-static bool g_MouseJustPressed[ImGuiMouseButton_COUNT] = {};
-static bool g_MouseDown[ImGuiMouseButton_COUNT] = {};
static ImGuiKeyModFlags g_KeyModifiers = ImGuiKeyModFlags_None;
static ImFocusObserver* g_FocusObserver = nil;
static KeyEventResponder* g_KeyEventResponder = nil;
@@ -451,17 +450,9 @@
g_FocusObserver = NULL;
}
-static void ImGui_ImplOSX_UpdateMouseCursorAndButtons()
+static void ImGui_ImplOSX_UpdateMouseCursor()
{
- // Update buttons
ImGuiIO& io = ImGui::GetIO();
- for (int i = 0; i < IM_ARRAYSIZE(io.MouseDown); i++)
- {
- // 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] || g_MouseDown[i];
- g_MouseJustPressed[i] = false;
- }
-
if (io.ConfigFlags & ImGuiConfigFlags_NoMouseCursorChange)
return;
@@ -570,7 +561,7 @@
g_Time = current_time;
ImGui_ImplOSX_UpdateKeyModifiers();
- ImGui_ImplOSX_UpdateMouseCursorAndButtons();
+ ImGui_ImplOSX_UpdateMouseCursor();
ImGui_ImplOSX_UpdateGamepads();
ImGui_ImplOSX_UpdateImePosWithView(view);
}
@@ -582,16 +573,16 @@
if (event.type == NSEventTypeLeftMouseDown || event.type == NSEventTypeRightMouseDown || event.type == NSEventTypeOtherMouseDown)
{
int button = (int)[event buttonNumber];
- if (button >= 0 && button < IM_ARRAYSIZE(g_MouseDown))
- g_MouseDown[button] = g_MouseJustPressed[button] = true;
+ if (button >= 0 && button < ImGuiMouseButton_COUNT)
+ io.AddMouseButtonEvent(button, true);
return io.WantCaptureMouse;
}
if (event.type == NSEventTypeLeftMouseUp || event.type == NSEventTypeRightMouseUp || event.type == NSEventTypeOtherMouseUp)
{
int button = (int)[event buttonNumber];
- if (button >= 0 && button < IM_ARRAYSIZE(g_MouseDown))
- g_MouseDown[button] = false;
+ if (button >= 0 && button < ImGuiMouseButton_COUNT)
+ io.AddMouseButtonEvent(button, false);
return io.WantCaptureMouse;
}
@@ -600,7 +591,7 @@
NSPoint mousePoint = event.locationInWindow;
mousePoint = [view convertPoint:mousePoint fromView:nil];
mousePoint = NSMakePoint(mousePoint.x, view.bounds.size.height - mousePoint.y);
- io.MousePos = ImVec2((float)mousePoint.x, (float)mousePoint.y);
+ io.AddMousePosEvent((float)mousePoint.x, (float)mousePoint.y);
}
if (event.type == NSEventTypeScrollWheel)
@@ -640,11 +631,9 @@
wheel_dx = [event deltaX];
wheel_dy = [event deltaY];
}
+ if (wheel_dx != 0.0 || wheel_dx != 0.0)
+ io.AddMouseWheelEvent((float)wheel_dx * 0.1f, (float)wheel_dy * 0.1f);
- if (fabs(wheel_dx) > 0.0)
- io.MouseWheelH += (float)wheel_dx * 0.1f;
- if (fabs(wheel_dy) > 0.0)
- io.MouseWheel += (float)wheel_dy * 0.1f;
return io.WantCaptureMouse;
}
diff --git a/backends/imgui_impl_sdl.cpp b/backends/imgui_impl_sdl.cpp
index 8feef9c..6a7d469 100644
--- a/backends/imgui_impl_sdl.cpp
+++ b/backends/imgui_impl_sdl.cpp
@@ -18,6 +18,7 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
+// 2022-01-XX: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
// 2022-01-12: Update mouse inputs using SDL_MOUSEMOTION/SDL_WINDOWEVENT_LEAVE + fallback to provide it when focused but not hovered/captured. More standard and will allow us to pass it to future input queue API.
// 2022-01-12: Maintain our own copy of MouseButtonsDown mask instead of using ImGui::IsAnyMouseDown() which will be obsoleted.
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
@@ -77,7 +78,6 @@
SDL_Window* Window;
Uint64 Time;
int MouseButtonsDown;
- bool MousePressed[3];
SDL_Cursor* MouseCursors[ImGuiMouseCursor_COUNT];
char* ClipboardTextData;
bool MouseCanUseGlobalState;
@@ -236,15 +236,14 @@
{
case SDL_MOUSEMOTION:
{
- io.MousePos = ImVec2((float)event->motion.x, (float)event->motion.y);
+ io.AddMousePosEvent((float)event->motion.x, (float)event->motion.y);
return true;
}
case SDL_MOUSEWHEEL:
{
- if (event->wheel.x > 0) io.MouseWheelH += 1;
- if (event->wheel.x < 0) io.MouseWheelH -= 1;
- if (event->wheel.y > 0) io.MouseWheel += 1;
- if (event->wheel.y < 0) io.MouseWheel -= 1;
+ float wheel_x = (event->wheel.x > 0) ? 1.0f : (event->wheel.x < 0) ? -1.0f : 0.0f;
+ float wheel_y = (event->wheel.y > 0) ? 1.0f : (event->wheel.y < 0) ? -1.0f : 0.0f;
+ io.AddMouseWheelEvent(wheel_x, wheel_y);
return true;
}
case SDL_MOUSEBUTTONDOWN:
@@ -256,8 +255,7 @@
if (event->button.button == SDL_BUTTON_MIDDLE) { mouse_button = 2; }
if (mouse_button == -1)
break;
- if (event->type == SDL_MOUSEBUTTONDOWN)
- bd->MousePressed[mouse_button] = true;
+ io.AddMouseButtonEvent(mouse_button, (event->type == SDL_MOUSEBUTTONDOWN));
bd->MouseButtonsDown = (event->type == SDL_MOUSEBUTTONDOWN) ? (bd->MouseButtonsDown | (1 << mouse_button)) : (bd->MouseButtonsDown & ~(1 << mouse_button));
return true;
}
@@ -277,7 +275,7 @@
case SDL_WINDOWEVENT:
{
if (event->window.event == SDL_WINDOWEVENT_LEAVE)
- io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
+ io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
if (event->window.event == SDL_WINDOWEVENT_FOCUS_GAINED)
io.AddFocusEvent(true);
else if (event->window.event == SDL_WINDOWEVENT_FOCUS_LOST)
@@ -425,16 +423,9 @@
int window_x, window_y, mouse_x_global, mouse_y_global;
SDL_GetGlobalMouseState(&mouse_x_global, &mouse_y_global);
SDL_GetWindowPosition(bd->Window, &window_x, &window_y);
- io.MousePos = ImVec2((float)(mouse_x_global - window_x), (float)(mouse_y_global - window_y));
+ io.AddMousePosEvent((float)(mouse_x_global - window_x), (float)(mouse_y_global - window_y));
}
}
-
- // Update buttons
- Uint32 mouse_buttons = SDL_GetMouseState(NULL, NULL);
- io.MouseDown[0] = bd->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] = bd->MousePressed[1] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0;
- io.MouseDown[2] = bd->MousePressed[2] || (mouse_buttons & SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0;
- bd->MousePressed[0] = bd->MousePressed[1] = bd->MousePressed[2] = false;
}
static void ImGui_ImplSDL2_UpdateMouseCursor()
diff --git a/backends/imgui_impl_win32.cpp b/backends/imgui_impl_win32.cpp
index bd3d547..eacf388 100644
--- a/backends/imgui_impl_win32.cpp
+++ b/backends/imgui_impl_win32.cpp
@@ -34,6 +34,7 @@
// CHANGELOG
// (minor and older changes stripped away, please see git history for details)
+// 2022-01-XX: Inputs: calling new io.AddMousePosEvent(), io.AddMouseButtonEvent(), io.AddMouseWheelEvent() API (1.87+).
// 2022-01-12: Update mouse inputs using WM_MOUSEMOVE/WM_MOUSELEAVE + fallback to provide it when focused but not hovered/captured. More standard and will allow us to pass it to future input queue API.
// 2022-01-12: Maintain our own copy of MouseButtonsDown mask instead of using ImGui::IsAnyMouseDown() which will be obsoleted.
// 2022-01-10: Inputs: calling new io.AddKeyEvent(), io.AddKeyModsEvent() + io.SetKeyEventNativeData() API (1.87+). Support for full ImGuiKey range.
@@ -264,7 +265,7 @@
{
POINT pos;
if (::GetCursorPos(&pos) && ::ScreenToClient(bd->hWnd, &pos))
- io.MousePos = ImVec2((float)pos.x, (float)pos.y);
+ io.AddMousePosEvent((float)pos.x, (float)pos.y);
}
}
}
@@ -512,13 +513,13 @@
::TrackMouseEvent(&tme);
bd->MouseTracked = true;
}
- io.MousePos = ImVec2((float)GET_X_LPARAM(lParam), (float)GET_Y_LPARAM(lParam));
+ io.AddMousePosEvent((float)GET_X_LPARAM(lParam), (float)GET_Y_LPARAM(lParam));
break;
case WM_MOUSELEAVE:
if (bd->MouseHwnd == hwnd)
bd->MouseHwnd = NULL;
bd->MouseTracked = false;
- io.MousePos = ImVec2(-FLT_MAX, -FLT_MAX);
+ io.AddMousePosEvent(-FLT_MAX, -FLT_MAX);
break;
case WM_LBUTTONDOWN: case WM_LBUTTONDBLCLK:
case WM_RBUTTONDOWN: case WM_RBUTTONDBLCLK:
@@ -533,7 +534,7 @@
if (bd->MouseButtonsDown == 0 && ::GetCapture() == NULL)
::SetCapture(hwnd);
bd->MouseButtonsDown |= 1 << button;
- io.MouseDown[button] = true;
+ io.AddMouseButtonEvent(button, true);
return 0;
}
case WM_LBUTTONUP:
@@ -549,14 +550,14 @@
bd->MouseButtonsDown &= ~(1 << button);
if (bd->MouseButtonsDown == 0 && ::GetCapture() == hwnd)
::ReleaseCapture();
- io.MouseDown[button] = false;
+ io.AddMouseButtonEvent(button, false);
return 0;
}
case WM_MOUSEWHEEL:
- io.MouseWheel += (float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA;
+ io.AddMouseWheelEvent(0.0f, (float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA);
return 0;
case WM_MOUSEHWHEEL:
- io.MouseWheelH += (float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA;
+ io.AddMouseWheelEvent((float)GET_WHEEL_DELTA_WPARAM(wParam) / (float)WHEEL_DELTA, 0.0f);
return 0;
case WM_KEYDOWN:
case WM_KEYUP:
diff --git a/examples/example_allegro5/example_allegro5.vcxproj b/examples/example_allegro5/example_allegro5.vcxproj
index 69b0ece..dd8a6dd 100644
--- a/examples/example_allegro5/example_allegro5.vcxproj
+++ b/examples/example_allegro5/example_allegro5.vcxproj
@@ -21,34 +21,34 @@
<PropertyGroup Label="Globals">
<ProjectGuid>{73F235B5-7D31-4FC6-8682-DDC5A097B9C1}</ProjectGuid>
<RootNamespace>example_allegro5</RootNamespace>
- <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
@@ -177,4 +177,4 @@
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" />
<ImportGroup Label="ExtensionTargets">
</ImportGroup>
-</Project>
+</Project>
\ No newline at end of file
diff --git a/examples/example_glut_opengl2/example_glut_opengl2.vcxproj b/examples/example_glut_opengl2/example_glut_opengl2.vcxproj
index 4c9d00f..907a4fd 100644
--- a/examples/example_glut_opengl2/example_glut_opengl2.vcxproj
+++ b/examples/example_glut_opengl2/example_glut_opengl2.vcxproj
@@ -21,34 +21,34 @@
<PropertyGroup Label="Globals">
<ProjectGuid>{F90D0333-5FB1-440D-918D-DD39A1B5187E}</ProjectGuid>
<RootNamespace>example_glut_opengl2</RootNamespace>
- <WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>
+ <WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>true</UseDebugLibraries>
<CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'" Label="Configuration">
<ConfigurationType>Application</ConfigurationType>
<UseDebugLibraries>false</UseDebugLibraries>
<WholeProgramOptimization>true</WholeProgramOptimization>
<CharacterSet>MultiByte</CharacterSet>
- <PlatformToolset>v140</PlatformToolset>
+ <PlatformToolset>v142</PlatformToolset>
</PropertyGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
<ImportGroup Label="ExtensionSettings">
diff --git a/examples/imgui_examples.sln b/examples/imgui_examples.sln
index df1006d..7f13ae5 100644
--- a/examples/imgui_examples.sln
+++ b/examples/imgui_examples.sln
@@ -1,7 +1,7 @@
Microsoft Visual Studio Solution File, Format Version 12.00
-# Visual Studio 14
-VisualStudioVersion = 14.0.25420.1
+# Visual Studio Version 16
+VisualStudioVersion = 16.0.32002.261
MinimumVisualStudioVersion = 10.0.40219.1
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_win32_directx9", "example_win32_directx9\example_win32_directx9.vcxproj", "{4165A294-21F2-44CA-9B38-E3F935ABADF5}"
EndProject
@@ -17,6 +17,12 @@
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_glfw_vulkan", "example_glfw_vulkan\example_glfw_vulkan.vcxproj", "{57E2DF5A-6FC8-45BB-99DD-91A18C646E80}"
EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_glut_opengl2", "example_glut_opengl2\example_glut_opengl2.vcxproj", "{F90D0333-5FB1-440D-918D-DD39A1B5187E}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_allegro5", "example_allegro5\example_allegro5.vcxproj", "{73F235B5-7D31-4FC6-8682-DDC5A097B9C1}"
+EndProject
+Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example_sdl_opengl3", "example_sdl_opengl3\example_sdl_opengl3.vcxproj", "{BBAEB705-1669-40F3-8567-04CF6A991F4C}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
@@ -81,8 +87,35 @@
{57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Release|Win32.Build.0 = Release|Win32
{57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Release|x64.ActiveCfg = Release|x64
{57E2DF5A-6FC8-45BB-99DD-91A18C646E80}.Release|x64.Build.0 = Release|x64
+ {F90D0333-5FB1-440D-918D-DD39A1B5187E}.Debug|Win32.ActiveCfg = Debug|Win32
+ {F90D0333-5FB1-440D-918D-DD39A1B5187E}.Debug|Win32.Build.0 = Debug|Win32
+ {F90D0333-5FB1-440D-918D-DD39A1B5187E}.Debug|x64.ActiveCfg = Debug|x64
+ {F90D0333-5FB1-440D-918D-DD39A1B5187E}.Debug|x64.Build.0 = Debug|x64
+ {F90D0333-5FB1-440D-918D-DD39A1B5187E}.Release|Win32.ActiveCfg = Release|Win32
+ {F90D0333-5FB1-440D-918D-DD39A1B5187E}.Release|Win32.Build.0 = Release|Win32
+ {F90D0333-5FB1-440D-918D-DD39A1B5187E}.Release|x64.ActiveCfg = Release|x64
+ {F90D0333-5FB1-440D-918D-DD39A1B5187E}.Release|x64.Build.0 = Release|x64
+ {73F235B5-7D31-4FC6-8682-DDC5A097B9C1}.Debug|Win32.ActiveCfg = Debug|Win32
+ {73F235B5-7D31-4FC6-8682-DDC5A097B9C1}.Debug|Win32.Build.0 = Debug|Win32
+ {73F235B5-7D31-4FC6-8682-DDC5A097B9C1}.Debug|x64.ActiveCfg = Debug|x64
+ {73F235B5-7D31-4FC6-8682-DDC5A097B9C1}.Debug|x64.Build.0 = Debug|x64
+ {73F235B5-7D31-4FC6-8682-DDC5A097B9C1}.Release|Win32.ActiveCfg = Release|Win32
+ {73F235B5-7D31-4FC6-8682-DDC5A097B9C1}.Release|Win32.Build.0 = Release|Win32
+ {73F235B5-7D31-4FC6-8682-DDC5A097B9C1}.Release|x64.ActiveCfg = Release|x64
+ {73F235B5-7D31-4FC6-8682-DDC5A097B9C1}.Release|x64.Build.0 = Release|x64
+ {BBAEB705-1669-40F3-8567-04CF6A991F4C}.Debug|Win32.ActiveCfg = Debug|Win32
+ {BBAEB705-1669-40F3-8567-04CF6A991F4C}.Debug|Win32.Build.0 = Debug|Win32
+ {BBAEB705-1669-40F3-8567-04CF6A991F4C}.Debug|x64.ActiveCfg = Debug|x64
+ {BBAEB705-1669-40F3-8567-04CF6A991F4C}.Debug|x64.Build.0 = Debug|x64
+ {BBAEB705-1669-40F3-8567-04CF6A991F4C}.Release|Win32.ActiveCfg = Release|Win32
+ {BBAEB705-1669-40F3-8567-04CF6A991F4C}.Release|Win32.Build.0 = Release|Win32
+ {BBAEB705-1669-40F3-8567-04CF6A991F4C}.Release|x64.ActiveCfg = Release|x64
+ {BBAEB705-1669-40F3-8567-04CF6A991F4C}.Release|x64.Build.0 = Release|x64
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
+ GlobalSection(ExtensibilityGlobals) = postSolution
+ SolutionGuid = {355DEA78-31C8-479C-ADA7-66787EB266B3}
+ EndGlobalSection
EndGlobal
diff --git a/imgui.cpp b/imgui.cpp
index d237d1d..529f0c6 100644
--- a/imgui.cpp
+++ b/imgui.cpp
@@ -1162,10 +1162,19 @@
// Pass in translated ASCII characters for text input.
// - with glfw you can get those from the callback set in glfwSetCharCallback()
// - on Windows you can get those using ToAscii+keyboard state, or via the WM_CHAR message
+// FIXME: Should in theory be called "AddCharacterEvent()" to be consistent with new API
void ImGuiIO::AddInputCharacter(unsigned int c)
{
- if (c != 0)
- InputQueueCharacters.push_back(c <= IM_UNICODE_CODEPOINT_MAX ? (ImWchar)c : IM_UNICODE_CODEPOINT_INVALID);
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(&g.IO == this && "Can only add events to current context.");
+ if (c == 0)
+ return;
+
+ ImGuiInputEvent e;
+ e.Type = ImGuiInputEventType_Char;
+ e.Source = ImGuiInputSource_Keyboard;
+ e.Text.Char = c;
+ g.InputEventsQueue.push_back(e);
}
// UTF16 strings use surrogate pairs to encode codepoints >= 0x10000, so
@@ -1178,7 +1187,7 @@
if ((c & 0xFC00) == 0xD800) // High surrogate, must save
{
if (InputQueueSurrogate != 0)
- InputQueueCharacters.push_back(IM_UNICODE_CODEPOINT_INVALID);
+ AddInputCharacter(IM_UNICODE_CODEPOINT_INVALID);
InputQueueSurrogate = c;
return;
}
@@ -1188,7 +1197,7 @@
{
if ((c & 0xFC00) != 0xDC00) // Invalid low surrogate
{
- InputQueueCharacters.push_back(IM_UNICODE_CODEPOINT_INVALID);
+ AddInputCharacter(IM_UNICODE_CODEPOINT_INVALID);
}
else
{
@@ -1201,7 +1210,7 @@
InputQueueSurrogate = 0;
}
- InputQueueCharacters.push_back(cp);
+ AddInputCharacter((unsigned)cp);
}
void ImGuiIO::AddInputCharactersUTF8(const char* utf8_chars)
@@ -1211,7 +1220,7 @@
unsigned int c = 0;
utf8_chars += ImTextCharFromUtf8(&c, utf8_chars, NULL);
if (c != 0)
- InputQueueCharacters.push_back((ImWchar)c);
+ AddInputCharacter(c);
}
}
@@ -1240,12 +1249,13 @@
// Queue a new key down/up event.
// - ImGuiKey key: Translated key (as in, generally ImGuiKey_A matches the key end-user would use to emit an 'A' character)
// - bool down: Is the key down? use false to signify a key release.
-// FIXME: In the current version this is setting key data immediately. This will evolve into a trickling queue.
void ImGuiIO::AddKeyEvent(ImGuiKey key, bool down)
{
//if (e->Down) { IMGUI_DEBUG_LOG("AddKeyEvent() Key='%s' %d, NativeKeycode = %d, NativeScancode = %d\n", ImGui::GetKeyName(e->Key), e->Down, e->NativeKeycode, e->NativeScancode); }
if (key == ImGuiKey_None)
return;
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(&g.IO == this && "Can only add events to current context.");
IM_ASSERT(ImGui::IsNamedKey(key)); // Backend needs to pass a valid ImGuiKey_ constant. 0..511 values are legacy native key codes which are not accepted by this API.
// Verify that backend isn't mixing up using new io.AddKeyEvent() api and old io.KeysDown[] + io.KeyMap[] data.
@@ -1254,15 +1264,19 @@
if (BackendUsingLegacyKeyArrays == -1)
for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++)
IM_ASSERT(KeyMap[n] == -1 && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!");
-#endif
BackendUsingLegacyKeyArrays = 0;
+#endif
- // Write key
- const int keydata_index = (key - ImGuiKey_KeysData_OFFSET);
- KeysData[keydata_index].Down = down;
+ ImGuiInputEvent e;
+ e.Type = ImGuiInputEventType_Key;
+ e.Source = ImGuiInputSource_Keyboard;
+ e.Key.Key = key;
+ e.Key.Down = down;
+ e.Key.Analog = down ? 1.0f : 0.0f;
+ g.InputEventsQueue.push_back(e);
}
-// [Optional] Call add AddKeyEvent().
+// [Optional] Call after AddKeyEvent().
// Specify native keycode, scancode + Specify index for legacy <1.87 IsKeyXXX() functions with native indices.
// If you are writing a backend in 2022 or don't use IsKeyXXX() with native values that are not ImGuiKey values, you can avoid calling this.
void ImGuiIO::SetKeyEventNativeData(ImGuiKey key, int native_keycode, int native_scancode, int native_legacy_index)
@@ -1287,18 +1301,68 @@
void ImGuiIO::AddKeyModsEvent(ImGuiKeyModFlags modifiers)
{
- KeyMods = modifiers;
- KeyCtrl = (modifiers & ImGuiKeyModFlags_Ctrl) != 0;
- KeyShift = (modifiers & ImGuiKeyModFlags_Shift) != 0;
- KeyAlt = (modifiers & ImGuiKeyModFlags_Alt) != 0;
- KeySuper = (modifiers & ImGuiKeyModFlags_Super) != 0;
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(&g.IO == this && "Can only add events to current context.");
+
+ ImGuiInputEvent e;
+ e.Type = ImGuiInputEventType_KeyMods;
+ e.Source = ImGuiInputSource_Keyboard;
+ e.KeyMods.Mods = modifiers;
+ g.InputEventsQueue.push_back(e);
+}
+
+// Queue a mouse move event
+void ImGuiIO::AddMousePosEvent(float x, float y)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(&g.IO == this && "Can only add events to current context.");
+
+ ImGuiInputEvent e;
+ e.Type = ImGuiInputEventType_MousePos;
+ e.Source = ImGuiInputSource_Mouse;
+ e.MousePos.PosX = x;
+ e.MousePos.PosY = y;
+ g.InputEventsQueue.push_back(e);
+}
+
+void ImGuiIO::AddMouseWheelEvent(float wheel_x, float wheel_y)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(&g.IO == this && "Can only add events to current context.");
+ if (wheel_x == 0.0f && wheel_y == 0.0f)
+ return;
+
+ ImGuiInputEvent e;
+ e.Type = ImGuiInputEventType_MouseWheel;
+ e.Source = ImGuiInputSource_Mouse;
+ e.MouseWheel.WheelX = wheel_x;
+ e.MouseWheel.WheelY = wheel_y;
+ g.InputEventsQueue.push_back(e);
+}
+
+void ImGuiIO::AddMouseButtonEvent(int mouse_button, bool down)
+{
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(&g.IO == this && "Can only add events to current context.");
+ IM_ASSERT(mouse_button >= 0 && mouse_button < ImGuiMouseButton_COUNT);
+
+ ImGuiInputEvent e;
+ e.Type = ImGuiInputEventType_MouseButton;
+ e.Source = ImGuiInputSource_Mouse;
+ e.MouseButton.Button = mouse_button;
+ e.MouseButton.Down = down;
+ g.InputEventsQueue.push_back(e);
}
void ImGuiIO::AddFocusEvent(bool focused)
{
- // We intentionally overwrite this and process in NewFrame(), in order to give a chance
- // to multi-viewports backends to queue AddFocusEvent(false),AddFocusEvent(true) in same frame.
- AppFocusLost = !focused;
+ ImGuiContext& g = *GImGui;
+ IM_ASSERT(&g.IO == this && "Can only add events to current context.");
+
+ ImGuiInputEvent e;
+ e.Type = ImGuiInputEventType_Focus;
+ e.AppFocused.Focused = focused;
+ g.InputEventsQueue.push_back(e);
}
//-----------------------------------------------------------------------------
@@ -4235,13 +4299,9 @@
//if (g.IO.AppFocusLost)
// ClosePopupsExceptModals();
- // Clear buttons state when focus is lost
- // (this is useful so e.g. releasing Alt after focus loss on Alt-Tab doesn't trigger the Alt menu toggle)
- if (g.IO.AppFocusLost)
- {
- g.IO.ClearInputKeys();
- g.IO.AppFocusLost = false;
- }
+ // Process input queue (trickle as many events as possible)
+ g.InputEventsTrail.resize(0);
+ UpdateInputEvents(true);
// Update keyboard input state
UpdateKeyboardInputs();
@@ -7653,6 +7713,182 @@
return input_source_names[source];
}
+#if 0
+static const char* GetInputEventTypeName(ImGuiInputEventType type)
+{
+ static const char* names[ImGuiInputEventType_COUNT] = { "None", "MousePos", "MouseWheel", "MouseButton", "Key", "KeyMods", "Char", "Focus" };
+ IM_ASSERT(type >= 0 && type < IM_ARRAYSIZE(names));
+ return names[type];
+}
+#endif
+
+static void DebugLogInputEvent(const ImGuiInputEvent* e)
+{
+ switch (e->Type)
+ {
+ case ImGuiInputEventType_MousePos:
+ IMGUI_DEBUG_LOG_IO("Event: MousePos (%.1f %.1f)\n", e->MousePos.PosX, e->MousePos.PosY);
+ break;
+ case ImGuiInputEventType_MouseButton:
+ IMGUI_DEBUG_LOG_IO("Event: MouseButton %d %s\n", e->MouseButton.Button, e->MouseButton.Down ? "Down" : "Up");
+ break;
+ case ImGuiInputEventType_MouseWheel:
+ IMGUI_DEBUG_LOG_IO("Event: MouseWheel (%.1f %.1f)\n", e->MouseWheel.WheelX, e->MouseWheel.WheelX);
+ break;
+ case ImGuiInputEventType_Key:
+ IMGUI_DEBUG_LOG_IO("Event: Key \"%s\" %s\n", ImGui::GetKeyName(e->Key.Key), e->Key.Down ? "Down" : "Up");
+ break;
+ case ImGuiInputEventType_KeyMods:
+ IMGUI_DEBUG_LOG_IO("Event: KeyMods Ctrl: %d, Shift: %d, Alt: %d, Super: %d\n", (e->KeyMods.Mods & ImGuiKeyModFlags_Ctrl) != 0, (e->KeyMods.Mods & ImGuiKeyModFlags_Shift) != 0, (e->KeyMods.Mods & ImGuiKeyModFlags_Alt) != 0, (e->KeyMods.Mods & ImGuiKeyModFlags_Super) != 0);
+ break;
+ case ImGuiInputEventType_Char:
+ IMGUI_DEBUG_LOG_IO("Event: Char: U+%08X (%c)\n", e->Text.Char, e->Text.Char);
+ break;
+ case ImGuiInputEventType_Focus:
+ IMGUI_DEBUG_LOG_IO("Event: AppFocused %d\n", e->AppFocused.Focused);
+ break;
+ case ImGuiInputEventType_None:
+ default:
+ break;
+ }
+}
+
+// Process input queue
+// - trickle_fast_inputs = false : process all events, turn into flattened input state (e.g. successive down/up/down/up will be lost)
+// - trickle_fast_inputs = true : process as many events as possible (successive down/up/down/up will be trickled over several frames so nothing is lost) (new feature in 1.87)
+void ImGui::UpdateInputEvents(bool trickle_fast_inputs)
+{
+ ImGuiContext& g = *GImGui;
+ ImGuiIO& io = g.IO;
+
+ bool mouse_moved = false, mouse_wheeled = false, key_changed = false, text_inputed = false;
+ int mouse_button_changed = 0x00, key_mods_changed = 0x00;
+ ImBitArray<ImGuiKey_KeysData_SIZE> key_changed_mask;
+
+ int event_n = 0;
+ for (; event_n < g.InputEventsQueue.Size; event_n++)
+ {
+ const ImGuiInputEvent* e = &g.InputEventsQueue[event_n];
+ if (e->Type == ImGuiInputEventType_MousePos)
+ {
+ if (io.MousePos.x != e->MousePos.PosX || io.MousePos.y != e->MousePos.PosY)
+ {
+ // Trickling Rule: Stop processing queued events if we already handled a mouse button change
+ if (trickle_fast_inputs && (mouse_button_changed != 0 || mouse_wheeled || key_changed || key_mods_changed || text_inputed))
+ break;
+ io.MousePos = ImVec2(e->MousePos.PosX, e->MousePos.PosY);
+ mouse_moved = true;
+ }
+ }
+ else if (e->Type == ImGuiInputEventType_MouseButton)
+ {
+ const ImGuiMouseButton button = e->MouseButton.Button;
+ IM_ASSERT(button >= 0 && button < ImGuiMouseButton_COUNT);
+ if (io.MouseDown[button] != e->MouseButton.Down)
+ {
+ // Trickling Rule: Stop processing queued events if we got multiple action on the same button
+ if (trickle_fast_inputs && ((mouse_button_changed & (1 << button)) || mouse_wheeled))
+ break;
+ io.MouseDown[button] = e->MouseButton.Down;
+ mouse_button_changed |= (1 << button);
+ }
+ }
+ else if (e->Type == ImGuiInputEventType_MouseWheel)
+ {
+ if (e->MouseWheel.WheelX != 0.0f || e->MouseWheel.WheelY != 0.0f)
+ {
+ // Trickling Rule: Stop processing queued events if we got multiple action on the event
+ if (trickle_fast_inputs && (mouse_wheeled || mouse_button_changed != 0))
+ break;
+ io.MouseWheelH += e->MouseWheel.WheelX;
+ io.MouseWheel += e->MouseWheel.WheelY;
+ mouse_wheeled = true;
+ }
+ }
+ else if (e->Type == ImGuiInputEventType_Key)
+ {
+ IM_ASSERT(e->Key.Key != ImGuiKey_None);
+ const int keydata_index = (e->Key.Key - ImGuiKey_KeysData_OFFSET);
+ ImGuiKeyData* keydata = &io.KeysData[keydata_index];
+ if (keydata->Down != e->Key.Down || keydata->AnalogValue != e->Key.Analog)
+ {
+ // Trickling Rule: Stop processing queued events if we got multiple action on the same button
+ if (trickle_fast_inputs && (key_changed_mask.TestBit(keydata_index) || text_inputed || mouse_button_changed != 0))
+ break;
+ keydata->Down = e->Key.Down;
+ keydata->AnalogValue = e->Key.Analog;
+ key_changed = true;
+ key_changed_mask.SetBit(keydata_index);
+ }
+ }
+ else if (e->Type == ImGuiInputEventType_KeyMods)
+ {
+ const ImGuiKeyModFlags modifiers = e->KeyMods.Mods;
+ if (io.KeyMods != modifiers)
+ {
+ // Trickling Rule: Stop processing queued events if we got multiple action on the same button
+ ImGuiKeyModFlags modifiers_that_are_changing = (io.KeyMods ^ modifiers);
+ if (trickle_fast_inputs && (key_mods_changed & modifiers_that_are_changing) != 0)
+ break;
+ io.KeyMods = modifiers;
+ io.KeyCtrl = (modifiers & ImGuiKeyModFlags_Ctrl) != 0;
+ io.KeyShift = (modifiers & ImGuiKeyModFlags_Shift) != 0;
+ io.KeyAlt = (modifiers & ImGuiKeyModFlags_Alt) != 0;
+ io.KeySuper = (modifiers & ImGuiKeyModFlags_Super) != 0;
+ key_mods_changed |= modifiers_that_are_changing;
+ }
+ }
+ else if (e->Type == ImGuiInputEventType_Char)
+ {
+ // Trickling Rule: Stop processing queued events if keys/mouse have been interacted with
+ if (trickle_fast_inputs && (key_changed || mouse_button_changed != 0 || mouse_moved || mouse_wheeled))
+ break;
+ unsigned int c = e->Text.Char;
+ io.InputQueueCharacters.push_back(c <= IM_UNICODE_CODEPOINT_MAX ? (ImWchar)c : IM_UNICODE_CODEPOINT_INVALID);
+ text_inputed = true;
+ }
+ else if (e->Type == ImGuiInputEventType_Focus)
+ {
+ // We intentionally overwrite this and process lower, in order to give a chance
+ // to multi-viewports backends to queue AddFocusEvent(false) + AddFocusEvent(true) in same frame.
+ io.AppFocusLost = !e->AppFocused.Focused;
+ }
+ else
+ {
+ IM_ASSERT(0 && "Unknown event!");
+ }
+ }
+
+ // Record trail (for domain-specific applications wanting to access a precise trail)
+ for (int n = 0; n < event_n; n++)
+ g.InputEventsTrail.push_back(g.InputEventsQueue[n]);
+
+ // Remaining events will be processed on the next frame
+ if (event_n == g.InputEventsQueue.Size)
+ {
+ g.InputEventsQueue.resize(0);
+ }
+ else
+ {
+ IMGUI_DEBUG_LOG_IO("Processed inputs:\n");
+
+ for (int n = 0; n < event_n; n++)
+ DebugLogInputEvent(&g.InputEventsQueue[n]);
+ g.InputEventsQueue.erase(g.InputEventsQueue.Data, g.InputEventsQueue.Data + event_n);
+ IMGUI_DEBUG_LOG_IO("Remaining inputs:\n");
+ for (int n = 0; n < g.InputEventsQueue.Size; n++)
+ DebugLogInputEvent(&g.InputEventsQueue[n]);
+ }
+
+ // Clear buttons state when focus is lost
+ // (this is useful so e.g. releasing Alt after focus loss on Alt-Tab doesn't trigger the Alt menu toggle)
+ if (g.IO.AppFocusLost)
+ {
+ g.IO.ClearInputKeys();
+ g.IO.AppFocusLost = false;
+ }
+}
+
//-----------------------------------------------------------------------------
// [SECTION] ERROR CHECKING
diff --git a/imgui.h b/imgui.h
index a1cfb76..e03b203 100644
--- a/imgui.h
+++ b/imgui.h
@@ -1926,6 +1926,7 @@
bool Down; // True for if key is down
float DownDuration; // Duration the key has been down (<0.0f: not pressed, 0.0f: just pressed, >0.0f: time held)
float DownDurationPrev; // Last frame duration the key has been down
+ float AnalogValue; // 0.0f..1.0f for gamepad values
};
struct ImGuiIO
@@ -2007,10 +2008,14 @@
// Input Functions
IMGUI_API void AddKeyEvent(ImGuiKey key, bool down); // Queue a new key down/up event. Key should be "translated" (as in, generally ImGuiKey_A matches the key end-user would use to emit an 'A' character)
IMGUI_API void AddKeyModsEvent(ImGuiKeyModFlags modifiers);// Queue a change of Ctrl/Shift/Alt/Super modifiers
+ IMGUI_API void AddMousePosEvent(float x, float y); // Queue a mouse position update. Use -FLT_MAX,-FLT_MAX to signify no mouse (e.g. app not focused and not hovered)
+ IMGUI_API void AddMouseWheelEvent(float wh_x, float wh_y); // Queue a mouse wheel update
+ IMGUI_API void AddMouseButtonEvent(int button, bool down); // Queue a mouse button change
IMGUI_API void AddFocusEvent(bool focused); // Queue an hosting application/platform windows gain or loss of focus
IMGUI_API void AddInputCharacter(unsigned int c); // Queue new character input
IMGUI_API void AddInputCharacterUTF16(ImWchar16 c); // Queue new character input from an UTF-16 character, it can be a surrogate
IMGUI_API void AddInputCharactersUTF8(const char* str); // Queue new characters input from an UTF-8 string
+
IMGUI_API void ClearInputCharacters(); // [Internal] Clear the text input buffer manually
IMGUI_API void ClearInputKeys(); // [Internal] Release all keys
IMGUI_API void SetKeyEventNativeData(ImGuiKey key, int native_keycode, int native_scancode, int native_legacy_index = -1); // [Optional] Specify index for legacy <1.87 IsKeyXXX() functions with native indices + specify native keycode, scancode.
diff --git a/imgui_internal.h b/imgui_internal.h
index 88e0985..9572d0d 100644
--- a/imgui_internal.h
+++ b/imgui_internal.h
@@ -199,8 +199,10 @@
// Debug Logging for selected systems. Remove the '((void)0) //' to enable.
//#define IMGUI_DEBUG_LOG_POPUP IMGUI_DEBUG_LOG // Enable log
//#define IMGUI_DEBUG_LOG_NAV IMGUI_DEBUG_LOG // Enable log
+//#define IMGUI_DEBUG_LOG_IO IMGUI_DEBUG_LOG // Enable log
#define IMGUI_DEBUG_LOG_POPUP(...) ((void)0) // Disable log
#define IMGUI_DEBUG_LOG_NAV(...) ((void)0) // Disable log
+#define IMGUI_DEBUG_LOG_IO(...) ((void)0) // Disable log
// Static Asserts
#if (__cplusplus >= 201100) || (defined(_MSVC_LANG) && _MSVC_LANG >= 201100)
@@ -900,6 +902,19 @@
ImGuiPlotType_Histogram
};
+enum ImGuiInputEventType
+{
+ ImGuiInputEventType_None = 0,
+ ImGuiInputEventType_MousePos,
+ ImGuiInputEventType_MouseWheel,
+ ImGuiInputEventType_MouseButton,
+ ImGuiInputEventType_Key,
+ ImGuiInputEventType_KeyMods,
+ ImGuiInputEventType_Char,
+ ImGuiInputEventType_Focus,
+ ImGuiInputEventType_COUNT
+};
+
enum ImGuiInputSource
{
ImGuiInputSource_None = 0,
@@ -911,6 +926,34 @@
ImGuiInputSource_COUNT
};
+// FIXME: Structures in the union below need to be declared as anonymous unions appears to be an extension?
+// Using ImVec2() would fail on Clang 'union member 'MousePos' has a non-trivial default constructor'
+struct ImGuiInputEventMousePos { float PosX, PosY; };
+struct ImGuiInputEventMouseWheel { float WheelX, WheelY; };
+struct ImGuiInputEventMouseButton { int Button; bool Down; };
+struct ImGuiInputEventKey { ImGuiKey Key; bool Down; float Analog; };
+struct ImGuiInputEventKeyMods { ImGuiKeyModFlags Mods; };
+struct ImGuiInputEventText { unsigned int Char; };
+struct ImGuiInputEventAppFocused { bool Focused; };
+
+struct ImGuiInputEvent
+{
+ ImGuiInputEventType Type;
+ ImGuiInputSource Source;
+ union
+ {
+ ImGuiInputEventMousePos MousePos; // if Type == ImGuiInputEventType_MousePos
+ ImGuiInputEventMouseWheel MouseWheel; // if Type == ImGuiInputEventType_MouseWheel
+ ImGuiInputEventMouseButton MouseButton; // if Type == ImGuiInputEventType_MouseButton
+ ImGuiInputEventKey Key; // if Type == ImGuiInputEventType_Key
+ ImGuiInputEventKeyMods KeyMods; // if Type == ImGuiInputEventType_Modifiers
+ ImGuiInputEventText Text; // if Type == ImGuiInputEventType_Text
+ ImGuiInputEventAppFocused AppFocused; // if Type == ImGuiInputEventType_Focus
+ };
+
+ ImGuiInputEvent() { memset(this, 0, sizeof(*this)); }
+};
+
// FIXME-NAV: Clarify/expose various repeat delay/rate
enum ImGuiInputReadMode
{
@@ -1502,6 +1545,8 @@
bool Initialized;
bool FontAtlasOwnedByContext; // IO.Fonts-> is owned by the ImGuiContext and will be destructed along with it.
ImGuiIO IO;
+ ImVector<ImGuiInputEvent> InputEventsQueue; // Input events which will be tricked/written into IO structure.
+ ImVector<ImGuiInputEvent> InputEventsTrail; // Past input events processed in NewFrame(). This is to allow domain-specific application to access e.g mouse/pen trail.
ImGuiStyle Style;
ImFont* Font; // (Shortcut) == FontStack.empty() ? IO.Font : FontStack.back()
float FontSize; // (Shortcut) == FontBaseSize * g.CurrentWindow->FontWindowScale == window->FontSize(). Text height for current window.
@@ -2457,6 +2502,7 @@
IMGUI_API void Shutdown(ImGuiContext* context); // Since 1.60 this is a _private_ function. You can call DestroyContext() to destroy the context created by CreateContext().
// NewFrame
+ IMGUI_API void UpdateInputEvents(bool trickle_fast_inputs);
IMGUI_API void UpdateHoveredWindowAndCaptureFlags();
IMGUI_API void StartMouseMovingWindow(ImGuiWindow* window);
IMGUI_API void UpdateMouseMovingWindowNewFrame();