From 7a3d330674c2e4e8e5810c94d63846a74cfc2684 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 19 Mar 2025 14:10:37 -0400 Subject: [PATCH] Add window::Drawing() --- examples/core/core_basic_window.cpp | 4 +--- include/Window.hpp | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 3 deletions(-) diff --git a/examples/core/core_basic_window.cpp b/examples/core/core_basic_window.cpp index 68a1709..7df3538 100644 --- a/examples/core/core_basic_window.cpp +++ b/examples/core/core_basic_window.cpp @@ -41,12 +41,10 @@ int main() { // Draw //---------------------------------------------------------------------------------- - BeginDrawing(); - { + while (window.Drawing()) { window.ClearBackground(RAYWHITE); textColor.DrawText("Congrats! You created your first window!", 190, 200, 20); } - EndDrawing(); //---------------------------------------------------------------------------------- } diff --git a/include/Window.hpp b/include/Window.hpp index 0228378..ef3d63b 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -410,6 +410,32 @@ public: * @see ::SetConfigFlags */ static void SetConfigFlags(unsigned int flags) { ::SetConfigFlags(flags); } + + /** + * Used to handle the BeginDrawing() and EndDrawing() calls. + * + * @code + * while (window.Drawing()) { + * DrawRectangle(); + * } + * @endcode + * + * @return True of false depending if we're within the BeginDrawing() / EndDrawing() scope. + */ + bool Drawing() { + if (m_drawing == false) { + BeginDrawing(); + m_drawing = true; + } + else { + EndDrawing(); + m_drawing = false; + } + return m_drawing; + } + + protected: + bool m_drawing = false; }; } // namespace raylib