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

View File

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

View File

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

View File

@ -67,7 +67,7 @@ do -- Image copying and access
end end
do -- Image copying and access (with .content) 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 beforeSprite = Sprite{ fromFile="sprites/abcd.aseprite" }
local imageBefore = app.image:clone() local imageBefore = app.image:clone()
@ -87,7 +87,7 @@ do -- Image copying and access (with .content)
app.clipboard.content = { app.clipboard.content = {
image = imageBefore, image = imageBefore,
palettte = sprite.palettes[1], palettte = sprite.palettes[1],
mask = sprite.selection, selection = sprite.selection,
tileset = app.layer.tileset tileset = app.layer.tileset
} }
@ -100,5 +100,5 @@ do -- Image copying and access (with .content)
assert(imageBefore:isEqual(c.image)) assert(imageBefore:isEqual(c.image))
expect_eq(sprite.palettes[1]:getColor(1).rgbaPixel, c.palette:getColor(1).rgbaPixel) 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)) 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 end