nitcorn/file_server: extract answer_file method
[nit.git] / lib / mnit / numbers.nit
index e7fb184..f3bdece 100644 (file)
@@ -24,8 +24,6 @@ class NumberImages
 
        # Images from 0 to 9
        var imgs: Array[Image]
-
-       private init(imgs: Array[Image]) do self.imgs = imgs
 end
 
 redef class App
@@ -39,11 +37,24 @@ redef class App
 end
 
 redef class Display
-       fun blit_number(imgs: NumberImages, number: Int, x, y: Int)
+       fun blit_number(imgs: NumberImages, number: Int, x, y: Int, centered: nullable Bool)
        do
                var str = number.to_s
+
+               if centered == true then
+                       var w = 0
+                       for c in str.chars do
+                               var d = c.code_point-'0'.code_point
+                               var img = imgs.imgs[d]
+                               w += (img.width.to_f * img.scale).to_i
+                       end
+                       x -= w / 2
+                       var img = imgs.imgs.first
+                       y -= (img.width.to_f * img.scale).to_i / 2
+               end
+
                for c in str.chars do
-                       var d = c.ascii-'0'.ascii
+                       var d = c.code_point-'0'.code_point
                        assert d >= 0 and d <= 9
                        var img = imgs.imgs[d]
                        blit(img, x, y)