[Bf-blender-cvs] [1c7d0b817fd] temp-greasepencil-object-stacksplit: WIP: New template_gpencil_modifier

Antonio Vazquez noreply at git.blender.org
Mon Jun 18 16:37:15 CEST 2018


Commit: 1c7d0b817fd4c076848579fff53819a1a711ff60
Author: Antonio Vazquez
Date:   Mon Jun 18 16:36:00 2018 +0200
Branches: temp-greasepencil-object-stacksplit
https://developer.blender.org/rB1c7d0b817fd4c076848579fff53819a1a711ff60

WIP: New template_gpencil_modifier

This template will be used by grease pencil modifiers.

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

M	source/blender/blenkernel/BKE_gpencil_modifier.h
M	source/blender/blenkernel/intern/gpencil_modifier.c
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_templates.c
M	source/blender/makesrna/intern/rna_ui_api.c

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

diff --git a/source/blender/blenkernel/BKE_gpencil_modifier.h b/source/blender/blenkernel/BKE_gpencil_modifier.h
index 5a948a5ea6b..10d26be655d 100644
--- a/source/blender/blenkernel/BKE_gpencil_modifier.h
+++ b/source/blender/blenkernel/BKE_gpencil_modifier.h
@@ -76,21 +76,11 @@ typedef enum {
 	*/
 	eGreasePencilModifierTypeFlag_RequiresOriginalData = (1 << 5),
 
-	/* For modifiers that support pointcache, so we can check to see if it has files we need to deal with
-	*/
-	eGreasePencilModifierTypeFlag_UsesPointCache = (1 << 6),
-
-	/* For physics modifiers, max one per type */
-	eGreasePencilModifierTypeFlag_Single = (1 << 7),
-
-	/* Some modifier can't be added manually by user */
-	eGreasePencilModifierTypeFlag_NoUserAdd = (1 << 8),
+	/* max one per type */
+	eGreasePencilModifierTypeFlag_Single = (1 << 6),
 
-	/* For modifiers that use CD_PREVIEW_MCOL for preview. */
-	eGreasePencilModifierTypeFlag_UsesPreview = (1 << 9),
-	eGreasePencilModifierTypeFlag_AcceptsLattice = (1 << 10),
 	/* Grease pencil modifiers */
-	eGreasePencilModifierTypeFlag_GpencilMod = (1 << 11),
+	eGreasePencilModifierTypeFlag_GpencilMod = (1 << 7),
 } GreasePencilModifierTypeFlag;
 
 /* IMPORTANT! Keep ObjectWalkFunc and IDWalkFunc signatures compatible. */
