Skip to content

V_DrawCroppedPatch(...) Lua exposure and improvements

This merge request separates V_DrawCroppedPatch(...)'s pscale into separate pscale (X scale) and vscale (Y scale) arguments, and gives it a colormap argument. It now has the same arguments as V_DrawStretchyFixedPatch(...), except with sx,sy,w,h tacked on at the end.
V_*SCALEPATCH and V_PERPLAYER video flag support have been added for it too, matching the exact way that V_DrawStretchyFixedPatch(...) handles those flags. V_PERPLAYER does not auto-crop at splitscreen borders. Edit: V_PERPLAYER auto-crops at splitscreen borders now when using V_DrawCroppedPatch(...).
Lastly, sx,sy,w,h have been changed from raw integers into fixed-point values, like x,y,pscale,vscale already are.

I have tested the parameters moderately, to make sure that both renderers handle the function the same way, and that neither of them do anything unexpected (as long as sx, sy, w, and h are all 0 or more; negative values will crash in software, and cause strange results in OpenGL).

Ultimately, this leads up to the next topic: V_DrawCroppedPatch(...) is now exposed to Lua as v.drawCropped(x,y,hscale,vscale,patch,flags,c,sx,sy,w,h), allowing scripters to draw patches where the top, bottom, left, and/or right sides can be cropped away. A vanilla in-game example is how the bottom of the Emerald Token coin disappears into the special stage box in intermission screens. Wiki-like usage explanation (feel free to copy to the wiki once merged, and/or edit to clear up confusion):

Function Description
v.drawCropped(fixed x, fixed y, fixed hscale, fixed vscale, patch_t patch, int flags, colormap c, fixed sx, fixed sy, fixed w, fixed h) Draws a patch at the screen coordinates given, but at a specific horizontal (hscale) and vertical (vscale) scale (e.g.: FRACUNIT is normal scale, FRACUNIT/2 is half normal scale, 2*FRACUNIT is twice normal scale, etc), with the sides cut off (sx, sy, w, h).

Notes:
* Coordinates are required to be fixed point values (e.g.: FRACUNIT is one pixel, FRACUNIT/2 is half a pixel, 2*FRACUNIT is two pixels, etc).
* flags determines the [[video flags]] given, which control extra effects such as translucency.
* c determines the colormap applied to the patch – use v.getColormap to obtain a value that can be used here, or use nil if you don't want a colormap.
* sx and sy determine how many pixels to cut off the left and top sides of the patch, respectively, (moving the remaining area left and up in the process,) and w and h determine how wide and tall an area of the patch to draw, not how much to cut off the right and bottom sides.
* sx, sy, w, and h select a region of the patch to draw regardless of hscale and vscale – if you set w to 5*FRACUNIT and set hscale to 2*FRACUNIT, the patch will take up 10 pixels of the screen, as the 5 pixels of the patch are doubled in size. The 5 pixels of the patch that get used will be the same regardless of hscale and vscale's values, referring to the patch itself.

Example Lua script, using convars called x, y, hscale, vscale, patch, flags, sx, sy, w, and h to control the cropped patch drawn while in-level, and crop to choose between v.drawCropped and v.drawStretched: LuaHud.lua

(On a slightly related note, OpenGL's V_DrawStretchyFixedPatch(...) now supports vscale being adjusted even if pscale is the default FRACUNIT. Software already supported that, and this was just an oversight from back when there was only a single scale value.)

TL;DR:

For Lua scripters:
- New HUD function v.drawCropped(x,y,hscale,vscale,patch,flags,c,sx,sy,w,h), for drawing patches where the sides are partially cropped away.
- (Additionally, bug fix, v.drawStretched(...) now supports vscale in OpenGL even when pscale is FRACUNIT. Software already supported it.)

For hardcoders:
- V_DrawCroppedPatch(...) has had pscale split into separate X and Y scales, given a colormap argument, and had sx,sy,w,h turned into fixed-point values. I did not rename the function nor make backwards-compatibility defines, given how little-used V_DrawCroppedPatch(...) is.

For changelog authors?:
- New Lua HUD function, v.drawCropped()

Edited by Zwip-Zwap Zapony

Merge request reports

Loading