Merge: mnit improvements from We Broke The World
authorJean Privat <jean@pryen.org>
Thu, 25 Sep 2014 21:41:22 +0000 (17:41 -0400)
committerJean Privat <jean@pryen.org>
Thu, 25 Sep 2014 21:41:22 +0000 (17:41 -0400)
Pull-Request: #777
Reviewed-by: Jean Privat <jean@pryen.org>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/mnit/opengles1.nit
lib/mnit/tileset.nit
lib/mnit_android/android_app.nit
lib/mnit_display.nit
lib/sdl.nit

index b19fbc7..ebdd8b6 100644 (file)
@@ -268,7 +268,9 @@ class Opengles1Display
                glFrontFace( GL_CW );
        `}
 
-       redef fun blit( image, x, y ) is extern  `{
+       redef fun blit(image, x, y) do native_blit(image, x.to_f, y.to_f)
+
+       private fun native_blit(image: Opengles1Image, x, y: Float)  `{
                GLfloat texture_coord[4][2] =
                {
                        {image->src_xo, image->src_yi},
@@ -309,14 +311,16 @@ class Opengles1Display
                }
        `}
 
-    redef fun blit_centered( img, x, y )
+    redef fun blit_centered(img, x, y)
     do
-               x = x - img.center_x
-               y = y - img.center_y
-               blit( img, x, y )
+               x = x.sub(img.center_x)
+               y = y.sub(img.center_y)
+               blit(img, x, y)
     end
 
-       redef fun blit_rotated( image, x, y, angle ) is extern  `{
+       redef fun blit_rotated(image, x, y, angle) do native_blit_rotated(image, x.to_f, y.to_f, angle)
+
+       private fun native_blit_rotated(image: Opengles1Image, x, y, angle: Float) `{
                GLfloat texture_coord[4][2] =
                {
                        {image->src_xo, image->src_yi},
@@ -358,7 +362,14 @@ class Opengles1Display
        `}
 
        # a = top left, b = bottom left, c = bottom right, d = top right
-       redef fun blit_stretched( image, ax, ay, bx, by, cx, cy, dx, dy ) is extern  `{
+       redef fun blit_stretched(image, ax, ay, bx, by, cx, cy, dx, dy)
+       do
+               native_blit_stretched(image,
+                       ax.to_f, ay.to_f, bx.to_f, by.to_f,
+                       cx.to_f, cy.to_f, dx.to_f, dy.to_f)
+       end
+
+       private fun native_blit_stretched(image: I, ax, ay, bx, by, cx, cy, dx, dy: Float) `{
                GLfloat texture_coord[4][2] =
                {
                        {image->src_xo, image->src_yi},
index b0eae74..8495c51 100644 (file)
@@ -51,7 +51,7 @@ class TileSet
        var nb_rows: Int
 
        # Cache for images of tiles
-       private var subimages = new Array[Image]
+       var subimages = new Array[Image]
 
        # The subimage of given tile
        # Aborts if x or y are out of bound
@@ -99,7 +99,7 @@ end
 redef class Display
        # Blit the text using a monospace bitmap font
        # '\n' are rendered as carriage return
-       fun text(text: String, font: TileSetFont, x, y: Int)
+       fun text(text: String, font: TileSetFont, x, y: Numeric)
        do
                var cx = x
                var cy = y
index 7054153..725c612 100644 (file)
@@ -155,12 +155,12 @@ class AndroidPointerEvent
 
        redef fun x: Float do return extern_x(motion_event.inner_event, pointer_id)
        private fun extern_x(motion_event: InnerAndroidMotionEvent, pointer_id: Int): Float is extern `{
-               return ((int) AMotionEvent_getX(motion_event, pointer_id) * mnit_zoom);
+               return ((int) AMotionEvent_getX(motion_event, pointer_id));
        `}
 
        redef fun y: Float do return extern_y(motion_event.inner_event, pointer_id)
        private fun extern_y(motion_event: InnerAndroidMotionEvent, pointer_id: Int): Float is extern `{
-               return ((int) AMotionEvent_getY(motion_event, pointer_id) * mnit_zoom);
+               return ((int) AMotionEvent_getY(motion_event, pointer_id));
        `}
 
        fun pressure: Float do return extern_pressure(motion_event.inner_event, pointer_id)
@@ -191,7 +191,7 @@ extern class AndroidKeyEvent in "C" `{AInputEvent *`}
                return AKeyEvent_getKeyCode(recv);
        `}
 
-       fun key_char: Char is extern `{
+       redef fun to_c `{
                int code = AKeyEvent_getKeyCode(recv);
                if (code >= AKEYCODE_0 && code <= AKEYCODE_9)
                        return '0'+code-AKEYCODE_0;
@@ -203,6 +203,9 @@ extern class AndroidKeyEvent in "C" `{AInputEvent *`}
        fun is_back_key: Bool do return key_code == 4
        fun is_menu_key: Bool do return key_code == 82
        fun is_search_key: Bool do return key_code == 84
+
+       fun is_volume_up: Bool do return key_code == 24
+       fun is_volume_down: Bool do return key_code == 25
 end
 
 redef class App
index 86b6b8d..7e474b7 100644 (file)
@@ -59,11 +59,11 @@ interface Drawable
        fun set_viewport( x, y, w, h: Int ) is abstract
 
        # Draw image on self, for top left position
-       fun blit( image: I, x, y: Int ) is abstract
+       fun blit(image: I, x, y: Numeric) is abstract
 
        # Draw image on self, for top left position but scaled
        # the width and height of the target rectangle is specified
-       fun blit_scaled(image: Image, x, y, w, h: Int)
+       fun blit_scaled(image: Image, x, y, w, h: Numeric)
        do
                var fx = x.to_f
                var fy = y.to_f
@@ -73,13 +73,13 @@ interface Drawable
        end
 
        # Draw image, centered at position
-       fun blit_centered( image: I, x, y: Int ) is abstract
+       fun blit_centered(image: I, x, y: Numeric) is abstract
 
        # Draw image, centered at position but rotated
-       fun blit_rotated( image: I, x, y, angle: Float ) is abstract
+       fun blit_rotated(image: I, x, y: Numeric, angle: Float) is abstract
 
        # Draw image, centered, rotated and scaled
-       fun blit_rotated_scaled( image: I, x, y, angle, scale: Float ) is abstract
+       fun blit_rotated_scaled(image: I, x, y: Numeric, angle, scale: Float) is abstract
 
        # Draw image by specifying the positon of each image corners
        # Corners are in counter-clockwise order stating top left
@@ -89,7 +89,7 @@ interface Drawable
        # | |
        # b-c
        # ~~~
-       fun blit_stretched( image: I, ax, ay, bx, by, cx, cy, dx, dy: Float )
+       fun blit_stretched(image: I, ax, ay, bx, by, cx, cy, dx, dy: Numeric)
                is abstract
 
        # Clear entire window with given color
index 6863cfc..df270e4 100644 (file)
@@ -172,7 +172,8 @@ extern class SDLDrawable `{SDL_Surface*`}
 
        redef type I: SDLImage
 
-       redef fun blit(img, x, y) `{
+       redef fun blit(img, x, y) do native_blit(img, x.to_i, y.to_i)
+       fun native_blit(img: I, x, y: Int) `{
                SDL_Rect dst;
                dst.x = x;
                dst.y = y;