Fixed oversights in collision code. More sound control.
[luagame.git] / funcs_font.cpp
blob02bfee43145e302c302208f378607ee0ccfc89d4
1 /*
2 Copyright (c)2006-2007 - Brett Lajzer
4 See LICENSE for license information.
5 */
7 #include <map>
8 #include <string>
9 #include "lua.hpp"
10 #include "SDL/SDL.h"
11 #include "SDL/SDL_ttf.h"
12 #include "funcs_font.h"
14 //loads a font and returns a pointer to it
15 int l_load_font(lua_State *L){
16 TTF_Font *font;
17 font = TTF_OpenFont(luaL_checkstring(L,1), (int)lua_tonumber(L,2));
19 lua_pushlightuserdata(L,font);
20 return 1;
23 //unloads a font
24 int l_close_font(lua_State *L){
25 TTF_CloseFont((TTF_Font*)lua_touserdata(L,1));
26 lua_pushnil(L);
27 return 1;
30 //gets dimensions of a string as rendered with a font
31 int l_font_string_metrics(lua_State *L){
32 int w, h;
33 TTF_SizeUTF8((TTF_Font*)lua_touserdata(L,1), luaL_checkstring(L,2), &w, &h);
35 lua_pushinteger(L, w);
36 lua_pushinteger(L, h);
38 return 2;
41 //render a string in a font
42 int l_render_string(lua_State *L){
43 SDL_Surface *temp;
44 SDL_Color color;
46 color.r = (int)lua_tonumber(L,3);
47 color.g = (int)lua_tonumber(L,4);
48 color.b = (int)lua_tonumber(L,5);
50 temp = TTF_RenderUTF8_Blended((TTF_Font*)lua_touserdata(L,1),luaL_checkstring(L,2), color);
52 lua_pushlightuserdata(L,temp);
53 lua_pushinteger(L, temp->w);
54 lua_pushinteger(L, temp->h);
56 return 3;