benches/strings: add .gitignore and `make clean`
[nit.git] / lib / sdl.nit
index 26ae459..6de6d2d 100644 (file)
 
 # SDL display support (used in Linux for windows and inputes only)
 module sdl is
-       c_compiler_option(exec("sdl-config", "--cflags"))
-       c_linker_option(exec("sdl-config", "--libs"), "-lSDL_image -lSDL_ttf")
+       cflags exec("sdl-config", "--cflags")
+       ldflags(exec("sdl-config", "--libs"), "-lSDL_image -lSDL_ttf")
 end
 
 import mnit_display
+import c
 
 in "C header" `{
        #include <unistd.h>
@@ -180,6 +181,12 @@ extern class SDLDisplay `{SDL_Surface *`}
        fun ignore_mouse_motion_events=(val: Bool) `{
                SDL_EventState(SDL_MOUSEMOTION, val? SDL_IGNORE: SDL_ENABLE);
        `}
+
+       # Does `self` has the mouse focus?
+       fun mouse_focus: Bool `{ return SDL_GetAppState() & SDL_APPMOUSEFOCUS; `}
+
+       # Does `self` has the input focus?
+       fun input_focus: Bool `{ return SDL_GetAppState() & SDL_APPINPUTFOCUS; `}
 end
 
 # Basic Drawing figures
@@ -244,6 +251,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
@@ -303,10 +316,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
@@ -362,27 +375,27 @@ class SDLKeyEvent
        super KeyEvent
        super SDLInputEvent
 
-       var key_name: String
+       redef var name
        var down: Bool
 
        init (key_name: String, down: Bool)
        do
-               self.key_name = key_name
+               self.name = key_name
                self.down = down
        end
 
        redef fun to_c: nullable Char
        do
-               if key_name.length == 1 then return key_name.chars.first
+               if name.length == 1 then return name.chars.first
                return null
        end
 
        redef fun to_s
        do
                if down then
-                       return "KeyboardEvent key {key_name} down"
+                       return "KeyboardEvent key {name} down"
                else
-                       return "KeyboardEvent key {key_name} up"
+                       return "KeyboardEvent key {name} up"
                end
        end
 
@@ -390,13 +403,13 @@ class SDLKeyEvent
        redef fun is_down do return down
 
        # Return true if the key is the up arrow
-       redef fun is_arrow_up do return key_name == "up"
+       redef fun is_arrow_up do return name == "up"
        # Return true if the key is the left arrow
-       redef fun is_arrow_left do return key_name == "left"
+       redef fun is_arrow_left do return name == "left"
        # Return true if the key is the down arrow
-       redef fun is_arrow_down do return key_name == "down"
+       redef fun is_arrow_down do return name == "down"
        # Return true if the key is the right arrow
-       redef fun is_arrow_right do return key_name == "right"
+       redef fun is_arrow_right do return name == "right"
 end
 
 class SDLQuitEvent