mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-06 04:58:47 +02:00
Merge branch 'master' into docking
# Conflicts: # backends/imgui_impl_glfw.cpp # backends/imgui_impl_sdl.cpp # backends/imgui_impl_vulkan.cpp # backends/imgui_impl_vulkan.h # backends/imgui_impl_win32.cpp # imgui.cpp # imgui.h # imgui_demo.cpp # imgui_internal.h
This commit is contained in:
161
imgui.cpp
161
imgui.cpp
@ -129,7 +129,6 @@ CODE
|
||||
- CTRL+X,CTRL+C,CTRL+V to use OS clipboard/
|
||||
- CTRL+Z,CTRL+Y to undo/redo.
|
||||
- ESCAPE to revert text to its original value.
|
||||
- You can apply arithmetic operators +,*,/ on numerical values. Use +- to subtract (because - would set a negative value!)
|
||||
- Controls are automatically adjusted for OSX to match standard OSX text editing operations.
|
||||
- General Keyboard controls: enable with ImGuiConfigFlags_NavEnableKeyboard.
|
||||
- General Gamepad controls: enable with ImGuiConfigFlags_NavEnableGamepad. See suggested mappings in imgui.h ImGuiNavInput_ + download PNG/PSD at http://dearimgui.org/controls_sheets
|
||||
@ -256,9 +255,9 @@ CODE
|
||||
io.DeltaTime = 1.0f/60.0f; // set the time elapsed since the previous frame (in seconds)
|
||||
io.DisplaySize.x = 1920.0f; // set the current display width
|
||||
io.DisplaySize.y = 1280.0f; // set the current display height here
|
||||
io.MousePos = my_mouse_pos; // set the mouse position
|
||||
io.MouseDown[0] = my_mouse_buttons[0]; // set the mouse button states
|
||||
io.MouseDown[1] = my_mouse_buttons[1];
|
||||
io.AddMousePosEvent(mouse_x, mouse_y); // update mouse position
|
||||
io.AddMouseButtonEvent(0, mouse_b[0]); // update mouse button states
|
||||
io.AddMouseButtonEvent(1, mouse_b[1]); // update mouse button states
|
||||
|
||||
// Call NewFrame(), after this point you can use ImGui::* functions anytime
|
||||
// (So you want to try calling NewFrame() as early as you can in your main loop to be able to use Dear ImGui everywhere)
|
||||
@ -348,27 +347,26 @@ CODE
|
||||
- You can ask questions and report issues at https://github.com/ocornut/imgui/issues/787
|
||||
- The initial focus was to support game controllers, but keyboard is becoming increasingly and decently usable.
|
||||
- Keyboard:
|
||||
- Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable.
|
||||
NewFrame() will automatically fill io.NavInputs[] based on your io.AddKeyEvent() calls.
|
||||
- When keyboard navigation is active (io.NavActive + ImGuiConfigFlags_NavEnableKeyboard), the io.WantCaptureKeyboard flag
|
||||
will be set. For more advanced uses, you may want to read from:
|
||||
- Application: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableKeyboard to enable.
|
||||
- Internally: NewFrame() will automatically fill io.NavInputs[] based on backend's io.AddKeyEvent() calls.
|
||||
- When keyboard navigation is active (io.NavActive + ImGuiConfigFlags_NavEnableKeyboard),
|
||||
the io.WantCaptureKeyboard flag will be set. For more advanced uses, you may want to read from:
|
||||
- io.NavActive: true when a window is focused and it doesn't have the ImGuiWindowFlags_NoNavInputs flag set.
|
||||
- io.NavVisible: true when the navigation cursor is visible (and usually goes false when mouse is used).
|
||||
- or query focus information with e.g. IsWindowFocused(ImGuiFocusedFlags_AnyWindow), IsItemFocused() etc. functions.
|
||||
Please reach out if you think the game vs navigation input sharing could be improved.
|
||||
- Gamepad:
|
||||
- Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad to enable.
|
||||
- Backend: Set io.BackendFlags |= ImGuiBackendFlags_HasGamepad + fill the io.NavInputs[] fields before calling NewFrame().
|
||||
Note that io.NavInputs[] is cleared by EndFrame().
|
||||
- See 'enum ImGuiNavInput_' in imgui.h for a description of inputs. For each entry of io.NavInputs[], set the following values:
|
||||
0.0f= not held. 1.0f= fully held. Pass intermediate 0.0f..1.0f values for analog triggers/sticks.
|
||||
- We use a simple >0.0f test for activation testing, and won't attempt to test for a dead-zone.
|
||||
Your code will probably need to transform your raw inputs (such as e.g. remapping your 0.2..0.9 raw input range to 0.0..1.0 imgui range, etc.).
|
||||
- Application: Set io.ConfigFlags |= ImGuiConfigFlags_NavEnableGamepad to enable.
|
||||
- Backend: Set io.BackendFlags |= ImGuiBackendFlags_HasGamepad + call io.AddKeyEvent/AddKeyAnalogEvent() with ImGuiKey_Gamepad_XXX keys.
|
||||
For analog values (0.0f to 1.0f), backend is responsible to handling a dead-zone and rescaling inputs accordingly.
|
||||
Backend code will probably need to transform your raw inputs (such as e.g. remapping your 0.2..0.9 raw input range to 0.0..1.0 imgui range, etc.).
|
||||
- Internally: NewFrame() will automatically fill io.NavInputs[] based on backend's io.AddKeyEvent() + io.AddKeyAnalogEvent() calls.
|
||||
- BEFORE 1.87, BACKENDS USED TO WRITE DIRECTLY TO io.NavInputs[]. This is going to be obsoleted in the future. Please call io functions instead!
|
||||
- You can download PNG/PSD files depicting the gamepad controls for common controllers at: http://dearimgui.org/controls_sheets
|
||||
- If you need to share inputs between your game and the imgui parts, the easiest approach is to go all-or-nothing, with a buttons combo
|
||||
to toggle the target. Please reach out if you think the game vs navigation input sharing could be improved.
|
||||
- If you need to share inputs between your game and the Dear ImGui interface, the easiest approach is to go all-or-nothing,
|
||||
with a buttons combo to toggle the target. Please reach out if you think the game vs navigation input sharing could be improved.
|
||||
- Mouse:
|
||||
- PS4 users: Consider emulating a mouse cursor with DualShock4 touch pad or a spare analog stick as a mouse-emulation fallback.
|
||||
- PS4/PS5 users: Consider emulating a mouse cursor with DualShock4 touch pad or a spare analog stick as a mouse-emulation fallback.
|
||||
- Consoles/Tablet/Phone users: Consider using a Synergy 1.x server (on your PC) + uSynergy.c (on your console/tablet/phone app) to share your PC mouse/keyboard.
|
||||
- On a TV/console system where readability may be lower or mouse inputs may be awkward, you may want to set the ImGuiConfigFlags_NavEnableSetMousePos flag.
|
||||
Enabling ImGuiConfigFlags_NavEnableSetMousePos + ImGuiBackendFlags_HasSetMousePos instructs dear imgui to move your mouse cursor along with navigation movements.
|
||||
@ -394,6 +392,14 @@ CODE
|
||||
- likewise io.MousePos and GetMousePos() will use OS coordinates.
|
||||
If you query mouse positions to interact with non-imgui coordinates you will need to offset them, e.g. subtract GetWindowViewport()->Pos.
|
||||
|
||||
- 2022/01/20 (1.87) - inputs: reworded gamepad IO.
|
||||
- Backend writing to io.NavInputs[] -> backend should call io.AddKeyEvent()/io.AddKeyAnalogEvent() with ImGuiKey_GamepadXXX values.
|
||||
- 2022/01/19 (1.87) - sliders, drags: removed support for legacy arithmetic operators (+,+-,*,/) when inputing text. This doesn't break any api/code but a feature that used to be accessible by end-users (which seemingly no one used).
|
||||
- 2022/01/17 (1.87) - inputs: reworked mouse IO.
|
||||
- Backend writing to io.MousePos -> backend should call io.AddMousePosEvent()
|
||||
- Backend writing to io.MouseDown[] -> backend should call io.AddMouseButtonEvent()
|
||||
- Backend writing to io.MouseWheel -> backend should call io.AddMouseWheelEvent()
|
||||
- Backend writing to io.MouseHoveredViewpot -> backend should call io.AddMouseViewportEvent() [Docking branch only]
|
||||
- 2022/01/10 (1.87) - inputs: reworked keyboard IO. Removed io.KeyMap[], io.KeysDown[] in favor of calling io.AddKeyEvent(). Removed GetKeyIndex(), now unecessary. All IsKeyXXX() functions now take ImGuiKey values. All features are still functional until IMGUI_DISABLE_OBSOLETE_KEYIO is defined. Read Changelog and Release Notes for details.
|
||||
- IsKeyPressed(MY_NATIVE_KEY_XXX) -> use IsKeyPressed(ImGuiKey_XXX)
|
||||
- IsKeyPressed(GetKeyIndex(ImGuiKey_XXX)) -> use IsKeyPressed(ImGuiKey_XXX)
|
||||
@ -1172,7 +1178,7 @@ ImGuiIO::ImGuiIO()
|
||||
#else
|
||||
ConfigMacOSXBehaviors = false;
|
||||
#endif
|
||||
ConfigInputEventQueue = true;
|
||||
ConfigInputTrickleEventQueue = true;
|
||||
ConfigInputTextCursorBlink = true;
|
||||
ConfigWindowsResizeFromEdges = true;
|
||||
ConfigWindowsMoveFromTitleBarOnly = false;
|
||||
@ -1194,6 +1200,7 @@ ImGuiIO::ImGuiIO()
|
||||
for (int i = 0; i < IM_ARRAYSIZE(KeysData); i++) { KeysData[i].DownDuration = KeysData[i].DownDurationPrev = -1.0f; }
|
||||
for (int i = 0; i < IM_ARRAYSIZE(NavInputsDownDuration); i++) NavInputsDownDuration[i] = -1.0f;
|
||||
BackendUsingLegacyKeyArrays = (ImS8)-1;
|
||||
BackendUsingLegacyNavInputArray = true; // assume using legacy array until proven wrong
|
||||
}
|
||||
|
||||
// Pass in translated ASCII characters for text input.
|
||||
@ -1284,9 +1291,10 @@ void ImGuiIO::ClearInputKeys()
|
||||
}
|
||||
|
||||
// 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.
|
||||
void ImGuiIO::AddKeyEvent(ImGuiKey key, bool down)
|
||||
// - 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
|
||||
void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value)
|
||||
{
|
||||
//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)
|
||||
@ -1303,15 +1311,23 @@ void ImGuiIO::AddKeyEvent(ImGuiKey key, bool down)
|
||||
IM_ASSERT(KeyMap[n] == -1 && "Backend needs to either only use io.AddKeyEvent(), either only fill legacy io.KeysDown[] + io.KeyMap[]. Not both!");
|
||||
BackendUsingLegacyKeyArrays = 0;
|
||||
#endif
|
||||
if (ImGui::IsGamepadKey(key))
|
||||
BackendUsingLegacyNavInputArray = false;
|
||||
|
||||
ImGuiInputEvent e;
|
||||
e.Type = ImGuiInputEventType_Key;
|
||||
e.Source = ImGuiInputSource_Keyboard;
|
||||
e.Source = ImGui::IsGamepadKey(key) ? ImGuiInputSource_Gamepad : ImGuiInputSource_Keyboard;
|
||||
e.Key.Key = key;
|
||||
e.Key.Down = down;
|
||||
e.Key.AnalogValue = analog_value;
|
||||
g.InputEventsQueue.push_back(e);
|
||||
}
|
||||
|
||||
void ImGuiIO::AddKeyEvent(ImGuiKey key, bool down)
|
||||
{
|
||||
AddKeyAnalogEvent(key, down, down ? 1.0f : 0.0f);
|
||||
}
|
||||
|
||||
// [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.
|
||||
@ -1361,6 +1377,21 @@ void ImGuiIO::AddMousePosEvent(float x, float 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);
|
||||
}
|
||||
|
||||
// Queue a mouse wheel event (most mouse/API will only have a Y component)
|
||||
void ImGuiIO::AddMouseWheelEvent(float wheel_x, float wheel_y)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -1376,20 +1407,6 @@ void ImGuiIO::AddMouseWheelEvent(float wheel_x, float 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::AddMouseViewportEvent(ImGuiID viewport_id)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -3410,7 +3427,7 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
|
||||
if (id)
|
||||
{
|
||||
g.ActiveIdIsAlive = id;
|
||||
g.ActiveIdSource = (g.NavActivateId == id || g.NavActivateInputId == id || g.NavJustMovedToId == id) ? ImGuiInputSource_Nav : ImGuiInputSource_Mouse;
|
||||
g.ActiveIdSource = (g.NavActivateId == id || g.NavActivateInputId == id || g.NavJustMovedToId == id) ? (ImGuiInputSource)ImGuiInputSource_Nav : ImGuiInputSource_Mouse;
|
||||
}
|
||||
|
||||
// Clear declaration of inputs claimed by the widget
|
||||
@ -4076,6 +4093,14 @@ static void ImGui::UpdateKeyboardInputs()
|
||||
}
|
||||
#endif
|
||||
|
||||
// Clear gamepad data if disabled
|
||||
if ((io.BackendFlags & ImGuiBackendFlags_HasGamepad) == 0)
|
||||
for (int i = ImGuiKey_Gamepad_BEGIN; i < ImGuiKey_Gamepad_END; i++)
|
||||
{
|
||||
io.KeysData[i - ImGuiKey_KeysData_OFFSET].Down = false;
|
||||
io.KeysData[i - ImGuiKey_KeysData_OFFSET].AnalogValue = 0.0f;
|
||||
}
|
||||
|
||||
// Update keys
|
||||
for (int i = 0; i < IM_ARRAYSIZE(io.KeysData); i++)
|
||||
{
|
||||
@ -4455,7 +4480,7 @@ void ImGui::NewFrame()
|
||||
|
||||
// Process input queue (trickle as many events as possible)
|
||||
g.InputEventsTrail.resize(0);
|
||||
UpdateInputEvents(g.IO.ConfigInputEventQueue);
|
||||
UpdateInputEvents(g.IO.ConfigInputTrickleEventQueue);
|
||||
|
||||
// Update keyboard input state
|
||||
UpdateKeyboardInputs();
|
||||
@ -6246,7 +6271,9 @@ static ImGuiWindow* ImGui::FindBlockingModal(ImGuiWindow* window)
|
||||
for (int i = g.OpenPopupStack.Size - 1; i >= 0; i--)
|
||||
{
|
||||
ImGuiWindow* popup_window = g.OpenPopupStack.Data[i].Window;
|
||||
if (popup_window == NULL || !popup_window->WasActive || !(popup_window->Flags & ImGuiWindowFlags_Modal)) // Check WasActive, because this code may run before popup renders on current frame.
|
||||
if (popup_window == NULL || !(popup_window->Flags & ImGuiWindowFlags_Modal))
|
||||
continue;
|
||||
if (!popup_window->Active && !popup_window->WasActive) // Check WasActive, because this code may run before popup renders on current frame, also check Active to handle newly created windows.
|
||||
continue;
|
||||
if (IsWindowWithinBeginStackOf(window, popup_window)) // Window is rendered over last modal, no render order change needed.
|
||||
break;
|
||||
@ -8036,7 +8063,7 @@ bool ImGui::IsMouseHoveringRect(const ImVec2& r_min, const ImVec2& r_max, bool c
|
||||
return true;
|
||||
}
|
||||
|
||||
const ImGuiKeyData* ImGui::GetKeyData(ImGuiKey key)
|
||||
ImGuiKeyData* ImGui::GetKeyData(ImGuiKey key)
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
int index;
|
||||
@ -8068,22 +8095,27 @@ static const char* const GKeyNames[] =
|
||||
{
|
||||
"Tab", "LeftArrow", "RightArrow", "UpArrow", "DownArrow", "PageUp", "PageDown",
|
||||
"Home", "End", "Insert", "Delete", "Backspace", "Space", "Enter", "Escape",
|
||||
"LeftCtrl", "LeftShift", "LeftAlt", "LeftSuper", "RightCtrl", "RightShift", "RightAlt", "RightSuper", "Menu",
|
||||
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H",
|
||||
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
|
||||
"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12",
|
||||
"Apostrophe", "Comma", "Minus", "Period", "Slash", "Semicolon", "Equal", "LeftBracket",
|
||||
"Backslash", "RightBracket", "GraveAccent", "CapsLock", "ScrollLock", "NumLock", "PrintScreen",
|
||||
"Pause", "Keypad0", "Keypad1", "Keypad2", "Keypad3", "Keypad4", "Keypad5", "Keypad6",
|
||||
"Keypad7", "Keypad8", "Keypad9", "KeypadDecimal", "KeypadDivide", "KeypadMultiply",
|
||||
"KeypadSubtract", "KeypadAdd", "KeypadEnter", "KeypadEqual", "LeftCtrl", "LeftShift",
|
||||
"LeftAlt", "LeftSuper", "RightCtrl", "RightShift", "RightAlt", "RightSuper", "Menu",
|
||||
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F", "G", "H",
|
||||
"I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z",
|
||||
"F1", "F2", "F3", "F4", "F5", "F6", "F7", "F8", "F9", "F10", "F11", "F12"
|
||||
"KeypadSubtract", "KeypadAdd", "KeypadEnter", "KeypadEqual",
|
||||
"GamepadStart", "GamepadBack", "GamepadFaceUp", "GamepadFaceDown", "GamepadFaceLeft", "GamepadFaceRight",
|
||||
"GamepadDpadUp", "GamepadDpadDown", "GamepadDpadLeft", "GamepadDpadRight",
|
||||
"GamepadL1", "GamepadR1", "GamepadL2", "GamepadR2", "GamepadL3", "GamepadR3",
|
||||
"GamepadLStickUp", "GamepadLStickDown", "GamepadLStickLeft", "GamepadLStickRight",
|
||||
"GamepadRStickUp", "GamepadRStickDown", "GamepadRStickLeft", "GamepadRStickRight"
|
||||
};
|
||||
IM_STATIC_ASSERT(ImGuiKey_NamedKey_COUNT == IM_ARRAYSIZE(GKeyNames));
|
||||
|
||||
const char* ImGui::GetKeyName(ImGuiKey key)
|
||||
{
|
||||
#ifdef IMGUI_DISABLE_OBSOLETE_KEYIO
|
||||
IM_ASSERT(IsNamedKey(key) && "Support for user key indices was dropped in favor of ImGuiKey. Please update backend and user code.");
|
||||
IM_ASSERT((IsNamedKey(key) || key == ImGuiKey_None) && "Support for user key indices was dropped in favor of ImGuiKey. Please update backend and user code.");
|
||||
#else
|
||||
if (IsLegacyKey(key))
|
||||
{
|
||||
@ -8376,12 +8408,13 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs)
|
||||
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)
|
||||
if (keydata->Down != e->Key.Down || keydata->AnalogValue != e->Key.AnalogValue)
|
||||
{
|
||||
// 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))
|
||||
if (trickle_fast_inputs && keydata->Down != e->Key.Down && (key_changed_mask.TestBit(keydata_index) || text_inputed || mouse_button_changed != 0))
|
||||
break;
|
||||
keydata->Down = e->Key.Down;
|
||||
keydata->AnalogValue = e->Key.AnalogValue;
|
||||
key_changed = true;
|
||||
key_changed_mask.SetBit(keydata_index);
|
||||
}
|
||||
@ -8425,6 +8458,7 @@ void ImGui::UpdateInputEvents(bool trickle_fast_inputs)
|
||||
}
|
||||
|
||||
// Record trail (for domain-specific applications wanting to access a precise trail)
|
||||
//if (event_n != 0) IMGUI_DEBUG_LOG("Processed: %d / Remaining: %d\n", event_n, g.InputEventsQueue.Size - event_n);
|
||||
for (int n = 0; n < event_n; n++)
|
||||
g.InputEventsTrail.push_back(g.InputEventsQueue[n]);
|
||||
|
||||
@ -10635,18 +10669,35 @@ static void ImGui::NavUpdate()
|
||||
io.WantSetMousePos = false;
|
||||
//if (g.NavScoringDebugCount > 0) IMGUI_DEBUG_LOG("NavScoringDebugCount %d for '%s' layer %d (Init:%d, Move:%d)\n", g.NavScoringDebugCount, g.NavWindow ? g.NavWindow->Name : "NULL", g.NavLayer, g.NavInitRequest || g.NavInitResultId != 0, g.NavMoveRequest);
|
||||
|
||||
// Update Gamepad->Nav inputs mapping
|
||||
// Set input source as Gamepad when buttons are pressed (as some features differs when used with Gamepad vs Keyboard)
|
||||
// (do it before we map Keyboard input!)
|
||||
const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
|
||||
const bool nav_gamepad_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableGamepad) != 0 && (io.BackendFlags & ImGuiBackendFlags_HasGamepad) != 0;
|
||||
if (nav_gamepad_active && g.NavInputSource != ImGuiInputSource_Gamepad)
|
||||
if (nav_gamepad_active && g.IO.BackendUsingLegacyNavInputArray == false)
|
||||
{
|
||||
if (io.NavInputs[ImGuiNavInput_Activate] > 0.0f || io.NavInputs[ImGuiNavInput_Input] > 0.0f || io.NavInputs[ImGuiNavInput_Cancel] > 0.0f || io.NavInputs[ImGuiNavInput_Menu] > 0.0f
|
||||
|| io.NavInputs[ImGuiNavInput_DpadLeft] > 0.0f || io.NavInputs[ImGuiNavInput_DpadRight] > 0.0f || io.NavInputs[ImGuiNavInput_DpadUp] > 0.0f || io.NavInputs[ImGuiNavInput_DpadDown] > 0.0f)
|
||||
g.NavInputSource = ImGuiInputSource_Gamepad;
|
||||
for (int n = 0; n < ImGuiNavInput_COUNT; n++)
|
||||
IM_ASSERT(io.NavInputs[n] == 0.0f && "Backend needs to either only use io.AddKeyEvent()/io.AddKeyAnalogEvent(), either only fill legacy io.NavInputs[]. Not both!");
|
||||
#define NAV_MAP_KEY(_KEY, _NAV_INPUT, _ACTIVATE_NAV) do { io.NavInputs[_NAV_INPUT] = io.KeysData[_KEY - ImGuiKey_KeysData_OFFSET].AnalogValue; if (_ACTIVATE_NAV && io.NavInputs[_NAV_INPUT] > 0.0f) { g.NavInputSource = ImGuiInputSource_Gamepad; } } while (0)
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadFaceDown, ImGuiNavInput_Activate, true);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadFaceRight, ImGuiNavInput_Cancel, true);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadFaceLeft, ImGuiNavInput_Menu, true);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadFaceUp, ImGuiNavInput_Input, true);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadDpadLeft, ImGuiNavInput_DpadLeft, true);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadDpadRight, ImGuiNavInput_DpadRight, true);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadDpadUp, ImGuiNavInput_DpadUp, true);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadDpadDown, ImGuiNavInput_DpadDown, true);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadL1, ImGuiNavInput_FocusPrev, false);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadR1, ImGuiNavInput_FocusNext, false);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadL1, ImGuiNavInput_TweakSlow, false);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadR1, ImGuiNavInput_TweakFast, false);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadLStickLeft, ImGuiNavInput_LStickLeft, false);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadLStickRight, ImGuiNavInput_LStickRight, false);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadLStickUp, ImGuiNavInput_LStickUp, false);
|
||||
NAV_MAP_KEY(ImGuiKey_GamepadLStickDown, ImGuiNavInput_LStickDown, false);
|
||||
#undef NAV_MAP_KEY
|
||||
}
|
||||
|
||||
// Update Keyboard->Nav inputs mapping
|
||||
const bool nav_keyboard_active = (io.ConfigFlags & ImGuiConfigFlags_NavEnableKeyboard) != 0;
|
||||
if (nav_keyboard_active)
|
||||
{
|
||||
#define NAV_MAP_KEY(_KEY, _NAV_INPUT) do { if (IsKeyDown(_KEY)) { io.NavInputs[_NAV_INPUT] = 1.0f; g.NavInputSource = ImGuiInputSource_Keyboard; } } while (0)
|
||||
|
Reference in New Issue
Block a user