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