diff --git a/examples/core/core_basic_window.cpp b/examples/core/core_basic_window.cpp index 68a17090..7df35381 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 02283787..54fe00f7 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -410,6 +410,38 @@ class Window { * @see ::SetConfigFlags */ static void SetConfigFlags(unsigned int flags) { ::SetConfigFlags(flags); } + + /** + * Alternates between calling `BeginDrawing()` and `EndDrawing()`. + * + * @code + * while (window.Drawing()) { + * DrawRectangle(); + * } + * @endcode + * + * @return True if we're within the `BeginDrawing()` scope. + */ + bool Drawing() { + if (m_drawing) { + EndDrawing(); + m_drawing = false; + } + else { + BeginDrawing(); + m_drawing = true; + } + + return m_drawing; + } + + protected: + /** + * Handles the internal drawing state for calling either `BeginDrawing()` or `EndDrawing()` from the `Drawing()` function. + * + * @see Drawing() + */ + bool m_drawing = false; }; } // namespace raylib