Blender
V5.0
source
blender
editors
interface
templates
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
#include "
UI_interface_layout.hh
"
23
27
static
void
shaderfx_panel_id
(
void
*fx_v,
char
*r_idname)
28
{
29
ShaderFxData
*fx = (
ShaderFxData
*)fx_v;
30
BKE_shaderfxType_panel_id
(
ShaderFxType
(fx->
type
), r_idname);
31
}
32
33
void
uiTemplateShaderFx
(
uiLayout
*
/*layout*/
,
bContext
*
C
)
34
{
35
ARegion
*region =
CTX_wm_region
(
C
);
36
Object
*ob =
blender::ed::object::context_active_object
(
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) {
42
UI_panels_free_instanced
(
C
, region);
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, ®ion->
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) {
58
const
ShaderFxTypeInfo
*fxi =
BKE_shaderfx_get_info
(
ShaderFxType
(fx->type));
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
}
CTX_wm_region
ARegion * CTX_wm_region(const bContext *C)
Definition
blenkernel/intern/context.cc:961
BKE_screen.hh
PANEL_TYPE_INSTANCED
@ PANEL_TYPE_INSTANCED
Definition
BKE_screen.hh:394
BKE_shader_fx.h
BKE_shaderfxType_panel_id
void BKE_shaderfxType_panel_id(ShaderFxType type, char *r_idname)
Definition
shader_fx.cc:147
BKE_shaderfx_get_info
const ShaderFxTypeInfo * BKE_shaderfx_get_info(ShaderFxType type)
Definition
shader_fx.cc:131
BLI_assert
#define BLI_assert(a)
Definition
BLI_assert.h:46
BLI_listbase.h
LISTBASE_FOREACH
#define LISTBASE_FOREACH(type, var, list)
Definition
BLI_listbase.h:363
MAX_NAME
#define MAX_NAME
Definition
DNA_defs.h:50
ShaderFxType
ShaderFxType
Definition
DNA_shader_fx_types.h:20
ED_object.hh
RNA_access.hh
C
#define C
Definition
RandGen.cpp:29
UI_interface.hh
UI_panels_free_instanced
void UI_panels_free_instanced(const bContext *C, ARegion *region)
Definition
interface_panel.cc:307
UI_panel_custom_data_set
void UI_panel_custom_data_set(Panel *panel, PointerRNA *custom_data)
Definition
interface_panel.cc:2749
UI_panel_list_matches_data
bool UI_panel_list_matches_data(ARegion *region, ListBase *data, uiListPanelIDFromDataFunc panel_idname_func)
Definition
interface_panel.cc:332
UI_panel_add_instanced
Panel * UI_panel_add_instanced(const bContext *C, ARegion *region, ListBase *panels, const char *panel_idname, PointerRNA *custom_data)
Definition
interface_panel.cc:257
UI_interface_layout.hh
uiTemplateShaderFx
void uiTemplateShaderFx(uiLayout *, bContext *C)
Definition
interface_template_shader_fx.cc:33
shaderfx_panel_id
static void shaderfx_panel_id(void *fx_v, char *r_idname)
Definition
interface_template_shader_fx.cc:27
blender::ed::object::context_active_object
Object * context_active_object(const bContext *C)
Definition
object_edit.cc:152
RNA_pointer_create_discrete
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
Definition
rna_access.cc:194
ARegion
Definition
DNA_screen_types.h:509
ARegion::panels
ListBase panels
Definition
DNA_screen_types.h:545
ListBase
Definition
DNA_listBase.h:32
ListBase::first
void * first
Definition
DNA_listBase.h:33
Object
Definition
DNA_object_types.h:191
Object::shader_fx
ListBase shader_fx
Definition
DNA_object_types.h:239
Object::id
ID id
Definition
DNA_object_types.h:198
PanelType::flag
int flag
Definition
BKE_screen.hh:343
Panel
Definition
DNA_screen_types.h:164
Panel::type
struct PanelType * type
Definition
DNA_screen_types.h:168
Panel::next
struct Panel * next
Definition
DNA_screen_types.h:165
PointerRNA
Definition
RNA_types.hh:50
ShaderFxData
Definition
DNA_shader_fx_types.h:50
ShaderFxData::type
int type
Definition
DNA_shader_fx_types.h:53
ShaderFxTypeInfo
Definition
BKE_shader_fx.h:62
ShaderFxTypeInfo::panel_register
void(* panel_register)(struct ARegionType *region_type)
Definition
BKE_shader_fx.h:137
bContext
Definition
blenkernel/intern/context.cc:63
uiLayout
Definition
UI_interface_layout.hh:102
Generated on
for Blender by
doxygen
1.16.1