Skip to content

Commit

Permalink
- pass clip rect as pointer to F2DDrawer::AddLine.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Aug 5, 2022
1 parent 931211b commit 735c2a9
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/am_map.cpp
Expand Up @@ -1745,7 +1745,7 @@ void DAutomap::drawMline (mline_t *ml, const AMColor &color)
twod->AddThickLine(x1, y1, x2, y2, am_linethickness, color.RGB, uint8_t(am_linealpha * 255));
} else {
// Use more efficient thin line drawing routine.
twod->AddLine(x1, y1, x2, y2, -1, -1, INT_MAX, INT_MAX, color.RGB, uint8_t(am_linealpha * 255));
twod->AddLine(x1, y1, x2, y2, nullptr, color.RGB, uint8_t(am_linealpha * 255));
}
}
}
Expand Down
12 changes: 6 additions & 6 deletions src/common/2d/v_2ddrawer.cpp
Expand Up @@ -1040,19 +1040,19 @@ void F2DDrawer::ClearScreen(PalEntry color)
//
//==========================================================================

void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, int clipx1, int clipy1, int clipx2, int clipy2, uint32_t color, uint8_t alpha)
void F2DDrawer::AddLine(double x1, double y1, double x2, double y2, const IntRect* clip, uint32_t color, uint8_t alpha)
{
PalEntry p = (PalEntry)color;
p.a = alpha;

RenderCommand dg;

if (clipx1 > 0 || clipy1 > 0 || clipx2 < GetWidth()- 1 || clipy2 < GetHeight() - 1)
if (clip != nullptr)
{
dg.mScissor[0] = clipx1 + int(offset.X);
dg.mScissor[1] = clipy1 + int(offset.Y);
dg.mScissor[2] = clipx2 + 1 + int(offset.X);
dg.mScissor[3] = clipy2 + 1 + int(offset.Y);
dg.mScissor[0] = clip->Left() + int(offset.X);
dg.mScissor[1] = clip->Top() + int(offset.Y);
dg.mScissor[2] = clip->Right() + int(offset.X);
dg.mScissor[3] = clip->Bottom() + int(offset.Y);
dg.mFlags |= DTF_Scissor;
}

Expand Down
3 changes: 2 additions & 1 deletion src/common/2d/v_2ddrawer.h
Expand Up @@ -11,6 +11,7 @@

struct DrawParms;
struct FColormap;
struct IntRect;

class DShape2DTransform : public DObject
{
Expand Down Expand Up @@ -226,7 +227,7 @@ class F2DDrawer
void AddClear(int left, int top, int right, int bottom, int palcolor, uint32_t color);


void AddLine(double x1, double y1, double x2, double y2, int cx, int cy, int cx2, int cy2, uint32_t color, uint8_t alpha = 255);
void AddLine(double x1, double y1, double x2, double y2, const IntRect* clip, uint32_t color, uint8_t alpha = 255);
void AddThickLine(int x1, int y1, int x2, int y2, double thickness, uint32_t color, uint8_t alpha = 255);
void AddPixel(int x1, int y1, uint32_t color);

Expand Down
4 changes: 2 additions & 2 deletions src/common/2d/v_draw.cpp
Expand Up @@ -1564,7 +1564,7 @@ void VirtualToRealCoordsInt(F2DDrawer *drawer, int &x, int &y, int &w, int &h,
static void DrawLine(int x0, int y0, int x1, int y1, uint32_t realcolor, int alpha)
{
if (!twod->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function");
twod->AddLine((float)x0, (float)y0, (float)x1, (float)y1, -1, -1, INT_MAX, INT_MAX, realcolor | MAKEARGB(255, 0, 0, 0), alpha);
twod->AddLine((float)x0, (float)y0, (float)x1, (float)y1, nullptr, realcolor | MAKEARGB(255, 0, 0, 0), alpha);
}

DEFINE_ACTION_FUNCTION_NATIVE(_Screen, DrawLine, DrawLine)
Expand All @@ -1589,7 +1589,7 @@ DEFINE_ACTION_FUNCTION(FCanvas, DrawLine)
PARAM_INT(y1);
PARAM_INT(color);
PARAM_INT(alpha);
self->Drawer.AddLine((float)x0, (float)y0, (float)x1, (float)y1, -1, -1, INT_MAX, INT_MAX, color | MAKEARGB(255, 0, 0, 0), alpha);
self->Drawer.AddLine((float)x0, (float)y0, (float)x1, (float)y1, nullptr, color | MAKEARGB(255, 0, 0, 0), alpha);
self->Tex->NeedUpdate();
return 0;
}
Expand Down
22 changes: 21 additions & 1 deletion src/common/utility/intrect.h
Expand Up @@ -6,7 +6,6 @@ struct IntRect
int left, top;
int width, height;


void Offset(int xofs, int yofs)
{
left += xofs;
Expand All @@ -26,6 +25,27 @@ struct IntRect
height = y - top;
}

int Left() const
{
return left;
}

int Top() const
{
return top;
}


int Right() const
{
return left + width;
}

int Bottom() const
{
return top + height;
}


};

0 comments on commit 735c2a9

Please sign in to comment.