Blender
V4.5
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
26
static
void
shaderfx_panel_id
(
void
*fx_v,
char
*r_idname)
27
{
28
ShaderFxData
*fx = (
ShaderFxData
*)fx_v;
29
BKE_shaderfxType_panel_id
(
ShaderFxType
(fx->
type
), r_idname);
30
}
31
32
void
uiTemplateShaderFx
(
uiLayout
*
/*layout*/
,
bContext
*
C
)
33
{
34
ARegion
*region =
CTX_wm_region
(
C
);
35
Object
*ob =
blender::ed::object::context_active_object
(
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) {
41
UI_panels_free_instanced
(
C
, region);
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, ®ion->
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) {
57
const
ShaderFxTypeInfo
*fxi =
BKE_shaderfx_get_info
(
ShaderFxType
(fx->type));
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
}
CTX_wm_region
ARegion * CTX_wm_region(const bContext *C)
Definition
blenkernel/intern/context.cc:802
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
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:2626
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
MAX_NAME
#define MAX_NAME
uiTemplateShaderFx
void uiTemplateShaderFx(uiLayout *, bContext *C)
Definition
interface_template_shader_fx.cc:32
shaderfx_panel_id
static void shaderfx_panel_id(void *fx_v, char *r_idname)
Definition
interface_template_shader_fx.cc:26
blender::ed::object::context_active_object
Object * context_active_object(const bContext *C)
Definition
object_edit.cc:148
RNA_pointer_create_discrete
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
Definition
rna_access.cc:186
ARegion
Definition
DNA_screen_types.h:500
ARegion::panels
ListBase panels
Definition
DNA_screen_types.h:536
ListBase
Definition
DNA_listBase.h:32
ListBase::first
void * first
Definition
DNA_listBase.h:33
Object
Definition
DNA_object_types.h:192
Object::shader_fx
ListBase shader_fx
Definition
DNA_object_types.h:245
Object::id
ID id
Definition
DNA_object_types.h:199
PanelType::flag
int flag
Definition
BKE_screen.hh:343
Panel
Definition
DNA_screen_types.h:160
Panel::type
struct PanelType * type
Definition
DNA_screen_types.h:164
Panel::next
struct Panel * next
Definition
DNA_screen_types.h:161
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:61
ShaderFxTypeInfo::panel_register
void(* panel_register)(struct ARegionType *region_type)
Definition
BKE_shader_fx.h:132
bContext
Definition
blenkernel/intern/context.cc:58
uiLayout
Definition
UI_interface_layout.hh:75
Generated on
for Blender by
doxygen
1.15.0