Browse Source

[rshapes] Review `DrawRectangleLines()` pixel offset (#4261)

* [rshapes] Remove `DrawRectangleLines()`'s + 1 offset

* ... and replace it with a -/+ 0.5 offset divided by current cam's zoom.
pull/4428/head
RadsammyT 1 month ago
committed by GitHub
parent
commit
385187f795
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 8 deletions
  1. +10
    -8
      src/rshapes.c

+ 10
- 8
src/rshapes.c View File

@ -807,19 +807,21 @@ void DrawRectangleGradientEx(Rectangle rec, Color topLeft, Color bottomLeft, Col
// 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 = rlGetMatrixModelview();
float zoomElement = 0.5f / mat.m0;
rlBegin(RL_LINES);
rlColor4ub(color.r, color.g, color.b, color.a);
rlVertex2f((float)posX, (float)posY);
rlVertex2f((float)posX + (float)width, (float)posY + 1);
rlVertex2f((float)posX - zoomElement, (float)posY);
rlVertex2f((float)posX + (float)width + zoomElement, (float)posY);
rlVertex2f((float)posX + (float)width, (float)posY + 1);
rlVertex2f((float)posX + (float)width, (float)posY + (float)height);
rlVertex2f((float)posX + (float)width, (float)posY - zoomElement);
rlVertex2f((float)posX + (float)width, (float)posY + (float)height + zoomElement);
rlVertex2f((float)posX + (float)width, (float)posY + (float)height);
rlVertex2f((float)posX + 1, (float)posY + (float)height);
rlVertex2f((float)posX + (float)width + zoomElement, (float)posY + (float)height);
rlVertex2f((float)posX - zoomElement, (float)posY + (float)height);
rlVertex2f((float)posX + 1, (float)posY + (float)height);
rlVertex2f((float)posX + 1, (float)posY + 1);
rlVertex2f((float)posX, (float)posY + (float)height + zoomElement);
rlVertex2f((float)posX, (float)posY - zoomElement);
rlEnd();
}

Loading…
Cancel
Save