Don't transform hidden layers (fix #2680)

This commit is contained in:
David Capello 2021-04-08 11:24:55 -03:00
parent 565057cf77
commit f3ab779bfd
8 changed files with 38 additions and 17 deletions

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
@ -96,8 +96,8 @@ void FlipCommand::onExecute(Context* ctx)
cels = get_unlocked_unique_cels(site.sprite(), range);
}
else if (site.cel() &&
site.layer() &&
site.layer()->isEditable()) {
site.layer() &&
site.layer()->canEditPixels()) {
cels.push_back(site.cel());
}

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
@ -217,7 +217,7 @@ void RotateCommand::onExecute(Context* context)
cels = get_unlocked_unique_cels(site.sprite(), range);
else if (site.cel() &&
site.layer() &&
site.layer()->isEditable()) {
site.layer()->canEditPixels()) {
cels.push_back(site.cel());
}

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019 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
@ -263,8 +263,7 @@ void FilterManagerImpl::applyToTarget()
}
else if (m_site.cel() &&
m_site.layer() &&
m_site.layer()->isEditable() &&
!m_site.layer()->isReference()) {
m_site.layer()->canEditPixels()) {
cels.push_back(m_site.cel());
}
break;
@ -272,8 +271,7 @@ void FilterManagerImpl::applyToTarget()
case CelsTarget::All: {
for (Cel* cel : m_site.sprite()->uniqueCels()) {
if (cel->layer()->isEditable() &&
!cel->layer()->isReference())
if (cel->layer()->canEditPixels())
cels.push_back(cel);
}
break;

View File

@ -999,15 +999,17 @@ CelList PixelsMovement::getEditableCels()
// TODO This case is used in paste too, where the cel() can be
// nullptr (e.g. we paste the clipboard image into an empty
// cel).
if (m_site.layer() && m_site.layer()->isEditableHierarchy())
if (m_site.layer() &&
m_site.layer()->canEditPixels()) {
cels.push_back(m_site.cel());
}
return cels;
}
// Current cel (m_site.cel()) can be nullptr when we paste in an
// empty cel (Ctrl+V) and cut (Ctrl+X) the floating pixels.
if (m_site.cel() &&
m_site.cel()->layer()->isEditableHierarchy()) {
m_site.cel()->layer()->canEditPixels()) {
CelList::iterator it;
// If we are in a linked cel, remove the cel that matches the

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
@ -25,6 +25,7 @@ namespace app {
using namespace doc;
// 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,
@ -39,8 +40,9 @@ static CelList get_cels_templ(const Sprite* sprite,
for (Layer* layer : range.selectedLayers()) {
if (!layer ||
!layer->isImage() ||
(onlyUnlockedCel && !layer->isEditableHierarchy()))
(onlyUnlockedCel && !layer->canEditPixels())) {
continue;
}
LayerImage* layerImage = static_cast<LayerImage*>(layer);
for (frame_t frame : range.selectedFrames()) {

View File

@ -1,4 +1,4 @@
Copyright (c) 2018-2020 Igara Studio S.A.
Copyright (c) 2018-2021 Igara Studio S.A.
Copyright (c) 2001-2018 David Capello
Permission is hereby granted, free of charge, to any person obtaining

View File

@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2020-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -177,6 +177,24 @@ bool Layer::isEditableHierarchy() const
return true;
}
// It's like isVisibleHierarchy + isEditableHierarchy. Returns true if
// the whole layer hierarchy is unlocked and visible, so the user can
// edit its pixels without unexpected side-effects (e.g. editing
// hidden layers).
bool Layer::canEditPixels() const
{
const Layer* layer = this;
while (layer) {
if (!layer->isVisible() ||
!layer->isEditable() ||
layer->isReference()) { // Cannot edit pixels from reference layers
return false;
}
layer = layer->parent();
}
return true;
}
bool Layer::hasAncestor(const Layer* ancestor) const
{
Layer* it = parent();

View File

@ -1,5 +1,5 @@
// Aseprite Document Library
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2020-2021 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This file is released under the terms of the MIT license.
@ -89,6 +89,7 @@ namespace doc {
bool isVisibleHierarchy() const;
bool isEditableHierarchy() const;
bool canEditPixels() const;
bool hasAncestor(const Layer* ancestor) const;
void setBackground(bool state) { switchFlags(LayerFlags::Background, state); }