diff --git a/src/am_map.cpp b/src/am_map.cpp index 491a5cbdfe..7c67a7c370 100644 --- a/src/am_map.cpp +++ b/src/am_map.cpp @@ -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)); } } } diff --git a/src/common/2d/v_2ddrawer.cpp b/src/common/2d/v_2ddrawer.cpp index 529c983231..bae286b844 100644 --- a/src/common/2d/v_2ddrawer.cpp +++ b/src/common/2d/v_2ddrawer.cpp @@ -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; } diff --git a/src/common/2d/v_2ddrawer.h b/src/common/2d/v_2ddrawer.h index 1d9af77cbe..2ac631e5d1 100644 --- a/src/common/2d/v_2ddrawer.h +++ b/src/common/2d/v_2ddrawer.h @@ -11,6 +11,7 @@ struct DrawParms; struct FColormap; +struct IntRect; class DShape2DTransform : public DObject { @@ -226,7 +227,7 @@ public: 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); diff --git a/src/common/2d/v_draw.cpp b/src/common/2d/v_draw.cpp index 85f5e76c96..807a207d17 100644 --- a/src/common/2d/v_draw.cpp +++ b/src/common/2d/v_draw.cpp @@ -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) @@ -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; } diff --git a/src/common/utility/intrect.h b/src/common/utility/intrect.h index 3cda7613e6..97e9bd90a0 100644 --- a/src/common/utility/intrect.h +++ b/src/common/utility/intrect.h @@ -6,7 +6,6 @@ struct IntRect int left, top; int width, height; - void Offset(int xofs, int yofs) { left += xofs; @@ -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; + } + };