2 #include "SDL/SDL_rotozoom.h"
3 #include "SDL/SDL_image.h"
7 //function for loading a surface from many different formats (except TIFF)
8 static int l_getimage(lua_State
*L
){
9 std::string
filename(luaL_checkstring(L
,1));
10 std::map
<std::string
, SDL_Surface
*>::iterator im
= image_store
.find(filename
);
12 if(im
== image_store
.end()){
13 SDL_Surface
*tmp
= IMG_Load(filename
.c_str());
14 image_store
[filename
] = tmp
;
15 lua_pushlightuserdata(L
, tmp
);
16 lua_pushinteger(L
, (lua_Integer
)tmp
->w
);
17 lua_pushinteger(L
, (lua_Integer
)tmp
->h
);
19 lua_pushlightuserdata(L
, im
->second
);
20 lua_pushinteger(L
, (lua_Integer
)im
->second
->w
);
21 lua_pushinteger(L
, (lua_Integer
)im
->second
->h
);
26 //forces an image to be unloaded from memory
27 static int l_releaseimage(lua_State
*L
){
28 std::string
filename(luaL_checkstring(L
,1));
29 std::map
<std::string
, SDL_Surface
*>::iterator im
= image_store
.find(filename
);
31 if(im
!= image_store
.end()){
32 SDL_FreeSurface(im
->second
);
33 image_store
.erase(im
);
39 //function for updating the display surface
40 static int l_flip(lua_State
*L
){
45 //function for simple blits (non-animated)
46 static int l_blit(lua_State
*L
){
47 SDL_Surface
*tmp
= (SDL_Surface
*)lua_touserdata(L
,1);
48 int x
= lua_tointeger(L
,2);
49 int y
= lua_tointeger(L
,3);
51 SDL_Rect
*dest
= new SDL_Rect
;
57 SDL_BlitSurface(tmp
, &tmp
->clip_rect
, screen
, dest
);
62 //function for blitting a frame of an animation
63 //frames are laid out horizontally
65 static int l_blitframe(lua_State
*L
){
66 SDL_Surface
*tmp
= (SDL_Surface
*)lua_touserdata(L
,1);
67 int x
= lua_tointeger(L
,2);
68 int y
= lua_tointeger(L
,3);
69 int numframes
= lua_tointeger(L
,4);
70 int frame
= lua_tointeger(L
,5);
73 SDL_Rect
*dest
= new SDL_Rect
;
76 dest
->w
= tmp
->w
/numframes
;
79 //make the src rect based on the frame info
80 SDL_Rect
*src
= new SDL_Rect
;
81 src
->x
= frame
* (tmp
->w
/numframes
);
82 src
->y
= tmp
->clip_rect
.y
;
83 src
->w
= tmp
->w
/numframes
;
86 SDL_BlitSurface(tmp
, src
, screen
, dest
);
93 static int l_show_cursor(lua_State
*L
){
94 bool show
= lua_toboolean(L
, 1);
96 SDL_ShowCursor((show
? SDL_ENABLE
: SDL_DISABLE
));
101 //fills screen with a color
102 static int l_fill_screen(lua_State
*L
){
103 SDL_FillRect(screen
, NULL
, SDL_MapRGB(screen
->format
, lua_tointeger(L
,1),lua_tointeger(L
,2),lua_tointeger(L
,3)));
107 //free surface interface (sad but true (-_-))
108 static int l_delete_image(lua_State
*L
){
109 SDL_Surface
*tmp
= (SDL_Surface
*)lua_touserdata(L
,1);
110 SDL_FreeSurface(tmp
);
116 //rotozoomer interface
117 static int l_rotzoom(lua_State
*L
){
118 SDL_Surface
*tmp
= (SDL_Surface
*)lua_touserdata(L
,1);
119 double angle
= lua_tonumber(L
,2);
120 double zoom
= lua_tonumber(L
,3);
122 SDL_Surface
*zoomed
= rotozoomSurface(tmp
, angle
, zoom
, SMOOTHING_OFF
);
124 lua_pushlightuserdata(L
, zoomed
);
125 lua_pushinteger(L
, (lua_Integer
)zoomed
->w
);
126 lua_pushinteger(L
, (lua_Integer
)zoomed
->h
);