|
RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
|
mask.h — 8-bit coverage masks: the one shape representation. More...
Data Structures | |
| struct | rmgui_mask_t |
| height rows of width coverage bytes, 0 (outside) to 255 (inside), rows contiguous and unpadded. More... | |
| struct | rmgui_mask_nine_t |
| A nine-slice shape: over any rect at least left + right wide and top + bottom tall it is whole (coverage 255) inside the rect inset by the four band widths, and inside the bands it reads its masks at their own size, never stretched across the rect's size: corner[0..3] the top-left (left x top), top-right (right x top), bottom-left (left x bottom) and bottom-right (right x bottom) corners; edge[0..3] one line across the top band (1 x top), the bottom band (1 x bottom), the left band (left x 1) and the right band (right x 1), repeated along that side between its corners. More... | |
Macros | |
| #define | RMGUI_MASK_HIT_MIN 128 |
| Coverage at or above this value is "inside" for hit-testing. | |
Functions | |
| int | rmgui_mask_alloc (rmgui_mask_t *out, int width, int height) |
| Allocate a width x height mask into *out, every byte 0. | |
| void | rmgui_mask_free (rmgui_mask_t *mask) |
| Release the mask's block and leave it empty. | |
| uint8_t | rmgui_mask_sample (const rmgui_mask_t *mask, rmgui_rect_t rect, int x, int y) |
| The coverage of the mask stretched over rect at point (x, y); 0 when mask is NULL or empty, rect has a non-positive extent, or (x, y) is outside rect. | |
| int | rmgui_mask_hit (const rmgui_mask_t *mask, rmgui_rect_t rect, int x, int y) |
| 1 when rmgui_mask_sample is at least RMGUI_MASK_HIT_MIN, else 0. | |
| int | rmgui_mask_rounded_rect (rmgui_mask_t *mask, int radius) |
| Replace every coverage byte with a rounded rectangle filling the mask. | |
| int | rmgui_mask_ellipse (rmgui_mask_t *mask) |
| Replace coverage with the inscribed ellipse. | |
| int | rmgui_mask_polygon (rmgui_mask_t *mask, const rmgui_draw_point_t *points, int count) |
| Replace coverage with rmgui_draw_aa_polygon's coverage in mask-local Q16 coordinates: convex polygons of either winding, strict edge interiors; non-convex inputs produce the intersection of edge half-planes. | |
| int | rmgui_mask_from_alpha (rmgui_mask_t *mask, const rmgui_fb_t *src) |
| Replace coverage with src's alpha channel, stretched by nearest-pixel mapping (destination x, y reads x*src.width/mask.width, likewise y). | |
| void | rmgui_mask_fill (rmgui_fb_t *fb, rmgui_rect_t rect, rmgui_rect_t clip, const rmgui_mask_t *shape, rmgui_color_t color) |
| Blend color into every pixel of rect clipped to fb and to clip, at the alpha round(color.a * c / 255) (halves up), c being the coverage of shape stretched over rect at that pixel. | |
| void | rmgui_mask_nine_free (rmgui_mask_nine_t *nine) |
| Release every mask and zero the bands. | |
mask.h — 8-bit coverage masks: the one shape representation.
A mask says, per pixel, how much of an element lies there; the same bytes clip what an element paints, decide where the pointer hits it and give embossing its height field.
A mask is stretched over a rect by nearest-pixel mapping: rect pixel (x, y) reads mask pixel ((x - rect.x) * width / rect.w, (y - rect.y) * height / rect.h). Integer-only, so every platform reads the same byte.
| #define RMGUI_MASK_HIT_MIN 128 |
Coverage at or above this value is "inside" for hit-testing.
| int rmgui_mask_alloc | ( | rmgui_mask_t * | out, |
| int | width, | ||
| int | height ) |
Allocate a width x height mask into *out, every byte 0.
*out must not hold an allocated mask (it is overwritten, not released). Returns 0, or -1 leaving *out unchanged when out is NULL, width or height is not positive, the byte size does not fit in size_t, or the allocation fails.
| void rmgui_mask_free | ( | rmgui_mask_t * | mask | ) |
Release the mask's block and leave it empty.
NULL or empty: no-op.
| uint8_t rmgui_mask_sample | ( | const rmgui_mask_t * | mask, |
| rmgui_rect_t | rect, | ||
| int | x, | ||
| int | y ) |
The coverage of the mask stretched over rect at point (x, y); 0 when mask is NULL or empty, rect has a non-positive extent, or (x, y) is outside rect.
| int rmgui_mask_hit | ( | const rmgui_mask_t * | mask, |
| rmgui_rect_t | rect, | ||
| int | x, | ||
| int | y ) |
1 when rmgui_mask_sample is at least RMGUI_MASK_HIT_MIN, else 0.
| int rmgui_mask_rounded_rect | ( | rmgui_mask_t * | mask, |
| int | radius ) |
Replace every coverage byte with a rounded rectangle filling the mask.
radius is clamped to [0, 64] and half the shorter extent. Coverage uses draw.h's 16 x 16 sample grid, samples strictly inside the rounded edge, rounded to 0..255. Returns 0, or -1 unchanged for NULL or empty mask. The mask's storage is never reallocated.
| int rmgui_mask_ellipse | ( | rmgui_mask_t * | mask | ) |
Replace coverage with the inscribed ellipse.
On draw.h's 16 x 16 sample grid, absolute distances from the centre divided by each semi-axis are rounded to Q16, halves up; samples whose squared distance is below one are inside. Coverage is rounded to 0..255. Returns 0, or -1 unchanged for NULL or empty mask. The mask's storage is never reallocated.
| int rmgui_mask_polygon | ( | rmgui_mask_t * | mask, |
| const rmgui_draw_point_t * | points, | ||
| int | count ) |
Replace coverage with rmgui_draw_aa_polygon's coverage in mask-local Q16 coordinates: convex polygons of either winding, strict edge interiors; non-convex inputs produce the intersection of edge half-planes.
Fewer than three points or collinear points produce an empty shape. Uses a temporary RGBA framebuffer, released before returning; never reallocates the mask. Returns 0, or -1 unchanged for NULL/empty mask, NULL points, count < 0, or temporary allocation failure.
| int rmgui_mask_from_alpha | ( | rmgui_mask_t * | mask, |
| const rmgui_fb_t * | src ) |
Replace coverage with src's alpha channel, stretched by nearest-pixel mapping (destination x, y reads x*src.width/mask.width, likewise y).
Returns 0, or -1 unchanged for NULL or empty mask or src. Never reallocates the mask.
| void rmgui_mask_fill | ( | rmgui_fb_t * | fb, |
| rmgui_rect_t | rect, | ||
| rmgui_rect_t | clip, | ||
| const rmgui_mask_t * | shape, | ||
| rmgui_color_t | color ) |
Blend color into every pixel of rect clipped to fb and to clip, at the alpha round(color.a * c / 255) (halves up), c being the coverage of shape stretched over rect at that pixel.
The pixel is blended once by draw.h's straight-over rule; alpha 0 leaves it untouched, so a mask of all 255 paints exactly what rmgui_draw_fill_rect paints, and a soft-edged mask gives soft edges. The stretch maps rect (not the clipped part) to the whole mask, so clipping never shifts the shape.
Paints nothing when fb is NULL or empty, shape is NULL or empty, rect or clip is empty, or color.a is 0.
| void rmgui_mask_nine_free | ( | rmgui_mask_nine_t * | nine | ) |
Release every mask and zero the bands.
NULL: no-op.