"[shapes] rectangle advanced: fix screen width and height to fit with other examples"
This commit is contained in:
parent
619d09081c
commit
ef0c18b447
|
|
@ -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
|
||||||
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
||||||
|
{
|
||||||
|
// Update rectangle bounds
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
|
double width = GetScreenWidth()/2.0, height = GetScreenHeight()/6.0;
|
||||||
|
Rectangle rec = {
|
||||||
|
GetScreenWidth() / 2.0 - width/2,
|
||||||
|
GetScreenHeight() / 2.0 - (5)*(height/2),
|
||||||
|
width, height
|
||||||
|
};
|
||||||
|
//--------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
// Draw
|
||||||
|
//----------------------------------------------------------------------------------
|
||||||
BeginDrawing();
|
BeginDrawing();
|
||||||
ClearBackground(RAYWHITE);
|
ClearBackground(RAYWHITE);
|
||||||
Rectangle rec = {
|
|
||||||
GetScreenWidth() / 2.0 - width/2,
|
// Draw All Rectangles with different roundess for each side and different gradients
|
||||||
GetScreenHeight() / 2.0 - (5)*(height/2),
|
|
||||||
width, height
|
|
||||||
};
|
|
||||||
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 |
Loading…
Reference in New Issue
Block a user