2016-12-06 09:28:54 +03:00
|
|
|
/*
|
|
|
|
* MIT License
|
|
|
|
*
|
|
|
|
* Copyright (c) 2016-2017 Patrick Rudolph <siro@das-labor.org>
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
|
|
* SOFTWARE.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* ==============================================================
|
|
|
|
*
|
|
|
|
* API
|
|
|
|
*
|
|
|
|
* ===============================================================
|
|
|
|
*/
|
2024-05-03 13:46:23 +03:00
|
|
|
|
2016-12-06 09:28:54 +03:00
|
|
|
#ifndef NK_RAWFB_H_
|
|
|
|
#define NK_RAWFB_H_
|
|
|
|
|
|
|
|
struct rawfb_context;
|
|
|
|
|
2024-05-03 13:46:23 +03:00
|
|
|
struct rawfb_pl {
|
|
|
|
unsigned char bytesPerPixel;
|
|
|
|
unsigned char rshift, gshift, bshift, ashift;
|
|
|
|
unsigned char rloss, gloss, bloss, aloss;
|
|
|
|
};
|
2019-06-06 21:41:52 +03:00
|
|
|
|
2016-12-06 09:28:54 +03:00
|
|
|
/* All functions are thread-safe */
|
2024-05-03 13:46:23 +03:00
|
|
|
NK_API struct rawfb_context *nk_rawfb_init(void *fb, void *tex_mem, const unsigned int w, const unsigned int h, const unsigned int pitch, const struct rawfb_pl pl);
|
2016-12-06 09:28:54 +03:00
|
|
|
NK_API void nk_rawfb_render(const struct rawfb_context *rawfb, const struct nk_color clear, const unsigned char enable_clear);
|
|
|
|
NK_API void nk_rawfb_shutdown(struct rawfb_context *rawfb);
|
2024-05-03 13:46:23 +03:00
|
|
|
NK_API void nk_rawfb_resize_fb(struct rawfb_context *rawfb, void *fb, const unsigned int w, const unsigned int h, const unsigned int pitch, const struct rawfb_pl pl);
|
2016-12-06 09:28:54 +03:00
|
|
|
|
|
|
|
#endif
|
|
|
|
/*
|
|
|
|
* ==============================================================
|
|
|
|
*
|
|
|
|
* IMPLEMENTATION
|
|
|
|
*
|
|
|
|
* ===============================================================
|
|
|
|
*/
|
|
|
|
#ifdef NK_RAWFB_IMPLEMENTATION
|
2024-01-20 15:46:45 +03:00
|
|
|
#include <string.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
2016-12-06 09:28:54 +03:00
|
|
|
struct rawfb_image {
|
|
|
|
void *pixels;
|
2017-10-07 15:30:22 +03:00
|
|
|
int w, h, pitch;
|
2024-05-03 13:46:23 +03:00
|
|
|
struct rawfb_pl pl;
|
2016-12-06 09:28:54 +03:00
|
|
|
};
|
|
|
|
struct rawfb_context {
|
|
|
|
struct nk_context ctx;
|
|
|
|
struct nk_rect scissors;
|
|
|
|
struct rawfb_image fb;
|
|
|
|
struct rawfb_image font_tex;
|
|
|
|
struct nk_font_atlas atlas;
|
|
|
|
};
|
|
|
|
|
|
|
|
#ifndef MIN
|
|
|
|
#define MIN(a,b) ((a) < (b) ? (a) : (b))
|
|
|
|
#endif
|
|
|
|
#ifndef MAX
|
|
|
|
#define MAX(a,b) ((a) < (b) ? (b) : (a))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
static unsigned int
|
2024-05-03 13:46:23 +03:00
|
|
|
nk_rawfb_color2int(const struct nk_color c, const struct rawfb_pl pl)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
unsigned int res = 0;
|
2019-06-06 21:41:52 +03:00
|
|
|
|
2024-05-03 13:46:23 +03:00
|
|
|
res |= (c.r >> pl.rloss) << pl.rshift;
|
|
|
|
res |= (c.g >> pl.gloss) << pl.gshift;
|
|
|
|
res |= (c.b >> pl.bloss) << pl.bshift;
|
|
|
|
res |= (c.a >> pl.aloss) << pl.ashift;
|
|
|
|
|
2016-12-06 09:28:54 +03:00
|
|
|
return (res);
|
|
|
|
}
|
|
|
|
|
2019-06-06 19:42:32 +03:00
|
|
|
static struct nk_color
|
2024-05-03 13:46:23 +03:00
|
|
|
nk_rawfb_int2color(const unsigned int i, const struct rawfb_pl pl)
|
2019-06-06 19:42:32 +03:00
|
|
|
{
|
2019-06-06 21:41:52 +03:00
|
|
|
struct nk_color col = {0,0,0,0};
|
|
|
|
|
2024-05-03 13:46:23 +03:00
|
|
|
col.r = (pl.rloss == 8) ? 0xff : ((i >> pl.rshift) << pl.rloss) & 0xff;
|
|
|
|
col.g = (pl.gloss == 8) ? 0xff : ((i >> pl.gshift) << pl.gloss) & 0xff;
|
|
|
|
col.b = (pl.bloss == 8) ? 0xff : ((i >> pl.bshift) << pl.bloss) & 0xff;
|
|
|
|
col.a = (pl.aloss == 8) ? 0xff : ((i >> pl.ashift) << pl.aloss) & 0xff;
|
|
|
|
|
2019-06-06 19:42:32 +03:00
|
|
|
return col;
|
|
|
|
}
|
|
|
|
|
2016-12-06 09:28:54 +03:00
|
|
|
static void
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_ctx_setpixel(const struct rawfb_context *rawfb,
|
2017-10-07 15:30:22 +03:00
|
|
|
const short x0, const short y0, const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
2019-06-06 21:41:52 +03:00
|
|
|
unsigned int c = nk_rawfb_color2int(col, rawfb->fb.pl);
|
2018-02-04 19:08:17 +03:00
|
|
|
unsigned char *pixels = rawfb->fb.pixels;
|
2016-12-06 09:28:54 +03:00
|
|
|
|
2018-02-04 19:08:17 +03:00
|
|
|
pixels += y0 * rawfb->fb.pitch;
|
2016-12-06 09:28:54 +03:00
|
|
|
|
|
|
|
if (y0 < rawfb->scissors.h && y0 >= rawfb->scissors.y &&
|
2024-05-03 13:46:23 +03:00
|
|
|
x0 >= rawfb->scissors.x && x0 < rawfb->scissors.w) {
|
|
|
|
|
|
|
|
if (rawfb->fb.pl.bytesPerPixel == sizeof(unsigned int)) {
|
|
|
|
*((unsigned int *)pixels + x0) = c;
|
|
|
|
} else if (rawfb->fb.pl.bytesPerPixel == sizeof(unsigned short)) {
|
|
|
|
*((unsigned short *)pixels + x0) = c;
|
|
|
|
} else {
|
|
|
|
*((unsigned char *)pixels + x0) = c;
|
|
|
|
}
|
|
|
|
}
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nk_rawfb_line_horizontal(const struct rawfb_context *rawfb,
|
2017-10-07 15:30:22 +03:00
|
|
|
const short x0, const short y, const short x1, const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
2017-10-07 15:30:22 +03:00
|
|
|
/* This function is called the most. Try to optimize it a bit...
|
|
|
|
* It does not check for scissors or image borders.
|
|
|
|
* The caller has to make sure it does no exceed bounds. */
|
2016-12-06 09:28:54 +03:00
|
|
|
unsigned int i, n;
|
2024-05-03 13:46:23 +03:00
|
|
|
unsigned char c[16 * 4];
|
2018-02-04 19:08:17 +03:00
|
|
|
unsigned char *pixels = rawfb->fb.pixels;
|
2024-05-03 13:46:23 +03:00
|
|
|
unsigned int bpp = rawfb->fb.pl.bytesPerPixel;
|
2018-02-04 19:08:17 +03:00
|
|
|
|
2024-05-03 13:46:23 +03:00
|
|
|
pixels += (y * rawfb->fb.pitch) + (x0 * bpp);
|
2016-12-06 09:28:54 +03:00
|
|
|
|
2024-05-03 13:46:23 +03:00
|
|
|
n = (x1 - x0) * bpp;
|
|
|
|
if (bpp == sizeof(unsigned int)) {
|
|
|
|
for (i = 0; i < sizeof(c) / bpp; i++)
|
|
|
|
((unsigned int *)c)[i] = nk_rawfb_color2int(col, rawfb->fb.pl);
|
|
|
|
} else if (bpp == sizeof(unsigned short)) {
|
|
|
|
for (i = 0; i < sizeof(c) / bpp; i++)
|
|
|
|
((unsigned short *)c)[i] = nk_rawfb_color2int(col, rawfb->fb.pl);
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < sizeof(c) / bpp; i++)
|
|
|
|
((unsigned char *)c)[i] = nk_rawfb_color2int(col, rawfb->fb.pl);
|
|
|
|
}
|
2016-12-06 09:28:54 +03:00
|
|
|
|
2024-05-03 13:46:23 +03:00
|
|
|
while (n > sizeof(c)) {
|
|
|
|
memcpy((void*)pixels, c, sizeof(c));
|
|
|
|
n -= sizeof(c); pixels += sizeof(c);
|
2017-10-07 15:30:22 +03:00
|
|
|
} for (i = 0; i < n; i++)
|
2024-05-03 13:46:23 +03:00
|
|
|
pixels[i] = c[i];
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_img_setpixel(const struct rawfb_image *img,
|
2017-10-07 15:30:22 +03:00
|
|
|
const int x0, const int y0, const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
2019-06-06 21:41:52 +03:00
|
|
|
unsigned int c = nk_rawfb_color2int(col, img->pl);
|
2016-12-06 09:28:54 +03:00
|
|
|
unsigned char *ptr;
|
|
|
|
NK_ASSERT(img);
|
2019-06-06 19:42:32 +03:00
|
|
|
if (y0 < img->h && y0 >= 0 && x0 >= 0 && x0 < img->w) {
|
2021-12-16 22:44:00 +03:00
|
|
|
ptr = (unsigned char *)img->pixels + (img->pitch * y0);
|
2019-06-06 19:42:32 +03:00
|
|
|
|
2024-05-03 13:46:23 +03:00
|
|
|
if (img->pl.bytesPerPixel == sizeof(unsigned int)) {
|
|
|
|
((unsigned int *)ptr)[x0] = c;
|
|
|
|
} else if (img->pl.bytesPerPixel == sizeof(unsigned short)) {
|
|
|
|
((unsigned short *)ptr)[x0] = c;
|
2016-12-06 09:28:54 +03:00
|
|
|
} else {
|
2024-05-03 13:46:23 +03:00
|
|
|
((unsigned char *)ptr)[x0] = c;
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct nk_color
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_img_getpixel(const struct rawfb_image *img, const int x0, const int y0)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
struct nk_color col = {0, 0, 0, 0};
|
|
|
|
unsigned char *ptr;
|
2019-06-11 01:03:22 +03:00
|
|
|
unsigned int pixel;
|
2016-12-06 09:28:54 +03:00
|
|
|
NK_ASSERT(img);
|
2019-06-06 19:42:32 +03:00
|
|
|
if (y0 < img->h && y0 >= 0 && x0 >= 0 && x0 < img->w) {
|
2021-12-16 22:44:00 +03:00
|
|
|
ptr = (unsigned char *)img->pixels + (img->pitch * y0);
|
2019-06-06 19:42:32 +03:00
|
|
|
|
2024-05-03 13:46:23 +03:00
|
|
|
if (img->pl.bytesPerPixel == sizeof(unsigned int)) {
|
2024-04-06 08:27:07 +03:00
|
|
|
pixel = ((unsigned int *)ptr)[x0];
|
|
|
|
col = nk_rawfb_int2color(pixel, img->pl);
|
2024-05-03 13:46:23 +03:00
|
|
|
} else if (img->pl.bytesPerPixel == sizeof(unsigned short)) {
|
|
|
|
pixel = ((unsigned short *)ptr)[x0];
|
|
|
|
col = nk_rawfb_int2color(pixel, img->pl);
|
|
|
|
} else {
|
|
|
|
pixel = ((unsigned char *)ptr)[x0];
|
|
|
|
col = nk_rawfb_int2color(pixel, img->pl);
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
2017-10-07 15:30:22 +03:00
|
|
|
} return col;
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
static void
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_img_blendpixel(const struct rawfb_image *img,
|
2017-10-07 15:30:22 +03:00
|
|
|
const int x0, const int y0, struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
struct nk_color col2;
|
|
|
|
unsigned char inv_a;
|
|
|
|
if (col.a == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
inv_a = 0xff - col.a;
|
2019-06-06 19:42:32 +03:00
|
|
|
col2 = nk_rawfb_img_getpixel(img, x0, y0);
|
2016-12-06 09:28:54 +03:00
|
|
|
col.r = (col.r * col.a + col2.r * inv_a) >> 8;
|
|
|
|
col.g = (col.g * col.a + col2.g * inv_a) >> 8;
|
|
|
|
col.b = (col.b * col.a + col2.b * inv_a) >> 8;
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_img_setpixel(img, x0, y0, col);
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nk_rawfb_scissor(struct rawfb_context *rawfb,
|
|
|
|
const float x,
|
|
|
|
const float y,
|
|
|
|
const float w,
|
|
|
|
const float h)
|
|
|
|
{
|
|
|
|
rawfb->scissors.x = MIN(MAX(x, 0), rawfb->fb.w);
|
|
|
|
rawfb->scissors.y = MIN(MAX(y, 0), rawfb->fb.h);
|
|
|
|
rawfb->scissors.w = MIN(MAX(w + x, 0), rawfb->fb.w);
|
|
|
|
rawfb->scissors.h = MIN(MAX(h + y, 0), rawfb->fb.h);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nk_rawfb_stroke_line(const struct rawfb_context *rawfb,
|
2017-10-07 15:30:22 +03:00
|
|
|
short x0, short y0, short x1, short y1,
|
|
|
|
const unsigned int line_thickness, const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
short tmp;
|
2017-10-07 15:30:22 +03:00
|
|
|
int dy, dx, stepx, stepy;
|
2016-12-06 09:28:54 +03:00
|
|
|
|
2021-12-16 22:44:00 +03:00
|
|
|
NK_UNUSED(line_thickness);
|
|
|
|
|
2016-12-06 09:28:54 +03:00
|
|
|
dy = y1 - y0;
|
|
|
|
dx = x1 - x0;
|
|
|
|
|
|
|
|
/* fast path */
|
|
|
|
if (dy == 0) {
|
|
|
|
if (dx == 0 || y0 >= rawfb->scissors.h || y0 < rawfb->scissors.y)
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (dx < 0) {
|
|
|
|
/* swap x0 and x1 */
|
|
|
|
tmp = x1;
|
|
|
|
x1 = x0;
|
|
|
|
x0 = tmp;
|
|
|
|
}
|
2019-06-01 02:31:54 +03:00
|
|
|
x1 = MIN(rawfb->scissors.w, x1);
|
|
|
|
x0 = MIN(rawfb->scissors.w, x0);
|
2016-12-06 09:28:54 +03:00
|
|
|
x1 = MAX(rawfb->scissors.x, x1);
|
|
|
|
x0 = MAX(rawfb->scissors.x, x0);
|
|
|
|
nk_rawfb_line_horizontal(rawfb, x0, y0, x1, col);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
if (dy < 0) {
|
|
|
|
dy = -dy;
|
|
|
|
stepy = -1;
|
2017-10-07 15:30:22 +03:00
|
|
|
} else stepy = 1;
|
2016-12-06 09:28:54 +03:00
|
|
|
|
|
|
|
if (dx < 0) {
|
|
|
|
dx = -dx;
|
|
|
|
stepx = -1;
|
2017-10-07 15:30:22 +03:00
|
|
|
} else stepx = 1;
|
2016-12-06 09:28:54 +03:00
|
|
|
|
|
|
|
dy <<= 1;
|
|
|
|
dx <<= 1;
|
|
|
|
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0, y0, col);
|
2016-12-06 09:28:54 +03:00
|
|
|
if (dx > dy) {
|
|
|
|
int fraction = dy - (dx >> 1);
|
|
|
|
while (x0 != x1) {
|
|
|
|
if (fraction >= 0) {
|
|
|
|
y0 += stepy;
|
|
|
|
fraction -= dx;
|
|
|
|
}
|
|
|
|
x0 += stepx;
|
|
|
|
fraction += dy;
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0, y0, col);
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
int fraction = dx - (dy >> 1);
|
|
|
|
while (y0 != y1) {
|
|
|
|
if (fraction >= 0) {
|
|
|
|
x0 += stepx;
|
|
|
|
fraction -= dy;
|
|
|
|
}
|
|
|
|
y0 += stepy;
|
|
|
|
fraction += dx;
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0, y0, col);
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nk_rawfb_fill_polygon(const struct rawfb_context *rawfb,
|
2017-10-07 15:30:22 +03:00
|
|
|
const struct nk_vec2i *pnts, int count, const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
int i = 0;
|
2017-10-07 15:30:22 +03:00
|
|
|
#define MAX_POINTS 64
|
2016-12-06 09:28:54 +03:00
|
|
|
int left = 10000, top = 10000, bottom = 0, right = 0;
|
2017-10-07 15:30:22 +03:00
|
|
|
int nodes, nodeX[MAX_POINTS], pixelX, pixelY, j, swap ;
|
2016-12-06 09:28:54 +03:00
|
|
|
|
2017-10-07 15:30:22 +03:00
|
|
|
if (count == 0) return;
|
2016-12-06 09:28:54 +03:00
|
|
|
if (count > MAX_POINTS)
|
|
|
|
count = MAX_POINTS;
|
|
|
|
|
|
|
|
/* Get polygon dimensions */
|
|
|
|
for (i = 0; i < count; i++) {
|
|
|
|
if (left > pnts[i].x)
|
|
|
|
left = pnts[i].x;
|
|
|
|
if (right < pnts[i].x)
|
|
|
|
right = pnts[i].x;
|
|
|
|
if (top > pnts[i].y)
|
|
|
|
top = pnts[i].y;
|
|
|
|
if (bottom < pnts[i].y)
|
|
|
|
bottom = pnts[i].y;
|
2017-10-07 15:30:22 +03:00
|
|
|
} bottom++; right++;
|
2016-12-06 09:28:54 +03:00
|
|
|
|
|
|
|
/* Polygon scanline algorithm released under public-domain by Darel Rex Finley, 2007 */
|
|
|
|
/* Loop through the rows of the image. */
|
|
|
|
for (pixelY = top; pixelY < bottom; pixelY ++) {
|
2017-10-07 15:30:22 +03:00
|
|
|
nodes = 0; /* Build a list of nodes. */
|
2016-12-06 09:28:54 +03:00
|
|
|
j = count - 1;
|
|
|
|
for (i = 0; i < count; i++) {
|
2017-10-07 15:30:22 +03:00
|
|
|
if (((pnts[i].y < pixelY) && (pnts[j].y >= pixelY)) ||
|
|
|
|
((pnts[j].y < pixelY) && (pnts[i].y >= pixelY))) {
|
|
|
|
nodeX[nodes++]= (int)((float)pnts[i].x
|
|
|
|
+ ((float)pixelY - (float)pnts[i].y) / ((float)pnts[j].y - (float)pnts[i].y)
|
2016-12-06 09:28:54 +03:00
|
|
|
* ((float)pnts[j].x - (float)pnts[i].x));
|
2017-10-07 15:30:22 +03:00
|
|
|
} j = i;
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Sort the nodes, via a simple “Bubble” sort. */
|
|
|
|
i = 0;
|
|
|
|
while (i < nodes - 1) {
|
|
|
|
if (nodeX[i] > nodeX[i+1]) {
|
|
|
|
swap = nodeX[i];
|
|
|
|
nodeX[i] = nodeX[i+1];
|
|
|
|
nodeX[i+1] = swap;
|
2017-10-07 15:30:22 +03:00
|
|
|
if (i) i--;
|
|
|
|
} else i++;
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
/* Fill the pixels between node pairs. */
|
|
|
|
for (i = 0; i < nodes; i += 2) {
|
2017-10-07 15:30:22 +03:00
|
|
|
if (nodeX[i+0] >= right) break;
|
|
|
|
if (nodeX[i+1] > left) {
|
|
|
|
if (nodeX[i+0] < left) nodeX[i+0] = left ;
|
|
|
|
if (nodeX[i+1] > right) nodeX[i+1] = right;
|
2016-12-06 09:28:54 +03:00
|
|
|
for (pixelX = nodeX[i]; pixelX < nodeX[i + 1]; pixelX++)
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_ctx_setpixel(rawfb, pixelX, pixelY, col);
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#undef MAX_POINTS
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nk_rawfb_stroke_arc(const struct rawfb_context *rawfb,
|
2017-10-07 15:30:22 +03:00
|
|
|
short x0, short y0, short w, short h, const short s,
|
|
|
|
const short line_thickness, const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
/* Bresenham's ellipses - modified to draw one quarter */
|
|
|
|
const int a2 = (w * w) / 4;
|
|
|
|
const int b2 = (h * h) / 4;
|
|
|
|
const int fa2 = 4 * a2, fb2 = 4 * b2;
|
|
|
|
int x, y, sigma;
|
|
|
|
|
2021-12-16 22:44:00 +03:00
|
|
|
NK_UNUSED(line_thickness);
|
|
|
|
|
2017-10-07 15:30:22 +03:00
|
|
|
if (s != 0 && s != 90 && s != 180 && s != 270) return;
|
|
|
|
if (w < 1 || h < 1) return;
|
2016-12-06 09:28:54 +03:00
|
|
|
|
|
|
|
/* Convert upper left to center */
|
|
|
|
h = (h + 1) / 2;
|
|
|
|
w = (w + 1) / 2;
|
2017-10-07 15:30:22 +03:00
|
|
|
x0 += w; y0 += h;
|
2016-12-06 09:28:54 +03:00
|
|
|
|
|
|
|
/* First half */
|
|
|
|
for (x = 0, y = h, sigma = 2*b2+a2*(1-2*h); b2*x <= a2*y; x++) {
|
|
|
|
if (s == 180)
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0 + x, y0 + y, col);
|
2016-12-06 09:28:54 +03:00
|
|
|
else if (s == 270)
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0 - x, y0 + y, col);
|
2016-12-06 09:28:54 +03:00
|
|
|
else if (s == 0)
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0 + x, y0 - y, col);
|
2016-12-06 09:28:54 +03:00
|
|
|
else if (s == 90)
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0 - x, y0 - y, col);
|
2016-12-06 09:28:54 +03:00
|
|
|
if (sigma >= 0) {
|
|
|
|
sigma += fa2 * (1 - y);
|
|
|
|
y--;
|
2017-10-07 15:30:22 +03:00
|
|
|
} sigma += b2 * ((4 * x) + 6);
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Second half */
|
|
|
|
for (x = w, y = 0, sigma = 2*a2+b2*(1-2*w); a2*y <= b2*x; y++) {
|
|
|
|
if (s == 180)
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0 + x, y0 + y, col);
|
2016-12-06 09:28:54 +03:00
|
|
|
else if (s == 270)
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0 - x, y0 + y, col);
|
2016-12-06 09:28:54 +03:00
|
|
|
else if (s == 0)
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0 + x, y0 - y, col);
|
2016-12-06 09:28:54 +03:00
|
|
|
else if (s == 90)
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0 - x, y0 - y, col);
|
2016-12-06 09:28:54 +03:00
|
|
|
if (sigma >= 0) {
|
|
|
|
sigma += fb2 * (1 - x);
|
|
|
|
x--;
|
2017-10-07 15:30:22 +03:00
|
|
|
} sigma += a2 * ((4 * y) + 6);
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-07 15:30:22 +03:00
|
|
|
nk_rawfb_fill_arc(const struct rawfb_context *rawfb, short x0, short y0,
|
|
|
|
short w, short h, const short s, const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
/* Bresenham's ellipses - modified to fill one quarter */
|
|
|
|
const int a2 = (w * w) / 4;
|
|
|
|
const int b2 = (h * h) / 4;
|
|
|
|
const int fa2 = 4 * a2, fb2 = 4 * b2;
|
|
|
|
int x, y, sigma;
|
|
|
|
struct nk_vec2i pnts[3];
|
2017-10-07 15:30:22 +03:00
|
|
|
if (w < 1 || h < 1) return;
|
2016-12-06 09:28:54 +03:00
|
|
|
if (s != 0 && s != 90 && s != 180 && s != 270)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Convert upper left to center */
|
|
|
|
h = (h + 1) / 2;
|
|
|
|
w = (w + 1) / 2;
|
|
|
|
x0 += w;
|
|
|
|
y0 += h;
|
|
|
|
|
|
|
|
pnts[0].x = x0;
|
|
|
|
pnts[0].y = y0;
|
|
|
|
pnts[2].x = x0;
|
|
|
|
pnts[2].y = y0;
|
2017-10-07 15:30:22 +03:00
|
|
|
|
2016-12-06 09:28:54 +03:00
|
|
|
/* First half */
|
|
|
|
for (x = 0, y = h, sigma = 2*b2+a2*(1-2*h); b2*x <= a2*y; x++) {
|
|
|
|
if (s == 180) {
|
|
|
|
pnts[1].x = x0 + x; pnts[1].y = y0 + y;
|
|
|
|
} else if (s == 270) {
|
|
|
|
pnts[1].x = x0 - x; pnts[1].y = y0 + y;
|
|
|
|
} else if (s == 0) {
|
|
|
|
pnts[1].x = x0 + x; pnts[1].y = y0 - y;
|
|
|
|
} else if (s == 90) {
|
|
|
|
pnts[1].x = x0 - x; pnts[1].y = y0 - y;
|
|
|
|
}
|
|
|
|
nk_rawfb_fill_polygon(rawfb, pnts, 3, col);
|
|
|
|
pnts[2] = pnts[1];
|
|
|
|
if (sigma >= 0) {
|
|
|
|
sigma += fa2 * (1 - y);
|
|
|
|
y--;
|
2017-10-07 15:30:22 +03:00
|
|
|
} sigma += b2 * ((4 * x) + 6);
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Second half */
|
|
|
|
for (x = w, y = 0, sigma = 2*a2+b2*(1-2*w); a2*y <= b2*x; y++) {
|
|
|
|
if (s == 180) {
|
|
|
|
pnts[1].x = x0 + x; pnts[1].y = y0 + y;
|
|
|
|
} else if (s == 270) {
|
|
|
|
pnts[1].x = x0 - x; pnts[1].y = y0 + y;
|
|
|
|
} else if (s == 0) {
|
|
|
|
pnts[1].x = x0 + x; pnts[1].y = y0 - y;
|
|
|
|
} else if (s == 90) {
|
|
|
|
pnts[1].x = x0 - x; pnts[1].y = y0 - y;
|
|
|
|
}
|
|
|
|
nk_rawfb_fill_polygon(rawfb, pnts, 3, col);
|
|
|
|
pnts[2] = pnts[1];
|
|
|
|
if (sigma >= 0) {
|
|
|
|
sigma += fb2 * (1 - x);
|
|
|
|
x--;
|
2017-10-07 15:30:22 +03:00
|
|
|
} sigma += a2 * ((4 * y) + 6);
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nk_rawfb_stroke_rect(const struct rawfb_context *rawfb,
|
2017-10-07 15:30:22 +03:00
|
|
|
const short x, const short y, const short w, const short h,
|
|
|
|
const short r, const short line_thickness, const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
if (r == 0) {
|
|
|
|
nk_rawfb_stroke_line(rawfb, x, y, x + w, y, line_thickness, col);
|
|
|
|
nk_rawfb_stroke_line(rawfb, x, y + h, x + w, y + h, line_thickness, col);
|
|
|
|
nk_rawfb_stroke_line(rawfb, x, y, x, y + h, line_thickness, col);
|
|
|
|
nk_rawfb_stroke_line(rawfb, x + w, y, x + w, y + h, line_thickness, col);
|
|
|
|
} else {
|
|
|
|
const short xc = x + r;
|
|
|
|
const short yc = y + r;
|
|
|
|
const short wc = (short)(w - 2 * r);
|
|
|
|
const short hc = (short)(h - 2 * r);
|
|
|
|
|
|
|
|
nk_rawfb_stroke_line(rawfb, xc, y, xc + wc, y, line_thickness, col);
|
|
|
|
nk_rawfb_stroke_line(rawfb, x + w, yc, x + w, yc + hc, line_thickness, col);
|
|
|
|
nk_rawfb_stroke_line(rawfb, xc, y + h, xc + wc, y + h, line_thickness, col);
|
|
|
|
nk_rawfb_stroke_line(rawfb, x, yc, x, yc + hc, line_thickness, col);
|
|
|
|
|
|
|
|
nk_rawfb_stroke_arc(rawfb, xc + wc - r, y,
|
|
|
|
(unsigned)r*2, (unsigned)r*2, 0 , line_thickness, col);
|
|
|
|
nk_rawfb_stroke_arc(rawfb, x, y,
|
|
|
|
(unsigned)r*2, (unsigned)r*2, 90 , line_thickness, col);
|
|
|
|
nk_rawfb_stroke_arc(rawfb, x, yc + hc - r,
|
|
|
|
(unsigned)r*2, (unsigned)r*2, 270 , line_thickness, col);
|
|
|
|
nk_rawfb_stroke_arc(rawfb, xc + wc - r, yc + hc - r,
|
|
|
|
(unsigned)r*2, (unsigned)r*2, 180 , line_thickness, col);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nk_rawfb_fill_rect(const struct rawfb_context *rawfb,
|
2017-10-07 15:30:22 +03:00
|
|
|
const short x, const short y, const short w, const short h,
|
|
|
|
const short r, const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
2017-10-07 15:30:22 +03:00
|
|
|
int i;
|
2016-12-06 09:28:54 +03:00
|
|
|
if (r == 0) {
|
2017-10-07 15:30:22 +03:00
|
|
|
for (i = 0; i < h; i++)
|
2016-12-06 09:28:54 +03:00
|
|
|
nk_rawfb_stroke_line(rawfb, x, y + i, x + w, y + i, 1, col);
|
|
|
|
} else {
|
|
|
|
const short xc = x + r;
|
|
|
|
const short yc = y + r;
|
|
|
|
const short wc = (short)(w - 2 * r);
|
|
|
|
const short hc = (short)(h - 2 * r);
|
|
|
|
|
|
|
|
struct nk_vec2i pnts[12];
|
|
|
|
pnts[0].x = x;
|
|
|
|
pnts[0].y = yc;
|
|
|
|
pnts[1].x = xc;
|
|
|
|
pnts[1].y = yc;
|
|
|
|
pnts[2].x = xc;
|
|
|
|
pnts[2].y = y;
|
|
|
|
|
|
|
|
pnts[3].x = xc + wc;
|
|
|
|
pnts[3].y = y;
|
|
|
|
pnts[4].x = xc + wc;
|
|
|
|
pnts[4].y = yc;
|
|
|
|
pnts[5].x = x + w;
|
|
|
|
pnts[5].y = yc;
|
|
|
|
|
|
|
|
pnts[6].x = x + w;
|
|
|
|
pnts[6].y = yc + hc;
|
|
|
|
pnts[7].x = xc + wc;
|
|
|
|
pnts[7].y = yc + hc;
|
|
|
|
pnts[8].x = xc + wc;
|
|
|
|
pnts[8].y = y + h;
|
|
|
|
|
|
|
|
pnts[9].x = xc;
|
|
|
|
pnts[9].y = y + h;
|
|
|
|
pnts[10].x = xc;
|
|
|
|
pnts[10].y = yc + hc;
|
|
|
|
pnts[11].x = x;
|
|
|
|
pnts[11].y = yc + hc;
|
|
|
|
|
|
|
|
nk_rawfb_fill_polygon(rawfb, pnts, 12, col);
|
|
|
|
|
|
|
|
nk_rawfb_fill_arc(rawfb, xc + wc - r, y,
|
|
|
|
(unsigned)r*2, (unsigned)r*2, 0 , col);
|
|
|
|
nk_rawfb_fill_arc(rawfb, x, y,
|
|
|
|
(unsigned)r*2, (unsigned)r*2, 90 , col);
|
|
|
|
nk_rawfb_fill_arc(rawfb, x, yc + hc - r,
|
|
|
|
(unsigned)r*2, (unsigned)r*2, 270 , col);
|
|
|
|
nk_rawfb_fill_arc(rawfb, xc + wc - r, yc + hc - r,
|
|
|
|
(unsigned)r*2, (unsigned)r*2, 180 , col);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-06 19:58:03 +03:00
|
|
|
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)
|
2024-04-06 08:27:07 +03:00
|
|
|
return;
|
2019-06-06 19:58:03 +03:00
|
|
|
|
|
|
|
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; i<w; i++)
|
|
|
|
{
|
2024-04-06 08:27:07 +03:00
|
|
|
edge_t[i].r = (((((float)tr.r - tl.r)/(w-1))*i) + 0.5) + tl.r;
|
|
|
|
edge_t[i].g = (((((float)tr.g - tl.g)/(w-1))*i) + 0.5) + tl.g;
|
|
|
|
edge_t[i].b = (((((float)tr.b - tl.b)/(w-1))*i) + 0.5) + tl.b;
|
|
|
|
edge_t[i].a = (((((float)tr.a - tl.a)/(w-1))*i) + 0.5) + tl.a;
|
|
|
|
|
|
|
|
edge_b[i].r = (((((float)br.r - bl.r)/(w-1))*i) + 0.5) + bl.r;
|
|
|
|
edge_b[i].g = (((((float)br.g - bl.g)/(w-1))*i) + 0.5) + bl.g;
|
|
|
|
edge_b[i].b = (((((float)br.b - bl.b)/(w-1))*i) + 0.5) + bl.b;
|
|
|
|
edge_b[i].a = (((((float)br.a - bl.a)/(w-1))*i) + 0.5) + bl.a;
|
2019-06-06 19:58:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Left and right edge gradients */
|
|
|
|
for (i=0; i<h; i++)
|
|
|
|
{
|
2024-04-06 08:27:07 +03:00
|
|
|
edge_l[i].r = (((((float)bl.r - tl.r)/(h-1))*i) + 0.5) + tl.r;
|
|
|
|
edge_l[i].g = (((((float)bl.g - tl.g)/(h-1))*i) + 0.5) + tl.g;
|
|
|
|
edge_l[i].b = (((((float)bl.b - tl.b)/(h-1))*i) + 0.5) + tl.b;
|
|
|
|
edge_l[i].a = (((((float)bl.a - tl.a)/(h-1))*i) + 0.5) + tl.a;
|
|
|
|
|
|
|
|
edge_r[i].r = (((((float)br.r - tr.r)/(h-1))*i) + 0.5) + tr.r;
|
|
|
|
edge_r[i].g = (((((float)br.g - tr.g)/(h-1))*i) + 0.5) + tr.g;
|
|
|
|
edge_r[i].b = (((((float)br.b - tr.b)/(h-1))*i) + 0.5) + tr.b;
|
|
|
|
edge_r[i].a = (((((float)br.a - tr.a)/(h-1))*i) + 0.5) + tr.a;
|
2019-06-06 19:58:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
for (i=0; i<h; i++) {
|
2024-04-06 08:27:07 +03:00
|
|
|
for (j=0; j<w; j++) {
|
|
|
|
if (i==0) {
|
|
|
|
nk_rawfb_img_blendpixel(&rawfb->fb, 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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-06-06 19:58:03 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
free(edge_buf);
|
|
|
|
}
|
|
|
|
|
2016-12-06 09:28:54 +03:00
|
|
|
static void
|
|
|
|
nk_rawfb_fill_triangle(const struct rawfb_context *rawfb,
|
2017-10-07 15:30:22 +03:00
|
|
|
const short x0, const short y0, const short x1, const short y1,
|
|
|
|
const short x2, const short y2, const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
struct nk_vec2i pnts[3];
|
|
|
|
pnts[0].x = x0;
|
|
|
|
pnts[0].y = y0;
|
|
|
|
pnts[1].x = x1;
|
|
|
|
pnts[1].y = y1;
|
|
|
|
pnts[2].x = x2;
|
|
|
|
pnts[2].y = y2;
|
|
|
|
nk_rawfb_fill_polygon(rawfb, pnts, 3, col);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nk_rawfb_stroke_triangle(const struct rawfb_context *rawfb,
|
2017-10-07 15:30:22 +03:00
|
|
|
const short x0, const short y0, const short x1, const short y1,
|
|
|
|
const short x2, const short y2, const unsigned short line_thickness,
|
|
|
|
const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
nk_rawfb_stroke_line(rawfb, x0, y0, x1, y1, line_thickness, col);
|
|
|
|
nk_rawfb_stroke_line(rawfb, x1, y1, x2, y2, line_thickness, col);
|
|
|
|
nk_rawfb_stroke_line(rawfb, x2, y2, x0, y0, line_thickness, col);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nk_rawfb_stroke_polygon(const struct rawfb_context *rawfb,
|
2017-10-07 15:30:22 +03:00
|
|
|
const struct nk_vec2i *pnts, const int count,
|
|
|
|
const unsigned short line_thickness, const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 1; i < count; ++i)
|
|
|
|
nk_rawfb_stroke_line(rawfb, pnts[i-1].x, pnts[i-1].y, pnts[i].x,
|
|
|
|
pnts[i].y, line_thickness, col);
|
|
|
|
nk_rawfb_stroke_line(rawfb, pnts[count-1].x, pnts[count-1].y,
|
|
|
|
pnts[0].x, pnts[0].y, line_thickness, col);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nk_rawfb_stroke_polyline(const struct rawfb_context *rawfb,
|
2017-10-07 15:30:22 +03:00
|
|
|
const struct nk_vec2i *pnts, const int count,
|
|
|
|
const unsigned short line_thickness, const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
for (i = 0; i < count-1; ++i)
|
|
|
|
nk_rawfb_stroke_line(rawfb, pnts[i].x, pnts[i].y,
|
|
|
|
pnts[i+1].x, pnts[i+1].y, line_thickness, col);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nk_rawfb_fill_circle(const struct rawfb_context *rawfb,
|
2017-10-07 15:30:22 +03:00
|
|
|
short x0, short y0, short w, short h, const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
/* Bresenham's ellipses */
|
|
|
|
const int a2 = (w * w) / 4;
|
|
|
|
const int b2 = (h * h) / 4;
|
|
|
|
const int fa2 = 4 * a2, fb2 = 4 * b2;
|
|
|
|
int x, y, sigma;
|
|
|
|
|
|
|
|
/* Convert upper left to center */
|
|
|
|
h = (h + 1) / 2;
|
|
|
|
w = (w + 1) / 2;
|
|
|
|
x0 += w;
|
|
|
|
y0 += h;
|
|
|
|
|
|
|
|
/* First half */
|
|
|
|
for (x = 0, y = h, sigma = 2*b2+a2*(1-2*h); b2*x <= a2*y; x++) {
|
|
|
|
nk_rawfb_stroke_line(rawfb, x0 - x, y0 + y, x0 + x, y0 + y, 1, col);
|
|
|
|
nk_rawfb_stroke_line(rawfb, x0 - x, y0 - y, x0 + x, y0 - y, 1, col);
|
|
|
|
if (sigma >= 0) {
|
|
|
|
sigma += fa2 * (1 - y);
|
|
|
|
y--;
|
2017-10-07 15:30:22 +03:00
|
|
|
} sigma += b2 * ((4 * x) + 6);
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
/* Second half */
|
|
|
|
for (x = w, y = 0, sigma = 2*a2+b2*(1-2*w); a2*y <= b2*x; y++) {
|
|
|
|
nk_rawfb_stroke_line(rawfb, x0 - x, y0 + y, x0 + x, y0 + y, 1, col);
|
|
|
|
nk_rawfb_stroke_line(rawfb, x0 - x, y0 - y, x0 + x, y0 - y, 1, col);
|
|
|
|
if (sigma >= 0) {
|
|
|
|
sigma += fb2 * (1 - x);
|
|
|
|
x--;
|
2017-10-07 15:30:22 +03:00
|
|
|
} sigma += a2 * ((4 * y) + 6);
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nk_rawfb_stroke_circle(const struct rawfb_context *rawfb,
|
2017-10-07 15:30:22 +03:00
|
|
|
short x0, short y0, short w, short h, const short line_thickness,
|
|
|
|
const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
/* Bresenham's ellipses */
|
|
|
|
const int a2 = (w * w) / 4;
|
|
|
|
const int b2 = (h * h) / 4;
|
|
|
|
const int fa2 = 4 * a2, fb2 = 4 * b2;
|
|
|
|
int x, y, sigma;
|
|
|
|
|
2021-12-16 22:44:00 +03:00
|
|
|
NK_UNUSED(line_thickness);
|
|
|
|
|
2016-12-06 09:28:54 +03:00
|
|
|
/* Convert upper left to center */
|
|
|
|
h = (h + 1) / 2;
|
|
|
|
w = (w + 1) / 2;
|
|
|
|
x0 += w;
|
|
|
|
y0 += h;
|
|
|
|
|
|
|
|
/* First half */
|
|
|
|
for (x = 0, y = h, sigma = 2*b2+a2*(1-2*h); b2*x <= a2*y; x++) {
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0 + x, y0 + y, col);
|
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0 - x, y0 + y, col);
|
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0 + x, y0 - y, col);
|
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0 - x, y0 - y, col);
|
2016-12-06 09:28:54 +03:00
|
|
|
if (sigma >= 0) {
|
|
|
|
sigma += fa2 * (1 - y);
|
|
|
|
y--;
|
2017-10-07 15:30:22 +03:00
|
|
|
} sigma += b2 * ((4 * x) + 6);
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
/* Second half */
|
|
|
|
for (x = w, y = 0, sigma = 2*a2+b2*(1-2*w); a2*y <= b2*x; y++) {
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0 + x, y0 + y, col);
|
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0 - x, y0 + y, col);
|
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0 + x, y0 - y, col);
|
|
|
|
nk_rawfb_ctx_setpixel(rawfb, x0 - x, y0 - y, col);
|
2016-12-06 09:28:54 +03:00
|
|
|
if (sigma >= 0) {
|
|
|
|
sigma += fb2 * (1 - x);
|
|
|
|
x--;
|
2017-10-07 15:30:22 +03:00
|
|
|
} sigma += a2 * ((4 * y) + 6);
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nk_rawfb_stroke_curve(const struct rawfb_context *rawfb,
|
2017-10-07 15:30:22 +03:00
|
|
|
const struct nk_vec2i p1, const struct nk_vec2i p2,
|
|
|
|
const struct nk_vec2i p3, const struct nk_vec2i p4,
|
|
|
|
const unsigned int num_segments, const unsigned short line_thickness,
|
|
|
|
const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
unsigned int i_step, segments;
|
|
|
|
float t_step;
|
|
|
|
struct nk_vec2i last = p1;
|
|
|
|
|
|
|
|
segments = MAX(num_segments, 1);
|
|
|
|
t_step = 1.0f/(float)segments;
|
|
|
|
for (i_step = 1; i_step <= segments; ++i_step) {
|
|
|
|
float t = t_step * (float)i_step;
|
|
|
|
float u = 1.0f - t;
|
|
|
|
float w1 = u*u*u;
|
|
|
|
float w2 = 3*u*u*t;
|
|
|
|
float w3 = 3*u*t*t;
|
|
|
|
float w4 = t * t *t;
|
|
|
|
float x = w1 * p1.x + w2 * p2.x + w3 * p3.x + w4 * p4.x;
|
|
|
|
float y = w1 * p1.y + w2 * p2.y + w3 * p3.y + w4 * p4.y;
|
|
|
|
nk_rawfb_stroke_line(rawfb, last.x, last.y,
|
|
|
|
(short)x, (short)y, line_thickness,col);
|
|
|
|
last.x = (short)x; last.y = (short)y;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-07 15:30:22 +03:00
|
|
|
nk_rawfb_clear(const struct rawfb_context *rawfb, const struct nk_color col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
nk_rawfb_fill_rect(rawfb, 0, 0, rawfb->fb.w, rawfb->fb.h, 0, col);
|
|
|
|
}
|
|
|
|
|
|
|
|
NK_API struct rawfb_context*
|
2017-10-07 15:30:22 +03:00
|
|
|
nk_rawfb_init(void *fb, void *tex_mem, const unsigned int w, const unsigned int h,
|
2024-05-03 13:46:23 +03:00
|
|
|
const unsigned int pitch, const struct rawfb_pl pl)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
const void *tex;
|
|
|
|
struct rawfb_context *rawfb;
|
2024-05-03 13:46:23 +03:00
|
|
|
|
2016-12-06 09:28:54 +03:00
|
|
|
rawfb = malloc(sizeof(struct rawfb_context));
|
|
|
|
if (!rawfb)
|
|
|
|
return NULL;
|
|
|
|
|
2021-05-16 23:54:56 +03:00
|
|
|
memset(rawfb, 0, sizeof(struct rawfb_context));
|
2016-12-06 09:28:54 +03:00
|
|
|
rawfb->font_tex.pixels = tex_mem;
|
2024-05-03 13:46:23 +03:00
|
|
|
rawfb->font_tex.pl.bytesPerPixel = 1;
|
|
|
|
rawfb->font_tex.pl.rshift = 0;
|
|
|
|
rawfb->font_tex.pl.gshift = 0;
|
|
|
|
rawfb->font_tex.pl.bshift = 0;
|
|
|
|
rawfb->font_tex.pl.ashift = 0;
|
|
|
|
rawfb->font_tex.pl.rloss = 8;
|
|
|
|
rawfb->font_tex.pl.gloss = 8;
|
|
|
|
rawfb->font_tex.pl.bloss = 8;
|
|
|
|
rawfb->font_tex.pl.aloss = 0;
|
|
|
|
rawfb->font_tex.w = rawfb->font_tex.h = rawfb->font_tex.pitch = 0;
|
2016-12-06 09:28:54 +03:00
|
|
|
|
|
|
|
rawfb->fb.pixels = fb;
|
2024-04-06 08:27:07 +03:00
|
|
|
rawfb->fb.w = w;
|
2016-12-06 09:28:54 +03:00
|
|
|
rawfb->fb.h = h;
|
2024-05-03 13:46:23 +03:00
|
|
|
rawfb->fb.pitch = pitch;
|
2019-06-06 21:41:52 +03:00
|
|
|
rawfb->fb.pl = pl;
|
2016-12-06 09:28:54 +03:00
|
|
|
|
2019-06-06 21:41:52 +03:00
|
|
|
if (0 == nk_init_default(&rawfb->ctx, 0)) {
|
2024-04-06 08:27:07 +03:00
|
|
|
free(rawfb);
|
|
|
|
return NULL;
|
2019-06-06 21:41:52 +03:00
|
|
|
}
|
2016-12-06 09:28:54 +03:00
|
|
|
|
|
|
|
nk_font_atlas_init_default(&rawfb->atlas);
|
|
|
|
nk_font_atlas_begin(&rawfb->atlas);
|
2024-05-03 13:46:23 +03:00
|
|
|
tex = nk_font_atlas_bake(&rawfb->atlas, &rawfb->font_tex.w, &rawfb->font_tex.h, NK_FONT_ATLAS_ALPHA8);
|
2019-06-06 21:41:52 +03:00
|
|
|
if (!tex) {
|
2024-04-06 08:27:07 +03:00
|
|
|
free(rawfb);
|
|
|
|
return NULL;
|
2019-06-06 21:41:52 +03:00
|
|
|
}
|
2016-12-06 09:28:54 +03:00
|
|
|
|
2024-05-03 13:46:23 +03:00
|
|
|
rawfb->font_tex.pitch = rawfb->font_tex.w * 1;
|
2016-12-06 09:28:54 +03:00
|
|
|
memcpy(rawfb->font_tex.pixels, tex, rawfb->font_tex.pitch * rawfb->font_tex.h);
|
|
|
|
nk_font_atlas_end(&rawfb->atlas, nk_handle_ptr(NULL), NULL);
|
|
|
|
if (rawfb->atlas.default_font)
|
|
|
|
nk_style_set_font(&rawfb->ctx, &rawfb->atlas.default_font->handle);
|
|
|
|
nk_style_load_all_cursors(&rawfb->ctx, rawfb->atlas.cursors);
|
|
|
|
nk_rawfb_scissor(rawfb, 0, 0, rawfb->fb.w, rawfb->fb.h);
|
2024-04-06 08:27:07 +03:00
|
|
|
|
2016-12-06 09:28:54 +03:00
|
|
|
return rawfb;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
nk_rawfb_stretch_image(const struct rawfb_image *dst,
|
2017-10-07 15:30:22 +03:00
|
|
|
const struct rawfb_image *src, const struct nk_rect *dst_rect,
|
2019-06-06 19:42:32 +03:00
|
|
|
const struct nk_rect *src_rect, const struct nk_rect *dst_scissors,
|
|
|
|
const struct nk_color *fg)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
short i, j;
|
2017-10-07 15:30:22 +03:00
|
|
|
struct nk_color col;
|
2016-12-06 09:28:54 +03:00
|
|
|
float xinc = src_rect->w / dst_rect->w;
|
|
|
|
float yinc = src_rect->h / dst_rect->h;
|
|
|
|
float xoff = src_rect->x, yoff = src_rect->y;
|
|
|
|
|
|
|
|
/* Simple nearest filtering rescaling */
|
|
|
|
/* TODO: use bilinear filter */
|
|
|
|
for (j = 0; j < (short)dst_rect->h; j++) {
|
|
|
|
for (i = 0; i < (short)dst_rect->w; i++) {
|
|
|
|
if (dst_scissors) {
|
|
|
|
if (i + (int)(dst_rect->x + 0.5f) < dst_scissors->x || i + (int)(dst_rect->x + 0.5f) >= dst_scissors->w)
|
|
|
|
continue;
|
|
|
|
if (j + (int)(dst_rect->y + 0.5f) < dst_scissors->y || j + (int)(dst_rect->y + 0.5f) >= dst_scissors->h)
|
|
|
|
continue;
|
|
|
|
}
|
2019-06-06 19:42:32 +03:00
|
|
|
col = nk_rawfb_img_getpixel(src, (int)xoff, (int) yoff);
|
2024-04-06 08:27:07 +03:00
|
|
|
if (col.r || col.g || col.b)
|
|
|
|
{
|
|
|
|
col.r = fg->r;
|
|
|
|
col.g = fg->g;
|
|
|
|
col.b = fg->b;
|
|
|
|
}
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_img_blendpixel(dst, i + (int)(dst_rect->x + 0.5f), j + (int)(dst_rect->y + 0.5f), col);
|
2016-12-06 09:28:54 +03:00
|
|
|
xoff += xinc;
|
|
|
|
}
|
|
|
|
xoff = src_rect->x;
|
|
|
|
yoff += yinc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
2017-10-07 15:30:22 +03:00
|
|
|
nk_rawfb_font_query_font_glyph(nk_handle handle, const float height,
|
|
|
|
struct nk_user_font_glyph *glyph, const nk_rune codepoint,
|
|
|
|
const nk_rune next_codepoint)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
float scale;
|
|
|
|
const struct nk_font_glyph *g;
|
|
|
|
struct nk_font *font;
|
|
|
|
NK_ASSERT(glyph);
|
|
|
|
NK_UNUSED(next_codepoint);
|
|
|
|
|
|
|
|
font = (struct nk_font*)handle.ptr;
|
|
|
|
NK_ASSERT(font);
|
|
|
|
NK_ASSERT(font->glyphs);
|
|
|
|
if (!font || !glyph)
|
|
|
|
return;
|
|
|
|
|
|
|
|
scale = height/font->info.height;
|
|
|
|
g = nk_font_find_glyph(font, codepoint);
|
|
|
|
glyph->width = (g->x1 - g->x0) * scale;
|
|
|
|
glyph->height = (g->y1 - g->y0) * scale;
|
|
|
|
glyph->offset = nk_vec2(g->x0 * scale, g->y0 * scale);
|
|
|
|
glyph->xadvance = (g->xadvance * scale);
|
|
|
|
glyph->uv[0] = nk_vec2(g->u0, g->v0);
|
|
|
|
glyph->uv[1] = nk_vec2(g->u1, g->v1);
|
|
|
|
}
|
|
|
|
|
|
|
|
NK_API void
|
|
|
|
nk_rawfb_draw_text(const struct rawfb_context *rawfb,
|
2017-10-07 15:30:22 +03:00
|
|
|
const struct nk_user_font *font, const struct nk_rect rect,
|
|
|
|
const char *text, const int len, const float font_height,
|
|
|
|
const struct nk_color fg)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
float x = 0;
|
|
|
|
int text_len = 0;
|
|
|
|
nk_rune unicode = 0;
|
|
|
|
nk_rune next = 0;
|
|
|
|
int glyph_len = 0;
|
|
|
|
int next_glyph_len = 0;
|
|
|
|
struct nk_user_font_glyph g;
|
|
|
|
if (!len || !text) return;
|
|
|
|
|
|
|
|
x = 0;
|
|
|
|
glyph_len = nk_utf_decode(text, &unicode, len);
|
|
|
|
if (!glyph_len) return;
|
|
|
|
|
|
|
|
/* draw every glyph image */
|
|
|
|
while (text_len < len && glyph_len) {
|
|
|
|
struct nk_rect src_rect;
|
|
|
|
struct nk_rect dst_rect;
|
|
|
|
float char_width = 0;
|
|
|
|
if (unicode == NK_UTF_INVALID) break;
|
|
|
|
|
|
|
|
/* query currently drawn glyph information */
|
|
|
|
next_glyph_len = nk_utf_decode(text + text_len + glyph_len, &next, (int)len - text_len);
|
|
|
|
nk_rawfb_font_query_font_glyph(font->userdata, font_height, &g, unicode,
|
|
|
|
(next == NK_UTF_INVALID) ? '\0' : next);
|
|
|
|
|
|
|
|
/* calculate and draw glyph drawing rectangle and image */
|
|
|
|
char_width = g.xadvance;
|
|
|
|
src_rect.x = g.uv[0].x * rawfb->font_tex.w;
|
|
|
|
src_rect.y = g.uv[0].y * rawfb->font_tex.h;
|
|
|
|
src_rect.w = g.uv[1].x * rawfb->font_tex.w - g.uv[0].x * rawfb->font_tex.w;
|
|
|
|
src_rect.h = g.uv[1].y * rawfb->font_tex.h - g.uv[0].y * rawfb->font_tex.h;
|
|
|
|
|
|
|
|
dst_rect.x = x + g.offset.x + rect.x;
|
|
|
|
dst_rect.y = g.offset.y + rect.y;
|
2024-04-06 08:27:07 +03:00
|
|
|
dst_rect.w = ceil(g.width);
|
|
|
|
dst_rect.h = ceil(g.height);
|
2016-12-06 09:28:54 +03:00
|
|
|
|
|
|
|
/* Use software rescaling to blit glyph from font_text to framebuffer */
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_stretch_image(&rawfb->fb, &rawfb->font_tex, &dst_rect, &src_rect, &rawfb->scissors, &fg);
|
2016-12-06 09:28:54 +03:00
|
|
|
|
|
|
|
/* offset next glyph */
|
|
|
|
text_len += glyph_len;
|
|
|
|
x += char_width;
|
|
|
|
glyph_len = next_glyph_len;
|
|
|
|
unicode = next;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
NK_API void
|
|
|
|
nk_rawfb_drawimage(const struct rawfb_context *rawfb,
|
2017-10-07 15:30:22 +03:00
|
|
|
const int x, const int y, const int w, const int h,
|
|
|
|
const struct nk_image *img, const struct nk_color *col)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
struct nk_rect src_rect;
|
|
|
|
struct nk_rect dst_rect;
|
|
|
|
|
|
|
|
src_rect.x = img->region[0];
|
|
|
|
src_rect.y = img->region[1];
|
|
|
|
src_rect.w = img->region[2];
|
|
|
|
src_rect.h = img->region[3];
|
|
|
|
|
|
|
|
dst_rect.x = x;
|
|
|
|
dst_rect.y = y;
|
|
|
|
dst_rect.w = w;
|
|
|
|
dst_rect.h = h;
|
2019-06-06 19:42:32 +03:00
|
|
|
nk_rawfb_stretch_image(&rawfb->fb, &rawfb->font_tex, &dst_rect, &src_rect, &rawfb->scissors, col);
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NK_API void
|
|
|
|
nk_rawfb_shutdown(struct rawfb_context *rawfb)
|
|
|
|
{
|
2019-06-06 21:41:52 +03:00
|
|
|
if (rawfb) {
|
2024-04-06 08:27:07 +03:00
|
|
|
nk_free(&rawfb->ctx);
|
|
|
|
memset(rawfb, 0, sizeof(struct rawfb_context));
|
|
|
|
free(rawfb);
|
2019-06-06 21:41:52 +03:00
|
|
|
}
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NK_API void
|
|
|
|
nk_rawfb_resize_fb(struct rawfb_context *rawfb,
|
|
|
|
void *fb,
|
|
|
|
const unsigned int w,
|
|
|
|
const unsigned int h,
|
2019-06-06 21:41:52 +03:00
|
|
|
const unsigned int pitch,
|
2024-05-03 13:46:23 +03:00
|
|
|
const struct rawfb_pl pl)
|
2016-12-06 09:28:54 +03:00
|
|
|
{
|
|
|
|
rawfb->fb.w = w;
|
|
|
|
rawfb->fb.h = h;
|
|
|
|
rawfb->fb.pixels = fb;
|
|
|
|
rawfb->fb.pitch = pitch;
|
2019-06-06 21:41:52 +03:00
|
|
|
rawfb->fb.pl = pl;
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
NK_API void
|
|
|
|
nk_rawfb_render(const struct rawfb_context *rawfb,
|
|
|
|
const struct nk_color clear,
|
|
|
|
const unsigned char enable_clear)
|
|
|
|
{
|
|
|
|
const struct nk_command *cmd;
|
2024-08-30 05:22:55 +03:00
|
|
|
|
2016-12-06 09:28:54 +03:00
|
|
|
if (enable_clear)
|
|
|
|
nk_rawfb_clear(rawfb, clear);
|
|
|
|
|
|
|
|
nk_foreach(cmd, (struct nk_context*)&rawfb->ctx) {
|
|
|
|
switch (cmd->type) {
|
|
|
|
case NK_COMMAND_NOP: break;
|
|
|
|
case NK_COMMAND_SCISSOR: {
|
|
|
|
const struct nk_command_scissor *s =(const struct nk_command_scissor*)cmd;
|
|
|
|
nk_rawfb_scissor((struct rawfb_context *)rawfb, s->x, s->y, s->w, s->h);
|
|
|
|
} break;
|
|
|
|
case NK_COMMAND_LINE: {
|
|
|
|
const struct nk_command_line *l = (const struct nk_command_line *)cmd;
|
|
|
|
nk_rawfb_stroke_line(rawfb, l->begin.x, l->begin.y, l->end.x,
|
|
|
|
l->end.y, l->line_thickness, l->color);
|
|
|
|
} break;
|
|
|
|
case NK_COMMAND_RECT: {
|
|
|
|
const struct nk_command_rect *r = (const struct nk_command_rect *)cmd;
|
|
|
|
nk_rawfb_stroke_rect(rawfb, r->x, r->y, r->w, r->h,
|
|
|
|
(unsigned short)r->rounding, r->line_thickness, r->color);
|
|
|
|
} break;
|
|
|
|
case NK_COMMAND_RECT_FILLED: {
|
|
|
|
const struct nk_command_rect_filled *r = (const struct nk_command_rect_filled *)cmd;
|
|
|
|
nk_rawfb_fill_rect(rawfb, r->x, r->y, r->w, r->h,
|
|
|
|
(unsigned short)r->rounding, r->color);
|
|
|
|
} break;
|
|
|
|
case NK_COMMAND_CIRCLE: {
|
|
|
|
const struct nk_command_circle *c = (const struct nk_command_circle *)cmd;
|
|
|
|
nk_rawfb_stroke_circle(rawfb, c->x, c->y, c->w, c->h, c->line_thickness, c->color);
|
|
|
|
} break;
|
|
|
|
case NK_COMMAND_CIRCLE_FILLED: {
|
|
|
|
const struct nk_command_circle_filled *c = (const struct nk_command_circle_filled *)cmd;
|
|
|
|
nk_rawfb_fill_circle(rawfb, c->x, c->y, c->w, c->h, c->color);
|
|
|
|
} break;
|
|
|
|
case NK_COMMAND_TRIANGLE: {
|
|
|
|
const struct nk_command_triangle*t = (const struct nk_command_triangle*)cmd;
|
|
|
|
nk_rawfb_stroke_triangle(rawfb, t->a.x, t->a.y, t->b.x, t->b.y,
|
|
|
|
t->c.x, t->c.y, t->line_thickness, t->color);
|
|
|
|
} break;
|
|
|
|
case NK_COMMAND_TRIANGLE_FILLED: {
|
|
|
|
const struct nk_command_triangle_filled *t = (const struct nk_command_triangle_filled *)cmd;
|
|
|
|
nk_rawfb_fill_triangle(rawfb, t->a.x, t->a.y, t->b.x, t->b.y,
|
|
|
|
t->c.x, t->c.y, t->color);
|
|
|
|
} break;
|
|
|
|
case NK_COMMAND_POLYGON: {
|
|
|
|
const struct nk_command_polygon *p =(const struct nk_command_polygon*)cmd;
|
|
|
|
nk_rawfb_stroke_polygon(rawfb, p->points, p->point_count, p->line_thickness,p->color);
|
|
|
|
} break;
|
|
|
|
case NK_COMMAND_POLYGON_FILLED: {
|
|
|
|
const struct nk_command_polygon_filled *p = (const struct nk_command_polygon_filled *)cmd;
|
|
|
|
nk_rawfb_fill_polygon(rawfb, p->points, p->point_count, p->color);
|
|
|
|
} break;
|
|
|
|
case NK_COMMAND_POLYLINE: {
|
|
|
|
const struct nk_command_polyline *p = (const struct nk_command_polyline *)cmd;
|
|
|
|
nk_rawfb_stroke_polyline(rawfb, p->points, p->point_count, p->line_thickness, p->color);
|
|
|
|
} break;
|
|
|
|
case NK_COMMAND_TEXT: {
|
|
|
|
const struct nk_command_text *t = (const struct nk_command_text*)cmd;
|
|
|
|
nk_rawfb_draw_text(rawfb, t->font, nk_rect(t->x, t->y, t->w, t->h),
|
|
|
|
t->string, t->length, t->height, t->foreground);
|
|
|
|
} break;
|
|
|
|
case NK_COMMAND_CURVE: {
|
|
|
|
const struct nk_command_curve *q = (const struct nk_command_curve *)cmd;
|
|
|
|
nk_rawfb_stroke_curve(rawfb, q->begin, q->ctrl[0], q->ctrl[1],
|
|
|
|
q->end, 22, q->line_thickness, q->color);
|
|
|
|
} break;
|
2019-06-06 19:58:03 +03:00
|
|
|
case NK_COMMAND_RECT_MULTI_COLOR: {
|
2024-04-06 08:27:07 +03:00
|
|
|
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;
|
2016-12-06 09:28:54 +03:00
|
|
|
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);
|
|
|
|
} break;
|
|
|
|
case NK_COMMAND_ARC: {
|
|
|
|
assert(0 && "NK_COMMAND_ARC not implemented\n");
|
|
|
|
} break;
|
|
|
|
case NK_COMMAND_ARC_FILLED: {
|
|
|
|
assert(0 && "NK_COMMAND_ARC_FILLED not implemented\n");
|
|
|
|
} break;
|
|
|
|
default: break;
|
|
|
|
}
|
2017-10-07 15:30:22 +03:00
|
|
|
} nk_clear((struct nk_context*)&rawfb->ctx);
|
2016-12-06 09:28:54 +03:00
|
|
|
}
|
|
|
|
#endif
|
2017-10-07 15:30:22 +03:00
|
|
|
|