Blender V4.5
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"
23
24static void modifier_panel_id(void *md_link, char *r_name)
25{
26 ModifierData *md = (ModifierData *)md_link;
28}
29
31{
32 ARegion *region = CTX_wm_region(C);
33
35 ListBase *modifiers = &ob->modifiers;
36
37 const bool panels_match = UI_panel_list_matches_data(region, modifiers, modifier_panel_id);
38
39 if (!panels_match) {
41 LISTBASE_FOREACH (ModifierData *, md, modifiers) {
43 if (mti->panel_register == nullptr) {
44 continue;
45 }
46
47 char panel_idname[MAX_NAME];
48 modifier_panel_id(md, panel_idname);
49
50 /* Create custom data RNA pointer. */
51 PointerRNA *md_ptr = MEM_new<PointerRNA>(__func__);
52 *md_ptr = RNA_pointer_create_id_subdata(ob->id, &RNA_Modifier, md);
53
54 UI_panel_add_instanced(C, region, &region->panels, panel_idname, md_ptr);
55 }
56 }
57 else {
58 /* Assuming there's only one group of instanced panels, update the custom data pointers. */
59 Panel *panel = static_cast<Panel *>(region->panels.first);
60 LISTBASE_FOREACH (ModifierData *, md, modifiers) {
62 if (mti->panel_register == nullptr) {
63 continue;
64 }
65
66 /* Move to the next instanced panel corresponding to the next modifier. */
67 while ((panel->type == nullptr) || !(panel->type->flag & PANEL_TYPE_INSTANCED)) {
68 panel = panel->next;
69 BLI_assert(panel !=
70 nullptr); /* There shouldn't be fewer panels than modifiers with UIs. */
71 }
72
73 PointerRNA *md_ptr = MEM_new<PointerRNA>(__func__);
74 *md_ptr = RNA_pointer_create_id_subdata(ob->id, &RNA_Modifier, md);
75 UI_panel_custom_data_set(panel, md_ptr);
76
77 panel = panel->next;
78 }
79 }
80}
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 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)
#define MAX_NAME
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