From 5967cb53e9cfe91b7b5cf00c8a7a5ebe86ff6995 Mon Sep 17 00:00:00 2001 From: Falk David Date: Tue, 27 Jun 2023 13:05:05 +0200 Subject: [PATCH] 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. --- .../blender/blenkernel/BKE_grease_pencil.hh | 3 +++ .../blenkernel/intern/grease_pencil.cc | 22 +++++++++++++++++-- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/source/blender/blenkernel/BKE_grease_pencil.hh b/source/blender/blenkernel/BKE_grease_pencil.hh index c0a2305ccda..5f9ebd83d71 100644 --- a/source/blender/blenkernel/BKE_grease_pencil.hh +++ b/source/blender/blenkernel/BKE_grease_pencil.hh @@ -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. */ diff --git a/source/blender/blenkernel/intern/grease_pencil.cc b/source/blender/blenkernel/intern/grease_pencil.cc index 2216cf576a7..198e9f79686 100644 --- a/source/blender/blenkernel/intern/grease_pencil.cc +++ b/source/blender/blenkernel/intern/grease_pencil.cc @@ -490,12 +490,12 @@ Map &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);