1 | /******************************************************************************************* |
2 | * |
3 | * raylib [shapes] example - draw circle sector (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 circle sector" ); |
27 | |
28 | Vector2 center = {(GetScreenWidth() - 300)/2, GetScreenHeight()/2 }; |
29 | |
30 | float outerRadius = 180.f; |
31 | int startAngle = 0; |
32 | int endAngle = 180; |
33 | int segments = 0; |
34 | |
35 | SetTargetFPS(60); // Set our game to run at 60 frames-per-second |
36 | //-------------------------------------------------------------------------------------- |
37 | |
38 | // Main game loop |
39 | while (!WindowShouldClose()) // Detect window close button or ESC key |
40 | { |
41 | // Update |
42 | //---------------------------------------------------------------------------------- |
43 | // NOTE: All variables update happens inside GUI control functions |
44 | //---------------------------------------------------------------------------------- |
45 | |
46 | // Draw |
47 | //---------------------------------------------------------------------------------- |
48 | BeginDrawing(); |
49 | |
50 | ClearBackground(RAYWHITE); |
51 | |
52 | DrawLine(500, 0, 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.6f)); |
53 | DrawRectangle(500, 0, GetScreenWidth() - 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.3f)); |
54 | |
55 | DrawCircleSector(center, outerRadius, startAngle, endAngle, segments, Fade(MAROON, 0.3)); |
56 | DrawCircleSectorLines(center, outerRadius, startAngle, endAngle, segments, Fade(MAROON, 0.6)); |
57 | |
58 | // Draw GUI controls |
59 | //------------------------------------------------------------------------------ |
60 | startAngle = GuiSliderBar((Rectangle){ 600, 40, 120, 20}, "StartAngle" , startAngle, 0, 720, true ); |
61 | endAngle = GuiSliderBar((Rectangle){ 600, 70, 120, 20}, "EndAngle" , endAngle, 0, 720, true); |
62 | |
63 | outerRadius = GuiSliderBar((Rectangle){ 600, 140, 120, 20}, "Radius" , outerRadius, 0, 200, true); |
64 | segments = GuiSliderBar((Rectangle){ 600, 170, 120, 20}, "Segments" , segments, 0, 100, true); |
65 | //------------------------------------------------------------------------------ |
66 | |
67 | DrawText(FormatText("MODE: %s" , (segments >= 4)? "MANUAL" : "AUTO" ), 600, 200, 10, (segments >= 4)? MAROON : DARKGRAY); |
68 | |
69 | DrawFPS(10, 10); |
70 | |
71 | EndDrawing(); |
72 | //---------------------------------------------------------------------------------- |
73 | } |
74 | |
75 | // De-Initialization |
76 | //-------------------------------------------------------------------------------------- |
77 | CloseWindow(); // Close window and OpenGL context |
78 | //-------------------------------------------------------------------------------------- |
79 | |
80 | return 0; |
81 | } |