From dd929f8b209f25acfa3d51465e5a12fcf6c1a1c1 Mon Sep 17 00:00:00 2001
From: =?utf8?q?Am=C3=A9lia=20Coutard-Sander?= <git@ameliathe1st.gay>
Date: Thu, 19 Dec 2024 16:43:17 +0100
Subject: [PATCH] =?utf8?q?Affichage=20centr=C3=A9=20sur=20la=20case=20cour?=
 =?utf8?q?ante?=
MIME-Version: 1.0
Content-Type: text/plain; charset=utf8
Content-Transfer-Encoding: 8bit

---
 bin/modes.ml | 16 ++++++++++------
 1 file changed, 10 insertions(+), 6 deletions(-)

diff --git a/bin/modes.ml b/bin/modes.ml
index c957f97..1bdbe32 100644
--- a/bin/modes.ml
+++ b/bin/modes.ml
@@ -66,22 +66,26 @@ module Normal (M : Automata.Automaton) = struct
     let initial () = { board = Automata.initial (module M); n = None; pos = (0, 0); current = M.default }
 
     let render { board; current; pos = px, py; _ } =
-            for x = 0 to (Graphics.size_x () / 16) + 1 do
-              for y = 0 to (Graphics.size_y () / 16) + 1 do
+            let w = (Graphics.size_x () / 16) + 1
+            and h = (Graphics.size_y () / 16) + 1 in
+            let wx = px - (w / 2)
+            and wy = py - (h / 2) in
+            for x = wx to wx + w do
+              for y = wy to wy + h do
                 let r, g, b = M.color (Automata.get x y board) in
                 let r, g, b = (int_of_char r, int_of_char g, int_of_char b) in
                 Graphics.set_color (Graphics.rgb r g b);
-                Graphics.fill_rect (x * 16) (y * 16) 16 16;
+                Graphics.fill_rect ((x - wx) * 16) ((y - wy) * 16) 16 16;
                 Graphics.set_color (Graphics.rgb 127 127 127);
-                Graphics.draw_rect (x * 16) (y * 16) 16 16
+                Graphics.draw_rect ((x - wx) * 16) ((y - wy) * 16) 16 16
               done
             done;
             let r, g, b = M.color current in
             let r, g, b = (int_of_char r, int_of_char g, int_of_char b) in
             Graphics.set_color (Graphics.rgb r g b);
-            Graphics.fill_rect ((px * 16) + 5) ((py * 16) + 5) 6 6;
+            Graphics.fill_rect (((px - wx) * 16) + 5) (((py - wy) * 16) + 5) 6 6;
             Graphics.set_color (Graphics.rgb 127 127 127);
-            Graphics.draw_rect ((px * 16) + 5) ((py * 16) + 5) 6 6
+            Graphics.draw_rect (((px - wx) * 16) + 5) (((py - wy) * 16) + 5) 6 6
 
     let update st =
             let set_current ({ board; pos = x, y; current; _ } as st) =
-- 
2.46.0