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