GPv3: Make visibility and lock state inheritable

This adds functions to check if a `LayerGroup` is visible or locked.
Additionally, visibility and the lock state is now inherited.
E.g. `Layer`s that are the children of a hidden `LayerGroup` will also
be hidden. This does not change their stored visibility. It just means
that the function `is_visible()` on the layers will return `false`.
The same applies for locking.
This commit is contained in:
Falk David
2023-06-27 13:05:05 +02:00
parent 258ba398ed
commit 5967cb53e9
2 changed files with 23 additions and 2 deletions

View File

@@ -287,6 +287,9 @@ class LayerGroup : public ::GreasePencilLayerTreeGroup {
return this->base.name;
}
bool is_visible() const;
bool is_locked() const;
/**
* Adds a group at the end of this group.
*/

View File

@@ -490,12 +490,12 @@ Map<int, GreasePencilFrame> &Layer::frames_for_write()
bool Layer::is_visible() const
{
return (this->base.flag & GP_LAYER_TREE_NODE_HIDE) == 0;
return this->parent_group().is_visible() && (this->base.flag & GP_LAYER_TREE_NODE_HIDE) == 0;
}
bool Layer::is_locked() const
{
return (this->base.flag & GP_LAYER_TREE_NODE_LOCKED) != 0;
return this->parent_group().is_locked() || (this->base.flag & GP_LAYER_TREE_NODE_LOCKED) != 0;
}
bool Layer::insert_frame(int frame_number, const GreasePencilFrame &frame)
@@ -616,6 +616,24 @@ LayerGroup::~LayerGroup()
this->runtime = nullptr;
}
bool LayerGroup::is_visible() const
{
if (this->base.parent) {
return this->base.parent->wrap().is_visible() &&
(this->base.flag & GP_LAYER_TREE_NODE_HIDE) == 0;
}
return (this->base.flag & GP_LAYER_TREE_NODE_HIDE) == 0;
}
bool LayerGroup::is_locked() const
{
if (this->base.parent) {
return this->base.parent->wrap().is_locked() ||
(this->base.flag & GP_LAYER_TREE_NODE_LOCKED) != 0;
}
return (this->base.flag & GP_LAYER_TREE_NODE_LOCKED) != 0;
}
LayerGroup &LayerGroup::add_group(LayerGroup *group)
{
BLI_assert(group != nullptr);