Changeset View
Changeset View
Standalone View
Standalone View
source/blender/editors/interface/interface_templates.c
| Show First 20 Lines • Show All 2,020 Lines • ▼ Show 20 Lines | |||||
| /** | /** | ||||
| * Check if the constraint panels don't match the data and rebuild the panels if so. | * Check if the constraint panels don't match the data and rebuild the panels if so. | ||||
| */ | */ | ||||
| void uiTemplateConstraints(uiLayout *UNUSED(layout), bContext *C, bool use_bone_constraints) | void uiTemplateConstraints(uiLayout *UNUSED(layout), bContext *C, bool use_bone_constraints) | ||||
| { | { | ||||
| ScrArea *sa = CTX_wm_area(C); | ScrArea *sa = CTX_wm_area(C); | ||||
| ARegion *region = CTX_wm_region(C); | ARegion *region = CTX_wm_region(C); | ||||
| Object *ob = ED_object_active_context(C); | |||||
| ListBase *constraints = get_constraints(C, use_bone_constraints); | ListBase *constraints = get_constraints(C, use_bone_constraints); | ||||
| /* Switch between the bone panel ID function and the object panel ID function. */ | /* Switch between the bone panel ID function and the object panel ID function. */ | ||||
| uiListPanelIDFromDataFunc panel_id_func = use_bone_constraints ? bone_constraint_panel_id : | uiListPanelIDFromDataFunc panel_id_func = use_bone_constraints ? bone_constraint_panel_id : | ||||
| object_constraint_panel_id; | object_constraint_panel_id; | ||||
| bool panels_match = UI_panel_list_matches_data(region, constraints, panel_id_func); | bool panels_match = UI_panel_list_matches_data(region, constraints, panel_id_func); | ||||
| if (!panels_match) { | if (!panels_match) { | ||||
| UI_panels_free_instanced(C, region); | UI_panels_free_instanced(C, region); | ||||
| bConstraint *con = (constraints == NULL) ? NULL : constraints->first; | bConstraint *con = (constraints == NULL) ? NULL : constraints->first; | ||||
| for (int i = 0; con; i++, con = con->next) { | for (int i = 0; con; i++, con = con->next) { | ||||
| char panel_idname[MAX_NAME]; | char panel_idname[MAX_NAME]; | ||||
| panel_id_func(con, panel_idname); | panel_id_func(con, panel_idname); | ||||
| /* Create custom data RNA pointer. */ | |||||
| 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( | Panel *new_panel = UI_panel_add_instanced( | ||||
| sa, region, ®ion->panels, panel_idname, i, NULL); | sa, region, ®ion->panels, panel_idname, i, con_ptr); | ||||
| if (new_panel) { | if (new_panel) { | ||||
| /* Set the list panel functionality function pointers since we don't do it with | /* Set the list panel functionality function pointers since we don't do it with python. */ | ||||
| * python. */ | |||||
| new_panel->type->set_list_data_expand_flag = set_constraint_expand_flag; | new_panel->type->set_list_data_expand_flag = set_constraint_expand_flag; | ||||
| new_panel->type->get_list_data_expand_flag = get_constraint_expand_flag; | new_panel->type->get_list_data_expand_flag = get_constraint_expand_flag; | ||||
| new_panel->type->reorder = constraint_reorder; | new_panel->type->reorder = constraint_reorder; | ||||
| UI_panel_set_expand_from_list_data(C, new_panel); | UI_panel_set_expand_from_list_data(C, new_panel); | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| else { | else { | ||||
| /* The expansion might have been changed elsewhere, so we still need to set it. */ | /* The expansion might have been changed elsewhere, so we still need to set it. */ | ||||
| LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { | LISTBASE_FOREACH (Panel *, panel, ®ion->panels) { | ||||
| if ((panel->type != NULL) && (panel->type->flag & PNL_INSTANCED)) { | if ((panel->type != NULL) && (panel->type->flag & PNL_INSTANCED)) { | ||||
| UI_panel_set_expand_from_list_data(C, panel); | UI_panel_set_expand_from_list_data(C, panel); | ||||
| } | } | ||||
| } | } | ||||
| /* Assuming there's only one group of instanced panels, update the custom data pointers. */ | |||||
| Panel *panel = region->panels.first; | |||||
| LISTBASE_FOREACH (bConstraint *, con, constraints) { | |||||
| /* Move to the next instanced panel corresponding to the next modifier. */ | |||||
Severin: *constraint | |||||
| while ((panel->type == NULL) || !(panel->type->flag & PNL_INSTANCED)) { | |||||
| panel = panel->next; | |||||
| BLI_assert(panel != NULL); /* There shouldn't be fewer panels than modifiers with UIs. */ | |||||
| } | |||||
| PointerRNA *con_ptr = MEM_mallocN(sizeof(PointerRNA), "panel customdata"); | |||||
SeverinUnsubmitted Done Inline ActionsWould make it "constraint panel customdata". Severin: Would make it `"constraint panel customdata"`. | |||||
| RNA_pointer_create(&ob->id, &RNA_Constraint, con, con_ptr); | |||||
| UI_panel_custom_data_set(panel, con_ptr); | |||||
| panel = panel->next; | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| #undef CONSTRAINT_TYPE_PANEL_PREFIX | #undef CONSTRAINT_TYPE_PANEL_PREFIX | ||||
| #undef CONSTRAINT_BONE_TYPE_PANEL_PREFIX | #undef CONSTRAINT_BONE_TYPE_PANEL_PREFIX | ||||
| /** \} */ | /** \} */ | ||||
| ▲ Show 20 Lines • Show All 5,304 Lines • Show Last 20 Lines | |||||
*constraint