From 38559a800065d8159fdfce3563a310578e78dff8 Mon Sep 17 00:00:00 2001 From: Rokas Kupstys Date: Fri, 16 Jun 2017 19:08:13 +0300 Subject: [PATCH] Auto-calculate metrics window size in DebugHud --- Source/Atomic/UI/SystemUI/DebugHud.cpp | 80 ++++++++++++++------------ Source/Atomic/UI/SystemUI/DebugHud.h | 2 + 2 files changed, 44 insertions(+), 38 deletions(-) diff --git a/Source/Atomic/UI/SystemUI/DebugHud.cpp b/Source/Atomic/UI/SystemUI/DebugHud.cpp index 953a134df7..0291cfd729 100644 --- a/Source/Atomic/UI/SystemUI/DebugHud.cpp +++ b/Source/Atomic/UI/SystemUI/DebugHud.cpp @@ -100,28 +100,9 @@ void DebugHud::ResetExtents() void DebugHud::RecalculateWindowPositions() { - auto withinExtents = [&](IntVector2 pos) -> IntVector2 - { - if (pos.x_ < 0) - pos.x_ += extents_.right_; - else if (pos.x_ > 0) - pos.x_ += extents_.left_; - else - pos.x_ = extents_.left_; - - if (pos.y_ < 0) - pos.y_ += extents_.bottom_; - else if (pos.y_ > 0) - pos.y_ += extents_.top_; - else - pos.y_ = extents_.top_; - - return pos; - }; - - posMode_ = withinExtents({0, -30}); - posStats_ = withinExtents({0, 0}); - posProfiler_ = withinExtents({-530, 0}); + posMode_ = WithinExtents({0, -30}); + posStats_ = WithinExtents({0, 0}); + posProfiler_ = WithinExtents({-530, 0}); } void DebugHud::SetProfilerMode(DebugHudProfileMode mode) @@ -210,6 +191,25 @@ void DebugHud::ClearAppStats() appStats_.Clear(); } +IntVector2 DebugHud::WithinExtents(IntVector2 pos) +{ + if (pos.x_ < 0) + pos.x_ += extents_.right_; + else if (pos.x_ > 0) + pos.x_ += extents_.left_; + else + pos.x_ = extents_.left_; + + if (pos.y_ < 0) + pos.y_ += extents_.bottom_; + else if (pos.y_ > 0) + pos.y_ += extents_.top_; + else + pos.y_ = extents_.top_; + + return pos; +}; + void DebugHud::RenderUi(StringHash eventType, VariantMap& eventData) { Renderer* renderer = GetSubsystem(); @@ -292,11 +292,12 @@ void DebugHud::RenderUi(StringHash eventType, VariantMap& eventData) if (mode_ & DEBUGHUD_SHOW_PROFILER) { ImGui::SetNextWindowPos(ImVec2(posProfiler_.x_, posProfiler_.y_)); - if (ImGui::Begin("DebugHud Metrics", 0, ImVec2(530, 1080), 0, backgroundTextWindowFlags)) + ImGui::SetNextWindowSize(ImVec2(sizeProfiler_.x_, sizeProfiler_.y_)); + if (ImGui::Begin("DebugHud Metrics", 0, ImVec2(0, 0), 0, backgroundTextWindowFlags)) { - if (profilerMode_ == DEBUG_HUD_PROFILE_PERFORMANCE) + if (profilerTimer_.GetMSec(false) >= profilerInterval_) { - if (profilerTimer_.GetMSec(false) >= profilerInterval_) + if (profilerMode_ == DEBUG_HUD_PROFILE_PERFORMANCE) { profilerTimer_.Reset(); Profiler* profiler = GetSubsystem(); @@ -306,25 +307,28 @@ void DebugHud::RenderUi(StringHash eventType, VariantMap& eventData) profiler->BeginInterval(); } } - ImGui::Text(profilerOutput_.CString()); - } - else - { - Metrics* metrics = GetSubsystem(); - if (metrics) + else { - if (metrics->GetEnabled()) + Metrics* metrics = GetSubsystem(); + if (metrics) { - metricsSnapshot_.Clear(); - metrics->Capture(&metricsSnapshot_); - ImGui::Text(metricsSnapshot_.PrintData(2).CString()); + if (metrics->GetEnabled()) + { + metricsSnapshot_.Clear(); + metrics->Capture(&metricsSnapshot_); + profilerOutput_ = metricsSnapshot_.PrintData(2); + } + else + profilerOutput_ = "Metrics system not enabled"; } else - ImGui::Text("Metrics system not enabled"); + profilerOutput_ = "Metrics subsystem not found"; } - else - ImGui::Text("Metrics subsystem not found"); + auto size = ImGui::CalcTextSize(profilerOutput_.CString()); + sizeProfiler_ = IntVector2(size.x + 20, size.y + 20); + posProfiler_ = WithinExtents({-(size.x + 20), 0}); } + ImGui::Text(profilerOutput_.CString()); } ImGui::End(); } diff --git a/Source/Atomic/UI/SystemUI/DebugHud.h b/Source/Atomic/UI/SystemUI/DebugHud.h index fa8951b9b7..98f0ce8c9c 100644 --- a/Source/Atomic/UI/SystemUI/DebugHud.h +++ b/Source/Atomic/UI/SystemUI/DebugHud.h @@ -97,6 +97,7 @@ class ATOMIC_API DebugHud : public Object /// Render system ui. void RenderUi(StringHash eventType, VariantMap& eventData); void RecalculateWindowPositions(); + IntVector2 WithinExtents(IntVector2 pos); /// Hashmap containing application specific stats. HashMap appStats_; @@ -127,6 +128,7 @@ class ATOMIC_API DebugHud : public Object IntVector2 posMode_; IntVector2 posStats_; IntVector2 posProfiler_; + IntVector2 sizeProfiler_; }; }