From bbff771d70698a148267d3e510b33858879ea8d0 Mon Sep 17 00:00:00 2001
From: Tristan Riehs <tristan.riehs@bordeaux-inp.fr>
Date: Tue, 25 Jun 2024 18:20:36 +0900
Subject: Display time calculations take

---
 src/calculer.c |  8 +++++---
 src/ray.c      | 46 +++++++++++++++++++++-------------------------
 2 files changed, 26 insertions(+), 28 deletions(-)

diff --git a/src/calculer.c b/src/calculer.c
index 589724f..8c1b629 100644
--- a/src/calculer.c
+++ b/src/calculer.c
@@ -31,6 +31,8 @@
 static int lower = 0;
 static int upper = 100;
 
+static int ms;
+
 static FILE *logfile;
 static char logbuf[64];
 #define LOGBUF_OFFSET 11
@@ -67,10 +69,10 @@ measure_after(void *data, int correct)
 	struct timespec tp;
 	clock_gettime(CLOCK_REALTIME, &tp);
 	int t1 = tp_ms(&tp);
-	int dt = t1 - t0;
+	ms = t1 - t0;
 	size_t bytes_written =
 		LOGBUF_OFFSET + sprintf(logbuf + LOGBUF_OFFSET,
-					"%d\t%d\n", dt, correct);
+					"%d\t%d\n", ms, correct);
 
 	return bytes_written != fwrite(logbuf, 1, bytes_written, logfile);
 }
@@ -214,7 +216,7 @@ main(int argc, char *argv[])
 		}
 #endif
 		measure_after(measure_data, input == res);
-		disp->display_res(input == res, 0);
+		disp->display_res(input == res, ms);
 	}
 
 	fclose(logfile);
diff --git a/src/ray.c b/src/ray.c
index 0e89f24..402d600 100644
--- a/src/ray.c
+++ b/src/ray.c
@@ -118,17 +118,6 @@ draw_calc(void)
 		 states[current_state].x, states[current_state].y);
 }
 
-void
-display_calc(int x, int y)
-{
-	states[current_state].x = x;
-	states[current_state].y = y;
-	BeginDrawing();
-	ClearBackground(RAYWHITE);
-	draw_calc();
-	EndDrawing();
-}
-
 static void
 draw_input(void)
 {
@@ -162,7 +151,6 @@ static void
 draw_res(void)
 {
 	char txt[64] = {0};
-	char *suffix;
 	Color col;
 	int win_width, win_height;
 	int txt_width;
@@ -171,33 +159,26 @@ draw_res(void)
 	win_width = GetScreenWidth();
 	win_height = GetScreenHeight();
 
-	for (int i = 0; i < STATE_COUNT; i++)
+	for (int i = 1; i < STATE_COUNT; i++)
 	{
-		j = (current_state + i)%STATE_COUNT;
+		int j = (current_state - i)%STATE_COUNT;
 		
 		if (states[j].ms == 0)
 			break;
 
 		if (states[j].right)
-		{
-			suffix = "RIGHT";
 			col = GREEN;
-		}
 		else
-		{
-			suffix = "WRONG";
 			col = RED;
-		}   
 
-		sprintf(txt, "%d + %d = %d (%s) %dms",
+		sprintf(txt, "%d + %d = %d %dms",
 			states[j].x, states[j].y,
-			states[j].input,
-			suffix, states[j].ms);
+			states[j].input, states[j].ms);
 
-		font_size = min(win_height/8, MAX_FONTSIZE/2);
+		font_size = min(win_height/STATE_COUNT, MAX_FONTSIZE/2);
 		txt_width = MeasureText(txt, font_size);
 		/* TODO: draw every results */
-		DrawText(txt, win_width-txt_width, 0, font_size, col);
+		DrawText(txt, win_width-txt_width, (int) font_size*1.2*i, font_size, col);
 	}
 }
 
@@ -212,6 +193,21 @@ redraw(void)
 	EndDrawing();
 }
 
+void
+display_calc(int x, int y)
+{
+	current_state = (current_state + 1)%STATE_COUNT;
+	states[current_state].x = x;
+	states[current_state].y = y;
+	states[current_state].ms = 0;
+	states[current_state].input = 0;
+	/* BeginDrawing(); */
+	/* ClearBackground(RAYWHITE); */
+	/* draw_calc(); */
+	/* EndDrawing(); */
+	redraw();
+}
+
 static void
 add_input_digit(int digit)
 {
-- 
cgit v1.2.3