[Bf-blender-cvs] [9106d88] soc-2016-layer_manager: Add initial API and structs for generic layer system

Julian Eisel noreply at git.blender.org
Mon May 23 18:14:12 CEST 2016


Commit: 9106d88d2679b8f3b45d3d1f2479d3ec30389fbc
Author: Julian Eisel
Date:   Mon May 23 18:11:34 2016 +0200
Branches: soc-2016-layer_manager
https://developer.blender.org/rB9106d88d2679b8f3b45d3d1f2479d3ec30389fbc

Add initial API and structs for generic layer system

This is a generic system that should work pretty well for us. The design might change later, this is kinda for experimenting.

Adds files blenkernel/BKE_layer.h and blenkernel/layer.c

===================================================================

A	source/blender/blenkernel/BKE_layer.h
M	source/blender/blenkernel/CMakeLists.txt
A	source/blender/blenkernel/intern/layer.c

===================================================================

diff --git a/source/blender/blenkernel/BKE_layer.h b/source/blender/blenkernel/BKE_layer.h
new file mode 100644
index 0000000..7198f66
--- /dev/null
+++ b/source/blender/blenkernel/BKE_layer.h
@@ -0,0 +1,73 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file BKE_layer.h
+ *  \ingroup bke
+ */
+
+#ifndef __BKE_LAYER_H__
+#define __BKE_LAYER_H__
+
+struct LayerTree;
+struct LayerTreeItem;
+
+
+/* -------------------------------------------------------------------- */
+/* Layer Tree */
+
+/**
+ * LayerTree.type
+ * Defines the type used for the layer tree.
+ */
+typedef enum eLayerTree_Type {
+	LAYER_TREETYPE_OBJECT,
+//	LAYER_TREETYPE_GPENCIL,
+//	LAYER_TREETYPE_ARMATURE,
+//	...
+} eLayerTree_Type;
+
+struct LayerTree *BKE_layertree_new(const eLayerTree_Type type);
+void BKE_layertree_delete(struct LayerTree *ltree);
+
+/* -------------------------------------------------------------------- */
+/* Layer Tree Item */
+
+typedef short (*LayerItemPollFunc)(const struct bContext *, struct LayerTreeItem *);
+typedef void  (*LayerItemDrawFunc)(struct LayerTreeItem *);
+typedef void  (*LayerItemDrawSettingsFunc)(struct LayerTreeItem *);
+
+typedef enum eLayerTreeItem_Type {
+	LAYER_ITEMTYPE_LAYER,
+	LAYER_ITEMTYPE_GROUP, /* layer group */
+	LAYER_ITEMTYPE_COMP,  /* compositing layer (wireframes, SSAO, blending type, etc) */
+} eLayerTreeItem_Type;
+
+struct LayerTreeItem *BKE_layeritem_add(
+        struct LayerTree *tree, struct LayerTreeItem *parent, const eLayerTreeItem_Type type,
+        const LayerItemPollFunc poll, LayerItemDrawFunc draw, LayerItemDrawSettingsFunc draw_settings);
+void BKE_layeritem_remove(struct LayerTree *tree, struct LayerTreeItem *litem);
+
+#endif  /* __BKE_LAYER_H__ */
+
diff --git a/source/blender/blenkernel/CMakeLists.txt b/source/blender/blenkernel/CMakeLists.txt
index afab0cc..dc86098 100644
--- a/source/blender/blenkernel/CMakeLists.txt
+++ b/source/blender/blenkernel/CMakeLists.txt
@@ -529,4 +529,11 @@ if(WITH_LEGACY_DEPSGRAPH)
 	add_definitions(-DWITH_LEGACY_DEPSGRAPH)
 endif()
 
+if (WITH_ADVANCED_LAYERS)
+	list (APPEND SRC
+		intern/layer.c
+		BKE_layer.h
+	)
+endif()
+
 blender_add_lib(bf_blenkernel "${SRC}" "${INC}" "${INC_SYS}")
