Keep empty cels#5684
Conversation
aseprite-bot
left a comment
There was a problem hiding this comment.
clang-tidy made some suggestions
| Cel* c = layer->cel(fr); | ||
| if (c && c->dataRef().get() == celData) | ||
| add(new cmd::RemoveCel(c)); | ||
| if (c && c->dataRef().get() == celData) { |
There was a problem hiding this comment.
warning: implicit conversion 'Cel *' -> 'bool' [readability-implicit-bool-conversion]
| if (c && c->dataRef().get() == celData) { | |
| if ((c != nullptr) && c->dataRef().get() == celData) { |
| { | ||
| auto& styles = skinTheme()->styles; | ||
| const ObjectId dataId = (*data->activeIt)->dataId(); | ||
| const bool has_image = ((*data->activeIt)->image() ? true : false); |
There was a problem hiding this comment.
warning: redundant boolean literal in ternary expression result [readability-simplify-boolean-expr]
| const bool has_image = ((*data->activeIt)->image() ? true : false); | |
| const bool has_image = (static_cast<bool>((*data->activeIt)->image())); |
aseprite-bot
left a comment
There was a problem hiding this comment.
clang-tidy made some suggestions
| else { | ||
| ASSERT(site.layer()->isTilemap()); | ||
| if (auto cel = site.cel()) { | ||
| if (auto cel = site.cel(); cel && cel->image()) { |
There was a problem hiding this comment.
warning: 'auto cel' can be declared as 'auto *cel' [readability-qualified-auto]
| if (auto cel = site.cel(); cel && cel->image()) { | |
| if (auto *cel = site.cel(); cel && cel->image()) { |
aseprite-bot
left a comment
There was a problem hiding this comment.
clang-tidy made some suggestions
| // Same size of cel image and background image, we can just | ||
| // replace pixels. | ||
| if (bg_image->width() == cel_image->width() && bg_image->height() == cel_image->height()) { | ||
| if (cel_image && bg_image->size() == cel_image->size()) { |
There was a problem hiding this comment.
warning: implicit conversion 'Image *' -> 'bool' [readability-implicit-bool-conversion]
| if (cel_image && bg_image->size() == cel_image->size()) { | |
| if ((cel_image != nullptr) && bg_image->size() == cel_image->size()) { |
| Cel* cel = layer->cel(frame); | ||
| if (!cel) { | ||
| ImageRef cel_image(Image::create(sprite->pixelFormat(), sprite->width(), sprite->height())); | ||
| ImageRef cel_image(Image::create(sprite->spec())); |
There was a problem hiding this comment.
warning: variable 'cel_image' of type 'ImageRef' (aka 'shared_ptr') can be declared 'const' [misc-const-correctness]
| ImageRef cel_image(Image::create(sprite->spec())); | |
| ImageRef const cel_image(Image::create(sprite->spec())); |
| if (!mask->bitmap()) | ||
| return; | ||
|
|
||
| ImageRef oldImage = cel->imageRef(); |
There was a problem hiding this comment.
warning: variable 'oldImage' of type 'ImageRef' (aka 'shared_ptr') can be declared 'const' [misc-const-correctness]
| ImageRef oldImage = cel->imageRef(); | |
| ImageRef const oldImage = cel->imageRef(); |
|
|
||
| doc::PixelFormat pixelFormat = (cel->layer()->isTilemap() ? sprite->pixelFormat() : | ||
| cel->image()->pixelFormat()); | ||
| doc::PixelFormat pixelFormat = (!cel->image() || cel->layer()->isTilemap() ? |
There was a problem hiding this comment.
warning: variable 'pixelFormat' of type 'doc::PixelFormat' can be declared 'const' [misc-const-correctness]
| doc::PixelFormat pixelFormat = (!cel->image() || cel->layer()->isTilemap() ? | |
| doc::PixelFormat const pixelFormat = (!cel->image() || cel->layer()->isTilemap() ? |
| else if (Cel* c = cel()) { | ||
| if (c->image() && m_layer && m_layer->canEditPixels()) | ||
| return CelList{ c }; | ||
| } |
There was a problem hiding this comment.
warning: do not use 'else' after 'return' [readability-else-after-return]
| } | |
| if (Cel* c = cel()) { | |
| if (c->image() && m_layer && m_layer->canEditPixels()) | |
| return CelList{ c }; | |
| } |
| if (algorithm::shrink_bounds(dstCel->image(), bg, dstLayer, bounds)) { | ||
| ImageRef trimmed(doc::crop_image(dstCel->image(), bounds, bg)); | ||
| if (algorithm::shrink_bounds(dstImage.get(), bg, dstLayer, bounds)) { | ||
| ImageRef trimmed(doc::crop_image(dstImage.get(), bounds, bg)); |
There was a problem hiding this comment.
warning: variable 'trimmed' of type 'ImageRef' (aka 'shared_ptr') can be declared 'const' [misc-const-correctness]
| ImageRef trimmed(doc::crop_image(dstImage.get(), bounds, bg)); | |
| ImageRef const trimmed(doc::crop_image(dstImage.get(), bounds, bg)); |
| ASSERT(!ctx->activeSite().cel() || ctx->activeSite().cel()->image()); | ||
|
|
||
| Cel* cel = ctx->activeSite().cel(); | ||
| const bool isAnImageOnDstCel = (cel && cel->image()); |
There was a problem hiding this comment.
warning: implicit conversion 'Cel *' -> 'bool' [readability-implicit-bool-conversion]
| const bool isAnImageOnDstCel = (cel && cel->image()); | |
| const bool isAnImageOnDstCel = ((cel != nullptr) && cel->image()); |
| ASSERT(!ctx->activeSite().cel() || ctx->activeSite().cel()->image()); | ||
|
|
||
| Cel* cel = ctx->activeSite().cel(); | ||
| const bool isAnImageOnDstCel = (cel && cel->image()); |
There was a problem hiding this comment.
warning: implicit conversion 'Image *' -> 'bool' [readability-implicit-bool-conversion]
| const bool isAnImageOnDstCel = (cel && cel->image()); | |
| const bool isAnImageOnDstCel = (cel && (cel->image() != nullptr)); |
| // Resize the image | ||
| const int w = std::max(1, int(scale.w * image->width())); | ||
| const int h = std::max(1, int(scale.h * image->height())); | ||
| doc::ImageRef newImage( |
There was a problem hiding this comment.
warning: variable 'newImage' of type 'doc::ImageRef' (aka 'shared_ptr') can be declared 'const' [misc-const-correctness]
| doc::ImageRef newImage( | |
| doc::ImageRef const newImage( |
|
@ckaiser would you mind to take a look to this? It's a quite large change, I'd like to add some tests and probably change some APIs as the code looks like a mess for all the given cases. |
ckaiser
left a comment
There was a problem hiding this comment.
Some things I found while testing:
- FlattenLayers crashed when merging down in some cases
- Linked Tilemaps behave differently in the UI than normal layers, if you link two tilemap cels that have no image data, then draw something in one of them and then undo that, the timeline won't go back to showing the "hollow" cel indicator.
- When merging a layer with a cel with user data into a layer with an empty cel, the user data is not preserved regardless of it had an image before, I think this happens without this patch, so it's default behavior but it feels strange to not merge user data.
|
Thanks for testing @ckaiser. As we talked I'll see how we can automate all these kind of tests before merging this PR. |
Should fix all issues from #1303.