"[shapes] rectangle advanced: fix screen width and height to fit with other examples"

This commit is contained in:
evertonse 2024-10-29 17:57:54 -03:00
parent 619d09081c
commit ef0c18b447
2 changed files with 34 additions and 10 deletions

View File

@ -3,6 +3,7 @@
#include <math.h> #include <math.h>
// Draw rectangle with rounded edges and horizontal gradient, with options to choose side of roundness // Draw rectangle with rounded edges and horizontal gradient, with options to choose side of roundness
// Adapted from both `DrawRectangleRounded` and `DrawRectangleGradientH`
void DrawRectangleRoundedGradientH(Rectangle rec, float roundnessLeft, float roundnessRight, int segments, Color left, Color right) void DrawRectangleRoundedGradientH(Rectangle rec, float roundnessLeft, float roundnessRight, int segments, Color left, Color right)
{ {
// Neither side is rounded // Neither side is rounded
@ -274,18 +275,35 @@ void DrawRectangleRoundedGradientH(Rectangle rec, float roundnessLeft, float rou
#endif #endif
} }
int main(int argc, char *argv[]) { int main(int argc, char *argv[])
InitWindow(600, 900, "Rectangle Rounded Gradient"); {
double width = 600/2.0, height = 900/6.0; // Initialization
//--------------------------------------------------------------------------------------
const int screenWidth = 800;
const int screenHeight = 450;
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - rectangle avanced");
SetTargetFPS(60);
//--------------------------------------------------------------------------------------
while (!WindowShouldClose()) { // Main game loop
BeginDrawing(); while (!WindowShouldClose()) // Detect window close button or ESC key
ClearBackground(RAYWHITE); {
// Update rectangle bounds
//----------------------------------------------------------------------------------
double width = GetScreenWidth()/2.0, height = GetScreenHeight()/6.0;
Rectangle rec = { Rectangle rec = {
GetScreenWidth() / 2.0 - width/2, GetScreenWidth() / 2.0 - width/2,
GetScreenHeight() / 2.0 - (5)*(height/2), GetScreenHeight() / 2.0 - (5)*(height/2),
width, height width, height
}; };
//--------------------------------------------------------------------------------------
// Draw
//----------------------------------------------------------------------------------
BeginDrawing();
ClearBackground(RAYWHITE);
// Draw All Rectangles with different roundess for each side and different gradients
DrawRectangleRoundedGradientH(rec, 0.8, 0.8, 36, BLUE, RED); DrawRectangleRoundedGradientH(rec, 0.8, 0.8, 36, BLUE, RED);
rec.y += rec.height + 1; rec.y += rec.height + 1;
@ -300,7 +318,13 @@ int main(int argc, char *argv[]) {
rec.y += rec.height + 1; rec.y += rec.height + 1;
DrawRectangleRoundedGradientH(rec, 1.0, 0.0, 36, BLUE, PINK); DrawRectangleRoundedGradientH(rec, 1.0, 0.0, 36, BLUE, PINK);
EndDrawing(); EndDrawing();
//--------------------------------------------------------------------------------------
} }
// De-Initialization
//--------------------------------------------------------------------------------------
CloseWindow(); // Close window and OpenGL context
//--------------------------------------------------------------------------------------
return 0; return 0;
} }

Binary file not shown.

Before

Width:  |  Height:  |  Size: 16 KiB

After

Width:  |  Height:  |  Size: 6.7 KiB