|
RMGui 0.15.0
C11 retained-mode UI library: layout kernel, style schema, widget painters, fonts, software framebuffer
|
gradient.h — allocation-free, multi-stop RGBA8 gradient composites. More...
Data Structures | |
| struct | rmgui_gradient_stop_t |
| A stop at pos / 65535 of the gradient axis; color is straight RGBA8. More... | |
Functions | |
| rmgui_color_t | rmgui_gradient_color (const rmgui_gradient_stop_t *stops, int n_stops, uint16_t pos) |
| Evaluate n_stops > 0 stops in non-decreasing position order. | |
| int | rmgui_gradient_linear (rmgui_fb_t *fb, rmgui_rect_t clip, rmgui_rect_t rect, rmgui_draw_point_t from, rmgui_draw_point_t to, const rmgui_gradient_stop_t *stops, int n_stops, rmgui_draw_mode_t mode) |
| Composite a linear gradient inside rect intersect clip intersect fb. | |
| int | rmgui_gradient_radial (rmgui_fb_t *fb, rmgui_rect_t clip, rmgui_rect_t rect, rmgui_draw_point_t centre, int32_t radius_x_q16, int32_t radius_y_q16, const rmgui_gradient_stop_t *stops, int n_stops, rmgui_draw_mode_t mode) |
| Composite an elliptical radial gradient over the same intersection and with the same stop, blend, clipping and return rules as linear. | |
| int | rmgui_gradient_conic (rmgui_fb_t *fb, rmgui_rect_t clip, rmgui_rect_t rect, rmgui_draw_point_t centre, int32_t angle_q16, const rmgui_gradient_stop_t *stops, int n_stops, rmgui_draw_mode_t mode) |
| Composite a clockwise angular gradient over the same intersection with linear's stop, blend, clipping, ownership and return rules. | |
gradient.h — allocation-free, multi-stop RGBA8 gradient composites.
| rmgui_color_t rmgui_gradient_color | ( | const rmgui_gradient_stop_t * | stops, |
| int | n_stops, | ||
| uint16_t | pos ) |
Evaluate n_stops > 0 stops in non-decreasing position order.
Outside their range the end colors hold; at coincident stops the last color wins. Stop colors are exact. Between positions p0 and p1, let d = p1-p0, f = pos-p0, A = (d-f)*a0 + f*a1 and, per RGB channel, C = (d-f)*a0*c0 + f*a1*c1. The result is alpha round(A/d), RGB round(C/A), rounding halves up; A == 0 returns transparent black. Thus interpolation is premultiplied, with no transparent-color bleed. NULL stops, a non-positive count or decreasing positions return transparent black. The caller bounds the count and provides that many readable stops, unchanged during a call. No allocation or count-dependent stack storage.
| int rmgui_gradient_linear | ( | rmgui_fb_t * | fb, |
| rmgui_rect_t | clip, | ||
| rmgui_rect_t | rect, | ||
| rmgui_draw_point_t | from, | ||
| rmgui_draw_point_t | to, | ||
| const rmgui_gradient_stop_t * | stops, | ||
| int | n_stops, | ||
| rmgui_draw_mode_t | mode ) |
Composite a linear gradient inside rect intersect clip intersect fb.
from and to are absolute Q16 device-pixel positions. For pixel centre P = (65536*x+32768, 65536*y+32768), the position is round(65535 * clamp(dot(P-from,to-from)/|to-from|^2, 0, 1)), halves up. Each pixel composites rmgui_gradient_color's straight result once using draw.h's OVER or ADD rule. Clipping never changes the sampled position. Returns 0, including an empty fb, rect or clip. Returns -1 unchanged for NULL fb, invalid stops (as above), invalid mode or from == to. All int coordinates are accepted, without allocation or overflow; work is bounded by the visible pixels and the caller's stop count.
| int rmgui_gradient_radial | ( | rmgui_fb_t * | fb, |
| rmgui_rect_t | clip, | ||
| rmgui_rect_t | rect, | ||
| rmgui_draw_point_t | centre, | ||
| int32_t | radius_x_q16, | ||
| int32_t | radius_y_q16, | ||
| const rmgui_gradient_stop_t * | stops, | ||
| int | n_stops, | ||
| rmgui_draw_mode_t | mode ) |
Composite an elliptical radial gradient over the same intersection and with the same stop, blend, clipping and return rules as linear.
centre and positive radii are absolute Q16 device-pixel units. For each pixel centre, normalize each signed displacement to Q16 by dividing by its radius, rounding nearest with halves toward positive infinity. Let D be floor(sqrt(nx*nx + ny*ny)); position is min(65535, round(D*65535/65536)), halves up. A displacement whose absolute value reaches either radius takes position 65535 directly. Non-positive radii refuse with -1 unchanged. No allocation; work is bounded by the visible pixels, 17 square-root steps and the caller's stop count per pixel.
| int rmgui_gradient_conic | ( | rmgui_fb_t * | fb, |
| rmgui_rect_t | clip, | ||
| rmgui_rect_t | rect, | ||
| rmgui_draw_point_t | centre, | ||
| int32_t | angle_q16, | ||
| const rmgui_gradient_stop_t * | stops, | ||
| int | n_stops, | ||
| rmgui_draw_mode_t | mode ) |
Composite a clockwise angular gradient over the same intersection with linear's stop, blend, clipping, ownership and return rules.
centre is an absolute Q16 device-pixel position; angle_q16 is a signed Q16 turn offset (65536 is one turn), reduced modulo one turn. Zero starts on the +x ray; increasing angles rotate the starting ray toward +y.
At each pixel centre, obtain the displacement angle clockwise from +x by 31-step integer CORDIC in Q32 turns, then round to Q16 with halves toward positive infinity. Position is (angle - angle_q16) modulo 65536, directly in stop-position units. The +x ray therefore samples 0 at zero offset, +y 16384, -x 32768 and -y 49152; axes and diagonals are exact. A pixel exactly at centre samples position 0 regardless of the offset. There is a seam at the starting ray; endpoint colors need not agree. No allocation or floating point; stack use is independent of stop count, work is bounded by visible pixels, 31 CORDIC steps and caller stop count.