2 Copyright (c)2006-2007 - Brett Lajzer
4 See LICENSE for license information.
8 #include "SDL/SDL_rotozoom.h"
9 #include "SDL/SDL_image.h"
13 //function for loading a surface from many different formats (except TIFF)
14 int l_getimage(lua_State
*L
){
15 std::string
filename(luaL_checkstring(L
,1));
16 std::map
<std::string
, SDL_Surface
*>::iterator im
= image_store
.find(filename
);
18 if(im
== image_store
.end()){
19 SDL_Surface
*tmp
= IMG_Load(filename
.c_str());
20 image_store
[filename
] = tmp
;
21 lua_pushlightuserdata(L
, tmp
);
22 lua_pushinteger(L
, (lua_Integer
)tmp
->w
);
23 lua_pushinteger(L
, (lua_Integer
)tmp
->h
);
25 lua_pushlightuserdata(L
, im
->second
);
26 lua_pushinteger(L
, (lua_Integer
)im
->second
->w
);
27 lua_pushinteger(L
, (lua_Integer
)im
->second
->h
);
32 //forces an image to be unloaded from memory
33 int l_releaseimage(lua_State
*L
){
34 std::string
filename(luaL_checkstring(L
,1));
35 std::map
<std::string
, SDL_Surface
*>::iterator im
= image_store
.find(filename
);
37 if(im
!= image_store
.end()){
38 SDL_FreeSurface(im
->second
);
39 image_store
.erase(im
);
45 //function for updating the display surface
46 int l_flip(lua_State
*L
){
51 //function for simple blits (non-animated)
52 int l_blit(lua_State
*L
){
53 SDL_Surface
*tmp
= (SDL_Surface
*)lua_touserdata(L
,1);
54 int x
= lua_tointeger(L
,2);
55 int y
= lua_tointeger(L
,3);
57 SDL_Rect
*dest
= new SDL_Rect
;
63 SDL_BlitSurface(tmp
, &tmp
->clip_rect
, screen
, dest
);
68 //function for blitting a frame of an animation
69 //frames are laid out horizontally
71 int l_blitframe(lua_State
*L
){
72 SDL_Surface
*tmp
= (SDL_Surface
*)lua_touserdata(L
,1);
73 int x
= lua_tointeger(L
,2);
74 int y
= lua_tointeger(L
,3);
75 int numframes
= lua_tointeger(L
,4);
76 int frame
= lua_tointeger(L
,5);
79 SDL_Rect
*dest
= new SDL_Rect
;
82 dest
->w
= tmp
->w
/numframes
;
85 //make the src rect based on the frame info
86 SDL_Rect
*src
= new SDL_Rect
;
87 src
->x
= frame
* (tmp
->w
/numframes
);
88 src
->y
= tmp
->clip_rect
.y
;
89 src
->w
= tmp
->w
/numframes
;
92 SDL_BlitSurface(tmp
, src
, screen
, dest
);
99 int l_show_cursor(lua_State
*L
){
100 bool show
= lua_toboolean(L
, 1);
102 SDL_ShowCursor((show
? SDL_ENABLE
: SDL_DISABLE
));
107 //fills screen with a color
108 int l_fill_screen(lua_State
*L
){
109 SDL_FillRect(screen
, NULL
, SDL_MapRGB(screen
->format
, lua_tointeger(L
,1),lua_tointeger(L
,2),lua_tointeger(L
,3)));
113 //free surface interface (sad but true (-_-))
114 int l_delete_image(lua_State
*L
){
115 SDL_Surface
*tmp
= (SDL_Surface
*)lua_touserdata(L
,1);
116 SDL_FreeSurface(tmp
);
122 //rotozoomer interface
123 int l_rotzoom(lua_State
*L
){
124 SDL_Surface
*tmp
= (SDL_Surface
*)lua_touserdata(L
,1);
125 double angle
= lua_tonumber(L
,2);
126 double zoom
= lua_tonumber(L
,3);
128 SDL_Surface
*zoomed
= rotozoomSurface(tmp
, angle
, zoom
, SMOOTHING_OFF
);
130 lua_pushlightuserdata(L
, zoomed
);
131 lua_pushinteger(L
, (lua_Integer
)zoomed
->w
);
132 lua_pushinteger(L
, (lua_Integer
)zoomed
->h
);