From 39b70b36861d85f02314dc0701e223e751eb1daa Mon Sep 17 00:00:00 2001 From: alufolie91 Date: Fri, 1 Dec 2023 16:13:45 +0100 Subject: [PATCH] add drawstretchypatch lua support --- src/lua_hudlib.c | 37 +++++++++++++++++++++++++++++++++++++ src/lua_hudlib_drawlist.c | 27 +++++++++++++++++++++++++++ src/lua_hudlib_drawlist.h | 10 ++++++++++ 3 files changed, 74 insertions(+) diff --git a/src/lua_hudlib.c b/src/lua_hudlib.c index 340bc1352..04bbaa928 100644 --- a/src/lua_hudlib.c +++ b/src/lua_hudlib.c @@ -596,6 +596,42 @@ static int libd_drawOnMinimap(lua_State *L) return 0; } +static int libd_drawStretched(lua_State *L) +{ + fixed_t x, y, hscale, vscale; + INT32 flags; + patch_t *patch; + UINT8 *colormap = NULL; + huddrawlist_h list; + + HUDONLY + x = luaL_checkinteger(L, 1); + y = luaL_checkinteger(L, 2); + hscale = luaL_checkinteger(L, 3); + if (hscale < 0) + return luaL_error(L, "negative horizontal scale"); + vscale = luaL_checkinteger(L, 4); + if (vscale < 0) + return luaL_error(L, "negative vertical scale"); + patch = *((patch_t **)luaL_checkudata(L, 5, META_PATCH)); + flags = luaL_optinteger(L, 6, 0); + if (!lua_isnoneornil(L, 7)) + colormap = *((UINT8 **)luaL_checkudata(L, 7, META_COLORMAP)); + + flags &= ~V_PARAMMASK; // Don't let crashes happen. + + 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_AddDrawStretched(list, x, y, hscale, vscale, patch, flags, colormap); + else + V_DrawStretchyFixedPatch(x, y, hscale, vscale, flags, patch, colormap); + return 0; +} + + static int libd_drawNum(lua_State *L) { INT32 x, y, flags, num; @@ -913,6 +949,7 @@ static luaL_Reg lib_draw[] = { {"cachePatch", libd_cachePatch}, {"draw", libd_draw}, {"drawScaled", libd_drawScaled}, + {"drawStretched", libd_drawStretched}, {"drawNum", libd_drawNum}, {"drawPaddedNum", libd_drawPaddedNum}, {"drawPingNum", libd_drawPingNum}, diff --git a/src/lua_hudlib_drawlist.c b/src/lua_hudlib_drawlist.c index eedbff910..c543c15d8 100644 --- a/src/lua_hudlib_drawlist.c +++ b/src/lua_hudlib_drawlist.c @@ -20,6 +20,7 @@ enum drawitem_e { DI_Draw = 0, DI_DrawScaled, + DI_DrawStretched, DI_DrawNum, DI_DrawPaddedNum, DI_DrawPingNum, @@ -216,6 +217,29 @@ void LUA_HUD_AddDrawScaled( item->colormap = colormap; } +void LUA_HUD_AddDrawStretched( + huddrawlist_h list, + fixed_t x, + fixed_t y, + fixed_t hscale, + fixed_t vscale, + patch_t *patch, + INT32 flags, + UINT8 *colormap +) +{ + size_t i = AllocateDrawItem(list); + drawitem_t *item = &list->items[i]; + item->type = DI_DrawStretched; + item->x = x; + item->y = y; + item->hscale = hscale; + item->vscale = vscale; + item->patch = patch; + item->flags = flags; + item->colormap = colormap; +} + void LUA_HUD_AddDrawNum( huddrawlist_h list, INT32 x, @@ -377,6 +401,9 @@ void LUA_HUD_DrawList(huddrawlist_h list) case DI_DrawScaled: V_DrawFixedPatch(item->x, item->y, item->scale, item->flags, item->patch, item->colormap); break; + case DI_DrawStretched: + V_DrawStretchyFixedPatch(item->x, item->y, item->hscale, item->vscale, item->flags, item->patch, item->colormap); + break; case DI_DrawNum: V_DrawTallNum(item->x, item->y, item->flags, item->num); break; diff --git a/src/lua_hudlib_drawlist.h b/src/lua_hudlib_drawlist.h index 992578778..4354b6f95 100644 --- a/src/lua_hudlib_drawlist.h +++ b/src/lua_hudlib_drawlist.h @@ -42,6 +42,16 @@ void LUA_HUD_AddDraw( INT32 flags, UINT8 *colormap ); +void LUA_HUD_AddDrawStretched( + huddrawlist_h list, + fixed_t x, + fixed_t y, + fixed_t hscale, + fixed_t vscale, + patch_t *patch, + INT32 flags, + UINT8 *colormap +); void LUA_HUD_AddDrawScaled( huddrawlist_h list, fixed_t x,