diff --git a/examples/shapes/shapes_draw_rectangle_rounded.c b/examples/shapes/shapes_draw_rectangle_rounded.c index 19280ed00..33b5c79d8 100644 --- a/examples/shapes/shapes_draw_rectangle_rounded.c +++ b/examples/shapes/shapes_draw_rectangle_rounded.c @@ -2,9 +2,10 @@ * * raylib [shapes] example - draw rectangle rounded (with gui options) * -* Example originally created with raylib 2.5, last time updated with raylib 2.5 +* Example originally created with raylib 2.5, last time updated with raylib 5.1 * * Example contributed by Vlad Adrian (@demizdor) and reviewed by Ramon Santamaria (@raysan5) +* Example extended to DrawRectangleRoundedPro and DrawRectangleRoundedLinesPro by Bruno Cabral (github.com/brccabral) * * Example licensed under an unmodified zlib/libpng license, which is an OSI-certified, * BSD-like license that allows static linking with closed source software @@ -26,7 +27,7 @@ int main(void) // Initialization //-------------------------------------------------------------------------------------- const int screenWidth = 800; - const int screenHeight = 450; + const int screenHeight = 550; InitWindow(screenWidth, screenHeight, "raylib [shapes] example - draw rectangle rounded"); @@ -40,6 +41,11 @@ int main(void) bool drawRoundedRect = true; bool drawRoundedLines = false; + bool topLeft = true; + bool topRight = true; + bool bottomLeft = true; + bool bottomRight = true; + SetTargetFPS(60); // Set our game to run at 60 frames-per-second //-------------------------------------------------------------------------------------- @@ -61,8 +67,8 @@ int main(void) DrawRectangle(560, 0, GetScreenWidth() - 500, GetScreenHeight(), Fade(LIGHTGRAY, 0.3f)); if (drawRect) DrawRectangleRec(rec, Fade(GOLD, 0.6f)); - if (drawRoundedRect) DrawRectangleRounded(rec, roundness, (int)segments, Fade(MAROON, 0.2f)); - if (drawRoundedLines) DrawRectangleRoundedLinesEx(rec, roundness, (int)segments, lineThick, Fade(MAROON, 0.4f)); + if (drawRoundedRect) DrawRectangleRoundedPro(rec, roundness, (int)segments, Fade(MAROON, 0.2f), topLeft, topRight, bottomLeft, bottomRight); + if (drawRoundedLines) DrawRectangleRoundedLinesPro(rec, roundness, (int)segments, lineThick, Fade(MAROON, 0.4f), topLeft, topRight, bottomLeft, bottomRight); // Draw GUI controls //------------------------------------------------------------------------------ @@ -75,6 +81,11 @@ int main(void) GuiCheckBox((Rectangle){ 640, 320, 20, 20 }, "DrawRoundedRect", &drawRoundedRect); GuiCheckBox((Rectangle){ 640, 350, 20, 20 }, "DrawRoundedLines", &drawRoundedLines); GuiCheckBox((Rectangle){ 640, 380, 20, 20}, "DrawRect", &drawRect); + + GuiCheckBox((Rectangle){ 640, 410, 20, 20 }, "TopLeft", &topLeft); + GuiCheckBox((Rectangle){ 640, 440, 20, 20 }, "TopRight", &topRight); + GuiCheckBox((Rectangle){ 640, 470, 20, 20 }, "BottomLeft", &bottomLeft); + GuiCheckBox((Rectangle){ 640, 500, 20, 20 }, "BottomRight", &bottomRight); //------------------------------------------------------------------------------ DrawText(TextFormat("MODE: %s", (segments >= 4)? "MANUAL" : "AUTO"), 640, 280, 10, (segments >= 4)? MAROON : DARKGRAY); diff --git a/src/raylib.h b/src/raylib.h index 7195fd55f..fdd55368b 100644 --- a/src/raylib.h +++ b/src/raylib.h @@ -1256,8 +1256,10 @@ RLAPI void DrawRectangleGradientEx(Rectangle rec, Color col1, Color col2, Color RLAPI void DrawRectangleLines(int posX, int posY, int width, int height, Color color); // Draw rectangle outline RLAPI void DrawRectangleLinesEx(Rectangle rec, float lineThick, Color color); // Draw rectangle outline with extended parameters RLAPI void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color color); // Draw rectangle with rounded edges +RLAPI void DrawRectangleRoundedPro(Rectangle rec, float roundness, int segments, Color color, bool topLeft, bool topRight, bool bottomLeft, bool bottomRight); // Draw rectangle with rounded edges on selected corners RLAPI void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, Color color); // Draw rectangle lines with rounded edges RLAPI void DrawRectangleRoundedLinesEx(Rectangle rec, float roundness, int segments, float lineThick, Color color); // Draw rectangle with rounded edges outline +RLAPI void DrawRectangleRoundedLinesPro(Rectangle rec, float roundness, int segments, float lineThick, Color color, bool topLeft, bool topRight, bool bottomLeft, bool bottomRight); // Draw rectangle with rounded edges outline on selected corners RLAPI void DrawTriangle(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw a color-filled triangle (vertex in counter-clockwise order!) RLAPI void DrawTriangleLines(Vector2 v1, Vector2 v2, Vector2 v3, Color color); // Draw triangle outline (vertex in counter-clockwise order!) RLAPI void DrawTriangleFan(const Vector2 *points, int pointCount, Color color); // Draw a triangle fan defined by points (first vertex is the center) diff --git a/src/rlgl.h b/src/rlgl.h index 530e44efc..750ea0cb8 100644 --- a/src/rlgl.h +++ b/src/rlgl.h @@ -789,6 +789,15 @@ RLAPI void rlSetMatrixViewOffsetStereo(Matrix right, Matrix left); // Set RLAPI void rlLoadDrawCube(void); // Load and draw a cube RLAPI void rlLoadDrawQuad(void); // Load and draw a quad +// Shapes +RLAPI void rlLine(Vector2 p1, Vector2 p2, Color color); +#if defined(SUPPORT_QUADS_DRAW_MODE) +RLAPI void rlRectangle(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Color color, Rectangle shapeRect, Texture2D texShapes); +#else +RLAPI void rlRectangle(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Color color); +#endif + + #if defined(__cplusplus) } #endif @@ -5118,4 +5127,37 @@ static Matrix rlMatrixInvert(Matrix mat) return result; } +void rlLine(Vector2 p1, Vector2 p2, Color color) +{ + rlColor4ub(color.r, color.g, color.b, color.a); + rlVertex2f(p1.x, p1.y); + rlVertex2f(p2.x, p2.y); +} + +#if defined(SUPPORT_QUADS_DRAW_MODE) +void rlRectangle(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Color color, Rectangle shapeRect, Texture2D texShapes) +{ + rlColor4ub(color.r, color.g, color.b, color.a); + rlTexCoord2f(shapeRect.x/texShapes.width, shapeRect.y/texShapes.height); + rlVertex2f(p1.x, p1.y); + rlTexCoord2f(shapeRect.x/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); + rlVertex2f(p2.x, p2.y); + rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); + rlVertex2f(p3.x, p3.y); + rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, shapeRect.y/texShapes.height); + rlVertex2f(p4.x, p4.y); +} +#else +void rlRectangle(Vector2 p1, Vector2 p2, Vector2 p3, Vector2 p4, Color color) +{ + rlColor4ub(color.r, color.g, color.b, color.a); + rlVertex2f(p1.x, p1.y); + rlVertex2f(p2.x, p2.y); + rlVertex2f(p3.x, p3.y); + rlVertex2f(p4.x, p4.y); + rlVertex2f(p1.x, p1.y); + rlVertex2f(p3.x, p3.y); +} +#endif + #endif // RLGL_IMPLEMENTATION diff --git a/src/rshapes.c b/src/rshapes.c index 95c54770e..0e4678e4e 100644 --- a/src/rshapes.c +++ b/src/rshapes.c @@ -862,9 +862,15 @@ void DrawRectangleLinesEx(Rectangle rec, float lineThick, Color color) // Draw rectangle with rounded edges void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color color) +{ + DrawRectangleRoundedPro(rec, roundness, segments, color, true, true, true, true); +} + +// Draw rectangle with rounded edges on selected corners +void DrawRectangleRoundedPro(Rectangle rec, float roundness, int segments, Color color, bool topLeft, bool topRight, bool bottomLeft, bool bottomRight) { // Not a rounded rectangle - if ((roundness <= 0.0f) || (rec.width < 1) || (rec.height < 1 )) + if ((roundness <= 0.0f) || (rec.width < 1) || (rec.height < 1 ) || (!topLeft && !topRight && !bottomLeft && !bottomRight)) { DrawRectangleRec(rec, color); return; @@ -912,16 +918,41 @@ void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color co {(float)(rec.x + rec.width) - radius, (float)(rec.y + rec.height) - radius}, {(float)rec.x + radius, (float)(rec.y + rec.height) - radius} // P10, P11 }; - const Vector2 centers[4] = { point[8], point[9], point[10], point[11] }; - const float angles[4] = { 180.0f, 270.0f, 0.0f, 90.0f }; + Vector2 centers[4]; + float angles[4]; + int countCenters = 0; + if (topLeft) + { + centers[countCenters] = point[8]; + angles[countCenters] = 180.0f; + ++countCenters; + } + if (topRight) + { + centers[countCenters] = point[9]; + angles[countCenters] = 270.0f; + ++countCenters; + } + if (bottomRight) + { + centers[countCenters] = point[10]; + angles[countCenters] = 0.0f; + ++countCenters; + } + if (bottomLeft) + { + centers[countCenters] = point[11]; + angles[countCenters] = 90.0f; + ++countCenters; + } #if defined(SUPPORT_QUADS_DRAW_MODE) rlSetTexture(GetShapesTexture().id); Rectangle shapeRect = GetShapesTextureRectangle(); rlBegin(RL_QUADS); - // Draw all the 4 corners: [1] Upper Left Corner, [3] Upper Right Corner, [5] Lower Right Corner, [7] Lower Left Corner - for (int k = 0; k < 4; ++k) // Hope the compiler is smart enough to unroll this loop + // Draw the selected corners + for (int k = 0; k < countCenters; ++k) // Hope the compiler is smart enough to unroll this loop { float angle = angles[k]; const Vector2 center = centers[k]; @@ -963,68 +994,46 @@ void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color co } } + if (!topLeft) + { + rlRectangle((Vector2) {point[7].x, point[0].y}, point[7], point[8], point[0], color, shapeRect, texShapes); + } + if (!topRight) + { + rlRectangle(point[1], point[9], point[2], (Vector2) {point[2].x, point[1].y}, color, shapeRect, texShapes); + } + if (!bottomLeft) + { + rlRectangle(point[6], (Vector2) {point[6].x, point[5].y}, point[5], point[11], color, shapeRect, texShapes); + } + if (!bottomRight) + { + rlRectangle(point[10], point[4], (Vector2) {point[3].x, point[4].y}, point[3], color, shapeRect, texShapes); + } + // [2] Upper Rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlTexCoord2f(shapeRect.x/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[0].x, point[0].y); - rlTexCoord2f(shapeRect.x/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[8].x, point[8].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[9].x, point[9].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[1].x, point[1].y); + rlRectangle(point[0], point[8], point[9], point[1], color, shapeRect, texShapes); // [4] Right Rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlTexCoord2f(shapeRect.x/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[2].x, point[2].y); - rlTexCoord2f(shapeRect.x/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[9].x, point[9].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[10].x, point[10].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[3].x, point[3].y); + rlRectangle(point[9], point[10], point[3], point[2], color, shapeRect, texShapes); // [6] Bottom Rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlTexCoord2f(shapeRect.x/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[11].x, point[11].y); - rlTexCoord2f(shapeRect.x/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[5].x, point[5].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[4].x, point[4].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[10].x, point[10].y); + rlRectangle(point[11], point[5], point[4], point[10], color, shapeRect, texShapes); // [8] Left Rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlTexCoord2f(shapeRect.x/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[7].x, point[7].y); - rlTexCoord2f(shapeRect.x/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[6].x, point[6].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[11].x, point[11].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[8].x, point[8].y); + rlRectangle(point[7], point[6], point[11], point[8], color, shapeRect, texShapes); // [9] Middle Rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlTexCoord2f(shapeRect.x/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[8].x, point[8].y); - rlTexCoord2f(shapeRect.x/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[11].x, point[11].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[10].x, point[10].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[9].x, point[9].y); + rlRectangle(point[8], point[11], point[10], point[9], color, shapeRect, texShapes); rlEnd(); rlSetTexture(0); + #else rlBegin(RL_TRIANGLES); - // Draw all of the 4 corners: [1] Upper Left Corner, [3] Upper Right Corner, [5] Lower Right Corner, [7] Lower Left Corner - for (int k = 0; k < 4; ++k) // Hope the compiler is smart enough to unroll this loop + // Draw the selected corners + for (int k = 0; k < countCenters; ++k) // Hope the compiler is smart enough to unroll this loop { float angle = angles[k]; const Vector2 center = centers[k]; @@ -1038,52 +1047,42 @@ void DrawRectangleRounded(Rectangle rec, float roundness, int segments, Color co } } + if (!topLeft) + { + rlRectangle((Vector2) {point[7].x, point[0].y}, point[7], point[8], point[0], color); + } + if (!topRight) + { + rlRectangle(point[1], point[9], point[2], (Vector2) {point[2].x, point[1].y}, color); + } + if (!bottomLeft) + { + rlRectangle(point[6], (Vector2) {point[6].x, point[5].y}, point[5], point[11], color); + } + if (!bottomRight) + { + rlRectangle(point[10], point[4], (Vector2) {point[3].x, point[4].y}, point[3], color); + } + // [2] Upper Rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(point[0].x, point[0].y); - rlVertex2f(point[8].x, point[8].y); - rlVertex2f(point[9].x, point[9].y); - rlVertex2f(point[1].x, point[1].y); - rlVertex2f(point[0].x, point[0].y); - rlVertex2f(point[9].x, point[9].y); + rlRectangle(point[0], point[8], point[9], point[1], color); // [4] Right Rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(point[9].x, point[9].y); - rlVertex2f(point[10].x, point[10].y); - rlVertex2f(point[3].x, point[3].y); - rlVertex2f(point[2].x, point[2].y); - rlVertex2f(point[9].x, point[9].y); - rlVertex2f(point[3].x, point[3].y); + rlRectangle(point[9], point[10], point[3], point[2], color); // [6] Bottom Rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(point[11].x, point[11].y); - rlVertex2f(point[5].x, point[5].y); - rlVertex2f(point[4].x, point[4].y); - rlVertex2f(point[10].x, point[10].y); - rlVertex2f(point[11].x, point[11].y); - rlVertex2f(point[4].x, point[4].y); + rlRectangle(point[11], point[5], point[4], point[10], color); // [8] Left Rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(point[7].x, point[7].y); - rlVertex2f(point[6].x, point[6].y); - rlVertex2f(point[11].x, point[11].y); - rlVertex2f(point[8].x, point[8].y); - rlVertex2f(point[7].x, point[7].y); - rlVertex2f(point[11].x, point[11].y); + rlRectangle(point[7], point[6], point[11], point[8], color); // [9] Middle Rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(point[8].x, point[8].y); - rlVertex2f(point[11].x, point[11].y); - rlVertex2f(point[10].x, point[10].y); - rlVertex2f(point[9].x, point[9].y); - rlVertex2f(point[8].x, point[8].y); - rlVertex2f(point[10].x, point[10].y); + rlRectangle(point[8], point[11], point[10], point[9], color); + rlEnd(); + #endif + } // Draw rectangle with rounded edges @@ -1095,11 +1094,17 @@ void DrawRectangleRoundedLines(Rectangle rec, float roundness, int segments, Col // Draw rectangle with rounded edges outline void DrawRectangleRoundedLinesEx(Rectangle rec, float roundness, int segments, float lineThick, Color color) +{ + DrawRectangleRoundedLinesPro(rec, roundness, segments, lineThick, color, true, true, true, true); +} + +// Draw rectangle with rounded edges outline +void DrawRectangleRoundedLinesPro(Rectangle rec, float roundness, int segments, float lineThick, Color color, bool topLeft, bool topRight, bool bottomLeft, bool bottomRight) { if (lineThick < 0) lineThick = 0; // Not a rounded rectangle - if (roundness <= 0.0f) + if (roundness <= 0.0f || (!topLeft && !topRight && !bottomLeft && !bottomRight)) { DrawRectangleLinesEx((Rectangle){rec.x-lineThick, rec.y-lineThick, rec.width+2*lineThick, rec.height+2*lineThick}, lineThick, color); return; @@ -1149,12 +1154,34 @@ void DrawRectangleRoundedLinesEx(Rectangle rec, float roundness, int segments, f { rec.x, (float)(rec.y + rec.height) - innerRadius}, {rec.x, (float)rec.y + innerRadius} // P14, P15 }; - const Vector2 centers[4] = { - {(float)rec.x + innerRadius, (float)rec.y + innerRadius}, {(float)(rec.x + rec.width) - innerRadius, (float)rec.y + innerRadius}, // P16, P17 - {(float)(rec.x + rec.width) - innerRadius, (float)(rec.y + rec.height) - innerRadius}, {(float)rec.x + innerRadius, (float)(rec.y + rec.height) - innerRadius} // P18, P19 - }; + Vector2 centers[4]; + float angles[4]; + int countCenters = 0; - const float angles[4] = { 180.0f, 270.0f, 0.0f, 90.0f }; + if (topLeft) + { + centers[countCenters] = (Vector2) {(float)rec.x + innerRadius, (float)rec.y + innerRadius}; // P16 + angles[countCenters] = 180.0f; + ++countCenters; + } + if (topRight) + { + centers[countCenters] = (Vector2) {(float)(rec.x + rec.width) - innerRadius, (float)rec.y + innerRadius}; // P17 + angles[countCenters] = 270.0f; + ++countCenters; + } + if (bottomRight) + { + centers[countCenters] = (Vector2) {(float)(rec.x + rec.width) - innerRadius, (float)(rec.y + rec.height) - innerRadius}; // P18 + angles[countCenters] = 0.0f; + ++countCenters; + } + if (bottomLeft) + { + centers[countCenters] = (Vector2) {(float)rec.x + innerRadius, (float)(rec.y + rec.height) - innerRadius}; // P19 + angles[countCenters] = 90.0f; + ++countCenters; + } if (lineThick > 1) { @@ -1164,8 +1191,8 @@ void DrawRectangleRoundedLinesEx(Rectangle rec, float roundness, int segments, f rlBegin(RL_QUADS); - // Draw all the 4 corners first: Upper Left Corner, Upper Right Corner, Lower Right Corner, Lower Left Corner - for (int k = 0; k < 4; ++k) // Hope the compiler is smart enough to unroll this loop + // Draw the selected corners + for (int k = 0; k < countCenters; ++k) // Hope the compiler is smart enough to unroll this loop { float angle = angles[k]; const Vector2 center = centers[k]; @@ -1189,57 +1216,45 @@ void DrawRectangleRoundedLinesEx(Rectangle rec, float roundness, int segments, f } } + // Draw horizontal corner and vertical corner + if (!topLeft) + { + rlRectangle((Vector2) {point[7].x, point[0].y}, (Vector2) {point[7].x, point[8].y}, point[8], point[0], color, shapeRect, texShapes); + rlRectangle((Vector2) {point[7].x, point[8].y}, point[7], point[15], (Vector2) {point[15].x, point[8].y}, color, shapeRect, texShapes); + } + if (!topRight) + { + rlRectangle(point[1], point[9], (Vector2) {point[2].x, point[9].y}, (Vector2) {point[2].x, point[1].y}, color, shapeRect, texShapes); + rlRectangle( (Vector2) {point[10].x, point[9].y}, point[10], point[2], (Vector2) {point[2].x, point[9].y}, color, shapeRect, texShapes); + } + if (!bottomLeft) + { + rlRectangle( (Vector2) {point[6].x, point[13].y}, (Vector2) {point[6].x, point[5].y}, point[5], point[13], color, shapeRect, texShapes); + rlRectangle( point[6], (Vector2) {point[6].x, point[13].y}, (Vector2) {point[14].x, point[13].y}, point[14], color, shapeRect, texShapes); + } + if (!bottomRight) + { + rlRectangle( point[12], point[4], (Vector2) {point[3].x, point[4].y}, (Vector2) {point[3].x, point[12].y}, color, shapeRect, texShapes); + rlRectangle( point[11], (Vector2) {point[11].x, point[12].y}, (Vector2) {point[3].x, point[12].y}, point[3], color, shapeRect, texShapes); + } + // Upper rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlTexCoord2f(shapeRect.x/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[0].x, point[0].y); - rlTexCoord2f(shapeRect.x/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[8].x, point[8].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[9].x, point[9].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[1].x, point[1].y); - + rlRectangle( point[0], point[8], point[9], point[1], color, shapeRect, texShapes); // Right rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlTexCoord2f(shapeRect.x/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[2].x, point[2].y); - rlTexCoord2f(shapeRect.x/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[10].x, point[10].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[11].x, point[11].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[3].x, point[3].y); - + rlRectangle( point[10], point[11], point[3], point[2], color, shapeRect, texShapes); // Lower rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlTexCoord2f(shapeRect.x/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[13].x, point[13].y); - rlTexCoord2f(shapeRect.x/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[5].x, point[5].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[4].x, point[4].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[12].x, point[12].y); - + rlRectangle( point[13], point[5], point[4], point[12], color, shapeRect, texShapes); // Left rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlTexCoord2f(shapeRect.x/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[15].x, point[15].y); - rlTexCoord2f(shapeRect.x/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[7].x, point[7].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, (shapeRect.y + shapeRect.height)/texShapes.height); - rlVertex2f(point[6].x, point[6].y); - rlTexCoord2f((shapeRect.x + shapeRect.width)/texShapes.width, shapeRect.y/texShapes.height); - rlVertex2f(point[14].x, point[14].y); + rlRectangle( point[7], point[6], point[14], point[15], color, shapeRect, texShapes); rlEnd(); rlSetTexture(0); + #else rlBegin(RL_TRIANGLES); - // Draw all of the 4 corners first: Upper Left Corner, Upper Right Corner, Lower Right Corner, Lower Left Corner - for (int k = 0; k < 4; ++k) // Hope the compiler is smart enough to unroll this loop + // Draw the selected corners + for (int k = 0; k < countCenters; ++k) // Hope the compiler is smart enough to unroll this loop { float angle = angles[k]; const Vector2 center = centers[k]; @@ -1260,41 +1275,37 @@ void DrawRectangleRoundedLinesEx(Rectangle rec, float roundness, int segments, f } } + // Draw horizontal corner and vertical corner + if (!topLeft) + { + rlRectangle((Vector2) {point[7].x, point[0].y}, (Vector2) {point[7].x, point[8].y}, point[8], point[0], color); + rlRectangle((Vector2) {point[7].x, point[8].y}, point[7], point[15], (Vector2) {point[15].x, point[8].y}, color); + } + if (!topRight) + { + rlRectangle(point[1], point[9], (Vector2) {point[2].x, point[9].y}, (Vector2) {point[2].x, point[1].y}, color); + rlRectangle( (Vector2) {point[10].x, point[9].y}, point[10], point[2], (Vector2) {point[2].x, point[9].y}, color); + } + if (!bottomLeft) + { + rlRectangle( (Vector2) {point[6].x, point[13].y}, (Vector2) {point[6].x, point[5].y}, point[5], point[13], color); + rlRectangle( point[6], (Vector2) {point[6].x, point[13].y}, (Vector2) {point[14].x, point[13].y}, point[14], color); + } + if (!bottomRight) + { + rlRectangle( point[12], point[4], (Vector2) {point[3].x, point[4].y}, (Vector2) {point[3].x, point[12].y}, color); + rlRectangle( point[11], (Vector2) {point[11].x, point[12].y}, (Vector2) {point[3].x, point[12].y}, point[3], color); + } + // Upper rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(point[0].x, point[0].y); - rlVertex2f(point[8].x, point[8].y); - rlVertex2f(point[9].x, point[9].y); - rlVertex2f(point[1].x, point[1].y); - rlVertex2f(point[0].x, point[0].y); - rlVertex2f(point[9].x, point[9].y); - + rlRectangle( point[0], point[8], point[9], point[1], color); // Right rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(point[10].x, point[10].y); - rlVertex2f(point[11].x, point[11].y); - rlVertex2f(point[3].x, point[3].y); - rlVertex2f(point[2].x, point[2].y); - rlVertex2f(point[10].x, point[10].y); - rlVertex2f(point[3].x, point[3].y); - + rlRectangle( point[10], point[11], point[3], point[2], color); // Lower rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(point[13].x, point[13].y); - rlVertex2f(point[5].x, point[5].y); - rlVertex2f(point[4].x, point[4].y); - rlVertex2f(point[12].x, point[12].y); - rlVertex2f(point[13].x, point[13].y); - rlVertex2f(point[4].x, point[4].y); - + rlRectangle( point[13], point[5], point[4], point[12], color); // Left rectangle - rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(point[7].x, point[7].y); - rlVertex2f(point[6].x, point[6].y); - rlVertex2f(point[14].x, point[14].y); - rlVertex2f(point[15].x, point[15].y); - rlVertex2f(point[7].x, point[7].y); - rlVertex2f(point[14].x, point[14].y); + rlRectangle( point[7], point[6], point[14], point[15], color); + rlEnd(); #endif } @@ -1303,8 +1314,8 @@ void DrawRectangleRoundedLinesEx(Rectangle rec, float roundness, int segments, f // Use LINES to draw the outline rlBegin(RL_LINES); - // Draw all the 4 corners first: Upper Left Corner, Upper Right Corner, Lower Right Corner, Lower Left Corner - for (int k = 0; k < 4; ++k) // Hope the compiler is smart enough to unroll this loop + // Draw the selected corners + for (int k = 0; k < countCenters; ++k) // Hope the compiler is smart enough to unroll this loop { float angle = angles[k]; const Vector2 center = centers[k]; @@ -1318,12 +1329,32 @@ void DrawRectangleRoundedLinesEx(Rectangle rec, float roundness, int segments, f } } - // And now the remaining 4 lines + // Draw the 4 main lines for (int i = 0; i < 8; i += 2) { - rlColor4ub(color.r, color.g, color.b, color.a); - rlVertex2f(point[i].x, point[i].y); - rlVertex2f(point[i + 1].x, point[i + 1].y); + rlLine(point[i], point[i + 1], color); + } + + // Draw the corners lines + if(!topLeft) + { + rlLine(point[7], (Vector2) {point[7].x, point[0].y}, color); + rlLine((Vector2) {point[7].x, point[0].y}, point[0], color); + } + if(!topRight) + { + rlLine(point[1], (Vector2) {point[2].x, point[1].y}, color); + rlLine((Vector2) {point[2].x, point[1].y}, point[2], color); + } + if(!bottomLeft) + { + rlLine(point[6], (Vector2) {point[6].x, point[5].y}, color); + rlLine((Vector2) {point[6].x, point[5].y}, point[5], color); + } + if(!bottomRight) + { + rlLine(point[4], (Vector2) {point[3].x, point[4].y}, color); + rlLine((Vector2) {point[3].x, point[4].y}, point[3], color); } rlEnd();