srb2::Draw: inherit global cliprect by default

- Let srb2::Draw be mixed seamlessly with C-style
  V_SetClipRect
This commit is contained in:
James R 2024-01-26 02:02:57 -08:00
parent fc40d86a73
commit 510c82ca6d
5 changed files with 31 additions and 8 deletions

View file

@ -251,18 +251,23 @@ void Chain::sticker(patch_t* end_graphic, UINT8 color) const
Chain::Clipper::Clipper(const Chain& chain)
{
V_SetClipRect(
FloatToFixed(chain.clipx1_),
FloatToFixed(chain.clipy1_),
FloatToFixed(chain.clipx2_ - chain.clipx1_),
FloatToFixed(chain.clipy2_ - chain.clipy1_),
chain.flags_
);
V_SaveClipRect(&save_);
if (chain.clip_)
{
V_SetClipRect(
FloatToFixed(chain.clipx1_),
FloatToFixed(chain.clipy1_),
FloatToFixed(chain.clipx2_ - chain.clipx1_),
FloatToFixed(chain.clipy2_ - chain.clipy1_),
chain.flags_
);
}
}
Chain::Clipper::~Clipper()
{
V_ClearClipRect();
V_RestoreClipRect(&save_);
}
patch_t* Draw::cache_patch(const char* name)

View file

@ -195,6 +195,9 @@ public:
{
explicit Clipper(const Chain& chain);
~Clipper();
private:
cliprect_t save_;
};
float x_ = 0.f;
@ -207,6 +210,7 @@ public:
float clipx2_ = BASEVIDWIDTH;
float clipy1_ = 0.f;
float clipy2_ = BASEVIDHEIGHT;
bool clip_ = false;
INT32 flags_ = 0;

View file

@ -87,6 +87,7 @@ inline Draw::Chain& Draw::Chain::clipx(float left, float right)
{
clipx1_ = left;
clipx2_ = right;
clip_ = true;
return *this;
}
@ -94,6 +95,7 @@ inline Draw::Chain& Draw::Chain::clipy(float top, float bottom)
{
clipy1_ = top;
clipy2_ = bottom;
clip_ = true;
return *this;
}

View file

@ -715,6 +715,16 @@ void V_ClearClipRect(void)
cliprect.enabled = false;
}
void V_SaveClipRect(cliprect_t *copy)
{
*copy = cliprect;
}
void V_RestoreClipRect(const cliprect_t *copy)
{
cliprect = *copy;
}
static UINT8 hudplusalpha[11] = { 10, 8, 6, 4, 2, 0, 0, 0, 0, 0, 0};
static UINT8 hudminusalpha[11] = { 10, 9, 9, 8, 8, 7, 7, 6, 6, 5, 5};

View file

@ -192,6 +192,8 @@ struct cliprect_t
const cliprect_t *V_GetClipRect(void);
void V_SetClipRect(fixed_t x, fixed_t y, fixed_t w, fixed_t h, INT32 flags);
void V_ClearClipRect(void);
void V_SaveClipRect(cliprect_t *copy);
void V_RestoreClipRect(const cliprect_t *copy);
// defines for old functions
#define V_DrawPatch(x,y,s,p) V_DrawFixedPatch((x)<<FRACBITS, (y)<<FRACBITS, FRACUNIT, s|V_NOSCALESTART|V_NOSCALEPATCH, p, NULL)