Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 37 additions & 11 deletions src/rshapes.c
Original file line number Diff line number Diff line change
Expand Up @@ -745,9 +745,20 @@ void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color col3,
// but it solves another issue: https://github.com/raysan5/raylib/issues/3884
void DrawRectangleLines(int posX, int posY, int width, int height, Color color)
{
Matrix mat = rlGetMatrixTransform();
float xOffset = 0.5f/mat.m0;
float yOffset = 0.5f/mat.m5;
Matrix t = rlGetMatrixTransform();
Matrix m = rlGetMatrixModelview();

// Compute upper-left 2x2 of M*T
float ax = m.m0*t.m0 + m.m4*t.m1;
float ay = m.m1*t.m0 + m.m5*t.m1;
float bx = m.m0*t.m4 + m.m4*t.m5;
float by = m.m1*t.m4 + m.m5*t.m5;

// Use the 2x2 inverse of M*T to convert 0.5 px screen-space to world units
// Using max(|bx|, |by|) and max(|ax|, |ay|) matches OpenGL's diamond-exit rule
float invDet = 0.5f/fabsf(ax*by - ay*bx);
float xOffset = ((fabsf(bx) > fabsf(by))? fabsf(bx) : fabsf(by))*invDet;
float yOffset = ((fabsf(ax) > fabsf(ay))? fabsf(ax) : fabsf(ay))*invDet;

rlBegin(RL_LINES);
rlColor4ub(color.r, color.g, color.b, color.a);
Expand Down Expand Up @@ -1142,17 +1153,32 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, Col
P5 ------------------ P4
*/

Matrix t = rlGetMatrixTransform();
Matrix m = rlGetMatrixModelview();

// Compute upper-left 2x2 of M*T
float ax = m.m0*t.m0 + m.m4*t.m1;
float ay = m.m1*t.m0 + m.m5*t.m1;
float bx = m.m0*t.m4 + m.m4*t.m5;
float by = m.m1*t.m4 + m.m5*t.m5;

// Use the 2x2 inverse of M*T to convert 0.5 px screen-space to world units
// Using max(|bx|, |by|) and max(|ax|, |ay|) matches OpenGL's diamond-exit rule
float invDet = 0.5f/fabsf(ax*by - ay*bx);
float xOffset = ((fabsf(bx) > fabsf(by))? fabsf(bx) : fabsf(by))*invDet;
float yOffset = ((fabsf(ax) > fabsf(ay))? fabsf(ax) : fabsf(ay))*invDet;

// The x-coordinates used for the outline
float x0 = rec.x + radius + 0.5f;
float x1 = (rec.x + rec.width) - radius - 0.5f;
float x2 = (rec.x + rec.width) - 0.5f;
float x3 = rec.x + 0.5f;
float x0 = rec.x + radius + xOffset;
float x1 = (rec.x + rec.width) - radius - xOffset;
float x2 = (rec.x + rec.width) - xOffset;
float x3 = rec.x + xOffset;

// The y-coordinates used for the outline
float y0 = rec.y + 0.5f;
float y1 = rec.y + radius + 0.5f;
float y2 = (rec.y + rec.height) - radius - 0.5f;
float y3 = (rec.y + rec.height) - 0.5f;
float y0 = rec.y + yOffset;
float y1 = rec.y + radius + yOffset;
float y2 = (rec.y + rec.height) - radius - yOffset;
float y3 = (rec.y + rec.height) - yOffset;

Vector2 points[8] = {
{ x0, y0 }, // P0
Expand Down
Loading