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.

94 regels
4.4 KiB

11 maanden geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
5 jaren geleden
  1. /*******************************************************************************************
  2. *
  3. * raylib [shapes] example - draw rectangle rounded (with gui options)
  4. *
  5. * Example originally created with raylib 2.5, last time updated with raylib 2.5
  6. *
  7. * Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
  8. *
  9. * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
  10. * BSD-like license that allows static linking with closed source software
  11. *
  12. * Copyright (c) 2018-2024 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
  13. *
  14. ********************************************************************************************/
  15. #include <raylib.h>
  16. #define RAYGUI_IMPLEMENTATION
  17. #include "raygui.h" // Required for GUI controls
  18. //------------------------------------------------------------------------------------
  19. // Program main entry point
  20. //------------------------------------------------------------------------------------
  21. int main(void)
  22. {
  23. // Initialization
  24. //--------------------------------------------------------------------------------------
  25. const int screenWidth = 800;
  26. const int screenHeight = 450;
  27. InitWindow(screenWidth, screenHeight, "raylib [shapes] example - draw rectangle rounded");
  28. float roundness = 0.2f;
  29. float width = 200.0f;
  30. float height = 100.0f;
  31. float segments = 0.0f;
  32. float lineThick = 1.0f;
  33. bool drawRect = false;
  34. bool drawRoundedRect = true;
  35. bool drawRoundedLines = false;
  36. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  37. //--------------------------------------------------------------------------------------
  38. // Main game loop
  39. while (!WindowShouldClose()) // Detect window close button or ESC key
  40. {
  41. // Update
  42. //----------------------------------------------------------------------------------
  43. Rectangle rec = { ((float)GetScreenWidth() - width - 250)/2, (GetScreenHeight() - height)/2.0f, (float)width, (float)height };
  44. //----------------------------------------------------------------------------------
  45. // Draw
  46. //----------------------------------------------------------------------------------
  47. BeginDrawing();
  48. ClearBackground(RAYWHITE);
  49. DrawLine(560, 0, 560, GetScreenHeight(), Fade(LIGHTGRAY, 0.6f));
  50. DrawRectangle(560, 0, GetScreenWidth() - 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.3f));
  51. if (drawRect) DrawRectangleRec(rec, Fade(GOLD, 0.6f));
  52. if (drawRoundedRect) DrawRectangleRounded(rec, roundness, (int)segments, Fade(MAROON, 0.2f));
  53. if (drawRoundedLines) DrawRectangleRoundedLinesEx(rec, roundness, (int)segments, lineThick, Fade(MAROON, 0.4f));
  54. // Draw GUI controls
  55. //------------------------------------------------------------------------------
  56. GuiSliderBar((Rectangle){ 640, 40, 105, 20 }, "Width", TextFormat("%.2f", width), &width, 0, (float)GetScreenWidth() - 300);
  57. GuiSliderBar((Rectangle){ 640, 70, 105, 20 }, "Height", TextFormat("%.2f", height), &height, 0, (float)GetScreenHeight() - 50);
  58. GuiSliderBar((Rectangle){ 640, 140, 105, 20 }, "Roundness", TextFormat("%.2f", roundness), &roundness, 0.0f, 1.0f);
  59. GuiSliderBar((Rectangle){ 640, 170, 105, 20 }, "Thickness", TextFormat("%.2f", lineThick), &lineThick, 0, 20);
  60. GuiSliderBar((Rectangle){ 640, 240, 105, 20}, "Segments", TextFormat("%.2f", segments), &segments, 0, 60);
  61. GuiCheckBox((Rectangle){ 640, 320, 20, 20 }, "DrawRoundedRect", &drawRoundedRect);
  62. GuiCheckBox((Rectangle){ 640, 350, 20, 20 }, "DrawRoundedLines", &drawRoundedLines);
  63. GuiCheckBox((Rectangle){ 640, 380, 20, 20}, "DrawRect", &drawRect);
  64. //------------------------------------------------------------------------------
  65. DrawText(TextFormat("MODE: %s", (segments >= 4)? "MANUAL" : "AUTO"), 640, 280, 10, (segments >= 4)? MAROON : DARKGRAY);
  66. DrawFPS(10, 10);
  67. EndDrawing();
  68. //----------------------------------------------------------------------------------
  69. }
  70. // De-Initialization
  71. //--------------------------------------------------------------------------------------
  72. CloseWindow(); // Close window and OpenGL context
  73. //--------------------------------------------------------------------------------------
  74. return 0;
  75. }