Nav: Tweak GetNavInputAmount(). Split debug defines.

This commit is contained in:
omar 2018-01-23 19:41:03 +01:00
parent d500113f1d
commit eb7ec781dc
2 changed files with 19 additions and 13 deletions

View File

@ -645,7 +645,8 @@
#include <stdint.h> // intptr_t #include <stdint.h> // intptr_t
#endif #endif
#define IMGUI_DEBUG_NAV 0 #define IMGUI_DEBUG_NAV_SCORING 0
#define IMGUI_DEBUG_NAV_RECTS 0
#ifdef _MSC_VER #ifdef _MSC_VER
#pragma warning (disable: 4127) // condition expression is constant #pragma warning (disable: 4127) // condition expression is constant
@ -2197,7 +2198,7 @@ static bool NavScoreItem(ImRect cand)
quadrant = (window->DC.LastItemId < g.NavId) ? ImGuiDir_Left : ImGuiDir_Right; quadrant = (window->DC.LastItemId < g.NavId) ? ImGuiDir_Left : ImGuiDir_Right;
} }
#if IMGUI_DEBUG_NAV #if IMGUI_DEBUG_NAV_SCORING
if (ImGui::IsMouseHoveringRect(cand.Min, cand.Max)) if (ImGui::IsMouseHoveringRect(cand.Min, cand.Max))
{ {
char buf[128]; char buf[128];
@ -2257,7 +2258,7 @@ static bool NavScoreItem(ImRect cand)
static inline void NavUpdateAnyRequestFlag() static inline void NavUpdateAnyRequestFlag()
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
g.NavAnyRequest = g.NavMoveRequest || g.NavInitRequest || IMGUI_DEBUG_NAV; g.NavAnyRequest = g.NavMoveRequest || g.NavInitRequest || IMGUI_DEBUG_NAV_SCORING;
} }
static void NavMoveRequestCancel() static void NavMoveRequestCancel()
@ -2294,7 +2295,7 @@ static void ImGui::NavProcessItem(ImGuiWindow* window, const ImRect& nav_bb, con
// Scoring for navigation // Scoring for navigation
if (g.NavId != id && !(item_flags & ImGuiItemFlags_NoNav)) if (g.NavId != id && !(item_flags & ImGuiItemFlags_NoNav))
{ {
#if IMGUI_DEBUG_NAV #if IMGUI_DEBUG_NAV_SCORING
// [DEBUG] Score all items in NavWindow at all times // [DEBUG] Score all items in NavWindow at all times
if (!g.NavMoveRequest) if (!g.NavMoveRequest)
g.NavMoveDir = g.NavMoveDirLast; g.NavMoveDir = g.NavMoveDirLast;
@ -2667,11 +2668,14 @@ static float GetNavInputAmount(ImGuiNavInput n, ImGuiNavReadMode mode)
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
if (mode == ImGuiNavReadMode_Down) if (mode == ImGuiNavReadMode_Down)
return g.IO.NavInputs[n]; // Instant, read analog input (0.0f..1.0f, as provided by user) return g.IO.NavInputs[n]; // Instant, read analog input (0.0f..1.0f, as provided by user)
const float t = g.IO.NavInputsDownDuration[n]; // Duration pressed
if (mode == ImGuiNavReadMode_Pressed) // Return 1.0f when just pressed, no repeat, ignore analog input (we don't need it for Pressed logic) const float t = g.IO.NavInputsDownDuration[n];
if (t < 0.0f && mode == ImGuiNavReadMode_Released) // Return 1.0f when just released, no repeat, ignore analog input.
return (g.IO.NavInputsDownDurationPrev[n] >= 0.0f ? 1.0f : 0.0f);
if (t < 0.0f)
return 0.0f;
if (mode == ImGuiNavReadMode_Pressed) // Return 1.0f when just pressed, no repeat, ignore analog input.
return (t == 0.0f) ? 1.0f : 0.0f; return (t == 0.0f) ? 1.0f : 0.0f;
if (mode == ImGuiNavReadMode_Released) // Return 1.0f when just release, no repeat, ignore analog input (we don't need it for Pressed logic)
return (t < 0.0f && g.IO.NavInputsDownDurationPrev[n] >= 0.0f) ? 1.0f : 0.0f;
if (mode == ImGuiNavReadMode_Repeat) if (mode == ImGuiNavReadMode_Repeat)
return (float)ImGui::CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay * 0.80f, g.IO.KeyRepeatRate * 0.80f); return (float)ImGui::CalcTypematicPressedRepeatAmount(t, t - g.IO.DeltaTime, g.IO.KeyRepeatDelay * 0.80f, g.IO.KeyRepeatRate * 0.80f);
if (mode == ImGuiNavReadMode_RepeatSlow) if (mode == ImGuiNavReadMode_RepeatSlow)
@ -2688,7 +2692,7 @@ static bool IsNavInputDown(ImGuiNavInput n)
} }
// Equivalent of IsKeyPressed() for NavInputs[] // Equivalent of IsKeyPressed() for NavInputs[]
static bool IsNavInputPressed(ImGuiNavInput n, ImGuiNavReadMode mode)// = ImGuiNavReadMode_Re) static bool IsNavInputPressed(ImGuiNavInput n, ImGuiNavReadMode mode)
{ {
return GetNavInputAmount(n, mode) > 0.0f; return GetNavInputAmount(n, mode) > 0.0f;
} }
@ -2708,7 +2712,7 @@ static ImVec2 GetNavInputAmount2d(int stick_no, ImGuiNavReadMode mode, float slo
return delta; return delta;
} }
// Window management mode (change focus, move/resize window, toggle menu layer) // Window management mode (hold to: change focus/move/resize, tap to: toggle menu layer)
static void ImGui::NavUpdateWindowing() static void ImGui::NavUpdateWindowing()
{ {
ImGuiContext& g = *GImGui; ImGuiContext& g = *GImGui;
@ -3057,7 +3061,9 @@ static void ImGui::NavUpdate()
g.NavScoringRectScreen.Min.x = ImMin(g.NavScoringRectScreen.Min.x + 1.0f, g.NavScoringRectScreen.Max.x); g.NavScoringRectScreen.Min.x = ImMin(g.NavScoringRectScreen.Min.x + 1.0f, g.NavScoringRectScreen.Max.x);
g.NavScoringRectScreen.Max.x = g.NavScoringRectScreen.Min.x; g.NavScoringRectScreen.Max.x = g.NavScoringRectScreen.Min.x;
//g.OverlayDrawList.AddRect(g.NavScoringRectScreen.Min, g.NavScoringRectScreen.Max, IM_COL32(255,200,0,255)); // [DEBUG] //g.OverlayDrawList.AddRect(g.NavScoringRectScreen.Min, g.NavScoringRectScreen.Max, IM_COL32(255,200,0,255)); // [DEBUG]
//if (g.NavWindow) for (int layer = 0; layer < 2; layer++) g.OverlayDrawList.AddRect(g.NavWindow->Pos + g.NavWindow->NavRectRel[layer].Min, g.NavWindow->Pos + g.NavWindow->NavRectRel[layer].Max, IM_COL32(255,200,0,255)); // [DEBUG] #if IMGUI_DEBUG_NAV_RECTS
if (g.NavWindow) for (int layer = 0; layer < 2; layer++) g.OverlayDrawList.AddRect(g.NavWindow->Pos + g.NavWindow->NavRectRel[layer].Min, g.NavWindow->Pos + g.NavWindow->NavRectRel[layer].Max, IM_COL32(255,200,0,255)); // [DEBUG]
#endif
} }
void ImGui::NewFrame() void ImGui::NewFrame()

