diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 824825fe7b29ea7c62278652624d04b0b106e27c..dd17f67a770fe519ec65de1d9ecacddd0285ce5a 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -989,6 +989,45 @@ static int libd_drawKartString(lua_State *L) return 0; } +static int libd_setClipRect(lua_State *L) +{ + fixed_t x = luaL_checkinteger(L, 1); + fixed_t y = luaL_checkinteger(L, 2); + fixed_t w = luaL_checkinteger(L, 3); + fixed_t h = luaL_checkinteger(L, 4); + INT32 flags = luaL_optinteger(L, 5, 0); + huddrawlist_h list; + + flags &= ~V_PARAMMASK; // Don't let crashes happen. + + HUDONLY + lua_getfield(L, LUA_REGISTRYINDEX, "HUD_DRAW_LIST"); + list = (huddrawlist_h) lua_touserdata(L, -1); + lua_pop(L, 1); + + if (LUA_HUD_IsDrawListValid(list)) + LUA_HUD_AddSetClipRect(list, x, y, w, h, flags); + else + V_SetClipRect(x, y, w, h, flags); + return 0; +} + +static int libd_clearClipRect(lua_State *L) +{ + huddrawlist_h list; + + HUDONLY + lua_getfield(L, LUA_REGISTRYINDEX, "HUD_DRAW_LIST"); + list = (huddrawlist_h) lua_touserdata(L, -1); + lua_pop(L, 1); + + if (LUA_HUD_IsDrawListValid(list)) + LUA_HUD_AddClearClipRect(list); + else + V_ClearClipRect(); + return 0; +} + static int libd_titleCardStringWidth(lua_State *L) { const char *str = luaL_checkstring(L, 1); @@ -1207,6 +1246,8 @@ static luaL_Reg lib_draw[] = { {"drawString", libd_drawString}, {"drawTitleCardString", libd_drawTitleCardString}, {"drawKartString", libd_drawKartString}, + {"setClipRect", libd_setClipRect}, + {"clearClipRect", libd_clearClipRect}, // misc {"stringWidth", libd_stringWidth}, {"titleCardStringWidth", libd_titleCardStringWidth}, diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index 1c7ee31178bb95ae15f760db378fe57f93c41723..e9120c6929bf4deba5ebe734c2f1900fc7136909 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -30,6 +30,8 @@ enum drawitem_e { DI_FadeScreen, DI_DrawTitleCardString, DI_DrawKartString, + DI_SetClipRect, + DI_ClearClipRect, DI_MAX, }; @@ -394,6 +396,34 @@ void LUA_HUD_AddDrawKartString( item->flags = flags; } +void LUA_HUD_AddSetClipRect( + huddrawlist_h list, + fixed_t x, + fixed_t y, + fixed_t w, + fixed_t h, + INT32 flags +) +{ + size_t i = AllocateDrawItem(list); + drawitem_t *item = &list->items[i]; + item->type = DI_SetClipRect; + item->x = x; + item->y = y; + item->w = w; + item->h = h; + item->flags = flags; +} + +void LUA_HUD_AddClearClipRect( + huddrawlist_h list +) +{ + size_t i = AllocateDrawItem(list); + drawitem_t *item = &list->items[i]; + item->type = DI_ClearClipRect; +} + void LUA_HUD_DrawList(huddrawlist_h list) { size_t i; @@ -474,6 +504,12 @@ void LUA_HUD_DrawList(huddrawlist_h list) case DI_DrawKartString: V_DrawTimerString(item->x, item->y, item->flags, itemstr); break; + case DI_SetClipRect: + V_SetClipRect(item->x, item->y, item->w, item->h, item->flags); + break; + case DI_ClearClipRect: + V_ClearClipRect(); + break; default: I_Error("can't draw draw list item: invalid draw list item type"); continue; diff --git a/src/lua_hudlib_drawlist.h b/src/lua_hudlib_drawlist.h index fea4499cb7b4bc8610c8b858d391f4c3975ac764..1ad55ac2ad5ae2b8aaa37d6d6c7a926879e9821a 100644 --- a/src/lua_hudlib_drawlist.h +++ b/src/lua_hudlib_drawlist.h @@ -122,6 +122,17 @@ void LUA_HUD_AddDrawKartString( const char *str, INT32 flags ); +void LUA_HUD_AddSetClipRect( + huddrawlist_h list, + fixed_t x, + fixed_t y, + fixed_t w, + fixed_t h, + INT32 flags +); +void LUA_HUD_AddClearClipRect( + huddrawlist_h list +); // Draws the given draw list void LUA_HUD_DrawList(huddrawlist_h list);