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