Added per-character color support to love.graphics.print/printf and Text objects. Resolves issue #865.

The aforementioned functions now optionally accept an array instead of a plain string. The array is in the format of: {{r, g, b [, a]}, "first colored text, ", {r, g, b [, a]}, "second colored text", ...}, where the color values specify the color to use in the next section of the text.
This commit is contained in:
Alex Szpakowski
2015-11-01 23:17:46 -04:00
parent 799e303673
commit 389b91cf6f
9 changed files with 399 additions and 195 deletions
@@ -851,7 +851,9 @@ int w_newText(lua_State *L)
luax_catchexcept(L, [&](){ t = instance()->newText(font); });
else
{
std::string text = luax_checkstring(L, 2);
std::vector<Font::ColoredString> text;
luax_checkcoloredstring(L, 2, text);
luax_catchexcept(L, [&](){ t = instance()->newText(font, text); });
}
@@ -1466,7 +1468,9 @@ int w_draw(lua_State *L)
int w_print(lua_State *L)
{
std::string str = luax_checkstring(L, 1);
std::vector<Font::ColoredString> str;
luax_checkcoloredstring(L, 1, str);
float x = (float)luaL_optnumber(L, 2, 0.0);
float y = (float)luaL_optnumber(L, 3, 0.0);
float angle = (float)luaL_optnumber(L, 4, 0.0f);
@@ -1485,7 +1489,9 @@ int w_print(lua_State *L)
int w_printf(lua_State *L)
{
std::string str = luax_checkstring(L, 1);
std::vector<Font::ColoredString> str;
luax_checkcoloredstring(L, 1, str);
float x = (float)luaL_checknumber(L, 2);
float y = (float)luaL_checknumber(L, 3);
float wrap = (float)luaL_checknumber(L, 4);