@@ -254,5 +244,7 @@ struct GreasePencilModifierData *BKE_gpencil_modifiers_findByType(struct Object
 struct GreasePencilModifierData *BKE_gpencil_modifiers_findByName(struct Object *ob, const char *name);
 void BKE_gpencil_modifier_copyData_generic(const struct GreasePencilModifierData *md_src, struct GreasePencilModifierData *md_dst);
 void BKE_gpencil_modifier_copyData(struct GreasePencilModifierData *md, struct GreasePencilModifierData *target);
+int  BKE_gpencil_modifiers_getCageIndex(struct Scene *scene, struct Object *ob,
+										int *r_lastPossibleCageIndex, bool is_virtual);
 
 #endif /* __BKE_GREASEPENCIL_H__ */
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c
index d9e6ddcd1f5..2b658167ae4 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -602,6 +602,38 @@ GreasePencilModifierData *BKE_gpencil_modifiers_findByName(Object *ob, const cha
 	return BLI_findstring(&(ob->greasepencil_modifiers), name, offsetof(GreasePencilModifierData, name));
 }
 
+/* used for buttons, to find out if the 'draw deformed in editmode' option is
+* there
+*/
+int BKE_gpencil_modifiers_getCageIndex(struct Scene *scene, Object *ob, int *r_lastPossibleCageIndex, bool is_virtual)
+{
+	GreasePencilModifierData *md = ob->greasepencil_modifiers.first;
+	int i, cageIndex = -1;
+
+	if (r_lastPossibleCageIndex) {
+		/* ensure the value is initialized */
+		*r_lastPossibleCageIndex = -1;
+	}
+
+	/* Find the last modifier acting on the cage. */
+	for (i = 0; md; i++, md = md->next) {
+		const GreasePencilModifierTypeInfo *mti = BKE_gpencil_modifierType_getInfo(md->type);
+		bool supports_mapping;
+
+		md->scene = scene;
+
+		if (mti->isDisabled && mti->isDisabled(md, 0)) continue;
+		if (!(mti->flags & eGreasePencilModifierTypeFlag_SupportsEditmode)) continue;
+
+		if (!(md->mode & eGreasePencilModifierMode_Realtime)) continue;
+		if (!(md->mode & eGreasePencilModifierMode_Editmode)) continue;
+
+
+	}
+
+	return cageIndex;
+}
+
 /* helper function for per-instance positioning */
 void BKE_gpencil_instance_modifier_instance_tfm(InstanceGreasePencilModifierData *mmd, const int elem_idx[3], float r_mat[4][4])
 {
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 0b4817c8049..23929ea9029 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1026,6 +1026,7 @@ void uiTemplateSearchPreview(
 void uiTemplatePathBuilder(uiLayout *layout, struct PointerRNA *ptr, const char *propname,
                            struct PointerRNA *root_ptr, const char *text);
 uiLayout *uiTemplateModifier(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr);
+uiLayout *uiTemplateGreasePencilModifier(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr);
 
 void uiTemplateOperatorRedoProperties(uiLayout *layout, const struct bContext *C);
 
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 22487f29977..7445ff421f9 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -39,6 +39,7 @@
 #include "DNA_object_force_types.h"
 #include "DNA_brush_types.h"
 #include "DNA_texture_types.h"
+#include "DNA_gpencil_modifier_types.h"
 
 #include "BLI_utildefines.h"
 #include "BLI_alloca.h"
@@ -57,6 +58,7 @@
 #include "BKE_colortools.h"
 #include "BKE_context.h"
 #include "BKE_global.h"
+#include "BKE_gpencil_modifier.h"
 #include "BKE_idcode.h"
 #include "BKE_idprop.h"
 #include "BKE_layer.h"
@@ -1531,6 +1533,139 @@ uiLayout *uiTemplateModifier(uiLayout *layout, bContext *C, PointerRNA *ptr)
 	return NULL;
 }
 
+static uiLayout *gpencil_draw_modifier(
+	uiLayout *layout, Scene *scene, Object *ob,
+	GreasePencilModifierData *md, int index, int cageIndex, int lastCageIndex)
+{
+	const GreasePencilModifierTypeInfo *mti = BKE_gpencil_modifierType_getInfo(md->type);
+	PointerRNA ptr;
+	uiBlock *block;
+	uiLayout *box, *column, *row, *sub;
+	uiLayout *result = NULL;
+
+	/* create RNA pointer */
+	RNA_pointer_create(&ob->id, &RNA_GreasePencilModifier, md, &ptr);
+
+	column = uiLayoutColumn(layout, true);
+	uiLayoutSetContextPointer(column, "modifier", &ptr);
+
+	/* rounded header ------------------------------------------------------------------- */
+	box = uiLayoutBox(column);
+
+	row = uiLayoutRow(box, false);
+	block = uiLayoutGetBlock(row);
+
+	UI_block_emboss_set(block, UI_EMBOSS_NONE);
+	/* Open/Close .................................  */
+	uiItemR(row, &ptr, "show_expanded", 0, "", ICON_NONE);
+
+	/* modifier-type icon */
+	uiItemL(row, "", RNA_struct_ui_icon(ptr.type));
+	UI_block_emboss_set(block, UI_EMBOSS);
+
+	/* modifier name */
+	md->scene = scene;
+	if (mti->isDisabled && mti->isDisabled(md, 0)) {
+		uiLayoutSetRedAlert(row, true);
+	}
+	uiItemR(row, &ptr, "name", 0, "", ICON_NONE);
+	uiLayoutSetRedAlert(row, false);
+
+	/* mode enabling buttons */
+	UI_block_align_begin(block);
+		uiItemR(row, &ptr, "show_render", 0, "", ICON_NONE);
+		uiItemR(row, &ptr, "show_viewport", 0, "", ICON_NONE);
+
+	if (mti->flags & eGreasePencilModifierTypeFlag_SupportsEditmode) {
+		sub = uiLayoutRow(row, true);
+		uiLayoutSetActive(sub, false);
+		uiItemR(sub, &ptr, "show_in_editmode", 0, "", ICON_NONE);
+	}
+
+	UI_block_align_end(block);
+
+	/* Up/Down + Delete ........................... */
+	UI_block_align_begin(block);
+	uiItemO(row, "", ICON_TRIA_UP, "OBJECT_OT_gpencil_modifier_move_up");
+	uiItemO(row, "", ICON_TRIA_DOWN, "OBJECT_OT_gpencil_modifier_move_down");
+	UI_block_align_end(block);
+
+	UI_block_emboss_set(block, UI_EMBOSS_NONE);
+	uiItemO(row, "", ICON_X, "OBJECT_OT_gpencil_modifier_remove");
+	UI_block_emboss_set(block, UI_EMBOSS);
+
+	/* modifier settings (under the header) --------------------------------------------------- */
+	if (md->mode & eGreasePencilModifierMode_Expanded) {
+		/* apply/convert/copy */
+		box = uiLayoutBox(column);
+		row = uiLayoutRow(box, false);
+
+		/* only here obdata, the rest of modifiers is ob level */
+		UI_block_lock_set(block, BKE_object_obdata_is_libdata(ob), ERROR_LIBDATA_MESSAGE);
+
+		uiLayoutSetOperatorContext(row, WM_OP_INVOKE_DEFAULT);
+		uiItemEnumO(row, "OBJECT_OT_gpencil_modifier_apply", CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Apply"),
+			0, "apply_as", MODIFIER_APPLY_DATA);
+
+		uiItemEnumO(row, "OBJECT_OT_gpencil_modifier_apply",
+			CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Apply as Shape Key"),
+			0, "apply_as", MODIFIER_APPLY_SHAPE);
+
+		UI_block_lock_clear(block);
+		UI_block_lock_set(block, ob && ID_IS_LINKED(ob), ERROR_LIBDATA_MESSAGE);
+
+		uiItemO(row, CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Copy"), ICON_NONE,
+			"OBJECT_OT_gpencil_modifier_copy");
+	
+		/* result is the layout block inside the box, that we return so that modifier settings can be drawn */
+		result = uiLayoutColumn(box, false);
+		block = uiLayoutAbsoluteBlock(box);
+	}
+
+	/* error messages */
+	if (md->error) {
+		box = uiLayoutBox(column);
+		row = uiLayoutRow(box, false);
+		uiItemL(row, md->error, ICON_ERROR);
+	}
+
+	return result;
+}
+
+uiLayout *uiTemplateGreasePencilModifier(uiLayout *layout, bContext *C, PointerRNA *ptr)
+{
+	Scene *scene = CTX_data_scene(C);
+	Object *ob;
+	GreasePencilModifierData *md, *vmd;
+	int i, lastCageIndex, cageIndex;
+
+	/* verify we have valid data */
+	if (!RNA_struct_is_a(ptr->type, &RNA_GreasePencilModifier)) {
+		RNA_warning("Expected modifier on object");
+		return NULL;
+	}
+
+	ob = ptr->id.data;
+	md = ptr->data;
+
+	if (!ob || !(GS(ob->id.name) == ID_OB)) {
+		RNA_warning("Expected modifier on object");
+		return NULL;
+	}
+
+	UI_block_lock_set(uiLayoutGetBlock(layout), (ob && ID_IS_LINKED(ob)), ERROR_LIBDATA_MESSAGE);
+
+	/* find modifier and draw it */
+	cageIndex = BKE_gpencil_modifiers_getCageIndex(scene, ob, &lastCageIndex, 0);
+
+	vmd = ob->greasepencil_modifiers.first;
+	for (i = 0; vmd; i++, vmd = vmd->next) {
+		if (md == vmd)
+			return gpencil_draw_modifier(layout, scene, ob, md, i, cageIndex, lastCageIndex);
+	}
+
+	return NULL;
+}
 
 /************************ Redo Buttons Template *************************/
 
diff --git a/source/blender/makesrna/intern/rna_ui_api.c b/source/blender/makesrna/intern/rna_ui_api.c
index 9377ef8a925..e7aceeaf940 100644
--- a/source/blender/makesrna/intern/rna_ui_api.c
+++ b/source/blender/makesrna/intern/rna_ui_api.c
@@ -837,6 +837,14 @@ void RNA_api_ui_layout(StructRNA *srna)
 	parm = RNA_def_pointer(func, "layout", "UILayout", "", "Sub-layout to put items in");
 	RNA_def_function_return(func, parm);
 
+	func = RNA_def_function(srna, "template_greasepencil_modifier", "uiTemplateGreasePencilModifier");
+	RNA_def_function_flag(func, FUNC_USE_CONTEXT);
+	RNA_def_function_ui_description(func, "Generates the UI layo

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list