Blender V5.0
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.h"
12
13#include "BKE_screen.hh"
14#include "BKE_shader_fx.h"
15
16#include "ED_object.hh"
17
18#include "RNA_access.hh"
19#include "RNA_prototypes.hh"
20
21#include "UI_interface.hh"
23
27static void shaderfx_panel_id(void *fx_v, char *r_idname)
28{
29 ShaderFxData *fx = (ShaderFxData *)fx_v;
31}
32
34{
35 ARegion *region = CTX_wm_region(C);
37 ListBase *shaderfx = &ob->shader_fx;
38
39 const bool panels_match = UI_panel_list_matches_data(region, shaderfx, shaderfx_panel_id);
40
41 if (!panels_match) {
43 LISTBASE_FOREACH (ShaderFxData *, fx, shaderfx) {
44 char panel_idname[MAX_NAME];
45 shaderfx_panel_id(fx, panel_idname);
46
47 /* Create custom data RNA pointer. */
48 PointerRNA *fx_ptr = MEM_new<PointerRNA>(__func__);
49 *fx_ptr = RNA_pointer_create_discrete(&ob->id, &RNA_ShaderFx, fx);
50
51 UI_panel_add_instanced(C, region, &region->panels, panel_idname, fx_ptr);
52 }
53 }
54 else {
55 /* Assuming there's only one group of instanced panels, update the custom data pointers. */
56 Panel *panel = static_cast<Panel *>(region->panels.first);
57 LISTBASE_FOREACH (ShaderFxData *, fx, shaderfx) {
59 if (fxi->panel_register == nullptr) {
60 continue;
61 }
62
63 /* Move to the next instanced panel corresponding to the next modifier. */
64 while ((panel->type == nullptr) || !(panel->type->flag & PANEL_TYPE_INSTANCED)) {
65 panel = panel->next;
66 BLI_assert(panel !=
67 nullptr); /* There shouldn't be fewer panels than modifiers with UIs. */
68 }
69
70 PointerRNA *fx_ptr = MEM_new<PointerRNA>(__func__);
71 *fx_ptr = RNA_pointer_create_discrete(&ob->id, &RNA_ShaderFx, fx);
72 UI_panel_custom_data_set(panel, fx_ptr);
73
74 panel = panel->next;
75 }
76 }
77}
ARegion * CTX_wm_region(const bContext *C)
@ PANEL_TYPE_INSTANCED
void BKE_shaderfxType_panel_id(ShaderFxType type, char *r_idname)
Definition shader_fx.cc:147
const ShaderFxTypeInfo * BKE_shaderfx_get_info(ShaderFxType type)
Definition shader_fx.cc:131
#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)
void uiTemplateShaderFx(uiLayout *, bContext *C)
static void shaderfx_panel_id(void *fx_v, char *r_idname)
Object * context_active_object(const bContext *C)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
ListBase panels
void * first
ListBase shader_fx
struct PanelType * type
struct Panel * next
void(* panel_register)(struct ARegionType *region_type)