Renamed "mask" to "selection" for Lua consistency, fixes

This commit is contained in:
Christian Kaiser 2024-12-06 17:57:02 -03:00 committed by David Capello
parent d7aa121b29
commit 4b2d98506f
4 changed files with 23 additions and 22 deletions

View File

@ -74,7 +74,7 @@ int Clipboard_get_image(lua_State* L)
return 1;
}
if (!result) // TODO: Can we have a false "nil" value without an error?
if (!result)
return luaL_error(L, "failed to get image from clipboard");
push_image(L, image);
@ -102,13 +102,11 @@ int Clipboard_set_image(lua_State* L)
if (!image)
return luaL_error(L, "invalid image");
const bool result = app::Clipboard::instance()->setNativeBitmap(
image,
const bool result = app::Clipboard::instance()->setNativeBitmap(image,
nullptr,
get_current_palette(),
nullptr,
image->maskColor() // TODO: Unsure if this is sufficient.
);
image->maskColor());
if (!result)
return luaL_error(L, "failed to set image to clipboard");
@ -139,7 +137,7 @@ int Clipboard_get_content(lua_State* L)
app::Clipboard::instance()->getNativeBitmap(&image, &mask, &palette, &tileset);
std::string text;
const bool clipResult = clip::get_text(text);
const bool clipResult = !bitmapResult ? clip::get_text(text) : false;
lua_createtable(L, 0, 5);
@ -153,7 +151,7 @@ int Clipboard_get_content(lua_State* L)
push_docobj<Mask>(L, mask);
else
lua_pushnil(L);
lua_setfield(L, -2, "mask");
lua_setfield(L, -2, "selection");
if (bitmapResult && palette)
push_palette(L, palette);
@ -197,11 +195,11 @@ int Clipboard_set_content(lua_State* L)
}
lua_pop(L, 1);
type = lua_getfield(L, 2, "mask");
type = lua_getfield(L, 2, "selection");
if (type != LUA_TNIL) {
mask = get_mask_from_arg(L, -1);
if (!mask)
return luaL_error(L, "invalid mask provided");
return luaL_error(L, "invalid selection provided");
}
lua_pop(L, 1);

View File

@ -153,12 +153,12 @@ bool Clipboard::setNativeBitmap(const doc::Image* image,
switch (image->pixelFormat()) {
case doc::IMAGE_RGB: {
// We use the RGB image data directly
clip::image img(image->getPixelAddress(0, 0), spec);
const clip::image img(image->getPixelAddress(0, 0), spec);
l.set_image(img);
break;
}
case doc::IMAGE_GRAYSCALE: {
clip::image img(spec);
const clip::image img(spec);
const doc::LockImageBits<doc::GrayscaleTraits> bits(image);
auto it = bits.begin();
uint32_t* dst = (uint32_t*)img.data();
@ -175,7 +175,10 @@ bool Clipboard::setNativeBitmap(const doc::Image* image,
break;
}
case doc::IMAGE_INDEXED: {
clip::image img(spec);
if (!palette)
return false;
const clip::image img(spec);
const doc::LockImageBits<doc::IndexedTraits> bits(image);
auto it = bits.begin();
uint32_t* dst = (uint32_t*)img.data();
@ -193,7 +196,7 @@ bool Clipboard::setNativeBitmap(const doc::Image* image,
l.set_image(img);
break;
}
default: TRACE("Unsupported pixelFormat: %d\n", image->pixelFormat()); return false;
default: return false;
}
return true;
@ -231,7 +234,7 @@ bool Clipboard::getNativeBitmap(doc::Image** image,
if (bits & 4)
*palette = doc::read_palette(is);
if (bits & 8)
*tileset = doc::read_tileset(is, nullptr);
*tileset = doc::read_tileset(is, nullptr, false);
if (image)
return true;
}

View File

@ -63,11 +63,11 @@ Tileset* read_tileset(std::istream& is,
const tileset_index ntiles = read32(is);
const Grid grid = read_grid(is);
auto* tileset = new Tileset(sprite, grid, sprite ? ntiles : 0);
if (sprite && setId)
if (setId)
tileset->setId(id);
for (tileset_index ti = 0; ti < ntiles; ++ti) {
const ImageRef image(read_image(is, sprite ? setId : false));
const ImageRef image(read_image(is, setId));
if (sprite)
tileset->set(ti, image);

View File

@ -67,7 +67,7 @@ do -- Image copying and access
end
do -- Image copying and access (with .content)
-- TODO: Using the previous image for now to avoid the IMAGE_TILEMAP format not being supported.
-- Using another image to avoid the IMAGE_TILEMAP format not being supported.
local beforeSprite = Sprite{ fromFile="sprites/abcd.aseprite" }
local imageBefore = app.image:clone()
@ -87,7 +87,7 @@ do -- Image copying and access (with .content)
app.clipboard.content = {
image = imageBefore,
palettte = sprite.palettes[1],
mask = sprite.selection,
selection = sprite.selection,
tileset = app.layer.tileset
}
@ -100,5 +100,5 @@ do -- Image copying and access (with .content)
assert(imageBefore:isEqual(c.image))
expect_eq(sprite.palettes[1]:getColor(1).rgbaPixel, c.palette:getColor(1).rgbaPixel)
assert(app.layer.tileset:tile(0).image:isEqual(c.tileset:tile(0).image))
expect_eq(sprite.selection, c.mask)
expect_eq(sprite.selection, c.selection)
end