Blender V5.0
rna_ui.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
8
9#include <cstdlib>
10
11#include "DNA_screen_types.h"
12
13#include "BLT_translation.hh"
14
15#include "BKE_file_handler.hh"
16#include "BKE_screen.hh"
17
18#include "RNA_define.hh"
19
20#include "RNA_enum_types.hh"
21#include "rna_internal.hh"
22
23#include "UI_interface.hh"
25
26#include "WM_toolsystem.hh"
27#include "WM_types.hh"
28
29/* see WM_types.hh */
31
32/* clang-format off */
34 {int(wmOpCallContext::InvokeDefault), "INVOKE_DEFAULT", 0, "Invoke Default", ""},
35 {int(wmOpCallContext::InvokeRegionWin), "INVOKE_REGION_WIN", 0, "Invoke Region Window", ""},
36 {int(wmOpCallContext::InvokeRegionChannels), "INVOKE_REGION_CHANNELS", 0, "Invoke Region Channels", ""},
37 {int(wmOpCallContext::InvokeRegionPreview), "INVOKE_REGION_PREVIEW", 0, "Invoke Region Preview", ""},
38 {int(wmOpCallContext::InvokeArea), "INVOKE_AREA", 0, "Invoke Area", ""},
39 {int(wmOpCallContext::InvokeScreen), "INVOKE_SCREEN", 0, "Invoke Screen", ""},
40 {int(wmOpCallContext::ExecDefault), "EXEC_DEFAULT", 0, "Exec Default", ""},
41 {int(wmOpCallContext::ExecRegionWin), "EXEC_REGION_WIN", 0, "Exec Region Window", ""},
42 {int(wmOpCallContext::ExecRegionChannels), "EXEC_REGION_CHANNELS", 0, "Exec Region Channels", ""},
43 {int(wmOpCallContext::ExecRegionPreview), "EXEC_REGION_PREVIEW", 0, "Exec Region Preview", ""},
44 {int(wmOpCallContext::ExecArea), "EXEC_AREA", 0, "Exec Area", ""},
45 {int(wmOpCallContext::ExecScreen), "EXEC_SCREEN", 0, "Exec Screen", ""},
46 {0, nullptr, 0, nullptr, nullptr},
47};
48/* clang-format on */
49
51 {UILST_LAYOUT_DEFAULT, "DEFAULT", 0, "Default Layout", "Use the default, multi-rows layout"},
52 {UILST_LAYOUT_COMPACT, "COMPACT", 0, "Compact Layout", "Use the compact, single-row layout"},
53 {0, nullptr, 0, nullptr, nullptr},
54};
55
56#ifdef RNA_RUNTIME
57
58# include "MEM_guardedalloc.h"
59
60# include "DNA_space_types.h"
61
62# include "RNA_access.hh"
63
64# include "BLI_dynstr.h"
65
66# include "BKE_context.hh"
67# include "BKE_main.hh"
68# include "BKE_report.hh"
69# include "BKE_screen.hh"
70
71# include "ED_asset_library.hh"
72# include "ED_asset_shelf.hh"
73
74# include "WM_api.hh"
75
76static ARegionType *region_type_find(ReportList *reports, int space_type, int region_type)
77{
78 SpaceType *st;
79 ARegionType *art;
80
81 st = BKE_spacetype_from_id(space_type);
82
83 for (art = (st) ? static_cast<ARegionType *>(st->regiontypes.first) : nullptr; art;
84 art = art->next)
85 {
86 if (art->regionid == region_type) {
87 break;
88 }
89 }
90
91 /* region type not found? abort */
92 if (art == nullptr) {
93 BKE_report(reports, RPT_ERROR, "Region not found in space type");
94 return nullptr;
95 }
96
97 return art;
98}
99
100/* Panel */
101
102static bool panel_poll(const bContext *C, PanelType *pt)
103{
104 extern FunctionRNA rna_Panel_poll_func;
105
106 ParameterList list;
107 FunctionRNA *func;
108 void *ret;
109 bool visible;
110
111 PointerRNA ptr = RNA_pointer_create_discrete(nullptr, pt->rna_ext.srna, nullptr); /* dummy */
112 func = &rna_Panel_poll_func; /* RNA_struct_find_function(&ptr, "poll"); */
113
114 RNA_parameter_list_create(&list, &ptr, func);
115 RNA_parameter_set_lookup(&list, "context", &C);
116 pt->rna_ext.call((bContext *)C, &ptr, func, &list);
117
118 RNA_parameter_get_lookup(&list, "visible", &ret);
119 visible = *(bool *)ret;
120
122
123 return visible;
124}
125
126static void panel_draw(const bContext *C, Panel *panel)
127{
128 extern FunctionRNA rna_Panel_draw_func;
129
130 ParameterList list;
131 FunctionRNA *func;
132
134 &CTX_wm_screen(C)->id, panel->type->rna_ext.srna, panel);
135 func = &rna_Panel_draw_func; /* RNA_struct_find_function(&ptr, "draw"); */
136
137 RNA_parameter_list_create(&list, &ptr, func);
138 RNA_parameter_set_lookup(&list, "context", &C);
139 panel->type->rna_ext.call((bContext *)C, &ptr, func, &list);
140
142}
143
144static void panel_draw_header(const bContext *C, Panel *panel)
145{
146 extern FunctionRNA rna_Panel_draw_header_func;
147
148 ParameterList list;
149 FunctionRNA *func;
150
152 &CTX_wm_screen(C)->id, panel->type->rna_ext.srna, panel);
153 func = &rna_Panel_draw_header_func; /* RNA_struct_find_function(&ptr, "draw_header"); */
154
155 RNA_parameter_list_create(&list, &ptr, func);
156 RNA_parameter_set_lookup(&list, "context", &C);
157 panel->type->rna_ext.call((bContext *)C, &ptr, func, &list);
158
160}
161
162static void panel_draw_header_preset(const bContext *C, Panel *panel)
163{
164 extern FunctionRNA rna_Panel_draw_header_preset_func;
165
166 ParameterList list;
167 FunctionRNA *func;
168
170 &CTX_wm_screen(C)->id, panel->type->rna_ext.srna, panel);
171 func = &rna_Panel_draw_header_preset_func;
172
173 RNA_parameter_list_create(&list, &ptr, func);
174 RNA_parameter_set_lookup(&list, "context", &C);
175 panel->type->rna_ext.call((bContext *)C, &ptr, func, &list);
176
178}
179
180static void panel_type_clear_recursive(Panel *panel, const PanelType *type)
181{
182 if (panel->type == type) {
183 panel->type = nullptr;
184 }
185
186 LISTBASE_FOREACH (Panel *, child_panel, &panel->children) {
187 panel_type_clear_recursive(child_panel, type);
188 }
189}
190
191static bool rna_Panel_unregister(Main *bmain, StructRNA *type)
192{
193 ARegionType *art;
194 PanelType *pt = static_cast<PanelType *>(RNA_struct_blender_type_get(type));
195
196 if (!pt) {
197 return false;
198 }
199 if (!(art = region_type_find(nullptr, pt->space_type, pt->region_type))) {
200 return false;
201 }
202
205
206 if (pt->parent) {
207 LinkData *link = static_cast<LinkData *>(
209 BLI_freelinkN(&pt->parent->children, link);
210 }
211
213
214 LISTBASE_FOREACH (LinkData *, link, &pt->children) {
215 PanelType *child_pt = static_cast<PanelType *>(link->data);
216 child_pt->parent = nullptr;
217 }
218
219 LISTBASE_FOREACH (bScreen *, screen, &bmain->screens) {
220 LISTBASE_FOREACH (ScrArea *, area, &screen->areabase) {
221 LISTBASE_FOREACH (SpaceLink *, sl, &area->spacedata) {
222 ListBase *regionbase = (sl == area->spacedata.first) ? &area->regionbase : &sl->regionbase;
223 LISTBASE_FOREACH (ARegion *, region, regionbase) {
224 LISTBASE_FOREACH (Panel *, panel, &region->panels) {
225 panel_type_clear_recursive(panel, pt);
226 }
227 /* The unregistered panel might have had a template that added instanced panels,
228 * so remove them just in case. They can be re-added on redraw anyway. */
229 UI_panels_free_instanced(nullptr, region);
230 }
231 }
232 }
233 }
234
236 BLI_freelinkN(&art->paneltypes, pt);
237
238 /* update while blender is running */
240 return true;
241}
242
243static StructRNA *rna_Panel_register(Main *bmain,
244 ReportList *reports,
245 void *data,
246 const char *identifier,
247 StructValidateFunc validate,
250{
251 const char *error_prefix = RPT_("Registering panel class:");
252 ARegionType *art;
253 PanelType *pt, *parent = nullptr, dummy_pt = {nullptr};
254 Panel dummy_panel = {nullptr};
255 bool have_function[4];
256 size_t over_alloc = 0; /* Warning, if this becomes a mess, we better do another allocation. */
257 char _panel_descr[RNA_DYN_DESCR_MAX];
258 size_t description_size = 0;
259
260 /* setup dummy panel & panel type to store static properties in */
261 dummy_panel.type = &dummy_pt;
262 _panel_descr[0] = '\0';
263 dummy_panel.type->description = _panel_descr;
264 PointerRNA dummy_panel_ptr = RNA_pointer_create_discrete(nullptr, &RNA_Panel, &dummy_panel);
265
266 /* We have to set default context! Else we get a void string... */
267 STRNCPY(dummy_pt.translation_context, BLT_I18NCONTEXT_DEFAULT_BPYRNA);
268
269 /* validate the python class */
270 if (validate(&dummy_panel_ptr, data, have_function) != 0) {
271 return nullptr;
272 }
273
274 if (strlen(identifier) >= sizeof(dummy_pt.idname)) {
275 BKE_reportf(reports,
276 RPT_ERROR,
277 "%s '%s' is too long, maximum length is %d",
278 error_prefix,
279 identifier,
280 int(sizeof(dummy_pt.idname)));
281 return nullptr;
282 }
283
284 if ((1 << dummy_pt.region_type) & RGN_TYPE_HAS_CATEGORY_MASK) {
285 if (dummy_pt.category[0] == '\0') {
286 /* Use a fallback, otherwise an empty value will draw the panel in every category. */
287 STRNCPY(dummy_pt.category, PNL_CATEGORY_FALLBACK);
288# ifndef NDEBUG
289 printf("%s '%s' misses category, please update the script\n", error_prefix, dummy_pt.idname);
290# endif
291 }
292 }
293 else {
294 if (dummy_pt.category[0] != '\0') {
295 if ((1 << dummy_pt.space_type) & WM_TOOLSYSTEM_SPACE_MASK) {
296 BKE_reportf(reports,
297 RPT_ERROR,
298 "%s '%s' has category '%s'",
299 error_prefix,
300 dummy_pt.idname,
301 dummy_pt.category);
302 return nullptr;
303 }
304 }
305 }
306
307 if (!(art = region_type_find(reports, dummy_pt.space_type, dummy_pt.region_type))) {
308 return nullptr;
309 }
310
311 /* check if we have registered this panel type before, and remove it */
312 for (pt = static_cast<PanelType *>(art->paneltypes.first); pt; pt = pt->next) {
313 if (STREQ(pt->idname, dummy_pt.idname)) {
314 PanelType *pt_next = pt->next;
315 StructRNA *srna = pt->rna_ext.srna;
316 if (srna) {
317 BKE_reportf(reports,
318 RPT_INFO,
319 "%s '%s', bl_idname '%s' has been registered before, unregistering previous",
320 error_prefix,
321 identifier,
322 dummy_pt.idname);
323 if (!rna_Panel_unregister(bmain, srna)) {
324 BKE_reportf(reports,
325 RPT_ERROR,
326 "%s '%s', bl_idname '%s' could not be unregistered",
327 error_prefix,
328 identifier,
329 dummy_pt.idname);
330 }
331 }
332 else {
333 BLI_freelinkN(&art->paneltypes, pt);
334 }
335
336 /* The order of panel types will be altered on re-registration. */
337 if (dummy_pt.parent_id[0] && (parent == nullptr)) {
338 for (pt = pt_next; pt; pt = pt->next) {
339 if (STREQ(pt->idname, dummy_pt.parent_id)) {
340 parent = pt;
341 break;
342 }
343 }
344 }
345
346 break;
347 }
348
349 if (dummy_pt.parent_id[0] && STREQ(pt->idname, dummy_pt.parent_id)) {
350 parent = pt;
351 }
352 }
353
354 if (!RNA_struct_available_or_report(reports, dummy_pt.idname)) {
355 return nullptr;
356 }
357 if (!RNA_struct_bl_idname_ok_or_report(reports, dummy_pt.idname, "_PT_")) {
358 return nullptr;
359 }
360 if (dummy_pt.parent_id[0] && !parent) {
361 BKE_reportf(reports,
362 RPT_ERROR,
363 "%s parent '%s' for '%s' not found",
364 error_prefix,
365 dummy_pt.parent_id,
366 dummy_pt.idname);
367 return nullptr;
368 }
369
370 /* create a new panel type */
371 if (_panel_descr[0]) {
372 description_size = strlen(_panel_descr) + 1;
373 over_alloc += description_size;
374 }
375 pt = static_cast<PanelType *>(
376 MEM_callocN(sizeof(PanelType) + over_alloc, "Python buttons panel"));
377 memcpy(pt, &dummy_pt, sizeof(dummy_pt));
378
379 if (_panel_descr[0]) {
380 char *buf = (char *)(pt + 1);
381 memcpy(buf, _panel_descr, description_size);
382 pt->description = buf;
383 }
384 else {
385 pt->description = nullptr;
386 }
387
388 pt->rna_ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, pt->idname, &RNA_Panel);
390 pt->rna_ext.data = data;
391 pt->rna_ext.call = call;
392 pt->rna_ext.free = free;
395
396 pt->poll = (have_function[0]) ? panel_poll : nullptr;
397 pt->draw = (have_function[1]) ? panel_draw : nullptr;
398 pt->draw_header = (have_function[2]) ? panel_draw_header : nullptr;
399 pt->draw_header_preset = (have_function[3]) ? panel_draw_header_preset : nullptr;
400
401 /* Find position to insert panel based on order. */
402 PanelType *pt_iter = static_cast<PanelType *>(art->paneltypes.last);
403
404 for (; pt_iter; pt_iter = pt_iter->prev) {
405 /* No header has priority. */
406 if ((pt->flag & PANEL_TYPE_NO_HEADER) && !(pt_iter->flag & PANEL_TYPE_NO_HEADER)) {
407 continue;
408 }
409 if (pt_iter->order <= pt->order) {
410 break;
411 }
412 }
413
414 /* Insert into list. */
415 BLI_insertlinkafter(&art->paneltypes, pt_iter, pt);
416
417 if (parent) {
418 pt->parent = parent;
419 LinkData *pt_child_iter = static_cast<LinkData *>(parent->children.last);
420 for (; pt_child_iter; pt_child_iter = pt_child_iter->prev) {
421 PanelType *pt_child = static_cast<PanelType *>(pt_child_iter->data);
422 if (pt_child->order <= pt->order) {
423 break;
424 }
425 }
426 BLI_insertlinkafter(&parent->children, pt_child_iter, BLI_genericNodeN(pt));
427 }
428
429 {
430 const char *owner_id = RNA_struct_state_owner_get();
431 if (owner_id) {
432 STRNCPY(pt->owner_id, owner_id);
433 }
434 }
435
437
438 /* update while blender is running */
440
441 return pt->rna_ext.srna;
442}
443
444static StructRNA *rna_Panel_refine(PointerRNA *ptr)
445{
446 Panel *menu = (Panel *)ptr->data;
447 return (menu->type && menu->type->rna_ext.srna) ? menu->type->rna_ext.srna : &RNA_Panel;
448}
449
450static StructRNA *rna_Panel_custom_data_typef(PointerRNA *ptr)
451{
452 Panel *panel = (Panel *)ptr->data;
453
454 return UI_panel_custom_data_get(panel)->type;
455}
456
457static PointerRNA rna_Panel_custom_data_get(PointerRNA *ptr)
458{
459 Panel *panel = (Panel *)ptr->data;
460
461 /* Because the panel custom data is general we can't refine the pointer type here. */
462 return *UI_panel_custom_data_get(panel);
463}
464
465/* UIList */
466static int rna_UIList_filter_const_FILTER_ITEM_get(PointerRNA * /*ptr*/)
467{
468 return UILST_FLT_ITEM;
469}
470
471static int rna_UIList_item_never_show(PointerRNA * /*ptr*/)
472{
474}
475
476static IDProperty **rna_UIList_idprops(PointerRNA *ptr)
477{
478 uiList *ui_list = (uiList *)ptr->data;
479 return &ui_list->properties;
480}
481
482static void rna_UIList_list_id_get(PointerRNA *ptr, char *value)
483{
484 uiList *ui_list = (uiList *)ptr->data;
485 if (!ui_list->type) {
486 value[0] = '\0';
487 return;
488 }
489
490 strcpy(value, WM_uilisttype_list_id_get(ui_list->type, ui_list));
491}
492
493static int rna_UIList_list_id_length(PointerRNA *ptr)
494{
495 uiList *ui_list = (uiList *)ptr->data;
496 if (!ui_list->type) {
497 return 0;
498 }
499
500 return strlen(WM_uilisttype_list_id_get(ui_list->type, ui_list));
501}
502
503static void uilist_draw_item(uiList *ui_list,
504 const bContext *C,
505 uiLayout *layout,
506 PointerRNA *dataptr,
507 PointerRNA *itemptr,
508 int icon,
509 PointerRNA *active_dataptr,
510 const char *active_propname,
511 int index,
512 int flt_flag)
513{
514 extern FunctionRNA rna_UIList_draw_item_func;
515
516 ParameterList list;
517 FunctionRNA *func;
518
520 &CTX_wm_screen(C)->id, ui_list->type->rna_ext.srna, ui_list);
521 func = &rna_UIList_draw_item_func; /* RNA_struct_find_function(&ul_ptr, "draw_item"); */
522
523 RNA_parameter_list_create(&list, &ul_ptr, func);
524 RNA_parameter_set_lookup(&list, "context", &C);
525 RNA_parameter_set_lookup(&list, "layout", &layout);
526 RNA_parameter_set_lookup(&list, "data", dataptr);
527 RNA_parameter_set_lookup(&list, "item", itemptr);
528 RNA_parameter_set_lookup(&list, "icon", &icon);
529 RNA_parameter_set_lookup(&list, "active_data", active_dataptr);
530 RNA_parameter_set_lookup(&list, "active_property", &active_propname);
531 RNA_parameter_set_lookup(&list, "index", &index);
532 RNA_parameter_set_lookup(&list, "flt_flag", &flt_flag);
533 ui_list->type->rna_ext.call((bContext *)C, &ul_ptr, func, &list);
534
536}
537
538static void uilist_draw_filter(uiList *ui_list, const bContext *C, uiLayout *layout)
539{
540 extern FunctionRNA rna_UIList_draw_filter_func;
541
542 ParameterList list;
543 FunctionRNA *func;
544
546 &CTX_wm_screen(C)->id, ui_list->type->rna_ext.srna, ui_list);
547 func = &rna_UIList_draw_filter_func; /* RNA_struct_find_function(&ul_ptr, "draw_filter"); */
548
549 RNA_parameter_list_create(&list, &ul_ptr, func);
550 RNA_parameter_set_lookup(&list, "context", &C);
551 RNA_parameter_set_lookup(&list, "layout", &layout);
552 ui_list->type->rna_ext.call((bContext *)C, &ul_ptr, func, &list);
553
555}
556
557static void uilist_filter_items(uiList *ui_list,
558 const bContext *C,
559 PointerRNA *dataptr,
560 const char *propname)
561{
562 extern FunctionRNA rna_UIList_filter_items_func;
563
564 ParameterList list;
565 FunctionRNA *func;
566 PropertyRNA *parm;
567
568 uiListDyn *flt_data = ui_list->dyn_data;
569 int *filter_flags, *filter_neworder;
570 void *ret1, *ret2;
571 int ret_len;
572 int len = flt_data->items_len = RNA_collection_length(dataptr, propname);
573
575 &CTX_wm_screen(C)->id, ui_list->type->rna_ext.srna, ui_list);
576 func = &rna_UIList_filter_items_func; /* RNA_struct_find_function(&ul_ptr, "filter_items"); */
577
578 RNA_parameter_list_create(&list, &ul_ptr, func);
579 RNA_parameter_set_lookup(&list, "context", &C);
580 RNA_parameter_set_lookup(&list, "data", dataptr);
581 RNA_parameter_set_lookup(&list, "property", &propname);
582
583 ui_list->type->rna_ext.call((bContext *)C, &ul_ptr, func, &list);
584
585 parm = RNA_function_find_parameter(nullptr, func, "filter_flags");
586 ret_len = RNA_parameter_dynamic_length_get(&list, parm);
587 if (!ELEM(ret_len, len, 0)) {
588 printf("%s: Error, py func returned %d items in %s, %d or none were expected.\n",
589 __func__,
591 "filter_flags",
592 len);
593 /* NOTE: we cannot return here, we would let flt_data in inconsistent state... see #38356. */
594 filter_flags = nullptr;
595 }
596 else {
597 RNA_parameter_get(&list, parm, &ret1);
598 filter_flags = (int *)ret1;
599 }
600
601 parm = RNA_function_find_parameter(nullptr, func, "filter_neworder");
602 ret_len = RNA_parameter_dynamic_length_get(&list, parm);
603 if (!ELEM(ret_len, len, 0)) {
604 printf("%s: Error, py func returned %d items in %s, %d or none were expected.\n",
605 __func__,
607 "filter_neworder",
608 len);
609 /* NOTE: we cannot return here, we would let flt_data in inconsistent state... see #38356. */
610 filter_neworder = nullptr;
611 }
612 else {
613 RNA_parameter_get(&list, parm, &ret2);
614 filter_neworder = (int *)ret2;
615 }
616
617 /* We have to do some final checks and transforms... */
618 {
619 int i;
620 if (filter_flags) {
621 flt_data->items_filter_flags = MEM_malloc_arrayN<int>(size_t(len), __func__);
622 memcpy(flt_data->items_filter_flags, filter_flags, sizeof(int) * len);
623
624 if (filter_neworder) {
625 /* For sake of simplicity, py filtering is expected to filter all items,
626 * but we actually only want reordering data for shown items!
627 */
628 int items_shown, shown_idx;
629 int t_idx, t_ni, prev_ni;
630 flt_data->items_shown = 0;
631 for (i = 0, shown_idx = 0; i < len; i++) {
633 filter_neworder[shown_idx++] = filter_neworder[i];
634 }
635 }
636 items_shown = flt_data->items_shown = shown_idx;
637 flt_data->items_filter_neworder = MEM_malloc_arrayN<int>(size_t(items_shown), __func__);
638 /* And now, bring back new indices into the [0, items_shown[ range!
639 * XXX This is O(N^2). :/
640 */
641 for (shown_idx = 0, prev_ni = -1; shown_idx < items_shown; shown_idx++) {
642 for (i = 0, t_ni = len, t_idx = -1; i < items_shown; i++) {
643 int ni = filter_neworder[i];
644 if (ni > prev_ni && ni < t_ni) {
645 t_idx = i;
646 t_ni = ni;
647 }
648 }
649 if (t_idx >= 0) {
650 prev_ni = t_ni;
651 flt_data->items_filter_neworder[t_idx] = shown_idx;
652 }
653 }
654 }
655 else {
656 /* we still have to set flt_data->items_shown... */
657 flt_data->items_shown = 0;
658 for (i = 0; i < len; i++) {
660 flt_data->items_shown++;
661 }
662 }
663 }
664 }
665 else {
666 flt_data->items_shown = len;
667
668 if (filter_neworder) {
669 flt_data->items_filter_neworder = MEM_malloc_arrayN<int>(size_t(len), __func__);
670 memcpy(flt_data->items_filter_neworder, filter_neworder, sizeof(int) * len);
671 }
672 }
673 }
674
676}
677
678static bool rna_UIList_unregister(Main *bmain, StructRNA *type)
679{
680 uiListType *ult = static_cast<uiListType *>(RNA_struct_blender_type_get(type));
681
682 if (!ult) {
683 return false;
684 }
685
688
689 WM_uilisttype_remove_ptr(bmain, ult);
690
691 /* update while blender is running */
693 return true;
694}
695
696static StructRNA *rna_UIList_register(Main *bmain,
697 ReportList *reports,
698 void *data,
699 const char *identifier,
700 StructValidateFunc validate,
703{
704 const char *error_prefix = "Registering uilist class:";
705 uiListType *ult, dummy_ult = {nullptr};
706 uiList dummy_uilist = {nullptr};
707 bool have_function[3];
708
709 /* setup dummy menu & menu type to store static properties in */
710 dummy_uilist.type = &dummy_ult;
711 PointerRNA dummy_ul_ptr = RNA_pointer_create_discrete(nullptr, &RNA_UIList, &dummy_uilist);
712
713 /* validate the python class */
714 if (validate(&dummy_ul_ptr, data, have_function) != 0) {
715 return nullptr;
716 }
717
718 if (strlen(identifier) >= sizeof(dummy_ult.idname)) {
719 BKE_reportf(reports,
720 RPT_ERROR,
721 "%s '%s' is too long, maximum length is %d",
722 error_prefix,
723 identifier,
724 int(sizeof(dummy_ult.idname)));
725 return nullptr;
726 }
727
728 /* Check if we have registered this UI-list type before, and remove it. */
729 ult = WM_uilisttype_find(dummy_ult.idname, true);
730 if (ult) {
731 BKE_reportf(reports,
732 RPT_INFO,
733 "%s '%s', bl_idname '%s' has been registered before, unregistering previous",
734 error_prefix,
735 identifier,
736 dummy_ult.idname);
737
738 StructRNA *srna = ult->rna_ext.srna;
739 if (!(srna && rna_UIList_unregister(bmain, srna))) {
740 BKE_reportf(reports,
741 RPT_ERROR,
742 "%s '%s', bl_idname '%s' %s",
743 error_prefix,
744 identifier,
745 dummy_ult.idname,
746 srna ? "is built-in" : "could not be unregistered");
747 return nullptr;
748 }
749 }
750 if (!RNA_struct_available_or_report(reports, dummy_ult.idname)) {
751 return nullptr;
752 }
753 if (!RNA_struct_bl_idname_ok_or_report(reports, dummy_ult.idname, "_UL_")) {
754 return nullptr;
755 }
756
757 /* create a new menu type */
758 ult = MEM_callocN<uiListType>("python uilist");
759 memcpy(ult, &dummy_ult, sizeof(dummy_ult));
760
761 ult->rna_ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, ult->idname, &RNA_UIList);
762 ult->rna_ext.data = data;
763 ult->rna_ext.call = call;
764 ult->rna_ext.free = free;
766
767 ult->draw_item = (have_function[0]) ? uilist_draw_item : nullptr;
768 ult->draw_filter = (have_function[1]) ? uilist_draw_filter : nullptr;
769 ult->filter_items = (have_function[2]) ? uilist_filter_items : nullptr;
770
772
773 /* update while blender is running */
775
776 return ult->rna_ext.srna;
777}
778
779static StructRNA *rna_UIList_refine(PointerRNA *ptr)
780{
781 uiList *ui_list = (uiList *)ptr->data;
782 return (ui_list->type && ui_list->type->rna_ext.srna) ? ui_list->type->rna_ext.srna :
783 &RNA_UIList;
784}
785
786/* Header */
787
788static void header_draw(const bContext *C, Header *hdr)
789{
790 extern FunctionRNA rna_Header_draw_func;
791
792 ParameterList list;
793 FunctionRNA *func;
794
796 &CTX_wm_screen(C)->id, hdr->type->rna_ext.srna, hdr);
797 func = &rna_Header_draw_func; /* RNA_struct_find_function(&htr, "draw"); */
798
799 RNA_parameter_list_create(&list, &htr, func);
800 RNA_parameter_set_lookup(&list, "context", &C);
801 hdr->type->rna_ext.call((bContext *)C, &htr, func, &list);
802
804}
805
806static bool rna_Header_unregister(Main * /*bmain*/, StructRNA *type)
807{
808 ARegionType *art;
809 HeaderType *ht = static_cast<HeaderType *>(RNA_struct_blender_type_get(type));
810
811 if (!ht) {
812 return false;
813 }
814 if (!(art = region_type_find(nullptr, ht->space_type, ht->region_type))) {
815 return false;
816 }
817
820
821 BLI_freelinkN(&art->headertypes, ht);
822
823 /* update while blender is running */
825 return true;
826}
827
828static StructRNA *rna_Header_register(Main *bmain,
829 ReportList *reports,
830 void *data,
831 const char *identifier,
832 StructValidateFunc validate,
835{
836 const char *error_prefix = "Registering header class:";
837 ARegionType *art;
838 HeaderType *ht, dummy_ht = {nullptr};
839 Header dummy_header = {nullptr};
840 bool have_function[1];
841
842 /* setup dummy header & header type to store static properties in */
843 dummy_header.type = &dummy_ht;
844 dummy_ht.region_type = RGN_TYPE_HEADER; /* RGN_TYPE_HEADER by default, may be overridden */
845 PointerRNA dummy_header_ptr = RNA_pointer_create_discrete(nullptr, &RNA_Header, &dummy_header);
846
847 /* validate the python class */
848 if (validate(&dummy_header_ptr, data, have_function) != 0) {
849 return nullptr;
850 }
851
852 if (strlen(identifier) >= sizeof(dummy_ht.idname)) {
853 BKE_reportf(reports,
854 RPT_ERROR,
855 "%s '%s' is too long, maximum length is %d",
856 error_prefix,
857 identifier,
858 int(sizeof(dummy_ht.idname)));
859 return nullptr;
860 }
861
862 if (!(art = region_type_find(reports, dummy_ht.space_type, dummy_ht.region_type))) {
863 return nullptr;
864 }
865
866 /* check if we have registered this header type before, and remove it */
867 ht = static_cast<HeaderType *>(
868 BLI_findstring(&art->headertypes, dummy_ht.idname, offsetof(HeaderType, idname)));
869 if (ht) {
870 BKE_reportf(reports,
871 RPT_INFO,
872 "%s '%s', bl_idname '%s' has been registered before, unregistering previous",
873 error_prefix,
874 identifier,
875 dummy_ht.idname);
876
877 StructRNA *srna = ht->rna_ext.srna;
878 if (!(srna && rna_Header_unregister(bmain, srna))) {
879 BKE_reportf(reports,
880 RPT_ERROR,
881 "%s '%s', bl_idname '%s' %s",
882 error_prefix,
883 identifier,
884 dummy_ht.idname,
885 srna ? "is built-in" : "could not be unregistered");
886 return nullptr;
887 }
888 }
889
890 if (!RNA_struct_available_or_report(reports, dummy_ht.idname)) {
891 return nullptr;
892 }
893 if (!RNA_struct_bl_idname_ok_or_report(reports, dummy_ht.idname, "_HT_")) {
894 return nullptr;
895 }
896
897 /* create a new header type */
898 ht = MEM_callocN<HeaderType>(__func__);
899 memcpy(ht, &dummy_ht, sizeof(dummy_ht));
900
901 ht->rna_ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, ht->idname, &RNA_Header);
902 ht->rna_ext.data = data;
903 ht->rna_ext.call = call;
904 ht->rna_ext.free = free;
906
907 ht->draw = (have_function[0]) ? header_draw : nullptr;
908
909 BLI_addtail(&art->headertypes, ht);
910
911 /* update while blender is running */
913
914 return ht->rna_ext.srna;
915}
916
917static StructRNA *rna_Header_refine(PointerRNA *htr)
918{
919 Header *hdr = (Header *)htr->data;
920 return (hdr->type && hdr->type->rna_ext.srna) ? hdr->type->rna_ext.srna : &RNA_Header;
921}
922
923/* Menu */
924
925static bool menu_poll(const bContext *C, MenuType *pt)
926{
927 extern FunctionRNA rna_Menu_poll_func;
928
929 ParameterList list;
930 FunctionRNA *func;
931 void *ret;
932 bool visible;
933
934 PointerRNA ptr = RNA_pointer_create_discrete(nullptr, pt->rna_ext.srna, nullptr); /* dummy */
935 func = &rna_Menu_poll_func; /* RNA_struct_find_function(&ptr, "poll"); */
936
937 RNA_parameter_list_create(&list, &ptr, func);
938 RNA_parameter_set_lookup(&list, "context", &C);
939 pt->rna_ext.call((bContext *)C, &ptr, func, &list);
940
941 RNA_parameter_get_lookup(&list, "visible", &ret);
942 visible = *(bool *)ret;
943
945
946 return visible;
947}
948
949static void menu_draw(const bContext *C, Menu *menu)
950{
951 extern FunctionRNA rna_Menu_draw_func;
952
953 ParameterList list;
954 FunctionRNA *func;
955
957 &CTX_wm_screen(C)->id, menu->type->rna_ext.srna, menu);
958 func = &rna_Menu_draw_func; /* RNA_struct_find_function(&mtr, "draw"); */
959
960 RNA_parameter_list_create(&list, &mtr, func);
961 RNA_parameter_set_lookup(&list, "context", &C);
962 menu->type->rna_ext.call((bContext *)C, &mtr, func, &list);
963
965}
966
967static bool rna_Menu_unregister(Main * /*bmain*/, StructRNA *type)
968{
969 MenuType *mt = static_cast<MenuType *>(RNA_struct_blender_type_get(type));
970
971 if (!mt) {
972 return false;
973 }
974
977
979
980 /* update while blender is running */
982 return true;
983}
984
985static StructRNA *rna_Menu_register(Main *bmain,
986 ReportList *reports,
987 void *data,
988 const char *identifier,
989 StructValidateFunc validate,
992{
993 const char *error_prefix = "Registering menu class:";
994 MenuType *mt, dummy_mt = {nullptr};
995 Menu dummy_menu = {nullptr};
996 bool have_function[2];
997 size_t over_alloc = 0; /* Warning, if this becomes a mess, we better do another allocation. */
998 size_t description_size = 0;
999 char _menu_descr[RNA_DYN_DESCR_MAX];
1000
1001 /* setup dummy menu & menu type to store static properties in */
1002 dummy_menu.type = &dummy_mt;
1003 _menu_descr[0] = '\0';
1004 dummy_menu.type->description = _menu_descr;
1005 PointerRNA dummy_menu_ptr = RNA_pointer_create_discrete(nullptr, &RNA_Menu, &dummy_menu);
1006
1007 /* We have to set default context! Else we get a void string... */
1009
1010 /* validate the python class */
1011 if (validate(&dummy_menu_ptr, data, have_function) != 0) {
1012 return nullptr;
1013 }
1014
1015 if (strlen(identifier) >= sizeof(dummy_mt.idname)) {
1016 BKE_reportf(reports,
1017 RPT_ERROR,
1018 "%s '%s' is too long, maximum length is %d",
1019 error_prefix,
1020 identifier,
1021 int(sizeof(dummy_mt.idname)));
1022 return nullptr;
1023 }
1024
1025 /* check if we have registered this menu type before, and remove it */
1026 mt = WM_menutype_find(dummy_mt.idname, true);
1027 if (mt) {
1028 BKE_reportf(reports,
1029 RPT_INFO,
1030 "%s '%s', bl_idname '%s' has been registered before, unregistering previous",
1031 error_prefix,
1032 identifier,
1033 dummy_mt.idname);
1034
1035 StructRNA *srna = mt->rna_ext.srna;
1036 if (!(srna && rna_Menu_unregister(bmain, srna))) {
1037 BKE_reportf(reports,
1038 RPT_ERROR,
1039 "%s '%s', bl_idname '%s' %s",
1040 error_prefix,
1041 identifier,
1042 dummy_mt.idname,
1043 srna ? "is built-in" : "could not be unregistered");
1044 return nullptr;
1045 }
1046 }
1047 if (!RNA_struct_available_or_report(reports, dummy_mt.idname)) {
1048 return nullptr;
1049 }
1050 if (!RNA_struct_bl_idname_ok_or_report(reports, dummy_mt.idname, "_MT_")) {
1051 return nullptr;
1052 }
1053
1054 /* create a new menu type */
1055 if (_menu_descr[0]) {
1056 description_size = strlen(_menu_descr) + 1;
1057 over_alloc += description_size;
1058 }
1059
1060 mt = static_cast<MenuType *>(MEM_callocN(sizeof(MenuType) + over_alloc, "Python buttons menu"));
1061 memcpy(mt, &dummy_mt, sizeof(dummy_mt));
1062
1063 if (_menu_descr[0]) {
1064 char *buf = (char *)(mt + 1);
1065 memcpy(buf, _menu_descr, description_size);
1066 mt->description = buf;
1067 }
1068 else {
1069 mt->description = nullptr;
1070 }
1071
1072 mt->rna_ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, mt->idname, &RNA_Menu);
1074 mt->rna_ext.data = data;
1075 mt->rna_ext.call = call;
1076 mt->rna_ext.free = free;
1079
1080 mt->poll = (have_function[0]) ? menu_poll : nullptr;
1081 mt->draw = (have_function[1]) ? menu_draw : nullptr;
1082
1083 {
1084 const char *owner_id = RNA_struct_state_owner_get();
1085 if (owner_id) {
1086 STRNCPY(mt->owner_id, owner_id);
1087 }
1088 }
1089
1090 WM_menutype_add(mt);
1091
1092 /* update while blender is running */
1094
1095 return mt->rna_ext.srna;
1096}
1097
1098static StructRNA *rna_Menu_refine(PointerRNA *mtr)
1099{
1100 Menu *menu = (Menu *)mtr->data;
1101 return (menu->type && menu->type->rna_ext.srna) ? menu->type->rna_ext.srna : &RNA_Menu;
1102}
1103
1104/* Asset Shelf */
1105
1106static bool asset_shelf_asset_poll(const AssetShelfType *shelf_type,
1107 const AssetRepresentationHandle *asset)
1108{
1109 extern FunctionRNA rna_AssetShelf_asset_poll_func;
1110
1112 nullptr, shelf_type->rna_ext.srna, nullptr); /* dummy */
1113 FunctionRNA *func = &rna_AssetShelf_asset_poll_func;
1114
1115 ParameterList list;
1116 RNA_parameter_list_create(&list, &ptr, func);
1117 RNA_parameter_set_lookup(&list, "asset", &asset);
1118 shelf_type->rna_ext.call(nullptr, &ptr, func, &list);
1119
1120 void *ret;
1121 RNA_parameter_get_lookup(&list, "visible", &ret);
1122 /* Get the value before freeing. */
1123 const bool is_visible = *(bool *)ret;
1124
1126
1127 return is_visible;
1128}
1129
1130static bool asset_shelf_poll(const bContext *C, const AssetShelfType *shelf_type)
1131{
1132 extern FunctionRNA rna_AssetShelf_poll_func;
1133
1135 nullptr, shelf_type->rna_ext.srna, nullptr); /* dummy */
1136 FunctionRNA *func = &rna_AssetShelf_poll_func; /* RNA_struct_find_function(&ptr, "poll"); */
1137
1138 ParameterList list;
1139 RNA_parameter_list_create(&list, &ptr, func);
1140 RNA_parameter_set_lookup(&list, "context", &C);
1141 shelf_type->rna_ext.call((bContext *)C, &ptr, func, &list);
1142
1143 void *ret;
1144 RNA_parameter_get_lookup(&list, "visible", &ret);
1145 /* Get the value before freeing. */
1146 const bool is_visible = *(bool *)ret;
1147
1149
1150 return is_visible;
1151}
1152
1153static const AssetWeakReference *asset_shelf_get_active_asset(const AssetShelfType *shelf_type)
1154{
1155 extern FunctionRNA rna_AssetShelf_get_active_asset_func;
1156
1158 nullptr, shelf_type->rna_ext.srna, nullptr); /* dummy */
1159
1160 FunctionRNA *func = &rna_AssetShelf_get_active_asset_func;
1161
1162 ParameterList list;
1163 RNA_parameter_list_create(&list, &ptr, func);
1164 shelf_type->rna_ext.call(nullptr, &ptr, func, &list);
1165
1166 void *ret;
1167 RNA_parameter_get_lookup(&list, "asset_reference", &ret);
1168 /* Get the value before freeing. */
1169 AssetWeakReference *active_asset = *(AssetWeakReference **)ret;
1170
1172
1173 return active_asset;
1174}
1175
1176static void asset_shelf_draw_context_menu(const bContext *C,
1177 const AssetShelfType *shelf_type,
1178 const AssetRepresentationHandle *asset,
1179 uiLayout *layout)
1180{
1181 extern FunctionRNA rna_AssetShelf_draw_context_menu_func;
1182
1184 nullptr, shelf_type->rna_ext.srna, nullptr); /* dummy */
1185
1186 FunctionRNA *func = &rna_AssetShelf_draw_context_menu_func;
1187 // RNA_struct_find_function(&ptr, "draw_context_menu");
1188
1189 ParameterList list;
1190 RNA_parameter_list_create(&list, &ptr, func);
1191 RNA_parameter_set_lookup(&list, "context", &C);
1192 RNA_parameter_set_lookup(&list, "asset", &asset);
1193 RNA_parameter_set_lookup(&list, "layout", &layout);
1194 shelf_type->rna_ext.call((bContext *)C, &ptr, func, &list);
1195
1197}
1198
1199static bool rna_AssetShelf_unregister(Main *bmain, StructRNA *type)
1200{
1201 AssetShelfType *shelf_type = static_cast<AssetShelfType *>(RNA_struct_blender_type_get(type));
1202
1203 if (!shelf_type) {
1204 return false;
1205 }
1206
1207 blender::ed::asset::shelf::type_unlink(*bmain, *shelf_type);
1208
1209 RNA_struct_free_extension(type, &shelf_type->rna_ext);
1211
1213
1214 /* update while blender is running */
1216
1217 return true;
1218}
1219
1220static StructRNA *rna_AssetShelf_register(Main *bmain,
1221 ReportList *reports,
1222 void *data,
1223 const char *identifier,
1224 StructValidateFunc validate,
1225 StructCallbackFunc call,
1227{
1228 std::unique_ptr<AssetShelfType> shelf_type = std::make_unique<AssetShelfType>();
1229
1230 /* setup dummy shelf & shelf type to store static properties in */
1231 AssetShelf dummy_shelf = {};
1232 dummy_shelf.type = shelf_type.get();
1233 PointerRNA dummy_shelf_ptr = RNA_pointer_create_discrete(nullptr, &RNA_AssetShelf, &dummy_shelf);
1234
1235 bool have_function[4];
1236
1237 /* validate the python class */
1238 if (validate(&dummy_shelf_ptr, data, have_function) != 0) {
1239 return nullptr;
1240 }
1241
1242 if (strlen(identifier) >= sizeof(shelf_type->idname)) {
1243 BKE_reportf(reports,
1244 RPT_ERROR,
1245 "Registering asset shelf class: '%s' is too long, maximum length is %d",
1246 identifier,
1247 int(sizeof(shelf_type->idname)));
1248 return nullptr;
1249 }
1250
1251 /* Check if we have registered this asset shelf type before, and remove it. */
1252 {
1254 shelf_type->idname);
1255 if (existing_shelf_type && existing_shelf_type->rna_ext.srna) {
1256 BKE_reportf(reports,
1257 RPT_INFO,
1258 "Registering asset shelf class: '%s' has been registered before, "
1259 "unregistering previous",
1260 shelf_type->idname);
1261
1262 rna_AssetShelf_unregister(bmain, existing_shelf_type->rna_ext.srna);
1263 }
1264 }
1265
1266 if (!RNA_struct_available_or_report(reports, shelf_type->idname)) {
1267 return nullptr;
1268 }
1269 if (!RNA_struct_bl_idname_ok_or_report(reports, shelf_type->idname, "_AST_")) {
1270 return nullptr;
1271 }
1272
1273 /* Create the new shelf type. */
1274 shelf_type->rna_ext.srna = RNA_def_struct_ptr(&BLENDER_RNA, shelf_type->idname, &RNA_AssetShelf);
1275 shelf_type->rna_ext.data = data;
1276 shelf_type->rna_ext.call = call;
1277 shelf_type->rna_ext.free = free;
1278 RNA_struct_blender_type_set(shelf_type->rna_ext.srna, shelf_type.get());
1279
1280 shelf_type->poll = have_function[0] ? asset_shelf_poll : nullptr;
1281 shelf_type->asset_poll = have_function[1] ? asset_shelf_asset_poll : nullptr;
1282 shelf_type->get_active_asset = have_function[2] ? asset_shelf_get_active_asset : nullptr;
1283 shelf_type->draw_context_menu = have_function[3] ? asset_shelf_draw_context_menu : nullptr;
1284
1285 StructRNA *srna = shelf_type->rna_ext.srna;
1286
1287 blender::ed::asset::shelf::type_register(std::move(shelf_type));
1288
1289 /* update while blender is running */
1291
1292 return srna;
1293}
1294
1295static void rna_AssetShelf_activate_operator_get(PointerRNA *ptr, char *value)
1296{
1297 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1298 strcpy(value, shelf->type->activate_operator.c_str());
1299}
1300
1301static int rna_AssetShelf_activate_operator_length(PointerRNA *ptr)
1302{
1303 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1304 return shelf->type->activate_operator.size();
1305}
1306
1307static void rna_AssetShelf_activate_operator_set(PointerRNA *ptr, const char *value)
1308{
1309 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1310 shelf->type->activate_operator = value;
1311}
1312
1313static void rna_AssetShelf_drag_operator_get(PointerRNA *ptr, char *value)
1314{
1315 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1316 strcpy(value, shelf->type->drag_operator.c_str());
1317}
1318
1319static int rna_AssetShelf_drag_operator_length(PointerRNA *ptr)
1320{
1321 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1322 return shelf->type->drag_operator.size();
1323}
1324
1325static void rna_AssetShelf_drag_operator_set(PointerRNA *ptr, const char *value)
1326{
1327 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1328 shelf->type->drag_operator = value;
1329}
1330
1331static StructRNA *rna_AssetShelf_refine(PointerRNA *shelf_ptr)
1332{
1333 AssetShelf *shelf = (AssetShelf *)shelf_ptr->data;
1334 return (shelf->type && shelf->type->rna_ext.srna) ? shelf->type->rna_ext.srna : &RNA_AssetShelf;
1335}
1336
1337static int rna_AssetShelf_asset_library_get(PointerRNA *ptr)
1338{
1339 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1342}
1343
1344static void rna_AssetShelf_asset_library_set(PointerRNA *ptr, int value)
1345{
1346 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1348 value);
1349}
1350
1351static int rna_AssetShelf_preview_size_default(PointerRNA *ptr, PropertyRNA * /*prop*/)
1352{
1353 AssetShelf *shelf = static_cast<AssetShelf *>(ptr->data);
1354 if (shelf->type && shelf->type->default_preview_size) {
1355 return shelf->type->default_preview_size;
1356 }
1358}
1359
1360static void rna_Panel_bl_description_set(PointerRNA *ptr, const char *value)
1361{
1362 Panel *data = (Panel *)(ptr->data);
1363 char *str = (char *)data->type->description;
1364 if (!str[0]) {
1366 }
1367 else {
1368 BLI_assert_msg(0, "setting the bl_description on a non-builtin panel");
1369 }
1370}
1371
1372static void rna_Menu_bl_description_set(PointerRNA *ptr, const char *value)
1373{
1374 Menu *data = (Menu *)(ptr->data);
1375 char *str = (char *)data->type->description;
1376 if (!str[0]) {
1378 }
1379 else {
1380 BLI_assert_msg(0, "setting the bl_description on a non-builtin menu");
1381 }
1382}
1383
1384/* UILayout */
1385
1386static bool rna_UILayout_active_get(PointerRNA *ptr)
1387{
1388 return static_cast<uiLayout *>(ptr->data)->active();
1389}
1390
1391static void rna_UILayout_active_set(PointerRNA *ptr, bool value)
1392{
1393 static_cast<uiLayout *>(ptr->data)->active_set(value);
1394}
1395
1396static bool rna_UILayout_active_default_get(PointerRNA *ptr)
1397{
1398 return static_cast<uiLayout *>(ptr->data)->active_default();
1399}
1400
1401static void rna_UILayout_active_default_set(PointerRNA *ptr, bool value)
1402{
1403 static_cast<uiLayout *>(ptr->data)->active_default_set(value);
1404}
1405
1406static bool rna_UILayout_activate_init_get(PointerRNA *ptr)
1407{
1408 return static_cast<uiLayout *>(ptr->data)->activate_init();
1409}
1410
1411static void rna_UILayout_activate_init_set(PointerRNA *ptr, bool value)
1412{
1413 static_cast<uiLayout *>(ptr->data)->activate_init_set(value);
1414}
1415
1416static bool rna_UILayout_alert_get(PointerRNA *ptr)
1417{
1418 return static_cast<uiLayout *>(ptr->data)->red_alert();
1419}
1420
1421static void rna_UILayout_alert_set(PointerRNA *ptr, bool value)
1422{
1423 static_cast<uiLayout *>(ptr->data)->red_alert_set(value);
1424}
1425
1426static void rna_UILayout_op_context_set(PointerRNA *ptr, int value)
1427{
1428 static_cast<uiLayout *>(ptr->data)->operator_context_set(blender::wm::OpCallContext(value));
1429}
1430
1431static int rna_UILayout_op_context_get(PointerRNA *ptr)
1432{
1433 return int(static_cast<uiLayout *>(ptr->data)->operator_context());
1434}
1435
1436static bool rna_UILayout_enabled_get(PointerRNA *ptr)
1437{
1438 return static_cast<uiLayout *>(ptr->data)->enabled();
1439}
1440
1441static void rna_UILayout_enabled_set(PointerRNA *ptr, bool value)
1442{
1443 static_cast<uiLayout *>(ptr->data)->enabled_set(value);
1444}
1445
1446# if 0
1447static int rna_UILayout_red_alert_get(PointerRNA *ptr)
1448{
1449 return static_cast<uiLayout *>(ptr->data)->red_alert();
1450}
1451
1452static void rna_UILayout_red_alert_set(PointerRNA *ptr, bool value)
1453{
1454 static_cast<uiLayout *>(ptr->data)->red_alert_set(value);
1455}
1456# endif
1457
1458static int rna_UILayout_alignment_get(PointerRNA *ptr)
1459{
1460 return int(static_cast<uiLayout *>(ptr->data)->alignment());
1461}
1462
1463static void rna_UILayout_alignment_set(PointerRNA *ptr, int value)
1464{
1465 static_cast<uiLayout *>(ptr->data)->alignment_set(blender::ui::LayoutAlign(value));
1466}
1467
1468static int rna_UILayout_direction_get(PointerRNA *ptr)
1469{
1470 return int(ptr->data_as<uiLayout>()->local_direction());
1471}
1472
1473static float rna_UILayout_scale_x_get(PointerRNA *ptr)
1474{
1475 return static_cast<uiLayout *>(ptr->data)->scale_x();
1476}
1477
1478static void rna_UILayout_scale_x_set(PointerRNA *ptr, float value)
1479{
1480 static_cast<uiLayout *>(ptr->data)->scale_x_set(value);
1481}
1482
1483static float rna_UILayout_scale_y_get(PointerRNA *ptr)
1484{
1485 return static_cast<uiLayout *>(ptr->data)->scale_y();
1486}
1487
1488static void rna_UILayout_scale_y_set(PointerRNA *ptr, float value)
1489{
1490 static_cast<uiLayout *>(ptr->data)->scale_y_set(value);
1491}
1492
1493static float rna_UILayout_units_x_get(PointerRNA *ptr)
1494{
1495 return static_cast<uiLayout *>(ptr->data)->ui_units_x();
1496}
1497
1498static void rna_UILayout_units_x_set(PointerRNA *ptr, float value)
1499{
1500 static_cast<uiLayout *>(ptr->data)->ui_units_x_set(value);
1501}
1502
1503static float rna_UILayout_units_y_get(PointerRNA *ptr)
1504{
1505 return static_cast<uiLayout *>(ptr->data)->ui_units_y();
1506}
1507
1508static void rna_UILayout_units_y_set(PointerRNA *ptr, float value)
1509{
1510 static_cast<uiLayout *>(ptr->data)->ui_units_y_set(value);
1511}
1512
1513static int rna_UILayout_emboss_get(PointerRNA *ptr)
1514{
1515 return int(static_cast<uiLayout *>(ptr->data)->emboss());
1516}
1517
1518static void rna_UILayout_emboss_set(PointerRNA *ptr, int value)
1519{
1520 static_cast<uiLayout *>(ptr->data)->emboss_set(blender::ui::EmbossType(value));
1521}
1522
1523static bool rna_UILayout_property_split_get(PointerRNA *ptr)
1524{
1525 return static_cast<const uiLayout *>(ptr->data)->use_property_split();
1526}
1527
1528static void rna_UILayout_property_split_set(PointerRNA *ptr, bool value)
1529{
1530 static_cast<uiLayout *>(ptr->data)->use_property_split_set(value);
1531}
1532
1533static bool rna_UILayout_property_decorate_get(PointerRNA *ptr)
1534{
1535 return static_cast<const uiLayout *>(ptr->data)->use_property_decorate();
1536}
1537
1538static void rna_UILayout_property_decorate_set(PointerRNA *ptr, bool value)
1539{
1540 static_cast<uiLayout *>(ptr->data)->use_property_decorate_set(value);
1541}
1542
1543/* File Handler */
1544
1545static bool file_handler_poll_drop(const bContext *C,
1546 blender::bke::FileHandlerType *file_handler_type)
1547{
1548 extern FunctionRNA rna_FileHandler_poll_drop_func;
1549
1551 nullptr, file_handler_type->rna_ext.srna, nullptr); /* dummy */
1552 FunctionRNA *func = &rna_FileHandler_poll_drop_func;
1553
1554 ParameterList list;
1555 RNA_parameter_list_create(&list, &ptr, func);
1556 RNA_parameter_set_lookup(&list, "context", &C);
1557 file_handler_type->rna_ext.call((bContext *)C, &ptr, func, &list);
1558
1559 void *ret;
1560 RNA_parameter_get_lookup(&list, "is_usable", &ret);
1561 /* Get the value before freeing. */
1562 const bool is_usable = *(bool *)ret;
1563
1565
1566 return is_usable;
1567}
1568
1569static bool rna_FileHandler_unregister(Main * /*bmain*/, StructRNA *type)
1570{
1571 using namespace blender;
1572 bke::FileHandlerType *file_handler_type = static_cast<bke::FileHandlerType *>(
1574
1575 if (!file_handler_type) {
1576 return false;
1577 }
1578
1579 RNA_struct_free_extension(type, &file_handler_type->rna_ext);
1581
1582 bke::file_handler_remove(file_handler_type);
1583
1584 return true;
1585}
1586
1587static StructRNA *rna_FileHandler_register(Main *bmain,
1588 ReportList *reports,
1589 void *data,
1590 const char *identifier,
1591 StructValidateFunc validate,
1592 StructCallbackFunc call,
1594{
1595 using namespace blender;
1596 bke::FileHandlerType dummy_file_handler_type{};
1597 FileHandler dummy_file_handler{};
1598
1599 dummy_file_handler.type = &dummy_file_handler_type;
1600
1601 /* Setup dummy file handler type to store static properties in. */
1602 PointerRNA dummy_file_handler_ptr = RNA_pointer_create_discrete(
1603 nullptr, &RNA_FileHandler, &dummy_file_handler);
1604
1605 bool have_function[1];
1606
1607 /* Validate the python class. */
1608 if (validate(&dummy_file_handler_ptr, data, have_function) != 0) {
1609 return nullptr;
1610 }
1611
1612 if (strlen(identifier) >= sizeof(dummy_file_handler_type.idname)) {
1613 BKE_reportf(reports,
1614 RPT_ERROR,
1615 "Registering file handler class: '%s' is too long, maximum length is %d",
1616 identifier,
1617 (int)sizeof(dummy_file_handler_type.idname));
1618 return nullptr;
1619 }
1620
1621 /* Check if there is a file handler registered with the same `idname`, and remove it. */
1622 auto registered_file_handler = bke::file_handler_find(dummy_file_handler_type.idname);
1623 if (registered_file_handler) {
1624 rna_FileHandler_unregister(bmain, registered_file_handler->rna_ext.srna);
1625 }
1626
1627 if (!RNA_struct_available_or_report(reports, dummy_file_handler_type.idname)) {
1628 return nullptr;
1629 }
1630 if (!RNA_struct_bl_idname_ok_or_report(reports, dummy_file_handler_type.idname, "_FH_")) {
1631 return nullptr;
1632 }
1633
1634 /* Create the new file handler type. */
1635 auto file_handler_type = std::make_unique<bke::FileHandlerType>();
1636 *file_handler_type = dummy_file_handler_type;
1637
1638 file_handler_type->rna_ext.srna = RNA_def_struct_ptr(
1639 &BLENDER_RNA, file_handler_type->idname, &RNA_FileHandler);
1640 file_handler_type->rna_ext.data = data;
1641 file_handler_type->rna_ext.call = call;
1642 file_handler_type->rna_ext.free = free;
1643 RNA_struct_blender_type_set(file_handler_type->rna_ext.srna, file_handler_type.get());
1644
1645 file_handler_type->poll_drop = have_function[0] ? file_handler_poll_drop : nullptr;
1646
1647 auto srna = file_handler_type->rna_ext.srna;
1648 bke::file_handler_add(std::move(file_handler_type));
1649
1650 return srna;
1651}
1652
1653static StructRNA *rna_FileHandler_refine(PointerRNA *file_handler_ptr)
1654{
1655 FileHandler *file_handler = (FileHandler *)file_handler_ptr->data;
1656 return (file_handler->type && file_handler->type->rna_ext.srna) ?
1657 file_handler->type->rna_ext.srna :
1658 &RNA_FileHandler;
1659}
1660
1661#else /* RNA_RUNTIME */
1662
1664{
1665 StructRNA *srna;
1666 PropertyRNA *prop;
1667
1668 static const EnumPropertyItem alignment_items[] = {
1669 {int(blender::ui::LayoutAlign::Expand), "EXPAND", 0, "Expand", ""},
1670 {int(blender::ui::LayoutAlign::Left), "LEFT", 0, "Left", ""},
1671 {int(blender::ui::LayoutAlign::Center), "CENTER", 0, "Center", ""},
1672 {int(blender::ui::LayoutAlign::Right), "RIGHT", 0, "Right", ""},
1673 {0, nullptr, 0, nullptr, nullptr},
1674 };
1675
1676 static const EnumPropertyItem direction_items[] = {
1677 {int(blender::ui::LayoutDirection::Horizontal), "HORIZONTAL", 0, "Horizontal", ""},
1678 {int(blender::ui::LayoutDirection::Vertical), "VERTICAL", 0, "Vertical", ""},
1679 {0, nullptr, 0, nullptr, nullptr},
1680 };
1681
1682 static const EnumPropertyItem emboss_items[] = {
1684 "NORMAL",
1685 0,
1686 "Regular",
1687 "Draw standard button emboss style"},
1688 {int(blender::ui::EmbossType::None), "NONE", 0, "None", "Draw only text and icons"},
1690 "PULLDOWN_MENU",
1691 0,
1692 "Pull-down Menu",
1693 "Draw pull-down menu style"},
1694 {int(blender::ui::EmbossType::PieMenu), "PIE_MENU", 0, "Pie Menu", "Draw radial menu style"},
1696 "NONE_OR_STATUS",
1697 0,
1698 "None or Status",
1699 "Draw with no emboss unless the button has a coloring status like an animation state"},
1700 {0, nullptr, 0, nullptr, nullptr},
1701 };
1702
1703 /* layout */
1704
1705 srna = RNA_def_struct(brna, "UILayout", nullptr);
1706 RNA_def_struct_sdna(srna, "uiLayout");
1707 RNA_def_struct_ui_text(srna, "UI Layout", "User interface layout in a panel or header");
1708
1709 prop = RNA_def_property(srna, "active", PROP_BOOLEAN, PROP_NONE);
1710 RNA_def_property_boolean_funcs(prop, "rna_UILayout_active_get", "rna_UILayout_active_set");
1711
1712 prop = RNA_def_property(srna, "active_default", PROP_BOOLEAN, PROP_NONE);
1714 prop, "rna_UILayout_active_default_get", "rna_UILayout_active_default_set");
1716 prop,
1717 "Active Default",
1718 "When true, an operator button defined after this will be activated when pressing return"
1719 "(use with popup dialogs)");
1720
1721 prop = RNA_def_property(srna, "activate_init", PROP_BOOLEAN, PROP_NONE);
1723 prop, "rna_UILayout_activate_init_get", "rna_UILayout_activate_init_set");
1725 prop,
1726 "Activate on Init",
1727 "When true, buttons defined in popups will be activated on first display "
1728 "(use so you can type into a field without having to click on it first)");
1729
1730 prop = RNA_def_property(srna, "operator_context", PROP_ENUM, PROP_NONE);
1733 prop, "rna_UILayout_op_context_get", "rna_UILayout_op_context_set", nullptr);
1735 "Operator Context",
1736 "Typically set to 'INVOKE_REGION_WIN', except some cases "
1737 "in :class:`bpy.types.Menu` when it's set to 'EXEC_REGION_WIN'.");
1738
1739 prop = RNA_def_property(srna, "enabled", PROP_BOOLEAN, PROP_NONE);
1740 RNA_def_property_boolean_funcs(prop, "rna_UILayout_enabled_get", "rna_UILayout_enabled_set");
1741 RNA_def_property_ui_text(prop, "Enabled", "When false, this (sub)layout is grayed out");
1742
1743 prop = RNA_def_property(srna, "alert", PROP_BOOLEAN, PROP_NONE);
1744 RNA_def_property_boolean_funcs(prop, "rna_UILayout_alert_get", "rna_UILayout_alert_set");
1745
1746 prop = RNA_def_property(srna, "alignment", PROP_ENUM, PROP_NONE);
1747 RNA_def_property_enum_items(prop, alignment_items);
1749 prop, "rna_UILayout_alignment_get", "rna_UILayout_alignment_set", nullptr);
1750
1751 prop = RNA_def_property(srna, "direction", PROP_ENUM, PROP_NONE);
1752 RNA_def_property_enum_items(prop, direction_items);
1753 RNA_def_property_enum_funcs(prop, "rna_UILayout_direction_get", nullptr, nullptr);
1755
1756 prop = RNA_def_property(srna, "scale_x", PROP_FLOAT, PROP_UNSIGNED);
1758 prop, "rna_UILayout_scale_x_get", "rna_UILayout_scale_x_set", nullptr);
1760 prop, "Scale X", "Scale factor along the X for items in this (sub)layout");
1761
1762 prop = RNA_def_property(srna, "scale_y", PROP_FLOAT, PROP_UNSIGNED);
1764 prop, "rna_UILayout_scale_y_get", "rna_UILayout_scale_y_set", nullptr);
1766 prop, "Scale Y", "Scale factor along the Y for items in this (sub)layout");
1767
1768 prop = RNA_def_property(srna, "ui_units_x", PROP_FLOAT, PROP_UNSIGNED);
1770 prop, "rna_UILayout_units_x_get", "rna_UILayout_units_x_set", nullptr);
1772 prop, "Units X", "Fixed size along the X for items in this (sub)layout");
1773
1774 prop = RNA_def_property(srna, "ui_units_y", PROP_FLOAT, PROP_UNSIGNED);
1776 prop, "rna_UILayout_units_y_get", "rna_UILayout_units_y_set", nullptr);
1778 prop, "Units Y", "Fixed size along the Y for items in this (sub)layout");
1779 RNA_api_ui_layout(srna);
1780
1781 prop = RNA_def_property(srna, "emboss", PROP_ENUM, PROP_NONE);
1782 RNA_def_property_enum_items(prop, emboss_items);
1783 RNA_def_property_enum_funcs(prop, "rna_UILayout_emboss_get", "rna_UILayout_emboss_set", nullptr);
1784
1785 prop = RNA_def_property(srna, "use_property_split", PROP_BOOLEAN, PROP_NONE);
1787 prop, "rna_UILayout_property_split_get", "rna_UILayout_property_split_set");
1788
1789 prop = RNA_def_property(srna, "use_property_decorate", PROP_BOOLEAN, PROP_NONE);
1791 prop, "rna_UILayout_property_decorate_get", "rna_UILayout_property_decorate_set");
1792}
1793
1794static void rna_def_panel(BlenderRNA *brna)
1795{
1796 StructRNA *srna;
1797 PropertyRNA *prop;
1798 PropertyRNA *parm;
1799 FunctionRNA *func;
1800
1801 static const EnumPropertyItem panel_flag_items[] = {
1803 "DEFAULT_CLOSED",
1804 0,
1805 "Default Closed",
1806 "Defines if the panel has to be open or collapsed at the time of its creation"},
1808 "HIDE_HEADER",
1809 0,
1810 "Hide Header",
1811 "If set to False, the panel shows a header, which contains a clickable "
1812 "arrow to collapse the panel and the label (see bl_label)"},
1814 "INSTANCED",
1815 0,
1816 "Instanced Panel",
1817 "Multiple panels with this type can be used as part of a list depending on data external "
1818 "to the UI. Used to create panels for the modifiers and other stacks."},
1820 "HEADER_LAYOUT_EXPAND",
1821 0,
1822 "Expand Header Layout",
1823 "Allow buttons in the header to stretch and shrink to fill the entire layout width"},
1824 {0, nullptr, 0, nullptr, nullptr},
1825 };
1826
1827 srna = RNA_def_struct(brna, "Panel", nullptr);
1828 RNA_def_struct_ui_text(srna, "Panel", "Panel containing UI elements");
1829 RNA_def_struct_sdna(srna, "Panel");
1830 RNA_def_struct_refine_func(srna, "rna_Panel_refine");
1831 RNA_def_struct_register_funcs(srna, "rna_Panel_register", "rna_Panel_unregister", nullptr);
1834
1835 /* poll */
1836 func = RNA_def_function(srna, "poll", nullptr);
1838 func, "If this method returns a non-null output, then the panel can be drawn");
1840 RNA_def_function_return(func, RNA_def_boolean(func, "visible", false, "", ""));
1841 parm = RNA_def_pointer(func, "context", "Context", "", "");
1843
1844 /* draw */
1845 func = RNA_def_function(srna, "draw", nullptr);
1846 RNA_def_function_ui_description(func, "Draw UI elements into the panel UI layout");
1848 parm = RNA_def_pointer(func, "context", "Context", "", "");
1850
1851 func = RNA_def_function(srna, "draw_header", nullptr);
1852 RNA_def_function_ui_description(func, "Draw UI elements into the panel's header UI layout");
1854 parm = RNA_def_pointer(func, "context", "Context", "", "");
1856
1857 func = RNA_def_function(srna, "draw_header_preset", nullptr);
1858 RNA_def_function_ui_description(func, "Draw UI elements for presets in the panel's header");
1860 parm = RNA_def_pointer(func, "context", "Context", "", "");
1862
1863 prop = RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
1864 RNA_def_property_struct_type(prop, "UILayout");
1865 RNA_def_property_ui_text(prop, "Layout", "Defines the structure of the panel in the UI");
1866
1867 prop = RNA_def_property(srna, "text", PROP_STRING, PROP_NONE);
1868 RNA_def_property_string_sdna(prop, nullptr, "drawname");
1869 RNA_def_property_ui_text(prop, "Text", "XXX todo");
1870
1871 prop = RNA_def_property(srna, "custom_data", PROP_POINTER, PROP_NONE);
1872 RNA_def_property_struct_type(prop, "Constraint");
1873 RNA_def_property_pointer_sdna(prop, nullptr, "runtime.custom_data_ptr");
1875 prop, "rna_Panel_custom_data_get", nullptr, "rna_Panel_custom_data_typef", nullptr);
1876 RNA_def_property_ui_text(prop, "Custom Data", "Panel data");
1878
1879 /* registration */
1880 prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
1881 RNA_def_property_string_sdna(prop, nullptr, "type->idname");
1884 "ID Name",
1885 "If this is set, the panel gets a custom ID, otherwise it takes the "
1886 "name of the class used to define the panel. For example, if the "
1887 "class name is \"OBJECT_PT_hello\", and bl_idname is not set by the "
1888 "script, then bl_idname = \"OBJECT_PT_hello\".");
1889
1890 prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
1891 RNA_def_property_string_sdna(prop, nullptr, "type->label");
1894 "Label",
1895 "The panel label, shows up in the panel header at the right of the "
1896 "triangle used to collapse the panel");
1897
1898 prop = RNA_def_property(srna, "bl_translation_context", PROP_STRING, PROP_NONE);
1899 RNA_def_property_string_sdna(prop, nullptr, "type->translation_context");
1903 "",
1904 "Specific translation context, only define when the label needs to be "
1905 "disambiguated from others using the exact same label");
1906
1908
1909 prop = RNA_def_property(srna, "bl_description", PROP_STRING, PROP_NONE);
1910 RNA_def_property_string_sdna(prop, nullptr, "type->description");
1911 RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
1912 RNA_def_property_string_funcs(prop, nullptr, nullptr, "rna_Panel_bl_description_set");
1913 // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
1915 RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for nullptr */
1916 RNA_def_property_ui_text(prop, "", "The panel tooltip");
1917
1918 prop = RNA_def_property(srna, "bl_category", PROP_STRING, PROP_NONE);
1919 RNA_def_property_string_sdna(prop, nullptr, "type->category");
1922 prop, "", "The category (tab) in which the panel will be displayed, when applicable");
1923
1924 prop = RNA_def_property(srna, "bl_owner_id", PROP_STRING, PROP_NONE);
1925 RNA_def_property_string_sdna(prop, nullptr, "type->owner_id");
1927 RNA_def_property_ui_text(prop, "", "The ID owning the data displayed in the panel, if any");
1928
1929 prop = RNA_def_property(srna, "bl_space_type", PROP_ENUM, PROP_NONE);
1930 RNA_def_property_enum_sdna(prop, nullptr, "type->space_type");
1933 RNA_def_property_ui_text(prop, "Space Type", "The space where the panel is going to be used in");
1934
1935 prop = RNA_def_property(srna, "bl_region_type", PROP_ENUM, PROP_NONE);
1936 RNA_def_property_enum_sdna(prop, nullptr, "type->region_type");
1940 prop, "Region Type", "The region where the panel is going to be used in");
1941
1942 prop = RNA_def_property(srna, "bl_context", PROP_STRING, PROP_NONE);
1943 RNA_def_property_string_sdna(prop, nullptr, "type->context");
1945 prop, PROP_REGISTER_OPTIONAL); /* Only used in Properties Editor and 3D View - Thomas */
1947 "Context",
1948 "The context in which the panel belongs to. (TODO: explain the "
1949 "possible combinations bl_context/bl_region_type/bl_space_type)");
1950
1951 prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE);
1953 RNA_def_property_enum_sdna(prop, nullptr, "type->flag");
1954 RNA_def_property_enum_items(prop, panel_flag_items);
1955 RNA_def_property_ui_text(prop, "Options", "Options for this panel type");
1956
1957 prop = RNA_def_property(srna, "bl_parent_id", PROP_STRING, PROP_NONE);
1958 RNA_def_property_string_sdna(prop, nullptr, "type->parent_id");
1961 prop, "Parent ID Name", "If this is set, the panel becomes a sub-panel");
1962
1963 prop = RNA_def_property(srna, "bl_ui_units_x", PROP_INT, PROP_UNSIGNED);
1964 RNA_def_property_int_sdna(prop, nullptr, "type->ui_units_x");
1966 RNA_def_property_ui_text(prop, "Units X", "When set, defines popup panel width");
1967
1968 prop = RNA_def_property(srna, "bl_order", PROP_INT, PROP_UNSIGNED);
1969 RNA_def_property_int_sdna(prop, nullptr, "type->order");
1972 prop,
1973 "Order",
1974 "Panels with lower numbers are default ordered before panels with higher numbers");
1975
1976 prop = RNA_def_property(srna, "use_pin", PROP_BOOLEAN, PROP_NONE);
1977 RNA_def_property_boolean_sdna(prop, nullptr, "flag", PNL_PIN);
1978 RNA_def_property_ui_text(prop, "Pin", "Show the panel on all tabs");
1979 /* XXX, should only tag region for redraw */
1980 RNA_def_property_update(prop, NC_WINDOW, nullptr);
1981
1982 prop = RNA_def_property(srna, "is_popover", PROP_BOOLEAN, PROP_NONE);
1983 RNA_def_property_boolean_sdna(prop, nullptr, "flag", PNL_POPOVER);
1985 RNA_def_property_ui_text(prop, "Popover", "");
1986}
1987
1988static void rna_def_uilist(BlenderRNA *brna)
1989{
1990 StructRNA *srna;
1991 PropertyRNA *prop;
1992 PropertyRNA *parm;
1993 FunctionRNA *func;
1994
1995 srna = RNA_def_struct(brna, "UIList", nullptr);
1996 RNA_def_struct_ui_text(srna, "UIList", "UI list containing the elements of a collection");
1997 RNA_def_struct_sdna(srna, "uiList");
1998 RNA_def_struct_refine_func(srna, "rna_UIList_refine");
1999 RNA_def_struct_register_funcs(srna, "rna_UIList_register", "rna_UIList_unregister", nullptr);
2000 RNA_def_struct_system_idprops_func(srna, "rna_UIList_idprops");
2002
2003 /* Registration */
2004 prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
2005 RNA_def_property_string_sdna(prop, nullptr, "type->idname");
2008 "ID Name",
2009 "If this is set, the uilist gets a custom ID, otherwise it takes the "
2010 "name of the class used to define the uilist (for example, if the "
2011 "class name is \"OBJECT_UL_vgroups\", and bl_idname is not set by the "
2012 "script, then bl_idname = \"OBJECT_UL_vgroups\")");
2013
2014 /* Data */
2015 /* Note that this is the "non-full" list-ID as obtained through #WM_uilisttype_list_id_get(),
2016 * which differs from the (internal) `uiList.list_id`. */
2017 prop = RNA_def_property(srna, "list_id", PROP_STRING, PROP_NONE);
2020 prop, "rna_UIList_list_id_get", "rna_UIList_list_id_length", nullptr);
2022 "List Name",
2023 "Identifier of the list, if any was passed to the \"list_id\" "
2024 "parameter of \"template_list()\"");
2025
2026 prop = RNA_def_property(srna, "layout_type", PROP_ENUM, PROP_NONE);
2029
2030 /* Filter options */
2031 prop = RNA_def_property(srna, "use_filter_show", PROP_BOOLEAN, PROP_NONE);
2032 RNA_def_property_boolean_sdna(prop, nullptr, "filter_flag", UILST_FLT_SHOW);
2033 RNA_def_property_ui_text(prop, "Show Filter", "Show filtering options");
2034
2035 prop = RNA_def_property(srna, "filter_name", PROP_STRING, PROP_NONE);
2036 RNA_def_property_string_sdna(prop, nullptr, "filter_byname");
2039 prop, "Filter by Name", "Only show items matching this name (use '*' as wildcard)");
2040
2041 prop = RNA_def_property(srna, "use_filter_invert", PROP_BOOLEAN, PROP_NONE);
2042 RNA_def_property_boolean_sdna(prop, nullptr, "filter_flag", UILST_FLT_EXCLUDE);
2043 RNA_def_property_ui_text(prop, "Invert", "Invert filtering (show hidden items, and vice versa)");
2044
2045 /* WARNING: This is sort of an abuse, sort-by-alpha is actually a value,
2046 * should even be an enum in full logic (of two values, sort by index and sort by name).
2047 * But for default UIList, it's nicer (better UI-wise) to show this as a boolean bit-flag option,
2048 * avoids having to define custom setters/getters using UILST_FLT_SORT_MASK to mask out
2049 * actual bitflags on same var, etc.
2050 */
2051 prop = RNA_def_property(srna, "use_filter_sort_alpha", PROP_BOOLEAN, PROP_NONE);
2052 RNA_def_property_boolean_sdna(prop, nullptr, "filter_sort_flag", UILST_FLT_SORT_ALPHA);
2053 RNA_def_property_ui_icon(prop, ICON_SORTALPHA, 0);
2054 RNA_def_property_ui_text(prop, "Sort by Name", "Sort items by their name");
2055
2056 prop = RNA_def_property(srna, "use_filter_sort_reverse", PROP_BOOLEAN, PROP_NONE);
2057 RNA_def_property_boolean_sdna(prop, nullptr, "filter_sort_flag", UILST_FLT_SORT_REVERSE);
2058 RNA_def_property_ui_text(prop, "Reverse", "Reverse the order of shown items");
2059
2060 prop = RNA_def_property(srna, "use_filter_sort_lock", PROP_BOOLEAN, PROP_NONE);
2061 RNA_def_property_boolean_sdna(prop, nullptr, "filter_sort_flag", UILST_FLT_SORT_LOCK);
2063 prop, "Lock Order", "Lock the order of shown items (user cannot change it)");
2064
2065 /* draw_item */
2066 func = RNA_def_function(srna, "draw_item", nullptr);
2068 func,
2069 "Draw an item in the list (NOTE: when you define your own draw_item "
2070 "function, you may want to check given 'item' is of the right type...)");
2072 parm = RNA_def_pointer(func, "context", "Context", "", "");
2074 parm = RNA_def_pointer(func, "layout", "UILayout", "", "Layout to draw the item");
2076 parm = RNA_def_pointer(
2077 func, "data", "AnyType", "", "Data from which to take Collection property");
2079 parm = RNA_def_pointer(func, "item", "AnyType", "", "Item of the collection property");
2081 parm = RNA_def_int(
2082 func, "icon", 0, 0, INT_MAX, "", "Icon of the item in the collection", 0, INT_MAX);
2084 parm = RNA_def_pointer(func,
2085 "active_data",
2086 "AnyType",
2087 "",
2088 "Data from which to take property for the active element");
2090 parm = RNA_def_string(func,
2091 "active_property",
2092 nullptr,
2093 0,
2094 "",
2095 "Identifier of property in active_data, for the active element");
2097 parm = RNA_def_int(
2098 func, "index", 0, 0, INT_MAX, "", "Index of the item in the collection", 0, INT_MAX);
2100 parm = RNA_def_property(func, "flt_flag", PROP_INT, PROP_UNSIGNED);
2101 RNA_def_property_ui_text(parm, "", "The filter-flag result for this item");
2103
2104 /* draw_filter */
2105 func = RNA_def_function(srna, "draw_filter", nullptr);
2106 RNA_def_function_ui_description(func, "Draw filtering options");
2108 parm = RNA_def_pointer(func, "context", "Context", "", "");
2110 parm = RNA_def_pointer(func, "layout", "UILayout", "", "Layout to draw the item");
2112
2113 /* filter */
2114 func = RNA_def_function(srna, "filter_items", nullptr);
2116 func,
2117 "Filter and/or re-order items of the collection (output filter results in "
2118 "filter_flags, and reorder results in filter_neworder arrays)");
2120 parm = RNA_def_pointer(func, "context", "Context", "", "");
2122 parm = RNA_def_pointer(
2123 func, "data", "AnyType", "", "Data from which to take Collection property");
2125 parm = RNA_def_string(
2126 func, "property", nullptr, 0, "", "Identifier of property in data, for the collection");
2128 prop = RNA_def_property(func, "filter_flags", PROP_INT, PROP_UNSIGNED);
2130 RNA_def_property_array(prop, 1); /* XXX Dummy value, default 0 does not work */
2132 "",
2133 "An array of filter flags, one for each item in the collection (NOTE: "
2134 "The upper 16 bits, including FILTER_ITEM, are reserved, only use the "
2135 "lower 16 bits for custom usages)");
2136 RNA_def_function_output(func, prop);
2137 prop = RNA_def_property(func, "filter_neworder", PROP_INT, PROP_UNSIGNED);
2139 RNA_def_property_array(prop, 1); /* XXX Dummy value, default 0 does not work */
2141 prop,
2142 "",
2143 "An array of indices, one for each item in the collection, mapping the org "
2144 "index to the new one");
2145 RNA_def_function_output(func, prop);
2146
2147 /* "Constants"! */
2148 RNA_define_verify_sdna(false); /* not in sdna */
2149
2150 prop = RNA_def_property(srna, "bitflag_filter_item", PROP_INT, PROP_UNSIGNED);
2152 prop,
2153 "FILTER_ITEM",
2154 "The value of the reserved bitflag 'FILTER_ITEM' (in filter_flags values)");
2155 RNA_def_property_int_funcs(prop, "rna_UIList_filter_const_FILTER_ITEM_get", nullptr, nullptr);
2157
2158 prop = RNA_def_property(srna, "bitflag_item_never_show", PROP_INT, PROP_UNSIGNED);
2159 RNA_def_property_ui_text(prop, "ITEM_NEVER_SHOW", "Skip the item from displaying in the list");
2160 RNA_def_property_int_funcs(prop, "rna_UIList_item_never_show", nullptr, nullptr);
2162}
2163
2164static void rna_def_header(BlenderRNA *brna)
2165{
2166 StructRNA *srna;
2167 PropertyRNA *prop;
2168 PropertyRNA *parm;
2169 FunctionRNA *func;
2170
2171 srna = RNA_def_struct(brna, "Header", nullptr);
2172 RNA_def_struct_ui_text(srna, "Header", "Editor header containing UI elements");
2173 RNA_def_struct_sdna(srna, "Header");
2174 RNA_def_struct_refine_func(srna, "rna_Header_refine");
2175 RNA_def_struct_register_funcs(srna, "rna_Header_register", "rna_Header_unregister", nullptr);
2177
2178 /* draw */
2179 func = RNA_def_function(srna, "draw", nullptr);
2180 RNA_def_function_ui_description(func, "Draw UI elements into the header UI layout");
2182 parm = RNA_def_pointer(func, "context", "Context", "", "");
2184
2185 RNA_define_verify_sdna(false); /* not in sdna */
2186
2187 prop = RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
2188 RNA_def_property_pointer_sdna(prop, nullptr, "layout");
2189 RNA_def_property_struct_type(prop, "UILayout");
2190 RNA_def_property_ui_text(prop, "Layout", "Structure of the header in the UI");
2191
2192 /* registration */
2193 prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
2194 RNA_def_property_string_sdna(prop, nullptr, "type->idname");
2197 "ID Name",
2198 "If this is set, the header gets a custom ID, otherwise it takes the "
2199 "name of the class used to define the header; for example, if the "
2200 "class name is \"OBJECT_HT_hello\", and bl_idname is not set by the "
2201 "script, then bl_idname = \"OBJECT_HT_hello\"");
2202
2203 prop = RNA_def_property(srna, "bl_space_type", PROP_ENUM, PROP_NONE);
2204 RNA_def_property_enum_sdna(prop, nullptr, "type->space_type");
2208 prop, "Space Type", "The space where the header is going to be used in");
2209
2210 prop = RNA_def_property(srna, "bl_region_type", PROP_ENUM, PROP_NONE);
2211 RNA_def_property_enum_sdna(prop, nullptr, "type->region_type");
2216 "Region Type",
2217 "The region where the header is going to be used in "
2218 "(defaults to header region)");
2219
2221}
2222
2223static void rna_def_menu(BlenderRNA *brna)
2224{
2225 StructRNA *srna;
2226 PropertyRNA *prop;
2227 PropertyRNA *parm;
2228 FunctionRNA *func;
2229
2230 static const EnumPropertyItem menu_flag_items[] = {
2232 "SEARCH_ON_KEY_PRESS",
2233 0,
2234 "Search on Key Press",
2235 "Open a menu search when a key pressed while the menu is open"},
2236 {0, nullptr, 0, nullptr, nullptr},
2237 };
2238
2239 srna = RNA_def_struct(brna, "Menu", nullptr);
2240 RNA_def_struct_ui_text(srna, "Menu", "Editor menu containing buttons");
2241 RNA_def_struct_sdna(srna, "Menu");
2242 RNA_def_struct_refine_func(srna, "rna_Menu_refine");
2243 RNA_def_struct_register_funcs(srna, "rna_Menu_register", "rna_Menu_unregister", nullptr);
2246
2247 /* poll */
2248 func = RNA_def_function(srna, "poll", nullptr);
2250 func, "If this method returns a non-null output, then the menu can be drawn");
2252 RNA_def_function_return(func, RNA_def_boolean(func, "visible", false, "", ""));
2253 parm = RNA_def_pointer(func, "context", "Context", "", "");
2255
2256 /* draw */
2257 func = RNA_def_function(srna, "draw", nullptr);
2258 RNA_def_function_ui_description(func, "Draw UI elements into the menu UI layout");
2260 parm = RNA_def_pointer(func, "context", "Context", "", "");
2262
2263 RNA_define_verify_sdna(false); /* not in sdna */
2264
2265 prop = RNA_def_property(srna, "layout", PROP_POINTER, PROP_NONE);
2266 RNA_def_property_pointer_sdna(prop, nullptr, "layout");
2267 RNA_def_property_struct_type(prop, "UILayout");
2268 RNA_def_property_ui_text(prop, "Layout", "Defines the structure of the menu in the UI");
2269
2270 /* registration */
2271 prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
2272 RNA_def_property_string_sdna(prop, nullptr, "type->idname");
2275 "ID Name",
2276 "If this is set, the menu gets a custom ID, otherwise it takes the "
2277 "name of the class used to define the menu (for example, if the "
2278 "class name is \"OBJECT_MT_hello\", and bl_idname is not set by the "
2279 "script, then bl_idname = \"OBJECT_MT_hello\")");
2280
2281 prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
2282 RNA_def_property_string_sdna(prop, nullptr, "type->label");
2284 RNA_def_property_ui_text(prop, "Label", "The menu label");
2285
2286 prop = RNA_def_property(srna, "bl_translation_context", PROP_STRING, PROP_NONE);
2287 RNA_def_property_string_sdna(prop, nullptr, "type->translation_context");
2290
2291 prop = RNA_def_property(srna, "bl_description", PROP_STRING, PROP_NONE);
2292 RNA_def_property_string_sdna(prop, nullptr, "type->description");
2293 RNA_def_property_string_maxlength(prop, RNA_DYN_DESCR_MAX); /* else it uses the pointer size! */
2294 RNA_def_property_string_funcs(prop, nullptr, nullptr, "rna_Menu_bl_description_set");
2295 // RNA_def_property_clear_flag(prop, PROP_EDITABLE);
2297 RNA_def_property_clear_flag(prop, PROP_NEVER_NULL); /* check for nullptr */
2298
2299 prop = RNA_def_property(srna, "bl_owner_id", PROP_STRING, PROP_NONE);
2300 RNA_def_property_string_sdna(prop, nullptr, "type->owner_id");
2302
2303 prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE);
2305 RNA_def_property_enum_sdna(prop, nullptr, "type->flag");
2306 RNA_def_property_enum_items(prop, menu_flag_items);
2307 RNA_def_property_ui_text(prop, "Options", "Options for this menu type");
2308
2310}
2311
2313{
2314 StructRNA *srna;
2315 PropertyRNA *prop;
2316
2317 static const EnumPropertyItem asset_shelf_flag_items[] = {
2319 "NO_ASSET_DRAG",
2320 0,
2321 "No Asset Dragging",
2322 "Disable the default asset dragging on drag events. Useful for implementing custom "
2323 "dragging via custom key-map items."},
2325 "DEFAULT_VISIBLE",
2326 0,
2327 "Visible by Default",
2328 "Unhide the asset shelf when it's available for the first time, otherwise it will be "
2329 "hidden"},
2331 "STORE_ENABLED_CATALOGS_IN_PREFERENCES",
2332 0,
2333 "Store Enabled Catalogs in Preferences",
2334 "Store the shelf's enabled catalogs in the preferences rather than the local asset shelf "
2335 "settings"},
2337 "ACTIVATE_FOR_CONTEXT_MENU",
2338 0,
2339 "",
2340 "When spawning a context menu for an asset, activate the asset and call "
2341 "`bl_activate_operator` if present, rather than just highlighting the asset"},
2342 {0, nullptr, 0, nullptr, nullptr},
2343 };
2344
2345 srna = RNA_def_struct(brna, "AssetShelf", nullptr);
2346 RNA_def_struct_ui_text(srna, "Asset Shelf", "Regions for quick access to assets");
2347 RNA_def_struct_refine_func(srna, "rna_AssetShelf_refine");
2349 srna, "rna_AssetShelf_register", "rna_AssetShelf_unregister", nullptr);
2352
2353 /* registration */
2354
2355 prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
2356 RNA_def_property_string_sdna(prop, nullptr, "type->idname");
2359 "ID Name",
2360 "If this is set, the asset gets a custom ID, otherwise it takes the "
2361 "name of the class used to define the asset (for example, if the "
2362 "class name is \"OBJECT_AST_hello\", and bl_idname is not set by the "
2363 "script, then bl_idname = \"OBJECT_AST_hello\")");
2364
2365 prop = RNA_def_property(srna, "bl_space_type", PROP_ENUM, PROP_NONE);
2366 RNA_def_property_enum_sdna(prop, nullptr, "type->space_type");
2370 "Space Type",
2371 "The space where the asset shelf will show up in. Ignored for popup "
2372 "asset shelves which can be displayed in any space.");
2373
2374 prop = RNA_def_property(srna, "bl_options", PROP_ENUM, PROP_NONE);
2376 RNA_def_property_enum_sdna(prop, nullptr, "type->flag");
2377 RNA_def_property_enum_items(prop, asset_shelf_flag_items);
2378 RNA_def_property_ui_text(prop, "Options", "Options for this asset shelf type");
2379
2380 prop = RNA_def_property(srna, "bl_activate_operator", PROP_STRING, PROP_NONE);
2382 "rna_AssetShelf_activate_operator_get",
2383 "rna_AssetShelf_activate_operator_length",
2384 "rna_AssetShelf_activate_operator_set");
2387 prop,
2388 "Activate Operator",
2389 "Operator to call when activating an item with asset reference properties");
2390
2391 prop = RNA_def_property(srna, "bl_drag_operator", PROP_STRING, PROP_NONE);
2393 "rna_AssetShelf_drag_operator_get",
2394 "rna_AssetShelf_drag_operator_length",
2395 "rna_AssetShelf_drag_operator_set");
2398 prop,
2399 "Drag Operator",
2400 "Operator to call when dragging an item with asset reference properties");
2401
2402 prop = RNA_def_property(srna, "bl_default_preview_size", PROP_INT, PROP_UNSIGNED);
2403 RNA_def_property_int_sdna(prop, nullptr, "type->default_preview_size");
2404 RNA_def_property_range(prop, 32, 256);
2407 prop, "Default Preview Size", "Default size of the asset preview thumbnails in pixels");
2408
2409 PropertyRNA *parm;
2410 FunctionRNA *func;
2411
2412 func = RNA_def_function(srna, "poll", nullptr);
2414 func, "If this method returns a non-null output, the asset shelf will be visible");
2416 RNA_def_function_return(func, RNA_def_boolean(func, "visible", false, "", ""));
2417 parm = RNA_def_pointer(func, "context", "Context", "", "");
2419
2420 func = RNA_def_function(srna, "asset_poll", nullptr);
2422 func,
2423 "Determine if an asset should be visible in the asset shelf. If this method returns a "
2424 "non-null output, the asset will be visible.");
2426 RNA_def_function_return(func, RNA_def_boolean(func, "visible", false, "", ""));
2427 parm = RNA_def_pointer(func, "asset", "AssetRepresentation", "", "");
2429
2430 func = RNA_def_function(srna, "get_active_asset", nullptr);
2432 func,
2433 "Return a reference to the asset that should be highlighted as active in the asset shelf");
2435 /* return type */
2436 parm = RNA_def_pointer(func,
2437 "asset_reference",
2438 "AssetWeakReference",
2439 "",
2440 "The weak reference to the asset to be highlighted as active, or None");
2441 RNA_def_function_return(func, parm);
2442
2443 func = RNA_def_function(srna, "draw_context_menu", nullptr);
2445 func, "Draw UI elements into the context menu UI layout displayed on right click");
2447 parm = RNA_def_pointer(func, "context", "Context", "", "");
2449 parm = RNA_def_pointer(func, "asset", "AssetRepresentation", "", "");
2451 parm = RNA_def_pointer(func, "layout", "UILayout", "", "");
2453
2455 srna, "rna_AssetShelf_asset_library_get", "rna_AssetShelf_asset_library_set");
2457 prop, "Asset Library", "Choose the asset library to display assets from");
2459
2460 prop = RNA_def_property(srna, "show_names", PROP_BOOLEAN, PROP_NONE);
2461 RNA_def_property_boolean_sdna(prop, nullptr, "settings.display_flag", ASSETSHELF_SHOW_NAMES);
2463 "Show Names",
2464 "Show the asset name together with the preview. Otherwise only the "
2465 "preview will be visible.");
2467
2468 prop = RNA_def_property(srna, "preview_size", PROP_INT, PROP_UNSIGNED);
2469 RNA_def_property_int_sdna(prop, nullptr, "settings.preview_size");
2470 RNA_def_property_range(prop, 32, 256);
2471 RNA_def_property_int_default_func(prop, "rna_AssetShelf_preview_size_default");
2472 RNA_def_property_ui_text(prop, "Preview Size", "Size of the asset preview thumbnails in pixels");
2474
2475 prop = RNA_def_property(srna, "search_filter", PROP_STRING, PROP_NONE);
2476 RNA_def_property_string_sdna(prop, nullptr, "settings.search_string");
2477 RNA_def_property_ui_text(prop, "Display Filter", "Filter assets by name");
2480}
2481
2483{
2484 StructRNA *srna;
2485 PropertyRNA *prop;
2486
2487 srna = RNA_def_struct(brna, "FileHandler", nullptr);
2489 "File Handler Type",
2490 "Extends functionality to operators that manages files, such as adding "
2491 "drag and drop support");
2492 RNA_def_struct_refine_func(srna, "rna_FileHandler_refine");
2494 srna, "rna_FileHandler_register", "rna_FileHandler_unregister", nullptr);
2495
2498
2499 /* registration */
2500
2501 prop = RNA_def_property(srna, "bl_idname", PROP_STRING, PROP_NONE);
2502 RNA_def_property_string_sdna(prop, nullptr, "type->idname");
2505 prop,
2506 "ID Name",
2507 "If this is set, the file handler gets a custom ID, otherwise it takes the "
2508 "name of the class used to define the file handler (for example, if the "
2509 "class name is \"OBJECT_FH_hello\", and bl_idname is not set by the "
2510 "script, then bl_idname = \"OBJECT_FH_hello\")");
2511
2512 prop = RNA_def_property(srna, "bl_import_operator", PROP_STRING, PROP_NONE);
2513 RNA_def_property_string_sdna(prop, nullptr, "type->import_operator");
2516 prop,
2517 "Operator",
2518 "Operator that can handle import for files with the extensions given in bl_file_extensions");
2519 prop = RNA_def_property(srna, "bl_export_operator", PROP_STRING, PROP_NONE);
2520 RNA_def_property_string_sdna(prop, nullptr, "type->export_operator");
2523 prop,
2524 "Operator",
2525 "Operator that can handle export for files with the extensions given in bl_file_extensions");
2526
2527 prop = RNA_def_property(srna, "bl_label", PROP_STRING, PROP_NONE);
2528 RNA_def_property_string_sdna(prop, nullptr, "type->label");
2530 RNA_def_property_ui_text(prop, "Label", "The file handler label");
2531
2532 prop = RNA_def_property(srna, "bl_file_extensions", PROP_STRING, PROP_NONE);
2533 RNA_def_property_string_sdna(prop, nullptr, "type->file_extensions_str");
2536 prop,
2537 "File Extensions",
2538 "Formatted string of file extensions supported by the file handler, each extension should "
2539 "start with a \".\" and be separated by \";\"."
2540 "\nFor Example: ``\".blend;.ble\"``");
2541
2542 PropertyRNA *parm;
2543 FunctionRNA *func;
2544
2545 func = RNA_def_function(srna, "poll_drop", nullptr);
2547 func,
2548 "If this method returns True, can be used to handle the drop of a drag-and-drop action");
2550 RNA_def_function_return(func, RNA_def_boolean(func, "is_usable", false, "", ""));
2551 parm = RNA_def_pointer(func, "context", "Context", "", "");
2553}
2554
2556{
2557 StructRNA *srna;
2558 PropertyRNA *prop;
2559
2560 srna = RNA_def_struct(brna, "LayoutPanelState", nullptr);
2561
2562 prop = RNA_def_property(srna, "is_open", PROP_BOOLEAN, PROP_NONE);
2564 RNA_def_property_ui_text(prop, "Is Open", "");
2565}
2566
2568{
2569 rna_def_ui_layout(brna);
2570 rna_def_panel(brna);
2571 rna_def_uilist(brna);
2572 rna_def_header(brna);
2573 rna_def_menu(brna);
2574 rna_def_asset_shelf(brna);
2577}
2578
2579#endif /* RNA_RUNTIME */
bScreen * CTX_wm_screen(const bContext *C)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
@ RPT_INFO
Definition BKE_report.hh:35
@ RPT_ERROR
Definition BKE_report.hh:39
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:153
@ ASSET_SHELF_TYPE_FLAG_ACTIVATE_FOR_CONTEXT_MENU
@ ASSET_SHELF_TYPE_FLAG_NO_ASSET_DRAG
@ ASSET_SHELF_TYPE_FLAG_STORE_CATALOGS_IN_PREFS
@ ASSET_SHELF_TYPE_FLAG_DEFAULT_VISIBLE
#define ASSET_SHELF_PREVIEW_SIZE_DEFAULT
SpaceType * BKE_spacetype_from_id(int spaceid)
Definition screen.cc:257
@ PANEL_TYPE_NO_HEADER
@ PANEL_TYPE_INSTANCED
@ PANEL_TYPE_DEFAULT_CLOSED
@ PANEL_TYPE_HEADER_EXPAND
#define BLI_assert_msg(a, msg)
Definition BLI_assert.h:53
A dynamically sized string ADT.
void BLI_kdtree_nd_ free(KDTree *tree)
LinkData * BLI_genericNodeN(void *data)
Definition listbase.cc:922
#define LISTBASE_FOREACH(type, var, list)
void * BLI_findstring(const ListBase *listbase, const char *id, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
Definition listbase.cc:608
void BLI_freelinkN(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:270
void void BLI_freelistN(ListBase *listbase) ATTR_NONNULL(1)
Definition listbase.cc:497
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:111
void BLI_insertlinkafter(ListBase *listbase, void *vprevlink, void *vnewlink) ATTR_NONNULL(1)
Definition listbase.cc:332
void * BLI_findptr(const struct ListBase *listbase, const void *ptr, int offset) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1)
char * STRNCPY(char(&dst)[N], const char *src)
Definition BLI_string.h:693
char * BLI_strncpy_utf8(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
#define ELEM(...)
#define STREQ(a, b)
#define RPT_(msgid)
#define BLT_I18NCONTEXT_DEFAULT_BPYRNA
@ LAYOUT_PANEL_STATE_FLAG_OPEN
@ PNL_PIN
@ PNL_POPOVER
@ UILST_FLT_EXCLUDE
@ UILST_FLT_SHOW
@ UILST_FLT_ITEM
@ UILST_FLT_ITEM_NEVER_SHOW
@ UILST_LAYOUT_COMPACT
@ UILST_LAYOUT_DEFAULT
@ ASSETSHELF_SHOW_NAMES
@ RGN_TYPE_HEADER
#define RGN_TYPE_HAS_CATEGORY_MASK
#define PNL_CATEGORY_FALLBACK
@ UILST_FLT_SORT_LOCK
@ UILST_FLT_SORT_ALPHA
@ UILST_FLT_SORT_REVERSE
struct AssetRepresentationHandle AssetRepresentationHandle
Read Guarded memory(de)allocation.
static void panel_draw(const bContext *, Panel *panel)
#define RNA_DYN_DESCR_MAX
@ PARM_PYFUNC_REGISTER_OPTIONAL
Definition RNA_types.hh:557
@ PARM_RNAPTR
Definition RNA_types.hh:547
@ PARM_REQUIRED
Definition RNA_types.hh:545
@ FUNC_NO_SELF
Definition RNA_types.hh:907
@ FUNC_REGISTER
Definition RNA_types.hh:921
@ FUNC_REGISTER_OPTIONAL
Definition RNA_types.hh:923
@ STRUCT_NO_DATABLOCK_IDPROPERTIES
Definition RNA_types.hh:970
@ STRUCT_NO_IDPROPERTIES
Definition RNA_types.hh:968
@ STRUCT_PUBLIC_NAMESPACE_INHERIT
Definition RNA_types.hh:976
int(*)(PointerRNA *ptr, void *data, bool *have_function) StructValidateFunc
Definition RNA_types.hh:985
@ PROP_FLOAT
Definition RNA_types.hh:164
@ PROP_BOOLEAN
Definition RNA_types.hh:162
@ PROP_ENUM
Definition RNA_types.hh:166
@ PROP_INT
Definition RNA_types.hh:163
@ PROP_STRING
Definition RNA_types.hh:165
@ PROP_POINTER
Definition RNA_types.hh:167
int(*)(bContext *C, PointerRNA *ptr, FunctionRNA *func, ParameterList *list) StructCallbackFunc
Definition RNA_types.hh:986
void(*)(void *data) StructFreeFunc
Definition RNA_types.hh:990
PropertyFlag
Definition RNA_types.hh:300
@ PROP_DYNAMIC
Definition RNA_types.hh:428
@ PROP_EDITABLE
Definition RNA_types.hh:306
@ PROP_ENUM_FLAG
Definition RNA_types.hh:404
@ PROP_REGISTER_OPTIONAL
Definition RNA_types.hh:412
@ PROP_NEVER_NULL
Definition RNA_types.hh:377
@ PROP_REGISTER
Definition RNA_types.hh:411
@ PROP_TEXTEDIT_UPDATE
Definition RNA_types.hh:326
@ PROP_NONE
Definition RNA_types.hh:233
@ PROP_UNSIGNED
Definition RNA_types.hh:249
#define C
Definition RandGen.cpp:29
void UI_panels_free_instanced(const bContext *C, ARegion *region)
bool UI_list_item_index_is_filtered_visible(const struct uiList *ui_list, int item_idx)
PointerRNA * UI_panel_custom_data_get(const Panel *panel)
#define WM_TOOLSYSTEM_SPACE_MASK
#define NC_WINDOW
Definition WM_types.hh:375
#define ND_REGIONS_ASSET_SHELF
Definition WM_types.hh:543
#define NC_SPACE
Definition WM_types.hh:392
BMesh const char void * data
#define offsetof(t, d)
#define str(s)
#define active
#define printf(...)
bool enabled
void * MEM_callocN(size_t len, const char *str)
Definition mallocn.cc:118
void * MEM_malloc_arrayN(size_t len, size_t size, const char *str)
Definition mallocn.cc:133
FileHandlerType * file_handler_find(StringRef idname)
void file_handler_add(std::unique_ptr< FileHandlerType > file_handler)
void file_handler_remove(FileHandlerType *file_handler)
AssetShelfType * type_find_from_idname(StringRef idname)
void type_unregister(const AssetShelfType &shelf_type)
void type_unlink(const Main &bmain, const AssetShelfType &shelf_type)
void type_register(std::unique_ptr< AssetShelfType > type)
int library_reference_to_enum_value(const AssetLibraryReference *library)
AssetLibraryReference library_reference_from_enum_value(int value)
return ret
void RNA_parameter_get(ParameterList *parms, PropertyRNA *parm, void **r_value)
int RNA_collection_length(PointerRNA *ptr, const char *name)
bool RNA_struct_available_or_report(ReportList *reports, const char *identifier)
void RNA_struct_blender_type_set(StructRNA *srna, void *blender_type)
void * RNA_struct_blender_type_get(StructRNA *srna)
void RNA_parameter_list_free(ParameterList *parms)
void RNA_parameter_set_lookup(ParameterList *parms, const char *identifier, const void *value)
const char * RNA_struct_state_owner_get()
int RNA_parameter_dynamic_length_get(ParameterList *parms, PropertyRNA *parm)
ParameterList * RNA_parameter_list_create(ParameterList *parms, PointerRNA *, FunctionRNA *func)
bool RNA_struct_bl_idname_ok_or_report(ReportList *reports, const char *identifier, const char *sep)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
void RNA_parameter_get_lookup(ParameterList *parms, const char *identifier, void **r_value)
PropertyRNA * RNA_function_find_parameter(PointerRNA *, FunctionRNA *func, const char *identifier)
PropertyRNA * rna_def_asset_library_reference_common(StructRNA *srna, const char *get, const char *set)
Definition rna_asset.cc:687
void RNA_def_property_boolean_sdna(PropertyRNA *prop, const char *structname, const char *propname, int64_t booleanbit)
PropertyRNA * RNA_def_string(StructOrFunctionRNA *cont_, const char *identifier, const char *default_value, const int maxlen, const char *ui_name, const char *ui_description)
void RNA_def_struct_refine_func(StructRNA *srna, const char *refine)
void RNA_def_property_pointer_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_struct_system_idprops_func(StructRNA *srna, const char *system_idproperties)
void RNA_def_struct_flag(StructRNA *srna, int flag)
void RNA_def_property_string_funcs(PropertyRNA *prop, const char *get, const char *length, const char *set)
void RNA_def_function_return(FunctionRNA *func, PropertyRNA *ret)
void RNA_def_property_enum_default(PropertyRNA *prop, int value)
void RNA_def_property_float_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_define_verify_sdna(bool verify)
void RNA_def_property_ui_text(PropertyRNA *prop, const char *name, const char *description)
void RNA_def_property_string_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_ui_icon(PropertyRNA *prop, int icon, int consecutive)
void RNA_def_struct_ui_text(StructRNA *srna, const char *name, const char *description)
void RNA_def_property_boolean_funcs(PropertyRNA *prop, const char *get, const char *set)
void RNA_def_struct_register_funcs(StructRNA *srna, const char *reg, const char *unreg, const char *instance)
void RNA_def_property_enum_items(PropertyRNA *prop, const EnumPropertyItem *item)
void RNA_def_struct_sdna(StructRNA *srna, const char *structname)
FunctionRNA * RNA_def_function(StructRNA *srna, const char *identifier, const char *call)
void RNA_def_property_array(PropertyRNA *prop, int length)
void RNA_def_property_range(PropertyRNA *prop, double min, double max)
PropertyRNA * RNA_def_pointer(StructOrFunctionRNA *cont_, const char *identifier, const char *type, const char *ui_name, const char *ui_description)
void RNA_def_property_string_maxlength(PropertyRNA *prop, int maxlength)
void RNA_def_property_struct_type(PropertyRNA *prop, const char *type)
void RNA_def_function_ui_description(FunctionRNA *func, const char *description)
void RNA_def_property_update(PropertyRNA *prop, int noteflag, const char *func)
PropertyRNA * RNA_def_property(StructOrFunctionRNA *cont_, const char *identifier, int type, int subtype)
void RNA_def_property_enum_funcs(PropertyRNA *prop, const char *get, const char *set, const char *item)
StructRNA * RNA_def_struct_ptr(BlenderRNA *brna, const char *identifier, StructRNA *srnafrom)
StructRNA * RNA_def_struct(BlenderRNA *brna, const char *identifier, const char *from)
void RNA_def_function_flag(FunctionRNA *func, int flag)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_struct_free_extension(StructRNA *srna, ExtensionRNA *rna_ext)
void RNA_def_property_pointer_funcs(PropertyRNA *prop, const char *get, const char *set, const char *type_fn, const char *poll)
void RNA_def_property_enum_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_property_int_funcs(PropertyRNA *prop, const char *get, const char *set, const char *range)
void RNA_def_property_string_default(PropertyRNA *prop, const char *value)
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
void RNA_struct_free(BlenderRNA *brna, StructRNA *srna)
void RNA_def_function_output(FunctionRNA *, PropertyRNA *ret)
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
void RNA_def_property_int_sdna(PropertyRNA *prop, const char *structname, const char *propname)
void RNA_def_struct_translation_context(StructRNA *srna, const char *context)
void RNA_def_property_int_default_func(PropertyRNA *prop, const char *get_default)
PropertyRNA * RNA_def_int(StructOrFunctionRNA *cont_, const char *identifier, const int default_value, const int hardmin, const int hardmax, const char *ui_name, const char *ui_description, const int softmin, const int softmax)
void RNA_def_parameter_flags(PropertyRNA *prop, PropertyFlag flag_property, ParameterFlag flag_parameter)
BlenderRNA BLENDER_RNA
void RNA_api_ui_layout(StructRNA *srna)
const EnumPropertyItem rna_enum_region_type_items[]
Definition rna_screen.cc:21
const EnumPropertyItem rna_enum_space_type_items[]
Definition rna_space.cc:73
const EnumPropertyItem rna_enum_operator_context_items[]
Definition rna_ui.cc:33
static void rna_def_header(BlenderRNA *brna)
Definition rna_ui.cc:2164
const EnumPropertyItem rna_enum_uilist_layout_type_items[]
Definition rna_ui.cc:50
blender::wm::OpCallContext wmOpCallContext
Definition rna_ui.cc:30
static void rna_def_uilist(BlenderRNA *brna)
Definition rna_ui.cc:1988
static void rna_def_asset_shelf(BlenderRNA *brna)
Definition rna_ui.cc:2312
static void rna_def_ui_layout(BlenderRNA *brna)
Definition rna_ui.cc:1663
static void rna_def_file_handler(BlenderRNA *brna)
Definition rna_ui.cc:2482
static void rna_def_menu(BlenderRNA *brna)
Definition rna_ui.cc:2223
static void rna_def_layout_panel_state(BlenderRNA *brna)
Definition rna_ui.cc:2555
static void rna_def_panel(BlenderRNA *brna)
Definition rna_ui.cc:1794
void RNA_def_ui(BlenderRNA *brna)
Definition rna_ui.cc:2567
ARegionType * next
ListBase headertypes
ListBase paneltypes
AssetLibraryReference asset_library_reference
short default_preview_size
std::string activate_operator
ExtensionRNA rna_ext
std::string drag_operator
struct AssetShelfType * type
AssetShelfSettings settings
StructRNA * srna
StructCallbackFunc call
StructFreeFunc free
FileHandlerTypeHandle * type
void(* draw)(const bContext *C, Header *header)
char idname[BKE_ST_MAXNAME]
ExtensionRNA rna_ext
HeaderType * type
void * data
struct LinkData * prev
void * last
void * first
ListBase screens
Definition BKE_main.hh:292
const char * description
bool(* poll)(const bContext *C, MenuType *mt)
ExtensionRNA rna_ext
char idname[BKE_ST_MAXNAME]
void(* draw)(const bContext *C, Menu *menu)
char owner_id[128]
char translation_context[BKE_ST_MAXNAME]
MenuType * type
ExtensionRNA rna_ext
void(* draw)(const bContext *C, Panel *panel)
short region_type
PanelType * prev
char idname[BKE_ST_MAXNAME]
bool(* poll)(const bContext *C, PanelType *pt)
short space_type
char translation_context[BKE_ST_MAXNAME]
char owner_id[128]
ListBase children
void(* draw_header_preset)(const bContext *C, Panel *panel)
PanelType * parent
void(* draw_header)(const bContext *C, Panel *panel)
PanelType * next
const char * description
struct PanelType * type
ListBase children
StructRNA * type
Definition RNA_types.hh:52
void * data
Definition RNA_types.hh:53
ListBase regiontypes
bool(* poll_drop)(const bContext *C, FileHandlerType *file_handle_type)
blender::ui::LayoutDirection local_direction() const
blender::wm::OpCallContext operator_context() const
blender::ui::LayoutAlign alignment() const
blender::ui::EmbossType emboss() const
int * items_filter_neworder
int * items_filter_flags
char idname[BKE_ST_MAXNAME]
uiListFilterItemsFunc filter_items
ExtensionRNA rna_ext
uiListDrawFilterFunc draw_filter
uiListDrawItemFunc draw_item
uiListDyn * dyn_data
struct uiListType * type
i
Definition text_draw.cc:230
uint len
void WM_main_add_notifier(uint type, void *reference)
PointerRNA * ptr
Definition wm_files.cc:4238
MenuType * WM_menutype_find(const StringRef idname, bool quiet)
bool WM_menutype_add(MenuType *mt)
void WM_menutype_freelink(MenuType *mt)
bool WM_paneltype_add(PanelType *pt)
void WM_paneltype_remove(PanelType *pt)
bool WM_uilisttype_add(uiListType *ult)
uiListType * WM_uilisttype_find(const StringRef idname, bool quiet)
const char * WM_uilisttype_list_id_get(const uiListType *ult, uiList *list)
void WM_uilisttype_remove_ptr(Main *bmain, uiListType *ult)