Remove love.graphics.setFont([<file>,] <size>) shorthand, idiom is now love.graphics.newFont([<file>,] <size>):set()

This makes sure that setFont doesn't create any fonts.
This commit is contained in:
Bart van Strien
2011-12-13 18:51:24 +01:00
parent d5d2e7b5ae
commit 9682ebecf9
6 changed files with 23 additions and 81 deletions
+11
View File
@@ -19,6 +19,7 @@
**/
// LOVE
#include "Graphics.h"
#include "wrap_Font.h"
namespace love
@@ -27,6 +28,8 @@ namespace graphics
{
namespace opengl
{
extern Graphics * instance;
Font * luax_checkfont(lua_State * L, int idx)
{
return luax_checktype<Font>(L, idx, "Font", GRAPHICS_FONT_T);
@@ -89,12 +92,20 @@ namespace opengl
return 1;
}
int w_Font_set(lua_State * L)
{
Font * t = luax_checkfont(L, 1);
instance->setFont(t);
return 0;
}
static const luaL_Reg functions[] = {
{ "getHeight", w_Font_getHeight },
{ "getWidth", w_Font_getWidth },
{ "getWrap", w_Font_getWrap },
{ "setLineHeight", w_Font_setLineHeight },
{ "getLineHeight", w_Font_getLineHeight },
{ "set", w_Font_set },
{ 0, 0 }
};
+1
View File
@@ -37,6 +37,7 @@ namespace opengl
int w_Font_getWrap(lua_State * L);
int w_Font_setLineHeight(lua_State * L);
int w_Font_getLineHeight(lua_State * L);
int w_Font_set(lua_State * L);
int luaopen_font(lua_State * L);
} // opengl
+4 -53
View File
@@ -32,7 +32,7 @@ namespace graphics
{
namespace opengl
{
static Graphics * instance = 0;
Graphics * instance = 0;
int w_checkMode(lua_State * L)
{
@@ -505,62 +505,13 @@ namespace opengl
return 4;
}
int w_setFont1(lua_State * L)
int w_setFont(lua_State * L)
{
// The second parameter is an optional int.
int size = luaL_optint(L, 2, 12);
Font * font;
bool created = false;
// If the first parameter isn't a Font, create a new one
if (!luax_istype(L, 1, GRAPHICS_FONT_T))
{
created = true;
lua_pushinteger(L, size); // push the size
lua_insert(L, 2); // move it to its proper place
// Convert to File, if necessary.
if (lua_isstring(L, 1))
luax_convobj(L, 1, "filesystem", "newFile");
// Convert to Data, if necessary.
if (luax_istype(L, 1, FILESYSTEM_FILE_T))
{
love::filesystem::File * f = luax_checktype<love::filesystem::File>(L, 1, "File", FILESYSTEM_FILE_T);
Data * d;
try
{
d = f->read();
}
catch (love::Exception & e)
{
return luaL_error(L, e.what());
}
lua_remove(L, 1); // get rid of the file
luax_newtype(L, "Data", DATA_T, (void*)d);
lua_insert(L, 1); // put it at the bottom of the stack
}
// Convert to Rasterizer, if necessary.
if (luax_istype(L, 1, DATA_T))
{
int idxs[] = {1, 2};
luax_convobj(L, idxs, 2, "font", "newRasterizer");
}
love::font::Rasterizer * rasterizer = luax_checktype<love::font::Rasterizer>(L, 1, "Rasterizer", FONT_RASTERIZER_T);
// Create the font.
font = instance->newFont(rasterizer);
if (font == 0)
return luaL_error(L, "Could not load font.");
}
else font = luax_checktype<Font>(L, 1, "Font", GRAPHICS_FONT_T);
Font * font = luax_checktype<Font>(L, 1, "Font", GRAPHICS_FONT_T);
instance->setFont(font);
if (created)
font->release();
return 0;
}
@@ -1232,7 +1183,7 @@ namespace opengl
{ "setBackgroundColor", w_setBackgroundColor },
{ "getBackgroundColor", w_getBackgroundColor },
{ "setFont1", w_setFont1 },
{ "setFont", w_setFont },
{ "getFont", w_getFont },
{ "setBlendMode", w_setBlendMode },
+1 -1
View File
@@ -67,7 +67,7 @@ namespace opengl
int w_getColor(lua_State * L);
int w_setBackgroundColor(lua_State * L);
int w_getBackgroundColor(lua_State * L);
int w_setFont1(lua_State * L);
int w_setFont(lua_State * L);
int w_getFont(lua_State * L);
int w_setBlendMode(lua_State * L);
int w_setColorMode(lua_State * L);
+2 -10
View File
@@ -1252,17 +1252,9 @@ do
return love.graphics.newFont1(font, size or 12)
end
love.graphics.setFont = function(font, size)
if type(font) == "number" or not font then
size = font
font = vera_ttf
end
return love.graphics.setFont1(font, size or 12)
end
love.graphics.print = function (...)
if not love.graphics.getFont() then
love.graphics.setFont(12)
love.graphics.newFont(12):set()
end
love.graphics.print1(...)
love.graphics.print = love.graphics.print1
@@ -1270,7 +1262,7 @@ do
love.graphics.printf = function (...)
if not love.graphics.getFont() then
love.graphics.setFont(12)
love.graphics.newFont(12):set()
end
love.graphics.printf1(...)
love.graphics.printf = love.graphics.printf1
+4 -17
View File
@@ -6203,27 +6203,14 @@ const unsigned char graphics_lua[] =
0x68, 0x69, 0x63, 0x73, 0x2e, 0x6e, 0x65, 0x77, 0x46, 0x6f, 0x6e, 0x74, 0x31, 0x28, 0x66, 0x6f, 0x6e, 0x74,
0x2c, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x31, 0x32, 0x29, 0x0a,
0x09, 0x65, 0x6e, 0x64, 0x0a,0x0a,
0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x73, 0x65, 0x74,
0x46, 0x6f, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x28, 0x66, 0x6f,
0x6e, 0x74, 0x2c, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x29, 0x0a,
0x09, 0x09, 0x69, 0x66, 0x20, 0x74, 0x79, 0x70, 0x65, 0x28, 0x66, 0x6f, 0x6e, 0x74, 0x29, 0x20, 0x3d, 0x3d,
0x20, 0x22, 0x6e, 0x75, 0x6d, 0x62, 0x65, 0x72, 0x22, 0x20, 0x6f, 0x72, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x66,
0x6f, 0x6e, 0x74, 0x20, 0x74, 0x68, 0x65, 0x6e, 0x0a,
0x09, 0x09, 0x09, 0x73, 0x69, 0x7a, 0x65, 0x20, 0x3d, 0x20, 0x66, 0x6f, 0x6e, 0x74, 0x0a,
0x09, 0x09, 0x09, 0x66, 0x6f, 0x6e, 0x74, 0x20, 0x3d, 0x20, 0x76, 0x65, 0x72, 0x61, 0x5f, 0x74, 0x74, 0x66, 0x0a,
0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
0x09, 0x09, 0x72, 0x65, 0x74, 0x75, 0x72, 0x6e, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70,
0x68, 0x69, 0x63, 0x73, 0x2e, 0x73, 0x65, 0x74, 0x46, 0x6f, 0x6e, 0x74, 0x31, 0x28, 0x66, 0x6f, 0x6e, 0x74,
0x2c, 0x20, 0x73, 0x69, 0x7a, 0x65, 0x20, 0x6f, 0x72, 0x20, 0x31, 0x32, 0x29, 0x0a,
0x09, 0x65, 0x6e, 0x64, 0x0a,0x0a,
0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x70, 0x72, 0x69,
0x6e, 0x74, 0x20, 0x3d, 0x20, 0x66, 0x75, 0x6e, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x20, 0x28, 0x2e, 0x2e, 0x2e,
0x29, 0x0a,
0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70,
0x68, 0x69, 0x63, 0x73, 0x2e, 0x67, 0x65, 0x74, 0x46, 0x6f, 0x6e, 0x74, 0x28, 0x29, 0x20, 0x74, 0x68, 0x65,
0x6e, 0x0a,
0x09, 0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x73,
0x65, 0x74, 0x46, 0x6f, 0x6e, 0x74, 0x28, 0x31, 0x32, 0x29, 0x0a,
0x09, 0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x6e,
0x65, 0x77, 0x46, 0x6f, 0x6e, 0x74, 0x28, 0x31, 0x32, 0x29, 0x3a, 0x73, 0x65, 0x74, 0x28, 0x29, 0x0a,
0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x70, 0x72,
0x69, 0x6e, 0x74, 0x31, 0x28, 0x2e, 0x2e, 0x2e, 0x29, 0x0a,
@@ -6237,8 +6224,8 @@ const unsigned char graphics_lua[] =
0x09, 0x09, 0x69, 0x66, 0x20, 0x6e, 0x6f, 0x74, 0x20, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70,
0x68, 0x69, 0x63, 0x73, 0x2e, 0x67, 0x65, 0x74, 0x46, 0x6f, 0x6e, 0x74, 0x28, 0x29, 0x20, 0x74, 0x68, 0x65,
0x6e, 0x0a,
0x09, 0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x73,
0x65, 0x74, 0x46, 0x6f, 0x6e, 0x74, 0x28, 0x31, 0x32, 0x29, 0x0a,
0x09, 0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x6e,
0x65, 0x77, 0x46, 0x6f, 0x6e, 0x74, 0x28, 0x31, 0x32, 0x29, 0x3a, 0x73, 0x65, 0x74, 0x28, 0x29, 0x0a,
0x09, 0x09, 0x65, 0x6e, 0x64, 0x0a,
0x09, 0x09, 0x6c, 0x6f, 0x76, 0x65, 0x2e, 0x67, 0x72, 0x61, 0x70, 0x68, 0x69, 0x63, 0x73, 0x2e, 0x70, 0x72,
0x69, 0x6e, 0x74, 0x66, 0x31, 0x28, 0x2e, 0x2e, 0x2e, 0x29, 0x0a,