1/*******************************************************************************************
2*
3* raylib [shapes] example - draw ring (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
19int 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 ring");
27
28 Vector2 center = {(GetScreenWidth() - 300)/2, GetScreenHeight()/2 };
29
30 float innerRadius = 80.0f;
31 float outerRadius = 190.0f;
32
33 int startAngle = 0;
34 int endAngle = 360;
35 int segments = 0;
36
37 bool drawRing = true;
38 bool drawRingLines = false;
39 bool drawCircleLines = false;
40
41 SetTargetFPS(60); // Set our game to run at 60 frames-per-second
42 //--------------------------------------------------------------------------------------
43
44 // Main game loop
45 while (!WindowShouldClose()) // Detect window close button or ESC key
46 {
47 // Update
48 //----------------------------------------------------------------------------------
49 // NOTE: All variables update happens inside GUI control functions
50 //----------------------------------------------------------------------------------
51
52 // Draw
53 //----------------------------------------------------------------------------------
54 BeginDrawing();
55
56 ClearBackground(RAYWHITE);
57
58 DrawLine(500, 0, 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.6f));
59 DrawRectangle(500, 0, GetScreenWidth() - 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.3f));
60
61 if (drawRing) DrawRing(center, innerRadius, outerRadius, startAngle, endAngle, segments, Fade(MAROON, 0.3));
62 if (drawRingLines) DrawRingLines(center, innerRadius, outerRadius, startAngle, endAngle, segments, Fade(BLACK, 0.4));
63 if (drawCircleLines) DrawCircleSectorLines(center, outerRadius, startAngle, endAngle, segments, Fade(BLACK, 0.4));
64
65 // Draw GUI controls
66 //------------------------------------------------------------------------------
67 startAngle = GuiSliderBar((Rectangle){ 600, 40, 120, 20 }, "StartAngle", startAngle, -450, 450, true);
68 endAngle = GuiSliderBar((Rectangle){ 600, 70, 120, 20 }, "EndAngle", endAngle, -450, 450, true);
69
70 innerRadius = GuiSliderBar((Rectangle){ 600, 140, 120, 20 }, "InnerRadius", innerRadius, 0, 100, true);
71 outerRadius = GuiSliderBar((Rectangle){ 600, 170, 120, 20 }, "OuterRadius", outerRadius, 0, 200, true);
72
73 segments = GuiSliderBar((Rectangle){ 600, 240, 120, 20 }, "Segments", segments, 0, 100, true);
74
75 drawRing = GuiCheckBox((Rectangle){ 600, 320, 20, 20 }, "Draw Ring", drawRing);
76 drawRingLines = GuiCheckBox((Rectangle){ 600, 350, 20, 20 }, "Draw RingLines", drawRingLines);
77 drawCircleLines = GuiCheckBox((Rectangle){ 600, 380, 20, 20 }, "Draw CircleLines", drawCircleLines);
78 //------------------------------------------------------------------------------
79
80 DrawText(FormatText("MODE: %s", (segments >= 4)? "MANUAL" : "AUTO"), 600, 270, 10, (segments >= 4)? MAROON : DARKGRAY);
81
82 DrawFPS(10, 10);
83
84 EndDrawing();
85 //----------------------------------------------------------------------------------
86 }
87
88 // De-Initialization
89 //--------------------------------------------------------------------------------------
90 CloseWindow(); // Close window and OpenGL context
91 //--------------------------------------------------------------------------------------
92
93 return 0;
94}