]> git.f4mnq.fr Git - cells.git/commitdiff
Affichage centré sur la case courante
authorAmélia Coutard-Sander <git@f4mnq.fr>
Wed, 7 Jan 2026 13:38:52 +0000 (14:38 +0100)
committerAmélia Coutard-Sander <git@f4mnq.fr>
Wed, 7 Jan 2026 13:53:54 +0000 (14:53 +0100)
bin/modes.ml

index b1f639fb1898b095a5a0729a64812c2e95462456..77cb316bf47870a45f7e31079d81d02c8902cc9c 100644 (file)
@@ -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) =