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
18 fun width
: Int is extern "sdl_surface_width"
19 fun height
: Int is extern "sdl_surface_height"
21 fun lock_surface
: Int is extern "SDL_LockSurface"
22 fun unlock_surface
: Int is extern "SDL_LockSurface"
24 fun blit_on
(dest
: SDL_Surface) is extern "sdl_blit_surface"
25 fun blit_on_xy
(dest
: SDL_Surface, dest_x
: Int, dest_y
: Int) is extern "sdl_blit_surface_xy"
27 fun update_rect
(x
: Int, y
: Int, w
: Int, h
: Int) is extern "SDL_UpdateRect"
30 update_rect
(0, 0, 0, 0)
33 fun clear
is extern "sdl_clear_sruface"
35 fun to_display_format
: SDL_Surface is extern "SDL_DisplayFormat"
36 fun free
is extern "SDL_FreeSurface"
41 fun flip
is extern "SDL_Flip"
46 fun is_keyboard
: Bool is extern "sdl_evt_is_keyboard"
47 fun as_keyboard
: SDL_KeyboardEvent is extern "sdl_evt_as_keyboard"
48 fun is_mouse_button
: Bool is extern "sdl_evt_is_mouse_button"
49 fun as_mouse_button
: SDL_MouseButtonEvent is extern "sdl_evt_as_mouse_button"
50 fun is_mouse_motion
: Bool is extern "sdl_evt_is_mouse_motion"
51 fun as_mouse_motion
: SDL_MouseMotionEvent is extern "sdl_evt_as_mouse_motion"
52 fun is_expose
: Bool is extern "sdl_evt_is_expose"
53 fun is_quit
: Bool is extern "sdl_evt_is_quit"
56 universal SDL_ButtonEvent
58 fun is_pressed
: Bool is abstract
61 universal SDL_MouseEvent
63 fun x
: Int is abstract
64 fun y
: Int is abstract
67 universal SDL_KeyboardEvent
68 special SDL_ButtonEvent
69 redef fun is_pressed
: Bool is extern "sdl_keyboard_evt_state"
72 universal SDL_MouseButtonEvent
73 special SDL_ButtonEvent
74 special SDL_MouseEvent
75 redef fun is_pressed
: Bool is extern "sdl_mouse_button_evt_state"
76 redef fun x
: Int is extern "sdl_mouse_button_evt_x"
77 redef fun y
: Int is extern "sdl_mouse_button_evt_y"
78 fun button
: Int is extern "sdl_mouse_button_evt_button"
81 universal SDL_MouseMotionEvent
82 special SDL_MouseEvent
83 redef fun x
: Int is extern "sdl_mouse_evt_x"
84 redef fun y
: Int is extern "sdl_mouse_evt_y"
85 fun xrel
: Int is extern "sdl_mouse_evt_xrel"
86 fun yrel
: Int is extern "sdl_mouse_evt_yrel"
89 class SDL_EventListener
90 fun on_keyboard
(evt
: SDL_KeyboardEvent)
93 fun on_mouse_button
(evt
: SDL_MouseButtonEvent)
96 fun on_mouse_motion
(evt
: SDL_MouseMotionEvent)
106 class SDL_EventProcessor
107 var _listeners
: Array[SDL_EventListener]
109 fun add_listener
(l
: SDL_EventListener)
114 fun remove_listener
(l
: SDL_EventListener)
119 fun process_one_event
121 if sdl_poll_next_event
then
122 process_event
(sdl_current_event
)
126 fun process_all_events
128 while sdl_poll_next_event
do
129 process_event
(sdl_current_event
)
133 private fun process_event
(evt
: SDL_Event)
135 var sdl_listeners
= _listeners
136 if evt
.is_keyboard
then
137 for i
in sdl_listeners
do
138 i
.on_keyboard
(evt
.as_keyboard
)
140 else if evt
.is_mouse_button
then
141 for i
in sdl_listeners
do
142 i
.on_mouse_button
(evt
.as_mouse_button
)
144 else if evt
.is_mouse_motion
then
145 for i
in sdl_listeners
do
146 i
.on_mouse_motion
(evt
.as_mouse_motion
)
148 else if evt
.is_expose
then
149 for i
in sdl_listeners
do
152 else if evt
.is_quit
then
153 for i
in sdl_listeners
do
161 _listeners
= new Array[SDL_EventListener]
167 fun sdl_init
is extern
171 fun sdl_set_video_mode
(w
: Int, h
: Int, d
: Int): SDL_Screen is extern
172 fun sdl_set_fullscreen_video_mode
(w
: Int, h
: Int, d
: Int): SDL_Screen is extern
174 fun sdl_load_raw_bmp
(s
: String): SDL_Surface
176 return sdl_load_bmp_native
(s
.to_cstring
)
178 fun sdl_load_bmp
(s
: String): SDL_Surface
180 var raw
= sdl_load_raw_bmp
(s
)
181 var sprite
= raw
.to_display_format
186 fun sdl_load_bmp_native
(s
: NativeString): SDL_Surface is extern
188 fun sdl_show_cursor
=(b
: Bool) is extern "sdl_show_cursor_1"
189 fun sdl_show_cursor
: Bool is extern "sdl_show_cursor_0"
193 fun sdl_grab
=(b
: Bool) is extern "sdl_grab_1"
194 fun sdl_grab
: Bool is extern "sdl_grab_0"
198 fun sdl_current_event
: SDL_Event is extern
199 fun sdl_poll_next_event
: Bool is extern
203 fun sdl_get_ticks
: Int is extern
204 fun sdl_delay
(ms
: Int) is extern