From c93e11ee6bce91e7c507f5a5ab8be48d432615fd Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Tue, 31 May 2022 11:34:04 +0300 Subject: [PATCH] Added sprite positions to debug overlay. --- SpaceCadetPinball/DebugOverlay.cpp | 21 +++++++++++++++++++++ SpaceCadetPinball/DebugOverlay.h | 1 + SpaceCadetPinball/options.cpp | 2 ++ SpaceCadetPinball/options.h | 1 + SpaceCadetPinball/winmain.cpp | 2 ++ 5 files changed, 27 insertions(+) diff --git a/SpaceCadetPinball/DebugOverlay.cpp b/SpaceCadetPinball/DebugOverlay.cpp index fda5598..e06a6e4 100644 --- a/SpaceCadetPinball/DebugOverlay.cpp +++ b/SpaceCadetPinball/DebugOverlay.cpp @@ -101,6 +101,10 @@ void DebugOverlay::DrawOverlay() if (options::Options.DebugOverlayGrid) DrawBoxGrid(); + // Draw bounding boxes around sprites + if (options::Options.DebugOverlaySprites) + DrawAllSprites(); + // Draw all edges registered in TCollisionComponent.EdgeList + flippers if (options::Options.DebugOverlayAllEdges) DrawAllEdges(); @@ -204,6 +208,23 @@ void DebugOverlay::DrawBallInfo() } } +void DebugOverlay::DrawAllSprites() +{ + SDL_SetRenderDrawColor(winmain::Renderer, 200, 200, 0, 255); + for (auto cmp : pb::MainTable->ComponentList) + { + if (cmp->RenderSprite) + { + auto& bmpR = cmp->RenderSprite->BmpRect; + if (bmpR.Width != 0 && bmpR.Height != 0) + { + SDL_Rect rect{ bmpR.XPosition, bmpR.YPosition, bmpR.Width, bmpR.Height }; + SDL_RenderDrawRect(winmain::Renderer, &rect); + } + } + } +} + void DebugOverlay::DrawCicleType(circle_type& circle) { vector2 linePt{ circle.Center.X + sqrt(circle.RadiusSq), circle.Center.Y }; diff --git a/SpaceCadetPinball/DebugOverlay.h b/SpaceCadetPinball/DebugOverlay.h index 136b7ce..56672c7 100644 --- a/SpaceCadetPinball/DebugOverlay.h +++ b/SpaceCadetPinball/DebugOverlay.h @@ -19,4 +19,5 @@ private: static void DrawBoxGrid(); static void DrawAllEdges(); static void DrawBallInfo(); + static void DrawAllSprites(); }; \ No newline at end of file diff --git a/SpaceCadetPinball/options.cpp b/SpaceCadetPinball/options.cpp index 0c9b3de..0a75a06 100644 --- a/SpaceCadetPinball/options.cpp +++ b/SpaceCadetPinball/options.cpp @@ -111,6 +111,7 @@ void options::InitPrimary() Options.DebugOverlayBallPosition = get_int("Debug Overlay Ball Position", true); Options.DebugOverlayBallEdges = get_int("Debug Overlay Ball Edges", true); Options.DebugOverlayCollisionMask = get_int("Debug Overlay Collision Mask", true); + Options.DebugOverlaySprites = get_int("Debug Overlay Sprites", true); } void options::InitSecondary() @@ -157,6 +158,7 @@ void options::uninit() set_int("Debug Overlay Ball Position", Options.DebugOverlayBallPosition); set_int("Debug Overlay Ball Edges", Options.DebugOverlayBallEdges); set_int("Debug Overlay Collision Mask", Options.DebugOverlayCollisionMask); + set_int("Debug Overlay Sprites", Options.DebugOverlaySprites); } diff --git a/SpaceCadetPinball/options.h b/SpaceCadetPinball/options.h index b1b581d..2f4eefc 100644 --- a/SpaceCadetPinball/options.h +++ b/SpaceCadetPinball/options.h @@ -88,6 +88,7 @@ struct optionsStruct bool DebugOverlayBallPosition; bool DebugOverlayBallEdges; bool DebugOverlayCollisionMask; + bool DebugOverlaySprites; }; struct ControlRef diff --git a/SpaceCadetPinball/winmain.cpp b/SpaceCadetPinball/winmain.cpp index 71d0a5e..44c0e1c 100644 --- a/SpaceCadetPinball/winmain.cpp +++ b/SpaceCadetPinball/winmain.cpp @@ -600,6 +600,8 @@ void winmain::RenderUi() { if (ImGui::MenuItem("Box Grid", nullptr, Options.DebugOverlayGrid)) Options.DebugOverlayGrid ^= true; + if (ImGui::MenuItem("Sprite Positions", nullptr, Options.DebugOverlaySprites)) + Options.DebugOverlaySprites ^= true; if (ImGui::MenuItem("All Edges", nullptr, Options.DebugOverlayAllEdges)) Options.DebugOverlayAllEdges ^= true; if (ImGui::MenuItem("Ball Position", nullptr, Options.DebugOverlayBallPosition))