diff --git a/src/v_2ddrawer.cpp b/src/v_2ddrawer.cpp index ad5effb30..a09ecd5fd 100644 --- a/src/v_2ddrawer.cpp +++ b/src/v_2ddrawer.cpp @@ -594,6 +594,46 @@ void F2DDrawer::AddLine(int x1, int y1, int x2, int y2, int palcolor, uint32_t c // //========================================================================== +void F2DDrawer::AddThickLine(int x1, int y1, int x2, int y2, double thickness, uint32_t color) +{ + PalEntry p = (PalEntry)color; + + DVector2 point0(x1, y1); + DVector2 point1(x2, y2); + + DVector2 delta = point1 - point0; + DVector2 perp(-delta.Y, delta.X); + perp.MakeUnit(); + perp *= thickness / 2; + + DVector2 corner0 = point0 + perp; + DVector2 corner1 = point0 - perp; + DVector2 corner2 = point1 + perp; + DVector2 corner3 = point1 - perp; + + RenderCommand dg; + + dg.mType = DrawTypeTriangles; + dg.mVertCount = 4; + dg.mVertIndex = (int)mVertices.Reserve(4); + dg.mRenderStyle = LegacyRenderStyles[STYLE_Translucent]; + auto ptr = &mVertices[dg.mVertIndex]; + ptr->Set(corner0.X, corner0.Y, 0, 0, 0, p); ptr++; + ptr->Set(corner1.X, corner1.Y, 0, 0, 0, p); ptr++; + ptr->Set(corner2.X, corner2.Y, 0, 0, 0, p); ptr++; + ptr->Set(corner3.X, corner3.Y, 0, 0, 0, p); ptr++; + dg.mIndexIndex = mIndices.Size(); + dg.mIndexCount += 6; + AddIndices(dg.mVertIndex, 6, 0, 1, 2, 1, 3, 2); + AddCommand(&dg); +} + +//========================================================================== +// +// +// +//========================================================================== + void F2DDrawer::AddPixel(int x1, int y1, int palcolor, uint32_t color) { PalEntry p = color ? (PalEntry)color : GPalette.BaseColors[palcolor]; diff --git a/src/v_2ddrawer.h b/src/v_2ddrawer.h index ec88dc908..f60665e9e 100644 --- a/src/v_2ddrawer.h +++ b/src/v_2ddrawer.h @@ -149,6 +149,7 @@ public: void AddLine(int x1, int y1, int x2, int y2, int palcolor, uint32_t color); + void AddThickLine(int x1, int y1, int x2, int y2, double thickness, uint32_t color); void AddPixel(int x1, int y1, int palcolor, uint32_t color); void Clear(); diff --git a/src/v_draw.cpp b/src/v_draw.cpp index e3ebe63bc..765b20003 100644 --- a/src/v_draw.cpp +++ b/src/v_draw.cpp @@ -1088,6 +1088,24 @@ DEFINE_ACTION_FUNCTION(_Screen, DrawLine) return 0; } +void DFrameBuffer::DrawThickLine(int x0, int y0, int x1, int y1, double thickness, uint32_t realcolor) { + m2DDrawer.AddThickLine(x0, y0, x1, y1, thickness, realcolor); +} + +DEFINE_ACTION_FUNCTION(_Screen, DrawThickLine) +{ + PARAM_PROLOGUE; + PARAM_INT(x0); + PARAM_INT(y0); + PARAM_INT(x1); + PARAM_INT(y1); + PARAM_FLOAT(thickness); + PARAM_INT(color); + if (!screen->HasBegun2D()) ThrowAbortException(X_OTHER, "Attempt to draw to screen outside a draw function"); + screen->DrawThickLine(x0, y0, x1, y1, thickness, color); + return 0; +} + //========================================================================== // // Draw a single pixel diff --git a/src/v_video.h b/src/v_video.h index 1e456e6b8..ec0e43f3d 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -498,6 +498,9 @@ public: // Draws a line void DrawLine(int x0, int y0, int x1, int y1, int palColor, uint32_t realcolor); + // Draws a line with thickness + void DrawThickLine(int x0, int y0, int x1, int y1, double thickness, uint32_t realcolor); + // Draws a single pixel void DrawPixel(int x, int y, int palcolor, uint32_t rgbcolor); diff --git a/wadsrc/static/zscript/base.txt b/wadsrc/static/zscript/base.txt index f310e2900..e648febd1 100644 --- a/wadsrc/static/zscript/base.txt +++ b/wadsrc/static/zscript/base.txt @@ -194,6 +194,7 @@ struct Screen native native static vararg void DrawChar(Font font, int normalcolor, double x, double y, int character, ...); native static vararg void DrawText(Font font, int normalcolor, double x, double y, String text, ...); native static void DrawLine(int x0, int y0, int x1, int y1, Color color); + native static void DrawThickLine(int x0, int y0, int x1, int y1, double thickness, Color color); native static void DrawFrame(int x, int y, int w, int h); native static Vector2, Vector2 VirtualToRealCoords(Vector2 pos, Vector2 size, Vector2 vsize, bool vbottom=false, bool handleaspect=true); native static double GetAspectRatio();