Ejemplo n.º 1
0
int LuaFonts::WrapText(lua_State* L)
{
	CglFont* font = tofont(L, 1);
	string text(luaL_checkstring(L, 2),lua_strlen(L, 2));
	const float maxWidth   = luaL_checkfloat(L, 3);
	const float maxHeight  = luaL_optfloat(L, 4, 1e9);
	const float size       = luaL_optfloat(L, 5, font->GetSize());

	const int lines = font->WrapInPlace(text,size,maxWidth,maxHeight);

	lua_pushsstring(L, text);
	lua_pushnumber(L, lines);
	return 2;
}
Ejemplo n.º 2
0
int LuaFonts::SetOutlineColor(lua_State* L)
{
	CglFont* font = tofont(L, 1);

	const int args = lua_gettop(L); // number of arguments
	if (args < 2) {
		luaL_error(L, "Incorrect arguments to font:SetOutlineColor([\"outlineColor\"])");
	}

	float4* color = NULL;

	if (lua_istable(L, 2)) {
		color = new float4;
		const int count = ParseFloatArray(L, 2, *color, 4);
		if (count < 3) {
			luaL_error(L, "Incorrect arguments to font:SetOutlineColor([\"outlineColor\"])");
		}
		if (count == 3) {
			color->w = 1.0f;
		}
	} else if (args >= 4) {
		color = new float4;
		color->x = lua_tonumber(L, 2);
		color->y = lua_tonumber(L, 3);
		color->z = lua_tonumber(L, 4);
		color->w = luaL_optfloat(L, 5, 1.0f);
	} else if (!lua_isnil(L, 2)) {
		luaL_error(L, "Incorrect arguments to font:SetOutlineColor([\"outlineColor\"])");
	}

	font->SetOutlineColor(color);
	delete color;
	return 0;
}
Ejemplo n.º 3
0
int LuaFonts::WrapText(lua_State* L)
{
	CglFont* font = tofont(L, 1);

	const int args = lua_gettop(L); // number of arguments
	if ((args < 3) || !lua_isstring(L, 2) || !lua_isnumber(L, 3)) {
		luaL_error(L, "Incorrect arguments to font:WrapText(\"text\", maxWidth, [maxHeight], [size])");
	}

	string text(lua_tostring(L, 2),lua_strlen(L, 2));
	const float maxWidth   = lua_tonumber(L, 3);
	const float maxHeight  = luaL_optfloat(L, 4, 1e9);
	const float size       = luaL_optfloat(L, 5, font->GetSize());

	const int lines = font->WrapInPlace(text,size,maxWidth,maxHeight);

	lua_pushlstring(L, text.c_str(), text.length());
	lua_pushnumber(L, lines);
	return 2;
}
Ejemplo n.º 4
0
int LuaFonts::Print(lua_State* L)
{
	CheckDrawingEnabled(L, __FUNCTION__);

	const int args = lua_gettop(L); // number of arguments
	if ((args < 4) ||
	    !lua_isstring(L, 2) || !lua_isnumber(L, 3) || !lua_isnumber(L, 4)) {
		luaL_error(L,
		  "Incorrect arguments to font:Print(msg, x, y [,size [,\"options\"] ]");
	}

	CglFont* font = tofont(L, 1);

	const string text(lua_tostring(L, 2),lua_strlen(L, 2));
	const float x     = lua_tonumber(L, 3);
	const float y     = lua_tonumber(L, 4);
	const float size  = luaL_optfloat(L, 5, font->GetSize());

	int options = FONT_NEAREST;

	if ((args >= 6) && lua_isstring(L, 6)) {
		const char* c = lua_tostring(L, 6);
		while (*c != 0) {
	  		switch (*c) {
				case 'c': { options |= FONT_CENTER;        break; }
				case 'r': { options |= FONT_RIGHT;         break; }

				case 'a': { options |= FONT_ASCENDER;      break; }
				case 't': { options |= FONT_TOP;           break; }
				case 'v': { options |= FONT_VCENTER;       break; }
				case 'x': { options |= FONT_BASELINE;      break; }
				case 'b': { options |= FONT_BOTTOM;        break; }
				case 'd': { options |= FONT_DESCENDER;     break; }

				case 's': { options |= FONT_SHADOW;        break; }
				case 'o':
				case 'O': { options |= FONT_OUTLINE;       break; }

				case 'n': { options ^= FONT_NEAREST;       break; }
			}
	  		c++;
		}
	}

	font->glPrint(x, y, size, options, text);

	return 0;
}
Ejemplo n.º 5
0
int LuaFonts::LoadFont(lua_State* L)
{
	const string fileName   = lua_tostring(L, 1);
	const int size          = luaL_optint(L, 2, 14);
	const int outlineWidth  = luaL_optint(L, 3, 2);
	const float outlineWeight = luaL_optfloat(L, 4, 15.0f);

	CglFont** font = (CglFont**)lua_newuserdata(L, sizeof(CglFont*));
	*font = CglFont::LoadFont(fileName,size,outlineWidth,outlineWeight);

	if (*font == NULL) {
		lua_pop(L, 1);
		return 0;
	}

	luaL_getmetatable(L, "Font");
	lua_setmetatable(L, -2);
	return 1;
}