[Bf-blender-cvs] [24da365d1c9] modifier-panels-ui: Empty grease pencil modifier panels

Hans Goudey noreply at git.blender.org
Tue Apr 28 21:53:07 CEST 2020


Commit: 24da365d1c9181a1d3743a604ed4163b681f2b0d
Author: Hans Goudey
Date:   Mon Apr 27 18:41:26 2020 -0500
Branches: modifier-panels-ui
https://developer.blender.org/rB24da365d1c9181a1d3743a604ed4163b681f2b0d

Empty grease pencil modifier panels

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

M	release/scripts/startup/bl_ui/properties_data_modifier.py
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/editors/space_buttons/space_buttons.c
M	source/blender/gpencil_modifiers/CMakeLists.txt
M	source/blender/gpencil_modifiers/intern/MOD_gpencilarmature.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilarray.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilbuild.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilcolor.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilhook.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencillattice.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilmirror.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilmultiply.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilnoise.c
M	source/blender/gpencil_modifiers/intern/MOD_gpenciloffset.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilopacity.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilsimplify.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilsmooth.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilsubdiv.c
M	source/blender/gpencil_modifiers/intern/MOD_gpenciltexture.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencilthick.c
M	source/blender/gpencil_modifiers/intern/MOD_gpenciltime.c
M	source/blender/gpencil_modifiers/intern/MOD_gpenciltint.c
A	source/blender/gpencil_modifiers/intern/MOD_ui_common.c
A	source/blender/gpencil_modifiers/intern/MOD_ui_common.h
M	source/blender/makesrna/intern/rna_ui_api.c

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

diff --git a/release/scripts/startup/bl_ui/properties_data_modifier.py b/release/scripts/startup/bl_ui/properties_data_modifier.py
index 50c4059f792..c7788adff3e 100644
--- a/release/scripts/startup/bl_ui/properties_data_modifier.py
+++ b/release/scripts/startup/bl_ui/properties_data_modifier.py
@@ -60,20 +60,9 @@ class DATA_PT_gpencil_modifiers(ModifierButtonsPanel, Panel):
 
     def draw(self, context):
         layout = self.layout
-
-        ob = context.object
-
         layout.operator_menu_enum("object.gpencil_modifier_add", "type")
+        layout.template_grease_pencil_modifiers()
 
-        for md in ob.grease_pencil_modifiers:
-            box = layout.template_greasepencil_modifier(md)
-            if box:
-                # match enum type to our functions, avoids a lookup table.
-                getattr(self, md.type)(box, ob, md)
-
-    # the mt.type enum is (ab)used for a lookup on function names
-    # ...to avoid lengthy if statements
-    # so each type must have a function here.
 
     def gpencil_masking(self, layout, ob, md, use_vertex, use_curve=False):
         gpd = ob.data
diff --git a/source/blender/blenkernel/BKE_gpencil_modifier.h b/source/blender/blenkernel/BKE_gpencil_modifier.h
index b48a6284567..629b3996c2d 100644
--- a/source/blender/blenkernel/BKE_gpencil_modifier.h
+++ b/source/blender/blenkernel/BKE_gpencil_modifier.h
@@ -26,6 +26,7 @@
 extern "C" {
 #endif
 
+struct ARegionType;
 struct Depsgraph;
 struct GpencilModifierData;
 struct ID;
@@ -255,8 +256,13 @@ typedef struct GpencilModifierTypeInfo {
                          struct Object *ob,
                          GreasePencilTexWalkFunc walk,
                          void *userData);
+
+  /* Register the panel types for the modifier's UI. */
+  void (*panelRegister)(struct ARegionType *region_type);
 } GpencilModifierTypeInfo;
 
+#define GPENCIL_MODIFIER_TYPE_PANEL_PREFIX "MOD_PT_gpencil_"
+
 /* Initialize modifier's global data (type info and some common global storages). */
 void BKE_gpencil_modifier_init(void);
 
