IO: remove ImGuiInputEvent::IgnoredAsSame (revert part of 839c3100), will filter earlier in next commit. (#5599)

Making it a separate commit as this leads to much indentation change.
This commit is contained in:
ocornut 2022-09-29 21:31:36 +02:00
parent 9e7f460c09
commit fac8295d6e
2 changed files with 39 additions and 58 deletions

View File

@ -8121,79 +8121,63 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs)
ImGuiInputEvent* e = &g.InputEventsQueue[event_n]; ImGuiInputEvent* e = &g.InputEventsQueue[event_n];
if (e->Type == ImGuiInputEventType_MousePos) if (e->Type == ImGuiInputEventType_MousePos)
{ {
// Trickling Rule: Stop processing queued events if we already handled a mouse button change
ImVec2 event_pos(e->MousePos.PosX, e->MousePos.PosY); ImVec2 event_pos(e->MousePos.PosX, e->MousePos.PosY);
if (IsMousePosValid(&event_pos)) if (IsMousePosValid(&event_pos))
event_pos = ImVec2(ImFloorSigned(event_pos.x), ImFloorSigned(event_pos.y)); // Apply same flooring as UpdateMouseInputs() event_pos = ImVec2(ImFloorSigned(event_pos.x), ImFloorSigned(event_pos.y)); // Apply same flooring as UpdateMouseInputs()
e->IgnoredAsSame = (io.MousePos.x == event_pos.x && io.MousePos.y == event_pos.y); if (trickle_fast_inputs && (mouse_button_changed != 0 || mouse_wheeled || key_changed || text_inputted))
if (!e->IgnoredAsSame) break;
{ io.MousePos = event_pos;
// Trickling Rule: Stop processing queued events if we already handled a mouse button change mouse_moved = true;
if (trickle_fast_inputs && (mouse_button_changed != 0 || mouse_wheeled || key_changed || text_inputted))
break;
io.MousePos = event_pos;
mouse_moved = true;
}
} }
else if (e->Type == ImGuiInputEventType_MouseButton) else if (e->Type == ImGuiInputEventType_MouseButton)
{ {
// Trickling Rule: Stop processing queued events if we got multiple action on the same button
const ImGuiMouseButton button = e->MouseButton.Button; const ImGuiMouseButton button = e->MouseButton.Button;
IM_ASSERT(button >= 0 && button < ImGuiMouseButton_COUNT); IM_ASSERT(button >= 0 && button < ImGuiMouseButton_COUNT);
e->IgnoredAsSame = (io.MouseDown[button] == e->MouseButton.Down); if (trickle_fast_inputs && ((mouse_button_changed & (1 << button)) || mouse_wheeled))
if (!e->IgnoredAsSame) break;
{ io.MouseDown[button] = e->MouseButton.Down;
// Trickling Rule: Stop processing queued events if we got multiple action on the same button mouse_button_changed |= (1 << 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) else if (e->Type == ImGuiInputEventType_MouseWheel)
{ {
e->IgnoredAsSame = (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 (!e->IgnoredAsSame) if (trickle_fast_inputs && (mouse_moved || mouse_button_changed != 0))
{ break;
// Trickling Rule: Stop processing queued events if we got multiple action on the event io.MouseWheelH += e->MouseWheel.WheelX;
if (trickle_fast_inputs && (mouse_moved || mouse_button_changed != 0)) io.MouseWheel += e->MouseWheel.WheelY;
break; mouse_wheeled = true;
io.MouseWheelH += e->MouseWheel.WheelX;
io.MouseWheel += e->MouseWheel.WheelY;
mouse_wheeled = true;
}
} }
else if (e->Type == ImGuiInputEventType_Key) else if (e->Type == ImGuiInputEventType_Key)
{ {
// Trickling Rule: Stop processing queued events if we got multiple action on the same button
ImGuiKey key = e->Key.Key; ImGuiKey key = e->Key.Key;
IM_ASSERT(key != ImGuiKey_None); IM_ASSERT(key != ImGuiKey_None);
ImGuiKeyData* key_data = GetKeyData(key); ImGuiKeyData* key_data = GetKeyData(key);
const int key_data_index = (int)(key_data - g.IO.KeysData); const int key_data_index = (int)(key_data - g.IO.KeysData);
e->IgnoredAsSame = (key_data->Down == e->Key.Down && key_data->AnalogValue == e->Key.AnalogValue); if (trickle_fast_inputs && key_data->Down != e->Key.Down && (key_changed_mask.TestBit(key_data_index) || text_inputted || mouse_button_changed != 0))
if (!e->IgnoredAsSame) break;
key_data->Down = e->Key.Down;
key_data->AnalogValue = e->Key.AnalogValue;
key_changed = true;
key_changed_mask.SetBit(key_data_index);
if (key == ImGuiMod_Ctrl || key == ImGuiMod_Shift || key == ImGuiMod_Alt || key == ImGuiMod_Super)
{ {
// Trickling Rule: Stop processing queued events if we got multiple action on the same button if (key == ImGuiMod_Ctrl) { io.KeyCtrl = key_data->Down; }
if (trickle_fast_inputs && key_data->Down != e->Key.Down && (key_changed_mask.TestBit(key_data_index) || text_inputted || mouse_button_changed != 0)) if (key == ImGuiMod_Shift) { io.KeyShift = key_data->Down; }
break; if (key == ImGuiMod_Alt) { io.KeyAlt = key_data->Down; }
key_data->Down = e->Key.Down; if (key == ImGuiMod_Super) { io.KeySuper = key_data->Down; }
key_data->AnalogValue = e->Key.AnalogValue; io.KeyMods = GetMergedModsFromBools();
key_changed = true;
key_changed_mask.SetBit(key_data_index);
if (key == ImGuiMod_Ctrl || key == ImGuiMod_Shift || key == ImGuiMod_Alt || key == ImGuiMod_Super)
{
if (key == ImGuiMod_Ctrl) { io.KeyCtrl = key_data->Down; }
if (key == ImGuiMod_Shift) { io.KeyShift = key_data->Down; }
if (key == ImGuiMod_Alt) { io.KeyAlt = key_data->Down; }
if (key == ImGuiMod_Super) { io.KeySuper = key_data->Down; }
io.KeyMods = GetMergedModsFromBools();
}
// Allow legacy code using io.KeysDown[GetKeyIndex()] with new backends
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
io.KeysDown[key_data_index] = key_data->Down;
if (io.KeyMap[key_data_index] != -1)
io.KeysDown[io.KeyMap[key_data_index]] = key_data->Down;
#endif
} }
// Allow legacy code using io.KeysDown[GetKeyIndex()] with new backends
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
io.KeysDown[key_data_index] = key_data->Down;
if (io.KeyMap[key_data_index] != -1)
io.KeysDown[io.KeyMap[key_data_index]] = key_data->Down;
#endif
} }
else if (e->Type == ImGuiInputEventType_Text) else if (e->Type == ImGuiInputEventType_Text)
{ {
@ -8210,9 +8194,7 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs)
// We intentionally overwrite this and process in NewFrame(), in order to give a chance // 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. // to multi-viewports backends to queue AddFocusEvent(false) + AddFocusEvent(true) in same frame.
const bool focus_lost = !e->AppFocused.Focused; const bool focus_lost = !e->AppFocused.Focused;
e->IgnoredAsSame = (io.AppFocusLost == focus_lost); io.AppFocusLost = focus_lost;
if (!e->IgnoredAsSame)
io.AppFocusLost = focus_lost;
} }
else else
{ {
@ -8229,7 +8211,7 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs)
#ifndef IMGUI_DISABLE_DEBUG_TOOLS #ifndef IMGUI_DISABLE_DEBUG_TOOLS
if (event_n != 0 && (g.DebugLogFlags & ImGuiDebugLogFlags_EventIO)) if (event_n != 0 && (g.DebugLogFlags & ImGuiDebugLogFlags_EventIO))
for (int n = 0; n < g.InputEventsQueue.Size; n++) for (int n = 0; n < g.InputEventsQueue.Size; n++)
DebugPrintInputEvent(n < event_n ? (g.InputEventsQueue[n].IgnoredAsSame ? "Processed (Same)" : "Processed") : "Remaining", &g.InputEventsQueue[n]); DebugPrintInputEvent(n < event_n ? "Processed" : "Remaining", &g.InputEventsQueue[n]);
#endif #endif
// Remaining events will be processed on the next frame // Remaining events will be processed on the next frame

View File

@ -1245,7 +1245,6 @@ struct ImGuiInputEvent
ImGuiInputEventText Text; // if Type == ImGuiInputEventType_Text ImGuiInputEventText Text; // if Type == ImGuiInputEventType_Text
ImGuiInputEventAppFocused AppFocused; // if Type == ImGuiInputEventType_Focus ImGuiInputEventAppFocused AppFocused; // if Type == ImGuiInputEventType_Focus
}; };
bool IgnoredAsSame;
bool AddedByTestEngine; bool AddedByTestEngine;
ImGuiInputEvent() { memset(this, 0, sizeof(*this)); } ImGuiInputEvent() { memset(this, 0, sizeof(*this)); }