The manual
ginnOS
The reference: libc, the libraries and the kernel
Loading...
Searching...
No Matches
gfx_round.c File Reference

libgfx: round rectangles, borders and soft shadows, drawn as CSS draws them. More...

#include "gfx_internal.h"
#include <math.h>
#include <stdlib.h>
#include <string.h>

Functions

void gfx_fill_round_rect_gradient (gfx_buffer_t *buf, gfx_rect_t r, int32_t radius, gfx_color_t top, gfx_color_t bottom)
 fill a round rectangle with a vertical gradient from top to bottom, sampled at the pixel centres (as a CSS linear-gradient).
void gfx_fill_round_rect (gfx_buffer_t *buf, gfx_rect_t r, int32_t radius, gfx_color_t color)
 fill a rectangle with round corners, with anti-aliased corners (as CSS border-radius).
void gfx_border_round_rect (gfx_buffer_t *buf, gfx_rect_t r, int32_t radius, int32_t width, gfx_color_t color)
 the border of a round rectangle: width pixels wide, inside r (as a CSS border with box-sizing: border-box).
void gfx_box_shadow (gfx_buffer_t *buf, gfx_rect_t box, int32_t radius, const gfx_shadow_t *s)
 draw a box-shadow of a round box.

Detailed Description

libgfx: round rectangles, borders and soft shadows, drawn as CSS draws them.

every shape here is a rectangle on whole pixels with a corner radius. a pixel's coverage comes from the distance d from its centre to the edge of the shape (negative inside): 0.5 - d, cut to 0..1. this is the usual anti-aliasing of browsers, so idunn looks close to its reference.

shadows follow CSS box-shadow: the shape is moved by the offset, made larger by the spread, blurred with sigma = blur / 2 (three box blurs, as SVG and Chrome do it), and drawn only outside the box (inside it, for an inset shadow).

Function Documentation

◆ gfx_fill_round_rect_gradient()

void gfx_fill_round_rect_gradient ( gfx_buffer_t * buf,
gfx_rect_t r,
int32_t radius,
gfx_color_t top,
gfx_color_t bottom )

fill a round rectangle with a vertical gradient from top to bottom, sampled at the pixel centres (as a CSS linear-gradient).

◆ gfx_fill_round_rect()

void gfx_fill_round_rect ( gfx_buffer_t * buf,
gfx_rect_t r,
int32_t radius,
gfx_color_t color )

fill a rectangle with round corners, with anti-aliased corners (as CSS border-radius).

Parameters
radiusthe corner radius (made smaller if the rectangle is small).

◆ gfx_border_round_rect()

void gfx_border_round_rect ( gfx_buffer_t * buf,
gfx_rect_t r,
int32_t radius,
int32_t width,
gfx_color_t color )

the border of a round rectangle: width pixels wide, inside r (as a CSS border with box-sizing: border-box).

the inside is not touched.

◆ gfx_box_shadow()

void gfx_box_shadow ( gfx_buffer_t * buf,
gfx_rect_t box,
int32_t radius,
const gfx_shadow_t * shadow )

draw a box-shadow of a round box.

an outer shadow is drawn only outside the box and an inset one only inside it, as in CSS: draw outer shadows before the box, inset ones after its background.

Parameters
boxthe border box (an inset shadow: the box inside the border).