Preserve floating point values in DrawRectangleLinesEx (#1683)

This commit is contained in:
Dan Bechard 2021-03-26 12:15:19 -07:00 committed by GitHub
parent f9bab14fdb
commit b6ca524bdd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -760,10 +760,26 @@ void DrawRectangleLinesEx(Rectangle rec, int lineThick, Color color)
else if (rec.width < rec.height) lineThick = (int)rec.width/2;
}
DrawRectangle( (int)rec.x, (int)rec.y, (int)rec.width, lineThick, color);
DrawRectangle( (int)(rec.x - lineThick + rec.width), (int)(rec.y + lineThick), lineThick, (int)(rec.height - lineThick*2.0f), color);
DrawRectangle( (int)rec.x, (int)(rec.y + rec.height - lineThick), (int)rec.width, lineThick, color);
DrawRectangle( (int)rec.x, (int)(rec.y + lineThick), lineThick, (int)(rec.height - lineThick*2), color);
// When rec = { x, y, 8.0f, 6.0f } and lineThick = 2, the following
// four rectangles are drawn ([T]op, [B]ottom, [L]eft, [R]ight):
//
// TTTTTTTT
// TTTTTTTT
// LL RR
// LL RR
// BBBBBBBB
// BBBBBBBB
//
float thick = (float)lineThick;
Rectangle top = { rec.x , rec.y , rec.width, thick };
Rectangle bottom = { rec.x , rec.y - thick + rec.height, rec.width, thick };
Rectangle left = { rec.x , rec.y + thick , thick , rec.height - thick * 2.0f };
Rectangle right = { rec.x - thick + rec.width, rec.y + thick , thick , rec.height - thick * 2.0f };
DrawRectangleRec(top, color);
DrawRectangleRec(bottom, color);
DrawRectangleRec(left, color);
DrawRectangleRec(right, color);
}
// Draw rectangle with rounded edges