From 89f75b27d8168eb5798531c627ca603119700873 Mon Sep 17 00:00:00 2001
From: Joseph Walton-Rivers <joseph@walton-rivers.uk>
Date: Sat, 27 Aug 2022 17:39:19 +0100
Subject: [PATCH] added some arc-generation code for use as progress bars

---
 demo/demo/grid.cpp         | 17 +++++++++++++++++
 include/fggl/gfx/paint.hpp | 27 ++++++++++++++++++++++++++-
 2 files changed, 43 insertions(+), 1 deletion(-)

diff --git a/demo/demo/grid.cpp b/demo/demo/grid.cpp
index 7f7d99b..f600861 100644
--- a/demo/demo/grid.cpp
+++ b/demo/demo/grid.cpp
@@ -55,6 +55,7 @@ namespace demo {
 		}
 	}
 
+	float progress = 0.0f;
 	void GridScene::render(fggl::gfx::Graphics &gfx) {
 		Game::render(gfx);
 
@@ -67,6 +68,22 @@ namespace demo {
 			paint.fill(hexTest);
 		}
 
+		// draw test arcs
+		for (int sides = 0; sides < 12; ++sides) {
+			float endAngle = progress * (M_PI * 2);
+
+			float startAngle = sides/12.0F * (M_PI * 2);
+			float endAngle2 = endAngle + startAngle;
+
+			auto hexTest = fggl::gfx::make_arc(fggl::math::vec2{sides + 3, 7} * DRAW_SIZE, DRAW_HALF, startAngle, endAngle2, fggl::gfx::colours::CYAN);
+			paint.fill(hexTest);
+		}
+
+		progress += 0.01F;
+		if ( progress > 1.0F) {
+			progress = 0.0F;
+		}
+
 		gfx.draw2D(paint);
 	}
 
diff --git a/include/fggl/gfx/paint.hpp b/include/fggl/gfx/paint.hpp
index 06d10ba..4a9b27a 100644
--- a/include/fggl/gfx/paint.hpp
+++ b/include/fggl/gfx/paint.hpp
@@ -97,7 +97,7 @@ namespace fggl::gfx {
 		bool sinFirst = true;
 	};
 
-	inline Path2D make_shape(math::vec2 center, float radius, int sides, math::vec3 colour = {1.0f, 1.0f, 1.0f}, ShapeOpts opts = {}) {
+	inline Path2D make_shape(math::vec2 center, float radius, int sides, math::vec3 colour = colours::WHITE, ShapeOpts opts = {}) {
 		double angle = (M_PI * 2.0) / sides;
 
 		fggl::gfx::Path2D tileGfx(center);
@@ -119,6 +119,31 @@ namespace fggl::gfx {
 		return tileGfx;
 	}
 
+	inline Path2D make_arc(math::vec2 center, float radius, float start, float end, math::vec3 colour = colours::WHITE, int slices = 25) {
+		const float angle = (M_PI * 2.0) / slices;
+		fggl::gfx::Path2D tileGfx(center);
+
+		tileGfx.colour(colour);
+		tileGfx.moveTo(center);
+		for (float totalAngle = start; totalAngle < end; totalAngle += angle) { // NOLINT(cert-flp30-c)
+			float xPos = (float)(sinf(totalAngle) * radius) + center.x;
+			float yPos = (float)(cosf(totalAngle) * radius) + center.y;
+			tileGfx.pathTo({xPos, yPos});
+			if ( (totalAngle + angle) > end) {
+				break;
+			}
+		}
+
+		{
+			float xPos = (float) (sinf(end) * radius) + center.x;
+			float yPos = (float) (cosf(end) * radius) + center.y;
+			tileGfx.pathTo( {xPos, yPos} );
+		}
+
+		tileGfx.close();
+		return tileGfx;
+	}
+
 	enum class PaintType {
 		FILL,
 		STROKE
-- 
GitLab