#include "DebugOverlay.h" #include #include #include "../Version.h" DebugOverlay::DebugOverlay() { SetPadding(UI::Thickness(0.0f)); SetMargin(UI::Thickness(0.0f)); SetHorizontalAlignment(UI::HorizontalAlignment::Center); SetVerticalAlignment(UI::VerticalAlignment::Top); std::string systemText = VERSION_STRING; fpsText = std::make_unique(0.0, 0.0, fps); fpsText->SetColor(1.0, 1.0, 1.0, 1.0); } void DebugOverlay::SetFps(double value) { const std::string newFps = std::to_string(static_cast(std::lround(value))); if (fps == newFps) { return; } fps = newFps; fpsText->SetText(fps); MarkDirty(UI::DirtyFlags::Layout | UI::DirtyFlags::Render); } void DebugOverlay::Measure(UI::Size /*availableSpace*/) { const UI::Size textSize = Text::Measure(fps); desiredSize = textSize; } void DebugOverlay::RefreshPrimitives() { const UI::Size textSize = Text::Measure(fps); fpsText->SetPosition(globalBounds.X, globalBounds.Y); marker = std::make_unique(globalBounds.X, globalBounds.Y, textSize.width, textSize.height); marker->SetColor(0.21, 0.21, 0.21, 1.0); } void DebugOverlay::Arrange(UI::Rect finalBounds) { const UI::Rect oldBounds = globalBounds; const bool refresh = IsDirty(UI::DirtyFlags::Layout | UI::DirtyFlags::Render); ArrangeCore(finalBounds); if (refresh || globalBounds != oldBounds) { RefreshPrimitives(); } ClearDirty(UI::DirtyFlags::Layout); } void DebugOverlay::Draw() { if (!visible) { return; } if (!marker || IsDirty(UI::DirtyFlags::Layout)) { RefreshPrimitives(); } marker->Render(); fpsText->Render(); ClearDirty(UI::DirtyFlags::Render); }