changeset 18:6a5c5b137348

implement method to run the algo function given the selected algo
author Dennis C. M. <dennis@denniscm.com>
date Sun, 25 Jun 2023 19:23:49 +0100
parents fba66d02f1cf
children a027304ec75d
files main.c
diffstat 1 files changed, 19 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Sun Jun 25 18:46:29 2023 +0100
+++ b/main.c	Sun Jun 25 19:23:49 2023 +0100
@@ -20,13 +20,13 @@
 FT_Library ft_library;
 FT_Face ft_face;
 
-char algos[4][50] = {
-	"Bubble sort", 
-	"Selection sort", 
-	"Insertion sort", 
-	"Quick sort"
+struct Algo {
+	char name[50];
+	void (*function)();
 };
 
+struct Algo algos[1];
+
 int selected_algo = 0;
 int speed = 5;
 int refresh_counter = 0;
@@ -162,7 +162,7 @@
 		glRasterPos2f(x, adjusted_y);
 		glDrawPixels(glyph_bitmap->width, glyph_bitmap->rows, GL_LUMINANCE, GL_UNSIGNED_BYTE, glyph_bitmap->buffer);
 
-		x += 15;
+		x += slot->advance.x / 64;
 	}
 }
 
@@ -195,9 +195,8 @@
 	// Render text
 	char text[256];
 
-
 	// Top: Column 1
-	sprintf(text, "Algorithm: %s", algos[selected_algo]);
+	sprintf(text, "Algorithm: %s", algos[selected_algo].name);
 	render_text(20, WINDOW_HEIGHT - 50, text);
 	
 	sprintf(text, "Speed: %i", speed);
@@ -227,7 +226,7 @@
 
 void idle() {
 	if (run) {
-		bubble_sort();
+		algos[selected_algo].function();
 		refresh_counter++;
 		iter_counter++;
 
@@ -272,12 +271,7 @@
 		// Reset algo steps
 		bs = (struct BubbleSortInfo){0, 0};
 	}
-
-	// enter: Run program
-	if (key == 13) {
-		run = true;
-	}
-
+	
 	// u: Increase speed
 	if (key == 117) {
 		speed++;
@@ -287,6 +281,13 @@
 	if (key == 100) {
 		speed--;
 	}
+	
+	// enter: Run program
+	if (key == 13) {
+		run = true;
+	}
+
+	
 }
 
 
@@ -349,6 +350,9 @@
 
 
 int main(int argc, char** argv) {
+	strcpy(algos[0].name, "Bubble sort");
+	algos[0].function = &bubble_sort;
+
 	create_array();
 
 	glutInit(&argc, argv);