RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
Loading...
Searching...
No Matches
pattern.h File Reference

pattern.h — tileable drawn patterns. More...

#include "fb.h"
#include "geom.h"

Data Structures

struct  rmgui_pattern_zellige_colors_t
 The four colours of a zellige. More...

Functions

int rmgui_pattern_zellige (rmgui_fb_t *tile, int cell_px, int grout_px, const rmgui_pattern_zellige_colors_t *colors)
 Renders the star-and-cross zellige into tile, every pixel written.
int rmgui_pattern_hatch (rmgui_fb_t *tile, int spacing_px, int width_px, rmgui_color_t line, rmgui_color_t field)
 Renders diagonal hatching into tile, every pixel written: parallel lines of colour line over field, running from the top-left toward the bottom-right at 45 degrees.

Detailed Description

pattern.h — tileable drawn patterns.

Each renderer fills a caller-owned tile with one repeat of a pattern; the caller lays it over an area with rmgui_backdrop_tile (backdrop.h). Nothing here allocates.

A tile holds premultiplied RGBA, the form rmgui_backdrop_tile consumes. Every colour parameter is straight RGBA (geom.h) whose alpha is honoured: a piece painted in a translucent colour is that colour at that alpha wherever it is whole, never stacked on the piece beside or under it, so a translucent pattern sits over a panel without its seams showing. Piece edges are anti-aliased: an edge pixel is the mix of the neighbouring colours weighted by the area each covers.

Integer-only: the same inputs yield the same bytes on every platform. Every renderer is periodic: the tile rendered at W x H, laid out k times across and l times down, equals the same renderer's tile at kW x lH byte for byte.

Function Documentation

◆ rmgui_pattern_zellige()

int rmgui_pattern_zellige ( rmgui_fb_t * tile,
int cell_px,
int grout_px,
const rmgui_pattern_zellige_colors_t * colors )

Renders the star-and-cross zellige into tile, every pixel written.

The pattern repeats on a square grid of cells, cell_px px on a side. A cell holds an eight-pointed star centred on its top-left corner (the area union of two squares of side cell_px / sqrt(2), one turned 45 degrees: its tips lie cell_px / 2 from its centre, so neighbouring stars touch tip to tip along the axes) and a cross centred on its centre. The cross fills what four stars leave around that centre: a square of side cell_px * (1 - sqrt(2)/2) (painted field) with a pointed arm (painted cross) on each side. Every piece is then drawn smaller by half of grout_px on all sides, so exactly grout_px px of grout separates any two pieces, and nothing else is painted. Coverage counts the union of the star's inset squares on the integer 16 x 16 sample grid before rounding to 0..255; their overlap counts once. Rendering uses bounded row scratch, independent of tile size.

tile.width and tile.height must each be a positive multiple of cell_px. Each extent plus cell_px must fit the positive int32_t Q16 coordinate domain (INT32_MAX / 65536 pixels). Pieces are placed on the cell grid from the tile's top-left corner, so the pattern is mirror-symmetric about the tile's vertical and horizontal axes, byte for byte.

Returns 0. Returns -1, leaving the tile unchanged, when tile or colors is NULL, tile is empty, cell_px or grout_px is below 1, cell_px is below 4 * grout_px (a piece would vanish), or the tile size is not as above.

◆ rmgui_pattern_hatch()

int rmgui_pattern_hatch ( rmgui_fb_t * tile,
int spacing_px,
int width_px,
rmgui_color_t line,
rmgui_color_t field )

Renders diagonal hatching into tile, every pixel written: parallel lines of colour line over field, running from the top-left toward the bottom-right at 45 degrees.

spacing_px is the distance between neighbouring lines along a row; width_px is each line's width measured across it. The line through the tile's top-left corner is the first of the family.

tile.width and tile.height must each be a positive multiple of spacing_px. width + height + 2 * spacing_px + width_px + 1 must not exceed INT32_MAX / 65536, the positive int32_t Q16 drawing coordinate domain.

Returns 0. Returns -1, leaving the tile unchanged, when tile is NULL or empty, spacing_px or width_px is below 1, width_px * sqrt(2) is not less than spacing_px (the lines would touch), or the tile size is not as above.