Added resources, and changed slightly how wrappers expose functions.

This commit is contained in:
rude
2009-07-30 00:37:43 +02:00
parent 8f4662c8a2
commit 0c241a14fb
30 changed files with 454 additions and 222 deletions
+4 -4
View File
@@ -400,9 +400,9 @@ namespace opengl
return new Frame(x, y, w, h, sw, sh);
}
Font * Graphics::newFont(love::filesystem::File * file, int size)
Font * Graphics::newFont(Data * data, int size)
{
Font * font = new TrueTypeFont(file, size);
Font * font = new TrueTypeFont(data, size);
// Load it and check for errors.
if(!font->load())
@@ -482,12 +482,12 @@ namespace opengl
currentFont->retain();
}
void Graphics::setFont( love::filesystem::File * file, int size )
void Graphics::setFont( Data * data, int size )
{
if(currentFont != 0)
currentFont->release();
currentFont = new TrueTypeFont(file, size);
currentFont = new TrueTypeFont(data, size);
currentFont->load();
}
+3 -3
View File
@@ -244,7 +244,7 @@ namespace opengl
/**
* Creates a Font object.
**/
Font * newFont(love::filesystem::File * file, int size);
Font * newFont(Data * data, int size);
/**
* Creates an ImageFont object.
@@ -284,10 +284,10 @@ namespace opengl
* Sets a default font. The font is
* loaded and sent to the GPU every time this is called,
* so no over-using.
* @param file File from which to load the font.
* @param data Data
* @param size The size of the font.
**/
void setFont( love::filesystem::File * file, int size = 12);
void setFont( Data * data, int size = 12);
/**
* Gets the current Font, or nil if none.
+4 -6
View File
@@ -131,16 +131,16 @@ namespace opengl
FT_Done_Glyph(glyph);
}
TrueTypeFont::TrueTypeFont(love::filesystem::File * file, int size)
: Font(size), file(file), textures(0), list(0)
TrueTypeFont::TrueTypeFont(Data * data, int size)
: Font(size), data(data), textures(0), list(0)
{
file->retain();
data->retain();
}
TrueTypeFont::~TrueTypeFont()
{
unload();
file->release();
data->release();
}
void TrueTypeFont::print(string text, float x, float y) const
@@ -200,8 +200,6 @@ namespace opengl
bool TrueTypeFont::loadVolatile()
{
Data * data = file->read();
trueHeight = size;
+2 -2
View File
@@ -53,7 +53,7 @@ namespace opengl
{
private:
love::filesystem::File * file;
Data * data;
protected:
@@ -93,7 +93,7 @@ namespace opengl
* @param file The file containing the TrueTypeFont data.
* @param size The size of the TrueTypeFont.
**/
TrueTypeFont(love::filesystem::File * file, int size);
TrueTypeFont(Data * data, int size);
/**
* Calls unload().
+31 -9
View File
@@ -174,17 +174,28 @@ namespace opengl
int _wrap_newFont(lua_State * L)
{
Data * d = 0;
// Convert to File, if necessary.
if(lua_isstring(L, 1))
luax_strtofile(L, 1);
// Check the value.
love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 1, "File", LOVE_FILESYSTEM_FILE_BITS);
if(luax_istype(L, 1, LOVE_FILESYSTEM_FILE_BITS))
{
// Check the value.
love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 1, "File", LOVE_FILESYSTEM_FILE_BITS);
d = file->read();
}
else if(luax_istype(L, 1, LOVE_DATA_BITS))
{
d = luax_checktype<Data>(L, 1, "Data", LOVE_DATA_BITS);
}
// Second optional parameter can be a number:
int size = luaL_optint(L, 2, 12);
Font * font = instance->newFont(file, size);
Font * font = instance->newFont(d, size);
if(font == 0)
return luaL_error(L, "Could not load the font");
@@ -284,7 +295,13 @@ namespace opengl
if(luax_istype(L, 1, LOVE_FILESYSTEM_FILE_BITS))
{
love::filesystem::File * file = luax_checktype<love::filesystem::File>(L, 1, "File", LOVE_FILESYSTEM_FILE_BITS);
instance->setFont(file, size);
instance->setFont(file->read(), size);
return 0;
}
else if(luax_istype(L, 1, LOVE_DATA_BITS))
{
Data * data = luax_checktype<Data>(L, 1, "Data", LOVE_DATA_BITS);
instance->setFont(data, size);
return 0;
}
@@ -524,7 +541,7 @@ namespace opengl
return 0;
}
int _wrap_print(lua_State * L)
int _wrap_print1(lua_State * L)
{
const char * str = luaL_checkstring(L, 1);
float x = (float)luaL_checknumber(L, 2);
@@ -553,7 +570,7 @@ namespace opengl
return 0;
}
int _wrap_printf(lua_State * L)
int _wrap_printf1(lua_State * L)
{
const char * str = luaL_checkstring(L, 1);
float x = (float)luaL_checknumber(L, 2);
@@ -693,6 +710,7 @@ namespace opengl
{ "getBackgroundColor", _wrap_getBackgroundColor },
{ "setFont", _wrap_setFont },
{ "getFont", _wrap_getFont },
{ "setBlendMode", _wrap_setBlendMode },
{ "setColorMode", _wrap_setColorMode },
@@ -717,8 +735,8 @@ namespace opengl
{ "drawf", _wrap_drawf },
{ "drawTest", _wrap_drawTest },
{ "print", _wrap_print },
{ "printf", _wrap_printf },
{ "print1", _wrap_print1 },
{ "printf1", _wrap_printf1 },
{ "setCaption", _wrap_setCaption },
{ "getCaption", _wrap_getCaption },
@@ -775,8 +793,12 @@ namespace opengl
}
luax_register_gc(L, "love.graphics", instance);
luax_register_module(L, wrap_Graphics_functions, wrap_Graphics_types, "graphics");
return luax_register_module(L, wrap_Graphics_functions, wrap_Graphics_types);
//# include <scripts/graphics.lua.h>
luaL_dofile(L, "../../src/scripts/graphics.lua");
return 0;
}
} // opengl
+2 -2
View File
@@ -78,8 +78,8 @@ namespace opengl
int _wrap_draw(lua_State * L);
int _wrap_draws(lua_State * L);
int _wrap_drawTest(lua_State * L);
int _wrap_print(lua_State * L);
int _wrap_printf(lua_State * L);
int _wrap_print1(lua_State * L);
int _wrap_printf1(lua_State * L);
int _wrap_point(lua_State * L);
int _wrap_line(lua_State * L);
int _wrap_triangle(lua_State * L);