Something went wrong. Try again.
art software for the rest of us
drawing paint image sdl art
Something went wrong. Try again.
C++
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859#include "DebugOverlay.h"#include <cmath>#include <string>#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<Text>(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<int>(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<Rectangle>(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);}