add canvas:rect

This commit is contained in:
MihailRis 2025-11-22 14:40:31 +03:00
parent fc292a57cd
commit f6dd298e07

View File

@ -125,7 +125,9 @@ static RGBA get_rgba(State* L, int first) {
rgba.rgba = static_cast<uint>(tointeger(L, first)); rgba.rgba = static_cast<uint>(tointeger(L, first));
break; break;
case 3: case 3:
rgba.a = static_cast<ubyte>(tointeger(L, first + 3)); if (lua::isnumber(L, first + 3)) {
rgba.a = static_cast<ubyte>(tointeger(L, first + 3));
}
[[fallthrough]]; [[fallthrough]];
case 2: case 2:
rgba.r = static_cast<ubyte>(tointeger(L, first)); rgba.r = static_cast<ubyte>(tointeger(L, first));
@ -199,6 +201,18 @@ static int l_blit(State* L) {
return 0; return 0;
} }
static int l_rect(State* L) {
auto& canvas = require_canvas(L, 1);
auto& image = canvas.getData();
int x = tointeger(L, 2);
int y = tointeger(L, 3);
int w = tointeger(L, 4);
int h = tointeger(L, 5);
RGBA rgba = get_rgba(L, 6);
image.drawRect(x, y, w, h, glm::ivec4 {rgba.r, rgba.g, rgba.b, rgba.a});
return 0;
}
static int l_set_data(State* L) { static int l_set_data(State* L) {
auto& canvas = require_canvas(L, 1); auto& canvas = require_canvas(L, 1);
auto& image = canvas.getData(); auto& image = canvas.getData();
@ -316,6 +330,7 @@ static std::unordered_map<std::string, lua_CFunction> methods {
{"line", lua::wrap<l_line>}, {"line", lua::wrap<l_line>},
{"blit", lua::wrap<l_blit>}, {"blit", lua::wrap<l_blit>},
{"clear", lua::wrap<l_clear>}, {"clear", lua::wrap<l_clear>},
{"rect", lua::wrap<l_rect>},
{"update", lua::wrap<l_update>}, {"update", lua::wrap<l_update>},
{"create_texture", lua::wrap<l_create_texture>}, {"create_texture", lua::wrap<l_create_texture>},
{"unbind_texture", lua::wrap<l_unbind_texture>}, {"unbind_texture", lua::wrap<l_unbind_texture>},