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