summaryrefslogtreecommitdiffhomepage
path: root/examples/core
diff options
context:
space:
mode:
authorRay <[email protected]>2022-07-07 11:07:41 +0200
committerRay <[email protected]>2022-07-07 11:07:41 +0200
commit9e97a2c4a1852f11335f4c2104093fe654d32c0c (patch)
treec16eeb2d3bb308901dd4f5368be96c968ccb5c89 /examples/core
parent8f65cb1d94aed703845a99b61da5321702048ac5 (diff)
downloadraylib-9e97a2c4a1852f11335f4c2104093fe654d32c0c.tar.gz
raylib-9e97a2c4a1852f11335f4c2104093fe654d32c0c.zip
ADDED: example: `core_window_should_close`
Diffstat (limited to 'examples/core')
-rw-r--r--examples/core/core_window_should_close.c75
-rw-r--r--examples/core/core_window_should_close.pngbin0 -> 15199 bytes
2 files changed, 75 insertions, 0 deletions
diff --git a/examples/core/core_window_should_close.c b/examples/core/core_window_should_close.c
new file mode 100644
index 00000000..3bf902d6
--- /dev/null
+++ b/examples/core/core_window_should_close.c
@@ -0,0 +1,75 @@
+/*******************************************************************************************
+*
+* raylib [core] example - Window should close
+*
+* This example has been created using raylib 1.0 (www.raylib.com)
+* raylib is licensed under an unmodified zlib/libpng license (View raylib.h for details)
+*
+* Copyright (c) 2013-2016 Ramon Santamaria (@raysan5)
+*
+********************************************************************************************/
+
+#include "raylib.h"
+
+//------------------------------------------------------------------------------------
+// Program main entry point
+//------------------------------------------------------------------------------------
+int main()
+{
+ // Initialization
+ //--------------------------------------------------------------------------------------
+ const int screenWidth = 800;
+ const int screenHeight = 450;
+
+ InitWindow(screenWidth, screenHeight, "raylib [core] example - window should close");
+
+ SetExitKey(KEY_NULL); // Disable KEY_ESCAPE to close window, X-button still works
+
+ bool exitWindowRequested = false; // Flag to request window to exit
+ bool exitWindow = false; // Flag to set window to exit
+
+ SetTargetFPS(60); // Set our game to run at 60 frames-per-second
+ //--------------------------------------------------------------------------------------
+
+ // Main game loop
+ while (!exitWindow)
+ {
+ // Update
+ //----------------------------------------------------------------------------------
+ // Detect if X-button or KEY_ESCAPE have been presssed to close window
+ if (WindowShouldClose() || IsKeyPressed(KEY_ESCAPE)) exitWindowRequested = true;
+
+ if (exitWindowRequested)
+ {
+ // A request for close window has been issued, we can save data before closing
+ // or just show a message asking for confirmation
+
+ if (IsKeyPressed(KEY_Y)) exitWindow = true;
+ else if (IsKeyPressed(KEY_N)) exitWindowRequested = false;
+ }
+ //----------------------------------------------------------------------------------
+
+ // Draw
+ //----------------------------------------------------------------------------------
+ BeginDrawing();
+
+ ClearBackground(RAYWHITE);
+
+ if (exitWindowRequested)
+ {
+ DrawRectangle(0, 100, screenWidth, 200, BLACK);
+ DrawText("Are you sure you want to exit program? [Y/N]", 40, 180, 30, WHITE);
+ }
+ else DrawText("Try to close the window to get confirmation message!", 120, 200, 20, LIGHTGRAY);
+
+ EndDrawing();
+ //----------------------------------------------------------------------------------
+ }
+
+ // De-Initialization
+ //--------------------------------------------------------------------------------------
+ CloseWindow(); // Close window and OpenGL context
+ //--------------------------------------------------------------------------------------
+
+ return 0;
+} \ No newline at end of file
diff --git a/examples/core/core_window_should_close.png b/examples/core/core_window_should_close.png
new file mode 100644
index 00000000..4ef088ac
--- /dev/null
+++ b/examples/core/core_window_should_close.png
Binary files differ