pass RenWindow by argument (#1321)

* pass RenWindow to all renderer functions that need it

* pass RenWindow to all rencache functions that need it
This commit is contained in:
Jan
2023-08-19 12:30:41 +08:00
committed by takase1121
parent 5907118683
commit a951c3cd39
7 changed files with 73 additions and 70 deletions
+8 -8
View File
@@ -90,7 +90,7 @@ static int f_font_load(lua_State *L) {
return ret_code;
RenFont** font = lua_newuserdata(L, sizeof(RenFont*));
*font = ren_font_load(filename, size, antialiasing, hinting, style);
*font = ren_font_load(&window_renderer, filename, size, antialiasing, hinting, style);
if (!*font)
return luaL_error(L, "failed to load font");
luaL_setmetatable(L, API_TYPE_FONT);
@@ -130,7 +130,7 @@ static int f_font_copy(lua_State *L) {
}
for (int i = 0; i < FONT_FALLBACK_MAX && fonts[i]; ++i) {
RenFont** font = lua_newuserdata(L, sizeof(RenFont*));
*font = ren_font_copy(fonts[i], size, antialiasing, hinting, style);
*font = ren_font_copy(&window_renderer, fonts[i], size, antialiasing, hinting, style);
if (!*font)
return luaL_error(L, "failed to copy font");
luaL_setmetatable(L, API_TYPE_FONT);
@@ -198,7 +198,7 @@ static int f_font_get_width(lua_State *L) {
size_t len;
const char *text = luaL_checklstring(L, 2, &len);
lua_pushnumber(L, ren_font_group_get_width(fonts, text, len));
lua_pushnumber(L, ren_font_group_get_width(&window_renderer, fonts, text, len));
return 1;
}
@@ -217,7 +217,7 @@ static int f_font_get_size(lua_State *L) {
static int f_font_set_size(lua_State *L) {
RenFont* fonts[FONT_FALLBACK_MAX]; font_retrieve(L, fonts, 1);
float size = luaL_checknumber(L, 2);
ren_font_group_set_size(fonts, size);
ren_font_group_set_size(&window_renderer, fonts, size);
return 0;
}
@@ -276,7 +276,7 @@ static int f_show_debug(lua_State *L) {
static int f_get_size(lua_State *L) {
int w, h;
ren_get_size(&w, &h);
ren_get_size(&window_renderer, &w, &h);
lua_pushnumber(L, w);
lua_pushnumber(L, h);
return 2;
@@ -284,13 +284,13 @@ static int f_get_size(lua_State *L) {
static int f_begin_frame(UNUSED lua_State *L) {
rencache_begin_frame();
rencache_begin_frame(&window_renderer);
return 0;
}
static int f_end_frame(UNUSED lua_State *L) {
rencache_end_frame();
rencache_end_frame(&window_renderer);
// clear the font reference table
lua_newtable(L);
lua_rawseti(L, LUA_REGISTRYINDEX, RENDERER_FONT_REF);
@@ -348,7 +348,7 @@ static int f_draw_text(lua_State *L) {
float x = luaL_checknumber(L, 3);
int y = luaL_checknumber(L, 4);
RenColor color = checkcolor(L, 5, 255);
x = rencache_draw_text(fonts, text, len, x, y, color);
x = rencache_draw_text(&window_renderer, fonts, text, len, x, y, color);
lua_pushnumber(L, x);
return 1;
}
+2 -4
View File
@@ -37,8 +37,6 @@
#endif
#endif
extern RenWindow window_renderer;
static const char* button_name(int button) {
switch (button) {
case SDL_BUTTON_LEFT : return "left";
@@ -188,7 +186,7 @@ top:
case SDL_WINDOWEVENT:
if (e.window.event == SDL_WINDOWEVENT_RESIZED) {
ren_resize_window();
ren_resize_window(&window_renderer);
lua_pushstring(L, "resized");
/* The size below will be in points. */
lua_pushinteger(L, e.window.data1);
@@ -473,7 +471,7 @@ static int f_set_window_size(lua_State *L) {
double y = luaL_checknumber(L, 4);
SDL_SetWindowSize(window_renderer.window, w, h);
SDL_SetWindowPosition(window_renderer.window, x, y);
ren_resize_window();
ren_resize_window(&window_renderer);
return 0;
}