From 1dfe4ebc19cd3124391439c7e08a445b7b28494d Mon Sep 17 00:00:00 2001 From: 0x0203 <44345347+0x0203@users.noreply.github.com> Date: Thu, 6 Jun 2019 12:58:03 -0400 Subject: [PATCH] Implement software rendering of RECT_MUTI_COLOR for x11_rawfb --- demo/x11_rawfb/nuklear_rawfb.h | 80 +++++++++++++++++++++++++++++++++- 1 file changed, 79 insertions(+), 1 deletion(-) diff --git a/demo/x11_rawfb/nuklear_rawfb.h b/demo/x11_rawfb/nuklear_rawfb.h index ef6f3316..9a8ea684 100644 --- a/demo/x11_rawfb/nuklear_rawfb.h +++ b/demo/x11_rawfb/nuklear_rawfb.h @@ -561,6 +561,81 @@ nk_rawfb_fill_rect(const struct rawfb_context *rawfb, } } +NK_API void +nk_rawfb_draw_rect_multi_color(const struct rawfb_context *rawfb, + const short x, const short y, const short w, const short h, struct nk_color tl, + struct nk_color tr, struct nk_color br, struct nk_color bl) +{ + int i, j; + struct nk_color *edge_buf; + struct nk_color *edge_t; + struct nk_color *edge_b; + struct nk_color *edge_l; + struct nk_color *edge_r; + struct nk_color pixel; + + edge_buf = malloc(((2*w) + (2*h)) * sizeof(struct nk_color)); + if (edge_buf == NULL) + return; + + edge_t = edge_buf; + edge_b = edge_buf + w; + edge_l = edge_buf + (w*2); + edge_r = edge_buf + (w*2) + h; + + /* Top and bottom edge gradients */ + for (i=0; ifb, x+j, y+i, edge_t[j]); + } else if (i==h-1) { + nk_rawfb_img_blendpixel(&rawfb->fb, x+j, y+i, edge_b[j]); + } else { + if (j==0) { + nk_rawfb_img_blendpixel(&rawfb->fb, x+j, y+i, edge_l[i]); + } else if (j==w-1) { + nk_rawfb_img_blendpixel(&rawfb->fb, x+j, y+i, edge_r[i]); + } else { + pixel.r = (((((float)edge_r[i].r - edge_l[i].r)/(w-1))*j) + 0.5) + edge_l[i].r; + pixel.g = (((((float)edge_r[i].g - edge_l[i].g)/(w-1))*j) + 0.5) + edge_l[i].g; + pixel.b = (((((float)edge_r[i].b - edge_l[i].b)/(w-1))*j) + 0.5) + edge_l[i].b; + pixel.a = (((((float)edge_r[i].a - edge_l[i].a)/(w-1))*j) + 0.5) + edge_l[i].a; + nk_rawfb_img_blendpixel(&rawfb->fb, x+j, y+i, pixel); + } + } + } + } + + free(edge_buf); +} + static void nk_rawfb_fill_triangle(const struct rawfb_context *rawfb, const short x0, const short y0, const short x1, const short y1, @@ -1002,7 +1077,10 @@ nk_rawfb_render(const struct rawfb_context *rawfb, nk_rawfb_stroke_curve(rawfb, q->begin, q->ctrl[0], q->ctrl[1], q->end, 22, q->line_thickness, q->color); } break; - case NK_COMMAND_RECT_MULTI_COLOR: + case NK_COMMAND_RECT_MULTI_COLOR: { + const struct nk_command_rect_multi_color *q = (const struct nk_command_rect_multi_color *)cmd; + nk_rawfb_draw_rect_multi_color(rawfb, q->x, q->y, q->w, q->h, q->left, q->top, q->right, q->bottom); + } break; case NK_COMMAND_IMAGE: { const struct nk_command_image *q = (const struct nk_command_image *)cmd; nk_rawfb_drawimage(rawfb, q->x, q->y, q->w, q->h, &q->img, &q->col);