Blender V5.0
interface_template_modifiers.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2024 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
10
11#include "BKE_context.hh"
12#include "BKE_modifier.hh"
13#include "BKE_screen.hh"
14
15#include "BLI_listbase.h"
16
17#include "ED_object.hh"
18
19#include "RNA_access.hh"
20#include "RNA_prototypes.hh"
21
22#include "UI_interface.hh"
24
25static void modifier_panel_id(void *md_link, char *r_name)
26{
27 ModifierData *md = (ModifierData *)md_link;
29}
30
32{
33 ARegion *region = CTX_wm_region(C);
34
36 ListBase *modifiers = &ob->modifiers;
37
38 const bool panels_match = UI_panel_list_matches_data(region, modifiers, modifier_panel_id);
39
40 if (!panels_match) {
42 LISTBASE_FOREACH (ModifierData *, md, modifiers) {
44 if (mti->panel_register == nullptr) {
45 continue;
46 }
47
48 char panel_idname[MAX_NAME];
49 modifier_panel_id(md, panel_idname);
50
51 /* Create custom data RNA pointer. */
52 PointerRNA *md_ptr = MEM_new<PointerRNA>(__func__);
53 *md_ptr = RNA_pointer_create_id_subdata(ob->id, &RNA_Modifier, md);
54
55 UI_panel_add_instanced(C, region, &region->panels, panel_idname, md_ptr);
56 }
57 }
58 else {
59 /* Assuming there's only one group of instanced panels, update the custom data pointers. */
60 Panel *panel = static_cast<Panel *>(region->panels.first);
61 LISTBASE_FOREACH (ModifierData *, md, modifiers) {
63 if (mti->panel_register == nullptr) {
64 continue;
65 }
66
67 /* Move to the next instanced panel corresponding to the next modifier. */
68 while ((panel->type == nullptr) || !(panel->type->flag & PANEL_TYPE_INSTANCED)) {
69 panel = panel->next;
70 BLI_assert(panel !=
71 nullptr); /* There shouldn't be fewer panels than modifiers with UIs. */
72 }
73
74 PointerRNA *md_ptr = MEM_new<PointerRNA>(__func__);
75 *md_ptr = RNA_pointer_create_id_subdata(ob->id, &RNA_Modifier, md);
76 UI_panel_custom_data_set(panel, md_ptr);
77
78 panel = panel->next;
79 }
80 }
81}
ARegion * CTX_wm_region(const bContext *C)
const ModifierTypeInfo * BKE_modifier_get_info(ModifierType type)
void BKE_modifier_type_panel_id(ModifierType type, char *r_idname)
@ PANEL_TYPE_INSTANCED
#define BLI_assert(a)
Definition BLI_assert.h:46
#define LISTBASE_FOREACH(type, var, list)
#define MAX_NAME
Definition DNA_defs.h:50
#define C
Definition RandGen.cpp:29
void UI_panels_free_instanced(const bContext *C, ARegion *region)
void UI_panel_custom_data_set(Panel *panel, PointerRNA *custom_data)
bool UI_panel_list_matches_data(ARegion *region, ListBase *data, uiListPanelIDFromDataFunc panel_idname_func)
Panel * UI_panel_add_instanced(const bContext *C, ARegion *region, ListBase *panels, const char *panel_idname, PointerRNA *custom_data)
static void modifier_panel_id(void *md_link, char *r_name)
void uiTemplateModifiers(uiLayout *, bContext *C)
Object * context_active_object(const bContext *C)
PointerRNA RNA_pointer_create_id_subdata(ID &id, StructRNA *type, void *data)
ListBase panels
void * first
void(* panel_register)(ARegionType *region_type)
ListBase modifiers
struct PanelType * type
struct Panel * next