2019-05-03 16:00:16 +02:00
|
|
|
/*******************************************************************************************
|
|
|
|
*
|
|
|
|
* raylib [shapes] example - draw ring (with gui options)
|
|
|
|
*
|
2022-07-20 01:28:37 +02:00
|
|
|
* Example originally created with raylib 2.5, last time updated with raylib 2.5
|
2019-05-03 16:00:16 +02:00
|
|
|
*
|
2019-05-14 15:34:23 +02:00
|
|
|
* Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5)
|
|
|
|
*
|
2022-07-20 01:28:37 +02:00
|
|
|
* Example licensed under an unmodified zlib/libpng license, which is an OSI-certified,
|
|
|
|
* BSD-like license that allows static linking with closed source software
|
|
|
|
*
|
2024-01-02 20:58:12 +01:00
|
|
|
* Copyright (c) 2018-2024 Vlad Adrian (@demizdor) and Ramon Santamaria (@raysan5)
|
2019-05-03 16:00:16 +02:00
|
|
|
*
|
|
|
|
********************************************************************************************/
|
|
|
|
|
|
|
|
#include <raylib.h>
|
|
|
|
|
|
|
|
#define RAYGUI_IMPLEMENTATION
|
2022-06-06 11:11:39 +02:00
|
|
|
#include "raygui.h" // Required for GUI controls
|
2019-05-03 16:00:16 +02:00
|
|
|
|
2022-06-21 19:53:18 +02:00
|
|
|
//------------------------------------------------------------------------------------
|
|
|
|
// Program main entry point
|
|
|
|
//------------------------------------------------------------------------------------
|
2019-05-20 16:36:42 +02:00
|
|
|
int main(void)
|
2019-05-03 16:00:16 +02:00
|
|
|
{
|
|
|
|
// Initialization
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
const int screenWidth = 800;
|
|
|
|
const int screenHeight = 450;
|
|
|
|
|
|
|
|
InitWindow(screenWidth, screenHeight, "raylib [shapes] example - draw ring");
|
|
|
|
|
2021-10-25 01:21:16 -07:00
|
|
|
Vector2 center = {(GetScreenWidth() - 300)/2.0f, GetScreenHeight()/2.0f };
|
2019-05-03 16:00:16 +02:00
|
|
|
|
|
|
|
float innerRadius = 80.0f;
|
|
|
|
float outerRadius = 190.0f;
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2021-03-19 18:13:55 +00:00
|
|
|
float startAngle = 0.0f;
|
|
|
|
float endAngle = 360.0f;
|
2023-06-09 18:07:25 +02:00
|
|
|
float segments = 0.0f;
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2019-05-03 16:00:16 +02:00
|
|
|
bool drawRing = true;
|
|
|
|
bool drawRingLines = false;
|
|
|
|
bool drawCircleLines = false;
|
2019-05-20 16:36:42 +02:00
|
|
|
|
|
|
|
SetTargetFPS(60); // Set our game to run at 60 frames-per-second
|
2019-05-03 16:00:16 +02:00
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
// Main game loop
|
|
|
|
while (!WindowShouldClose()) // Detect window close button or ESC key
|
|
|
|
{
|
|
|
|
// Update
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
// NOTE: All variables update happens inside GUI control functions
|
|
|
|
//----------------------------------------------------------------------------------
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2019-05-03 16:00:16 +02:00
|
|
|
// Draw
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
BeginDrawing();
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2019-05-03 16:00:16 +02:00
|
|
|
ClearBackground(RAYWHITE);
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2019-05-03 16:00:16 +02:00
|
|
|
DrawLine(500, 0, 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.6f));
|
|
|
|
DrawRectangle(500, 0, GetScreenWidth() - 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.3f));
|
|
|
|
|
2023-06-09 18:07:25 +02:00
|
|
|
if (drawRing) DrawRing(center, innerRadius, outerRadius, startAngle, endAngle, (int)segments, Fade(MAROON, 0.3f));
|
|
|
|
if (drawRingLines) DrawRingLines(center, innerRadius, outerRadius, startAngle, endAngle, (int)segments, Fade(BLACK, 0.4f));
|
|
|
|
if (drawCircleLines) DrawCircleSectorLines(center, outerRadius, startAngle, endAngle, (int)segments, Fade(BLACK, 0.4f));
|
2019-05-03 16:00:16 +02:00
|
|
|
|
|
|
|
// Draw GUI controls
|
|
|
|
//------------------------------------------------------------------------------
|
2024-08-06 16:05:53 -07:00
|
|
|
GuiSliderBar((Rectangle){ 600, 40, 120, 20 }, "StartAngle", TextFormat("%.2f", startAngle), &startAngle, -450, 450);
|
|
|
|
GuiSliderBar((Rectangle){ 600, 70, 120, 20 }, "EndAngle", TextFormat("%.2f", endAngle), &endAngle, -450, 450);
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2024-08-06 16:05:53 -07:00
|
|
|
GuiSliderBar((Rectangle){ 600, 140, 120, 20 }, "InnerRadius", TextFormat("%.2f", innerRadius), &innerRadius, 0, 100);
|
|
|
|
GuiSliderBar((Rectangle){ 600, 170, 120, 20 }, "OuterRadius", TextFormat("%.2f", outerRadius), &outerRadius, 0, 200);
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2024-08-06 16:05:53 -07:00
|
|
|
GuiSliderBar((Rectangle){ 600, 240, 120, 20 }, "Segments", TextFormat("%.2f", segments), &segments, 0, 100);
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2023-06-09 18:07:25 +02:00
|
|
|
GuiCheckBox((Rectangle){ 600, 320, 20, 20 }, "Draw Ring", &drawRing);
|
|
|
|
GuiCheckBox((Rectangle){ 600, 350, 20, 20 }, "Draw RingLines", &drawRingLines);
|
|
|
|
GuiCheckBox((Rectangle){ 600, 380, 20, 20 }, "Draw CircleLines", &drawCircleLines);
|
2019-05-03 16:00:16 +02:00
|
|
|
//------------------------------------------------------------------------------
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2022-08-02 09:58:56 +02:00
|
|
|
int minSegments = (int)ceilf((endAngle - startAngle)/90);
|
2021-04-06 13:29:58 +01:00
|
|
|
DrawText(TextFormat("MODE: %s", (segments >= minSegments)? "MANUAL" : "AUTO"), 600, 270, 10, (segments >= minSegments)? MAROON : DARKGRAY);
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2019-05-03 16:00:16 +02:00
|
|
|
DrawFPS(10, 10);
|
2019-05-20 16:36:42 +02:00
|
|
|
|
2019-05-03 16:00:16 +02:00
|
|
|
EndDrawing();
|
|
|
|
//----------------------------------------------------------------------------------
|
|
|
|
}
|
|
|
|
|
|
|
|
// De-Initialization
|
2019-05-20 16:36:42 +02:00
|
|
|
//--------------------------------------------------------------------------------------
|
2019-05-03 16:00:16 +02:00
|
|
|
CloseWindow(); // Close window and OpenGL context
|
|
|
|
//--------------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|