[Bf-blender-cvs] [ba4a2a4c8b8] master: UI: Use instanced panel custom data instead of list index

Hans Goudey noreply at git.blender.org
Wed Sep 2 21:13:51 CEST 2020


Commit: ba4a2a4c8b827201b18e97d9dd025ef93a4db754
Author: Hans Goudey
Date:   Wed Sep 2 14:13:26 2020 -0500
Branches: master
https://developer.blender.org/rBba4a2a4c8b827201b18e97d9dd025ef93a4db754

UI: Use instanced panel custom data instead of list index

For modifier shortcuts we added a "custom_data" field to panels.
This commit uses the same system for accessing the list data that
corresponds to each panel. This way the context is only used once
and the modifier for each panel can be accessed more easily later.

This ends up being mostly a cleanup commit with a few small changes
in interface_panel.c. The large changes in the UI functions are due
to the fact that the panel custom data is now passed around as a
single pointer instead of being created again for every panel.

The list_index variable in Panel.runtime is removed as it's now
unnecessary.

Differential Revision: https://developer.blender.org/D8559

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

M	release/scripts/startup/bl_ui/properties_constraint.py
M	source/blender/editors/include/UI_interface.h
M	source/blender/editors/interface/interface_panel.c
M	source/blender/editors/interface/interface_templates.c
M	source/blender/editors/screen/area.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.c
M	source/blender/gpencil_modifiers/intern/MOD_gpencil_ui_common.h
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
M	source/blender/makesdna/DNA_screen_types.h
M	source/blender/makesrna/intern/rna_ui.c
M	source/blender/modifiers/intern/MOD_armature.c
M	source/blender/modifiers/intern/MOD_array.c
M	source/blender/modifiers/intern/MOD_bevel.c
M	source/blender/modifiers/intern/MOD_boolean.c
M	source/blender/modifiers/intern/MOD_build.c
M	source/blender/modifiers/intern/MOD_cast.c
M	source/blender/modifiers/intern/MOD_cloth.c
M	source/blender/modifiers/intern/MOD_collision.c
M	source/blender/modifiers/intern/MOD_correctivesmooth.c
M	source/blender/modifiers/intern/MOD_curve.c
M	source/blender/modifiers/intern/MOD_datatransfer.c
M	source/blender/modifiers/intern/MOD_decimate.c
M	source/blender/modifiers/intern/MOD_displace.c
M	source/blender/modifiers/intern/MOD_dynamicpaint.c
M	source/blender/modifiers/intern/MOD_edgesplit.c
M	source/blender/modifiers/intern/MOD_explode.c
M	source/blender/modifiers/intern/MOD_fluid.c
M	source/blender/modifiers/intern/MOD_hook.c
M	source/blender/modifiers/intern/MOD_laplaciandeform.c
M	source/blender/modifiers/intern/MOD_laplaciansmooth.c
M	source/blender/modifiers/intern/MOD_lattice.c
M	source/blender/modifiers/intern/MOD_mask.cc
M	source/blender/modifiers/intern/MOD_meshcache.c
M	source/blender/modifiers/intern/MOD_meshdeform.c
M	source/blender/modifiers/intern/MOD_meshsequencecache.c
M	source/blender/modifiers/intern/MOD_mirror.c
M	source/blender/modifiers/intern/MOD_multires.c
M	source/blender/modifiers/intern/MOD_normal_edit.c
M	source/blender/modifiers/intern/MOD_ocean.c
M	source/blender/modifiers/intern/MOD_particleinstance.c
M	source/blender/modifiers/intern/MOD_particlesystem.c
M	source/blender/modifiers/intern/MOD_remesh.c
M	source/blender/modifiers/intern/MOD_screw.c
M	source/blender/modifiers/intern/MOD_shrinkwrap.c
M	source/blender/modifiers/intern/MOD_simpledeform.c
M	source/blender/modifiers/intern/MOD_simulation.cc
M	source/blender/modifiers/intern/MOD_skin.c
M	source/blender/modifiers/intern/MOD_smooth.c
M	source/blender/modifiers/intern/MOD_softbody.c
M	source/blender/modifiers/intern/MOD_solidify.c
M	source/blender/modifiers/intern/MOD_subsurf.c
M	source/blender/modifiers/intern/MOD_surface.c
M	source/blender/modifiers/intern/MOD_surfacedeform.c
M	source/blender/modifiers/intern/MOD_triangulate.c
M	source/blender/modifiers/intern/MOD_ui_common.c
M	source/blender/modifiers/intern/MOD_ui_common.h
M	source/blender/modifiers/intern/MOD_uvproject.c
M	source/blender/modifiers/intern/MOD_uvwarp.c
M	source/blender/modifiers/intern/MOD_warp.c
M	source/blender/modifiers/intern/MOD_wave.c
M	source/blender/modifiers/intern/MOD_weighted_normal.c
M	source/blender/modifiers/intern/MOD_weightvgedit.c
M	source/blender/modifiers/intern/MOD_weightvgmix.c
M	source/blender/modifiers/intern/MOD_weightvgproximity.c
M	source/blender/modifiers/intern/MOD_weld.c
M	source/blender/modifiers/intern/MOD_wireframe.c
M	source/blender/shader_fx/intern/FX_shader_blur.c
M	source/blender/shader_fx/intern/FX_shader_colorize.c
M	source/blender/shader_fx/intern/FX_shader_flip.c
M	source/blender/shader_fx/intern/FX_shader_glow.c
M	source/blender/shader_fx/intern/FX_shader_pixel.c
M	source/blender/shader_fx/intern/FX_shader_rim.c
M	source/blender/shader_fx/intern/FX_shader_shadow.c
M	source/blender/shader_fx/intern/FX_shader_swirl.c
M	source/blender/shader_fx/intern/FX_shader_wave.c
M	source/blender/shader_fx/intern/FX_ui_common.c
M	source/blender/shader_fx/intern/FX_ui_common.h

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

