sdl2: intro minimal bindings to SDL2 mixer
[nit.git] / lib / mnit / numbers.nit
index 827b4cc..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,14 +37,28 @@ 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
-                       blit(imgs.imgs[d], x, y)
-                       x += imgs.imgs[d].width
+                       var img = imgs.imgs[d]
+                       blit(img, x, y)
+                       x += (img.width.to_f * img.scale).to_i
                end
        end
 end