|
RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
|
draw.h — blended RGBA8 draw primitives over an rmgui_fb_t: pixels, runs, rectangle outlines and fills, rounded fills, lines, vertical gradients, bevels, and anti-aliased discs, rings, thick lines and convex polygons. More...
Data Structures | |
| struct | rmgui_draw_vgrad_stop_t |
| Gradient stop for rmgui_draw_vgrad: row counts from the top row of the gradient rect (row 0), independent of clipping; color.r, color.g, color.b is the exact color of that row. More... | |
| struct | rmgui_draw_point_t |
| A point in Q16 device px. More... | |
| struct | rmgui_draw_vertex_t |
| General contours: nonzero move starts a contour; each closes implicitly. More... | |
| struct | rmgui_draw_crossing_t |
| Caller-owned scanline scratch, one element per vertex. More... | |
Enumerations | |
| enum | rmgui_draw_mode_t { RMGUI_DRAW_MODE_OVER , RMGUI_DRAW_MODE_ADD } |
| How a source pixel combines with the pixel under it: OVER source over destination. More... | |
| enum | rmgui_draw_cap_t { RMGUI_DRAW_CAP_BUTT , RMGUI_DRAW_CAP_ROUND } |
| The end of an rmgui_draw_aa_line: BUTT stops at the end point, ROUND adds a half disc of the line's width around it. More... | |
| enum | rmgui_draw_fill_rule_t { RMGUI_DRAW_FILL_NONZERO , RMGUI_DRAW_FILL_EVEN_ODD } |
| General contour winding rules. More... | |
Functions | |
| rmgui_color_t | rmgui_draw_blend (rmgui_color_t under, rmgui_color_t top) |
| The color rmgui_draw_fill_rect leaves on a pixel of color under when painting top.r, top.g, top.b at coverage top.a (the straight-over rule above). | |
| void | rmgui_draw_pixel (rmgui_fb_t *fb, int x, int y, rmgui_color_t color) |
| Blend the pixel (x, y). | |
| void | rmgui_draw_hline (rmgui_fb_t *fb, int x, int y, int len, rmgui_color_t color) |
| Blend the len pixels (x . | |
| void | rmgui_draw_vline (rmgui_fb_t *fb, int x, int y, int len, rmgui_color_t color) |
| Blend the len pixels (x, y . | |
| void | rmgui_draw_rect (rmgui_fb_t *fb, rmgui_rect_t rect, rmgui_color_t color) |
| Blend the one-pixel outline of rect. | |
| void | rmgui_draw_fill_rect (rmgui_fb_t *fb, rmgui_rect_t rect, rmgui_color_t color) |
| Blend every pixel of rect. | |
| void | rmgui_draw_fill_rounded (rmgui_fb_t *fb, rmgui_rect_t rect, int radius, rmgui_color_t color) |
| Blend rect with rounded corners of radius radius, clamped to half the shorter side. | |
| void | rmgui_draw_line (rmgui_fb_t *fb, int x0, int y0, int x1, int y1, rmgui_color_t color) |
| Blend the 8-connected line from (x0, y0) to (x1, y1), endpoints inclusive. | |
| void | rmgui_draw_vgrad (rmgui_fb_t *fb, rmgui_rect_t rect, const rmgui_draw_vgrad_stop_t *stops, int n_stops) |
| Fill rect with a vertical gradient, written verbatim with alpha 255 (not blended). | |
| rmgui_color_t | rmgui_draw_vgrad_color (const rmgui_draw_vgrad_stop_t *stops, int n_stops, int row) |
| The color rmgui_draw_vgrad paints on gradient row row for the given stops, alpha 255. | |
| void | rmgui_draw_bevel_raised (rmgui_fb_t *fb, rmgui_rect_t rect, rmgui_color_t light, rmgui_color_t dark) |
| Write the 1px raised bevel of rect verbatim with alpha 255: light on the top run and left interior column, dark on the bottom run and right interior column, with rmgui_draw_rect's edge ownership. | |
| void | rmgui_draw_bevel_recessed (rmgui_fb_t *fb, rmgui_rect_t rect, rmgui_color_t light, rmgui_color_t dark) |
| rmgui_draw_bevel_raised with the two colors swapped: dark on top and left, light on bottom and right. | |
| void | rmgui_draw_aa_disc (rmgui_fb_t *fb, rmgui_rect_t clip, rmgui_draw_point_t centre, int32_t radius_q16, rmgui_color_t color, rmgui_draw_mode_t mode) |
| The disc of radius_q16 about centre: samples s with |s - centre| < radius. | |
| void | rmgui_draw_aa_ring (rmgui_fb_t *fb, rmgui_rect_t clip, rmgui_draw_point_t centre, int32_t outer_q16, int32_t inner_q16, rmgui_color_t color, rmgui_draw_mode_t mode) |
| The ring about centre: samples s with inner <= |s - centre| < outer, the disc of outer less the disc of inner. | |
| void | rmgui_draw_aa_line (rmgui_fb_t *fb, rmgui_rect_t clip, rmgui_draw_point_t from, rmgui_draw_point_t to, int32_t width_q16, rmgui_draw_cap_t cap, rmgui_color_t color, rmgui_draw_mode_t mode) |
| The line of width_q16 from from to to. | |
| void | rmgui_draw_aa_polygon (rmgui_fb_t *fb, rmgui_rect_t clip, const rmgui_draw_point_t *points, int count, rmgui_color_t color, rmgui_draw_mode_t mode) |
| The convex polygon through points[0 . | |
| int | rmgui_draw_aa_contours (rmgui_fb_t *, rmgui_rect_t, const rmgui_draw_vertex_t *, size_t, rmgui_draw_fill_rule_t, rmgui_color_t, rmgui_draw_mode_t, rmgui_draw_crossing_t *, size_t) |
| Paint arbitrary, possibly self-intersecting contours once at 16x16 coverage. | |
draw.h — blended RGBA8 draw primitives over an rmgui_fb_t: pixels, runs, rectangle outlines and fills, rounded fills, lines, vertical gradients, bevels, and anti-aliased discs, rings, thick lines and convex polygons.
Every primitive shares these invariants:
| enum rmgui_draw_mode_t |
How a source pixel combines with the pixel under it: OVER source over destination.
A straight colour (r, g, b) at coverage a follows the straight-over rule above (what rmgui_draw_fill_rect does). A premultiplied source s of alpha a (a layer surface or shadow, a backdrop tile) makes every channel, alpha included, s + round(dst * (255-a) / 255); ADD each colour channel becomes min(255, dst + round(a*src/255)) and alpha becomes min(255, dst_alpha + a): light accumulates. Used by the effect painters (layer.h, particle.h, backdrop.h).
The anti-aliased shapes (rmgui_draw_aa_*). Positions and lengths are Q16 device px: 65536 is one px, the _q16 fixed point of motion.h, so a caller mapping a logical canvas to device px passes the scaled values. Geometry is resolved to 1/256 px: every position and radius is rounded to the nearest 1/256 px, halves up. Each pixel (x, y) holds 16 x 16 sample points, sample (i, j) at (x + (2i+1)/32, y + (2j+1)/32) px, and its coverage c, 0..256, is the count of its samples inside the shape by the inside test each shape states below. A pixel with c > 0 is painted once with color at alpha (color.a * c + 128) / 256 in mode (the OVER straight-over rule or the ADD rule at rmgui_draw_mode_t); c == 256 paints color.a exactly, c == 0 leaves the pixel untouched. Painting is clipped to fb and to clip. Any int32 position or length is safe: the work is bounded by the visible pixels and every intermediate stays in 64 bits. Painting nothing: a NULL fb or points, color.a == 0, an empty clip, a mode or cap outside its enum.
| Enumerator | |
|---|---|
| RMGUI_DRAW_MODE_OVER | |
| RMGUI_DRAW_MODE_ADD | |
| enum rmgui_draw_cap_t |
| rmgui_color_t rmgui_draw_blend | ( | rmgui_color_t | under, |
| rmgui_color_t | top ) |
The color rmgui_draw_fill_rect leaves on a pixel of color under when painting top.r, top.g, top.b at coverage top.a (the straight-over rule above).
| void rmgui_draw_pixel | ( | rmgui_fb_t * | fb, |
| int | x, | ||
| int | y, | ||
| rmgui_color_t | color ) |
Blend the pixel (x, y).
| void rmgui_draw_hline | ( | rmgui_fb_t * | fb, |
| int | x, | ||
| int | y, | ||
| int | len, | ||
| rmgui_color_t | color ) |
Blend the len pixels (x .
. x+len-1, y). len <= 0 paints nothing.
| void rmgui_draw_vline | ( | rmgui_fb_t * | fb, |
| int | x, | ||
| int | y, | ||
| int | len, | ||
| rmgui_color_t | color ) |
Blend the len pixels (x, y .
. y+len-1). len <= 0 paints nothing.
| void rmgui_draw_rect | ( | rmgui_fb_t * | fb, |
| rmgui_rect_t | rect, | ||
| rmgui_color_t | color ) |
Blend the one-pixel outline of rect.
The top and bottom runs span the full width and own the corners; the side runs span the h-2 interior rows.
| void rmgui_draw_fill_rect | ( | rmgui_fb_t * | fb, |
| rmgui_rect_t | rect, | ||
| rmgui_color_t | color ) |
Blend every pixel of rect.
fb.h's rmgui_fb_fill_rect is the verbatim (non-blending) fill.
| void rmgui_draw_fill_rounded | ( | rmgui_fb_t * | fb, |
| rmgui_rect_t | rect, | ||
| int | radius, | ||
| rmgui_color_t | color ) |
Blend rect with rounded corners of radius radius, clamped to half the shorter side.
Row d rows from the nearer horizontal edge (d < radius) is inset on both sides by radius - isqrt(radius^2 - (radius-d)^2). radius <= 0 is rmgui_draw_fill_rect.
| void rmgui_draw_line | ( | rmgui_fb_t * | fb, |
| int | x0, | ||
| int | y0, | ||
| int | x1, | ||
| int | y1, | ||
| rmgui_color_t | color ) |
Blend the 8-connected line from (x0, y0) to (x1, y1), endpoints inclusive.
With D the larger and d the smaller of |x1-x0| and |y1-y0|, the point i steps along the major axis (x on ties) for i = 0 .. D and floor((2*d*i + D - 1) / (2*D)) steps along the minor axis toward the end point: the Bresenham line, exact halves resolved toward the start.
| void rmgui_draw_vgrad | ( | rmgui_fb_t * | fb, |
| rmgui_rect_t | rect, | ||
| const rmgui_draw_vgrad_stop_t * | stops, | ||
| int | n_stops ) |
Fill rect with a vertical gradient, written verbatim with alpha 255 (not blended).
Each rect row row is one flat color from stops (n_stops entries): rows at or above stops[0].row take its color, rows at or below stops[n_stops-1].row take the last color, and a row between the consecutive stops s0 and s1 with s0.row <= row < s1.row takes, per channel, c0 + (c1 - c0) * (row - s0.row) / (s1.row - s0.row) with C truncating division, so each stop row gets its stop's exact color. A pair with s1.row <= s0.row paints s0's color over its span. n_stops <= 0 paints nothing.
| rmgui_color_t rmgui_draw_vgrad_color | ( | const rmgui_draw_vgrad_stop_t * | stops, |
| int | n_stops, | ||
| int | row ) |
The color rmgui_draw_vgrad paints on gradient row row for the given stops, alpha 255.
NULL stops or n_stops <= 0 (a gradient that paints nothing) returns transparent black.
| void rmgui_draw_bevel_raised | ( | rmgui_fb_t * | fb, |
| rmgui_rect_t | rect, | ||
| rmgui_color_t | light, | ||
| rmgui_color_t | dark ) |
Write the 1px raised bevel of rect verbatim with alpha 255: light on the top run and left interior column, dark on the bottom run and right interior column, with rmgui_draw_rect's edge ownership.
The colors' a is not read: bevels are opaque.
| void rmgui_draw_bevel_recessed | ( | rmgui_fb_t * | fb, |
| rmgui_rect_t | rect, | ||
| rmgui_color_t | light, | ||
| rmgui_color_t | dark ) |
rmgui_draw_bevel_raised with the two colors swapped: dark on top and left, light on bottom and right.
| void rmgui_draw_aa_disc | ( | rmgui_fb_t * | fb, |
| rmgui_rect_t | clip, | ||
| rmgui_draw_point_t | centre, | ||
| int32_t | radius_q16, | ||
| rmgui_color_t | color, | ||
| rmgui_draw_mode_t | mode ) |
The disc of radius_q16 about centre: samples s with |s - centre| < radius.
radius_q16 below 128 (under 1/512 px) paints nothing.
| void rmgui_draw_aa_ring | ( | rmgui_fb_t * | fb, |
| rmgui_rect_t | clip, | ||
| rmgui_draw_point_t | centre, | ||
| int32_t | outer_q16, | ||
| int32_t | inner_q16, | ||
| rmgui_color_t | color, | ||
| rmgui_draw_mode_t | mode ) |
The ring about centre: samples s with inner <= |s - centre| < outer, the disc of outer less the disc of inner.
inner_q16 that rounds to <= 0 is rmgui_draw_aa_disc of outer_q16; inner >= outer paints nothing.
| void rmgui_draw_aa_line | ( | rmgui_fb_t * | fb, |
| rmgui_rect_t | clip, | ||
| rmgui_draw_point_t | from, | ||
| rmgui_draw_point_t | to, | ||
| int32_t | width_q16, | ||
| rmgui_draw_cap_t | cap, | ||
| rmgui_color_t | color, | ||
| rmgui_draw_mode_t | mode ) |
The line of width_q16 from from to to.
With h the half width (width_q16 / 512 rounded half up, in 1/256 px) and n the vector of length h perpendicular to to - from, rounded to 1/256 px per component (halves away from zero): BUTT is the rectangle with corners from + n, to + n, to - n, from - n (rmgui_draw_aa_polygon of them); ROUND adds the discs of radius h about from and to, each sample row covering the hull of the three pieces' spans. Swapping from and to paints the same pixels. h == 0 paints nothing, as does a zero-length BUTT line; a zero-length ROUND line is rmgui_draw_aa_disc of radius width_q16 / 2.
| void rmgui_draw_aa_polygon | ( | rmgui_fb_t * | fb, |
| rmgui_rect_t | clip, | ||
| const rmgui_draw_point_t * | points, | ||
| int | count, | ||
| rmgui_color_t | color, | ||
| rmgui_draw_mode_t | mode ) |
The convex polygon through points[0 .
. count-1], either winding: the samples strictly inside every edge, the inside of an edge being the side the polygon's first non-zero turn bends toward. Zero-length edges are ignored. A non-convex input paints the intersection of those edge half-planes; count < 3, or every point on one line, paints nothing.
| int rmgui_draw_aa_contours | ( | rmgui_fb_t * | , |
| rmgui_rect_t | , | ||
| const rmgui_draw_vertex_t * | , | ||
| size_t | , | ||
| rmgui_draw_fill_rule_t | , | ||
| rmgui_color_t | , | ||
| rmgui_draw_mode_t | , | ||
| rmgui_draw_crossing_t * | , | ||
| size_t | ) |
Paint arbitrary, possibly self-intersecting contours once at 16x16 coverage.
Scratch capacity must be >= count, including empty clips. No allocation; fixed stack coverage is 1024 uint16_t values. Edges are scheduled by their Y bounds in caller scratch; each sample row visits only edges overlapping its pixel row and repairs their crossing order. Returns -1 unchanged on NULL, missing initial MOVE, invalid rule/mode, or insufficient scratch; zero vertices paints nothing.