- [CHG] draw.rect i draw.rectFill ara pillen (x,y,w,h), com les persones normals, no (x1,y1,x2,y2) com el subnormal de pico-8

This commit is contained in:
2025-02-19 13:34:55 +01:00
parent ecb493f9c8
commit 2f0817d20c
3 changed files with 29 additions and 25 deletions

20
lua.cpp
View File

@@ -407,22 +407,22 @@ extern "C" {
} }
static int cpp_draw_rect(lua_State *L) { static int cpp_draw_rect(lua_State *L) {
int x0 = luaL_checknumber(L, 1); int x = luaL_checknumber(L, 1);
int y0 = luaL_checknumber(L, 2); int y = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3); int w = luaL_checknumber(L, 3);
int y1 = luaL_checknumber(L, 4); int h = luaL_checknumber(L, 4);
uint8_t color = luaL_checkinteger(L, 5); uint8_t color = luaL_checkinteger(L, 5);
rect(x0, y0, x1, y1, color); rect(x, y, w, h, color);
return 0; return 0;
} }
static int cpp_draw_rectfill(lua_State *L) { static int cpp_draw_rectfill(lua_State *L) {
int x0 = luaL_checknumber(L, 1); int x = luaL_checknumber(L, 1);
int y0 = luaL_checknumber(L, 2); int y = luaL_checknumber(L, 2);
int x1 = luaL_checknumber(L, 3); int w = luaL_checknumber(L, 3);
int y1 = luaL_checknumber(L, 4); int h = luaL_checknumber(L, 4);
uint8_t color = luaL_checkinteger(L, 5); uint8_t color = luaL_checkinteger(L, 5);
rectfill(x0, y0, x1, y1, color); rectfill(x, y, w, h, color);
return 0; return 0;
} }

View File

@@ -676,25 +676,29 @@ void vline(int x, int y0, int y1, uint8_t color) {
vline(x, y0, y1); vline(x, y0, y1);
} }
void rect(int x0, int y0, int x1, int y1) { void rect(int x, int y, int w, int h) {
hline(x0, y0, x1); int x1 = w-x+1;
hline(x0, y1, x1); int y1 = h-y+1;
vline(x0, y0, y1); hline(x, y, x1);
vline(x1, y0, y1); hline(x, y1, x1);
vline(x, y, y1);
vline(x1, y, y1);
} }
void rect(int x0, int y0, int x1, int y1, uint8_t color) { void rect(int x, int y, int w, int h, uint8_t color) {
ds::pen_color = color; ds::pen_color = color;
rect(x0, y0, x1, y1); rect(x, y, w, h);
} }
void rectfill(int x0, int y0, int x1, int y1) { void rectfill(int x, int y, int w, int h) {
for (int y=y0; y<=y1; ++y) hline(x0, y, x1); int x1 = w-x+1;
int y1 = h-y+1;
for (int y=y; y<=y1; ++y) hline(x, y, x1);
} }
void rectfill(int x0, int y0, int x1, int y1, uint8_t color) { void rectfill(int x, int y, int w, int h, uint8_t color) {
ds::pen_color = color; ds::pen_color = color;
rectfill(x0, y0, x1, y1); rectfill(x, y, w, h);
} }
void fillp(uint16_t pat, bool transparent) { void fillp(uint16_t pat, bool transparent) {

8
mini.h
View File

@@ -156,11 +156,11 @@ void hline(int x0, int y, int x1, uint8_t color);
void vline(int x, int y0, int y1); void vline(int x, int y0, int y1);
void vline(int x, int y0, int y1, uint8_t color); void vline(int x, int y0, int y1, uint8_t color);
void rect(int x0, int y0, int x1, int y1); void rect(int x, int y, int w, int h);
void rect(int x0, int y0, int x1, int y1, uint8_t color); void rect(int x, int y, int w, int h, uint8_t color);
void rectfill(int x0, int y0, int x1, int y1); void rectfill(int x, int y, int w, int h);
void rectfill(int x0, int y0, int x1, int y1, uint8_t color); void rectfill(int x, int y, int w, int h, uint8_t color);
void fillp(uint16_t pat, bool transparent = false); void fillp(uint16_t pat, bool transparent = false);