Fix regression cannot move/resize reference layers

Regression introduced in f3ab779bfded7710934cff6b9cc6b596756eccbb
This commit is contained in:
David Capello 2021-04-16 10:23:35 -03:00
parent cdf271af74
commit 4fe8c93c5c
9 changed files with 36 additions and 23 deletions

View File

@ -93,7 +93,7 @@ void FlipCommand::onExecute(Context* ctx)
auto range = site.range();
if (range.enabled()) {
cels = get_unlocked_unique_cels(site.sprite(), range);
cels = get_unique_cels_to_edit_pixels(site.sprite(), range);
}
else if (site.cel() &&
site.layer() &&

View File

@ -214,7 +214,7 @@ void RotateCommand::onExecute(Context* context)
auto range = App::instance()->timeline()->range();
if (range.enabled())
cels = get_unlocked_unique_cels(site.sprite(), range);
cels = get_unique_cels_to_edit_pixels(site.sprite(), range);
else if (site.cel() &&
site.layer() &&
site.layer()->canEditPixels()) {

View File

@ -256,10 +256,8 @@ void FilterManagerImpl::applyToTarget()
case CelsTarget::Selected: {
auto range = m_site.range();
if (range.enabled()) {
for (Cel* cel : get_unlocked_unique_cels(m_site.sprite(), range)) {
if (!cel->layer()->isReference())
cels.push_back(cel);
}
for (Cel* cel : get_unique_cels_to_edit_pixels(m_site.sprite(), range))
cels.push_back(cel);
}
else if (m_site.cel() &&
m_site.layer() &&

View File

@ -562,7 +562,7 @@ bool DocView::onClear(Context* ctx)
CelList cels;
if (site.range().enabled()) {
cels = get_unlocked_unique_cels(site.sprite(), site.range());
cels = get_unique_cels_to_edit_pixels(site.sprite(), site.range());
}
else if (site.cel()) {
cels.push_back(site.cel());

View File

@ -70,7 +70,7 @@ MovingCelCollect::MovingCelCollect(Editor* editor, Layer* layer)
}
// Record start positions of all cels in selected range
for (Cel* cel : get_unlocked_unique_cels(editor->sprite(), range2)) {
for (Cel* cel : get_unique_cels_to_move_cel(editor->sprite(), range2)) {
Layer* layer = cel->layer();
ASSERT(layer);

View File

@ -992,8 +992,8 @@ CelList PixelsMovement::getEditableCels()
CelList cels;
if (editMultipleCels()) {
cels = get_unlocked_unique_cels(
m_site.sprite(), m_site.range());
cels = get_unique_cels_to_edit_pixels(m_site.sprite(),
m_site.range());
}
else {
// TODO This case is used in paste too, where the cel() can be

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2019-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -283,7 +283,7 @@ void cut(ContextWriter& writer)
Site site = writer.context()->activeSite();
CelList cels;
if (site.range().enabled()) {
cels = get_unlocked_unique_cels(site.sprite(), site.range());
cels = get_unique_cels_to_edit_pixels(site.sprite(), site.range());
}
else if (site.cel()) {
cels.push_back(site.cel());

View File

@ -24,23 +24,31 @@ namespace app {
using namespace doc;
enum class Target {
kAllCels,
kUniqueCels,
kUniqueCanMoveCels,
kUniqueCanEditPixelsCels,
};
// TODO the DocRange should be "iteratable" to replace this function
// or we can wait to C++20 coroutines and co_yield
static CelList get_cels_templ(const Sprite* sprite,
DocRange range,
const bool onlyUniqueCels,
const bool onlyUnlockedCel)
const Target target)
{
CelList cels;
if (!range.convertToCels(sprite))
return cels;
// Used to visit linked cels just once.
std::set<ObjectId> visited;
for (Layer* layer : range.selectedLayers()) {
if (!layer ||
!layer->isImage() ||
(onlyUnlockedCel && !layer->canEditPixels())) {
(target == Target::kUniqueCanMoveCels && !layer->isEditableHierarchy()) ||
(target == Target::kUniqueCanEditPixelsCels && !layer->canEditPixels())) {
continue;
}
@ -50,9 +58,10 @@ static CelList get_cels_templ(const Sprite* sprite,
if (!cel)
continue;
if (!onlyUniqueCels ||
if (target == Target::kAllCels ||
visited.find(cel->data()->id()) == visited.end()) {
if (onlyUniqueCels)
// Only unique cels (avoid visited cels)
if (target != Target::kAllCels)
visited.insert(cel->data()->id());
cels.push_back(cel);
@ -64,17 +73,22 @@ static CelList get_cels_templ(const Sprite* sprite,
CelList get_cels(const doc::Sprite* sprite, const DocRange& range)
{
return get_cels_templ(sprite, range, false, false);
return get_cels_templ(sprite, range, Target::kAllCels);
}
CelList get_unique_cels(const Sprite* sprite, const DocRange& range)
{
return get_cels_templ(sprite, range, true, false);
return get_cels_templ(sprite, range, Target::kUniqueCels);
}
CelList get_unlocked_unique_cels(const Sprite* sprite, const DocRange& range)
CelList get_unique_cels_to_move_cel(const Sprite* sprite, const DocRange& range)
{
return get_cels_templ(sprite, range, true, true);
return get_cels_templ(sprite, range, Target::kUniqueCanMoveCels);
}
CelList get_unique_cels_to_edit_pixels(const Sprite* sprite, const DocRange& range)
{
return get_cels_templ(sprite, range, Target::kUniqueCanEditPixelsCels);
}
} // namespace app

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2020-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
@ -24,7 +24,8 @@ namespace app {
doc::CelList get_cels(const doc::Sprite* sprite, const DocRange& range);
doc::CelList get_unique_cels(const doc::Sprite* sprite, const DocRange& range);
doc::CelList get_unlocked_unique_cels(const doc::Sprite* sprite, const DocRange& range);
doc::CelList get_unique_cels_to_edit_pixels(const doc::Sprite* sprite, const DocRange& range);
doc::CelList get_unique_cels_to_move_cel(const doc::Sprite* sprite, const DocRange& range);
} // namespace app