You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

196 lines
8.2 KiB

  1. /*******************************************************************************************
  2. *
  3. * raylib [core] example - window flags
  4. *
  5. * Example originally created with raylib 3.5, last time updated with raylib 3.5
  6. *
  7. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  8. * BSD-like license that allows static linking with closed source software
  9. *
  10. * Copyright (c) 2020-2024 Ramon Santamaria (@raysan5)
  11. *
  12. ********************************************************************************************/
  13. #include "raylib.h"
  14. //------------------------------------------------------------------------------------
  15. // Program main entry point
  16. //------------------------------------------------------------------------------------
  17. int main(void)
  18. {
  19. // Initialization
  20. //---------------------------------------------------------
  21. const int screenWidth = 800;
  22. const int screenHeight = 450;
  23. // Possible window flags
  24. /*
  25. FLAG_VSYNC_HINT
  26. FLAG_FULLSCREEN_MODE -> not working properly -> wrong scaling!
  27. FLAG_WINDOW_RESIZABLE
  28. FLAG_WINDOW_UNDECORATED
  29. FLAG_WINDOW_TRANSPARENT
  30. FLAG_WINDOW_HIDDEN
  31. FLAG_WINDOW_MINIMIZED -> Not supported on window creation
  32. FLAG_WINDOW_MAXIMIZED -> Not supported on window creation
  33. FLAG_WINDOW_UNFOCUSED
  34. FLAG_WINDOW_TOPMOST
  35. FLAG_WINDOW_HIGHDPI -> errors after minimize-resize, fb size is recalculated
  36. FLAG_WINDOW_ALWAYS_RUN
  37. FLAG_MSAA_4X_HINT
  38. */
  39. // Set configuration flags for window creation
  40. //SetConfigFlags(FLAG_VSYNC_HINT | FLAG_MSAA_4X_HINT | FLAG_WINDOW_HIGHDPI);
  41. InitWindow(screenWidth, screenHeight, "raylib [core] example - window flags");
  42. Vector2 ballPosition = { GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f };
  43. Vector2 ballSpeed = { 5.0f, 4.0f };
  44. float ballRadius = 20;
  45. int framesCounter = 0;
  46. //SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  47. //----------------------------------------------------------
  48. // Main game loop
  49. while (!WindowShouldClose()) // Detect window close button or ESC key
  50. {
  51. // Update
  52. //-----------------------------------------------------
  53. if (IsKeyPressed(KEY_F)) ToggleFullscreen(); // modifies window size when scaling!
  54. if (IsKeyPressed(KEY_R))
  55. {
  56. if (IsWindowState(FLAG_WINDOW_RESIZABLE)) ClearWindowState(FLAG_WINDOW_RESIZABLE);
  57. else SetWindowState(FLAG_WINDOW_RESIZABLE);
  58. }
  59. if (IsKeyPressed(KEY_D))
  60. {
  61. if (IsWindowState(FLAG_WINDOW_UNDECORATED)) ClearWindowState(FLAG_WINDOW_UNDECORATED);
  62. else SetWindowState(FLAG_WINDOW_UNDECORATED);
  63. }
  64. if (IsKeyPressed(KEY_H))
  65. {
  66. if (!IsWindowState(FLAG_WINDOW_HIDDEN)) SetWindowState(FLAG_WINDOW_HIDDEN);
  67. framesCounter = 0;
  68. }
  69. if (IsWindowState(FLAG_WINDOW_HIDDEN))
  70. {
  71. framesCounter++;
  72. if (framesCounter >= 240) ClearWindowState(FLAG_WINDOW_HIDDEN); // Show window after 3 seconds
  73. }
  74. if (IsKeyPressed(KEY_N))
  75. {
  76. if (!IsWindowState(FLAG_WINDOW_MINIMIZED)) MinimizeWindow();
  77. framesCounter = 0;
  78. }
  79. if (IsWindowState(FLAG_WINDOW_MINIMIZED))
  80. {
  81. framesCounter++;
  82. if (framesCounter >= 240) RestoreWindow(); // Restore window after 3 seconds
  83. }
  84. if (IsKeyPressed(KEY_M))
  85. {
  86. // NOTE: Requires FLAG_WINDOW_RESIZABLE enabled!
  87. if (IsWindowState(FLAG_WINDOW_MAXIMIZED)) RestoreWindow();
  88. else MaximizeWindow();
  89. }
  90. if (IsKeyPressed(KEY_U))
  91. {
  92. if (IsWindowState(FLAG_WINDOW_UNFOCUSED)) ClearWindowState(FLAG_WINDOW_UNFOCUSED);
  93. else SetWindowState(FLAG_WINDOW_UNFOCUSED);
  94. }
  95. if (IsKeyPressed(KEY_T))
  96. {
  97. if (IsWindowState(FLAG_WINDOW_TOPMOST)) ClearWindowState(FLAG_WINDOW_TOPMOST);
  98. else SetWindowState(FLAG_WINDOW_TOPMOST);
  99. }
  100. if (IsKeyPressed(KEY_A))
  101. {
  102. if (IsWindowState(FLAG_WINDOW_ALWAYS_RUN)) ClearWindowState(FLAG_WINDOW_ALWAYS_RUN);
  103. else SetWindowState(FLAG_WINDOW_ALWAYS_RUN);
  104. }
  105. if (IsKeyPressed(KEY_V))
  106. {
  107. if (IsWindowState(FLAG_VSYNC_HINT)) ClearWindowState(FLAG_VSYNC_HINT);
  108. else SetWindowState(FLAG_VSYNC_HINT);
  109. }
  110. // Bouncing ball logic
  111. ballPosition.x += ballSpeed.x;
  112. ballPosition.y += ballSpeed.y;
  113. if ((ballPosition.x >= (GetScreenWidth() - ballRadius)) || (ballPosition.x <= ballRadius)) ballSpeed.x *= -1.0f;
  114. if ((ballPosition.y >= (GetScreenHeight() - ballRadius)) || (ballPosition.y <= ballRadius)) ballSpeed.y *= -1.0f;
  115. //-----------------------------------------------------
  116. // Draw
  117. //-----------------------------------------------------
  118. BeginDrawing();
  119. if (IsWindowState(FLAG_WINDOW_TRANSPARENT)) ClearBackground(BLANK);
  120. else ClearBackground(RAYWHITE);
  121. DrawCircleV(ballPosition, ballRadius, MAROON);
  122. DrawRectangleLinesEx((Rectangle) { 0, 0, (float)GetScreenWidth(), (float)GetScreenHeight() }, 4, RAYWHITE);
  123. DrawCircleV(GetMousePosition(), 10, DARKBLUE);
  124. DrawFPS(10, 10);
  125. DrawText(TextFormat("Screen Size: [%i, %i]", GetScreenWidth(), GetScreenHeight()), 10, 40, 10, GREEN);
  126. // Draw window state info
  127. DrawText("Following flags can be set after window creation:", 10, 60, 10, GRAY);
  128. if (IsWindowState(FLAG_FULLSCREEN_MODE)) DrawText("[F] FLAG_FULLSCREEN_MODE: on", 10, 80, 10, LIME);
  129. else DrawText("[F] FLAG_FULLSCREEN_MODE: off", 10, 80, 10, MAROON);
  130. if (IsWindowState(FLAG_WINDOW_RESIZABLE)) DrawText("[R] FLAG_WINDOW_RESIZABLE: on", 10, 100, 10, LIME);
  131. else DrawText("[R] FLAG_WINDOW_RESIZABLE: off", 10, 100, 10, MAROON);
  132. if (IsWindowState(FLAG_WINDOW_UNDECORATED)) DrawText("[D] FLAG_WINDOW_UNDECORATED: on", 10, 120, 10, LIME);
  133. else DrawText("[D] FLAG_WINDOW_UNDECORATED: off", 10, 120, 10, MAROON);
  134. if (IsWindowState(FLAG_WINDOW_HIDDEN)) DrawText("[H] FLAG_WINDOW_HIDDEN: on", 10, 140, 10, LIME);
  135. else DrawText("[H] FLAG_WINDOW_HIDDEN: off", 10, 140, 10, MAROON);
  136. if (IsWindowState(FLAG_WINDOW_MINIMIZED)) DrawText("[N] FLAG_WINDOW_MINIMIZED: on", 10, 160, 10, LIME);
  137. else DrawText("[N] FLAG_WINDOW_MINIMIZED: off", 10, 160, 10, MAROON);
  138. if (IsWindowState(FLAG_WINDOW_MAXIMIZED)) DrawText("[M] FLAG_WINDOW_MAXIMIZED: on", 10, 180, 10, LIME);
  139. else DrawText("[M] FLAG_WINDOW_MAXIMIZED: off", 10, 180, 10, MAROON);
  140. if (IsWindowState(FLAG_WINDOW_UNFOCUSED)) DrawText("[G] FLAG_WINDOW_UNFOCUSED: on", 10, 200, 10, LIME);
  141. else DrawText("[U] FLAG_WINDOW_UNFOCUSED: off", 10, 200, 10, MAROON);
  142. if (IsWindowState(FLAG_WINDOW_TOPMOST)) DrawText("[T] FLAG_WINDOW_TOPMOST: on", 10, 220, 10, LIME);
  143. else DrawText("[T] FLAG_WINDOW_TOPMOST: off", 10, 220, 10, MAROON);
  144. if (IsWindowState(FLAG_WINDOW_ALWAYS_RUN)) DrawText("[A] FLAG_WINDOW_ALWAYS_RUN: on", 10, 240, 10, LIME);
  145. else DrawText("[A] FLAG_WINDOW_ALWAYS_RUN: off", 10, 240, 10, MAROON);
  146. if (IsWindowState(FLAG_VSYNC_HINT)) DrawText("[V] FLAG_VSYNC_HINT: on", 10, 260, 10, LIME);
  147. else DrawText("[V] FLAG_VSYNC_HINT: off", 10, 260, 10, MAROON);
  148. DrawText("Following flags can only be set before window creation:", 10, 300, 10, GRAY);
  149. if (IsWindowState(FLAG_WINDOW_HIGHDPI)) DrawText("FLAG_WINDOW_HIGHDPI: on", 10, 320, 10, LIME);
  150. else DrawText("FLAG_WINDOW_HIGHDPI: off", 10, 320, 10, MAROON);
  151. if (IsWindowState(FLAG_WINDOW_TRANSPARENT)) DrawText("FLAG_WINDOW_TRANSPARENT: on", 10, 340, 10, LIME);
  152. else DrawText("FLAG_WINDOW_TRANSPARENT: off", 10, 340, 10, MAROON);
  153. if (IsWindowState(FLAG_MSAA_4X_HINT)) DrawText("FLAG_MSAA_4X_HINT: on", 10, 360, 10, LIME);
  154. else DrawText("FLAG_MSAA_4X_HINT: off", 10, 360, 10, MAROON);
  155. EndDrawing();
  156. //-----------------------------------------------------
  157. }
  158. // De-Initialization
  159. //---------------------------------------------------------
  160. CloseWindow(); // Close window and OpenGL context
  161. //----------------------------------------------------------
  162. return 0;
  163. }