mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Added resources, and changed slightly how wrappers expose functions.
This commit is contained in:
@@ -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();
|
||||
}
|
||||
|
||||
|
||||
@@ -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.
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
|
||||
@@ -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().
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user