feat: implemented different corner radiae for raylib clay renderer
This commit is contained in:
parent
80e1b84cb4
commit
f8dc3d3bee
50
vendor/clay_renderer_raylib.c
vendored
50
vendor/clay_renderer_raylib.c
vendored
|
@ -167,9 +167,57 @@ void Clay_Raylib_Render(Clay_RenderCommandArray renderCommands)
|
|||
}
|
||||
case CLAY_RENDER_COMMAND_TYPE_RECTANGLE: {
|
||||
Clay_RectangleElementConfig *config = renderCommand->config.rectangleElementConfig;
|
||||
if (config->cornerRadius.topLeft > 0) {
|
||||
if (config->cornerRadius.topLeft > 0 && config->cornerRadius.topLeft == config->cornerRadius.topRight && config->cornerRadius.topLeft == config->cornerRadius.bottomLeft && config->cornerRadius.topLeft == config->cornerRadius.bottomRight) {
|
||||
float radius = (config->cornerRadius.topLeft * 2) / (float)((boundingBox.width > boundingBox.height) ? boundingBox.height : boundingBox.width);
|
||||
DrawRectangleRounded((Rectangle) { boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height }, radius, 8, CLAY_COLOR_TO_RAYLIB_COLOR(config->color));
|
||||
} else if (config->cornerRadius.topLeft != 0.f || config->cornerRadius.topRight != 0.f || config->cornerRadius.bottomLeft != 0.f || config->cornerRadius.bottomRight != 0.f) {
|
||||
//float radiusReferenceSide = (float)((boundingBox.width > boundingBox.height) ? boundingBox.height : boundingBox.width);
|
||||
float radius = config->cornerRadius.topLeft;
|
||||
Color color = CLAY_COLOR_TO_RAYLIB_COLOR(config->color);
|
||||
if (radius > 0.f) {
|
||||
DrawCircleSector((Vector2){boundingBox.x + radius, boundingBox.y + radius}, radius, 180.f, 270.f, 10, color);
|
||||
}
|
||||
radius = config->cornerRadius.topRight;
|
||||
if (radius > 0.f) {
|
||||
DrawCircleSector((Vector2){boundingBox.x + boundingBox.width - radius, boundingBox.y + radius}, radius, 270.f, 360.f, 10, color);
|
||||
}
|
||||
radius = config->cornerRadius.bottomRight;
|
||||
if (radius > 0.f) {
|
||||
DrawCircleSector((Vector2){boundingBox.x + boundingBox.width - radius, boundingBox.y + boundingBox.height - radius}, radius, 0.f, 90.f, 10, color);
|
||||
}
|
||||
radius = config->cornerRadius.bottomLeft;
|
||||
if (radius > 0.f) {
|
||||
DrawCircleSector((Vector2){boundingBox.x + radius, boundingBox.y + boundingBox.height - radius}, radius, 90.f, 180.f, 10, color);
|
||||
}
|
||||
Rectangle rectangle = {
|
||||
.x = boundingBox.x + config->cornerRadius.topLeft,
|
||||
.y = boundingBox.y,
|
||||
.width = boundingBox.width - config->cornerRadius.topLeft - config->cornerRadius.topRight,
|
||||
.height = (config->cornerRadius.topLeft > config->cornerRadius.topRight) ? config->cornerRadius.topLeft : config->cornerRadius.topRight
|
||||
};
|
||||
DrawRectangleRec(rectangle, color);
|
||||
rectangle.x = boundingBox.x + boundingBox.width - config->cornerRadius.topRight;
|
||||
rectangle.y = boundingBox.y + config->cornerRadius.topRight;
|
||||
rectangle.width = (config->cornerRadius.topRight > config->cornerRadius.bottomRight) ? config->cornerRadius.topRight : config->cornerRadius.bottomRight;
|
||||
rectangle.height = boundingBox.height - config->cornerRadius.topRight - config->cornerRadius.bottomRight;
|
||||
DrawRectangleRec(rectangle, color);
|
||||
rectangle.height = (config->cornerRadius.bottomLeft > config->cornerRadius.bottomRight) ? config->cornerRadius.bottomLeft : config->cornerRadius.bottomRight;
|
||||
rectangle.width = boundingBox.width - config->cornerRadius.bottomLeft - config->cornerRadius.bottomRight;
|
||||
rectangle.x = boundingBox.x + config->cornerRadius.bottomLeft;
|
||||
rectangle.y = boundingBox.y + boundingBox.height - rectangle.height;
|
||||
DrawRectangleRec(rectangle, color);
|
||||
rectangle.width = (config->cornerRadius.topLeft > config->cornerRadius.bottomLeft) ? config->cornerRadius.topLeft : config->cornerRadius.bottomLeft;
|
||||
rectangle.height = boundingBox.height - config->cornerRadius.topLeft - config->cornerRadius.bottomLeft;
|
||||
rectangle.x = boundingBox.x;
|
||||
rectangle.y = boundingBox.y + config->cornerRadius.topLeft;
|
||||
DrawRectangleRec(rectangle, color);
|
||||
float largestLeft = ((config->cornerRadius.topLeft > config->cornerRadius.bottomLeft) ? config->cornerRadius.topLeft : config->cornerRadius.bottomLeft);
|
||||
float largestTop = ((config->cornerRadius.topLeft > config->cornerRadius.topRight) ? config->cornerRadius.topRight : config->cornerRadius.topRight);
|
||||
rectangle.x = boundingBox.x + largestLeft;
|
||||
rectangle.y = boundingBox.y + largestTop;
|
||||
rectangle.width = boundingBox.width - ((config->cornerRadius.topRight > config->cornerRadius.bottomRight) ? config->cornerRadius.topRight : config->cornerRadius.bottomRight) - largestLeft;
|
||||
rectangle.height = boundingBox.height - ((config->cornerRadius.bottomLeft > config->cornerRadius.bottomRight) ? config->cornerRadius.bottomLeft : config->cornerRadius.bottomRight) - largestTop;
|
||||
DrawRectangleRec(rectangle, color);
|
||||
} else {
|
||||
DrawRectangle(boundingBox.x, boundingBox.y, boundingBox.width, boundingBox.height, CLAY_COLOR_TO_RAYLIB_COLOR(config->color));
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue