Blender V5.3
wm_operators.cc
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2007 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
11
12#include "UI_interface_c.hh"
13#include <algorithm>
14#include <cctype>
15#include <cerrno>
16#include <cfloat>
17#include <cstddef>
18#include <cstdio>
19#include <cstring>
20#include <sstream>
21
22#include <fmt/format.h>
23
24#ifdef WIN32
25# include "GHOST_ISystem.hh"
26#endif
27
28#include "MEM_guardedalloc.h"
29
30#include "CLG_log.h"
31
32#include "DNA_ID.h"
33#include "DNA_armature_types.h"
34#include "DNA_brush_types.h"
35#include "DNA_object_types.h"
36#include "DNA_scene_types.h"
37#include "DNA_screen_types.h"
38#include "DNA_userdef_types.h"
40
41#include "BLT_translation.hh"
42
43#include "BLI_dial_2d.hh"
44#include "BLI_listbase.hh"
46#include "BLI_math_vector_c.hh"
48#include "BLI_path_utils.hh"
49#include "BLI_string.hh"
50#include "BLI_string_utf8.hh"
51#include "BLI_time.hh"
52#include "BLI_utildefines.hh"
53
54#include "BKE_anim_data.hh"
55#include "BKE_brush.hh"
56#include "BKE_colortools.hh"
57#include "BKE_context.hh"
58#include "BKE_global.hh"
59#include "BKE_idprop.hh"
60#include "BKE_image.hh"
61#include "BKE_image_format.hh"
62#include "BKE_lib_id.hh"
63#include "BKE_lib_query.hh"
64#include "BKE_library.hh"
65#include "BKE_main.hh"
66#include "BKE_material.hh"
67#include "BKE_paint.hh"
68#include "BKE_preview_image.hh"
69#include "BKE_report.hh"
70#include "BKE_scene.hh"
71#include "BKE_screen.hh" /* #BKE_ST_MAXNAME. */
72#include "BKE_wm_runtime.hh"
73
74#include "BKE_idtype.hh"
75
76#include "BLF_api.hh"
77
78#include "GPU_immediate.hh"
79#include "GPU_immediate_util.hh"
80#include "GPU_matrix.hh"
81#include "GPU_state.hh"
82
83#include "IMB_imbuf.hh"
84#include "IMB_imbuf_types.hh"
85
86#include "ED_fileselect.hh"
87#include "ED_gpencil_legacy.hh"
88#include "ED_grease_pencil.hh"
89#include "ED_numinput.hh"
90#include "ED_screen.hh"
91#include "ED_undo.hh"
92#include "ED_view3d.hh"
93
95
96#include "RNA_access.hh"
97#include "RNA_define.hh"
98#include "RNA_enum_types.hh"
99#include "RNA_path.hh"
100#include "RNA_prototypes.hh"
101
102#include "UI_interface.hh"
103#include "UI_interface_icons.hh"
104#include "UI_interface_layout.hh"
105#include "UI_resources.hh"
106
107#include "WM_api.hh"
108#include "WM_keymap.hh"
109#include "WM_types.hh"
110
111#include "wm.hh"
112#include "wm_draw.hh"
113#include "wm_event_system.hh"
114#include "wm_event_types.hh"
115#include "wm_files.hh"
116#include "wm_window.hh"
117
118#ifdef WITH_XR_OPENXR
119# include "wm_xr.hh"
120#endif
121
122namespace blender {
123
124#define UNDOCUMENTED_OPERATOR_TIP N_("(undocumented operator)")
125
126/* -------------------------------------------------------------------- */
129
130#define OP_BL_SEP_STRING "_OT_"
131#define OP_BL_SEP_LEN 4
132
133#define OP_PY_SEP_CHAR '.'
134#define OP_PY_SEP_LEN 1
135
136/* Difference between python 'identifier' and BL/C code one ("." separator replaced by "_OT_"),
137 * and final `\0` char. */
138#define OP_MAX_PY_IDNAME (OP_MAX_TYPENAME - OP_BL_SEP_LEN + OP_PY_SEP_LEN - 1)
139
140size_t WM_operator_py_idname(char *dst, const char *src)
141{
142 const char *sep = strstr(src, OP_BL_SEP_STRING);
143 if (sep) {
144 const size_t sep_offset = size_t(sep - src);
145
146 /* NOTE: we use ASCII `tolower` instead of system `tolower`, because the
147 * latter depends on the locale, and can lead to `idname` mismatch. */
148 memcpy(dst, src, sep_offset);
149 BLI_str_tolower_ascii(dst, sep_offset);
150
151 dst[sep_offset] = OP_PY_SEP_CHAR;
152 return BLI_strncpy_rlen(dst + (sep_offset + OP_PY_SEP_LEN),
153 sep + OP_BL_SEP_LEN,
154 OP_MAX_TYPENAME - sep_offset - OP_PY_SEP_LEN) +
155 (sep_offset + OP_PY_SEP_LEN);
156 }
157 /* Should not happen but support just in case. */
158 return BLI_strncpy_rlen(dst, src, OP_MAX_TYPENAME);
159}
160
161size_t WM_operator_bl_idname(char *dst, const char *src)
162{
163 const size_t from_len = strlen(src);
164
165 const char *sep = strchr(src, OP_PY_SEP_CHAR);
166 if (sep && (from_len <= OP_MAX_PY_IDNAME)) {
167 const size_t sep_offset = size_t(sep - src);
168 memcpy(dst, src, sep_offset);
169 BLI_str_toupper_ascii(dst, sep_offset);
170
171 memcpy(dst + sep_offset, OP_BL_SEP_STRING, OP_BL_SEP_LEN);
172 BLI_strncpy(dst + sep_offset + OP_BL_SEP_LEN,
173 sep + OP_PY_SEP_LEN,
174 from_len - sep_offset - OP_PY_SEP_LEN + 1);
175 return from_len + OP_BL_SEP_LEN - OP_PY_SEP_LEN;
176 }
177 /* Should not happen but support just in case. */
178 return BLI_strncpy_rlen(dst, src, OP_MAX_TYPENAME);
179}
180
181bool WM_operator_bl_idname_is_valid(const char *idname)
182{
183 const char *sep = strstr(idname, OP_BL_SEP_STRING);
184 /* Separator missing or at string beginning/end. */
185 if ((sep == nullptr) || (sep == idname) || (sep[OP_BL_SEP_LEN] == '\0')) {
186 return false;
187 }
188
189 for (const char *ch = idname; ch < sep; ch++) {
190 if ((*ch >= 'A' && *ch <= 'Z') || (*ch >= '0' && *ch <= '9') || *ch == '_') {
191 continue;
192 }
193 return false;
194 }
195
196 for (const char *ch = sep + OP_BL_SEP_LEN; *ch; ch++) {
197 if ((*ch >= 'a' && *ch <= 'z') || (*ch >= '0' && *ch <= '9') || *ch == '_') {
198 continue;
199 }
200 return false;
201 }
202 return true;
203}
204
206 const char *idname,
207 FunctionRef<std::string()> error_prefix_fn)
208{
209 const char *ch = idname;
210 int dot = 0;
211 int i;
212 for (i = 0; *ch; i++, ch++) {
213 if ((*ch >= 'a' && *ch <= 'z') || (*ch >= '0' && *ch <= '9') || *ch == '_') {
214 /* Pass. */
215 }
216 else if (*ch == '.') {
217 if (ch == idname || (*(ch + 1) == '\0')) {
218 std::string error_prefix = error_prefix_fn();
220 reports, RPT_ERROR, "%sInvalid character at position %d", error_prefix.c_str(), i);
221 return false;
222 }
223 dot++;
224 }
225 else {
226 std::string error_prefix = error_prefix_fn();
228 reports, RPT_ERROR, "%sInvalid character at position %d", error_prefix.c_str(), i);
229 return false;
230 }
231 }
232
233 if (i > OP_MAX_PY_IDNAME) {
234 std::string error_prefix = error_prefix_fn();
235 BKE_reportf(reports,
236 RPT_ERROR,
237 "%sIdentifier too long, maximum length is %d",
238 error_prefix.c_str(),
240 return false;
241 }
242
243 if (dot != 1) {
244 std::string error_prefix = error_prefix_fn();
245 BKE_reportf(reports, RPT_ERROR, "%sMust contain 1 '.' character", error_prefix.c_str());
246 return false;
247 }
248 return true;
249}
250
252 const char *classname,
253 const char *idname)
254{
255 return operator_idname_ok_or_report_impl(reports, idname, [&]() {
256 return fmt::format(
257 "Registering operator class '{}', invalid bl_idname '{}', ", classname, idname);
258 });
259}
260
261bool WM_operator_idname_ok_or_report(ReportList *reports, const char *idname)
262{
263 return operator_idname_ok_or_report_impl(reports, idname, [&]() { return ""; });
264}
265
267 wmOperator *op,
268 const bool all_args,
269 const bool macro_args,
270 wmOperatorType *ot,
271 PointerRNA *opptr)
272{
273 char idname_py[OP_MAX_TYPENAME];
274
275 /* For building the string. */
276 std::stringstream ss;
277
278 /* Arbitrary, but can get huge string with stroke painting otherwise. */
279 int max_prop_length = 10;
280
281 WM_operator_py_idname(idname_py, ot->idname);
282 ss << "bpy.ops." << idname_py << "(";
283
284 if (op && op->macro.first()) {
285 /* Special handling for macros, else we only get default values in this case... */
286 wmOperator *opm;
287 bool first_op = true;
288
289 opm = macro_args ? op->macro.first() : nullptr;
290
291 for (; opm; opm = opm->next) {
292 PointerRNA *opmptr = opm->ptr;
293 PointerRNA opmptr_default;
294 if (opmptr == nullptr) {
295 opmptr_default = WM_operator_properties_create_ptr(opm->type);
296 opmptr = &opmptr_default;
297 }
298
299 std::string string_args = RNA_pointer_as_string_id(C, opmptr);
300 if (first_op) {
301 ss << opm->type->idname << '=' << string_args;
302 first_op = false;
303 }
304 else {
305 ss << ", " << opm->type->idname << '=' << string_args;
306 }
307
308 if (opmptr == &opmptr_default) {
309 WM_operator_properties_free(&opmptr_default);
310 }
311 }
312 }
313 else {
314 /* Only to get the original props for comparisons. */
315 PointerRNA opptr_default;
316 const bool macro_args_test = ot->macro.first() ? macro_args : true;
317
318 if (opptr == nullptr) {
319 opptr_default = WM_operator_properties_create_ptr(ot);
320 opptr = &opptr_default;
321 }
322
324 C, opptr, false, all_args, macro_args_test, max_prop_length);
325
326 if (opptr == &opptr_default) {
327 WM_operator_properties_free(&opptr_default);
328 }
329 }
330
331 ss << ')';
332
333 return ss.str();
334}
335
337 wmOperator *op,
338 const bool all_args,
339 const bool macro_args)
340{
341 return WM_operator_pystring_ex(C, op, all_args, macro_args, op->type, op->ptr);
342}
343
344std::string WM_operator_pystring_abbreviate(std::string str, int str_len_max)
345{
346 const int str_len = str.size();
347 const size_t parens_start = str.find('(');
348 if (parens_start == std::string::npos) {
349 return str;
350 }
351
352 const size_t parens_end = str.find(parens_start + 1, ')');
353 if (parens_end == std::string::npos) {
354 return str;
355 }
356
357 const int parens_len = parens_end - parens_start;
358 if (parens_len <= str_len_max) {
359 return str;
360 }
361
362 /* Truncate after the first comma. */
363 const size_t comma_first = str.find(parens_start, ',');
364 if (comma_first == std::string::npos) {
365 return str;
366 }
367 const char end_str[] = " ... )";
368 const int end_str_len = sizeof(end_str) - 1;
369
370 /* Leave a place for the first argument. */
371 const int new_str_len = (comma_first - parens_start) + 1;
372
373 if (str_len < new_str_len + parens_start + end_str_len + 1) {
374 return str;
375 }
376
377 return str.substr(0, comma_first) + end_str;
378}
379
380/* Return nullptr if no match is found. */
381#if 0
382static const char *wm_context_member_from_ptr(bContext *C, const PointerRNA *ptr, bool *r_is_id)
383{
384 /* Loop over all context items and do 2 checks
385 *
386 * - See if the pointer is in the context.
387 * - See if the pointers ID is in the context.
388 */
389
390 /* Don't get from the context store since this is normally
391 * set only for the UI and not usable elsewhere. */
392 ListBaseT<LinkData> lb = CTX_data_dir_get_ex(C, false, true, true);
393 LinkData *link;
394
395 const char *member_found = nullptr;
396 const char *member_id = nullptr;
397 bool member_found_is_id = false;
398
399 for (link = lb.first; link; link = link->next) {
400 const char *identifier = link->data;
401 PointerRNA ctx_item_ptr = {};
402 // CTX_data_pointer_get(C, identifier); /* XXX, this isn't working. */
403
404 if (!ctx_item_ptr.has_type()) {
405 continue;
406 }
407
408 if (ptr->owner_id == ctx_item_ptr.owner_id) {
409 const bool is_id = RNA_struct_is_ID(ctx_item_ptr.type);
410 if ((ptr->data == ctx_item_ptr.data) && (ptr->type == ctx_item_ptr.type)) {
411 /* Found! */
412 member_found = identifier;
413 member_found_is_id = is_id;
414 break;
415 }
416 if (is_id) {
417 /* Found a reference to this ID, so fall back to it if there is no direct reference. */
418 member_id = identifier;
419 }
420 }
421 }
422 lb.free_no_destruct();
423
424 if (member_found) {
425 *r_is_id = member_found_is_id;
426 return member_found;
427 }
428 else if (member_id) {
429 *r_is_id = true;
430 return member_id;
431 }
432 else {
433 return nullptr;
434 }
435}
436
437#else
438
439/* Use hard coded checks for now. */
440
455static const char *wm_context_member_from_ptr(const bContext *C,
456 const PointerRNA *ptr,
457 bool *r_is_id)
458{
459 const char *member_id = nullptr;
460 bool is_id = false;
461
462# define CTX_TEST_PTR_ID(C, member, idptr) \
463 { \
464 const char *ctx_member = member; \
465 PointerRNA ctx_item_ptr = CTX_data_pointer_get(C, ctx_member); \
466 if (ctx_item_ptr.owner_id == idptr) { \
467 member_id = ctx_member; \
468 is_id = true; \
469 break; \
470 } \
471 } \
472 (void)0
473
474# define CTX_TEST_PTR_ID_CAST(C, member, member_full, cast, idptr) \
475 { \
476 const char *ctx_member = member; \
477 const char *ctx_member_full = member_full; \
478 PointerRNA ctx_item_ptr = CTX_data_pointer_get(C, ctx_member); \
479 if (ctx_item_ptr.owner_id && (ID *)cast(ctx_item_ptr.owner_id) == idptr) { \
480 member_id = ctx_member_full; \
481 is_id = true; \
482 break; \
483 } \
484 } \
485 (void)0
486
487# define TEST_PTR_DATA_TYPE(member, rna_type, rna_ptr, dataptr_cmp) \
488 { \
489 const char *ctx_member = member; \
490 if (RNA_struct_is_a((rna_ptr)->type, (rna_type)) && (rna_ptr)->data == (dataptr_cmp)) { \
491 member_id = ctx_member; \
492 break; \
493 } \
494 } \
495 (void)0
496
497/* A version of #TEST_PTR_DATA_TYPE that calls `CTX_data_pointer_get_type(C, member)`. */
498# define TEST_PTR_DATA_TYPE_FROM_CONTEXT(member, rna_type, rna_ptr) \
499 { \
500 const char *ctx_member = member; \
501 if (RNA_struct_is_a((rna_ptr)->type, (rna_type)) && \
502 (rna_ptr)->data == (CTX_data_pointer_get_type(C, ctx_member, (rna_type)).data)) \
503 { \
504 member_id = ctx_member; \
505 break; \
506 } \
507 } \
508 (void)0
509
510 /* General checks (multiple ID types). */
511 if (ptr->owner_id) {
512 const ID_Type ptr_id_type = GS(ptr->owner_id->name);
513
514 /* Support break in the macros for an early exit. */
515 do {
516 /* Animation Data. */
517 if (id_type_can_have_animdata(ptr_id_type)) {
518 TEST_PTR_DATA_TYPE_FROM_CONTEXT("active_nla_track", RNA_NlaTrack, ptr);
519 TEST_PTR_DATA_TYPE_FROM_CONTEXT("active_nla_strip", RNA_NlaStrip, ptr);
520 }
521 } while (false);
522 }
523
524 /* Specific ID type checks. */
525 if (ptr->owner_id && (member_id == nullptr)) {
526
527 const ID_Type ptr_id_type = GS(ptr->owner_id->name);
528 switch (ptr_id_type) {
529 case ID_SCE: {
530 TEST_PTR_DATA_TYPE_FROM_CONTEXT("active_strip", RNA_Strip, ptr);
531
532 CTX_TEST_PTR_ID(C, "scene", ptr->owner_id);
533 break;
534 }
535 case ID_OB: {
536 TEST_PTR_DATA_TYPE_FROM_CONTEXT("active_pose_bone", RNA_PoseBone, ptr);
537
538 CTX_TEST_PTR_ID(C, "object", ptr->owner_id);
539 break;
540 }
541 /* From #rna_Main_objects_new. */
543
544 if (ptr_id_type == ID_AR) {
545 const bArmature *arm = id_cast<bArmature *>(ptr->owner_id);
546 if (arm->edbo != nullptr) {
547 TEST_PTR_DATA_TYPE("active_bone", RNA_EditBone, ptr, arm->act_edbone);
548 }
549 else {
550 TEST_PTR_DATA_TYPE("active_bone", RNA_Bone, ptr, arm->act_bone);
551 }
552 }
553
554# define ID_CAST_OBDATA(id_pt) (((Object *)(id_pt))->data)
555 CTX_TEST_PTR_ID_CAST(C, "object", "object.data", ID_CAST_OBDATA, ptr->owner_id);
556 break;
557# undef ID_CAST_OBDATA
558 }
559 case ID_MA: {
560# define ID_CAST_OBMATACT(id_pt) \
561 BKE_object_material_get(((Object *)id_pt), ((Object *)id_pt)->actcol)
563 C, "object", "object.active_material", ID_CAST_OBMATACT, ptr->owner_id);
564 break;
565# undef ID_CAST_OBMATACT
566 }
567 case ID_WO: {
568# define ID_CAST_SCENEWORLD(id_pt) (((Scene *)(id_pt))->world)
569 CTX_TEST_PTR_ID_CAST(C, "scene", "scene.world", ID_CAST_SCENEWORLD, ptr->owner_id);
570 break;
571# undef ID_CAST_SCENEWORLD
572 }
573 case ID_SCR: {
574 CTX_TEST_PTR_ID(C, "screen", ptr->owner_id);
575
576 TEST_PTR_DATA_TYPE("area", RNA_Area, ptr, CTX_wm_area(C));
577 TEST_PTR_DATA_TYPE("region", RNA_Region, ptr, CTX_wm_region(C));
578
579 SpaceLink *space_data = CTX_wm_space_data(C);
580 if (space_data != nullptr) {
581 TEST_PTR_DATA_TYPE("space_data", RNA_Space, ptr, space_data);
582
583 switch (space_data->spacetype) {
584 case SPACE_VIEW3D: {
585 const View3D *v3d = reinterpret_cast<View3D *>(space_data);
586 const View3DShading *shading = &v3d->shading;
587
588 TEST_PTR_DATA_TYPE("space_data.overlay", RNA_View3DOverlay, ptr, v3d);
589 TEST_PTR_DATA_TYPE("space_data.shading", RNA_View3DShading, ptr, shading);
590 /* Same region as #rna_SpaceView3D_region_3d_get. */
591 const ARegion *region = CTX_wm_area(C)->regionbase.last();
593 "space_data.region_3d", RNA_RegionView3D, ptr, region->regiondata);
594 break;
595 }
596 case SPACE_GRAPH: {
597 const SpaceGraph *sipo = reinterpret_cast<SpaceGraph *>(space_data);
598 const bDopeSheet *ads = sipo->ads;
599 TEST_PTR_DATA_TYPE("space_data.dopesheet", RNA_DopeSheet, ptr, ads);
600 break;
601 }
602 case SPACE_FILE: {
603 const SpaceFile *sfile = reinterpret_cast<SpaceFile *>(space_data);
605 TEST_PTR_DATA_TYPE("space_data.params", RNA_FileSelectParams, ptr, params);
606 break;
607 }
608 case SPACE_IMAGE: {
609 const SpaceImage *sima = reinterpret_cast<SpaceImage *>(space_data);
610 TEST_PTR_DATA_TYPE("space_data.overlay", RNA_SpaceImageOverlay, ptr, sima);
611 TEST_PTR_DATA_TYPE("space_data.uv_editor", RNA_SpaceUVEditor, ptr, sima);
612 break;
613 }
614 case SPACE_NLA: {
615 const SpaceNla *snla = reinterpret_cast<SpaceNla *>(space_data);
616 const bDopeSheet *ads = snla->ads;
617 TEST_PTR_DATA_TYPE("space_data.dopesheet", RNA_DopeSheet, ptr, ads);
618 break;
619 }
620 case SPACE_ACTION: {
621 const SpaceAction *sact = reinterpret_cast<SpaceAction *>(space_data);
622 const bDopeSheet *ads = &sact->ads;
623 TEST_PTR_DATA_TYPE("space_data.dopesheet", RNA_DopeSheet, ptr, ads);
624 break;
625 }
626 case SPACE_NODE: {
627 const SpaceNode *snode = reinterpret_cast<SpaceNode *>(space_data);
628 TEST_PTR_DATA_TYPE("space_data.overlay", RNA_SpaceNodeOverlay, ptr, snode);
629 break;
630 }
631 case SPACE_CLIP: {
632 const SpaceClip *sclip = reinterpret_cast<SpaceClip *>(space_data);
633 TEST_PTR_DATA_TYPE("space_data.overlay", RNA_SpaceClipOverlay, ptr, sclip);
634 break;
635 }
636 case SPACE_SEQ: {
637 const SpaceSeq *sseq = reinterpret_cast<SpaceSeq *>(space_data);
639 "space_data.preview_overlay", RNA_SequencerPreviewOverlay, ptr, sseq);
641 "space_data.timeline_overlay", RNA_SequencerTimelineOverlay, ptr, sseq);
642 TEST_PTR_DATA_TYPE("space_data.cache_overlay", RNA_SequencerCacheOverlay, ptr, sseq);
643 break;
644 }
645 }
646 }
647
648 break;
649 }
650 default:
651 break;
652 }
653# undef CTX_TEST_PTR_ID
654# undef CTX_TEST_PTR_ID_CAST
655# undef TEST_PTR_DATA_TYPE
656 }
657
658 *r_is_id = is_id;
659
660 return member_id;
661}
662#endif
663
664std::optional<std::string> WM_context_path_resolve_property_full(const bContext *C,
665 const PointerRNA *ptr,
666 PropertyRNA *prop,
667 int index)
668{
669 bool is_id;
670 const char *member_id = wm_context_member_from_ptr(C, ptr, &is_id);
671 if (!member_id) {
672 return std::nullopt;
673 }
674 std::string member_id_data_path;
675 if (is_id && !RNA_struct_is_ID(ptr->type)) {
676 std::optional<std::string> data_path = RNA_path_from_ID_to_struct(ptr);
677 if (data_path) {
678 if (prop != nullptr) {
679 std::string prop_str = RNA_path_property_py(ptr, prop, index);
680 if (prop_str[0] == '[') {
681 member_id_data_path = fmt::format("{}.{}{}", member_id, *data_path, prop_str);
682 }
683 else {
684 member_id_data_path = fmt::format("{}.{}.{}", member_id, *data_path, prop_str);
685 }
686 }
687 else {
688 member_id_data_path = fmt::format("{}.{}", member_id, *data_path);
689 }
690 }
691 }
692 else {
693 if (prop != nullptr) {
694 std::string prop_str = RNA_path_property_py(ptr, prop, index);
695 if (prop_str[0] == '[') {
696 member_id_data_path = fmt::format("{}{}", member_id, prop_str);
697 }
698 else {
699 member_id_data_path = fmt::format("{}.{}", member_id, prop_str);
700 }
701 }
702 else {
703 member_id_data_path = member_id;
704 }
705 }
706
707 return member_id_data_path;
708}
709
710std::optional<std::string> WM_context_path_resolve_full(bContext *C, const PointerRNA *ptr)
711{
712 return WM_context_path_resolve_property_full(C, ptr, nullptr, -1);
713}
714
715static std::optional<std::string> wm_prop_pystring_from_context(bContext *C,
716 PointerRNA *ptr,
717 PropertyRNA *prop,
718 int index)
719{
720 std::optional<std::string> member_id_data_path = WM_context_path_resolve_property_full(
721 C, ptr, prop, index);
722 if (!member_id_data_path.has_value()) {
723 return std::nullopt;
724 }
725 return "bpy.context." + member_id_data_path.value();
726}
727
728std::optional<std::string> WM_prop_pystring_assign(bContext *C,
729 PointerRNA *ptr,
730 PropertyRNA *prop,
731 int index)
732{
733 std::optional<std::string> lhs = C ? wm_prop_pystring_from_context(C, ptr, prop, index) :
734 std::nullopt;
735
736 if (!lhs.has_value()) {
737 /* Fall back to `bpy.data.foo[id]` if we don't find in the context. */
738 if (std::optional<std::string> lhs_str = RNA_path_full_property_py(ptr, prop, index)) {
739 lhs = lhs_str;
740 }
741 else {
742 return std::nullopt;
743 }
744 }
745
746 std::string rhs = RNA_property_as_string(C, ptr, prop, index, INT_MAX);
747
748 std::string ret = fmt::format("{} = {}", lhs.value(), rhs);
749 return ret;
750}
751
753{
754 wmWindowManager *wm = G_MAIN->wm.first();
755 /* Set the ID so the context can be accessed: see #STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID. */
756 return RNA_pointer_create_discrete(wm ? &wm->id : nullptr, ot->srna, nullptr);
757}
758
760{
761 wmOperatorType *ot = WM_operatortype_find(opstring, false);
762
763 if (ot) {
765 }
766 wmWindowManager *wm = G_MAIN->wm.first();
767 /* Set the ID so the context can be accessed: see #STRUCT_NO_CONTEXT_WITHOUT_OWNER_ID. */
768 return RNA_pointer_create_discrete(wm ? &wm->id : nullptr, RNA_OperatorProperties, nullptr);
769}
770
771void WM_operator_properties_alloc(PointerRNA **ptr, IDProperty **properties, const char *opstring)
772{
773 IDProperty *tmp_properties = nullptr;
774 /* Allow passing nullptr for properties, just create the properties here then. */
775 if (properties == nullptr) {
776 properties = &tmp_properties;
777 }
778
779 if (*properties == nullptr) {
780 *properties = bke::idprop::create_group("wmOpItemProp").release();
781 }
782
783 if (*ptr == nullptr) {
784 *ptr = MEM_new<PointerRNA>("wmOpItemPtr", WM_operator_properties_create(opstring));
785 }
786
787 (*ptr)->data = *properties;
788}
789
790void WM_operator_properties_sanitize(PointerRNA *ptr, const bool no_context)
791{
792 RNA_STRUCT_BEGIN (ptr, prop) {
793 switch (RNA_property_type(prop)) {
794 case PROP_ENUM:
795 if (no_context) {
797 }
798 else {
800 }
801 break;
802 case PROP_POINTER: {
803 StructRNA *ptype = RNA_property_pointer_type(ptr, prop);
804
805 /* Recurse into operator properties. */
806 if (RNA_struct_is_a(ptype, RNA_OperatorProperties)) {
807 PointerRNA opptr = RNA_property_pointer_get(ptr, prop);
808 WM_operator_properties_sanitize(&opptr, no_context);
809 }
810 break;
811 }
812 default:
813 break;
814 }
815 }
817}
818
819bool WM_operator_properties_default(PointerRNA *ptr, const bool do_update)
820{
821 bool changed = false;
822 RNA_STRUCT_BEGIN (ptr, prop) {
823 switch (RNA_property_type(prop)) {
824 case PROP_POINTER: {
825 StructRNA *ptype = RNA_property_pointer_type(ptr, prop);
826 if (ptype != RNA_Struct) {
827 PointerRNA opptr = RNA_property_pointer_get(ptr, prop);
828 changed |= WM_operator_properties_default(&opptr, do_update);
829 }
830 break;
831 }
832 default:
833 if ((do_update == false) || (RNA_property_is_set(ptr, prop) == false)) {
834 if (RNA_property_reset(nullptr, ptr, prop, -1)) {
835 changed = true;
836 }
837 }
838 break;
839 }
840 }
842
843 return changed;
844}
845
847{
848 if (*op->ptr) {
850
851 RNA_PROP_BEGIN (op->ptr, itemptr, iterprop) {
852 PropertyRNA *prop = static_cast<PropertyRNA *>(itemptr.data);
853
854 if ((RNA_property_flag(prop) & (PROP_SKIP_SAVE | PROP_SKIP_PRESET)) == 0) {
855 const char *identifier = RNA_property_identifier(prop);
856 RNA_struct_system_idprops_unset(op->ptr, identifier);
857 }
858 }
860 }
861}
862
864{
865 IDProperty *properties = static_cast<IDProperty *>(ptr->data);
866
867 if (properties) {
868 IDP_ClearProperty(properties);
869 }
870}
871
873{
874 IDProperty *properties = static_cast<IDProperty *>(ptr->data);
875
876 if (properties) {
877 IDP_FreeProperty(properties);
878 ptr->data = nullptr; /* Just in case. */
879 }
880}
881
883
884/* -------------------------------------------------------------------- */
887
888#if 1 /* May want to disable operator remembering previous state for testing. */
889
891{
892 bool changed = false;
893 IDProperty *replaceprops = bke::idprop::create_group("wmOperatorProperties").release();
894
896
897 RNA_PROP_BEGIN (op->ptr, itemptr, iterprop) {
898 PropertyRNA *prop = static_cast<PropertyRNA *>(itemptr.data);
899 if ((RNA_property_flag(prop) & PROP_SKIP_SAVE) == 0) {
900 if (!RNA_property_is_set(op->ptr, prop)) { /* Don't override a setting already set. */
901 const char *identifier = RNA_property_identifier(prop);
902 IDProperty *idp_src = IDP_GetPropertyFromGroup(last_properties, identifier);
903 if (idp_src) {
904 IDProperty *idp_dst = IDP_CopyProperty(idp_src);
905
906 /* NOTE: in the future this may need to be done recursively,
907 * but for now RNA doesn't access nested operators. */
908 idp_dst->flag |= IDP_FLAG_GHOST;
909
910 /* Add to temporary group instead of immediate replace,
911 * because we are iterating over this group. */
912 IDP_AddToGroup(replaceprops, idp_dst);
913 changed = true;
914 }
915 }
916 }
917 }
919
920 if (changed) {
921 CLOG_DEBUG(WM_LOG_OPERATORS, "Loading previous properties for '%s'", op->type->idname);
922 }
923 IDP_MergeGroup(op->properties, replaceprops, true);
924 IDP_FreeProperty(replaceprops);
925 return changed;
926}
927
929{
930 bool changed = false;
931 if (op->type->last_properties) {
933 for (wmOperator &opm : op->macro) {
935 if (idp_src) {
936 changed |= operator_last_properties_init_impl(&opm, idp_src);
937 }
938 }
939 }
940 return changed;
941}
942
944{
945 if (op->type->last_properties) {
947 op->type->last_properties = nullptr;
948 }
949
950 if (op->properties) {
951 if (!op->properties->data.group.is_empty()) {
952 CLOG_DEBUG(WM_LOG_OPERATORS, "Storing properties for '%s'", op->type->idname);
953 }
955 }
956
957 if (op->macro.first() != nullptr) {
958 for (wmOperator &opm : op->macro) {
959 if (opm.properties) {
960 if (op->type->last_properties == nullptr) {
961 op->type->last_properties = bke::idprop::create_group("wmOperatorProperties").release();
962 }
963 IDProperty *idp_macro = IDP_CopyProperty(opm.properties);
964 STRNCPY(idp_macro->name, opm.type->idname);
965 IDP_ReplaceInGroup(op->type->last_properties, idp_macro);
966 }
967 }
968 }
969
970 return (op->type->last_properties != nullptr);
971}
972
973#else
974
975bool WM_operator_last_properties_init(wmOperator * /*op*/)
976{
977 return false;
978}
979
981{
982 return false;
983}
984
985#endif
986
988
989/* -------------------------------------------------------------------- */
992
994{
995 PropertyRNA *wait_to_deselect_prop = RNA_struct_find_property(op->ptr,
996 "wait_to_deselect_others");
997 const bool use_select_on_click = RNA_struct_property_is_set(op->ptr, "use_select_on_click");
998 const short init_event_type = short(POINTER_AS_INT(op->customdata));
999
1000 /* Get settings from RNA properties for operator. */
1001 const int mval[2] = {RNA_int_get(op->ptr, "mouse_x"), RNA_int_get(op->ptr, "mouse_y")};
1002
1003 if (init_event_type == 0) {
1004 op->customdata = POINTER_FROM_INT(int(event->type));
1005
1006 if (use_select_on_click) {
1007 /* Don't do any selection yet. Wait to see if there's a drag or click (release) event. */
1010 }
1011
1012 if (event->val == KM_PRESS) {
1013 RNA_property_boolean_set(op->ptr, wait_to_deselect_prop, true);
1014
1015 wmOperatorStatus retval = op->type->exec(C, op);
1016 OPERATOR_RETVAL_CHECK(retval);
1017
1018 if (retval & OPERATOR_RUNNING_MODAL) {
1020 }
1021 return retval | OPERATOR_PASS_THROUGH;
1022 }
1023 /* If we are in init phase, and cannot validate init of modal operations,
1024 * just fall back to basic exec.
1025 */
1026 RNA_property_boolean_set(op->ptr, wait_to_deselect_prop, false);
1027
1028 wmOperatorStatus retval = op->type->exec(C, op);
1029 OPERATOR_RETVAL_CHECK(retval);
1030
1031 return retval | OPERATOR_PASS_THROUGH;
1032 }
1033 if (event->type == init_event_type && event->val == KM_RELEASE) {
1034 RNA_property_boolean_set(op->ptr, wait_to_deselect_prop, false);
1035
1036 wmOperatorStatus retval = op->type->exec(C, op);
1037 OPERATOR_RETVAL_CHECK(retval);
1038
1039 return retval | OPERATOR_PASS_THROUGH;
1040 }
1041 if (ISMOUSE_MOTION(event->type)) {
1042 const int drag_delta[2] = {
1043 mval[0] - event->mval[0],
1044 mval[1] - event->mval[1],
1045 };
1046 /* If user moves mouse more than defined threshold, we consider select operator as
1047 * finished. Otherwise, it is still running until we get an 'release' event. In any
1048 * case, we pass through event, but select op is not finished yet. */
1049 if (WM_event_drag_test_with_delta(event, drag_delta)) {
1051 }
1052 /* Important not to return anything other than PASS_THROUGH here,
1053 * otherwise it prevents underlying drag detection code to work properly. */
1054 return OPERATOR_PASS_THROUGH;
1055 }
1056
1058}
1059
1061{
1062 ARegion *region = CTX_wm_region(C);
1063
1064 int mval[2];
1065 WM_event_drag_start_mval(event, region, mval);
1066
1067 RNA_int_set(op->ptr, "mouse_x", mval[0]);
1068 RNA_int_set(op->ptr, "mouse_y", mval[1]);
1069
1071
1072 wmOperatorStatus retval = op->type->modal(C, op, event);
1073 OPERATOR_RETVAL_CHECK(retval);
1074 return retval;
1075}
1076
1078{
1079 if (op->flag & OP_IS_INVOKE) {
1080 Scene *scene = CTX_data_scene(C);
1081 View3D *v3d = CTX_wm_view3d(C);
1082
1083 const float dia = v3d ? ED_view3d_grid_scale(scene, v3d, nullptr) :
1084 ED_scene_grid_scale(scene, nullptr);
1085
1086 /* Always run, so the values are initialized,
1087 * otherwise we may get differ behavior when `dia != 1.0`. */
1088 RNA_STRUCT_BEGIN (op->ptr, prop) {
1089 if (RNA_property_type(prop) == PROP_FLOAT) {
1091 if (pstype == PROP_DISTANCE) {
1092 /* We don't support arrays yet. */
1093 BLI_assert(RNA_property_array_check(prop) == false);
1094 /* Initialize. */
1095 if (!RNA_property_is_set_ex(op->ptr, prop, false)) {
1096 const float value = RNA_property_float_get_default(op->ptr, prop) * dia;
1097 RNA_property_float_set(op->ptr, prop, value);
1098 }
1099 }
1100 }
1101 }
1103 }
1104}
1105
1107{
1108 return (op->flag & OP_IS_INVOKE && !(U.uiflag & USER_REDUCE_MOTION)) ? U.smooth_viewtx : 0;
1109}
1110
1112{
1113 PropertyRNA *prop = op->type->prop;
1114
1115 if (prop == nullptr) {
1116 CLOG_ERROR(WM_LOG_OPERATORS, "'%s' has no enum property set", op->type->idname);
1117 }
1118 else if (RNA_property_type(prop) != PROP_ENUM) {
1120 "'%s', '%s' is not an enum property",
1121 op->type->idname,
1123 }
1124 else if (RNA_property_is_set(op->ptr, prop)) {
1125 const wmOperatorStatus retval = op->type->exec(C, op);
1126 OPERATOR_RETVAL_CHECK(retval);
1127 return retval;
1128 }
1129 else {
1131 C, WM_operatortype_name(op->type, op->ptr).c_str(), ICON_NONE);
1132 ui::Layout &layout = *popup_menu_layout(pup);
1133 /* Set this so the default execution context is the same as submenus. */
1134 layout.operator_context_set(opcontext);
1135 layout.op_enum(op->type->idname,
1137 static_cast<IDProperty *>(op->ptr->data),
1138 opcontext,
1139 UI_ITEM_NONE);
1140 popup_menu_end(C, pup);
1141 return OPERATOR_INTERFACE;
1142 }
1143
1144 return OPERATOR_CANCELLED;
1145}
1146
1151
1153 wmOperator *op; /* The operator that will be executed when selecting an item. */
1154};
1155
1157static ui::Block *wm_enum_search_menu(bContext *C, ARegion *region, void *arg)
1158{
1159 EnumSearchMenu *search_menu = static_cast<EnumSearchMenu *>(arg);
1160 wmWindow *win = CTX_wm_window(C);
1161 wmOperator *op = search_menu->op;
1162 /* `template_ID` uses `4 * widget_unit` for width,
1163 * we use a bit more, some items may have a suffix to show. */
1164 const int width = ui::searchbox_size_x();
1165 const int height = ui::searchbox_size_y();
1166 static char search[256] = "";
1167
1168 ui::Block *block = block_begin(C, region, "_popup", ui::EmbossType::Emboss);
1170 block_theme_style_set(block, ui::BLOCK_THEME_STYLE_POPUP);
1171
1172 search[0] = '\0';
1173 ui::Button *but = uiDefSearchButO_ptr(block,
1174 op->type,
1175 static_cast<IDProperty *>(op->ptr->data),
1176 search,
1177 ICON_VIEWZOOM,
1178 sizeof(search),
1179 0,
1180 0,
1181 width,
1182 UI_UNIT_Y,
1183 "");
1184
1185 /* Fake button, it holds space for search items. */
1186 uiDefBut(
1187 block, ui::ButtonType::Label, "", 0, -height, width, height, nullptr, 0, 0, std::nullopt);
1188
1189 /* Move it downwards, mouse over button. */
1190 block_bounds_set_popup(block, UI_SEARCHBOX_BOUNDS, int2{0, -UI_UNIT_Y});
1191
1192 button_focus_on_enter_event(win, but);
1193
1194 return block;
1195}
1196
1198{
1199 static EnumSearchMenu search_menu;
1200 search_menu.op = op;
1201 /* Refreshing not supported, because operator might get freed. */
1202 const bool can_refresh = false;
1203 popup_block_invoke_ex(C, wm_enum_search_menu, &search_menu, nullptr, can_refresh);
1204 return OPERATOR_INTERFACE;
1205}
1206
1208 wmOperator *op,
1209 const char *title,
1210 const int icon,
1211 const char *message,
1212 const wm::OpCallContext /*opcontext*/)
1213{
1215 switch (icon) {
1216 case ICON_NONE:
1217 alert_icon = ui::AlertIcon::None;
1218 break;
1219 case ICON_STATUS_WARNING_FILLED:
1220 alert_icon = ui::AlertIcon::Warning;
1221 break;
1222 case ICON_QUESTION:
1223 alert_icon = ui::AlertIcon::Question;
1224 break;
1225 case ICON_STATUS_ERROR_FILLED:
1226 alert_icon = ui::AlertIcon::Error;
1227 break;
1228 case ICON_STATUS_INFO_FILLED:
1229 alert_icon = ui::AlertIcon::Info;
1230 break;
1231 }
1232 return WM_operator_confirm_ex(C, op, IFACE_(title), nullptr, IFACE_(message), alert_icon, false);
1233}
1234
1236{
1238 C, op, IFACE_(message), nullptr, IFACE_("OK"), ui::AlertIcon::None, false);
1239}
1240
1242{
1244 C, op, IFACE_(op->type->name), nullptr, IFACE_("OK"), ui::AlertIcon::None, false);
1245}
1246
1248 wmOperator *op,
1249 const wmEvent * /*event*/)
1250{
1251 const bool confirm = RNA_boolean_get(op->ptr, "confirm");
1252 if (confirm) {
1254 C, op, IFACE_(op->type->name), nullptr, IFACE_("OK"), ui::AlertIcon::None, false);
1255 }
1256 return op->type->exec(C, op);
1257}
1258
1260{
1261 if (RNA_struct_property_is_set(op->ptr, "filepath")) {
1262 return WM_operator_call_notest(C, op); /* Call exec direct. */
1263 }
1266}
1267
1269{
1270 char filepath[FILE_MAX];
1271 /* Don't nullptr check prop, this can only run on ops with a 'filepath'. */
1272 PropertyRNA *prop = RNA_struct_find_property(op->ptr, "filepath");
1273 RNA_property_string_get(op->ptr, prop, filepath);
1274 if (BKE_image_path_ext_from_imformat_ensure(filepath, sizeof(filepath), im_format)) {
1275 RNA_property_string_set(op->ptr, prop, filepath);
1276 /* NOTE: we could check for and update 'filename' here,
1277 * but so far nothing needs this. */
1278 return true;
1279 }
1280 return false;
1281}
1282
1284{
1285 if (CTX_wm_window(C) == nullptr) {
1286 return false;
1287 }
1288 return true;
1289}
1290
1291bool WM_operator_check_ui_enabled(const bContext *C, const char *idname)
1292{
1294 Scene *scene = CTX_data_scene(C);
1295
1296 return !((ED_undo_is_valid(C, idname) == false) ||
1298}
1299
1301{
1303
1304 /* Only for operators that are registered and did an undo push. */
1305 for (wmOperator &op : wm->runtime->operators.items_reversed()) {
1306 if ((op.type->flag & OPTYPE_REGISTER) && (op.type->flag & OPTYPE_UNDO)) {
1307 return &op;
1308 }
1309 }
1310
1311 return nullptr;
1312}
1313
1315{
1316 if (ot->last_properties == nullptr) {
1317 ot->last_properties = bke::idprop::create_group("wmOperatorProperties").release();
1318 }
1319 return ot->last_properties;
1320}
1321
1323{
1324 wmWindowManager *wm = G_MAIN->wm.first();
1326 *ptr = RNA_pointer_create_discrete(wm ? &wm->id : nullptr, ot->srna, props);
1327}
1328
1330{
1331 Main *bmain = CTX_data_main(C);
1332 ID *id = nullptr;
1333
1334 /* Check input variables. */
1335 if (RNA_struct_property_is_set(op->ptr, "filepath")) {
1336 const bool is_relative_path = RNA_boolean_get(op->ptr, "relative_path");
1337 char filepath[FILE_MAX];
1338 bool exists = false;
1339
1340 RNA_string_get(op->ptr, "filepath", filepath);
1341
1342 errno = 0;
1343
1344 if (idcode == ID_IM) {
1345 id = reinterpret_cast<ID *>(BKE_image_load_exists(bmain, filepath, true, &exists));
1346 }
1347 else {
1349 }
1350
1351 if (!id) {
1352 BKE_reportf(op->reports,
1353 RPT_ERROR,
1354 "Cannot read %s '%s': %s",
1356 filepath,
1357 errno ? strerror(errno) : RPT_("unsupported format"));
1358 return nullptr;
1359 }
1360
1361 if (is_relative_path) {
1362 if (exists == false) {
1363 if (idcode == ID_IM) {
1364 BLI_path_rel((id_cast<Image *>(id))->filepath, BKE_main_blendfile_path(bmain));
1365 }
1366 else {
1368 }
1369 }
1370 }
1371
1372 return id;
1373 }
1374
1376 return nullptr;
1377 }
1378
1379 /* Lookup an already existing ID. */
1381
1382 if (!id) {
1383 /* Print error with the name if the name is available. */
1384
1385 if (RNA_struct_property_is_set(op->ptr, "name")) {
1386 char name[MAX_ID_NAME - 2];
1387 RNA_string_get(op->ptr, "name", name);
1389 op->reports, RPT_ERROR, "%s '%s' not found", BKE_idtype_idcode_to_name(idcode), name);
1390 return nullptr;
1391 }
1392
1393 BKE_reportf(op->reports, RPT_ERROR, "%s not found", BKE_idtype_idcode_to_name(idcode));
1394 return nullptr;
1395 }
1396
1397 id_us_plus(id);
1398 return id;
1399}
1400
1401static void wm_block_redo_cb(bContext *C, void *arg_op, int /*arg_event*/)
1402{
1403 wmOperator *op = static_cast<wmOperator *>(arg_op);
1404
1405 if (op == WM_operator_last_redo(C)) {
1406 /* Operator was already executed once? undo & repeat. */
1408 }
1409 else {
1410 /* Operator not executed yet, call it. */
1411 ED_undo_push_op(C, op);
1413
1414 WM_operator_repeat(C, op);
1415 }
1416}
1417
1418static void wm_block_redo_cancel_cb(bContext *C, void *arg_op)
1419{
1420 wmOperator *op = static_cast<wmOperator *>(arg_op);
1421
1422 /* If operator never got executed, free it. */
1423 if (op != WM_operator_last_redo(C)) {
1424 WM_operator_free(op);
1425 }
1426}
1427
1428static ui::Block *wm_block_create_redo(bContext *C, ARegion *region, void *arg_op)
1429{
1430 wmOperator *op = static_cast<wmOperator *>(arg_op);
1431 const uiStyle *style = ui::style_get_dpi();
1432 int width = 15 * UI_UNIT_X;
1433
1434 ui::Block *block = block_begin(C, region, __func__, ui::EmbossType::Emboss);
1435 block_flag_disable(block, ui::BLOCK_LOOP);
1436 block_theme_style_set(block, ui::BLOCK_THEME_STYLE_REGULAR);
1437
1438 /* #BLOCK_NUMSELECT for layer buttons. */
1439 block_flag_enable(block,
1442
1443 /* If register is not enabled, the operator gets freed on #OPERATOR_FINISHED
1444 * ui_apply_but_funcs_after calls #ED_undo_operator_repeat_cb and crashes. */
1446
1447 block_func_handle_set(block, wm_block_redo_cb, arg_op);
1448 popup_dummy_panel_set(region, block, op->idname);
1449 ui::Layout &layout = ui::block_layout(block,
1452 0,
1453 0,
1454 width,
1455 UI_UNIT_Y,
1456 0,
1457 style);
1458
1459 if (op == WM_operator_last_redo(C)) {
1461 layout.enabled_set(false);
1462 }
1463 }
1464
1465 uiItemL_ex(&layout, WM_operatortype_name(op->type, op->ptr), ICON_NONE, true, false);
1467 layout.separator(0.5f);
1468
1469 ui::Layout &col = layout.column(false);
1470 uiTemplateOperatorPropertyButs(C, &col, op, ui::BUT_LABEL_ALIGN_NONE, 0);
1471
1472 block_bounds_set_popup(block, 7 * UI_SCALE_FAC, nullptr);
1473
1474 return block;
1475}
1476
1493
1494/* Only invoked by OK button in popups created with #wm_block_dialog_create(). */
1496{
1497 wmOperator *op;
1498 {
1499 /* Execute will free the operator.
1500 * In this case, wm_operator_ui_popup_cancel won't run. */
1501 op = data->op;
1502 MEM_delete(data);
1503 }
1504
1505 /* Explicitly set RETURN_OK flag, otherwise the menu might be canceled
1506 * in case WM_operator_call_ex exits/reloads the current file (#49199). */
1507
1508 popup_menu_retval_set(block, ui::RETURN_OK, true);
1509
1510 /* Get context data *after* WM_operator_call_ex
1511 * which might have closed the current file and changed context. */
1512 wmWindow *win = CTX_wm_window(C);
1513 popup_block_close(C, win, block);
1514
1515 WM_operator_call_ex(C, op, true);
1516}
1517
1518static void wm_operator_ui_popup_cancel(bContext *C, void *user_data);
1519
1520/* Only invoked by Cancel button in popups created with #wm_block_dialog_create(). */
1522{
1524 popup_menu_retval_set(block, ui::RETURN_CANCEL, true);
1525 wmWindow *win = CTX_wm_window(C);
1526 popup_block_close(C, win, block);
1527}
1528
1532static ui::Block *wm_block_dialog_create(bContext *C, ARegion *region, void *user_data)
1533{
1534 wmOpPopUp *data = static_cast<wmOpPopUp *>(user_data);
1535 wmOperator *op = data->op;
1536 const uiStyle *style = ui::style_get_dpi();
1537 const bool small = data->size == WM_POPUP_SIZE_SMALL;
1538 const short icon_size = (small ? 32 : 40) * UI_SCALE_FAC;
1539
1540 ui::Block *block = block_begin(C, region, __func__, ui::EmbossType::Emboss);
1541 block_flag_disable(block, ui::BLOCK_LOOP);
1542 block_theme_style_set(block, ui::BLOCK_THEME_STYLE_POPUP);
1543 popup_dummy_panel_set(region, block, op->idname);
1544
1545 if (data->mouse_move_quit) {
1546 block_flag_enable(block, ui::BLOCK_MOVEMOUSE_QUIT);
1547 }
1548 if (data->icon < ui::AlertIcon::None || data->icon >= ui::AlertIcon::Max) {
1550 }
1551
1552 block_flag_enable(block, ui::BLOCK_KEEP_OPEN | ui::BLOCK_NUMSELECT | ui::BLOCK_POPUP);
1553
1554 ui::fontstyle_set(&style->widget);
1555 /* Width based on the text lengths. */
1556 int text_width = std::max(
1557 120 * UI_SCALE_FAC,
1558 BLF_width(style->widget.uifont_id, data->title.c_str(), BLF_DRAW_STR_DUMMY_MAX));
1559
1560 /* Widen the dialog to fit message lines, wrapping lines that are longer than the maximum. */
1561 const std::string message = StringRef(data->message).trim();
1562 const int message_width_max = std::max(data->width, 30 * UI_UNIT_X);
1563 std::istringstream message_stream(message);
1564 std::string line;
1565 while (std::getline(message_stream, line)) {
1566 const int line_width = BLF_width(
1567 style->widget.uifont_id, line.c_str(), BLF_DRAW_STR_DUMMY_MAX);
1568 text_width = std::max(text_width, std::min(line_width, message_width_max));
1569 }
1570
1571 int dialog_width = std::max(text_width + int(style->columnspace * 2.5), data->width);
1572
1573 /* Adjust width if the button text is long. */
1574 const int longest_button_text = std::max(
1575 BLF_width(style->widget.uifont_id, data->confirm_text.c_str(), BLF_DRAW_STR_DUMMY_MAX),
1577 dialog_width = std::max(dialog_width, 3 * longest_button_text);
1578
1579 ui::Layout &layout = [&]() -> ui::Layout & {
1580 if (data->icon != ui::AlertIcon::None) {
1581 return *uiItemsAlertBox(block, style, dialog_width + icon_size, data->icon, icon_size);
1582 }
1583 return ui::block_layout(block,
1586 0,
1587 0,
1588 dialog_width,
1589 0,
1590 0,
1591 style);
1592 }();
1593
1594 /* Title. */
1595 if (!data->title.empty()) {
1596 uiItemL_ex(&layout, data->title, ICON_NONE, true, false);
1597
1598 /* Line under the title if there are properties but no message body. */
1599 if (data->include_properties && message.empty()) {
1601 };
1602 }
1603
1604 if (!message.empty()) {
1605 layout.separator(0.1f);
1606 layout.label_multiline(message, ICON_NONE);
1607 }
1608
1609 if (data->include_properties) {
1610 layout.separator(0.5f);
1611 uiTemplateOperatorPropertyButs(C, &layout, op, ui::BUT_LABEL_ALIGN_SPLIT_COLUMN, 0);
1612 }
1613
1614 layout.separator(small ? 0.1f : 1.8f);
1615
1616 /* Clear so the OK button is left alone. */
1617 block_func_set(block, nullptr, nullptr, nullptr);
1618
1619#ifdef _WIN32
1620 const bool windows_layout = true;
1621#else
1622 const bool windows_layout = false;
1623#endif
1624
1625 /* Check there are no active default buttons, allowing a dialog to define its own
1626 * confirmation buttons which are shown instead of these, see: #124098. */
1627 if (!block_has_active_default_button(layout.block())) {
1628 /* New column so as not to interfere with custom layouts, see: #26436. */
1629 ui::Layout &col = layout.column(false);
1630 ui::Block *col_block = col.block();
1631 ui::Button *confirm_but;
1632 ui::Button *cancel_but;
1633
1634 /* Right align buttons in wide dialogs, instead of stretching them. Same width as the
1635 * buttons in the unsaved changes dialog. */
1636 const int buttons_width_max = std::max(18 * UI_UNIT_X, 3 * longest_button_text);
1637 ui::Layout *buttons_layout = &col;
1638 if (dialog_width > buttons_width_max) {
1639 ui::Layout &buttons_split = col.split(1.0f - float(buttons_width_max) / float(dialog_width),
1640 false);
1641 buttons_split.column(false);
1642 buttons_layout = &buttons_split.column(false);
1643 }
1644
1645 ui::Layout &split = buttons_layout->split(0.0f, true);
1646 split.scale_y_set(small ? 1.0f : 1.2f);
1647
1648 if (windows_layout) {
1649 confirm_but = uiDefBut(col_block,
1651 data->confirm_text.c_str(),
1652 0,
1653 0,
1654 0,
1655 UI_UNIT_Y,
1656 nullptr,
1657 0,
1658 0,
1659 "");
1660 split.column(false);
1661 }
1662
1663 cancel_but = uiDefBut(
1664 col_block, ui::ButtonType::But, IFACE_("Cancel"), 0, 0, 0, UI_UNIT_Y, nullptr, 0, 0, "");
1665
1666 if (!windows_layout) {
1667 split.column(false);
1668 confirm_but = uiDefBut(col_block,
1670 data->confirm_text.c_str(),
1671 0,
1672 0,
1673 0,
1674 UI_UNIT_Y,
1675 nullptr,
1676 0,
1677 0,
1678 "");
1679 }
1680
1681 button_func_set(confirm_but,
1682 [data, col_block](bContext &C) { dialog_exec_cb(&C, data, col_block); });
1683 button_func_set(cancel_but,
1684 [data, col_block](bContext &C) { dialog_cancel_cb(&C, data, col_block); });
1685 button_flag_enable((data->cancel_default) ? cancel_but : confirm_but, ui::BUT_ACTIVE_DEFAULT);
1686 }
1687
1688 const int padding = (small ? 7 : 14) * UI_SCALE_FAC;
1689
1690 if (data->position == WM_POPUP_POSITION_MOUSE) {
1691 const float button_center_x = windows_layout ? -0.4f : -0.90f;
1692 const float button_center_y = small ? 2.0f : 3.1f;
1693 const int bounds_offset[2] = {int(button_center_x * layout.width()),
1694 int(button_center_y * UI_UNIT_X)};
1695 block_bounds_set_popup(block, padding, bounds_offset);
1696 }
1697 else if (data->position == WM_POPUP_POSITION_CENTER) {
1698 block_bounds_set_centered(block, padding);
1699 }
1700
1701 return block;
1702}
1703
1704static ui::Block *wm_operator_ui_create(bContext *C, ARegion *region, void *user_data)
1705{
1706 wmOpPopUp *data = static_cast<wmOpPopUp *>(user_data);
1707 wmOperator *op = data->op;
1708 const uiStyle *style = ui::style_get_dpi();
1709
1710 ui::Block *block = block_begin(C, region, __func__, ui::EmbossType::Emboss);
1711 block_flag_disable(block, ui::BLOCK_LOOP);
1712 block_flag_enable(block, ui::BLOCK_KEEP_OPEN | ui::BLOCK_MOVEMOUSE_QUIT | ui::BLOCK_POPUP);
1713 if (data->use_numselect) {
1714 block_flag_enable(block, ui::BLOCK_NUMSELECT);
1715 }
1716 block_theme_style_set(block, ui::BLOCK_THEME_STYLE_REGULAR);
1717
1718 popup_dummy_panel_set(region, block, op->idname);
1719
1720 ui::Layout &layout = ui::block_layout(
1721 block, ui::LayoutDirection::Vertical, ui::LayoutType::Panel, 0, 0, data->width, 0, 0, style);
1722
1723 /* Since UI is defined the auto-layout args are not used. */
1724 uiTemplateOperatorPropertyButs(C, &layout, op, ui::BUT_LABEL_ALIGN_COLUMN, 0);
1725
1726 block_func_set(block, nullptr, nullptr, nullptr);
1727
1728 block_bounds_set_popup(block, 6 * UI_SCALE_FAC, nullptr);
1729
1730 return block;
1731}
1732
1733static void wm_operator_ui_popup_cancel(bContext *C, void *user_data)
1734{
1735 wmOpPopUp *data = static_cast<wmOpPopUp *>(user_data);
1736 wmOperator *op = data->op;
1737
1738 if (op) {
1739 if (op->type->cancel) {
1740 op->type->cancel(C, op);
1741 }
1742
1743 if (data->free_op) {
1744 WM_operator_free(op);
1745 }
1746 }
1747
1748 MEM_delete(data);
1749}
1750
1751static void wm_operator_ui_popup_ok(bContext *C, void *arg, int retval)
1752{
1753 wmOpPopUp *data = static_cast<wmOpPopUp *>(arg);
1754 wmOperator *op = data->op;
1755
1756 if (op && retval > 0) {
1757 WM_operator_call_ex(C, op, true);
1758 }
1759
1760 MEM_delete(data);
1761}
1762
1764 wmOperator *op,
1765 const char *title,
1766 const char *message,
1767 const char *confirm_text,
1768 ui::AlertIcon icon,
1769 bool cancel_default)
1770{
1771 wmOpPopUp *data = MEM_new<wmOpPopUp>(__func__);
1772 data->op = op;
1773
1774 /* Larger dialog needs a wider minimum width to balance with the big icon. */
1775 const float min_width = (message == nullptr) ? 180.0f : 230.0f;
1776 data->width = int(min_width * UI_SCALE_FAC * ui::style_get()->widget.points /
1778
1779 data->free_op = true;
1780 data->title = (title == nullptr) ? WM_operatortype_name(op->type, op->ptr) : title;
1781 data->message = (message == nullptr) ? std::string() : message;
1782 data->confirm_text = (confirm_text == nullptr) ? IFACE_("OK") : confirm_text;
1783 data->icon = icon;
1784 data->size = (message == nullptr) ? WM_POPUP_SIZE_SMALL : WM_POPUP_SIZE_LARGE;
1785 data->position = (message == nullptr) ? WM_POPUP_POSITION_MOUSE : WM_POPUP_POSITION_CENTER;
1786 data->cancel_default = cancel_default;
1787 data->mouse_move_quit = (message == nullptr) ? true : false;
1788 data->include_properties = false;
1789
1790 popup_block_ex(
1792
1794}
1795
1797 wmOperator *op,
1798 int width,
1799 const bool use_numselect)
1800{
1801 wmOpPopUp *data = MEM_new<wmOpPopUp>(__func__);
1802 data->op = op;
1803 data->width = width * UI_SCALE_FAC;
1804 data->use_numselect = use_numselect;
1805 data->free_op = true; /* If this runs and gets registered we may want not to free it. */
1806 popup_block_ex(C, wm_operator_ui_create, nullptr, wm_operator_ui_popup_cancel, data, op);
1808}
1809
1816 bContext *C,
1817 wmOperator *op,
1818 const bool do_call,
1819 const bool do_redo,
1820 std::optional<std::string> title = std::nullopt,
1821 std::optional<std::string> confirm_text = std::nullopt,
1822 const bool cancel_default = false,
1823 std::optional<std::string> message = std::nullopt)
1824{
1825 if ((op->type->flag & OPTYPE_REGISTER) == 0) {
1826 BKE_reportf(op->reports,
1827 RPT_ERROR,
1828 "Operator '%s' does not have register enabled, incorrect invoke function",
1829 op->type->idname);
1830 return OPERATOR_CANCELLED;
1831 }
1832
1833 if (do_redo) {
1834 if ((op->type->flag & OPTYPE_UNDO) == 0) {
1835 BKE_reportf(op->reports,
1836 RPT_ERROR,
1837 "Operator '%s' does not have undo enabled, incorrect invoke function",
1838 op->type->idname);
1839 return OPERATOR_CANCELLED;
1840 }
1841 }
1842
1843 /* If we don't have global undo, we can't do undo push for automatic redo,
1844 * so we require manual OK clicking in this popup. */
1845 if (!do_redo || !(U.uiflag & USER_GLOBALUNDO)) {
1847 C, op, 300, title, confirm_text, cancel_default, message);
1848 }
1849
1850 popup_block_ex(C, wm_block_create_redo, nullptr, wm_block_redo_cancel_cb, op, op);
1851
1852 if (do_call) {
1853 wm_block_redo_cb(C, op, 0);
1854 }
1855
1857}
1858
1860 wmOperator *op,
1861 const wmEvent * /*event*/,
1862 std::optional<std::string> title,
1863 std::optional<std::string> confirm_text,
1864 const bool cancel_default,
1865 std::optional<std::string> message)
1866{
1868 C, op, false, false, title, confirm_text, cancel_default, message);
1869}
1870
1872 wmOperator *op,
1873 const wmEvent * /*event*/)
1874{
1875 return wm_operator_props_popup_ex(C, op, false, false, {}, {});
1876}
1877
1879 wmOperator *op,
1880 const wmEvent * /*event*/)
1881{
1882 return wm_operator_props_popup_ex(C, op, true, true);
1883}
1884
1886{
1887 return wm_operator_props_popup_ex(C, op, false, true);
1888}
1889
1891 wmOperator *op,
1892 int width,
1893 std::optional<std::string> title,
1894 std::optional<std::string> confirm_text,
1895 const bool cancel_default,
1896 std::optional<std::string> message,
1897 const bool show_icon)
1898{
1899 wmOpPopUp *data = MEM_new<wmOpPopUp>(__func__);
1900 data->op = op;
1901 data->width = int(float(width) * UI_SCALE_FAC * ui::style_get()->widget.points /
1903 data->free_op = true; /* If this runs and gets registered we may want not to free it. */
1904 data->title = title ? std::move(*title) : WM_operatortype_name(op->type, op->ptr);
1905 data->confirm_text = confirm_text ? std::move(*confirm_text) : IFACE_("OK");
1906 data->message = message ? std::move(*message) : std::string();
1907 data->icon = show_icon ? ui::AlertIcon::Info : ui::AlertIcon::None;
1908 data->size = (show_icon || message) ? WM_POPUP_SIZE_LARGE : WM_POPUP_SIZE_SMALL;
1909 data->position = (message) ? WM_POPUP_POSITION_CENTER : WM_POPUP_POSITION_MOUSE;
1910 data->cancel_default = cancel_default;
1911 data->mouse_move_quit = false;
1912 data->include_properties = true;
1913
1914 /* The operator is not executed until popup OK button is clicked. */
1915 popup_block_ex(
1917
1919}
1920
1922{
1923 /* `CTX_wm_reports(C)` because operator is on stack, not active in event system. */
1924 if ((op->type->flag & OPTYPE_REGISTER) == 0) {
1926 RPT_ERROR,
1927 "Operator redo '%s' does not have register enabled, incorrect invoke function",
1928 op->type->idname);
1929 return OPERATOR_CANCELLED;
1930 }
1931 if (op->type->poll && op->type->poll(C) == 0) {
1933 CTX_wm_reports(C), RPT_ERROR, "Operator redo '%s': wrong context", op->type->idname);
1934 return OPERATOR_CANCELLED;
1935 }
1936
1937 /* Operator is stored and kept alive in the window manager. So passing a pointer to the UI is
1938 * fine, it will remain valid. */
1940
1941 return OPERATOR_CANCELLED;
1942}
1943
1945
1946/* -------------------------------------------------------------------- */
1949
1950#ifdef WITH_INPUT_IME
1951std::optional<wmOperatorStatus> WM_operator_IME_insert_maybe(bContext *C,
1952 wmOperator *op,
1953 const wmEvent *event,
1954 const char *prop_id)
1955{
1956 const wmWindow *win = CTX_wm_window(C);
1957 if (win == nullptr) {
1958 return std::nullopt;
1959 }
1960 if (IS_EVENT_IME_ANY(event->type)) {
1961 /* Keep the composition preview current, including #WM_IME_COMPOSITE_END which must
1962 * erase it (canceling inserts no text so nothing else redraws). */
1964 }
1965 if (event->type == WM_IME_COMPOSITE_EVENT) {
1966 const wmIMEData *ime_data = win->runtime->ime_data;
1967 if (ime_data && !ime_data->result.empty()) {
1968 RNA_string_set(op->ptr, prop_id, ime_data->result.c_str());
1969 return op->type->exec(C, op);
1970 }
1971 }
1972 if (win->runtime->ime_data_is_composing) {
1973 return OPERATOR_CANCELLED;
1974 }
1975 return std::nullopt;
1976}
1977
1978std::optional<wmOperatorStatus> WM_operator_IME_edit_maybe(const bContext *C)
1979{
1980 const wmWindow *win = CTX_wm_window(C);
1981 if (win && win->runtime->ime_data_is_composing) {
1982 return OPERATOR_CANCELLED;
1983 }
1984 return std::nullopt;
1985}
1986#endif /* WITH_INPUT_IME */
1987
1989
1990/* -------------------------------------------------------------------- */
1995
1997{
1998 G.debug_value = RNA_int_get(op->ptr, "debug_value");
2001
2002 return OPERATOR_FINISHED;
2003}
2004
2006 wmOperator *op,
2007 const wmEvent * /*event*/)
2008{
2009 RNA_int_set(op->ptr, "debug_value", G.debug_value);
2010 return WM_operator_props_dialog_popup(C, op, 250, IFACE_("Set Debug Value"), IFACE_("Set"));
2011}
2012
2014{
2015 ot->name = "Debug Menu";
2016 ot->idname = "WM_OT_debug_menu";
2017 ot->description = "Open a popup to set the debug level";
2018
2022
2023 ot->prop = RNA_def_int(
2024 ot->srna, "debug_value", 0, SHRT_MIN, SHRT_MAX, "Debug Value", "", -10000, 10000);
2025}
2026
2028
2029/* -------------------------------------------------------------------- */
2032
2034{
2035 PointerRNA ptr = CTX_data_pointer_get_type(C, "active_operator", RNA_Operator);
2036
2037 if (!ptr) {
2038 BKE_report(op->reports, RPT_ERROR, "No operator in context");
2039 return OPERATOR_CANCELLED;
2040 }
2041
2042 WM_operator_properties_reset(static_cast<wmOperator *>(ptr.data));
2043 return OPERATOR_FINISHED;
2044}
2045
2046/* Used by operator preset menu. pre-2.65 this was a 'Reset' button. */
2048{
2049 ot->name = "Restore Operator Defaults";
2050 ot->idname = "WM_OT_operator_defaults";
2051 ot->description = "Set the active operator to its default values";
2052
2054
2055 ot->flag = OPTYPE_INTERNAL;
2056}
2057
2059
2060/* -------------------------------------------------------------------- */
2063
2069
2075
2076static char g_search_text[256] = "";
2077
2078static ui::Block *wm_block_search_menu(bContext *C, ARegion *region, void *userdata)
2079{
2080 const SearchPopupInit_Data *init_data = static_cast<const SearchPopupInit_Data *>(userdata);
2081
2082 ui::Block *block = block_begin(C, region, "_popup", ui::EmbossType::Emboss);
2084 block_theme_style_set(block, ui::BLOCK_THEME_STYLE_POPUP);
2085
2086 ui::Button *but = uiDefSearchBut(block,
2088 ICON_VIEWZOOM,
2089 sizeof(g_search_text),
2090 0,
2091 0,
2092 init_data->size[0],
2093 UI_UNIT_Y,
2094 "");
2095
2096 if (init_data->search_type == SEARCH_TYPE_OPERATOR) {
2097 button_func_operator_search(but);
2098 }
2099 else if (init_data->search_type == SEARCH_TYPE_MENU) {
2100 button_func_menu_search(but);
2101 }
2102 else if (init_data->search_type == SEARCH_TYPE_SINGLE_MENU) {
2103 button_func_menu_search(but, init_data->single_menu_idname.c_str());
2104 button_flag_enable(but, ui::BUT_ACTIVATE_ON_INIT_NO_SELECT);
2105 }
2106 else {
2108 }
2109
2110 button_flag_enable(but, ui::BUT_ACTIVATE_ON_INIT);
2111
2112 /* Fake button, it holds space for search items. */
2113 const int height = init_data->size[1] - UI_SEARCHBOX_BOUNDS;
2114 uiDefBut(block,
2116 "",
2117 0,
2118 -height,
2119 init_data->size[0],
2120 height,
2121 nullptr,
2122 0,
2123 0,
2124 std::nullopt);
2125
2126 /* Move it downwards, mouse over button. */
2127 block_bounds_set_popup(block, UI_SEARCHBOX_BOUNDS, int2{0, -UI_UNIT_Y});
2128
2129 return block;
2130}
2131
2133{
2134 return OPERATOR_FINISHED;
2135}
2136
2138{
2139 /* Exception for launching via space-bar. */
2140 if (event->type == EVT_SPACEKEY) {
2141 bool ok = true;
2142 ScrArea *area = CTX_wm_area(C);
2143 if (area) {
2144 if (area->spacetype == SPACE_CONSOLE) {
2145 /* So we can use the shortcut in the console. */
2146 ok = false;
2147 }
2148 else if (area->spacetype == SPACE_TEXT) {
2149 /* So we can use the space-bar in the text editor. */
2150 ok = false;
2151 }
2152 }
2153 else {
2154 Object *editob = CTX_data_edit_object(C);
2155 if (editob && editob->type == OB_FONT) {
2156 /* So we can use the space-bar for entering text. */
2157 ok = false;
2158 }
2159 }
2160 if (!ok) {
2161 return OPERATOR_PASS_THROUGH;
2162 }
2163 }
2164
2165 SearchType search_type;
2166 if (STREQ(op->type->idname, "WM_OT_search_menu")) {
2167 search_type = SEARCH_TYPE_MENU;
2168 }
2169 else if (STREQ(op->type->idname, "WM_OT_search_single_menu")) {
2170 search_type = SEARCH_TYPE_SINGLE_MENU;
2171 }
2172 else {
2173 search_type = SEARCH_TYPE_OPERATOR;
2174 }
2175
2176 static SearchPopupInit_Data data{};
2177
2178 if (search_type == SEARCH_TYPE_SINGLE_MENU) {
2179 data.single_menu_idname = RNA_string_get(op->ptr, "menu_idname");
2180
2181 std::string buffer = RNA_string_get(op->ptr, "initial_query");
2182 STRNCPY(g_search_text, buffer.c_str());
2183 }
2184 else {
2185 g_search_text[0] = '\0';
2186 }
2187
2188 data.search_type = search_type;
2189 data.size[0] = ui::searchbox_size_x() * 2;
2190 data.size[1] = ui::searchbox_size_y();
2191
2192 popup_block_invoke_ex(C, wm_block_search_menu, &data, nullptr, false);
2193
2194 return OPERATOR_INTERFACE;
2195}
2196
2198{
2199 ot->name = "Search Menu";
2200 ot->idname = "WM_OT_search_menu";
2201 ot->description = "Pop-up a search over all menus in the current context";
2202
2206}
2207
2209{
2210 ot->name = "Search Operator";
2211 ot->idname = "WM_OT_search_operator";
2212 ot->description = "Pop-up a search over all available operators in current context";
2213
2217}
2218
2220{
2221 ot->name = "Search Single Menu";
2222 ot->idname = "WM_OT_search_single_menu";
2223 ot->description = "Pop-up a search for a menu in current context";
2224
2228
2229 RNA_def_string(ot->srna, "menu_idname", nullptr, 0, "Menu Name", "Menu to search in");
2230 RNA_def_string(ot->srna,
2231 "initial_query",
2232 nullptr,
2233 0,
2234 "Initial Query",
2235 "Query to insert into the search box");
2236}
2237
2239{
2240 char idname[BKE_ST_MAXNAME];
2241 RNA_string_get(op->ptr, "name", idname);
2242
2243 return ui::popup_menu_invoke(C, idname, op->reports);
2244}
2245
2247{
2248 char idname[BKE_ST_MAXNAME];
2249 RNA_string_get(ptr, "name", idname);
2250 MenuType *mt = WM_menutype_find(idname, true);
2251 return (mt) ? CTX_IFACE_(mt->translation_context, mt->label) :
2253}
2254
2255static std::string wm_call_menu_get_description(bContext * /*C*/,
2256 wmOperatorType * /*ot*/,
2257 PointerRNA *ptr)
2258{
2259 char idname[BKE_ST_MAXNAME];
2260 RNA_string_get(ptr, "name", idname);
2261 MenuType *mt = WM_menutype_find(idname, true);
2262 if (!mt) {
2263 return "";
2264 }
2265 if (!mt->description) {
2266 return "";
2267 }
2269}
2270
2272{
2273 ot->name = "Call Menu";
2274 ot->idname = "WM_OT_call_menu";
2275 ot->description = "Open a predefined menu";
2276
2277 ot->exec = wm_call_menu_exec;
2281
2282 ot->flag = OPTYPE_INTERNAL;
2283
2284 PropertyRNA *prop;
2285
2286 prop = RNA_def_string(ot->srna, "name", nullptr, BKE_ST_MAXNAME, "Name", "Name of the menu");
2288 prop,
2290 /* Only a suggestion as menu items may be referenced from add-ons that have been disabled. */
2292}
2293
2295{
2296 char idname[BKE_ST_MAXNAME];
2297 RNA_string_get(op->ptr, "name", idname);
2298
2299 return ui::pie_menu_invoke(C, idname, event);
2300}
2301
2303{
2304 char idname[BKE_ST_MAXNAME];
2305 RNA_string_get(op->ptr, "name", idname);
2306
2307 return ui::pie_menu_invoke(C, idname, CTX_wm_window(C)->runtime->eventstate);
2308}
2309
2311{
2312 ot->name = "Call Pie Menu";
2313 ot->idname = "WM_OT_call_menu_pie";
2314 ot->description = "Open a predefined pie menu";
2315
2320
2321 ot->flag = OPTYPE_INTERNAL;
2322
2323 PropertyRNA *prop;
2324
2325 prop = RNA_def_string(ot->srna, "name", nullptr, BKE_ST_MAXNAME, "Name", "Name of the pie menu");
2327 prop,
2329 /* Only a suggestion as menu items may be referenced from add-ons that have been disabled. */
2331}
2332
2334{
2335 char idname[BKE_ST_MAXNAME];
2336 RNA_string_get(op->ptr, "name", idname);
2337 const bool keep_open = RNA_boolean_get(op->ptr, "keep_open");
2338 const bool use_numselect = RNA_boolean_get(op->ptr, "auto_keymap");
2339
2340 return ui::popover_panel_invoke(C, idname, keep_open, use_numselect, op->reports);
2341}
2342
2344{
2345 char idname[BKE_ST_MAXNAME];
2346 RNA_string_get(ptr, "name", idname);
2347 PanelType *pt = WM_paneltype_find(idname, true);
2348 return (pt) ? CTX_IFACE_(pt->translation_context, pt->label) :
2350}
2351
2353{
2354 ot->name = "Call Panel";
2355 ot->idname = "WM_OT_call_panel";
2356 ot->description = "Open a predefined panel";
2357
2361
2362 ot->flag = OPTYPE_INTERNAL;
2363
2364 PropertyRNA *prop;
2365
2366 prop = RNA_def_string(ot->srna, "name", nullptr, BKE_ST_MAXNAME, "Name", "Name of the menu");
2368 prop,
2370 /* Only a suggestion as menu items may be referenced from add-ons that have been disabled. */
2373 prop = RNA_def_boolean(ot->srna, "keep_open", true, "Keep Open", "");
2375 prop = RNA_def_boolean(ot->srna,
2376 "auto_keymap",
2377 false,
2378 "Auto Keymap",
2379 "Assign accelerator keys to buttons, shown as underlined characters");
2381}
2382
2384 wmOperator *op,
2385 const wmEvent * /*event*/)
2386{
2387 std::string asset_shelf_id = RNA_string_get(op->ptr, "name");
2388
2389 if (!ui::asset_shelf_popover_invoke(*C, asset_shelf_id, *op->reports)) {
2391 }
2392
2393 return OPERATOR_INTERFACE;
2394}
2395
2396/* Needs to be defined at WM level to be globally accessible. */
2398{
2399 /* identifiers */
2400 ot->name = "Call Asset Shelf Popover";
2401 ot->idname = "WM_OT_call_asset_shelf_popover";
2402 ot->description = "Open a predefined asset shelf in a popup";
2403
2404 /* API callbacks. */
2406
2407 ot->flag = OPTYPE_INTERNAL;
2408
2409 RNA_def_string(ot->srna,
2410 "name",
2411 nullptr,
2412 0,
2413 "Asset Shelf Name",
2414 "Identifier of the asset shelf to display");
2415}
2416
2418
2419/* -------------------------------------------------------------------- */
2422
2428{
2429 wmWindow *win = CTX_wm_window(C);
2430 bScreen *screen;
2431
2432 if (win == nullptr) {
2433 return false;
2434 }
2435 if (!((screen = WM_window_get_active_screen(win)) && (screen->state == SCREENNORMAL))) {
2436 return false;
2437 }
2438 if (G.background) {
2439 return false;
2440 }
2441
2442 return true;
2443}
2444
2446{
2447 wmWindow *win = CTX_wm_window(C);
2448 bScreen *screen;
2449
2450 if (win == nullptr) {
2451 return false;
2452 }
2453 if (!((screen = WM_window_get_active_screen(win)) && (screen->state != SCREENFULL))) {
2454 return false;
2455 }
2456 if (G.background) {
2457 return false;
2458 }
2459
2460 return true;
2461}
2462
2463/* Included for script-access. */
2465{
2466 ot->name = "Close Window";
2467 ot->idname = "WM_OT_window_close";
2468 ot->description = "Close the current window";
2469
2472}
2473
2475{
2476 ot->name = "New Window";
2477 ot->idname = "WM_OT_window_new";
2478 ot->description = "Create a new window";
2479
2482}
2483
2485{
2486 ot->name = "New Main Window";
2487 ot->idname = "WM_OT_window_new_main";
2488 ot->description = "Create a new main window with its own workspace and scene selection";
2489
2492}
2493
2495{
2496 ot->name = "Toggle Window Fullscreen";
2497 ot->idname = "WM_OT_window_fullscreen_toggle";
2498 ot->description = "Toggle the current window full-screen";
2499
2502}
2503
2509
2511 wmOperator * /*op*/,
2512 const wmEvent * /*event*/)
2513{
2514 if (U.uiflag & USER_SAVE_PROMPT) {
2516 }
2517 else {
2519 }
2520 return OPERATOR_FINISHED;
2521}
2522
2524{
2525 ot->name = "Quit Blender";
2526 ot->idname = "WM_OT_quit_blender";
2527 ot->description = "Quit Blender";
2528
2531}
2532
2534
2535/* -------------------------------------------------------------------- */
2538
2539#if defined(WIN32)
2540
2541static wmOperatorStatus wm_console_toggle_exec(bContext * /*C*/, wmOperator * /*op*/)
2542{
2543 GHOST_ISystem *ghost_system = GHOST_ISystem::getSystem();
2545 return OPERATOR_FINISHED;
2546}
2547
2548static void WM_OT_console_toggle(wmOperatorType *ot)
2549{
2550 /* XXX Have to mark these for xgettext, as under linux they do not exists... */
2551 ot->name = CTX_N_(BLT_I18NCONTEXT_OPERATOR_DEFAULT, "Toggle System Console");
2552 ot->idname = "WM_OT_console_toggle";
2553 ot->description = N_("Toggle System Console");
2554
2555 ot->exec = wm_console_toggle_exec;
2556 ot->poll = WM_operator_winactive;
2557}
2558
2559#endif
2560
2562
2563/* -------------------------------------------------------------------- */
2571
2573 short region_type,
2574 wmPaintCursorPoll poll,
2576 void *customdata)
2577{
2578 wmWindowManager *wm = G_MAIN->wm.first();
2579
2580 wmPaintCursor *pc = MEM_new_zeroed<wmPaintCursor>("paint cursor");
2581
2582 BLI_addtail(&wm->runtime->paintcursors, pc);
2583
2584 pc->customdata = customdata;
2585 pc->poll = poll;
2586 pc->draw = draw;
2587
2588 pc->space_type = space_type;
2589 pc->region_type = region_type;
2590
2591 return pc;
2592}
2593
2595{
2596 wmWindowManager *wm = G_MAIN->wm.first();
2597 for (wmPaintCursor &pc : wm->runtime->paintcursors) {
2598 if (&pc == handle) {
2599 BLI_remlink(&wm->runtime->paintcursors, &pc);
2600 MEM_delete(&pc);
2601 return true;
2602 }
2603 }
2604 return false;
2605}
2606
2608 wmPaintCursorDraw draw_fn,
2609 void (*free)(void *))
2610{
2611 for (wmPaintCursor &pc : wm->runtime->paintcursors.items_mutable()) {
2612 if (pc.draw == draw_fn) {
2613 if (free) {
2614 free(pc.customdata);
2615 }
2616 BLI_remlink(&wm->runtime->paintcursors, &pc);
2617 MEM_delete(&pc);
2618 }
2619 }
2620}
2621
2623
2624/* -------------------------------------------------------------------- */
2627
2628#define WM_RADIAL_CONTROL_DISPLAY_SIZE (200 * UI_SCALE_FAC)
2629#define WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE (35 * UI_SCALE_FAC)
2630#define WM_RADIAL_CONTROL_DISPLAY_WIDTH \
2631 (WM_RADIAL_CONTROL_DISPLAY_SIZE - WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE)
2632#define WM_RADIAL_MAX_STR 10
2633
2639 PropertyRNA *prop = nullptr;
2647 float initial_value = 0.0f;
2648 float current_value = 0.0f;
2649 float min_value = 0.0f;
2650 float max_value = 0.0f;
2651 /* Original screen space coordinates that the operator started on. */
2652 int initial_co[2] = {};
2653 /* Modified value of #initial_co to simplify calculating new values. */
2655 int slow_mouse[2] = {};
2656 bool slow_mode = false;
2657 bool snap = false;
2658 Dial *dial = nullptr;
2660 ListBaseT<wmPaintCursor> orig_paintcursors = {};
2661 bool use_secondary_tex = false;
2662 void *cursor = nullptr;
2664 int init_event = 0;
2665};
2666
2668{
2669 RadialControl *rc = static_cast<RadialControl *>(op->customdata);
2670 char msg[UI_MAX_DRAW_STR];
2671 ScrArea *area = CTX_wm_area(C);
2672 Scene *scene = CTX_data_scene(C);
2673
2674 if (hasNumInput(&rc->num_input)) {
2675 char num_str[NUM_STR_REP_LEN];
2676 outputNumInput(&rc->num_input, num_str, scene->unit);
2677 SNPRINTF(msg, "%s: %s", RNA_property_ui_name(rc->prop), num_str);
2678 }
2679 else {
2680 const char *ui_name = RNA_property_ui_name(rc->prop);
2681 switch (rc->subtype) {
2682 case PROP_NONE:
2683 case PROP_DISTANCE:
2685 SNPRINTF(msg, "%s: %0.4f", ui_name, rc->current_value);
2686 break;
2687 case PROP_PIXEL:
2689 SNPRINTF(msg, "%s: %d", ui_name, int(rc->current_value)); /* XXX: round to nearest? */
2690 break;
2691 case PROP_PERCENTAGE:
2692 SNPRINTF(msg, "%s: %3.1f%%", ui_name, rc->current_value);
2693 break;
2694 case PROP_FACTOR:
2695 SNPRINTF(msg, "%s: %1.3f", ui_name, rc->current_value);
2696 break;
2697 case PROP_ANGLE:
2698 SNPRINTF(msg, "%s: %3.2f", ui_name, RAD2DEGF(rc->current_value));
2699 break;
2700 default:
2701 STRNCPY(msg, ui_name); /* XXX: No value? */
2702 break;
2703 }
2704 }
2705
2706 ED_area_status_text(area, msg);
2707}
2708
2710{
2711 float d[2] = {0, 0};
2712 float zoom[2] = {1, 1};
2713
2715 copy_v2_v2_int(rc->initial_co, event->xy);
2716
2717 switch (rc->subtype) {
2718 case PROP_NONE:
2719 case PROP_DISTANCE:
2720 case PROP_PIXEL:
2721 d[0] = rc->initial_value;
2722 break;
2725 d[0] = rc->initial_value / 2.0f;
2726 break;
2727 case PROP_PERCENTAGE:
2728 d[0] = (rc->initial_value) / 100.0f * WM_RADIAL_CONTROL_DISPLAY_WIDTH +
2730 break;
2731 case PROP_FACTOR:
2734 break;
2735 case PROP_ANGLE:
2738 break;
2739 default:
2740 return;
2741 }
2742
2743 if (rc->zoom_prop) {
2745 d[0] *= zoom[0];
2746 d[1] *= zoom[1];
2747 }
2748
2749 rc->initial_radial_center[0] -= d[0];
2750 rc->initial_radial_center[1] -= d[1];
2751}
2752
2754{
2755 ImBuf *ibuf;
2756
2757 switch (RNA_type_to_ID_code(rc->image_id_ptr.type)) {
2758 case ID_BR:
2759 if ((ibuf = BKE_brush_gen_radial_control_imbuf(static_cast<Brush *>(rc->image_id_ptr.data),
2761 !ELEM(rc->subtype,
2762 PROP_NONE,
2763 PROP_PIXEL,
2767 {
2768
2769 rc->texture = GPU_texture_create_2d("radial_control",
2770 ibuf->x,
2771 ibuf->y,
2772 1,
2773 gpu::TextureFormat::UNORM_8,
2775 ibuf->float_data());
2776
2778 GPU_texture_swizzle_set(rc->texture, "111r");
2779
2780 IMB_freeImBuf(ibuf);
2781 }
2782 break;
2783 default:
2784 break;
2785 }
2786}
2787
2788static void radial_control_paint_tex(RadialControl *rc, float radius, float alpha)
2789{
2790
2791 /* Set fill color. */
2792 float col[3] = {0, 0, 0};
2793 if (rc->fill_col_prop) {
2794 PointerRNA *fill_ptr;
2795 PropertyRNA *fill_prop;
2796
2797 if (rc->fill_col_override_prop &&
2799 {
2800 fill_ptr = &rc->fill_col_override_ptr;
2801 fill_prop = rc->fill_col_override_prop;
2802 }
2803 else {
2804 fill_ptr = &rc->fill_col_ptr;
2805 fill_prop = rc->fill_col_prop;
2806 }
2807
2808 RNA_property_float_get_array(fill_ptr, fill_prop, col);
2809 }
2810
2811 GPUVertFormat *format = immVertexFormat();
2812 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
2813
2814 if (rc->texture) {
2815 uint texCoord = GPU_vertformat_attr_add(format, "texCoord", gpu::VertAttrType::SFLOAT_32_32);
2816
2817 /* Set up rotation if available. */
2818 if (rc->rot_prop) {
2819 float rot = RNA_property_float_get(&rc->rot_ptr, rc->rot_prop);
2822 }
2823
2825
2826 immUniformColor3fvAlpha(col, alpha);
2827 immBindTexture("image", rc->texture);
2828
2829 /* Draw textured quad. */
2831
2832 immAttr2f(texCoord, 0, 0);
2833 immVertex2f(pos, -radius, -radius);
2834
2835 immAttr2f(texCoord, 1, 0);
2836 immVertex2f(pos, radius, -radius);
2837
2838 immAttr2f(texCoord, 1, 1);
2839 immVertex2f(pos, radius, radius);
2840
2841 immAttr2f(texCoord, 0, 1);
2842 immVertex2f(pos, -radius, radius);
2843
2844 immEnd();
2845
2847
2848 /* Undo rotation. */
2849 if (rc->rot_prop) {
2851 }
2852 }
2853 else {
2854 /* Flat color if no texture available. */
2856 immUniformColor3fvAlpha(col, alpha);
2857 imm_draw_circle_fill_2d(pos, 0.0f, 0.0f, radius, 40);
2858 }
2859
2861}
2862
2863static void radial_control_paint_curve(uint pos, Brush *br, float radius, int line_segments)
2864{
2865 GPU_line_width(2.0f);
2866 immUniformColor4f(0.8f, 0.8f, 0.8f, 0.85f);
2867 float step = (radius * 2.0f) / float(line_segments);
2869 immBegin(GPU_PRIM_LINES, line_segments * 2);
2870 for (int i = 0; i < line_segments; i++) {
2871 float h1 = BKE_brush_curve_strength_clamped(br, fabsf((i * step) - radius), radius);
2872 immVertex2f(pos, -radius + (i * step), h1 * radius);
2873 float h2 = BKE_brush_curve_strength_clamped(br, fabsf(((i + 1) * step) - radius), radius);
2874 immVertex2f(pos, -radius + ((i + 1) * step), h2 * radius);
2875 }
2876 immEnd();
2877}
2878
2880 const int2 & /*xy*/,
2881 const float2 & /*tilt*/,
2882 void *customdata)
2883{
2884 RadialControl *rc = static_cast<RadialControl *>(customdata);
2885 const uiStyle *style = ui::style_get();
2886 const uiFontStyle *fstyle = &style->widget;
2887 const int fontid = fstyle->uifont_id;
2888 short fstyle_points = fstyle->points;
2889 char str[WM_RADIAL_MAX_STR];
2890 short strdrawlen = 0;
2891 float strwidth, strheight;
2892 float r1 = 0.0f, r2 = 0.0f, rmin = 0.0, tex_radius, alpha;
2893 float zoom[2], col[4] = {1.0f, 1.0f, 1.0f, 1.0f};
2894 float text_color[4];
2895
2896 switch (rc->subtype) {
2897 case PROP_NONE:
2898 case PROP_DISTANCE:
2899 case PROP_PIXEL:
2900 r1 = rc->current_value;
2901 r2 = rc->initial_value;
2902 tex_radius = r1;
2903 alpha = 0.75;
2904 break;
2907 r1 = rc->current_value / 2.0f;
2908 r2 = rc->initial_value / 2.0f;
2909 tex_radius = r1;
2910 alpha = 0.75;
2911 break;
2912 case PROP_PERCENTAGE:
2915 r2 = tex_radius = WM_RADIAL_CONTROL_DISPLAY_SIZE;
2917 SNPRINTF(str, "%3.1f%%", rc->current_value);
2918 strdrawlen = BLI_strlen_utf8(str);
2919 tex_radius = r1;
2920 alpha = 0.75;
2921 break;
2922 case PROP_FACTOR:
2925 r2 = tex_radius = WM_RADIAL_CONTROL_DISPLAY_SIZE;
2927 alpha = rc->current_value / 2.0f + 0.5f;
2928 SNPRINTF(str, "%1.3f", rc->current_value);
2929 strdrawlen = BLI_strlen_utf8(str);
2930 break;
2931 case PROP_ANGLE:
2932 r1 = r2 = tex_radius = WM_RADIAL_CONTROL_DISPLAY_SIZE;
2933 alpha = 0.75;
2935 SNPRINTF(str, "%3.2f", RAD2DEGF(rc->current_value));
2936 strdrawlen = BLI_strlen_utf8(str);
2937 break;
2938 default:
2939 tex_radius = WM_RADIAL_CONTROL_DISPLAY_SIZE; /* NOTE: this is a dummy value. */
2940 alpha = 0.75;
2941 break;
2942 }
2943
2944 int x, y;
2945 if (rc->subtype == PROP_ANGLE) {
2946 /* Use the initial mouse position to draw the rotation preview. This avoids starting the
2947 * rotation in a random direction. */
2948 x = rc->initial_radial_center[0];
2949 y = rc->initial_radial_center[1];
2950 }
2951 else {
2952 /* Keep cursor in the original place. */
2953 x = rc->initial_co[0];
2954 y = rc->initial_co[1];
2955 }
2956 GPU_matrix_translate_2f(float(x), float(y));
2957
2959 GPU_line_smooth(true);
2960
2961 /* Apply zoom if available. */
2962 if (rc->zoom_prop) {
2965 }
2966
2967 /* Draw rotated texture. */
2968 radial_control_paint_tex(rc, tex_radius, alpha);
2969
2970 /* Set line color. */
2971 if (rc->col_prop) {
2973 }
2974
2975 GPUVertFormat *format = immVertexFormat();
2976 uint pos = GPU_vertformat_attr_add(format, "pos", gpu::VertAttrType::SFLOAT_32_32);
2977
2979
2980 if (rc->subtype == PROP_ANGLE) {
2982
2983 /* Draw original angle line. */
2984 GPU_matrix_rotate_3f(RAD2DEGF(rc->initial_value), 0.0f, 0.0f, 1.0f);
2988 immEnd();
2989
2990 /* Draw new angle line. */
2991 GPU_matrix_rotate_3f(RAD2DEGF(rc->current_value - rc->initial_value), 0.0f, 0.0f, 1.0f);
2995 immEnd();
2996
2998 }
2999
3000 bool draw_rounded_box = false;
3001 float roundness = 1.0f;
3002 float tip_scale_x = 1.0f;
3003 if (RNA_type_to_ID_code(rc->image_id_ptr.type) == ID_BR && rc->prop &&
3004 STREQ(RNA_property_identifier(rc->prop), "size"))
3005 {
3006 const Brush *br = static_cast<const Brush *>(rc->image_id_ptr.data);
3007 if (br) {
3009 draw_rounded_box = BKE_brush_has_cube_tip(br, paint_mode);
3010 roundness = br->tip_roundness;
3011 tip_scale_x = br->tip_scale_x;
3012 }
3013 }
3014
3015 /* Draw circles on top. */
3016 GPU_line_width(2.0f);
3017 immUniformColor3fvAlpha(col, 0.8f);
3018 if (draw_rounded_box) {
3020 0,
3021 0,
3022 float2(r1, r1 * tip_scale_x),
3023 float2(r1 * roundness, r1 * roundness * tip_scale_x),
3024 80);
3025 }
3026 else {
3027 imm_draw_circle_wire_2d(pos, 0.0f, 0.0f, r1, 80);
3028 }
3029
3030 GPU_line_width(1.0f);
3031 immUniformColor3fvAlpha(col, 0.5f);
3032 if (draw_rounded_box) {
3034 0,
3035 0,
3036 float2(r2, r2 * tip_scale_x),
3037 float2(r2 * roundness, r2 * roundness * tip_scale_x),
3038 80);
3039 }
3040 else {
3041 imm_draw_circle_wire_2d(pos, 0.0f, 0.0f, r2, 80);
3042 }
3043 if (rmin > 0.0f) {
3044 /* Inner fill circle to increase the contrast of the value. */
3045 const float black[3] = {0.0f};
3046 immUniformColor3fvAlpha(black, 0.2f);
3047 imm_draw_circle_fill_2d(pos, 0.0, 0.0f, rmin, 80);
3048
3049 immUniformColor3fvAlpha(col, 0.5f);
3050 imm_draw_circle_wire_2d(pos, 0.0, 0.0f, rmin, 80);
3051 }
3052
3053 /* Draw curve falloff preview. */
3055 Brush *br = static_cast<Brush *>(rc->image_id_ptr.data);
3056 if (br) {
3057 radial_control_paint_curve(pos, br, r2, 120);
3058 }
3059 }
3060
3062
3063 BLF_size(fontid, 1.75f * fstyle_points * UI_SCALE_FAC);
3065 BLF_color4fv(fontid, text_color);
3066
3067 /* Draw value. */
3068 BLF_width_and_height(fontid, str, strdrawlen, &strwidth, &strheight);
3069 BLF_position(fontid, -0.5f * strwidth, -0.5f * strheight, 0.0f);
3070 BLF_draw(fontid, str, strdrawlen);
3071
3073 GPU_line_smooth(false);
3074}
3075
3081
3088 wmOperator *op,
3089 const char *name,
3090 PointerRNA *r_ptr,
3091 PropertyRNA **r_prop,
3092 int req_length,
3093 RCPropFlags flags)
3094{
3095 PropertyRNA *unused_prop;
3096
3097 /* Check flags. */
3098 if ((flags & RC_PROP_REQUIRE_BOOL) && (flags & RC_PROP_REQUIRE_FLOAT)) {
3099 BKE_report(op->reports, RPT_ERROR, "Property cannot be both boolean and float");
3100 return 0;
3101 }
3102
3103 /* Get an rna string path from the operator's properties. */
3104 std::string str = RNA_string_get(op->ptr, name);
3105 if (str.empty()) {
3106 if (r_prop) {
3107 *r_prop = nullptr;
3108 }
3109 return 1;
3110 }
3111
3112 if (!r_prop) {
3113 r_prop = &unused_prop;
3114 }
3115
3116 /* Get rna from path. */
3117 if (!RNA_path_resolve(ctx_ptr, str.c_str(), r_ptr, r_prop)) {
3118 if (flags & RC_PROP_ALLOW_MISSING) {
3119 return 1;
3120 }
3121 BKE_reportf(op->reports, RPT_ERROR, "Could not resolve path '%s'", name);
3122 return 0;
3123 }
3124
3125 /* Check property type. */
3127 PropertyType prop_type = RNA_property_type(*r_prop);
3128
3129 if (((flags & RC_PROP_REQUIRE_BOOL) && (prop_type != PROP_BOOLEAN)) ||
3130 ((flags & RC_PROP_REQUIRE_FLOAT) && (prop_type != PROP_FLOAT)))
3131 {
3132 BKE_reportf(op->reports, RPT_ERROR, "Property from path '%s' is not a float", name);
3133 return 0;
3134 }
3135 }
3136
3137 /* Check property's array length. */
3138 int len;
3139 if (*r_prop && (len = RNA_property_array_length(r_ptr, *r_prop)) != req_length) {
3140 BKE_reportf(op->reports,
3141 RPT_ERROR,
3142 "Property from path '%s' has length %d instead of %d",
3143 name,
3144 len,
3145 req_length);
3146 return 0;
3147 }
3148
3149 /* Success. */
3150 return 1;
3151}
3152
3153/* Initialize the rna pointers and properties using rna paths. */
3155{
3156 RadialControl *rc = static_cast<RadialControl *>(op->customdata);
3157
3158 PointerRNA ctx_ptr = RNA_pointer_create_discrete(nullptr, RNA_Context, C);
3159
3160 /* Check if we use primary or secondary path. */
3161 PointerRNA use_secondary_ptr;
3162 PropertyRNA *use_secondary_prop = nullptr;
3163 if (!radial_control_get_path(&ctx_ptr,
3164 op,
3165 "use_secondary",
3166 &use_secondary_ptr,
3167 &use_secondary_prop,
3168 0,
3170 {
3171 return 0;
3172 }
3173
3174 const char *data_path;
3175 if (use_secondary_prop && RNA_property_boolean_get(&use_secondary_ptr, use_secondary_prop)) {
3176 data_path = "data_path_secondary";
3177 }
3178 else {
3179 data_path = "data_path_primary";
3180 }
3181
3182 if (!radial_control_get_path(&ctx_ptr, op, data_path, &rc->ptr, &rc->prop, 0, RCPropFlags(0))) {
3183 return 0;
3184 }
3185
3186 /* Data path is required. */
3187 if (!rc->prop) {
3188 return 0;
3189 }
3190
3192 &ctx_ptr, op, "rotation_path", &rc->rot_ptr, &rc->rot_prop, 0, RC_PROP_REQUIRE_FLOAT))
3193 {
3194 return 0;
3195 }
3196
3198 &ctx_ptr, op, "color_path", &rc->col_ptr, &rc->col_prop, 4, RC_PROP_REQUIRE_FLOAT))
3199 {
3200 return 0;
3201 }
3202
3203 if (!radial_control_get_path(&ctx_ptr,
3204 op,
3205 "fill_color_path",
3206 &rc->fill_col_ptr,
3207 &rc->fill_col_prop,
3208 3,
3210 {
3211 return 0;
3212 }
3213
3214 if (!radial_control_get_path(&ctx_ptr,
3215 op,
3216 "fill_color_override_path",
3219 3,
3221 {
3222 return 0;
3223 }
3224 if (!radial_control_get_path(&ctx_ptr,
3225 op,
3226 "fill_color_override_test_path",
3229 0,
3231 {
3232 return 0;
3233 }
3234
3235 /* Slightly ugly; allow this property to not resolve correctly.
3236 * Needed because 3d texture paint shares the same key-map as 2d image paint. */
3237 if (!radial_control_get_path(&ctx_ptr,
3238 op,
3239 "zoom_path",
3240 &rc->zoom_ptr,
3241 &rc->zoom_prop,
3242 2,
3244 {
3245 return 0;
3246 }
3247
3249 &ctx_ptr, op, "image_id", &rc->image_id_ptr, nullptr, 0, RCPropFlags(0)))
3250 {
3251 return 0;
3252 }
3253 if (rc->image_id_ptr) {
3254 /* Extra check, pointer must be to an ID. */
3256 BKE_report(op->reports, RPT_ERROR, "Pointer from path image_id is not an ID");
3257 return 0;
3258 }
3259 }
3260
3261 rc->use_secondary_tex = RNA_boolean_get(op->ptr, "secondary_tex");
3262
3263 return 1;
3264}
3265
3266static void radial_control_status(bContext *C, const RadialControl *radial_control)
3267{
3268 const char *ui_name = RNA_property_ui_name(radial_control->prop);
3269
3270 WorkspaceStatus status(C);
3271 status.item(IFACE_("Confirm"), ICON_EVENT_RETURN, ICON_MOUSE_LMB);
3272 status.item(IFACE_("Cancel"), ICON_EVENT_ESC, ICON_MOUSE_RMB);
3273 status.item(ui_name, ICON_MOUSE_MOVE);
3274 status.item_bool(IFACE_("Snap"), radial_control->snap, ICON_EVENT_CTRL);
3275 status.item_bool(IFACE_("Precision Mode"), radial_control->slow_mode, ICON_EVENT_SHIFT);
3276}
3277
3279{
3280 op->customdata = MEM_new<RadialControl>(__func__);
3281 if (!op->customdata) {
3282 return OPERATOR_CANCELLED;
3283 }
3284 RadialControl *rc = static_cast<RadialControl *>(op->customdata);
3285
3286 if (!radial_control_get_properties(C, op)) {
3287 MEM_delete(rc);
3288 return OPERATOR_CANCELLED;
3289 }
3290
3291 /* Get type, initial, min, and max values of the property. */
3292 switch (rc->type = RNA_property_type(rc->prop)) {
3293 case PROP_INT: {
3294 int value, min, max, step;
3295
3296 value = RNA_property_int_get(&rc->ptr, rc->prop);
3297 RNA_property_int_ui_range(&rc->ptr, rc->prop, &min, &max, &step);
3298
3299 rc->initial_value = value;
3300 rc->min_value = min_ii(value, min);
3301 rc->max_value = max_ii(value, max);
3302 break;
3303 }
3304 case PROP_FLOAT: {
3305 float value, min, max, step, precision;
3306
3307 value = RNA_property_float_get(&rc->ptr, rc->prop);
3308 RNA_property_float_ui_range(&rc->ptr, rc->prop, &min, &max, &step, &precision);
3309
3310 rc->initial_value = value;
3311 rc->min_value = min_ff(value, min);
3312 rc->max_value = max_ff(value, max);
3313 break;
3314 }
3315 default:
3316 BKE_report(op->reports, RPT_ERROR, "Property must be an integer or a float");
3317 MEM_delete(rc);
3318 return OPERATOR_CANCELLED;
3319 }
3320
3321 /* Initialize numerical input. */
3322 initNumInput(&rc->num_input);
3323 rc->num_input.idx_max = 0;
3327
3328 /* Get subtype of property. */
3330 if (!ELEM(rc->subtype,
3331 PROP_NONE,
3336 PROP_ANGLE,
3337 PROP_PIXEL,
3339 {
3340 BKE_report(op->reports,
3341 RPT_ERROR,
3342 "Property must be a none, distance, factor, percentage, angle, or pixel");
3343 MEM_delete(rc);
3344 return OPERATOR_CANCELLED;
3345 }
3346
3347 rc->current_value = rc->initial_value;
3350
3352
3353 /* Temporarily disable other paint cursors. */
3355 rc->orig_paintcursors = wm->runtime->paintcursors;
3356 wm->runtime->paintcursors.clear_no_delete();
3357
3358 /* Add radial control paint cursor. */
3361
3364
3366}
3367
3368static void radial_control_set_value(RadialControl *rc, float val)
3369{
3370 switch (rc->type) {
3371 case PROP_INT:
3372 RNA_property_int_set(&rc->ptr, rc->prop, val);
3373 break;
3374 case PROP_FLOAT:
3375 RNA_property_float_set(&rc->ptr, rc->prop, val);
3376 break;
3377 default:
3378 break;
3379 }
3380}
3381
3383{
3384 RadialControl *rc = static_cast<RadialControl *>(op->customdata);
3386 ScrArea *area = CTX_wm_area(C);
3387
3388 if (rc->dial) {
3389 BLI_dial_free(rc->dial);
3390 rc->dial = nullptr;
3391 }
3392
3393 ED_area_status_text(area, nullptr);
3394 ED_workspace_status_text(C, nullptr);
3395
3396 WM_paint_cursor_end(static_cast<wmPaintCursor *>(rc->cursor));
3397
3398 /* Restore original paint cursors. */
3399 wm->runtime->paintcursors = rc->orig_paintcursors;
3400
3401 /* Not sure if this is a good notifier to use;
3402 * intended purpose is to update the UI so that the
3403 * new value is displayed in sliders/number-fields. */
3405
3406 if (rc->texture != nullptr) {
3408 }
3409
3410 MEM_delete(rc);
3411}
3412
3414{
3415 RadialControl *rc = static_cast<RadialControl *>(op->customdata);
3416 float new_value, dist = 0.0f, zoom[2];
3417 float delta[2];
3419 float angle_precision = 0.0f;
3420 const bool has_numInput = hasNumInput(&rc->num_input);
3421 bool handled = false;
3422 float numValue;
3423 /* TODO: fix hard-coded events. */
3424
3425 /* Modal numinput active, try to handle numeric inputs first... */
3426 if (event->val == KM_PRESS && has_numInput && handleNumInput(C, &rc->num_input, event)) {
3427 handled = true;
3428 applyNumInput(&rc->num_input, &numValue);
3429
3430 if (rc->subtype == PROP_ANGLE) {
3431 numValue = fmod(numValue, 2.0f * float(M_PI));
3432 if (numValue < 0.0f) {
3433 numValue += 2.0f * float(M_PI);
3434 }
3435 }
3436
3437 CLAMP(numValue, rc->min_value, rc->max_value);
3438 new_value = numValue;
3439
3440 radial_control_set_value(rc, new_value);
3441 rc->current_value = new_value;
3444 }
3445
3446 handled = false;
3447 switch (event->type) {
3448 case EVT_ESCKEY:
3449 case RIGHTMOUSE:
3450 /* Canceled; restore original value. */
3451 if (rc->init_event != RIGHTMOUSE) {
3454 }
3455 break;
3456
3457 case LEFTMOUSE:
3458 case EVT_PADENTER:
3459 case EVT_RETKEY:
3460 /* Done; value already set. */
3461 /* Keep the RNA update separate from setting the value, for some properties this could lead
3462 * to a continues flickering due to invalidating the overlay texture. */
3463 RNA_property_update(C, &rc->ptr, rc->prop);
3465 break;
3466
3467 case MOUSEMOVE:
3468 if (!has_numInput) {
3469 if (rc->slow_mode) {
3470 if (rc->subtype == PROP_ANGLE) {
3471 /* Calculate the initial angle here first. */
3472 delta[0] = rc->initial_radial_center[0] - rc->slow_mouse[0];
3473 delta[1] = rc->initial_radial_center[1] - rc->slow_mouse[1];
3474
3475 /* Precision angle gets calculated from dial and gets added later. */
3476 angle_precision = -0.1f *
3477 BLI_dial_angle(rc->dial,
3478 float2{float(event->xy[0]), float(event->xy[1])});
3479 }
3480 else {
3481 delta[0] = rc->initial_radial_center[0] - rc->slow_mouse[0];
3482 delta[1] = 0.0f;
3483
3484 if (rc->zoom_prop) {
3486 delta[0] /= zoom[0];
3487 }
3488
3489 dist = len_v2(delta);
3490
3491 delta[0] = event->xy[0] - rc->slow_mouse[0];
3492
3493 if (rc->zoom_prop) {
3494 delta[0] /= zoom[0];
3495 }
3496
3497 dist = dist + 0.1f * (delta[0]);
3498 }
3499 }
3500 else {
3501 delta[0] = float(rc->initial_radial_center[0] - event->xy[0]);
3502 delta[1] = float(rc->initial_radial_center[1] - event->xy[1]);
3503 if (rc->zoom_prop) {
3505 delta[0] /= zoom[0];
3506 delta[1] /= zoom[1];
3507 }
3508 if (rc->subtype == PROP_ANGLE) {
3509 dist = len_v2(delta);
3510 }
3511 else {
3512 dist = clamp_f(-delta[0], 0.0f, FLT_MAX);
3513 }
3514 }
3515
3516 /* If modifying a "diameter" value (e.g. the paint mode radii), assume that we've
3517 * moved twice as far as we actually have to make the radius change in size in
3518 * sync with the cursor */
3520 dist *= 2.0f;
3521 }
3522
3523 /* Calculate new value and apply snapping. */
3524 switch (rc->subtype) {
3525 case PROP_NONE:
3526 case PROP_DISTANCE:
3528 case PROP_PIXEL:
3530 new_value = dist;
3531 if (rc->snap) {
3532 new_value = (int(new_value) + 5) / 10 * 10;
3533 }
3534 break;
3535 case PROP_PERCENTAGE:
3536 new_value = ((dist - WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE) /
3538 100.0f;
3539 if (rc->snap) {
3540 new_value = int(new_value + 2.5f) / 5 * 5;
3541 }
3542 break;
3543 case PROP_FACTOR:
3545 if (rc->snap) {
3546 new_value = (int(ceil(new_value * 10.0f)) * 10.0f) / 100.0f;
3547 }
3548 /* Invert new value to increase the factor moving the mouse to the right. */
3549 new_value = 1 - new_value;
3550 break;
3551 case PROP_ANGLE:
3552 new_value = atan2f(delta[1], delta[0]) + float(M_PI) + angle_precision;
3553 new_value = fmod(new_value, 2.0f * float(M_PI));
3554 if (new_value < 0.0f) {
3555 new_value += 2.0f * float(M_PI);
3556 }
3557 if (rc->snap) {
3558 new_value = DEG2RADF((int(RAD2DEGF(new_value)) + 5) / 10 * 10);
3559 }
3560 break;
3561 default:
3562 new_value = dist; /* NOTE(@ideasman42): Dummy value, should this ever happen? */
3563 break;
3564 }
3565
3566 /* Clamp and update. */
3567 CLAMP(new_value, rc->min_value, rc->max_value);
3568 radial_control_set_value(rc, new_value);
3569 rc->current_value = new_value;
3570 handled = true;
3571 break;
3572 }
3573 break;
3574
3575 case EVT_LEFTSHIFTKEY:
3576 case EVT_RIGHTSHIFTKEY: {
3577 if (event->val == KM_PRESS) {
3578 rc->slow_mouse[0] = event->xy[0];
3579 rc->slow_mouse[1] = event->xy[1];
3580 rc->slow_mode = true;
3581 if (rc->subtype == PROP_ANGLE) {
3582 const float initial_position[2] = {float(rc->initial_radial_center[0]),
3584 const float current_position[2] = {float(rc->slow_mouse[0]), float(rc->slow_mouse[1])};
3585 rc->dial = BLI_dial_init(initial_position, 0.0f);
3586 /* Immediately set the position to get a an initial direction. */
3587 BLI_dial_angle(rc->dial, current_position);
3588 }
3589 handled = true;
3590 }
3591 if (event->val == KM_RELEASE) {
3592 rc->slow_mode = false;
3593 handled = true;
3594 if (rc->dial) {
3595 BLI_dial_free(rc->dial);
3596 rc->dial = nullptr;
3597 }
3598 }
3599 break;
3600 }
3601
3602 case EVT_LEFTCTRLKEY:
3603 case EVT_RIGHTCTRLKEY: {
3604 if (event->val == KM_PRESS) {
3605 rc->snap = true;
3606 handled = true;
3607 }
3608 if (event->val == KM_RELEASE) {
3609 rc->snap = false;
3610 handled = true;
3611 }
3612 }
3613 default: {
3614 break;
3615 }
3616 }
3617
3618 /* Modal numinput inactive, try to handle numeric inputs last... */
3619 if (!handled && event->val == KM_PRESS && handleNumInput(C, &rc->num_input, event)) {
3620 applyNumInput(&rc->num_input, &numValue);
3621
3622 if (rc->subtype == PROP_ANGLE) {
3623 numValue = fmod(numValue, 2.0f * float(M_PI));
3624 if (numValue < 0.0f) {
3625 numValue += 2.0f * float(M_PI);
3626 }
3627 }
3628
3629 CLAMP(numValue, rc->min_value, rc->max_value);
3630 new_value = numValue;
3631
3632 radial_control_set_value(rc, new_value);
3633
3634 rc->current_value = new_value;
3637 }
3638
3639 if (!handled && (event->val == KM_RELEASE) && (rc->init_event == event->type) &&
3640 RNA_boolean_get(op->ptr, "release_confirm"))
3641 {
3642 /* Keep the RNA update separate from setting the value, for some properties this could lead to
3643 * a continues flickering due to invalidating the overlay texture. */
3644 RNA_property_update(C, &rc->ptr, rc->prop);
3646 }
3647
3650
3651 if (ret & OPERATOR_FINISHED) {
3653 if (wm->op_undo_depth == 0) {
3654 ID *id = rc->ptr.owner_id;
3655 std::optional<UndoEncodeHints> undo_hints_or_none =
3657 if (undo_hints_or_none) {
3658 ED_undo_push(C, op->type->name, *undo_hints_or_none);
3659 }
3660 }
3661 }
3662
3663 if (ret != OPERATOR_RUNNING_MODAL) {
3665 }
3666
3667 if (ret == OPERATOR_RUNNING_MODAL) {
3669 }
3670 return ret;
3671}
3672
3674{
3675 ot->name = "Radial Control";
3676 ot->idname = "WM_OT_radial_control";
3677 ot->description = "Set some size property (e.g. brush size) with mouse wheel";
3678
3682
3684
3685 /* All paths relative to the context. */
3686 PropertyRNA *prop;
3687 prop = RNA_def_string(ot->srna,
3688 "data_path_primary",
3689 nullptr,
3690 0,
3691 "Primary Data Path",
3692 "Primary path of property to be set by the radial control");
3694
3695 prop = RNA_def_string(ot->srna,
3696 "data_path_secondary",
3697 nullptr,
3698 0,
3699 "Secondary Data Path",
3700 "Secondary path of property to be set by the radial control");
3702
3703 prop = RNA_def_string(ot->srna,
3704 "use_secondary",
3705 nullptr,
3706 0,
3707 "Use Secondary",
3708 "Path of property to select between the primary and secondary data paths");
3710
3711 prop = RNA_def_string(ot->srna,
3712 "rotation_path",
3713 nullptr,
3714 0,
3715 "Rotation Path",
3716 "Path of property used to rotate the texture display");
3718
3719 prop = RNA_def_string(ot->srna,
3720 "color_path",
3721 nullptr,
3722 0,
3723 "Color Path",
3724 "Path of property used to set the color of the control");
3726
3727 prop = RNA_def_string(ot->srna,
3728 "fill_color_path",
3729 nullptr,
3730 0,
3731 "Fill Color Path",
3732 "Path of property used to set the fill color of the control");
3734
3735 prop = RNA_def_string(
3736 ot->srna, "fill_color_override_path", nullptr, 0, "Fill Color Override Path", "");
3738 prop = RNA_def_string(
3739 ot->srna, "fill_color_override_test_path", nullptr, 0, "Fill Color Override Test", "");
3741
3742 prop = RNA_def_string(ot->srna,
3743 "zoom_path",
3744 nullptr,
3745 0,
3746 "Zoom Path",
3747 "Path of property used to set the zoom level for the control");
3749
3750 prop = RNA_def_string(ot->srna,
3751 "image_id",
3752 nullptr,
3753 0,
3754 "Image ID",
3755 "Path of ID that is used to generate an image for the control");
3757
3758 prop = RNA_def_boolean(
3759 ot->srna, "secondary_tex", false, "Secondary Texture", "Tweak brush secondary/mask texture");
3761
3762 prop = RNA_def_boolean(
3763 ot->srna, "release_confirm", false, "Confirm On Release", "Finish operation on key release");
3765}
3766
3768
3769/* -------------------------------------------------------------------- */
3774
3775/* Uses no type defines, fully local testing function anyway. */
3776
3778{
3779 wmWindow *win = CTX_wm_window(C);
3780 bScreen *screen = CTX_wm_screen(C);
3781
3782 CTX_wm_region_popup_set(C, nullptr);
3783
3784 for (ScrArea &area : screen->areabase) {
3785 ED_area_tag_redraw(&area);
3786 }
3788
3789 CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
3790}
3791
3792enum {
3800};
3801
3803 {eRTDrawRegion, "DRAW", 0, "Draw Region", "Draw region"},
3804 {eRTDrawRegionSwap, "DRAW_SWAP", 0, "Draw Region & Swap", "Draw region and swap"},
3805 {eRTDrawWindow, "DRAW_WIN", 0, "Draw Window", "Draw window"},
3806 {eRTDrawWindowSwap, "DRAW_WIN_SWAP", 0, "Draw Window & Swap", "Draw window and swap"},
3807 {eRTAnimationStep, "ANIM_STEP", 0, "Animation Step", "Animation steps"},
3808 {eRTAnimationPlay, "ANIM_PLAY", 0, "Animation Play", "Animation playback"},
3809 {eRTUndo, "UNDO", 0, "Undo/Redo", "Undo and redo"},
3810 {0, nullptr, 0, nullptr, nullptr},
3811};
3812
3814 Scene *scene,
3815 Depsgraph *depsgraph,
3816 wmWindow *win,
3817 ScrArea *area,
3818 ARegion *region,
3819 const int type,
3820 const int cfra,
3821 const int steps_done,
3822 const int steps_total)
3823{
3824 if (type == eRTDrawRegion) {
3825 if (region) {
3826 wm_draw_region_test(C, area, region);
3827 }
3828 }
3829 else if (type == eRTDrawRegionSwap) {
3830 CTX_wm_region_popup_set(C, nullptr);
3831
3832 ED_region_tag_redraw(region);
3834
3835 CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
3836 }
3837 else if (type == eRTDrawWindow) {
3838 bScreen *screen = WM_window_get_active_screen(win);
3839
3840 CTX_wm_region_popup_set(C, nullptr);
3841
3842 for (ScrArea &area_iter : screen->areabase) {
3843 CTX_wm_area_set(C, &area_iter);
3844 for (ARegion &region_iter : area_iter.regionbase) {
3845 if (!region_iter.runtime->visible) {
3846 continue;
3847 }
3848 CTX_wm_region_set(C, &region_iter);
3849 wm_draw_region_test(C, &area_iter, &region_iter);
3850 }
3851 }
3852
3853 CTX_wm_window_set(C, win); /* XXX context manipulation warning! */
3854
3855 CTX_wm_area_set(C, area);
3856 CTX_wm_region_set(C, region);
3857 }
3858 else if (type == eRTDrawWindowSwap) {
3860 }
3861 else if (type == eRTAnimationStep) {
3862 scene->r.cfra += (cfra == scene->r.cfra) ? 1 : -1;
3864 }
3865 else if (type == eRTAnimationPlay) {
3866 /* Play anim, return on same frame as started with. */
3867 int tot = (scene->r.efra - scene->r.sfra) + 1;
3868 const int frames_total = tot * steps_total;
3869 int frames_done = tot * steps_done;
3870
3871 while (tot--) {
3872 WM_progress_set(win, float(frames_done) / float(frames_total));
3873 frames_done++;
3874
3875 /* TODO: ability to escape! */
3876 scene->r.cfra++;
3877 if (scene->r.cfra > scene->r.efra) {
3878 scene->r.cfra = scene->r.sfra;
3879 }
3880
3883 }
3884 }
3885 else { /* #eRTUndo. */
3886 /* Undo and redo, including depsgraph update since that can be a
3887 * significant part of the cost. */
3888 ED_undo_pop(C);
3890 ED_undo_redo(C);
3892 }
3893}
3894
3896{
3897 /* Check background mode as many of these actions use redrawing.
3898 * NOTE(@ideasman42): if it's useful to support undo or animation step this could
3899 * be allowed at the moment this seems like a corner case that isn't needed. */
3900 return !G.background && WM_operator_winactive(C);
3901}
3902
3904{
3905 Scene *scene = CTX_data_scene(C);
3906 wmWindow *win = CTX_wm_window(C);
3907 ScrArea *area = CTX_wm_area(C);
3908 ARegion *region = CTX_wm_region(C);
3910 const int type = RNA_enum_get(op->ptr, "type");
3911 const int iter = RNA_int_get(op->ptr, "iterations");
3912 const double time_limit = double(RNA_float_get(op->ptr, "time_limit"));
3913 const int cfra = scene->r.cfra;
3914 const char *infostr = "";
3915
3916 /* NOTE: Depsgraph is used to update scene for a new state, so no need to ensure evaluation
3917 * here.
3918 */
3919 Depsgraph *depsgraph = CTX_data_depsgraph_pointer(C);
3920
3922
3923 WM_cursor_wait(true);
3924
3925 double time_start = BLI_time_now_seconds();
3926
3928
3929 int iter_steps = 0;
3930 for (int a = 0; a < iter; a++) {
3931
3932 if (type == eRTAnimationPlay) {
3933 WorkspaceStatus status(C);
3934 status.item(fmt::format("{} / {} {}", a + 1, iter, infostr), ICON_STATUS_INFO);
3935 }
3936
3937 redraw_timer_step(C, scene, depsgraph, win, area, region, type, cfra, a, iter);
3938 iter_steps += 1;
3939
3940 if (time_limit != 0.0) {
3941 if ((BLI_time_now_seconds() - time_start) > time_limit) {
3942 break;
3943 }
3944 a = 0;
3945 }
3946 }
3947
3948 double time_delta = (BLI_time_now_seconds() - time_start) * 1000;
3949
3950 if (type == eRTAnimationPlay) {
3951 ED_workspace_status_text(C, nullptr);
3952 WM_progress_clear(win);
3953 }
3954
3955 WM_cursor_wait(false);
3956
3957 BKE_reportf(op->reports,
3959 "%d \u00D7 %s: %.4f ms, average: %.8f ms",
3960 iter_steps,
3961 infostr,
3962 time_delta,
3963 time_delta / iter_steps);
3964
3965 return OPERATOR_FINISHED;
3966}
3967
3969{
3970 ot->name = "Redraw Timer";
3971 ot->idname = "WM_OT_redraw_timer";
3972 ot->description = "Simple redraw timer to test the speed of updating the interface";
3973
3974 ot->invoke = WM_menu_invoke;
3975 ot->exec = redraw_timer_exec;
3976 ot->poll = redraw_timer_poll;
3977
3978 ot->prop = RNA_def_enum(ot->srna, "type", redraw_timer_type_items, eRTDrawRegion, "Type", "");
3980 ot->srna, "iterations", 10, 1, INT_MAX, "Iterations", "Number of times to redraw", 1, 1000);
3981 RNA_def_float(ot->srna,
3982 "time_limit",
3983 0.0,
3984 0.0,
3985 FLT_MAX,
3986 "Time Limit",
3987 "Seconds to run the test for (override iterations)",
3988 0.0,
3989 60.0);
3990}
3991
3993
3994/* -------------------------------------------------------------------- */
3999
4005
4007{
4008 ot->name = "Memory Statistics";
4009 ot->idname = "WM_OT_memory_statistics";
4010 ot->description = "Print memory statistics to the console";
4011
4013}
4014
4016
4017/* -------------------------------------------------------------------- */
4022
4027
4028static void previews_id_ensure(bContext *C, Scene *scene, ID *id)
4029{
4030 BLI_assert(ELEM(GS(id->name), ID_MA, ID_TE, ID_IM, ID_WO, ID_LA));
4031
4032 /* Only preview non-library datablocks, lib ones do not pertain to this .blend file!
4033 * Same goes for ID with no user. */
4034 if (ID_IS_EDITABLE(id) && (id->us != 0)) {
4035 ui::icon_render_id(C, scene, id, ICON_SIZE_ICON, false);
4036 ui::icon_render_id(C, scene, id, ICON_SIZE_PREVIEW, false);
4037 }
4038}
4039
4041{
4042 const LibraryForeachIDCallbackFlag cb_flag = cb_data->cb_flag;
4043
4045 return IDWALK_RET_NOP;
4046 }
4047
4048 PreviewsIDEnsureData *data = static_cast<PreviewsIDEnsureData *>(cb_data->user_data);
4049 ID *id = *cb_data->id_pointer;
4050
4051 if (id && (id->tag & ID_TAG_DOIT)) {
4052 BLI_assert(ELEM(GS(id->name), ID_MA, ID_TE, ID_IM, ID_WO, ID_LA));
4053 previews_id_ensure(data->C, data->scene, id);
4054 id->tag &= ~ID_TAG_DOIT;
4055 }
4056
4057 return IDWALK_RET_NOP;
4058}
4059
4061{
4062 Main *bmain = CTX_data_main(C);
4063 ListBaseT<ID> *lb[] = {&bmain->materials.cast<ID>(),
4064 &bmain->textures.cast<ID>(),
4065 &bmain->images.cast<ID>(),
4066 &bmain->worlds.cast<ID>(),
4067 &bmain->lights.cast<ID>(),
4068 nullptr};
4069 PreviewsIDEnsureData preview_id_data;
4070
4071 /* We use ID_TAG_DOIT to check whether we have already handled a given ID or not. */
4072 BKE_main_id_tag_all(bmain, ID_TAG_DOIT, false);
4073 for (int i = 0; lb[i]; i++) {
4075 }
4076
4077 preview_id_data.C = C;
4078 for (Scene &scene : bmain->scenes) {
4079 preview_id_data.scene = &scene;
4080 ID *id = id_cast<ID *>(&scene);
4081
4083 nullptr, id, previews_id_ensure_callback, &preview_id_data, IDWALK_RECURSE);
4084 }
4085
4086 /* Check a last time for ID not used (fake users only, in theory), and
4087 * do our best for those, using current scene... */
4088 for (int i = 0; lb[i]; i++) {
4089 for (ID &id : *lb[i]) {
4090 if (id.tag & ID_TAG_DOIT) {
4091 previews_id_ensure(C, nullptr, &id);
4092 id.tag &= ~ID_TAG_DOIT;
4093 }
4094 }
4095 }
4096
4097 return OPERATOR_FINISHED;
4098}
4099
4101{
4102 ot->name = "Refresh Data-Block Previews";
4103 ot->idname = "WM_OT_previews_ensure";
4104 ot->description =
4105 "Ensure data-block previews are available and up-to-date "
4106 "(to be saved in .blend file, only for some types like materials, textures, etc.)";
4107
4109}
4110
4112
4113/* -------------------------------------------------------------------- */
4116
4130
4131/* Only types supporting previews currently. */
4133 {PREVIEW_FILTER_ALL, "ALL", 0, "All Types", ""},
4135 "GEOMETRY",
4136 0,
4137 "All Geometry Types",
4138 "Clear previews for scenes, collections and objects"},
4140 "SHADING",
4141 0,
4142 "All Shading Types",
4143 "Clear previews for materials, lights, worlds, textures and images"},
4144 {PREVIEW_FILTER_SCENE, "SCENE", 0, "Scenes", ""},
4145 {PREVIEW_FILTER_COLLECTION, "COLLECTION", 0, "Collections", ""},
4146 {PREVIEW_FILTER_OBJECT, "OBJECT", 0, "Objects", ""},
4147 {PREVIEW_FILTER_MATERIAL, "MATERIAL", 0, "Materials", ""},
4148 {PREVIEW_FILTER_LIGHT, "LIGHT", 0, "Lights", ""},
4149 {PREVIEW_FILTER_WORLD, "WORLD", 0, "Worlds", ""},
4150 {PREVIEW_FILTER_TEXTURE, "TEXTURE", 0, "Textures", ""},
4151 {PREVIEW_FILTER_IMAGE, "IMAGE", 0, "Images", ""},
4152#if 0 /* XXX: TODO. */
4153 {PREVIEW_FILTER_BRUSH, "BRUSH", 0, "Brushes", ""},
4154#endif
4155 {0, nullptr, 0, nullptr, nullptr},
4156};
4157
4159{
4160 switch (filter) {
4161 case PREVIEW_FILTER_ALL:
4169 return FILTER_ID_SCE;
4171 return FILTER_ID_GR;
4173 return FILTER_ID_OB;
4175 return FILTER_ID_MA;
4177 return FILTER_ID_LA;
4179 return FILTER_ID_WO;
4181 return FILTER_ID_TE;
4183 return FILTER_ID_IM;
4184 }
4185
4186 return 0;
4187}
4188
4190{
4191 Main *bmain = CTX_data_main(C);
4192 ListBaseT<ID> *lb[] = {
4193 &bmain->objects.cast<ID>(),
4194 &bmain->collections.cast<ID>(),
4195 &bmain->materials.cast<ID>(),
4196 &bmain->worlds.cast<ID>(),
4197 &bmain->lights.cast<ID>(),
4198 &bmain->textures.cast<ID>(),
4199 &bmain->images.cast<ID>(),
4200 nullptr,
4201 };
4202
4203 const int id_filters = preview_filter_to_idfilter(
4204 PreviewFilterID(RNA_enum_get(op->ptr, "id_type")));
4205
4206 for (int i = 0; lb[i]; i++) {
4207 ID *id = lb[i]->first();
4208 if (!id) {
4209 continue;
4210 }
4211
4212#if 0
4213 printf("%s: %d, %d, %d -> %d\n",
4214 id->name,
4215 GS(id->name),
4217 id_filters,
4218 BKE_idtype_idcode_to_idfilter(GS(id->name)) & id_filters);
4219#endif
4220
4221 if (!(BKE_idtype_idcode_to_idfilter(GS(id->name)) & id_filters)) {
4222 continue;
4223 }
4224
4225 for (; id; id = static_cast<ID *>(id->next)) {
4227
4228 BKE_previewimg_clear(prv_img);
4229 }
4230 }
4231
4232 return OPERATOR_FINISHED;
4233}
4234
4236{
4237 ot->name = "Clear Data-Block Previews";
4238 ot->idname = "WM_OT_previews_clear";
4239 ot->description =
4240 "Clear data-block previews (only for some types like objects, materials, textures, etc.)";
4241
4243 ot->invoke = WM_menu_invoke;
4244
4245 ot->prop = RNA_def_enum_flag(ot->srna,
4246 "id_type",
4249 "Data-Block Type",
4250 "Which data-block previews to clear");
4251}
4252
4254
4255/* -------------------------------------------------------------------- */
4258
4260{
4262
4263 if (std::optional<std::string> manual_id = ui::button_online_manual_id_from_active(C)) {
4264 PointerRNA ptr_props = WM_operator_properties_create("WM_OT_doc_view_manual");
4265 RNA_string_set(&ptr_props, "doc_id", manual_id.value().c_str());
4266
4268 WM_operatortype_find("WM_OT_doc_view_manual", false),
4270 &ptr_props,
4271 nullptr);
4272
4273 WM_operator_properties_free(&ptr_props);
4274 }
4275
4276 return retval;
4277}
4278
4280{
4281 /* Identifiers. */
4282 ot->name = "View Online Manual";
4283 ot->idname = "WM_OT_doc_view_manual_ui_context";
4284 ot->description = "View a context based online manual in a web browser";
4285
4286 /* Callbacks. */
4289}
4290
4292
4293/* -------------------------------------------------------------------- */
4298
4300{
4301 PropertyRNA *prop;
4302
4303 ot->name = "Set Stereo 3D";
4304 ot->idname = "WM_OT_set_stereo_3d";
4305 ot->description = "Toggle 3D stereo support for current window (or change the display mode)";
4306
4313
4314 prop = RNA_def_enum(ot->srna,
4315 "display_mode",
4318 "Display Mode",
4319 "");
4321 prop = RNA_def_enum(ot->srna,
4322 "anaglyph_type",
4325 "Anaglyph Type",
4326 "");
4328 prop = RNA_def_enum(ot->srna,
4329 "interlace_type",
4332 "Interlace Type",
4333 "");
4335 prop = RNA_def_boolean(ot->srna,
4336 "use_interlace_swap",
4337 false,
4338 "Swap Left/Right",
4339 "Swap left and right stereo channels");
4341 prop = RNA_def_boolean(ot->srna,
4342 "use_sidebyside_crosseyed",
4343 false,
4344 "Cross-Eyed",
4345 "Right eye should see left image and vice versa");
4347}
4348
4350
4351/* -------------------------------------------------------------------- */
4354
4356{
4398#if defined(WIN32)
4399 WM_operatortype_append(WM_OT_console_toggle);
4400#endif
4405
4406#ifdef WITH_XR_OPENXR
4408#endif
4409
4410 /* Gizmos. */
4413}
4414
4415/* Circle-select-like modal operators. */
4417{
4418 static const EnumPropertyItem modal_items[] = {
4419 {GESTURE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
4420 {GESTURE_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
4421 {GESTURE_MODAL_CIRCLE_ADD, "ADD", 0, "Add", ""},
4422 {GESTURE_MODAL_CIRCLE_SUB, "SUBTRACT", 0, "Subtract", ""},
4423 {GESTURE_MODAL_CIRCLE_SIZE, "SIZE", 0, "Size", ""},
4424
4425 {GESTURE_MODAL_SELECT, "SELECT", 0, "Select", ""},
4426 {GESTURE_MODAL_DESELECT, "DESELECT", 0, "Deselect", ""},
4427 {GESTURE_MODAL_NOP, "NOP", 0, "No Operation", ""},
4428
4429 {0, nullptr, 0, nullptr, nullptr},
4430 };
4431
4432 /* WARNING: Name is incorrect, use for non-3d views. */
4433 wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "View3D Gesture Circle");
4434
4435 /* This function is called for each space-type, only needs to add map once. */
4436 if (keymap && keymap->modal_items) {
4437 return;
4438 }
4439
4440 keymap = WM_modalkeymap_ensure(keyconf, "View3D Gesture Circle", modal_items);
4441
4442 /* Assign map to operators. */
4443 WM_modalkeymap_assign(keymap, "VIEW3D_OT_select_circle");
4444 WM_modalkeymap_assign(keymap, "UV_OT_select_circle");
4445 WM_modalkeymap_assign(keymap, "SEQUENCER_OT_select_circle");
4446 WM_modalkeymap_assign(keymap, "CLIP_OT_select_circle");
4447 WM_modalkeymap_assign(keymap, "MASK_OT_select_circle");
4448 WM_modalkeymap_assign(keymap, "NODE_OT_select_circle");
4449 WM_modalkeymap_assign(keymap, "GRAPH_OT_select_circle");
4450 WM_modalkeymap_assign(keymap, "ACTION_OT_select_circle");
4451}
4452
4453/* Straight line modal operators. */
4455{
4456 static const EnumPropertyItem modal_items[] = {
4457 {GESTURE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
4458 {GESTURE_MODAL_SELECT, "SELECT", 0, "Select", ""},
4459 {GESTURE_MODAL_BEGIN, "BEGIN", 0, "Begin", ""},
4460 {GESTURE_MODAL_MOVE, "MOVE", 0, "Move", ""},
4461 {GESTURE_MODAL_SNAP, "SNAP", 0, "Snap", ""},
4462 {GESTURE_MODAL_FLIP, "FLIP", 0, "Flip", ""},
4463 {0, nullptr, 0, nullptr, nullptr},
4464 };
4465
4466 wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Gesture Straight Line");
4467
4468 /* This function is called for each space-type, only needs to add map once. */
4469 if (keymap && keymap->modal_items) {
4470 return;
4471 }
4472
4473 keymap = WM_modalkeymap_ensure(keyconf, "Gesture Straight Line", modal_items);
4474
4475 /* Assign map to operators. */
4476 WM_modalkeymap_assign(keymap, "IMAGE_OT_sample_line");
4477 WM_modalkeymap_assign(keymap, "PAINT_OT_weight_gradient");
4478 WM_modalkeymap_assign(keymap, "MESH_OT_bisect");
4479 WM_modalkeymap_assign(keymap, "PAINT_OT_mask_line_gesture");
4480 WM_modalkeymap_assign(keymap, "SCULPT_OT_face_set_line_gesture");
4481 WM_modalkeymap_assign(keymap, "SCULPT_OT_trim_line_gesture");
4482 WM_modalkeymap_assign(keymap, "SCULPT_OT_project_line_gesture");
4483 WM_modalkeymap_assign(keymap, "PAINT_OT_hide_show_line_gesture");
4484}
4485
4486/* Box_select-like modal operators. */
4488{
4489 static const EnumPropertyItem modal_items[] = {
4490 {GESTURE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
4491 {GESTURE_MODAL_SELECT, "SELECT", 0, "Select", ""},
4492 {GESTURE_MODAL_DESELECT, "DESELECT", 0, "Deselect", ""},
4493 {GESTURE_MODAL_BEGIN, "BEGIN", 0, "Begin", ""},
4494 {GESTURE_MODAL_MOVE, "MOVE", 0, "Move", ""},
4495 {0, nullptr, 0, nullptr, nullptr},
4496 };
4497
4498 wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Gesture Box");
4499
4500 /* This function is called for each space-type, only needs to add map once. */
4501 if (keymap && keymap->modal_items) {
4502 return;
4503 }
4504
4505 keymap = WM_modalkeymap_ensure(keyconf, "Gesture Box", modal_items);
4506
4507 /* Assign map to operators. */
4508 WM_modalkeymap_assign(keymap, "ACTION_OT_select_box");
4509 WM_modalkeymap_assign(keymap, "ANIM_OT_channels_select_box");
4510 WM_modalkeymap_assign(keymap, "ANIM_OT_previewrange_set");
4511 WM_modalkeymap_assign(keymap, "INFO_OT_select_box");
4512 WM_modalkeymap_assign(keymap, "FILE_OT_select_box");
4513 WM_modalkeymap_assign(keymap, "GRAPH_OT_select_box");
4514 WM_modalkeymap_assign(keymap, "MARKER_OT_select_box");
4515 WM_modalkeymap_assign(keymap, "NLA_OT_select_box");
4516 WM_modalkeymap_assign(keymap, "NODE_OT_select_box");
4517 WM_modalkeymap_assign(keymap, "NODE_OT_viewer_border");
4518 WM_modalkeymap_assign(keymap, "PAINT_OT_hide_show");
4519 WM_modalkeymap_assign(keymap, "OUTLINER_OT_select_box");
4520#if 0 /* Template. */
4521 WM_modalkeymap_assign(keymap, "SCREEN_OT_box_select");
4522#endif
4523 WM_modalkeymap_assign(keymap, "SEQUENCER_OT_select_box");
4524 WM_modalkeymap_assign(keymap, "SEQUENCER_OT_box_blade");
4525 WM_modalkeymap_assign(keymap, "SEQUENCER_OT_view_ghost_border");
4526 WM_modalkeymap_assign(keymap, "UV_OT_select_box");
4527 WM_modalkeymap_assign(keymap, "UV_OT_custom_region_set");
4528 WM_modalkeymap_assign(keymap, "CLIP_OT_select_box");
4529 WM_modalkeymap_assign(keymap, "CLIP_OT_graph_select_box");
4530 WM_modalkeymap_assign(keymap, "MASK_OT_select_box");
4531 WM_modalkeymap_assign(keymap, "PAINT_OT_mask_box_gesture");
4532 WM_modalkeymap_assign(keymap, "SCULPT_OT_face_set_box_gesture");
4533 WM_modalkeymap_assign(keymap, "SCULPT_OT_trim_box_gesture");
4534 WM_modalkeymap_assign(keymap, "VIEW2D_OT_zoom_border");
4535 WM_modalkeymap_assign(keymap, "VIEW3D_OT_clip_border");
4536 WM_modalkeymap_assign(keymap, "VIEW3D_OT_render_border");
4537 WM_modalkeymap_assign(keymap, "VIEW3D_OT_select_box");
4538 /* XXX TODO: zoom border should perhaps map right-mouse to zoom out instead of in+cancel. */
4539 WM_modalkeymap_assign(keymap, "VIEW3D_OT_zoom_border");
4540 WM_modalkeymap_assign(keymap, "IMAGE_OT_render_border");
4541 WM_modalkeymap_assign(keymap, "IMAGE_OT_view_zoom_border");
4542 WM_modalkeymap_assign(keymap, "GREASE_PENCIL_OT_erase_box");
4543}
4544
4545/* Lasso modal operators. */
4547{
4548 static const EnumPropertyItem modal_items[] = {
4549 {GESTURE_MODAL_MOVE, "MOVE", 0, "Move", ""},
4550 {0, nullptr, 0, nullptr, nullptr},
4551 };
4552
4553 wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Gesture Lasso");
4554
4555 /* This function is called for each space-type, only needs to add map once. */
4556 if (keymap && keymap->modal_items) {
4557 return;
4558 }
4559
4560 keymap = WM_modalkeymap_ensure(keyconf, "Gesture Lasso", modal_items);
4561
4562 /* Assign map to operators. */
4563 WM_modalkeymap_assign(keymap, "VIEW3D_OT_select_lasso");
4564 WM_modalkeymap_assign(keymap, "MASK_OT_select_lasso");
4565 WM_modalkeymap_assign(keymap, "PAINT_OT_mask_lasso_gesture");
4566 WM_modalkeymap_assign(keymap, "SCULPT_OT_face_set_lasso_gesture");
4567 WM_modalkeymap_assign(keymap, "SCULPT_OT_trim_lasso_gesture");
4568 WM_modalkeymap_assign(keymap, "ACTION_OT_select_lasso");
4569 WM_modalkeymap_assign(keymap, "CLIP_OT_select_lasso");
4570 WM_modalkeymap_assign(keymap, "GRAPH_OT_select_lasso");
4571 WM_modalkeymap_assign(keymap, "NODE_OT_select_lasso");
4572 WM_modalkeymap_assign(keymap, "UV_OT_select_lasso");
4573 WM_modalkeymap_assign(keymap, "SEQUENCER_OT_select_lasso");
4574 WM_modalkeymap_assign(keymap, "PAINT_OT_hide_show_lasso_gesture");
4575 WM_modalkeymap_assign(keymap, "GREASE_PENCIL_OT_erase_lasso");
4576}
4577
4578/* Polyline modal operators */
4580{
4581 static const EnumPropertyItem modal_items[] = {
4582 {GESTURE_MODAL_CONFIRM, "CONFIRM", 0, "Confirm", ""},
4583 {GESTURE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
4584 {GESTURE_MODAL_SELECT, "SELECT", 0, "Select", ""},
4585 {GESTURE_MODAL_MOVE, "MOVE", 0, "Move", ""},
4586 {0, nullptr, 0, nullptr, nullptr},
4587 };
4588
4589 wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Gesture Polyline");
4590
4591 /* This function is called for each space-type, only needs to add map once. */
4592 if (keymap && keymap->modal_items) {
4593 return;
4594 }
4595
4596 keymap = WM_modalkeymap_ensure(keyconf, "Gesture Polyline", modal_items);
4597
4598 /* assign map to operators */
4599 WM_modalkeymap_assign(keymap, "PAINT_OT_hide_show_polyline_gesture");
4600 WM_modalkeymap_assign(keymap, "PAINT_OT_mask_polyline_gesture");
4601 WM_modalkeymap_assign(keymap, "SCULPT_OT_face_set_polyline_gesture");
4602 WM_modalkeymap_assign(keymap, "SCULPT_OT_trim_polyline_gesture");
4603}
4604
4605/* Zoom to border modal operators. */
4607{
4608 static const EnumPropertyItem modal_items[] = {
4609 {GESTURE_MODAL_CANCEL, "CANCEL", 0, "Cancel", ""},
4610 {GESTURE_MODAL_IN, "IN", 0, "In", ""},
4611 {GESTURE_MODAL_OUT, "OUT", 0, "Out", ""},
4612 {GESTURE_MODAL_BEGIN, "BEGIN", 0, "Begin", ""},
4613 {0, nullptr, 0, nullptr, nullptr},
4614 };
4615
4616 wmKeyMap *keymap = WM_modalkeymap_find(keyconf, "Gesture Zoom Border");
4617
4618 /* This function is called for each space-type, only needs to add map once. */
4619 if (keymap && keymap->modal_items) {
4620 return;
4621 }
4622
4623 keymap = WM_modalkeymap_ensure(keyconf, "Gesture Zoom Border", modal_items);
4624
4625 /* Assign map to operators. */
4626 WM_modalkeymap_assign(keymap, "VIEW2D_OT_zoom_border");
4627 WM_modalkeymap_assign(keymap, "VIEW3D_OT_zoom_border");
4628 WM_modalkeymap_assign(keymap, "IMAGE_OT_view_zoom_border");
4629}
4630
4632{
4633 WM_keymap_ensure(keyconf, "Window", SPACE_EMPTY, RGN_TYPE_WINDOW);
4634
4635 wm_gizmos_keymap(keyconf);
4637 gesture_box_modal_keymap(keyconf);
4642
4644}
4645
4647
4648/* -------------------------------------------------------------------- */
4655
4656static bool rna_id_enum_filter_single(const ID *id, void *user_data)
4657{
4658 return (id != user_data);
4659}
4660
4661static bool rna_id_enum_filter_single_and_assets(const ID *id, void *user_data)
4662{
4663 if (!rna_id_enum_filter_single(id, user_data)) {
4664 return false;
4665 }
4666 if (id->asset_data != nullptr) {
4667 return false;
4668 }
4669 return true;
4670}
4671
4672/* Generic itemf's for operators that take library args. */
4673static const EnumPropertyItem *rna_id_itemf(bool *r_free,
4674 ID *id,
4675 bool local,
4676 bool (*filter_ids)(const ID *id, void *user_data),
4677 void *user_data)
4678{
4679 EnumPropertyItem item_tmp = {0}, *item = nullptr;
4680 int totitem = 0;
4681 int i = 0;
4682
4683 if (id != nullptr) {
4684 const short id_type = GS(id->name);
4685 for (; id; id = static_cast<ID *>(id->next)) {
4686 if ((filter_ids != nullptr) && filter_ids(id, user_data) == false) {
4687 i++;
4688 continue;
4689 }
4690 if (local == false || !ID_IS_LINKED(id)) {
4691 item_tmp.identifier = item_tmp.name = id->name + 2;
4692 item_tmp.value = i++;
4693
4694 const BIFIconID lib_state_icon = ui::icon_from_library(id);
4695 /* Indicate library linking, override or asset state in icon. In enum menus that's the only
4696 * way to tell apart linked IDs from their overridden versions. */
4697 if (lib_state_icon != ICON_NONE) {
4698 item_tmp.icon = lib_state_icon;
4699 }
4700 /* Show collection color tag icons in menus. */
4701 else if (id_type == ID_GR) {
4702 item_tmp.icon = ui::icon_color_from_collection(reinterpret_cast<Collection *>(id));
4703 }
4704
4705 RNA_enum_item_add(&item, &totitem, &item_tmp);
4706 }
4707 }
4708 }
4709
4710 RNA_enum_item_end(&item, &totitem);
4711 *r_free = true;
4712
4713 return item;
4714}
4715
4716/* Can add more ID types as needed. */
4717
4719 PointerRNA * /*ptr*/,
4720 PropertyRNA * /*prop*/,
4721 bool *r_free)
4722{
4723
4724 return rna_id_itemf(
4725 r_free, C ? CTX_data_main(C)->actions.first_as<ID>() : nullptr, false, nullptr, nullptr);
4726}
4727#if 0 /* UNUSED. */
4728const EnumPropertyItem *RNA_action_local_itemf(bContext *C,
4729 PointerRNA * /*ptr*/,
4730 PropertyRNA * /*prop*/,
4731 bool *r_free)
4732{
4733 return rna_id_itemf(r_free, C ? (ID *)CTX_data_main(C)->action.first : nullptr, true);
4734}
4735#endif
4736
4738 PointerRNA * /*ptr*/,
4739 PropertyRNA * /*prop*/,
4740 bool *r_free)
4741{
4742 return rna_id_itemf(
4743 r_free, C ? CTX_data_main(C)->collections.first_as<ID>() : nullptr, false, nullptr, nullptr);
4744}
4746 PointerRNA * /*ptr*/,
4747 PropertyRNA * /*prop*/,
4748 bool *r_free)
4749{
4750 return rna_id_itemf(
4751 r_free, C ? CTX_data_main(C)->collections.first_as<ID>() : nullptr, true, nullptr, nullptr);
4752}
4753
4755 PointerRNA * /*ptr*/,
4756 PropertyRNA * /*prop*/,
4757 bool *r_free)
4758{
4759 return rna_id_itemf(
4760 r_free, C ? CTX_data_main(C)->images.first_as<ID>() : nullptr, false, nullptr, nullptr);
4761}
4763 PointerRNA * /*ptr*/,
4764 PropertyRNA * /*prop*/,
4765 bool *r_free)
4766{
4767 return rna_id_itemf(
4768 r_free, C ? CTX_data_main(C)->images.first_as<ID>() : nullptr, true, nullptr, nullptr);
4769}
4770
4772 PointerRNA * /*ptr*/,
4773 PropertyRNA * /*prop*/,
4774 bool *r_free)
4775{
4776 return rna_id_itemf(
4777 r_free, C ? CTX_data_main(C)->scenes.first_as<ID>() : nullptr, false, nullptr, nullptr);
4778}
4780 PointerRNA * /*ptr*/,
4781 PropertyRNA * /*prop*/,
4782 bool *r_free)
4783{
4784 return rna_id_itemf(
4785 r_free, C ? CTX_data_main(C)->scenes.first_as<ID>() : nullptr, true, nullptr, nullptr);
4786}
4788 PointerRNA * /*ptr*/,
4789 PropertyRNA * /*prop*/,
4790 bool *r_free)
4791{
4792 Scene *sequencer_scene = C ? CTX_data_sequencer_scene(C) : nullptr;
4793 return rna_id_itemf(r_free,
4794 C ? CTX_data_main(C)->scenes.first_as<ID>() : nullptr,
4795 false,
4797 sequencer_scene);
4798}
4800 PointerRNA * /*ptr*/,
4801 PropertyRNA * /*prop*/,
4802 bool *r_free)
4803{
4804 return rna_id_itemf(
4805 r_free, C ? CTX_data_main(C)->movieclips.first_as<ID>() : nullptr, false, nullptr, nullptr);
4806}
4808 PointerRNA * /*ptr*/,
4809 PropertyRNA * /*prop*/,
4810 bool *r_free)
4811{
4812 return rna_id_itemf(
4813 r_free, C ? CTX_data_main(C)->movieclips.first_as<ID>() : nullptr, true, nullptr, nullptr);
4814}
4815
4817 PointerRNA * /*ptr*/,
4818 PropertyRNA * /*prop*/,
4819 bool *r_free)
4820{
4821 return rna_id_itemf(r_free,
4822 C ? static_cast<ID *>(CTX_data_main(C)->masks.first_) : nullptr,
4823 false,
4824 nullptr,
4825 nullptr);
4826}
4828 PointerRNA * /*ptr*/,
4829 PropertyRNA * /*prop*/,
4830 bool *r_free)
4831{
4832 return rna_id_itemf(r_free,
4833 C ? static_cast<ID *>(CTX_data_main(C)->masks.first_) : nullptr,
4834 true,
4835 nullptr,
4836 nullptr);
4837}
4838
4840
4841} // namespace blender
#define G_MAIN
General operations, lookup, etc. for materials.
#define BKE_ST_MAXNAME
Definition BKE_screen.hh:91
#define BLF_DRAW_STR_DUMMY_MAX
Definition BLF_api.hh:456
#define DEG2RADF(_deg)
#define RAD2DEGF(_rad)
#define M_PI
#define FILE_MAX
#define SNPRINTF(dst, format,...)
Platform independent time functions.
#define RPT_(msgid)
#define CTX_N_(context, msgid)
#define CTX_IFACE_(context, msgid)
#define BLT_I18NCONTEXT_OPERATOR_DEFAULT
#define IFACE_(msgid)
#define CLOG_ERROR(clg_ref,...)
Definition CLG_log.h:188
#define CLOG_DEBUG(clg_ref,...)
Definition CLG_log.h:191
ID and Library types, which are fundamental for SDNA.
#define FILTER_ID_OB
Definition DNA_ID.h:1216
#define FILTER_ID_MA
Definition DNA_ID.h:1210
#define ID_IS_LINKED(_id)
Definition DNA_ID.h:697
#define MAX_ID_NAME
Definition DNA_ID.h:367
#define FILTER_ID_LA
Definition DNA_ID.h:1207
#define FILTER_ID_GR
Definition DNA_ID.h:1205
#define FILTER_ID_TE
Definition DNA_ID.h:1222
#define ID_IS_EDITABLE(_id)
Definition DNA_ID.h:708
#define FILTER_ID_IM
Definition DNA_ID.h:1206
#define FILTER_ID_SCE
Definition DNA_ID.h:1219
#define FILTER_ID_WO
Definition DNA_ID.h:1225
Object is a sort of wrapper for general info.
#define OB_DATA_SUPPORT_ID_CASE
#define RGN_TYPE_ANY
#define SPACE_TYPE_ANY
#define UI_SCALE_FAC
#define OPERATOR_RETVAL_CHECK(ret)
#define OP_MAX_TYPENAME
#define NUM_STR_REP_LEN
@ GHOST_kConsoleWindowStateToggle
Read Blender memory allocation and freeing.
#define RNA_PROP_END
#define RNA_STRUCT_BEGIN(sptr, prop)
#define RNA_STRUCT_END
#define RNA_PROP_BEGIN(sptr, itemptr, prop)
#define RNA_SUBTYPE_UNIT_VALUE(subtype)
Definition RNA_types.hh:268
#define C
Definition RandGen.cpp:29
#define UI_UNIT_Y
#define UI_SEARCHBOX_BOUNDS
#define UI_DEFAULT_TEXT_POINTS
#define UI_UNIT_X
#define UI_ITEM_NONE
#define UI_MAX_DRAW_STR
#define NC_WINDOW
Definition WM_types.hh:388
#define CLAMP(a, b, c)
#define BLI_assert_unreachable()
#define POINTER_FROM_INT(i)
#define POINTER_AS_INT(i)
#define ELEM(...)
#define STREQ(a, b)
btScalar max
static GHOST_ISystem * getSystem()
virtual bool setConsoleWindowState(GHOST_TConsoleWindowState action)=0
constexpr StringRef()
void item(std::string text, int icon1, int icon2=0)
Definition area.cc:1076
void item_bool(std::string text, bool inverted, int icon1, int icon2=0)
Definition area.cc:1097
#define rot(x, k)
#define str(s)
#define SHRT_MAX
#define FLT_MAX
#define INT_MAX
float dot(VecOp< float, D >, VecOp< float, D >) RET
#define ceil
VecBase< float, D > step(VecOp< float, D >, VecOp< float, D >) RET
ccl_device_inline dual1 len(const ccl_private dual< T > &a)
Definition math_dual.h:263
ccl_device_inline float2 fmod(const float2 a, const float b)
std::unique_ptr< IDProperty, IDPropertyDeleter > create_group(StringRef prop_name, eIDPropertyFlag flags={})
Allocate a new IDProperty of type IDP_GROUP.
void free(Subdiv *subdiv)
Definition subdiv.cc:192
void imm_draw_rounded_box_wire_2d(uint pos, float x, float y, float2 radius, float2 corner_radius, int nsegments)
void split(const std::string &s, const char delim, std::vector< std::string > &tokens)
Definition abc_util.cc:68
void get_color_4fv(int colorid, float col[4])
std::optional< std::string > button_online_manual_id_from_active(const bContext *C) ATTR_WARN_UNUSED_RESULT
const uiStyle * style_get()
wmOperatorStatus popup_menu_invoke(bContext *C, const char *idname, ReportList *reports) ATTR_NONNULL(1
PopupMenu * popup_menu_begin(bContext *C, const char *title, int icon) ATTR_NONNULL()
void fontstyle_set(const uiFontStyle *fs)
const uiStyle * style_get_dpi()
void popup_block_invoke(bContext *C, BlockCreateFunc func, void *arg, FreeArgFunc arg_free, StructRNA *srna_owner=nullptr)
wmOperatorStatus popover_panel_invoke(bContext *C, const char *idname, bool keep_open, bool use_numselect, ReportList *reports)
wmOperatorStatus pie_menu_invoke(bContext *C, const char *idname, const wmEvent *event)
void icon_render_id(const bContext *C, Scene *scene, ID *id, enum eIconSizes size, bool use_job)
int icon_color_from_collection(const Collection *collection)
int icon_from_library(const ID *id)
Layout & block_layout(Block *block, LayoutDirection direction, LayoutType type, int x, int y, int size, int em, int padding, const uiStyle *style)
bool asset_shelf_popover_invoke(bContext &C, StringRef asset_shelf_idname, ReportList &reports)
@ BUT_ACTIVATE_ON_INIT_NO_SELECT
BMesh Iterators.
ID * WM_operator_drop_load_path(bContext *C, wmOperator *op, const short idcode)
MINLINE float min_ff(float a, float b)
const EnumPropertyItem * RNA_movieclip_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
const char * BKE_idtype_idcode_to_name(short idcode)
Definition idtype.cc:261
UserDef U
Definition blender.cc:58
int RNA_property_array_length(PointerRNA *ptr, PropertyRNA *prop)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
void WM_operatortype_append(void(*opfunc)(wmOperatorType *))
static void WM_OT_doc_view_manual_ui_context(wmOperatorType *ot)
void WM_OT_clear_recent_files(wmOperatorType *ot)
Definition wm_files.cc:4490
uint64_t BKE_idtype_idcode_to_idfilter(short idcode)
Definition idtype.cc:473
static void gesture_polyline_modal_keymap(wmKeyConfig *keyconf)
void wm_operatortypes_register()
std::string WM_operator_pystring_abbreviate(std::string str, int str_len_max)
static void WM_OT_window_new_main(wmOperatorType *ot)
wmOperatorStatus WM_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
void BKE_scene_graph_update_for_newframe(Depsgraph *depsgraph)
Definition scene.cc:2953
IDProperty * WM_operator_last_properties_ensure_idprops(wmOperatorType *ot)
PointerRNA RNA_property_pointer_get(PointerRNA *ptr, PropertyRNA *prop)
static const EnumPropertyItem preview_id_type_items[]
void RNA_enum_item_add(EnumPropertyItem **items, int *totitem, const EnumPropertyItem *item)
bool WM_operator_py_idname_ok_or_report(ReportList *reports, const char *classname, const char *idname)
ScrArea * CTX_wm_area(const bContext *C)
void WM_OT_save_as_mainfile(wmOperatorType *ot)
Definition wm_files.cc:4279
MINLINE void copy_v2_v2_int(int r[2], const int a[2])
static bool wm_operator_winactive_not_full(bContext *C)
static ui::Block * wm_block_create_redo(bContext *C, ARegion *region, void *arg_op)
std::optional< std::string > WM_context_path_resolve_property_full(const bContext *C, const PointerRNA *ptr, PropertyRNA *prop, int index)
char * STRNCPY(char(&dst)[N], const char *src)
int RNA_enum_get(PointerRNA *ptr, const char *name)
void WM_operator_free(wmOperator *op)
Definition wm.cc:277
void IDP_ReplaceInGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:737
uint padding(uint offset, uint alignment)
void wm_draw_region_test(bContext *C, ScrArea *area, ARegion *region)
Definition wm_draw.cc:1793
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 BKE_previewimg_clear(PreviewImage *prv)
bool ED_undo_operator_repeat(bContext *C, wmOperator *op)
Definition ed_undo.cc:879
@ ICON_SIZE_ICON
@ ICON_SIZE_PREVIEW
void RNA_property_float_get_array(PointerRNA *ptr, PropertyRNA *prop, float *values)
@ RPT_WARNING
Definition BKE_report.hh:40
wmOperatorStatus WM_operator_confirm(bContext *C, wmOperator *op, const wmEvent *)
void BLF_position(int fontid, float x, float y, float z)
Definition blf.cc:390
Scene * CTX_data_sequencer_scene(const bContext *C)
void BLI_str_toupper_ascii(char *str, size_t len) ATTR_NONNULL(1)
void immEnd()
PropertyRNA * RNA_struct_find_property(PointerRNA *ptr, const char *identifier)
static void WM_OT_window_close(wmOperatorType *ot)
wmOperatorStatus wm_window_new_exec(bContext *C, wmOperator *op)
float BLF_width(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(2)
Definition blf.cc:835
void RNA_property_update(bContext *C, PointerRNA *ptr, PropertyRNA *prop)
wmKeyMap * WM_modalkeymap_find(wmKeyConfig *keyconf, const char *idname)
Definition wm_keymap.cc:999
static const EnumPropertyItem * rna_id_itemf(bool *r_free, ID *id, bool local, bool(*filter_ids)(const ID *id, void *user_data), void *user_data)
static wmOperatorStatus wm_call_menu_exec(bContext *C, wmOperator *op)
void WM_operator_properties_alloc(PointerRNA **ptr, IDProperty **properties, const char *opstring)
void GPU_matrix_scale_2fv(const float vec[2])
bool RNA_struct_is_a(const StructRNA *type, const StructRNA *srna)
static std::string wm_call_menu_get_name(wmOperatorType *ot, PointerRNA *ptr)
unsigned int uint
Definition BKE_text.h:55
const EnumPropertyItem * RNA_mask_local_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
@ WM_POPUP_POSITION_MOUSE
Definition WM_types.hh:1058
@ WM_POPUP_POSITION_CENTER
Definition WM_types.hh:1059
std::string WM_operatortype_name(wmOperatorType *ot, PointerRNA *properties)
void WM_OT_read_factory_settings(wmOperatorType *ot)
Definition wm_files.cc:3229
void WM_operator_properties_sanitize(PointerRNA *ptr, const bool no_context)
bool handleNumInput(bContext *C, NumInput *n, const wmEvent *event)
Definition numinput.cc:344
bool RNA_path_resolve(const PointerRNA *ptr, const char *path, PointerRNA *r_ptr, PropertyRNA **r_prop)
Definition rna_path.cc:529
wmOperatorStatus WM_operator_filesel(bContext *C, wmOperator *op, const wmEvent *)
static void WM_OT_debug_menu(wmOperatorType *ot)
static uint preview_filter_to_idfilter(enum PreviewFilterID filter)
void WM_OT_splash_about(wmOperatorType *ot)
void wm_xr_operatortypes_register()
bool RNA_property_reset(Main *bmain, PointerRNA *ptr, PropertyRNA *prop, int index)
void WM_operator_properties_reset(wmOperator *op)
void id_us_plus(ID *id)
Definition lib_id.cc:433
std::optional< std::string > WM_prop_pystring_assign(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index)
void WM_operator_properties_free(PointerRNA *ptr)
void RNA_property_float_set(PointerRNA *ptr, PropertyRNA *prop, float value)
void WM_OT_link(wmOperatorType *ot)
ID * WM_operator_properties_id_lookup_from_name_or_session_uid(Main *bmain, PointerRNA *ptr, const ID_Type type)
static void WM_OT_search_menu(wmOperatorType *ot)
Depsgraph * CTX_data_depsgraph_pointer(const bContext *C)
static char g_search_text[256]
const char * RNA_property_identifier(const PropertyRNA *prop)
void WM_OT_set_working_color_space(wmOperatorType *ot)
GPUVertFormat * immVertexFormat()
bool IDP_AddToGroup(IDProperty *group, IDProperty *prop) ATTR_NONNULL()
Definition idprop.cc:788
void RNA_string_set(PointerRNA *ptr, const char *name, const char *value)
IDProperty * IDP_CopyProperty(const IDProperty *prop) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:986
static wmOperatorStatus radial_control_modal(bContext *C, wmOperator *op, const wmEvent *event)
@ WM_JOB_TYPE_ANY
Definition WM_api.hh:2008
void CTX_wm_window_set(bContext *C, wmWindow *win)
IDProperty * IDP_GetPropertyFromGroup(const IDProperty *prop, StringRef name) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL()
Definition idprop.cc:818
static void gesture_zoom_border_modal_keymap(wmKeyConfig *keyconf)
void WM_keymap_fix_linking()
void RNA_int_set(PointerRNA *ptr, const char *name, int value)
static void radial_control_set_tex(RadialControl *rc)
bool WM_operator_bl_idname_is_valid(const char *idname)
static std::optional< std::string > wm_prop_pystring_from_context(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index)
@ WM_POPUP_SIZE_LARGE
Definition WM_types.hh:1054
@ WM_POPUP_SIZE_SMALL
Definition WM_types.hh:1053
MenuType * WM_menutype_find(const StringRef idname, bool quiet)
static void init_data(ModifierData *md)
void WM_paneltype_idname_visit_for_search(const bContext *, PointerRNA *, PropertyRNA *, const char *, FunctionRef< void(StringPropertySearchVisitParams)> visit_fn)
const EnumPropertyItem * RNA_movieclip_local_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
std::optional< std::string > RNA_path_from_ID_to_struct(const PointerRNA *ptr)
Definition rna_path.cc:1078
static bool operator_last_properties_init_impl(wmOperator *op, IDProperty *last_properties)
int WM_operator_smooth_viewtx_get(const wmOperator *op)
void immBegin(GPUPrimType, uint vertex_len)
static wmOperatorStatus previews_clear_exec(bContext *C, wmOperator *op)
PropertyRNA * RNA_def_enum(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
void WM_operator_properties_clear(PointerRNA *ptr)
const EnumPropertyItem * RNA_collection_local_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
PointerRNA WM_operator_properties_create_ptr(wmOperatorType *ot)
PropertyUnit RNA_property_unit(PropertyRNA *prop)
wmOperatorStatus wm_window_fullscreen_toggle_exec(bContext *C, wmOperator *)
short RNA_type_to_ID_code(const StructRNA *type)
static void gesture_straightline_modal_keymap(wmKeyConfig *keyconf)
static int radial_control_get_path(PointerRNA *ctx_ptr, wmOperator *op, const char *name, PointerRNA *r_ptr, PropertyRNA **r_prop, int req_length, RCPropFlags flags)
void GPU_line_smooth(bool enable)
Definition gpu_state.cc:80
std::string RNA_property_string_get(PointerRNA *ptr, PropertyRNA *prop)
static void gesture_box_modal_keymap(wmKeyConfig *keyconf)
int RNA_int_get(PointerRNA *ptr, const char *name)
wmOperatorStatus WM_operator_call_notest(bContext *C, wmOperator *op)
static wmOperatorStatus wm_exit_blender_invoke(bContext *C, wmOperator *, const wmEvent *)
size_t WM_operator_bl_idname(char *dst, const char *src)
bool hasNumInput(const NumInput *n)
Definition numinput.cc:188
static void WM_OT_call_menu_pie(wmOperatorType *ot)
wmWindow * CTX_wm_window(const bContext *C)
MINLINE int max_ii(int a, int b)
bool id_type_can_have_animdata(short id_type)
Definition anim_data.cc:69
void wm_gizmos_keymap(wmKeyConfig *keyconf)
void WM_OT_lib_reload(wmOperatorType *ot)
void GPU_matrix_rotate_2d(float deg)
@ GESTURE_MODAL_CIRCLE_ADD
@ GESTURE_MODAL_DESELECT
@ GESTURE_MODAL_CIRCLE_SUB
@ GESTURE_MODAL_CIRCLE_SIZE
@ GESTURE_MODAL_CONFIRM
void WM_progress_clear(wmWindow *win)
PropertyRNA * RNA_struct_iterator_property(StructRNA *type)
static wmOperatorStatus wm_debug_menu_exec(bContext *C, wmOperator *op)
static wmOperatorStatus radial_control_invoke(bContext *C, wmOperator *op, const wmEvent *event)
ImBuf * BKE_brush_gen_radial_control_imbuf(Brush *br, bool secondary, bool display_gradient)
Definition brush.cc:1791
@ WM_JOB_BACKGROUND
Definition WM_api.hh:1999
void ED_undo_push_op(bContext *C, wmOperator *op)
Definition ed_undo.cc:553
wmOperatorStatus WM_generic_select_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void ED_region_tag_redraw(ARegion *region)
Definition area.cc:681
std::optional< std::string > WM_context_path_resolve_full(bContext *C, const PointerRNA *ptr)
void WM_OT_append(wmOperatorType *ot)
static void gesture_lasso_modal_keymap(wmKeyConfig *keyconf)
void immAttr2f(uint attr_id, float x, float y)
wmOperatorStatus WM_operator_props_popup_confirm(bContext *C, wmOperator *op, const wmEvent *)
std::string WM_operator_pystring(bContext *C, wmOperator *op, const bool all_args, const bool macro_args)
std::optional< UndoEncodeHints > ED_undo_is_legacy_compatible_for_property(bContext *C, ID *id, const PointerRNA &ptr, const PropertyRNA &prop)
Definition ed_undo.cc:607
void WM_OT_open_mainfile(wmOperatorType *ot)
Definition wm_files.cc:3534
static void WM_OT_search_single_menu(wmOperatorType *ot)
void IDP_MergeGroup(IDProperty *dest, const IDProperty *src, bool do_overwrite) ATTR_NONNULL()
Definition idprop.cc:783
void immUnbindProgram()
static wmOperatorStatus wm_search_menu_invoke(bContext *C, wmOperator *op, const wmEvent *event)
wmOperatorStatus WM_operator_ui_popup(bContext *C, wmOperator *op, int width, const bool use_numselect)
void WM_OT_save_homefile(wmOperatorType *ot)
Definition wm_files.cc:2735
@ RC_PROP_ALLOW_MISSING
@ RC_PROP_REQUIRE_BOOL
@ RC_PROP_REQUIRE_FLOAT
void GPU_line_width(float width)
Definition gpu_state.cc:151
wmOperatorStatus wm_stereo3d_set_invoke(bContext *C, wmOperator *op, const wmEvent *)
Definition wm_stereo.cc:346
const EnumPropertyItem * RNA_collection_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
@ GPU_BLEND_NONE
Definition GPU_state.hh:88
@ GPU_BLEND_ALPHA
Definition GPU_state.hh:90
static void redraw_timer_window_swap(bContext *C)
const EnumPropertyItem * RNA_action_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
@ WM_IME_COMPOSITE_EVENT
bool RNA_property_boolean_get(PointerRNA *ptr, PropertyRNA *prop)
bool RNA_property_array_check(PropertyRNA *prop)
void wm_window_make_drawable(wmWindowManager *wm, wmWindow *win)
static wmOperatorStatus wm_call_pie_menu_exec(bContext *C, wmOperator *op)
static void radial_control_paint_curve(uint pos, Brush *br, float radius, int line_segments)
static void radial_control_status(bContext *C, const RadialControl *radial_control)
Global G
Definition blender.cc:57
const char * BKE_main_blendfile_path(const Main *bmain) ATTR_NONNULL()
Definition main.cc:1058
@ PREVIEW_FILTER_SHADING
@ PREVIEW_FILTER_GEOMETRY
@ PREVIEW_FILTER_WORLD
@ PREVIEW_FILTER_SCENE
@ PREVIEW_FILTER_COLLECTION
@ PREVIEW_FILTER_LIGHT
@ PREVIEW_FILTER_MATERIAL
@ PREVIEW_FILTER_TEXTURE
@ PREVIEW_FILTER_IMAGE
@ PREVIEW_FILTER_OBJECT
static void WM_OT_call_panel(wmOperatorType *ot)
void RNA_property_int_set(PointerRNA *ptr, PropertyRNA *prop, int value)
void immBindBuiltinProgram(GPUBuiltinShader shader_id)
void imm_draw_circle_wire_2d(uint shdr_pos, float x, float y, float radius, int nsegments)
std::string RNA_pointer_as_string_id(bContext *C, PointerRNA *ptr)
PropertyType RNA_property_type(PropertyRNA *prop)
PointerRNA WM_operator_properties_create(const char *opstring)
static wmOperatorStatus wm_call_pie_menu_invoke(bContext *C, wmOperator *op, const wmEvent *event)
void WM_OT_read_factory_userpref(wmOperatorType *ot)
Definition wm_files.cc:2952
const EnumPropertyItem * RNA_image_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
void BKE_curvemapping_init(CurveMapping *cumap)
wmOperatorStatus WM_operator_call_ex(bContext *C, wmOperator *op, const bool store)
wmOperatorStatus WM_operator_props_popup_call(bContext *C, wmOperator *op, const wmEvent *)
static ui::Block * wm_operator_ui_create(bContext *C, ARegion *region, void *user_data)
std::string WM_operator_pystring_ex(bContext *C, wmOperator *op, const bool all_args, const bool macro_args, wmOperatorType *ot, PointerRNA *opptr)
void WM_operator_view3d_unit_defaults(bContext *C, wmOperator *op)
void BLF_size(int fontid, float size)
Definition blf.cc:445
char * BLI_strncpy(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_NONNULL(1
wmOperatorStatus wm_window_close_exec(bContext *C, wmOperator *)
void WM_OT_recover_last_session(wmOperatorType *ot)
Definition wm_files.cc:3694
const EnumPropertyItem * RNA_image_local_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
void IMB_freeImBuf(ImBuf *ibuf)
VecBase< int32_t, 2 > int2
VecBase< float, 2 > float2
void IDP_ClearProperty(IDProperty *prop)
Definition idprop.cc:1408
void RNA_property_string_set(PointerRNA *ptr, PropertyRNA *prop, const char *value)
static bool redraw_timer_poll(bContext *C)
static void radial_control_set_value(RadialControl *rc, float val)
StructRNA * RNA_property_pointer_type(PointerRNA *ptr, PropertyRNA *prop)
static void radial_control_update_header(wmOperator *op, bContext *C)
void * MEM_new_zeroed(size_t len, const char *str) ATTR_WARN_UNUSED_RESULT ATTR_ALLOC_SIZE(1) ATTR_NONNULL(2)
void immVertex2f(uint attr_id, float x, float y)
@ PROP_STRING_SEARCH_SORT
Definition RNA_types.hh:876
@ PROP_STRING_SEARCH_SUGGESTION
Definition RNA_types.hh:883
void ED_undo_redo(bContext *C)
Definition ed_undo.cc:380
@ PROP_BOOLEAN
Definition RNA_types.hh:210
@ PROP_POINTER
Definition RNA_types.hh:215
@ GPU_TEXTURE_USAGE_SHADER_READ
static bool wm_operator_winactive_normal(bContext *C)
@ SEARCH_TYPE_OPERATOR
@ SEARCH_TYPE_SINGLE_MENU
static wmOperatorStatus wm_call_panel_exec(bContext *C, wmOperator *op)
Image * BKE_image_load_exists(Main *bmain, const char *filepath, bool check_open=true, bool *r_exists=nullptr)
void WM_OT_revert_mainfile(wmOperatorType *ot)
Definition wm_files.cc:3617
@ IDP_FLAG_GHOST
void BLI_remlink(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:138
void WM_OT_id_linked_relocate(wmOperatorType *ot)
void BKE_report(ReportList *reports, eReportType type, const char *message)
Definition report.cc:162
BMesh const char void * data
std::string RNA_pointer_as_string_keywords(bContext *C, PointerRNA *ptr, const bool as_function, const bool all_args, const bool nested_args, const int max_prop_length)
static void WM_OT_operator_defaults(wmOperatorType *ot)
wmOperatorStatus WM_operator_confirm_message_ex(bContext *C, wmOperator *op, const char *title, const int icon, const char *message, const wm::OpCallContext)
bool WM_jobs_has_running(const wmWindowManager *window_manager, const void *owner, const eWM_JobType type, const eWM_JobFlag exclude_flags)
Definition wm_jobs.cc:809
const EnumPropertyItem * RNA_scene_without_sequencer_scene_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
bool RNA_property_is_set_ex(PointerRNA *ptr, PropertyRNA *prop, bool use_ghost)
static void dialog_exec_cb(bContext *C, wmOpPopUp *data, ui::Block *block)
void RNA_def_property_string_search_func_runtime(PropertyRNA *prop, StringPropertySearchFunc search_fn, const eStringPropertySearchFlag search_flag)
wmOperatorStatus WM_menu_invoke_ex(bContext *C, wmOperator *op, wm::OpCallContext opcontext)
void WM_progress_set(wmWindow *win, float progress)
wmWindowManager * CTX_wm_manager(const bContext *C)
void initNumInput(NumInput *n)
Definition numinput.cc:85
wmOperatorStatus WM_operator_repeat(bContext *C, wmOperator *op)
void ED_undo_pop(bContext *C)
Definition ed_undo.cc:376
void WM_OT_read_userpref(wmOperatorType *ot)
Definition wm_files.cc:2913
void wm_window_keymap(wmKeyConfig *keyconf)
Object * CTX_data_edit_object(const bContext *C)
void ED_undo_push(bContext *C, const char *str, UndoEncodeHints hints=UndoEncodeHints(0))
Definition ed_undo.cc:103
const EnumPropertyItem * RNA_mask_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
void WM_menutype_idname_visit_for_search(const bContext *, PointerRNA *, PropertyRNA *, const char *, FunctionRef< void(StringPropertySearchVisitParams)> visit_fn)
bool WM_operator_properties_id_lookup_is_set(PointerRNA *ptr)
static ui::Block * wm_enum_search_menu(bContext *C, ARegion *region, void *arg)
void GPU_texture_swizzle_set(gpu::Texture *texture, const char swizzle[4])
void GPU_texture_filter_mode(gpu::Texture *texture, bool use_filter)
void WM_operator_last_properties_ensure(wmOperatorType *ot, PointerRNA *ptr)
void wm_quit_with_optional_confirmation_prompt(bContext *C, wmWindow *win)
Definition wm_window.cc:436
char char size_t BLI_strncpy_rlen(char *__restrict dst, const char *__restrict src, size_t dst_maxncpy) ATTR_WARN_UNUSED_RESULT ATTR_NONNULL(1
const EnumPropertyItem rna_enum_stereo3d_display_items[]
Definition rna_scene.cc:527
PreviewImage * BKE_previewimg_id_ensure(ID *id)
int RNA_property_flag(PropertyRNA *prop)
void GPU_matrix_rotate_3f(float deg, float x, float y, float z)
static void dialog_cancel_cb(bContext *C, wmOpPopUp *data, ui::Block *block)
wmOperatorStatus WM_operator_props_popup(bContext *C, wmOperator *op, const wmEvent *)
void immUniformColor4f(float r, float g, float b, float a)
bool void BLI_path_rel(char path[FILE_MAX], const char *basepath) ATTR_NONNULL(1)
bool WM_operator_last_properties_init(wmOperator *op)
const EnumPropertyItem * RNA_scene_local_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
static void WM_OT_previews_clear(wmOperatorType *ot)
static bool rna_id_enum_filter_single_and_assets(const ID *id, void *user_data)
static void WM_OT_window_new(wmOperatorType *ot)
float ED_scene_grid_scale(const Scene *scene, const char **r_grid_unit)
PanelType * WM_paneltype_find(const StringRef idname, bool quiet)
wmKeyMap * WM_keymap_ensure(wmKeyConfig *keyconf, const char *idname, int spaceid, int regionid)
Definition wm_keymap.cc:935
float ED_view3d_grid_scale(const Scene *scene, const View3D *v3d, const char **r_grid_unit)
static void radial_control_paint_tex(RadialControl *rc, float radius, float alpha)
bool ED_operator_regionactive(bContext *C)
bool RNA_struct_property_is_set(PointerRNA *ptr, const char *identifier)
PointerRNA RNA_pointer_create_discrete(ID *id, StructRNA *type, void *data)
wmOperatorStatus WM_operator_redo_popup(bContext *C, wmOperator *op)
int BKE_image_path_ext_from_imformat_ensure(char *filepath, size_t filepath_maxncpy, const ImageFormatData *im_format)
void(*) MEM_printmemlist_stats()
void immBindTexture(const char *name, gpu::Texture *tex)
void ED_area_status_text(ScrArea *area, const char *str)
Definition area.cc:975
static void WM_OT_call_menu(wmOperatorType *ot)
void RNA_enum_item_end(EnumPropertyItem **items, int *totitem)
wmOperatorStatus WM_operator_props_dialog_popup(bContext *C, wmOperator *op, int width, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default, std::optional< std::string > message, const bool show_icon)
void WM_OT_clear_recent_projects(wmOperatorType *ot)
Definition wm_files.cc:4523
wmOperatorStatus wm_window_new_main_exec(bContext *C, wmOperator *op)
bool RNA_boolean_get(PointerRNA *ptr, const char *name)
wmOperatorStatus WM_operator_confirm_ex(bContext *C, wmOperator *op, const char *title, const char *message, const char *confirm_text, ui::AlertIcon icon, bool cancel_default)
void CTX_wm_region_popup_set(bContext *C, ARegion *region_popup)
std::string RNA_path_property_py(const PointerRNA *ptr, PropertyRNA *prop, int index)
Definition rna_path.cc:1410
void wm_stereo3d_set_draw(bContext *, wmOperator *op)
Definition wm_stereo.cc:356
void WM_OT_save_mainfile(wmOperatorType *ot)
Definition wm_files.cc:4390
void GIZMOGROUP_OT_gizmo_select(wmOperatorType *ot)
static wmOperatorStatus previews_ensure_exec(bContext *C, wmOperator *)
void WM_OT_save_userpref(wmOperatorType *ot)
Definition wm_files.cc:2764
wmOperatorStatus WM_generic_select_modal(bContext *C, wmOperator *op, const wmEvent *event)
void GPU_matrix_translate_2f(float x, float y)
bool(*)(bContext *C) wmPaintCursorPoll
Definition WM_types.hh:1272
CLG_LogRef * WM_LOG_OPERATORS
FileSelectParams * ED_fileselect_get_active_params(const SpaceFile *sfile)
Definition filesel.cc:393
void BLF_draw(int fontid, const char *str, size_t str_len, ResultBLF *r_info=nullptr) ATTR_NONNULL(2)
Definition blf.cc:587
uint GPU_vertformat_attr_add(GPUVertFormat *format, StringRef name, gpu::VertAttrType type)
void BKE_main_id_tag_all(Main *mainvar, int tag, bool value)
Definition lib_id.cc:1314
void WM_event_add_notifier(const bContext *C, uint type, void *reference)
void WM_event_drag_start_mval(const wmEvent *event, const ARegion *region, int r_mval[2])
bool RNA_struct_system_idprops_unset(PointerRNA *ptr, const char *identifier)
static std::string wm_call_menu_get_description(bContext *, wmOperatorType *, PointerRNA *ptr)
wmPaintCursor * WM_paint_cursor_activate(short space_type, short region_type, wmPaintCursorPoll poll, wmPaintCursorDraw draw, void *customdata)
void BLI_str_tolower_ascii(char *str, size_t len) ATTR_NONNULL(1)
bool applyNumInput(NumInput *n, float *vec)
Definition numinput.cc:207
static ui::Block * wm_block_dialog_create(bContext *C, ARegion *region, void *user_data)
static wmOperatorStatus redraw_timer_exec(bContext *C, wmOperator *op)
bool RNA_struct_is_ID(const StructRNA *type)
void wm_exit_schedule_delayed(const bContext *C)
void(*)(bContext *C, const int2 &xy, const float2 &tilt, void *customdata) wmPaintCursorDraw
Definition WM_types.hh:1273
int BIFIconID
Definition ED_asset.hh:30
static void WM_OT_quit_blender(wmOperatorType *ot)
void RNA_def_property_clear_flag(PropertyRNA *prop, PropertyFlag flag)
static wmOperatorStatus doc_view_manual_ui_context_exec(bContext *C, wmOperator *)
void RNA_property_int_ui_range(PointerRNA *ptr, PropertyRNA *prop, int *softmin, int *softmax, int *step)
float BKE_brush_curve_strength_clamped(const Brush *br, float p, float len)
Definition brush.cc:1751
ListBaseT< LinkData > CTX_data_dir_get_ex(const bContext *C, bool use_store, bool use_rna, bool use_all)
wmOperatorStatus WM_operator_props_popup_confirm_ex(bContext *C, wmOperator *op, const wmEvent *, std::optional< std::string > title, std::optional< std::string > confirm_text, const bool cancel_default, std::optional< std::string > message)
float RNA_property_float_get(PointerRNA *ptr, PropertyRNA *prop)
static void WM_OT_search_operator(wmOperatorType *ot)
void wm_stereo3d_set_cancel(bContext *, wmOperator *op)
Definition wm_stereo.cc:401
const EnumPropertyItem * RNA_scene_itemf(bContext *C, PointerRNA *ptr, PropertyRNA *prop, bool *r_free)
PropertySubType RNA_property_subtype(PropertyRNA *prop)
static wmOperatorStatus asset_shelf_popover_invoke(bContext *C, wmOperator *op, const wmEvent *)
SpaceLink * CTX_wm_space_data(const bContext *C)
static void previews_id_ensure(bContext *C, Scene *scene, ID *id)
wmOperatorType * WM_operatortype_find(const char *idname, bool quiet)
wmEventHandler_Op * WM_event_add_modal_handler(bContext *C, wmOperator *op)
static int radial_control_get_properties(bContext *C, wmOperator *op)
static const EnumPropertyItem redraw_timer_type_items[]
void RNA_def_property_flag(PropertyRNA *prop, PropertyFlag flag)
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)
bool wm_stereo3d_set_check(bContext *, wmOperator *)
Definition wm_stereo.cc:393
bool WM_operator_idname_ok_or_report(ReportList *reports, const char *idname)
static const char * wm_context_member_from_ptr(const bContext *C, const PointerRNA *ptr, bool *r_is_id)
static wmOperatorStatus memory_statistics_exec(bContext *, wmOperator *)
void BKE_reportf(ReportList *reports, eReportType type, const char *format,...) ATTR_PRINTF_FORMAT(3
Definition report.cc:191
float RNA_property_float_get_default(PointerRNA *ptr, PropertyRNA *prop)
bool WM_operator_winactive(bContext *C)
const EnumPropertyItem rna_enum_stereo3d_interlace_type_items[]
Definition rna_scene.cc:566
void BLI_addtail(ListBase *listbase, void *vlink) ATTR_NONNULL(1)
Definition listbase.cc:118
Main * CTX_data_main(const bContext *C)
wmOperatorStatus wm_stereo3d_set_exec(bContext *C, wmOperator *op)
Definition wm_stereo.cc:256
static void WM_OT_previews_ensure(wmOperatorType *ot)
void BLI_dial_free(Dial *dial)
std::optional< std::string > RNA_path_full_property_py(const PointerRNA *ptr, PropertyRNA *prop, int index)
Definition rna_path.cc:1376
static void radial_control_cancel(bContext *C, wmOperator *op)
void IDP_FreeProperty(IDProperty *prop)
Definition idprop.cc:1403
void WM_paint_cursor_remove_by_type(wmWindowManager *wm, wmPaintCursorDraw draw_fn, void(*free)(void *))
static wmOperatorStatus wm_debug_menu_invoke(bContext *C, wmOperator *op, const wmEvent *)
static void wm_block_redo_cb(bContext *C, void *arg_op, int)
void WM_OT_read_homefile(wmOperatorType *ot)
Definition wm_files.cc:3153
bool BKE_brush_has_cube_tip(const Brush *brush, PaintMode paint_mode)
Definition brush.cc:1816
void WM_OT_save_auto_save(wmOperatorType *ot)
Definition wm_files.cc:2529
MINLINE float max_ff(float a, float b)
void GPU_texture_free(gpu::Texture *texture)
void outputNumInput(NumInput *n, char *str, const UnitSettings &unit_settings)
Definition numinput.cc:104
static void WM_OT_redraw_timer(wmOperatorType *ot)
const EnumPropertyItem rna_enum_stereo3d_anaglyph_type_items[]
Definition rna_scene.cc:559
static ui::Block * wm_block_search_menu(bContext *C, ARegion *region, void *userdata)
static wmOperatorStatus wm_operator_props_popup_ex(bContext *C, wmOperator *op, const bool do_call, const bool do_redo, std::optional< std::string > title=std::nullopt, std::optional< std::string > confirm_text=std::nullopt, const bool cancel_default=false, std::optional< std::string > message=std::nullopt)
static void WM_OT_stereo3d_set(wmOperatorType *ot)
static void WM_OT_call_asset_shelf_popover(wmOperatorType *ot)
bool RNA_enum_description(const EnumPropertyItem *item, const int value, const char **r_description)
wmOperatorStatus WM_operator_name_call_ptr(bContext *C, wmOperatorType *ot, wm::OpCallContext context, PointerRNA *properties, const wmEvent *event)
ID_Type GS(const char *name)
Definition DNA_ID.h:410
@ PROP_ENUM_NO_CONTEXT
Definition RNA_types.hh:500
@ PROP_SKIP_PRESET
Definition RNA_types.hh:543
@ PROP_SKIP_SAVE
Definition RNA_types.hh:414
static wmOperatorStatus wm_operator_defaults_exec(bContext *C, wmOperator *op)
@ ID_TAG_DOIT
Definition DNA_ID.h:1029
static bool rna_id_enum_filter_single(const ID *id, void *user_data)
void BKE_main_id_tag_listbase(ListBaseT< ID > *lb, int tag, bool value)
Definition lib_id.cc:1291
Dial * BLI_dial_init(const float start_position[2], float threshold)
static void gesture_circle_modal_keymap(wmKeyConfig *keyconf)
wmOperator * WM_operator_last_redo(const bContext *C)
void wm_operator_register(bContext *C, wmOperator *op)
Definition wm.cc:350
PropertyRNA * RNA_def_enum_flag(StructOrFunctionRNA *cont_, const char *identifier, const EnumPropertyItem *items, const int default_value, const char *ui_name, const char *ui_description)
@ KM_RELEASE
Definition WM_types.hh:325
void WM_modalkeymap_assign(wmKeyMap *km, const char *opname)
static wmOperatorStatus wm_search_menu_exec(bContext *, wmOperator *)
double BLI_time_now_seconds()
Definition time.cc:30
static bool operator_idname_ok_or_report_impl(ReportList *reports, const char *idname, FunctionRef< std::string()> error_prefix_fn)
wmOperatorStatus WM_enum_search_invoke(bContext *C, wmOperator *op, const wmEvent *)
void GPU_texture_unbind(gpu::Texture *texture)
void GIZMOGROUP_OT_gizmo_tweak(wmOperatorType *ot)
static void wm_operator_ui_popup_cancel(bContext *C, void *user_data)
void RNA_property_boolean_set(PointerRNA *ptr, PropertyRNA *prop, bool value)
static void wm_operator_ui_popup_ok(bContext *C, void *arg, int retval)
bool WM_operator_properties_default(PointerRNA *ptr, const bool do_update)
Scene * CTX_data_scene(const bContext *C)
void ED_screen_refresh(bContext *C, wmWindowManager *wm, wmWindow *win)
bScreen * CTX_wm_screen(const bContext *C)
static wmOperatorStatus wm_exit_blender_exec(bContext *C, wmOperator *)
void CTX_wm_region_set(bContext *C, ARegion *region)
static void WM_OT_window_fullscreen_toggle(wmOperatorType *ot)
void WM_OT_recover_auto_save(wmOperatorType *ot)
Definition wm_files.cc:3756
wmKeyMap * WM_modalkeymap_ensure(wmKeyConfig *keyconf, const char *idname, const EnumPropertyItem *items)
Definition wm_keymap.cc:972
void RNA_property_float_ui_range(PointerRNA *ptr, PropertyRNA *prop, float *softmin, float *softmax, float *step, float *precision)
float BLI_dial_angle(Dial *dial, const float current_position[2])
void GPU_blend(GPUBlend blend)
Definition gpu_state.cc:44
@ OPTYPE_REGISTER
Definition WM_types.hh:188
@ OPTYPE_UNDO
Definition WM_types.hh:190
@ OPTYPE_BLOCKING
Definition WM_types.hh:192
@ OPTYPE_INTERNAL
Definition WM_types.hh:210
void wm_event_do_refresh_wm_and_depsgraph(bContext *C)
void wm_draw_update(bContext *C)
Definition wm_draw.cc:1706
std::string RNA_string_get(PointerRNA *ptr, const char *name)
static void radial_control_set_initial_mouse(RadialControl *rc, const wmEvent *event)
MINLINE float len_v2(const float v[2]) ATTR_WARN_UNUSED_RESULT
LibraryForeachIDCallbackFlag
@ IDWALK_CB_EMBEDDED_NOT_OWNING
@ IDWALK_CB_EMBEDDED
size_t BLI_strlen_utf8(const char *strc) ATTR_NONNULL(1) ATTR_WARN_UNUSED_RESULT
PropertyRNA * RNA_def_boolean(StructOrFunctionRNA *cont_, const char *identifier, const bool default_value, const char *ui_name, const char *ui_description)
@ PROP_PERCENTAGE
Definition RNA_types.hh:307
@ PROP_FACTOR
Definition RNA_types.hh:308
@ PROP_DISTANCE_DIAMETER
Definition RNA_types.hh:351
@ PROP_DISTANCE
Definition RNA_types.hh:313
@ PROP_PIXEL_DIAMETER
Definition RNA_types.hh:350
ReportList * CTX_wm_reports(const bContext *C)
int WM_userdef_event_type_from_keymap_type(int kmitype)
bool WM_event_drag_test_with_delta(const wmEvent *event, const int drag_delta[2])
void BLF_width_and_height(int fontid, const char *str, size_t str_len, float *r_width, float *r_height) ATTR_NONNULL()
Definition blf.cc:822
bool WM_operator_check_ui_enabled(const bContext *C, const char *idname)
int RNA_property_int_get(PointerRNA *ptr, PropertyRNA *prop)
void GPU_matrix_pop()
void immUniformColor3fvAlpha(const float rgb[3], float a)
bool WM_operator_last_properties_store(wmOperator *op)
void imm_draw_circle_fill_2d(uint shdr_pos, float x, float y, float radius, int nsegments)
bScreen * WM_window_get_active_screen(const wmWindow *win)
void WM_cursor_wait(bool val)
MINLINE int min_ii(int a, int b)
static void WM_OT_radial_control(wmOperatorType *ot)
PropertyRNA * RNA_def_float(StructOrFunctionRNA *cont_, const char *identifier, const float default_value, const float hardmin, const float hardmax, const char *ui_name, const char *ui_description, const float softmin, const float softmax)
size_t WM_operator_py_idname(char *dst, const char *src)
void WM_OT_splash(wmOperatorType *ot)
void BKE_library_foreach_ID_link(Main *bmain, ID *id, FunctionRef< LibraryIDLinkCallback > callback, void *user_data, LibraryForeachIDFlag flag)
Definition lib_query.cc:449
ARegion * CTX_wm_region(const bContext *C)
void ED_workspace_status_text(bContext *C, const char *str)
Definition area.cc:1153
static void wm_block_redo_cancel_cb(bContext *C, void *arg_op)
PaintMode BKE_paintmode_get_active_from_context(const bContext *C)
bool ED_undo_is_valid(const bContext *C, const char *undoname)
Definition ed_undo.cc:574
wmOperatorStatus WM_operator_confirm_or_exec(bContext *C, wmOperator *op, const wmEvent *)
float RNA_float_get(PointerRNA *ptr, const char *name)
static std::string wm_call_panel_get_name(wmOperatorType *ot, PointerRNA *ptr)
void WM_OT_lib_relocate(wmOperatorType *ot)
PointerRNA CTX_data_pointer_get_type(const bContext *C, const char *member, StructRNA *type)
bool RNA_property_is_set(PointerRNA *ptr, PropertyRNA *prop)
bool WM_operator_filesel_ensure_ext_imtype(wmOperator *op, const ImageFormatData *im_format)
static void WM_OT_memory_statistics(wmOperatorType *ot)
static void redraw_timer_step(bContext *C, Scene *scene, Depsgraph *depsgraph, wmWindow *win, ScrArea *area, ARegion *region, const int type, const int cfra, const int steps_done, const int steps_total)
View3D * CTX_wm_view3d(const bContext *C)
void WM_event_add_fileselect(bContext *C, wmOperator *op)
gpu::Texture * GPU_texture_create_2d(const char *name, int width, int height, int mip_len, gpu::TextureFormat format, eGPUTextureUsage usage, const float *data)
wmOperatorStatus WM_operator_confirm_message(bContext *C, wmOperator *op, const char *message)
void GPU_matrix_push()
void BLF_color4fv(int fontid, const float rgba[4])
Definition blf.cc:507
const char * RNA_property_ui_name(const PropertyRNA *prop, const PointerRNA *ptr)
static void radial_control_paint_cursor(bContext *C, const int2 &, const float2 &, void *customdata)
void WM_OT_read_history(wmOperatorType *ot)
Definition wm_files.cc:2979
std::string RNA_property_as_string(bContext *C, PointerRNA *ptr, PropertyRNA *prop, int index, int max_prop_length)
void ED_area_tag_redraw(ScrArea *area)
Definition area.cc:784
static int previews_id_ensure_callback(LibraryIDLinkCallbackData *cb_data)
MINLINE float clamp_f(float value, float min, float max)
bool WM_paint_cursor_end(wmPaintCursor *handle)
void CTX_wm_area_set(bContext *C, ScrArea *area)
@ NUM_NO_NEGATIVE
#define fabsf
#define sinf
#define cosf
#define atan2f
KERNEL_FEATURE_LIGHT_PASSES KERNEL_FEATURE_PATH_GUIDING float
#define min(a, b)
Definition sort.cc:38
bke::ARegionRuntime * runtime
struct CurveMapping * curve_distance_falloff
ListBaseT< struct IDProperty > group
Definition DNA_ID.h:133
eIDPropertyFlag flag
Definition DNA_ID.h:151
IDPropertyData data
Definition DNA_ID.h:157
char name[258]
Definition DNA_ID.h:433
const float * float_data() const
LibraryForeachIDCallbackFlag cb_flag
ListBaseT< Collection > collections
Definition BKE_main.hh:406
ListBaseT< Light > lights
Definition BKE_main.hh:396
ListBaseT< World > worlds
Definition BKE_main.hh:399
ListBaseT< Material > materials
Definition BKE_main.hh:392
ListBaseT< Object > objects
Definition BKE_main.hh:388
ListBaseT< Image > images
Definition BKE_main.hh:394
ListBaseT< Scene > scenes
Definition BKE_main.hh:386
ListBaseT< Tex > textures
Definition BKE_main.hh:393
char translation_context[BKE_ST_MAXNAME]
char label[BKE_ST_MAXNAME]
const char * description
int unit_type[NUM_MAX_ELEMENTS]
short val_flag[NUM_MAX_ELEMENTS]
char translation_context[BKE_ST_MAXNAME]
char label[BKE_ST_MAXNAME]
StructRNA * type
Definition RNA_types.hh:63
PropertyRNA * fill_col_override_test_prop
PropertyRNA * fill_col_prop
ListBaseT< wmPaintCursor > orig_paintcursors
PropertySubType subtype
PropertyRNA * fill_col_override_prop
PointerRNA fill_col_override_test_ptr
struct UnitSettings unit
struct RenderData r
ListBaseT< ARegion > regionbase
struct bDopeSheet * ads
struct bDopeSheet * ads
View3DShading shading
ListBaseT< EditBone > * edbo
struct EditBone * act_edbone
eScreen_State state
ListBaseT< struct ScrArea > areabase
void enabled_set(bool enabled)
void label_multiline(StringRefNull label, int icon, FontStyleAlign align=UI_STYLE_TEXT_LEFT, int max_lines=0)
void operator_context_set(wm::OpCallContext opcontext)
Layout & split(float percentage, bool align)
Layout & column(bool align)
void op_enum(StringRefNull opname, StringRefNull propname, IDProperty *properties, wm::OpCallContext context, eUI_Item_Flag flag, const int active=-1)
void separator(float factor=1.0f, LayoutSeparatorType type=LayoutSeparatorType::Auto)
wmEventType type
Definition WM_types.hh:817
std::string confirm_text
wmPopupPosition position
IDProperty * last_properties
Definition WM_types.hh:1206
wmOperatorStatus(*) exec(bContext *C, wmOperator *op) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1125
bool(*) check(bContext *C, wmOperator *op)
Definition WM_types.hh:1133
const char * description
Definition WM_types.hh:1115
void(*) cancel(bContext *C, wmOperator *op)
Definition WM_types.hh:1149
ListBaseT< wmOperatorTypeMacro > macro
Definition WM_types.hh:1218
const char * translation_context
Definition WM_types.hh:1113
void(*) ui(bContext *C, wmOperator *op)
Definition WM_types.hh:1176
bool(*) poll(bContext *C) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1165
wmOperatorStatus(*) invoke(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1141
wmOperatorStatus(*) modal(bContext *C, wmOperator *op, const wmEvent *event) ATTR_WARN_UNUSED_RESULT
Definition WM_types.hh:1157
std::string(*) get_description(bContext *C, wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1197
std::string(*) get_name(wmOperatorType *ot, PointerRNA *ptr)
Definition WM_types.hh:1191
ListBaseT< wmOperator > macro
struct ReportList * reports
struct wmOperatorType * type
wmPaintCursorPoll poll
Definition WM_types.hh:1283
wmPaintCursorDraw draw
Definition WM_types.hh:1284
uiFontStyle widget
short columnspace
#define N_(msgid)
#define ISMOUSE_MOTION(event_type)
#define IS_EVENT_IME_ANY(event_type)
#define CTX_TEST_PTR_ID_CAST(C, member, member_full, cast, idptr)
#define ID_CAST_SCENEWORLD(id_pt)
#define CTX_TEST_PTR_ID(C, member, idptr)
#define ID_CAST_OBDATA(id_pt)
#define TEST_PTR_DATA_TYPE_FROM_CONTEXT(member, rna_type, rna_ptr)
#define ID_CAST_OBMATACT(id_pt)
#define OP_MAX_PY_IDNAME
#define OP_BL_SEP_LEN
#define WM_RADIAL_CONTROL_DISPLAY_WIDTH
#define OP_BL_SEP_STRING
#define TEST_PTR_DATA_TYPE(member, rna_type, rna_ptr, dataptr_cmp)
#define WM_RADIAL_CONTROL_DISPLAY_MIN_SIZE
#define OP_PY_SEP_LEN
#define OP_PY_SEP_CHAR
#define WM_RADIAL_MAX_STR
#define WM_RADIAL_CONTROL_DISPLAY_SIZE