Blender V4.5
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"
22
26static void shaderfx_panel_id(void *fx_v, char *r_idname)
27{
28 ShaderFxData *fx = (ShaderFxData *)fx_v;
30}
31
33{
34 ARegion *region = CTX_wm_region(C);
36 ListBase *shaderfx = &ob->shader_fx;
37
38 const bool panels_match = UI_panel_list_matches_data(region, shaderfx, shaderfx_panel_id);
39
40 if (!panels_match) {
42 LISTBASE_FOREACH (ShaderFxData *, fx, shaderfx) {
43 char panel_idname[MAX_NAME];
44 shaderfx_panel_id(fx, panel_idname);
45
46 /* Create custom data RNA pointer. */
47 PointerRNA *fx_ptr = MEM_new<PointerRNA>(__func__);
48 *fx_ptr = RNA_pointer_create_discrete(&ob->id, &RNA_ShaderFx, fx);
49
50 UI_panel_add_instanced(C, region, &region->panels, panel_idname, fx_ptr);
51 }
52 }
53 else {
54 /* Assuming there's only one group of instanced panels, update the custom data pointers. */
55 Panel *panel = static_cast<Panel *>(region->panels.first);
56 LISTBASE_FOREACH (ShaderFxData *, fx, shaderfx) {
58 if (fxi->panel_register == nullptr) {
59 continue;
60 }
61
62 /* Move to the next instanced panel corresponding to the next modifier. */
63 while ((panel->type == nullptr) || !(panel->type->flag & PANEL_TYPE_INSTANCED)) {
64 panel = panel->next;
65 BLI_assert(panel !=
66 nullptr); /* There shouldn't be fewer panels than modifiers with UIs. */
67 }
68
69 PointerRNA *fx_ptr = MEM_new<PointerRNA>(__func__);
70 *fx_ptr = RNA_pointer_create_discrete(&ob->id, &RNA_ShaderFx, fx);
71 UI_panel_custom_data_set(panel, fx_ptr);
72
73 panel = panel->next;
74 }
75 }
76}
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 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
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)