mirror of
https://github.com/Drezil/imgui.git
synced 2025-07-06 04:58:47 +02:00
Added ImGuiKey_MouseXXX aliases. (#4921) Reworked SetItemUsingMouseWheel() to use this for ActiveId. (#2891)
The rework of SetItemUsingMouseWheel() is half-complete since there's a HoveredIdUsingMouseWheel component. This will however be totally cleaned when we transtion to InputOwner system.
This commit is contained in:
37
imgui.cpp
37
imgui.cpp
@ -1278,6 +1278,7 @@ void ImGuiIO::AddKeyAnalogEvent(ImGuiKey key, bool down, float analog_value)
|
||||
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.
|
||||
IM_ASSERT(!ImGui::IsAliasKey(key)); // Backend cannot submit ImGuiKey_MouseXXX values they are automatically inferred from AddMouseXXX() events.
|
||||
|
||||
// Verify that backend isn't mixing up using new io.AddKeyEvent() api and old io.KeysDown[] + io.KeyMap[] data.
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
|
||||
@ -3423,7 +3424,6 @@ void ImGui::SetActiveID(ImGuiID id, ImGuiWindow* window)
|
||||
|
||||
// Clear declaration of inputs claimed by the widget
|
||||
// (Please note that this is WIP and not all keys/inputs are thoroughly declared by all widgets yet)
|
||||
g.ActiveIdUsingMouseWheel = false;
|
||||
g.ActiveIdUsingNavDirMask = 0x00;
|
||||
g.ActiveIdUsingKeyInputMask.ClearAllBits();
|
||||
#ifndef IMGUI_DISABLE_OBSOLETE_KEYIO
|
||||
@ -3961,6 +3961,14 @@ static bool IsWindowActiveAndVisible(ImGuiWindow* window)
|
||||
return (window->Active) && (!window->Hidden);
|
||||
}
|
||||
|
||||
static void UpdateAliasKey(ImGuiKey key, bool v, float analog_value)
|
||||
{
|
||||
IM_ASSERT(ImGui::IsAliasKey(key));
|
||||
ImGuiKeyData* key_data = ImGui::GetKeyData(key);
|
||||
key_data->Down = v;
|
||||
key_data->AnalogValue = analog_value;
|
||||
}
|
||||
|
||||
static void ImGui::UpdateKeyboardInputs()
|
||||
{
|
||||
ImGuiContext& g = *GImGui;
|
||||
@ -4034,8 +4042,12 @@ static void ImGui::UpdateKeyboardInputs()
|
||||
|
||||
#endif
|
||||
|
||||
// Synchronize io.KeyMods with individual modifiers io.KeyXXX bools
|
||||
// Synchronize io.KeyMods with individual modifiers io.KeyXXX bools, update aliases
|
||||
io.KeyMods = GetMergedModFlags();
|
||||
for (int n = 0; n < ImGuiMouseButton_COUNT; n++)
|
||||
UpdateAliasKey(MouseButtonToKey(n), io.MouseDown[n], io.MouseDown[n] ? 1.0f : 0.0f);
|
||||
UpdateAliasKey(ImGuiKey_MouseWheelX, io.MouseWheelH != 0.0f, io.MouseWheelH);
|
||||
UpdateAliasKey(ImGuiKey_MouseWheelY, io.MouseWheel != 0.0f, io.MouseWheel);
|
||||
|
||||
// Clear gamepad data if disabled
|
||||
if ((io.BackendFlags & ImGuiBackendFlags_HasGamepad) == 0)
|
||||
@ -4142,12 +4154,13 @@ void ImGui::UpdateMouseWheel()
|
||||
}
|
||||
}
|
||||
|
||||
float wheel_x = g.IO.MouseWheelH;
|
||||
float wheel_y = g.IO.MouseWheel;
|
||||
if (wheel_x == 0.0f && wheel_y == 0.0f)
|
||||
return;
|
||||
const bool hovered_id_using_mouse_wheel = (g.HoveredIdPreviousFrame != 0 && g.HoveredIdPreviousFrameUsingMouseWheel);
|
||||
const bool active_id_using_mouse_wheel_x = g.ActiveIdUsingKeyInputMask.TestBit(ImGuiKey_MouseWheelX);
|
||||
const bool active_id_using_mouse_wheel_y = g.ActiveIdUsingKeyInputMask.TestBit(ImGuiKey_MouseWheelY);
|
||||
|
||||
if ((g.ActiveId != 0 && g.ActiveIdUsingMouseWheel) || (g.HoveredIdPreviousFrame != 0 && g.HoveredIdPreviousFrameUsingMouseWheel))
|
||||
float wheel_x = (!hovered_id_using_mouse_wheel && !active_id_using_mouse_wheel_x) ? g.IO.MouseWheelH : 0.0f;
|
||||
float wheel_y = (!hovered_id_using_mouse_wheel && !active_id_using_mouse_wheel_y) ? g.IO.MouseWheel : 0;
|
||||
if (wheel_x == 0.0f && wheel_y == 0.0f)
|
||||
return;
|
||||
|
||||
ImGuiWindow* window = g.WheelingWindow ? g.WheelingWindow : g.HoveredWindow;
|
||||
@ -5206,7 +5219,10 @@ void ImGui::SetItemUsingMouseWheel()
|
||||
if (g.HoveredId == id)
|
||||
g.HoveredIdUsingMouseWheel = true;
|
||||
if (g.ActiveId == id)
|
||||
g.ActiveIdUsingMouseWheel = true;
|
||||
{
|
||||
g.ActiveIdUsingKeyInputMask.SetBit(ImGuiKey_MouseWheelX);
|
||||
g.ActiveIdUsingKeyInputMask.SetBit(ImGuiKey_MouseWheelY);
|
||||
}
|
||||
}
|
||||
|
||||
void ImGui::SetActiveIdUsingNavAndKeys()
|
||||
@ -7662,7 +7678,8 @@ static const char* const GKeyNames[] =
|
||||
"GamepadL1", "GamepadR1", "GamepadL2", "GamepadR2", "GamepadL3", "GamepadR3",
|
||||
"GamepadLStickLeft", "GamepadLStickRight", "GamepadLStickUp", "GamepadLStickDown",
|
||||
"GamepadRStickLeft", "GamepadRStickRight", "GamepadRStickUp", "GamepadRStickDown",
|
||||
"ModCtrl", "ModShift", "ModAlt", "ModSuper"
|
||||
"ModCtrl", "ModShift", "ModAlt", "ModSuper",
|
||||
"MouseLeft", "MouseRight", "MouseMiddle", "MouseX1", "MouseX2", "MouseWheelX", "MouseWheelY",
|
||||
};
|
||||
IM_STATIC_ASSERT(ImGuiKey_NamedKey_COUNT == IM_ARRAYSIZE(GKeyNames));
|
||||
|
||||
@ -12691,7 +12708,7 @@ void ImGui::ShowMetricsWindow(bool* p_open)
|
||||
int active_id_using_key_input_count = 0;
|
||||
for (int n = ImGuiKey_NamedKey_BEGIN; n < ImGuiKey_NamedKey_END; n++)
|
||||
active_id_using_key_input_count += g.ActiveIdUsingKeyInputMask[n] ? 1 : 0;
|
||||
Text("ActiveIdUsing: Wheel: %d, NavDirMask: %X, KeyInputMask: %d key(s)", g.ActiveIdUsingMouseWheel, g.ActiveIdUsingNavDirMask, active_id_using_key_input_count);
|
||||
Text("ActiveIdUsing: NavDirMask: %X, KeyInputMask: %d key(s)", g.ActiveIdUsingNavDirMask, active_id_using_key_input_count);
|
||||
Text("HoveredId: 0x%08X (%.2f sec), AllowOverlap: %d", g.HoveredIdPreviousFrame, g.HoveredIdTimer, g.HoveredIdAllowOverlap); // Not displaying g.HoveredId as it is update mid-frame
|
||||
Text("DragDrop: %d, SourceId = 0x%08X, Payload \"%s\" (%d bytes)", g.DragDropActive, g.DragDropPayload.SourceId, g.DragDropPayload.DataType, g.DragDropPayload.DataSize);
|
||||
Unindent();
|
||||
|
Reference in New Issue
Block a user