Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans Goudey <h.goudey@me.com>2020-09-02 22:13:26 +0300
committerHans Goudey <h.goudey@me.com>2020-09-02 22:13:26 +0300
commitba4a2a4c8b827201b18e97d9dd025ef93a4db754 (patch)
treea71d6b72aaf0616ebda671bf4b011880b49bb280 /source/blender/editors/interface/interface_templates.c
parentff7d74235023d0c927c0ad3f4d72d1c5dd41b240 (diff)
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
Diffstat (limited to 'source/blender/editors/interface/interface_templates.c')
-rw-r--r--source/blender/editors/interface/interface_templates.c30
1 files changed, 14 insertions, 16 deletions
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)
PointerRNA *md_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata");
RNA_pointer_create(&ob->id, &RNA_GpencilModifier, 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);
@@ -2220,7 +2218,7 @@ void uiTemplateShaderFx(uiLayout *UNUSED(layout), bContext *C)
PointerRNA *fx_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata");
RNA_pointer_create(&ob->id, &RNA_ShaderFx, fx, fx_ptr);
- Panel *new_panel = UI_panel_add_instanced(region, &region->panels, panel_idname, i, fx_ptr);
+ Panel *new_panel = UI_panel_add_instanced(region, &region->panels, panel_idname, fx_ptr);
if (new_panel != NULL) {
UI_panel_set_expand_from_list_data(C, new_panel);