Merge: Minor graphics related fixes and features
authorJean Privat <jean@pryen.org>
Tue, 20 Jan 2015 04:18:57 +0000 (11:18 +0700)
committerJean Privat <jean@pryen.org>
Tue, 20 Jan 2015 04:18:57 +0000 (11:18 +0700)
Pull-Request: #1113
Reviewed-by: Lucas Bajolet <r4pass@hotmail.com>
Reviewed-by: Alexandre Terrasa <alexandre@moz-code.org>

lib/c.nit
lib/glesv2/glesv2.nit
lib/sdl.nit

index d94ae8e..ae1b875 100644 (file)
--- a/lib/c.nit
+++ b/lib/c.nit
@@ -70,10 +70,10 @@ extern class NativeCArray `{ void * `}
        type E: nullable Object
 
        # Get element at `index`.
-       fun [](index: E): E is abstract
+       fun [](index: Int): E is abstract
 
        # Set `val` at `index`.
-       fun []=(index: E, val: E) is abstract
+       fun []=(index: Int, val: E) is abstract
 
        # Return pointer to the address to the second element of this array
        #
index 01ca43c..06803ae 100644 (file)
@@ -146,15 +146,21 @@ extern class GLProgram `{GLuint`}
                return active_attrib_name_native(index, max_size).to_s
        end
        private fun active_attrib_name_native(index, max_size: Int): NativeString `{
+               // We get more values than we need, for compatibility. At least the
+               // NVidia driver tries to fill them even if NULL.
+
                char *name = malloc(max_size);
-               glGetActiveAttrib(recv, index, max_size, NULL, NULL, NULL, name);
+               int size;
+               GLenum type;
+               glGetActiveAttrib(recv, index, max_size, NULL, &size, &type, name);
                return name;
        `}
 
        # Size of the active attribute at `index`
        fun active_attrib_size(index: Int): Int `{
                int size;
-               glGetActiveAttrib(recv, index, 0, NULL, NULL, &size, NULL);
+               GLenum type;
+               glGetActiveAttrib(recv, index, 0, NULL, &size, &type, NULL);
                return size;
        `}
 
@@ -162,8 +168,9 @@ extern class GLProgram `{GLuint`}
        #
        # May only be float related data types (single float, vectors and matrix).
        fun active_attrib_type(index: Int): GLFloatDataType `{
+               int size;
                GLenum type;
-               glGetActiveAttrib(recv, index, 0, NULL, &type, NULL, NULL);
+               glGetActiveAttrib(recv, index, 0, NULL, &size, &type, NULL);
                return type;
        `}
 
@@ -175,14 +182,17 @@ extern class GLProgram `{GLuint`}
        end
        private fun active_uniform_name_native(index, max_size: Int): NativeString `{
                char *name = malloc(max_size);
-               glGetActiveUniform(recv, index, max_size, NULL, NULL, NULL, name);
+               int size;
+               GLenum type;
+               glGetActiveUniform(recv, index, max_size, NULL, &size, &type, name);
                return name;
        `}
 
        # Size of the active uniform at `index`
        fun active_uniform_size(index: Int): Int `{
                int size;
-               glGetActiveUniform(recv, index, 0, NULL, NULL, &size, NULL);
+               GLenum type;
+               glGetActiveUniform(recv, index, 0, NULL, &size, &type, NULL);
                return size;
        `}
 
@@ -190,8 +200,9 @@ extern class GLProgram `{GLuint`}
        #
        # May be any data type supported by OpenGL ES 2.0 shaders.
        fun active_uniform_type(index: Int): GLDataType `{
-               GLenum type;
-               glGetActiveUniform(recv, index, 0, NULL, &type, NULL, NULL);
+               int size;
+               GLenum type = 0;
+               glGetActiveUniform(recv, index, 0, NULL, &size, &type, NULL);
                return type;
        `}
 end
index 5225f9f..16695e2 100644 (file)
@@ -21,6 +21,7 @@ module sdl is
 end
 
 import mnit_display
+import c
 
 in "C header" `{
        #include <unistd.h>
@@ -160,7 +161,26 @@ extern class SDLDisplay `{SDL_Surface *`}
        fun warp_mouse(x,y: Int) `{ SDL_WarpMouse(x, y); `}
 
        # Show or hide the cursor
-       fun show_cursor(show: Bool) `{ SDL_ShowCursor(show); `}
+       fun show_cursor=(val: Bool) `{ SDL_ShowCursor(val? SDL_ENABLE: SDL_DISABLE); `}
+
+       # Is the cursor visible?
+       fun show_cursor: Bool `{ SDL_ShowCursor(SDL_QUERY); `}
+
+       # Grab or release the input
+       fun grab_input=(val: Bool) `{ SDL_WM_GrabInput(val? SDL_GRAB_ON: SDL_GRAB_OFF); `}
+
+       # Is the input grabbed?
+       fun grab_input: Bool `{ SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON; `}
+
+       # Are instances of `SDLMouseMotionEvent` ignored?
+       fun ignore_mouse_motion_events: Bool `{
+               return SDL_EventState(SDL_MOUSEMOTION, SDL_QUERY);
+       `}
+
+       # Do not raise instances of `SDLMouseMotionEvent` if `val`
+       fun ignore_mouse_motion_events=(val: Bool) `{
+               SDL_EventState(SDL_MOUSEMOTION, val? SDL_IGNORE: SDL_ENABLE);
+       `}
 end
 
 # Basic Drawing figures
@@ -225,6 +245,12 @@ extern class SDLImage
        redef fun height: Int `{ return recv->h; `}
 
        fun is_ok: Bool do return not address_is_null
+
+       # Returns a reference to the pixels of the texture
+       fun pixels: NativeCByteArray `{ return recv->pixels; `}
+
+       # Does this texture has an alpha mask?
+       fun amask: Bool `{ return recv->format->Amask; `}
 end
 
 # A simple rectangle
@@ -284,10 +310,10 @@ class SDLMouseButtonEvent
        fun is_left_button: Bool do return button == 1
 
        # Is this event raised by the right button?
-       fun is_right_button: Bool do return button == 2
+       fun is_right_button: Bool do return button == 3
 
        # Is this event raised by the middle button?
-       fun is_middle_button: Bool do return button == 3
+       fun is_middle_button: Bool do return button == 2
 
        # Is this event raised by the wheel going down?
        fun is_down_wheel: Bool do return button == 4