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