Blender V5.3
interface_template_shader_fx.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 "BLI_listbase.hh"
12
13#include "BKE_screen.hh"
14#include "BKE_shader_fx.hh"
15
16#include "ED_object.hh"
17
18#include "RNA_access.hh"
19#include "RNA_prototypes.hh"
20
21#include "UI_interface.hh"
23
24namespace blender::ui {
25
29static void shaderfx_panel_id(void *fx_v, char *r_idname)
30{
31 ShaderFxData *fx = static_cast<ShaderFxData *>(fx_v);
33}
34
35void template_shader_fx(Layout * /*layout*/, bContext *C)
36{
37 ARegion *region = CTX_wm_region(C);
39 ListBaseT<ShaderFxData> *shaderfx = &ob->shader_fx;
40
41 const bool panels_match = panel_list_matches_data(region, shaderfx, shaderfx_panel_id);
42
43 if (!panels_match) {
44 panels_free_instanced(C, region);
45 for (ShaderFxData &fx : *shaderfx) {
46 char panel_idname[MAX_NAME];
47 shaderfx_panel_id(&fx, panel_idname);
48
49 /* Create custom data RNA pointer. */
50 PointerRNA *fx_ptr = MEM_new<PointerRNA>(__func__);
51 *fx_ptr = RNA_pointer_create_discrete(&ob->id, RNA_ShaderFx, &fx);
52
53 panel_add_instanced(C, region, &region->panels, panel_idname, fx_ptr);
54 }
55 }
56 else {
57 /* Assuming there's only one group of instanced panels, update the custom data pointers. */
58 Panel *panel = region->panels.first();
59 for (ShaderFxData &fx : *shaderfx) {
61 if (fxi->panel_register == nullptr) {
62 continue;
63 }
64
65 /* Move to the next instanced panel corresponding to the next modifier. */
66 while ((panel->type == nullptr) || !(panel->type->flag & PANEL_TYPE_INSTANCED)) {
67 panel = panel->next;
68 BLI_assert(panel !=
69 nullptr); /* There shouldn't be fewer panels than modifiers with UIs. */
70 }
71
72 PointerRNA *fx_ptr = MEM_new<PointerRNA>(__func__);
73 *fx_ptr = RNA_pointer_create_discrete(&ob->id, RNA_ShaderFx, &fx);
74 panel_custom_data_set(panel, fx_ptr);
75
76 panel = panel->next;
77 }
78 }
79}
80
81} // namespace blender::ui
#define MAX_NAME
Definition DNA_defs.h:63
#define C
Definition RandGen.cpp:29
Object * context_active_object(const bContext *C)
void template_shader_fx(Layout *layout, bContext *C)
bool panel_list_matches_data(ARegion *region, ListBase *data, ListPanelIDFromDataFunc panel_idname_func)
void panels_free_instanced(const bContext *C, ARegion *region)
static void shaderfx_panel_id(void *fx_v, char *r_idname)
void panel_custom_data_set(Panel *panel, PointerRNA *custom_data)
Panel * panel_add_instanced(const bContext *C, ARegion *region, ListBaseT< Panel > *panels, const char *panel_idname, PointerRNA *custom_data)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
@ PANEL_TYPE_INSTANCED
ARegion * CTX_wm_region(const bContext *C)
void BKE_shaderfxType_panel_id(ShaderFxType type, char *r_idname)
Definition shader_fx.cc:150
const ShaderFxTypeInfo * BKE_shaderfx_get_info(ShaderFxType type)
Definition shader_fx.cc:134
ListBaseT< Panel > panels
ListBaseT< ShaderFxData > shader_fx
struct PanelType * type
struct Panel * next
void(*) panel_register(ARegionType *region_type)