Mercurial > repos > blastem
annotate nuklear_ui/nuklear_rawfb.h @ 2429:da3dc881d3f0
Initial implementation of storbook artwork display
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Sun, 04 Feb 2024 20:11:39 -0800 |
parents | 56a1171e29b9 |
children |
rev | line source |
---|---|
1825
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1 /* |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
2 * MIT License |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
3 * |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 * Copyright (c) 2016-2017 Patrick Rudolph <siro@das-labor.org> |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
5 * |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
6 * Permission is hereby granted, free of charge, to any person obtaining a copy |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
7 * of this software and associated documentation files (the "Software"), to deal |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 * in the Software without restriction, including without limitation the rights |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
10 * copies of the Software, and to permit persons to whom the Software is |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
11 * furnished to do so, subject to the following conditions: |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
12 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
13 * The above copyright notice and this permission notice shall be included in all |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
14 * copies or substantial portions of the Software. |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 * SOFTWARE. |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 /* |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 * ============================================================== |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 * |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 * API |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 * |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
29 * =============================================================== |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
30 */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
31 #ifndef NK_RAWFB_H_ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
32 #define NK_RAWFB_H_ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
33 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
34 struct rawfb_context; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
35 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
36 /* All functions are thread-safe */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
37 NK_API struct rawfb_context *nk_rawfb_init(void *fb, struct nk_context *context, const unsigned int w, const unsigned int h, const unsigned int pitch); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
38 NK_API void nk_rawfb_render(const struct rawfb_context *rawfb, const struct nk_color clear, const unsigned char enable_clear); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
39 NK_API void nk_rawfb_shutdown(struct rawfb_context *rawfb); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
40 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); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
41 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
42 #endif |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
43 /* |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
44 * ============================================================== |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
45 * |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
46 * IMPLEMENTATION |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
47 * |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
48 * =============================================================== |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
49 */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
50 #ifdef NK_RAWFB_IMPLEMENTATION |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
51 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
52 struct rawfb_image { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
53 void *pixels; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
54 int w, h, pitch; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
55 enum nk_font_atlas_format format; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
56 }; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
57 struct rawfb_context { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
58 struct nk_context *ctx; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
59 struct nk_rect scissors; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
60 struct rawfb_image fb; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
61 struct rawfb_image font_tex; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
62 struct nk_font_atlas atlas; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
63 }; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
64 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
65 #ifndef MIN |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
66 #define MIN(a,b) ((a) < (b) ? (a) : (b)) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
67 #endif |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
68 #ifndef MAX |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
69 #define MAX(a,b) ((a) < (b) ? (b) : (a)) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
70 #endif |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
71 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
72 static unsigned int |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
73 nk_color_from_byte(const nk_byte *c) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
74 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
75 unsigned int res = 0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
76 #if defined(RAWFB_RGBX_8888) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
77 res |= (unsigned int)c[0] << 16; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
78 res |= (unsigned int)c[1] << 8; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
79 res |= (unsigned int)c[2] << 0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
80 #elif defined(RAWFB_XRGB_8888) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
81 res = ((unsigned int *)c)[0]; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
82 #else |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
83 #error Define one of RAWFB_RGBX_8888 , RAWFB_XRGB_8888 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
84 #endif |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
85 return (res); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
86 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
87 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
88 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
89 nk_rawfb_setpixel(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
90 const short x0, const short y0, const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
91 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
92 unsigned int c = nk_color_from_byte(&col.r); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
93 unsigned char *pixels = rawfb->fb.pixels; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
94 unsigned int *ptr; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
95 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
96 pixels += y0 * rawfb->fb.pitch; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
97 ptr = (unsigned int *)pixels; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
98 ptr += x0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
99 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
100 if (y0 < rawfb->scissors.h && y0 >= rawfb->scissors.y && |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 x0 >= rawfb->scissors.x && x0 < rawfb->scissors.w) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 *ptr = c; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 nk_rawfb_line_horizontal(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 const short x0, const short y, const short x1, const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 /* This function is called the most. Try to optimize it a bit... |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 * It does not check for scissors or image borders. |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 * The caller has to make sure it does no exceed bounds. */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 unsigned int i, n; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 unsigned int c[16]; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 unsigned char *pixels = rawfb->fb.pixels; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 unsigned int *ptr; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 pixels += y * rawfb->fb.pitch; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 ptr = (unsigned int *)pixels; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 ptr += x0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 n = x1 - x0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 for (i = 0; i < sizeof(c) / sizeof(c[0]); i++) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 c[i] = nk_color_from_byte(&col.r); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 while (n > 16) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 memcpy((void *)ptr, c, sizeof(c)); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 n -= 16; ptr += 16; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 } for (i = 0; i < n; i++) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 ptr[i] = c[i]; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
131 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 nk_rawfb_imagesetpixel(const struct rawfb_image *img, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
134 const int x0, const int y0, const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 unsigned char *ptr; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
137 NK_ASSERT(img); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 if (y0 < img->h && y0 > 0 && x0 > 0 && x0 < img->w) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 ptr = img->pixels; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 if (img->format == NK_FONT_ATLAS_ALPHA8) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 ptr += img->pitch * y0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 ptr[x0] = col.a; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 } else { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 ptr += img->pitch * y0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 ((struct nk_color *)ptr)[x0] = col; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
148 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
149 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
150 static struct nk_color |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
151 nk_image_getpixel(const struct rawfb_image *img, const int x0, const int y0) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
152 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
153 struct nk_color col = {0, 0, 0, 0}; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
154 unsigned char *ptr; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
155 NK_ASSERT(img); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
156 if (y0 < img->h && y0 > 0 && x0 > 0 && x0 < img->w) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
157 ptr = img->pixels; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
158 if (img->format == NK_FONT_ATLAS_ALPHA8) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
159 ptr += img->pitch * y0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
160 col.a = ptr[x0]; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
161 col.b = col.g = col.r = 0xff; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
162 } else { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
163 ptr += img->pitch * y0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
164 col = ((struct nk_color *)ptr)[x0]; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
165 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
166 } return col; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
167 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
168 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
169 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
170 nk_image_blendpixel(const struct rawfb_image *img, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
171 const int x0, const int y0, struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
172 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
173 struct nk_color col2; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
174 unsigned char inv_a; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
175 if (col.a == 0) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
176 return; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
177 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
178 inv_a = 0xff - col.a; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
179 col2 = nk_image_getpixel(img, x0, y0); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
180 col.r = (col.r * col.a + col2.r * inv_a) >> 8; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
181 col.g = (col.g * col.a + col2.g * inv_a) >> 8; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
182 col.b = (col.b * col.a + col2.b * inv_a) >> 8; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
183 nk_rawfb_imagesetpixel(img, x0, y0, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
184 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
185 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
186 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
187 nk_rawfb_scissor(struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
188 const float x, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
189 const float y, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
190 const float w, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
191 const float h) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
192 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
193 rawfb->scissors.x = MIN(MAX(x, 0), rawfb->fb.w); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
194 rawfb->scissors.y = MIN(MAX(y, 0), rawfb->fb.h); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
195 rawfb->scissors.w = MIN(MAX(w + x, 0), rawfb->fb.w); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
196 rawfb->scissors.h = MIN(MAX(h + y, 0), rawfb->fb.h); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
197 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
198 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
199 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
200 nk_rawfb_stroke_line(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
201 short x0, short y0, short x1, short y1, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
202 const unsigned int line_thickness, const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
203 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
204 short tmp; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
205 int dy, dx, stepx, stepy; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
206 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
207 dy = y1 - y0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
208 dx = x1 - x0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
209 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
210 /* fast path */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
211 if (dy == 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
212 if (dx == 0 || y0 >= rawfb->scissors.h || y0 < rawfb->scissors.y) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
213 return; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
214 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
215 if (dx < 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
216 /* swap x0 and x1 */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
217 tmp = x1; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
218 x1 = x0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
219 x0 = tmp; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
220 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
221 x1 = MIN(rawfb->scissors.w - 1, x1); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
222 x0 = MIN(rawfb->scissors.w - 1, x0); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
223 x1 = MAX(rawfb->scissors.x, x1); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
224 x0 = MAX(rawfb->scissors.x, x0); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
225 nk_rawfb_line_horizontal(rawfb, x0, y0, x1, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
226 return; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
227 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
228 if (dy < 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
229 dy = -dy; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
230 stepy = -1; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
231 } else stepy = 1; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
232 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
233 if (dx < 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
234 dx = -dx; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
235 stepx = -1; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
236 } else stepx = 1; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
237 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
238 dy <<= 1; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
239 dx <<= 1; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
240 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
241 nk_rawfb_setpixel(rawfb, x0, y0, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
242 if (dx > dy) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
243 int fraction = dy - (dx >> 1); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
244 while (x0 != x1) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
245 if (fraction >= 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
246 y0 += stepy; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
247 fraction -= dx; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
248 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
249 x0 += stepx; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
250 fraction += dy; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
251 nk_rawfb_setpixel(rawfb, x0, y0, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
252 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
253 } else { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
254 int fraction = dx - (dy >> 1); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
255 while (y0 != y1) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
256 if (fraction >= 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
257 x0 += stepx; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
258 fraction -= dy; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
259 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
260 y0 += stepy; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
261 fraction += dx; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
262 nk_rawfb_setpixel(rawfb, x0, y0, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
263 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
264 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
265 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
266 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
267 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
268 nk_rawfb_fill_polygon(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
269 const struct nk_vec2i *pnts, int count, const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
270 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
271 int i = 0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
272 #define MAX_POINTS 64 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
273 int left = 10000, top = 10000, bottom = 0, right = 0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
274 int nodes, nodeX[MAX_POINTS], pixelX, pixelY, j, swap ; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
275 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
276 if (count == 0) return; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
277 if (count > MAX_POINTS) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
278 count = MAX_POINTS; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
279 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
280 /* Get polygon dimensions */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
281 for (i = 0; i < count; i++) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
282 if (left > pnts[i].x) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
283 left = pnts[i].x; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
284 if (right < pnts[i].x) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
285 right = pnts[i].x; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
286 if (top > pnts[i].y) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
287 top = pnts[i].y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
288 if (bottom < pnts[i].y) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
289 bottom = pnts[i].y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
290 } bottom++; right++; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
291 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
292 /* Polygon scanline algorithm released under public-domain by Darel Rex Finley, 2007 */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
293 /* Loop through the rows of the image. */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
294 for (pixelY = top; pixelY < bottom; pixelY ++) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
295 nodes = 0; /* Build a list of nodes. */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
296 j = count - 1; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
297 for (i = 0; i < count; i++) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
298 if (((pnts[i].y < pixelY) && (pnts[j].y >= pixelY)) || |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
299 ((pnts[j].y < pixelY) && (pnts[i].y >= pixelY))) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
300 nodeX[nodes++]= (int)((float)pnts[i].x |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
301 + ((float)pixelY - (float)pnts[i].y) / ((float)pnts[j].y - (float)pnts[i].y) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
302 * ((float)pnts[j].x - (float)pnts[i].x)); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
303 } j = i; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
304 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
305 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
306 /* Sort the nodes, via a simple “Bubble” sort. */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
307 i = 0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
308 while (i < nodes - 1) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
309 if (nodeX[i] > nodeX[i+1]) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
310 swap = nodeX[i]; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
311 nodeX[i] = nodeX[i+1]; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
312 nodeX[i+1] = swap; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
313 if (i) i--; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
314 } else i++; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
315 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
316 /* Fill the pixels between node pairs. */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
317 for (i = 0; i < nodes; i += 2) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
318 if (nodeX[i+0] >= right) break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
319 if (nodeX[i+1] > left) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
320 if (nodeX[i+0] < left) nodeX[i+0] = left ; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
321 if (nodeX[i+1] > right) nodeX[i+1] = right; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
322 for (pixelX = nodeX[i]; pixelX < nodeX[i + 1]; pixelX++) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
323 nk_rawfb_setpixel(rawfb, pixelX, pixelY, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
324 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
325 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
326 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
327 #undef MAX_POINTS |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
328 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
329 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
330 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
331 nk_rawfb_stroke_arc(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
332 short x0, short y0, short w, short h, const short s, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
333 const short line_thickness, const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
334 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
335 /* Bresenham's ellipses - modified to draw one quarter */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
336 const int a2 = (w * w) / 4; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
337 const int b2 = (h * h) / 4; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
338 const int fa2 = 4 * a2, fb2 = 4 * b2; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
339 int x, y, sigma; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
340 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
341 if (s != 0 && s != 90 && s != 180 && s != 270) return; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
342 if (w < 1 || h < 1) return; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
343 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
344 /* Convert upper left to center */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
345 h = (h + 1) / 2; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
346 w = (w + 1) / 2; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
347 x0 += w; y0 += h; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
348 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
349 /* First half */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
350 for (x = 0, y = h, sigma = 2*b2+a2*(1-2*h); b2*x <= a2*y; x++) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
351 if (s == 180) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
352 nk_rawfb_setpixel(rawfb, x0 + x, y0 + y, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
353 else if (s == 270) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
354 nk_rawfb_setpixel(rawfb, x0 - x, y0 + y, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
355 else if (s == 0) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
356 nk_rawfb_setpixel(rawfb, x0 + x, y0 - y, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
357 else if (s == 90) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
358 nk_rawfb_setpixel(rawfb, x0 - x, y0 - y, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
359 if (sigma >= 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
360 sigma += fa2 * (1 - y); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
361 y--; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
362 } sigma += b2 * ((4 * x) + 6); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
363 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
364 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
365 /* Second half */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
366 for (x = w, y = 0, sigma = 2*a2+b2*(1-2*w); a2*y <= b2*x; y++) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
367 if (s == 180) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
368 nk_rawfb_setpixel(rawfb, x0 + x, y0 + y, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
369 else if (s == 270) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
370 nk_rawfb_setpixel(rawfb, x0 - x, y0 + y, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
371 else if (s == 0) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
372 nk_rawfb_setpixel(rawfb, x0 + x, y0 - y, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
373 else if (s == 90) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
374 nk_rawfb_setpixel(rawfb, x0 - x, y0 - y, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
375 if (sigma >= 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
376 sigma += fb2 * (1 - x); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
377 x--; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
378 } sigma += a2 * ((4 * y) + 6); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
379 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
380 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
381 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
382 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
383 nk_rawfb_fill_arc(const struct rawfb_context *rawfb, short x0, short y0, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
384 short w, short h, const short s, const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
385 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
386 /* Bresenham's ellipses - modified to fill one quarter */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
387 const int a2 = (w * w) / 4; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
388 const int b2 = (h * h) / 4; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
389 const int fa2 = 4 * a2, fb2 = 4 * b2; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
390 int x, y, sigma; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
391 struct nk_vec2i pnts[3]; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
392 if (w < 1 || h < 1) return; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
393 if (s != 0 && s != 90 && s != 180 && s != 270) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
394 return; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
395 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
396 /* Convert upper left to center */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
397 h = (h + 1) / 2; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
398 w = (w + 1) / 2; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
399 x0 += w; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
400 y0 += h; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
401 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
402 pnts[0].x = x0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
403 pnts[0].y = y0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
404 pnts[2].x = x0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
405 pnts[2].y = y0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
406 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
407 /* First half */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
408 for (x = 0, y = h, sigma = 2*b2+a2*(1-2*h); b2*x <= a2*y; x++) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
409 if (s == 180) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
410 pnts[1].x = x0 + x; pnts[1].y = y0 + y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
411 } else if (s == 270) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
412 pnts[1].x = x0 - x; pnts[1].y = y0 + y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
413 } else if (s == 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
414 pnts[1].x = x0 + x; pnts[1].y = y0 - y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
415 } else if (s == 90) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
416 pnts[1].x = x0 - x; pnts[1].y = y0 - y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
417 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
418 nk_rawfb_fill_polygon(rawfb, pnts, 3, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
419 pnts[2] = pnts[1]; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
420 if (sigma >= 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
421 sigma += fa2 * (1 - y); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
422 y--; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
423 } sigma += b2 * ((4 * x) + 6); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
424 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
425 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
426 /* Second half */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
427 for (x = w, y = 0, sigma = 2*a2+b2*(1-2*w); a2*y <= b2*x; y++) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
428 if (s == 180) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
429 pnts[1].x = x0 + x; pnts[1].y = y0 + y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
430 } else if (s == 270) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
431 pnts[1].x = x0 - x; pnts[1].y = y0 + y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
432 } else if (s == 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
433 pnts[1].x = x0 + x; pnts[1].y = y0 - y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
434 } else if (s == 90) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
435 pnts[1].x = x0 - x; pnts[1].y = y0 - y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
436 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
437 nk_rawfb_fill_polygon(rawfb, pnts, 3, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
438 pnts[2] = pnts[1]; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
439 if (sigma >= 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
440 sigma += fb2 * (1 - x); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
441 x--; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
442 } sigma += a2 * ((4 * y) + 6); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
443 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
444 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
445 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
446 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
447 nk_rawfb_stroke_rect(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
448 const short x, const short y, const short w, const short h, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
449 const short r, const short line_thickness, const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
450 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
451 if (r == 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
452 nk_rawfb_stroke_line(rawfb, x, y, x + w, y, line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
453 nk_rawfb_stroke_line(rawfb, x, y + h, x + w, y + h, line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
454 nk_rawfb_stroke_line(rawfb, x, y, x, y + h, line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
455 nk_rawfb_stroke_line(rawfb, x + w, y, x + w, y + h, line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
456 } else { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
457 const short xc = x + r; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
458 const short yc = y + r; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
459 const short wc = (short)(w - 2 * r); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
460 const short hc = (short)(h - 2 * r); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
461 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
462 nk_rawfb_stroke_line(rawfb, xc, y, xc + wc, y, line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
463 nk_rawfb_stroke_line(rawfb, x + w, yc, x + w, yc + hc, line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
464 nk_rawfb_stroke_line(rawfb, xc, y + h, xc + wc, y + h, line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
465 nk_rawfb_stroke_line(rawfb, x, yc, x, yc + hc, line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
466 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
467 nk_rawfb_stroke_arc(rawfb, xc + wc - r, y, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
468 (unsigned)r*2, (unsigned)r*2, 0 , line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
469 nk_rawfb_stroke_arc(rawfb, x, y, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
470 (unsigned)r*2, (unsigned)r*2, 90 , line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
471 nk_rawfb_stroke_arc(rawfb, x, yc + hc - r, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
472 (unsigned)r*2, (unsigned)r*2, 270 , line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
473 nk_rawfb_stroke_arc(rawfb, xc + wc - r, yc + hc - r, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
474 (unsigned)r*2, (unsigned)r*2, 180 , line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
475 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
476 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
477 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
478 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
479 nk_rawfb_fill_rect(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
480 const short x, const short y, const short w, const short h, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
481 const short r, const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
482 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
483 int i; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
484 if (r == 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
485 for (i = 0; i < h; i++) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
486 nk_rawfb_stroke_line(rawfb, x, y + i, x + w, y + i, 1, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
487 } else { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
488 const short xc = x + r; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
489 const short yc = y + r; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
490 const short wc = (short)(w - 2 * r); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
491 const short hc = (short)(h - 2 * r); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
492 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
493 struct nk_vec2i pnts[12]; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
494 pnts[0].x = x; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
495 pnts[0].y = yc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
496 pnts[1].x = xc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
497 pnts[1].y = yc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
498 pnts[2].x = xc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
499 pnts[2].y = y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
500 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
501 pnts[3].x = xc + wc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
502 pnts[3].y = y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
503 pnts[4].x = xc + wc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
504 pnts[4].y = yc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
505 pnts[5].x = x + w; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
506 pnts[5].y = yc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
507 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
508 pnts[6].x = x + w; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
509 pnts[6].y = yc + hc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
510 pnts[7].x = xc + wc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
511 pnts[7].y = yc + hc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
512 pnts[8].x = xc + wc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
513 pnts[8].y = y + h; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
514 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
515 pnts[9].x = xc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
516 pnts[9].y = y + h; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
517 pnts[10].x = xc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
518 pnts[10].y = yc + hc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
519 pnts[11].x = x; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
520 pnts[11].y = yc + hc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
521 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
522 nk_rawfb_fill_polygon(rawfb, pnts, 12, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
523 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
524 nk_rawfb_fill_arc(rawfb, xc + wc - r, y, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
525 (unsigned)r*2, (unsigned)r*2, 0 , col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
526 nk_rawfb_fill_arc(rawfb, x, y, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
527 (unsigned)r*2, (unsigned)r*2, 90 , col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
528 nk_rawfb_fill_arc(rawfb, x, yc + hc - r, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
529 (unsigned)r*2, (unsigned)r*2, 270 , col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
530 nk_rawfb_fill_arc(rawfb, xc + wc - r, yc + hc - r, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
531 (unsigned)r*2, (unsigned)r*2, 180 , col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
532 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
533 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
534 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
535 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
536 nk_rawfb_fill_triangle(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
537 const short x0, const short y0, const short x1, const short y1, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
538 const short x2, const short y2, const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
539 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
540 struct nk_vec2i pnts[3]; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
541 pnts[0].x = x0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
542 pnts[0].y = y0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
543 pnts[1].x = x1; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
544 pnts[1].y = y1; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
545 pnts[2].x = x2; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
546 pnts[2].y = y2; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
547 nk_rawfb_fill_polygon(rawfb, pnts, 3, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
548 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
549 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
550 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
551 nk_rawfb_stroke_triangle(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
552 const short x0, const short y0, const short x1, const short y1, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
553 const short x2, const short y2, const unsigned short line_thickness, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
554 const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
555 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
556 nk_rawfb_stroke_line(rawfb, x0, y0, x1, y1, line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
557 nk_rawfb_stroke_line(rawfb, x1, y1, x2, y2, line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
558 nk_rawfb_stroke_line(rawfb, x2, y2, x0, y0, line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
559 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
560 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
561 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
562 nk_rawfb_stroke_polygon(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
563 const struct nk_vec2i *pnts, const int count, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
564 const unsigned short line_thickness, const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
565 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
566 int i; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
567 for (i = 1; i < count; ++i) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
568 nk_rawfb_stroke_line(rawfb, pnts[i-1].x, pnts[i-1].y, pnts[i].x, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
569 pnts[i].y, line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
570 nk_rawfb_stroke_line(rawfb, pnts[count-1].x, pnts[count-1].y, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
571 pnts[0].x, pnts[0].y, line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
572 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
573 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
574 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
575 nk_rawfb_stroke_polyline(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
576 const struct nk_vec2i *pnts, const int count, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
577 const unsigned short line_thickness, const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
578 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
579 int i; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
580 for (i = 0; i < count-1; ++i) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
581 nk_rawfb_stroke_line(rawfb, pnts[i].x, pnts[i].y, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
582 pnts[i+1].x, pnts[i+1].y, line_thickness, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
583 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
584 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
585 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
586 nk_rawfb_fill_circle(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
587 short x0, short y0, short w, short h, const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
588 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
589 /* Bresenham's ellipses */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
590 const int a2 = (w * w) / 4; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
591 const int b2 = (h * h) / 4; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
592 const int fa2 = 4 * a2, fb2 = 4 * b2; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
593 int x, y, sigma; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
594 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
595 /* Convert upper left to center */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
596 h = (h + 1) / 2; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
597 w = (w + 1) / 2; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
598 x0 += w; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
599 y0 += h; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
600 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
601 /* First half */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
602 for (x = 0, y = h, sigma = 2*b2+a2*(1-2*h); b2*x <= a2*y; x++) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
603 nk_rawfb_stroke_line(rawfb, x0 - x, y0 + y, x0 + x, y0 + y, 1, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
604 nk_rawfb_stroke_line(rawfb, x0 - x, y0 - y, x0 + x, y0 - y, 1, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
605 if (sigma >= 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
606 sigma += fa2 * (1 - y); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
607 y--; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
608 } sigma += b2 * ((4 * x) + 6); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
609 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
610 /* Second half */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
611 for (x = w, y = 0, sigma = 2*a2+b2*(1-2*w); a2*y <= b2*x; y++) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
612 nk_rawfb_stroke_line(rawfb, x0 - x, y0 + y, x0 + x, y0 + y, 1, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
613 nk_rawfb_stroke_line(rawfb, x0 - x, y0 - y, x0 + x, y0 - y, 1, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
614 if (sigma >= 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
615 sigma += fb2 * (1 - x); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
616 x--; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
617 } sigma += a2 * ((4 * y) + 6); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
618 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
619 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
620 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
621 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
622 nk_rawfb_stroke_circle(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
623 short x0, short y0, short w, short h, const short line_thickness, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
624 const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
625 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
626 /* Bresenham's ellipses */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
627 const int a2 = (w * w) / 4; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
628 const int b2 = (h * h) / 4; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
629 const int fa2 = 4 * a2, fb2 = 4 * b2; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
630 int x, y, sigma; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
631 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
632 /* Convert upper left to center */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
633 h = (h + 1) / 2; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
634 w = (w + 1) / 2; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
635 x0 += w; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
636 y0 += h; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
637 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
638 /* First half */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
639 for (x = 0, y = h, sigma = 2*b2+a2*(1-2*h); b2*x <= a2*y; x++) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
640 nk_rawfb_setpixel(rawfb, x0 + x, y0 + y, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
641 nk_rawfb_setpixel(rawfb, x0 - x, y0 + y, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
642 nk_rawfb_setpixel(rawfb, x0 + x, y0 - y, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
643 nk_rawfb_setpixel(rawfb, x0 - x, y0 - y, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
644 if (sigma >= 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
645 sigma += fa2 * (1 - y); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
646 y--; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
647 } sigma += b2 * ((4 * x) + 6); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
648 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
649 /* Second half */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
650 for (x = w, y = 0, sigma = 2*a2+b2*(1-2*w); a2*y <= b2*x; y++) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
651 nk_rawfb_setpixel(rawfb, x0 + x, y0 + y, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
652 nk_rawfb_setpixel(rawfb, x0 - x, y0 + y, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
653 nk_rawfb_setpixel(rawfb, x0 + x, y0 - y, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
654 nk_rawfb_setpixel(rawfb, x0 - x, y0 - y, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
655 if (sigma >= 0) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
656 sigma += fb2 * (1 - x); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
657 x--; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
658 } sigma += a2 * ((4 * y) + 6); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
659 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
660 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
661 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
662 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
663 nk_rawfb_stroke_curve(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
664 const struct nk_vec2i p1, const struct nk_vec2i p2, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
665 const struct nk_vec2i p3, const struct nk_vec2i p4, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
666 const unsigned int num_segments, const unsigned short line_thickness, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
667 const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
668 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
669 unsigned int i_step, segments; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
670 float t_step; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
671 struct nk_vec2i last = p1; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
672 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
673 segments = MAX(num_segments, 1); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
674 t_step = 1.0f/(float)segments; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
675 for (i_step = 1; i_step <= segments; ++i_step) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
676 float t = t_step * (float)i_step; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
677 float u = 1.0f - t; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
678 float w1 = u*u*u; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
679 float w2 = 3*u*u*t; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
680 float w3 = 3*u*t*t; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
681 float w4 = t * t *t; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
682 float x = w1 * p1.x + w2 * p2.x + w3 * p3.x + w4 * p4.x; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
683 float y = w1 * p1.y + w2 * p2.y + w3 * p3.y + w4 * p4.y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
684 nk_rawfb_stroke_line(rawfb, last.x, last.y, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
685 (short)x, (short)y, line_thickness,col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
686 last.x = (short)x; last.y = (short)y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
687 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
688 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
689 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
690 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
691 nk_rawfb_clear(const struct rawfb_context *rawfb, const struct nk_color col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
692 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
693 nk_rawfb_fill_rect(rawfb, 0, 0, rawfb->fb.w, rawfb->fb.h, 0, col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
694 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
695 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
696 NK_API struct rawfb_context* |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
697 nk_rawfb_init(void *fb, struct nk_context *context, const unsigned int w, const unsigned int h, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
698 const unsigned int pitch) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
699 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
700 struct rawfb_context *rawfb; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
701 rawfb = malloc(sizeof(struct rawfb_context)); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
702 if (!rawfb) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
703 return NULL; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
704 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
705 nk_memset(rawfb, 0, sizeof(struct rawfb_context)); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
706 rawfb->font_tex.format = NK_FONT_ATLAS_ALPHA8; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
707 rawfb->font_tex.w = rawfb->font_tex.h = 0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
708 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
709 rawfb->fb.pixels = fb; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
710 rawfb->fb.w= w; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
711 rawfb->fb.h = h; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
712 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
713 #if defined(RAWFB_XRGB_8888) || defined(RAWFB_RGBX_8888) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
714 rawfb->fb.format = NK_FONT_ATLAS_RGBA32; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
715 rawfb->fb.pitch = pitch; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
716 #else |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
717 #error Fixme |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
718 #endif |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
719 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
720 rawfb->ctx = context; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
721 nk_rawfb_scissor(rawfb, 0, 0, rawfb->fb.w, rawfb->fb.h); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
722 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
723 return rawfb; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
724 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
725 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
726 NK_API void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
727 nk_rawfb_font_stash_begin(struct rawfb_context *rawfb, struct nk_font_atlas **atlas) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
728 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
729 nk_font_atlas_init_default(&rawfb->atlas); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
730 nk_font_atlas_begin(&rawfb->atlas); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
731 *atlas = &rawfb->atlas; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
732 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
733 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
734 NK_API void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
735 nk_rawfb_font_stash_end(struct rawfb_context *rawfb) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
736 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
737 const void *tex; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
738 tex = nk_font_atlas_bake(&rawfb->atlas, &rawfb->font_tex.w, &rawfb->font_tex.h, rawfb->font_tex.format); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
739 if (!tex) return; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
740 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
741 switch(rawfb->font_tex.format) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
742 case NK_FONT_ATLAS_ALPHA8: |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
743 rawfb->font_tex.pitch = rawfb->font_tex.w * 1; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
744 break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
745 case NK_FONT_ATLAS_RGBA32: |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
746 rawfb->font_tex.pitch = rawfb->font_tex.w * 4; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
747 break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
748 }; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
749 /* Store the font texture in tex scratch memory */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
750 rawfb->font_tex.pixels = malloc(rawfb->font_tex.pitch * rawfb->font_tex.h); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
751 memcpy(rawfb->font_tex.pixels, tex, rawfb->font_tex.pitch * rawfb->font_tex.h); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
752 nk_font_atlas_end(&rawfb->atlas, nk_handle_ptr(NULL), NULL); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
753 if (rawfb->atlas.default_font) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
754 nk_style_set_font(rawfb->ctx, &rawfb->atlas.default_font->handle); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
755 nk_style_load_all_cursors(rawfb->ctx, rawfb->atlas.cursors); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
756 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
757 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
758 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
759 nk_rawfb_stretch_image(const struct rawfb_image *dst, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
760 const struct rawfb_image *src, const struct nk_rect *dst_rect, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
761 const struct nk_rect *src_rect, const struct nk_rect *dst_scissors) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
762 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
763 short i, j; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
764 struct nk_color col; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
765 float xinc = src_rect->w / dst_rect->w; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
766 float yinc = src_rect->h / dst_rect->h; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
767 float xoff = src_rect->x, yoff = src_rect->y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
768 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
769 /* Simple nearest filtering rescaling */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
770 /* TODO: use bilinear filter */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
771 for (j = 0; j < (short)dst_rect->h; j++) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
772 for (i = 0; i < (short)dst_rect->w; i++) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
773 if (dst_scissors) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
774 if (i + (int)(dst_rect->x + 0.5f) < dst_scissors->x || i + (int)(dst_rect->x + 0.5f) >= dst_scissors->w) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
775 continue; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
776 if (j + (int)(dst_rect->y + 0.5f) < dst_scissors->y || j + (int)(dst_rect->y + 0.5f) >= dst_scissors->h) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
777 continue; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
778 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
779 col = nk_image_getpixel(src, (int)xoff, (int) yoff); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
780 nk_image_blendpixel(dst, i + (int)(dst_rect->x + 0.5f), j + (int)(dst_rect->y + 0.5f), col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
781 xoff += xinc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
782 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
783 xoff = src_rect->x; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
784 yoff += yinc; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
785 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
786 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
787 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
788 static void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
789 nk_rawfb_font_query_font_glyph(nk_handle handle, const float height, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
790 struct nk_user_font_glyph *glyph, const nk_rune codepoint, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
791 const nk_rune next_codepoint) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
792 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
793 float scale; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
794 const struct nk_font_glyph *g; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
795 struct nk_font *font; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
796 NK_ASSERT(glyph); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
797 NK_UNUSED(next_codepoint); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
798 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
799 font = (struct nk_font*)handle.ptr; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
800 NK_ASSERT(font); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
801 NK_ASSERT(font->glyphs); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
802 if (!font || !glyph) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
803 return; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
804 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
805 scale = height/font->info.height; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
806 g = nk_font_find_glyph(font, codepoint); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
807 glyph->width = (g->x1 - g->x0) * scale; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
808 glyph->height = (g->y1 - g->y0) * scale; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
809 glyph->offset = nk_vec2(g->x0 * scale, g->y0 * scale); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
810 glyph->xadvance = (g->xadvance * scale); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
811 glyph->uv[0] = nk_vec2(g->u0, g->v0); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
812 glyph->uv[1] = nk_vec2(g->u1, g->v1); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
813 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
814 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
815 NK_API void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
816 nk_rawfb_draw_text(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
817 const struct nk_user_font *font, const struct nk_rect rect, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
818 const char *text, const int len, const float font_height, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
819 const struct nk_color fg) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
820 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
821 float x = 0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
822 int text_len = 0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
823 nk_rune unicode = 0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
824 nk_rune next = 0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
825 int glyph_len = 0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
826 int next_glyph_len = 0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
827 struct nk_user_font_glyph g; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
828 if (!len || !text) return; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
829 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
830 x = 0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
831 glyph_len = nk_utf_decode(text, &unicode, len); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
832 if (!glyph_len) return; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
833 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
834 /* draw every glyph image */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
835 while (text_len < len && glyph_len) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
836 struct nk_rect src_rect; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
837 struct nk_rect dst_rect; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
838 float char_width = 0; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
839 if (unicode == NK_UTF_INVALID) break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
840 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
841 /* query currently drawn glyph information */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
842 next_glyph_len = nk_utf_decode(text + text_len + glyph_len, &next, (int)len - text_len); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
843 nk_rawfb_font_query_font_glyph(font->userdata, font_height, &g, unicode, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
844 (next == NK_UTF_INVALID) ? '\0' : next); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
845 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
846 /* calculate and draw glyph drawing rectangle and image */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
847 char_width = g.xadvance; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
848 src_rect.x = g.uv[0].x * rawfb->font_tex.w; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
849 src_rect.y = g.uv[0].y * rawfb->font_tex.h; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
850 src_rect.w = g.uv[1].x * rawfb->font_tex.w - g.uv[0].x * rawfb->font_tex.w; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
851 src_rect.h = g.uv[1].y * rawfb->font_tex.h - g.uv[0].y * rawfb->font_tex.h; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
852 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
853 dst_rect.x = x + g.offset.x + rect.x; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
854 dst_rect.y = g.offset.y + rect.y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
855 dst_rect.w = ceilf(g.width); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
856 dst_rect.h = ceilf(g.height); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
857 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
858 /* TODO: account fg */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
859 /* Use software rescaling to blit glyph from font_text to framebuffer */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
860 nk_rawfb_stretch_image(&rawfb->fb, &rawfb->font_tex, &dst_rect, &src_rect, &rawfb->scissors); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
861 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
862 /* offset next glyph */ |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
863 text_len += glyph_len; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
864 x += char_width; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
865 glyph_len = next_glyph_len; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
866 unicode = next; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
867 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
868 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
869 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
870 NK_API void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
871 nk_rawfb_drawimage(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
872 const int x, const int y, const int w, const int h, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
873 const struct nk_image *img, const struct nk_color *col) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
874 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
875 struct nk_rect src_rect; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
876 struct nk_rect dst_rect; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
877 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
878 const struct rawfb_image *rfb_img = img->handle.ptr; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
879 if (!rfb_img) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
880 rfb_img = &rawfb->font_tex; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
881 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
882 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
883 src_rect.x = img->region[0]; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
884 src_rect.y = img->region[1]; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
885 if (nk_image_is_subimage(img)) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
886 src_rect.w = img->region[2]; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
887 src_rect.h = img->region[3]; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
888 } else { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
889 src_rect.w = rfb_img->w; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
890 src_rect.h = rfb_img->h; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
891 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
892 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
893 dst_rect.x = x; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
894 dst_rect.y = y; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
895 dst_rect.w = w; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
896 dst_rect.h = h; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
897 nk_rawfb_stretch_image(&rawfb->fb, rfb_img, &dst_rect, &src_rect, &rawfb->scissors); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
898 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
899 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
900 NK_API void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
901 nk_rawfb_shutdown(struct rawfb_context *rawfb) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
902 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
903 nk_memset(rawfb, 0, sizeof(struct rawfb_context)); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
904 free(rawfb); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
905 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
906 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
907 NK_API void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
908 nk_rawfb_resize_fb(struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
909 void *fb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
910 const unsigned int w, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
911 const unsigned int h, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
912 const unsigned int pitch) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
913 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
914 rawfb->fb.w = w; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
915 rawfb->fb.h = h; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
916 rawfb->fb.pixels = fb; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
917 rawfb->fb.pitch = pitch; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
918 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
919 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
920 NK_API void |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
921 nk_rawfb_render(const struct rawfb_context *rawfb, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
922 const struct nk_color clear, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
923 const unsigned char enable_clear) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
924 { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
925 const struct nk_command *cmd; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
926 if (enable_clear) |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
927 nk_rawfb_clear(rawfb, clear); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
928 |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
929 nk_foreach(cmd, rawfb->ctx) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
930 switch (cmd->type) { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
931 case NK_COMMAND_NOP: break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
932 case NK_COMMAND_SCISSOR: { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
933 const struct nk_command_scissor *s =(const struct nk_command_scissor*)cmd; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
934 nk_rawfb_scissor((struct rawfb_context *)rawfb, s->x, s->y, s->w, s->h); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
935 } break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
936 case NK_COMMAND_LINE: { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
937 const struct nk_command_line *l = (const struct nk_command_line *)cmd; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
938 nk_rawfb_stroke_line(rawfb, l->begin.x, l->begin.y, l->end.x, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
939 l->end.y, l->line_thickness, l->color); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
940 } break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
941 case NK_COMMAND_RECT: { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
942 const struct nk_command_rect *r = (const struct nk_command_rect *)cmd; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
943 nk_rawfb_stroke_rect(rawfb, r->x, r->y, r->w, r->h, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
944 (unsigned short)r->rounding, r->line_thickness, r->color); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
945 } break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
946 case NK_COMMAND_RECT_FILLED: { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
947 const struct nk_command_rect_filled *r = (const struct nk_command_rect_filled *)cmd; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
948 nk_rawfb_fill_rect(rawfb, r->x, r->y, r->w, r->h, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
949 (unsigned short)r->rounding, r->color); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
950 } break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
951 case NK_COMMAND_CIRCLE: { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
952 const struct nk_command_circle *c = (const struct nk_command_circle *)cmd; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
953 nk_rawfb_stroke_circle(rawfb, c->x, c->y, c->w, c->h, c->line_thickness, c->color); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
954 } break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
955 case NK_COMMAND_CIRCLE_FILLED: { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
956 const struct nk_command_circle_filled *c = (const struct nk_command_circle_filled *)cmd; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
957 nk_rawfb_fill_circle(rawfb, c->x, c->y, c->w, c->h, c->color); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
958 } break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
959 case NK_COMMAND_TRIANGLE: { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
960 const struct nk_command_triangle*t = (const struct nk_command_triangle*)cmd; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
961 nk_rawfb_stroke_triangle(rawfb, t->a.x, t->a.y, t->b.x, t->b.y, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
962 t->c.x, t->c.y, t->line_thickness, t->color); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
963 } break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
964 case NK_COMMAND_TRIANGLE_FILLED: { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
965 const struct nk_command_triangle_filled *t = (const struct nk_command_triangle_filled *)cmd; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
966 nk_rawfb_fill_triangle(rawfb, t->a.x, t->a.y, t->b.x, t->b.y, |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
967 t->c.x, t->c.y, t->color); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
968 } break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
969 case NK_COMMAND_POLYGON: { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
970 const struct nk_command_polygon *p =(const struct nk_command_polygon*)cmd; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
971 nk_rawfb_stroke_polygon(rawfb, p->points, p->point_count, p->line_thickness,p->color); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
972 } break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
973 case NK_COMMAND_POLYGON_FILLED: { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
974 const struct nk_command_polygon_filled *p = (const struct nk_command_polygon_filled *)cmd; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
975 nk_rawfb_fill_polygon(rawfb, p->points, p->point_count, p->color); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
976 } break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
977 case NK_COMMAND_POLYLINE: { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
978 const struct nk_command_polyline *p = (const struct nk_command_polyline *)cmd; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
979 nk_rawfb_stroke_polyline(rawfb, p->points, p->point_count, p->line_thickness, p->color); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
980 } break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
981 case NK_COMMAND_TEXT: { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
982 const struct nk_command_text *t = (const struct nk_command_text*)cmd; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
983 nk_rawfb_draw_text(rawfb, t->font, nk_rect(t->x, t->y, t->w, t->h), |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
984 t->string, t->length, t->height, t->foreground); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
985 } break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
986 case NK_COMMAND_CURVE: { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
987 const struct nk_command_curve *q = (const struct nk_command_curve *)cmd; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
988 nk_rawfb_stroke_curve(rawfb, q->begin, q->ctrl[0], q->ctrl[1], |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
989 q->end, 22, q->line_thickness, q->color); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
990 } break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
991 case NK_COMMAND_RECT_MULTI_COLOR: |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
992 case NK_COMMAND_IMAGE: { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
993 const struct nk_command_image *q = (const struct nk_command_image *)cmd; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
994 nk_rawfb_drawimage(rawfb, q->x, q->y, q->w, q->h, &q->img, &q->col); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
995 } break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
996 case NK_COMMAND_ARC: { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
997 assert(0 && "NK_COMMAND_ARC not implemented\n"); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
998 } break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
999 case NK_COMMAND_ARC_FILLED: { |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1000 assert(0 && "NK_COMMAND_ARC_FILLED not implemented\n"); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1001 } break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1002 default: break; |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1003 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1004 } nk_clear(rawfb->ctx); |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1005 } |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1006 #endif |
56a1171e29b9
Allow Nuklear UI to be used when OpenGL is disabled
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
1007 |