1 # This file is part of NIT ( http://www.nitlanguage.org ).
3 # Copyright 2006 Jean Privat <jean@pryen.org>
5 # This file is free software, which comes along with NIT. This software is
6 # distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
7 # without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
8 # PARTICULAR PURPOSE. You can modify it is you want, provided this header
9 # is kept unaltered, and a notification of the changes is added.
10 # You are allowed to redistribute it and sell it, alone or is a part of
13 # Binding to the SDL multomedia library
17 fun width
: Int is extern "sdl_surface_width"
18 fun height
: Int is extern "sdl_surface_height"
20 fun lock_surface
: Int is extern "SDL_LockSurface"
21 fun unlock_surface
: Int is extern "SDL_LockSurface"
23 fun blit_on
(dest
: SDL_Surface) is extern "sdl_blit_surface"
24 fun blit_on_xy
(dest
: SDL_Surface, dest_x
: Int, dest_y
: Int) is extern "sdl_blit_surface_xy"
26 fun update_rect
(x
: Int, y
: Int, w
: Int, h
: Int) is extern "SDL_UpdateRect"
29 update_rect
(0, 0, 0, 0)
32 fun clear
is extern "sdl_clear_sruface"
34 fun to_display_format
: SDL_Surface is extern "SDL_DisplayFormat"
35 fun free
is extern "SDL_FreeSurface"
40 fun flip
is extern "SDL_Flip"
44 fun is_keyboard
: Bool is extern "sdl_evt_is_keyboard"
45 fun as_keyboard
: SDL_KeyboardEvent is extern "sdl_evt_as_keyboard"
46 fun is_mouse_button
: Bool is extern "sdl_evt_is_mouse_button"
47 fun as_mouse_button
: SDL_MouseButtonEvent is extern "sdl_evt_as_mouse_button"
48 fun is_mouse_motion
: Bool is extern "sdl_evt_is_mouse_motion"
49 fun as_mouse_motion
: SDL_MouseMotionEvent is extern "sdl_evt_as_mouse_motion"
50 fun is_expose
: Bool is extern "sdl_evt_is_expose"
51 fun is_quit
: Bool is extern "sdl_evt_is_quit"
54 extern SDL_ButtonEvent
56 fun is_pressed
: Bool is abstract
61 fun x
: Int is abstract
62 fun y
: Int is abstract
65 extern SDL_KeyboardEvent
67 redef fun is_pressed
: Bool is extern "sdl_keyboard_evt_state"
70 extern SDL_MouseButtonEvent
73 redef fun is_pressed
: Bool is extern "sdl_mouse_button_evt_state"
74 redef fun x
: Int is extern "sdl_mouse_button_evt_x"
75 redef fun y
: Int is extern "sdl_mouse_button_evt_y"
76 fun button
: Int is extern "sdl_mouse_button_evt_button"
79 extern SDL_MouseMotionEvent
81 redef fun x
: Int is extern "sdl_mouse_evt_x"
82 redef fun y
: Int is extern "sdl_mouse_evt_y"
83 fun xrel
: Int is extern "sdl_mouse_evt_xrel"
84 fun yrel
: Int is extern "sdl_mouse_evt_yrel"
87 class SDL_EventListener
88 fun on_keyboard
(evt
: SDL_KeyboardEvent)
91 fun on_mouse_button
(evt
: SDL_MouseButtonEvent)
94 fun on_mouse_motion
(evt
: SDL_MouseMotionEvent)
104 class SDL_EventProcessor
105 var _listeners
: Array[SDL_EventListener]
107 fun add_listener
(l
: SDL_EventListener)
112 fun remove_listener
(l
: SDL_EventListener)
117 fun process_one_event
119 if sdl_poll_next_event
then
120 process_event
(sdl_current_event
)
124 fun process_all_events
126 while sdl_poll_next_event
do
127 process_event
(sdl_current_event
)
131 private fun process_event
(evt
: SDL_Event)
133 var sdl_listeners
= _listeners
134 if evt
.is_keyboard
then
135 for i
in sdl_listeners
do
136 i
.on_keyboard
(evt
.as_keyboard
)
138 else if evt
.is_mouse_button
then
139 for i
in sdl_listeners
do
140 i
.on_mouse_button
(evt
.as_mouse_button
)
142 else if evt
.is_mouse_motion
then
143 for i
in sdl_listeners
do
144 i
.on_mouse_motion
(evt
.as_mouse_motion
)
146 else if evt
.is_expose
then
147 for i
in sdl_listeners
do
150 else if evt
.is_quit
then
151 for i
in sdl_listeners
do
159 _listeners
= new Array[SDL_EventListener]
165 fun sdl_init
is extern
169 fun sdl_set_video_mode
(w
: Int, h
: Int, d
: Int): SDL_Screen is extern
170 fun sdl_set_fullscreen_video_mode
(w
: Int, h
: Int, d
: Int): SDL_Screen is extern
172 fun sdl_load_raw_bmp
(s
: String): SDL_Surface
174 return sdl_load_bmp_native
(s
.to_cstring
)
176 fun sdl_load_bmp
(s
: String): SDL_Surface
178 var raw
= sdl_load_raw_bmp
(s
)
179 var sprite
= raw
.to_display_format
184 fun sdl_load_bmp_native
(s
: NativeString): SDL_Surface is extern
186 fun sdl_show_cursor
=(b
: Bool) is extern "sdl_show_cursor_1"
187 fun sdl_show_cursor
: Bool is extern "sdl_show_cursor_0"
191 fun sdl_grab
=(b
: Bool) is extern "sdl_grab_1"
192 fun sdl_grab
: Bool is extern "sdl_grab_0"
196 fun sdl_current_event
: SDL_Event is extern
197 fun sdl_poll_next_event
: Bool is extern
201 fun sdl_get_ticks
: Int is extern
202 fun sdl_delay
(ms
: Int) is extern