MCPcopy Create free account
hub / github.com/TheForceEngine/TheForceEngine / AddKeyAnalogEvent

Method AddKeyAnalogEvent

TheForceEngine/TFE_Ui/imGUI/imgui.cpp:1541–1590  ·  view source on GitHub ↗

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. - float analog_value: 0.0f..1.0f IMPORTANT: THIS FUNCTION AND OTHER "ADD" GRABS THE CONTEXT FROM OUR INSTANCE. WE NEED TO ENSURE THAT ALL FUNCTION CALLS ARE FULFILLING

Source from the content-addressed store, hash-verified

1539// IMPORTANT: THIS FUNCTION AND OTHER "ADD" GRABS THE CONTEXT FROM OUR INSTANCE.
1540// WE NEED TO ENSURE THAT ALL FUNCTION CALLS ARE FULFILLING THIS, WHICH IS WHY GetKeyData() HAS AN EXPLICIT CONTEXT.
1541void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value)
1542{
1543 //if (e->Down) { IMGUI_DEBUG_LOG_IO("AddKeyEvent() Key='%s' %d, NativeKeycode = %d, NativeScancode = %d\n", ImGui::GetKeyName(e->Key), e->Down, e->NativeKeycode, e->NativeScancode); }
1544 IM_ASSERT(Ctx != NULL);
1545 if (key == ImGuiKey_None || !AppAcceptingEvents)
1546 return;
1547 ImGuiContext& g = *Ctx;
1548 IM_ASSERT(ImGui::IsNamedKeyOrMod(key)); // Backend needs to pass a valid ImGuiKey_ constant. 0..511 values are legacy native key codes which are not accepted by this API.
1549 IM_ASSERT(ImGui::IsAliasKey(key) == false); // Backend cannot submit ImGuiKey_MouseXXX values they are automatically inferred from AddMouseXXX() events.
1550
1551 // MacOS: swap Cmd(Super) and Ctrl
1552 if (g.IO.ConfigMacOSXBehaviors)
1553 {
1554 if (key == ImGuiMod_Super) { key = ImGuiMod_Ctrl; }
1555 else if (key == ImGuiMod_Ctrl) { key = ImGuiMod_Super; }
1556 else if (key == ImGuiKey_LeftSuper) { key = ImGuiKey_LeftCtrl; }
1557 else if (key == ImGuiKey_RightSuper){ key = ImGuiKey_RightCtrl; }
1558 else if (key == ImGuiKey_LeftCtrl) { key = ImGuiKey_LeftSuper; }
1559 else if (key == ImGuiKey_RightCtrl) { key = ImGuiKey_RightSuper; }
1560 }
1561
1562 // Verify that backend isn't mixing up using new io.AddKeyEvent() api and old io.KeysDown[] + io.KeyMap[] data.
1563#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
1564 IM_ASSERT((BackendUsingLegacyKeyArrays == -1 || BackendUsingLegacyKeyArrays == 0) && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!");
1565 if (BackendUsingLegacyKeyArrays == -1)
1566 for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++)
1567 IM_ASSERT(KeyMap[n] == -1 && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!");
1568 BackendUsingLegacyKeyArrays = 0;
1569#endif
1570 if (ImGui::IsGamepadKey(key))
1571 BackendUsingLegacyNavInputArray = false;
1572
1573 // Filter duplicate (in particular: key mods and gamepad analog values are commonly spammed)
1574 const ImGuiInputEvent* latest_event = FindLatestInputEvent(&g, ImGuiInputEventType_Key, (int)key);
1575 const ImGuiKeyData* key_data = ImGui::GetKeyData(&g, key);
1576 const bool latest_key_down = latest_event ? latest_event->Key.Down : key_data->Down;
1577 const float latest_key_analog = latest_event ? latest_event->Key.AnalogValue : key_data->AnalogValue;
1578 if (latest_key_down == down && latest_key_analog == analog_value)
1579 return;
1580
1581 // Add event
1582 ImGuiInputEvent e;
1583 e.Type = ImGuiInputEventType_Key;
1584 e.Source = ImGui::IsGamepadKey(key) ? ImGuiInputSource_Gamepad : ImGuiInputSource_Keyboard;
1585 e.EventId = g.InputEventsNextEventId++;
1586 e.Key.Key = key;
1587 e.Key.Down = down;
1588 e.Key.AnalogValue = analog_value;
1589 g.InputEventsQueue.push_back(e);
1590}
1591
1592void ImGuiIO::AddKeyEvent(ImGuiKey key, bool down)
1593{

Callers 1

Calls 6

IsNamedKeyOrModFunction · 0.85
IsAliasKeyFunction · 0.85
IsGamepadKeyFunction · 0.85
FindLatestInputEventFunction · 0.85
GetKeyDataFunction · 0.85
push_backMethod · 0.80

Tested by

no test coverage detected