1 #include "portability.h"
7 #include "../elk_config.h"
97 jsval_t jse_ext_canvas_fillStyle(
struct js *
js, jsval_t *args,
int nargs) {
98 if (nargs != 1)
return js_mknum(
js->Canvas.fillStyle);
99 int c = jse_func_atoi(js_str(
js,(args[0])));
100 qemu_log(
" [JSE] [EXT] [Canvas] [fillStyle] Color:%x", c);
101 js->Canvas.fillStyle = c;
102 return js_mknum(
js->Canvas.fillStyle);
105 jsval_t jse_ext_canvas_setPixel(
struct js *
js, jsval_t *args,
int nargs) {
106 if (nargs != 3)
return js_mkfalse();
107 int x = jse_func_atoi(js_str(
js,(args[0])));
108 int y = jse_func_atoi(js_str(
js,(args[1])));
109 int c = jse_func_atoi(js_str(
js,(args[2])));
110 qemu_log(
" [JSE] [EXT] [Canvas] [setPixel] X: %d | Y: %d | Color:%x", x, y, c);
116 jsval_t jse_ext_canvas_lineWidth(
struct js *
js, jsval_t *args,
int nargs) {
117 if (nargs != 1)
return js_mknum(
js->Canvas.lineWidth);
118 int c = jse_func_atoi(js_str(
js,(args[0])));
119 qemu_log(
" [JSE] [EXT] [Canvas] [lineWidth] lineWidth:%d", c);
120 js->Canvas.lineWidth = c;
121 return js_mknum(
js->Canvas.lineWidth);
125 jsval_t jse_ext_canvas_width(
struct js *
js, jsval_t *args,
int nargs) {
126 return js_mknum(
js->Canvas.width);
130 jsval_t jse_ext_canvas_height(
struct js *
js, jsval_t *args,
int nargs) {
131 return js_mknum(
js->Canvas.height);
134 jsval_t jse_ext_canvas_fillRect(
struct js *
js, jsval_t *args,
int nargs) {
135 if (nargs != 4)
return js_mkundef();
136 int x = jse_getInt(
js,args[0]);
137 int y = jse_getInt(
js,args[1]);
138 int w = jse_getInt(
js,args[2]);
139 int h = jse_getInt(
js,args[3]);
141 int color =
js->Canvas.fillStyle;
142 qemu_log(
" [JSE] [EXT] [Canvas] [fillRect] X:%d Y:%d W:%d H:%d Color:%x", x, y, w, h, color);
149 jsval_t jse_ext_canvas_clearRect(
struct js *
js, jsval_t *args,
int nargs) {
150 if (nargs != 4)
return js_mkundef();
151 int x = jse_getInt(
js,args[0]);
152 int y = jse_getInt(
js,args[1]);
153 int w = jse_getInt(
js,args[2]);
154 int h = jse_getInt(
js,args[3]);
157 qemu_log(
" [JSE] [EXT] [Canvas] [clearRect] X:%d Y:%d W:%d H:%d", x, y, w, h);
163 jsval_t jse_ext_canvas_strokeRect(
struct js *
js, jsval_t *args,
int nargs) {
164 if (nargs != 4)
return js_mkundef();
165 int x = jse_getInt(
js,args[0]);
166 int y = jse_getInt(
js,args[1]);
167 int w = jse_getInt(
js,args[2]);
168 int h = jse_getInt(
js,args[3]);
169 int lineWidth =
js->Canvas.lineWidth;
170 int color =
js->Canvas.fillStyle;
171 if (lineWidth == 0)
return js_mkfalse();
173 for (
int i = 0; i < lineWidth; i++) {
174 int new_width = w + 2 * i;
175 int new_height = h + 2 * i;
176 set_pixel(x - i, y - i, color);
177 set_pixel(x - i + new_width, y - i, color);
178 set_pixel(x - i, y - i + new_height, color);
179 set_pixel(x - i + new_width, y - i + new_height, color);
182 for (
int i = 0; i < lineWidth; i++) {
185 int new_width = w - 2 * i;
186 int new_height = h - 2 * i;
187 for (
int j = new_y; j < new_y + new_height; j++) {
188 set_pixel(new_x, j, color);
189 set_pixel(new_x + new_width, j, color);
191 for (
int j = new_x; j < new_x + new_width; j++) {
192 set_pixel(j, new_y, color);
193 set_pixel(j, new_y + new_height, color);
196 qemu_log(
" [JSE] [EXT] [Canvas] [strokeRect] X:%d Y:%d W:%d H:%d Color:%x", x, y, w, h, color);
204 void jse_canvas_config(
struct js*
js){
206 JSE_CANVAS cfg =
js->Canvas;
207 cfg.fillStyle = 0xFFFFFF;
212 qemu_note(
"[JSE] [EXT] [Canvas] Registration of functions");
213 js_set(
js, js_glob(
js),
"canvas_fillRect", js_mkfun(jse_ext_canvas_fillRect));
214 js_set(
js, js_glob(
js),
"canvas_clearRect", js_mkfun(jse_ext_canvas_clearRect));
215 js_set(
js, js_glob(
js),
"canvas_strokeRect", js_mkfun(jse_ext_canvas_strokeRect));
217 js_set(
js, js_glob(
js),
"canvas_height", js_mkfun(jse_ext_canvas_height));
218 js_set(
js, js_glob(
js),
"canvas_width", js_mkfun(jse_ext_canvas_width));
220 js_set(
js, js_glob(
js),
"canvas_fillStyle", js_mkfun(jse_ext_canvas_fillStyle));
221 js_set(
js, js_glob(
js),
"canvas_lineWidth", js_mkfun(jse_ext_canvas_lineWidth));
225 js_set(
js, js_glob(
js),
"canvas_setPixel", js_mkfun(jse_ext_canvas_setPixel));
228 js_set(
js, js_glob(
js),
"canvas_rect", js_mkfun(jse_ext_canvas_fillRect));
232 void jse_canvas_destroy(
struct js*
js){
void drawRect(uint32_t x, uint32_t y, uint32_t w, uint32_t h, uint32_t color)
Рисуем залитый прямоугольник