MCPcopy Create free account
hub / github.com/Raais/ImStudio / UpdateInputEvents

Method UpdateInputEvents

src/third-party/imgui/imgui.cpp:7781–7898  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

7779// - trickle_fast_inputs = false : process all events, turn into flattened input state (e.g. successive down/up/down/up will be lost)
7780// - 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)
7781void ImGui::UpdateInputEvents(bool trickle_fast_inputs)
7782{
7783 ImGuiContext& g = *GImGui;
7784 ImGuiIO& io = g.IO;
7785
7786 bool mouse_moved = false, mouse_wheeled = false, key_changed = false, text_inputed = false;
7787 int mouse_button_changed = 0x00;
7788 ImBitArray<ImGuiKey_KeysData_SIZE> key_changed_mask;
7789
7790 int event_n = 0;
7791 for (; event_n < g.InputEventsQueue.Size; event_n++)
7792 {
7793 const ImGuiInputEvent* e = &g.InputEventsQueue[event_n];
7794 if (e->Type == ImGuiInputEventType_MousePos)
7795 {
7796 ImVec2 event_pos(e->MousePos.PosX, e->MousePos.PosY);
7797 if (IsMousePosValid(&event_pos))
7798 event_pos = ImVec2(ImFloorSigned(event_pos.x), ImFloorSigned(event_pos.y)); // Apply same flooring as UpdateMouseInputs()
7799 if (io.MousePos.x != event_pos.x || io.MousePos.y != event_pos.y)
7800 {
7801 // Trickling Rule: Stop processing queued events if we already handled a mouse button change
7802 if (trickle_fast_inputs && (mouse_button_changed != 0 || mouse_wheeled || key_changed || text_inputed))
7803 break;
7804 io.MousePos = event_pos;
7805 mouse_moved = true;
7806 }
7807 }
7808 else if (e->Type == ImGuiInputEventType_MouseButton)
7809 {
7810 const ImGuiMouseButton button = e->MouseButton.Button;
7811 IM_ASSERT(button >= 0 && button < ImGuiMouseButton_COUNT);
7812 if (io.MouseDown[button] != e->MouseButton.Down)
7813 {
7814 // Trickling Rule: Stop processing queued events if we got multiple action on the same button
7815 if (trickle_fast_inputs && ((mouse_button_changed & (1 << button)) || mouse_wheeled))
7816 break;
7817 io.MouseDown[button] = e->MouseButton.Down;
7818 mouse_button_changed |= (1 << button);
7819 }
7820 }
7821 else if (e->Type == ImGuiInputEventType_MouseWheel)
7822 {
7823 if (e->MouseWheel.WheelX != 0.0f || e->MouseWheel.WheelY != 0.0f)
7824 {
7825 // Trickling Rule: Stop processing queued events if we got multiple action on the event
7826 if (trickle_fast_inputs && (mouse_wheeled || mouse_button_changed != 0))
7827 break;
7828 io.MouseWheelH += e->MouseWheel.WheelX;
7829 io.MouseWheel += e->MouseWheel.WheelY;
7830 mouse_wheeled = true;
7831 }
7832 }
7833 else if (e->Type == ImGuiInputEventType_Key)
7834 {
7835 ImGuiKey key = e->Key.Key;
7836 IM_ASSERT(key != ImGuiKey_None);
7837 const int keydata_index = (key - ImGuiKey_KeysData_OFFSET);
7838 ImGuiKeyData* keydata = &io.KeysData[keydata_index];

Callers

nothing calls this directly

Calls 7

ImVec2Function · 0.85
ImFloorSignedFunction · 0.85
TestBitMethod · 0.80
push_backMethod · 0.80
resizeMethod · 0.80
ClearInputKeysMethod · 0.80
SetBitMethod · 0.45

Tested by

no test coverage detected