Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions examples/core/core_basic_window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
//----------------------------------------------------------------------------------
}

Expand Down
32 changes: 32 additions & 0 deletions include/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down