View File

@ -999,7 +999,7 @@ struct ImGuiIO
bool WantCaptureKeyboard; // When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. This is set by ImGui when it wants to use your keyboard inputs. bool WantCaptureKeyboard; // When io.WantCaptureKeyboard is true, do not dispatch keyboard input data to your main application. This is set by ImGui when it wants to use your keyboard inputs.
bool WantTextInput; // Mobile/console: when io.WantTextInput is true, you may display an on-screen keyboard. This is set by ImGui when it wants textual keyboard input to happen (e.g. when a InputText widget is active). bool WantTextInput; // Mobile/console: when io.WantTextInput is true, you may display an on-screen keyboard. This is set by ImGui when it wants textual keyboard input to happen (e.g. when a InputText widget is active).
bool WantMoveMouse; // MousePos has been altered, back-end should reposition mouse on next frame. Set only when 'NavMovesMouse=true'. bool WantMoveMouse; // MousePos has been altered, back-end should reposition mouse on next frame. Set only when 'NavMovesMouse=true'.
bool NavUsable; // Directional navigation is currently allowed (will handle ImGuiKey_NavXXX events). bool NavUsable; // Directional navigation is currently allowed (will handle ImGuiKey_NavXXX events) ~ a window is focused and it doesn't use the ImGuiWindowFlags_NoNavInputs flag.
bool NavActive; // Directional navigation is active/visible and currently allowed (will handle ImGuiKey_NavXXX events). bool NavActive; // Directional navigation is active/visible and currently allowed (will handle ImGuiKey_NavXXX events).
float Framerate; // Application framerate estimation, in frame per second. Solely for convenience. Rolling average estimation based on IO.DeltaTime over 120 frames float Framerate; // Application framerate estimation, in frame per second. Solely for convenience. Rolling average estimation based on IO.DeltaTime over 120 frames
int MetricsAllocs; // Number of active memory allocations int MetricsAllocs; // Number of active memory allocations