2
0

Functions_-_drawroundedrect.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #include "raylib.h"
  2. static void drawroundedrect(int x, int y, int w,int h,Color col);
  3. static void drawroundedrectline(int x, int y, int w,int h,Color col);
  4. int main(void)
  5. {
  6. // Initialization
  7. //--------------------------------------------------------------------------------------
  8. const int screenWidth = 800;
  9. const int screenHeight = 450;
  10. InitWindow(screenWidth, screenHeight, "raylib example.");
  11. SetTargetFPS(60); // Set our game to run at 60 frames-per-second
  12. //--------------------------------------------------------------------------------------
  13. // Main game loop
  14. while (!WindowShouldClose()) // Detect window close button or ESC key
  15. {
  16. // Update
  17. //----------------------------------------------------------------------------------
  18. //----------------------------------------------------------------------------------
  19. // Draw
  20. //----------------------------------------------------------------------------------
  21. BeginDrawing();
  22. ClearBackground(RAYWHITE);
  23. drawroundedrect(10,0,screenWidth-20,20,DARKGRAY);
  24. drawroundedrect(screenWidth-20,20,20,screenHeight-40,DARKGRAY);
  25. drawroundedrectline(200,200,320,150,GRAY);
  26. EndDrawing();
  27. //----------------------------------------------------------------------------------
  28. }
  29. // De-Initialization
  30. //--------------------------------------------------------------------------------------
  31. CloseWindow(); // Close window and OpenGL context
  32. //--------------------------------------------------------------------------------------
  33. return 0;
  34. }
  35. void drawroundedrect(int x, int y, int w,int h,Color col){
  36. // our round border size.
  37. int roundsize = 20;
  38. // if messy then look here..
  39. if(w<50)roundsize/=2;
  40. if(h<50)roundsize/=2;
  41. if(w<20)roundsize/=2;
  42. if(h<20)roundsize/=2;
  43. // first draw 4 circles at the corners
  44. DrawCircle(x+roundsize,y+roundsize,roundsize,col);
  45. DrawCircle(x+w-roundsize,y+roundsize,roundsize,col);
  46. DrawCircle(x+roundsize,y+h-roundsize,roundsize,col);
  47. DrawCircle(x+w-roundsize,y+h-roundsize,roundsize,col);
  48. // Draw two rectangles on top of the circles..
  49. DrawRectangle(x,y+roundsize,w,h-roundsize*2,col);
  50. DrawRectangle(x+roundsize,y,w-roundsize*2,h,col);
  51. }
  52. void drawroundedrectline(int x, int y, int w,int h,Color col){
  53. int roundsize = 20;
  54. // if messy then look here..
  55. if(w<50)roundsize/=2;
  56. if(h<50)roundsize/=2;
  57. if(w<20)roundsize/=2;
  58. if(h<20)roundsize/=2;
  59. // first draw 4 circles at the corners
  60. DrawCircle(x+roundsize,y+roundsize,roundsize,col);
  61. DrawCircle(x+w-roundsize,y+roundsize,roundsize,col);
  62. DrawCircle(x+roundsize,y+h-roundsize,roundsize,col);
  63. DrawCircle(x+w-roundsize,y+h-roundsize,roundsize,col);
  64. // Draw the edge lines.
  65. DrawCircleLines(x+roundsize,y+roundsize,roundsize,BLACK);
  66. DrawCircleLines(x+w-roundsize,y+roundsize,roundsize,BLACK);
  67. DrawCircleLines(x+roundsize,y+h-roundsize,roundsize,BLACK);
  68. DrawCircleLines(x+w-roundsize,y+h-roundsize,roundsize,BLACK);
  69. // Draw two rectangles on top of the circles..
  70. DrawRectangle(x,y+roundsize,w,h-roundsize*2,col);
  71. DrawRectangle(x+roundsize,y,w-roundsize*2,h,col);
  72. // Draw the lines on the outside.
  73. DrawLine(x,y+roundsize,x,y+h-roundsize,BLACK);
  74. DrawLine(x+w,y+roundsize,x+w,y+h-roundsize,BLACK);
  75. DrawLine(x+roundsize,y,x+w-roundsize,y,BLACK);
  76. DrawLine(x+roundsize,y+h,x+w-roundsize,y+h,BLACK);
  77. }