mirror of
https://github.com/aseprite/aseprite.git
synced 2025-02-05 00:39:50 +00:00
[lua] Add Image:clear(Rectangle, color) overload (fix #3799)
We can use: Image:clear() Image:clear(color) Image:clear(rectangle) Image:clear(rectangle, color) If the color is not specified it will be the transparent color of the image. Co-authored-by: David Capello <david@igara.com>
This commit is contained in:
parent
89ced2e557
commit
d4d18c99be
@ -220,13 +220,25 @@ int Image_clear(lua_State* L)
|
||||
auto obj = get_obj<ImageObj>(L, 1);
|
||||
auto img = obj->image(L);
|
||||
doc::color_t color;
|
||||
if (lua_isnone(L, 2))
|
||||
gfx::Rect rc;
|
||||
int i = 2;
|
||||
|
||||
if (auto rcPtr = may_get_obj<gfx::Rect>(L, i)) {
|
||||
rc = *rcPtr;
|
||||
++i;
|
||||
}
|
||||
else {
|
||||
rc = img->bounds(); // Clear the whole image
|
||||
}
|
||||
|
||||
if (lua_isnone(L, i))
|
||||
color = img->maskColor();
|
||||
else if (lua_isinteger(L, 2))
|
||||
color = lua_tointeger(L, 2);
|
||||
else if (lua_isinteger(L, i))
|
||||
color = lua_tointeger(L, i);
|
||||
else
|
||||
color = convert_args_into_pixel_color(L, 2, img->pixelFormat());
|
||||
doc::clear_image(img, color);
|
||||
color = convert_args_into_pixel_color(L, i, img->pixelFormat());
|
||||
|
||||
doc::fill_rect(img, rc, color); // Clips the rectangle to the image bounds
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -41,6 +41,27 @@ do
|
||||
assert(not a:isEmpty())
|
||||
end
|
||||
|
||||
-- Clear
|
||||
do
|
||||
local spec = ImageSpec{
|
||||
width=2, height=2,
|
||||
colorMode=ColorMode.INDEXED,
|
||||
transparentColor=1 }
|
||||
|
||||
local img = Image(spec)
|
||||
img:clear()
|
||||
expect_img(img, { 1, 1,
|
||||
1, 1 })
|
||||
|
||||
img:clear(img.bounds)
|
||||
expect_img(img, { 1, 1,
|
||||
1, 1 })
|
||||
|
||||
img:clear(Rectangle(1, 0, 1, 2), 2)
|
||||
expect_img(img, { 1, 2,
|
||||
1, 2 })
|
||||
end
|
||||
|
||||
-- Clone
|
||||
do
|
||||
local c = Image(a)
|
||||
|
Loading…
x
Reference in New Issue
Block a user