From 7a3d330674c2e4e8e5810c94d63846a74cfc2684 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 19 Mar 2025 14:10:37 -0400 Subject: [PATCH 1/3] 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 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..ef3d63b0 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -410,6 +410,32 @@ class Window { * @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 From 9bb0d6ffec5825cc75438da43220c50225250d93 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Wed, 19 Mar 2025 14:12:42 -0400 Subject: [PATCH 2/3] draawing: flip the statement --- include/Window.hpp | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/include/Window.hpp b/include/Window.hpp index ef3d63b0..84271068 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -423,14 +423,15 @@ class Window { * @return True of false depending if we're within the BeginDrawing() / EndDrawing() scope. */ bool Drawing() { - if (m_drawing == false) { - BeginDrawing(); - m_drawing = true; - } - else { + if (m_drawing) { EndDrawing(); m_drawing = false; } + else { + BeginDrawing(); + m_drawing = true; + } + return m_drawing; } From db8c70bf3a2aa17508a5afcd2f1aeb37e6416568 Mon Sep 17 00:00:00 2001 From: Rob Loach Date: Thu, 20 Mar 2025 13:44:31 -0400 Subject: [PATCH 3/3] Update Drawing() documentation --- include/Window.hpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/Window.hpp b/include/Window.hpp index 84271068..54fe00f7 100644 --- a/include/Window.hpp +++ b/include/Window.hpp @@ -412,7 +412,7 @@ class Window { static void SetConfigFlags(unsigned int flags) { ::SetConfigFlags(flags); } /** - * Used to handle the BeginDrawing() and EndDrawing() calls. + * Alternates between calling `BeginDrawing()` and `EndDrawing()`. * * @code * while (window.Drawing()) { @@ -420,7 +420,7 @@ class Window { * } * @endcode * - * @return True of false depending if we're within the BeginDrawing() / EndDrawing() scope. + * @return True if we're within the `BeginDrawing()` scope. */ bool Drawing() { if (m_drawing) { @@ -436,6 +436,11 @@ class Window { } protected: + /** + * Handles the internal drawing state for calling either `BeginDrawing()` or `EndDrawing()` from the `Drawing()` function. + * + * @see Drawing() + */ bool m_drawing = false; }; } // namespace raylib