diff --git a/source/blender/blenkernel/intern/gpencil_modifier.c b/source/blender/blenkernel/intern/gpencil_modifier.c
index b732d9cdd4c..a8e05cfe914 100644
--- a/source/blender/blenkernel/intern/gpencil_modifier.c
+++ b/source/blender/blenkernel/intern/gpencil_modifier.c
@@ -508,7 +508,8 @@ bool BKE_gpencil_modifier_dependsOnTime(GpencilModifierData *md)
 const GpencilModifierTypeInfo *BKE_gpencil_modifierType_getInfo(GpencilModifierType type)
 {
   /* type unsigned, no need to check < 0 */
-  if (type < NUM_GREASEPENCIL_MODIFIER_TYPES && modifier_gpencil_types[type]->name[0] != '\0') {
+  if (type < NUM_GREASEPENCIL_MODIFIER_TYPES && type > 0 &&
+      modifier_gpencil_types[type]->name[0] != '\0') {
     return modifier_gpencil_types[type];
   }
   else {
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 490b65d197e..b03c305bd13 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1994,6 +1994,7 @@ void uiTemplatePathBuilder(uiLayout *layout,
                            struct PointerRNA *root_ptr,
                            const char *text);
 void uiTemplateModifiers(uiLayout *layout, struct bContext *C);
+void uiTemplateGpencilModifiers(uiLayout *layout, struct bContext *C);
 void uiTemplateConstraints(uiLayout *layout, struct bContext *C);
 
 uiLayout *uiTemplateGpencilModifier(uiLayout *layout, struct bContext *C, struct PointerRNA *ptr);
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 3b318c93e19..79345ecda5c 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -1866,6 +1866,57 @@ void uiTemplateModifiers(uiLayout *UNUSED(layout), bContext *C)
 
 /** \} */
 
+/* -------------------------------------------------------------------- */
+/** \name Grease Pencil Modifiers Template
+ *
+ *  Template for building the panel layout for the active object's modifiers.
+ * \{ */
+
+#define ERROR_LIBDATA_MESSAGE TIP_("Can't edit external library data")
+
+static PanelType *panel_type_from_gpencil_modifier(ARegion *region, Link *md_link)
+{
+  ARegionType *region_type = region->type;
+  GpencilModifierData *md = (GpencilModifierData *)md_link;
+  GpencilModifierType type = md->type;
+  const GpencilModifierTypeInfo *mti = BKE_gpencil_modifierType_getInfo(type);
+
+  /* Get the name of the modifier's panel type which was defined when the panel was registered. */
+  char panel_idname[BKE_ST_MAXNAME];
+  strcpy(panel_idname, GPENCIL_MODIFIER_TYPE_PANEL_PREFIX);
+  strcat(panel_idname, mti->name);
+
+  return BLI_findstring(&region_type->paneltypes, panel_idname, offsetof(PanelType, idname));
+}
+
+void uiTemplateGpencilModifiers(uiLayout *UNUSED(layout), bContext *C)
+{
+  ScrArea *sa = CTX_wm_area(C);
+  ARegion *region = CTX_wm_region(C);
+  Object *ob = CTX_data_active_object(C);
+  ListBase *modifiers = &ob->greasepencil_modifiers;
+
+  bool panels_match = UI_panel_list_matches_data(
+      region, modifiers, panel_type_from_gpencil_modifier);
+
+  if (!panels_match) {
+    UI_panels_free_list(C, region);
+    GpencilModifierData *md = modifiers->first;
+    for (int i = 0; md; i++, md = md->next) {
+      const GpencilModifierTypeInfo *mti = BKE_gpencil_modifierType_getInfo(md->type);
+      if (mti->panelRegister) {
+        PanelType *panel_type = panel_type_from_gpencil_modifier(region, (Link *)md);
+        BLI_assert(panel_type != NULL);
+
+        Panel *new_panel = UI_panel_add_list(sa, region, &region->panels, panel_type, i);
+        UI_panel_set_expand_from_list_data(C, new_panel);
+      }
+    }
+  }
+}
+
+/** \} */
+
 /* -------------------------------------------------------------------- */
 /** \name Constraints Template
  *
@@ -1979,149 +2030,6 @@ void uiTemplateConstraints(uiLayout *UNUSED(layout), bContext *C)
 
 /** \} */
 
-/* -------------------------------------------------------------------- */
-/** \name Grease Pencil Modifier Template
- * \{ */
-
-static uiLayout *gpencil_draw_modifier(uiLayout *layout, Object *ob, GpencilModifierData *md)
-{
-  const GpencilModifierTypeInfo *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_GpencilModifier, 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 */
-  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 & eGpencilModifierTypeFlag_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 & eGpencilModifierMode_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);
-
-    sub = uiLayoutRow(row, false);
-    if (mti->flags & eGpencilModifierTypeFlag_NoApply) {
-      uiLayoutSetEnabled(sub, false);
-    }
-    uiItemEnumO(sub,
-                "OBJECT_OT_gpencil_modifier_apply",
-                CTX_IFACE_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Apply"),
-                0,
-                "apply_as",
-                MODIFIER_APPLY_DATA);
-
-    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 *uiTemplateGpencilModifier(uiLayout *layout, bContext *UNUSED(C), PointerRNA *ptr)
-{
-  Object *ob;
-  GpencilModifierData *md, *vmd;
-  int i;
-
-  /* verify we have valid data */
-  if (!RNA_struct_is_a(ptr->type, &RNA_GpencilModifier)) {
-    RNA_warning("Expected modifier on object");
-    return NULL;
-  }
-
-  ob = (Object *)ptr->owner_id;
-  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

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list