Add renderer.text_scaled() Lua binding
lua_bindings.cpp: - Added new lua_renderer_text_scaled() function - Wraps renderer->draw_string_scaled() with proper scale support - Registered as renderer.text_scaled(x, y, text, on, scale) - Scale parameter defaults to 1 if omitted Updated all 4 games to use text_scaled(): - simon_says.lua: All text now uses text_scaled with scale=2 - tic_tac_toe.lua: All text now uses text_scaled with scale=2 - memory_match.lua: All text now uses text_scaled with scale=2 - 2048.lua: All text now uses text_scaled with scale=2 This properly uses the C++ renderer's scaled text rendering instead of workarounds in Lua, providing better performance and consistency.
This commit is contained in:
@@ -125,6 +125,23 @@ static int lua_renderer_text(lua_State* L) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
// renderer.text_scaled(x, y, text, on, scale)
|
||||
static int lua_renderer_text_scaled(lua_State* L) {
|
||||
LuaGame* game = get_game(L);
|
||||
if (!game) return 0;
|
||||
|
||||
int x = luaL_checkinteger(L, 1);
|
||||
int y = luaL_checkinteger(L, 2);
|
||||
const char* text = luaL_checkstring(L, 3);
|
||||
bool on = lua_toboolean(L, 4);
|
||||
int scale = lua_isnone(L, 5) ? 1 : luaL_checkinteger(L, 5);
|
||||
|
||||
game->renderer->set_text_color(on);
|
||||
game->renderer->draw_string_scaled(x, y, text, scale, 1);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
// renderer.triangle(x0, y0, x1, y1, x2, y2, on, filled)
|
||||
static int lua_renderer_triangle(lua_State* L) {
|
||||
LuaGame* game = get_game(L);
|
||||
@@ -281,6 +298,10 @@ void lua_bindings_register(lua_State* L, LuaGame* game) {
|
||||
lua_pushcfunction(L, lua_renderer_text);
|
||||
lua_settable(L, -3);
|
||||
|
||||
lua_pushstring(L, "text_scaled");
|
||||
lua_pushcfunction(L, lua_renderer_text_scaled);
|
||||
lua_settable(L, -3);
|
||||
|
||||
lua_pushstring(L, "triangle");
|
||||
lua_pushcfunction(L, lua_renderer_triangle);
|
||||
lua_settable(L, -3);
|
||||
|
||||
Reference in New Issue
Block a user