diff --git a/source/blender/blenkernel/intern/layer.c b/source/blender/blenkernel/intern/layer.c
new file mode 100644
index 0000000..642a148
--- /dev/null
+++ b/source/blender/blenkernel/intern/layer.c
@@ -0,0 +1,152 @@
+/*
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * The Original Code is Copyright (C) 2016 Blender Foundation.
+ * All rights reserved.
+ *
+ * Contributor(s): none yet.
+ *
+ * ***** END GPL LICENSE BLOCK *****
+ */
+
+/** \file blender/blenkernel/intern/layer.c
+ *  \ingroup bke
+ *
+ * \brief Functions for a generic layer managment system.
+ *
+ * TODO sorting, renaming, drawing
+ */
+
+#include "BKE_context.h"
+#include "BKE_layer.h" /* own include */
+
+#include "BLI_listbase.h"
+
+#include "DNA_defs.h"
+
+#include "MEM_guardedalloc.h"
+
+
+#define MAX_LAYER_FILTER_STR 64
+
+typedef struct LayerTree {
+	eLayerTree_Type type;
+
+	ListBase items; /* LayerTreeItem - TODO check if worth using array instead */
+
+	/* filtering */
+	short filterflag;
+	char filter_str[MAX_LAYER_FILTER_STR];
+} LayerTree;
+
+/**
+ * \brief An item of the layer tree.
+ * Used as a base struct for the individual layer tree item types (layer, layer group, compositing layer, etc).
+ */
+typedef struct LayerTreeItem {
+	struct LayerTreeItem *next, *prev;
+
+	eLayerTreeItem_Type type;
+	char name[MAX_NAME]; /* name displayed in GUI */
+
+	LayerTree *tree; /* pointer back to layer tree - TODO check if needed */
+	struct LayerTreeItem *parent; /* the group this item belongs to */
+
+	/* item is grayed out if this check fails */
+	LayerItemPollFunc poll;
+	/* drawing of the item in the list */
+	LayerItemDrawFunc draw;
+	/* drawing of the expanded layer settings (gear wheel icon) */
+	LayerItemDrawSettingsFunc draw_settings;
+} LayerTreeItem;
+
+
+/* -------------------------------------------------------------------- */
+/** \name Layer Tree
+ *
+ * A layer tree is the container for the tree/list of layers and layer groups that is displayed in the GUI later.
+ *
+ * \{ */
+
+LayerTree *BKE_layertree_new(const eLayerTree_Type type)
+{
+	LayerTree *ltree = MEM_callocN(sizeof(LayerTree), __func__);
+	ltree->type = type;
+	return ltree;
+}
+
+void BKE_layertree_delete(LayerTree *ltree)
+{
+	for (LayerTreeItem *litem = ltree->items.first, *next_litem; litem; litem = next_litem) {
+		next_litem = litem->next;
+		BKE_layeritem_remove(ltree, litem);
+	}
+	BLI_assert(BLI_listbase_is_empty(&ltree->items));
+
+	MEM_freeN(ltree);
+}
+
+/** \} */ /* Layer Tree */
+
+
+/* -------------------------------------------------------------------- */
+/** \name Layer Tree Item
+ *
+ * An item of the layer tree (layer, layer group, compositing layer, etc).
+ * Although the technical precise term is "layer tree item", we usually just call it "layer item".
+ *
+ * \{ */
+
+/**
+ * Allocate a new layer item of \a type and add it to the layer tree \a tree. Sorting happens later.
+ *
+ * \param parent: The parent layer group of the new item. NULL for ungrouped items
+ * \return The newly created layer item.
+ */
+LayerTreeItem *BKE_layeritem_add(
+        LayerTree *tree, LayerTreeItem *parent, const eLayerTreeItem_Type type,
+        const LayerItemPollFunc poll, LayerItemDrawFunc draw, LayerItemDrawSettingsFunc draw_settings)
+{
+	LayerTreeItem *litem = MEM_callocN(sizeof(LayerTreeItem), __func__);
+
+	BLI_assert(!parent || ELEM(parent->type, LAYER_ITEMTYPE_GROUP));
+	BLI_assert(!parent || parent->tree == tree);
+
+	litem->type = type;
+	litem->parent = parent;
+	litem->tree = tree;
+
+	/* callbacks */
+	litem->poll = poll;
+	litem->draw = draw;
+	litem->draw_settings = draw_settings;
+
+	BLI_addhead(&tree->items, litem);
+
+	return litem;
+}
+
+/**
+ * Free and unlink \a litem from \a tree.
+ */
+void BKE_layeritem_remove(LayerTree *tree, LayerTreeItem *litem)
+{
+	BLI_remlink(&tree->items, litem);
+	MEM_freeN(litem);
+}
+
+/** \} */ /* Layer Tree Item */




More information about the Bf-blender-cvs mailing list