diff --git a/release/scripts/startup/bl_ui/properties_constraint.py b/release/scripts/startup/bl_ui/properties_constraint.py
index b47d4223372..da35ea680b8 100644
--- a/release/scripts/startup/bl_ui/properties_constraint.py
+++ b/release/scripts/startup/bl_ui/properties_constraint.py
@@ -114,11 +114,7 @@ class ConstraintButtonsPanel(Panel):
                 col.prop_search(con, "subtarget", con.target, "vertex_groups", text="Vertex Group")
 
     def get_constraint(self, context):
-        con = None
-        if context.pose_bone:
-            con = context.pose_bone.constraints[self.list_panel_index]
-        else:
-            con = context.object.constraints[self.list_panel_index]
+        con = self.custom_data
         self.layout.context_pointer_set("constraint", con)
         return con
 
@@ -963,11 +959,7 @@ class ConstraintButtonsSubPanel(Panel):
     bl_options = {'DRAW_BOX'}
 
     def get_constraint(self, context):
-        con = None
-        if context.pose_bone:
-            con = context.pose_bone.constraints[self.list_panel_index]
-        else:
-            con = context.object.constraints[self.list_panel_index]
+        con = self.custom_data
         self.layout.context_pointer_set("constraint", con)
         return con
 
diff --git a/source/blender/editors/include/UI_interface.h b/source/blender/editors/include/UI_interface.h
index 4fc537ca5c2..01e3dd22648 100644
--- a/source/blender/editors/include/UI_interface.h
+++ b/source/blender/editors/include/UI_interface.h
@@ -1698,6 +1698,8 @@ void UI_panel_category_draw_all(struct ARegion *region, const char *category_id_
 
 struct PanelType *UI_paneltype_find(int space_id, int region_id, const char *idname);
 
+/* Panel custom data. */
+struct PointerRNA *UI_panel_custom_data_get(const struct Panel *panel);
 struct PointerRNA *UI_region_panel_custom_data_under_cursor(const struct bContext *C,
                                                             const struct wmEvent *event);
 void UI_panel_custom_data_set(struct Panel *panel, struct PointerRNA *custom_data);
@@ -1706,11 +1708,10 @@ void UI_panel_custom_data_set(struct Panel *panel, struct PointerRNA *custom_dat
 struct Panel *UI_panel_add_instanced(struct ARegion *region,
                                      struct ListBase *panels,
                                      char *panel_idname,
-                                     int list_index,
                                      struct PointerRNA *custom_data);
 void UI_panels_free_instanced(const struct bContext *C, struct ARegion *region);
 
-#define LIST_PANEL_UNIQUE_STR_LEN 4
+#define INSTANCED_PANEL_UNIQUE_STR_LEN 4
 void UI_list_panel_unique_str(struct Panel *panel, char *r_name);
 
 void UI_panel_set_expand_from_list_data(const struct bContext *C, struct Panel *panel);
diff --git a/source/blender/editors/interface/interface_panel.c b/source/blender/editors/interface/interface_panel.c
index bc38e177cea..cf0bb8d4e8c 100644
--- a/source/blender/editors/interface/interface_panel.c
+++ b/source/blender/editors/interface/interface_panel.c
@@ -223,21 +223,19 @@ static bool panels_need_realign(ScrArea *area, ARegion *region, Panel **r_panel_
 static Panel *UI_panel_add_instanced_ex(ARegion *region,
                                         ListBase *panels,
                                         PanelType *panel_type,
-                                        int list_index,
                                         PointerRNA *custom_data)
 {
   Panel *panel = MEM_callocN(sizeof(Panel), "instanced panel");
   panel->type = panel_type;
   BLI_strncpy(panel->panelname, panel_type->idname, sizeof(panel->panelname));
 
-  panel->runtime.list_index = list_index;
   panel->runtime.custom_data_ptr = custom_data;
 
   /* Add the panel's children too. Although they aren't instanced panels, we can still use this
    * function to create them, as UI_panel_begin does other things we don't need to do. */
   LISTBASE_FOREACH (LinkData *, child, &panel_type->children) {
     PanelType *child_type = child->data;
-    UI_panel_add_instanced_ex(region, &panel->children, child_type, list_index, custom_data);
+    UI_panel_add_instanced_ex(region, &panel->children, child_type, custom_data);
   }
 
   /* Make sure the panel is added to the end of the display-order as well. This is needed for
@@ -262,8 +260,10 @@ static Panel *UI_panel_add_instanced_ex(ARegion *region,
  * Called in situations where panels need to be added dynamically rather than having only one panel
  * corresponding to each #PanelType.
  */
-Panel *UI_panel_add_instanced(
-    ARegion *region, ListBase *panels, char *panel_idname, int list_index, PointerRNA *custom_data)
+Panel *UI_panel_add_instanced(ARegion *region,
+                              ListBase *panels,
+                              char *panel_idname,
+                              PointerRNA *custom_data)
 {
   ARegionType *region_type = region->type;
 
@@ -275,7 +275,7 @@ Panel *UI_panel_add_instanced(
     return NULL;
   }
 
-  return UI_panel_add_instanced_ex(region, panels, panel_type, list_index, custom_data);
+  return UI_panel_add_instanced_ex(region, panels, panel_type, custom_data);
 }
 
 /**
@@ -284,7 +284,9 @@ Panel *UI_panel_add_instanced(
  */
 void UI_list_panel_unique_str(Panel *panel, char *r_name)
 {
-  snprintf(r_name, LIST_PANEL_UNIQUE_STR_LEN, "%d", panel->runtime.list_index);
+  /* The panel sortorder will be unique for a specific panel type because the instanced
+   * panel list is regenerated for every change in the data order / length. */
+  snprintf(r_name, INSTANCED_PANEL_UNIQUE_STR_LEN, "%d", panel->sortorder);
 }
 
 /**
@@ -453,11 +455,6 @@ static void reorder_instanced_panel_list(bContext *C, ARegion *region, Panel *dr
   }
   MEM_freeN(panel_sort);
 
-  /* Don't reorder the panel didn't change order after being dropped. */
-  if (move_to_index == drag_panel->runtime.list_index) {
-    return;
-  }
-
   /* Set the bit to tell the interface to instanced the list. */
   drag_panel->flag |= PNL_INSTANCED_LIST_ORDER_CHANGED;
 
@@ -2482,6 +2479,11 @@ void UI_panel_custom_data_set(Panel *panel, PointerRNA *custom_data)
   ui_panel_custom_data_set_recursive(panel, custom_data);
 }
 
+PointerRNA *UI_panel_custom_data_get(const Panel *panel)
+{
+  return panel->runtime.custom_data_ptr;
+}
+
 PointerRNA *UI_region_panel_custom_data_under_cursor(const bContext *C, const wmEvent *event)
 {
   ARegion *region = CTX_wm_region(C);
@@ -2506,9 +2508,7 @@ PointerRNA *UI_region_panel_custom_data_under_cursor(const bContext *C, const wm
     return NULL;
   }
 
-  PointerRNA *customdata = panel->runtime.custom_data_ptr;
-
-  return customdata;
+  return UI_panel_custom_data_get(panel);
 }
 
 /** \} */
diff --git a/source/blender/editors/interface/interface_templates.c b/source/blender/editors/interface/interface_templates.c
index 8962755ea90..c27279ab744 100644
--- a/source/blender/editors/interface/interface_templates.c
+++ b/source/blender/editors/interface/interface_templates.c
@@ -1882,7 +1882,7 @@ void uiTemplateModifiers(uiLayout *UNUSED(layout), bContext *C)
       PointerRNA *md_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata");
       RNA_pointer_create(&ob->id, &RNA_Modifier, md, md_ptr);
 
-      Panel *new_panel = UI_panel_add_instanced(region, &region->panels, panel_idname, i, md_ptr);
+      Panel *new_panel = UI_panel_add_instanced(region, &region->panels, panel_idname, md_ptr);
 
       if (new_panel != NULL) {
         UI_panel_set_expand_from_list_data(C, new_panel);
@@ -1967,10 +1967,11 @@ static ListBase *get_constraints(const bContext *C, bool use_bone_constraints)
  */
 static void constraint_reorder(bContext *C, Panel *panel, int new_index)
 {
-  const bool constraint_from_bone = constraint_panel_is_bone(panel);
-  ListBase *lb = get_constraints(C, constraint_from_bone);
+  bool constraint_from_bone = constraint_panel_is_bone(panel);
+
+  PointerRNA *con_ptr = UI_panel_custom_data_get(panel);
+  bConstraint *con = (bConstraint *)con_ptr->data;
 
-  bConstraint *con = BLI_findlink(lb, panel->runtime.list_index);
   PointerRNA props_ptr;
   wmOperatorType *ot = WM_operatortype_find("CONSTRAINT_OT_move_to_index", false);
   WM_operator_properties_create_ptr(&props_ptr, ot);
@@ -1985,24 +1986,21 @@ static void constraint_reorder(bContext *C, Panel *panel, int new_index)
 /**
  * Get the expand flag from the active constraint to use for the panel.
  */
-static short get_constraint_expand_flag(const bContext *C, Panel *panel)
+static short get_constraint_expand_flag(const bContext *UNUSED(C), Panel *panel)
 {
-  const bool constraint_from_bone = constraint_panel_is_bone(panel);
-  ListBase *lb = get_constraints(C, constraint_from_bone);
+  PointerRNA *con_ptr = UI_panel_custom_data_get(panel);
+  bConstraint *con = (bConstraint *)con_ptr->data;
 
-  bConstraint *con = BLI_findlink(lb, panel->runtime.list_index);
   return con->ui_expand_flag;
 }
 
 /**
  * Save the expand flag for the panel and sub-panels to the constraint.
  */
-static void set_constraint_expand_flag(const bContext *C, Panel *panel, short expand_flag)
+static void set_constraint_expand_flag(const bContext *UNUSED(C), Panel *panel, short expand_flag)
 {
-  const bool constraint_from_bone = constraint_panel_is_bone(panel);
-  ListBase *lb = get_constraints(C, constraint_from_bone);
-
-  bConstraint *con = BLI_findlink(lb, panel->runtime.list_index);
+  PointerRNA *con_ptr = UI_panel_custom_data_get(panel);
+  bConstraint *con = (bConstraint *)con_ptr->data;
   con->ui_expand_flag = expand_flag;
 }
 
@@ -2057,7 +2055,7 @@ void uiTemplateConstraints(uiLayout *UNUSED(layout), bContext *C, bool use_bone_
       PointerRNA *con_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata");
       RNA_pointer_create(&ob->id, &RNA_Constraint, con, con_ptr);
 
-      Panel *new_panel = UI_panel_add_instanced(region, &region->panels, panel_idname, i, con_ptr);
+      Panel *new_panel = UI_panel_add_instanced(region, &region->panels, panel_idname, con_ptr);
 
       if (new_panel) {
         /* Set the list panel functionality function pointers since we don't do it with python. */
@@ -2138,7 +2136,7 @@ void uiTemplateGpencilModifiers(uiLayout *UNUSED(layout), bContext *C

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list